X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtktreednd.c;h=d65cdc09737beb6c33162c1d6b54593aada74b79;hb=1708ae3f1a962d3bbfcc0e673c5fa9f629d16eae;hp=f798022c25dfb1c3cc9fe98f08facc0f1f07ccb6;hpb=ef4356b567e59d98e837ec41993e50d20dd65a46;p=~andy%2Fgtk diff --git a/gtk/gtktreednd.c b/gtk/gtktreednd.c index f798022c2..d65cdc097 100644 --- a/gtk/gtktreednd.c +++ b/gtk/gtktreednd.c @@ -12,13 +12,37 @@ * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ +#include "config.h" #include #include "gtktreednd.h" +#include "gtkintl.h" + + +/** + * SECTION:gtktreednd + * @Short_description: Interfaces for drag-and-drop support in GtkTreeView + * @Title: GtkTreeView drag-and-drop + * + * 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. + */ + GType gtk_tree_drag_source_get_type (void) @@ -27,7 +51,7 @@ gtk_tree_drag_source_get_type (void) if (!our_type) { - static const GTypeInfo our_info = + const GTypeInfo our_info = { sizeof (GtkTreeDragSourceIface), /* class_size */ NULL, /* base_init */ @@ -40,7 +64,9 @@ gtk_tree_drag_source_get_type (void) NULL }; - our_type = g_type_register_static (G_TYPE_INTERFACE, "GtkTreeDragSource", &our_info, 0); + our_type = g_type_register_static (G_TYPE_INTERFACE, + I_("GtkTreeDragSource"), + &our_info, 0); } return our_type; @@ -54,7 +80,7 @@ gtk_tree_drag_dest_get_type (void) if (!our_type) { - static const GTypeInfo our_info = + const GTypeInfo our_info = { sizeof (GtkTreeDragDestIface), /* class_size */ NULL, /* base_init */ @@ -67,12 +93,40 @@ gtk_tree_drag_dest_get_type (void) NULL }; - our_type = g_type_register_static (G_TYPE_INTERFACE, "GtkTreeDragDest", &our_info, 0); + our_type = g_type_register_static (G_TYPE_INTERFACE, I_("GtkTreeDragDest"), &our_info, 0); } return our_type; } +/** + * gtk_tree_drag_source_row_draggable: + * @drag_source: a #GtkTreeDragSource + * @path: row on which user is initiating a drag + * + * 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. + * + * Return value: %TRUE if the row can be dragged + **/ +gboolean +gtk_tree_drag_source_row_draggable (GtkTreeDragSource *drag_source, + GtkTreePath *path) +{ + GtkTreeDragSourceIface *iface = GTK_TREE_DRAG_SOURCE_GET_IFACE (drag_source); + + g_return_val_if_fail (path != NULL, FALSE); + + if (iface->row_draggable) + return (* iface->row_draggable) (drag_source, path); + else + return TRUE; + /* Returning TRUE if row_draggable is not implemented is a fallback. + Interface implementations such as GtkTreeStore and GtkListStore really should + implement row_draggable. */ +} + /** * gtk_tree_drag_source_drag_data_delete: @@ -103,7 +157,8 @@ gtk_tree_drag_source_drag_data_delete (GtkTreeDragSource *drag_source, * gtk_tree_drag_source_drag_data_get: * @drag_source: a #GtkTreeDragSource * @path: row that was dragged - * @selection_data: a #GtkSelectionData to fill with data from the dragged row + * @selection_data: a #GtkSelectionData to fill with data + * from the dragged row * * Asks the #GtkTreeDragSource to fill in @selection_data with a * representation of the row at @path. @selection_data->target gives @@ -155,6 +210,35 @@ gtk_tree_drag_dest_drag_data_received (GtkTreeDragDest *drag_dest, return (* iface->drag_data_received) (drag_dest, dest, selection_data); } + +/** + * gtk_tree_drag_dest_row_drop_possible: + * @drag_dest: a #GtkTreeDragDest + * @dest_path: destination row + * @selection_data: the data being dragged + * + * 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 + * @selection_data 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. + * + * Return value: %TRUE if a drop is possible before @dest_path + **/ +gboolean +gtk_tree_drag_dest_row_drop_possible (GtkTreeDragDest *drag_dest, + GtkTreePath *dest_path, + GtkSelectionData *selection_data) +{ + GtkTreeDragDestIface *iface = GTK_TREE_DRAG_DEST_GET_IFACE (drag_dest); + + g_return_val_if_fail (iface->row_drop_possible != NULL, FALSE); + g_return_val_if_fail (selection_data != NULL, FALSE); + g_return_val_if_fail (dest_path != NULL, FALSE); + + return (* iface->row_drop_possible) (drag_dest, dest_path, selection_data); +} + typedef struct _TreeRowData TreeRowData; struct _TreeRowData @@ -164,7 +248,7 @@ struct _TreeRowData }; /** - * gtk_selection_data_set_tree_row: + * gtk_tree_set_row_drag_data: * @selection_data: some #GtkSelectionData * @tree_model: a #GtkTreeModel * @path: a row in @tree_model @@ -175,9 +259,9 @@ struct _TreeRowData * Return value: %TRUE if the #GtkSelectionData had the proper target type to allow us to set a tree row **/ gboolean -gtk_selection_data_set_tree_row (GtkSelectionData *selection_data, - GtkTreeModel *tree_model, - GtkTreePath *path) +gtk_tree_set_row_drag_data (GtkSelectionData *selection_data, + GtkTreeModel *tree_model, + GtkTreePath *path) { TreeRowData *trd; gchar *path_str; @@ -188,7 +272,7 @@ gtk_selection_data_set_tree_row (GtkSelectionData *selection_data, g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE); g_return_val_if_fail (path != NULL, FALSE); - if (selection_data->target != gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE)) + if (gtk_selection_data_get_target (selection_data) != gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW")) return FALSE; path_str = gtk_tree_path_to_string (path); @@ -202,11 +286,13 @@ gtk_selection_data_set_tree_row (GtkSelectionData *selection_data, trd = g_malloc (struct_size); strcpy (trd->path, path_str); + + g_free (path_str); trd->model = tree_model; gtk_selection_data_set (selection_data, - gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE), + gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"), 8, /* bytes */ (void*)trd, struct_size); @@ -217,10 +303,10 @@ gtk_selection_data_set_tree_row (GtkSelectionData *selection_data, } /** - * gtk_selection_data_get_tree_row: + * gtk_tree_get_row_drag_data: * @selection_data: a #GtkSelectionData - * @tree_model: a #GtkTreeModel - * @path: row in @tree_model + * @tree_model: (out): a #GtkTreeModel + * @path: (out): row in @tree_model * * Obtains a @tree_model and @path from selection data of target type * %GTK_TREE_MODEL_ROW. Normally called from a drag_data_received handler. @@ -236,9 +322,9 @@ gtk_selection_data_set_tree_row (GtkSelectionData *selection_data, * is otherwise valid **/ gboolean -gtk_selection_data_get_tree_row (GtkSelectionData *selection_data, - GtkTreeModel **tree_model, - GtkTreePath **path) +gtk_tree_get_row_drag_data (GtkSelectionData *selection_data, + GtkTreeModel **tree_model, + GtkTreePath **path) { TreeRowData *trd; @@ -249,11 +335,14 @@ gtk_selection_data_get_tree_row (GtkSelectionData *selection_data, if (path) *path = NULL; - - if (selection_data->target != gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE)) + + if (gtk_selection_data_get_target (selection_data) != gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW")) + return FALSE; + + if (gtk_selection_data_get_length (selection_data) < 0) return FALSE; - trd = (void*) selection_data->data; + trd = (void*) gtk_selection_data_get_data (selection_data); if (tree_model) *tree_model = trd->model;