toolpalette.c 26.6 KB
Newer Older
1 2 3 4 5 6
/* Tool Palette
 *
 * A tool palette widget shows groups of toolbar items as a grid of icons
 * or a list of names.
 */

7
#include <string.h>
8
#include <gtk/gtk.h>
9 10
#include "config.h"
#include "demo-common.h"
11 12 13 14 15 16 17

static GtkWidget *window = NULL;

static void load_stock_items (GtkToolPalette *palette);
static void load_toggle_items (GtkToolPalette *palette);
static void load_special_items (GtkToolPalette *palette);

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
typedef struct _CanvasItem CanvasItem;

struct _CanvasItem
{
  GdkPixbuf *pixbuf;
  gdouble x, y;
};

static CanvasItem *drop_item = NULL;
static GList *canvas_items = NULL;

/********************************/
/* ====== Canvas drawing ====== */
/********************************/

static CanvasItem*
canvas_item_new (GtkWidget     *widget,
                 GtkToolButton *button,
                 gdouble        x,
                 gdouble        y)
{
  CanvasItem *item = NULL;
  const gchar *stock_id;
  GdkPixbuf *pixbuf;

  stock_id = gtk_tool_button_get_stock_id (button);
  pixbuf = gtk_widget_render_icon (widget, stock_id, GTK_ICON_SIZE_DIALOG, NULL);

  if (pixbuf)
    {
      item = g_slice_new0 (CanvasItem);
      item->pixbuf = pixbuf;
      item->x = x;
      item->y = y;
    }

  return item;
}

static void
canvas_item_free (CanvasItem *item)
{
  g_object_unref (item->pixbuf);
  g_slice_free (CanvasItem, item);
}

static void
canvas_item_draw (const CanvasItem *item,
                  cairo_t          *cr,
                  gboolean          preview)
{
  gdouble cx = gdk_pixbuf_get_width (item->pixbuf);
  gdouble cy = gdk_pixbuf_get_height (item->pixbuf);

  gdk_cairo_set_source_pixbuf (cr,
                               item->pixbuf,
                               item->x - cx * 0.5,
                               item->y - cy * 0.5);

  if (preview)
    cairo_paint_with_alpha (cr, 0.6);
  else
    cairo_paint (cr);
}

static gboolean
84 85
canvas_draw (GtkWidget *widget,
             cairo_t   *cr)
86 87
{
  GList *iter;
88

89
  cairo_set_source_rgb (cr, 1, 1, 1);
90
  cairo_paint (cr);
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

  for (iter = canvas_items; iter; iter = iter->next)
    canvas_item_draw (iter->data, cr, FALSE);

  if (drop_item)
    canvas_item_draw (drop_item, cr, TRUE);

  return TRUE;
}

/*****************************/
/* ====== Palette DnD ====== */
/*****************************/

static void
palette_drop_item (GtkToolItem      *drag_item,
                   GtkToolItemGroup *drop_group,
                   gint              x,
                   gint              y)
{
  GtkWidget *drag_group = gtk_widget_get_parent (GTK_WIDGET (drag_item));
  GtkToolItem *drop_item = gtk_tool_item_group_get_drop_item (drop_group, x, y);
  gint drop_position = -1;

  if (drop_item)
    drop_position = gtk_tool_item_group_get_item_position (GTK_TOOL_ITEM_GROUP (drop_group), drop_item);

  if (GTK_TOOL_ITEM_GROUP (drag_group) != drop_group)
    {
      gboolean homogeneous, expand, fill, new_row;

      g_object_ref (drag_item);
      gtk_container_child_get (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item),
                               "homogeneous", &homogeneous,
                               "expand", &expand,
                               "fill", &fill,
                               "new-row", &new_row,
                               NULL);
      gtk_container_remove (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item));
      gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (drop_group),
                                  drag_item, drop_position);
      gtk_container_child_set (GTK_CONTAINER (drop_group), GTK_WIDGET (drag_item),
                               "homogeneous", homogeneous,
                               "expand", expand,
                               "fill", fill,
                               "new-row", new_row,
                               NULL);
      g_object_unref (drag_item);
    }
  else
    gtk_tool_item_group_set_item_position (GTK_TOOL_ITEM_GROUP (drop_group),
                                           drag_item, drop_position);
}

