[gthumb/ext] use common functions to handle basic viewer_page events



commit 7e73ab86a370d3ec936ec0bd8bd8571af0a74365
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Sep 24 18:16:33 2009 +0200

    use common functions to handle basic viewer_page events
    
    do not repeat the same event hadler for every viewer_page
    refocus the viewer after loading and image
    
    [bug #595575]

 extensions/file_viewer/gth-file-viewer-page.c   |   53 +++++++++++--------
 extensions/image_viewer/gth-image-viewer-page.c |   62 +++++++---------------
 gthumb/gth-browser.c                            |   64 +++++++++++++++++++++++
 gthumb/gth-browser.h                            |    6 ++
 gthumb/gth-image-viewer.c                       |    6 +-
 gthumb/gth-image-viewer.h                       |    2 +-
 gthumb/gth-viewer-page.c                        |    7 +++
 gthumb/gth-viewer-page.h                        |    2 +
 8 files changed, 134 insertions(+), 68 deletions(-)
---
diff --git a/extensions/file_viewer/gth-file-viewer-page.c b/extensions/file_viewer/gth-file-viewer-page.c
index 98df0f1..4439a8e 100644
--- a/extensions/file_viewer/gth-file-viewer-page.c
+++ b/extensions/file_viewer/gth-file-viewer-page.c
@@ -54,26 +54,16 @@ viewer_scroll_event_cb (GtkWidget 	     *widget,
 			GdkEventScroll       *event,
 			GthFileViewerPage   *self)
 {
-	if (event->direction == GDK_SCROLL_UP)
-		gth_browser_show_prev_image (self->priv->browser, FALSE, FALSE);
-	else if (event->direction == GDK_SCROLL_DOWN)
-		gth_browser_show_next_image (self->priv->browser, FALSE, FALSE);
-
-	return TRUE;
+	return gth_browser_viewer_scroll_event_cb (self->priv->browser, event);
 }
 
 
-static void
-thumb_loader_ready_cb (GthThumbLoader *il,
-		       GError         *error,
-		       gpointer        user_data)
+static gboolean
+viewer_key_press_cb (GtkWidget         *widget,
+		     GdkEventKey       *event,
+		     GthFileViewerPage *self)
 {
-	GthFileViewerPage *self = user_data;
-
-	if (error != NULL)
-		return;
-
-	gtk_image_set_from_pixbuf (GTK_IMAGE (self->priv->icon), gth_thumb_loader_get_pixbuf (self->priv->thumb_loader));
+	return gth_browser_viewer_key_press_cb (self->priv->browser, event);
 }
 
 
@@ -82,12 +72,18 @@ viewer_button_press_cb (GtkWidget         *widget,
 		        GdkEventButton    *event,
 		        GthFileViewerPage *self)
 {
-	if (event->button == 3) {
-		gth_browser_file_menu_popup (self->priv->browser, event);
-		return TRUE;
-	}
+	return gth_browser_viewer_button_press_cb (self->priv->browser, event);
+}
 
-	return FALSE;
+
+static void
+thumb_loader_ready_cb (GthThumbLoader    *il,
+		       GError            *error,
+		       GthFileViewerPage *self)
+{
+	if (error != NULL)
+		return;
+	gtk_image_set_from_pixbuf (GTK_IMAGE (self->priv->icon), gth_thumb_loader_get_pixbuf (self->priv->thumb_loader));
 }
 
 
@@ -133,6 +129,7 @@ gth_file_viewer_page_real_activate (GthViewerPage *base,
 	gtk_box_pack_start (GTK_BOX (vbox2), self->priv->icon, FALSE, FALSE, 0);
 
 	self->priv->label = gtk_label_new ("...");
+	gtk_label_set_selectable (GTK_LABEL (self->priv->label), TRUE);
 	gtk_widget_show (self->priv->label);
 	gtk_box_pack_start (GTK_BOX (vbox2), self->priv->label, FALSE, FALSE, 0);
 
@@ -144,9 +141,12 @@ gth_file_viewer_page_real_activate (GthViewerPage *base,
 			  "button_press_event",
 			  G_CALLBACK (viewer_button_press_cb),
 			  self);
+	g_signal_connect (G_OBJECT (self->priv->label),
+			  "key_press_event",
+			  G_CALLBACK (viewer_key_press_cb),
+			  self);
 
 	gth_browser_set_viewer_widget (browser, self->priv->viewer);
-	gtk_widget_grab_focus (self->priv->viewer);
 }
 
 
@@ -208,12 +208,20 @@ gth_file_viewer_page_real_view (GthViewerPage *base,
 	if (icon != NULL)
 		gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_DIALOG);
 
+	gth_viewer_page_focus (GTH_VIEWER_PAGE (self));
 	gth_thumb_loader_set_file (self->priv->thumb_loader, file_data);
 	gth_thumb_loader_load (self->priv->thumb_loader);
 }
 
 
 static void
