[maemo-commits] [maemo-commits] r11782 - in projects/haf/trunk/gtk+: . gtk
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Wed May 23 17:36:12 EEST 2007
- Previous message: [maemo-commits] r11781 - in projects/haf/trunk/hildon-desktop: . src
- Next message: [maemo-commits] r11783 - projects/haf/trunk/glib/gobject
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: kris Date: 2007-05-23 17:36:10 +0300 (Wed, 23 May 2007) New Revision: 11782 Modified: projects/haf/trunk/gtk+/ChangeLog projects/haf/trunk/gtk+/gtk/gtktreemodelfilter.c Log: 2007-05-23 Kristian Rietveld <kris at imendio.com> * gtk/gtktreemodelfilter.c (gtk_tree_model_filter_drag_dest_init), (gtk_tree_model_filter_drag_data_received), (gtk_tree_model_filter_row_drop_possible): Add implementation of DragDestInterface which delegates the calls to its child model likewise as the implementation of the DragSourceInterface. (Fixes NB#50640). Modified: projects/haf/trunk/gtk+/ChangeLog =================================================================== --- projects/haf/trunk/gtk+/ChangeLog 2007-05-23 14:24:09 UTC (rev 11781) +++ projects/haf/trunk/gtk+/ChangeLog 2007-05-23 14:36:10 UTC (rev 11782) @@ -1,3 +1,12 @@ +2007-05-23 Kristian Rietveld <kris at imendio.com> + + * gtk/gtktreemodelfilter.c (gtk_tree_model_filter_drag_dest_init), + (gtk_tree_model_filter_drag_data_received), + (gtk_tree_model_filter_row_drop_possible): Add implementation of + DragDestInterface which delegates the calls to its child model + likewise as the implementation of the DragSourceInterface. (Fixes + NB#50640). + 2007-05-23 Tommi Komulainen <tommi.komulainen at nokia.com> Merge from trunk: Modified: projects/haf/trunk/gtk+/gtk/gtktreemodelfilter.c =================================================================== --- projects/haf/trunk/gtk+/gtk/gtktreemodelfilter.c 2007-05-23 14:24:09 UTC (rev 11781) +++ projects/haf/trunk/gtk+/gtk/gtktreemodelfilter.c 2007-05-23 14:36:10 UTC (rev 11782) @@ -132,6 +132,7 @@ /* general code (object/interface init, properties, etc) */ static void gtk_tree_model_filter_tree_model_init (GtkTreeModelIface *iface); static void gtk_tree_model_filter_drag_source_init (GtkTreeDragSourceIface *iface); +static void gtk_tree_model_filter_drag_dest_init (GtkTreeDragDestIface *iface); static void gtk_tree_model_filter_finalize (GObject *object); static void gtk_tree_model_filter_set_property (GObject *object, guint prop_id, @@ -211,6 +212,14 @@ static gboolean gtk_tree_model_filter_drag_data_delete (GtkTreeDragSource *drag_source, GtkTreePath *path); +/* TreeDragDest interface */ +static gboolean gtk_tree_model_filter_drag_data_received (GtkTreeDragDest *drag_dest, + GtkTreePath *dest, + GtkSelectionData *selection_data); +static gboolean gtk_tree_model_filter_row_drop_possible (GtkTreeDragDest *drag_dest, + GtkTreePath *dest, + GtkSelectionData *selection_data); + /* private functions */ static void gtk_tree_model_filter_build_level (GtkTreeModelFilter *filter, FilterLevel *parent_level, @@ -279,7 +288,9 @@ G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, gtk_tree_model_filter_tree_model_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE, - gtk_tree_model_filter_drag_source_init)) + gtk_tree_model_filter_drag_source_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_DEST, + gtk_tree_model_filter_drag_dest_init)) static void gtk_tree_model_filter_init (GtkTreeModelFilter *filter) @@ -355,7 +366,14 @@ iface->drag_data_get = gtk_tree_model_filter_drag_data_get; } +static void +gtk_tree_model_filter_drag_dest_init (GtkTreeDragDestIface *iface) +{ + iface->drag_data_received = gtk_tree_model_filter_drag_data_received; + iface->row_drop_possible = gtk_tree_model_filter_row_drop_possible; +} + static void gtk_tree_model_filter_finalize (GObject *object) { @@ -2707,6 +2725,188 @@ return deleted; } +/* TreeDragSource interface implementation */ +static gboolean +gtk_tree_model_filter_drag_data_received (GtkTreeDragDest *drag_dest, + GtkTreePath *dest_path, + GtkSelectionData *selection_data) +{ + GtkTreeModelFilter *tree_model_filter = (GtkTreeModelFilter *)drag_dest; + GtkTreePath *child_path; + gboolean received; + + g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (drag_dest), FALSE); + g_return_val_if_fail (dest_path != NULL, FALSE); + + child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, dest_path); + if (!child_path) + { + GtkTreePath *parent_path; + + parent_path = gtk_tree_path_copy (dest_path); + if (gtk_tree_path_up (parent_path) + && gtk_tree_path_get_depth (parent_path) > 0) + { + GtkTreeIter iter; + + /* Check if the parent exists */ + received = gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_dest), + &iter, parent_path); + g_assert (received != FALSE); + + if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (drag_dest), &iter)) + { + gint n; + GtkTreeIter child_iter; + + /* Parent has children, so the drop was after the last node + * in parent's child level. + */ + + gtk_tree_model_filter_convert_iter_to_child_iter (tree_model_filter, &child_iter, &iter); + n = gtk_tree_model_iter_n_children (tree_model_filter->priv->child_model, &child_iter); + + child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, parent_path); + gtk_tree_path_append_index (child_path, n); + } + else + { + /* Parent does not have children: this was a drop on + * the parent. + */ + child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, parent_path); + gtk_tree_path_append_index (child_path, 0); + } + + if (gtk_tree_path_get_depth (child_path) > 1 + && (tree_model_filter->priv->child_flags & GTK_TREE_MODEL_LIST_ONLY)) + { + gtk_tree_path_free (child_path); + gtk_tree_path_free (parent_path); + return FALSE; + } + + received = gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (tree_model_filter->priv->child_model), child_path, selection_data); + gtk_tree_path_free (child_path); + gtk_tree_path_free (parent_path); + return received; + } + else + { + gint n; + + /* There is no parent, check root level */ + gtk_tree_path_free (parent_path); + + n = gtk_tree_model_iter_n_children (tree_model_filter->priv->child_model, NULL); + + child_path = gtk_tree_path_new_from_indices (n, -1); + received = gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (tree_model_filter->priv->child_model), child_path, selection_data); + gtk_tree_path_free (child_path); + + return received; + } + + g_assert_not_reached (); + } + + received = gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (tree_model_filter->priv->child_model), child_path, selection_data); + gtk_tree_path_free (child_path); + + return received; +} + +static gboolean +gtk_tree_model_filter_row_drop_possible (GtkTreeDragDest *drag_dest, + GtkTreePath *dest_path, + GtkSelectionData *selection_data) +{ + GtkTreeModelFilter *tree_model_filter = (GtkTreeModelFilter *)drag_dest; + GtkTreePath *child_path; + gboolean possible; + + g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (drag_dest), FALSE); + g_return_val_if_fail (dest_path != NULL, FALSE); + + child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, dest_path); + + if (!child_path) + { + GtkTreePath *parent_path; + + parent_path = gtk_tree_path_copy (dest_path); + if (gtk_tree_path_up (parent_path) + && gtk_tree_path_get_depth (parent_path) > 0) + { + GtkTreeIter iter; + + /* Check if the parent exists */ + possible = gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_dest), + &iter, parent_path); + g_assert (possible != FALSE); + + if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (drag_dest), &iter)) + { + gint n; + GtkTreeIter child_iter; + + /* Parent has children, so the drop was after the last node + * in parent's child level. + */ + + gtk_tree_model_filter_convert_iter_to_child_iter (tree_model_filter, &child_iter, &iter); + n = gtk_tree_model_iter_n_children (tree_model_filter->priv->child_model, &child_iter); + + child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, parent_path); + gtk_tree_path_append_index (child_path, n); + } + else + { + /* Parent does not have children: this was a drop on + * the parent. + */ + child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, parent_path); + gtk_tree_path_append_index (child_path, 0); + } + + if (gtk_tree_path_get_depth (child_path) > 1 + && (tree_model_filter->priv->child_flags & GTK_TREE_MODEL_LIST_ONLY)) + { + gtk_tree_path_free (child_path); + gtk_tree_path_free (parent_path); + return FALSE; + } + + possible = gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (tree_model_filter->priv->child_model), child_path, selection_data); + gtk_tree_path_free (child_path); + gtk_tree_path_free (parent_path); + return possible; + } + else + { + gint n; + + /* There is no parent, check root level */ + gtk_tree_path_free (parent_path); + + n = gtk_tree_model_iter_n_children (tree_model_filter->priv->child_model, NULL); + + child_path = gtk_tree_path_new_from_indices (n, -1); + possible = gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (tree_model_filter->priv->child_model), child_path, selection_data); + gtk_tree_path_free (child_path); + + return possible; + } + + g_assert_not_reached (); + } + + possible = gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (tree_model_filter->priv->child_model), child_path, selection_data); + gtk_tree_path_free (child_path); + + return possible; +} + /* bits and pieces */ static void gtk_tree_model_filter_set_model (GtkTreeModelFilter *filter,
- Previous message: [maemo-commits] r11781 - in projects/haf/trunk/hildon-desktop: . src
- Next message: [maemo-commits] r11783 - projects/haf/trunk/glib/gobject
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]