[gtk+/wip/attachment-parameters: 9/16] gtknotebook: use gtk_menu_popup_with_parameters ()



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

    gtknotebook: use gtk_menu_popup_with_parameters ()

 gtk/gtknotebook.c |   79 ++++++++++++++++++++++-------------------------------
 1 files changed, 33 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 8048dab..2e4dde4 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2918,8 +2918,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_parameters (GTK_MENU (priv->menu),
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      3,
+                                      event->time,
+                                      NULL);
+
       return TRUE;
     }
 
@@ -2962,58 +2968,39 @@ gtk_notebook_button_press (GtkWidget      *widget,
   return TRUE;
 }
 
-static void
-popup_position_func (GtkMenu  *menu,
-                     gint     *x,
-                     gint     *y,
-                     gboolean *push_in,
-                     gpointer  data)
+static gboolean
+gtk_notebook_popup_menu (GtkWidget *widget)
 {
-  GtkNotebook *notebook = data;
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
-  GtkAllocation allocation;
-  GtkWidget *w;
-  GtkRequisition requisition;
+  GdkAttachmentParameters *parameters;
 
-  if (priv->focus_tab)
+  if (priv->menu)
     {
-      GtkNotebookPage *page;
-
-      page = priv->focus_tab->data;
-      w = page->tab_label;
-    }
-  else
-   {
-     w = GTK_WIDGET (notebook);
-   }
+      parameters = gdk_attachment_parameters_new ();
 
-  gdk_window_get_origin (gtk_widget_get_window (w), x, y);
+      gtk_menu_update_parameters (GTK_MENU (priv->menu), parameters);
 
-  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;
+      gdk_attachment_parameters_add_primary_options (parameters,
+                                                     GDK_ATTACHMENT_ATTACH_BOTTOM_EDGE,
+                                                     GDK_ATTACHMENT_ATTACH_TOP_EDGE,
+                                                     GDK_ATTACHMENT_FORCE_FIRST_OPTION,
+                                                     NULL);
 
-  *y += allocation.y + allocation.height;
+      gdk_attachment_parameters_add_secondary_options (parameters,
+                                                       GDK_ATTACHMENT_ALIGN_BACKWARD_EDGES,
+                                                       GDK_ATTACHMENT_ALIGN_FORWARD_EDGES,
+                                                       GDK_ATTACHMENT_FORCE_FIRST_OPTION_IF_PRIMARY_FORCED,
+                                                       NULL);
 
-  *push_in = FALSE;
-}
-
-static gboolean
-gtk_notebook_popup_menu (GtkWidget *widget)
-{
-  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
-  GtkNotebookPrivate *priv = notebook->priv;
+      gtk_menu_popup_with_parameters (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 (),
+                                      parameters);
 
-  if (priv->menu)
-    {
-      gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
-                      popup_position_func, notebook,
-                      0, gtk_get_current_event_time ());
       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]