1 | /* |
2 | * Copyright (C) 2006 Nokia Corporation. |
3 | * Author: Xan Lopez <xan.lopez@nokia.com> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public License |
7 | * version 2.1 as published by the Free Software Foundation. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, but |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | */ |
18 | |
19 | #include <gtk/gtk.h> |
20 | |
21 | static const char *baseline_pos_str[] = { |
22 | "BASELINE_POSITION_TOP" , |
23 | "BASELINE_POSITION_CENTER" , |
24 | "BASELINE_POSITION_BOTTOM" |
25 | }; |
26 | |
27 | static void |
28 | baseline_row_value_changed (GtkSpinButton *spin_button, |
29 | GtkGrid *grid) |
30 | { |
31 | int row = gtk_spin_button_get_value_as_int (spin_button); |
32 | |
33 | gtk_grid_set_baseline_row (grid, row); |
34 | } |
35 | |
36 | static void |
37 | homogeneous_changed (GtkToggleButton *toggle_button, |
38 | GtkGrid *grid) |
39 | { |
40 | gtk_grid_set_row_homogeneous (grid, homogeneous: gtk_toggle_button_get_active (toggle_button)); |
41 | } |
42 | |
43 | static void |
44 | baseline_position_changed (GtkComboBox *combo, |
45 | GtkBox *hbox) |
46 | { |
47 | int i = gtk_combo_box_get_active (combo_box: combo); |
48 | |
49 | gtk_box_set_baseline_position (box: hbox, position: i); |
50 | } |
51 | |
52 | static void |
53 | image_size_value_changed (GtkSpinButton *spin_button, |
54 | GtkImage *image) |
55 | { |
56 | int size = gtk_spin_button_get_value_as_int (spin_button); |
57 | |
58 | gtk_image_set_pixel_size (GTK_IMAGE (image), pixel_size: size); |
59 | } |
60 | |
61 | static void |
62 | set_font_size (GtkWidget *widget, int size) |
63 | { |
64 | const char *class[3] = { "small-font" , "medium-font" , "large-font" }; |
65 | |
66 | gtk_widget_add_css_class (widget, css_class: class[size]); |
67 | } |
68 | |
69 | static void |
70 | quit_cb (GtkWidget *widget, |
71 | gpointer data) |
72 | { |
73 | gboolean *done = data; |
74 | |
75 | *done = TRUE; |
76 | |
77 | g_main_context_wakeup (NULL); |
78 | } |
79 | |
80 | int |
81 | main (int argc, |
82 | char **argv) |
83 | { |
84 | GtkWidget *window, *label, *entry, *button, *grid, *notebook; |
85 | GtkWidget *vbox, *hbox, *grid_hbox, *spin, *spin2, *toggle, *combo, *image; |
86 | GtkAdjustment *adjustment; |
87 | int i, j; |
88 | GtkCssProvider *provider; |
89 | gboolean done = FALSE; |
90 | GtkWidget *group = NULL; |
91 | |
92 | gtk_init (); |
93 | |
94 | provider = gtk_css_provider_new (); |
95 | gtk_css_provider_load_from_data (css_provider: provider, |
96 | data: ".small-font { font-size: 5px; }" |
97 | ".medium-font { font-size: 10px; }" |
98 | ".large-font { font-size: 15px; }" , length: -1); |
99 | gtk_style_context_add_provider_for_display (display: gdk_display_get_default (), |
100 | GTK_STYLE_PROVIDER (provider), |
101 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
102 | g_object_unref (object: provider); |
103 | window = gtk_window_new (); |
104 | g_signal_connect (G_OBJECT (window), "destroy" , G_CALLBACK (quit_cb), &done); |
105 | |
106 | notebook = gtk_notebook_new (); |
107 | gtk_window_set_child (GTK_WINDOW (window), child: notebook); |
108 | |
109 | vbox = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 5); |
110 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), |
111 | child: vbox, tab_label: gtk_label_new (str: "hboxes" )); |
112 | |
113 | for (j = 0; j < 2; j++) |
114 | { |
115 | hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 10); |
116 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
117 | |
118 | const char *aligns_names[] = { "FILL" , "BASELINE" }; |
119 | GtkAlign aligns[] = { GTK_ALIGN_FILL, GTK_ALIGN_BASELINE}; |
120 | |
121 | label = gtk_label_new (str: aligns_names[j]); |
122 | gtk_box_append (GTK_BOX (hbox), child: label); |
123 | |
124 | for (i = 0; i < 3; i++) { |
125 | label = gtk_label_new (str: "│XYyj,Ö..." ); |
126 | |
127 | set_font_size (widget: label, size: i); |
128 | |
129 | gtk_widget_set_valign (widget: label, align: aligns[j]); |
130 | |
131 | gtk_box_append (GTK_BOX (hbox), child: label); |
132 | } |
133 | |
134 | for (i = 0; i < 3; i++) { |
135 | entry = gtk_entry_new (); |
136 | gtk_editable_set_text (GTK_EDITABLE (entry), text: "│XYyj,Ö..." ); |
137 | |
138 | set_font_size (widget: entry, size: i); |
139 | |
140 | gtk_widget_set_valign (widget: entry, align: aligns[j]); |
141 | |
142 | gtk_box_append (GTK_BOX (hbox), child: entry); |
143 | } |
144 | |
145 | spin = gtk_spin_button_new (NULL, climb_rate: 0, digits: 1); |
146 | gtk_orientable_set_orientation (GTK_ORIENTABLE (spin), orientation: GTK_ORIENTATION_VERTICAL); |
147 | gtk_widget_set_valign (widget: spin, align: aligns[j]); |
148 | gtk_box_append (GTK_BOX (hbox), child: spin); |
149 | |
150 | spin = gtk_spin_button_new (NULL, climb_rate: 0, digits: 1); |
151 | gtk_widget_set_valign (widget: spin, align: aligns[j]); |
152 | gtk_box_append (GTK_BOX (hbox), child: spin); |
153 | } |
154 | |
155 | grid_hbox = hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 10); |
156 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
157 | |
158 | combo = gtk_combo_box_text_new (); |
159 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: baseline_pos_str[0]); |
160 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: baseline_pos_str[1]); |
161 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: baseline_pos_str[2]); |
162 | gtk_combo_box_set_active (GTK_COMBO_BOX (combo), index_: 1); |
163 | gtk_box_append (GTK_BOX (hbox), child: combo); |
164 | |
165 | for (j = 0; j < 2; j++) |
166 | { |
167 | hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 10); |
168 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
169 | |
170 | g_signal_connect (G_OBJECT (combo), "changed" , |
171 | G_CALLBACK (baseline_position_changed), hbox); |
172 | |
173 | if (j == 0) |
174 | label = gtk_label_new (str: "Baseline:" ); |
175 | else |
176 | label = gtk_label_new (str: "Normal:" ); |
177 | gtk_box_append (GTK_BOX (hbox), child: label); |
178 | |
179 | for (i = 0; i < 3; i++) |
180 | { |
181 | button = gtk_button_new_with_label (label: "│Xyj,Ö" ); |
182 | |
183 | set_font_size (widget: button, size: i); |
184 | |
185 | if (j == 0) |
186 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
187 | |
188 | gtk_box_append (GTK_BOX (hbox), child: button); |
189 | } |
190 | |
191 | for (i = 0; i < 3; i++) |
192 | { |
193 | GtkWidget *box = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 6); |
194 | button = gtk_button_new (); |
195 | |
196 | gtk_box_append (GTK_BOX (box), child: gtk_label_new (str: "│Xyj,Ö" )); |
197 | gtk_box_append (GTK_BOX (box), child: gtk_image_new_from_icon_name (icon_name: "face-sad" )); |
198 | gtk_button_set_child (GTK_BUTTON (button), child: box); |
199 | |
200 | set_font_size (widget: button, size: i); |
201 | |
202 | if (j == 0) |
203 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
204 | |
205 | gtk_box_append (GTK_BOX (hbox), child: button); |
206 | } |
207 | |
208 | image = gtk_image_new_from_icon_name (icon_name: "face-sad" ); |
209 | gtk_image_set_pixel_size (GTK_IMAGE (image), pixel_size: 34); |
210 | if (j == 0) |
211 | gtk_widget_set_valign (widget: image, align: GTK_ALIGN_BASELINE); |
212 | gtk_box_append (GTK_BOX (hbox), child: image); |
213 | |
214 | button = gtk_toggle_button_new_with_label (label: "│Xyj,Ö" ); |
215 | if (j == 0) |
216 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
217 | gtk_box_append (GTK_BOX (hbox), child: button); |
218 | |
219 | button = gtk_toggle_button_new_with_label (label: "│Xyj,Ö" ); |
220 | if (j == 0) |
221 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
222 | gtk_box_append (GTK_BOX (hbox), child: button); |
223 | |
224 | button = gtk_check_button_new_with_label (label: "│Xyj,Ö" ); |
225 | if (j == 0) |
226 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
227 | gtk_box_append (GTK_BOX (hbox), child: button); |
228 | |
229 | button = gtk_check_button_new_with_label (label: "│Xyj,Ö" ); |
230 | if (j == 0) |
231 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
232 | gtk_box_append (GTK_BOX (hbox), child: button); |
233 | if (group == NULL) |
234 | { |
235 | group = button; |
236 | gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE); |
237 | } |
238 | else |
239 | gtk_check_button_set_group (GTK_CHECK_BUTTON (button), |
240 | GTK_CHECK_BUTTON (group)); |
241 | } |
242 | |
243 | |
244 | vbox = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 0); |
245 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), |
246 | child: vbox, tab_label: gtk_label_new (str: "grid" )); |
247 | |
248 | grid_hbox = hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 10); |
249 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
250 | |
251 | label = gtk_label_new (str: "Align me:" ); |
252 | gtk_widget_set_valign (widget: label, align: GTK_ALIGN_BASELINE); |
253 | |
254 | gtk_box_append (GTK_BOX (hbox), child: label); |
255 | |
256 | grid = gtk_grid_new (); |
257 | gtk_widget_set_valign (widget: grid, align: GTK_ALIGN_BASELINE); |
258 | gtk_grid_set_column_spacing (GTK_GRID (grid), spacing: 8); |
259 | gtk_grid_set_row_spacing (GTK_GRID (grid), spacing: 8); |
260 | |
261 | for (j = 0; j < 4; j++) |
262 | { |
263 | const char *labels[] = { "Normal:" , "Baseline (top):" , "Baseline (center):" , "Baseline (bottom):" }; |
264 | label = gtk_label_new (str: labels[j]); |
265 | |
266 | gtk_grid_attach (GTK_GRID (grid), |
267 | child: label, |
268 | column: 0, row: j, |
269 | width: 1, height: 1); |
270 | gtk_widget_set_vexpand (widget: label, TRUE); |
271 | |
272 | if (j != 0) |
273 | gtk_grid_set_row_baseline_position (GTK_GRID (grid), |
274 | row: j, pos: (GtkBaselinePosition)(j-1)); |
275 | |
276 | for (i = 0; i < 3; i++) |
277 | { |
278 | label = gtk_label_new (str: "Xyjg,Ö." ); |
279 | |
280 | set_font_size (widget: label, size: i); |
281 | |
282 | if (j != 0) |
283 | gtk_widget_set_valign (widget: label, align: GTK_ALIGN_BASELINE); |
284 | |
285 | gtk_grid_attach (GTK_GRID (grid), |
286 | child: label, |
287 | column: i+1, row: j, |
288 | width: 1, height: 1); |
289 | } |
290 | |
291 | for (i = 0; i < 3; i++) |
292 | { |
293 | GtkWidget *box = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 6); |
294 | button = gtk_button_new (); |
295 | |
296 | gtk_box_append (GTK_BOX (box), child: gtk_label_new (str: "│Xyj,Ö" )); |
297 | gtk_box_append (GTK_BOX (box), child: gtk_image_new_from_icon_name (icon_name: "face-sad" )); |
298 | gtk_button_set_child (GTK_BUTTON (button), child: box); |
299 | |
300 | set_font_size (widget: button, size: i); |
301 | |
302 | if (j != 0) |
303 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
304 | |
305 | gtk_grid_attach (GTK_GRID (grid), |
306 | child: button, |
307 | column: i+4, row: j, |
308 | width: 1, height: 1); |
309 | } |
310 | |
311 | } |
312 | |
313 | gtk_box_append (GTK_BOX (hbox), child: grid); |
314 | |
315 | hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 10); |
316 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
317 | |
318 | adjustment = gtk_adjustment_new (value: 0.0, lower: -1.0, upper: 5.0, step_increment: 1.0, page_increment: 1.0, page_size: 0.0); |
319 | spin = gtk_spin_button_new (adjustment, climb_rate: 1.0, digits: 0); |
320 | g_signal_connect (spin, "value-changed" , (GCallback)baseline_row_value_changed, grid); |
321 | gtk_box_append (GTK_BOX (hbox), child: spin); |
322 | |
323 | toggle = gtk_toggle_button_new_with_label (label: "Homogeneous" ); |
324 | g_signal_connect (toggle, "toggled" , (GCallback)homogeneous_changed, grid); |
325 | gtk_box_append (GTK_BOX (hbox), child: toggle); |
326 | |
327 | combo = gtk_combo_box_text_new (); |
328 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: baseline_pos_str[0]); |
329 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: baseline_pos_str[1]); |
330 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: baseline_pos_str[2]); |
331 | gtk_combo_box_set_active (GTK_COMBO_BOX (combo), index_: 1); |
332 | g_signal_connect (G_OBJECT (combo), "changed" , |
333 | G_CALLBACK (baseline_position_changed), grid_hbox); |
334 | gtk_box_append (GTK_BOX (hbox), child: combo); |
335 | |
336 | vbox = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 0); |
337 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), |
338 | child: vbox, tab_label: gtk_label_new (str: "button box" )); |
339 | |
340 | hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 10); |
341 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
342 | |
343 | adjustment = gtk_adjustment_new (value: 34.0, lower: 1.0, upper: 64.0, step_increment: 1.0, page_increment: 1.0, page_size: 0.0); |
344 | spin = gtk_spin_button_new (adjustment, climb_rate: 1.0, digits: 0); |
345 | gtk_box_append (GTK_BOX (hbox), child: spin); |
346 | |
347 | adjustment = gtk_adjustment_new (value: 16.0, lower: 1.0, upper: 64.0, step_increment: 1.0, page_increment: 1.0, page_size: 0.0); |
348 | spin2 = gtk_spin_button_new (adjustment, climb_rate: 1.0, digits: 0); |
349 | gtk_box_append (GTK_BOX (hbox), child: spin2); |
350 | |
351 | for (j = 0; j < 3; j++) |
352 | { |
353 | hbox = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 0); |
354 | gtk_box_append (GTK_BOX (vbox), child: hbox); |
355 | |
356 | gtk_box_set_baseline_position (GTK_BOX (hbox), position: j); |
357 | |
358 | label = gtk_label_new (str: baseline_pos_str[j]); |
359 | gtk_box_append (GTK_BOX (hbox), child: label); |
360 | gtk_widget_set_vexpand (widget: label, TRUE); |
361 | |
362 | image = gtk_image_new_from_icon_name (icon_name: "face-sad" ); |
363 | gtk_image_set_pixel_size (GTK_IMAGE (image), pixel_size: 34); |
364 | gtk_box_append (GTK_BOX (hbox), child: image); |
365 | |
366 | g_signal_connect (spin, "value-changed" , (GCallback)image_size_value_changed, image); |
367 | |
368 | for (i = 0; i < 3; i++) |
369 | { |
370 | button = gtk_button_new_with_label (label: "│Xyj,Ö" ); |
371 | |
372 | set_font_size (widget: button, size: i); |
373 | |
374 | if (i != 0) |
375 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
376 | |
377 | gtk_box_append (GTK_BOX (hbox), child: button); |
378 | } |
379 | |
380 | for (i = 0; i < 3; i++) |
381 | { |
382 | GtkWidget *box = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 6); |
383 | button = gtk_button_new (); |
384 | |
385 | gtk_box_append (GTK_BOX (box), child: gtk_label_new (str: "│Xyj,Ö" )); |
386 | image = gtk_image_new_from_icon_name (icon_name: "face-sad" ); |
387 | gtk_image_set_pixel_size (GTK_IMAGE (image), pixel_size: 16); |
388 | gtk_box_append (GTK_BOX (box), child: image); |
389 | gtk_button_set_child (GTK_BUTTON (button), child: box); |
390 | |
391 | if (i == 0) |
392 | g_signal_connect (spin2, "value-changed" , (GCallback)image_size_value_changed, image); |
393 | |
394 | set_font_size (widget: button, size: i); |
395 | |
396 | gtk_widget_set_valign (widget: button, align: GTK_ALIGN_BASELINE); |
397 | |
398 | gtk_box_append (GTK_BOX (hbox), child: button); |
399 | } |
400 | } |
401 | |
402 | gtk_widget_show (widget: window); |
403 | |
404 | while (!done) |
405 | g_main_context_iteration (NULL, TRUE); |
406 | |
407 | return 0; |
408 | } |
409 | |