diff options
author | Cody Russell <crussell@canonical.com> | 2009-12-18 13:43:11 +0100 |
---|---|---|
committer | Cody Russell <bratsche@gnome.org> | 2009-12-28 09:33:41 -0600 |
commit | 8a523393acf46d8e31f5ab0f8bd9a44b2450c6e7 (patch) | |
tree | fe5b12804e9cf2320b91841d88a70592ae915f61 /tests | |
parent | 74b8191f5589f4f3373ab11e5e9ea0a6606dfe02 (diff) | |
download | gtk+-8a523393acf46d8e31f5ab0f8bd9a44b2450c6e7.tar.gz |
GtkOffscreenWindow implementation for #604901
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/testoffscreenwindow.c | 92 |
2 files changed, 98 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index e9da96d697..b537f1a687 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -59,6 +59,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \ testnotebookdnd \ testnouiprint \ testoffscreen \ + testoffscreenwindow \ testorientable \ testprint \ testrgb \ @@ -141,6 +142,7 @@ testmultiscreen_DEPENDENCIES = $(TEST_DEPS) testnotebookdnd_DEPENDENCIES = $(TEST_DEPS) testnouiprint_DEPENDENCIES = $(TEST_DEPS) testoffscreen_DEPENDENCIES = $(TEST_DEPS) +testoffscreenwindow_DEPENDENCIES = $(TEST_DEPS) testorientable_DEPENDENCIES = $(TEST_DEPS) testprint_DEPENDENCIES = $(TEST_DEPS) testrecentchooser_DEPENDENCIES = $(TEST_DEPS) @@ -204,6 +206,7 @@ testmultiscreen_LDADD = $(LDADDS) testnotebookdnd_LDADD = $(LDADDS) testnouiprint_LDADD = $(LDADDS) testoffscreen_LDADD = $(LDADDS) +testoffscreenwindow_LDADD = $(LDADDS) testorientable_LDADD = $(LDADDS) testprint_LDADD = $(LDADDS) testrecentchooser_LDADD = $(LDADDS) @@ -340,6 +343,9 @@ testoffscreen_SOURCES = \ gtkoffscreenbox.h \ testoffscreen.c +testoffscreenwindnow_SOURCES = \ + testoffscreenwindow.c + testwindow_SOURCES = \ testwindows.c diff --git a/tests/testoffscreenwindow.c b/tests/testoffscreenwindow.c new file mode 100644 index 0000000000..a70e36b1ae --- /dev/null +++ b/tests/testoffscreenwindow.c @@ -0,0 +1,92 @@ +#include <gtk/gtk.h> + +static gboolean +da_expose (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) +{ + GtkOffscreenWindow *offscreen = (GtkOffscreenWindow *)user_data; + GdkPixmap *pixmap; + cairo_t *cr; + + if (GTK_WIDGET_DRAWABLE (widget)) + { + pixmap = gdk_offscreen_window_get_pixmap (GTK_WIDGET (offscreen)->window); + + cr = gdk_cairo_create (widget->window); + gdk_cairo_set_source_pixmap (cr, pixmap, 50, 50); + cairo_paint (cr); + cairo_destroy (cr); + } + + return FALSE; +} + +static gboolean +offscreen_damage (GtkWidget *widget, + GdkEventExpose *event, + GtkWidget *da) +{ + gtk_widget_queue_draw (da); + + return TRUE; +} + +static gboolean +da_button_press (GtkWidget *area, GdkEventButton *event, GtkWidget *button) +{ + gtk_widget_set_size_request (button, 150, 60); + return TRUE; +} + +int +main (int argc, char **argv) +{ + GtkWidget *window; + GtkWidget *button; + GtkWidget *offscreen; + GtkWidget *da; + + gtk_init (&argc, &argv); + + offscreen = gtk_offscreen_window_new (); + + button = gtk_button_new_with_label ("Test"); + gtk_widget_set_size_request (button, 50, 50); + gtk_container_add (GTK_CONTAINER (offscreen), button); + gtk_widget_show (button); + + gtk_widget_show (offscreen); + + /* Queue exposures and ensure they are handled so + * that the result is uptodate for the first + * expose of the window. If you want to get further + * changes, also track damage on the offscreen + * as done above. + */ + gtk_widget_draw (offscreen, NULL); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + da = gtk_drawing_area_new (); + gtk_container_add (GTK_CONTAINER (window), da); + + g_signal_connect (da, + "expose-event", + G_CALLBACK (da_expose), + offscreen); + + g_signal_connect (offscreen, + "damage-event", + G_CALLBACK (offscreen_damage), + da); + + gtk_widget_add_events (da, GDK_BUTTON_PRESS_MASK); + g_signal_connect (da, "button_press_event", G_CALLBACK (da_button_press), + button); + + gtk_widget_show_all (window); + + gtk_main(); + + return 0; +} |