]> Pileus Git - ~andy/gtk/blob - tests/testexpand.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testexpand.c
1 /* testexpand.c
2  * Copyright (C) 2010 Havoc Pennington
3  *
4  * Author:
5  *      Havoc Pennington <hp@pobox.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <gtk/gtk.h>
22
23 static void
24 on_toggle_hexpand (GtkToggleButton *toggle,
25                    void            *data)
26 {
27   g_object_set (toggle,
28                 "hexpand", gtk_toggle_button_get_active (toggle),
29                 NULL);
30 }
31
32 static void
33 on_toggle_vexpand (GtkToggleButton *toggle,
34                    void            *data)
35 {
36   g_object_set (toggle,
37                 "vexpand", gtk_toggle_button_get_active (toggle),
38                 NULL);
39 }
40
41 static void
42 create_box_window (void)
43 {
44   GtkWidget *window;
45   GtkWidget *box1, *box2, *box3;
46   GtkWidget *toggle;
47   GtkWidget *alignment;
48   GtkWidget *colorbox;
49   GdkRGBA red, blue;
50
51   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
52   gtk_window_set_title (GTK_WINDOW (window), "Boxes");
53
54   box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
55   box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
56   box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
57
58   gtk_box_pack_start (GTK_BOX (box1),
59                       gtk_label_new ("VBox 1 Top"),
60                       FALSE, FALSE, 0);
61   gtk_box_pack_start (GTK_BOX (box1),
62                       box2,
63                       FALSE, TRUE, 0);
64   gtk_box_pack_end (GTK_BOX (box1),
65                     gtk_label_new ("VBox 1 Bottom"),
66                     FALSE, FALSE, 0);
67
68   gtk_box_pack_start (GTK_BOX (box2),
69                       gtk_label_new ("HBox 2 Left"),
70                       FALSE, FALSE, 0);
71   gtk_box_pack_start (GTK_BOX (box2),
72                       box3,
73                       FALSE, TRUE, 0);
74   gtk_box_pack_end (GTK_BOX (box2),
75                     gtk_label_new ("HBox 2 Right"),
76                     FALSE, FALSE, 0);
77
78   gtk_box_pack_start (GTK_BOX (box3),
79                       gtk_label_new ("VBox 3 Top"),
80                       FALSE, FALSE, 0);
81   gtk_box_pack_end (GTK_BOX (box3),
82                     gtk_label_new ("VBox 3 Bottom"),
83                     FALSE, FALSE, 0);
84
85   gdk_rgba_parse (&red, "red");
86   gdk_rgba_parse (&blue, "blue");
87
88   colorbox = gtk_event_box_new ();
89   gtk_widget_override_background_color (colorbox, 0, &red);
90
91   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
92   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
93   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
94
95   toggle = gtk_toggle_button_new_with_label ("H Expand");
96   g_signal_connect (G_OBJECT (toggle), "toggled",
97                     G_CALLBACK (on_toggle_hexpand), NULL);
98   gtk_container_add (GTK_CONTAINER (alignment), toggle);
99
100   gtk_box_pack_start (GTK_BOX (box3),
101                       colorbox,
102                       FALSE, TRUE, 0);
103
104   colorbox = gtk_event_box_new ();
105   gtk_widget_override_background_color (colorbox, 0, &blue);
106
107   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
108   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
109   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
110
111   toggle = gtk_toggle_button_new_with_label ("V Expand");
112   g_signal_connect (G_OBJECT (toggle), "toggled",
113                     G_CALLBACK (on_toggle_vexpand), NULL);
114   gtk_container_add (GTK_CONTAINER (alignment), toggle);
115   gtk_box_pack_start (GTK_BOX (box3),
116                       colorbox,
117                       FALSE, TRUE, 0);
118
119   gtk_container_add (GTK_CONTAINER (window), box1);
120   gtk_widget_show_all (window);
121 }
122
123 static void
124 create_grid_window (void)
125 {
126   GtkWidget *window;
127   GtkWidget *grid;
128   GtkWidget *toggle;
129   GtkWidget *alignment;
130   GtkWidget *colorbox;
131   GdkRGBA red, blue;
132
133   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
134   gtk_window_set_title (GTK_WINDOW (window), "Grid");
135
136   grid = gtk_grid_new ();
137
138   gtk_grid_attach (GTK_GRID (grid),
139                    gtk_label_new ("Top"),
140                    1, 0, 1, 1);
141   gtk_grid_attach (GTK_GRID (grid),
142                    gtk_label_new ("Bottom"),
143                    1, 3, 1, 1);
144   gtk_grid_attach (GTK_GRID (grid),
145                    gtk_label_new ("Left"),
146                    0, 1, 1, 2);
147   gtk_grid_attach (GTK_GRID (grid),
148                    gtk_label_new ("Right"),
149                    2, 1, 1, 2);
150
151   gdk_rgba_parse (&red, "red");
152   gdk_rgba_parse (&blue, "blue");
153
154   colorbox = gtk_event_box_new ();
155   gtk_widget_override_background_color (colorbox, GTK_STATE_NORMAL, &red);
156
157   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
158   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
159   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
160
161   toggle = gtk_toggle_button_new_with_label ("H Expand");
162   g_signal_connect (G_OBJECT (toggle), "toggled",
163                     G_CALLBACK (on_toggle_hexpand), NULL);
164   gtk_container_add (GTK_CONTAINER (alignment), toggle);
165
166   gtk_grid_attach (GTK_GRID (grid),
167                    colorbox,
168                    1, 1, 1, 1);
169
170   colorbox = gtk_event_box_new ();
171   gtk_widget_override_background_color (colorbox, 0, &blue);
172
173   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
174   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
175   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
176
177   toggle = gtk_toggle_button_new_with_label ("V Expand");
178   g_signal_connect (G_OBJECT (toggle), "toggled",
179                     G_CALLBACK (on_toggle_vexpand), NULL);
180   gtk_container_add (GTK_CONTAINER (alignment), toggle);
181
182   gtk_grid_attach (GTK_GRID (grid),
183                    colorbox,
184                    1, 2, 1, 1);
185
186   gtk_container_add (GTK_CONTAINER (window), grid);
187   gtk_widget_show_all (window);
188 }
189
190 int
191 main (int argc, char *argv[])
192 {
193   gtk_init (&argc, &argv);
194
195   if (g_getenv ("RTL"))
196     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
197
198   create_box_window ();
199   create_grid_window ();
200
201   gtk_main ();
202
203   return 0;
204 }