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
23static void
24on_toggle_hexpand (GtkToggleButton *toggle,
25 void *data)
26{
27 g_object_set (object: toggle,
28 first_property_name: "hexpand", gtk_toggle_button_get_active (toggle_button: toggle),
29 NULL);
30}
31
32static void
33on_toggle_vexpand (GtkToggleButton *toggle,
34 void *data)
35{
36 g_object_set (object: toggle,
37 first_property_name: "vexpand", gtk_toggle_button_get_active (toggle_button: toggle),
38 NULL);
39}
40
41static void
42create_box_window (void)
43{
44 GtkWidget *window;
45 GtkWidget *box1, *box2, *box3;
46 GtkWidget *toggle;
47 GtkWidget *colorbox;
48
49 window = gtk_window_new ();
50 gtk_window_set_title (GTK_WINDOW (window), title: "Boxes");
51
52 box1 = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 0);
53 box2 = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 0);
54 box3 = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 0);
55
56 gtk_box_append (GTK_BOX (box1),
57 child: gtk_label_new (str: "VBox 1 Top"));
58 gtk_box_append (GTK_BOX (box1),
59 child: box2);
60 gtk_box_append (GTK_BOX(box1),
61 child: gtk_label_new (str: "VBox 1 Bottom"));
62
63 gtk_box_append (GTK_BOX (box2),
64 child: gtk_label_new (str: "HBox 2 Left"));
65 gtk_box_append (GTK_BOX (box2),
66 child: box3);
67 gtk_box_append (GTK_BOX(box2),
68 child: gtk_label_new (str: "HBox 2 Right"));
69
70 gtk_box_append (GTK_BOX (box3),
71 child: gtk_label_new (str: "VBox 3 Top"));
72
73 colorbox = gtk_frame_new (NULL);
74
75 toggle = gtk_toggle_button_new_with_label (label: "H Expand");
76 gtk_widget_set_halign (widget: toggle, align: GTK_ALIGN_CENTER);
77 gtk_widget_set_valign (widget: toggle, align: GTK_ALIGN_CENTER);
78 gtk_widget_set_margin_start (widget: toggle, margin: 5);
79 gtk_widget_set_margin_end (widget: toggle, margin: 5);
80 gtk_widget_set_margin_top (widget: toggle, margin: 5);
81 gtk_widget_set_margin_bottom (widget: toggle, margin: 5);
82 g_signal_connect (G_OBJECT (toggle), "toggled",
83 G_CALLBACK (on_toggle_hexpand), NULL);
84 gtk_frame_set_child (GTK_FRAME (colorbox), child: toggle);
85
86 gtk_box_append (GTK_BOX (box3), child: colorbox);
87
88 colorbox = gtk_frame_new (NULL);
89
90 toggle = gtk_toggle_button_new_with_label (label: "V Expand");
91 gtk_widget_set_halign (widget: toggle, align: GTK_ALIGN_CENTER);
92 gtk_widget_set_valign (widget: toggle, align: GTK_ALIGN_CENTER);
93 gtk_widget_set_margin_start (widget: toggle, margin: 5);
94 gtk_widget_set_margin_end (widget: toggle, margin: 5);
95 gtk_widget_set_margin_top (widget: toggle, margin: 5);
96 gtk_widget_set_margin_bottom (widget: toggle, margin: 5);
97 g_signal_connect (G_OBJECT (toggle), "toggled",
98 G_CALLBACK (on_toggle_vexpand), NULL);
99 gtk_frame_set_child (GTK_FRAME (colorbox), child: toggle);
100 gtk_box_append (GTK_BOX (box3), child: colorbox);
101 gtk_box_append (GTK_BOX (box3),
102 child: gtk_label_new (str: "VBox 3 Bottom"));
103
104 gtk_window_set_child (GTK_WINDOW (window), child: box1);
105 gtk_widget_show (widget: window);
106}
107
108static void
109create_grid_window (void)
110{
111 GtkWidget *window;
112 GtkWidget *grid;
113 GtkWidget *toggle;
114 GtkWidget *colorbox;
115
116 window = gtk_window_new ();
117 gtk_window_set_title (GTK_WINDOW (window), title: "Grid");
118
119 grid = gtk_grid_new ();
120
121 gtk_grid_attach (GTK_GRID (grid), child: gtk_label_new (str: "Top"), column: 1, row: 0, width: 1, height: 1);
122 gtk_grid_attach (GTK_GRID (grid), child: gtk_label_new (str: "Bottom"), column: 1, row: 3, width: 1, height: 1);
123 gtk_grid_attach (GTK_GRID (grid), child: gtk_label_new (str: "Left"), column: 0, row: 1, width: 1, height: 2);
124 gtk_grid_attach (GTK_GRID (grid), child: gtk_label_new (str: "Right"), column: 2, row: 1, width: 1, height: 2);
125
126 colorbox = gtk_frame_new (NULL);
127
128 toggle = gtk_toggle_button_new_with_label (label: "H Expand");
129 gtk_widget_set_halign (widget: toggle, align: GTK_ALIGN_CENTER);
130 gtk_widget_set_valign (widget: toggle, align: GTK_ALIGN_CENTER);
131 gtk_widget_set_margin_start (widget: toggle, margin: 5);
132 gtk_widget_set_margin_end (widget: toggle, margin: 5);
133 gtk_widget_set_margin_top (widget: toggle, margin: 5);
134 gtk_widget_set_margin_bottom (widget: toggle, margin: 5);
135 g_signal_connect (G_OBJECT (toggle), "toggled",
136 G_CALLBACK (on_toggle_hexpand), NULL);
137 gtk_frame_set_child (GTK_FRAME (colorbox), child: toggle);
138
139 gtk_grid_attach (GTK_GRID (grid), child: colorbox, column: 1, row: 1, width: 1, height: 1);
140
141 colorbox = gtk_frame_new (NULL);
142
143 toggle = gtk_toggle_button_new_with_label (label: "V Expand");
144 gtk_widget_set_halign (widget: toggle, align: GTK_ALIGN_CENTER);
145 gtk_widget_set_valign (widget: toggle, align: GTK_ALIGN_CENTER);
146 gtk_widget_set_margin_start (widget: toggle, margin: 5);
147 gtk_widget_set_margin_end (widget: toggle, margin: 5);
148 gtk_widget_set_margin_top (widget: toggle, margin: 5);
149 gtk_widget_set_margin_bottom (widget: toggle, margin: 5);
150 g_signal_connect (G_OBJECT (toggle), "toggled",
151 G_CALLBACK (on_toggle_vexpand), NULL);
152 gtk_frame_set_child (GTK_FRAME (colorbox), child: toggle);
153
154 gtk_grid_attach (GTK_GRID (grid), child: colorbox, column: 1, row: 2, width: 1, height: 1);
155
156 gtk_window_set_child (GTK_WINDOW (window), child: grid);
157 gtk_widget_show (widget: window);
158}
159
160int
161main (int argc, char *argv[])
162{
163 gtk_init ();
164
165 if (g_getenv (variable: "RTL"))
166 gtk_widget_set_default_direction (dir: GTK_TEXT_DIR_RTL);
167
168 create_box_window ();
169 create_grid_window ();
170
171 while (TRUE)
172 g_main_context_iteration (NULL, TRUE);
173
174 return 0;
175}
176

source code of gtk/tests/testexpand.c