2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define VT_COL_WIDTH_NAME 160
29 #define VT_COL_WIDTH_TYPE 20
30 #define VT_COL_WIDTH_VISIBLE 20
32 #define TREEVIEW_GET(model,iter,what,dest) gtk_tree_model_get(GTK_TREE_MODEL(model),(iter),(what),(dest),-1)
35 VT_ITEM_EDITED_SIGNAL
,
36 VT_ITEM_TOGGLED_SIGNAL
,
40 static guint treeview_signals
[VT_LAST_SIGNAL
] = { 0, 0 };
42 static GObjectClass
*parent_class
;
57 /* properties dialog, delete, rename, etc. */
65 GdkPixbuf
*layer_type_icons
[VIK_LAYER_NUM_TYPES
];
68 /* TODO: find, make "static" and put up here all non-"a_" functions */
69 static void treeview_class_init ( VikTreeviewClass
*klass
);
70 static void treeview_init ( VikTreeview
*vt
);
71 static void treeview_finalize ( GObject
*gob
);
72 static void treeview_add_columns ( VikTreeview
*vt
);
74 static gboolean
treeview_drag_data_received ( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
, GtkSelectionData
*selection_data
);
75 static gboolean
treeview_drag_data_delete ( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
77 GType
vik_treeview_get_type (void)
79 static GType vt_type
= 0;
83 static const GTypeInfo vt_info
=
85 sizeof (VikTreeviewClass
),
87 NULL
, /* base_finalize */
88 (GClassInitFunc
) treeview_class_init
,
89 NULL
, /* class_finalize */
90 NULL
, /* class_data */
93 (GInstanceInitFunc
) treeview_init
,
95 vt_type
= g_type_register_static ( GTK_TYPE_TREE_VIEW
, "VikTreeview", &vt_info
, 0 );
101 static void treeview_class_init ( VikTreeviewClass
*klass
)
104 GObjectClass
*object_class
;
106 object_class
= G_OBJECT_CLASS (klass
);
108 object_class
->finalize
= treeview_finalize
;
110 parent_class
= g_type_class_peek_parent (klass
);
112 treeview_signals
[VT_ITEM_EDITED_SIGNAL
] = g_signal_new ( "item_edited", G_TYPE_FROM_CLASS (klass
), G_SIGNAL_RUN_FIRST
| G_SIGNAL_ACTION
, G_STRUCT_OFFSET (VikTreeviewClass
, item_edited
), NULL
, NULL
,
113 gtk_marshal_VOID__POINTER_POINTER
, G_TYPE_NONE
, 2, GTK_TYPE_POINTER
, G_TYPE_POINTER
);
114 /* VOID__UINT_POINTER: kinda hack-ish, but it works. */
116 treeview_signals
[VT_ITEM_TOGGLED_SIGNAL
] = g_signal_new ( "item_toggled", G_TYPE_FROM_CLASS (klass
), G_SIGNAL_RUN_FIRST
| G_SIGNAL_ACTION
, G_STRUCT_OFFSET (VikTreeviewClass
, item_toggled
), NULL
, NULL
,
117 g_cclosure_marshal_VOID__POINTER
, G_TYPE_NONE
, 1, GTK_TYPE_POINTER
);
120 static void treeview_edited_cb (GtkCellRendererText
*cell
, gchar
*path_str
, const gchar
*new_name
, VikTreeview
*vt
)
124 /* get type and data */
125 vik_treeview_get_iter_from_path_str ( vt
, &iter
, path_str
);
127 g_signal_emit ( G_OBJECT(vt
), treeview_signals
[VT_ITEM_EDITED_SIGNAL
], 0, &iter
, new_name
);
130 static void treeview_toggled_cb (GtkCellRendererToggle
*cell
, gchar
*path_str
, VikTreeview
*vt
)
134 /* get type and data */
135 vik_treeview_get_iter_from_path_str ( vt
, &iter
, path_str
);
137 g_signal_emit ( G_OBJECT(vt
),
138 treeview_signals
[VT_ITEM_TOGGLED_SIGNAL
], 0, &iter
);
141 VikTreeview
*vik_treeview_new ()
143 return VIK_TREEVIEW ( g_object_new ( VIK_TREEVIEW_TYPE
, NULL
) );
146 gint
vik_treeview_item_get_type ( VikTreeview
*vt
, GtkTreeIter
*iter
)
149 TREEVIEW_GET ( vt
->model
, iter
, TYPE_COLUMN
, &rv
);
153 gint
vik_treeview_item_get_data ( VikTreeview
*vt
, GtkTreeIter
*iter
)
156 TREEVIEW_GET ( vt
->model
, iter
, ITEM_DATA_COLUMN
, &rv
);
160 gpointer
vik_treeview_item_get_pointer ( VikTreeview
*vt
, GtkTreeIter
*iter
)
163 TREEVIEW_GET ( vt
->model
, iter
, ITEM_POINTER_COLUMN
, &rv
);
167 void vik_treeview_item_set_pointer ( VikTreeview
*vt
, GtkTreeIter
*iter
, gpointer pointer
)
169 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, ITEM_POINTER_COLUMN
, pointer
, -1 );
172 gpointer
vik_treeview_item_get_parent ( VikTreeview
*vt
, GtkTreeIter
*iter
)
175 TREEVIEW_GET ( vt
->model
, iter
, ITEM_PARENT_COLUMN
, &rv
);
179 gboolean
vik_treeview_get_iter_from_path_str ( VikTreeview
*vt
, GtkTreeIter
*iter
, const gchar
*path_str
)
181 return gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL(vt
->model
), iter
, path_str
);
184 static void treeview_add_columns ( VikTreeview
*vt
)
187 GtkCellRenderer
*renderer
;
188 GtkTreeViewColumn
*column
;
190 renderer
= gtk_cell_renderer_text_new ();
191 g_signal_connect (renderer
, "edited",
192 G_CALLBACK (treeview_edited_cb
), vt
);
194 g_object_set (G_OBJECT (renderer
), "xalign", 0.0, NULL
);
196 col_offset
= gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vt
),
200 "editable", EDITABLE_COLUMN
,
203 column
= gtk_tree_view_get_column (GTK_TREE_VIEW (vt
), col_offset
- 1);
204 gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column
),
205 GTK_TREE_VIEW_COLUMN_FIXED
);
206 gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column
),
208 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
209 gtk_tree_view_column_set_resizable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
211 renderer
= gtk_cell_renderer_pixbuf_new ();
213 g_object_set (G_OBJECT (renderer
), "xalign", 0.5, NULL
);
215 col_offset
= gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vt
),
222 column
= gtk_tree_view_get_column (GTK_TREE_VIEW (vt
), col_offset
- 1);
223 gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column
),
225 gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column
),
226 GTK_TREE_VIEW_COLUMN_FIXED
);
227 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
230 renderer
= gtk_cell_renderer_toggle_new ();
231 g_object_set (G_OBJECT (renderer
), "xalign", 0.5, NULL
);
233 g_signal_connect (renderer
, "toggled", G_CALLBACK (treeview_toggled_cb
), vt
);
235 col_offset
= gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vt
),
246 column
= gtk_tree_view_get_column (GTK_TREE_VIEW (vt
), col_offset
- 1);
247 gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column
),
248 VT_COL_WIDTH_VISIBLE
);
249 gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column
),
250 GTK_TREE_VIEW_COLUMN_FIXED
);
251 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
255 static void select_cb(GtkTreeSelection
*selection
, gpointer data
)
257 VikTreeview
*vt
= data
;
259 GtkTreeIter iter
, parent
;
263 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) return;
264 type
= vik_treeview_item_get_type( vt
, &iter
);
266 while ( type
!= VIK_TREEVIEW_TYPE_LAYER
) {
267 if ( ! vik_treeview_item_get_parent_iter ( vt
, &iter
, &parent
) )
270 type
= vik_treeview_item_get_type (vt
, &iter
);
273 vl
= VIK_LAYER( vik_treeview_item_get_pointer ( vt
, &iter
) );
275 vw
= VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl
));
276 vik_window_selected_layer(vw
, vl
);
279 void treeview_init ( VikTreeview
*vt
)
283 vt
->model
= GTK_TREE_MODEL(gtk_tree_store_new ( NUM_COLUMNS
, G_TYPE_STRING
, G_TYPE_BOOLEAN
, GDK_TYPE_PIXBUF
, G_TYPE_INT
, G_TYPE_POINTER
, G_TYPE_POINTER
, G_TYPE_INT
, G_TYPE_BOOLEAN
, G_TYPE_BOOLEAN
));
285 /* create tree view */
286 gtk_tree_view_set_model ( GTK_TREE_VIEW(vt
), vt
->model
);
287 treeview_add_columns ( vt
);
288 g_object_unref (vt
->model
);
290 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (vt
), TRUE
);
291 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (vt
)),
292 GTK_SELECTION_SINGLE
);
294 /* Override treestore's dnd methods only; this is easier than deriving from GtkTreeStore.
295 * The downside is that all treestores will have this behavior, so this needs to be
296 * changed if we add more treeviews in the future. //Alex
299 GtkTreeDragSourceIface
*isrc
;
300 GtkTreeDragDestIface
*idest
;
302 isrc
= g_type_interface_peek (g_type_class_peek(G_OBJECT_TYPE(vt
->model
)), GTK_TYPE_TREE_DRAG_SOURCE
);
303 isrc
->drag_data_delete
= treeview_drag_data_delete
;
305 idest
= g_type_interface_peek (g_type_class_peek(G_OBJECT_TYPE(vt
->model
)), GTK_TYPE_TREE_DRAG_DEST
);
306 idest
->drag_data_received
= treeview_drag_data_received
;
309 for ( i
= 0; i
< VIK_LAYER_NUM_TYPES
; i
++ )
310 vt
->layer_type_icons
[i
] = vik_layer_load_icon ( i
); /* if icon can't be loaded, it will be null and simply not be shown. */
312 gtk_tree_view_set_reorderable (GTK_TREE_VIEW(vt
), TRUE
);
313 g_signal_connect(gtk_tree_view_get_selection (GTK_TREE_VIEW (vt
)), "changed",
314 G_CALLBACK(select_cb
), vt
);
318 gboolean
vik_treeview_item_get_parent_iter ( VikTreeview
*vt
, GtkTreeIter
*iter
, GtkTreeIter
*parent
)
320 return gtk_tree_model_iter_parent ( GTK_TREE_MODEL(vt
->model
), parent
, iter
);
323 gboolean
vik_treeview_move_item ( VikTreeview
*vt
, GtkTreeIter
*iter
, gboolean up
)
325 gint t
= vik_treeview_item_get_type ( vt
, iter
);
326 if ( t
== VIK_TREEVIEW_TYPE_LAYER
)
328 GtkTreeIter switch_iter
;
331 /* iter to path to iter */
332 GtkTreePath
*path
= gtk_tree_model_get_path ( vt
->model
, iter
);
333 if ( !gtk_tree_path_prev ( path
) || !gtk_tree_model_get_iter ( vt
->model
, &switch_iter
, path
) )
335 gtk_tree_path_free ( path
);
338 gtk_tree_path_free ( path
);
343 if ( !gtk_tree_model_iter_next ( vt
->model
, &switch_iter
) )
346 gtk_tree_store_swap ( GTK_TREE_STORE(vt
->model
), iter
, &switch_iter
);
348 /* now, the easy part. actually switching them, not the GUI */
349 } /* if item is map */
353 gboolean
vik_treeview_get_iter_at_pos ( VikTreeview
*vt
, GtkTreeIter
*iter
, gint x
, gint y
)
356 gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW(vt
), x
, y
, &path
, NULL
, NULL
, NULL
);
360 gtk_tree_model_get_iter (GTK_TREE_MODEL(vt
->model
), iter
, path
);
361 gtk_tree_path_free ( path
);
365 void vik_treeview_select_iter ( VikTreeview
*vt
, GtkTreeIter
*iter
)
367 gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( vt
) ), iter
);
370 gboolean
vik_treeview_get_selected_iter ( VikTreeview
*vt
, GtkTreeIter
*iter
)
372 return gtk_tree_selection_get_selected ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( vt
) ), NULL
, iter
);
375 void vik_treeview_item_delete ( VikTreeview
*vt
, GtkTreeIter
*iter
)
377 gtk_tree_store_remove ( GTK_TREE_STORE(vt
->model
), iter
);
380 /* Treeview Reform Project */
382 void vik_treeview_item_set_name ( VikTreeview
*vt
, GtkTreeIter
*iter
, const gchar
*to
)
384 g_return_if_fail ( iter
!= NULL
&& to
!= NULL
);
385 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, to
, -1);
388 void vik_treeview_item_set_visible ( VikTreeview
*vt
, GtkTreeIter
*iter
, gboolean to
)
390 g_return_if_fail ( iter
!= NULL
);
391 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, VISIBLE_COLUMN
, to
, -1 );
394 void vik_treeview_expand ( VikTreeview
*vt
, GtkTreeIter
*iter
)
397 path
= gtk_tree_model_get_path ( vt
->model
, iter
);
398 gtk_tree_view_expand_row ( GTK_TREE_VIEW(vt
), path
, FALSE
);
399 gtk_tree_path_free ( path
);
402 void vik_treeview_item_select ( VikTreeview
*vt
, GtkTreeIter
*iter
)
404 gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( vt
) ), iter
);
407 void vik_treeview_add_layer ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
,
408 gpointer item
, gint data
, gint icon_type
)
410 g_assert ( iter
!= NULL
);
411 g_assert ( icon_type
< VIK_LAYER_NUM_TYPES
);
412 gtk_tree_store_prepend ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
413 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, name
, VISIBLE_COLUMN
, TRUE
,
414 TYPE_COLUMN
, VIK_TREEVIEW_TYPE_LAYER
, ITEM_PARENT_COLUMN
, parent
, ITEM_POINTER_COLUMN
, item
,
415 ITEM_DATA_COLUMN
, data
, HAS_VISIBLE_COLUMN
, TRUE
, EDITABLE_COLUMN
, TRUE
,
416 ICON_COLUMN
, icon_type
>= 0 ? vt
->layer_type_icons
[icon_type
] : NULL
, -1 );
419 void vik_treeview_insert_layer ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
,
420 gpointer item
, gint data
, gint icon_type
, GtkTreeIter
*sibling
)
422 g_assert ( iter
!= NULL
);
423 g_assert ( icon_type
< VIK_LAYER_NUM_TYPES
);
425 gtk_tree_store_insert_before ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
, sibling
);
427 gtk_tree_store_append ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
430 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, name
, VISIBLE_COLUMN
, TRUE
,
431 TYPE_COLUMN
, VIK_TREEVIEW_TYPE_LAYER
, ITEM_PARENT_COLUMN
, parent
, ITEM_POINTER_COLUMN
, item
,
432 ITEM_DATA_COLUMN
, data
, HAS_VISIBLE_COLUMN
, TRUE
, EDITABLE_COLUMN
, TRUE
,
433 ICON_COLUMN
, icon_type
>= 0 ? vt
->layer_type_icons
[icon_type
] : NULL
, -1 );
436 void vik_treeview_add_sublayer ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
, gpointer item
,
437 gint data
, GdkPixbuf
*icon
, gboolean has_visible
, gboolean editable
)
439 g_assert ( iter
!= NULL
);
441 gtk_tree_store_prepend ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
442 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, name
, VISIBLE_COLUMN
, TRUE
, TYPE_COLUMN
, VIK_TREEVIEW_TYPE_SUBLAYER
, ITEM_PARENT_COLUMN
, parent
, ITEM_POINTER_COLUMN
, item
, ITEM_DATA_COLUMN
, data
, HAS_VISIBLE_COLUMN
, has_visible
, EDITABLE_COLUMN
, editable
, ICON_COLUMN
, icon
, -1 );
446 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
448 void vik_treeview_sublayer_realphabetize ( VikTreeview
*vt
, GtkTreeIter
*iter
, const gchar
*newname
)
450 GtkTreeIter search_iter
, parent_iter
;
452 g_assert ( iter
!= NULL
);
454 gtk_tree_model_iter_parent ( vt
->model
, &parent_iter
, iter
);
456 g_assert ( gtk_tree_model_iter_children ( vt
->model
, &search_iter
, &parent_iter
) );
459 gtk_tree_model_get ( vt
->model
, &search_iter
, NAME_COLUMN
, &search_name
, -1 );
460 if ( strcmp ( search_name
, newname
) > 0 ) /* not >= or would trip on itself */
462 gtk_tree_store_move_before ( GTK_TREE_STORE(vt
->model
), iter
, &search_iter
);
465 } while ( gtk_tree_model_iter_next ( vt
->model
, &search_iter
) );
467 gtk_tree_store_move_before ( GTK_TREE_STORE(vt
->model
), iter
, NULL
);
470 void vik_treeview_add_sublayer_alphabetized
471 ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
, gpointer item
,
472 gint data
, GdkPixbuf
*icon
, gboolean has_visible
, gboolean editable
)
474 GtkTreeIter search_iter
;
476 g_assert ( iter
!= NULL
);
478 if ( gtk_tree_model_iter_children ( vt
->model
, &search_iter
, parent_iter
) )
480 gboolean found_greater_string
= FALSE
;
482 gtk_tree_model_get ( vt
->model
, &search_iter
, NAME_COLUMN
, &search_name
, -1 );
483 if ( strcmp ( search_name
, name
) >= 0 )
485 gtk_tree_store_insert_before ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
, &search_iter
);
486 found_greater_string
= TRUE
;
489 } while ( gtk_tree_model_iter_next ( vt
->model
, &search_iter
) );
491 if ( ! found_greater_string
)
492 gtk_tree_store_append ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
495 gtk_tree_store_prepend ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
497 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, name
, VISIBLE_COLUMN
, TRUE
, TYPE_COLUMN
, VIK_TREEVIEW_TYPE_SUBLAYER
, ITEM_PARENT_COLUMN
, parent
, ITEM_POINTER_COLUMN
, item
, ITEM_DATA_COLUMN
, data
, HAS_VISIBLE_COLUMN
, has_visible
, EDITABLE_COLUMN
, editable
, ICON_COLUMN
, icon
, -1 );
502 static void treeview_finalize ( GObject
*gob
)
504 VikTreeview
*vt
= VIK_TREEVIEW ( gob
);
507 for ( i
= 0; i
< VIK_LAYER_NUM_TYPES
; i
++ )
508 if ( vt
->layer_type_icons
[i
] != NULL
)
509 g_object_unref ( G_OBJECT(vt
->layer_type_icons
[i
]) );
511 G_OBJECT_CLASS(parent_class
)->finalize(gob
);
514 static gboolean
treeview_drag_data_received (GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
, GtkSelectionData
*selection_data
)
516 GtkTreeModel
*tree_model
;
517 GtkTreeStore
*tree_store
;
518 GtkTreeModel
*src_model
= NULL
;
519 GtkTreePath
*src_path
= NULL
, *dest_cp
= NULL
;
520 gboolean retval
= FALSE
;
521 GtkTreeIter src_iter
, root_iter
, dest_iter
, dest_parent
;
526 g_return_val_if_fail (GTK_IS_TREE_STORE (drag_dest
), FALSE
);
528 tree_model
= GTK_TREE_MODEL (drag_dest
);
529 tree_store
= GTK_TREE_STORE (drag_dest
);
531 if (gtk_tree_get_row_drag_data (selection_data
, &src_model
, &src_path
) && src_model
== tree_model
) {
533 * Copy src_path to dest. There are two subcases here, depending on what
536 * 1. src_path is a layer. In this case, interpret the drop
537 * as a request to move the layer to a different aggregate layer.
538 * If the destination is not an aggregate layer, use the first
541 * 2. src_path is a sublayer. In this case, find ancestors of
542 * both source and destination nodes who are full layers,
543 * and call the move method of that layer type.
546 if (!gtk_tree_model_get_iter (src_model
, &src_iter
, src_path
)) {
549 if (!gtk_tree_path_compare(src_path
, dest
)) {
553 i_src
= gtk_tree_path_get_indices (src_path
);
554 dest_cp
= gtk_tree_path_copy (dest
);
556 gtk_tree_model_get_iter_first(tree_model
, &root_iter
);
557 TREEVIEW_GET(tree_model
, &root_iter
, ITEM_POINTER_COLUMN
, &vl
);
561 if (gtk_tree_path_get_depth(dest_cp
)>1) { /* can't be sibling of top layer */
562 VikLayer
*vl_src
, *vl_dest
;
564 /* Find the first ancestor that is a full layer, and store in dest_parent.
565 * In addition, put in dest_iter where Gtk wants us to insert the dragged object.
566 * (Note that this may end up being an invalid iter).
569 gtk_tree_path_up(dest_cp
);
570 dest_iter
= dest_parent
;
571 gtk_tree_model_get_iter (src_model
, &dest_parent
, dest_cp
);
572 } while (gtk_tree_path_get_depth(dest_cp
)>1 &&
573 vik_treeview_item_get_type(vt
, &dest_parent
) != VIK_TREEVIEW_TYPE_LAYER
);
576 g_assert ( vik_treeview_item_get_parent(vt
, &src_iter
) );
577 vl_src
= vik_treeview_item_get_parent(vt
, &src_iter
);
578 vl_dest
= vik_treeview_item_get_pointer(vt
, &dest_parent
);
580 /* TODO: might want to allow different types, and let the clients handle how they want */
581 if (vl_src
->type
== vl_dest
->type
&& vik_layer_get_interface(vl_dest
->type
)->drag_drop_request
) {
582 // g_print("moving an item from layer '%s' into layer '%s'\n", vl_src->name, vl_dest->name);
583 vik_layer_get_interface(vl_dest
->type
)->drag_drop_request(vl_src
, vl_dest
, &src_iter
, dest
);
590 gtk_tree_path_free(dest_cp
);
592 gtk_tree_path_free (src_path
);
598 * This may not be necessary.
600 static gboolean
treeview_drag_data_delete ( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
)
602 gchar
*s_dest
= gtk_tree_path_to_string(path
);
603 g_print("delete data from %s\n", s_dest
);