1 /* extendedlayoutexample.c
2 * Copyright (C) 2010 Openismus GmbH
5 * Tristan Van Berkom <tristan.van.berkom@gmail.com>
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.
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.
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.
28 const gchar *interface;
33 /* These strings were generated with:
35 * IFS=""; while read line; do echo -n \"; echo -n $line | sed -e 's|\"|\\"|g'; echo \"; done < file.glade
37 TestInterface interfaces[] = {
40 "Demonstrates how labels will request a natural size in a horizontal space",
42 " <requires lib=\"gtk+\" version=\"2.20\"/>"
43 " <!-- interface-naming-policy project-wide -->"
44 " <object class=\"GtkWindow\" id=\"window\">"
45 " <property name=\"default_width\">450</property>"
46 " <property name=\"default_height\">50</property>"
48 " <object class=\"GtkHBox\" id=\"hbox5\">"
49 " <property name=\"visible\">True</property>"
51 " <object class=\"GtkLabel\" id=\"label9\">"
52 " <property name=\"visible\">True</property>"
53 " <property name=\"label\" translatable=\"yes\">Some labels do ellipsize</property>"
54 " <property name=\"ellipsize\">end</property>"
56 " <attribute name=\"weight\" value=\"bold\"/>"
57 " <attribute name=\"foreground\" value=\"#09610feefe03\"/>"
61 " <property name=\"position\">0</property>"
65 " <object class=\"GtkLabel\" id=\"label10\">"
66 " <property name=\"visible\">True</property>"
67 " <property name=\"label\" translatable=\"yes\">but some</property>"
68 " <property name=\"ellipsize\">end</property>"
70 " <attribute name=\"weight\" value=\"bold\"/>"
71 " <attribute name=\"foreground\" value=\"#0000af6b0993\"/>"
75 " <property name=\"position\">1</property>"
79 " <object class=\"GtkLabel\" id=\"label11\">"
80 " <property name=\"visible\">True</property>"
81 " <property name=\"label\" translatable=\"yes\">do not at all</property>"
83 " <attribute name=\"style\" value=\"normal\"/>"
84 " <attribute name=\"weight\" value=\"bold\"/>"
85 " <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
89 " <property name=\"position\">2</property>"
101 "Demonstrates how a wrapping label can require a height contextual to its allocated width",
103 " <requires lib=\"gtk+\" version=\"2.18\"/>"
104 " <!-- interface-naming-policy project-wide -->"
105 " <object class=\"GtkWindow\" id=\"window\">"
106 " <property name=\"border_width\">12</property>"
107 " <property name=\"default_width\">300</property>"
109 " <object class=\"GtkHPaned\" id=\"hpaned1\">"
110 " <property name=\"visible\">True</property>"
111 " <property name=\"can_focus\">True</property>"
113 " <object class=\"GtkVBox\" id=\"vbox2\">"
114 " <property name=\"visible\">True</property>"
116 " <object class=\"GtkLabel\" id=\"label3\">"
117 " <property name=\"visible\">True</property>"
118 " <property name=\"label\" translatable=\"yes\">A short static label.</property>"
120 " <attribute name=\"weight\" value=\"bold\"/>"
124 " <property name=\"position\">0</property>"
128 " <object class=\"GtkFrame\" id=\"frame1\">"
129 " <property name=\"label\">Long label</property>"
130 " <property name=\"visible\">True</property>"
132 " <object class=\"GtkLabel\" id=\"label1\">"
133 " <property name=\"visible\">True</property>"
134 " <property name=\"label\" translatable=\"yes\">This is a really long label for the purpose of testing line wrapping is working correctly in conjunction with height-for-width support in GTK+</property>"
135 " <property name=\"wrap\">True</property>"
136 " <property name=\"max_width_chars\">30</property>"
138 " <attribute name=\"foreground\" value=\"#18c52119f796\"/>"
144 " <property name=\"expand\">False</property>"
145 " <property name=\"position\">1</property>"
149 " <object class=\"GtkButton\" id=\"button2\">"
150 " <property name=\"visible\">True</property>"
151 " <property name=\"can_focus\">True</property>"
152 " <property name=\"receives_default\">True</property>"
154 " <object class=\"GtkLabel\" id=\"label2\">"
155 " <property name=\"visible\">True</property>"
156 " <property name=\"label\" translatable=\"yes\">A really really long label inside a button to demonstrate height for width working inside buttons</property>"
157 " <property name=\"wrap\">True</property>"
158 " <property name=\"max_width_chars\">25</property>"
160 " <attribute name=\"foreground\" value=\"#1e3687ab0a52\"/>"
166 " <property name=\"expand\">False</property>"
167 " <property name=\"position\">2</property>"
172 " <property name=\"resize\">False</property>"
173 " <property name=\"shrink\">False</property>"
177 " <object class=\"GtkLabel\" id=\"label4\">"
178 " <property name=\"visible\">True</property>"
179 " <property name=\"label\" translatable=\"yes\">This static label\n"
180 "can shrink.</property>"
181 " <property name=\"justify\">center</property>"
183 " <attribute name=\"style\" value=\"normal\"/>"
184 " <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
188 " <property name=\"resize\">True</property>"
189 " <property name=\"shrink\">True</property>"
201 "Demonstrates how a horizontal box can calculate the collective height for an allocated width",
203 " <requires lib=\"gtk+\" version=\"2.20\"/>"
204 " <!-- interface-naming-policy project-wide -->"
205 " <object class=\"GtkWindow\" id=\"window\">"
206 " <property name=\"default_height\">200</property>"
207 " <property name=\"default_width\">600</property>"
209 " <object class=\"GtkHPaned\" id=\"hpaned1\">"
210 " <property name=\"visible\">True</property>"
211 " <property name=\"can_focus\">True</property>"
213 " <object class=\"GtkVBox\" id=\"vbox1\">"
214 " <property name=\"visible\">True</property>"
216 " <object class=\"GtkHBox\" id=\"hbox1\">"
217 " <property name=\"visible\">True</property>"
219 " <object class=\"GtkButton\" id=\"button1\">"
220 " <property name=\"visible\">True</property>"
221 " <property name=\"can_focus\">True</property>"
222 " <property name=\"receives_default\">True</property>"
223 " <property name=\"use_action_appearance\">False</property>"
225 " <object class=\"GtkLabel\" id=\"label2\">"
226 " <property name=\"visible\">True</property>"
227 " <property name=\"label\" translatable=\"yes\">A button that wraps.</property>"
228 " <property name=\"wrap\">True</property>"
229 " <property name=\"width_chars\">10</property>"
231 " <attribute name=\"foreground\" value=\"#0000041dffff\"/>"
237 " <property name=\"expand\">False</property>"
238 " <property name=\"position\">0</property>"
242 " <object class=\"GtkLabel\" id=\"label1\">"
243 " <property name=\"visible\">True</property>"
244 " <property name=\"label\" translatable=\"yes\">Lets try setting up some long text to wrap up in this hbox and see if the height-for-width is gonna work !</property>"
245 " <property name=\"wrap\">True</property>"
246 " <property name=\"width_chars\">30</property>"
248 " <attribute name=\"foreground\" value=\"#07d0a9b20972\"/>"
252 " <property name=\"position\">1</property>"
257 " <property name=\"expand\">False</property>"
258 " <property name=\"position\">0</property>"
262 " <object class=\"GtkButton\" id=\"button2\">"
263 " <property name=\"label\" translatable=\"yes\">A button that expands in the vbox</property>"
264 " <property name=\"visible\">True</property>"
265 " <property name=\"can_focus\">True</property>"
266 " <property name=\"receives_default\">True</property>"
267 " <property name=\"use_action_appearance\">False</property>"
270 " <property name=\"position\">1</property>"
275 " <property name=\"resize\">False</property>"
276 " <property name=\"shrink\">False</property>"
280 " <object class=\"GtkLabel\" id=\"label4\">"
281 " <property name=\"visible\">True</property>"
282 " <property name=\"label\" translatable=\"yes\">This label is\n"
283 "set to shrink inside\n"
284 "the paned window.</property>"
285 " <property name=\"justify\">center</property>"
287 " <attribute name=\"style\" value=\"normal\"/>"
288 " <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
292 " <property name=\"resize\">True</property>"
293 " <property name=\"shrink\">True</property>"
305 "Demonstrates how a horizontal box will consider width-for-height when allocating children "
306 "even if the toplevel window is requested as height-for-width.",
308 " <requires lib=\"gtk+\" version=\"2.20\"/>"
309 " <!-- interface-naming-policy project-wide -->"
310 " <object class=\"GtkWindow\" id=\"window\">"
311 " <property name=\"default_width\">400</property>"
312 " <property name=\"default_height\">300</property>"
314 " <object class=\"GtkVPaned\" id=\"vpaned1\">"
315 " <property name=\"visible\">True</property>"
316 " <property name=\"can_focus\">True</property>"
318 " <object class=\"GtkHBox\" id=\"hbox1\">"
319 " <property name=\"visible\">True</property>"
321 " <object class=\"GtkLabel\" id=\"label1\">"
322 " <property name=\"visible\">True</property>"
323 " <property name=\"label\" translatable=\"yes\">Some long width-for-height text that wraps</property>"
324 " <property name=\"justify\">center</property>"
325 " <property name=\"wrap\">True</property>"
326 " <property name=\"width_chars\">10</property>"
327 " <property name=\"angle\">90</property>"
329 " <attribute name=\"weight\" value=\"bold\"/>"
330 " <attribute name=\"foreground\" value=\"#03e307ddfb5f\"/>"
334 " <property name=\"expand\">False</property>"
335 " <property name=\"position\">0</property>"
339 " <object class=\"GtkFrame\" id=\"frame1\">"
340 " <property name=\"visible\">True</property>"
341 " <property name=\"label_xalign\">0</property>"
342 " <property name=\"shadow_type\">out</property>"
344 " <object class=\"GtkLabel\" id=\"label5\">"
345 " <property name=\"visible\">True</property>"
346 " <property name=\"label\" translatable=\"yes\">Neither of the panes are\n"
347 "set to shrink.</property>"
348 " <property name=\"justify\">center</property>"
350 " <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
354 " <child type=\"label_item\">"
359 " <property name=\"position\">1</property>"
364 " <property name=\"resize\">False</property>"
365 " <property name=\"shrink\">False</property>"
369 " <object class=\"GtkHBox\" id=\"hbox2\">"
370 " <property name=\"visible\">True</property>"
372 " <object class=\"GtkFrame\" id=\"frame2\">"
373 " <property name=\"visible\">True</property>"
374 " <property name=\"label_xalign\">0</property>"
375 " <property name=\"shadow_type\">out</property>"
377 " <object class=\"GtkLabel\" id=\"label4\">"
378 " <property name=\"visible\">True</property>"
379 " <property name=\"label\" translatable=\"yes\">The interface is allocated as height\n"
380 "for width, but the horizontal boxes\n"
381 "allocate in width for height mode.</property>"
383 " <attribute name=\"foreground\" value=\"#000097970808\"/>"
387 " <child type=\"label_item\">"
392 " <property name=\"position\">0</property>"
396 " <object class=\"GtkLabel\" id=\"label3\">"
397 " <property name=\"visible\">True</property>"
398 " <property name=\"label\" translatable=\"yes\">Some long width-for-height text that wraps</property>"
399 " <property name=\"justify\">center</property>"
400 " <property name=\"wrap\">True</property>"
401 " <property name=\"width_chars\">10</property>"
402 " <property name=\"angle\">270</property>"
404 " <attribute name=\"weight\" value=\"bold\"/>"
405 " <attribute name=\"foreground\" value=\"#03e307ddfb5f\"/>"
409 " <property name=\"expand\">False</property>"
410 " <property name=\"position\">1</property>"
415 " <property name=\"resize\">False</property>"
416 " <property name=\"shrink\">False</property>"
428 "This test demonstrates how \"width-chars\" and \"max-width-chars\" can be used "
429 "to effect minimum and natural widths in wrapping labels.",
431 " <requires lib=\"gtk+\" version=\"2.20\"/>"
432 " <!-- interface-naming-policy project-wide -->"
433 " <object class=\"GtkWindow\" id=\"window\">"
434 " <property name=\"default_width\">900</property>"
436 " <object class=\"GtkHPaned\" id=\"hpaned1\">"
437 " <property name=\"visible\">True</property>"
438 " <property name=\"can_focus\">True</property>"
440 " <object class=\"GtkVBox\" id=\"vbox1\">"
441 " <property name=\"visible\">True</property>"
443 " <object class=\"GtkHBox\" id=\"hbox1\">"
444 " <property name=\"visible\">True</property>"
445 " <property name=\"spacing\">6</property>"
447 " <object class=\"GtkLabel\" id=\"label1\">"
448 " <property name=\"visible\">True</property>"
449 " <property name=\"label\" translatable=\"yes\">The first 2 labels require 10 characters.</property>"
450 " <property name=\"wrap\">True</property>"
451 " <property name=\"width_chars\">10</property>"
453 " <attribute name=\"weight\" value=\"bold\"/>"
454 " <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
458 " <property name=\"expand\">False</property>"
459 " <property name=\"fill\">False</property>"
460 " <property name=\"position\">0</property>"
464 " <object class=\"GtkLabel\" id=\"label2\">"
465 " <property name=\"visible\">True</property>"
466 " <property name=\"label\" translatable=\"yes\">This label has a maximum natural width of 20 characters. The second two labels expand.</property>"
467 " <property name=\"wrap\">True</property>"
468 " <property name=\"width_chars\">10</property>"
469 " <property name=\"max_width_chars\">20</property>"
471 " <attribute name=\"weight\" value=\"bold\"/>"
472 " <attribute name=\"foreground\" value=\"#05c2a161134b\"/>"
476 " <property name=\"expand\">True</property>"
477 " <property name=\"fill\">True</property>"
478 " <property name=\"position\">1</property>"
482 " <object class=\"GtkLabel\" id=\"label3\">"
483 " <property name=\"visible\">True</property>"
484 " <property name=\"label\" translatable=\"yes\">This label requires a default minimum size.</property>"
485 " <property name=\"wrap\">True</property>"
487 " <attribute name=\"weight\" value=\"bold\"/>"
488 " <attribute name=\"foreground\" value=\"#03e30758fb5f\"/>"
492 " <property name=\"position\">2</property>"
497 " <property name=\"position\">0</property>"
501 " <object class=\"GtkLabel\" id=\"label4\">"
502 " <property name=\"visible\">True</property>"
503 " <property name=\"label\" translatable=\"yes\">This test demonstrates how the \"width-chars\" and \"max-width-chars\"\n"
504 "properties can be used to specify the minimum requested wrap width\n"
505 "and the maximum natural wrap width respectively.</property>"
506 " <property name=\"ellipsize\">end</property>"
507 " <property name=\"width_chars\">30</property>"
509 " <attribute name=\"style\" value=\"normal\"/>"
510 " <attribute name=\"foreground\" value=\"#05470000abaf\"/>"
514 " <property name=\"position\">1</property>"
519 " <property name=\"resize\">False</property>"
520 " <property name=\"shrink\">False</property>"
524 " <object class=\"GtkLabel\" id=\"label5\">"
525 " <property name=\"visible\">True</property>"
526 " <property name=\"label\" translatable=\"yes\">Some static\n"
527 "text that shrinks.\n"
529 "You will need to stretch\n"
530 "this window quite wide\n"
531 "to see the effects.</property>"
532 " <property name=\"justify\">center</property>"
534 " <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
538 " <property name=\"resize\">True</property>"
539 " <property name=\"shrink\">True</property>"
553 test_clicked (GtkWidget *button,
554 TestInterface *interface)
556 if (!interface->window)
558 GtkBuilder *builder = gtk_builder_new ();
560 gtk_builder_add_from_string (builder, interface->interface, -1, NULL);
561 interface->window = (GtkWidget *)gtk_builder_get_object (builder, "window");
563 g_signal_connect (interface->window, "delete_event",
564 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
567 gtk_widget_show (interface->window);
574 GtkWidget *window, *vbox, *button;
577 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
578 vbox = gtk_vbox_new (FALSE, 6);
580 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
582 gtk_widget_show (vbox);
583 gtk_container_add (GTK_CONTAINER (window), vbox);
585 for (i = 0; i < G_N_ELEMENTS (interfaces); i++)
587 button = gtk_button_new_with_label (interfaces[i].name);
589 gtk_widget_set_tooltip_text (button, interfaces[i].tooltip);
591 g_signal_connect (G_OBJECT (button), "clicked",
592 G_CALLBACK (test_clicked), &interfaces[i]);
594 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
595 gtk_widget_show (button);
604 main (int argc, char *argv[])
608 gtk_init (&argc, &argv);
610 window = create_window ();
612 g_signal_connect (window, "delete-event",
613 G_CALLBACK (gtk_main_quit), window);
615 gtk_widget_show (window);