Debian Codegraph @

demos/gtk-demo/toolpalette.c

raw
1 /* Tool Palette
2 *
3 * A tool palette widget shows groups of toolbar items as a grid of icons
4 * or a list of names.
5 */
6
7 #include <string.h>
8 #include <gtk/gtk.h>
9
10 static GtkWidget *window = NULL;
11
12 static void load_icon_items (GtkToolPalette *palette);
13 static void load_toggle_items (GtkToolPalette *palette);
14 static void load_special_items (GtkToolPalette *palette);
15
16 typedef struct _CanvasItem CanvasItem;
17
18 struct _CanvasItem
19 {
20 GdkPixbuf *pixbuf;
21 gdouble x, y;
22 };
23
24 static gboolean drag_data_requested_for_drop = FALSE;
25 static CanvasItem *drop_item = NULL;
26 static GList *canvas_items = NULL;
27
28 /********************************/
29 /* ====== Canvas drawing ====== */
30 /********************************/
31
32 static CanvasItem*
33 canvas_item_new (GtkWidget *widget,
34 GtkToolButton *button,
35 gdouble x,
36 gdouble y)
37 {
38 CanvasItem *item = NULL;
39 const gchar *icon_name;
40 GdkPixbuf *pixbuf;
41 GtkIconTheme *icon_theme;
42 int width;
43
44 icon_name = gtk_tool_button_get_icon_name (button);
45 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
46 gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &width, NULL);
47 pixbuf = gtk_icon_theme_load_icon (icon_theme,
48 icon_name,
49 width,
50 GTK_ICON_LOOKUP_GENERIC_FALLBACK,
51 NULL);
52
53 if (pixbuf)
54 {
55 item = g_slice_new0 (CanvasItem);
56 item->pixbuf = pixbuf;
57 item->x = x;
58 item->y = y;
59 }
60
61 return item;
62 }
63
64 static void
65 canvas_item_free (CanvasItem *item)
66 {
67 g_object_unref (item->pixbuf);
68 g_slice_free (CanvasItem, item);
69 }
70
71 static void
72 canvas_item_draw (const CanvasItem *item,
73 cairo_t *cr,
74 gboolean preview)
75 {
76 gdouble cx = gdk_pixbuf_get_width (item->pixbuf);
77 gdouble cy = gdk_pixbuf_get_height (item->pixbuf);
78
79 gdk_cairo_set_source_pixbuf (cr,
80 item->pixbuf,
81 item->x - cx * 0.5,
82 item->y - cy * 0.5);
83
84 if (preview)
85 cairo_paint_with_alpha (cr, 0.6);
86 else
87 cairo_paint (cr);
88 }
89
90 static gboolean
91 canvas_draw (GtkWidget *widget,
92 cairo_t *cr)
93 {
94 GList *iter;
95
96 cairo_set_source_rgb (cr, 1, 1, 1);
97 cairo_paint (cr);
98
99 for (iter = canvas_items; iter; iter = iter->next)
100 canvas_item_draw (iter->data, cr, FALSE);
101
102 if (drop_item)
103 canvas_item_draw (drop_item, cr, TRUE);
104
105 return TRUE;
106 }
107
108 /*****************************/
109 /* ====== Palette DnD ====== */
110 /*****************************/
111
112 static void
113 palette_drop_item (GtkToolItem *drag_item,
114 GtkToolItemGroup *drop_group,
115 gint x,
116 gint y)
117 {
118 GtkWidget *drag_group = gtk_widget_get_parent (GTK_WIDGET (drag_item));
119 GtkToolItem *drop_item = gtk_tool_item_group_get_drop_item (drop_group, x, y);
120 gint drop_position = -1;
121
122 if (drop_item)
123 drop_position = gtk_tool_item_group_get_item_position (GTK_TOOL_ITEM_GROUP (drop_group), drop_item);
124
125 if (GTK_TOOL_ITEM_GROUP (drag_group) != drop_group)
126 {
127 gboolean homogeneous, expand, fill, new_row;
128
129 g_object_ref (drag_item);
130 gtk_container_child_get (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item),
131 "homogeneous", &homogeneous,
132 "expand", &expand,
133 "fill", &fill,
134 "new-row", &new_row,
135 NULL);
136 gtk_container_remove (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item));
137 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (drop_group),
138 drag_item, drop_position);
139 gtk_container_child_set (GTK_CONTAINER (drop_group), GTK_WIDGET (drag_item),
140 "homogeneous", homogeneous,
141 "expand", expand,
142 "fill", fill,
143 "new-row", new_row,
144 NULL);
145 g_object_unref (drag_item);
146 }
147 else
148 gtk_tool_item_group_set_item_position (GTK_TOOL_ITEM_GROUP (drop_group),
149 drag_item, drop_position);
150 }
151
152 static void
153 palette_drop_group (GtkToolPalette *palette,
154 GtkToolItemGroup *drag_group,
155 GtkToolItemGroup *drop_group)
156 {
157 gint drop_position = -1;
158
159 if (drop_group)
160 drop_position = gtk_tool_palette_get_group_position (palette, drop_group);
161
162 gtk_tool_palette_set_group_position (palette, drag_group, drop_position);
163 }
164
165 static void
166 palette_drag_data_received (GtkWidget *widget,
167 GdkDragContext *context,
168 gint x,
169 gint y,
170 GtkSelectionData *selection,
171 guint info,
172 guint time,
173 gpointer data)
174 {
175 GtkAllocation allocation;
176 GtkToolItemGroup *drop_group = NULL;
177 GtkWidget *drag_palette = gtk_drag_get_source_widget (context);
178 GtkWidget *drag_item = NULL;
179
180 while (drag_palette && !GTK_IS_TOOL_PALETTE (drag_palette))
181 drag_palette = gtk_widget_get_parent (drag_palette);
182
183 if (drag_palette)
184 {
185 drag_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (drag_palette),
186 selection);
187 drop_group = gtk_tool_palette_get_drop_group (GTK_TOOL_PALETTE (widget),
188 x, y);
189 }
190
191 if (GTK_IS_TOOL_ITEM_GROUP (drag_item))
192 palette_drop_group (GTK_TOOL_PALETTE (drag_palette),
193 GTK_TOOL_ITEM_GROUP (drag_item),
194 drop_group);
195 else if (GTK_IS_TOOL_ITEM (drag_item) && drop_group)
196 {
197 gtk_widget_get_allocation (GTK_WIDGET (drop_group), &allocation);
198 palette_drop_item (GTK_TOOL_ITEM (drag_item),
199 drop_group,
200 x - allocation.x,
201 y - allocation.y);
202 }
203 }
204
205 /********************************/
206 /* ====== Passive Canvas ====== */
207 /********************************/
208
209 static void
210 passive_canvas_drag_data_received (GtkWidget *widget,
211 GdkDragContext *context,
212 gint x,
213 gint y,
214 GtkSelectionData *selection,
215 guint info,
216 guint time,
217 gpointer data)
218 {
219 /* find the tool button, which is the source of this DnD operation */
220
221 GtkWidget *palette = gtk_drag_get_source_widget (context);
222 CanvasItem *canvas_item = NULL;
223 GtkWidget *tool_item = NULL;
224
225 while (palette && !GTK_IS_TOOL_PALETTE (palette))
226 palette = gtk_widget_get_parent (palette);
227
228 if (palette)
229 tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
230 selection);
231
232 g_assert (NULL == drop_item);
233
234 /* append a new canvas item when a tool button was found */
235
236 if (GTK_IS_TOOL_ITEM (tool_item))
237 canvas_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y);
238
239 if (canvas_item)
240 {
241 canvas_items = g_list_append (canvas_items, canvas_item);
242 gtk_widget_queue_draw (widget);
243 }
244 }
245
246 /************************************/
247 /* ====== Interactive Canvas ====== */
248 /************************************/
249
250 static gboolean
251 interactive_canvas_drag_motion (GtkWidget *widget,
252 GdkDragContext *context,
253 gint x,
254 gint y,
255 guint time,
256 gpointer data)
257 {
258 if (drop_item)
259 {
260 /* already have a drop indicator - just update position */
261
262 drop_item->x = x;
263 drop_item->y = y;
264
265 gtk_widget_queue_draw (widget);
266 gdk_drag_status (context, GDK_ACTION_COPY, time);
267 }
268 else
269 {
270 /* request DnD data for creating a drop indicator */
271
272 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
273
274 if (!target)
275 return FALSE;
276
277 drag_data_requested_for_drop = FALSE;
278 gtk_drag_get_data (widget, context, target, time);
279 }
280
281 return TRUE;
282 }
283
284 static void
285 interactive_canvas_drag_data_received (GtkWidget *widget,
286 GdkDragContext *context,
287 gint x,
288 gint y,
289 GtkSelectionData *selection,
290 guint info,
291 guint time,
292 gpointer data)
293
294 {
295 /* find the tool button which is the source of this DnD operation */
296
297 GtkWidget *palette = gtk_drag_get_source_widget (context);
298 GtkWidget *tool_item = NULL;
299 CanvasItem *item;
300
301 while (palette && !GTK_IS_TOOL_PALETTE (palette))
302 palette = gtk_widget_get_parent (palette);
303
304 if (palette)
305 tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
306 selection);
307
308 /* create a canvas item when a tool button was found */
309
310 g_assert (NULL == drop_item);
311
312 if (!GTK_IS_TOOL_ITEM (tool_item))
313 return;
314
315 if (drop_item)
316 {
317 canvas_item_free (drop_item);
318 drop_item = NULL;
319 }
320
321 item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y);
322
323 /* Either create a new item or just create a preview item,
324 depending on why the drag data was requested. */
325 if(drag_data_requested_for_drop)
326 {
327 canvas_items = g_list_append (canvas_items, item);
328 drop_item = NULL;
329
330 gtk_drag_finish (context, TRUE, FALSE, time);
331 } else
332 {
333 drop_item = item;
334 gdk_drag_status (context, GDK_ACTION_COPY, time);
335 }
336
337 gtk_widget_queue_draw (widget);
338 }
339
340 static gboolean
341 interactive_canvas_drag_drop (GtkWidget *widget,
342 GdkDragContext *context,
343 gint x,
344 gint y,
345 guint time,
346 gpointer data)
347 {
348 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
349
350 if (!target)
351 return FALSE;
352
353 drag_data_requested_for_drop = TRUE;
354 gtk_drag_get_data (widget, context, target, time);
355
356 return FALSE;
357 }
358
359 static void
360 interactive_canvas_drag_leave (gpointer data)
361 {
362 if (drop_item)
363 {
364 GtkWidget *widget = GTK_WIDGET (data);
365
366 canvas_item_free (drop_item);
367 drop_item = NULL;
368
369 if (widget)
370 gtk_widget_queue_draw (widget);
371 }
372 }
373
374 static void
375 on_combo_orientation_changed (GtkComboBox *combo_box,
376 gpointer user_data)
377 {
378 GtkToolPalette *palette = GTK_TOOL_PALETTE (user_data);
379 GtkScrolledWindow *sw;
380 GtkTreeModel *model = gtk_combo_box_get_model (combo_box);
381 GtkTreeIter iter;
382 gint val = 0;
383
384 sw = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (GTK_WIDGET (palette)));
385
386 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
387 return;
388
389 gtk_tree_model_get (model, &iter, 1, &val, -1);
390
391 gtk_orientable_set_orientation (GTK_ORIENTABLE (palette), val);
392
393 if (val == GTK_ORIENTATION_HORIZONTAL)
394 gtk_scrolled_window_set_policy (sw, GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
395 else
396 gtk_scrolled_window_set_policy (sw, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
397 }
398
399 static void
400 on_combo_style_changed (GtkComboBox *combo_box,
401 gpointer user_data)
402 {
403 GtkToolPalette *palette = GTK_TOOL_PALETTE (user_data);
404 GtkTreeModel *model = gtk_combo_box_get_model (combo_box);
405 GtkTreeIter iter;
406 gint val = 0;
407
408 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
409 return;
410
411 gtk_tree_model_get (model, &iter, 1, &val, -1);
412
413 if (val == -1)
414 gtk_tool_palette_unset_style (palette);
415 else
416 gtk_tool_palette_set_style (palette, val);
417 }
418
419 GtkWidget *
420 do_toolpalette (GtkWidget *do_widget)
421 {
422 GtkWidget *box = NULL;
423 GtkWidget *hbox = NULL;
424 GtkWidget *combo_orientation = NULL;
425 GtkListStore *orientation_model = NULL;
426 GtkWidget *combo_style = NULL;
427 GtkListStore *style_model = NULL;
428 GtkCellRenderer *cell_renderer = NULL;
429 GtkTreeIter iter;
430 GtkWidget *palette = NULL;
431 GtkWidget *palette_scroller = NULL;
432 GtkWidget *notebook = NULL;
433 GtkWidget *contents = NULL;
434 GtkWidget *contents_scroller = NULL;
435
436 if (!window)
437 {
438 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
439 gtk_window_set_screen (GTK_WINDOW (window),
440 gtk_widget_get_screen (do_widget));
441 gtk_window_set_title (GTK_WINDOW (window), "Tool Palette");
442 gtk_window_set_default_size (GTK_WINDOW (window), 200, 600);
443
444 g_signal_connect (window, "destroy",
445 G_CALLBACK (gtk_widget_destroyed), &window);
446 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
447
448 /* Add widgets to control the ToolPalette appearance: */
449 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
450 gtk_container_add (GTK_CONTAINER (window), box);
451
452 /* Orientation combo box: */
453 orientation_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
454 gtk_list_store_append (orientation_model, &iter);
455 gtk_list_store_set (orientation_model, &iter,
456 0, "Horizontal",
457 1, GTK_ORIENTATION_HORIZONTAL,
458 -1);
459 gtk_list_store_append (orientation_model, &iter);
460 gtk_list_store_set (orientation_model, &iter,
461 0, "Vertical",
462 1, GTK_ORIENTATION_VERTICAL,
463 -1);
464
465 combo_orientation =
466 gtk_combo_box_new_with_model (GTK_TREE_MODEL (orientation_model));
467 cell_renderer = gtk_cell_renderer_text_new ();
468 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_orientation),
469 cell_renderer,
470 TRUE);
471 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_orientation),
472 cell_renderer,
473 "text", 0,
474 NULL);
475 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_orientation), &iter);
476 gtk_box_pack_start (GTK_BOX (box), combo_orientation, FALSE, FALSE, 0);
477
478 /* Style combo box: */
479 style_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
480 gtk_list_store_append (style_model, &iter);
481 gtk_list_store_set (style_model, &iter,
482 0, "Text",
483 1, GTK_TOOLBAR_TEXT,
484 -1);
485 gtk_list_store_append (style_model, &iter);
486 gtk_list_store_set (style_model, &iter,
487 0, "Both",
488 1, GTK_TOOLBAR_BOTH,
489 -1);
490 gtk_list_store_append (style_model, &iter);
491 gtk_list_store_set (style_model, &iter,
492 0, "Both: Horizontal",
493 1, GTK_TOOLBAR_BOTH_HORIZ,
494 -1);
495 gtk_list_store_append (style_model, &iter);
496 gtk_list_store_set (style_model, &iter,
497 0, "Icons",
498 1, GTK_TOOLBAR_ICONS,
499 -1);
500 gtk_list_store_append (style_model, &iter);
501 gtk_list_store_set (style_model, &iter,
502 0, "Default",
503 1, -1, /* A custom meaning for this demo. */
504 -1);
505 combo_style = gtk_combo_box_new_with_model (GTK_TREE_MODEL (style_model));
506 cell_renderer = gtk_cell_renderer_text_new ();
507 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_style),
508 cell_renderer,
509 TRUE);
510 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_style),
511 cell_renderer,
512 "text", 0,
513 NULL);
514 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_style), &iter);
515 gtk_box_pack_start (GTK_BOX (box), combo_style, FALSE, FALSE, 0);
516
517 /* Add hbox */
518 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
519 gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
520
521 /* Add and fill the ToolPalette: */
522 palette = gtk_tool_palette_new ();
523
524 load_icon_items (GTK_TOOL_PALETTE (palette));
525 load_toggle_items (GTK_TOOL_PALETTE (palette));
526 load_special_items (GTK_TOOL_PALETTE (palette));
527
528 palette_scroller = gtk_scrolled_window_new (NULL, NULL);
529 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (palette_scroller),
530 GTK_POLICY_NEVER,
531 GTK_POLICY_AUTOMATIC);
532 gtk_container_set_border_width (GTK_CONTAINER (palette_scroller), 6);
533 gtk_widget_set_hexpand (palette_scroller, TRUE);
534
535 gtk_container_add (GTK_CONTAINER (palette_scroller), palette);
536 gtk_container_add (GTK_CONTAINER (hbox), palette_scroller);
537
538 gtk_widget_show_all (box);
539
540 /* Connect signals: */
541 g_signal_connect (combo_orientation, "changed",
542 G_CALLBACK (on_combo_orientation_changed), palette);
543 g_signal_connect (combo_style, "changed",
544 G_CALLBACK (on_combo_style_changed), palette);
545
546 /* Keep the widgets in sync: */
547 on_combo_orientation_changed (GTK_COMBO_BOX (combo_orientation), palette);
548
549 /* ===== notebook ===== */
550
551 notebook = gtk_notebook_new ();
552 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
553 gtk_box_pack_end (GTK_BOX(hbox), notebook, FALSE, FALSE, 0);
554
555 /* ===== DnD for tool items ===== */
556
557 g_signal_connect (palette, "drag-data-received",
558 G_CALLBACK (palette_drag_data_received), NULL);
559
560 gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
561 palette,
562 GTK_DEST_DEFAULT_ALL,
563 GTK_TOOL_PALETTE_DRAG_ITEMS |
564 GTK_TOOL_PALETTE_DRAG_GROUPS,
565 GDK_ACTION_MOVE);
566
567 /* ===== passive DnD dest ===== */
568
569 contents = gtk_drawing_area_new ();
570 gtk_widget_set_app_paintable (contents, TRUE);
571
572 g_object_connect (contents,
573 "signal::draw", canvas_draw, NULL,
574 "signal::drag-data-received", passive_canvas_drag_data_received, NULL,
575 NULL);
576
577 gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
578 contents,
579 GTK_DEST_DEFAULT_ALL,
580 GTK_TOOL_PALETTE_DRAG_ITEMS,
581 GDK_ACTION_COPY);
582
583 contents_scroller = gtk_scrolled_window_new (NULL, NULL);
584 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
585 GTK_POLICY_AUTOMATIC,
586 GTK_POLICY_ALWAYS);
587 gtk_container_add (GTK_CONTAINER (contents_scroller), contents);
588 gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);
589
590 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
591 contents_scroller,
592 gtk_label_new ("Passive DnD Mode"));
593
594 /* ===== interactive DnD dest ===== */
595
596 contents = gtk_drawing_area_new ();
597 gtk_widget_set_app_paintable (contents, TRUE);
598
599 g_object_connect (contents,
600 "signal::draw", canvas_draw, NULL,
601 "signal::drag-motion", interactive_canvas_drag_motion, NULL,
602 "signal::drag-data-received", interactive_canvas_drag_data_received, NULL,
603 "signal::drag-leave", interactive_canvas_drag_leave, contents,
604 "signal::drag-drop", interactive_canvas_drag_drop, NULL,
605 NULL);
606
607 gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
608 contents,
609 GTK_DEST_DEFAULT_HIGHLIGHT,
610 GTK_TOOL_PALETTE_DRAG_ITEMS,
611 GDK_ACTION_COPY);
612
613 contents_scroller = gtk_scrolled_window_new (NULL, NULL);
614 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
615 GTK_POLICY_AUTOMATIC,
616 GTK_POLICY_ALWAYS);
617 gtk_container_add (GTK_CONTAINER (contents_scroller), contents);
618 gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);
619
620 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), contents_scroller,
621 gtk_label_new ("Interactive DnD Mode"));
622 }
623
624 if (!gtk_widget_get_visible (window))
625 {
626 gtk_widget_show_all (window);
627 }
628 else
629 {
630 gtk_widget_destroy (window);
631 window = NULL;
632 }
633
634 return window;
635 }
636
637
638 static void
639 load_icon_items (GtkToolPalette *palette)
640 {
641 GList *contexts;
642 GList *l;
643 GtkIconTheme *icon_theme;
644
645 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (palette)));
646
647 contexts = gtk_icon_theme_list_contexts (icon_theme);
648 for (l = contexts; l; l = l->next)
649 {
650 gchar *context = l->data;
651 GList *icon_names;
652 GList *ll;
653 const guint max_icons = 10;
654 guint icons_count = 0;
655
656 GtkWidget *group = gtk_tool_item_group_new (context);
657 gtk_container_add (GTK_CONTAINER (palette), group);
658
659 if (g_strcmp0 (context, "Animations") == 0)
660 continue;
661
662 g_message ("Got context '%s'", context);
663 icon_names = gtk_icon_theme_list_icons (icon_theme, context);
664 icon_names = g_list_sort (icon_names, (GCompareFunc) strcmp);
665
666 for (ll = icon_names; ll; ll = ll->next)
667 {
668 GtkToolItem *item;
669 gchar *id = ll->data;
670
671 if (g_str_equal (id, "emblem-desktop"))
672 continue;
673
674 if (g_str_has_suffix (id, "-symbolic"))
675 continue;
676
677 g_message ("Got id '%s'", id);
678
679 item = gtk_tool_button_new (NULL, NULL);
680 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), id);
681 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item), id);
682 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
683
684 /* Prevent us having an insane number of icons: */
685 ++icons_count;
686 if(icons_count >= max_icons)
687 break;
688 }
689
690 g_list_free_full (icon_names, g_free);
691 }
692
693 g_list_free_full (contexts, g_free);
694 }
695
696 static void
697 load_toggle_items (GtkToolPalette *palette)
698 {
699 GSList *toggle_group = NULL;
700 GtkToolItem *item;
701 GtkWidget *group;
702 char *label;
703 int i;
704
705 group = gtk_tool_item_group_new ("Radio Item");
706 gtk_container_add (GTK_CONTAINER (palette), group);
707
708 for (i = 1; i <= 10; ++i)
709 {
710 label = g_strdup_printf ("#%d", i);
711 item = gtk_radio_tool_button_new (toggle_group);
712 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), label);
713 g_free (label);
714
715 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
716 toggle_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
717 }
718 }
719
720 static GtkToolItem *
721 create_entry_item (const char *text)
722 {
723 GtkToolItem *item;
724 GtkWidget *entry;
725
726 entry = gtk_entry_new ();
727 gtk_entry_set_text (GTK_ENTRY (entry), text);
728 gtk_entry_set_width_chars (GTK_ENTRY (entry), 5);
729
730 item = gtk_tool_item_new ();
731 gtk_container_add (GTK_CONTAINER (item), entry);
732
733 return item;
734 }
735
736 static void
737 load_special_items (GtkToolPalette *palette)
738 {
739 GtkToolItem *item;
740 GtkWidget *group;
741 GtkWidget *label_button;
742
743 group = gtk_tool_item_group_new (NULL);
744 label_button = gtk_button_new_with_label ("Advanced Features");
745 gtk_widget_show (label_button);
746 gtk_tool_item_group_set_label_widget (GTK_TOOL_ITEM_GROUP (group),
747 label_button);
748 gtk_container_add (GTK_CONTAINER (palette), group);
749
750 item = create_entry_item ("homogeneous=FALSE");
751 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
752 gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
753 "homogeneous", FALSE, NULL);
754
755 item = create_entry_item ("homogeneous=FALSE, expand=TRUE");
756 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
757 gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
758 "homogeneous", FALSE, "expand", TRUE,
759 NULL);
760
761 item = create_entry_item ("homogeneous=FALSE, expand=TRUE, fill=FALSE");
762 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
763 gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
764 "homogeneous", FALSE, "expand", TRUE,
765 "fill", FALSE, NULL);
766
767 item = create_entry_item ("homogeneous=FALSE, expand=TRUE, new-row=TRUE");
768 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
769 gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
770 "homogeneous", FALSE, "expand", TRUE,
771 "new-row", TRUE, NULL);
772
773 item = gtk_tool_button_new (NULL, NULL);
774 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-up");
775 gtk_tool_item_set_tooltip_text (item, "Show on vertical palettes only");
776 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
777 gtk_tool_item_set_visible_horizontal (item, FALSE);
778
779 item = gtk_tool_button_new (NULL, NULL);
780 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-next");
781 gtk_tool_item_set_tooltip_text (item, "Show on horizontal palettes only");
782 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
783 gtk_tool_item_set_visible_vertical (item, FALSE);
784
785 item = gtk_tool_button_new (NULL, NULL);
786 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "edit-delete");
787 gtk_tool_item_set_tooltip_text (item, "Do not show at all");
788 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
789 gtk_widget_set_no_show_all (GTK_WIDGET (item), TRUE);
790
791 item = gtk_tool_button_new (NULL, NULL);
792 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "view-fullscreen");
793 gtk_tool_item_set_tooltip_text (item, "Expanded this item");
794 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
795 gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
796 "homogeneous", FALSE,
797 "expand", TRUE,
798 NULL);
799
800 item = gtk_tool_button_new (NULL, NULL);
801 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "help-browser");
802 gtk_tool_item_set_tooltip_text (item, "A regular item");
803 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
804 }