static void
Javier Jardón's avatar
Javier Jardón committed
146 147 148
palette_drop_group (GtkToolPalette   *palette,
                    GtkToolItemGroup *drag_group,
                    GtkToolItemGroup *drop_group)
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
{
  gint drop_position = -1;

  if (drop_group)
    drop_position = gtk_tool_palette_get_group_position (palette, drop_group);

  gtk_tool_palette_set_group_position (palette, drag_group, drop_position);
}

static void
palette_drag_data_received (GtkWidget        *widget,
                            GdkDragContext   *context,
                            gint              x,
                            gint              y,
                            GtkSelectionData *selection,
164 165 166
                            guint             info,
                            guint             time,
                            gpointer          data)
167
{
168
  GtkAllocation     allocation;
Javier Jardón's avatar
Javier Jardón committed
169 170 171
  GtkToolItemGroup *drop_group = NULL;
  GtkWidget        *drag_palette = gtk_drag_get_source_widget (context);
  GtkWidget        *drag_item = NULL;
172 173 174 175 176 177

  while (drag_palette && !GTK_IS_TOOL_PALETTE (drag_palette))
    drag_palette = gtk_widget_get_parent (drag_palette);

  if (drag_palette)
    {
178 179 180 181
      drag_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (drag_palette),
                                                  selection);
      drop_group = gtk_tool_palette_get_drop_group (GTK_TOOL_PALETTE (widget),
                                                    x, y);
182 183 184
    }

  if (GTK_IS_TOOL_ITEM_GROUP (drag_item))
Javier Jardón's avatar
Javier Jardón committed
185 186 187
    palette_drop_group (GTK_TOOL_PALETTE (drag_palette),
                        GTK_TOOL_ITEM_GROUP (drag_item),
                        drop_group);
188
  else if (GTK_IS_TOOL_ITEM (drag_item) && drop_group)
189 190 191 192 193 194 195
    {
      gtk_widget_get_allocation (GTK_WIDGET (drop_group), &allocation);
      palette_drop_item (GTK_TOOL_ITEM (drag_item),
                         drop_group,
                         x - allocation.x,
                         y - allocation.y);
    }
196 197 198 199 200 201 202 203 204 205 206 207
}

/********************************/
/* ====== Passive Canvas ====== */
/********************************/

static void
passive_canvas_drag_data_received (GtkWidget        *widget,
                                   GdkDragContext   *context,
                                   gint              x,
                                   gint              y,
                                   GtkSelectionData *selection,
208 209 210
                                   guint             info,
                                   guint             time,
                                   gpointer          data)
211 212 213 214 215 216 217 218 219 220 221
{
  /* find the tool button, which is the source of this DnD operation */

  GtkWidget *palette = gtk_drag_get_source_widget (context);
  CanvasItem *canvas_item = NULL;
  GtkWidget *tool_item = NULL;

  while (palette && !GTK_IS_TOOL_PALETTE (palette))
    palette = gtk_widget_get_parent (palette);

  if (palette)
222 223
    tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
                                                selection);
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

  g_assert (NULL == drop_item);

  /* append a new canvas item when a tool button was found */

  if (GTK_IS_TOOL_ITEM (tool_item))
    canvas_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y);

  if (canvas_item)
    {
      canvas_items = g_list_append (canvas_items, canvas_item);
      gtk_widget_queue_draw (widget);
    }
}

/************************************/
/* ====== Interactive Canvas ====== */
/************************************/

static gboolean
244 245 246 247 248 249
interactive_canvas_drag_motion (GtkWidget      *widget,
                                GdkDragContext *context,
                                gint            x,
                                gint            y,
                                guint           time,
                                gpointer        data)
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
{
  if (drop_item)
    {
      /* already have a drop indicator - just update position */

      drop_item->x = x;
      drop_item->y = y;

      gtk_widget_queue_draw (widget);
      gdk_drag_status (context, GDK_ACTION_COPY, time);
    }
  else
    {
      /* request DnD data for creating a drop indicator */

      GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);

      if (!target)
        return FALSE;

      gtk_drag_get_data (widget, context, target, time);
    }

  return TRUE;
}

static void
interactive_canvas_drag_data_received (GtkWidget        *widget,
                                       GdkDragContext   *context,
                                       gint              x,
                                       gint              y,
                                       GtkSelectionData *selection,
282 283 284
                                       guint             info,
                                       guint             time,
                                       gpointer          data)
