Marking translatable string in main.c
[viking.git] / src / viklayerspanel.c
blobddbcc47d8138838f99eec873a5e9072b425e3eb4
1 /*
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
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include "viking.h"
28 #include <string.h>
30 #include <glib/gi18n.h>
32 enum {
33 VLP_UPDATE_SIGNAL,
34 VLP_LAST_SIGNAL
37 static void layers_panel_class_init ( VikLayersPanelClass *klass );
38 static void layers_panel_init ( VikLayersPanel *vlp );
39 static void layers_item_edited (VikLayersPanel *vlp, GtkTreeIter *iter, const gchar *new_text);
40 static void layers_item_toggled (VikLayersPanel *vlp, GtkTreeIter *iter);
42 static guint layers_panel_signals[VLP_LAST_SIGNAL] = { 0 };
44 static GObjectClass *parent_class;
46 struct _VikLayersPanel {
47 GtkVBox vbox;
49 VikAggregateLayer *toplayer;
50 GtkTreeIter toplayer_iter;
52 VikTreeview *vt;
53 VikViewport *vvp; /* reference */
55 GtkItemFactory *popup_factory;
58 static GtkItemFactoryEntry base_entries[] = {
59 { N_("/C_ut"), NULL, (GtkItemFactoryCallback) vik_layers_panel_cut_selected, -1, "<StockItem>", GTK_STOCK_CUT },
60 { N_("/_Copy"), NULL, (GtkItemFactoryCallback) vik_layers_panel_copy_selected, -1, "<StockItem>", GTK_STOCK_COPY },
61 { N_("/_Paste"), NULL, (GtkItemFactoryCallback) vik_layers_panel_paste_selected, -1, "<StockItem>", GTK_STOCK_PASTE },
62 { N_("/_Delete"), NULL, (GtkItemFactoryCallback) vik_layers_panel_delete_selected, -1, "<StockItem>", GTK_STOCK_DELETE },
63 { N_("/New Layer"), NULL, NULL, -1, "<Branch>" },
66 #define NUM_BASE_ENTRIES 5
68 static void layers_item_toggled (VikLayersPanel *vlp, GtkTreeIter *iter);
69 static void layers_item_edited (VikLayersPanel *vlp, GtkTreeIter *iter, const gchar *new_text);
70 static void layers_popup_cb (VikLayersPanel *vlp);
71 static void layers_popup ( VikLayersPanel *vlp, GtkTreeIter *iter, gint mouse_button );
72 static gboolean layers_button_press_cb (VikLayersPanel *vlp, GdkEventButton *event);
73 static void layers_move_item ( VikLayersPanel *vlp, gboolean up );
74 static void layers_move_item_up ( VikLayersPanel *vlp );
75 static void layers_move_item_down ( VikLayersPanel *vlp );
76 static void layers_panel_finalize ( GObject *gob );
78 GType vik_layers_panel_get_type()
80 static GType vlp_type = 0;
82 if (!vlp_type)
84 static const GTypeInfo vlp_info =
86 sizeof (VikLayersPanelClass),
87 NULL, /* base_init */
88 NULL, /* base_finalize */
89 (GClassInitFunc) layers_panel_class_init,
90 NULL, /* class_finalize */
91 NULL, /* class_data */
92 sizeof (VikLayersPanel),
94 (GInstanceInitFunc) layers_panel_init,
96 vlp_type = g_type_register_static ( GTK_TYPE_VBOX, "VikLayersPanel", &vlp_info, 0 );
99 return vlp_type;
102 static void layers_panel_class_init ( VikLayersPanelClass *klass )
104 GObjectClass *object_class;
106 object_class = G_OBJECT_CLASS (klass);
108 object_class->finalize = layers_panel_finalize;
110 parent_class = g_type_class_peek_parent (klass);
112 layers_panel_signals[VLP_UPDATE_SIGNAL] = g_signal_new ( "update", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (VikLayersPanelClass, update), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
115 VikLayersPanel *vik_layers_panel_new ()
117 return VIK_LAYERS_PANEL ( g_object_new ( VIK_LAYERS_PANEL_TYPE, NULL ) );
120 void vik_layers_panel_set_viewport ( VikLayersPanel *vlp, VikViewport *vvp )
122 vlp->vvp = vvp;
123 /* TODO: also update GCs (?) */
126 VikViewport *vik_layers_panel_get_viewport ( VikLayersPanel *vlp )
128 return vlp->vvp;
131 static void layers_panel_init ( VikLayersPanel *vlp )
133 GtkWidget *hbox;
134 GtkWidget *upbutton, *upimage, *downbutton, *downimage;
135 GtkWidget *scrolledwindow;
136 GtkItemFactoryEntry entry;
137 guint i, tmp;
139 vlp->vvp = NULL;
141 hbox = gtk_hbox_new ( TRUE, 2 );
142 vlp->vt = vik_treeview_new ( );
144 vlp->toplayer = vik_aggregate_layer_new ();
145 vik_layer_rename ( VIK_LAYER(vlp->toplayer), _("Top Layer"));
146 g_signal_connect_swapped ( G_OBJECT(vlp->toplayer), "update", G_CALLBACK(vik_layers_panel_emit_update), vlp );
148 vik_treeview_add_layer ( vlp->vt, NULL, &(vlp->toplayer_iter), VIK_LAYER(vlp->toplayer)->name, NULL, vlp->toplayer, VIK_LAYER_AGGREGATE, VIK_LAYER_AGGREGATE );
149 vik_layer_realize ( VIK_LAYER(vlp->toplayer), vlp->vt, &(vlp->toplayer_iter) );
151 g_signal_connect_swapped ( vlp->vt, "popup_menu", G_CALLBACK(layers_popup_cb), vlp);
152 g_signal_connect_swapped ( vlp->vt, "button_press_event", G_CALLBACK(layers_button_press_cb), vlp);
153 g_signal_connect_swapped ( vlp->vt, "item_toggled", G_CALLBACK(layers_item_toggled), vlp);
154 g_signal_connect_swapped ( vlp->vt, "item_edited", G_CALLBACK(layers_item_edited), vlp);
156 upimage = gtk_image_new_from_stock ( GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON );
157 upbutton = gtk_button_new ( );
158 gtk_container_add ( GTK_CONTAINER(upbutton), upimage );
159 gtk_box_pack_start ( GTK_BOX(hbox), upbutton, TRUE, TRUE, 0 );
160 g_signal_connect_swapped ( G_OBJECT(upbutton), "clicked", G_CALLBACK(layers_move_item_up), vlp );
161 downimage = gtk_image_new_from_stock ( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON );
162 downbutton = gtk_button_new ( );
163 gtk_container_add ( GTK_CONTAINER(downbutton), downimage );
164 gtk_box_pack_start ( GTK_BOX(hbox), downbutton, TRUE, TRUE, 0 );
165 g_signal_connect_swapped ( G_OBJECT(downbutton), "clicked", G_CALLBACK(layers_move_item_down), vlp );
167 scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
168 gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
169 gtk_container_add ( GTK_CONTAINER(scrolledwindow), GTK_WIDGET(vlp->vt) );
171 gtk_box_pack_start ( GTK_BOX(vlp), scrolledwindow, TRUE, TRUE, 0 );
172 gtk_box_pack_start ( GTK_BOX(vlp), hbox, FALSE, FALSE, 0 );
174 vlp->popup_factory = gtk_item_factory_new ( GTK_TYPE_MENU, "<main>", NULL );
175 gtk_item_factory_create_items ( vlp->popup_factory, NUM_BASE_ENTRIES, base_entries, vlp );
176 for ( i = 0; i < VIK_LAYER_NUM_TYPES; i++ )
178 /* TODO: FIXME: if name has a '/' in it it will get all messed up. why not have an itemfactory field with
179 name, icon, shortcut, etc.? */
180 entry.path = g_strdup_printf("%s/New %s Layer", base_entries[NUM_BASE_ENTRIES-1].path, vik_layer_get_interface(i)->name );
181 entry.accelerator = NULL;
182 entry.callback = (GtkItemFactoryCallback) vik_layers_panel_new_layer;
183 entry.callback_action = i;
184 if ( vik_layer_get_interface(i)->icon )
186 entry.item_type = "<ImageItem>";
187 entry.extra_data = gdk_pixdata_serialize ( vik_layer_get_interface(i)->icon, &tmp );
189 else
190 entry.item_type = "<Item>";
192 gtk_item_factory_create_item ( vlp->popup_factory, &entry, vlp, 1 );
193 g_free ( (gpointer) entry.extra_data );
194 g_free ( entry.path );
198 void vik_layers_panel_emit_update ( VikLayersPanel *vlp )
200 g_signal_emit ( G_OBJECT(vlp), layers_panel_signals[VLP_UPDATE_SIGNAL], 0 );
203 static void layers_item_toggled (VikLayersPanel *vlp, GtkTreeIter *iter)
205 gboolean visible;
206 gpointer p;
207 gint type;
209 /* get type and data */
210 type = vik_treeview_item_get_type ( vlp->vt, iter );
211 p = vik_treeview_item_get_pointer ( vlp->vt, iter );
213 switch ( type )
215 case VIK_TREEVIEW_TYPE_LAYER:
216 visible = (VIK_LAYER(p)->visible ^= 1);
217 vik_layer_emit_update_although_invisible ( VIK_LAYER(p) ); /* set trigger for half-drawn */
218 break;
219 case VIK_TREEVIEW_TYPE_SUBLAYER:
220 visible = vik_layer_sublayer_toggle_visible ( VIK_LAYER(vik_treeview_item_get_parent(vlp->vt, iter)),
221 vik_treeview_item_get_data(vlp->vt, iter), p);
222 vik_layer_emit_update_although_invisible ( VIK_LAYER(vik_treeview_item_get_parent(vlp->vt, iter)) );
223 break;
224 default: return;
227 vik_treeview_item_set_visible ( vlp->vt, iter, visible );
230 static void layers_item_edited (VikLayersPanel *vlp, GtkTreeIter *iter, const gchar *new_text)
232 if ( vik_treeview_item_get_type ( vlp->vt, iter ) == VIK_TREEVIEW_TYPE_LAYER )
234 VikLayer *l;
236 /* get iter and layer */
237 l = VIK_LAYER ( vik_treeview_item_get_pointer ( vlp->vt, iter ) );
239 if ( strcmp ( l->name, new_text ) != 0 )
241 vik_layer_rename ( l, new_text );
242 vik_treeview_item_set_name ( vlp->vt, iter, l->name );
245 else
247 const gchar *name = vik_layer_sublayer_rename_request ( vik_treeview_item_get_parent ( vlp->vt, iter ), new_text, vlp, vik_treeview_item_get_data ( vlp->vt, iter ), vik_treeview_item_get_pointer ( vlp->vt, iter ), iter );
248 if ( name )
249 vik_treeview_item_set_name ( vlp->vt, iter, name);
253 static gboolean layers_button_press_cb ( VikLayersPanel *vlp, GdkEventButton *event )
255 if (event->button == 3)
257 GtkTreeIter iter;
258 if ( vik_treeview_get_iter_at_pos ( vlp->vt, &iter, event->x, event->y ) )
260 layers_popup ( vlp, &iter, 3 );
261 vik_treeview_item_select ( vlp->vt, &iter );
263 else
264 layers_popup ( vlp, NULL, 3 );
265 return TRUE;
267 return FALSE;
270 static void layers_popup ( VikLayersPanel *vlp, GtkTreeIter *iter, gint mouse_button )
272 GtkMenu *menu = NULL;
275 if ( iter )
277 if ( vik_treeview_item_get_type ( vlp->vt, iter ) == VIK_TREEVIEW_TYPE_LAYER )
279 VikLayer *layer = VIK_LAYER(vik_treeview_item_get_pointer ( vlp->vt, iter ));
281 if ( layer->type == VIK_LAYER_AGGREGATE )
282 menu = GTK_MENU(gtk_item_factory_get_widget ( vlp->popup_factory, "<main>" ));
283 else
285 GtkWidget *del, *prop;
286 VikStdLayerMenuItem menu_selection = vik_layer_get_menu_items_selection(layer);
288 menu = GTK_MENU ( gtk_menu_new () );
290 if (menu_selection & VIK_MENU_ITEM_PROPERTY) {
291 prop = gtk_image_menu_item_new_from_stock ( GTK_STOCK_PROPERTIES, NULL );
292 g_signal_connect_swapped ( G_OBJECT(prop), "activate", G_CALLBACK(vik_layers_panel_properties), vlp );
293 gtk_menu_shell_append (GTK_MENU_SHELL (menu), prop);
294 gtk_widget_show ( prop );
297 if (menu_selection & VIK_MENU_ITEM_CUT) {
298 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_CUT, NULL );
299 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_cut_selected), vlp );
300 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
301 gtk_widget_show ( del );
304 if (menu_selection & VIK_MENU_ITEM_COPY) {
305 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_COPY, NULL );
306 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_copy_selected), vlp );
307 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
308 gtk_widget_show ( del );
311 if (menu_selection & VIK_MENU_ITEM_PASTE) {
312 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_PASTE, NULL );
313 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_paste_selected), vlp );
314 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
315 gtk_widget_show ( del );
318 if (menu_selection & VIK_MENU_ITEM_DELETE) {
319 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_DELETE, NULL );
320 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_delete_selected), vlp );
321 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
322 gtk_widget_show ( del );
325 vik_layer_add_menu_items ( layer, menu, vlp );
328 else
330 menu = GTK_MENU ( gtk_menu_new () );
331 if ( ! vik_layer_sublayer_add_menu_items ( vik_treeview_item_get_parent ( vlp->vt, iter ), menu, vlp, vik_treeview_item_get_data ( vlp->vt, iter ), vik_treeview_item_get_pointer ( vlp->vt, iter ), iter ) )
333 gtk_widget_destroy ( GTK_WIDGET(menu) );
334 return;
336 /* TODO: specific things for different types */
339 else
340 menu = GTK_MENU(gtk_item_factory_get_widget ( vlp->popup_factory, base_entries[NUM_BASE_ENTRIES-1].path ));
341 gtk_menu_popup ( menu, NULL, NULL, NULL, NULL, mouse_button, gtk_get_current_event_time() );
344 static void layers_popup_cb ( VikLayersPanel *vlp )
346 GtkTreeIter iter;
347 layers_popup ( vlp, vik_treeview_get_selected_iter ( vlp->vt, &iter ) ? &iter : NULL, 0 );
350 gboolean vik_layers_panel_new_layer ( VikLayersPanel *vlp, gint type )
352 VikLayer *l;
353 g_assert ( vlp->vvp );
354 l = vik_layer_create ( type, vlp->vvp, VIK_GTK_WINDOW_FROM_WIDGET(vlp), TRUE );
355 if ( l )
357 vik_layers_panel_add_layer ( vlp, l );
358 vik_layers_panel_emit_update ( vlp );
359 return TRUE;
361 return FALSE;
364 void vik_layers_panel_add_layer ( VikLayersPanel *vlp, VikLayer *l )
366 GtkTreeIter iter;
367 GtkTreeIter *replace_iter = NULL;
369 /* could be something different so we have to do this */
370 vik_layer_change_coord_mode ( l, vik_viewport_get_coord_mode(vlp->vvp) );
372 if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
373 vik_aggregate_layer_add_layer ( vlp->toplayer, l );
374 else
376 VikAggregateLayer *addtoagg;
377 if (vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER )
379 if ( IS_VIK_AGGREGATE_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter )) )
380 addtoagg = VIK_AGGREGATE_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter ));
381 else {
382 VikLayer *vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter ));
383 while ( ! IS_VIK_AGGREGATE_LAYER(vl) ) {
384 iter = vl->iter;
385 vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &vl->iter ));
386 g_assert ( vl->realized );
388 addtoagg = VIK_AGGREGATE_LAYER(vl);
389 replace_iter = &iter;
392 else
394 /* a sublayer is selected, first get its parent (layer), then find the layer's parent (aggr. layer) */
395 VikLayer *vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter ));
396 replace_iter = &(vl->iter);
397 g_assert ( vl->realized );
398 VikLayer *grandpa = (vik_treeview_item_get_parent ( vlp->vt, &(vl->iter) ) );
399 if (IS_VIK_AGGREGATE_LAYER(grandpa))
400 addtoagg = VIK_AGGREGATE_LAYER(grandpa);
401 else {
402 addtoagg = vlp->toplayer;
403 replace_iter = &grandpa->iter;
406 if ( replace_iter )
407 vik_aggregate_layer_insert_layer ( addtoagg, l, replace_iter );
408 else
409 vik_aggregate_layer_add_layer ( addtoagg, l );
413 static void layers_move_item ( VikLayersPanel *vlp, gboolean up )
415 GtkTreeIter iter;
416 VikAggregateLayer *parent;
418 /* TODO: deactivate the buttons and stuff */
419 if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
420 return;
422 vik_treeview_select_iter ( vlp->vt, &iter ); /* cancel any layer-name editing going on... */
424 if ( vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER )
426 parent = VIK_AGGREGATE_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter ));
427 if ( parent ) /* not toplevel */
429 vik_aggregate_layer_move_layer ( parent, &iter, up );
430 vik_layers_panel_emit_update ( vlp );
435 gboolean vik_layers_panel_properties ( VikLayersPanel *vlp )
437 GtkTreeIter iter;
438 g_assert ( vlp->vvp );
440 if ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) && vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER )
442 if ( vik_treeview_item_get_data ( vlp->vt, &iter ) == VIK_LAYER_AGGREGATE )
443 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), _("Aggregate Layers have no settable properties.") );
444 vik_layer_properties ( VIK_LAYER( vik_treeview_item_get_pointer ( vlp->vt, &iter ) ), vlp->vvp );
445 return TRUE;
447 else
448 return FALSE;
451 void vik_layers_panel_draw_all ( VikLayersPanel *vlp )
453 if ( vlp->vvp && VIK_LAYER(vlp->toplayer)->visible )
454 vik_aggregate_layer_draw ( vlp->toplayer, vlp->vvp );
457 void vik_layers_panel_draw_all_using_viewport ( VikLayersPanel *vlp, VikViewport *vvp )
459 if ( vlp->vvp && VIK_LAYER(vlp->toplayer)->visible )
460 vik_aggregate_layer_draw ( vlp->toplayer, vvp );
463 void vik_layers_panel_cut_selected ( VikLayersPanel *vlp )
465 gint type;
466 GtkTreeIter iter;
468 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
470 type = vik_treeview_item_get_type ( vlp->vt, &iter );
472 if ( type == VIK_TREEVIEW_TYPE_LAYER )
474 VikAggregateLayer *parent = vik_treeview_item_get_parent ( vlp->vt, &iter );
476 if ( parent )
479 /* reset trigger if trigger deleted */
480 if ( vik_layers_panel_get_selected ( vlp ) == vik_viewport_get_trigger ( vlp->vvp ) )
481 vik_viewport_set_trigger ( vlp->vvp, NULL );
483 a_clipboard_copy_selected ( vlp );
484 if ( vik_aggregate_layer_delete ( parent, &iter ) )
485 vik_layers_panel_emit_update ( vlp );
487 else
488 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), _("You cannot cut the Top Layer.") );
492 void vik_layers_panel_copy_selected ( VikLayersPanel *vlp )
494 gint type;
495 GtkTreeIter iter;
497 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
499 type = vik_treeview_item_get_type ( vlp->vt, &iter );
501 if ( type == VIK_TREEVIEW_TYPE_LAYER ) {
502 a_clipboard_copy_selected ( vlp );
506 void vik_layers_panel_paste_selected ( VikLayersPanel *vlp )
508 GtkTreeIter iter;
509 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
510 a_clipboard_paste ( vlp );
513 void vik_layers_panel_delete_selected ( VikLayersPanel *vlp )
515 gint type;
516 GtkTreeIter iter;
518 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
520 type = vik_treeview_item_get_type ( vlp->vt, &iter );
522 if ( type == VIK_TREEVIEW_TYPE_LAYER )
524 VikAggregateLayer *parent = vik_treeview_item_get_parent ( vlp->vt, &iter );
525 if ( parent )
527 /* reset trigger if trigger deleted */
528 if ( vik_layers_panel_get_selected ( vlp ) == vik_viewport_get_trigger ( vlp->vvp ) )
529 vik_viewport_set_trigger ( vlp->vvp, NULL );
531 if (IS_VIK_AGGREGATE_LAYER(parent)) {
532 if ( vik_aggregate_layer_delete ( parent, &iter ) )
533 vik_layers_panel_emit_update ( vlp );
536 else
537 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), _("You cannot delete the Top Layer.") );
539 else if (type == VIK_TREEVIEW_TYPE_SUBLAYER) {
540 VikLayer *sel = vik_layers_panel_get_selected ( vlp );
541 if ( vik_layer_get_interface(sel->type)->delete_item ) {
542 gint subtype = vik_treeview_item_get_data( vlp->vt, &iter);
543 vik_layer_get_interface(sel->type)->delete_item ( sel, subtype, vik_treeview_item_get_pointer(sel->vt, &iter) );
548 VikLayer *vik_layers_panel_get_selected ( VikLayersPanel *vlp )
550 GtkTreeIter iter, parent;
551 gint type;
553 if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
554 return NULL;
556 type = vik_treeview_item_get_type ( vlp->vt, &iter );
558 while ( type != VIK_TREEVIEW_TYPE_LAYER )
560 if ( ! vik_treeview_item_get_parent_iter ( vlp->vt, &iter, &parent ) )
561 return NULL;
562 iter = parent;
563 type = vik_treeview_item_get_type ( vlp->vt, &iter );
566 return VIK_LAYER( vik_treeview_item_get_pointer ( vlp->vt, &iter ) );
569 static void layers_move_item_up ( VikLayersPanel *vlp )
571 layers_move_item ( vlp, TRUE );
574 static void layers_move_item_down ( VikLayersPanel *vlp )
576 layers_move_item ( vlp, FALSE );
579 #if 0
580 gboolean vik_layers_panel_tool ( VikLayersPanel *vlp, guint16 layer_type, VikToolInterfaceFunc tool_func, GdkEventButton *event, VikViewport *vvp )
582 VikLayer *vl = vik_layers_panel_get_selected ( vlp );
583 if ( vl && vl->type == layer_type )
585 tool_func ( vl, event, vvp );
586 return TRUE;
588 else if ( VIK_LAYER(vlp->toplayer)->visible &&
589 vik_aggregate_layer_tool ( vlp->toplayer, layer_type, tool_func, event, vvp ) != 1 ) /* either accepted or rejected, but a layer was found */
590 return TRUE;
591 return FALSE;
593 #endif
595 VikLayer *vik_layers_panel_get_layer_of_type ( VikLayersPanel *vlp, gint type )
597 VikLayer *rv = vik_layers_panel_get_selected ( vlp );
598 if ( rv == NULL || rv->type != type )
599 if ( VIK_LAYER(vlp->toplayer)->visible )
600 return vik_aggregate_layer_get_top_visible_layer_of_type ( vlp->toplayer, type );
601 else
602 return NULL;
603 else
604 return rv;
607 GList *vik_layers_panel_get_all_layers_of_type(VikLayersPanel *vlp, gint type)
609 GList *layers = NULL;
611 return (vik_aggregate_layer_get_all_layers_of_type ( vlp->toplayer, layers, type ));
614 VikAggregateLayer *vik_layers_panel_get_top_layer ( VikLayersPanel *vlp )
616 return vlp->toplayer;
619 void vik_layers_panel_clear ( VikLayersPanel *vlp )
621 if ( (! vik_aggregate_layer_is_empty(vlp->toplayer)) && a_dialog_overwrite ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), _("Are you sure you wish to delete all layers?"), NULL ) )
622 vik_aggregate_layer_clear ( vlp->toplayer ); /* simply deletes all layers */
625 void vik_layers_panel_change_coord_mode ( VikLayersPanel *vlp, VikCoordMode mode )
627 vik_layer_change_coord_mode ( VIK_LAYER(vlp->toplayer), mode );
630 static void layers_panel_finalize ( GObject *gob )
632 VikLayersPanel *vlp = VIK_LAYERS_PANEL ( gob );
633 g_object_unref ( VIK_LAYER(vlp->toplayer) );
634 g_object_unref ( G_OBJECT(vlp->popup_factory) );
635 G_OBJECT_CLASS(parent_class)->finalize(gob);