[gtk: 1/3] tests: Stop using legacy gtk_menu_popup API



commit af21583d4d60edf9782cdd803b3854f5c4b2a967
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed Jul 25 16:39:53 2018 +0200

    tests: Stop using legacy gtk_menu_popup API
    
    Use the new portable APIs, so that menus will be positioned properly on
    all backends.

 tests/testiconview.c |  3 +--
 tests/testtoolbar.c  | 48 ++++++++++++++++--------------------------------
 2 files changed, 17 insertions(+), 34 deletions(-)
---
diff --git a/tests/testiconview.c b/tests/testiconview.c
index 7d52899301..b008dd1093 100644
--- a/tests/testiconview.c
+++ b/tests/testiconview.c
@@ -384,8 +384,7 @@ do_popup_menu (GtkWidget *icon_list,
       event_time = gtk_get_current_event_time ();
     }
 
-  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 
-                  button, event_time);
+  gtk_menu_popup_at_pointer (GTK_MENU (menu), event);
 }
        
 
diff --git a/tests/testtoolbar.c b/tests/testtoolbar.c
index 24d80b9d1e..c49b2cdb5f 100644
--- a/tests/testtoolbar.c
+++ b/tests/testtoolbar.c
@@ -320,34 +320,9 @@ rtl_toggled (GtkCheckButton *check)
     gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
 }
 
-typedef struct
-{
-  int x;
-  int y;
-} MenuPositionData;
-
-static void
-position_function (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data)
-{
-  /* Do not do this in your own code */
-
-  MenuPositionData *position_data = user_data;
-
-  if (x)
-    *x = position_data->x;
-
-  if (y)
-    *y = position_data->y;
-
-  if (push_in)
-    *push_in = FALSE;
-}
-
 static gboolean
 popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number)
 {
-  MenuPositionData position_data;
-  
   GtkMenu *menu = GTK_MENU (gtk_menu_new ());
   int i;
 
@@ -358,18 +333,27 @@ popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number)
       item = gtk_menu_item_new_with_mnemonic (label);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
     }
-  gtk_widget_show (GTK_WIDGET (menu));
 
   if (button_number != -1)
     {
-      position_data.x = x;
-      position_data.y = y;
-      
-      gtk_menu_popup (menu, NULL, NULL, position_function,
-                     &position_data, button_number, gtk_get_current_event_time());
+      gtk_menu_popup_at_pointer (menu, NULL);
     }
   else
-    gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
+    {
+      GtkWindow *window;
+      GtkWidget *widget;
+
+      window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (toolbar)));
+      widget = gtk_window_get_focus (window);
+      if (!widget)
+        widget = GTK_WIDGET (toolbar);
+
+      gtk_menu_popup_at_widget (menu,
+                                widget,
+                                GDK_GRAVITY_SOUTH_EAST,
+                                GDK_GRAVITY_NORTH_WEST,
+                                NULL);
+    }
 
   return TRUE;
 }


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