[Xfce4-commits] <ristretto:master> Add menu to the image-viewer widget.

Stephan Arts noreply at xfce.org
Sun Oct 2 13:48:02 CEST 2011


Updating branch refs/heads/master
         to fce79947f6e1430d12c891b3834f141e507fbc87 (commit)
       from 431cdf956c20f67fc9d16291bc5649f16e4dc9ec (commit)

commit fce79947f6e1430d12c891b3834f141e507fbc87
Author: Stephan Arts <stephan at xfce.org>
Date:   Sun Oct 2 13:46:58 2011 +0200

    Add menu to the image-viewer widget.

 src/image_viewer.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/image_viewer.h |    5 ++++
 src/main_window.c  |    9 +++++-
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/src/image_viewer.c b/src/image_viewer.c
index a63126f..b8fef76 100644
--- a/src/image_viewer.c
+++ b/src/image_viewer.c
@@ -58,6 +58,8 @@ struct _RsttoImageViewerPriv
     RsttoImageViewerOrientation  orientation;
     gdouble                      quality;
 
+
+    GtkMenu                     *menu;
     /* */
     /***/
     gboolean                     revert_zoom_direction;
@@ -185,6 +187,9 @@ static gboolean
 rstto_button_release_event (
         GtkWidget *widget,
         GdkEventButton *event);
+static gboolean
+rstto_popup_menu (
+        GtkWidget *widget);
 
 static void
 cb_rstto_bgcolor_changed (
@@ -313,6 +318,7 @@ rstto_image_viewer_class_init(RsttoImageViewerClass *viewer_class)
     widget_class->button_press_event = rstto_button_press_event;
     widget_class->button_release_event = rstto_button_release_event;
     widget_class->motion_notify_event = rstto_motion_notify_event;
+    widget_class->popup_menu = rstto_popup_menu;
 
     object_class->destroy = rstto_image_viewer_destroy;
 
@@ -1228,6 +1234,29 @@ rstto_image_viewer_get_orientation (RsttoImageViewer *viewer)
     return viewer->priv->orientation;
 }
 
+void
+rstto_image_viewer_set_menu (
+    RsttoImageViewer *viewer,
+    GtkMenu *menu)
+{
+    if (viewer->priv->menu)
+    {
+        gtk_menu_detach(viewer->priv->menu);
+        gtk_widget_destroy(GTK_WIDGET(viewer->priv->menu));
+    }
+
+    viewer->priv->menu = menu;
+
+    if (viewer->priv->menu)
+    {
+        gtk_menu_attach_to_widget(
+                viewer->priv->menu,
+                GTK_WIDGET(viewer),
+                NULL);
+    }
+
+}
+
 
 /************************/
 /** CALLBACK FUNCTIONS **/
@@ -2044,6 +2073,22 @@ rstto_button_press_event (
                 rstto_image_viewer_set_motion_state (viewer, RSTTO_IMAGE_VIEWER_MOTION_STATE_BOX_ZOOM);
             }
         }
+        return TRUE;
+    }
+    if(event->button == 3)
+    {
+        if (viewer->priv->menu)
+        {
+            gtk_widget_show_all(GTK_WIDGET(viewer->priv->menu));
+            gtk_menu_popup(viewer->priv->menu,
+                           NULL,
+                           NULL,
+                           NULL,
+                           NULL,
+                           3,
+                           event->time);
+        }
+        return TRUE;
     }
     return FALSE;
 }
@@ -2231,3 +2276,24 @@ cb_rstto_zoom_direction_changed (
     RsttoImageViewer *viewer = RSTTO_IMAGE_VIEWER (user_data);
     viewer->priv->revert_zoom_direction = rstto_settings_get_boolean_property (RSTTO_SETTINGS (settings), "revert-zoom-direction"); 
 }
+ 
+static gboolean
+rstto_popup_menu (
+        GtkWidget *widget)
+{
+    RsttoImageViewer *viewer = RSTTO_IMAGE_VIEWER (viewer);
+
+    if (viewer->priv->menu)
+    {
+        gtk_widget_show_all(GTK_WIDGET(viewer->priv->menu));
+        gtk_menu_popup(viewer->priv->menu,
+                       NULL,
+                       NULL,
+                       NULL,
+                       NULL,
+                       0,
+                       gtk_get_current_event_time());
+        return TRUE;
+    }
+    return FALSE;
+}
diff --git a/src/image_viewer.h b/src/image_viewer.h
index a7298b6..7a69094 100644
--- a/src/image_viewer.h
+++ b/src/image_viewer.h
@@ -103,6 +103,11 @@ rstto_image_viewer_set_orientation (
 RsttoImageViewerOrientation
 rstto_image_viewer_get_orientation (RsttoImageViewer *viewer);
 
+void
+rstto_image_viewer_set_menu (
+    RsttoImageViewer *viewer,
+    GtkMenu *menu);
+
 G_END_DECLS
 
 #endif /* __RISTRETTO_IMAGE_VIEWER_H__ */
diff --git a/src/main_window.c b/src/main_window.c
index 46bdaa2..5a32d26 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -529,8 +529,6 @@ rstto_main_window_init (RsttoMainWindow *window)
     window->priv->image_viewer_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/image-viewer-menu");
     window->priv->position_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/navigation-toolbar-menu");
 
-    
-    
     /**
      * Get the separator toolitem and tell it to expand
      */
@@ -552,6 +550,13 @@ rstto_main_window_init (RsttoMainWindow *window)
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window->priv->p_viewer_s_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
     gtk_container_add (GTK_CONTAINER (window->priv->p_viewer_s_window), window->priv->image_viewer);
 
+    rstto_image_viewer_set_menu (
+        RSTTO_IMAGE_VIEWER(window->priv->image_viewer),
+        GTK_MENU(window->priv->image_viewer_menu));
+
+    
+    
+
     //rstto_picture_viewer_set_menu (RSTTO_PICTURE_VIEWER (window->priv->picture_viewer), GTK_MENU(window->priv->image_viewer_menu));
     window->priv->thumbnailbar = rstto_thumbnail_bar_new (NULL);
 


More information about the Xfce4-commits mailing list