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
24 /* static for a very good reason -- share between windows */
28 #define DATA_SUBLAYER 2
30 guint8 type = DATA_NONE;
35 void a_clipboard_copy ( VikLayersPanel *vlp )
37 VikLayer *sel = vik_layers_panel_get_selected ( vlp );
42 vik_treeview_get_selected_iter ( sel->vt, &iter );
47 if ( vik_treeview_item_get_type ( sel->vt, &iter ) == VIK_TREEVIEW_TYPE_SUBLAYER )
49 layer_type = sel->type;
50 if ( vik_layer_get_interface(layer_type)->copy_item && (clipboard = vik_layer_get_interface(layer_type)->
51 copy_item(sel,subtype=vik_treeview_item_get_data(sel->vt,&iter),vik_treeview_item_get_pointer(sel->vt,&iter)) ))
57 g_object_ref ( G_OBJECT(sel) );
62 gboolean a_clipboard_paste ( VikLayersPanel *vlp )
64 if ( clipboard && type == DATA_LAYER )
66 /* oooh, _private_ ... so sue me, there's no other way to do this. */
67 if ( G_OBJECT(clipboard)->ref_count == 1 )
68 { /* optimization -- if layer has been deleted, don't copy the layer. */
69 g_object_ref ( G_OBJECT(clipboard) );
70 vik_layers_panel_add_layer ( vlp, VIK_LAYER(clipboard) );
75 VikLayer *new_layer = vik_layer_copy ( VIK_LAYER(clipboard), vik_layers_panel_get_viewport(vlp) );
78 vik_layers_panel_add_layer ( vlp, new_layer );
83 else if ( clipboard && type == DATA_SUBLAYER )
85 VikLayer *sel = vik_layers_panel_get_selected ( vlp );
86 if ( sel && sel->type == layer_type)
88 if ( vik_layer_get_interface(layer_type)->paste_item )
89 return vik_layer_get_interface(layer_type)->paste_item ( sel, subtype, clipboard );
92 a_dialog_error_msg_extra ( VIK_GTK_WINDOW_FROM_WIDGET(GTK_WIDGET(vlp)), "The clipboard contains sublayer data for a %s layers. You must select a layer of this type to paste the clipboard data.", vik_layer_get_interface(layer_type)->name );
98 void a_clipboard_uninit ()
100 if ( clipboard && type == DATA_LAYER )
101 g_object_unref ( G_OBJECT(clipboard) );
102 else if ( clipboard && type == DATA_SUBLAYER )
103 if ( vik_layer_get_interface(layer_type)->free_copied_item )
104 vik_layer_get_interface(layer_type)->free_copied_item(subtype,clipboard);