3 /*******************************************************
5 *******************************************************/
9 SIMPLE_COLUMN_DESCRIPTION,
13 static GtkCellRenderer *cell_1 = NULL, *cell_2 = NULL, *cell_3 = NULL;
16 simple_list_model (void)
20 gtk_list_store_new (N_SIMPLE_COLUMNS,
21 G_TYPE_STRING, /* name text */
22 G_TYPE_STRING, /* icon name */
23 G_TYPE_STRING); /* description text */
25 gtk_list_store_append (store, &iter);
26 gtk_list_store_set (store, &iter,
27 SIMPLE_COLUMN_NAME, "Alice in wonderland",
28 SIMPLE_COLUMN_ICON, "gtk-execute",
29 SIMPLE_COLUMN_DESCRIPTION,
30 "Twas brillig, and the slithy toves "
31 "did gyre and gimble in the wabe; "
32 "all mimsy were the borogoves, "
33 "and the mome raths outgrabe",
36 gtk_list_store_append (store, &iter);
37 gtk_list_store_set (store, &iter,
38 SIMPLE_COLUMN_NAME, "Marry Poppins",
39 SIMPLE_COLUMN_ICON, "gtk-yes",
40 SIMPLE_COLUMN_DESCRIPTION, "Supercalifragilisticexpialidocious",
43 gtk_list_store_append (store, &iter);
44 gtk_list_store_set (store, &iter,
45 SIMPLE_COLUMN_NAME, "George Bush",
46 SIMPLE_COLUMN_ICON, "gtk-dialog-warning",
47 SIMPLE_COLUMN_DESCRIPTION, "It's a very good question, very direct, "
48 "and I'm not going to answer it",
51 gtk_list_store_append (store, &iter);
52 gtk_list_store_set (store, &iter,
53 SIMPLE_COLUMN_NAME, "Whinnie the pooh",
54 SIMPLE_COLUMN_ICON, "gtk-stop",
55 SIMPLE_COLUMN_DESCRIPTION, "The most wonderful thing about tiggers, "
56 "is tiggers are wonderful things",
59 gtk_list_store_append (store, &iter);
60 gtk_list_store_set (store, &iter,
61 SIMPLE_COLUMN_NAME, "Aleister Crowley",
62 SIMPLE_COLUMN_ICON, "gtk-about",
63 SIMPLE_COLUMN_DESCRIPTION,
64 "Thou shalt do what thou wilt shall be the whole of the law",
67 gtk_list_store_append (store, &iter);
68 gtk_list_store_set (store, &iter,
69 SIMPLE_COLUMN_NAME, "Mark Twain",
70 SIMPLE_COLUMN_ICON, "gtk-quit",
71 SIMPLE_COLUMN_DESCRIPTION,
72 "Giving up smoking is the easiest thing in the world. "
73 "I know because I've done it thousands of times.",
77 return (GtkTreeModel *)store;
81 simple_iconview (void)
86 GtkCellRenderer *renderer;
88 iconview = gtk_icon_view_new ();
89 gtk_widget_show (iconview);
91 model = simple_list_model ();
93 gtk_icon_view_set_model (GTK_ICON_VIEW (iconview), model);
94 gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (iconview), GTK_ORIENTATION_HORIZONTAL);
96 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
98 cell_1 = renderer = gtk_cell_renderer_text_new ();
99 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, FALSE, FALSE);
100 gtk_cell_area_attribute_connect (area, renderer, "text", SIMPLE_COLUMN_NAME);
102 cell_2 = renderer = gtk_cell_renderer_pixbuf_new ();
103 g_object_set (G_OBJECT (renderer), "xalign", 0.0F, NULL);
104 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, TRUE, FALSE, FALSE);
105 gtk_cell_area_attribute_connect (area, renderer, "stock-id", SIMPLE_COLUMN_ICON);
107 cell_3 = renderer = gtk_cell_renderer_text_new ();
108 g_object_set (G_OBJECT (renderer),
109 "wrap-mode", PANGO_WRAP_WORD,
112 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE, FALSE);
113 gtk_cell_area_attribute_connect (area, renderer, "text", SIMPLE_COLUMN_DESCRIPTION);
119 orientation_changed (GtkComboBox *combo,
120 GtkIconView *iconview)
122 GtkOrientation orientation = gtk_combo_box_get_active (combo);
124 gtk_icon_view_set_item_orientation (iconview, orientation);
128 align_cell_2_toggled (GtkToggleButton *toggle,
129 GtkIconView *iconview)
131 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
132 gboolean align = gtk_toggle_button_get_active (toggle);
134 gtk_cell_area_cell_set (area, cell_2, "align", align, NULL);
138 align_cell_3_toggled (GtkToggleButton *toggle,
139 GtkIconView *iconview)
141 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
142 gboolean align = gtk_toggle_button_get_active (toggle);
144 gtk_cell_area_cell_set (area, cell_3, "align", align, NULL);
148 expand_cell_1_toggled (GtkToggleButton *toggle,
149 GtkIconView *iconview)
151 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
152 gboolean expand = gtk_toggle_button_get_active (toggle);
154 gtk_cell_area_cell_set (area, cell_1, "expand", expand, NULL);
158 expand_cell_2_toggled (GtkToggleButton *toggle,
159 GtkIconView *iconview)
161 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
162 gboolean expand = gtk_toggle_button_get_active (toggle);
164 gtk_cell_area_cell_set (area, cell_2, "expand", expand, NULL);
168 expand_cell_3_toggled (GtkToggleButton *toggle,
169 GtkIconView *iconview)
171 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
172 gboolean expand = gtk_toggle_button_get_active (toggle);
174 gtk_cell_area_cell_set (area, cell_3, "expand", expand, NULL);
178 simple_cell_area (void)
180 GtkWidget *window, *widget;
181 GtkWidget *iconview, *frame, *vbox, *hbox;
183 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
185 gtk_window_set_title (GTK_WINDOW (window), "CellArea expand and alignments");
187 iconview = simple_iconview ();
189 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
190 frame = gtk_frame_new (NULL);
191 gtk_widget_show (hbox);
192 gtk_widget_show (frame);
194 gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
195 gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
197 gtk_container_add (GTK_CONTAINER (frame), iconview);
199 gtk_box_pack_end (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
201 /* Now add some controls */
202 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
203 gtk_widget_show (vbox);
204 gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
206 widget = gtk_combo_box_text_new ();
207 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
208 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
209 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
210 gtk_widget_show (widget);
211 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
213 g_signal_connect (G_OBJECT (widget), "changed",
214 G_CALLBACK (orientation_changed), iconview);
216 widget = gtk_check_button_new_with_label ("Align 2nd Cell");
217 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
218 gtk_widget_show (widget);
219 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
221 g_signal_connect (G_OBJECT (widget), "toggled",
222 G_CALLBACK (align_cell_2_toggled), iconview);
224 widget = gtk_check_button_new_with_label ("Align 3rd Cell");
225 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
226 gtk_widget_show (widget);
227 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
229 g_signal_connect (G_OBJECT (widget), "toggled",
230 G_CALLBACK (align_cell_3_toggled), iconview);
233 widget = gtk_check_button_new_with_label ("Expand 1st Cell");
234 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
235 gtk_widget_show (widget);
236 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
238 g_signal_connect (G_OBJECT (widget), "toggled",
239 G_CALLBACK (expand_cell_1_toggled), iconview);
241 widget = gtk_check_button_new_with_label ("Expand 2nd Cell");
242 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
243 gtk_widget_show (widget);
244 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
246 g_signal_connect (G_OBJECT (widget), "toggled",
247 G_CALLBACK (expand_cell_2_toggled), iconview);
249 widget = gtk_check_button_new_with_label ("Expand 3rd Cell");
250 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
251 gtk_widget_show (widget);
252 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
254 g_signal_connect (G_OBJECT (widget), "toggled",
255 G_CALLBACK (expand_cell_3_toggled), iconview);
257 gtk_container_add (GTK_CONTAINER (window), hbox);
259 gtk_widget_show (window);
262 /*******************************************************
264 *******************************************************/
265 static GtkCellRenderer *focus_renderer, *sibling_renderer;
270 FOCUS_COLUMN_STATIC_TEXT,
274 static GtkTreeModel *
275 focus_list_model (void)
278 GtkListStore *store =
279 gtk_list_store_new (N_FOCUS_COLUMNS,
280 G_TYPE_STRING, /* name text */
281 G_TYPE_BOOLEAN, /* check */
282 G_TYPE_STRING); /* static text */
284 gtk_list_store_append (store, &iter);
285 gtk_list_store_set (store, &iter,
286 FOCUS_COLUMN_NAME, "Enter a string",
287 FOCUS_COLUMN_CHECK, TRUE,
288 FOCUS_COLUMN_STATIC_TEXT, "Does it fly ?",
291 gtk_list_store_append (store, &iter);
292 gtk_list_store_set (store, &iter,
293 FOCUS_COLUMN_NAME, "Enter a string",
294 FOCUS_COLUMN_CHECK, FALSE,
295 FOCUS_COLUMN_STATIC_TEXT, "Would you put it in a toaster ?",
298 gtk_list_store_append (store, &iter);
299 gtk_list_store_set (store, &iter,
300 FOCUS_COLUMN_NAME, "Type something",
301 FOCUS_COLUMN_CHECK, FALSE,
302 FOCUS_COLUMN_STATIC_TEXT, "Does it feed on cute kittens ?",
305 return (GtkTreeModel *)store;
309 cell_toggled (GtkCellRendererToggle *cell_renderer,
311 GtkIconView *iconview)
313 GtkTreeModel *model = gtk_icon_view_get_model (iconview);
317 g_print ("Cell toggled !\n");
319 if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
322 gtk_tree_model_get (model, &iter, FOCUS_COLUMN_CHECK, &active, -1);
323 gtk_list_store_set (GTK_LIST_STORE (model), &iter, FOCUS_COLUMN_CHECK, !active, -1);
327 cell_edited (GtkCellRendererToggle *cell_renderer,
329 const gchar *new_text,
330 GtkIconView *iconview)
332 GtkTreeModel *model = gtk_icon_view_get_model (iconview);
335 g_print ("Cell edited with new text '%s' !\n", new_text);
337 if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
340 gtk_list_store_set (GTK_LIST_STORE (model), &iter, FOCUS_COLUMN_NAME, new_text, -1);
344 focus_iconview (gboolean color_bg, GtkCellRenderer **focus, GtkCellRenderer **sibling)
349 GtkCellRenderer *renderer, *toggle;
351 iconview = gtk_icon_view_new ();
352 gtk_widget_show (iconview);
354 model = focus_list_model ();
356 gtk_icon_view_set_model (GTK_ICON_VIEW (iconview), model);
357 gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (iconview), GTK_ORIENTATION_HORIZONTAL);
359 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
361 renderer = gtk_cell_renderer_text_new ();
362 g_object_set (G_OBJECT (renderer), "editable", TRUE, NULL);
363 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, TRUE, FALSE, FALSE);
364 gtk_cell_area_attribute_connect (area, renderer, "text", FOCUS_COLUMN_NAME);
367 g_object_set (G_OBJECT (renderer), "cell-background", "red", NULL);
369 g_signal_connect (G_OBJECT (renderer), "edited",
370 G_CALLBACK (cell_edited), iconview);
372 toggle = renderer = gtk_cell_renderer_toggle_new ();
373 g_object_set (G_OBJECT (renderer), "xalign", 0.0F, NULL);
374 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE, FALSE);
375 gtk_cell_area_attribute_connect (area, renderer, "active", FOCUS_COLUMN_CHECK);
378 g_object_set (G_OBJECT (renderer), "cell-background", "green", NULL);
383 g_signal_connect (G_OBJECT (renderer), "toggled",
384 G_CALLBACK (cell_toggled), iconview);
386 renderer = gtk_cell_renderer_text_new ();
387 g_object_set (G_OBJECT (renderer),
388 "wrap-mode", PANGO_WRAP_WORD,
393 g_object_set (G_OBJECT (renderer), "cell-background", "blue", NULL);
398 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE, FALSE);
399 gtk_cell_area_attribute_connect (area, renderer, "text", FOCUS_COLUMN_STATIC_TEXT);
401 gtk_cell_area_add_focus_sibling (area, toggle, renderer);
407 focus_sibling_toggled (GtkToggleButton *toggle,
408 GtkIconView *iconview)
410 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
411 gboolean active = gtk_toggle_button_get_active (toggle);
414 gtk_cell_area_add_focus_sibling (area, focus_renderer, sibling_renderer);
416 gtk_cell_area_remove_focus_sibling (area, focus_renderer, sibling_renderer);
418 gtk_widget_queue_draw (GTK_WIDGET (iconview));
423 focus_cell_area (void)
425 GtkWidget *window, *widget;
426 GtkWidget *iconview, *frame, *vbox, *hbox;
428 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
429 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
430 gtk_widget_show (hbox);
432 gtk_window_set_title (GTK_WINDOW (window), "Focus and editable cells");
434 iconview = focus_iconview (FALSE, &focus_renderer, &sibling_renderer);
436 frame = gtk_frame_new (NULL);
437 gtk_widget_show (frame);
439 gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
440 gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
442 gtk_container_add (GTK_CONTAINER (frame), iconview);
444 gtk_box_pack_end (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
446 /* Now add some controls */
447 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
448 gtk_widget_show (vbox);
449 gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
451 widget = gtk_combo_box_text_new ();
452 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
453 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
454 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
455 gtk_widget_show (widget);
456 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
458 g_signal_connect (G_OBJECT (widget), "changed",
459 G_CALLBACK (orientation_changed), iconview);
461 widget = gtk_check_button_new_with_label ("Focus Sibling");
462 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
463 gtk_widget_show (widget);
464 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
466 g_signal_connect (G_OBJECT (widget), "toggled",
467 G_CALLBACK (focus_sibling_toggled), iconview);
469 gtk_container_add (GTK_CONTAINER (window), hbox);
471 gtk_widget_show (window);
476 /*******************************************************
478 *******************************************************/
480 cell_spacing_changed (GtkSpinButton *spin_button,
481 GtkIconView *iconview)
483 GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
486 value = (gint)gtk_spin_button_get_value (spin_button);
488 gtk_cell_area_box_set_spacing (GTK_CELL_AREA_BOX (area), value);
492 row_spacing_changed (GtkSpinButton *spin_button,
493 GtkIconView *iconview)
497 value = (gint)gtk_spin_button_get_value (spin_button);
499 gtk_icon_view_set_row_spacing (iconview, value);
503 item_padding_changed (GtkSpinButton *spin_button,
504 GtkIconView *iconview)
508 value = (gint)gtk_spin_button_get_value (spin_button);
510 gtk_icon_view_set_item_padding (iconview, value);
514 background_area (void)
516 GtkWidget *window, *widget, *label, *main_vbox;
517 GtkWidget *iconview, *frame, *vbox, *hbox;
519 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
520 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
521 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
522 gtk_widget_show (hbox);
523 gtk_widget_show (main_vbox);
524 gtk_container_add (GTK_CONTAINER (window), main_vbox);
526 gtk_window_set_title (GTK_WINDOW (window), "Background Area");
528 label = gtk_label_new ("In this example, row spacing gets devided into the background area, "
529 "column spacing is added between each background area, item_padding is "
530 "prepended space distributed to the background area.");
531 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
532 gtk_label_set_width_chars (GTK_LABEL (label), 40);
533 gtk_widget_show (label);
534 gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);
536 iconview = focus_iconview (TRUE, NULL, NULL);
538 frame = gtk_frame_new (NULL);
539 gtk_widget_show (frame);
541 gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
542 gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
544 gtk_container_add (GTK_CONTAINER (frame), iconview);
546 gtk_box_pack_end (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
548 /* Now add some controls */
549 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
550 gtk_widget_show (vbox);
551 gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
552 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
554 widget = gtk_combo_box_text_new ();
555 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
556 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
557 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
558 gtk_widget_show (widget);
559 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
561 g_signal_connect (G_OBJECT (widget), "changed",
562 G_CALLBACK (orientation_changed), iconview);
564 widget = gtk_spin_button_new_with_range (0, 10, 1);
565 label = gtk_label_new ("Cell spacing");
566 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
567 gtk_widget_show (hbox);
568 gtk_widget_show (label);
569 gtk_widget_show (widget);
570 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
571 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
572 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
574 g_signal_connect (G_OBJECT (widget), "value-changed",
575 G_CALLBACK (cell_spacing_changed), iconview);
578 widget = gtk_spin_button_new_with_range (0, 10, 1);
579 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), gtk_icon_view_get_row_spacing (GTK_ICON_VIEW (iconview)));
580 label = gtk_label_new ("Row spacing");
581 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
582 gtk_widget_show (hbox);
583 gtk_widget_show (label);
584 gtk_widget_show (widget);
585 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
586 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
587 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
589 g_signal_connect (G_OBJECT (widget), "value-changed",
590 G_CALLBACK (row_spacing_changed), iconview);
592 widget = gtk_spin_button_new_with_range (0, 30, 1);
593 label = gtk_label_new ("Item padding");
594 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), gtk_icon_view_get_item_padding (GTK_ICON_VIEW (iconview)));
595 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
596 gtk_widget_show (hbox);
597 gtk_widget_show (label);
598 gtk_widget_show (widget);
599 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
600 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
601 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
603 g_signal_connect (G_OBJECT (widget), "value-changed",
604 G_CALLBACK (item_padding_changed), iconview);
606 gtk_widget_show (window);
615 main (int argc, char *argv[])
617 gtk_init (NULL, NULL);
619 if (g_getenv ("RTL"))
620 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);