2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 * Copyright (C) 2005-2006, Alex Foobarian <foobarian@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "background.h"
30 #include "datasources.h"
35 #include "preferences.h"
36 #include "icons/icons.h"
37 #include "vikexttools.h"
38 #include "garminsymbols.h"
51 #include <glib/gstdio.h>
52 #include <glib/gprintf.h>
53 #include <glib/gi18n.h>
55 #include <gdk/gdkkeysyms.h>
57 #define VIKING_WINDOW_WIDTH 1000
58 #define VIKING_WINDOW_HEIGHT 800
59 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
60 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024
61 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
63 static void window_finalize ( GObject *gob );
64 static GObjectClass *parent_class;
66 static void window_init ( VikWindow *vw );
67 static void window_class_init ( VikWindowClass *klass );
68 static void window_set_filename ( VikWindow *vw, const gchar *filename );
70 static void draw_update ( VikWindow *vw );
72 static void newwindow_cb ( GtkAction *a, VikWindow *vw );
76 static gboolean delete_event( VikWindow *vw );
78 static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data );
80 static void window_configure_event ( VikWindow *vw );
81 static void draw_sync ( VikWindow *vw );
82 static void draw_redraw ( VikWindow *vw );
83 static void draw_scroll ( VikWindow *vw, GdkEventScroll *event );
84 static void draw_click ( VikWindow *vw, GdkEventButton *event );
85 static void draw_release ( VikWindow *vw, GdkEventButton *event );
86 static void draw_mouse_motion ( VikWindow *vw, GdkEventMotion *event );
87 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw );
88 static void draw_goto_cb ( GtkAction *a, VikWindow *vw );
90 static void draw_status ( VikWindow *vw );
92 /* End Drawing Functions */
94 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw );
95 static void menu_properties_cb ( GtkAction *a, VikWindow *vw );
96 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw );
104 #define TOOL_LAYER_TYPE_NONE -1
109 toolbox_tool_t *tools;
113 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw );
114 static toolbox_tools_t* toolbox_create(VikWindow *vw);
115 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type );
116 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
117 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
118 static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name);
119 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
120 static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event);
121 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
125 static void window_create_ui( VikWindow *window );
126 static void register_vik_icons (GtkIconFactory *icon_factory);
129 static void load_file ( GtkAction *a, VikWindow *vw );
130 static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
131 static gboolean save_file ( GtkAction *a, VikWindow *vw );
132 static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw );
133 static gboolean window_save ( VikWindow *vw );
137 VikViewport *viking_vvp;
138 VikLayersPanel *viking_vlp;
139 VikStatusbar *viking_vs;
143 GtkItemFactory *item_factory;
145 /* tool management state */
148 guint16 tool_layer_id;
149 guint16 tool_tool_id;
151 GtkActionGroup *action_group;
156 guint draw_image_width, draw_image_height;
157 gboolean draw_image_save_as_png;
162 GtkWidget *open_dia, *save_dia;
163 GtkWidget *save_img_dia, *save_img_dir_dia;
165 gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
168 /* half-drawn update */
170 VikCoord trigger_center;
172 /* Store at this level for highlighted selection drawing since it applies to the viewport and the layers panel */
173 /* Only one of these items can be selected at the same time */
174 gpointer selected_vtl; /* notionally VikTrwLayer */
175 gpointer selected_tracks; /* notionally GList */
176 gpointer selected_track; /* notionally VikTrack */
177 gpointer selected_waypoints; /* notionally GList */
178 gpointer selected_waypoint; /* notionally VikWaypoint */
179 /* only use for individual track or waypoint */
180 gpointer selected_name; /* notionally gchar */
181 ////// NEED TO THINK ABOUT VALIDITY OF THESE //////
182 ////// i.e. what happens when stuff is deleted elsewhere //////
183 ////// Generally seems alright as can not access them //////
184 ////// containing_vtl now seems unecessary //////
185 /* For track(s) & waypoint(s) it is the layer they are in - this helps refering to the individual item easier */
186 gpointer containing_vtl; /* notionally VikTrwLayer */
200 VW_OPENWINDOW_SIGNAL,
204 static guint window_signals[VW_LAST_SIGNAL] = { 0 };
206 static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler"), N_("Select") };
208 GType vik_window_get_type (void)
210 static GType vw_type = 0;
214 static const GTypeInfo vw_info =
216 sizeof (VikWindowClass),
217 NULL, /* base_init */
218 NULL, /* base_finalize */
219 (GClassInitFunc) window_class_init, /* class_init */
220 NULL, /* class_finalize */
221 NULL, /* class_data */
224 (GInstanceInitFunc) window_init,
226 vw_type = g_type_register_static ( GTK_TYPE_WINDOW, "VikWindow", &vw_info, 0 );
232 VikViewport * vik_window_viewport(VikWindow *vw)
234 return(vw->viking_vvp);
237 VikLayersPanel * vik_window_layers_panel(VikWindow *vw)
239 return(vw->viking_vlp);
243 * Returns the statusbar for the window
245 VikStatusbar * vik_window_get_statusbar ( VikWindow *vw )
247 return vw->viking_vs;
250 void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
252 int i, j, tool_count;
253 VikLayerInterface *layer_interface;
255 if (!vw->action_group) return;
257 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
259 layer_interface = vik_layer_get_interface(i);
260 tool_count = layer_interface->tools_count;
262 for (j = 0; j < tool_count; j++) {
263 action = gtk_action_group_get_action(vw->action_group,
264 layer_interface->tools[j].name);
265 g_object_set(action, "sensitive", i == vl->type, NULL);
270 static void window_finalize ( GObject *gob )
272 VikWindow *vw = VIK_WINDOW(gob);
273 g_return_if_fail ( vw != NULL );
275 a_background_remove_status ( vw->viking_vs );
277 G_OBJECT_CLASS(parent_class)->finalize(gob);
281 static void window_class_init ( VikWindowClass *klass )
284 GObjectClass *object_class;
286 window_signals[VW_NEWWINDOW_SIGNAL] = g_signal_new ( "newwindow", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (VikWindowClass, newwindow), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
287 window_signals[VW_OPENWINDOW_SIGNAL] = g_signal_new ( "openwindow", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (VikWindowClass, openwindow), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
289 object_class = G_OBJECT_CLASS (klass);
291 object_class->finalize = window_finalize;
293 parent_class = g_type_class_peek_parent (klass);
297 static void window_init ( VikWindow *vw )
299 GtkWidget *main_vbox;
302 vw->action_group = NULL;
304 vw->viking_vvp = vik_viewport_new();
305 vw->viking_vlp = vik_layers_panel_new();
306 vik_layers_panel_set_viewport ( vw->viking_vlp, vw->viking_vvp );
307 vw->viking_vs = vik_statusbar_new();
309 vw->vt = toolbox_create(vw);
310 window_create_ui(vw);
311 window_set_filename (vw, NULL);
312 vw->toolbar = GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar"));
314 toolbox_activate(vw->vt, "Pan");
317 vw->item_factory = NULL;
319 vw->modified = FALSE;
320 vw->only_updating_coord_mode_ui = FALSE;
322 vw->pan_move = FALSE;
323 vw->pan_x = vw->pan_y = -1;
324 vw->draw_image_width = DRAW_IMAGE_DEFAULT_WIDTH;
325 vw->draw_image_height = DRAW_IMAGE_DEFAULT_HEIGHT;
326 vw->draw_image_save_as_png = DRAW_IMAGE_DEFAULT_SAVE_AS_PNG;
328 main_vbox = gtk_vbox_new(FALSE, 1);
329 gtk_container_add (GTK_CONTAINER (vw), main_vbox);
331 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainMenu"), FALSE, TRUE, 0);
332 gtk_box_pack_start (GTK_BOX(main_vbox), GTK_WIDGET(vw->toolbar), FALSE, TRUE, 0);
333 gtk_toolbar_set_icon_size (vw->toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
334 gtk_toolbar_set_style (vw->toolbar, GTK_TOOLBAR_ICONS);
336 vik_ext_tools_add_menu_items ( vw, vw->uim );
338 g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
340 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw);
341 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw);
342 gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK );
343 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw);
344 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw);
345 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw);
346 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
347 g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
349 g_signal_connect_swapped (G_OBJECT (vw->viking_vvp), "key_press_event", G_CALLBACK (key_press_event), vw);
351 gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT);
353 hpaned = gtk_hpaned_new ();
354 gtk_paned_pack1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp), FALSE, FALSE );
355 gtk_paned_pack2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp), TRUE, TRUE );
357 /* This packs the button into the window (a gtk container). */
358 gtk_box_pack_start (GTK_BOX(main_vbox), hpaned, TRUE, TRUE, 0);
360 gtk_box_pack_end (GTK_BOX(main_vbox), GTK_WIDGET(vw->viking_vs), FALSE, TRUE, 0);
362 a_background_add_status(vw->viking_vs);
366 vw->save_img_dia = NULL;
367 vw->save_img_dir_dia = NULL;
370 VikWindow *vik_window_new ()
372 return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
375 static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data )
377 VikLayer *vl = vik_layers_panel_get_selected ( vw->viking_vlp );
378 if (vl && vw->vt->active_tool != -1 && vw->vt->tools[vw->vt->active_tool].ti.key_press ) {
379 gint ltype = vw->vt->tools[vw->vt->active_tool].layer_type;
380 if ( vl && ltype == vl->type )
381 return vw->vt->tools[vw->vt->active_tool].ti.key_press(vl, event, vw->vt->tools[vw->vt->active_tool].state);
384 // No layer - but enable window tool keypress processing - these should be able to handle a NULL layer
385 if ( vw->vt->tools[vw->vt->active_tool].ti.key_press ) {
386 return vw->vt->tools[vw->vt->active_tool].ti.key_press ( vl, event, vw->vt->tools[vw->vt->active_tool].state );
389 /* Restore Main Menu via Escape key if the user has hidden it */
390 /* This key is more likely to be used as they may not remember the function key */
391 if ( event->keyval == GDK_Escape ) {
392 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ViewMainMenu" );
394 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box) );
396 gtk_widget_show ( gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu" ) );
397 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(check_box), TRUE );
398 return TRUE; /* handled keypress */
403 return FALSE; /* don't handle the keypress */
406 static gboolean delete_event( VikWindow *vw )
408 #ifdef VIKING_PROMPT_IF_MODIFIED
415 dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
416 _("Do you want to save the changes you made to the document \"%s\"?\n"
418 "Your changes will be lost if you don't save them."),
419 vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") ) );
420 gtk_dialog_add_buttons ( dia, _("Don't Save"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
421 switch ( gtk_dialog_run ( dia ) )
423 case GTK_RESPONSE_NO: gtk_widget_destroy ( GTK_WIDGET(dia) ); return FALSE;
424 case GTK_RESPONSE_CANCEL: gtk_widget_destroy ( GTK_WIDGET(dia) ); return TRUE;
425 default: gtk_widget_destroy ( GTK_WIDGET(dia) ); return ! save_file(NULL, vw);
432 static void newwindow_cb ( GtkAction *a, VikWindow *vw )
434 g_signal_emit ( G_OBJECT(vw), window_signals[VW_NEWWINDOW_SIGNAL], 0 );
437 static void draw_update ( VikWindow *vw )
443 static void draw_sync ( VikWindow *vw )
445 vik_viewport_sync(vw->viking_vvp);
447 /* other things may be necc here later. */
450 static void draw_status ( VikWindow *vw )
452 static gchar zoom_level[22];
453 gdouble xmpp = vik_viewport_get_xmpp (vw->viking_vvp);
454 gdouble ympp = vik_viewport_get_ympp(vw->viking_vvp);
455 gchar *unit = vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM ? _("mpp") : _("pixelfact");
457 g_snprintf ( zoom_level, 22, "%.3f/%.3f %s", xmpp, ympp, unit );
459 if ( (int)xmpp - xmpp < 0.0 )
460 g_snprintf ( zoom_level, 22, "%.3f %s", xmpp, unit );
462 /* xmpp should be a whole number so don't show useless .000 bit */
463 g_snprintf ( zoom_level, 22, "%d %s", (int)xmpp, unit );
464 if ( vw->current_tool == TOOL_LAYER )
465 vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_TOOL, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name );
467 vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_TOOL, _(tool_names[vw->current_tool]) );
469 vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_ZOOM, zoom_level );
472 void vik_window_set_redraw_trigger(VikLayer *vl)
474 VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl));
479 static void window_configure_event ( VikWindow *vw )
481 static int first = 1;
484 // This is a hack to set the cursor corresponding to the first tool
485 // FIXME find the correct way to initialize both tool and its cursor
486 const GdkCursor *cursor = NULL;
488 cursor = toolbox_get_cursor(vw->vt, "Pan");
489 /* We set cursor, even if it is NULL: it resets to default */
490 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, (GdkCursor *)cursor );
494 static void draw_redraw ( VikWindow *vw )
496 VikCoord old_center = vw->trigger_center;
497 vw->trigger_center = *(vik_viewport_get_center(vw->viking_vvp));
498 VikLayer *new_trigger = vw->trigger;
500 VikLayer *old_trigger = VIK_LAYER(vik_viewport_get_trigger(vw->viking_vvp));
503 ; /* do nothing -- have to redraw everything. */
504 else if ( (old_trigger != new_trigger) || !vik_coord_equals(&old_center, &vw->trigger_center) || (new_trigger->type == VIK_LAYER_AGGREGATE) )
505 vik_viewport_set_trigger ( vw->viking_vvp, new_trigger ); /* todo: set to half_drawn mode if new trigger is above old */
507 vik_viewport_set_half_drawn ( vw->viking_vvp, TRUE );
510 vik_viewport_clear ( vw->viking_vvp);
511 vik_layers_panel_draw_all ( vw->viking_vlp );
512 vik_viewport_draw_scale ( vw->viking_vvp );
513 vik_viewport_draw_copyright ( vw->viking_vvp );
514 vik_viewport_draw_centermark ( vw->viking_vvp );
515 vik_viewport_draw_logo ( vw->viking_vvp );
517 vik_viewport_set_half_drawn ( vw->viking_vvp, FALSE ); /* just in case. */
520 gboolean draw_buf_done = TRUE;
522 static gboolean draw_buf(gpointer data)
524 gpointer *pass_along = data;
526 gdk_draw_drawable (pass_along[0], pass_along[1],
527 pass_along[2], 0, 0, 0, 0, -1, -1);
528 draw_buf_done = TRUE;
534 /* Mouse event handlers ************************************************************************/
536 static void vik_window_pan_click (VikWindow *vw, GdkEventButton *event)
538 /* set panning origin */
539 vw->pan_move = FALSE;
540 vw->pan_x = (gint) event->x;
541 vw->pan_y = (gint) event->y;
544 static void draw_click (VikWindow *vw, GdkEventButton *event)
546 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
548 /* middle button pressed. we reserve all middle button and scroll events
549 * for panning and zooming; tools only get left/right/movement
551 if ( event->button == 2) {
552 vik_window_pan_click ( vw, event );
555 toolbox_click(vw->vt, event);
559 static void vik_window_pan_move (VikWindow *vw, GdkEventMotion *event)
561 if ( vw->pan_x != -1 ) {
562 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
563 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
565 vw->pan_x = event->x;
566 vw->pan_y = event->y;
571 static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
573 static VikCoord coord;
574 static struct UTM utm;
575 static struct LatLon ll;
576 #define BUFFER_SIZE 50
577 static char pointer_buf[BUFFER_SIZE];
578 gchar *lat = NULL, *lon = NULL;
581 VikDemInterpol interpol_method;
583 /* This is a hack, but work far the best, at least for single pointer systems.
584 * See http://bugzilla.gnome.org/show_bug.cgi?id=587714 for more. */
586 gdk_window_get_pointer (event->window, &x, &y, NULL);
590 toolbox_move(vw->vt, event);
592 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
593 vik_coord_to_utm ( &coord, &utm );
594 a_coords_utm_to_latlon ( &utm, &ll );
595 a_coords_latlon_to_string ( &ll, &lat, &lon );
596 /* Change interpolate method according to scale */
597 zoom = vik_viewport_get_zoom(vw->viking_vvp);
599 interpol_method = VIK_DEM_INTERPOL_NONE;
600 else if (zoom >= 1.0)
601 interpol_method = VIK_DEM_INTERPOL_SIMPLE;
603 interpol_method = VIK_DEM_INTERPOL_BEST;
604 if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION) {
605 if ( a_vik_get_units_height () == VIK_UNITS_HEIGHT_METRES )
606 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dm"), lat, lon, alt );
608 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dft"), lat, lon, (int)VIK_METERS_TO_FEET(alt) );
611 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s"), lat, lon );
616 vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_POSITION, pointer_buf );
618 vik_window_pan_move ( vw, event );
620 /* This is recommended by the GTK+ documentation, but does not work properly.
621 * Use deprecated way until GTK+ gets a solution for correct motion hint handling:
622 * http://bugzilla.gnome.org/show_bug.cgi?id=587714
624 /* gdk_event_request_motions ( event ); */
627 static void vik_window_pan_release ( VikWindow *vw, GdkEventButton *event )
629 if ( vw->pan_move == FALSE )
630 vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
632 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
633 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
634 vw->pan_move = FALSE;
635 vw->pan_x = vw->pan_y = -1;
639 static void draw_release ( VikWindow *vw, GdkEventButton *event )
641 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
643 if ( event->button == 2 ) { /* move / pan */
644 vik_window_pan_release(vw, event);
647 toolbox_release(vw->vt, event);
651 static void draw_scroll (VikWindow *vw, GdkEventScroll *event)
653 guint modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK);
654 if ( modifiers == GDK_CONTROL_MASK ) {
655 /* control == pan up & down */
656 if ( event->direction == GDK_SCROLL_UP )
657 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 );
659 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)*2/3 );
660 } else if ( modifiers == GDK_SHIFT_MASK ) {
661 /* shift == pan left & right */
662 if ( event->direction == GDK_SCROLL_UP )
663 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 );
665 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)*2/3, vik_viewport_get_height(vw->viking_vvp)/2 );
666 } else if ( modifiers == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) {
667 /* control+shift == make sure mouse is still over the same point on the map when we zoom */
670 gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
671 gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
672 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
673 if ( event->direction == GDK_SCROLL_UP )
674 vik_viewport_zoom_in (vw->viking_vvp);
676 vik_viewport_zoom_out(vw->viking_vvp);
677 vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
678 vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
679 center_y + (y - event->y) );
681 if ( event->direction == GDK_SCROLL_UP )
682 vik_viewport_zoom_in (vw->viking_vvp);
684 vik_viewport_zoom_out (vw->viking_vvp);
692 /********************************************************************************
694 ********************************************************************************/
695 static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gdouble distance)
697 PangoFontDescription *pfd;
700 GdkGC *labgc = vik_viewport_new_gc ( vvp, "#cccccc", 1);
701 GdkGC *thickgc = gdk_gc_new(d);
703 gdouble len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
704 gdouble dx = (x2-x1)/len*10;
705 gdouble dy = (y2-y1)/len*10;
706 gdouble c = cos(15.0 * M_PI/180.0);
707 gdouble s = sin(15.0 * M_PI/180.0);
709 gdouble baseangle = 0;
712 /* draw line with arrow ends */
714 gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
715 a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
716 gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
719 a_viewport_clip_line(&x1, &y1, &x2, &y2);
720 gdk_draw_line(d, gc, x1, y1, x2, y2);
722 gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
723 gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
724 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));
725 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c - dy * s), y2 - (dy * c + dx * s));
726 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c + dy * s), y1 + (dy * c - dx * s));
727 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c - dy * s), y1 + (dy * c + dx * s));
732 angle = atan2(dy, dx) + M_PI_2;
734 if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
740 vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
741 vik_coord_to_latlon ( &test, &ll );
742 ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
743 a_coords_latlon_to_utm ( &ll, &u );
744 vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
745 vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
747 baseangle = M_PI - atan2(tx-x1, ty-y1);
758 gdk_gc_copy(thickgc, gc);
759 gdk_gc_set_line_attributes(thickgc, CW, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
760 gdk_color_parse("#2255cc", &color);
761 gdk_gc_set_rgb_fg_color(thickgc, &color);
763 gdk_draw_arc (d, thickgc, FALSE, x1-CR+CW/2, y1-CR+CW/2, 2*CR-CW, 2*CR-CW, (90 - baseangle*180/M_PI)*64, -angle*180/M_PI*64);
766 gdk_gc_copy(thickgc, gc);
767 gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
768 for (i=0; i<180; i++) {
769 c = cos(i*M_PI/90.0 + baseangle);
770 s = sin(i*M_PI/90.0 + baseangle);
773 gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
775 gdouble ticksize = 2*CW;
776 gdk_draw_line (d, thickgc, x1 + (CR-CW)*c, y1 + (CR-CW)*s, x1 + (CR+ticksize)*c, y1 + (CR+ticksize)*s);
780 gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
781 gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
782 gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
783 c = (CR+CW*2)*cos(baseangle);
784 s = (CR+CW*2)*sin(baseangle);
785 gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
786 gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
789 #define LABEL(x, y, w, h) { \
790 gdk_draw_rectangle(d, labgc, TRUE, (x)-2, (y)-1, (w)+4, (h)+1); \
791 gdk_draw_rectangle(d, gc, FALSE, (x)-2, (y)-1, (w)+4, (h)+1); \
792 gdk_draw_layout(d, gc, (x), (y), pl); }
797 pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
799 pfd = pango_font_description_from_string ("Sans 8"); // FIXME: settable option? global variable?
800 pango_layout_set_font_description (pl, pfd);
801 pango_font_description_free (pfd);
803 pango_layout_set_text(pl, "N", -1);
804 gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
806 /* draw label with distance */
807 vik_units_distance_t dist_units = a_vik_get_units_distance ();
808 switch (dist_units) {
809 case VIK_UNITS_DISTANCE_KILOMETRES:
810 if (distance >= 1000 && distance < 100000) {
811 g_sprintf(str, "%3.2f km", distance/1000.0);
812 } else if (distance < 1000) {
813 g_sprintf(str, "%d m", (int)distance);
815 g_sprintf(str, "%d km", (int)distance/1000);
818 case VIK_UNITS_DISTANCE_MILES:
819 if (distance >= VIK_MILES_TO_METERS(1) && distance < VIK_MILES_TO_METERS(100)) {
820 g_sprintf(str, "%3.2f miles", VIK_METERS_TO_MILES(distance));
821 } else if (distance < VIK_MILES_TO_METERS(1)) {
822 g_sprintf(str, "%d yards", (int)(distance*1.0936133));
824 g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
828 g_critical("Houston, we've had a problem. distance=%d", dist_units);
831 pango_layout_set_text(pl, str, -1);
833 pango_layout_get_pixel_size ( pl, &wd, &hd );
836 yd = (y1+y2)/2 - hd/2 - dx;
839 yd = (y1+y2)/2 - hd/2 + dx;
842 if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
847 LABEL(xd, yd, wd, hd);
849 /* draw label with bearing */
850 g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
851 pango_layout_set_text(pl, str, -1);
852 pango_layout_get_pixel_size ( pl, &wb, &hb );
853 xb = x1 + CR*cos(angle-M_PI_2);
854 yb = y1 + CR*sin(angle-M_PI_2);
856 if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
862 GdkRectangle r1 = {xd-2, yd-1, wd+4, hd+1}, r2 = {xb-2, yb-1, wb+4, hb+1};
863 if (gdk_rectangle_intersect(&r1, &r2, &r2)) {
867 LABEL(xb, yb, wb, hb);
871 g_object_unref ( G_OBJECT ( pl ) );
872 g_object_unref ( G_OBJECT ( labgc ) );
873 g_object_unref ( G_OBJECT ( thickgc ) );
879 gboolean has_oldcoord;
881 } ruler_tool_state_t;
883 static gpointer ruler_create (VikWindow *vw, VikViewport *vvp)
885 ruler_tool_state_t *s = g_new(ruler_tool_state_t, 1);
888 s->has_oldcoord = FALSE;
892 static void ruler_destroy (ruler_tool_state_t *s)
897 static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
902 if ( event->button == 1 ) {
903 gchar *lat=NULL, *lon=NULL;
904 vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
905 vik_coord_to_latlon ( &coord, &ll );
906 a_coords_latlon_to_string ( &ll, &lat, &lon );
907 if ( s->has_oldcoord ) {
908 vik_units_distance_t dist_units = a_vik_get_units_distance ();
909 switch (dist_units) {
910 case VIK_UNITS_DISTANCE_KILOMETRES:
911 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
913 case VIK_UNITS_DISTANCE_MILES:
914 temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
917 temp = g_strdup_printf ("Just to keep the compiler happy");
918 g_critical("Houston, we've had a problem. distance=%d", dist_units);
921 s->has_oldcoord = FALSE;
924 temp = g_strdup_printf ( "%s %s", lat, lon );
925 s->has_oldcoord = TRUE;
928 vik_statusbar_set_message ( s->vw->viking_vs, VIK_STATUSBAR_INFO, temp );
934 vik_viewport_set_center_screen ( s->vvp, (gint) event->x, (gint) event->y );
935 draw_update ( s->vw );
937 return VIK_LAYER_TOOL_ACK;
940 static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, ruler_tool_state_t *s)
942 VikViewport *vvp = s->vvp;
943 VikWindow *vw = s->vw;
949 if ( s->has_oldcoord ) {
950 int oldx, oldy, w1, h1, w2, h2;
951 static GdkPixmap *buf = NULL;
952 gchar *lat=NULL, *lon=NULL;
953 w1 = vik_viewport_get_width(vvp);
954 h1 = vik_viewport_get_height(vvp);
956 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
958 gdk_drawable_get_size(buf, &w2, &h2);
959 if (w1 != w2 || h1 != h2) {
960 g_object_unref ( G_OBJECT ( buf ) );
961 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
964 vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
965 vik_coord_to_latlon ( &coord, &ll );
966 vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
968 gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc,
969 vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
970 draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
972 static gpointer pass_along[3];
973 pass_along[0] = GTK_WIDGET(vvp)->window;
974 pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
976 g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
977 draw_buf_done = FALSE;
979 a_coords_latlon_to_string(&ll, &lat, &lon);
980 vik_units_distance_t dist_units = a_vik_get_units_distance ();
981 switch (dist_units) {
982 case VIK_UNITS_DISTANCE_KILOMETRES:
983 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
985 case VIK_UNITS_DISTANCE_MILES:
986 temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES (vik_coord_diff( &coord, &(s->oldcoord) )) );
989 temp = g_strdup_printf ("Just to keep the compiler happy");
990 g_critical("Houston, we've had a problem. distance=%d", dist_units);
992 vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_INFO, temp );
995 return VIK_LAYER_TOOL_ACK;
998 static VikLayerToolFuncStatus ruler_release (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
1000 return VIK_LAYER_TOOL_ACK;
1003 static void ruler_deactivate (VikLayer *vl, ruler_tool_state_t *s)
1005 draw_update ( s->vw );
1008 static gboolean ruler_key_press (VikLayer *vl, GdkEventKey *event, ruler_tool_state_t *s)
1010 if (event->keyval == GDK_Escape) {
1011 s->has_oldcoord = FALSE;
1012 ruler_deactivate ( vl, s );
1018 static VikToolInterface ruler_tool =
1020 (VikToolConstructorFunc) ruler_create,
1021 (VikToolDestructorFunc) ruler_destroy,
1022 (VikToolActivationFunc) NULL,
1023 (VikToolActivationFunc) ruler_deactivate,
1024 (VikToolMouseFunc) ruler_click,
1025 (VikToolMouseMoveFunc) ruler_move,
1026 (VikToolMouseFunc) ruler_release,
1027 (VikToolKeyFunc) ruler_key_press,
1028 GDK_CURSOR_IS_PIXMAP,
1029 &cursor_ruler_pixbuf };
1030 /*** end ruler code ********************************************************/
1034 /********************************************************************************
1036 ********************************************************************************/
1037 static gpointer zoomtool_create (VikWindow *vw, VikViewport *vvp)
1042 static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
1044 vw->modified = TRUE;
1045 vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
1046 if ( event->button == 1 )
1047 vik_viewport_zoom_in (vw->viking_vvp);
1048 else if ( event->button == 3 )
1049 vik_viewport_zoom_out (vw->viking_vvp);
1051 return VIK_LAYER_TOOL_ACK;
1054 static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event, VikViewport *vvp)
1056 return VIK_LAYER_TOOL_ACK;
1059 static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
1061 return VIK_LAYER_TOOL_ACK;
1064 static VikToolInterface zoom_tool =
1066 (VikToolConstructorFunc) zoomtool_create,
1067 (VikToolDestructorFunc) NULL,
1068 (VikToolActivationFunc) NULL,
1069 (VikToolActivationFunc) NULL,
1070 (VikToolMouseFunc) zoomtool_click,
1071 (VikToolMouseMoveFunc) zoomtool_move,
1072 (VikToolMouseFunc) zoomtool_release,
1074 GDK_CURSOR_IS_PIXMAP,
1075 &cursor_zoom_pixbuf };
1076 /*** end zoom code ********************************************************/
1078 /********************************************************************************
1080 ********************************************************************************/
1081 static gpointer pantool_create (VikWindow *vw, VikViewport *vvp)
1086 static VikLayerToolFuncStatus pantool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
1088 vw->modified = TRUE;
1089 if ( event->button == 1 )
1090 vik_window_pan_click ( vw, event );
1092 return VIK_LAYER_TOOL_ACK;
1095 static VikLayerToolFuncStatus pantool_move (VikLayer *vl, GdkEventMotion *event, VikWindow *vw)
1097 vik_window_pan_move ( vw, event );
1098 return VIK_LAYER_TOOL_ACK;
1101 static VikLayerToolFuncStatus pantool_release (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
1103 if ( event->button == 1 )
1104 vik_window_pan_release ( vw, event );
1105 return VIK_LAYER_TOOL_ACK;
1108 static VikToolInterface pan_tool =
1110 (VikToolConstructorFunc) pantool_create,
1111 (VikToolDestructorFunc) NULL,
1112 (VikToolActivationFunc) NULL,
1113 (VikToolActivationFunc) NULL,
1114 (VikToolMouseFunc) pantool_click,
1115 (VikToolMouseMoveFunc) pantool_move,
1116 (VikToolMouseFunc) pantool_release,
1119 /*** end pan code ********************************************************/
1121 /********************************************************************************
1123 ********************************************************************************/
1124 static gpointer selecttool_create (VikWindow *vw, VikViewport *vvp)
1126 tool_ed_t *t = g_new(tool_ed_t, 1);
1130 t->is_waypoint = FALSE;
1134 static void selecttool_destroy (tool_ed_t *t)
1142 GdkEventButton *event;
1143 tool_ed_t *tool_edit;
1146 static void click_layer_selected (VikLayer *vl, clicker *ck)
1148 /* Do nothing when function call returns true; */
1149 /* i.e. stop on first found item */
1152 if ( vik_layer_get_interface(vl->type)->select_click )
1153 ck->cont = !vik_layer_get_interface(vl->type)->select_click ( vl, ck->event, ck->vvp, ck->tool_edit );
1156 static VikLayerToolFuncStatus selecttool_click (VikLayer *vl, GdkEventButton *event, tool_ed_t *t)
1158 /* Only allow selection on primary button */
1159 if ( event->button == 1 ) {
1160 /* Enable click to apply callback to potentially all track/waypoint layers */
1161 /* Useful as we can find things that aren't necessarily in the currently selected layer */
1162 GList* gl = vik_layers_panel_get_all_layers_of_type ( t->vw->viking_vlp, VIK_LAYER_TRW, FALSE ); // Don't get invisible layers
1165 ck.vvp = t->vw->viking_vvp;
1168 g_list_foreach ( gl, (GFunc) click_layer_selected, &ck );
1171 // If nothing found then deselect & redraw screen if necessary to remove the highlight
1174 VikTreeview *vtv = vik_layers_panel_get_treeview ( t->vw->viking_vlp );
1176 if ( vik_treeview_get_selected_iter ( vtv, &iter ) ) {
1177 // Only clear if selected thing is a TrackWaypoint layer or a sublayer
1178 gint type = vik_treeview_item_get_type ( vtv, &iter );
1179 if ( type == VIK_TREEVIEW_TYPE_SUBLAYER ||
1180 VIK_LAYER(vik_treeview_item_get_pointer ( vtv, &iter ))->type == VIK_LAYER_TRW ) {
1182 vik_treeview_item_unselect ( vtv, &iter );
1183 if ( vik_window_clear_highlight ( t->vw ) )
1184 draw_update ( t->vw );
1189 else if ( ( event->button == 3 ) && ( vl && ( vl->type == VIK_LAYER_TRW ) ) ) {
1191 /* Act on currently selected item to show menu */
1192 if ( ( t->vw->selected_track || t->vw->selected_waypoint ) && t->vw->selected_name )
1193 if ( vik_layer_get_interface(vl->type)->show_viewport_menu )
1194 vik_layer_get_interface(vl->type)->show_viewport_menu ( vl, event, t->vw->viking_vvp );
1197 return VIK_LAYER_TOOL_ACK;
1200 static VikLayerToolFuncStatus selecttool_move (VikLayer *vl, GdkEventButton *event, tool_ed_t *t)
1202 /* Only allow selection on primary button */
1203 if ( event->button == 1 ) {
1204 // Don't care about vl here
1206 if ( vik_layer_get_interface(VIK_LAYER_TRW)->select_move )
1207 vik_layer_get_interface(VIK_LAYER_TRW)->select_move ( vl, event, t->vvp, t );
1209 return VIK_LAYER_TOOL_ACK;
1212 static VikLayerToolFuncStatus selecttool_release (VikLayer *vl, GdkEventButton *event, tool_ed_t *t)
1214 /* Only allow selection on primary button */
1215 if ( event->button == 1 ) {
1216 // Don't care about vl here
1218 if ( vik_layer_get_interface(VIK_LAYER_TRW)->select_release )
1219 vik_layer_get_interface(VIK_LAYER_TRW)->select_release ( (VikLayer*)t->vtl, event, t->vvp, t );
1221 return VIK_LAYER_TOOL_ACK;
1224 static VikToolInterface select_tool =
1226 (VikToolConstructorFunc) selecttool_create,
1227 (VikToolDestructorFunc) selecttool_destroy,
1228 (VikToolActivationFunc) NULL,
1229 (VikToolActivationFunc) NULL,
1230 (VikToolMouseFunc) selecttool_click,
1231 (VikToolMouseMoveFunc) selecttool_move,
1232 (VikToolMouseFunc) selecttool_release,
1233 (VikToolKeyFunc) NULL,
1237 /*** end select tool code ********************************************************/
1239 static void draw_pan_cb ( GtkAction *a, VikWindow *vw )
1241 if (!strcmp(gtk_action_get_name(a), "PanNorth")) {
1242 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, 0 );
1243 } else if (!strcmp(gtk_action_get_name(a), "PanEast")) {
1244 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp), vik_viewport_get_height(vw->viking_vvp)/2 );
1245 } else if (!strcmp(gtk_action_get_name(a), "PanSouth")) {
1246 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp) );
1247 } else if (!strcmp(gtk_action_get_name(a), "PanWest")) {
1248 vik_viewport_set_center_screen ( vw->viking_vvp, 0, vik_viewport_get_height(vw->viking_vvp)/2 );
1253 static void full_screen_cb ( GtkAction *a, VikWindow *vw )
1255 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/FullScreen" );
1256 g_assert(check_box);
1257 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1259 gtk_window_fullscreen ( GTK_WINDOW(vw) );
1261 gtk_window_unfullscreen ( GTK_WINDOW(vw) );
1264 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw )
1268 if (!strcmp(gtk_action_get_name(a), "ZoomIn")) {
1271 else if (!strcmp(gtk_action_get_name(a), "ZoomOut")) {
1274 else if (!strcmp(gtk_action_get_name(a), "Zoom0.25")) {
1277 else if (!strcmp(gtk_action_get_name(a), "Zoom0.5")) {
1281 gchar *s = (gchar *)gtk_action_get_name(a);
1287 case -3: vik_viewport_zoom_in ( vw->viking_vvp ); break;
1288 case -4: vik_viewport_zoom_out ( vw->viking_vvp ); break;
1289 case -1: vik_viewport_set_zoom ( vw->viking_vvp, 0.5 ); break;
1290 case -2: vik_viewport_set_zoom ( vw->viking_vvp, 0.25 ); break;
1291 default: vik_viewport_set_zoom ( vw->viking_vvp, what );
1296 void draw_goto_cb ( GtkAction *a, VikWindow *vw )
1298 VikCoord new_center;
1300 if (!strcmp(gtk_action_get_name(a), "GotoLL")) {
1301 struct LatLon ll, llold;
1302 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &llold );
1303 if ( a_dialog_goto_latlon ( GTK_WINDOW(vw), &ll, &llold ) )
1304 vik_coord_load_from_latlon ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &ll );
1308 else if (!strcmp(gtk_action_get_name(a), "GotoUTM")) {
1309 struct UTM utm, utmold;
1310 vik_coord_to_utm ( vik_viewport_get_center ( vw->viking_vvp ), &utmold );
1311 if ( a_dialog_goto_utm ( GTK_WINDOW(vw), &utm, &utmold ) )
1312 vik_coord_load_from_utm ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &utm );
1317 g_critical("Houston, we've had a problem.");
1321 vik_viewport_set_center_coord ( vw->viking_vvp, &new_center );
1325 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw )
1328 for ( type = 0; type < VIK_LAYER_NUM_TYPES; type++ ) {
1329 if (!strcmp(vik_layer_get_interface(type)->name, gtk_action_get_name(a))) {
1330 if ( vik_layers_panel_new_layer ( vw->viking_vlp, type ) ) {
1332 vw->modified = TRUE;
1338 static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw )
1340 a_clipboard_copy_selected ( vw->viking_vlp );
1343 static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw )
1345 vik_layers_panel_cut_selected ( vw->viking_vlp );
1346 vw->modified = TRUE;
1349 static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw )
1351 if ( a_clipboard_paste ( vw->viking_vlp ) )
1353 vw->modified = TRUE;
1357 static void menu_properties_cb ( GtkAction *a, VikWindow *vw )
1359 if ( ! vik_layers_panel_properties ( vw->viking_vlp ) )
1360 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to show its properties.") );
1363 static void help_help_cb ( GtkAction *a, VikWindow *vw )
1366 ShellExecute(NULL, "open", ""PACKAGE".pdf", NULL, NULL, SW_SHOWNORMAL);
1368 #if GTK_CHECK_VERSION (2, 14, 0)
1370 uri = g_strdup_printf("ghelp:%s", PACKAGE);
1371 gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, NULL);
1374 #endif /* WINDOWS */
1377 static void help_about_cb ( GtkAction *a, VikWindow *vw )
1379 a_dialog_about(GTK_WINDOW(vw));
1382 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
1384 if ( vik_layers_panel_get_selected ( vw->viking_vlp ) )
1386 vik_layers_panel_delete_selected ( vw->viking_vlp );
1387 vw->modified = TRUE;
1390 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to delete.") );
1393 static void view_side_panel_cb ( GtkAction *a, VikWindow *vw )
1395 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ViewSidePanel" );
1396 g_assert(check_box);
1397 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1399 gtk_widget_show(GTK_WIDGET(vw->viking_vlp));
1401 gtk_widget_hide(GTK_WIDGET(vw->viking_vlp));
1404 static void view_statusbar_cb ( GtkAction *a, VikWindow *vw )
1406 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ViewStatusBar" );
1409 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box) );
1411 gtk_widget_show ( GTK_WIDGET(vw->viking_vs) );
1413 gtk_widget_hide ( GTK_WIDGET(vw->viking_vs) );
1416 static void view_toolbar_cb ( GtkAction *a, VikWindow *vw )
1418 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ViewToolbar" );
1421 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box) );
1423 gtk_widget_show ( GTK_WIDGET(vw->toolbar) );
1425 gtk_widget_hide ( GTK_WIDGET(vw->toolbar) );
1428 static void view_main_menu_cb ( GtkAction *a, VikWindow *vw )
1430 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ViewMainMenu" );
1433 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box) );
1435 gtk_widget_hide ( gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu" ) );
1437 gtk_widget_show ( gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu" ) );
1440 /***************************************
1441 ** tool management routines
1443 ***************************************/
1445 static toolbox_tools_t* toolbox_create(VikWindow *vw)
1447 toolbox_tools_t *vt = g_new(toolbox_tools_t, 1);
1450 vt->active_tool = -1;
1452 if (!vw->viking_vvp) {
1453 g_critical("no viewport found.");
1459 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type )
1461 vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1);
1462 vt->tools[vt->n_tools].ti = *vti;
1463 vt->tools[vt->n_tools].layer_type = layer_type;
1465 vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp);
1468 vt->tools[vt->n_tools].state = NULL;
1473 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name)
1476 for (i=0; i<vt->n_tools; i++) {
1477 if (!strcmp(tool_name, vt->tools[i].ti.name)) {
1484 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name)
1486 int tool = toolbox_get_tool(vt, tool_name);
1487 toolbox_tool_t *t = &vt->tools[tool];
1488 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1490 if (tool == vt->n_tools) {
1491 g_critical("trying to activate a non-existent tool...");
1494 /* is the tool already active? */
1495 if (vt->active_tool == tool) {
1499 if (vt->active_tool != -1) {
1500 if (vt->tools[vt->active_tool].ti.deactivate) {
1501 vt->tools[vt->active_tool].ti.deactivate(NULL, vt->tools[vt->active_tool].state);
1504 if (t->ti.activate) {
1505 t->ti.activate(vl, t->state);
1507 vt->active_tool = tool;
1510 static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name)
1512 int tool = toolbox_get_tool(vt, tool_name);
1513 toolbox_tool_t *t = &vt->tools[tool];
1514 if (t->ti.cursor == NULL) {
1515 if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) {
1516 GError *cursor_load_err = NULL;
1517 GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err);
1518 /* TODO: settable offeset */
1519 t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
1520 g_object_unref ( G_OBJECT(cursor_pixbuf) );
1522 t->ti.cursor = gdk_cursor_new ( t->ti.cursor_type );
1525 return t->ti.cursor;
1528 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
1530 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1531 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) {
1532 gint ltype = vt->tools[vt->active_tool].layer_type;
1533 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1534 vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state);
1538 static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event)
1540 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1541 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) {
1542 gint ltype = vt->tools[vt->active_tool].layer_type;
1543 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1544 if ( VIK_LAYER_TOOL_ACK_GRAB_FOCUS == vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state) )
1545 gtk_widget_grab_focus ( GTK_WIDGET(vt->vw->viking_vvp) );
1549 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event)
1551 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1552 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release ) {
1553 gint ltype = vt->tools[vt->active_tool].layer_type;
1554 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1555 vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state);
1558 /** End tool management ************************************/
1560 void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id )
1562 gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].name ) );
1565 /* this function gets called whenever a toolbar tool is clicked */
1566 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
1568 /* White Magic, my friends ... White Magic... */
1569 int layer_id, tool_id;
1570 const GdkCursor *cursor = NULL;
1572 toolbox_activate(vw->vt, gtk_action_get_name(a));
1574 cursor = toolbox_get_cursor(vw->vt, gtk_action_get_name(a));
1575 /* We set cursor, even if it is NULL: it resets to default */
1576 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, (GdkCursor *)cursor );
1578 if (!strcmp(gtk_action_get_name(a), "Pan")) {
1579 vw->current_tool = TOOL_PAN;
1581 else if (!strcmp(gtk_action_get_name(a), "Zoom")) {
1582 vw->current_tool = TOOL_ZOOM;
1584 else if (!strcmp(gtk_action_get_name(a), "Ruler")) {
1585 vw->current_tool = TOOL_RULER;
1587 else if (!strcmp(gtk_action_get_name(a), "Select")) {
1588 vw->current_tool = TOOL_SELECT;
1591 /* TODO: only enable tools from active layer */
1592 for (layer_id=0; layer_id<VIK_LAYER_NUM_TYPES; layer_id++) {
1593 for ( tool_id = 0; tool_id < vik_layer_get_interface(layer_id)->tools_count; tool_id++ ) {
1594 if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].name, gtk_action_get_name(a))) {
1595 vw->current_tool = TOOL_LAYER;
1596 vw->tool_layer_id = layer_id;
1597 vw->tool_tool_id = tool_id;
1605 static void window_set_filename ( VikWindow *vw, const gchar *filename )
1610 g_free ( vw->filename );
1611 if ( filename == NULL )
1613 vw->filename = NULL;
1614 file = _("Untitled");
1618 vw->filename = g_strdup(filename);
1619 file = a_file_basename ( filename );
1621 title = g_strdup_printf( "%s - Viking", file );
1622 gtk_window_set_title ( GTK_WINDOW(vw), title );
1626 GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode )
1628 GtkWidget *mode_button;
1631 #ifdef VIK_CONFIG_EXPEDIA
1632 case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
1634 case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break;
1635 case VIK_VIEWPORT_DRAWMODE_LATLON: buttonname = "/ui/MainMenu/View/ModeLatLon"; break;
1636 default: buttonname = "/ui/MainMenu/View/ModeUTM";
1638 mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
1639 g_assert ( mode_button );
1644 * vik_window_get_pan_move:
1645 * @vw: some VikWindow
1647 * Retrieves @vw's pan_move.
1649 * Should be removed as soon as possible.
1651 * Returns: @vw's pan_move
1655 gboolean vik_window_get_pan_move ( VikWindow *vw )
1657 return vw->pan_move;
1660 static void on_activate_recent_item (GtkRecentChooser *chooser,
1665 filename = gtk_recent_chooser_get_current_uri (chooser);
1666 if (filename != NULL)
1668 GFile *file = g_file_new_for_uri ( filename );
1669 gchar *path = g_file_get_path ( file );
1670 g_object_unref ( file );
1671 if ( self->filename )
1673 GSList *filenames = NULL;
1674 filenames = g_slist_append ( filenames, path );
1675 g_signal_emit ( G_OBJECT(self), window_signals[VW_OPENWINDOW_SIGNAL], 0, filenames );
1676 // NB: GSList & contents are freed by main.open_window
1679 vik_window_open_file ( self, path, TRUE );
1687 static void setup_recent_files (VikWindow *self)
1689 GtkRecentManager *manager;
1690 GtkRecentFilter *filter;
1691 GtkWidget *menu, *menu_item;
1693 filter = gtk_recent_filter_new ();
1694 /* gtk_recent_filter_add_application (filter, g_get_application_name()); */
1695 gtk_recent_filter_add_group(filter, "viking");
1697 manager = gtk_recent_manager_get_default ();
1698 menu = gtk_recent_chooser_menu_new_for_manager (manager);
1699 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu), GTK_RECENT_SORT_MRU);
1700 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
1702 menu_item = gtk_ui_manager_get_widget (self->uim, "/ui/MainMenu/File/OpenRecentFile");
1703 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu);
1705 g_signal_connect (G_OBJECT (menu), "item-activated",
1706 G_CALLBACK (on_activate_recent_item), (gpointer) self);
1709 static void update_recently_used_document(const gchar *filename)
1711 /* Update Recently Used Document framework */
1712 GtkRecentManager *manager = gtk_recent_manager_get_default();
1713 GtkRecentData *recent_data = g_slice_new (GtkRecentData);
1714 gchar *groups[] = {"viking", NULL};
1715 GFile *file = g_file_new_for_commandline_arg(filename);
1716 gchar *uri = g_file_get_uri(file);
1717 gchar *basename = g_path_get_basename(filename);
1718 g_object_unref(file);
1721 recent_data->display_name = basename;
1722 recent_data->description = NULL;
1723 recent_data->mime_type = "text/x-gps-data";
1724 recent_data->app_name = (gchar *) g_get_application_name ();
1725 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL);
1726 recent_data->groups = groups;
1727 recent_data->is_private = FALSE;
1728 if (!gtk_recent_manager_add_full (manager, uri, recent_data))
1730 g_warning (_("Unable to add '%s' to the list of recently used documents"), uri);
1735 g_free (recent_data->app_exec);
1736 g_slice_free (GtkRecentData, recent_data);
1739 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename )
1741 switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) )
1743 case LOAD_TYPE_READ_FAILURE:
1744 a_dialog_error_msg ( GTK_WINDOW(vw), _("The file you requested could not be opened.") );
1746 case LOAD_TYPE_GPSBABEL_FAILURE:
1747 a_dialog_error_msg ( GTK_WINDOW(vw), _("GPSBabel is required to load files of this type or GPSBabel encountered problems.") );
1749 case LOAD_TYPE_UNSUPPORTED_FAILURE:
1750 a_dialog_error_msg_extra ( GTK_WINDOW(vw), _("Unsupported file type for %s"), filename );
1752 case LOAD_TYPE_VIK_SUCCESS:
1754 GtkWidget *mode_button;
1756 if ( change_filename )
1757 window_set_filename ( vw, filename );
1758 mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) );
1759 vw->only_updating_coord_mode_ui = TRUE; /* if we don't set this, it will change the coord to UTM if we click Lat/Lon. I don't know why. */
1760 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE );
1761 vw->only_updating_coord_mode_ui = FALSE;
1763 vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) );
1765 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ShowScale" );
1766 g_assert ( mode_button );
1767 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_scale(vw->viking_vvp) );
1769 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ShowCenterMark" );
1770 g_assert ( mode_button );
1771 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) );
1773 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ShowHighlight" );
1774 g_assert ( mode_button );
1775 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_highlight (vw->viking_vvp) );
1777 //case LOAD_TYPE_OTHER_SUCCESS:
1779 update_recently_used_document(filename);
1784 static void load_file ( GtkAction *a, VikWindow *vw )
1786 GSList *files = NULL;
1787 GSList *cur_file = NULL;
1789 if (!strcmp(gtk_action_get_name(a), "Open")) {
1792 else if (!strcmp(gtk_action_get_name(a), "Append")) {
1796 g_critical("Houston, we've had a problem.");
1800 if ( ! vw->open_dia )
1802 vw->open_dia = gtk_file_chooser_dialog_new (_("Please select a GPS data file to open. "),
1804 GTK_FILE_CHOOSER_ACTION_OPEN,
1805 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1806 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1808 GtkFileFilter *filter;
1809 // NB file filters are listed this way for alphabetical ordering
1810 #ifdef VIK_CONFIG_GEOCACHES
1811 filter = gtk_file_filter_new ();
1812 gtk_file_filter_set_name( filter, _("Geocaching") );
1813 gtk_file_filter_add_pattern ( filter, "*.loc" ); // No MIME type available
1814 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter);
1817 filter = gtk_file_filter_new ();
1818 gtk_file_filter_set_name( filter, _("Google Earth") );
1819 gtk_file_filter_add_mime_type ( filter, "application/vnd.google-earth.kml+xml");
1820 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter);
1822 filter = gtk_file_filter_new ();
1823 gtk_file_filter_set_name( filter, _("GPX") );
1824 gtk_file_filter_add_pattern ( filter, "*.gpx" ); // No MIME type available
1825 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter);
1827 filter = gtk_file_filter_new ();
1828 gtk_file_filter_set_name( filter, _("Viking") );
1829 gtk_file_filter_add_pattern ( filter, "*.vik" );
1830 gtk_file_filter_add_pattern ( filter, "*.viking" );
1831 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter);
1833 // NB could have filters for gpspoint (*.gps,*.gpsoint?) + gpsmapper (*.gsm,*.gpsmapper?)
1834 // However assume this are barely used and thus not worthy of inclusion
1835 // as they'll just make the options too many and have no clear file pattern
1836 // one can always use the all option
1837 filter = gtk_file_filter_new ();
1838 gtk_file_filter_set_name( filter, _("All") );
1839 gtk_file_filter_add_pattern ( filter, "*" );
1840 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(vw->open_dia), filter);
1841 // Default to any file - same as before open filters were added
1842 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(vw->open_dia), filter);
1844 gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(vw->open_dia), TRUE );
1845 gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) );
1846 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE );
1848 if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_ACCEPT )
1850 gtk_widget_hide ( vw->open_dia );
1851 #ifdef VIKING_PROMPT_IF_MODIFIED
1852 if ( (vw->modified || vw->filename) && newwindow )
1854 if ( vw->filename && newwindow )
1856 g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) ) );
1858 files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) );
1859 gboolean change_fn = newwindow && (g_slist_length(files)==1); /* only change fn if one file */
1862 while ( cur_file ) {
1863 gchar *file_name = cur_file->data;
1864 vik_window_open_file ( vw, file_name, change_fn );
1866 cur_file = g_slist_next (cur_file);
1868 g_slist_free (files);
1872 gtk_widget_hide ( vw->open_dia );
1875 static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
1877 gboolean rv = FALSE;
1879 if ( ! vw->save_dia )
1881 vw->save_dia = gtk_file_chooser_dialog_new (_("Save as Viking File."),
1883 GTK_FILE_CHOOSER_ACTION_SAVE,
1884 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1885 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1887 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) );
1888 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
1891 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_ACCEPT )
1893 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_dia) );
1894 if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == FALSE || a_dialog_yes_or_no ( GTK_WINDOW(vw->save_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) )
1896 window_set_filename ( vw, fn );
1897 rv = window_save ( vw );
1898 vw->modified = FALSE;
1902 gtk_widget_hide ( vw->save_dia );
1906 static gboolean window_save ( VikWindow *vw )
1908 if ( a_file_save ( vik_layers_panel_get_top_layer ( vw->viking_vlp ), vw->viking_vvp, vw->filename ) )
1910 update_recently_used_document ( vw->filename );
1915 a_dialog_error_msg ( GTK_WINDOW(vw), _("The filename you requested could not be opened for writing.") );
1920 static gboolean save_file ( GtkAction *a, VikWindow *vw )
1922 if ( ! vw->filename )
1923 return save_file_as ( NULL, vw );
1926 vw->modified = FALSE;
1927 return window_save ( vw );
1931 static void acquire_from_gps ( GtkAction *a, VikWindow *vw )
1933 // Via the file menu, acquiring from a GPS makes a new layer
1934 // this has always been the way (not entirely sure if this was the real intention!)
1935 // thus maintain the behaviour ATM.
1936 // Hence explicit setting here (as the value may be changed elsewhere)
1937 vik_datasource_gps_interface.mode = VIK_DATASOURCE_CREATENEWLAYER;
1938 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface );
1941 static void acquire_from_file ( GtkAction *a, VikWindow *vw )
1943 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_file_interface );
1946 static void acquire_from_google ( GtkAction *a, VikWindow *vw )
1948 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
1951 #ifdef VIK_CONFIG_OPENSTREETMAP
1952 static void acquire_from_osm ( GtkAction *a, VikWindow *vw )
1954 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_osm_interface );
1958 #ifdef VIK_CONFIG_GEOCACHES
1959 static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
1961 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface );
1965 #ifdef VIK_CONFIG_GEOTAG
1966 static void acquire_from_geotag ( GtkAction *a, VikWindow *vw )
1968 vik_datasource_geotag_interface.mode = VIK_DATASOURCE_CREATENEWLAYER;
1969 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_geotag_interface );
1973 static void goto_default_location( GtkAction *a, VikWindow *vw)
1976 ll.lat = a_vik_get_default_lat();
1977 ll.lon = a_vik_get_default_long();
1978 vik_viewport_set_center_latlon(vw->viking_vvp, &ll);
1979 vik_layers_panel_emit_update(vw->viking_vlp);
1983 static void goto_address( GtkAction *a, VikWindow *vw)
1985 a_vik_goto(vw, vw->viking_vlp, vw->viking_vvp);
1988 static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw )
1993 static void preferences_cb ( GtkAction *a, VikWindow *vw )
1995 gboolean wp_icon_size = a_vik_get_use_large_waypoint_icons();
1997 a_preferences_show_window ( GTK_WINDOW(vw) );
1999 // Delete icon indexing 'cache' and so automatically regenerates with the new setting when changed
2000 if (wp_icon_size != a_vik_get_use_large_waypoint_icons())
2001 clear_garmin_icon_syms ();
2006 static void default_location_cb ( GtkAction *a, VikWindow *vw )
2008 /* Simplistic repeat of preference setting
2009 Only the name & type are important for setting the preference via this 'external' way */
2010 VikLayerParam pref_lat[] = {
2011 { VIKING_PREFERENCES_NAMESPACE "default_latitude",
2012 VIK_LAYER_PARAM_DOUBLE,
2015 VIK_LAYER_WIDGET_SPINBUTTON,
2019 VikLayerParam pref_lon[] = {
2020 { VIKING_PREFERENCES_NAMESPACE "default_longitude",
2021 VIK_LAYER_PARAM_DOUBLE,
2024 VIK_LAYER_WIDGET_SPINBUTTON,
2029 /* Get current center */
2031 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &ll );
2033 /* Apply to preferences */
2034 VikLayerParamData vlp_data;
2035 vlp_data.d = ll.lat;
2036 a_preferences_run_setparam (vlp_data, pref_lat);
2037 vlp_data.d = ll.lon;
2038 a_preferences_run_setparam (vlp_data, pref_lon);
2039 /* Remember to save */
2040 a_preferences_save_to_file();
2043 static void clear_cb ( GtkAction *a, VikWindow *vw )
2045 vik_layers_panel_clear ( vw->viking_vlp );
2046 window_set_filename ( vw, NULL );
2050 static void window_close ( GtkAction *a, VikWindow *vw )
2052 if ( ! delete_event ( vw ) )
2053 gtk_widget_destroy ( GTK_WIDGET(vw) );
2056 static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw )
2058 if (save_file( NULL, vw)) {
2059 window_close( NULL, vw);
2066 static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
2068 gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
2069 if ( a_dialog_custom_zoom ( GTK_WINDOW(vw), &xmpp, &ympp ) )
2071 vik_viewport_set_xmpp ( vw->viking_vvp, xmpp );
2072 vik_viewport_set_ympp ( vw->viking_vvp, ympp );
2077 static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h, gdouble zoom, gboolean save_as_png )
2079 /* more efficient way: stuff draws directly to pixbuf (fork viewport) */
2080 GdkPixbuf *pixbuf_to_save;
2081 gdouble old_xmpp, old_ympp;
2082 GError *error = NULL;
2084 /* backup old zoom & set new */
2085 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
2086 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
2087 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
2089 /* reset width and height: */
2090 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
2092 /* draw all layers */
2095 /* save buffer as file. */
2096 pixbuf_to_save = gdk_pixbuf_get_from_drawable ( NULL, GDK_DRAWABLE(vik_viewport_get_pixmap ( vw->viking_vvp )), NULL, 0, 0, 0, 0, w, h);
2097 gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL );
2100 g_warning("Unable to write to file %s: %s", fn, error->message );
2101 g_error_free (error);
2103 g_object_unref ( G_OBJECT(pixbuf_to_save) );
2105 /* pretend like nothing happened ;) */
2106 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
2107 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
2108 vik_viewport_configure ( vw->viking_vvp );
2112 static void save_image_dir ( VikWindow *vw, const gchar *fn, guint w, guint h, gdouble zoom, gboolean save_as_png, guint tiles_w, guint tiles_h )
2114 gulong size = sizeof(gchar) * (strlen(fn) + 15);
2115 gchar *name_of_file = g_malloc ( size );
2117 struct UTM utm_orig, utm;
2119 /* *** copied from above *** */
2120 GdkPixbuf *pixbuf_to_save;
2121 gdouble old_xmpp, old_ympp;
2122 GError *error = NULL;
2124 /* backup old zoom & set new */
2125 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
2126 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
2127 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
2129 /* reset width and height: do this only once for all images (same size) */
2130 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
2131 /* *** end copy from above *** */
2133 g_assert ( vik_viewport_get_coord_mode ( vw->viking_vvp ) == VIK_COORD_UTM );
2137 utm_orig = *((const struct UTM *)vik_viewport_get_center ( vw->viking_vvp ));
2139 for ( y = 1; y <= tiles_h; y++ )
2141 for ( x = 1; x <= tiles_w; x++ )
2143 g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, G_DIR_SEPARATOR, y, x, save_as_png ? "png" : "jpg" );
2145 if ( tiles_w & 0x1 )
2146 utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom);
2148 utm.easting += ((gdouble)x - (((gdouble)tiles_w)+1)/2) * (w*zoom);
2149 if ( tiles_h & 0x1 ) /* odd */
2150 utm.northing -= ((gdouble)y - ceil(((gdouble)tiles_h)/2)) * (h*zoom);
2152 utm.northing -= ((gdouble)y - (((gdouble)tiles_h)+1)/2) * (h*zoom);
2154 /* move to correct place. */
2155 vik_viewport_set_center_utm ( vw->viking_vvp, &utm );
2159 /* save buffer as file. */
2160 pixbuf_to_save = gdk_pixbuf_get_from_drawable ( NULL, GDK_DRAWABLE(vik_viewport_get_pixmap ( vw->viking_vvp )), NULL, 0, 0, 0, 0, w, h);
2161 gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL );
2164 g_warning("Unable to write to file %s: %s", name_of_file, error->message );
2165 g_error_free (error);
2168 g_object_unref ( G_OBJECT(pixbuf_to_save) );
2172 vik_viewport_set_center_utm ( vw->viking_vvp, &utm_orig );
2173 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
2174 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
2175 vik_viewport_configure ( vw->viking_vvp );
2178 g_free ( name_of_file );
2181 static void draw_to_image_file_current_window_cb(GtkWidget* widget,GdkEventButton *event,gpointer *pass_along)
2183 VikWindow *vw = VIK_WINDOW(pass_along[0]);
2184 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
2185 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
2186 gdouble width_min, width_max, height_min, height_max;
2189 gtk_spin_button_get_range ( width_spin, &width_min, &width_max );
2190 gtk_spin_button_get_range ( height_spin, &height_min, &height_max );
2192 /* TODO: support for xzoom and yzoom values */
2193 width = vik_viewport_get_width ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
2194 height = vik_viewport_get_height ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
2196 if ( width > width_max || width < width_min || height > height_max || height < height_min )
2197 a_dialog_info_msg ( GTK_WINDOW(vw), _("Viewable region outside allowable pixel size bounds for image. Clipping width/height values.") );
2199 gtk_spin_button_set_value ( width_spin, width );
2200 gtk_spin_button_set_value ( height_spin, height );
2203 static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
2205 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
2206 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
2209 w = gtk_spin_button_get_value(width_spin) * gtk_spin_button_get_value(zoom_spin);
2210 h = gtk_spin_button_get_value(height_spin) * gtk_spin_button_get_value(zoom_spin);
2211 if (pass_along[4]) /* save many images; find TOTAL area covered */
2213 w *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[4]));
2214 h *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[5]));
2216 vik_units_distance_t dist_units = a_vik_get_units_distance ();
2217 switch (dist_units) {
2218 case VIK_UNITS_DISTANCE_KILOMETRES:
2219 label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. km)"), (glong)w, (glong)h, (w*h/1000000));
2221 case VIK_UNITS_DISTANCE_MILES:
2222 label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. miles)"), (glong)w, (glong)h, (w*h/2589988.11));
2225 label_text = g_strdup_printf ("Just to keep the compiler happy");
2226 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2229 gtk_label_set_text(GTK_LABEL(pass_along[6]), label_text);
2230 g_free ( label_text );
2233 static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_image_only )
2235 /* todo: default for answers inside VikWindow or static (thruout instance) */
2236 GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Save to Image File"), GTK_WINDOW(vw),
2237 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
2239 GTK_RESPONSE_REJECT,
2241 GTK_RESPONSE_ACCEPT,
2243 GtkWidget *width_label, *width_spin, *height_label, *height_spin;
2244 GtkWidget *png_radio, *jpeg_radio;
2245 GtkWidget *current_window_button;
2246 gpointer current_window_pass_along[7];
2247 GtkWidget *zoom_label, *zoom_spin;
2248 GtkWidget *total_size_label;
2250 /* only used if (!one_image_only) */
2251 GtkWidget *tiles_width_spin = NULL, *tiles_height_spin = NULL;
2254 width_label = gtk_label_new ( _("Width (pixels):") );
2255 width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_width, 10, 5000, 10, 100, 0 )), 10, 0 );
2256 height_label = gtk_label_new ( _("Height (pixels):") );
2257 height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_height, 10, 5000, 10, 100, 0 )), 10, 0 );
2259 zoom_label = gtk_label_new ( _("Zoom (meters per pixel):") );
2260 /* TODO: separate xzoom and yzoom factors */
2261 zoom_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vik_viewport_get_xmpp(vw->viking_vvp), VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM/2.0, 1, 100, 0 )), 16, 0);
2263 total_size_label = gtk_label_new ( NULL );
2265 current_window_button = gtk_button_new_with_label ( _("Area in current viewable window") );
2266 current_window_pass_along [0] = vw;
2267 current_window_pass_along [1] = width_spin;
2268 current_window_pass_along [2] = height_spin;
2269 current_window_pass_along [3] = zoom_spin;
2270 current_window_pass_along [4] = NULL; /* used for one_image_only != 1 */
2271 current_window_pass_along [5] = NULL;
2272 current_window_pass_along [6] = total_size_label;
2273 g_signal_connect ( G_OBJECT(current_window_button), "button_press_event", G_CALLBACK(draw_to_image_file_current_window_cb), current_window_pass_along );
2275 png_radio = gtk_radio_button_new_with_label ( NULL, _("Save as PNG") );
2276 jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), _("Save as JPEG") );
2278 if ( ! vw->draw_image_save_as_png )
2279 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE );
2281 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_label, FALSE, FALSE, 0);
2282 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_spin, FALSE, FALSE, 0);
2283 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_label, FALSE, FALSE, 0);
2284 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_spin, FALSE, FALSE, 0);
2285 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), current_window_button, FALSE, FALSE, 0);
2286 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), png_radio, FALSE, FALSE, 0);
2287 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), jpeg_radio, FALSE, FALSE, 0);
2288 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_label, FALSE, FALSE, 0);
2289 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_spin, FALSE, FALSE, 0);
2291 if ( ! one_image_only )
2293 GtkWidget *tiles_width_label, *tiles_height_label;
2296 tiles_width_label = gtk_label_new ( _("East-west image tiles:") );
2297 tiles_width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
2298 tiles_height_label = gtk_label_new ( _("North-south image tiles:") );
2299 tiles_height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
2300 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_label, FALSE, FALSE, 0);
2301 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_spin, FALSE, FALSE, 0);
2302 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_label, FALSE, FALSE, 0);
2303 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_spin, FALSE, FALSE, 0);
2305 current_window_pass_along [4] = tiles_width_spin;
2306 current_window_pass_along [5] = tiles_height_spin;
2307 g_signal_connect ( G_OBJECT(tiles_width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
2308 g_signal_connect ( G_OBJECT(tiles_height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
2310 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), total_size_label, FALSE, FALSE, 0);
2311 g_signal_connect ( G_OBJECT(width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
2312 g_signal_connect ( G_OBJECT(height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
2313 g_signal_connect ( G_OBJECT(zoom_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
2315 draw_to_image_file_total_area_cb ( NULL, current_window_pass_along ); /* set correct size info now */
2317 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
2319 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
2321 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
2323 gtk_widget_hide ( GTK_WIDGET(dialog) );
2324 if ( one_image_only )
2325 save_image_file ( vw, fn,
2326 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
2327 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
2328 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
2329 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ) );
2331 // NB is in UTM mode ATM
2332 save_image_dir ( vw, fn,
2333 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
2334 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
2335 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
2336 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ),
2337 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_width_spin) ),
2338 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_height_spin) ) );
2341 gtk_widget_destroy ( GTK_WIDGET(dialog) );
2345 static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw )
2348 if (!vw->save_img_dia) {
2349 vw->save_img_dia = gtk_file_chooser_dialog_new (_("Save Image"),
2351 GTK_FILE_CHOOSER_ACTION_SAVE,
2352 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2353 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
2355 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) );
2356 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE );
2359 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_ACCEPT )
2361 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dia) );
2362 if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == FALSE || a_dialog_yes_or_no ( GTK_WINDOW(vw->save_img_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) )
2364 draw_to_image_file ( vw, fn, TRUE );
2370 gtk_widget_hide ( vw->save_img_dia );
2373 static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw )
2377 if ( vik_viewport_get_coord_mode(vw->viking_vvp) != VIK_COORD_UTM ) {
2378 a_dialog_error_msg ( GTK_WINDOW(vw), _("You must be in UTM mode to use this feature") );
2382 if (!vw->save_img_dir_dia) {
2383 vw->save_img_dir_dia = gtk_file_chooser_dialog_new (_("Choose a directory to hold images"),
2385 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
2386 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2387 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2389 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) );
2390 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE );
2393 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_ACCEPT )
2395 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dir_dia) );
2398 draw_to_image_file ( vw, fn, FALSE );
2404 gtk_widget_hide ( vw->save_img_dir_dia );
2407 #if GTK_CHECK_VERSION(2,10,0)
2408 static void print_cb ( GtkAction *a, VikWindow *vw )
2410 a_print(vw, vw->viking_vvp);
2414 /* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */
2415 static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWindow *vw )
2417 VikViewportDrawMode drawmode;
2418 if (!strcmp(gtk_action_get_name(a), "ModeUTM")) {
2419 drawmode = VIK_VIEWPORT_DRAWMODE_UTM;
2421 else if (!strcmp(gtk_action_get_name(a), "ModeLatLon")) {
2422 drawmode = VIK_VIEWPORT_DRAWMODE_LATLON;
2424 else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) {
2425 drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA;
2427 else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) {
2428 drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
2431 g_critical("Houston, we've had a problem.");
2435 if ( !vw->only_updating_coord_mode_ui )
2437 VikViewportDrawMode olddrawmode = vik_viewport_get_drawmode ( vw->viking_vvp );
2438 if ( olddrawmode != drawmode )
2440 /* this takes care of coord mode too */
2441 vik_viewport_set_drawmode ( vw->viking_vvp, drawmode );
2442 if ( drawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
2443 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_UTM );
2444 } else if ( olddrawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
2445 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_LATLON );
2452 static void set_draw_scale ( GtkAction *a, VikWindow *vw )
2454 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ShowScale" );
2455 g_assert(check_box);
2456 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
2457 vik_viewport_set_draw_scale ( vw->viking_vvp, state );
2461 static void set_draw_centermark ( GtkAction *a, VikWindow *vw )
2463 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ShowCenterMark" );
2464 g_assert(check_box);
2465 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
2466 vik_viewport_set_draw_centermark ( vw->viking_vvp, state );
2470 static void set_draw_highlight ( GtkAction *a, VikWindow *vw )
2472 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/SetShow/ShowHighlight" );
2473 g_assert(check_box);
2474 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
2475 vik_viewport_set_draw_highlight ( vw->viking_vvp, state );
2479 static void set_bg_color ( GtkAction *a, VikWindow *vw )
2481 GtkWidget *colorsd = gtk_color_selection_dialog_new ( _("Choose a background color") );
2482 GdkColor *color = vik_viewport_get_background_gdkcolor ( vw->viking_vvp );
2483 gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2484 gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2485 if ( gtk_dialog_run ( GTK_DIALOG(colorsd) ) == GTK_RESPONSE_OK )
2487 gtk_color_selection_get_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2488 vik_viewport_set_background_gdkcolor ( vw->viking_vvp, color );
2492 gtk_widget_destroy ( colorsd );
2495 static void set_highlight_color ( GtkAction *a, VikWindow *vw )
2497 GtkWidget *colorsd = gtk_color_selection_dialog_new ( _("Choose a track highlight color") );
2498 GdkColor *color = vik_viewport_get_highlight_gdkcolor ( vw->viking_vvp );
2499 gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2500 gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2501 if ( gtk_dialog_run ( GTK_DIALOG(colorsd) ) == GTK_RESPONSE_OK )
2503 gtk_color_selection_get_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2504 vik_viewport_set_highlight_gdkcolor ( vw->viking_vvp, color );
2508 gtk_widget_destroy ( colorsd );
2513 /***********************************************************************************************
2515 ***********************************************************************************************/
2517 static GtkActionEntry entries[] = {
2518 { "File", NULL, N_("_File"), 0, 0, 0 },
2519 { "Edit", NULL, N_("_Edit"), 0, 0, 0 },
2520 { "View", NULL, N_("_View"), 0, 0, 0 },
2521 { "SetShow", NULL, N_("_Show"), 0, 0, 0 },
2522 { "SetZoom", NULL, N_("_Zoom"), 0, 0, 0 },
2523 { "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
2524 { "Layers", NULL, N_("_Layers"), 0, 0, 0 },
2525 { "Tools", NULL, N_("_Tools"), 0, 0, 0 },
2526 { "Exttools", NULL, N_("_Webtools"), 0, 0, 0 },
2527 { "Help", NULL, N_("_Help"), 0, 0, 0 },
2529 { "New", GTK_STOCK_NEW, N_("_New"), "<control>N", N_("New file"), (GCallback)newwindow_cb },
2530 { "Open", GTK_STOCK_OPEN, N_("_Open..."), "<control>O", N_("Open a file"), (GCallback)load_file },
2531 { "OpenRecentFile", NULL, N_("Open _Recent File"), NULL, NULL, (GCallback)NULL },
2532 { "Append", GTK_STOCK_ADD, N_("Append _File..."), NULL, N_("Append data from a different file"), (GCallback)load_file },
2533 { "Acquire", GTK_STOCK_GO_DOWN, N_("A_cquire"), NULL, NULL, (GCallback)NULL },
2534 { "AcquireGPS", NULL, N_("From _GPS..."), NULL, N_("Transfer data from a GPS device"), (GCallback)acquire_from_gps },
2535 { "AcquireGPSBabel", NULL, N_("Import File With GPS_Babel..."), NULL, N_("Import file via GPSBabel converter"), (GCallback)acquire_from_file },
2536 { "AcquireGoogle", NULL, N_("Google _Directions..."), NULL, N_("Get driving directions from Google"), (GCallback)acquire_from_google },
2537 #ifdef VIK_CONFIG_OPENSTREETMAP
2538 { "AcquireOSM", NULL, N_("_OSM Traces..."), NULL, N_("Get traces from OpenStreetMap"), (GCallback)acquire_from_osm },
2540 #ifdef VIK_CONFIG_GEOCACHES
2541 { "AcquireGC", NULL, N_("Geo_caches..."), NULL, N_("Get Geocaches from geocaching.com"), (GCallback)acquire_from_gc },
2543 #ifdef VIK_CONFIG_GEOTAG
2544 { "AcquireGeotag", NULL, N_("From Geotagged _Images..."), NULL, N_("Create waypoints from geotagged images"), (GCallback)acquire_from_geotag },
2546 { "Save", GTK_STOCK_SAVE, N_("_Save"), "<control>S", N_("Save the file"), (GCallback)save_file },
2547 { "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), NULL, N_("Save the file under different name"), (GCallback)save_file_as },
2548 { "GenImg", GTK_STOCK_CLEAR, N_("_Generate Image File..."), NULL, N_("Save a snapshot of the workspace into a file"), (GCallback)draw_to_image_file_cb },
2549 { "GenImgDir", GTK_STOCK_DND_MULTIPLE, N_("Generate _Directory of Images..."), NULL, N_("FIXME:IMGDIR"), (GCallback)draw_to_image_dir_cb },
2551 #if GTK_CHECK_VERSION(2,10,0)
2552 { "Print", GTK_STOCK_PRINT, N_("_Print..."), NULL, N_("Print maps"), (GCallback)print_cb },
2555 { "Exit", GTK_STOCK_QUIT, N_("E_xit"), "<control>W", N_("Exit the program"), (GCallback)window_close },
2556 { "SaveExit", GTK_STOCK_QUIT, N_("Save and Exit"), NULL, N_("Save and Exit the program"), (GCallback)save_file_and_exit },
2558 { "GotoDefaultLocation", GTK_STOCK_HOME, N_("Go to the _Default Location"), NULL, N_("Go to the default location"), (GCallback)goto_default_location },
2559 { "GotoSearch", GTK_STOCK_JUMP_TO, N_("Go to _Location..."), NULL, N_("Go to address/place using text search"), (GCallback)goto_address },
2560 { "GotoLL", GTK_STOCK_JUMP_TO, N_("_Go to Lat/Lon..."), NULL, N_("Go to arbitrary lat/lon coordinate"), (GCallback)draw_goto_cb },
2561 { "GotoUTM", GTK_STOCK_JUMP_TO, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb },
2562 { "SetHLColor",GTK_STOCK_SELECT_COLOR, N_("Set _Highlight Color..."), NULL, NULL, (GCallback)set_highlight_color },
2563 { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Bac_kground Color..."), NULL, NULL, (GCallback)set_bg_color },
2564 { "ZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus", NULL, (GCallback)draw_zoom_cb },
2565 { "ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus", NULL, (GCallback)draw_zoom_cb },
2566 { "ZoomTo", GTK_STOCK_ZOOM_FIT, N_("Zoom _To..."), "<control>Z", NULL, (GCallback)zoom_to_cb },
2567 { "Zoom0.25", NULL, N_("0.25"), NULL, NULL, (GCallback)draw_zoom_cb },
2568 { "Zoom0.5", NULL, N_("0.5"), NULL, NULL, (GCallback)draw_zoom_cb },
2569 { "Zoom1", NULL, N_("1"), NULL, NULL, (GCallback)draw_zoom_cb },
2570 { "Zoom2", NULL, N_("2"), NULL, NULL, (GCallback)draw_zoom_cb },
2571 { "Zoom4", NULL, N_("4"), NULL, NULL, (GCallback)draw_zoom_cb },
2572 { "Zoom8", NULL, N_("8"), NULL, NULL, (GCallback)draw_zoom_cb },
2573 { "Zoom16", NULL, N_("16"), NULL, NULL, (GCallback)draw_zoom_cb },
2574 { "Zoom32", NULL, N_("32"), NULL, NULL, (GCallback)draw_zoom_cb },
2575 { "Zoom64", NULL, N_("64"), NULL, NULL, (GCallback)draw_zoom_cb },
2576 { "Zoom128", NULL, N_("128"), NULL, NULL, (GCallback)draw_zoom_cb },
2577 { "Zoom256", NULL, N_("256"), NULL, NULL, (GCallback)draw_zoom_cb },
2578 { "Zoom512", NULL, N_("512"), NULL, NULL, (GCallback)draw_zoom_cb },
2579 { "Zoom1024", NULL, N_("1024"), NULL, NULL, (GCallback)draw_zoom_cb },
2580 { "Zoom2048", NULL, N_("2048"), NULL, NULL, (GCallback)draw_zoom_cb },
2581 { "Zoom4096", NULL, N_("4096"), NULL, NULL, (GCallback)draw_zoom_cb },
2582 { "Zoom8192", NULL, N_("8192"), NULL, NULL, (GCallback)draw_zoom_cb },
2583 { "Zoom16384", NULL, N_("16384"), NULL, NULL, (GCallback)draw_zoom_cb },
2584 { "Zoom32768", NULL, N_("32768"), NULL, NULL, (GCallback)draw_zoom_cb },
2585 { "PanNorth", NULL, N_("Pan _North"), "<control>Up", NULL, (GCallback)draw_pan_cb },
2586 { "PanEast", NULL, N_("Pan _East"), "<control>Right", NULL, (GCallback)draw_pan_cb },
2587 { "PanSouth", NULL, N_("Pan _South"), "<control>Down", NULL, (GCallback)draw_pan_cb },
2588 { "PanWest", NULL, N_("Pan _West"), "<control>Left", NULL, (GCallback)draw_pan_cb },
2589 { "BGJobs", GTK_STOCK_EXECUTE, N_("Background _Jobs"), NULL, NULL, (GCallback)a_background_show_window },
2591 { "Cut", GTK_STOCK_CUT, N_("Cu_t"), NULL, NULL, (GCallback)menu_cut_layer_cb },
2592 { "Copy", GTK_STOCK_COPY, N_("_Copy"), NULL, NULL, (GCallback)menu_copy_layer_cb },
2593 { "Paste", GTK_STOCK_PASTE, N_("_Paste"), NULL, NULL, (GCallback)menu_paste_layer_cb },
2594 { "Delete", GTK_STOCK_DELETE, N_("_Delete"), NULL, NULL, (GCallback)menu_delete_layer_cb },
2595 { "DeleteAll", NULL, N_("Delete All"), NULL, NULL, (GCallback)clear_cb },
2596 { "MapCacheFlush",NULL, N_("_Flush Map Cache"), NULL, NULL, (GCallback)mapcache_flush_cb },
2597 { "SetDefaultLocation", GTK_STOCK_GO_FORWARD, N_("_Set the Default Location"), NULL, N_("Set the Default Location to the current position"),(GCallback)default_location_cb },
2598 { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences"), NULL, NULL, (GCallback)preferences_cb },
2599 { "Properties",GTK_STOCK_PROPERTIES, N_("_Properties"), NULL, NULL, (GCallback)menu_properties_cb },
2601 { "HelpEntry", GTK_STOCK_HELP, N_("_Help"), "F1", NULL, (GCallback)help_help_cb },
2602 { "About", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, (GCallback)help_about_cb },
2606 /* FIXME use VIEWPORT_DRAWMODE values */
2607 static GtkRadioActionEntry mode_entries[] = {
2608 { "ModeUTM", NULL, N_("_UTM Mode"), "<control>u", NULL, 0 },
2609 { "ModeExpedia", NULL, N_("_Expedia Mode"), "<control>e", NULL, 1 },
2610 { "ModeMercator", NULL, N_("_Mercator Mode"), "<control>m", NULL, 4 },
2611 { "ModeLatLon", NULL, N_("Lat_/Lon Mode"), "<control>l", NULL, 5 },
2614 static GtkRadioActionEntry tool_entries[] = {
2615 { "Pan", "vik-icon-pan", N_("_Pan"), "<control><shift>P", N_("Pan Tool"), 0 },
2616 { "Zoom", "vik-icon-zoom", N_("_Zoom"), "<control><shift>Z", N_("Zoom Tool"), 1 },
2617 { "Ruler", "vik-icon-ruler", N_("_Ruler"), "<control><shift>R", N_("Ruler Tool"), 2 },
2618 { "Select", "vik-icon-select", N_("_Select"), "<control><shift>S", N_("Select Tool"), 3 }
2621 static GtkToggleActionEntry toggle_entries[] = {
2622 { "ShowScale", NULL, N_("Show _Scale"), "F5", N_("Show Scale"), (GCallback)set_draw_scale, TRUE },
2623 { "ShowCenterMark", NULL, N_("Show _Center Mark"), "F6", N_("Show Center Mark"), (GCallback)set_draw_centermark, TRUE },
2624 { "ShowHighlight", GTK_STOCK_UNDERLINE, N_("Show _Highlight"), "F7", N_("Show Highlight"), (GCallback)set_draw_highlight, TRUE },
2625 { "FullScreen", GTK_STOCK_FULLSCREEN, N_("_Full Screen"), "F11", N_("Activate full screen mode"), (GCallback)full_screen_cb, FALSE },
2626 { "ViewSidePanel", GTK_STOCK_INDEX, N_("Show Side _Panel"), "F9", N_("Show Side Panel"), (GCallback)view_side_panel_cb, TRUE },
2627 { "ViewStatusBar", NULL, N_("Show Status_bar"), "F12", N_("Show Statusbar"), (GCallback)view_statusbar_cb, TRUE },
2628 { "ViewToolbar", NULL, N_("Show _Toolbar"), "F3", N_("Show Toolbar"), (GCallback)view_toolbar_cb, TRUE },
2629 { "ViewMainMenu", NULL, N_("Show _Menu"), "F4", N_("Show Menu"), (GCallback)view_main_menu_cb, TRUE },
2632 #include "menu.xml.h"
2633 static void window_create_ui( VikWindow *window )
2636 GtkActionGroup *action_group;
2637 GtkAccelGroup *accel_group;
2640 GtkIconFactory *icon_factory;
2641 GtkIconSet *icon_set;
2642 GtkRadioActionEntry *tools = NULL, *radio;
2645 uim = gtk_ui_manager_new ();
2648 toolbox_add_tool(window->vt, &ruler_tool, TOOL_LAYER_TYPE_NONE);
2649 toolbox_add_tool(window->vt, &zoom_tool, TOOL_LAYER_TYPE_NONE);
2650 toolbox_add_tool(window->vt, &pan_tool, TOOL_LAYER_TYPE_NONE);
2651 toolbox_add_tool(window->vt, &select_tool, TOOL_LAYER_TYPE_NONE);
2654 if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) {
2655 g_error_free (error);
2659 action_group = gtk_action_group_new ("MenuActions");
2660 gtk_action_group_set_translation_domain(action_group, PACKAGE_NAME);
2661 gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
2662 gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
2663 gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window);
2665 icon_factory = gtk_icon_factory_new ();
2666 gtk_icon_factory_add_default (icon_factory);
2668 register_vik_icons(icon_factory);
2671 for (i=0; i<G_N_ELEMENTS(tool_entries); i++) {
2672 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2673 radio = &tools[ntools];
2675 *radio = tool_entries[i];
2676 radio->value = ntools;
2679 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2680 GtkActionEntry action;
2681 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Layers/",
2682 vik_layer_get_interface(i)->name,
2683 vik_layer_get_interface(i)->name,
2684 GTK_UI_MANAGER_MENUITEM, FALSE);
2686 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (vik_layer_get_interface(i)->icon, FALSE, NULL ));
2687 gtk_icon_factory_add (icon_factory, vik_layer_get_interface(i)->name, icon_set);
2688 gtk_icon_set_unref (icon_set);
2690 action.name = vik_layer_get_interface(i)->name;
2691 action.stock_id = vik_layer_get_interface(i)->name;
2692 action.label = g_strdup_printf( _("New %s Layer"), vik_layer_get_interface(i)->name);
2693 action.accelerator = NULL;
2694 action.tooltip = NULL;
2695 action.callback = (GCallback)menu_addlayer_cb;
2696 gtk_action_group_add_actions(action_group, &action, 1, window);
2698 if ( vik_layer_get_interface(i)->tools_count ) {
2699 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2700 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2703 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2704 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2705 radio = &tools[ntools];
2708 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools",
2709 _(vik_layer_get_interface(i)->tools[j].name),
2710 vik_layer_get_interface(i)->tools[j].name,
2711 GTK_UI_MANAGER_MENUITEM, FALSE);
2712 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems",
2713 _(vik_layer_get_interface(i)->tools[j].name),
2714 vik_layer_get_interface(i)->tools[j].name,
2715 GTK_UI_MANAGER_TOOLITEM, FALSE);
2717 toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i);
2719 radio->name = vik_layer_get_interface(i)->tools[j].name;
2720 radio->stock_id = vik_layer_get_interface(i)->tools[j].name,
2721 radio->label = _(vik_layer_get_interface(i)->tools[j].name);
2722 radio->accelerator = NULL;
2723 radio->tooltip = _(vik_layer_get_interface(i)->tools[j].name);
2724 radio->value = ntools;
2727 g_object_unref (icon_factory);
2729 gtk_action_group_add_radio_actions(action_group, tools, ntools, 0, (GCallback)menu_tool_cb, window);
2732 gtk_ui_manager_insert_action_group (uim, action_group, 0);
2734 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2735 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2736 GtkAction *action = gtk_action_group_get_action(action_group,
2737 vik_layer_get_interface(i)->tools[j].name);
2738 g_object_set(action, "sensitive", FALSE, NULL);
2741 window->action_group = action_group;
2743 accel_group = gtk_ui_manager_get_accel_group (uim);
2744 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
2745 gtk_ui_manager_ensure_update (uim);
2747 setup_recent_files(window);
2753 const GdkPixdata *data;
2756 { &begintr_18_pixbuf, "Begin Track" },
2757 { &route_finder_18_pixbuf, "Route Finder" },
2758 { &mover_22_pixbuf, "vik-icon-pan" },
2759 { &demdl_18_pixbuf, "DEM Download/Import" },
2760 { &showpic_18_pixbuf, "Show Picture" },
2761 { &addtr_18_pixbuf, "Create Track" },
2762 { &edtr_18_pixbuf, "Edit Trackpoint" },
2763 { &addwp_18_pixbuf, "Create Waypoint" },
2764 { &edwp_18_pixbuf, "Edit Waypoint" },
2765 { &zoom_18_pixbuf, "vik-icon-zoom" },
2766 { &ruler_18_pixbuf, "vik-icon-ruler" },
2767 { &select_18_pixbuf, "vik-icon-select" },
2768 { &geozoom_18_pixbuf, "Georef Zoom Tool" },
2769 { &geomove_18_pixbuf, "Georef Move Map" },
2770 { &mapdl_18_pixbuf, "Maps Download" },
2773 static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
2776 register_vik_icons (GtkIconFactory *icon_factory)
2778 GtkIconSet *icon_set;
2781 for (i = 0; i < n_stock_icons; i++) {
2782 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (
2783 stock_icons[i].data, FALSE, NULL ));
2784 gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set);
2785 gtk_icon_set_unref (icon_set);
2789 gpointer vik_window_get_selected_trw_layer ( VikWindow *vw )
2791 return vw->selected_vtl;
2794 void vik_window_set_selected_trw_layer ( VikWindow *vw, gpointer vtl )
2796 vw->selected_vtl = vtl;
2797 vw->containing_vtl = vtl;
2799 vw->selected_track = NULL;
2800 vw->selected_tracks = NULL;
2801 vw->selected_waypoint = NULL;
2802 vw->selected_waypoints = NULL;
2803 vw->selected_name = NULL;
2804 // Set highlight thickness
2805 vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) );
2808 gpointer vik_window_get_selected_tracks ( VikWindow *vw )
2810 return vw->selected_tracks;
2813 void vik_window_set_selected_tracks ( VikWindow *vw, gpointer gl, gpointer vtl )
2815 vw->selected_tracks = gl;
2816 vw->containing_vtl = vtl;
2818 vw->selected_vtl = NULL;
2819 vw->selected_track = NULL;
2820 vw->selected_waypoint = NULL;
2821 vw->selected_waypoints = NULL;
2822 vw->selected_name = NULL;
2823 // Set highlight thickness
2824 vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) );
2827 gpointer vik_window_get_selected_track ( VikWindow *vw )
2829 return vw->selected_track;
2832 void vik_window_set_selected_track ( VikWindow *vw, gpointer *vt, gpointer vtl, gpointer name )
2834 vw->selected_track = vt;
2835 vw->containing_vtl = vtl;
2836 vw->selected_name = name;
2838 vw->selected_vtl = NULL;
2839 vw->selected_tracks = NULL;
2840 vw->selected_waypoint = NULL;
2841 vw->selected_waypoints = NULL;
2842 // Set highlight thickness
2843 vik_viewport_set_highlight_thickness ( vw->viking_vvp, vik_trw_layer_get_property_tracks_line_thickness (vw->containing_vtl) );
2846 gpointer vik_window_get_selected_waypoints ( VikWindow *vw )
2848 return vw->selected_waypoints;
2851 void vik_window_set_selected_waypoints ( VikWindow *vw, gpointer gl, gpointer vtl )
2853 vw->selected_waypoints = gl;
2854 vw->containing_vtl = vtl;
2856 vw->selected_vtl = NULL;
2857 vw->selected_track = NULL;
2858 vw->selected_tracks = NULL;
2859 vw->selected_waypoint = NULL;
2860 vw->selected_name = NULL;
2863 gpointer vik_window_get_selected_waypoint ( VikWindow *vw )
2865 return vw->selected_waypoint;
2868 void vik_window_set_selected_waypoint ( VikWindow *vw, gpointer *vwp, gpointer vtl, gpointer name )
2870 vw->selected_waypoint = vwp;
2871 vw->containing_vtl = vtl;
2872 vw->selected_name = name;
2874 vw->selected_vtl = NULL;
2875 vw->selected_track = NULL;
2876 vw->selected_tracks = NULL;
2877 vw->selected_waypoints = NULL;
2880 gpointer vik_window_get_selected_name ( VikWindow *vw )
2882 return vw->selected_name;
2885 gboolean vik_window_clear_highlight ( VikWindow *vw )
2887 gboolean need_redraw = FALSE;
2888 if ( vw->selected_vtl != NULL ) {
2889 vw->selected_vtl = NULL;
2892 if ( vw->selected_track != NULL ) {
2893 vw->selected_track = NULL;
2896 if ( vw->selected_tracks != NULL ) {
2897 vw->selected_tracks = NULL;
2900 if ( vw->selected_waypoint != NULL ) {
2901 vw->selected_waypoint = NULL;
2904 if ( vw->selected_waypoints != NULL ) {
2905 vw->selected_waypoints = NULL;