forked from AuroraMiddleware/gtk
testgtk: Drop snapshot
This needs to be redone with modern snapshotting infrastructure. Lets drop it for now, it is somewhat duplicative with inspector features.
This commit is contained in:
parent
98f31e61d7
commit
75024fea60
296
tests/testgtk.c
296
tests/testgtk.c
@ -6466,301 +6466,6 @@ create_progress_bar (GtkWidget *widget)
|
||||
gtk_widget_destroy (pdata->window);
|
||||
}
|
||||
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
gboolean found;
|
||||
gboolean first;
|
||||
GtkWidget *res_widget;
|
||||
} FindWidgetData;
|
||||
|
||||
static void
|
||||
find_widget (GtkWidget *widget, FindWidgetData *data)
|
||||
{
|
||||
GtkAllocation new_allocation;
|
||||
gint x_offset = 0;
|
||||
gint y_offset = 0;
|
||||
|
||||
gtk_widget_get_allocation (widget, &new_allocation);
|
||||
|
||||
if (data->found || !gtk_widget_get_mapped (widget))
|
||||
return;
|
||||
|
||||
/* Note that in the following code, we only count the
|
||||
* position as being inside a WINDOW widget if it is inside
|
||||
* widget->window; points that are outside of widget->window
|
||||
* but within the allocation are not counted. This is consistent
|
||||
* with the way we highlight drag targets.
|
||||
*/
|
||||
if (gtk_widget_get_has_surface (widget))
|
||||
{
|
||||
new_allocation.x = 0;
|
||||
new_allocation.y = 0;
|
||||
}
|
||||
|
||||
if (gtk_widget_get_parent (widget) && !data->first)
|
||||
{
|
||||
GdkSurface *window = gtk_widget_get_surface (widget);
|
||||
while (window != gtk_widget_get_surface (gtk_widget_get_parent (widget)))
|
||||
{
|
||||
gint tx, ty, twidth, theight;
|
||||
|
||||
twidth = gdk_surface_get_width (window);
|
||||
theight = gdk_surface_get_height (window);
|
||||
|
||||
if (new_allocation.x < 0)
|
||||
{
|
||||
new_allocation.width += new_allocation.x;
|
||||
new_allocation.x = 0;
|
||||
}
|
||||
if (new_allocation.y < 0)
|
||||
{
|
||||
new_allocation.height += new_allocation.y;
|
||||
new_allocation.y = 0;
|
||||
}
|
||||
if (new_allocation.x + new_allocation.width > twidth)
|
||||
new_allocation.width = twidth - new_allocation.x;
|
||||
if (new_allocation.y + new_allocation.height > theight)
|
||||
new_allocation.height = theight - new_allocation.y;
|
||||
|
||||
gdk_surface_get_position (window, &tx, &ty);
|
||||
new_allocation.x += tx;
|
||||
x_offset += tx;
|
||||
new_allocation.y += ty;
|
||||
y_offset += ty;
|
||||
|
||||
window = gdk_surface_get_parent (window);
|
||||
}
|
||||
}
|
||||
|
||||
if ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
|
||||
(data->x < new_allocation.x + new_allocation.width) &&
|
||||
(data->y < new_allocation.y + new_allocation.height))
|
||||
{
|
||||
/* First, check if the drag is in a valid drop site in
|
||||
* one of our children
|
||||
*/
|
||||
if (GTK_IS_CONTAINER (widget))
|
||||
{
|
||||
FindWidgetData new_data = *data;
|
||||
|
||||
new_data.x -= x_offset;
|
||||
new_data.y -= y_offset;
|
||||
new_data.found = FALSE;
|
||||
new_data.first = FALSE;
|
||||
|
||||
gtk_container_forall (GTK_CONTAINER (widget),
|
||||
(GtkCallback)find_widget,
|
||||
&new_data);
|
||||
|
||||
data->found = new_data.found;
|
||||
if (data->found)
|
||||
data->res_widget = new_data.res_widget;
|
||||
}
|
||||
|
||||
/* If not, and this widget is registered as a drop site, check to
|
||||
* emit "drag_motion" to check if we are actually in
|
||||
* a drop site.
|
||||
*/
|
||||
if (!data->found)
|
||||
{
|
||||
data->found = TRUE;
|
||||
data->res_widget = widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
find_widget_at_pointer (GdkDevice *device)
|
||||
{
|
||||
GtkWidget *widget = NULL;
|
||||
GdkSurface *pointer_window;
|
||||
gint x, y;
|
||||
FindWidgetData data;
|
||||
|
||||
pointer_window = gdk_device_get_surface_at_position (device, NULL, NULL);
|
||||
|
||||
if (pointer_window)
|
||||
{
|
||||
gpointer widget_ptr;
|
||||
|
||||
gdk_surface_get_user_data (pointer_window, &widget_ptr);
|
||||
widget = widget_ptr;
|
||||
}
|
||||
|
||||
if (widget)
|
||||
{
|
||||
gdk_surface_get_device_position (gtk_widget_get_surface (widget),
|
||||
device,
|
||||
&x, &y, NULL);
|
||||
|
||||
data.x = x;
|
||||
data.y = y;
|
||||
data.found = FALSE;
|
||||
data.first = TRUE;
|
||||
|
||||
find_widget (widget, &data);
|
||||
if (data.found)
|
||||
return data.res_widget;
|
||||
return widget;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct SnapshotData {
|
||||
GtkWidget *toplevel_button;
|
||||
GtkWidget **window;
|
||||
GdkCursor *cursor;
|
||||
gboolean in_query;
|
||||
gboolean is_toplevel;
|
||||
gint handler;
|
||||
};
|
||||
|
||||
static void
|
||||
destroy_snapshot_data (GtkWidget *widget,
|
||||
struct SnapshotData *data)
|
||||
{
|
||||
if (*data->window)
|
||||
*data->window = NULL;
|
||||
|
||||
if (data->cursor)
|
||||
{
|
||||
g_object_unref (data->cursor);
|
||||
data->cursor = NULL;
|
||||
}
|
||||
|
||||
if (data->handler)
|
||||
{
|
||||
g_signal_handler_disconnect (widget, data->handler);
|
||||
data->handler = 0;
|
||||
}
|
||||
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static gint
|
||||
snapshot_widget_event (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
struct SnapshotData *data)
|
||||
{
|
||||
GtkWidget *res_widget = NULL;
|
||||
|
||||
if (!data->in_query)
|
||||
return FALSE;
|
||||
|
||||
if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE)
|
||||
{
|
||||
gtk_grab_remove (widget);
|
||||
gdk_seat_ungrab (gdk_event_get_seat (event));
|
||||
|
||||
res_widget = find_widget_at_pointer (gdk_event_get_device (event));
|
||||
if (data->is_toplevel && res_widget)
|
||||
res_widget = gtk_widget_get_toplevel (res_widget);
|
||||
if (res_widget)
|
||||
{
|
||||
GtkWidget *window, *image;
|
||||
GdkPaintable *paintable;
|
||||
|
||||
paintable = gtk_widget_paintable_new (res_widget);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
image = gtk_image_new_from_paintable (paintable);
|
||||
g_object_unref (paintable);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (window), image);
|
||||
gtk_widget_show (window);
|
||||
}
|
||||
|
||||
data->in_query = FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
snapshot_widget (GtkButton *button,
|
||||
struct SnapshotData *data)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (button);
|
||||
GdkDevice *device;
|
||||
|
||||
device = gtk_get_current_event_device ();
|
||||
if (device == NULL)
|
||||
return;
|
||||
|
||||
data->is_toplevel = widget == data->toplevel_button;
|
||||
|
||||
if (!data->cursor)
|
||||
data->cursor = gdk_cursor_new_from_name ("crosshair", NULL);
|
||||
|
||||
gdk_seat_grab (gdk_device_get_seat (device),
|
||||
gtk_widget_get_surface (widget),
|
||||
GDK_SEAT_CAPABILITY_ALL_POINTING,
|
||||
TRUE, data->cursor, NULL, NULL, NULL);
|
||||
|
||||
g_signal_connect (button, "event",
|
||||
G_CALLBACK (snapshot_widget_event), data);
|
||||
|
||||
gtk_grab_add (widget);
|
||||
|
||||
data->in_query = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
create_snapshot (GtkWidget *widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
GtkWidget *button;
|
||||
GtkWidget *vbox;
|
||||
struct SnapshotData *data;
|
||||
|
||||
data = g_new (struct SnapshotData, 1);
|
||||
data->window = &window;
|
||||
data->in_query = FALSE;
|
||||
data->cursor = NULL;
|
||||
data->handler = 0;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
gtk_window_set_display (GTK_WINDOW (window),
|
||||
gtk_widget_get_display (widget));
|
||||
|
||||
data->handler = g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (destroy_snapshot_data),
|
||||
data);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (window), "test snapshot");
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
button = gtk_button_new_with_label ("Snapshot widget");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), button);
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (snapshot_widget),
|
||||
data);
|
||||
|
||||
button = gtk_button_new_with_label ("Snapshot toplevel");
|
||||
data->toplevel_button = button;
|
||||
gtk_box_pack_start (GTK_BOX (vbox), button);
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (snapshot_widget),
|
||||
data);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show (window);
|
||||
else
|
||||
gtk_widget_destroy (window);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Timeout Test
|
||||
*/
|
||||
@ -7437,7 +7142,6 @@ struct {
|
||||
{ "saved position", create_saved_position },
|
||||
{ "scrolled windows", create_scrolled_windows },
|
||||
{ "size groups", create_size_groups },
|
||||
{ "snapshot", create_snapshot },
|
||||
{ "spinbutton", create_spins },
|
||||
{ "statusbar", create_statusbar },
|
||||
{ "test mainloop", create_mainloop, TRUE },
|
||||
|
Loading…
Reference in New Issue
Block a user