QA: strong type the second argument of the *_post_read functions.
[viking.git] / src / viklayerspanel.c
bloba7ff0054a06c5be8006a9494d163809685643271
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 #include "viking.h"
24 #include <string.h>
26 enum {
27 VLP_UPDATE_SIGNAL,
28 VLP_LAST_SIGNAL
31 static void layers_panel_class_init ( VikLayersPanelClass *klass );
32 static void layers_panel_init ( VikLayersPanel *vlp );
33 static void layers_item_edited (VikLayersPanel *vlp, GtkTreeIter *iter, const gchar *new_text);
34 static void layers_item_toggled (VikLayersPanel *vlp, GtkTreeIter *iter);
36 static guint layers_panel_signals[VLP_LAST_SIGNAL] = { 0 };
38 static GObjectClass *parent_class;
40 struct _VikLayersPanel {
41 GtkVBox vbox;
43 VikAggregateLayer *toplayer;
44 GtkTreeIter toplayer_iter;
46 VikTreeview *vt;
47 VikViewport *vvp; /* reference */
49 GtkItemFactory *popup_factory;
52 static GtkItemFactoryEntry base_entries[] = {
53 { "/C_ut", NULL, (GtkItemFactoryCallback) vik_layers_panel_cut_selected, -1, "<StockItem>", GTK_STOCK_CUT },
54 { "/_Copy", NULL, (GtkItemFactoryCallback) vik_layers_panel_copy_selected, -1, "<StockItem>", GTK_STOCK_COPY },
55 { "/_Paste", NULL, (GtkItemFactoryCallback) vik_layers_panel_paste_selected, -1, "<StockItem>", GTK_STOCK_PASTE },
56 { "/_Delete", NULL, (GtkItemFactoryCallback) vik_layers_panel_delete_selected, -1, "<StockItem>", GTK_STOCK_DELETE },
57 { "/New Layer", NULL, NULL, -1, "<Branch>" },
60 #define NUM_BASE_ENTRIES 5
62 static void layers_item_toggled (VikLayersPanel *vlp, GtkTreeIter *iter);
63 static void layers_item_edited (VikLayersPanel *vlp, GtkTreeIter *iter, const gchar *new_text);
64 static void layers_popup_cb (VikLayersPanel *vlp);
65 static void layers_popup ( VikLayersPanel *vlp, GtkTreeIter *iter, gint mouse_button );
66 static gboolean layers_button_press_cb (VikLayersPanel *vlp, GdkEventButton *event);
67 static void layers_move_item ( VikLayersPanel *vlp, gboolean up );
68 static void layers_move_item_up ( VikLayersPanel *vlp );
69 static void layers_move_item_down ( VikLayersPanel *vlp );
70 static void layers_panel_finalize ( GObject *gob );
72 GType vik_layers_panel_get_type()
74 static GType vlp_type = 0;
76 if (!vlp_type)
78 static const GTypeInfo vlp_info =
80 sizeof (VikLayersPanelClass),
81 NULL, /* base_init */
82 NULL, /* base_finalize */
83 (GClassInitFunc) layers_panel_class_init,
84 NULL, /* class_finalize */
85 NULL, /* class_data */
86 sizeof (VikLayersPanel),
88 (GInstanceInitFunc) layers_panel_init,
90 vlp_type = g_type_register_static ( GTK_TYPE_VBOX, "VikLayersPanel", &vlp_info, 0 );
93 return vlp_type;
96 static void layers_panel_class_init ( VikLayersPanelClass *klass )
98 GObjectClass *object_class;
100 object_class = G_OBJECT_CLASS (klass);
102 object_class->finalize = layers_panel_finalize;
104 parent_class = g_type_class_peek_parent (klass);
106 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);
109 VikLayersPanel *vik_layers_panel_new ()
111 return VIK_LAYERS_PANEL ( g_object_new ( VIK_LAYERS_PANEL_TYPE, NULL ) );
114 void vik_layers_panel_set_viewport ( VikLayersPanel *vlp, VikViewport *vvp )
116 vlp->vvp = vvp;
117 /* TODO: also update GCs (?) */
120 VikViewport *vik_layers_panel_get_viewport ( VikLayersPanel *vlp )
122 return vlp->vvp;
125 static void layers_panel_init ( VikLayersPanel *vlp )
127 GtkWidget *hbox;
128 GtkWidget *upbutton, *upimage, *downbutton, *downimage;
129 GtkWidget *scrolledwindow;
130 GtkItemFactoryEntry entry;
131 guint i, tmp;
133 vlp->vvp = NULL;
135 hbox = gtk_hbox_new ( TRUE, 2 );
136 vlp->vt = vik_treeview_new ( );
138 vlp->toplayer = vik_aggregate_layer_new ();
139 vik_layer_rename ( VIK_LAYER(vlp->toplayer), "Top Layer");
140 g_signal_connect_swapped ( G_OBJECT(vlp->toplayer), "update", G_CALLBACK(vik_layers_panel_emit_update), vlp );
142 vik_treeview_add_layer ( vlp->vt, NULL, &(vlp->toplayer_iter), VIK_LAYER(vlp->toplayer)->name, NULL, vlp->toplayer, VIK_LAYER_AGGREGATE, VIK_LAYER_AGGREGATE );
143 vik_layer_realize ( VIK_LAYER(vlp->toplayer), vlp->vt, &(vlp->toplayer_iter) );
145 g_signal_connect_swapped ( vlp->vt, "popup_menu", G_CALLBACK(layers_popup_cb), vlp);
146 g_signal_connect_swapped ( vlp->vt, "button_press_event", G_CALLBACK(layers_button_press_cb), vlp);
147 g_signal_connect_swapped ( vlp->vt, "item_toggled", G_CALLBACK(layers_item_toggled), vlp);
148 g_signal_connect_swapped ( vlp->vt, "item_edited", G_CALLBACK(layers_item_edited), vlp);
150 upimage = gtk_image_new_from_stock ( GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON );
151 upbutton = gtk_button_new ( );
152 gtk_container_add ( GTK_CONTAINER(upbutton), upimage );
153 gtk_box_pack_start ( GTK_BOX(hbox), upbutton, TRUE, TRUE, 0 );
154 g_signal_connect_swapped ( G_OBJECT(upbutton), "clicked", G_CALLBACK(layers_move_item_up), vlp );
155 downimage = gtk_image_new_from_stock ( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON );
156 downbutton = gtk_button_new ( );
157 gtk_container_add ( GTK_CONTAINER(downbutton), downimage );
158 gtk_box_pack_start ( GTK_BOX(hbox), downbutton, TRUE, TRUE, 0 );
159 g_signal_connect_swapped ( G_OBJECT(downbutton), "clicked", G_CALLBACK(layers_move_item_down), vlp );
161 scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
162 gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
163 gtk_container_add ( GTK_CONTAINER(scrolledwindow), GTK_WIDGET(vlp->vt) );
165 gtk_box_pack_start ( GTK_BOX(vlp), scrolledwindow, TRUE, TRUE, 0 );
166 gtk_box_pack_start ( GTK_BOX(vlp), hbox, FALSE, FALSE, 0 );
168 vlp->popup_factory = gtk_item_factory_new ( GTK_TYPE_MENU, "<main>", NULL );
169 gtk_item_factory_create_items ( vlp->popup_factory, NUM_BASE_ENTRIES, base_entries, vlp );
170 for ( i = 0; i < VIK_LAYER_NUM_TYPES; i++ )
172 /* TODO: FIXME: if name has a '/' in it it will get all messed up. why not have an itemfactory field with
173 name, icon, shortcut, etc.? */
174 entry.path = g_strdup_printf("%s/New %s Layer", base_entries[NUM_BASE_ENTRIES-1].path, vik_layer_get_interface(i)->name );
175 entry.accelerator = NULL;
176 entry.callback = (GtkItemFactoryCallback) vik_layers_panel_new_layer;
177 entry.callback_action = i;
178 if ( vik_layer_get_interface(i)->icon )
180 entry.item_type = "<ImageItem>";
181 entry.extra_data = gdk_pixdata_serialize ( vik_layer_get_interface(i)->icon, &tmp );
183 else
184 entry.item_type = "<Item>";
186 gtk_item_factory_create_item ( vlp->popup_factory, &entry, vlp, 1 );
187 g_free ( (gpointer) entry.extra_data );
188 g_free ( entry.path );
192 void vik_layers_panel_emit_update ( VikLayersPanel *vlp )
194 g_signal_emit ( G_OBJECT(vlp), layers_panel_signals[VLP_UPDATE_SIGNAL], 0 );
197 static void layers_item_toggled (VikLayersPanel *vlp, GtkTreeIter *iter)
199 gboolean visible;
200 gpointer p;
201 gint type;
203 /* get type and data */
204 type = vik_treeview_item_get_type ( vlp->vt, iter );
205 p = vik_treeview_item_get_pointer ( vlp->vt, iter );
207 switch ( type )
209 case VIK_TREEVIEW_TYPE_LAYER: visible = (VIK_LAYER(p)->visible ^= 1); break;
210 case VIK_TREEVIEW_TYPE_SUBLAYER: visible = vik_layer_sublayer_toggle_visible ( VIK_LAYER(vik_treeview_item_get_parent(vlp->vt, iter)), vik_treeview_item_get_data(vlp->vt, iter), p); break;
211 default: return;
214 vik_treeview_item_set_visible ( vlp->vt, iter, visible );
216 vik_layers_panel_emit_update ( vlp );
219 static void layers_item_edited (VikLayersPanel *vlp, GtkTreeIter *iter, const gchar *new_text)
221 if ( vik_treeview_item_get_type ( vlp->vt, iter ) == VIK_TREEVIEW_TYPE_LAYER )
223 VikLayer *l;
225 /* get iter and layer */
226 l = VIK_LAYER ( vik_treeview_item_get_pointer ( vlp->vt, iter ) );
228 if ( strcmp ( l->name, new_text ) != 0 )
230 vik_layer_rename ( l, new_text );
231 vik_treeview_item_set_name ( vlp->vt, iter, l->name );
234 else
236 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 );
237 if ( name )
238 vik_treeview_item_set_name ( vlp->vt, iter, name);
242 static gboolean layers_button_press_cb ( VikLayersPanel *vlp, GdkEventButton *event )
244 if (event->button == 3)
246 GtkTreeIter iter;
247 if ( vik_treeview_get_iter_at_pos ( vlp->vt, &iter, event->x, event->y ) )
249 layers_popup ( vlp, &iter, 3 );
250 vik_treeview_item_select ( vlp->vt, &iter );
252 else
253 layers_popup ( vlp, NULL, 3 );
254 return TRUE;
256 return FALSE;
259 static void layers_popup ( VikLayersPanel *vlp, GtkTreeIter *iter, gint mouse_button )
261 GtkMenu *menu = NULL;
264 if ( iter )
266 if ( vik_treeview_item_get_type ( vlp->vt, iter ) == VIK_TREEVIEW_TYPE_LAYER )
268 VikLayer *layer = VIK_LAYER(vik_treeview_item_get_pointer ( vlp->vt, iter ));
270 if ( layer->type == VIK_LAYER_AGGREGATE )
271 menu = GTK_MENU(gtk_item_factory_get_widget ( vlp->popup_factory, "<main>" ));
272 else
274 GtkWidget *del, *prop;
275 VikStdLayerMenuItem menu_selection = vik_layer_get_menu_items_selection(layer);
277 menu = GTK_MENU ( gtk_menu_new () );
279 if (menu_selection & VIK_MENU_ITEM_PROPERTY) {
280 prop = gtk_image_menu_item_new_from_stock ( GTK_STOCK_PROPERTIES, NULL );
281 g_signal_connect_swapped ( G_OBJECT(prop), "activate", G_CALLBACK(vik_layers_panel_properties), vlp );
282 gtk_menu_shell_append (GTK_MENU_SHELL (menu), prop);
283 gtk_widget_show ( prop );
286 if (menu_selection & VIK_MENU_ITEM_CUT) {
287 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_CUT, NULL );
288 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_cut_selected), vlp );
289 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
290 gtk_widget_show ( del );
293 if (menu_selection & VIK_MENU_ITEM_COPY) {
294 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_COPY, NULL );
295 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_copy_selected), vlp );
296 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
297 gtk_widget_show ( del );
300 if (menu_selection & VIK_MENU_ITEM_PASTE) {
301 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_PASTE, NULL );
302 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_paste_selected), vlp );
303 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
304 gtk_widget_show ( del );
307 if (menu_selection & VIK_MENU_ITEM_DELETE) {
308 del = gtk_image_menu_item_new_from_stock ( GTK_STOCK_DELETE, NULL );
309 g_signal_connect_swapped ( G_OBJECT(del), "activate", G_CALLBACK(vik_layers_panel_delete_selected), vlp );
310 gtk_menu_shell_append (GTK_MENU_SHELL (menu), del);
311 gtk_widget_show ( del );
314 vik_layer_add_menu_items ( layer, menu, vlp );
317 else
319 menu = GTK_MENU ( gtk_menu_new () );
320 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 ) )
322 gtk_widget_destroy ( GTK_WIDGET(menu) );
323 return;
325 /* TODO: specific things for different types */
328 else
329 menu = GTK_MENU(gtk_item_factory_get_widget ( vlp->popup_factory, base_entries[NUM_BASE_ENTRIES-1].path ));
330 gtk_menu_popup ( menu, NULL, NULL, NULL, NULL, mouse_button, gtk_get_current_event_time() );
333 static void layers_popup_cb ( VikLayersPanel *vlp )
335 GtkTreeIter iter;
336 layers_popup ( vlp, vik_treeview_get_selected_iter ( vlp->vt, &iter ) ? &iter : NULL, 0 );
339 gboolean vik_layers_panel_new_layer ( VikLayersPanel *vlp, gint type )
341 VikLayer *l;
342 g_assert ( vlp->vvp );
343 l = vik_layer_create ( type, vlp->vvp, VIK_GTK_WINDOW_FROM_WIDGET(vlp), TRUE );
344 if ( l )
346 vik_layers_panel_add_layer ( vlp, l );
347 vik_layers_panel_emit_update ( vlp );
348 return TRUE;
350 return FALSE;
353 void vik_layers_panel_add_layer ( VikLayersPanel *vlp, VikLayer *l )
355 GtkTreeIter iter;
356 GtkTreeIter *replace_iter = NULL;
358 /* could be something different so we have to do this */
359 vik_layer_change_coord_mode ( l, vik_viewport_get_coord_mode(vlp->vvp) );
361 if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
362 vik_aggregate_layer_add_layer ( vlp->toplayer, l );
363 else
365 VikAggregateLayer *addtoagg;
366 if (vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER )
368 if ( IS_VIK_AGGREGATE_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter )) )
369 addtoagg = VIK_AGGREGATE_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter ));
370 else {
371 VikLayer *vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter ));
372 while ( ! IS_VIK_AGGREGATE_LAYER(vl) ) {
373 iter = vl->iter;
374 vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &vl->iter ));
375 g_assert ( vl->realized );
377 addtoagg = VIK_AGGREGATE_LAYER(vl);
378 replace_iter = &iter;
381 else
383 /* a sublayer is selected, first get its parent (layer), then find the layer's parent (aggr. layer) */
384 VikLayer *vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter ));
385 replace_iter = &(vl->iter);
386 g_assert ( vl->realized );
387 addtoagg = VIK_AGGREGATE_LAYER(vik_treeview_item_get_parent ( vlp->vt, &(vl->iter) ) );
389 if ( replace_iter )
390 vik_aggregate_layer_insert_layer ( addtoagg, l, replace_iter );
391 else
392 vik_aggregate_layer_add_layer ( addtoagg, l );
396 static void layers_move_item ( VikLayersPanel *vlp, gboolean up )
398 GtkTreeIter iter;
399 VikAggregateLayer *parent;
401 /* TODO: deactivate the buttons and stuff */
402 if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
403 return;
405 vik_treeview_select_iter ( vlp->vt, &iter ); /* cancel any layer-name editing going on... */
407 if ( vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER )
409 parent = VIK_AGGREGATE_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter ));
410 if ( parent ) /* not toplevel */
412 vik_aggregate_layer_move_layer ( parent, &iter, up );
413 vik_layers_panel_emit_update ( vlp );
418 gboolean vik_layers_panel_properties ( VikLayersPanel *vlp )
420 GtkTreeIter iter;
421 g_assert ( vlp->vvp );
423 if ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) && vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER )
425 if ( vik_treeview_item_get_data ( vlp->vt, &iter ) == VIK_LAYER_AGGREGATE )
426 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), "Aggregate Layers have no settable properties." );
427 vik_layer_properties ( VIK_LAYER( vik_treeview_item_get_pointer ( vlp->vt, &iter ) ), vlp->vvp );
428 return TRUE;
430 else
431 return FALSE;
434 void vik_layers_panel_draw_all ( VikLayersPanel *vlp )
436 if ( vlp->vvp && VIK_LAYER(vlp->toplayer)->visible )
437 vik_aggregate_layer_draw ( vlp->toplayer, vlp->vvp );
440 void vik_layers_panel_draw_all_using_viewport ( VikLayersPanel *vlp, VikViewport *vvp )
442 if ( vlp->vvp && VIK_LAYER(vlp->toplayer)->visible )
443 vik_aggregate_layer_draw ( vlp->toplayer, vvp );
446 void vik_layers_panel_cut_selected ( VikLayersPanel *vlp )
448 gint type;
449 GtkTreeIter iter;
451 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
453 type = vik_treeview_item_get_type ( vlp->vt, &iter );
455 if ( type == VIK_TREEVIEW_TYPE_LAYER )
457 VikAggregateLayer *parent = vik_treeview_item_get_parent ( vlp->vt, &iter );
458 if ( parent )
460 a_clipboard_copy_selected ( vlp );
461 if ( vik_aggregate_layer_delete ( parent, &iter ) )
462 vik_layers_panel_emit_update ( vlp );
464 else
465 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), "You cannot cut the Top Layer." );
469 void vik_layers_panel_copy_selected ( VikLayersPanel *vlp )
471 gint type;
472 GtkTreeIter iter;
474 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
476 type = vik_treeview_item_get_type ( vlp->vt, &iter );
478 if ( type == VIK_TREEVIEW_TYPE_LAYER ) {
479 a_clipboard_copy_selected ( vlp );
483 void vik_layers_panel_paste_selected ( VikLayersPanel *vlp )
485 GtkTreeIter iter;
486 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
487 a_clipboard_paste ( vlp );
490 void vik_layers_panel_delete_selected ( VikLayersPanel *vlp )
492 gint type;
493 GtkTreeIter iter;
495 g_return_if_fail ( vik_treeview_get_selected_iter ( vlp->vt, &iter ) );
497 type = vik_treeview_item_get_type ( vlp->vt, &iter );
499 if ( type == VIK_TREEVIEW_TYPE_LAYER )
501 VikAggregateLayer *parent = vik_treeview_item_get_parent ( vlp->vt, &iter );
502 if ( parent )
504 if (IS_VIK_AGGREGATE_LAYER(parent)) {
505 if ( vik_aggregate_layer_delete ( parent, &iter ) )
506 vik_layers_panel_emit_update ( vlp );
509 else
510 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), "You cannot delete the Top Layer." );
512 else if (type == VIK_TREEVIEW_TYPE_SUBLAYER) {
513 VikLayer *sel = vik_layers_panel_get_selected ( vlp );
514 if ( vik_layer_get_interface(sel->type)->delete_item ) {
515 gint subtype = vik_treeview_item_get_data( vlp->vt, &iter);
516 vik_layer_get_interface(sel->type)->delete_item ( sel, subtype, vik_treeview_item_get_pointer(sel->vt, &iter) );
521 VikLayer *vik_layers_panel_get_selected ( VikLayersPanel *vlp )
523 GtkTreeIter iter, parent;
524 gint type;
526 if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
527 return NULL;
529 type = vik_treeview_item_get_type ( vlp->vt, &iter );
531 while ( type != VIK_TREEVIEW_TYPE_LAYER )
533 if ( ! vik_treeview_item_get_parent_iter ( vlp->vt, &iter, &parent ) )
534 return NULL;
535 iter = parent;
536 type = vik_treeview_item_get_type ( vlp->vt, &iter );
539 return VIK_LAYER( vik_treeview_item_get_pointer ( vlp->vt, &iter ) );
542 static void layers_move_item_up ( VikLayersPanel *vlp )
544 layers_move_item ( vlp, TRUE );
547 static void layers_move_item_down ( VikLayersPanel *vlp )
549 layers_move_item ( vlp, FALSE );
552 #if 0
553 gboolean vik_layers_panel_tool ( VikLayersPanel *vlp, guint16 layer_type, VikToolInterfaceFunc tool_func, GdkEventButton *event, VikViewport *vvp )
555 VikLayer *vl = vik_layers_panel_get_selected ( vlp );
556 if ( vl && vl->type == layer_type )
558 tool_func ( vl, event, vvp );
559 return TRUE;
561 else if ( VIK_LAYER(vlp->toplayer)->visible &&
562 vik_aggregate_layer_tool ( vlp->toplayer, layer_type, tool_func, event, vvp ) != 1 ) /* either accepted or rejected, but a layer was found */
563 return TRUE;
564 return FALSE;
566 #endif
568 VikLayer *vik_layers_panel_get_layer_of_type ( VikLayersPanel *vlp, gint type )
570 VikLayer *rv = vik_layers_panel_get_selected ( vlp );
571 if ( rv == NULL || rv->type != type )
572 if ( VIK_LAYER(vlp->toplayer)->visible )
573 return vik_aggregate_layer_get_top_visible_layer_of_type ( vlp->toplayer, type );
574 else
575 return NULL;
576 else
577 return rv;
580 GList *vik_layers_panel_get_all_layers_of_type(VikLayersPanel *vlp, gint type)
582 GList *layers = NULL;
584 return (vik_aggregate_layer_get_all_layers_of_type ( vlp->toplayer, layers, type ));
587 VikAggregateLayer *vik_layers_panel_get_top_layer ( VikLayersPanel *vlp )
589 return vlp->toplayer;
592 void vik_layers_panel_clear ( VikLayersPanel *vlp )
594 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 ) )
595 vik_aggregate_layer_clear ( vlp->toplayer ); /* simply deletes all layers */
598 void vik_layers_panel_change_coord_mode ( VikLayersPanel *vlp, VikCoordMode mode )
600 vik_layer_change_coord_mode ( VIK_LAYER(vlp->toplayer), mode );
603 static void layers_panel_finalize ( GObject *gob )
605 VikLayersPanel *vlp = VIK_LAYERS_PANEL ( gob );
606 g_object_unref ( VIK_LAYER(vlp->toplayer) );
607 g_object_unref ( G_OBJECT(vlp->popup_factory) );
608 G_OBJECT_CLASS(parent_class)->finalize(gob);