285 286

{
287
  /* find the tool button which is the source of this DnD operation */
288 289 290 291 292 293 294 295

  GtkWidget *palette = gtk_drag_get_source_widget (context);
  GtkWidget *tool_item = NULL;

  while (palette && !GTK_IS_TOOL_PALETTE (palette))
    palette = gtk_widget_get_parent (palette);

  if (palette)
296 297
    tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
                                                selection);
298 299 300 301 302 303 304 305 306 307 308 309 310 311

  /* create a drop indicator when a tool button was found */

  g_assert (NULL == drop_item);

  if (GTK_IS_TOOL_ITEM (tool_item))
    {
      drop_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y);
      gdk_drag_status (context, GDK_ACTION_COPY, time);
      gtk_widget_queue_draw (widget);
    }
}

static gboolean
312 313 314 315 316 317
interactive_canvas_drag_drop (GtkWidget      *widget,
                              GdkDragContext *context,
                              gint            x,
                              gint            y,
                              guint           time,
                              gpointer        data)
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
{
  if (drop_item)
    {
      /* turn the drop indicator into a real canvas item */

      drop_item->x = x;
      drop_item->y = y;

      canvas_items = g_list_append (canvas_items, drop_item);
      drop_item = NULL;

      /* signal the item was accepted and redraw */

      gtk_drag_finish (context, TRUE, FALSE, time);
      gtk_widget_queue_draw (widget);

      return TRUE;
    }

  return FALSE;
}

static gboolean
interactive_canvas_real_drag_leave (gpointer data)
{
  if (drop_item)
    {
      GtkWidget *widget = GTK_WIDGET (data);

      canvas_item_free (drop_item);
      drop_item = NULL;

      gtk_widget_queue_draw (widget);
    }

  return FALSE;
}

static void
357 358 359 360
interactive_canvas_drag_leave (GtkWidget      *widget,
                               GdkDragContext *context,
                               guint           time,
                               gpointer        data)
361 362 363 364 365
{
  /* defer cleanup until a potential "drag-drop" signal was received */
  g_idle_add (interactive_canvas_real_drag_leave, widget);
}

366 367 368
static void
on_combo_orientation_changed (GtkComboBox *combo_box,
                              gpointer     user_data)
369 370
{
  GtkToolPalette *palette = GTK_TOOL_PALETTE (user_data);
371
  GtkScrolledWindow *sw;
372 373
  GtkTreeModel *model = gtk_combo_box_get_model (combo_box);
  GtkTreeIter iter;
374 375
  gint val = 0;

376 377
  sw = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (GTK_WIDGET (palette)));

378
  if (!gtk_combo_box_get_active_iter (combo_box, &iter))
379 380 381
    return;

  gtk_tree_model_get (model, &iter, 1, &val, -1);
382

383
  gtk_orientable_set_orientation (GTK_ORIENTABLE (palette), val);
384 385 386 387 388

  if (val == GTK_ORIENTATION_HORIZONTAL)
    gtk_scrolled_window_set_policy (sw, GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
  else
    gtk_scrolled_window_set_policy (sw, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
389 390
}

391 392 393
static void
on_combo_style_changed (GtkComboBox *combo_box,
                        gpointer     user_data)
394 395 396 397
{
  GtkToolPalette *palette = GTK_TOOL_PALETTE (user_data);
  GtkTreeModel *model = gtk_combo_box_get_model (combo_box);
  GtkTreeIter iter;
398 399 400
  gint val = 0;

  if (!gtk_combo_box_get_active_iter (combo_box, &iter))
401 402 403
    return;

  gtk_tree_model_get (model, &iter, 1, &val, -1);
404

405 406 407 408
  if (val == -1)
    gtk_tool_palette_unset_style (palette);
  else
    gtk_tool_palette_set_style (palette, val);
409 410 411 412 413 414
}

GtkWidget *
do_toolpalette (GtkWidget *do_widget)
{
  GtkWidget *box = NULL;
415
  GtkWidget *hbox = NULL;
416
  GtkWidget *combo_orientation = NULL;
417
  GtkListStore *orientation_model = NULL;
418
  GtkWidget *combo_style = NULL;
419
  GtkListStore *style_model = NULL;
420 421 422 423
  GtkCellRenderer *cell_renderer = NULL;
  GtkTreeIter iter;
  GtkWidget *palette = NULL;
  GtkWidget *palette_scroller = NULL;
424 425 426
  GtkWidget *notebook = NULL;
  GtkWidget *contents = NULL;
  GtkWidget *contents_scroller = NULL;
427 428 429 430 431 432 433 434 435

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
                             gtk_widget_get_screen (do_widget));
      gtk_window_set_title (GTK_WINDOW (window), "Tool Palette");
      gtk_window_set_default_size (GTK_WINDOW (window), 200, 600);

436 437
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);
438 439 440 441 442
      gtk_container_set_border_width (GTK_CONTAINER (window), 8);

      /* Add widgets to control the ToolPalette appearance: */
      box = gtk_vbox_new (FALSE, 6);
      gtk_container_add (GTK_CONTAINER (window), box);
