Commit b743e6a1 authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte
Browse files

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
parent c81c0241
......@@ -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;
}
/**
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment