[gtk+/wip/attach-params: 230/231] gtkmenuitem: set submenu_direction



commit ba99fe9b2fcec3235fcf2de9bbb3c040c9217269
Author: William Hua <william hua canonical com>
Date:   Thu Jan 14 16:59:46 2016 -0500

    gtkmenuitem: set submenu_direction

 gtk/gtkmenuitem.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 49 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index a953bd7..fa8000c 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -1923,6 +1923,45 @@ get_offsets (GtkMenu *menu,
 }
 
 static void
+gtk_menu_item_update_submenu_direction (GdkWindow             *window,
+                                        const GdkAttachParams *params,
+                                        gint                   x,
+                                        gint                   y,
+                                        gint                   offset_x,
+                                        gint                   offset_y,
+                                        GdkAttachRule          primary_rule,
+                                        GdkAttachRule          secondary_rule,
+                                        gpointer               user_data)
+{
+  GtkMenuItem *menu_item;
+  GtkMenuItemPrivate *priv;
+  GdkAttachRule horizontal_rule;
+
+  g_return_if_fail (GTK_IS_MENU_ITEM (user_data));
+
+  if ((primary_rule & GDK_ATTACH_AXIS_MASK) == GDK_ATTACH_AXIS_X)
+    horizontal_rule = primary_rule;
+  else if ((secondary_rule & GDK_ATTACH_AXIS_MASK) == GDK_ATTACH_AXIS_X)
+    horizontal_rule = secondary_rule;
+  else
+    return;
+
+  menu_item = user_data;
+  priv = menu_item->priv;
+
+  switch (horizontal_rule & GDK_ATTACH_WINDOW_MASK)
+    {
+    case GDK_ATTACH_WINDOW_MIN:
+      priv->submenu_direction = GTK_DIRECTION_RIGHT;
+      break;
+
+    case GDK_ATTACH_WINDOW_MAX:
+      priv->submenu_direction = GTK_DIRECTION_LEFT;
+      break;
+    }
+}
+
+static void
 gtk_menu_item_real_popup_submenu (GtkWidget *widget,
                                   gboolean   remember_exact_time)
 {
@@ -1971,9 +2010,9 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
           params = gtk_menu_create_params (GTK_MENU (priv->submenu));
 
           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-            menu_item->priv->submenu_direction = GTK_DIRECTION_LEFT;
+            priv->submenu_direction = GTK_DIRECTION_LEFT;
           else
-            menu_item->priv->submenu_direction = GTK_DIRECTION_RIGHT;
+            priv->submenu_direction = GTK_DIRECTION_RIGHT;
 
           if (GTK_IS_MENU (parent))
             {
@@ -1981,7 +2020,7 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
               parent_menu_item = GTK_MENU_ITEM (parent_menu->priv->parent_menu_item);
 
               if (parent_menu_item && !parent_menu->priv->torn_off)
-                menu_item->priv->submenu_direction = parent_menu_item->priv->submenu_direction;
+                priv->submenu_direction = parent_menu_item->priv->submenu_direction;
             }
 
           switch (priv->submenu_placement)
@@ -1992,7 +2031,7 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
                                                    GDK_ATTACH_AXIS_Y | GDK_ATTACH_RECT_MIN | 
GDK_ATTACH_WINDOW_MAX,
                                                    NULL);
 
-              if (menu_item->priv->submenu_direction == GTK_DIRECTION_LEFT)
+              if (priv->submenu_direction == GTK_DIRECTION_LEFT)
                 gdk_attach_params_add_secondary_rules (params,
                                                        GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MAX | 
GDK_ATTACH_WINDOW_MAX,
                                                        GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MIN | 
GDK_ATTACH_WINDOW_MIN,
@@ -2018,7 +2057,7 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
 
               gdk_attach_params_set_attach_margin (params, &attach_margin);
 
-              if (menu_item->priv->submenu_direction == GTK_DIRECTION_LEFT)
+              if (priv->submenu_direction == GTK_DIRECTION_LEFT)
                 gdk_attach_params_add_primary_rules (params,
                                                      GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MIN | 
GDK_ATTACH_WINDOW_MAX,
                                                      GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MAX | 
GDK_ATTACH_WINDOW_MIN,
@@ -2037,6 +2076,11 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget,
               break;
             }
 
+          gdk_attach_params_set_position_callback (params,
+                                                   gtk_menu_item_update_submenu_direction,
+                                                   g_object_ref (menu_item),
+                                                   g_object_unref);
+
           if (GTK_IS_MENU_BAR (parent))
             type_hint = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
 


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