443

444
      /* Orientation combo box: */
445 446 447 448 449 450 451 452 453 454 455 456 457 458
      orientation_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
      gtk_list_store_append (orientation_model, &iter);
      gtk_list_store_set (orientation_model, &iter,
                          0, "Horizontal",
                          1, GTK_ORIENTATION_HORIZONTAL,
                          -1);
      gtk_list_store_append (orientation_model, &iter);
      gtk_list_store_set (orientation_model, &iter,
                          0, "Vertical",
                          1, GTK_ORIENTATION_VERTICAL,
                          -1);

      combo_orientation =
        gtk_combo_box_new_with_model (GTK_TREE_MODEL (orientation_model));
459
      cell_renderer = gtk_cell_renderer_text_new ();
460 461 462 463 464 465 466 467
      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_orientation),
                                  cell_renderer,
                                  TRUE);
      gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_orientation),
                                      cell_renderer,
                                      "text", 0,
                                      NULL);
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_orientation), &iter);
468
      gtk_box_pack_start (GTK_BOX (box), combo_orientation, FALSE, FALSE, 0);
469

470
      /* Style combo box: */
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
      style_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
      gtk_list_store_append (style_model, &iter);
      gtk_list_store_set (style_model, &iter,
                          0, "Text",
                          1, GTK_TOOLBAR_TEXT,
                          -1);
      gtk_list_store_append (style_model, &iter);
      gtk_list_store_set (style_model, &iter,
                          0, "Both",
                          1, GTK_TOOLBAR_BOTH,
                          -1);
      gtk_list_store_append (style_model, &iter);
      gtk_list_store_set (style_model, &iter,
                          0, "Both: Horizontal",
                          1, GTK_TOOLBAR_BOTH_HORIZ,
                          -1);
      gtk_list_store_append (style_model, &iter);
      gtk_list_store_set (style_model, &iter,
                          0, "Icons",
                          1, GTK_TOOLBAR_ICONS,
                          -1);
      gtk_list_store_append (style_model, &iter);
      gtk_list_store_set (style_model, &iter,
                          0, "Default",
                          1, -1,  /* A custom meaning for this demo. */
                          -1);
      combo_style = gtk_combo_box_new_with_model (GTK_TREE_MODEL (style_model));
498
      cell_renderer = gtk_cell_renderer_text_new ();
499 500 501 502 503 504 505 506
      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_style),
                                  cell_renderer,
                                  TRUE);
      gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_style),
                                      cell_renderer,
                                      "text", 0,
                                      NULL);
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_style), &iter);
507 508
      gtk_box_pack_start (GTK_BOX (box), combo_style, FALSE, FALSE, 0);

509 510 511
      /* Add hbox */
      hbox = gtk_hbox_new (FALSE, 5);
      gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
512

513 514
      /* Add and fill the ToolPalette: */
      palette = gtk_tool_palette_new ();
515

516 517 518
      load_stock_items (GTK_TOOL_PALETTE (palette));
      load_toggle_items (GTK_TOOL_PALETTE (palette));
      load_special_items (GTK_TOOL_PALETTE (palette));
519

520 521
      palette_scroller = gtk_scrolled_window_new (NULL, NULL);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (palette_scroller),
522 523
                                      GTK_POLICY_NEVER,
                                      GTK_POLICY_AUTOMATIC);
524
      gtk_container_set_border_width (GTK_CONTAINER (palette_scroller), 6);
525

526
      gtk_container_add (GTK_CONTAINER (palette_scroller), palette);
527
      gtk_container_add (GTK_CONTAINER (hbox), palette_scroller);
