]> Pileus Git - ~andy/gtk/blob - tests/testexpand.c
gtkiconview: Use symbolic names for button numbers
[~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_grid_window (void)
127 {
128   GtkWidget *window;
129   GtkWidget *grid;
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), "Grid");
137
138   grid = gtk_grid_new ();
139
140   gtk_grid_attach (GTK_GRID (grid),
141                    gtk_label_new ("Top"),
142                    1, 0, 1, 1);
143   gtk_grid_attach (GTK_GRID (grid),
144                    gtk_label_new ("Bottom"),
145                    1, 3, 1, 1);
146   gtk_grid_attach (GTK_GRID (grid),
147                    gtk_label_new ("Left"),
148                    0, 1, 1, 2);
149   gtk_grid_attach (GTK_GRID (grid),
150                    gtk_label_new ("Right"),
151                    2, 1, 1, 2);
152
153   gdk_rgba_parse (&red, "red");
154   gdk_rgba_parse (&blue, "blue");
155
156   colorbox = gtk_event_box_new ();
157   gtk_widget_override_background_color (colorbox, GTK_STATE_NORMAL, &red);
158
159   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
160   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
161   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
162
163   toggle = gtk_toggle_button_new_with_label ("H Expand");
164   g_signal_connect (G_OBJECT (toggle), "toggled",
165                     G_CALLBACK (on_toggle_hexpand), NULL);
166   gtk_container_add (GTK_CONTAINER (alignment), toggle);
167
168   gtk_grid_attach (GTK_GRID (grid),
169                    colorbox,
170                    1, 1, 1, 1);
171
172   colorbox = gtk_event_box_new ();
173   gtk_widget_override_background_color (colorbox, 0, &blue);
174
175   alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
176   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);
177   gtk_container_add (GTK_CONTAINER (colorbox), alignment);
178
179   toggle = gtk_toggle_button_new_with_label ("V Expand");
180   g_signal_connect (G_OBJECT (toggle), "toggled",
181                     G_CALLBACK (on_toggle_vexpand), NULL);
182   gtk_container_add (GTK_CONTAINER (alignment), toggle);
183
184   gtk_grid_attach (GTK_GRID (grid),
185                    colorbox,
186                    1, 2, 1, 1);
187
188   gtk_container_add (GTK_CONTAINER (window), grid);
189   gtk_widget_show_all (window);
190 }
191
192 int
193 main (int argc, char *argv[])
194 {
195   gtk_init (&argc, &argv);
196
197   if (g_getenv ("RTL"))
198     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
199
200   create_box_window ();
201   create_grid_window ();
202
203   gtk_main ();
204
205   return 0;
206 }