+gth_file_viewer_page_real_focus (GthViewerPage *base)
+{
+	gtk_widget_grab_focus (GTH_FILE_VIEWER_PAGE (base)->priv->label);
+}
+
+
+static void
 gth_file_viewer_page_real_fullscreen (GthViewerPage *base,
 				      gboolean       active)
 {
@@ -274,6 +282,7 @@ gth_viewer_page_interface_init (GthViewerPageIface *iface)
 	iface->hide = gth_file_viewer_page_real_hide;
 	iface->can_view = gth_file_viewer_page_real_can_view;
 	iface->view = gth_file_viewer_page_real_view;
+	iface->focus = gth_file_viewer_page_real_focus;
 	iface->fullscreen = gth_file_viewer_page_real_fullscreen;
 	iface->show_pointer = gth_file_viewer_page_real_show_pointer;
 	iface->update_sensitivity = gth_file_viewer_page_real_update_sensitivity;
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 5b5dbf0..73edb5e 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -219,26 +219,16 @@ image_button_press_cb (GtkWidget          *widget,
 		       GdkEventButton     *event,
 		       GthImageViewerPage *self)
 {
-	if (event->button == 3) {
-		gth_browser_file_menu_popup (self->priv->browser, event);
-		return TRUE;
-	}
-
-	return FALSE;
+	return gth_browser_viewer_button_press_cb (self->priv->browser, event);
 }
 
 
 static gboolean
-mouse_wheel_scrolled_cb (GtkWidget 	     *widget,
-  		   	 GdkScrollDirection   direction,
-			 GthImageViewerPage  *self)
+mouse_whell_scroll_cb (GtkWidget 	   *widget,
+		       GdkEventScroll      *event,
+		       GthImageViewerPage  *self)
 {
-	if (direction == GDK_SCROLL_UP)
-		gth_browser_show_prev_image (self->priv->browser, FALSE, FALSE);
-	else
-		gth_browser_show_next_image (self->priv->browser, FALSE, FALSE);
-
-	return TRUE;
+	return gth_browser_viewer_scroll_event_cb (self->priv->browser, event);
 }
 
 
@@ -247,31 +237,7 @@ viewer_key_press_cb (GtkWidget          *widget,
 		     GdkEventKey        *event,
 		     GthImageViewerPage *self)
 {
-	switch (gdk_keyval_to_lower (event->keyval)) {
-	case GDK_Page_Up:
-	case GDK_BackSpace:
-		gth_browser_show_prev_image (self->priv->browser, TRUE, FALSE);
-		return TRUE;
-
-	case GDK_Page_Down:
-	case GDK_space:
-		gth_browser_show_next_image (self->priv->browser, TRUE, FALSE);
-		return TRUE;
-
-	case GDK_Home:
-		gth_browser_show_first_image (self->priv->browser, TRUE, FALSE);
-		return TRUE;
-
-	case GDK_End:
-		gth_browser_show_last_image (self->priv->browser, TRUE, FALSE);
-		return TRUE;
-
-	case GDK_f:
-		gth_browser_fullscreen (self->priv->browser);
-		break;
-	}
-
-	return gth_hook_invoke_get ("gth-browser-file-list-key-press", self->priv->browser, event) != NULL;
+	return gth_browser_viewer_key_press_cb (self->priv->browser, event);
 }
 
 
@@ -300,6 +266,9 @@ image_preloader_requested_ready_cb (GthImagePreloader  *preloader,
 	if (image_loader == NULL)
 		return;
 
+	if (GTK_WIDGET_VISIBLE (self->priv->viewer))
+		gth_viewer_page_focus (GTH_VIEWER_PAGE (self));
+
 	gth_image_viewer_load_from_image_loader (GTH_IMAGE_VIEWER (self->priv->viewer), image_loader);
 }
 
@@ -450,7 +419,7 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
 				self);
 	g_signal_connect_after (G_OBJECT (self->priv->viewer),
 				"mouse_wheel_scroll",
-				G_CALLBACK (mouse_wheel_scrolled_cb),
+				G_CALLBACK (mouse_whell_scroll_cb),
 				self);
 	g_signal_connect (G_OBJECT (self->priv->viewer),
 			  "key_press_event",
@@ -461,6 +430,7 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
 	gtk_widget_show (self->priv->nav_window);
 
 	gth_browser_set_viewer_widget (browser, self->priv->nav_window);
+	gth_viewer_page_focus (GTH_VIEWER_PAGE (self));
 
 	/* gconf notifications */
 
@@ -547,7 +517,7 @@ gth_image_viewer_page_real_show (GthViewerPage *base)
 		g_error_free (error);
 	}
 
