Chapter 13. ToolPalette

# Chapter 13. ToolPalette

A `ToolPalette` is similar to a `Toolbar` but can contain a grid of items, categorized into groups. The user may hide or expand each group. As in a toolbar, the items may be displayed as only icons, as only text, or as icons with text.

The `ToolPalette`'s items might be dragged or simply activated. For instance, the user might drag objects to a canvas to create new items there. Or the user might click an item to activate a certain brush size in a drawing application.

`ToolItemGroup`s should be added to the tool palette via the base class's `Gtk::Container::add()` method, for instance like so:

    Gtk::ToolItemGroup* group_brushes =
      Gtk::manage(new Gtk::ToolItemGroup("Brushes"));
    m_ToolPalette.add(*group_brushes);

`Gtk::ToolItem`s can then be added to the group. For instance, like so:

    Gtk::ToolButton* button = Gtk::manage(new Gtk::ToolButton(icon, "Big"));
    button->set_tooltip_text("Big Brush);
    group_brushes->insert(*button);

You might then handle the `ToolButton`'s `clicked` signal. Alternatively, you could allow the item to be dragged to another widget, by calling `Gtk::ToolPalette::add_drag_dest()` and then using `Gtk::ToolPalette::get_drag_item()` in the other widget's `drag_data_received` signal handler.

ToolPalette Reference

ToolItemGroup Reference

ToolItem Reference

## Drag and Drop

Call `add_drag_dest()` to allow items or groups to be dragged from the tool palette to a particular destination widget. You can then use `get_drag_item()` to discover which ToolItem or ToolItemGroup is being dragged. You can use `dynamic_cast` to discover whether it is an item or a group. For instance, you might use this in your `drag_data_received` signal handler, to add a dropped item, or to show a suitable icon while dragging.

See the Drag and Drop chapter for general advice about Drag and Drop with gtkmm.

Examples |  | ToolPalette Example