[gtk+/wip/attachment-parameters-3: 21/27] gtkrecentchooserdefault: use gtk_menu_popup_with_parameters ()



commit 09c2baefd47370622672389b1ca91554cf255153
Author: William Hua <william hua canonical com>
Date:   Fri Sep 25 09:18:14 2015 -0400

    gtkrecentchooserdefault: use gtk_menu_popup_with_parameters ()

 gtk/gtkrecentchooserdefault.c |   73 +++++++++++++++--------------------------
 1 files changed, 27 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index f6b0b87..9827b6a 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -1729,61 +1729,42 @@ recent_view_menu_build (GtkRecentChooserDefault *impl)
   recent_view_menu_ensure_state (impl);
 }
 
-/* taken from gtkfilechooserdefault.c */
-static void
-popup_position_func (GtkMenu   *menu,
-                     gint      *x,
-                     gint      *y,
-                     gboolean  *push_in,
-                     gpointer  user_data)
-{
-  GtkAllocation allocation;
-  GtkWidget *widget = GTK_WIDGET (user_data);
-  GdkScreen *screen = gtk_widget_get_screen (widget);
-  GtkRequisition req;
-  gint monitor_num;
-  GdkRectangle monitor;
-
-  if (G_UNLIKELY (!gtk_widget_get_realized (widget)))
-    return;
-
-  gdk_window_get_origin (gtk_widget_get_window (widget),
-                         x, y);
-
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
-                                 &req, NULL);
-
-  gtk_widget_get_allocation (widget, &allocation);
-  *x += (allocation.width - req.width) / 2;
-  *y += (allocation.height - req.height) / 2;
-
-  monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
-  gtk_menu_set_monitor (menu, monitor_num);
-  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
-
-  *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
-  *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
-
-  *push_in = FALSE;
-}
-
-
 static void
 recent_view_menu_popup (GtkRecentChooserDefault *impl,
                        GdkEventButton          *event)
 {
+  GdkAttachmentParameters *parameters;
+
   recent_view_menu_build (impl);
   
   if (event)
-    gtk_menu_popup (GTK_MENU (impl->priv->recent_popup_menu),
-                   NULL, NULL, NULL, NULL,
-                   event->button, event->time);
+    gtk_menu_popup_with_parameters (GTK_MENU (impl->priv->recent_popup_menu),
+                                    NULL,
+                                    NULL,
+                                    NULL,
+                                    event->button,
+                                    event->time,
+                                    NULL);
   else
     {
-      gtk_menu_popup (GTK_MENU (impl->priv->recent_popup_menu),
-                     NULL, NULL,
-                     popup_position_func, impl->priv->recent_view,
-                     0, GDK_CURRENT_TIME);
+      parameters = gtk_menu_create_parameters (GTK_MENU (impl->priv->recent_popup_menu));
+
+      gdk_attachment_parameters_add_primary_options (parameters,
+                                                     GDK_ATTACH_AXIS_Y | GDK_ATTACH_RECT_MID | 
GDK_ATTACH_WINDOW_MID,
+                                                     NULL);
+
+      gdk_attachment_parameters_add_secondary_options (parameters,
+                                                       GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MID | 
GDK_ATTACH_WINDOW_MID,
+                                                       NULL);
+
+      gtk_menu_popup_with_parameters (GTK_MENU (impl->priv->recent_popup_menu),
+                                      NULL,
+                                      NULL,
+                                      impl->priv->recent_view,
+                                      0,
+                                      GDK_CURRENT_TIME,
+                                      parameters);
+
       gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->priv->recent_popup_menu),
                                   FALSE);
     }


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