changeset 448:a73cc0fa14d0

Use explicit names for mouse buttons instead of numbers. MOUSE_BUTTON_LEFT = 1 MOUSE_BUTTON_MIDDLE = 2 MOUSE_BUTTON_RIGHT = 3 It makes the code easier to read.
author zas_
date Sun, 20 Apr 2008 21:30:36 +0000
parents d87de3a3eb3b
children 115db540bd0c
files src/collect-table.c src/dupe.c src/img-view.c src/info.c src/layout_image.c src/pan-view.c src/pixbuf-renderer.c src/search.c src/typedefs.h src/ui_bookmark.c src/ui_misc.c src/ui_pathsel.c src/utilops.c src/view_dir.c src/view_dir_list.c src/view_dir_tree.c src/view_file_icon.c src/view_file_list.c
diffstat 18 files changed, 72 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/src/collect-table.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/collect-table.c	Sun Apr 20 21:30:36 2008 +0000
@@ -1427,7 +1427,7 @@
 
 	switch (bevent->button)
 		{
-		case 1:
+		case MOUSE_BUTTON_LEFT:
 			if (bevent->type == GDK_2BUTTON_PRESS)
 				{
 				if (info)
@@ -1440,7 +1440,7 @@
 				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;
@@ -1469,7 +1469,7 @@
 		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);
@@ -1503,7 +1503,7 @@
 				}
 			}
 		}
-	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));
--- a/src/dupe.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/dupe.c	Sun Apr 20 21:30:36 2008 +0000
@@ -2289,7 +2289,7 @@
 
 	dw->click_item = di;
 
-	if (bevent->button == 3)
+	if (bevent->button == MOUSE_BUTTON_RIGHT)
 		{
 		/* right click menu */
 		GtkWidget *menu;
@@ -2312,14 +2312,15 @@
 
 	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 == 3)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;
+
+	if (bevent->button == MOUSE_BUTTON_RIGHT)
 		{
 		if (!dupe_listview_item_is_selected(dw, di, widget))
 			{
@@ -2337,7 +2338,8 @@
 		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))
@@ -2358,7 +2360,7 @@
 	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));
 
@@ -2371,7 +2373,7 @@
 		gtk_tree_path_free(tpath);
 		}
 
-	if (bevent->button == 2)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE)
 		{
 		if (di && dw->click_item == di)
 			{
--- a/src/img-view.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/img-view.c	Sun Apr 20 21:30:36 2008 +0000
@@ -603,13 +603,13 @@
 
 	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;
--- a/src/info.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/info.c	Sun Apr 20 21:30:36 2008 +0000
@@ -696,11 +696,11 @@
 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);
 		}
--- a/src/layout_image.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/layout_image.c	Sun Apr 20 21:30:36 2008 +0000
@@ -1544,13 +1544,13 @@
 
 	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)
 				{
@@ -1669,7 +1669,7 @@
 
 	switch (button)
 		{
-		case 3:
+		case MOUSE_BUTTON_RIGHT:
 			menu = layout_image_pop_menu(lw);
 			if (imd == lw->image)
 				{
--- a/src/pan-view.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/pan-view.c	Sun Apr 20 21:30:36 2008 +0000
@@ -2026,7 +2026,7 @@
 		}
 
 	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;
@@ -2037,7 +2037,7 @@
 
 	switch (event->button)
 		{
-		case 1:
+		case MOUSE_BUTTON_LEFT:
 			pan_info_update(pw, pi);
 
 			if (!pi && pw->layout == PAN_LAYOUT_CALENDAR)
@@ -2046,9 +2046,9 @@
 				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);
--- a/src/pixbuf-renderer.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/pixbuf-renderer.c	Sun Apr 20 21:30:36 2008 +0000
@@ -3593,7 +3593,7 @@
 
 	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;
@@ -3603,10 +3603,10 @@
 					 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:
@@ -3643,11 +3643,11 @@
 
 	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);
 			}
--- a/src/search.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/search.c	Sun Apr 20 21:30:36 2008 +0000
@@ -1045,7 +1045,7 @@
 
 	sd->click_fd = mfd ? mfd->fd : NULL;
 
-	if (bevent->button == 3)
+	if (bevent->button == MOUSE_BUTTON_RIGHT)
 		{
 		GtkWidget *menu;
 
@@ -1055,14 +1055,14 @@
 
 	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 == 3)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;
+
+	if (bevent->button == MOUSE_BUTTON_RIGHT)
 		{
 		if (!search_result_row_selected(sd, mfd->fd))
 			{
@@ -1079,7 +1079,7 @@
 		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))
@@ -1101,7 +1101,7 @@
 
 	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));
 
@@ -1114,7 +1114,7 @@
 		gtk_tree_path_free(tpath);
 		}
 