528

529
      gtk_widget_show_all (box);
530

531
      /* Connect signals: */
532 533 534 535 536
      g_signal_connect (combo_orientation, "changed",
                        G_CALLBACK (on_combo_orientation_changed), palette);
      g_signal_connect (combo_style, "changed",
                        G_CALLBACK (on_combo_style_changed), palette);

537 538
      /* Keep the widgets in sync: */
      on_combo_orientation_changed (GTK_COMBO_BOX (combo_orientation), palette);
539 540 541 542 543 544

      /* ===== notebook ===== */

      notebook = gtk_notebook_new ();
      gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
      gtk_box_pack_end (GTK_BOX(hbox), notebook, FALSE, FALSE, 0);
545

546 547 548
      /* ===== DnD for tool items ===== */

      g_signal_connect (palette, "drag-data-received",
549
                        G_CALLBACK (palette_drag_data_received), NULL);
550 551

      gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
552 553
                                      palette,
                                      GTK_DEST_DEFAULT_ALL,
554 555 556 557 558 559 560 561 562 563
                                      GTK_TOOL_PALETTE_DRAG_ITEMS |
                                      GTK_TOOL_PALETTE_DRAG_GROUPS,
                                      GDK_ACTION_MOVE);

      /* ===== passive DnD dest ===== */

      contents = gtk_drawing_area_new ();
      gtk_widget_set_app_paintable (contents, TRUE);

      g_object_connect (contents,
564
                        "signal::draw", canvas_draw, NULL,
565 566 567 568
                        "signal::drag-data-received", passive_canvas_drag_data_received, NULL,
                        NULL);

      gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
569 570
                                      contents,
                                      GTK_DEST_DEFAULT_ALL,
571 572 573 574 575
                                      GTK_TOOL_PALETTE_DRAG_ITEMS,
                                      GDK_ACTION_COPY);

      contents_scroller = gtk_scrolled_window_new (NULL, NULL);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
576 577 578 579
                                      GTK_POLICY_AUTOMATIC,
                                      GTK_POLICY_ALWAYS);
      gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (contents_scroller),
                                             contents);
580 581
      gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);

582 583
      gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                                contents_scroller,
584 585 586 587 588 589 590 591
                                gtk_label_new ("Passive DnD Mode"));

      /* ===== interactive DnD dest ===== */

      contents = gtk_drawing_area_new ();
      gtk_widget_set_app_paintable (contents, TRUE);

      g_object_connect (contents,
592
                        "signal::draw", canvas_draw, NULL,
593
                        "signal::drag-motion", interactive_canvas_drag_motion, NULL,
594
                        "signal::drag-data-received", interactive_canvas_drag_data_received, NULL,
595 596
                        "signal::drag-leave", interactive_canvas_drag_leave, NULL,
                        "signal::drag-drop", interactive_canvas_drag_drop, NULL,
597 598 599
                        NULL);

      gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette),
600 601
                                      contents,
                                      GTK_DEST_DEFAULT_HIGHLIGHT,
602 603 604 605 606
                                      GTK_TOOL_PALETTE_DRAG_ITEMS,
                                      GDK_ACTION_COPY);

      contents_scroller = gtk_scrolled_window_new (NULL, NULL);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (contents_scroller),
607 608 609 610
                                      GTK_POLICY_AUTOMATIC,
                                      GTK_POLICY_ALWAYS);
      gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (contents_scroller),
                                             contents);
611 612 613 614
      gtk_container_set_border_width (GTK_CONTAINER (contents_scroller), 6);

      gtk_notebook_append_page (GTK_NOTEBOOK (notebook), contents_scroller,
                                gtk_label_new ("Interactive DnD Mode"));
615 616
    }

617
  if (!gtk_widget_get_visible (window))
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
    {
      gtk_widget_show_all (window);
    }
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

  return window;
}


