[glade/glade-3-12] Reworked glade_util_get_placeholder_from_pointer() to use gdk_device_get_window_at_position() to get



commit cfabe76ac60caef08e740921c6c680ecf4987c8e
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 373da38..bf9542e 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 368c007..80bdd7e 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -1550,7 +1550,11 @@ paste_cb (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)));
 }
 
 static void



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