Next: , Previous: GtkTreeView, Up: Top


36 GtkTreeView drag-and-drop

Interfaces for drag-and-drop support in GtkTreeView

36.1 Overview

GTK+ supports Drag-and-Drop in tree views with a high-level and a low-level API.

The low-level API consists of the GTK+ DND API, augmented by some treeview utility functions: gtk-tree-view-set-drag-dest-row, gtk-tree-view-get-drag-dest-row, gtk-tree-view-get-dest-row-at-pos, gtk-tree-view-create-row-drag-icon, gtk-tree-set-row-drag-data and gtk-tree-get-row-drag-data. This API leaves a lot of flexibility, but nothing is done automatically, and implementing advanced features like hover-to-open-rows or autoscrolling on top of this API is a lot of work.

On the other hand, if you write to the high-level API, then all the bookkeeping of rows is done for you, as well as things like hover-to-open and auto-scroll, but your models have to implement the <gtk-tree-drag-source> and <gtk-tree-drag-dest> interfaces.

36.2 Usage

— Class: <gtk-tree-drag-source>

Derives from <ginterface>.

This class defines no direct slots.

— Class: <gtk-tree-drag-dest>

Derives from <ginterface>.

This class defines no direct slots.

— Function: gtk-tree-drag-source-drag-data-get (self <gtk-tree-drag-source>) (path <gtk-tree-path>) (selection_data <gtk-selection-data>) ⇒  (ret bool)
— Method: drag-data-get

Asks the <gtk-tree-drag-source> to fill in selection-data with a representation of the row at path. selection-data->target gives the required type of the data. Should robustly handle a path no longer found in the model!

drag-source
a <gtk-tree-drag-source>
path
row that was dragged
selection-data
a <gtk-selection-data> to fill with data from the dragged row
ret
#t’ if data of the required type was provided
— Function: gtk-tree-drag-source-row-draggable (self <gtk-tree-drag-source>) (path <gtk-tree-path>) ⇒  (ret bool)
— Method: row-draggable

Asks the <gtk-tree-drag-source> whether a particular row can be used as the source of a DND operation. If the source doesn't implement this interface, the row is assumed draggable.

drag-source
a <gtk-tree-drag-source>
path
row on which user is initiating a drag
ret
#t’ if the row can be dragged
— Function: gtk-tree-set-row-drag-data (self <gtk-selection-data>) (tree_model <gtk-tree-model>) (path <gtk-tree-path>) ⇒  (ret bool)

Sets selection data of target type ‘GTK_TREE_MODEL_ROW’. Normally used in a drag_data_get handler.

selection-data
some <gtk-selection-data>
tree-model
a <gtk-tree-model>
path
a row in tree-model
ret
#t’ if the <gtk-selection-data> had the proper target type to allow us to set a tree row