CtkToolPalette

CtkToolPalette — A tool palette with categories

Functions

Properties

CtkIconSize icon-size Read / Write
gboolean icon-size-set Read / Write
CtkToolbarStyle toolbar-style Read / Write

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkContainer
                ╰── CtkToolPalette

Implemented Interfaces

CtkToolPalette implements AtkImplementorIface, CtkBuildable, CtkOrientable and CtkScrollable.

Includes

#include <ctk/ctk.h>

Description

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

A CtkToolPalette is created with a call to ctk_tool_palette_new().

CtkToolItems cannot be added directly to a CtkToolPalette - instead they are added to a CtkToolItemGroup which can than be added to a CtkToolPalette. To add a CtkToolItemGroup to a CtkToolPalette, use ctk_container_add().

1
2
3
4
5
6
7
8
9
10
CtkWidget *palette, *group;
CtkToolItem *item;

palette = ctk_tool_palette_new ();
group = ctk_tool_item_group_new (_("Test Category"));
ctk_container_add (CTK_CONTAINER (palette), group);

item = ctk_tool_button_new (NULL, _("_Open"));
ctk_tool_button_set_icon_name (CTK_TOOL_BUTTON (item), "document-open");
ctk_tool_item_group_insert (CTK_TOOL_ITEM_GROUP (group), item, -1);

The easiest way to use drag and drop with CtkToolPalette is to call ctk_tool_palette_add_drag_dest() with the desired drag source palette and the desired drag target widget . Then ctk_tool_palette_get_drag_item() can be used to get the dragged item in the “drag-data-received” signal handler of the drag target.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
static void
passive_canvas_drag_data_received (CtkWidget        *widget,
                                   CdkDragContext   *context,
                                   gint              x,
                                   gint              y,
                                   CtkSelectionData *selection,
                                   guint             info,
                                   guint             time,
                                   gpointer          data)
{
  CtkWidget *palette;
  CtkWidget *item;

  // Get the dragged item
  palette = ctk_widget_get_ancestor (ctk_drag_get_source_widget (context),
                                     CTK_TYPE_TOOL_PALETTE);
  if (palette != NULL)
    item = ctk_tool_palette_get_drag_item (CTK_TOOL_PALETTE (palette),
                                           selection);

  // Do something with item
}

CtkWidget *target, palette;

palette = ctk_tool_palette_new ();
target = ctk_drawing_area_new ();

g_signal_connect (G_OBJECT (target), "drag-data-received",
                  G_CALLBACK (passive_canvas_drag_data_received), NULL);
ctk_tool_palette_add_drag_dest (CTK_TOOL_PALETTE (palette), target,
                                CTK_DEST_DEFAULT_ALL,
                                CTK_TOOL_PALETTE_DRAG_ITEMS,
                                CDK_ACTION_COPY);

CSS nodes

CtkToolPalette has a single CSS node named toolpalette.

Functions

ctk_tool_palette_new ()

CtkWidget *
ctk_tool_palette_new (void);

Creates a new tool palette.

Returns

a new CtkToolPalette

Since: 2.20


ctk_tool_palette_get_exclusive ()

gboolean
ctk_tool_palette_get_exclusive (CtkToolPalette *palette,
                                CtkToolItemGroup *group);

Gets whether group is exclusive or not. See ctk_tool_palette_set_exclusive().

Parameters

palette

a CtkToolPalette

 

group

a CtkToolItemGroup which is a child of palette

 

Returns

TRUE if group is exclusive

Since: 2.20


ctk_tool_palette_set_exclusive ()

void
ctk_tool_palette_set_exclusive (CtkToolPalette *palette,
                                CtkToolItemGroup *group,
                                gboolean exclusive);

Sets whether the group should be exclusive or not. If an exclusive group is expanded all other groups are collapsed.

Parameters

palette

a CtkToolPalette

 

group

a CtkToolItemGroup which is a child of palette

 

exclusive

whether the group should be exclusive or not

 

Since: 2.20


ctk_tool_palette_get_expand ()

gboolean
ctk_tool_palette_get_expand (CtkToolPalette *palette,
                             CtkToolItemGroup *group);

Gets whether group should be given extra space. See ctk_tool_palette_set_expand().

Parameters

palette

a CtkToolPalette

 

group

a CtkToolItemGroup which is a child of palette

 

Returns

TRUE if group should be given extra space, FALSE otherwise

Since: 2.20


