[glade] Reworked glade_util_get_placeholder_from_pointer() to use gdk_device_get_window_at_position() to get



commit b743e6a14bb7abb28c428fa60c1b387f9d47e7bf
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Thu May 3 16:44:20 2012 -0300

    Reworked glade_util_get_placeholder_from_pointer() to use gdk_device_get_window_at_position()
    to get the placeholder window from the pointer.
    Use glade_util_get_placeholder_from_pointer() in paste action activate

 gladeui/glade-utils.c |   44 ++++++++++++++------------------------------
 src/glade-window.c    |    6 +++++-
 2 files changed, 19 insertions(+), 31 deletions(-)
---
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 1286cd0..fb00f9d 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -1114,40 +1114,24 @@ glade_util_search_devhelp (const gchar *book,
 GtkWidget *
 glade_util_get_placeholder_from_pointer (GtkContainer *container)
 {
-  GtkWidget *toplevel;
-  GtkWidget *retval = NULL, *child;
-  GtkAllocation allocation;
-  GList *c, *l;
-  gint x, y, x2, y2;
-
-  g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
-
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
-
-  gtk_widget_get_pointer (toplevel, &x, &y);
-
-  for (c = l = glade_util_container_get_all_children (container);
-       l; l = g_list_next (l))
+  GdkDeviceManager *manager;
+  GdkDisplay *display;
+  GdkDevice *device;
+  GdkWindow *window;
+
+  if (((display = gtk_widget_get_display (GTK_WIDGET (container))) || 
+       (display = gdk_display_get_default ())) &&
+      (manager = gdk_display_get_device_manager (display)) &&
+      (device = gdk_device_manager_get_client_pointer (manager)) &&
+      (window = gdk_device_get_window_at_position (device, NULL, NULL)))
     {
-      child = l->data;
-
-      if (GLADE_IS_PLACEHOLDER (child) && gtk_widget_get_mapped (child))
-        {
-          gtk_widget_translate_coordinates (toplevel, child, x, y, &x2, &y2);
+      gpointer widget;
+      gdk_window_get_user_data (window, &widget);
 
-          gtk_widget_get_allocation (child, &allocation);
-          if (x2 >= 0 && y2 >= 0 &&
-              x2 <= allocation.width && y2 <= allocation.height)
-            {
-              retval = child;
-              break;
-            }
-        }
+      return GLADE_IS_PLACEHOLDER (widget) ? GTK_WIDGET (widget) : NULL;
     }
 
-  g_list_free (c);
-
-  return retval;
+  return NULL;
 }
 
 /**
diff --git a/src/glade-window.c b/src/glade-window.c
index dca459a..e969b50 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -1502,7 +1502,11 @@ on_paste_action_activate (GtkAction *action, GladeWindow *window)
 
   project = glade_design_view_get_project (window->priv->active_view);
 
-  glade_project_command_paste (project, NULL);
+  /* If this action is activated with a key binging (ctrl-v) the widget will be 
+   * pasted over the placeholder below the default pointer.
+   */
+  glade_project_command_paste (project,
+                               glade_util_get_placeholder_from_pointer (GTK_CONTAINER (window)));
 }
 
 void



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