Debian Codegraph @

demos/gtk-demo/toolpalette.c

raw symbols SCIP
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 #include "config.h"
10 #include "demo-common.h"
11
12 static GtkWidget *window = NULL;
13
14 static void load_stock_items (GtkToolPalette *palette);
15 static void load_toggle_items (GtkToolPalette *palette);
16 static void load_special_items (GtkToolPalette *palette);
17
18 typedef struct _CanvasItem CanvasItem;
19
20 struct _CanvasItem
21 {
22 GdkPixbuf *pixbuf;
23 gdouble x, y;
24 };
25
26 static CanvasItem *drop_item = NULL;
27 static GList *canvas_items = NULL;
28
29 /********************************/
30 /* ====== Canvas drawing ====== */
31 /********************************/
32
33 static CanvasItem*
34 canvas_item_new (GtkWidget *widget,
35 GtkToolButton *button,
36 gdouble x,
37 gdouble y)
38 {
39 CanvasItem *item = NULL;
40 const gchar *stock_id;
41 GdkPixbuf *pixbuf;
42
43 stock_id = gtk_tool_button_get_stock_id (button);
44 pixbuf = gtk_widget_render_icon (widget, stock_id, GTK_ICON_SIZE_DIALOG, NULL);
45
46 if (pixbuf)
47 {
48 item = g_slice_new0 (CanvasItem);
49 item->pixbuf = pixbuf;
50 item->x = x;
51 item->y = y;
52 }
53
54 return item;
55 }
56
57 static void
58 canvas_item_free (CanvasItem *item)
59 {
60 g_object_unref (item->pixbuf);
61 g_slice_free (CanvasItem, item);
62 }
63
64 static void
65 canvas_item_draw (const CanvasItem *item,
66 cairo_t *cr,
67 gboolean preview)
68 {
69 gdouble cx = gdk_pixbuf_get_width (item->pixbuf);
70 gdouble cy = gdk_pixbuf_get_height (item->pixbuf);
71
72 gdk_cairo_set_source_pixbuf (cr,
73 item->pixbuf,
74 item->x - cx * 0.5,
75 item->y - cy * 0.5);
76
77 if (preview)
78 cairo_paint_with_alpha (cr, 0.6);
79 else
80 cairo_paint (cr);
81 }
82
83 static gboolean
84 canvas_expose_event (GtkWidget *widget,
85 GdkEventExpose *event)
86 {
87 cairo_t *cr;
88 GList *iter;
89 GtkAllocation allocation;
90
91 cr = gdk_cairo_create (gtk_widget_get_window (widget));
92 gdk_cairo_region (cr, event->region);
93 cairo_clip (cr);
94
95 gtk_widget_get_allocation (widget, &allocation);
96 cairo_set_source_rgb (cr, 1, 1, 1);
97 cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
98 cairo_fill (cr);
99
100 for (iter = canvas_items; iter; iter = iter->next)
101 canvas_item_draw (iter->data, cr, FALSE);
102
103 if (drop_item)
104 canvas_item_draw (drop_item, cr, TRUE);
105
106 cairo_destroy (cr);
107
108 return TRUE;
109 }
110
111 /*****************************/
112 /* ====== Palette DnD ====== */
113 /*****************************/
114
115 static void
116 palette_drop_item (GtkToolItem *drag_item,
117 GtkToolItemGroup *drop_group,
118 gint x,
119 gint y)
120 {
121 GtkWidget *drag_group = gtk_widget_get_parent (GTK_WIDGET (drag_item));
122 GtkToolItem *drop_item = gtk_tool_item_group_get_drop_item (drop_group, x, y);
123 gint drop_position = -1;
124
125 if (drop_item)
126 drop_position = gtk_tool_item_group_get_item_position (GTK_TOOL_ITEM_GROUP (drop_group), drop_item);
127
128 if (GTK_TOOL_ITEM_GROUP (drag_group) != drop_group)
129 {
130 gboolean homogeneous, expand, fill, new_row;
131
132 g_object_ref (drag_item);
133 gtk_container_child_get (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item),
134 "homogeneous", &homogeneous,
135 "expand", &expand,
136 "fill", &fill,
137 "new-row", &new_row,
138 NULL);
139 gtk_container_remove (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item));
140 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (drop_group),
141 drag_item, drop_position);
142 gtk_container_child_set (GTK_CONTAINER (drop_group), GTK_WIDGET (drag_item),
143 "homogeneous", homogeneous,
144 "expand", expand,
145 "fill", fill,
146 "new-row", new_row,
147 NULL);
148 g_object_unref (drag_item);
149 }
150 else
151 gtk_tool_item_group_set_item_position (GTK_TOOL_ITEM_GROUP (drop_group),
152 drag_item, drop_position);
153 }
154
155 static void
156 palette_drop_group (GtkToolPalette *palette,
157 GtkToolItemGroup *drag_group,
158 GtkToolItemGroup *drop_group)
159 {
160 gint drop_position = -1;
161
162 if (drop_group)
163 drop_position = gtk_tool_palette_get_group_position (palette, drop_group);
164
165 gtk_tool_palette_set_group_position (palette, drag_group, drop_position);
166 }
167
168 static void
169 palette_drag_data_received (GtkWidget *widget,
170 GdkDragContext *context,
171 gint x,
172 gint y,
173 GtkSelectionData *selection,
174 guint info,
175 guint time,
176 gpointer data)
177 {
178 GtkToolItemGroup *drop_group = NULL;
179 GtkWidget *drag_palette = gtk_drag_get_source_widget (context);
180 GtkWidget *drag_item = NULL;
181 GtkAllocation allocation;
182
183 while (drag_palette && !GTK_IS_TOOL_PALETTE (drag_palette))
184 drag_palette = gtk_widget_get_parent (drag_palette);
185
186 if (drag_palette)
187 {
188 drag_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (drag_palette),
189 selection);
190 drop_group = gtk_tool_palette_get_drop_group (GTK_TOOL_PALETTE (widget),
191 x, y);
192 gtk_widget_get_allocation (GTK_WIDGET (drop_group), &allocation);
193 }
194
195 if (GTK_IS_TOOL_ITEM_GROUP (drag_item))
196 palette_drop_group (GTK_TOOL_PALETTE (drag_palette),
197 GTK_TOOL_ITEM_GROUP (drag_item),
198 drop_group);
199 else if (GTK_IS_TOOL_ITEM (drag_item) && drop_group)
200 palette_drop_item (GTK_TOOL_ITEM (drag_item),
201 drop_group,
202 x - allocation.x,
203 y - allocation.y);
204 }
205
206 /********************************/
207 /* ====== Passive Canvas ====== */
208 /********************************/
209
210 static void
211 passive_canvas_drag_data_received (GtkWidget *widget,
212 GdkDragContext *context,
213 gint x,
214 gint y,
215 GtkSelectionData *selection,
216 guint info,
217 guint time,
218 gpointer data)
219 {
220 /* find the tool button, which is the source of this DnD operation */
221
222 GtkWidget *palette = gtk_drag_get_source_widget (context);
223 CanvasItem *canvas_item = NULL;
224 GtkWidget *tool_item = NULL;
225
226 while (palette && !GTK_IS_TOOL_PALETTE (palette))
227 palette = gtk_widget_get_parent (palette);
228
229 if (palette)
230 tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
231 selection);
232
233 g_assert (NULL == drop_item);
234
235 /* append a new canvas item when a tool button was found */
236
237 if (GTK_IS_TOOL_ITEM (tool_item))
238 canvas_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y);
239
240 if (canvas_item)
241 {
242 canvas_items = g_list_append (canvas_items, canvas_item);
243 gtk_widget_queue_draw (widget);
244 }
245 }
246
247 /************************************/
248 /* ====== Interactive Canvas ====== */
249 /************************************/
250
251 static gboolean
252 interactive_canvas_drag_motion (GtkWidget *widget,
253 GdkDragContext *context,
254 gint x,
255 gint y,
256 guint time,
257 gpointer data)
258 {
259 if (drop_item)
260 {
261 /* already have a drop indicator - just update position */
262
263 drop_item->x = x;
264 drop_item->y = y;
265
266 gtk_widget_queue_draw (widget);
267 gdk_drag_status (context, GDK_ACTION_COPY, time);
268 }
269 else
270 {
271 /* request DnD data for creating a drop indicator */
272
273 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
274
275 if (!target)
276 return FALSE;
277
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
300 while (palette && !GTK_IS_TOOL_PALETTE (palette))
301 palette = gtk_widget_get_parent (palette);
302
303 if (palette)
304 tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
305 selection);
306
307 /* create a drop indicator when a tool button was found */
308
309 g_assert (NULL == drop_item);
310
311 if (GTK_IS_TOOL_ITEM (tool_item))
312 {
313 drop_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y);
314 gdk_drag_status (context, GDK_ACTION_COPY, time);
315 gtk_widget_queue_draw (widget);
316 }
317 }
318
319 static gboolean
320 interactive_canvas_drag_drop (GtkWidget *widget,
321 GdkDragContext *context,
322 gint x,
323 gint y,
324 guint time,
325 gpointer data)
326 {
327 if (drop_item)
328 {
329 /* turn the drop indicator into a real canvas item */
330
331 drop_item->x = x;
332 drop_item->y = y;
333
334 canvas_items = g_list_append (canvas_items, drop_item);
335 drop_item = NULL;
336
337 /* signal the item was accepted and redraw */
338
339 gtk_drag_finish (context, TRUE, FALSE, time);
340 gtk_widget_queue_draw (widget);
341
342 return TRUE;
343 }
344
345 return FALSE;
346 }
347
348 static gboolean
349 interactive_canvas_real_drag_leave (gpointer data)
350 {
351 if (drop_item)
352 {
353 GtkWidget *widget = GTK_WIDGET (data);
354
355 canvas_item_free (drop_item);
356 drop_item = NULL;
357
358 gtk_widget_queue_draw (widget);
359 }
360
361 return FALSE;
362 }
363
364 static void
365 interactive_canvas_drag_leave (GtkWidget *widget,
366 GdkDragContext *context,
367 guint time,
368 gpointer data)
369 {
370 /* defer cleanup until a potential "drag-drop" signal was received */
371 g_idle_add (interactive_canvas_real_drag_leave, widget);
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 = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (GTK_WIDGET (palette)));
380 GtkTreeModel *model = gtk_combo_box_get_model (combo_box);
381 GtkTreeIter iter;
382 gint val = 0;
383
384 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
385 return;
386
387 gtk_tree_model_get (model, &iter, 1, &val, -1);
388
389 gtk_orientable_set_orientation (GTK_ORIENTABLE (palette), val);
390
391 if (val == GTK_ORIENTATION_HORIZONTAL)
392 gtk_scrolled_window_set_policy (sw, GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
393 else
394 gtk_scrolled_window_set_policy (sw, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
395 }
396
397 static void
398 on_combo_style_changed (GtkComboBox *combo_box,
399 gpointer user_data)
400 {
401 GtkToolPalette *palette = GTK_TOOL_PALETTE (user_data);
402 GtkTreeModel *model = gtk_combo_box_get_model (combo_box);
403 GtkTreeIter iter;
404 gint val = 0;
405
406 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
407 return;
408
409 gtk_tree_model_get (model, &iter, 1, &val, -1);
410
411 if (val == -1)
412 gtk_tool_palette_unset_style (palette);
413 else
414 gtk_tool_palette_set_style (palette, val);
415 }
416
417 GtkWidget *
418 do_toolpalette (GtkWidget *do_widget)
419 {
420 GtkWidget *box = NULL;
421 GtkWidget *hbox = NULL;
422 GtkWidget *combo_orientation = NULL;
423 GtkListStore *orientation_model = NULL;
424 GtkWidget *combo_style = NULL;
425 GtkListStore *style_model = NULL;
426 GtkCellRenderer *cell_renderer = NULL;
427 GtkTreeIter iter;
428 GtkWidget *palette = NULL;
429 GtkWidget *palette_scroller = NULL;
430 GtkWidget *notebook = NULL;
431 GtkWidget *contents = NULL;
432 GtkWidget *contents_scroller = NULL;
433
434 if (!window)
435 {
436 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
437 gtk_window_set_screen (GTK_WINDOW (window),
438 gtk_widget_get_screen (do_widget));
439 gtk_window_set_title (GTK_WINDOW (window), "Tool Palette");
440 gtk_window_set_default_size (GTK_WINDOW (window), 200, 600);
441
442 g_signal_connect (window, "destroy",
443 G_CALLBACK (gtk_widget_destroyed), &window);
444 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
445
446 /* Add widgets to control the ToolPalette appearance: */
447 box = gtk_vbox_new (FALSE, 6);
448 gtk_container_add (GTK_CONTAINER (window), box);
449
450 /* Orientation combo box: */
451 orientation_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
452 gtk_list_store_append (orientation_model, &iter);
453 gtk_list_store_set (orientation_model, &iter,
454 0, "Horizontal",
455 1, GTK_ORIENTATION_HORIZONTAL,
456 -1);
457 gtk_list_store_append (orientation_model, &iter);
458 gtk_list_store_set (orientation_model, &iter,
459 0, "Vertical",
460 1, GTK_ORIENTATION_VERTICAL,
461 -1);
462
463 combo_orientation =
464 gtk_combo_box_new_with_model (GTK_TREE_MODEL (orientation_model));
465 cell_renderer = gtk_cell_renderer_text_new ();
466 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_orientation),
467 cell_renderer,
468 TRUE);
469 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_orientation),
470 cell_renderer,
471 "text", 0,
472 NULL);
473 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_orientation), &iter);
474 gtk_box_pack_start (GTK_BOX (box), combo_orientation, FALSE, FALSE, 0);
475
476 /* Style combo box: */
477 style_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
478 gtk_list_store_append (style_model, &iter);
479 gtk_list_store_set (style_model, &iter,
480 0, "Text",
481 1, GTK_TOOLBAR_TEXT,
482 -1);
483 gtk_list_store_append (style_model, &iter);
484 gtk_list_store_set (style_model, &iter,
485 0, "Both",
486 1, GTK_TOOLBAR_BOTH,
487 -1);
488 gtk_list_store_append (style_model, &iter);
489 gtk_list_store_set (style_model, &iter,
490 0, "Both: Horizontal",
491 1, GTK_TOOLBAR_BOTH_HORIZ,
492 -1);
493 gtk_list_store_append (style_model, &iter);
494 gtk_list_store_set (style_model, &iter,
495 0, "Icons",
496 1, GTK_TOOLBAR_ICONS,
497 -1);
498 gtk_list_store_append (style_model, &iter);
499 gtk_list_store_set (style_model, &iter,
500 0, "Default",
501 1, -1, /* A custom meaning for this demo. */
502 -1);
503 combo_style = gtk_combo_box_new_with_model (GTK_TREE_MODEL (style_model));
504 cell_renderer = gtk_cell_renderer_text_new ();
505 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_style),
506 cell_renderer,
507 TRUE);
508 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_style),
509 cell_renderer,
510 "text", 0,
511 NULL);
512 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_style), &iter);
513 gtk_box_pack_start (GTK_BOX (box), combo_style, FALSE, FALSE, 0);
514
515 /* Add hbox */
516 hbox = gtk_hbox_new (FALSE, 5);
517 gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
518
519 /* Add and fill the ToolPalette: */
520 palette = gtk_tool_palette_new ();
521
522 load_stock_items (GTK_TOOL_PALETTE (palette));
523 load_toggle_items (GTK_TOOL_PALETTE (palette));
524 load_special_items (GTK_TOOL_PALETTE (palette));
525
526 palette_scroller = gtk_scrolled_window_new (NULL, NULL);
527 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (palette_scroller),
528 GTK_POLICY_NEVER,
529 GTK_POLICY_AUTOMATIC);
530 gtk_container_set_border_width (GTK_CONTAINER (palette_scroller), 6);
531
532 gtk_container_add (GTK_CONTAINER (palette_scroller), palette);
533 gtk_container_add (GTK_CONTAINER (hbox), palette_scroller);
534
535 gtk_widget_show_all (box);
536
537 /* Connect signals: */
538 g_signal_connect (combo_orientation, "changed",
539 G_CALLBACK (on_combo_orientation_changed), palette);
540 g_signal_connect (combo_style, "changed",
541 G_CALLBACK (on_combo_style_changed), palette);
542
543 /* Keep the widgets in sync: */
544 on_combo_orientation_changed (GTK_COMBO_BOX (combo_orientation), palette);
545
546 /* ===== notebook ===== */
547
548 notebook = gtk_notebook_new ();
549 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
550 gtk_box_pack_end (GTK_BOX(hbox), notebook, FALSE, FALSE, 0);
551
552 /* ===== DnD for tool items ===== */
553
554 g_signal_connect (palette, "drag-data-received",
555 G_CALLBACK (palette_drag_data_received), NULL);
556
557 gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
558 palette,
559 GTK_DEST_DEFAULT_ALL,
560 GTK_TOOL_PALETTE_DRAG_ITEMS |
561 GTK_TOOL_PALETTE_DRAG_GROUPS,
562 GDK_ACTION_MOVE);
563
564 /* ===== passive DnD dest ===== */
565
566 contents = gtk_drawing_area_new ();
567 gtk_widget_set_app_paintable (contents, TRUE);
568
569 g_object_connect (contents,
570 "signal::expose-event", canvas_expose_event, NULL,
571 "signal::drag-data-received", passive_canvas_drag_data_received, NULL,
572 NULL);
573
574 gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
575 contents,
576 GTK_DEST_DEFAULT_ALL,
577 GTK_TOOL_PALETTE_DRAG_ITEMS,
578 GDK_ACTION_COPY);
579
580 contents_scroller = gtk_scrolled_window_new (NULL, NULL);
581 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
582 GTK_POLICY_AUTOMATIC,
583 GTK_POLICY_ALWAYS);
584 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (contents_scroller),
585 contents);
586 gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);
587
588 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
589 contents_scroller,
590 gtk_label_new ("Passive DnD Mode"));
591
592 /* ===== interactive DnD dest ===== */
593
594 contents = gtk_drawing_area_new ();
595 gtk_widget_set_app_paintable (contents, TRUE);
596
597 g_object_connect (contents,
598 "signal::expose-event", canvas_expose_event, NULL,
599 "signal::drag-motion", interactive_canvas_drag_motion, NULL,
600 "signal::drag-data-received", interactive_canvas_drag_data_received, NULL,
601 "signal::drag-leave", interactive_canvas_drag_leave, NULL,
602 "signal::drag-drop", interactive_canvas_drag_drop, NULL,
603 NULL);
604
605 gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
606 contents,
607 GTK_DEST_DEFAULT_HIGHLIGHT,
608 GTK_TOOL_PALETTE_DRAG_ITEMS,
609 GDK_ACTION_COPY);
610
611 contents_scroller = gtk_scrolled_window_new (NULL, NULL);
612 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
613 GTK_POLICY_AUTOMATIC,
614 GTK_POLICY_ALWAYS);
615 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (contents_scroller),
616 contents);
617 gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);
618
619 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), contents_scroller,
620 gtk_label_new ("Interactive DnD Mode"));
621 }
622
623 if (!gtk_widget_get_visible (window))
624 {
625 gtk_widget_show_all (window);
626 }
627 else
628 {
629 gtk_widget_destroy (window);
630 window = NULL;
631 }
632
633 return window;
634 }
635
636
637 static void
638 load_stock_items (GtkToolPalette *palette)
639 {
640 GtkWidget *group_af = gtk_tool_item_group_new ("Stock Icons (A-F)");
641 GtkWidget *group_gn = gtk_tool_item_group_new ("Stock Icons (G-N)");
642 GtkWidget *group_or = gtk_tool_item_group_new ("Stock Icons (O-R)");
643 GtkWidget *group_sz = gtk_tool_item_group_new ("Stock Icons (S-Z)");
644 GtkWidget *group = NULL;
645
646 GtkToolItem *item;
647 GSList *stock_ids;
648 GSList *iter;
649
650 stock_ids = gtk_stock_list_ids ();
651 stock_ids = g_slist_sort (stock_ids, (GCompareFunc) strcmp);
652
653 gtk_container_add (GTK_CONTAINER (palette), group_af);
654 gtk_container_add (GTK_CONTAINER (palette), group_gn);
655 gtk_container_add (GTK_CONTAINER (palette), group_or);
656 gtk_container_add (GTK_CONTAINER (palette), group_sz);
657
658 for (iter = stock_ids; iter; iter = g_slist_next (iter))
659 {
660 GtkStockItem stock_item;
661 gchar *id = iter->data;
662
663 switch (id[4])
664 {
665 case 'a':
666 group = group_af;
667 break;
668
669 case 'g':
670 group = group_gn;
671 break;
672
673 case 'o':
674 group = group_or;
675 break;
676
677 case 's':
678 group = group_sz;
679 break;
680 }
681
682 item = gtk_tool_button_new_from_stock (id);
683 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item), id);
684 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
685 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
686
687 if (!gtk_stock_lookup (id, &stock_item) || !stock_item.label)
688 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), id);
689
690 g_free (id);
691 }
692
693 g_slist_free (stock_ids);
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_from_stock (GTK_STOCK_GO_UP);
774 gtk_tool_item_set_tooltip_text (item, "Show on vertical palettes only");
775 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
776 gtk_tool_item_set_visible_horizontal (item, FALSE);
777
778 item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
779 gtk_tool_item_set_tooltip_text (item, "Show on horizontal palettes only");
780 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
781 gtk_tool_item_set_visible_vertical (item, FALSE);
782
783 item = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE);
784 gtk_tool_item_set_tooltip_text (item, "Do not show at all");
785 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
786 gtk_widget_set_no_show_all (GTK_WIDGET (item), TRUE);
787
788 item = gtk_tool_button_new_from_stock (GTK_STOCK_FULLSCREEN);
789 gtk_tool_item_set_tooltip_text (item, "Expanded this item");
790 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
791 gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
792 "homogeneous", FALSE,
793 "expand", TRUE,
794 NULL);
795
796 item = gtk_tool_button_new_from_stock (GTK_STOCK_HELP);
797 gtk_tool_item_set_tooltip_text (item, "A regular item");
798 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
799 }