Skip to content

Commit

Permalink
Use explicit names for mouse buttons instead of numbers.
Browse files Browse the repository at this point in the history
MOUSE_BUTTON_LEFT   = 1
MOUSE_BUTTON_MIDDLE = 2
MOUSE_BUTTON_RIGHT  = 3
It makes the code easier to read.
  • Loading branch information
Laurent Monin committed Apr 20, 2008
1 parent cd9fb13 commit 7d1f6b9
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 59 deletions.
8 changes: 4 additions & 4 deletions src/collect-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent,

switch (bevent->button)
{
case 1:
case MOUSE_BUTTON_LEFT:
if (bevent->type == GDK_2BUTTON_PRESS)
{
if (info)
Expand All @@ -1440,7 +1440,7 @@ static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent,
gtk_widget_grab_focus(ct->listview);
}
break;
case 3:
case MOUSE_BUTTON_RIGHT:
ct->popup = collection_table_popup_menu(ct, (info != NULL));
gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
break;
Expand Down Expand Up @@ -1469,7 +1469,7 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
}

if (bevent->button == 1 &&
if (bevent->button == MOUSE_BUTTON_LEFT &&
info && ct->click_info == info)
{
collection_table_set_focus(ct, info);
Expand Down Expand Up @@ -1503,7 +1503,7 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
}
}
}
else if (bevent->button == 2 &&
else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
info && ct->click_info == info)
{
collection_table_select_util(ct, info, !INFO_SELECTED(info));
Expand Down
16 changes: 9 additions & 7 deletions src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@ static gint dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gp

dw->click_item = di;

if (bevent->button == 3)
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
/* right click menu */
GtkWidget *menu;
Expand All @@ -2312,14 +2312,15 @@ static gint dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gp

if (!di) return FALSE;

if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS)
if (bevent->button == MOUSE_BUTTON_LEFT &&
bevent->type == GDK_2BUTTON_PRESS)
{
dupe_menu_view(dw, di, widget, FALSE);
}

if (bevent->button == 2) return TRUE;
if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;

if (bevent->button == 3)
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
if (!dupe_listview_item_is_selected(dw, di, widget))
{
Expand All @@ -2337,7 +2338,8 @@ static gint dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gp
return TRUE;
}

if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS &&
if (bevent->button == MOUSE_BUTTON_LEFT &&
bevent->type == GDK_BUTTON_PRESS &&
!(bevent->state & GDK_SHIFT_MASK ) &&
!(bevent->state & GDK_CONTROL_MASK ) &&
dupe_listview_item_is_selected(dw, di, widget))
Expand All @@ -2358,7 +2360,7 @@ static gint dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent,
GtkTreeIter iter;
DupeItem *di = NULL;

if (bevent->button != 1 && bevent->button != 2) return TRUE;
if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE;

store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));

Expand All @@ -2371,7 +2373,7 @@ static gint dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent,
gtk_tree_path_free(tpath);
}

