[gtk+/wip/attachment-parameters-4: 17/24] gtknotebook: use gtk_menu_popup_with_params ()



commit 8f179e2838701836aedf07c1ababcabfa12ff689
Author: William Hua <william hua canonical com>
Date:   Wed Sep 23 11:10:19 2015 -0400

    gtknotebook: use gtk_menu_popup_with_params ()

 gtk/gtknotebook.c |   75 ++++++++++++++++++++--------------------------------
 1 files changed, 29 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 0da495c..d2ee121 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2930,8 +2930,14 @@ 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,
+                                  NULL);
+
       return TRUE;
     }
 
@@ -2974,58 +2980,35 @@ 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_FLIP_IF_RTL,
+                                             GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MAX | GDK_ATTACH_WINDOW_MAX 
| GDK_ATTACH_FLIP_IF_RTL,
+                                             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 (),
+                                  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]