[evince] Remove gtk_menu_popup() calls



commit 6a6437ffe8232da63575c47fa9363bfa9c40b1f9
Author: Jason Crain <jcrain inspiresomeone us>
Date:   Wed Jan 15 14:48:47 2020 -0700

    Remove gtk_menu_popup() calls
    
    This function is deprecated since gtk version 3.22. Replace it with the
    gtk_menu_popup_at_* functions.
    
    This adds a function ev_gui_menu_popup_at_tree_view_selection() to
    replace the ev_gui_menu_position_tree_selection() function, which opens
    a popup menu at the currently selected row of a GtkTreeView.
    
    Issue #1023

 shell/ev-sidebar-bookmarks.c | 13 +++++++------
 shell/ev-sidebar-links.c     | 10 +++-------
 shell/ev-utils.c             | 41 +++++++++++++++++++++++++++++++++++++++++
 shell/ev-utils.h             |  2 ++
 4 files changed, 53 insertions(+), 13 deletions(-)
---
diff --git a/shell/ev-sidebar-bookmarks.c b/shell/ev-sidebar-bookmarks.c
index df55c904..9aac3262 100644
--- a/shell/ev-sidebar-bookmarks.c
+++ b/shell/ev-sidebar-bookmarks.c
@@ -354,12 +354,13 @@ ev_sidebar_bookmarks_popup_menu_show (EvSidebarBookmarks *sidebar_bookmarks,
         if (!priv->popup)
                 priv->popup = gtk_ui_manager_get_widget (priv->ui_manager, "/BookmarksPopup");
 
-        gtk_menu_popup (GTK_MENU (priv->popup),
-                        NULL, NULL,
-                        keyboard_mode ? ev_gui_menu_position_tree_selection : NULL,
-                        keyboard_mode ? tree_view : NULL,
-                        keyboard_mode ? 0 : 3,
-                        gtk_get_current_event_time ());
+        if (keyboard_mode) {
+                ev_gui_menu_popup_at_tree_view_selection (GTK_MENU (priv->popup),
+                                                          tree_view);
+        } else {
+                gtk_menu_popup_at_pointer (GTK_MENU (priv->popup), NULL);
+        }
+
         return TRUE;
 }
 
diff --git a/shell/ev-sidebar-links.c b/shell/ev-sidebar-links.c
index a35cc1eb..628e68c9 100644
--- a/shell/ev-sidebar-links.c
+++ b/shell/ev-sidebar-links.c
@@ -352,10 +352,7 @@ popup_menu_cb (GtkWidget *treeview, EvSidebarLinks *sidebar)
 {
        GtkMenu *menu = build_popup_menu (sidebar);
 
-       gtk_menu_popup (menu, NULL, NULL,
-                       ev_gui_menu_position_tree_selection,
-                       sidebar->priv->tree_view, 0,
-                       gtk_get_current_event_time ());
+       ev_gui_menu_popup_at_tree_view_selection (menu, GTK_TREE_VIEW (sidebar->priv->tree_view));
        gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
 }
 
@@ -374,9 +371,8 @@ button_press_cb (GtkWidget *treeview,
                                                   NULL, NULL, NULL)) {
                        gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview),
                                                  path, NULL, FALSE);
-                       gtk_menu_popup (build_popup_menu (sidebar), NULL,
-                                       NULL, NULL, NULL, event->button,
-                                       gtk_get_current_event_time ());
+                       gtk_menu_popup_at_pointer (build_popup_menu (sidebar),
+                                                  (GdkEvent *) event);
                        gtk_tree_path_free (path);
 
                        return TRUE;
diff --git a/shell/ev-utils.c b/shell/ev-utils.c
index 50d3906b..fd427387 100644
--- a/shell/ev-utils.c
+++ b/shell/ev-utils.c
@@ -297,6 +297,47 @@ ev_gui_menu_position_tree_selection (GtkMenu   *menu,
        ev_gui_sanitise_popup_position (menu, widget, x, y);
 }
 
+/**
+ * ev_gui_menu_popup_at_tree_view_selection:
+ * @menu: a #GtkMenu to show
+ * @tree_view: a #GtkTreeView
+ *
+ * Opens a popup menu positioned at the currently selected row of @tree_view.
+ */
+void
+ev_gui_menu_popup_at_tree_view_selection (GtkMenu     *menu,
+                                         GtkTreeView *tree_view)
+{
+       GtkTreeSelection *selection;
+       GList            *selected_rows;
+
+       selection = gtk_tree_view_get_selection (tree_view);
+       selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
+       if (selected_rows) {
+               GdkWindow     *window;
+               GdkRectangle   rect;
+               GtkAllocation  allocation;
+
+               window = gtk_widget_get_window (GTK_WIDGET (tree_view));
+               gtk_tree_view_get_cell_area (tree_view, selected_rows->data,
+                                            NULL, &rect);
+               gtk_tree_view_convert_bin_window_to_widget_coords (tree_view, 0, rect.y,
+                                                                  NULL, &rect.y);
+               gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
+               rect.width = allocation.width;
+               gtk_menu_popup_at_rect (menu, window, &rect,
+                                       GDK_GRAVITY_SOUTH_WEST,
+                                       GDK_GRAVITY_NORTH_WEST,
+                                       NULL);
+               g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free);
+       } else {
+               gtk_menu_popup_at_widget (menu, GTK_WIDGET (tree_view),
+                                         GDK_GRAVITY_CENTER,
+                                         GDK_GRAVITY_CENTER,
+                                         NULL);
+       }
+}
+
 static void
 file_filter_add_mime_types (GdkPixbufFormat *format, GtkFileFilter *filter,
                            GtkFileFilter   *supported_filter)
diff --git a/shell/ev-utils.h b/shell/ev-utils.h
index a58d3d7d..f9e3020f 100644
--- a/shell/ev-utils.h
+++ b/shell/ev-utils.h
@@ -36,6 +36,8 @@ void                  ev_gui_menu_position_tree_selection (GtkMenu   *menu,
                                                             gint      *y,
                                                             gboolean  *push_in,
                                                             gpointer   user_data);
+void                    ev_gui_menu_popup_at_tree_view_selection (GtkMenu     *menu,
+                                                                 GtkTreeView *tree_view);
 
 void                           file_chooser_dialog_add_writable_pixbuf_formats (GtkFileChooser *chooser);
 GdkPixbufFormat*       get_gdk_pixbuf_format_by_extension (const gchar *uri);


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