summaryrefslogtreecommitdiff
path: root/tests/testextendedlayout2.c
blob: 73875ea1f26398d899d487df8b31c3aa352a212a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/* testextendedlayout2.c
 * Copyright (C) 2010 Openismus GmbH
 *
 * Author:
 *      Tristan Van Berkom <tristan.van.berkom@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <gtk/gtk.h>

typedef struct {
  const gchar *name;
  const gchar *tooltip;
  const gchar *interface;
  GtkWidget   *window;
} TestInterface;


/* These strings were generated with:
 *
 *     IFS=""; while read line; do echo -n \"; echo -n $line | sed -e 's|\"|\\"|g'; echo \"; done < file.glade
 */
TestInterface interfaces[] = {
  {
    "Ellipsizing Labels",
    "Demonstrates how labels will request a natural size in a horizontal space",
    "<interface>"
    "  <requires lib=\"gtk+\" version=\"2.20\"/>"
    "  <!-- interface-naming-policy project-wide -->"
    "  <object class=\"GtkWindow\" id=\"window\">"
    "    <property name=\"default_width\">450</property>"
    "    <property name=\"default_height\">50</property>"
    "    <child>"
    "      <object class=\"GtkHBox\" id=\"hbox5\">"
    "        <property name=\"visible\">True</property>"
    "        <child>"
    "          <object class=\"GtkLabel\" id=\"label9\">"
    "            <property name=\"visible\">True</property>"
    "            <property name=\"label\" translatable=\"yes\">Some labels do ellipsize</property>"
    "            <property name=\"ellipsize\">end</property>"
    "            <attributes>"
    "              <attribute name=\"weight\" value=\"bold\"/>"
    "              <attribute name=\"foreground\" value=\"#09610feefe03\"/>"
    "            </attributes>"
    "          </object>"
    "          <packing>"
    "            <property name=\"position\">0</property>"
    "          </packing>"
    "        </child>"
    "        <child>"
    "          <object class=\"GtkLabel\" id=\"label10\">"
    "            <property name=\"visible\">True</property>"
    "            <property name=\"label\" translatable=\"yes\">but some</property>"
    "            <property name=\"ellipsize\">end</property>"
    "            <attributes>"
    "              <attribute name=\"weight\" value=\"bold\"/>"
    "              <attribute name=\"foreground\" value=\"#0000af6b0993\"/>"
    "            </attributes>"
    "          </object>"
    "          <packing>"
    "            <property name=\"position\">1</property>"
    "          </packing>"
    "        </child>"
    "        <child>"
    "          <object class=\"GtkLabel\" id=\"label11\">"
    "            <property name=\"visible\">True</property>"
    "            <property name=\"label\" translatable=\"yes\">do not at all</property>"
    "            <attributes>"
    "              <attribute name=\"style\" value=\"normal\"/>"
    "              <attribute name=\"weight\" value=\"bold\"/>"
    "              <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
    "            </attributes>"
    "          </object>"
    "          <packing>"
    "            <property name=\"position\">2</property>"
    "          </packing>"
    "        </child>"
    "      </object>"
    "    </child>"
    "  </object>"
    "</interface>",
    NULL
  },

  {
    "Wrapping Label",
    "Demonstrates how a wrapping label can require a height contextual to its allocated width",
    "<interface>"
    "  <requires lib=\"gtk+\" version=\"2.18\"/>"
    "  <!-- interface-naming-policy project-wide -->"
    "  <object class=\"GtkWindow\" id=\"window\">"
    "    <property name=\"border_width\">12</property>"
    "    <property name=\"default_width\">300</property>"
    "    <child>"
    "      <object class=\"GtkHPaned\" id=\"hpaned1\">"
    "        <property name=\"visible\">True</property>"
    "        <property name=\"can_focus\">True</property>"
    "        <child>"
    "          <object class=\"GtkVBox\" id=\"vbox2\">"
    "            <property name=\"visible\">True</property>"
    "            <child>"
    "              <object class=\"GtkLabel\" id=\"label3\">"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"label\" translatable=\"yes\">A short static label.</property>"
    "                <attributes>"
    "                  <attribute name=\"weight\" value=\"bold\"/>"
    "                </attributes>"
    "              </object>"
    "              <packing>"
    "                <property name=\"position\">0</property>"
    "              </packing>"
    "            </child>"
    "            <child>"
    "              <object class=\"GtkLabel\" id=\"label1\">"
    "                <property name=\"visible\">True</property>"
    "                <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>"
    "                <property name=\"wrap\">True</property>"
    "                <property name=\"max_width_chars\">30</property>"
    "                <attributes>"
    "                  <attribute name=\"foreground\" value=\"#18c52119f796\"/>"
    "                </attributes>"
    "              </object>"
    "              <packing>"
    "                <property name=\"expand\">False</property>"
    "                <property name=\"position\">1</property>"
    "              </packing>"
    "            </child>"
    "            <child>"
    "              <object class=\"GtkButton\" id=\"button2\">"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"can_focus\">True</property>"
    "                <property name=\"receives_default\">True</property>"
    "                <child>"
    "                  <object class=\"GtkLabel\" id=\"label2\">"
    "                    <property name=\"visible\">True</property>"
    "                    <property name=\"label\" translatable=\"yes\">A really really long label inside a button to demonstrate height for width working inside buttons</property>"
    "                    <property name=\"wrap\">True</property>"
    "                    <property name=\"max_width_chars\">25</property>"
    "                    <attributes>"
    "                      <attribute name=\"foreground\" value=\"#1e3687ab0a52\"/>"
    "                    </attributes>"
    "                  </object>"
    "                </child>"
    "              </object>"
    "              <packing>"
    "                <property name=\"expand\">False</property>"
    "                <property name=\"position\">2</property>"
    "              </packing>"
    "            </child>"
    "          </object>"
    "          <packing>"
    "            <property name=\"resize\">False</property>"
    "            <property name=\"shrink\">False</property>"
    "          </packing>"
    "        </child>"
    "        <child>"
    "          <object class=\"GtkLabel\" id=\"label4\">"
    "            <property name=\"visible\">True</property>"
    "            <property name=\"label\" translatable=\"yes\">This static label\n"
    "can shrink.</property>"
    "            <property name=\"justify\">center</property>"
    "            <attributes>"
    "              <attribute name=\"style\" value=\"normal\"/>"
    "              <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
    "            </attributes>"
    "          </object>"
    "          <packing>"
    "            <property name=\"resize\">True</property>"
    "            <property name=\"shrink\">True</property>"
    "          </packing>"
    "        </child>"
    "      </object>"
    "    </child>"
    "  </object>"
    "</interface>",
    NULL
  },

  {
    "Horizontal Box",
    "Demonstrates how a horizontal box can calculate the collective height for an allocated width",
    "<interface>"
    "  <requires lib=\"gtk+\" version=\"2.20\"/>"
    "  <!-- interface-naming-policy project-wide -->"
    "  <object class=\"GtkWindow\" id=\"window\">"
    "    <property name=\"default_height\">200</property>"
    "    <property name=\"default_width\">600</property>"
    "    <child>"
    "      <object class=\"GtkHPaned\" id=\"hpaned1\">"
    "        <property name=\"visible\">True</property>"
    "        <property name=\"can_focus\">True</property>"
    "        <child>"
    "          <object class=\"GtkVBox\" id=\"vbox1\">"
    "            <property name=\"visible\">True</property>"
    "            <child>"
    "              <object class=\"GtkHBox\" id=\"hbox1\">"
    "                <property name=\"visible\">True</property>"
    "                <child>"
    "                  <object class=\"GtkButton\" id=\"button1\">"
    "                    <property name=\"visible\">True</property>"
    "                    <property name=\"can_focus\">True</property>"
    "                    <property name=\"receives_default\">True</property>"
    "                    <property name=\"use_action_appearance\">False</property>"
    "                    <child>"
    "                      <object class=\"GtkLabel\" id=\"label2\">"
    "                        <property name=\"visible\">True</property>"
    "                        <property name=\"label\" translatable=\"yes\">A button that wraps.</property>"
    "                        <property name=\"wrap\">True</property>"
    "                        <property name=\"width_chars\">10</property>"
    "                        <attributes>"
    "                          <attribute name=\"foreground\" value=\"#0000041dffff\"/>"
    "                        </attributes>"
    "                      </object>"
    "                    </child>"
    "                  </object>"
    "                  <packing>"
    "                    <property name=\"expand\">False</property>"
    "                    <property name=\"position\">0</property>"
    "                  </packing>"
    "                </child>"
    "                <child>"
    "                  <object class=\"GtkLabel\" id=\"label1\">"
    "                    <property name=\"visible\">True</property>"
    "                    <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>"
    "                    <property name=\"wrap\">True</property>"
    "                    <property name=\"width_chars\">30</property>"
    "                    <attributes>"
    "                      <attribute name=\"foreground\" value=\"#07d0a9b20972\"/>"
    "                    </attributes>"
    "                  </object>"
    "                  <packing>"
    "                    <property name=\"position\">1</property>"
    "                  </packing>"
    "                </child>"
    "              </object>"
    "              <packing>"
    "                <property name=\"expand\">False</property>"
    "                <property name=\"position\">0</property>"
    "              </packing>"
    "            </child>"
    "            <child>"
    "              <object class=\"GtkButton\" id=\"button2\">"
    "                <property name=\"label\" translatable=\"yes\">A button that expands in the vbox</property>"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"can_focus\">True</property>"
    "                <property name=\"receives_default\">True</property>"
    "                <property name=\"use_action_appearance\">False</property>"
    "              </object>"
    "              <packing>"
    "                <property name=\"position\">1</property>"
    "              </packing>"
    "            </child>"
    "          </object>"
    "          <packing>"
    "            <property name=\"resize\">False</property>"
    "            <property name=\"shrink\">False</property>"
    "          </packing>"
    "        </child>"
    "        <child>"
    "          <object class=\"GtkLabel\" id=\"label4\">"
    "            <property name=\"visible\">True</property>"
    "            <property name=\"label\" translatable=\"yes\">This label is\n"
    "set to shrink inside\n"
    "the paned window.</property>"
    "            <property name=\"justify\">center</property>"
    "            <attributes>"
    "              <attribute name=\"style\" value=\"normal\"/>"
    "              <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
    "            </attributes>"
    "          </object>"
    "          <packing>"
    "            <property name=\"resize\">True</property>"
    "            <property name=\"shrink\">True</property>"
    "          </packing>"
    "        </child>"
    "      </object>"
    "    </child>"
    "  </object>"
    "</interface>",
    NULL
  },

  {
    "Vertical Labels",
    "Demonstrates how a horizontal box will consider width-for-height when allocating children "
    "even if the toplevel window is requested as height-for-width.",
    "<interface>"
    "  <requires lib=\"gtk+\" version=\"2.20\"/>"
    "  <!-- interface-naming-policy project-wide -->"
    "  <object class=\"GtkWindow\" id=\"window\">"
    "    <property name=\"default_width\">400</property>"
    "    <property name=\"default_height\">300</property>"
    "    <child>"
    "      <object class=\"GtkVPaned\" id=\"vpaned1\">"
    "        <property name=\"visible\">True</property>"
    "        <property name=\"can_focus\">True</property>"
    "        <child>"
    "          <object class=\"GtkHBox\" id=\"hbox1\">"
    "            <property name=\"visible\">True</property>"
    "            <child>"
    "              <object class=\"GtkLabel\" id=\"label1\">"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"label\" translatable=\"yes\">Some long width-for-height text that wraps</property>"
    "                <property name=\"justify\">center</property>"
    "                <property name=\"wrap\">True</property>"
    "                <property name=\"width_chars\">10</property>"
    "                <property name=\"angle\">90</property>"
    "                <attributes>"
    "                  <attribute name=\"weight\" value=\"bold\"/>"
    "                  <attribute name=\"foreground\" value=\"#03e307ddfb5f\"/>"
    "                </attributes>"
    "              </object>"
    "              <packing>"
    "                <property name=\"expand\">False</property>"
    "                <property name=\"position\">0</property>"
    "              </packing>"
    "            </child>"
    "            <child>"
    "              <object class=\"GtkFrame\" id=\"frame1\">"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"label_xalign\">0</property>"
    "                <property name=\"shadow_type\">out</property>"
    "                <child>"
    "                  <object class=\"GtkLabel\" id=\"label5\">"
    "                    <property name=\"visible\">True</property>"
    "                    <property name=\"label\" translatable=\"yes\">Neither of the panes are\n"
    "set to shrink.</property>"
    "                    <property name=\"justify\">center</property>"
    "                    <attributes>"
    "                      <attribute name=\"foreground\" value=\"#ffff00000000\"/>"
    "                    </attributes>"
    "                  </object>"
    "                </child>"
    "                <child type=\"label_item\">"
    "                  <placeholder/>"
    "                </child>"
    "              </object>"
    "              <packing>"
    "                <property name=\"position\">1</property>"
    "              </packing>"
    "            </child>"
    "          </object>"
    "          <packing>"
    "            <property name=\"resize\">False</property>"
    "            <property name=\"shrink\">False</property>"
    "          </packing>"
    "        </child>"
    "        <child>"
    "          <object class=\"GtkHBox\" id=\"hbox2\">"
    "            <property name=\"visible\">True</property>"
    "            <child>"
    "              <object class=\"GtkFrame\" id=\"frame2\">"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"label_xalign\">0</property>"
    "                <property name=\"shadow_type\">out</property>"
    "                <child>"
    "                  <object class=\"GtkLabel\" id=\"label4\">"
    "                    <property name=\"visible\">True</property>"
    "                    <property name=\"label\" translatable=\"yes\">The interface is allocated as height\n"
    "for width, but the horizontal boxes\n"
    "allocate in width for height mode.</property>"
    "                    <attributes>"
    "                      <attribute name=\"foreground\" value=\"#000097970808\"/>"
    "                    </attributes>"
    "                  </object>"
    "                </child>"
    "                <child type=\"label_item\">"
    "                  <placeholder/>"
    "                </child>"
    "              </object>"
    "              <packing>"
    "                <property name=\"position\">0</property>"
    "              </packing>"
    "            </child>"
    "            <child>"
    "              <object class=\"GtkLabel\" id=\"label3\">"
    "                <property name=\"visible\">True</property>"
    "                <property name=\"label\" translatable=\"yes\">Some long width-for-height text that wraps</property>"
    "                <property name=\"justify\">center</property>"
    "                <property name=\"wrap\">True</property>"
    "                <property name=\"width_chars\">10</property>"
    "                <property name=\"angle\">270</property>"
    "                <attributes>"
    "                  <attribute name=\"weight\" value=\"bold\"/>"
    "                  <attribute name=\"foreground\" value=\"#03e307ddfb5f\"/>"
    "                </attributes>"
    "              </object>"
    "              <packing>"
    "                <property name=\"expand\">False</property>"
    "                <property name=\"position\">1</property>"
    "              </packing>"
    "            </child>"
    "          </object>"
    "          <packing>"
    "            <property name=\"resize\">False</property>"
    "            <property name=\"shrink\">False</property>"
    "          </packing>"
    "        </child>"
    "      </object>"
    "    </child>"
    "  </object>"
    "</interface>",
    NULL
  },

};


