]> Pileus Git - ~andy/gtk/blob - tests/testexpand.c
gtk: remove "gboolean homogeneous" from gtk_box_new()
[~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, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <gtk/gtk.h>
24
25 static void
26 on_toggle_hexpand (GtkToggleButton *toggle,
27                    void            *data)
28 {
29   GtkWidget *parent;
30
31   /* get the event box with color set on it */
32   parent = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (toggle)));
33
34   g_object_set (toggle,
35                 "hexpand", gtk_toggle_button_get_active (toggle),
36                 NULL);
37 }
38
39 static void
40 on_toggle_vexpand (GtkToggleButton *toggle,
41                    void            *data)
42 {
43   GtkWidget *parent;
44
45   /* get the event box with color set on it */
46   parent = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (toggle)));
47
48   g_object_set (toggle,
49                 "vexpand", gtk_toggle_button_get_active (toggle),
50                 NULL);
51 }
52
53 static void
54 create_box_window (void)
55 {
56   GtkWidget *window;
57   GtkWidget *box1, *box2, *box3;
58   GtkWidget *toggle;
59   GtkWidget *alignment;
60   GtkWidget *colorbox;
61   GdkColor red, blue;
62
63   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
64   gtk_window_set_title (GTK_WINDOW (window), "Boxes");
65
66   box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
67   box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
68   box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
69
70   gtk_box_pack_start (GTK_BOX (box1),
71                       gtk_label_new ("VBox 1 Top"),
72                       FALSE, FALSE, 0);
73   gtk_box_pack_start (GTK_BOX (box1),
74                       box2,
75                       FALSE, TRUE, 0);
76   gtk_box_pack_end (GTK_BOX (box1),
77                     gtk_label_new ("VBox 1 Bottom"),
78                     FALSE, FALSE, 0);
79
80   gtk_box_pack_start (GTK_BOX (box2),
81                       gtk_label_new ("HBox 2 Left"),
82                       FALSE, FALSE, 0);
83   gtk_box_pack_start (GTK_BOX (box2),
84                       box3,
85                       FALSE, TRUE, 0);
86   gtk_box_pack_end (GTK_BOX (box2),
87                     gtk_label_new ("HBox 2 Right"),
88                     FALSE, FALSE, 0);
89
90   gtk_box_pack_start (GTK_BOX (box3),
91                       gtk_label_new ("VBox 3 Top"),
92                       FALSE, FALSE, 0);
93   gtk_box_pack_end (GTK_BOX (box3),
94                     gtk_label_new ("VBox 3 Bottom"),
95                     FALSE, FALSE, 0);
96
97   gdk_color_parse ("red", &red);
98   gdk_color_parse ("blue", &blue);
99
100   colorbox = gtk_event_box_new ();
101   gtk_widget_modify_bg (colorbox, GTK_STATE_NORMAL, &red);
102
103   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
104   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
105   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
106
107   toggle = gtk_toggle_button_new_with_label ("H Expand");
108   g_signal_connect (G_OBJECT (toggle), "toggled",
109                     G_CALLBACK (on_toggle_hexpand), NULL);
110   gtk_container_add (GTK_CONTAINER (alignment), toggle);
111
112   gtk_box_pack_start (GTK_BOX (box3),
113                       colorbox,
114                       FALSE, TRUE, 0);
115
116   colorbox = gtk_event_box_new ();
117   gtk_widget_modify_bg (colorbox, GTK_STATE_NORMAL, &blue);
118
119   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
120   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
121   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
122
123   toggle = gtk_toggle_button_new_with_label ("V Expand");
124   g_signal_connect (G_OBJECT (toggle), "toggled",
125                     G_CALLBACK (on_toggle_vexpand), NULL);
126   gtk_container_add (GTK_CONTAINER (alignment), toggle);
127   gtk_box_pack_start (GTK_BOX (box3),
128                       colorbox,
129                       FALSE, TRUE, 0);
130
131   gtk_container_add (GTK_CONTAINER (window), box1);
132   gtk_widget_show_all (window);
133 }
134
135 static void
136 create_table_window (void)
137 {
138   GtkWidget *window;
139   GtkWidget *table;
140   GtkWidget *toggle;
141   GtkWidget *alignment;
142   GtkWidget *colorbox;
143   GdkColor red, blue;
144
145   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
146   gtk_window_set_title (GTK_WINDOW (window), "Table");
147
148   table = gtk_table_new (4, 3, FALSE);
149
150   gtk_table_attach (GTK_TABLE (table),
151                     gtk_label_new ("Top"),
152                     1, 2, 0, 1,
153                     GTK_FILL, GTK_FILL, 0, 0);
154   gtk_table_attach (GTK_TABLE (table),
155                     gtk_label_new ("Bottom"),
156                     1, 2, 3, 4,
157                     GTK_FILL, GTK_FILL, 0, 0);
158   gtk_table_attach (GTK_TABLE (table),
159                     gtk_label_new ("Left"),
160                     0, 1, 1, 3,
161                     GTK_FILL, GTK_FILL, 0, 0);
162   gtk_table_attach (GTK_TABLE (table),
163                     gtk_label_new ("Right"),
164                     2, 3, 1, 3,
165                     GTK_FILL, GTK_FILL, 0, 0);
166
167   gdk_color_parse ("red", &red);
168   gdk_color_parse ("blue", &blue);
169
170   colorbox = gtk_event_box_new ();
171   gtk_widget_modify_bg (colorbox, GTK_STATE_NORMAL, &red);
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 ("H Expand");
178   g_signal_connect (G_OBJECT (toggle), "toggled",
179                     G_CALLBACK (on_toggle_hexpand), NULL);
180   gtk_container_add (GTK_CONTAINER (alignment), toggle);
181
182   gtk_table_attach (GTK_TABLE (table),
183                     colorbox,
184                     1, 2, 1, 2,
185                     GTK_FILL, GTK_FILL, 0, 0);
186
187   colorbox = gtk_event_box_new ();
188   gtk_widget_modify_bg (colorbox, GTK_STATE_NORMAL, &blue);
189
190   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
191   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
192   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
193
194   toggle = gtk_toggle_button_new_with_label ("V Expand");
195   g_signal_connect (G_OBJECT (toggle), "toggled",
196                     G_CALLBACK (on_toggle_vexpand), NULL);
197   gtk_container_add (GTK_CONTAINER (alignment), toggle);
198
199   gtk_table_attach (GTK_TABLE (table),
200                     colorbox,
201                     1, 2, 2, 3,
202                     GTK_FILL, GTK_FILL, 0, 0);
203
204   gtk_container_add (GTK_CONTAINER (window), table);
205   gtk_widget_show_all (window);
206 }
207
208 int
209 main (int argc, char *argv[])
210 {
211   gtk_init (&argc, &argv);
212
213   create_box_window ();
214   create_table_window ();
215
216   gtk_main ();
217
218   return 0;
219 }