[gtk+/wip/attach-params: 9/20] gtklabel: use gtk_menu_popup_with_params ()



commit 4af876f43ffbd61931f8876086bebb8649377c92
Author: William Hua <william hua canonical com>
Date:   Wed Jan 20 02:20:20 2016 -0600

    gtklabel: use gtk_menu_popup_with_params ()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756579

 gtk/gtklabel.c |   69 ++++++++++++++++++++-----------------------------------
 1 files changed, 25 insertions(+), 44 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index a1bbb05..0dc7271 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -6547,44 +6547,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)
 {
@@ -6623,6 +6585,7 @@ gtk_label_do_popup (GtkLabel       *label,
   GtkWidget *menu;
   gboolean have_selection;
   GtkLabelLink *link;
+  GdkAttachParams *params;
 
   if (!priv->select_info)
     return;
@@ -6694,14 +6657,32 @@ 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_set_anchors (params, GDK_WINDOW_EDGE_SOUTH, GDK_WINDOW_EDGE_NORTH_WEST);
+      gdk_attach_params_set_flip_flags (params, FALSE, TRUE);
+
+      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]