mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-06 00:30:08 +00:00
testgtk: Remove snapshot test
gtk_widget_get_snapshot is on its way out. The test can be added back once we have gtk_widget_draw(), but until then, there's no way to take snapshots.
This commit is contained in:
parent
8ac0e98f98
commit
99c82af20a
166
tests/testgtk.c
166
tests/testgtk.c
@ -9027,171 +9027,6 @@ create_properties (GtkWidget *widget)
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
gdk_cursor_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 (event->type == GDK_BUTTON_RELEASE)
|
||||
{
|
||||
gtk_grab_remove (widget);
|
||||
gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
|
||||
GDK_CURRENT_TIME);
|
||||
|
||||
res_widget = find_widget_at_pointer (gtk_widget_get_display (widget));
|
||||
if (data->is_toplevel && res_widget)
|
||||
res_widget = gtk_widget_get_toplevel (res_widget);
|
||||
if (res_widget)
|
||||
{
|
||||
GdkPixmap *pixmap;
|
||||
GtkWidget *window, *image;
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
pixmap = gtk_widget_get_snapshot (res_widget, NULL);
|
||||
gtk_widget_realize (window);
|
||||
if (gdk_drawable_get_depth (gtk_widget_get_window (window)) != gdk_drawable_get_depth (pixmap))
|
||||
{
|
||||
/* this branch is needed to convert ARGB -> RGB */
|
||||
int width, height;
|
||||
GdkPixbuf *pixbuf;
|
||||
gdk_drawable_get_size (pixmap, &width, &height);
|
||||
pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap,
|
||||
gtk_widget_get_colormap (res_widget),
|
||||
0, 0,
|
||||
0, 0,
|
||||
width, height);
|
||||
image = gtk_image_new_from_pixbuf (pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
}
|
||||
else
|
||||
image = gtk_image_new_from_pixmap (pixmap, NULL);
|
||||
gtk_container_add (GTK_CONTAINER (window), image);
|
||||
g_object_unref (pixmap);
|
||||
gtk_widget_show_all (window);
|
||||
}
|
||||
|
||||
data->in_query = FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
snapshot_widget (GtkButton *button,
|
||||
struct SnapshotData *data)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (button);
|
||||
gint failure;
|
||||
|
||||
g_signal_connect (button, "event",
|
||||
G_CALLBACK (snapshot_widget_event), data);
|
||||
|
||||
data->is_toplevel = widget == data->toplevel_button;
|
||||
|
||||
if (!data->cursor)
|
||||
data->cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
|
||||
GDK_TARGET);
|
||||
|
||||
failure = gdk_pointer_grab (gtk_widget_get_window (widget),
|
||||
TRUE,
|
||||
GDK_BUTTON_RELEASE_MASK,
|
||||
NULL,
|
||||
data->cursor,
|
||||
GDK_CURRENT_TIME);
|
||||
|
||||
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_screen (GTK_WINDOW (window),
|
||||
gtk_widget_get_screen (widget));
|
||||
|
||||
data->handler = g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (destroy_snapshot_data),
|
||||
data);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (window), "test snapshot");
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 1);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
button = gtk_button_new_with_label ("Snapshot widget");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
|
||||
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, TRUE, TRUE, 0);
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (snapshot_widget),
|
||||
data);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show_all (window);
|
||||
else
|
||||
gtk_widget_destroy (window);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Selection Test
|
||||
*/
|
||||
@ -10278,7 +10113,6 @@ struct {
|
||||
{ "scrolled windows", create_scrolled_windows },
|
||||
{ "shapes", create_shapes },
|
||||
{ "size groups", create_size_groups },
|
||||
{ "snapshot", create_snapshot },
|
||||
{ "spinbutton", create_spins },
|
||||
{ "statusbar", create_statusbar },
|
||||
{ "styles", create_styles },
|
||||
|
Loading…
Reference in New Issue
Block a user