ctk_tool_palette_set_expand ()

void
ctk_tool_palette_set_expand (CtkToolPalette *palette,
                             CtkToolItemGroup *group,
                             gboolean expand);

Sets whether the group should be given extra space.

Parameters

palette

a CtkToolPalette

 

group

a CtkToolItemGroup which is a child of palette

 

expand

whether the group should be given extra space

 

Since: 2.20


ctk_tool_palette_get_group_position ()

gint
ctk_tool_palette_get_group_position (CtkToolPalette *palette,
                                     CtkToolItemGroup *group);

Gets the position of group in palette as index. See ctk_tool_palette_set_group_position().

Parameters

palette

a CtkToolPalette

 

group

a CtkToolItemGroup

 

Returns

the index of group or -1 if group is not a child of palette

Since: 2.20


ctk_tool_palette_set_group_position ()

void
ctk_tool_palette_set_group_position (CtkToolPalette *palette,
                                     CtkToolItemGroup *group,
                                     gint position);

Sets the position of the group as an index of the tool palette. If position is 0 the group will become the first child, if position is -1 it will become the last child.

Parameters

palette

a CtkToolPalette

 

group

a CtkToolItemGroup which is a child of palette

 

position

a new index for group

 

Since: 2.20


ctk_tool_palette_get_icon_size ()

CtkIconSize
ctk_tool_palette_get_icon_size (CtkToolPalette *palette);

Gets the size of icons in the tool palette. See ctk_tool_palette_set_icon_size().

Parameters

palette

a CtkToolPalette

 

Returns

the CtkIconSize of icons in the tool palette.

[type int]

Since: 2.20


ctk_tool_palette_set_icon_size ()

void
ctk_tool_palette_set_icon_size (CtkToolPalette *palette,
                                CtkIconSize icon_size);

Sets the size of icons in the tool palette.

Parameters

palette

a CtkToolPalette

 

icon_size

the CtkIconSize that icons in the tool palette shall have.

[type int]

Since: 2.20


ctk_tool_palette_unset_icon_size ()

void
ctk_tool_palette_unset_icon_size (CtkToolPalette *palette);

Unsets the tool palette icon size set with ctk_tool_palette_set_icon_size(), so that user preferences will be used to determine the icon size.

Parameters

palette

a CtkToolPalette

 

Since: 2.20


ctk_tool_palette_get_style ()

CtkToolbarStyle
ctk_tool_palette_get_style (CtkToolPalette *palette);

Gets the style (icons, text or both) of items in the tool palette.

Parameters

palette

a CtkToolPalette

 

Returns

the CtkToolbarStyle of items in the tool palette.

Since: 2.20


ctk_tool_palette_set_style ()

void
ctk_tool_palette_set_style (CtkToolPalette *palette,
                            CtkToolbarStyle style);

Sets the style (text, icons or both) of items in the tool palette.

Parameters

palette

a CtkToolPalette

 

style

the CtkToolbarStyle that items in the tool palette shall have

 

Since: 2.20


ctk_tool_palette_unset_style ()

void
ctk_tool_palette_unset_style (CtkToolPalette *palette);

Unsets a toolbar style set with ctk_tool_palette_set_style(), so that user preferences will be used to determine the toolbar style.

Parameters

palette

a CtkToolPalette

 

Since: 2.20


ctk_tool_palette_add_drag_dest ()

void
ctk_tool_palette_add_drag_dest (CtkToolPalette *palette,
                                CtkWidget *widget,
                                CtkDestDefaults flags,
                                CtkToolPaletteDragTargets targets,
                                CdkDragAction actions);

Sets palette as drag source (see ctk_tool_palette_set_drag_source()) and sets widget as a drag destination for drags from palette . See ctk_drag_dest_set().

Parameters

palette

a CtkToolPalette

 

widget

a CtkWidget which should be a drag destination for palette

 

flags

the flags that specify what actions CTK+ should take for drops on that widget

 

targets

the CtkToolPaletteDragTargets which the widget should support

 

actions

the CdkDragActions which the widget should suppport

 

Since: 2.20


ctk_tool_palette_get_drag_item ()

CtkWidget *
ctk_tool_palette_get_drag_item (CtkToolPalette *palette,
                                const CtkSelectionData *selection);

Get the dragged item from the selection. This could be a CtkToolItem or a CtkToolItemGroup.

Parameters

palette

a CtkToolPalette

 

selection

a CtkSelectionData

 