if (bevent->button == 2)
if (bevent->button == MOUSE_BUTTON_MIDDLE)
{
if (di && dw->click_item == di)
{
Expand Down
6 changes: 3 additions & 3 deletions src/img-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,13 @@ static void button_cb(ImageWindow *imd, gint button, guint32 time,

switch (button)
{
case 1:
case MOUSE_BUTTON_LEFT:
view_step_next(vw);
break;
case 2:
case MOUSE_BUTTON_MIDDLE:
view_step_prev(vw);
break;
case 3:
case MOUSE_BUTTON_RIGHT:
menu = view_popup_menu(vw);
gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, time);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,11 @@ static void info_window_next_cb(GtkWidget *widget, gpointer data)
static void info_window_image_button_cb(ImageWindow *imd, gint button, guint32 time,
gdouble x, gdouble y, guint state, gpointer data)
{
if (button == 1)
if (button == MOUSE_BUTTON_LEFT)
{
info_window_next_cb(NULL, data);
}
else if (button == 2 || button == 3)
else if (button == MOUSE_BUTTON_MIDDLE || button == MOUSE_BUTTON_RIGHT)
{
info_window_back_cb(NULL, data);
}
Expand Down
8 changes: 4 additions & 4 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,13 +1544,13 @@ static void layout_image_button_cb(ImageWindow *imd, gint button, guint32 time,

switch (button)
{
case 1:
case MOUSE_BUTTON_LEFT:
layout_image_next(lw);
break;
case 2:
case MOUSE_BUTTON_MIDDLE:
layout_image_prev(lw);
break;
case 3:
case MOUSE_BUTTON_RIGHT:
menu = layout_image_pop_menu(lw);
if (imd == lw->image)
{
Expand Down Expand Up @@ -1669,7 +1669,7 @@ static void layout_image_button_inactive_cb(ImageWindow *imd, gint button, guint

switch (button)
{
case 3:
case MOUSE_BUTTON_RIGHT:
menu = layout_image_pop_menu(lw);
if (imd == lw->image)
{
Expand Down
8 changes: 4 additions & 4 deletions src/pan-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ static void button_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
}

pi = pan_item_find_by_coord(pw, PAN_ITEM_BOX, rx, ry, "info");
if (pi && event->button == 1)
if (pi && event->button == MOUSE_BUTTON_LEFT)
{
pan_info_update(pw, NULL);
return;
Expand All @@ -2037,7 +2037,7 @@ static void button_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)

switch (event->button)
{
case 1:
case MOUSE_BUTTON_LEFT:
pan_info_update(pw, pi);

if (!pi && pw->layout == PAN_LAYOUT_CALENDAR)
Expand All @@ -2046,9 +2046,9 @@ static void button_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
pan_calendar_update(pw, pi);
}
break;
case 2:
case MOUSE_BUTTON_MIDDLE:
break;
case 3:
case MOUSE_BUTTON_RIGHT:
pan_info_update(pw, pi);
menu = pan_popup_menu(pw);
gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
Expand Down
10 changes: 5 additions & 5 deletions src/pixbuf-renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3593,7 +3593,7 @@ static gint pr_mouse_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointe

switch (bevent->button)
{
case 1:
case MOUSE_BUTTON_LEFT:
pr->in_drag = TRUE;
pr->drag_last_x = bevent->x;
pr->drag_last_y = bevent->y;
Expand All @@ -3603,10 +3603,10 @@ static gint pr_mouse_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointe
NULL, NULL, bevent->time);
gtk_grab_add(widget);
break;
case 2:
case MOUSE_BUTTON_MIDDLE:
pr->drag_moved = 0;
break;
case 3:
case MOUSE_BUTTON_RIGHT:
pr_clicked_signal(pr, bevent);
break;
default:
Expand Down Expand Up @@ -3643,11 +3643,11 @@ static gint pr_mouse_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpoin

if (pr->drag_moved < PR_DRAG_SCROLL_THRESHHOLD)
{
if (bevent->button == 1 && (bevent->state & GDK_SHIFT_MASK))
if (bevent->button == MOUSE_BUTTON_LEFT && (bevent->state & GDK_SHIFT_MASK))
{
pr_scroller_start(pr, bevent->x, bevent->y);
}
else if (bevent->button == 1 || bevent->button == 2)
else if (bevent->button == MOUSE_BUTTON_LEFT || bevent->button == MOUSE_BUTTON_MIDDLE)
{
pr_clicked_signal(pr, bevent);
}
Expand Down
14 changes: 7 additions & 7 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ static gint search_result_press_cb(GtkWidget *widget, GdkEventButton *bevent, gp

sd->click_fd = mfd ? mfd->fd : NULL;

if (bevent->button == 3)
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
GtkWidget *menu;

Expand All @@ -1055,14 +1055,14 @@ static gint search_result_press_cb(GtkWidget *widget, GdkEventButton *bevent, gp

if (!mfd) return FALSE;

if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS)
if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS)
{
layout_image_set_fd(NULL, mfd->fd);
}

if (bevent->button == 2) return TRUE;
if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;

if (bevent->button == 3)
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
if (!search_result_row_selected(sd, mfd->fd))
{
Expand All @@ -1079,7 +1079,7 @@ static gint search_result_press_cb(GtkWidget *widget, GdkEventButton *bevent, gp
return TRUE;
}

if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS &&
if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_BUTTON_PRESS &&
!(bevent->state & GDK_SHIFT_MASK ) &&
!(bevent->state & GDK_CONTROL_MASK ) &&
search_result_row_selected(sd, mfd->fd))
Expand All @@ -1101,7 +1101,7 @@ static gint search_result_release_cb(GtkWidget *widget, GdkEventButton *bevent,

MatchFileData *mfd = NULL;

if (bevent->button != 1 && bevent->button != 2) return TRUE;
if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE;

store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));

Expand All @@ -1114,7 +1114,7 @@ static gint search_result_release_cb(GtkWidget *widget, GdkEventButton *bevent,
gtk_tree_path_free(tpath);
}

if (bevent->button == 2)
if (bevent->button == MOUSE_BUTTON_MIDDLE)
{
if (mfd && sd->click_fd == mfd->fd)
{
Expand Down
8 changes: 8 additions & 0 deletions src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
#ifndef TYPEDEFS_H
#define TYPEDEFS_H

typedef enum {
MOUSE_BUTTON_LEFT = 1,
MOUSE_BUTTON_MIDDLE = 2,
MOUSE_BUTTON_RIGHT = 3,
MOUSE_BUTTON_WHEEL_UP = 4,
MOUSE_BUTTON_WHEEL_DOWN = 5
} MouseButton;

typedef enum {
DIRVIEW_LIST,
DIRVIEW_TREE
Expand Down
2 changes: 1 addition & 1 deletion src/ui_bookmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ static gint bookmark_press_cb(GtkWidget *button, GdkEventButton *event, gpointer
{
BookMarkData *bm = data;

if (event->button != 3) return FALSE;
if (event->button != MOUSE_BUTTON_RIGHT) return FALSE;

bookmark_menu_popup(bm, button, event->button, event->time, FALSE);

Expand Down
5 changes: 3 additions & 2 deletions src/ui_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

#include "main.h"
#include "ui_misc.h"

#include "ui_bookmark.h"
Expand Down Expand Up @@ -1249,7 +1250,7 @@ static gint sizer_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
{
SizerData *sd = data;

if (bevent->button != 1) return FALSE;
if (bevent->button != MOUSE_BUTTON_LEFT) return FALSE;

sd->in_drag = TRUE;
sd->press_x = bevent->x_root;
Expand All @@ -1270,7 +1271,7 @@ static gint sizer_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer
{
SizerData *sd = data;

if (bevent->button != 1) return FALSE;
if (bevent->button != MOUSE_BUTTON_LEFT) return FALSE;

if (gdk_pointer_is_grabbed() && GTK_WIDGET_HAS_GRAB(sd->sizer))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ui_pathsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ static gint dest_press_cb(GtkWidget *view, GdkEventButton *event, gpointer data)
GtkTreeIter iter;
GtkTreeSelection *selection;

if (event->button != 3 ||
if (event->button != MOUSE_BUTTON_RIGHT ||
!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(view), event->x, event->y,
&tpath, &column, &cell_x, &cell_y))
{
Expand Down
4 changes: 2 additions & 2 deletions src/utilops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1721,11 +1721,11 @@ static void file_util_delete_multiple_review_next(GtkWidget *button, gpointer da
static void file_util_delete_multiple_review_button_cb(ImageWindow *imd, gint button, guint32 time,
gdouble x, gdouble y, guint state, gpointer data)
{
if (button == 1)
if (button == MOUSE_BUTTON_LEFT)
{
file_util_delete_multiple_review_next(NULL, data);
}
else if (button == 2 || button == 3)
else if (button == MOUSE_BUTTON_MIDDLE || button == MOUSE_BUTTON_RIGHT)
{
file_util_delete_multiple_review_back(NULL, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/view_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ gint vd_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
if (!vd->click_fd) return FALSE;
vd_color_set(vd, vd->click_fd, FALSE);

if (bevent->button != 1) return TRUE;
if (bevent->button != MOUSE_BUTTON_LEFT) return TRUE;

if ((bevent->x != 0 || bevent->y != 0) &&
gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
Expand Down
2 changes: 1 addition & 1 deletion src/view_dir_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
vd->click_fd = fd;
vd_color_set(vd, vd->click_fd, TRUE);

if (bevent->button == 3)
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
vd->popup = vd_pop_menu(vd, vd->click_fd);
gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL,
Expand Down
6 changes: 3 additions & 3 deletions src/view_dir_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
/* clicking this region should automatically reveal an expander, if necessary
* treeview bug: the expander will not expand until a button_motion_event highlights it.
*/
if (bevent->button == 1 &&
if (bevent->button == MOUSE_BUTTON_LEFT &&
!left_of_expander &&
!gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath))
{
Expand All @@ -850,14 +850,14 @@ gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
vd->click_fd = (nd) ? nd->fd : NULL;
vd_color_set(vd, vd->click_fd, TRUE);

if (bevent->button == 3)
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
vd->popup = vd_pop_menu(vd, vd->click_fd);
gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
}

return (bevent->button != 1);
return (bevent->button != MOUSE_BUTTON_LEFT);
}

static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data)
Expand Down
Loading

0 comments on commit 7d1f6b9

Please sign in to comment.