[gtk+/wip/attach-params: 13/20] gtknotebook: use gtk_menu_popup_with_params ()



commit 9bc737e141035f1b70300fdb5047dc167f88da3d
Author: William Hua <william hua canonical com>
Date:   Wed Jan 6 12:00:00 2016 -0500

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

 gtk/gtknotebook.c |   79 ++++++++++++++++++++++-------------------------------
 1 files changed, 33 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 0da495c..ee9ef9e 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2930,8 +2930,16 @@ gtk_notebook_button_press (GtkWidget      *widget,
 
   if (priv->menu && gdk_event_triggers_context_menu ((GdkEvent *) event))
     {
-      gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
-                      NULL, NULL, 3, event->time);
+      gtk_menu_popup_with_params (GTK_MENU (priv->menu),
+                                  NULL,
+                                  NULL,
+                                  NULL,
+                                  3,
+                                  event->time,
+                                  TRUE,
+                                  GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+                                  NULL);
+
       return TRUE;
     }
 
@@ -2974,58 +2982,37 @@ gtk_notebook_button_press (GtkWidget      *widget,
   return TRUE;
 }
 
-static void
-popup_position_func (GtkMenu  *menu,
-                     gint     *x,
-                     gint     *y,
-                     gboolean *push_in,
-                     gpointer  data)
-{
-  GtkNotebook *notebook = data;
-  GtkNotebookPrivate *priv = notebook->priv;
-  GtkAllocation allocation;
-  GtkWidget *w;
-  GtkRequisition requisition;
-
-  if (priv->focus_tab)
-    {
-      GtkNotebookPage *page;
-
-      page = priv->focus_tab->data;
-      w = page->tab_label;
-    }
-  else
-   {
-     w = GTK_WIDGET (notebook);
-   }
-
-  gdk_window_get_origin (gtk_widget_get_window (w), x, y);
-
-  gtk_widget_get_allocation (w, &allocation);
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
-                                 &requisition, NULL);
-
-  if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
-    *x += allocation.x + allocation.width - requisition.width;
-  else
-    *x += allocation.x;
-
-  *y += allocation.y + allocation.height;
-
-  *push_in = FALSE;
-}
-
 static gboolean
 gtk_notebook_popup_menu (GtkWidget *widget)
 {
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
+  GdkAttachParams *params;
 
   if (priv->menu)
     {
-      gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
-                      popup_position_func, notebook,
-                      0, gtk_get_current_event_time ());
+      params = gtk_menu_create_params (GTK_MENU (priv->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_MIN | GDK_ATTACH_WINDOW_MIN,
+                                             GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MAX | GDK_ATTACH_WINDOW_MAX,
+                                             NULL);
+
+      gtk_menu_popup_with_params (GTK_MENU (priv->menu),
+                                  NULL,
+                                  NULL,
+                                  priv->focus_tab ? GTK_NOTEBOOK_PAGE (priv->focus_tab)->tab_label : 
GTK_WIDGET (notebook),
+                                  0,
+                                  gtk_get_current_event_time (),
+                                  TRUE,
+                                  GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+                                  params);
+
       gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
       return TRUE;
     }


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