summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am17
-rw-r--r--tests/flicker.c216
-rw-r--r--tests/gtkoffscreenbox.c660
-rw-r--r--tests/gtkoffscreenbox.h52
-rw-r--r--tests/testclientmessage.c244
-rw-r--r--tests/testoffscreen.c381
-rw-r--r--tests/testwindows.c1061
7 files changed, 2509 insertions, 122 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d5b07e7490..db686263af 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,6 +26,7 @@ endif
noinst_PROGRAMS = $(TEST_PROGS) \
simple \
+ flicker \
print-editor \
testaccel \
testassistant \
@@ -55,6 +56,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testmultiscreen \
testnotebookdnd \
testnouiprint \
+ testoffscreen \
testorientable \
testprint \
testrgb \
@@ -79,6 +81,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testtreesort \
treestoretest \
testxinerama \
+ testwindows \
pixbuf-read \
pixbuf-lowmem \
pixbuf-randomly-modified \
@@ -104,6 +107,7 @@ endif
endif
+flicker_DEPENDENCIES = $(TEST_DEPS)
simple_DEPENDENCIES = $(TEST_DEPS)
print_editor_DEPENDENCIES = $(TEST_DEPS)
testicontheme_DEPENDENCIES = $(TEST_DEPS)
@@ -134,6 +138,7 @@ testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
testmultiscreen_DEPENDENCIES = $(TEST_DEPS)
testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
testnouiprint_DEPENDENCIES = $(TEST_DEPS)
+testoffscreen_DEPENDENCIES = $(TEST_DEPS)
testorientable_DEPENDENCIES = $(TEST_DEPS)
testprint_DEPENDENCIES = $(TEST_DEPS)
testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
@@ -162,7 +167,9 @@ testactions_DEPENDENCIES = $(TEST_DEPS)
testgrouping_DEPENDENCIES = $(TEST_DEPS)
testtooltips_DEPENDENCIES = $(TEST_DEPS)
testvolumebutton_DEPENDENCIES = $(TEST_DEPS)
+testwindows_DEPENDENCIES = $(TEST_DEPS)
+flicker_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
print_editor_LDADD = $(LDADDS)
testaccel_LDADD = $(LDADDS)
@@ -193,6 +200,7 @@ testmultidisplay_LDADD = $(LDADDS)
testmultiscreen_LDADD = $(LDADDS)
testnotebookdnd_LDADD = $(LDADDS)
testnouiprint_LDADD = $(LDADDS)
+testoffscreen_LDADD = $(LDADDS)
testorientable_LDADD = $(LDADDS)
testprint_LDADD = $(LDADDS)
testrecentchooser_LDADD = $(LDADDS)
@@ -228,6 +236,7 @@ testactions_LDADD = $(LDADDS)
testgrouping_LDADD = $(LDADDS)
testtooltips_LDADD = $(LDADDS)
testvolumebutton_LDADD = $(LDADDS)
+testwindows_LDADD = $(LDADDS)
testentrycompletion_SOURCES = \
@@ -320,6 +329,14 @@ testrecentchoosermenu_SOURCES = \
testvolumebutton_SOURCES = \
testvolumebutton.c
+testoffscreen_SOURCES = \
+ gtkoffscreenbox.c \
+ gtkoffscreenbox.h \
+ testoffscreen.c
+
+testwindow_SOURCES = \
+ testwindows.c
+
EXTRA_DIST += \
prop-editor.h \
testgtk.1 \
diff --git a/tests/flicker.c b/tests/flicker.c
new file mode 100644
index 0000000000..39c9601c37
--- /dev/null
+++ b/tests/flicker.c
@@ -0,0 +1,216 @@
+#include <gtk/gtk.h>
+
+GtkWidget*
+create_flicker (void)
+{
+ GtkWidget *window1;
+ GtkWidget *hpaned1;
+ GtkWidget *vpaned2;
+ GtkWidget *hbox2;
+ GtkObject *spinbutton7_adj;
+ GtkWidget *spinbutton7;
+ GtkObject *spinbutton8_adj;
+ GtkWidget *spinbutton8;
+ GtkWidget *vbox1;
+ GtkObject *spinbutton9_adj;
+ GtkWidget *spinbutton9;
+ GtkObject *spinbutton10_adj;
+ GtkWidget *spinbutton10;
+ GtkObject *spinbutton11_adj;
+ GtkWidget *spinbutton11;
+ GtkObject *spinbutton12_adj;
+ GtkWidget *spinbutton12;
+ GtkObject *spinbutton13_adj;
+ GtkWidget *spinbutton13;
+ GtkObject *spinbutton14_adj;
+ GtkWidget *spinbutton14;
+ GtkObject *spinbutton15_adj;
+ GtkWidget *spinbutton15;
+ GtkObject *spinbutton16_adj;
+ GtkWidget *spinbutton16;
+ GtkWidget *vpaned1;
+ GtkWidget *hbox1;
+ GtkObject *spinbutton17_adj;
+ GtkWidget *spinbutton17;
+ GtkObject *spinbutton18_adj;
+ GtkWidget *spinbutton18;
+ GtkObject *spinbutton19_adj;
+ GtkWidget *spinbutton19;
+ GtkWidget *vbox2;
+ GtkObject *spinbutton20_adj;
+ GtkWidget *spinbutton20;
+ GtkObject *spinbutton21_adj;
+ GtkWidget *spinbutton21;
+ GtkObject *spinbutton22_adj;
+ GtkWidget *spinbutton22;
+ GtkObject *spinbutton23_adj;
+ GtkWidget *spinbutton23;
+ GtkObject *spinbutton24_adj;
+ GtkWidget *spinbutton24;
+ GtkObject *spinbutton25_adj;
+ GtkWidget *spinbutton25;
+ GtkObject *spinbutton26_adj;
+ GtkWidget *spinbutton26;
+ GtkObject *spinbutton27_adj;
+ GtkWidget *spinbutton27;
+
+ window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window1), 500, 400);
+ gtk_window_set_title (GTK_WINDOW (window1), "window1");
+
+ hpaned1 = gtk_hpaned_new ();
+ gtk_widget_show (hpaned1);
+ gtk_container_add (GTK_CONTAINER (window1), hpaned1);
+ gtk_paned_set_position (GTK_PANED (hpaned1), 100);
+
+ vpaned2 = gtk_vpaned_new ();
+ gtk_widget_show (vpaned2);
+ gtk_paned_pack1 (GTK_PANED (hpaned1), vpaned2, FALSE, TRUE);
+ gtk_paned_set_position (GTK_PANED (vpaned2), 100);
+
+ hbox2 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_show (hbox2);
+ gtk_paned_pack1 (GTK_PANED (vpaned2), hbox2, FALSE, TRUE);
+
+ spinbutton7_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton7 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton7_adj), 1, 0);
+ gtk_widget_show (spinbutton7);
+ gtk_box_pack_start (GTK_BOX (hbox2), spinbutton7, TRUE, TRUE, 0);
+
+ spinbutton8_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton8 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton8_adj), 1, 0);
+ gtk_widget_show (spinbutton8);
+ gtk_box_pack_start (GTK_BOX (hbox2), spinbutton8, TRUE, TRUE, 0);
+
+ vbox1 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (vbox1);
+ gtk_paned_pack2 (GTK_PANED (vpaned2), vbox1, TRUE, TRUE);
+
+ spinbutton9_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton9 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton9_adj), 1, 0);
+ gtk_widget_show (spinbutton9);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton9, FALSE, FALSE, 0);
+
+ spinbutton10_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton10 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton10_adj), 1, 0);
+ gtk_widget_show (spinbutton10);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton10, FALSE, FALSE, 0);
+
+ spinbutton11_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton11 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton11_adj), 1, 0);
+ gtk_widget_show (spinbutton11);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton11, FALSE, FALSE, 0);
+
+ spinbutton12_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton12 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton12_adj), 1, 0);
+ gtk_widget_show (spinbutton12);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton12, FALSE, FALSE, 0);
+
+ spinbutton13_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton13 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton13_adj), 1, 0);
+ gtk_widget_show (spinbutton13);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton13, FALSE, FALSE, 0);
+
+ spinbutton14_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton14 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton14_adj), 1, 0);
+ gtk_widget_show (spinbutton14);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton14, FALSE, FALSE, 0);
+
+ spinbutton15_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton15 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton15_adj), 1, 0);
+ gtk_widget_show (spinbutton15);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton15, FALSE, FALSE, 0);
+
+ spinbutton16_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton16 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton16_adj), 1, 0);
+ gtk_widget_show (spinbutton16);
+ gtk_box_pack_start (GTK_BOX (vbox1), spinbutton16, FALSE, FALSE, 0);
+
+ vpaned1 = gtk_vpaned_new ();
+ gtk_widget_show (vpaned1);
+ gtk_paned_pack2 (GTK_PANED (hpaned1), vpaned1, TRUE, TRUE);
+ gtk_paned_set_position (GTK_PANED (vpaned1), 0);
+
+ hbox1 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_show (hbox1);
+ gtk_paned_pack1 (GTK_PANED (vpaned1), hbox1, FALSE, TRUE);
+
+ spinbutton17_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton17 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton17_adj), 1, 0);
+ gtk_widget_show (spinbutton17);
+ gtk_box_pack_start (GTK_BOX (hbox1), spinbutton17, TRUE, TRUE, 0);
+
+ spinbutton18_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton18 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton18_adj), 1, 0);
+ gtk_widget_show (spinbutton18);
+ gtk_box_pack_start (GTK_BOX (hbox1), spinbutton18, TRUE, TRUE, 0);
+
+ spinbutton19_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton19 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton19_adj), 1, 0);
+ gtk_widget_show (spinbutton19);
+ gtk_box_pack_start (GTK_BOX (hbox1), spinbutton19, TRUE, TRUE, 0);
+
+ vbox2 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (vbox2);
+ gtk_paned_pack2 (GTK_PANED (vpaned1), vbox2, FALSE, FALSE);
+
+ spinbutton20_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton20 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton20_adj), 1, 0);
+ gtk_widget_show (spinbutton20);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton20, FALSE, FALSE, 0);
+
+ spinbutton21_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton21 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton21_adj), 1, 0);
+ gtk_widget_show (spinbutton21);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton21, FALSE, FALSE, 0);
+
+ spinbutton22_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton22 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton22_adj), 1, 0);
+ gtk_widget_show (spinbutton22);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton22, FALSE, FALSE, 0);
+
+ spinbutton23_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton23 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton23_adj), 1, 0);
+ gtk_widget_show (spinbutton23);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton23, FALSE, FALSE, 0);
+
+ spinbutton24_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton24 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton24_adj), 1, 0);
+ gtk_widget_show (spinbutton24);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton24, FALSE, FALSE, 0);
+
+ spinbutton25_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton25 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton25_adj), 1, 0);
+ gtk_widget_show (spinbutton25);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton25, FALSE, FALSE, 0);
+
+ spinbutton26_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton26 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton26_adj), 1, 0);
+ gtk_widget_show (spinbutton26);
+ gtk_box_pack_start (GTK_BOX (vbox2), spinbutton26, TRUE, FALSE, 0);
+
+ spinbutton27_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10);
+ spinbutton27 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton27_adj), 1, 0);
+ gtk_widget_show (spinbutton27);
+ gtk_box_pack_end (GTK_BOX (vbox2), spinbutton27, FALSE, FALSE, 0);
+
+
+ return window1;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window1;
+
+ gtk_set_locale ();
+ gtk_init (&argc, &argv);
+
+ window1 = create_flicker ();
+ gtk_widget_show (window1);
+
+ gtk_main ();
+ return 0;
+}
+
diff --git a/tests/gtkoffscreenbox.c b/tests/gtkoffscreenbox.c
new file mode 100644
index 0000000000..d781c438f9
--- /dev/null
+++ b/tests/gtkoffscreenbox.c
@@ -0,0 +1,660 @@
+/*
+ * gtkoffscreenbox.c
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <gtk/gtk.h>
+
+#include "gtkoffscreenbox.h"
+
+static void gtk_offscreen_box_realize (GtkWidget *widget);
+static void gtk_offscreen_box_unrealize (GtkWidget *widget);
+static void gtk_offscreen_box_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_offscreen_box_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gboolean gtk_offscreen_box_damage (GtkWidget *widget,
+ GdkEventExpose *event);
+static gboolean gtk_offscreen_box_expose (GtkWidget *widget,
+ GdkEventExpose *offscreen);
+
+static void gtk_offscreen_box_add (GtkContainer *container,
+ GtkWidget *child);
+static void gtk_offscreen_box_remove (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_offscreen_box_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data);
+static GType gtk_offscreen_box_child_type (GtkContainer *container);
+
+#define CHILD1_SIZE_SCALE 1.0
+#define CHILD2_SIZE_SCALE 1.0
+
+G_DEFINE_TYPE (GtkOffscreenBox, gtk_offscreen_box, GTK_TYPE_CONTAINER);
+
+static void
+to_child_2 (GtkOffscreenBox *offscreen_box,
+ double widget_x, double widget_y,
+ double *x_out, double *y_out)
+{
+ GtkAllocation child_area;
+ double x, y, xr, yr;
+ double cos_angle, sin_angle;
+
+ x = widget_x;
+ y = widget_y;
+
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ y -= offscreen_box->child1->allocation.height;
+
+ child_area = offscreen_box->child2->allocation;
+
+ x -= child_area.width / 2;
+ y -= child_area.height / 2;
+
+ cos_angle = cos (-offscreen_box->angle);
+ sin_angle = sin (-offscreen_box->angle);
+
+ xr = x * cos_angle - y * sin_angle;
+ yr = x * sin_angle + y * cos_angle;
+ x = xr;
+ y = yr;
+
+ x += child_area.width / 2;
+ y += child_area.height / 2;
+
+ *x_out = x;
+ *y_out = y;
+}
+
+static void
+to_parent_2 (GtkOffscreenBox *offscreen_box,
+ double offscreen_x, double offscreen_y,
+ double *x_out, double *y_out)
+{
+ GtkAllocation child_area;
+ double x, y, xr, yr;
+ double cos_angle, sin_angle;
+
+ child_area = offscreen_box->child2->allocation;
+
+ x = offscreen_x;
+ y = offscreen_y;
+
+ x -= child_area.width / 2;
+ y -= child_area.height / 2;
+
+ cos_angle = cos (offscreen_box->angle);
+ sin_angle = sin (offscreen_box->angle);
+
+ xr = x * cos_angle - y * sin_angle;
+ yr = x * sin_angle + y * cos_angle;
+ x = xr;
+ y = yr;
+
+ x += child_area.width / 2;
+ y += child_area.height / 2;
+
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ y += offscreen_box->child1->allocation.height;
+
+ *x_out = x;
+ *y_out = y;
+}
+
+static void
+gtk_offscreen_box_class_init (GtkOffscreenBoxClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+
+ widget_class->realize = gtk_offscreen_box_realize;
+ widget_class->unrealize = gtk_offscreen_box_unrealize;
+ widget_class->size_request = gtk_offscreen_box_size_request;
+ widget_class->size_allocate = gtk_offscreen_box_size_allocate;
+ widget_class->expose_event = gtk_offscreen_box_expose;
+
+ g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
+ GTK_TYPE_OFFSCREEN_BOX,
+ g_cclosure_new (G_CALLBACK (gtk_offscreen_box_damage),
+ NULL, NULL));
+
+ container_class->add = gtk_offscreen_box_add;
+ container_class->remove = gtk_offscreen_box_remove;
+ container_class->forall = gtk_offscreen_box_forall;
+ container_class->child_type = gtk_offscreen_box_child_type;
+}
+
+static void
+gtk_offscreen_box_init (GtkOffscreenBox *offscreen_box)
+{
+ GTK_WIDGET_UNSET_FLAGS (offscreen_box, GTK_NO_WINDOW);
+}
+
+GtkWidget *
+gtk_offscreen_box_new (void)
+{
+ return g_object_new (GTK_TYPE_OFFSCREEN_BOX, NULL);
+}
+
+static GdkWindow *
+get_offscreen_parent (GdkWindow *offscreen_window,
+ GtkOffscreenBox *offscreen_box)
+{
+ return GTK_WIDGET (offscreen_box)->window;
+}
+
+static GdkWindow *
+pick_offscreen_child (GdkWindow *offscreen_window,
+ double widget_x, double widget_y,
+ GtkOffscreenBox *offscreen_box)
+{
+ GtkAllocation child_area;
+ double x, y;
+
+ /* First check for child 2 */
+ if (offscreen_box->child2 &&
+ GTK_WIDGET_VISIBLE (offscreen_box->child2))
+ {
+ to_child_2 (offscreen_box,
+ widget_x, widget_y,
+ &x, &y);
+
+ child_area = offscreen_box->child2->allocation;
+
+ if (x >= 0 && x < child_area.width &&
+ y >= 0 && y < child_area.height)
+ return offscreen_box->offscreen_window2;
+ }
+
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ {
+ x = widget_x;
+ y = widget_y;
+
+ child_area = offscreen_box->child1->allocation;
+
+ if (x >= 0 && x < child_area.width &&
+ y >= 0 && y < child_area.height)
+ return offscreen_box->offscreen_window1;
+ }
+
+ return NULL;
+}
+
+static void
+offscreen_window_to_parent1 (GdkWindow *offscreen_window,
+ double offscreen_x,
+ double offscreen_y,
+ double *parent_x,
+ double *parent_y,
+ GtkOffscreenBox *offscreen_box)
+{
+ *parent_x = offscreen_x;
+ *parent_y = offscreen_y;
+}
+
+static void
+offscreen_window_from_parent1 (GdkWindow *window,
+ double parent_x,
+ double parent_y,
+ double *offscreen_x,
+ double *offscreen_y,
+ GtkOffscreenBox *offscreen_box)
+{
+ *offscreen_x = parent_x;
+ *offscreen_y = parent_y;
+}
+
+static void
+offscreen_window_to_parent2 (GdkWindow *offscreen_window,
+ double offscreen_x,
+ double offscreen_y,
+ double *parent_x,
+ double *parent_y,
+ GtkOffscreenBox *offscreen_box)
+{
+ to_parent_2 (offscreen_box,
+ offscreen_x, offscreen_y,
+ parent_x, parent_y);
+}
+
+static void
+offscreen_window_from_parent2 (GdkWindow *window,
+ double parent_x,
+ double parent_y,
+ double *offscreen_x,
+ double *offscreen_y,
+ GtkOffscreenBox *offscreen_box)
+{
+ to_child_2 (offscreen_box,
+ parent_x, parent_y,
+ offscreen_x, offscreen_y);
+}
+
+static void
+gtk_offscreen_box_realize (GtkWidget *widget)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ gint border_width;
+ GtkRequisition child_requisition;
+ int start_y = 0;
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+ border_width = GTK_CONTAINER (widget)->border_width;
+
+ attributes.x = widget->allocation.x + border_width;
+ attributes.y = widget->allocation.y + border_width;
+ attributes.width = widget->allocation.width - 2 * border_width;
+ attributes.height = widget->allocation.height - 2 * border_width;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.event_mask = gtk_widget_get_events (widget)
+ | GDK_EXPOSURE_MASK
+ | GDK_POINTER_MOTION_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_SCROLL_MASK
+ | GDK_ENTER_NOTIFY_MASK
+ | GDK_LEAVE_NOTIFY_MASK;
+
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.wclass = GDK_INPUT_OUTPUT;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+ widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (widget->window, widget);
+
+ gdk_window_set_has_offscreen_children (widget->window, TRUE);
+ g_signal_connect (widget->window, "pick-offscreen-child",
+ G_CALLBACK (pick_offscreen_child), offscreen_box);
+
+ attributes.window_type = GDK_WINDOW_OFFSCREEN;
+
+ /* Child 1 */
+ attributes.x = attributes.y = 0;
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ {
+ attributes.width = offscreen_box->child1->allocation.width;
+ attributes.height = offscreen_box->child1->allocation.height;
+ start_y += offscreen_box->child1->allocation.height;
+ }
+ offscreen_box->offscreen_window1 = gdk_window_new (gtk_widget_get_root_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (offscreen_box->offscreen_window1, widget);
+ if (offscreen_box->child1)
+ gtk_widget_set_parent_window (offscreen_box->child1, offscreen_box->offscreen_window1);
+
+ g_signal_connect (offscreen_box->offscreen_window1, "get-offscreen-parent",
+ G_CALLBACK (get_offscreen_parent), offscreen_box);
+ g_signal_connect (offscreen_box->offscreen_window1, "to_parent",
+ G_CALLBACK (offscreen_window_to_parent1), offscreen_box);
+ g_signal_connect (offscreen_box->offscreen_window1, "from_parent",
+ G_CALLBACK (offscreen_window_from_parent1), offscreen_box);
+
+ /* Child 2 */
+ attributes.y = start_y;
+ child_requisition.width = child_requisition.height = 0;
+ if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+ {
+ attributes.width = offscreen_box->child2->allocation.width;
+ attributes.height = offscreen_box->child2->allocation.height;
+ }
+ offscreen_box->offscreen_window2 = gdk_window_new (gtk_widget_get_root_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (offscreen_box->offscreen_window2, widget);
+ if (offscreen_box->child2)
+ gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2);
+ g_signal_connect (offscreen_box->offscreen_window2, "get-offscreen-parent",
+ G_CALLBACK (get_offscreen_parent), offscreen_box);
+ g_signal_connect (offscreen_box->offscreen_window2, "to_parent",
+ G_CALLBACK (offscreen_window_to_parent2), offscreen_box);
+ g_signal_connect (offscreen_box->offscreen_window2, "from_parent",
+ G_CALLBACK (offscreen_window_from_parent2), offscreen_box);
+
+ widget->style = gtk_style_attach (widget->style, widget->window);
+
+ gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+ gtk_style_set_background (widget->style, offscreen_box->offscreen_window1, GTK_STATE_NORMAL);
+ gtk_style_set_background (widget->style, offscreen_box->offscreen_window2, GTK_STATE_NORMAL);
+
+ gdk_window_show (offscreen_box->offscreen_window1);
+ gdk_window_show (offscreen_box->offscreen_window2);
+}
+
+static void
+gtk_offscreen_box_unrealize (GtkWidget *widget)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
+
+ gdk_window_set_user_data (offscreen_box->offscreen_window1, NULL);
+ gdk_window_destroy (offscreen_box->offscreen_window1);
+ offscreen_box->offscreen_window1 = NULL;
+
+ gdk_window_set_user_data (offscreen_box->offscreen_window2, NULL);
+ gdk_window_destroy (offscreen_box->offscreen_window2);
+ offscreen_box->offscreen_window2 = NULL;
+
+ GTK_WIDGET_CLASS (gtk_offscreen_box_parent_class)->unrealize (widget);
+}
+
+static GType
+gtk_offscreen_box_child_type (GtkContainer *container)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
+
+ if (offscreen_box->child1 && offscreen_box->child2)
+ return G_TYPE_NONE;
+
+ return GTK_TYPE_WIDGET;
+}
+
+static void
+gtk_offscreen_box_add (GtkContainer *container,
+ GtkWidget *widget)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
+
+ if (!offscreen_box->child1)
+ gtk_offscreen_box_add1 (offscreen_box, widget);
+ else if (!offscreen_box->child2)
+ gtk_offscreen_box_add2 (offscreen_box, widget);
+ else
+ g_warning ("GtkOffscreenBox cannot have more than 2 children\n");
+}
+
+void
+gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen_box,
+ GtkWidget *child)
+{
+ g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
+ g_return_if_fail (GTK_IS_WIDGET (child));
+
+ if (offscreen_box->child1 == NULL)
+ {
+ gtk_widget_set_parent_window (child, offscreen_box->offscreen_window1);
+ gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
+ offscreen_box->child1 = child;
+ }
+}
+
+void
+gtk_offscreen_box_add2 (GtkOffscreenBox *offscreen_box,
+ GtkWidget *child)
+{
+ g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
+ g_return_if_fail (GTK_IS_WIDGET (child));
+
+ if (offscreen_box->child2 == NULL)
+ {
+ gtk_widget_set_parent_window (child, offscreen_box->offscreen_window2);
+ gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
+ offscreen_box->child2 = child;
+ }
+}
+
+static void
+gtk_offscreen_box_remove (GtkContainer *container,
+ GtkWidget *widget)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
+ gboolean was_visible;
+
+ was_visible = GTK_WIDGET_VISIBLE (widget);
+
+ if (offscreen_box->child1 == widget)
+ {
+ gtk_widget_unparent (widget);
+
+ offscreen_box->child1 = NULL;
+
+ if (was_visible && GTK_WIDGET_VISIBLE (container))
+ gtk_widget_queue_resize (GTK_WIDGET (container));
+ }
+ else if (offscreen_box->child2 == widget)
+ {
+ gtk_widget_unparent (widget);
+
+ offscreen_box->child2 = NULL;
+
+ if (was_visible && GTK_WIDGET_VISIBLE (container))
+ gtk_widget_queue_resize (GTK_WIDGET (container));
+ }
+}
+
+static void
+gtk_offscreen_box_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
+
+ g_return_if_fail (callback != NULL);
+
+ if (offscreen_box->child1)
+ (*callback) (offscreen_box->child1, callback_data);
+ if (offscreen_box->child2)
+ (*callback) (offscreen_box->child2, callback_data);
+}
+
+void
+gtk_offscreen_box_set_angle (GtkOffscreenBox *offscreen_box,
+ gdouble angle)
+{
+ g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
+
+ offscreen_box->angle = angle;
+ gtk_widget_queue_draw (GTK_WIDGET (offscreen_box));
+
+ /* TODO: Really needs to resent pointer events if over the rotated window */
+}
+
+
+static void
+gtk_offscreen_box_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
+ int w, h;
+
+ w = 0;
+ h = 0;
+
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_size_request (offscreen_box->child1, &child_requisition);
+
+ w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
+ h += CHILD1_SIZE_SCALE * child_requisition.height;
+ }
+
+ if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_size_request (offscreen_box->child2, &child_requisition);
+
+ w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
+ h += CHILD2_SIZE_SCALE * child_requisition.height;
+ }
+
+ requisition->width = GTK_CONTAINER (widget)->border_width * 2 + w;
+ requisition->height = GTK_CONTAINER (widget)->border_width * 2 + h;
+}
+
+static void
+gtk_offscreen_box_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkOffscreenBox *offscreen_box;
+ gint border_width;
+ gint start_y;
+
+ widget->allocation = *allocation;
+ offscreen_box = GTK_OFFSCREEN_BOX (widget);
+
+ border_width = GTK_CONTAINER (widget)->border_width;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_window_move_resize (widget->window,
+ allocation->x + border_width,
+ allocation->y + border_width,
+ allocation->width - border_width * 2,
+ allocation->height - border_width * 2);
+
+ start_y = 0;
+
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ {
+ GtkRequisition child_requisition;
+ GtkAllocation child_allocation;
+
+ gtk_widget_get_child_requisition (offscreen_box->child1, &child_requisition);
+ child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
+ child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
+ child_allocation.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
+ child_allocation.height = child_requisition.height;
+
+ start_y += CHILD1_SIZE_SCALE * child_requisition.height;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_window_move_resize (offscreen_box->offscreen_window1,
+ child_allocation.x,
+ child_allocation.y,
+ child_allocation.width,
+ child_allocation.height);
+
+ child_allocation.x = child_allocation.y = 0;
+ gtk_widget_size_allocate (offscreen_box->child1, &child_allocation);
+ }
+
+ if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+ {
+ GtkRequisition child_requisition;
+ GtkAllocation child_allocation;
+
+ gtk_widget_get_child_requisition (offscreen_box->child2, &child_requisition);
+ child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
+ child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
+ child_allocation.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
+ child_allocation.height = child_requisition.height;
+
+ start_y += CHILD2_SIZE_SCALE * child_requisition.height;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_window_move_resize (offscreen_box->offscreen_window2,
+ child_allocation.x,
+ child_allocation.y,
+ child_allocation.width,
+ child_allocation.height);
+
+ child_allocation.x = child_allocation.y = 0;
+ gtk_widget_size_allocate (offscreen_box->child2, &child_allocation);
+ }
+}
+
+static gboolean
+gtk_offscreen_box_damage (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ gdk_window_invalidate_rect (widget->window, NULL, FALSE);
+
+ return TRUE;
+}
+
+static gboolean
+gtk_offscreen_box_expose (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
+
+ if (GTK_WIDGET_DRAWABLE (widget))
+ {
+ if (event->window == widget->window)
+ {
+ GdkPixmap *pixmap;
+ GtkAllocation child_area;
+ cairo_t *cr;
+ int start_y = 0;
+
+ if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+ {
+ pixmap = gdk_window_get_offscreen_pixmap (offscreen_box->offscreen_window1);
+ child_area = offscreen_box->child1->allocation;
+
+ cr = gdk_cairo_create (widget->window);
+
+ gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
+
+ start_y += child_area.height;
+ }
+
+ if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+ {
+ gint w, h;
+
+ pixmap = gdk_window_get_offscreen_pixmap (offscreen_box->offscreen_window2);
+ child_area = offscreen_box->child2->allocation;
+
+ cr = gdk_cairo_create (widget->window);
+
+ /* transform */
+ cairo_translate (cr, 0, start_y);
+ cairo_translate (cr, child_area.width / 2, child_area.height / 2);
+ cairo_rotate (cr, offscreen_box->angle);
+ cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
+
+ /* clip */
+ gdk_drawable_get_size (pixmap, &w, &h);
+ cairo_rectangle (cr, 0, 0, w, h);
+ cairo_clip (cr);
+
+ /* paint */
+ gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
+ }
+ }
+ else if (event->window == offscreen_box->offscreen_window1)
+ {
+ gtk_paint_flat_box (widget->style, event->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+ &event->area, widget, "blah",
+ 0, 0, -1, -1);
+
+ if (offscreen_box->child1)
+ gtk_container_propagate_expose (GTK_CONTAINER (widget),
+ offscreen_box->child1,
+ event);
+ }
+ else if (event->window == offscreen_box->offscreen_window2)
+ {
+ gtk_paint_flat_box (widget->style, event->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+ &event->area, widget, "blah",
+ 0, 0, -1, -1);
+
+ if (offscreen_box->child2)
+ gtk_container_propagate_expose (GTK_CONTAINER (widget),
+ offscreen_box->child2,
+ event);
+ }
+ }
+
+ return FALSE;
+}
diff --git a/tests/gtkoffscreenbox.h b/tests/gtkoffscreenbox.h
new file mode 100644
index 0000000000..aa1d15d775
--- /dev/null
+++ b/tests/gtkoffscreenbox.h
@@ -0,0 +1,52 @@
+#ifndef __GTK_OFFSCREEN_BOX_H__
+#define __GTK_OFFSCREEN_BOX_H__
+
+
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_OFFSCREEN_BOX (gtk_offscreen_box_get_type ())
+#define GTK_OFFSCREEN_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OFFSCREEN_BOX, GtkOffscreenBox))
+#define GTK_OFFSCREEN_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OFFSCREEN_BOX, GtkOffscreenBoxClass))
+#define GTK_IS_OFFSCREEN_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OFFSCREEN_BOX))
+#define GTK_IS_OFFSCREEN_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OFFSCREEN_BOX))
+#define GTK_OFFSCREEN_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_OFFSCREEN_BOX, GtkOffscreenBoxClass))
+
+typedef struct _GtkOffscreenBox GtkOffscreenBox;
+typedef struct _GtkOffscreenBoxClass GtkOffscreenBoxClass;
+
+struct _GtkOffscreenBox
+{
+ GtkContainer container;
+
+ GtkWidget *child1;
+ GtkWidget *child2;
+
+ GdkWindow *offscreen_window1;
+ GdkWindow *offscreen_window2;
+
+ gdouble angle;
+};
+
+struct _GtkOffscreenBoxClass
+{
+ GtkBinClass parent_class;
+};
+
+GType gtk_offscreen_box_get_type (void) G_GNUC_CONST;
+GtkWidget* gtk_offscreen_box_new (void);
+void gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen,
+ GtkWidget *child);
+void gtk_offscreen_box_add2 (GtkOffscreenBox *offscreen,
+ GtkWidget *child);
+void gtk_offscreen_box_set_angle (GtkOffscreenBox *offscreen,
+ double angle);
+
+
+
+G_END_DECLS
+
+#endif /* __GTK_OFFSCREEN_BOX_H__ */
diff --git a/tests/testclientmessage.c b/tests/testclientmessage.c
index 436e9e80d0..bd1a097108 100644
--- a/tests/testclientmessage.c
+++ b/tests/testclientmessage.c
@@ -1,122 +1,122 @@
-/* testclientmessage.c
- * Copyright (C) 2008 Novell, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include <gtk/gtk.h>
-
-static GdkAtom my_type;
-static GdkAtom random_type;
-
-static void
-send_known (void)
-{
- GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
- static int counter = 42;
- int i;
-
- event->client.window = NULL;
- event->client.message_type = my_type;
- event->client.data_format = 32;
- event->client.data.l[0] = counter++;
- for (i = 1; i < 5; i++)
- event->client.data.l[i] = 0;
-
- gdk_screen_broadcast_client_message (gdk_display_get_default_screen (gdk_display_get_default ()), event);
-
- gdk_event_free (event);
-}
-
-void
-send_random (void)
-{
- GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
- static int counter = 1;
- int i;
-
- event->client.window = NULL;
- event->client.message_type = random_type;
- event->client.data_format = 32;
- event->client.data.l[0] = counter++;
- for (i = 1; i < 5; i++)
- event->client.data.l[i] = 0;
-
- gdk_screen_broadcast_client_message (gdk_display_get_default_screen (gdk_display_get_default ()), event);
-
- gdk_event_free (event);
-}
-
-static GdkFilterReturn
-filter_func (GdkXEvent *xevent,
- GdkEvent *event,
- gpointer data)
-{
- g_print ("Got matching client message!\n");
- return GDK_FILTER_REMOVE;
-}
-
-int
-main (int argc, char **argv)
-{
- GtkWidget *window;
- GtkWidget *vbox;
- GtkWidget *button;
-
- gtk_init (&argc, &argv);
-
- my_type = gdk_atom_intern ("GtkTestClientMessage", FALSE);
- random_type = gdk_atom_intern (g_strdup_printf ("GtkTestClientMessage-%d",
- g_rand_int_range (g_rand_new (), 1, 99)),
- FALSE);
-
- g_print ("using random client message type %s\n", gdk_atom_name (random_type));
-
- window = g_object_connect (g_object_new (gtk_window_get_type (),
- "type", GTK_WINDOW_TOPLEVEL,
- "title", "testclientmessage",
- "border_width", 10,
- NULL),
- "signal::destroy", gtk_main_quit, NULL,
- NULL);
- vbox = g_object_new (gtk_vbox_get_type (),
- "GtkWidget::parent", window,
- "GtkWidget::visible", TRUE,
- NULL);
- button = g_object_connect (g_object_new (gtk_button_get_type (),
- "GtkButton::label", "send known client message",
- "GtkWidget::parent", vbox,
- "GtkWidget::visible", TRUE,
- NULL),
- "signal::clicked", send_known, NULL,
- NULL);
- button = g_object_connect (g_object_new (gtk_button_get_type (),
- "GtkButton::label", "send random client message",
- "GtkWidget::parent", vbox,
- "GtkWidget::visible", TRUE,
- NULL),
- "signal::clicked", send_random, NULL,
- NULL);
- gdk_display_add_client_message_filter (gdk_display_get_default (),
- my_type,
- filter_func,
- NULL);
- gtk_widget_show (window);
-
- gtk_main ();
-
- return 0;
-}
+/* testclientmessage.c
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+static GdkAtom my_type;
+static GdkAtom random_type;
+
+static void
+send_known (void)
+{
+ GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
+ static int counter = 42;
+ int i;
+
+ event->client.window = NULL;
+ event->client.message_type = my_type;
+ event->client.data_format = 32;
+ event->client.data.l[0] = counter++;
+ for (i = 1; i < 5; i++)
+ event->client.data.l[i] = 0;
+
+ gdk_screen_broadcast_client_message (gdk_display_get_default_screen (gdk_display_get_default ()), event);
+
+ gdk_event_free (event);
+}
+
+void
+send_random (void)
+{
+ GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
+ static int counter = 1;
+ int i;
+
+ event->client.window = NULL;
+ event->client.message_type = random_type;
+ event->client.data_format = 32;
+ event->client.data.l[0] = counter++;
+ for (i = 1; i < 5; i++)
+ event->client.data.l[i] = 0;
+
+ gdk_screen_broadcast_client_message (gdk_display_get_default_screen (gdk_display_get_default ()), event);
+
+ gdk_event_free (event);
+}
+
+static GdkFilterReturn
+filter_func (GdkXEvent *xevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ g_print ("Got matching client message!\n");
+ return GDK_FILTER_REMOVE;
+}
+
+int
+main (int argc, char **argv)
+{
+ GtkWidget *window;
+ GtkWidget *vbox;
+ GtkWidget *button;
+
+ gtk_init (&argc, &argv);
+
+ my_type = gdk_atom_intern ("GtkTestClientMessage", FALSE);
+ random_type = gdk_atom_intern (g_strdup_printf ("GtkTestClientMessage-%d",
+ g_rand_int_range (g_rand_new (), 1, 99)),
+ FALSE);
+
+ g_print ("using random client message type %s\n", gdk_atom_name (random_type));
+
+ window = g_object_connect (g_object_new (gtk_window_get_type (),
+ "type", GTK_WINDOW_TOPLEVEL,
+ "title", "testclientmessage",
+ "border_width", 10,
+ NULL),
+ "signal::destroy", gtk_main_quit, NULL,
+ NULL);
+ vbox = g_object_new (gtk_vbox_get_type (),
+ "GtkWidget::parent", window,
+ "GtkWidget::visible", TRUE,
+ NULL);
+ button = g_object_connect (g_object_new (gtk_button_get_type (),
+ "GtkButton::label", "send known client message",
+ "GtkWidget::parent", vbox,
+ "GtkWidget::visible", TRUE,
+ NULL),
+ "signal::clicked", send_known, NULL,
+ NULL);
+ button = g_object_connect (g_object_new (gtk_button_get_type (),
+ "GtkButton::label", "send random client message",
+ "GtkWidget::parent", vbox,
+ "GtkWidget::visible", TRUE,
+ NULL),
+ "signal::clicked", send_random, NULL,
+ NULL);
+ gdk_display_add_client_message_filter (gdk_display_get_default (),
+ my_type,
+ filter_func,
+ NULL);
+ gtk_widget_show (window);
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/tests/testoffscreen.c b/tests/testoffscreen.c
new file mode 100644
index 0000000000..f332d62c42
--- /dev/null
+++ b/tests/testoffscreen.c
@@ -0,0 +1,381 @@
+/*
+ * testoffscreen.c
+ */
+
+#undef GTK_DISABLE_DEPRECATED
+
+#include <math.h>
+#include <gtk/gtk.h>
+#include "gtkoffscreenbox.h"
+
+
+static void
+combo_changed_cb (GtkWidget *combo,
+ gpointer data)
+{
+ GtkWidget *label = GTK_WIDGET (data);
+ gint active;
+
+ active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+
+ gtk_label_set_ellipsize (GTK_LABEL (label), (PangoEllipsizeMode)active);
+}
+
+static gboolean
+layout_expose_handler (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ GtkLayout *layout = GTK_LAYOUT (widget);
+
+ gint i,j;
+ gint imin, imax, jmin, jmax;
+
+ if (event->window != layout->bin_window)
+ return FALSE;
+
+ imin = (event->area.x) / 10;
+ imax = (event->area.x + event->area.width + 9) / 10;
+
+ jmin = (event->area.y) / 10;
+ jmax = (event->area.y + event->area.height + 9) / 10;
+
+ for (i = imin; i < imax; i++)
+ for (j = jmin; j < jmax; j++)
+ if ((i + j) % 2)
+ gdk_draw_rectangle (layout->bin_window,
+ widget->style->black_gc,
+ TRUE,
+ 10 * i, 10 * j,
+ 1 + i % 10, 1 + j % 10);
+
+ return FALSE;
+}
+
+static gboolean
+scroll_layout (gpointer data)
+{
+ GtkWidget *layout = data;
+ GtkAdjustment *adj;
+
+ adj = gtk_layout_get_hadjustment (GTK_LAYOUT (layout));
+ gtk_adjustment_set_value (adj,
+ gtk_adjustment_get_value (adj) + 5.0);
+ return TRUE;
+}
+
+static guint layout_timeout;
+
+static void
+create_layout (GtkWidget *vbox)
+{
+ GtkWidget *layout;
+ GtkWidget *scrolledwindow;
+ GtkWidget *button;
+ gchar buf[16];
+ gint i, j;
+
+ scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
+ GTK_SHADOW_IN);
+ gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (scrolledwindow),
+ GTK_CORNER_TOP_RIGHT);
+
+ gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
+
+ layout = gtk_layout_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow), layout);
+
+ /* We set step sizes here since GtkLayout does not set
+ * them itself.
+ */
+ GTK_LAYOUT (layout)->hadjustment->step_increment = 10.0;
+ GTK_LAYOUT (layout)->vadjustment->step_increment = 10.0;
+
+ gtk_widget_set_events (layout, GDK_EXPOSURE_MASK);
+ g_signal_connect (layout, "expose_event",
+ G_CALLBACK (layout_expose_handler),
+ NULL);
+
+ gtk_layout_set_size (GTK_LAYOUT (layout), 1600, 128000);
+
+ for (i = 0 ; i < 16 ; i++)
+ for (j = 0 ; j < 16 ; j++)
+ {
+ g_snprintf (buf, sizeof (buf), "Button %d, %d", i, j);
+
+ if ((i + j) % 2)
+ button = gtk_button_new_with_label (buf);
+ else
+ button = gtk_label_new (buf);
+
+ gtk_layout_put (GTK_LAYOUT (layout), button,
+ j * 100, i * 100);
+ }
+
+ for (i = 16; i < 1280; i++)
+ {
+ g_snprintf (buf, sizeof (buf), "Button %d, %d", i, 0);
+
+ if (i % 2)
+ button = gtk_button_new_with_label (buf);
+ else
+ button = gtk_label_new (buf);
+
+ gtk_layout_put (GTK_LAYOUT (layout), button,
+ 0, i * 100);
+ }
+
+ layout_timeout = g_timeout_add (1000, scroll_layout, layout);
+}
+
+static void
+create_treeview (GtkWidget *vbox)
+{
+ GtkWidget *scrolledwindow;
+ GtkListStore *store;
+ GtkWidget *tree_view;
+ GSList *stock_ids;
+ GSList *list;
+
+ scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
+ GTK_SHADOW_IN);
+
+ gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
+
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+ tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ gtk_container_add (GTK_CONTAINER (scrolledwindow), tree_view);
+
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), -1,
+ "Icon",
+ gtk_cell_renderer_pixbuf_new (),
+ "stock-id", 0,
+ NULL);
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), -1,
+ "Label",
+ gtk_cell_renderer_text_new (),
+ "text", 1,
+ NULL);
+
+ stock_ids = gtk_stock_list_ids ();
+
+ for (list = stock_ids; list; list = g_slist_next (list))
+ {
+ const gchar *stock_id = list->data;
+ GtkStockItem item;
+
+ if (gtk_stock_lookup (stock_id, &item))
+ {
+ gtk_list_store_insert_with_values (store, NULL, -1,
+ 0, item.stock_id,
+ 1, item.label,
+ -1);
+ }
+ }
+
+ g_slist_foreach (stock_ids, (GFunc) g_free, NULL);
+ g_slist_free (stock_ids);
+}
+
+static GtkWidget *
+create_widgets (void)
+{
+ GtkWidget *main_hbox, *main_vbox;
+ GtkWidget *vbox, *hbox, *label, *combo, *entry, *button, *cb;
+ GtkWidget *sw, *text_view;
+ GList *cbitems = NULL;
+
+ main_vbox = gtk_vbox_new (0, FALSE);
+
+ main_hbox = gtk_hbox_new (0, FALSE);
+ gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, TRUE, 0);
+
+ vbox = gtk_vbox_new (0, FALSE);
+ gtk_box_pack_start (GTK_BOX (main_hbox), vbox, TRUE, TRUE, 0);
+
+ hbox = gtk_hbox_new (0, FALSE);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new ("This label may be ellipsized\nto make it fit.");
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ combo = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "NONE");
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "START");
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "MIDDLE");
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "END");
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+
+ g_signal_connect (combo, "changed",
+ G_CALLBACK (combo_changed_cb),
+ label);
+
+ entry = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (entry), "an entry - lots of text.... lots of text.... lots of text.... lots of text.... ");
+ gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
+ label = gtk_label_new ("Label after entry.");
+ gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+
+ button = gtk_button_new_with_label ("Button");
+ gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+
+ button = gtk_check_button_new_with_mnemonic ("_Check button");
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+ cb = gtk_combo_new ();
+ cbitems = g_list_append (cbitems, "item0");
+ cbitems = g_list_append (cbitems, "item1 item1");
+ cbitems = g_list_append (cbitems, "item2 item2 item2");
+ gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems);
+ gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (cb)->entry), "hello world ♥ foo");
+ gtk_editable_select_region (GTK_EDITABLE (GTK_COMBO (cb)->entry),
+ 0, -1);
+ gtk_box_pack_start (GTK_BOX (vbox), cb, TRUE, TRUE, 0);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ text_view = gtk_text_view_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (sw), text_view);
+
+ create_layout (vbox);
+
+ create_treeview (main_hbox);
+
+ return main_vbox;
+}
+
+
+static void
+scale_changed (GtkRange *range,
+ GtkOffscreenBox *offscreen_box)
+{
+ gtk_offscreen_box_set_angle (offscreen_box, gtk_range_get_value (range));
+}
+
+static GtkWidget *scale = NULL;
+
+static void
+remove_clicked (GtkButton *button,
+ GtkWidget *widget)
+{
+ gtk_widget_destroy (widget);
+ g_source_remove (layout_timeout);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+ gtk_widget_set_sensitive (scale, FALSE);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ GtkWidget *window, *widget, *vbox, *button;
+ GtkWidget *offscreen = NULL;
+ gboolean use_offscreen;
+
+ gtk_init (&argc, &argv);
+
+ use_offscreen = argc == 1;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 300,300);
+
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_main_quit),
+ NULL);
+
+ vbox = gtk_vbox_new (0, FALSE);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ scale = gtk_hscale_new_with_range (0,
+ M_PI * 2,
+ 0.01);
+ gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
+
+ button = gtk_button_new_with_label ("Remove child 2");
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+ if (use_offscreen)
+ {
+ offscreen = gtk_offscreen_box_new ();
+
+ g_signal_connect (scale, "value_changed",
+ G_CALLBACK (scale_changed),
+ offscreen);
+ }
+ else
+ {
+ offscreen = gtk_vpaned_new ();
+ }
+
+ gtk_box_pack_start (GTK_BOX (vbox), offscreen, TRUE, TRUE, 0);
+
+ widget = create_widgets ();
+ if (use_offscreen)
+ gtk_offscreen_box_add1 (GTK_OFFSCREEN_BOX (offscreen),
+ widget);
+ else
+ gtk_paned_add1 (GTK_PANED (offscreen), widget);
+
+ widget = create_widgets ();
+ if (1)
+ {
+ GtkWidget *widget2, *box2, *offscreen2;
+
+ offscreen2 = gtk_offscreen_box_new ();
+ gtk_box_pack_start (GTK_BOX (widget), offscreen2, FALSE, FALSE, 0);
+
+ g_signal_connect (scale, "value_changed",
+ G_CALLBACK (scale_changed),
+ offscreen2);
+
+ box2 = gtk_vbox_new (FALSE, 0);
+ gtk_offscreen_box_add2 (GTK_OFFSCREEN_BOX (offscreen2), box2);
+
+ widget2 = gtk_button_new_with_label ("Offscreen in offscreen");
+ gtk_box_pack_start (GTK_BOX (box2), widget2, FALSE, FALSE, 0);
+
+ widget2 = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (widget2), "Offscreen in offscreen");
+ gtk_box_pack_start (GTK_BOX (box2), widget2, FALSE, FALSE, 0);
+ }
+
+ if (use_offscreen)
+ gtk_offscreen_box_add2 (GTK_OFFSCREEN_BOX (offscreen), widget);
+ else
+ gtk_paned_add2 (GTK_PANED (offscreen), widget);
+
+ gtk_widget_show_all (window);
+
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (remove_clicked),
+ widget);
+
+ /* redirect */
+ if (0)
+ {
+ GtkWidget *redirect_win;
+
+ redirect_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (redirect_win), 400,400);
+ gtk_widget_show (redirect_win);
+ gtk_widget_realize (redirect_win);
+ gtk_widget_realize (window);
+ gdk_window_redirect_to_drawable (window->window,
+ GDK_DRAWABLE (redirect_win->window),
+ 0, 0, 0, 0, -1, -1);
+ }
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/tests/testwindows.c b/tests/testwindows.c
new file mode 100644
index 0000000000..ca8d8e5dec
--- /dev/null
+++ b/tests/testwindows.c
@@ -0,0 +1,1061 @@
+#include <gtk/gtk.h>
+#include <X11/Xlib.h>
+
+static GtkWidget *darea;
+static GtkTreeStore *window_store = NULL;
+static GtkWidget *treeview;
+
+static void update_store (void);
+
+static GtkWidget *main_window;
+
+static gboolean
+window_has_impl (GdkWindow *window)
+{
+ GdkWindowObject *w;
+ w = (GdkWindowObject *)window;
+ return w->parent == NULL || w->parent->impl != w->impl;
+}
+
+GdkWindow *
+create_window (GdkWindow *parent,
+ int x, int y, int w, int h,
+ GdkColor *color)
+{
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ GdkWindow *window;
+ GdkColor *bg;
+
+ attributes.x = x;
+ attributes.y = y;
+ attributes.width = w;
+ attributes.height = h;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.event_mask = GDK_STRUCTURE_MASK
+ | GDK_BUTTON_MOTION_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_EXPOSURE_MASK
+ | GDK_ENTER_NOTIFY_MASK
+ | GDK_LEAVE_NOTIFY_MASK;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
+
+ window = gdk_window_new (parent, &attributes, attributes_mask);
+ gdk_window_set_user_data (window, darea);
+
+ bg = g_new (GdkColor, 1);
+ if (color)
+ *bg = *color;
+ else
+ {
+ bg->red = g_random_int_range (0, 0xffff);
+ bg->blue = g_random_int_range (0, 0xffff);
+ bg->green = g_random_int_range (0, 0xffff);;
+ }
+
+ gdk_rgb_find_color (gtk_widget_get_colormap (darea), bg);
+ gdk_window_set_background (window, bg);
+ g_object_set_data_full (G_OBJECT (window), "color", bg, g_free);
+
+ gdk_window_show (window);
+
+ return window;
+}
+
+static void
+add_window_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GList **selected = data;
+ GdkWindow *window;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (window_store),
+ iter,
+ 0, &window,
+ -1);
+
+ *selected = g_list_prepend (*selected, window);
+}
+
+static GList *
+get_selected_windows (void)
+{
+ GtkTreeSelection *sel;
+ GList *selected;
+
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+
+ selected = NULL;
+ gtk_tree_selection_selected_foreach (sel, add_window_cb, &selected);
+
+ return selected;
+}
+
+static gboolean
+find_window_helper (GtkTreeModel *model,
+ GdkWindow *window,
+ GtkTreeIter *iter,
+ GtkTreeIter *selected_iter)
+{
+ GtkTreeIter child_iter;
+ GdkWindow *w;
+
+ do
+ {
+ gtk_tree_model_get (model, iter,
+ 0, &w,
+ -1);
+ if (w == window)
+ {
+ *selected_iter = *iter;
+ return TRUE;
+ }
+
+ if (gtk_tree_model_iter_children (model,
+ &child_iter,
+ iter))
+ {
+ if (find_window_helper (model, window, &child_iter, selected_iter))
+ return TRUE;
+ }
+ } while (gtk_tree_model_iter_next (model, iter));
+
+ return FALSE;
+}
+
+static gboolean
+find_window (GdkWindow *window,
+ GtkTreeIter *window_iter)
+{
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (window_store), &iter))
+ return FALSE;
+
+ return find_window_helper (GTK_TREE_MODEL (window_store),
+ window,
+ &iter,
+ window_iter);
+}
+
+static void
+toggle_selection_window (GdkWindow *window)
+{
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+
+ if (window != NULL &&
+ find_window (window, &iter))
+ {
+ if (gtk_tree_selection_iter_is_selected (selection, &iter))
+ gtk_tree_selection_unselect_iter (selection, &iter);
+ else
+ gtk_tree_selection_select_iter (selection, &iter);
+ }
+}
+
+static void
+unselect_windows (void)
+{
+ GtkTreeSelection *selection;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+
+ gtk_tree_selection_unselect_all (selection);
+}
+
+
+static void
+select_window (GdkWindow *window)
+{
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+
+ if (window != NULL &&
+ find_window (window, &iter))
+ gtk_tree_selection_select_iter (selection, &iter);
+}
+
+static void
+select_windows (GList *windows)
+{
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ GList *l;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ gtk_tree_selection_unselect_all (selection);
+
+ for (l = windows; l != NULL; l = l->next)
+ {
+ if (find_window (l->data, &iter))
+ gtk_tree_selection_select_iter (selection, &iter);
+ }
+}
+
+static void
+add_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GdkWindow *parent;
+ GList *l;
+
+ l = get_selected_windows ();
+ if (l != NULL)
+ parent = l->data;
+ else
+ parent = darea->window;
+
+ g_list_free (l);
+
+ create_window (parent, 10, 10, 100, 100, NULL);
+ update_store ();
+}
+
+static void
+draw_drawable_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GdkGC *gc;
+ gc = gdk_gc_new (darea->window);
+ gdk_draw_drawable (darea->window,
+ gc,
+ darea->window,
+ -15, -15,
+ 40, 70,
+ 100, 100);
+ g_object_unref (gc);
+}
+
+
+static void
+remove_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GList *l, *selected;
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ gdk_window_destroy (l->data);
+
+ g_list_free (selected);
+
+ update_store ();
+}
+
+static void save_children (GString *s, GdkWindow *window);
+
+static void
+save_window (GString *s,
+ GdkWindow *window)
+{
+ gint x, y, w, h;
+ GdkColor *color;
+
+ gdk_window_get_position (window, &x, &y);
+ gdk_drawable_get_size (GDK_DRAWABLE (window), &w, &h);
+ color = g_object_get_data (G_OBJECT (window), "color");
+
+ g_string_append_printf (s, "%d,%d %dx%d (%d,%d,%d) %d %d\n",
+ x, y, w, h,
+ color->red, color->green, color->blue,
+ window_has_impl (window),
+ g_list_length (gdk_window_peek_children (window)));
+
+ save_children (s, window);
+}
+
+
+static void
+save_children (GString *s,
+ GdkWindow *window)
+{
+ GList *l;
+ GdkWindow *child;
+
+ for (l = g_list_reverse (gdk_window_peek_children (window));
+ l != NULL;
+ l = l->next)
+ {
+ child = l->data;
+
+ save_window (s, child);
+ }
+}
+
+
+static void
+save_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GString *s;
+ GtkWidget *dialog;
+ GFile *file;
+
+ s = g_string_new ("");
+
+ save_children (s, darea->window);
+
+ dialog = gtk_file_chooser_dialog_new ("Filename for window data",
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+
+ g_file_replace_contents (file,
+ s->str, s->len,
+ NULL, FALSE,
+ 0, NULL, NULL, NULL);
+
+ g_object_unref (file);
+ }
+
+ gtk_widget_destroy (dialog);
+ g_string_free (s, TRUE);
+}
+
+static void
+destroy_children (GdkWindow *window)
+{
+ GList *l;
+ GdkWindow *child;
+
+ for (l = gdk_window_peek_children (window);
+ l != NULL;
+ l = l->next)
+ {
+ child = l->data;
+
+ destroy_children (child);
+ gdk_window_destroy (child);
+ }
+}
+
+static char **
+parse_window (GdkWindow *parent, char **lines)
+{
+ int x, y, w, h, r, g, b, native, n_children;
+ GdkWindow *window;
+ GdkColor color;
+ int i;
+
+ if (*lines == NULL)
+ return lines;
+
+ if (sscanf(*lines, "%d,%d %dx%d (%d,%d,%d) %d %d",
+ &x, &y, &w, &h, &r, &g, &b, &native, &n_children) == 9)
+ {
+ lines++;
+ color.red = r;
+ color.green = g;
+ color.blue = b;
+ window = create_window (parent, x, y, w, h, &color);
+ if (native)
+ gdk_window_ensure_native (window);
+
+ for (i = 0; i < n_children; i++)
+ lines = parse_window (window, lines);
+ }
+ else
+ lines++;
+
+ return lines;
+}
+
+static void
+load_file (GFile *file)
+{
+ char *data;
+ char **lines, **l;
+
+ if (g_file_load_contents (file, NULL, &data, NULL, NULL, NULL))
+ {
+ destroy_children (darea->window);
+
+ lines = g_strsplit (data, "\n", -1);
+
+ l = lines;
+ while (*l != NULL)
+ l = parse_window (darea->window, l);
+ }
+
+ update_store ();
+}
+
+static void
+move_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GdkWindow *window;
+ GtkDirectionType direction;
+ GList *selected, *l;
+ gint x, y;
+
+ direction = GPOINTER_TO_INT (data);
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_window_get_position (window, &x, &y);
+
+ switch (direction) {
+ case GTK_DIR_UP:
+ y -= 10;
+ break;
+ case GTK_DIR_DOWN:
+ y += 10;
+ break;
+ case GTK_DIR_LEFT:
+ x -= 10;
+ break;
+ case GTK_DIR_RIGHT:
+ x += 10;
+ break;
+ default:
+ break;
+ }
+
+ gdk_window_move (window, x, y);
+ }
+
+ g_list_free (selected);
+}
+
+static void
+manual_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GdkWindow *window;
+ GList *selected, *l;
+ int x, y, w, h;
+ GtkWidget *dialog, *table, *label, *xspin, *yspin, *wspin, *hspin;
+
+
+ selected = get_selected_windows ();
+
+ if (selected == NULL)
+ return;
+
+ gdk_window_get_position (selected->data, &x, &y);
+ gdk_drawable_get_size (selected->data, &w, &h);
+
+ dialog = gtk_dialog_new_with_buttons ("Select new position and size",
+ GTK_WINDOW (main_window),
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
+
+
+ table = gtk_table_new (2, 4, TRUE);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+ table,
+ FALSE, FALSE,
+ 2);
+
+
+ label = gtk_label_new ("x:");
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ label,
+ 0, 1,
+ 0, 1);
+ label = gtk_label_new ("y:");
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ label,
+ 0, 1,
+ 1, 2);
+ label = gtk_label_new ("width:");
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ label,
+ 0, 1,
+ 2, 3);
+ label = gtk_label_new ("height:");
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ label,
+ 0, 1,
+ 3, 4);
+
+ xspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (xspin), x);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ xspin,
+ 1, 2,
+ 0, 1);
+ yspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (yspin), y);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ yspin,
+ 1, 2,
+ 1, 2);
+ wspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (wspin), w);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ wspin,
+ 1, 2,
+ 2, 3);
+ hspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (hspin), h);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ hspin,
+ 1, 2,
+ 3, 4);
+
+ gtk_widget_show_all (dialog);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+
+ x = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (xspin));
+ y = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (yspin));
+ w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (wspin));
+ h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (hspin));
+
+ gtk_widget_destroy (dialog);
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_window_move_resize (window, x, y, w, h);
+ }
+
+ g_list_free (selected);
+}
+
+static void
+scroll_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GdkWindow *window;
+ GtkDirectionType direction;
+ GList *selected, *l;
+ gint dx, dy;
+
+ direction = GPOINTER_TO_INT (data);
+
+ selected = get_selected_windows ();
+
+ dx = 0; dy = 0;
+ switch (direction) {
+ case GTK_DIR_UP:
+ dy = 10;
+ break;
+ case GTK_DIR_DOWN:
+ dy = -10;
+ break;
+ case GTK_DIR_LEFT:
+ dx = 10;
+ break;
+ case GTK_DIR_RIGHT:
+ dx = -10;
+ break;
+ default:
+ break;
+ }
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_window_scroll (window, dx, dy);
+ }
+
+ g_list_free (selected);
+}
+
+
+static void
+raise_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GList *selected, *l;
+ GdkWindow *window;
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_window_raise (window);
+ }
+
+ g_list_free (selected);
+
+ update_store ();
+}
+
+static void
+lower_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GList *selected, *l;
+ GdkWindow *window;
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_window_lower (window);
+ }
+
+ g_list_free (selected);
+
+ update_store ();
+}
+
+
+static void
+smaller_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GList *selected, *l;
+ GdkWindow *window;
+ int w, h;
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_drawable_get_size (GDK_DRAWABLE (window), &w, &h);
+
+ w -= 10;
+ h -= 10;
+ if (w < 1)
+ w = 1;
+ if (h < 1)
+ h = 1;
+
+ gdk_window_resize (window, w, h);
+ }
+
+ g_list_free (selected);
+}
+
+static void
+larger_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GList *selected, *l;
+ GdkWindow *window;
+ int w, h;
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_drawable_get_size (GDK_DRAWABLE (window), &w, &h);
+
+ w += 10;
+ h += 10;
+
+ gdk_window_resize (window, w, h);
+ }
+
+ g_list_free (selected);
+}
+
+static void
+native_window_clicked (GtkWidget *button,
+ gpointer data)
+{
+ GList *selected, *l;
+ GdkWindow *window;
+
+ selected = get_selected_windows ();
+
+ for (l = selected; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ gdk_window_ensure_native (window);
+ }
+
+ g_list_free (selected);
+
+ update_store ();
+}
+
+static gboolean
+darea_button_release_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ toggle_selection_window (event->window);
+ }
+ else
+ {
+ unselect_windows ();
+ select_window (event->window);
+ }
+
+ return TRUE;
+}
+
+static void
+render_window_cell (GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GdkWindow *window;
+ char *name;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (window_store),
+ iter,
+ 0, &window,
+ -1);
+
+ if (window_has_impl (window))
+ name = g_strdup_printf ("%p (native)", window);
+ else
+ name = g_strdup_printf ("%p", window);
+ g_object_set (cell,
+ "text", name,
+ "background-gdk", &((GdkWindowObject *)window)->bg_color,
+ NULL);
+}
+
+static void
+add_children (GtkTreeStore *store,
+ GdkWindow *window,
+ GtkTreeIter *window_iter)
+{
+ GList *l;
+ GtkTreeIter child_iter;
+
+ for (l = gdk_window_peek_children (window);
+ l != NULL;
+ l = l->next)
+ {
+ gtk_tree_store_append (store, &child_iter, window_iter);
+ gtk_tree_store_set (store, &child_iter,
+ 0, l->data,
+ -1);
+
+ add_children (store, l->data, &child_iter);
+ }
+}
+
+static void
+update_store (void)
+{
+ GList *selected;
+
+ selected = get_selected_windows ();
+
+ gtk_tree_store_clear (window_store);
+
+ add_children (window_store, darea->window, NULL);
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (treeview));
+
+ select_windows (selected);
+ g_list_free (selected);
+}
+
+
+int
+main (int argc, char **argv)
+{
+ GtkWidget *window, *vbox, *hbox, *frame;
+ GtkWidget *button, *scrolled, *table;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+ GdkColor black = {0};
+ GFile *file;
+
+ gtk_init (&argc, &argv);
+
+ main_window = window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 0);
+
+ g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);
+
+ hbox = gtk_hbox_new (FALSE, 5);
+ gtk_container_add (GTK_CONTAINER (window), hbox);
+ gtk_widget_show (hbox);
+
+ frame = gtk_frame_new ("GdkWindows");
+ gtk_box_pack_start (GTK_BOX (hbox),
+ frame,
+ FALSE, FALSE,
+ 5);
+ gtk_widget_show (frame);
+
+ darea = gtk_drawing_area_new ();
+ /*gtk_widget_set_double_buffered (darea, FALSE);*/
+ gtk_widget_add_events (darea, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
+ gtk_widget_set_size_request (darea, 500, 500);
+ g_signal_connect (darea, "button_release_event",
+ G_CALLBACK (darea_button_release_event),
+ NULL);
+
+
+ gtk_container_add (GTK_CONTAINER (frame), darea);
+ gtk_widget_realize (darea);
+ gtk_widget_show (darea);
+ gtk_widget_modify_bg (darea, GTK_STATE_NORMAL,
+ &black);
+
+
+ vbox = gtk_vbox_new (FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (hbox),
+ vbox,
+ FALSE, FALSE,
+ 5);
+ gtk_widget_show (vbox);
+
+ window_store = gtk_tree_store_new (1, GDK_TYPE_WINDOW);
+
+ treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (window_store));
+ gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
+ GTK_SELECTION_MULTIPLE);
+ column = gtk_tree_view_column_new ();
+ gtk_tree_view_column_set_title (column, "Window");
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (column, renderer, TRUE);
+ gtk_tree_view_column_set_cell_data_func (column,
+ renderer,
+ render_window_cell,
+ NULL, NULL);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_set_size_request (scrolled, 200, 400);
+ gtk_container_add (GTK_CONTAINER (scrolled), treeview);
+ gtk_box_pack_start (GTK_BOX (vbox),
+ scrolled,
+ FALSE, FALSE,
+ 5);
+ gtk_widget_show (scrolled);
+ gtk_widget_show (treeview);
+
+ table = gtk_table_new (4, 4, TRUE);
+ gtk_box_pack_start (GTK_BOX (vbox),
+ table,
+ FALSE, FALSE,
+ 2);
+ gtk_widget_show (table);
+
+ button = gtk_button_new ();
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_stock (GTK_STOCK_GO_BACK,
+ GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (move_window_clicked),
+ GINT_TO_POINTER (GTK_DIR_LEFT));
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 0, 1,
+ 1, 2);
+ gtk_widget_show (button);
+
+ button = gtk_button_new ();
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_stock (GTK_STOCK_GO_UP,
+ GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (move_window_clicked),
+ GINT_TO_POINTER (GTK_DIR_UP));
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 1, 2,
+ 0, 1);
+ gtk_widget_show (button);
+
+ button = gtk_button_new ();
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,
+ GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (move_window_clicked),
+ GINT_TO_POINTER (GTK_DIR_RIGHT));
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 2, 3,
+ 1, 2);
+ gtk_widget_show (button);
+
+ button = gtk_button_new ();
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_stock (GTK_STOCK_GO_DOWN,
+ GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (move_window_clicked),
+ GINT_TO_POINTER (GTK_DIR_DOWN));
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 1, 2,
+ 2, 3);
+ gtk_widget_show (button);
+
+
+ button = gtk_button_new_with_label ("Raise");
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (raise_window_clicked),
+ NULL);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 0, 1,
+ 0, 1);
+ gtk_widget_show (button);
+
+ button = gtk_button_new_with_label ("Lower");
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (lower_window_clicked),
+ NULL);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 0, 1,
+ 2, 3);
+ gtk_widget_show (button);
+
+
+ button = gtk_button_new_with_label ("Smaller");
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (smaller_window_clicked),
+ NULL);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 2, 3,
+ 0, 1);
+ gtk_widget_show (button);
+
+ button = gtk_button_new_with_label ("Larger");
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (larger_window_clicked),
+ NULL);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 2, 3,
+ 2, 3);
+ gtk_widget_show (button);
+
+ button = gtk_button_new_with_label ("Native");
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (native_window_clicked),
+ NULL);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 1, 2,
+ 1, 2);
+ gtk_widget_show (button);
+
+
+ button = gtk_button_new_with_label ("scroll");
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_stock (GTK_STOCK_GO_UP,
+ GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (scroll_window_clicked),
+ GINT_TO_POINTER (GTK_DIR_UP));
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 3, 4,
+ 0, 1);
+ gtk_widget_show (button);
+
+ button = gtk_button_new_with_label ("scroll");
+ gtk_button_set_image (GTK_BUTTON (button),
+ gtk_image_new_from_stock (GTK_STOCK_GO_DOWN,
+ GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (scroll_window_clicked),
+ GINT_TO_POINTER (GTK_DIR_DOWN));
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 3, 4,
+ 1, 2);
+ gtk_widget_show (button);
+
+ button = gtk_button_new_with_label ("Manual");
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (manual_clicked),
+ NULL);
+ gtk_table_attach_defaults (GTK_TABLE (table),
+ button,
+ 3, 4,
+ 2, 3);
+ gtk_widget_show (button);
+
+ button = gtk_button_new_with_label ("draw drawable");
+ gtk_box_pack_start (GTK_BOX (vbox),
+ button,
+ FALSE, FALSE,
+ 2);
+ gtk_widget_show (button);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (draw_drawable_clicked),
+ NULL);
+
+ button = gtk_button_new_with_label ("Add window");
+ gtk_box_pack_start (GTK_BOX (vbox),
+ button,
+ FALSE, FALSE,
+ 2);
+ gtk_widget_show (button);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (add_window_clicked),
+ NULL);
+
+ button = gtk_button_new_with_label ("Remove window");
+ gtk_box_pack_start (GTK_BOX (vbox),
+ button,
+ FALSE, FALSE,
+ 2);
+ gtk_widget_show (button);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (remove_window_clicked),
+ NULL);
+
+ button = gtk_button_new_with_label ("Save");
+ gtk_box_pack_start (GTK_BOX (vbox),
+ button,
+ FALSE, FALSE,
+ 2);
+ gtk_widget_show (button);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (save_clicked),
+ NULL);
+
+ gtk_widget_show (window);
+
+ if (argc == 2)
+ {
+ file = g_file_new_for_commandline_arg (argv[1]);
+ load_file (file);
+ g_object_unref (file);
+ }
+
+ gtk_main ();
+
+ return 0;
+}