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
27 #include <glib/gi18n.h>
34 #define TREEVIEW_GET(model,iter,what,dest) gtk_tree_model_get(GTK_TREE_MODEL(model),(iter),(what),(dest),-1)
37 VT_ITEM_EDITED_SIGNAL
,
38 VT_ITEM_TOGGLED_SIGNAL
,
42 static guint treeview_signals
[VT_LAST_SIGNAL
] = { 0, 0 };
44 static GObjectClass
*parent_class
;
59 /* properties dialog, delete, rename, etc. */
67 GdkPixbuf
*layer_type_icons
[VIK_LAYER_NUM_TYPES
];
69 gboolean was_a_toggle
;
72 /* TODO: find, make "static" and put up here all non-"a_" functions */
73 static void treeview_class_init ( VikTreeviewClass
*klass
);
74 static void treeview_init ( VikTreeview
*vt
);
75 static void treeview_finalize ( GObject
*gob
);
76 static void treeview_add_columns ( VikTreeview
*vt
);
78 static gboolean
treeview_drag_data_received ( GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
, GtkSelectionData
*selection_data
);
79 static gboolean
treeview_drag_data_delete ( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
);
81 GType
vik_treeview_get_type (void)
83 static GType vt_type
= 0;
87 static const GTypeInfo vt_info
=
89 sizeof (VikTreeviewClass
),
91 NULL
, /* base_finalize */
92 (GClassInitFunc
) treeview_class_init
,
93 NULL
, /* class_finalize */
94 NULL
, /* class_data */
97 (GInstanceInitFunc
) treeview_init
,
99 vt_type
= g_type_register_static ( GTK_TYPE_TREE_VIEW
, "VikTreeview", &vt_info
, 0 );
105 static void treeview_class_init ( VikTreeviewClass
*klass
)
108 GObjectClass
*object_class
;
110 object_class
= G_OBJECT_CLASS (klass
);
112 object_class
->finalize
= treeview_finalize
;
114 parent_class
= g_type_class_peek_parent (klass
);
116 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
,
117 gtk_marshal_VOID__POINTER_POINTER
, G_TYPE_NONE
, 2, GTK_TYPE_POINTER
, G_TYPE_POINTER
);
118 /* VOID__UINT_POINTER: kinda hack-ish, but it works. */
120 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
,
121 g_cclosure_marshal_VOID__POINTER
, G_TYPE_NONE
, 1, GTK_TYPE_POINTER
);
124 static void treeview_edited_cb (GtkCellRendererText
*cell
, gchar
*path_str
, const gchar
*new_name
, VikTreeview
*vt
)
128 /* get type and data */
129 vik_treeview_get_iter_from_path_str ( vt
, &iter
, path_str
);
131 g_signal_emit ( G_OBJECT(vt
), treeview_signals
[VT_ITEM_EDITED_SIGNAL
], 0, &iter
, new_name
);
134 static void treeview_toggled_cb (GtkCellRendererToggle
*cell
, gchar
*path_str
, VikTreeview
*vt
)
138 /* get type and data */
139 vik_treeview_get_iter_from_path_str ( vt
, &iter
, path_str
);
140 vt
->was_a_toggle
= TRUE
;
142 g_signal_emit ( G_OBJECT(vt
),
143 treeview_signals
[VT_ITEM_TOGGLED_SIGNAL
], 0, &iter
);
146 VikTreeview
*vik_treeview_new ()
148 return VIK_TREEVIEW ( g_object_new ( VIK_TREEVIEW_TYPE
, NULL
) );
151 gint
vik_treeview_item_get_type ( VikTreeview
*vt
, GtkTreeIter
*iter
)
154 TREEVIEW_GET ( vt
->model
, iter
, TYPE_COLUMN
, &rv
);
158 gint
vik_treeview_item_get_data ( VikTreeview
*vt
, GtkTreeIter
*iter
)
161 TREEVIEW_GET ( vt
->model
, iter
, ITEM_DATA_COLUMN
, &rv
);
165 gpointer
vik_treeview_item_get_pointer ( VikTreeview
*vt
, GtkTreeIter
*iter
)
168 TREEVIEW_GET ( vt
->model
, iter
, ITEM_POINTER_COLUMN
, &rv
);
172 void vik_treeview_item_set_pointer ( VikTreeview
*vt
, GtkTreeIter
*iter
, gpointer pointer
)
174 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, ITEM_POINTER_COLUMN
, pointer
, -1 );
177 gpointer
vik_treeview_item_get_parent ( VikTreeview
*vt
, GtkTreeIter
*iter
)
180 TREEVIEW_GET ( vt
->model
, iter
, ITEM_PARENT_COLUMN
, &rv
);
184 gboolean
vik_treeview_get_iter_from_path_str ( VikTreeview
*vt
, GtkTreeIter
*iter
, const gchar
*path_str
)
186 return gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL(vt
->model
), iter
, path_str
);
189 static void treeview_add_columns ( VikTreeview
*vt
)
192 GtkCellRenderer
*renderer
;
193 GtkTreeViewColumn
*column
;
196 renderer
= gtk_cell_renderer_text_new ();
197 g_signal_connect (renderer
, "edited",
198 G_CALLBACK (treeview_edited_cb
), vt
);
200 g_object_set (G_OBJECT (renderer
), "xalign", 0.0, NULL
);
202 col_offset
= gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vt
),
206 "editable", EDITABLE_COLUMN
,
209 column
= gtk_tree_view_get_column (GTK_TREE_VIEW (vt
), col_offset
- 1);
210 gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column
),
211 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
212 gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
215 renderer
= gtk_cell_renderer_pixbuf_new ();
217 g_object_set (G_OBJECT (renderer
), "xalign", 0.5, NULL
);
219 col_offset
= gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (vt
),
225 column
= gtk_tree_view_get_column (GTK_TREE_VIEW (vt
), col_offset
- 1);
226 gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column
),
227 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
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_sizing (GTK_TREE_VIEW_COLUMN (column
),
248 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
252 static void select_cb(GtkTreeSelection
*selection
, gpointer data
)
254 VikTreeview
*vt
= data
;
256 GtkTreeIter iter
, parent
;
260 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) return;
261 type
= vik_treeview_item_get_type( vt
, &iter
);
263 while ( type
!= VIK_TREEVIEW_TYPE_LAYER
) {
264 if ( ! vik_treeview_item_get_parent_iter ( vt
, &iter
, &parent
) )
267 type
= vik_treeview_item_get_type (vt
, &iter
);
270 vl
= VIK_LAYER( vik_treeview_item_get_pointer ( vt
, &iter
) );
272 vw
= VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl
));
273 vik_window_selected_layer(vw
, vl
);
276 static gboolean
treeview_selection_filter(GtkTreeSelection
*selection
, GtkTreeModel
*model
, GtkTreePath
*path
, gboolean path_currently_selected
, gpointer data
)
278 VikTreeview
*vt
= data
;
280 if (vt
->was_a_toggle
) {
281 vt
->was_a_toggle
= FALSE
;
288 void treeview_init ( VikTreeview
*vt
)
292 vt
->was_a_toggle
= FALSE
;
294 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
));
296 /* create tree view */
297 gtk_tree_selection_set_select_function(gtk_tree_view_get_selection (GTK_TREE_VIEW(vt
)), treeview_selection_filter
, vt
, NULL
);
299 gtk_tree_view_set_model ( GTK_TREE_VIEW(vt
), vt
->model
);
300 treeview_add_columns ( vt
);
301 g_object_unref (vt
->model
);
303 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (vt
), TRUE
);
304 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (vt
)),
305 GTK_SELECTION_SINGLE
);
307 /* Override treestore's dnd methods only; this is easier than deriving from GtkTreeStore.
308 * The downside is that all treestores will have this behavior, so this needs to be
309 * changed if we add more treeviews in the future. //Alex
312 GtkTreeDragSourceIface
*isrc
;
313 GtkTreeDragDestIface
*idest
;
315 isrc
= g_type_interface_peek (g_type_class_peek(G_OBJECT_TYPE(vt
->model
)), GTK_TYPE_TREE_DRAG_SOURCE
);
316 isrc
->drag_data_delete
= treeview_drag_data_delete
;
318 idest
= g_type_interface_peek (g_type_class_peek(G_OBJECT_TYPE(vt
->model
)), GTK_TYPE_TREE_DRAG_DEST
);
319 idest
->drag_data_received
= treeview_drag_data_received
;
322 for ( i
= 0; i
< VIK_LAYER_NUM_TYPES
; i
++ )
323 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. */
325 gtk_tree_view_set_reorderable (GTK_TREE_VIEW(vt
), TRUE
);
326 g_signal_connect(gtk_tree_view_get_selection (GTK_TREE_VIEW (vt
)), "changed",
327 G_CALLBACK(select_cb
), vt
);
331 gboolean
vik_treeview_item_get_parent_iter ( VikTreeview
*vt
, GtkTreeIter
*iter
, GtkTreeIter
*parent
)
333 return gtk_tree_model_iter_parent ( GTK_TREE_MODEL(vt
->model
), parent
, iter
);
336 gboolean
vik_treeview_move_item ( VikTreeview
*vt
, GtkTreeIter
*iter
, gboolean up
)
338 gint t
= vik_treeview_item_get_type ( vt
, iter
);
339 if ( t
== VIK_TREEVIEW_TYPE_LAYER
)
341 GtkTreeIter switch_iter
;
344 /* iter to path to iter */
345 GtkTreePath
*path
= gtk_tree_model_get_path ( vt
->model
, iter
);
346 if ( !gtk_tree_path_prev ( path
) || !gtk_tree_model_get_iter ( vt
->model
, &switch_iter
, path
) )
348 gtk_tree_path_free ( path
);
351 gtk_tree_path_free ( path
);
356 if ( !gtk_tree_model_iter_next ( vt
->model
, &switch_iter
) )
359 gtk_tree_store_swap ( GTK_TREE_STORE(vt
->model
), iter
, &switch_iter
);
361 /* now, the easy part. actually switching them, not the GUI */
362 } /* if item is map */
366 gboolean
vik_treeview_get_iter_at_pos ( VikTreeview
*vt
, GtkTreeIter
*iter
, gint x
, gint y
)
369 gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW(vt
), x
, y
, &path
, NULL
, NULL
, NULL
);
373 gtk_tree_model_get_iter (GTK_TREE_MODEL(vt
->model
), iter
, path
);
374 gtk_tree_path_free ( path
);
378 void vik_treeview_select_iter ( VikTreeview
*vt
, GtkTreeIter
*iter
)
380 gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( vt
) ), iter
);
383 gboolean
vik_treeview_get_selected_iter ( VikTreeview
*vt
, GtkTreeIter
*iter
)
385 return gtk_tree_selection_get_selected ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( vt
) ), NULL
, iter
);
388 void vik_treeview_item_delete ( VikTreeview
*vt
, GtkTreeIter
*iter
)
390 gtk_tree_store_remove ( GTK_TREE_STORE(vt
->model
), iter
);
393 /* Treeview Reform Project */
395 void vik_treeview_item_set_name ( VikTreeview
*vt
, GtkTreeIter
*iter
, const gchar
*to
)
397 g_return_if_fail ( iter
!= NULL
&& to
!= NULL
);
398 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, to
, -1);
401 void vik_treeview_item_set_visible ( VikTreeview
*vt
, GtkTreeIter
*iter
, gboolean to
)
403 g_return_if_fail ( iter
!= NULL
);
404 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, VISIBLE_COLUMN
, to
, -1 );
407 void vik_treeview_expand ( VikTreeview
*vt
, GtkTreeIter
*iter
)
410 path
= gtk_tree_model_get_path ( vt
->model
, iter
);
411 gtk_tree_view_expand_row ( GTK_TREE_VIEW(vt
), path
, FALSE
);
412 gtk_tree_path_free ( path
);
415 void vik_treeview_item_select ( VikTreeview
*vt
, GtkTreeIter
*iter
)
417 gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( vt
) ), iter
);
420 void vik_treeview_add_layer ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
,
421 gpointer item
, gint data
, gint icon_type
)
423 g_assert ( iter
!= NULL
);
424 g_assert ( icon_type
< VIK_LAYER_NUM_TYPES
);
425 gtk_tree_store_prepend ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
426 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, name
, VISIBLE_COLUMN
, TRUE
,
427 TYPE_COLUMN
, VIK_TREEVIEW_TYPE_LAYER
, ITEM_PARENT_COLUMN
, parent
, ITEM_POINTER_COLUMN
, item
,
428 ITEM_DATA_COLUMN
, data
, HAS_VISIBLE_COLUMN
, TRUE
, EDITABLE_COLUMN
, TRUE
,
429 ICON_COLUMN
, icon_type
>= 0 ? vt
->layer_type_icons
[icon_type
] : NULL
, -1 );
432 void vik_treeview_insert_layer ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
,
433 gpointer item
, gint data
, gint icon_type
, GtkTreeIter
*sibling
)
435 g_assert ( iter
!= NULL
);
436 g_assert ( icon_type
< VIK_LAYER_NUM_TYPES
);
438 gtk_tree_store_insert_before ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
, sibling
);
440 gtk_tree_store_append ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
443 gtk_tree_store_set ( GTK_TREE_STORE(vt
->model
), iter
, NAME_COLUMN
, name
, VISIBLE_COLUMN
, TRUE
,
444 TYPE_COLUMN
, VIK_TREEVIEW_TYPE_LAYER
, ITEM_PARENT_COLUMN
, parent
, ITEM_POINTER_COLUMN
, item
,
445 ITEM_DATA_COLUMN
, data
, HAS_VISIBLE_COLUMN
, TRUE
, EDITABLE_COLUMN
, TRUE
,
446 ICON_COLUMN
, icon_type
>= 0 ? vt
->layer_type_icons
[icon_type
] : NULL
, -1 );
449 void vik_treeview_add_sublayer ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
, gpointer item
,
450 gint data
, GdkPixbuf
*icon
, gboolean has_visible
, gboolean editable
)
452 g_assert ( iter
!= NULL
);
454 gtk_tree_store_prepend ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
455 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 );
459 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
461 void vik_treeview_sublayer_realphabetize ( VikTreeview
*vt
, GtkTreeIter
*iter
, const gchar
*newname
)
463 GtkTreeIter search_iter
, parent_iter
;
464 gchar
*search_name
= NULL
;
465 g_assert ( iter
!= NULL
);
467 gtk_tree_model_iter_parent ( vt
->model
, &parent_iter
, iter
);
469 g_assert ( gtk_tree_model_iter_children ( vt
->model
, &search_iter
, &parent_iter
) );
472 gtk_tree_model_get ( vt
->model
, &search_iter
, NAME_COLUMN
, &search_name
, -1 );
473 if ( strcmp ( search_name
, newname
) > 0 ) /* not >= or would trip on itself */
475 gtk_tree_store_move_before ( GTK_TREE_STORE(vt
->model
), iter
, &search_iter
);
476 g_free (search_name
);
480 g_free (search_name
);
482 } while ( gtk_tree_model_iter_next ( vt
->model
, &search_iter
) );
484 gtk_tree_store_move_before ( GTK_TREE_STORE(vt
->model
), iter
, NULL
);
487 void vik_treeview_add_sublayer_alphabetized
488 ( VikTreeview
*vt
, GtkTreeIter
*parent_iter
, GtkTreeIter
*iter
, const gchar
*name
, gpointer parent
, gpointer item
,
489 gint data
, GdkPixbuf
*icon
, gboolean has_visible
, gboolean editable
)
491 GtkTreeIter search_iter
;
492 gchar
*search_name
= NULL
;
493 g_assert ( iter
!= NULL
);
495 if ( gtk_tree_model_iter_children ( vt
->model
, &search_iter
, parent_iter
) )
497 gboolean found_greater_string
= FALSE
;
499 gtk_tree_model_get ( vt
->model
, &search_iter
, NAME_COLUMN
, &search_name
, -1 );
500 if ( strcmp ( search_name
, name
) >= 0 )
502 gtk_tree_store_insert_before ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
, &search_iter
);
503 found_greater_string
= TRUE
;
504 g_free (search_name
);
508 g_free (search_name
);
510 } while ( gtk_tree_model_iter_next ( vt
->model
, &search_iter
) );
512 if ( ! found_greater_string
)
513 gtk_tree_store_append ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
516 gtk_tree_store_prepend ( GTK_TREE_STORE(vt
->model
), iter
, parent_iter
);
518 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 );
523 static void treeview_finalize ( GObject
*gob
)
525 VikTreeview
*vt
= VIK_TREEVIEW ( gob
);
528 for ( i
= 0; i
< VIK_LAYER_NUM_TYPES
; i
++ )
529 if ( vt
->layer_type_icons
[i
] != NULL
)
530 g_object_unref ( G_OBJECT(vt
->layer_type_icons
[i
]) );
532 G_OBJECT_CLASS(parent_class
)->finalize(gob
);
535 static gboolean
treeview_drag_data_received (GtkTreeDragDest
*drag_dest
, GtkTreePath
*dest
, GtkSelectionData
*selection_data
)
537 GtkTreeModel
*tree_model
;
538 GtkTreeStore
*tree_store
;
539 GtkTreeModel
*src_model
= NULL
;
540 GtkTreePath
*src_path
= NULL
, *dest_cp
= NULL
;
541 gboolean retval
= FALSE
;
542 GtkTreeIter src_iter
, root_iter
, dest_iter
, dest_parent
;
547 g_return_val_if_fail (GTK_IS_TREE_STORE (drag_dest
), FALSE
);
549 tree_model
= GTK_TREE_MODEL (drag_dest
);
550 tree_store
= GTK_TREE_STORE (drag_dest
);
552 if (gtk_tree_get_row_drag_data (selection_data
, &src_model
, &src_path
) && src_model
== tree_model
) {
554 * Copy src_path to dest. There are two subcases here, depending on what
557 * 1. src_path is a layer. In this case, interpret the drop
558 * as a request to move the layer to a different aggregate layer.
559 * If the destination is not an aggregate layer, use the first
562 * 2. src_path is a sublayer. In this case, find ancestors of
563 * both source and destination nodes who are full layers,
564 * and call the move method of that layer type.
567 if (!gtk_tree_model_get_iter (src_model
, &src_iter
, src_path
)) {
570 if (!gtk_tree_path_compare(src_path
, dest
)) {
574 i_src
= gtk_tree_path_get_indices (src_path
);
575 dest_cp
= gtk_tree_path_copy (dest
);
577 gtk_tree_model_get_iter_first(tree_model
, &root_iter
);
578 TREEVIEW_GET(tree_model
, &root_iter
, ITEM_POINTER_COLUMN
, &vl
);
582 if (gtk_tree_path_get_depth(dest_cp
)>1) { /* can't be sibling of top layer */
583 VikLayer
*vl_src
, *vl_dest
;
585 /* Find the first ancestor that is a full layer, and store in dest_parent.
586 * In addition, put in dest_iter where Gtk wants us to insert the dragged object.
587 * (Note that this may end up being an invalid iter).
590 gtk_tree_path_up(dest_cp
);
591 dest_iter
= dest_parent
;
592 gtk_tree_model_get_iter (src_model
, &dest_parent
, dest_cp
);
593 } while (gtk_tree_path_get_depth(dest_cp
)>1 &&
594 vik_treeview_item_get_type(vt
, &dest_parent
) != VIK_TREEVIEW_TYPE_LAYER
);
597 g_assert ( vik_treeview_item_get_parent(vt
, &src_iter
) );
598 vl_src
= vik_treeview_item_get_parent(vt
, &src_iter
);
599 vl_dest
= vik_treeview_item_get_pointer(vt
, &dest_parent
);
601 /* TODO: might want to allow different types, and let the clients handle how they want */
602 if (vl_src
->type
== vl_dest
->type
&& vik_layer_get_interface(vl_dest
->type
)->drag_drop_request
) {
603 // g_print("moving an item from layer '%s' into layer '%s'\n", vl_src->name, vl_dest->name);
604 vik_layer_get_interface(vl_dest
->type
)->drag_drop_request(vl_src
, vl_dest
, &src_iter
, dest
);
611 gtk_tree_path_free(dest_cp
);
613 gtk_tree_path_free (src_path
);
619 * This may not be necessary.
621 static gboolean
treeview_drag_data_delete ( GtkTreeDragSource
*drag_source
, GtkTreePath
*path
)
623 gchar
*s_dest
= gtk_tree_path_to_string(path
);
624 g_print(_("delete data from %s\n"), s_dest
);