]> Pileus Git - ~andy/gtk/blob - tests/testexpand.c
Silence more compiler warnings
[~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   g_object_set (toggle,
30                 "hexpand", gtk_toggle_button_get_active (toggle),
31                 NULL);
32 }
33
34 static void
35 on_toggle_vexpand (GtkToggleButton *toggle,
36                    void            *data)
37 {
38   g_object_set (toggle,
39                 "vexpand", gtk_toggle_button_get_active (toggle),
40                 NULL);
41 }
42
43 static void
44 create_box_window (void)
45 {
46   GtkWidget *window;
47   GtkWidget *box1, *box2, *box3;
48   GtkWidget *toggle;
49   GtkWidget *alignment;
50   GtkWidget *colorbox;
51   GdkRGBA red, blue;
52
53   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
54   gtk_window_set_title (GTK_WINDOW (window), "Boxes");
55
56   box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
57   box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
58   box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
59
60   gtk_box_pack_start (GTK_BOX (box1),
61                       gtk_label_new ("VBox 1 Top"),
62                       FALSE, FALSE, 0);
63   gtk_box_pack_start (GTK_BOX (box1),
64                       box2,
65                       FALSE, TRUE, 0);
66   gtk_box_pack_end (GTK_BOX (box1),
67                     gtk_label_new ("VBox 1 Bottom"),
68                     FALSE, FALSE, 0);
69
70   gtk_box_pack_start (GTK_BOX (box2),
71                       gtk_label_new ("HBox 2 Left"),
72                       FALSE, FALSE, 0);
73   gtk_box_pack_start (GTK_BOX (box2),
74                       box3,
75                       FALSE, TRUE, 0);
76   gtk_box_pack_end (GTK_BOX (box2),
77                     gtk_label_new ("HBox 2 Right"),
78                     FALSE, FALSE, 0);
79
80   gtk_box_pack_start (GTK_BOX (box3),
81                       gtk_label_new ("VBox 3 Top"),
82                       FALSE, FALSE, 0);
83   gtk_box_pack_end (GTK_BOX (box3),
84                     gtk_label_new ("VBox 3 Bottom"),
85                     FALSE, FALSE, 0);
86
87   gdk_rgba_parse (&red, "red");
88   gdk_rgba_parse (&blue, "blue");
89
90   colorbox = gtk_event_box_new ();
91   gtk_widget_override_background_color (colorbox, 0, &red);
92
93   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
94   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
95   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
96
97   toggle = gtk_toggle_button_new_with_label ("H Expand");
98   g_signal_connect (G_OBJECT (toggle), "toggled",
99                     G_CALLBACK (on_toggle_hexpand), NULL);
100   gtk_container_add (GTK_CONTAINER (alignment), toggle);
101
102   gtk_box_pack_start (GTK_BOX (box3),
103                       colorbox,
104                       FALSE, TRUE, 0);
105
106   colorbox = gtk_event_box_new ();
107   gtk_widget_override_background_color (colorbox, 0, &blue);
108
109   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
110   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
111   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
112
113   toggle = gtk_toggle_button_new_with_label ("V Expand");
114   g_signal_connect (G_OBJECT (toggle), "toggled",
115                     G_CALLBACK (on_toggle_vexpand), NULL);
116   gtk_container_add (GTK_CONTAINER (alignment), toggle);
117   gtk_box_pack_start (GTK_BOX (box3),
118                       colorbox,
119                       FALSE, TRUE, 0);
120
121   gtk_container_add (GTK_CONTAINER (window), box1);
122   gtk_widget_show_all (window);
123 }
124
125 static void
126 create_table_window (void)
127 {
128   GtkWidget *window;
129   GtkWidget *table;
130   GtkWidget *toggle;
131   GtkWidget *alignment;
132   GtkWidget *colorbox;
133   GdkRGBA red, blue;
134
135   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
136   gtk_window_set_title (GTK_WINDOW (window), "Table");
137
138   table = gtk_table_new (4, 3, FALSE);
139
140   gtk_table_attach (GTK_TABLE (table),
141                     gtk_label_new ("Top"),
142                     1, 2, 0, 1,
143                     GTK_FILL, GTK_FILL, 0, 0);
144   gtk_table_attach (GTK_TABLE (table),
145                     gtk_label_new ("Bottom"),
146                     1, 2, 3, 4,
147                     GTK_FILL, GTK_FILL, 0, 0);
148   gtk_table_attach (GTK_TABLE (table),
149                     gtk_label_new ("Left"),
150                     0, 1, 1, 3,
151                     GTK_FILL, GTK_FILL, 0, 0);
152   gtk_table_attach (GTK_TABLE (table),
153                     gtk_label_new ("Right"),
154                     2, 3, 1, 3,
155                     GTK_FILL, GTK_FILL, 0, 0);
156
157   gdk_rgba_parse (&red, "red");
158   gdk_rgba_parse (&blue, "blue");
159
160   colorbox = gtk_event_box_new ();
161   gtk_widget_override_background_color (colorbox, GTK_STATE_NORMAL, &red);
162
163   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
164   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
165   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
166
167   toggle = gtk_toggle_button_new_with_label ("H Expand");
168   g_signal_connect (G_OBJECT (toggle), "toggled",
169                     G_CALLBACK (on_toggle_hexpand), NULL);
170   gtk_container_add (GTK_CONTAINER (alignment), toggle);
171
172   gtk_table_attach (GTK_TABLE (table),
173                     colorbox,
174                     1, 2, 1, 2,
175                     GTK_FILL, GTK_FILL, 0, 0);
176
177   colorbox = gtk_event_box_new ();
178   gtk_widget_override_background_color (colorbox, 0, &blue);
179
180   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
181   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
182   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
183
184   toggle = gtk_toggle_button_new_with_label ("V Expand");
185   g_signal_connect (G_OBJECT (toggle), "toggled",
186                     G_CALLBACK (on_toggle_vexpand), NULL);
187   gtk_container_add (GTK_CONTAINER (alignment), toggle);
188
189   gtk_table_attach (GTK_TABLE (table),
190                     colorbox,
191                     1, 2, 2, 3,
192                     GTK_FILL, GTK_FILL, 0, 0);
193
194   gtk_container_add (GTK_CONTAINER (window), table);
195   gtk_widget_show_all (window);
196 }
197
198 int
199 main (int argc, char *argv[])
200 {
201   gtk_init (&argc, &argv);
202
203   create_box_window ();
204   create_table_window ();
205
206   gtk_main ();
207
208   return 0;
209 }