Returns

the dragged item in selection.

[transfer none]

Since: 2.20


ctk_tool_palette_get_drag_target_group ()

const CtkTargetEntry *
ctk_tool_palette_get_drag_target_group
                               (void);

Get the target entry for a dragged CtkToolItemGroup.

Returns

the CtkTargetEntry for a dragged group.

[transfer none]

Since: 2.20


ctk_tool_palette_get_drag_target_item ()

const CtkTargetEntry *
ctk_tool_palette_get_drag_target_item (void);

Gets the target entry for a dragged CtkToolItem.

Returns

the CtkTargetEntry for a dragged item.

[transfer none]

Since: 2.20


ctk_tool_palette_get_drop_group ()

CtkToolItemGroup *
ctk_tool_palette_get_drop_group (CtkToolPalette *palette,
                                 gint x,
                                 gint y);

Gets the group at position (x, y).

Parameters

palette

a CtkToolPalette

 

x

the x position

 

y

the y position

 

Returns

the CtkToolItemGroup at position or NULL if there is no such group.

[nullable][transfer none]

Since: 2.20


ctk_tool_palette_get_drop_item ()

CtkToolItem *
ctk_tool_palette_get_drop_item (CtkToolPalette *palette,
                                gint x,
                                gint y);

Gets the item at position (x, y). See ctk_tool_palette_get_drop_group().

Parameters

palette

a CtkToolPalette

 

x

the x position

 

y

the y position

 

Returns

the CtkToolItem at position or NULL if there is no such item.

[nullable][transfer none]

Since: 2.20


ctk_tool_palette_set_drag_source ()

void
ctk_tool_palette_set_drag_source (CtkToolPalette *palette,
                                  CtkToolPaletteDragTargets targets);

Sets the tool palette as a drag source. Enables all groups and items in the tool palette as drag sources on button 1 and button 3 press with copy and move actions. See ctk_drag_source_set().

Parameters

palette

a CtkToolPalette

 

targets

the CtkToolPaletteDragTargets which the widget should support

 

Since: 2.20


ctk_tool_palette_get_hadjustment ()

CtkAdjustment *
ctk_tool_palette_get_hadjustment (CtkToolPalette *palette);

ctk_tool_palette_get_hadjustment has been deprecated since version 3.0 and should not be used in newly-written code.

Use ctk_scrollable_get_hadjustment()

Gets the horizontal adjustment of the tool palette.

Parameters

palette

a CtkToolPalette

 

Returns

the horizontal adjustment of palette .

[transfer none]

Since: 2.20


ctk_tool_palette_get_vadjustment ()

CtkAdjustment *
ctk_tool_palette_get_vadjustment (CtkToolPalette *palette);

ctk_tool_palette_get_vadjustment has been deprecated since version 3.0 and should not be used in newly-written code.

Use ctk_scrollable_get_vadjustment()

Gets the vertical adjustment of the tool palette.

Parameters

palette

a CtkToolPalette

 

Returns

the vertical adjustment of palette .

[transfer none]

Since: 2.20

Types and Values

struct CtkToolPalette

struct CtkToolPalette;

This should not be accessed directly. Use the accessor functions below.


struct CtkToolPaletteClass

struct CtkToolPaletteClass {
  CtkContainerClass parent_class;
};

Members


enum CtkToolPaletteDragTargets

Flags used to specify the supported drag targets.

Members

CTK_TOOL_PALETTE_DRAG_ITEMS

Support drag of items.

 

CTK_TOOL_PALETTE_DRAG_GROUPS

Support drag of groups.

 

Property Details

The “icon-size” property

  “icon-size”                CtkIconSize

The size of the icons in a tool palette. When this property is set, it overrides the default setting.

This should only be used for special-purpose tool palettes, normal application tool palettes should respect the user preferences for the size of icons.

Owner: CtkToolPalette

Flags: Read / Write

Default value: CTK_ICON_SIZE_SMALL_TOOLBAR

Since: 2.20


The “icon-size-set” property

  “icon-size-set”            gboolean

Is TRUE if the “icon-size” property has been set.

Owner: CtkToolPalette

Flags: Read / Write

Default value: FALSE

Since: 2.20


The “toolbar-style” property

  “toolbar-style”            CtkToolbarStyle

The style of items in the tool palette.

Owner: CtkToolPalette

Flags: Read / Write

Default value: CTK_TOOLBAR_ICONS

Since: 2.20