[gtk+/wip/attach-params: 10/20] gtkentry: use gtk_menu_popup_with_params ()



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

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

 gtk/gtkentry.c |  103 +++++++++++++++++++++++++-------------------------------
 1 files changed, 46 insertions(+), 57 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index ca13c3f..4c62bff 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -9608,59 +9608,12 @@ popup_menu_detach (GtkWidget *attach_widget,
   priv_attach->popup_menu = NULL;
 }
 
-static void
-popup_position_func (GtkMenu   *menu,
-                     gint      *x,
-                     gint      *y,
-                     gboolean  *push_in,
-                     gpointer  user_data)
-{
-  GtkEntry *entry = GTK_ENTRY (user_data);
-  GtkEntryPrivate *priv = entry->priv;
-  GtkWidget *widget = GTK_WIDGET (entry);
-  GdkScreen *screen;
-  GtkRequisition menu_req;
-  GdkRectangle monitor;
-  gint monitor_num, strong_x, height;
- 
-  g_return_if_fail (gtk_widget_get_realized (widget));
-
-  gdk_window_get_origin (priv->text_area, x, y);
-
-  screen = gtk_widget_get_screen (widget);
-  monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
-  if (monitor_num < 0)
-    monitor_num = 0;
-  gtk_menu_set_monitor (menu, monitor_num);
-
-  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
-  gtk_widget_get_preferred_size (priv->popup_menu,
-                                 &menu_req, NULL);
-  height = gdk_window_get_height (priv->text_area);
-  gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
-
-  *x += 0 + strong_x - priv->scroll_offset;
-  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-    *x -= menu_req.width;
-
-  if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
-    *y += height;
-  else if ((*y - menu_req.height) >= monitor.y)
-    *y -= menu_req.height;
-  else if (monitor.y + monitor.height - (*y + height) > *y)
-    *y += height;
-  else
-    *y -= menu_req.height;
-
-  *push_in = FALSE;
-}
-
 typedef struct
 {
   GtkEntry *entry;
   guint button;
   guint time;
-  GdkDevice *device;
+  GdkSeat *seat;
 } PopupInfo;
 
 static void
@@ -9678,6 +9631,9 @@ popup_targets_received (GtkClipboard     *clipboard,
       gboolean clipboard_contains_text;
       GtkWidget *menu;
       GtkWidget *menuitem;
+      GdkAttachParams *params;
+      GdkRectangle rectangle;
+      gint strong_x;
 
       clipboard_contains_text = gtk_selection_data_targets_include_text (data);
       if (info_entry_priv->popup_menu)
@@ -9721,15 +9677,48 @@ popup_targets_received (GtkClipboard     *clipboard,
 
       g_signal_emit (entry, signals[POPULATE_POPUP], 0, menu);
 
-      if (info->device)
-       gtk_menu_popup_for_device (GTK_MENU (menu),
-                                   info->device, NULL, NULL, NULL, NULL, NULL,
-                                   info->button, info->time);
+      if (info->seat)
+        gtk_menu_popup_with_params (GTK_MENU (menu),
+                                    info->seat,
+                                    NULL,
+                                    NULL,
+                                    info->button,
+                                    info->time,
+                                    TRUE,
+                                    GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+                                    NULL);
       else
        {
-          gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                          popup_position_func, entry,
-                          0, gtk_get_current_event_time ());
+          params = gtk_menu_create_params (GTK_MENU (menu));
+
+          gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
+          rectangle.x = strong_x - info_entry_priv->scroll_offset;
+          rectangle.y = 0;
+          rectangle.width = 1;
+          rectangle.height = gdk_window_get_height (info_entry_priv->text_area);
+
+          gdk_attach_params_set_attach_rect (params, &rectangle, info_entry_priv->text_area);
+
+          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_MAX | 
GDK_ATTACH_WINDOW_MIN,
+                                                 GDK_ATTACH_AXIS_X | GDK_ATTACH_RECT_MIN | 
GDK_ATTACH_WINDOW_MAX,
+                                                 NULL);
+
+          gtk_menu_popup_with_params (GTK_MENU (menu),
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      0,
+                                      gtk_get_current_event_time (),
+                                      TRUE,
+                                      GDK_WINDOW_TYPE_HINT_POPUP_MENU,
+                                      params);
+
           gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
        }
     }
@@ -9754,13 +9743,13 @@ gtk_entry_do_popup (GtkEntry       *entry,
     {
       gdk_event_get_button (event, &info->button);
       info->time = gdk_event_get_time (event);
-      info->device = gdk_event_get_device (event);
+      info->seat = gdk_event_get_seat (event);
     }
   else
     {
       info->button = 0;
       info->time = gtk_get_current_event_time ();
-      info->device = NULL;
+      info->seat = NULL;
     }
 
   gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),


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