static void
test_clicked (GtkWidget     *button, 
	      TestInterface *interface)
{
  if (!interface->window)
    {
      GtkBuilder *builder = gtk_builder_new ();
      
      gtk_builder_add_from_string (builder, interface->interface, -1, NULL);
      interface->window = (GtkWidget *)gtk_builder_get_object (builder, "window");

      g_signal_connect (interface->window, "delete_event", 
			G_CALLBACK (gtk_widget_hide_on_delete), NULL);
    }

  gtk_widget_show (interface->window);
}


static GtkWidget *
create_window (void)
{
  GtkWidget *window, *vbox, *button;
  gint i;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  vbox   = gtk_vbox_new (FALSE, 6);

  gtk_container_set_border_width (GTK_CONTAINER (window), 8);

  gtk_widget_show (vbox);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  for (i = 0; i < G_N_ELEMENTS (interfaces); i++)
    {
      button = gtk_button_new_with_label (interfaces[i].name);

      gtk_widget_set_tooltip_text (button, interfaces[i].tooltip);

      g_signal_connect (G_OBJECT (button), "clicked", 
			G_CALLBACK (test_clicked), &interfaces[i]);

      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
      gtk_widget_show (button);
    }

  return window;
}



int
main (int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init (&argc, &argv);

  window = create_window ();

  g_signal_connect (window, "delete-event",
                    G_CALLBACK (gtk_main_quit), window);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}