-	gtk_widget_grab_focus (self->priv->viewer);
+	gth_viewer_page_focus (GTH_VIEWER_PAGE (self));
 }
 
 
@@ -623,6 +593,13 @@ gth_image_viewer_page_real_view (GthViewerPage *base,
 
 
 static void
+gth_image_viewer_page_real_focus (GthViewerPage *base)
+{
+	gtk_widget_grab_focus (GTH_IMAGE_VIEWER_PAGE (base)->priv->viewer);
+}
+
+
+static void
 gth_image_viewer_page_real_fullscreen (GthViewerPage *base,
 				       gboolean       active)
 {
@@ -1088,6 +1065,7 @@ gth_viewer_page_interface_init (GthViewerPageIface *iface)
 	iface->hide = gth_image_viewer_page_real_hide;
 	iface->can_view = gth_image_viewer_page_real_can_view;
 	iface->view = gth_image_viewer_page_real_view;
+	iface->focus = gth_image_viewer_page_real_focus;
 	iface->fullscreen = gth_image_viewer_page_real_fullscreen;
 	iface->show_pointer = gth_image_viewer_page_real_show_pointer;
 	iface->update_sensitivity = gth_image_viewer_page_real_update_sensitivity;
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 9db6f30..7d1cf91 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -3949,6 +3949,70 @@ gth_browser_get_list_extra_widget (GthBrowser *browser)
 }
 
 
+gboolean
+gth_browser_viewer_button_press_cb (GthBrowser     *browser,
+				    GdkEventButton *event)
+{
+	if (event->button == 3) {
+		gth_browser_file_menu_popup (browser, event);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+
+gboolean
+gth_browser_viewer_scroll_event_cb (GthBrowser     *browser,
+				    GdkEventScroll *event)
+{
+	if (event->state & GDK_SHIFT_MASK)
+		return FALSE;
+
+	if (event->state & GDK_CONTROL_MASK)
+		return FALSE;
+
+	if (event->direction == GDK_SCROLL_UP)
+		gth_browser_show_prev_image (browser, FALSE, FALSE);
+	else
+		gth_browser_show_next_image (browser, FALSE, FALSE);
+
+	return TRUE;
+}
+
+
+gboolean
+gth_browser_viewer_key_press_cb (GthBrowser  *browser,
+				 GdkEventKey *event)
+{
+	switch (gdk_keyval_to_lower (event->keyval)) {
+	case GDK_Page_Up:
+	case GDK_BackSpace:
+		gth_browser_show_prev_image (browser, FALSE, FALSE);
+		return TRUE;
+
+	case GDK_Page_Down:
+	case GDK_space:
+		gth_browser_show_next_image (browser, FALSE, FALSE);
+		return TRUE;
+
+	case GDK_Home:
+		gth_browser_show_first_image (browser, FALSE, FALSE);
+		return TRUE;
+
+	case GDK_End:
+		gth_browser_show_last_image (browser, FALSE, FALSE);
+		return TRUE;
+
+	case GDK_f:
+		gth_browser_fullscreen (browser);
+		break;
+	}
+
+	return gth_hook_invoke_get ("gth-browser-file-list-key-press", browser, event) != NULL;
+}
+
+
 void
 gth_browser_set_viewer_widget (GthBrowser *browser,
 			       GtkWidget  *widget)
diff --git a/gthumb/gth-browser.h b/gthumb/gth-browser.h
index 9e98e21..b4161e9 100644
--- a/gthumb/gth-browser.h
+++ b/gthumb/gth-browser.h
@@ -115,6 +115,12 @@ GtkWidget *      gth_browser_get_list_extra_widget  (GthBrowser       *browser);
 void             gth_browser_set_current_page       (GthBrowser       *browser,
 						     GthBrowserPage    page);
 GthBrowserPage 	 gth_browser_get_current_page       (GthBrowser       *browser);
+gboolean         gth_browser_viewer_button_press_cb (GthBrowser       *browser,
+						     GdkEventButton   *event);
+gboolean	 gth_browser_viewer_scroll_event_cb (GthBrowser       *browser,
+						     GdkEventScroll   *event);
+gboolean         gth_browser_viewer_key_press_cb    (GthBrowser       *browser,
+						     GdkEventKey      *event);
 void             gth_browser_set_viewer_widget      (GthBrowser       *browser,
 						     GtkWidget        *widget);
 GtkWidget *      gth_browser_get_viewer_widget      (GthBrowser       *browser);
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index b40ecb8..b1f0c4d 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -1170,8 +1170,8 @@ gth_image_viewer_scroll_event (GtkWidget      *widget,
 	if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN) {
 		g_signal_emit (G_OBJECT (viewer),
 			       gth_image_viewer_signals[MOUSE_WHEEL_SCROLL],
-				0,
-				event->direction);
+			       0,
+			       event);
 		return TRUE;
 	}
 
@@ -1464,7 +1464,7 @@ gth_image_viewer_class_init (GthImageViewerClass *class)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (GthImageViewerClass, mouse_wheel_scroll),
 			      NULL, NULL,
-			      g_cclosure_marshal_VOID__ENUM,
+			      g_cclosure_marshal_VOID__POINTER,
 			      G_TYPE_NONE,
 			      1,
 			      GDK_TYPE_SCROLL_DIRECTION);
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index 54b5d20..60477ec 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -136,7 +136,7 @@ struct _GthImageViewerClass
 					 GtkAdjustment      *vadj);
 	void (* repainted)              (GthImageViewer     *viewer);
 	void (* mouse_wheel_scroll)	(GthImageViewer     *viewer,
-	 				 GdkScrollDirection  direction);
+					 GdkEventScroll     *event);
 
 	/* -- Key binding signals -- */
 
