]> Pileus Git - ~andy/gtk/blob - tests/testoffscreenwindow.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testoffscreenwindow.c
1 #include <gtk/gtk.h>
2
3 static gboolean
4 da_draw (GtkWidget *widget,
5          cairo_t   *cr,
6          gpointer   user_data)
7 {
8   GtkOffscreenWindow *offscreen = (GtkOffscreenWindow *)user_data;
9
10   cairo_set_source_surface (cr,
11                             gtk_offscreen_window_get_surface (offscreen),
12                             50, 50);
13   cairo_paint (cr);
14
15   return FALSE;
16 }
17
18 static gboolean
19 offscreen_damage (GtkWidget      *widget,
20                   GdkEventExpose *event,
21                   GtkWidget      *da)
22 {
23   gtk_widget_queue_draw (da);
24
25   return TRUE;
26 }
27
28 static gboolean
29 da_button_press (GtkWidget *area, GdkEventButton *event, GtkWidget *button)
30 {
31   gtk_widget_set_size_request (button, 150, 60);
32   return TRUE;
33 }
34
35 int
36 main (int argc, char **argv)
37 {
38   GtkWidget *window;
39   GtkWidget *button;
40   GtkWidget *offscreen;
41   GtkWidget *da;
42
43   gtk_init (&argc, &argv);
44
45   offscreen = gtk_offscreen_window_new ();
46
47   button = gtk_button_new_with_label ("Test");
48   gtk_widget_set_size_request (button, 50, 50);
49   gtk_container_add (GTK_CONTAINER (offscreen), button);
50   gtk_widget_show (button);
51
52   gtk_widget_show (offscreen);
53
54   /* Queue exposures and ensure they are handled so
55    * that the result is uptodate for the first
56    * expose of the window. If you want to get further
57    * changes, also track damage on the offscreen
58    * as done above.
59    */
60   gtk_widget_queue_draw (offscreen);
61
62   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
63   g_signal_connect (window, "delete-event",
64                     G_CALLBACK (gtk_main_quit), window);
65   da = gtk_drawing_area_new ();
66   gtk_container_add (GTK_CONTAINER (window), da);
67
68   g_signal_connect (da,
69                     "draw",
70                     G_CALLBACK (da_draw),
71                     offscreen);
72
73   g_signal_connect (offscreen,
74                     "damage-event",
75                     G_CALLBACK (offscreen_damage),
76                     da);
77
78   gtk_widget_add_events (da, GDK_BUTTON_PRESS_MASK);
79   g_signal_connect (da, "button_press_event", G_CALLBACK (da_button_press),
80                     button);
81
82   gtk_widget_show_all (window);
83
84   gtk_main();
85
86   return 0;
87 }