changeset 128:98e2632b5d3d

improved connected scroll and active image switching
author nadvornik
date Tue, 10 Jul 2007 21:25:51 +0000
parents 271afad04d07
children 89fc00ffbce2
files src/image.c src/image.h src/layout_image.c src/pixbuf-renderer.c src/pixbuf-renderer.h src/typedefs.h
diffstat 6 files changed, 93 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/image.c	Fri Jun 29 15:16:46 2007 +0000
+++ b/src/image.c	Tue Jul 10 21:25:51 2007 +0000
@@ -64,6 +64,19 @@
 		}
 }
 
+static void image_drag_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
+{
+	ImageWindow *imd = data;
+
+	if (imd->func_drag)
+		{
+		imd->func_drag(imd, event->button, event->time,
+				 event->x, event->y, event->state,
+				 event->x - pr->drag_last_x, event->y - pr->drag_last_y,
+				 imd->data_button);
+		}
+}
+
 static void image_scroll_notify_cb(PixbufRenderer *pr, gpointer data)
 {
 	ImageWindow *imd = data;
@@ -1103,6 +1116,14 @@
 	imd->data_button = data;
 }
 
+void image_set_drag_func(ImageWindow *imd,
+			   void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer),
+			   gpointer data)
+{
+	imd->func_drag = func;
+	imd->data_drag = data;
+}
+
 void image_set_scroll_func(ImageWindow *imd,
 			   void (*func)(ImageWindow *, GdkScrollDirection direction, guint32 time, gdouble x, gdouble y, guint state, gpointer),
 			   gpointer data)
@@ -1836,6 +1857,8 @@
 			 G_CALLBACK(image_zoom_cb), imd);
 	g_signal_connect(G_OBJECT(imd->pr), "render_complete",
 			 G_CALLBACK(image_render_complete_cb), imd);
+	g_signal_connect(G_OBJECT(imd->pr), "drag",
+			 G_CALLBACK(image_drag_cb), imd);
 
 	image_list = g_list_append(image_list, imd);
 
--- a/src/image.h	Fri Jun 29 15:16:46 2007 +0000
+++ b/src/image.h	Tue Jul 10 21:25:51 2007 +0000
@@ -25,6 +25,9 @@
 void image_set_button_func(ImageWindow *imd,
 	void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gpointer),
 	gpointer data);
+void image_set_drag_func(ImageWindow *imd,
+	void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer),
+	gpointer data);
 void image_set_scroll_func(ImageWindow *imd,
 	void (*func)(ImageWindow *, GdkScrollDirection direction, guint32 time, gdouble x, gdouble y, guint state, gpointer),
         gpointer data);
--- a/src/layout_image.c	Fri Jun 29 15:16:46 2007 +0000
+++ b/src/layout_image.c	Tue Jul 10 21:25:51 2007 +0000
@@ -1526,10 +1526,10 @@
 		}
 }
 
-static void layout_image_scroll_notify_cb(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data)
+static void layout_image_drag_cb(ImageWindow *imd, gint button, guint32 time,
+				 gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer data)
 {
 	gint i;
-	printf("scroll cb %d %d %d %d\n", x,y,width, height);
 	LayoutWindow *lw = data;
 
 
@@ -1554,6 +1554,7 @@
 				   gdouble x, gdouble y, guint state, gpointer data)
 {
 	LayoutWindow *lw = data;
+	GtkWidget *menu;
 	gint i = image_idx(lw, imd);
 	
 	if (i != -1)
@@ -1561,8 +1562,48 @@
 		printf("image activate %d\n", i);
 		layout_image_activate(lw, i);
 		}
+
+	switch (button)
+		{
+		case 3:
+			menu = layout_image_pop_menu(lw);
+			if (imd == lw->image)
+				{
+				g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
+				}
+			gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, time);
+			break;
+		default:
+			break;
+		}
+
 }
 
