GtkTreeView drag-and-drop — Interfaces for drag-and-drop support in GtkTreeView
gboolean | gtk_tree_drag_source_drag_data_delete () |
GdkContentProvider * | gtk_tree_drag_source_drag_data_get () |
gboolean | gtk_tree_drag_source_row_draggable () |
gboolean | gtk_tree_drag_dest_drag_data_received () |
gboolean | gtk_tree_drag_dest_row_drop_possible () |
GdkContentProvider * | gtk_tree_create_row_drag_content () |
gboolean | gtk_tree_get_row_drag_data () |
GtkTreeDragSource | |
struct | GtkTreeDragSourceIface |
GtkTreeDragDest | |
struct | GtkTreeDragDestIface |
#define | GTK_TYPE_TREE_ROW_DATA |
GInterface ├── GtkTreeDragDest ╰── GtkTreeDragSource
GtkTreeDragSource is implemented by GtkListStore, GtkTreeModelFilter, GtkTreeModelSort and GtkTreeStore.
GtkTreeDragDest is implemented by GtkListStore and GtkTreeStore.
#include <gtk/gtk.h>
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 GtkTreeDragSource and GtkTreeDragDest interfaces.
gboolean gtk_tree_drag_source_drag_data_delete (GtkTreeDragSource *drag_source
,GtkTreePath *path
);
Asks the GtkTreeDragSource to delete the row at path
, because it was moved somewhere else via drag-and-drop. Returns FALSE
if the deletion fails because path
no longer exists, or for some model-specific reason. Should robustly handle a path
no longer found in the model!
drag_source | ||
path | row that was being dragged |
TRUE
if the row was successfully deleted
GdkContentProvider * gtk_tree_drag_source_drag_data_get (GtkTreeDragSource *drag_source
,GtkTreePath *path
);
Asks the GtkTreeDragSource to return a GdkContentProvider representing the row at path
. Should robustly handle a path
no longer found in the model!
drag_source | ||
path | row that was dragged |
gboolean gtk_tree_drag_source_row_draggable (GtkTreeDragSource *drag_source
,GtkTreePath *path
);
Asks the GtkTreeDragSource 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 | ||
path | row on which user is initiating a drag |
TRUE
if the row can be dragged
gboolean gtk_tree_drag_dest_drag_data_received (GtkTreeDragDest *drag_dest
,GtkTreePath *dest
,const GValue *value
);
Asks the GtkTreeDragDest to insert a row before the path dest
, deriving the contents of the row from value
. If dest
is outside the tree so that inserting before it is impossible, FALSE
will be returned. Also, FALSE
may be returned if the new row is not created for some model-specific reason. Should robustly handle a dest
no longer found in the model!
drag_dest | ||
dest | row to drop in front of | |
value | data to drop |
whether a new row was created before position dest
gboolean gtk_tree_drag_dest_row_drop_possible (GtkTreeDragDest *drag_dest
,GtkTreePath *dest_path
,const GValue *value
);
Determines whether a drop is possible before the given dest_path
, at the same depth as dest_path
. i.e., can we drop the data in value
at that location. dest_path
does not have to exist; the return value will almost certainly be FALSE
if the parent of dest_path
doesn’t exist, though.
drag_dest | ||
dest_path | destination row | |
value | the data being dropped |
TRUE
if a drop is possible before dest_path
GdkContentProvider * gtk_tree_create_row_drag_content (GtkTreeModel *tree_model
,GtkTreePath *path
);
Creates a content provider for dragging path
from tree_model
.
tree_model | ||
path | a row in |
gboolean gtk_tree_get_row_drag_data (const GValue *value
,GtkTreeModel **tree_model
,GtkTreePath **path
);
Obtains a tree_model
and path
from value of target type GTK_TYPE_TREE_ROW_DATA
.
The returned path must be freed with gtk_tree_path_free()
.
value | a GValue | |
tree_model | a GtkTreeModel. | [nullable][optional][transfer none][out] |
path | row in | [nullable][optional][out] |
TRUE
if selection_data
had target type GTK_TYPE_TREE_ROW_DATA
is otherwise valid
typedef struct _GtkTreeDragSource GtkTreeDragSource;
struct GtkTreeDragSourceIface { /* VTable - not signals */ gboolean (* row_draggable) (GtkTreeDragSource *drag_source, GtkTreePath *path); GdkContentProvider * (* drag_data_get)(GtkTreeDragSource *drag_source, GtkTreePath *path); gboolean (* drag_data_delete) (GtkTreeDragSource *drag_source, GtkTreePath *path); };
| Asks the GtkTreeDragSource whether a particular row can be used as the source of a DND operation. | |
| Asks the GtkTreeDragSource to fill in selection_data with a representation of the row at path. | |
| Asks the GtkTreeDragSource to delete the row at path, because it was moved somewhere else via drag-and-drop. |
typedef struct _GtkTreeDragDest GtkTreeDragDest;
struct GtkTreeDragDestIface { /* VTable - not signals */ gboolean (* drag_data_received) (GtkTreeDragDest *drag_dest, GtkTreePath *dest, const GValue *value); gboolean (* row_drop_possible) (GtkTreeDragDest *drag_dest, GtkTreePath *dest_path, const GValue *value); };
| Asks the GtkTreeDragDest to insert a row before the path dest, deriving the contents of the row from selection_data. | |
| Determines whether a drop is possible before the given dest_path, at the same depth as dest_path. |
#define GTK_TYPE_TREE_ROW_DATA (gtk_tree_row_data_get_type ())
Data in this format will be provided by gtk_tree_create_row_drag_content()
and can be consumed via gtk_tree_get_row_drag_data()
.
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/gtk4-GtkTreeView-drag-and-drop.html