static void
load_stock_items (GtkToolPalette *palette)
{
634 635 636 637
  GtkWidget *group_af = gtk_tool_item_group_new ("Stock Icons (A-F)");
  GtkWidget *group_gn = gtk_tool_item_group_new ("Stock Icons (G-N)");
  GtkWidget *group_or = gtk_tool_item_group_new ("Stock Icons (O-R)");
  GtkWidget *group_sz = gtk_tool_item_group_new ("Stock Icons (S-Z)");
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
  GtkWidget *group = NULL;

  GtkToolItem *item;
  GSList *stock_ids;
  GSList *iter;

  stock_ids = gtk_stock_list_ids ();
  stock_ids = g_slist_sort (stock_ids, (GCompareFunc) strcmp);

  gtk_container_add (GTK_CONTAINER (palette), group_af);
  gtk_container_add (GTK_CONTAINER (palette), group_gn);
  gtk_container_add (GTK_CONTAINER (palette), group_or);
  gtk_container_add (GTK_CONTAINER (palette), group_sz);

  for (iter = stock_ids; iter; iter = g_slist_next (iter))
    {
      GtkStockItem stock_item;
      gchar *id = iter->data;

      switch (id[4])
        {
          case 'a':
            group = group_af;
            break;

          case 'g':
            group = group_gn;
            break;

          case 'o':
            group = group_or;
            break;

          case 's':
            group = group_sz;
            break;
        }

      item = gtk_tool_button_new_from_stock (id);
      gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item), id);
      gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
      gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);

      if (!gtk_stock_lookup (id, &stock_item) || !stock_item.label)
        gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), id);

      g_free (id);
    }

  g_slist_free (stock_ids);
}

static void
load_toggle_items (GtkToolPalette *palette)
{
  GSList *toggle_group = NULL;
  GtkToolItem *item;
  GtkWidget *group;
  char *label;
  int i;

699
  group = gtk_tool_item_group_new ("Radio Item");
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
  gtk_container_add (GTK_CONTAINER (palette), group);

  for (i = 1; i <= 10; ++i)
    {
      label = g_strdup_printf ("#%d", i);
      item = gtk_radio_tool_button_new (toggle_group);
      gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), label);
      g_free (label);

      gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
      toggle_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
    }
}

static GtkToolItem *
create_entry_item (const char *text)
{
  GtkToolItem *item;
  GtkWidget *entry;

  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), text);
  gtk_entry_set_width_chars (GTK_ENTRY (entry), 5);

  item = gtk_tool_item_new ();
  gtk_container_add (GTK_CONTAINER (item), entry);

  return item;
}

static void
load_special_items (GtkToolPalette *palette)
{
  GtkToolItem *item;
  GtkWidget *group;
735
  GtkWidget *label_button;
736

737
  group = gtk_tool_item_group_new (NULL);
738
  label_button = gtk_button_new_with_label ("Advanced Features");
739 740
  gtk_widget_show (label_button);
  gtk_tool_item_group_set_label_widget (GTK_TOOL_ITEM_GROUP (group),
741
                                        label_button);
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
  gtk_container_add (GTK_CONTAINER (palette), group);

  item = create_entry_item ("homogeneous=FALSE");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
                           "homogeneous", FALSE, NULL);

  item = create_entry_item ("homogeneous=FALSE, expand=TRUE");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
                           "homogeneous", FALSE, "expand", TRUE,
                           NULL);

  item = create_entry_item ("homogeneous=FALSE, expand=TRUE, fill=FALSE");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
                           "homogeneous", FALSE, "expand", TRUE,
                           "fill", FALSE, NULL);

  item = create_entry_item ("homogeneous=FALSE, expand=TRUE, new-row=TRUE");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
                           "homogeneous", FALSE, "expand", TRUE,
                           "new-row", TRUE, NULL);

  item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_UP);
  gtk_tool_item_set_tooltip_text (item, "Show on vertical palettes only");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_tool_item_set_visible_horizontal (item, FALSE);

  item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
  gtk_tool_item_set_tooltip_text (item, "Show on horizontal palettes only");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_tool_item_set_visible_vertical (item, FALSE);

  item = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE);
  gtk_tool_item_set_tooltip_text (item, "Do not show at all");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_widget_set_no_show_all (GTK_WIDGET (item), TRUE);

  item = gtk_tool_button_new_from_stock (GTK_STOCK_FULLSCREEN);
  gtk_tool_item_set_tooltip_text (item, "Expanded this item");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
  gtk_container_child_set (GTK_CONTAINER (group), GTK_WIDGET (item),
                           "homogeneous", FALSE,
                           "expand", TRUE,
                           NULL);

  item = gtk_tool_button_new_from_stock (GTK_STOCK_HELP);
  gtk_tool_item_set_tooltip_text (item, "A regular item");
  gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
}