+static void layout_image_drag_inactive_cb(ImageWindow *imd, gint button, guint32 time,
+				 gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer data)
+{
+	LayoutWindow *lw = data;
+
+	gint i = image_idx(lw, imd);
+	
+	if (i != -1)
+		{
+		printf("image activate %d\n", i);
+		layout_image_activate(lw, i);
+		}
+
+
+	for (i=0; i < MAX_SPLIT_IMAGES; i++)
+		{
+		if (lw->split_images[i] && lw->split_images[i] != imd)
+//			if (lw->connect_zoom)
+//				image_sync_zoom_from_image(lw->split_images[i], imd);
+			if (lw->connect_scroll)
+				image_sync_scroll_from_image_absolute(lw->split_images[i], imd);
+		}
+}
+
+
 static void layout_image_set_buttons(LayoutWindow *lw)
 {
 	image_set_button_func(lw->image, layout_image_button_cb, lw);
@@ -1619,7 +1660,7 @@
 	if (!lw->split_images[i]) return;
 	image_set_update_func(lw->split_images[i], NULL, NULL);
 	layout_image_set_buttons_inactive(lw, i);
-	image_set_scroll_notify_func(lw->split_images[i], NULL, NULL);
+	image_set_drag_func(lw->image, layout_image_drag_inactive_cb, lw);
 
 	image_attach_window(lw->split_images[i], NULL, NULL, NULL, FALSE);
 	image_select(lw->split_images[i], FALSE);
@@ -1645,7 +1686,7 @@
 	
 	image_set_update_func(lw->image, layout_image_update_cb, lw);
 	layout_image_set_buttons(lw);
-	image_set_scroll_notify_func(lw->image, layout_image_scroll_notify_cb, lw);
+	image_set_drag_func(lw->image, layout_image_drag_cb, lw);
 
 	image_attach_window(lw->image, lw->window, NULL, "GQview", FALSE);
 
--- a/src/pixbuf-renderer.c	Fri Jun 29 15:16:46 2007 +0000
+++ b/src/pixbuf-renderer.c	Tue Jul 10 21:25:51 2007 +0000
@@ -136,6 +136,7 @@
 	SIGNAL_CLICKED,
 	SIGNAL_SCROLL_NOTIFY,
 	SIGNAL_RENDER_COMPLETE,
+	SIGNAL_DRAG,
 	SIGNAL_COUNT
 };
 
@@ -420,6 +421,16 @@
 			     NULL, NULL,
 			     g_cclosure_marshal_VOID__VOID,
 			     G_TYPE_NONE, 0);
+
+	signals[SIGNAL_DRAG] = 
+		g_signal_new("drag",
+			     G_OBJECT_CLASS_TYPE(gobject_class),
+			     G_SIGNAL_RUN_LAST,
+			     G_STRUCT_OFFSET(PixbufRendererClass, drag),
+			     NULL, NULL,
+			     g_cclosure_marshal_VOID__BOXED,
+			     G_TYPE_NONE, 1,
+			     GDK_TYPE_EVENT);
 }
 
 static void pixbuf_renderer_init(PixbufRenderer *pr)
@@ -2487,6 +2498,11 @@
 		}
 }
 
+static void pr_drag_signal(PixbufRenderer *pr, GdkEventButton *bevent)
+{
+	g_signal_emit(pr, signals[SIGNAL_DRAG], 0, bevent);
+}
+
 /*
  *-------------------------------------------------------------------
  * sync and clamp
@@ -3000,6 +3016,8 @@
 	pixbuf_renderer_scroll(pr, (pr->drag_last_x - bevent->x) * accel,
 			       (pr->drag_last_y - bevent->y) * accel);
 
+	pr_drag_signal(pr, bevent);
+
 	pr->drag_last_x = bevent->x;
 	pr->drag_last_y = bevent->y;
 
--- a/src/pixbuf-renderer.h	Fri Jun 29 15:16:46 2007 +0000
+++ b/src/pixbuf-renderer.h	Tue Jul 10 21:25:51 2007 +0000
@@ -141,6 +141,7 @@
 	void (* scroll_notify)	(PixbufRenderer *pr);
 
 	void (* render_complete)(PixbufRenderer *pr);
+	void (* drag)		(PixbufRenderer *pr, GdkEventButton *event);
 };
 
 
--- a/src/typedefs.h	Fri Jun 29 15:16:46 2007 +0000
+++ b/src/typedefs.h	Tue Jul 10 21:25:51 2007 +0000
@@ -279,10 +279,13 @@
 	/* button, scroll functions */
 	void (*func_button)(ImageWindow *, gint button,
 			    guint32 time, gdouble x, gdouble y, guint state, gpointer);
+	void (*func_drag)(ImageWindow *, gint button,
+			    guint32 time, gdouble x, gdouble y, guint state, gdouble dx, gdouble dy,gpointer);
 	void (*func_scroll)(ImageWindow *, GdkScrollDirection direction,
 			    guint32 time, gdouble x, gdouble y, guint state, gpointer);
 
 	gpointer data_button;
+	gpointer data_drag;
 	gpointer data_scroll;
 
 	/* scroll notification (for scroll bar implementation) */