[gtk+/wip/attachment-parameters: 10/20] gtkentry: use gtk_menu_popup_with_parameters ()



commit f8a4c7364caa85c6b2215abc63ea330064f36c1e
Author: William Hua <william hua canonical com>
Date:   Tue Sep 22 00:57:59 2015 -0400

    gtkentry: use gtk_menu_popup_with_parameters ()

 gtk/gtkentry.c |   99 +++++++++++++++++++++++++-------------------------------
 1 files changed, 44 insertions(+), 55 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index ea0bd61..b83d421 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -9550,55 +9550,6 @@ 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;
-  GtkBorder borders;
-  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);
-  _gtk_entry_get_borders (entry, &borders);
-
-  *x += borders.left + 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;
@@ -9622,6 +9573,10 @@ popup_targets_received (GtkClipboard     *clipboard,
       gboolean clipboard_contains_text;
       GtkWidget *menu;
       GtkWidget *menuitem;
+      GdkAttachmentParameters *parameters;
+      GdkRectangle rectangle;
+      GtkBorder border;
+      gint strong_x;
 
       clipboard_contains_text = gtk_selection_data_targets_include_text (data);
       if (info_entry_priv->popup_menu)
@@ -9666,14 +9621,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);
+        gtk_menu_popup_with_parameters (GTK_MENU (menu),
+                                        info->device,
+                                        NULL,
+                                        NULL,
+                                        info->button,
+                                        info->time,
+                                        NULL);
       else
        {
-          gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                          popup_position_func, entry,
-                          0, gtk_get_current_event_time ());
+          parameters = gdk_attachment_parameters_new ();
+
+          gtk_menu_update_parameters (GTK_MENU (menu), parameters);
+
+          _gtk_entry_get_borders (entry, &border);
+          gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
+          gdk_window_get_origin (info_entry_priv->text_area, &rectangle.x, &rectangle.y);
+          rectangle.x += border.left + strong_x - info_entry_priv->scroll_offset;
+          rectangle.width = 1;
+          rectangle.height = gdk_window_get_height (info_entry_priv->text_area);
+
+          gdk_attachment_parameters_set_attachment_rectangle (parameters, &rectangle);
+
+          gdk_attachment_parameters_add_primary_options (parameters,
+                                                         GDK_ATTACHMENT_ATTACH_BOTTOM_EDGE,
+                                                         GDK_ATTACHMENT_ATTACH_TOP_EDGE,
+                                                         GDK_ATTACHMENT_FORCE_FIRST_OPTION,
+                                                         NULL);
+
+          gdk_attachment_parameters_add_secondary_options (parameters,
+                                                           GDK_ATTACHMENT_ATTACH_FORWARD_EDGE,
+                                                           GDK_ATTACHMENT_ATTACH_BACKWARD_EDGE,
+                                                           
GDK_ATTACHMENT_FORCE_FIRST_OPTION_IF_PRIMARY_FORCED,
+                                                           NULL);
+
+          gtk_menu_popup_with_parameters (GTK_MENU (menu),
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          0,
+                                          gtk_get_current_event_time (),
+                                          parameters);
+
           gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
        }
     }


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