[gtk+/wip/attachment-parameters-4: 9/20] gtklabel: use gtk_menu_popup_with_params ()



commit b41bbca2fa15145e04448248b607ef0f737fb38f
Author: William Hua <william hua canonical com>
Date:   Tue Sep 22 00:29:38 2015 -0400

    gtklabel: use gtk_menu_popup_with_params ()

 gtk/gtklabel.c |   76 +++++++++++++++++++++++--------------------------------
 1 files changed, 32 insertions(+), 44 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index af158e9..de79f45 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -6558,44 +6558,6 @@ popup_menu_detach (GtkWidget *attach_widget,
 }
 
 static void
-popup_position_func (GtkMenu   *menu,
-                     gint      *x,
-                     gint      *y,
-                     gboolean  *push_in,
-                     gpointer  user_data)
-{
-  GtkLabel *label;
-  GtkWidget *widget;
-  GtkAllocation allocation;
-  GtkRequisition req;
-  GdkScreen *screen;
-
-  label = GTK_LABEL (user_data);
-  widget = GTK_WIDGET (label);
-
-  g_return_if_fail (gtk_widget_get_realized (widget));
-
-  screen = gtk_widget_get_screen (widget);
-  gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
-
-  gtk_widget_get_allocation (widget, &allocation);
-
-  *x += allocation.x;
-  *y += allocation.y;
-
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
-                                 &req, NULL);
-
-  gtk_widget_get_allocation (widget, &allocation);
-
-  *x += allocation.width / 2;
-  *y += allocation.height;
-
-  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
-  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
-}
-
-static void
 open_link_activate_cb (GtkMenuItem *menuitem,
                        GtkLabel    *label)
 {
@@ -6634,6 +6596,7 @@ gtk_label_do_popup (GtkLabel       *label,
   GtkWidget *menu;
   gboolean have_selection;
   GtkLabelLink *link;
+  GdkAttachParams *params;
 
   if (!priv->select_info)
     return;
@@ -6705,14 +6668,39 @@ gtk_label_do_popup (GtkLabel       *label,
   g_signal_emit (label, signals[POPULATE_POPUP], 0, menu);
 
   if (event)
-    gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                    NULL, NULL,
-                    event->button, event->time);
+    gtk_menu_popup_with_params (GTK_MENU (menu),
+                                NULL,
+                                NULL,
+                                NULL,
+                                event->button,
+                                event->time,
+                                TRUE,
+                                GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+                                NULL);
   else
     {
-      gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                      popup_position_func, label,
-                      0, gtk_get_current_event_time ());
+      params = gtk_menu_create_params (GTK_MENU (menu));
+
+      gdk_attach_params_add_primary_rules (params,
+                                           GDK_ATTACH_AXIS_Y | GDK_ATTACH_RECT_MAX | GDK_ATTACH_WINDOW_MIN,
+                                           GDK_ATTACH_AXIS_Y | GDK_ATTACH_RECT_MIN | GDK_ATTACH_WINDOW_MAX,
+                                           NULL);
+
+      gdk_attach_params_add_secondary_rules (params,
+                                             GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MID | GDK_ATTACH_WINDOW_MIN,
+                                             GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MID | GDK_ATTACH_WINDOW_MAX,
+                                             NULL);
+
+      gtk_menu_popup_with_params (GTK_MENU (menu),
+                                  NULL,
+                                  NULL,
+                                  GTK_WIDGET (label),
+                                  0,
+                                  gtk_get_current_event_time (),
+                                  TRUE,
+                                  GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+                                  params);
+
       gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
     }
 }


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