ToolPalette


Object Hierarchy:

Gtk.ToolPalette Gtk.ToolPalette Gtk.ToolPalette Gtk.Container Gtk.Container Gtk.Container->Gtk.ToolPalette Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Container GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.ToolPalette Atk.Implementor->Gtk.Container Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.ToolPalette Gtk.Buildable->Gtk.Container Gtk.Buildable->Gtk.Widget Gtk.Orientable Gtk.Orientable Gtk.Orientable->Gtk.ToolPalette Gtk.Scrollable Gtk.Scrollable Gtk.Scrollable->Gtk.ToolPalette

Description:

[ CCode ( type_id = "gtk_tool_palette_get_type ()" ) ]
[ Version ( since = "2.20" ) ]
public class ToolPalette : Container, Implementor, Buildable, Orientable, Scrollable

A ToolPalette allows you to add ToolItems to a palette-like container with different categories and drag and drop support.

A ToolPalette is created with a call to ToolPalette.

ToolItems cannot be added directly to a ToolPalette - instead they are added to a ToolItemGroup which can than be added to a ToolPalette. To add a ToolItemGroup to a ToolPalette, use add.

GtkWidget *palette, *group;
GtkToolItem *item;

palette = gtk_tool_palette_new ();
group = gtk_tool_item_group_new (_("Test Category"));
gtk_container_add (GTK_CONTAINER (palette), group);

item = gtk_tool_button_new (NULL, _("_Open"));
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open");
gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);

The easiest way to use drag and drop with ToolPalette is to call add_drag_dest with the desired drag source palette and the desired drag target widget. Then get_drag_item can be used to get the dragged item in the drag_data_received signal handler of the drag target.

static void
passive_canvas_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection,
guint info,
guint time,
gpointer data)
{
GtkWidget *palette;
GtkWidget *item;

// Get the dragged item
palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context),
GTK_TYPE_TOOL_PALETTE);
if (palette != NULL)
item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
selection);

// Do something with item
}

GtkWidget *target, palette;

palette = gtk_tool_palette_new ();
target = gtk_drawing_area_new ();

g_signal_connect (G_OBJECT (target), "drag-data-received",
G_CALLBACK (passive_canvas_drag_data_received), NULL);
gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
GTK_DEST_DEFAULT_ALL,
GTK_TOOL_PALETTE_DRAG_ITEMS,
GDK_ACTION_COPY);

CSS nodes

GtkToolPalette has a single CSS node named toolpalette.

Example: ToolPalette:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.ToolPalette";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (150, 200);


// ToolPalette:
Gtk.ToolPalette toolpalette = new Gtk.ToolPalette ();
this.add (toolpalette);

// ItemGroup 1
Gtk.ToolItemGroup group = new Gtk.ToolItemGroup ("Group 1");
toolpalette.add (group);

Gtk.Image img = new Gtk.Image.from_icon_name ("list-add", Gtk.IconSize.SMALL_TOOLBAR);
Gtk.ToolButton toolbutton = new Gtk.ToolButton (img, null);
group.add (toolbutton);

img = new Gtk.Image.from_icon_name ("dialog-password", Gtk.IconSize.SMALL_TOOLBAR);
toolbutton = new Gtk.ToolButton (img, null);
group.add (toolbutton);

// ItemGroup 2
group = new Gtk.ToolItemGroup ("Group 2");
toolpalette.add (group);

img = new Gtk.Image.from_icon_name ("dialog-warning-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
toolbutton = new Gtk.ToolButton (img, null);
group.add (toolbutton);

img = new Gtk.Image.from_icon_name ("go-home", Gtk.IconSize.SMALL_TOOLBAR);
toolbutton = new Gtk.ToolButton (img, null);
group.add (toolbutton);

img = new Gtk.Image.from_icon_name ("help-about", Gtk.IconSize.SMALL_TOOLBAR);
toolbutton = new Gtk.ToolButton (img, null);
group.add(toolbutton);
}

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}

valac --pkg gtk+-3.0 Gtk.ToolPalette.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Static methods:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor
All known members inherited from interface Gtk.Orientable