diff --git a/gthumb/gth-viewer-page.c b/gthumb/gth-viewer-page.c
index 1e738e8..42adc12 100644
--- a/gthumb/gth-viewer-page.c
+++ b/gthumb/gth-viewer-page.c
@@ -93,6 +93,13 @@ gth_viewer_page_view (GthViewerPage *self,
 
 
 void
+gth_viewer_page_focus (GthViewerPage  *self)
+{
+	GTH_VIEWER_PAGE_GET_INTERFACE (self)->focus (self);
+}
+
+
+void
 gth_viewer_page_fullscreen (GthViewerPage *self,
 			    gboolean       active)
 {
diff --git a/gthumb/gth-viewer-page.h b/gthumb/gth-viewer-page.h
index 4e36e57..f6a9cc2 100644
--- a/gthumb/gth-viewer-page.h
+++ b/gthumb/gth-viewer-page.h
@@ -54,6 +54,7 @@ struct _GthViewerPageIface {
 				 	  GthFileData   *file_data);
 	void      (*view)                (GthViewerPage *self,
 				 	  GthFileData   *file_data);
+	void      (*focus)               (GthViewerPage *self);
 	void      (*fullscreen)          (GthViewerPage *self,
 					  gboolean       active);
 	void      (*show_pointer)        (GthViewerPage *self,
@@ -80,6 +81,7 @@ gboolean     gth_viewer_page_can_view            (GthViewerPage  *self,
 						  GthFileData    *file_data);
 void         gth_viewer_page_view                (GthViewerPage  *self,
 						  GthFileData    *file_data);
+void         gth_viewer_page_focus               (GthViewerPage  *self);
 void         gth_viewer_page_fullscreen          (GthViewerPage  *self,
 						  gboolean       active);
 void         gth_viewer_page_show_pointer        (GthViewerPage  *self,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]