-	if (bevent->button == 2)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE)
 		{
 		if (mfd && sd->click_fd == mfd->fd)
 			{
--- a/src/typedefs.h	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/typedefs.h	Sun Apr 20 21:30:36 2008 +0000
@@ -14,6 +14,14 @@
 #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
 } DirViewType;
--- a/src/ui_bookmark.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/ui_bookmark.c	Sun Apr 20 21:30:36 2008 +0000
@@ -735,7 +735,7 @@
 {
 	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);
 
--- a/src/ui_misc.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/ui_misc.c	Sun Apr 20 21:30:36 2008 +0000
@@ -21,6 +21,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "main.h"
 #include "ui_misc.h"
 
 #include "ui_bookmark.h"
@@ -1249,7 +1250,7 @@
 {
 	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;
@@ -1270,7 +1271,7 @@
 {
 	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))
 		{
--- a/src/ui_pathsel.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/ui_pathsel.c	Sun Apr 20 21:30:36 2008 +0000
@@ -669,7 +669,7 @@
 	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))
 		{
--- a/src/utilops.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/utilops.c	Sun Apr 20 21:30:36 2008 +0000
@@ -1721,11 +1721,11 @@
 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);
 		}
--- a/src/view_dir.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/view_dir.c	Sun Apr 20 21:30:36 2008 +0000
@@ -929,7 +929,7 @@
 	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,
--- a/src/view_dir_list.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/view_dir_list.c	Sun Apr 20 21:30:36 2008 +0000
@@ -337,7 +337,7 @@
 	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,
--- a/src/view_dir_tree.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/view_dir_tree.c	Sun Apr 20 21:30:36 2008 +0000
@@ -832,7 +832,7 @@
 			/* 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))
 				{
@@ -850,14 +850,14 @@
 	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)
--- a/src/view_file_icon.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/view_file_icon.c	Sun Apr 20 21:30:36 2008 +0000
@@ -1450,7 +1450,7 @@
 
 	switch (bevent->button)
 		{
-		case 1:
+		case MOUSE_BUTTON_LEFT:
 			if (!GTK_WIDGET_HAS_FOCUS(vfi->listview))
 				{
 				gtk_widget_grab_focus(vfi->listview);
@@ -1464,7 +1464,7 @@
 				}
 #endif
 			break;
-		case 3:
+		case MOUSE_BUTTON_RIGHT:
 			vfi->popup = vficon_pop_menu(vfi, (id != NULL));
 			gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
 			break;
@@ -1496,7 +1496,7 @@
 
 	if (id) was_selected = (id->selected & SELECTION_SELECTED);
 
-	if (bevent->button == 1 &&
+	if (bevent->button == MOUSE_BUTTON_LEFT &&
 	    id && vfi->click_id == id)
 		{
 		vficon_set_focus(vfi, id);
@@ -1531,7 +1531,7 @@
 				}
 			}
 		}
-	else if (bevent->button == 2 &&
+	else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
 		 id && vfi->click_id == id)
 		{
 		vficon_select_util(vfi, id, !(id->selected & SELECTION_SELECTED));
--- a/src/view_file_list.c	Sun Apr 20 20:35:26 2008 +0000
+++ b/src/view_file_list.c	Sun Apr 20 21:30:36 2008 +0000
@@ -715,7 +715,7 @@
 		GtkTreeModel *store;
 		col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column_store_idx"));
 
-		if (bevent->button == 1 &&
+		if (bevent->button == MOUSE_BUTTON_LEFT &&
 		    col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST)
 			return FALSE;
 
@@ -731,7 +731,7 @@
 
 	vfl->click_fd = fd;
 
-	if (bevent->button == 3)
+	if (bevent->button == MOUSE_BUTTON_RIGHT)
 		{
 		vfl->popup = vflist_pop_menu(vfl, vfl->click_fd, col_idx);
 		gtk_menu_popup(GTK_MENU(vfl->popup), NULL, NULL, NULL, NULL,
@@ -741,7 +741,7 @@
 
 	if (!fd) return FALSE;
 
-	if (bevent->button == 2)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE)
 		{
 		if (!vflist_row_is_selected(vfl, fd))
 			{
@@ -751,7 +751,7 @@
 		}
 
 
-	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 ) &&
 	    vflist_row_is_selected(vfl, fd))
@@ -761,7 +761,7 @@
 		}
 
 #if 0
-	if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS)
+	if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS)
 		{
 		if (vfl->layout) layout_image_full_screen_start(vfl->layout);
 		}
@@ -777,12 +777,12 @@
 	GtkTreeIter iter;
 	FileData *fd = NULL;
 
-	if (bevent->button == 2)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE)
 		{
 		vflist_color_set(vfl, vfl->click_fd, FALSE);
 		}
 
-	if (bevent->button != 1 && bevent->button != 2)
+	if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE)
 		{
 		return TRUE;
 		}
@@ -799,7 +799,7 @@
 		gtk_tree_path_free(tpath);
 		}
 
-	if (bevent->button == 2)
+	if (bevent->button == MOUSE_BUTTON_MIDDLE)
 		{
 		if (fd && vfl->click_fd == fd)
 			{