2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "background.h"
29 #include "datasources.h"
34 #include "preferences.h"
35 #include "icons/icons.h"
36 #include "vikexttools.h"
37 #include "garminsymbols.h"
50 #include <glib/gstdio.h>
51 #include <glib/gprintf.h>
52 #include <glib/gi18n.h>
55 #define VIKING_WINDOW_WIDTH 1000
56 #define VIKING_WINDOW_HEIGHT 800
57 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
58 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024
59 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
61 static void window_finalize ( GObject *gob );
62 static GObjectClass *parent_class;
64 static void window_init ( VikWindow *vw );
65 static void window_class_init ( VikWindowClass *klass );
66 static void window_set_filename ( VikWindow *vw, const gchar *filename );
68 static void draw_update ( VikWindow *vw );
70 static void newwindow_cb ( GtkAction *a, VikWindow *vw );
74 static gboolean delete_event( VikWindow *vw );
76 static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data );
78 static void window_configure_event ( VikWindow *vw );
79 static void draw_sync ( VikWindow *vw );
80 static void draw_redraw ( VikWindow *vw );
81 static void draw_scroll ( VikWindow *vw, GdkEventScroll *event );
82 static void draw_click ( VikWindow *vw, GdkEventButton *event );
83 static void draw_release ( VikWindow *vw, GdkEventButton *event );
84 static void draw_mouse_motion ( VikWindow *vw, GdkEventMotion *event );
85 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw );
86 static void draw_goto_cb ( GtkAction *a, VikWindow *vw );
88 static void draw_status ();
90 /* End Drawing Functions */
92 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw );
93 static void menu_properties_cb ( GtkAction *a, VikWindow *vw );
94 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw );
102 #define TOOL_LAYER_TYPE_NONE -1
107 toolbox_tool_t *tools;
111 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw );
112 static toolbox_tools_t* toolbox_create(VikWindow *vw);
113 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type );
114 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
115 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
116 static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name);
117 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
118 static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event);
119 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
123 static void window_create_ui( VikWindow *window );
124 static void register_vik_icons (GtkIconFactory *icon_factory);
127 static void load_file ( GtkAction *a, VikWindow *vw );
128 static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
129 static gboolean save_file ( GtkAction *a, VikWindow *vw );
130 static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw );
131 static gboolean window_save ( VikWindow *vw );
135 VikViewport *viking_vvp;
136 VikLayersPanel *viking_vlp;
137 VikStatusbar *viking_vs;
141 GtkItemFactory *item_factory;
143 /* tool management state */
146 guint16 tool_layer_id;
147 guint16 tool_tool_id;
149 GtkActionGroup *action_group;
154 guint draw_image_width, draw_image_height;
155 gboolean draw_image_save_as_png;
160 GtkWidget *open_dia, *save_dia;
161 GtkWidget *save_img_dia, *save_img_dir_dia;
163 gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
166 /* half-drawn update */
168 VikCoord trigger_center;
181 VW_OPENWINDOW_SIGNAL,
185 static guint window_signals[VW_LAST_SIGNAL] = { 0 };
187 static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler") };
189 GType vik_window_get_type (void)
191 static GType vw_type = 0;
195 static const GTypeInfo vw_info =
197 sizeof (VikWindowClass),
198 NULL, /* base_init */
199 NULL, /* base_finalize */
200 (GClassInitFunc) window_class_init, /* class_init */
201 NULL, /* class_finalize */
202 NULL, /* class_data */
205 (GInstanceInitFunc) window_init,
207 vw_type = g_type_register_static ( GTK_TYPE_WINDOW, "VikWindow", &vw_info, 0 );
213 VikViewport * vik_window_viewport(VikWindow *vw)
215 return(vw->viking_vvp);
218 void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
220 int i, j, tool_count;
221 VikLayerInterface *layer_interface;
223 if (!vw->action_group) return;
225 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
227 layer_interface = vik_layer_get_interface(i);
228 tool_count = layer_interface->tools_count;
230 for (j = 0; j < tool_count; j++) {
231 action = gtk_action_group_get_action(vw->action_group,
232 layer_interface->tools[j].name);
233 g_object_set(action, "sensitive", i == vl->type, NULL);
238 static void window_finalize ( GObject *gob )
240 VikWindow *vw = VIK_WINDOW(gob);
241 g_return_if_fail ( vw != NULL );
243 a_background_remove_status ( vw->viking_vs );
245 G_OBJECT_CLASS(parent_class)->finalize(gob);
249 static void window_class_init ( VikWindowClass *klass )
252 GObjectClass *object_class;
254 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);
255 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);
257 object_class = G_OBJECT_CLASS (klass);
259 object_class->finalize = window_finalize;
261 parent_class = g_type_class_peek_parent (klass);
265 static void window_init ( VikWindow *vw )
267 GtkWidget *main_vbox;
270 vw->action_group = NULL;
272 vw->viking_vvp = vik_viewport_new();
273 vw->viking_vlp = vik_layers_panel_new();
274 vik_layers_panel_set_viewport ( vw->viking_vlp, vw->viking_vvp );
275 vw->viking_vs = vik_statusbar_new();
277 vw->vt = toolbox_create(vw);
278 window_create_ui(vw);
279 window_set_filename (vw, NULL);
281 toolbox_activate(vw->vt, "Pan");
284 vw->item_factory = NULL;
286 vw->modified = FALSE;
287 vw->only_updating_coord_mode_ui = FALSE;
289 vw->pan_move = FALSE;
290 vw->pan_x = vw->pan_y = -1;
291 vw->draw_image_width = DRAW_IMAGE_DEFAULT_WIDTH;
292 vw->draw_image_height = DRAW_IMAGE_DEFAULT_HEIGHT;
293 vw->draw_image_save_as_png = DRAW_IMAGE_DEFAULT_SAVE_AS_PNG;
295 main_vbox = gtk_vbox_new(FALSE, 1);
296 gtk_container_add (GTK_CONTAINER (vw), main_vbox);
298 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainMenu"), FALSE, TRUE, 0);
299 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainToolbar"), FALSE, TRUE, 0);
300 gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
301 gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
303 vik_ext_tools_add_menu_items ( vw, vw->uim );
305 g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
307 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw);
308 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw);
309 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 );
310 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw);
311 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw);
312 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw);
313 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
314 g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
316 g_signal_connect_swapped (G_OBJECT (vw->viking_vvp), "key_press_event", G_CALLBACK (key_press_event), vw);
318 gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT);
320 hpaned = gtk_hpaned_new ();
321 gtk_paned_pack1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp), FALSE, FALSE );
322 gtk_paned_pack2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp), TRUE, TRUE );
324 /* This packs the button into the window (a gtk container). */
325 gtk_box_pack_start (GTK_BOX(main_vbox), hpaned, TRUE, TRUE, 0);
327 gtk_box_pack_end (GTK_BOX(main_vbox), GTK_WIDGET(vw->viking_vs), FALSE, TRUE, 0);
329 a_background_add_status(vw->viking_vs);
333 vw->save_img_dia = NULL;
334 vw->save_img_dir_dia = NULL;
337 VikWindow *vik_window_new ()
339 return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
342 static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data )
344 VikLayer *vl = vik_layers_panel_get_selected ( vw->viking_vlp );
345 if (vl && vw->vt->active_tool != -1 && vw->vt->tools[vw->vt->active_tool].ti.key_press ) {
346 gint ltype = vw->vt->tools[vw->vt->active_tool].layer_type;
347 if ( vl && ltype == vl->type )
348 return vw->vt->tools[vw->vt->active_tool].ti.key_press(vl, event, vw->vt->tools[vw->vt->active_tool].state);
350 return FALSE; /* don't handle the keypress */
353 static gboolean delete_event( VikWindow *vw )
355 #ifdef VIKING_PROMPT_IF_MODIFIED
362 dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
363 _("Do you want to save the changes you made to the document \"%s\"?\n"
365 "Your changes will be lost if you don't save them."),
366 vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") ) );
367 gtk_dialog_add_buttons ( dia, _("Don't Save"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
368 switch ( gtk_dialog_run ( dia ) )
370 case GTK_RESPONSE_NO: gtk_widget_destroy ( GTK_WIDGET(dia) ); return FALSE;
371 case GTK_RESPONSE_CANCEL: gtk_widget_destroy ( GTK_WIDGET(dia) ); return TRUE;
372 default: gtk_widget_destroy ( GTK_WIDGET(dia) ); return ! save_file(NULL, vw);
379 static void newwindow_cb ( GtkAction *a, VikWindow *vw )
381 g_signal_emit ( G_OBJECT(vw), window_signals[VW_NEWWINDOW_SIGNAL], 0 );
384 static void draw_update ( VikWindow *vw )
390 static void draw_sync ( VikWindow *vw )
392 vik_viewport_sync(vw->viking_vvp);
394 /* other things may be necc here later. */
397 static void draw_status ( VikWindow *vw )
399 static gchar zoom_level[22];
400 g_snprintf ( zoom_level, 22, "%.3f/%.3f %s", vik_viewport_get_xmpp (vw->viking_vvp), vik_viewport_get_ympp(vw->viking_vvp), vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM ? _("mpp") : _("pixelfact") );
401 if ( vw->current_tool == TOOL_LAYER )
402 vik_statusbar_set_message ( vw->viking_vs, 0, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name );
404 vik_statusbar_set_message ( vw->viking_vs, 0, _(tool_names[vw->current_tool]) );
406 vik_statusbar_set_message ( vw->viking_vs, 2, zoom_level );
409 void vik_window_set_redraw_trigger(VikLayer *vl)
411 VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl));
416 static void window_configure_event ( VikWindow *vw )
418 static int first = 1;
421 // This is a hack to set the cursor corresponding to the first tool
422 // FIXME find the correct way to initialize both tool and its cursor
423 const GdkCursor *cursor = NULL;
425 cursor = toolbox_get_cursor(vw->vt, "Pan");
426 /* We set cursor, even if it is NULL: it resets to default */
427 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, (GdkCursor *)cursor );
431 static void draw_redraw ( VikWindow *vw )
433 VikCoord old_center = vw->trigger_center;
434 vw->trigger_center = *(vik_viewport_get_center(vw->viking_vvp));
435 VikLayer *new_trigger = vw->trigger;
437 VikLayer *old_trigger = VIK_LAYER(vik_viewport_get_trigger(vw->viking_vvp));
440 ; /* do nothing -- have to redraw everything. */
441 else if ( (old_trigger != new_trigger) || !vik_coord_equals(&old_center, &vw->trigger_center) || (new_trigger->type == VIK_LAYER_AGGREGATE) )
442 vik_viewport_set_trigger ( vw->viking_vvp, new_trigger ); /* todo: set to half_drawn mode if new trigger is above old */
444 vik_viewport_set_half_drawn ( vw->viking_vvp, TRUE );
447 vik_viewport_clear ( vw->viking_vvp);
448 vik_layers_panel_draw_all ( vw->viking_vlp );
449 vik_viewport_draw_scale ( vw->viking_vvp );
450 vik_viewport_draw_centermark ( vw->viking_vvp );
452 vik_viewport_set_half_drawn ( vw->viking_vvp, FALSE ); /* just in case. */
455 gboolean draw_buf_done = TRUE;
457 static gboolean draw_buf(gpointer data)
459 gpointer *pass_along = data;
461 gdk_draw_drawable (pass_along[0], pass_along[1],
462 pass_along[2], 0, 0, 0, 0, -1, -1);
463 draw_buf_done = TRUE;
469 /* Mouse event handlers ************************************************************************/
471 static void vik_window_pan_click (VikWindow *vw, GdkEventButton *event)
473 /* set panning origin */
474 vw->pan_move = FALSE;
475 vw->pan_x = (gint) event->x;
476 vw->pan_y = (gint) event->y;
479 static void draw_click (VikWindow *vw, GdkEventButton *event)
481 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
483 /* middle button pressed. we reserve all middle button and scroll events
484 * for panning and zooming; tools only get left/right/movement
486 if ( event->button == 2) {
487 vik_window_pan_click ( vw, event );
490 toolbox_click(vw->vt, event);
494 static void vik_window_pan_move (VikWindow *vw, GdkEventMotion *event)
496 if ( vw->pan_x != -1 ) {
497 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
498 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
501 vw->pan_x = event->x;
502 vw->pan_y = event->y;
506 static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
508 static VikCoord coord;
509 static struct UTM utm;
510 static struct LatLon ll;
511 #define BUFFER_SIZE 50
512 static char pointer_buf[BUFFER_SIZE];
513 gchar *lat = NULL, *lon = NULL;
516 VikDemInterpol interpol_method;
518 /* This is a hack, but work far the best, at least for single pointer systems.
519 * See http://bugzilla.gnome.org/show_bug.cgi?id=587714 for more. */
521 gdk_window_get_pointer (event->window, &x, &y, NULL);
525 toolbox_move(vw->vt, event);
527 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
528 vik_coord_to_utm ( &coord, &utm );
529 a_coords_utm_to_latlon ( &utm, &ll );
530 a_coords_latlon_to_string ( &ll, &lat, &lon );
531 /* Change interpolate method according to scale */
532 zoom = vik_viewport_get_zoom(vw->viking_vvp);
534 interpol_method = VIK_DEM_INTERPOL_NONE;
535 else if (zoom >= 1.0)
536 interpol_method = VIK_DEM_INTERPOL_SIMPLE;
538 interpol_method = VIK_DEM_INTERPOL_BEST;
539 if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION) {
540 if ( a_vik_get_units_height () == VIK_UNITS_HEIGHT_METRES )
541 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dm"), lat, lon, alt );
543 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dft"), lat, lon, (int)VIK_METERS_TO_FEET(alt) );
546 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s"), lat, lon );
551 vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
553 vik_window_pan_move ( vw, event );
555 /* This is recommended by the GTK+ documentation, but does not work properly.
556 * Use deprecated way until GTK+ gets a solution for correct motion hint handling:
557 * http://bugzilla.gnome.org/show_bug.cgi?id=587714
559 /* gdk_event_request_motions ( event ); */
562 static void vik_window_pan_release ( VikWindow *vw, GdkEventButton *event )
564 if ( vw->pan_move == FALSE )
565 vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
567 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
568 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
570 vw->pan_x = vw->pan_y = -1;
573 static void draw_release ( VikWindow *vw, GdkEventButton *event )
575 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
577 if ( event->button == 2 ) { /* move / pan */
578 vik_window_pan_release(vw, event);
581 toolbox_release(vw->vt, event);
585 static void draw_scroll (VikWindow *vw, GdkEventScroll *event)
587 guint modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK);
588 if ( modifiers == GDK_CONTROL_MASK ) {
589 /* control == pan up & down */
590 if ( event->direction == GDK_SCROLL_UP )
591 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 );
593 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 );
594 } else if ( modifiers == GDK_SHIFT_MASK ) {
595 /* shift == pan left & right */
596 if ( event->direction == GDK_SCROLL_UP )
597 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 );
599 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 );
600 } else if ( modifiers == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) {
601 /* control+shift == make sure mouse is still over the same point on the map when we zoom */
604 gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
605 gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
606 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
607 if ( event->direction == GDK_SCROLL_UP )
608 vik_viewport_zoom_in (vw->viking_vvp);
610 vik_viewport_zoom_out(vw->viking_vvp);
611 vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
612 vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
613 center_y + (y - event->y) );
615 if ( event->direction == GDK_SCROLL_UP )
616 vik_viewport_zoom_in (vw->viking_vvp);
618 vik_viewport_zoom_out (vw->viking_vvp);
626 /********************************************************************************
628 ********************************************************************************/
629 static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gdouble distance)
631 PangoFontDescription *pfd;
634 GdkGC *labgc = vik_viewport_new_gc ( vvp, "#cccccc", 1);
635 GdkGC *thickgc = gdk_gc_new(d);
637 gdouble len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
638 gdouble dx = (x2-x1)/len*10;
639 gdouble dy = (y2-y1)/len*10;
640 gdouble c = cos(15.0 * M_PI/180.0);
641 gdouble s = sin(15.0 * M_PI/180.0);
643 gdouble baseangle = 0;
646 /* draw line with arrow ends */
648 gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
649 a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
650 gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
653 a_viewport_clip_line(&x1, &y1, &x2, &y2);
654 gdk_draw_line(d, gc, x1, y1, x2, y2);
656 gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
657 gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
658 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));
659 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c - dy * s), y2 - (dy * c + dx * s));
660 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c + dy * s), y1 + (dy * c - dx * s));
661 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c - dy * s), y1 + (dy * c + dx * s));
666 angle = atan2(dy, dx) + M_PI_2;
668 if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
674 vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
675 vik_coord_to_latlon ( &test, &ll );
676 ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
677 a_coords_latlon_to_utm ( &ll, &u );
678 vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
679 vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
681 baseangle = M_PI - atan2(tx-x1, ty-y1);
692 gdk_gc_copy(thickgc, gc);
693 gdk_gc_set_line_attributes(thickgc, CW, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
694 gdk_color_parse("#2255cc", &color);
695 gdk_gc_set_rgb_fg_color(thickgc, &color);
697 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);
700 gdk_gc_copy(thickgc, gc);
701 gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
702 for (i=0; i<180; i++) {
703 c = cos(i*M_PI/90.0 + baseangle);
704 s = sin(i*M_PI/90.0 + baseangle);
707 gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
709 gdouble ticksize = 2*CW;
710 gdk_draw_line (d, thickgc, x1 + (CR-CW)*c, y1 + (CR-CW)*s, x1 + (CR+ticksize)*c, y1 + (CR+ticksize)*s);
714 gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
715 gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
716 gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
717 c = (CR+CW*2)*cos(baseangle);
718 s = (CR+CW*2)*sin(baseangle);
719 gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
720 gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
723 #define LABEL(x, y, w, h) { \
724 gdk_draw_rectangle(d, labgc, TRUE, (x)-2, (y)-1, (w)+4, (h)+1); \
725 gdk_draw_rectangle(d, gc, FALSE, (x)-2, (y)-1, (w)+4, (h)+1); \
726 gdk_draw_layout(d, gc, (x), (y), pl); }
731 pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
733 pfd = pango_font_description_from_string ("Sans 8"); // FIXME: settable option? global variable?
734 pango_layout_set_font_description (pl, pfd);
735 pango_font_description_free (pfd);
737 pango_layout_set_text(pl, "N", -1);
738 gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
740 /* draw label with distance */
741 vik_units_distance_t dist_units = a_vik_get_units_distance ();
742 switch (dist_units) {
743 case VIK_UNITS_DISTANCE_KILOMETRES:
744 if (distance >= 1000 && distance < 100000) {
745 g_sprintf(str, "%3.2f km", distance/1000.0);
746 } else if (distance < 1000) {
747 g_sprintf(str, "%d m", (int)distance);
749 g_sprintf(str, "%d km", (int)distance/1000);
752 case VIK_UNITS_DISTANCE_MILES:
753 if (distance >= 1600 && distance < 160000) {
754 g_sprintf(str, "%3.2f miles", distance/1600.0);
755 } else if (distance < 1600) {
756 g_sprintf(str, "%d yards", (int)(distance*1.0936133));
758 g_sprintf(str, "%d miles", (int)distance/1600);
762 g_critical("Houston, we've had a problem. distance=%d", dist_units);
765 pango_layout_set_text(pl, str, -1);
767 pango_layout_get_pixel_size ( pl, &wd, &hd );
770 yd = (y1+y2)/2 - hd/2 - dx;
773 yd = (y1+y2)/2 - hd/2 + dx;
776 if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
781 LABEL(xd, yd, wd, hd);
783 /* draw label with bearing */
784 g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
785 pango_layout_set_text(pl, str, -1);
786 pango_layout_get_pixel_size ( pl, &wb, &hb );
787 xb = x1 + CR*cos(angle-M_PI_2);
788 yb = y1 + CR*sin(angle-M_PI_2);
790 if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
796 GdkRectangle r1 = {xd-2, yd-1, wd+4, hd+1}, r2 = {xb-2, yb-1, wb+4, hb+1};
797 if (gdk_rectangle_intersect(&r1, &r2, &r2)) {
801 LABEL(xb, yb, wb, hb);
805 g_object_unref ( G_OBJECT ( pl ) );
806 g_object_unref ( G_OBJECT ( labgc ) );
807 g_object_unref ( G_OBJECT ( thickgc ) );
813 gboolean has_oldcoord;
815 } ruler_tool_state_t;
817 static gpointer ruler_create (VikWindow *vw, VikViewport *vvp)
819 ruler_tool_state_t *s = g_new(ruler_tool_state_t, 1);
822 s->has_oldcoord = FALSE;
826 static void ruler_destroy (ruler_tool_state_t *s)
831 static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
836 if ( event->button == 1 ) {
837 gchar *lat=NULL, *lon=NULL;
838 vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
839 vik_coord_to_latlon ( &coord, &ll );
840 a_coords_latlon_to_string ( &ll, &lat, &lon );
841 if ( s->has_oldcoord ) {
842 vik_units_distance_t dist_units = a_vik_get_units_distance ();
843 switch (dist_units) {
844 case VIK_UNITS_DISTANCE_KILOMETRES:
845 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
847 case VIK_UNITS_DISTANCE_MILES:
848 temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) )* 0.000621371192);
851 temp = g_strdup_printf ("Just to keep the compiler happy");
852 g_critical("Houston, we've had a problem. distance=%d", dist_units);
855 s->has_oldcoord = FALSE;
858 temp = g_strdup_printf ( "%s %s", lat, lon );
859 s->has_oldcoord = TRUE;
862 vik_statusbar_set_message ( s->vw->viking_vs, 3, temp );
868 vik_viewport_set_center_screen ( s->vvp, (gint) event->x, (gint) event->y );
869 draw_update ( s->vw );
871 return VIK_LAYER_TOOL_ACK;
874 static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, ruler_tool_state_t *s)
876 VikViewport *vvp = s->vvp;
877 VikWindow *vw = s->vw;
883 if ( s->has_oldcoord ) {
884 int oldx, oldy, w1, h1, w2, h2;
885 static GdkPixmap *buf = NULL;
886 gchar *lat=NULL, *lon=NULL;
887 w1 = vik_viewport_get_width(vvp);
888 h1 = vik_viewport_get_height(vvp);
890 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
892 gdk_drawable_get_size(buf, &w2, &h2);
893 if (w1 != w2 || h1 != h2) {
894 g_object_unref ( G_OBJECT ( buf ) );
895 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
898 vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
899 vik_coord_to_latlon ( &coord, &ll );
900 vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
902 gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc,
903 vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
904 draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
906 static gpointer pass_along[3];
907 pass_along[0] = GTK_WIDGET(vvp)->window;
908 pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
910 g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
911 draw_buf_done = FALSE;
913 a_coords_latlon_to_string(&ll, &lat, &lon);
914 vik_units_distance_t dist_units = a_vik_get_units_distance ();
915 switch (dist_units) {
916 case VIK_UNITS_DISTANCE_KILOMETRES:
917 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
919 case VIK_UNITS_DISTANCE_MILES:
920 temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) )* 0.000621371192);
923 temp = g_strdup_printf ("Just to keep the compiler happy");
924 g_critical("Houston, we've had a problem. distance=%d", dist_units);
926 vik_statusbar_set_message ( vw->viking_vs, 3, temp );
929 return VIK_LAYER_TOOL_ACK;
932 static VikLayerToolFuncStatus ruler_release (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
934 return VIK_LAYER_TOOL_ACK;
937 static void ruler_deactivate (VikLayer *vl, ruler_tool_state_t *s)
939 draw_update ( s->vw );
942 static VikToolInterface ruler_tool =
944 (VikToolConstructorFunc) ruler_create,
945 (VikToolDestructorFunc) ruler_destroy,
946 (VikToolActivationFunc) NULL,
947 (VikToolActivationFunc) ruler_deactivate,
948 (VikToolMouseFunc) ruler_click,
949 (VikToolMouseMoveFunc) ruler_move,
950 (VikToolMouseFunc) ruler_release,
952 GDK_CURSOR_IS_PIXMAP,
953 &cursor_ruler_pixbuf };
954 /*** end ruler code ********************************************************/
958 /********************************************************************************
960 ********************************************************************************/
961 static gpointer zoomtool_create (VikWindow *vw, VikViewport *vvp)
966 static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
969 vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
970 if ( event->button == 1 )
971 vik_viewport_zoom_in (vw->viking_vvp);
972 else if ( event->button == 3 )
973 vik_viewport_zoom_out (vw->viking_vvp);
975 return VIK_LAYER_TOOL_ACK;
978 static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event, VikViewport *vvp)
980 return VIK_LAYER_TOOL_ACK;
983 static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
985 return VIK_LAYER_TOOL_ACK;
988 static VikToolInterface zoom_tool =
990 (VikToolConstructorFunc) zoomtool_create,
991 (VikToolDestructorFunc) NULL,
992 (VikToolActivationFunc) NULL,
993 (VikToolActivationFunc) NULL,
994 (VikToolMouseFunc) zoomtool_click,
995 (VikToolMouseMoveFunc) zoomtool_move,
996 (VikToolMouseFunc) zoomtool_release,
998 GDK_CURSOR_IS_PIXMAP,
999 &cursor_zoom_pixbuf };
1000 /*** end zoom code ********************************************************/
1002 /********************************************************************************
1004 ********************************************************************************/
1005 static gpointer pantool_create (VikWindow *vw, VikViewport *vvp)
1010 static VikLayerToolFuncStatus pantool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
1012 vw->modified = TRUE;
1013 if ( event->button == 1 )
1014 vik_window_pan_click ( vw, event );
1016 return VIK_LAYER_TOOL_ACK;
1019 static VikLayerToolFuncStatus pantool_move (VikLayer *vl, GdkEventMotion *event, VikWindow *vw)
1021 vik_window_pan_move ( vw, event );
1022 return VIK_LAYER_TOOL_ACK;
1025 static VikLayerToolFuncStatus pantool_release (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
1027 if ( event->button == 1 )
1028 vik_window_pan_release ( vw, event );
1029 return VIK_LAYER_TOOL_ACK;
1032 static VikToolInterface pan_tool =
1034 (VikToolConstructorFunc) pantool_create,
1035 (VikToolDestructorFunc) NULL,
1036 (VikToolActivationFunc) NULL,
1037 (VikToolActivationFunc) NULL,
1038 (VikToolMouseFunc) pantool_click,
1039 (VikToolMouseMoveFunc) pantool_move,
1040 (VikToolMouseFunc) pantool_release,
1043 /*** end pan code ********************************************************/
1045 static void draw_pan_cb ( GtkAction *a, VikWindow *vw )
1047 if (!strcmp(gtk_action_get_name(a), "PanNorth")) {
1048 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, 0 );
1049 } else if (!strcmp(gtk_action_get_name(a), "PanEast")) {
1050 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp), vik_viewport_get_height(vw->viking_vvp)/2 );
1051 } else if (!strcmp(gtk_action_get_name(a), "PanSouth")) {
1052 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp) );
1053 } else if (!strcmp(gtk_action_get_name(a), "PanWest")) {
1054 vik_viewport_set_center_screen ( vw->viking_vvp, 0, vik_viewport_get_height(vw->viking_vvp)/2 );
1059 static void full_screen_cb ( GtkAction *a, VikWindow *vw )
1061 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/FullScreen" );
1062 g_assert(check_box);
1063 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1065 gtk_window_fullscreen ( GTK_WINDOW(vw) );
1067 gtk_window_unfullscreen ( GTK_WINDOW(vw) );
1070 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw )
1074 if (!strcmp(gtk_action_get_name(a), "ZoomIn")) {
1077 else if (!strcmp(gtk_action_get_name(a), "ZoomOut")) {
1080 else if (!strcmp(gtk_action_get_name(a), "Zoom0.25")) {
1083 else if (!strcmp(gtk_action_get_name(a), "Zoom0.5")) {
1087 gchar *s = (gchar *)gtk_action_get_name(a);
1093 case -3: vik_viewport_zoom_in ( vw->viking_vvp ); break;
1094 case -4: vik_viewport_zoom_out ( vw->viking_vvp ); break;
1095 case -1: vik_viewport_set_zoom ( vw->viking_vvp, 0.5 ); break;
1096 case -2: vik_viewport_set_zoom ( vw->viking_vvp, 0.25 ); break;
1097 default: vik_viewport_set_zoom ( vw->viking_vvp, what );
1102 void draw_goto_cb ( GtkAction *a, VikWindow *vw )
1104 VikCoord new_center;
1106 if (!strcmp(gtk_action_get_name(a), "GotoLL")) {
1107 struct LatLon ll, llold;
1108 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &llold );
1109 if ( a_dialog_goto_latlon ( GTK_WINDOW(vw), &ll, &llold ) )
1110 vik_coord_load_from_latlon ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &ll );
1114 else if (!strcmp(gtk_action_get_name(a), "GotoUTM")) {
1115 struct UTM utm, utmold;
1116 vik_coord_to_utm ( vik_viewport_get_center ( vw->viking_vvp ), &utmold );
1117 if ( a_dialog_goto_utm ( GTK_WINDOW(vw), &utm, &utmold ) )
1118 vik_coord_load_from_utm ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &utm );
1123 g_critical("Houston, we've had a problem.");
1127 vik_viewport_set_center_coord ( vw->viking_vvp, &new_center );
1131 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw )
1134 for ( type = 0; type < VIK_LAYER_NUM_TYPES; type++ ) {
1135 if (!strcmp(vik_layer_get_interface(type)->name, gtk_action_get_name(a))) {
1136 if ( vik_layers_panel_new_layer ( vw->viking_vlp, type ) ) {
1138 vw->modified = TRUE;
1144 static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw )
1146 a_clipboard_copy_selected ( vw->viking_vlp );
1149 static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw )
1151 a_clipboard_copy_selected ( vw->viking_vlp );
1152 menu_delete_layer_cb ( a, vw );
1155 static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw )
1157 if ( a_clipboard_paste ( vw->viking_vlp ) )
1160 vw->modified = TRUE;
1164 static void menu_properties_cb ( GtkAction *a, VikWindow *vw )
1166 if ( ! vik_layers_panel_properties ( vw->viking_vlp ) )
1167 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to show its properties.") );
1170 static void help_help_cb ( GtkAction *a, VikWindow *vw )
1172 #if GTK_CHECK_VERSION (2, 14, 0)
1174 uri = g_strdup_printf("ghelp:%s", PACKAGE);
1175 gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, NULL);
1180 static void help_about_cb ( GtkAction *a, VikWindow *vw )
1182 a_dialog_about(GTK_WINDOW(vw));
1185 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
1187 if ( vik_layers_panel_get_selected ( vw->viking_vlp ) )
1189 vik_layers_panel_delete_selected ( vw->viking_vlp );
1190 vw->modified = TRUE;
1193 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to delete.") );
1196 static void view_side_panel_cb ( GtkAction *a, VikWindow *vw )
1198 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ViewSidePanel" );
1199 g_assert(check_box);
1200 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1202 gtk_widget_show(GTK_WIDGET(vw->viking_vlp));
1204 gtk_widget_hide(GTK_WIDGET(vw->viking_vlp));
1207 /***************************************
1208 ** tool management routines
1210 ***************************************/
1212 static toolbox_tools_t* toolbox_create(VikWindow *vw)
1214 toolbox_tools_t *vt = g_new(toolbox_tools_t, 1);
1217 vt->active_tool = -1;
1219 if (!vw->viking_vvp) {
1220 g_critical("no viewport found.");
1226 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type )
1228 vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1);
1229 vt->tools[vt->n_tools].ti = *vti;
1230 vt->tools[vt->n_tools].layer_type = layer_type;
1232 vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp);
1235 vt->tools[vt->n_tools].state = NULL;
1240 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name)
1243 for (i=0; i<vt->n_tools; i++) {
1244 if (!strcmp(tool_name, vt->tools[i].ti.name)) {
1251 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name)
1253 int tool = toolbox_get_tool(vt, tool_name);
1254 toolbox_tool_t *t = &vt->tools[tool];
1255 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1257 if (tool == vt->n_tools) {
1258 g_critical("trying to activate a non-existent tool...");
1261 /* is the tool already active? */
1262 if (vt->active_tool == tool) {
1266 if (vt->active_tool != -1) {
1267 if (vt->tools[vt->active_tool].ti.deactivate) {
1268 vt->tools[vt->active_tool].ti.deactivate(NULL, vt->tools[vt->active_tool].state);
1271 if (t->ti.activate) {
1272 t->ti.activate(vl, t->state);
1274 vt->active_tool = tool;
1277 static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name)
1279 int tool = toolbox_get_tool(vt, tool_name);
1280 toolbox_tool_t *t = &vt->tools[tool];
1281 if (t->ti.cursor == NULL) {
1282 if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) {
1283 GError *cursor_load_err = NULL;
1284 GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err);
1285 /* TODO: settable offeset */
1286 t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
1287 g_object_unref ( G_OBJECT(cursor_pixbuf) );
1289 t->ti.cursor = gdk_cursor_new ( t->ti.cursor_type );
1292 return t->ti.cursor;
1295 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
1297 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1298 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) {
1299 gint ltype = vt->tools[vt->active_tool].layer_type;
1300 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1301 vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state);
1305 static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event)
1307 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1308 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) {
1309 gint ltype = vt->tools[vt->active_tool].layer_type;
1310 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1311 if ( VIK_LAYER_TOOL_ACK_GRAB_FOCUS == vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state) )
1312 gtk_widget_grab_focus ( GTK_WIDGET(vt->vw->viking_vvp) );
1316 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event)
1318 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1319 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release ) {
1320 gint ltype = vt->tools[vt->active_tool].layer_type;
1321 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1322 vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state);
1325 /** End tool management ************************************/
1327 void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id )
1329 gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].name ) );
1332 /* this function gets called whenever a toolbar tool is clicked */
1333 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
1335 /* White Magic, my friends ... White Magic... */
1336 int layer_id, tool_id;
1337 const GdkCursor *cursor = NULL;
1339 toolbox_activate(vw->vt, gtk_action_get_name(a));
1341 cursor = toolbox_get_cursor(vw->vt, gtk_action_get_name(a));
1342 /* We set cursor, even if it is NULL: it resets to default */
1343 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, (GdkCursor *)cursor );
1345 if (!strcmp(gtk_action_get_name(a), "Pan")) {
1346 vw->current_tool = TOOL_PAN;
1348 else if (!strcmp(gtk_action_get_name(a), "Zoom")) {
1349 vw->current_tool = TOOL_ZOOM;
1351 else if (!strcmp(gtk_action_get_name(a), "Ruler")) {
1352 vw->current_tool = TOOL_RULER;
1355 /* TODO: only enable tools from active layer */
1356 for (layer_id=0; layer_id<VIK_LAYER_NUM_TYPES; layer_id++) {
1357 for ( tool_id = 0; tool_id < vik_layer_get_interface(layer_id)->tools_count; tool_id++ ) {
1358 if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].name, gtk_action_get_name(a))) {
1359 vw->current_tool = TOOL_LAYER;
1360 vw->tool_layer_id = layer_id;
1361 vw->tool_tool_id = tool_id;
1369 static void window_set_filename ( VikWindow *vw, const gchar *filename )
1374 g_free ( vw->filename );
1375 if ( filename == NULL )
1377 vw->filename = NULL;
1378 file = _("Untitled");
1382 vw->filename = g_strdup(filename);
1383 file = a_file_basename ( filename );
1385 title = g_strdup_printf( "%s - Viking", file );
1386 gtk_window_set_title ( GTK_WINDOW(vw), title );
1390 GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode )
1392 GtkWidget *mode_button;
1395 #ifdef VIK_CONFIG_EXPEDIA
1396 case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
1398 case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break;
1399 default: buttonname = "/ui/MainMenu/View/ModeUTM";
1401 mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
1402 g_assert ( mode_button );
1406 static void on_activate_recent_item (GtkRecentChooser *chooser,
1411 filename = gtk_recent_chooser_get_current_uri (chooser);
1412 if (filename != NULL)
1414 GFile *file = g_file_new_for_uri ( filename );
1415 gchar *path = g_file_get_path ( file );
1416 g_object_unref ( file );
1417 if ( self->filename )
1419 gchar *filenames[] = { path, NULL };
1420 g_signal_emit ( G_OBJECT(self), window_signals[VW_OPENWINDOW_SIGNAL], 0, filenames );
1423 vik_window_open_file ( self, path, TRUE );
1430 static void setup_recent_files (VikWindow *self)
1432 GtkRecentManager *manager;
1433 GtkRecentFilter *filter;
1434 GtkWidget *menu, *menu_item;
1436 filter = gtk_recent_filter_new ();
1437 /* gtk_recent_filter_add_application (filter, g_get_application_name()); */
1438 gtk_recent_filter_add_group(filter, "viking");
1440 manager = gtk_recent_manager_get_default ();
1441 menu = gtk_recent_chooser_menu_new_for_manager (manager);
1442 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu), GTK_RECENT_SORT_MRU);
1443 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
1445 menu_item = gtk_ui_manager_get_widget (self->uim, "/ui/MainMenu/File/OpenRecentFile");
1446 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu);
1448 g_signal_connect (G_OBJECT (menu), "item-activated",
1449 G_CALLBACK (on_activate_recent_item), (gpointer) self);
1452 static void update_recently_used_document(const gchar *filename)
1454 /* Update Recently Used Document framework */
1455 GtkRecentManager *manager = gtk_recent_manager_get_default();
1456 GtkRecentData *recent_data = g_slice_new (GtkRecentData);
1457 gchar *groups[] = {"viking", NULL};
1458 GFile *file = g_file_new_for_commandline_arg(filename);
1459 gchar *uri = g_file_get_uri(file);
1460 gchar *basename = g_path_get_basename(filename);
1461 g_object_unref(file);
1464 recent_data->display_name = basename;
1465 recent_data->description = NULL;
1466 recent_data->mime_type = "text/x-gps-data";
1467 recent_data->app_name = (gchar *) g_get_application_name ();
1468 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL);
1469 recent_data->groups = groups;
1470 recent_data->is_private = FALSE;
1471 if (!gtk_recent_manager_add_full (manager, uri, recent_data))
1473 g_warning (_("Unable to add '%s' to the list of recently used documents"), uri);
1478 g_free (recent_data->app_exec);
1479 g_slice_free (GtkRecentData, recent_data);
1482 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename )
1484 switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) )
1487 a_dialog_error_msg ( GTK_WINDOW(vw), _("The file you requested could not be opened.") );
1491 GtkWidget *mode_button;
1493 if ( change_filename )
1494 window_set_filename ( vw, filename );
1495 mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) );
1496 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. */
1497 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE );
1498 vw->only_updating_coord_mode_ui = FALSE;
1500 vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) );
1502 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
1503 g_assert ( mode_button );
1504 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_scale(vw->viking_vvp) );
1506 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
1507 g_assert ( mode_button );
1508 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) );
1511 update_recently_used_document(filename);
1515 static void load_file ( GtkAction *a, VikWindow *vw )
1517 GSList *files = NULL;
1518 GSList *cur_file = NULL;
1520 if (!strcmp(gtk_action_get_name(a), "Open")) {
1523 else if (!strcmp(gtk_action_get_name(a), "Append")) {
1527 g_critical("Houston, we've had a problem.");
1531 if ( ! vw->open_dia )
1533 vw->open_dia = gtk_file_chooser_dialog_new (_("Please select a GPS data file to open. "),
1535 GTK_FILE_CHOOSER_ACTION_OPEN,
1536 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1537 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1539 gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(vw->open_dia), TRUE );
1540 gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) );
1541 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE );
1543 if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_ACCEPT )
1545 gtk_widget_hide ( vw->open_dia );
1546 #ifdef VIKING_PROMPT_IF_MODIFIED
1547 if ( (vw->modified || vw->filename) && newwindow )
1549 if ( vw->filename && newwindow )
1551 g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) ) );
1553 files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) );
1554 gboolean change_fn = newwindow && (g_slist_length(files)==1); /* only change fn if one file */
1557 while ( cur_file ) {
1558 gchar *file_name = cur_file->data;
1559 vik_window_open_file ( vw, file_name, change_fn );
1561 cur_file = g_slist_next (cur_file);
1563 g_slist_free (files);
1567 gtk_widget_hide ( vw->open_dia );
1570 static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
1572 gboolean rv = FALSE;
1574 if ( ! vw->save_dia )
1576 vw->save_dia = gtk_file_chooser_dialog_new (_("Save as Viking File."),
1578 GTK_FILE_CHOOSER_ACTION_SAVE,
1579 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1580 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1582 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) );
1583 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
1586 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_ACCEPT )
1588 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_dia) );
1589 if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == FALSE || a_dialog_overwrite ( GTK_WINDOW(vw->save_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) )
1591 window_set_filename ( vw, fn );
1592 rv = window_save ( vw );
1593 vw->modified = FALSE;
1597 gtk_widget_hide ( vw->save_dia );
1601 static gboolean window_save ( VikWindow *vw )
1603 if ( a_file_save ( vik_layers_panel_get_top_layer ( vw->viking_vlp ), vw->viking_vvp, vw->filename ) )
1605 update_recently_used_document ( vw->filename );
1610 a_dialog_error_msg ( GTK_WINDOW(vw), _("The filename you requested could not be opened for writing.") );
1615 static gboolean save_file ( GtkAction *a, VikWindow *vw )
1617 if ( ! vw->filename )
1618 return save_file_as ( NULL, vw );
1621 vw->modified = FALSE;
1622 return window_save ( vw );
1626 static void acquire_from_gps ( GtkAction *a, VikWindow *vw )
1628 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface );
1631 static void acquire_from_google ( GtkAction *a, VikWindow *vw )
1633 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
1636 #ifdef VIK_CONFIG_GEOCACHES
1637 static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
1639 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface );
1643 static void goto_default_location( GtkAction *a, VikWindow *vw)
1646 ll.lat = a_vik_get_default_lat();
1647 ll.lon = a_vik_get_default_long();
1648 vik_viewport_set_center_latlon(vw->viking_vvp, &ll);
1649 vik_layers_panel_emit_update(vw->viking_vlp);
1653 static void goto_address( GtkAction *a, VikWindow *vw)
1655 a_vik_goto(vw, vw->viking_vlp, vw->viking_vvp);
1658 static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw )
1663 static void preferences_cb ( GtkAction *a, VikWindow *vw )
1665 gboolean wp_icon_size = a_vik_get_use_large_waypoint_icons();
1667 a_preferences_show_window ( GTK_WINDOW(vw) );
1669 // Delete icon indexing 'cache' and so automatically regenerates with the new setting when changed
1670 if (wp_icon_size != a_vik_get_use_large_waypoint_icons())
1671 clear_garmin_icon_syms ();
1676 static void default_location_cb ( GtkAction *a, VikWindow *vw )
1678 /* Simplistic repeat of preference setting
1679 Only the name & type are important for setting the preference via this 'external' way */
1680 VikLayerParam pref_lat[] = {
1681 { VIKING_PREFERENCES_NAMESPACE "default_latitude",
1682 VIK_LAYER_PARAM_DOUBLE,
1685 VIK_LAYER_WIDGET_SPINBUTTON,
1689 VikLayerParam pref_lon[] = {
1690 { VIKING_PREFERENCES_NAMESPACE "default_longitude",
1691 VIK_LAYER_PARAM_DOUBLE,
1694 VIK_LAYER_WIDGET_SPINBUTTON,
1699 /* Get current center */
1701 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &ll );
1703 /* Apply to preferences */
1704 VikLayerParamData vlp_data;
1705 vlp_data.d = ll.lat;
1706 a_preferences_run_setparam (vlp_data, pref_lat);
1707 vlp_data.d = ll.lon;
1708 a_preferences_run_setparam (vlp_data, pref_lon);
1709 /* Remember to save */
1710 a_preferences_save_to_file();
1713 static void clear_cb ( GtkAction *a, VikWindow *vw )
1715 vik_layers_panel_clear ( vw->viking_vlp );
1716 window_set_filename ( vw, NULL );
1720 static void window_close ( GtkAction *a, VikWindow *vw )
1722 if ( ! delete_event ( vw ) )
1723 gtk_widget_destroy ( GTK_WIDGET(vw) );
1726 static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw )
1728 if (save_file( NULL, vw)) {
1729 window_close( NULL, vw);
1736 static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
1738 gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1739 if ( a_dialog_custom_zoom ( GTK_WINDOW(vw), &xmpp, &ympp ) )
1741 vik_viewport_set_xmpp ( vw->viking_vvp, xmpp );
1742 vik_viewport_set_ympp ( vw->viking_vvp, ympp );
1747 static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h, gdouble zoom, gboolean save_as_png )
1749 /* more efficient way: stuff draws directly to pixbuf (fork viewport) */
1750 GdkPixbuf *pixbuf_to_save;
1751 gdouble old_xmpp, old_ympp;
1752 GError *error = NULL;
1754 /* backup old zoom & set new */
1755 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1756 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1757 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1759 /* reset width and height: */
1760 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1762 /* draw all layers */
1765 /* save buffer as file. */
1766 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);
1767 gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL );
1770 g_warning("Unable to write to file %s: %s", fn, error->message );
1771 g_error_free (error);
1773 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1775 /* pretend like nothing happened ;) */
1776 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1777 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1778 vik_viewport_configure ( vw->viking_vvp );
1782 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 )
1784 gulong size = sizeof(gchar) * (strlen(fn) + 15);
1785 gchar *name_of_file = g_malloc ( size );
1787 struct UTM utm_orig, utm;
1789 /* *** copied from above *** */
1790 GdkPixbuf *pixbuf_to_save;
1791 gdouble old_xmpp, old_ympp;
1792 GError *error = NULL;
1794 /* backup old zoom & set new */
1795 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1796 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1797 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1799 /* reset width and height: do this only once for all images (same size) */
1800 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1801 /* *** end copy from above *** */
1803 g_assert ( vik_viewport_get_coord_mode ( vw->viking_vvp ) == VIK_COORD_UTM );
1807 utm_orig = *((const struct UTM *)vik_viewport_get_center ( vw->viking_vvp ));
1809 for ( y = 1; y <= tiles_h; y++ )
1811 for ( x = 1; x <= tiles_w; x++ )
1813 g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, G_DIR_SEPARATOR, y, x, save_as_png ? "png" : "jpg" );
1815 if ( tiles_w & 0x1 )
1816 utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom);
1818 utm.easting += ((gdouble)x - (((gdouble)tiles_w)+1)/2) * (w*zoom);
1819 if ( tiles_h & 0x1 ) /* odd */
1820 utm.northing -= ((gdouble)y - ceil(((gdouble)tiles_h)/2)) * (h*zoom);
1822 utm.northing -= ((gdouble)y - (((gdouble)tiles_h)+1)/2) * (h*zoom);
1824 /* move to correct place. */
1825 vik_viewport_set_center_utm ( vw->viking_vvp, &utm );
1829 /* save buffer as file. */
1830 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);
1831 gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL );
1834 g_warning("Unable to write to file %s: %s", name_of_file, error->message );
1835 g_error_free (error);
1838 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1842 vik_viewport_set_center_utm ( vw->viking_vvp, &utm_orig );
1843 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1844 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1845 vik_viewport_configure ( vw->viking_vvp );
1848 g_free ( name_of_file );
1851 static void draw_to_image_file_current_window_cb(GtkWidget* widget,GdkEventButton *event,gpointer *pass_along)
1853 VikWindow *vw = VIK_WINDOW(pass_along[0]);
1854 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1855 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1856 gdouble width_min, width_max, height_min, height_max;
1859 gtk_spin_button_get_range ( width_spin, &width_min, &width_max );
1860 gtk_spin_button_get_range ( height_spin, &height_min, &height_max );
1862 /* TODO: support for xzoom and yzoom values */
1863 width = vik_viewport_get_width ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1864 height = vik_viewport_get_height ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1866 if ( width > width_max || width < width_min || height > height_max || height < height_min )
1867 a_dialog_info_msg ( GTK_WINDOW(vw), _("Viewable region outside allowable pixel size bounds for image. Clipping width/height values.") );
1869 gtk_spin_button_set_value ( width_spin, width );
1870 gtk_spin_button_set_value ( height_spin, height );
1873 static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
1875 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1876 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1879 w = gtk_spin_button_get_value(width_spin) * gtk_spin_button_get_value(zoom_spin);
1880 h = gtk_spin_button_get_value(height_spin) * gtk_spin_button_get_value(zoom_spin);
1881 if (pass_along[4]) /* save many images; find TOTAL area covered */
1883 w *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[4]));
1884 h *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[5]));
1886 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1887 switch (dist_units) {
1888 case VIK_UNITS_DISTANCE_KILOMETRES:
1889 label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. km)"), (glong)w, (glong)h, (w*h/1000000));
1891 case VIK_UNITS_DISTANCE_MILES:
1892 label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. miles)"), (glong)w, (glong)h, (w*h/2589988.11));
1895 label_text = g_strdup_printf ("Just to keep the compiler happy");
1896 g_critical("Houston, we've had a problem. distance=%d", dist_units);
1899 gtk_label_set_text(GTK_LABEL(pass_along[6]), label_text);
1900 g_free ( label_text );
1903 static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_image_only )
1905 /* todo: default for answers inside VikWindow or static (thruout instance) */
1906 GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Save to Image File"), GTK_WINDOW(vw),
1907 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1909 GTK_RESPONSE_REJECT,
1911 GTK_RESPONSE_ACCEPT,
1913 GtkWidget *width_label, *width_spin, *height_label, *height_spin;
1914 GtkWidget *png_radio, *jpeg_radio;
1915 GtkWidget *current_window_button;
1916 gpointer current_window_pass_along[7];
1917 GtkWidget *zoom_label, *zoom_spin;
1918 GtkWidget *total_size_label;
1920 /* only used if (!one_image_only) */
1921 GtkWidget *tiles_width_spin = NULL, *tiles_height_spin = NULL;
1924 width_label = gtk_label_new ( _("Width (pixels):") );
1925 width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_width, 10, 5000, 10, 100, 0 )), 10, 0 );
1926 height_label = gtk_label_new ( _("Height (pixels):") );
1927 height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_height, 10, 5000, 10, 100, 0 )), 10, 0 );
1929 zoom_label = gtk_label_new ( _("Zoom (meters per pixel):") );
1930 /* TODO: separate xzoom and yzoom factors */
1931 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);
1933 total_size_label = gtk_label_new ( NULL );
1935 current_window_button = gtk_button_new_with_label ( _("Area in current viewable window") );
1936 current_window_pass_along [0] = vw;
1937 current_window_pass_along [1] = width_spin;
1938 current_window_pass_along [2] = height_spin;
1939 current_window_pass_along [3] = zoom_spin;
1940 current_window_pass_along [4] = NULL; /* used for one_image_only != 1 */
1941 current_window_pass_along [5] = NULL;
1942 current_window_pass_along [6] = total_size_label;
1943 g_signal_connect ( G_OBJECT(current_window_button), "button_press_event", G_CALLBACK(draw_to_image_file_current_window_cb), current_window_pass_along );
1945 png_radio = gtk_radio_button_new_with_label ( NULL, _("Save as PNG") );
1946 jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), _("Save as JPEG") );
1948 if ( ! vw->draw_image_save_as_png )
1949 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE );
1951 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_label, FALSE, FALSE, 0);
1952 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_spin, FALSE, FALSE, 0);
1953 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_label, FALSE, FALSE, 0);
1954 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_spin, FALSE, FALSE, 0);
1955 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), current_window_button, FALSE, FALSE, 0);
1956 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), png_radio, FALSE, FALSE, 0);
1957 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), jpeg_radio, FALSE, FALSE, 0);
1958 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_label, FALSE, FALSE, 0);
1959 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_spin, FALSE, FALSE, 0);
1961 if ( ! one_image_only )
1963 GtkWidget *tiles_width_label, *tiles_height_label;
1966 tiles_width_label = gtk_label_new ( _("East-west image tiles:") );
1967 tiles_width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1968 tiles_height_label = gtk_label_new ( _("North-south image tiles:") );
1969 tiles_height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1970 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_label, FALSE, FALSE, 0);
1971 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_spin, FALSE, FALSE, 0);
1972 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_label, FALSE, FALSE, 0);
1973 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_spin, FALSE, FALSE, 0);
1975 current_window_pass_along [4] = tiles_width_spin;
1976 current_window_pass_along [5] = tiles_height_spin;
1977 g_signal_connect ( G_OBJECT(tiles_width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1978 g_signal_connect ( G_OBJECT(tiles_height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1980 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), total_size_label, FALSE, FALSE, 0);
1981 g_signal_connect ( G_OBJECT(width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1982 g_signal_connect ( G_OBJECT(height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1983 g_signal_connect ( G_OBJECT(zoom_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1985 draw_to_image_file_total_area_cb ( NULL, current_window_pass_along ); /* set correct size info now */
1987 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
1989 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
1991 gtk_widget_hide ( GTK_WIDGET(dialog) );
1992 if ( one_image_only )
1993 save_image_file ( vw, fn,
1994 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1995 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1996 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1997 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ) );
1999 if ( vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM )
2000 save_image_dir ( vw, fn,
2001 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
2002 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
2003 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
2004 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ),
2005 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_width_spin) ),
2006 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_height_spin) ) );
2008 a_dialog_error_msg ( GTK_WINDOW(vw), _("You must be in UTM mode to use this feature") );
2011 gtk_widget_destroy ( GTK_WIDGET(dialog) );
2015 static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw )
2018 if (!vw->save_img_dia) {
2019 vw->save_img_dia = gtk_file_chooser_dialog_new (_("Save Image"),
2021 GTK_FILE_CHOOSER_ACTION_SAVE,
2022 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2023 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
2025 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) );
2026 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE );
2029 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_ACCEPT )
2031 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dia) );
2032 if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == FALSE || a_dialog_overwrite ( GTK_WINDOW(vw->save_img_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) )
2034 draw_to_image_file ( vw, fn, TRUE );
2038 gtk_widget_hide ( vw->save_img_dia );
2041 static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw )
2045 if (!vw->save_img_dir_dia) {
2046 vw->save_img_dir_dia = gtk_file_chooser_dialog_new (_("Choose a directory to hold images"),
2048 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
2049 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2050 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2052 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) );
2053 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE );
2056 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_ACCEPT )
2058 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dir_dia) );
2061 draw_to_image_file ( vw, fn, FALSE );
2067 gtk_widget_hide ( vw->save_img_dir_dia );
2070 #if GTK_CHECK_VERSION(2,10,0)
2071 static void print_cb ( GtkAction *a, VikWindow *vw )
2073 a_print(vw, vw->viking_vvp);
2077 /* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */
2078 static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWindow *vw )
2080 VikViewportDrawMode drawmode;
2081 if (!strcmp(gtk_action_get_name(a), "ModeUTM")) {
2082 drawmode = VIK_VIEWPORT_DRAWMODE_UTM;
2084 else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) {
2085 drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA;
2087 else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) {
2088 drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
2091 g_critical("Houston, we've had a problem.");
2095 if ( !vw->only_updating_coord_mode_ui )
2097 VikViewportDrawMode olddrawmode = vik_viewport_get_drawmode ( vw->viking_vvp );
2098 if ( olddrawmode != drawmode )
2100 /* this takes care of coord mode too */
2101 vik_viewport_set_drawmode ( vw->viking_vvp, drawmode );
2102 if ( drawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
2103 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_UTM );
2104 } else if ( olddrawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
2105 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_LATLON );
2112 static void set_draw_scale ( GtkAction *a, VikWindow *vw )
2114 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
2115 g_assert(check_box);
2116 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
2117 vik_viewport_set_draw_scale ( vw->viking_vvp, state );
2121 static void set_draw_centermark ( GtkAction *a, VikWindow *vw )
2123 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
2124 g_assert(check_box);
2125 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
2126 vik_viewport_set_draw_centermark ( vw->viking_vvp, state );
2130 static void set_bg_color ( GtkAction *a, VikWindow *vw )
2132 GtkWidget *colorsd = gtk_color_selection_dialog_new ( _("Choose a background color") );
2133 GdkColor *color = vik_viewport_get_background_gdkcolor ( vw->viking_vvp );
2134 gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2135 gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2136 if ( gtk_dialog_run ( GTK_DIALOG(colorsd) ) == GTK_RESPONSE_OK )
2138 gtk_color_selection_get_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2139 vik_viewport_set_background_gdkcolor ( vw->viking_vvp, color );
2143 gtk_widget_destroy ( colorsd );
2148 /***********************************************************************************************
2150 ***********************************************************************************************/
2152 static GtkActionEntry entries[] = {
2153 { "File", NULL, N_("_File"), 0, 0, 0 },
2154 { "Edit", NULL, N_("_Edit"), 0, 0, 0 },
2155 { "View", NULL, N_("_View"), 0, 0, 0 },
2156 { "SetZoom", NULL, N_("_Zoom"), 0, 0, 0 },
2157 { "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
2158 { "Layers", NULL, N_("_Layers"), 0, 0, 0 },
2159 { "Tools", NULL, N_("_Tools"), 0, 0, 0 },
2160 { "Exttools", NULL, N_("_Webtools"), 0, 0, 0 },
2161 { "Help", NULL, N_("_Help"), 0, 0, 0 },
2163 { "New", GTK_STOCK_NEW, N_("_New"), "<control>N", N_("New file"), (GCallback)newwindow_cb },
2164 { "Open", GTK_STOCK_OPEN, N_("_Open..."), "<control>O", N_("Open a file"), (GCallback)load_file },
2165 { "OpenRecentFile", NULL, N_("Open _Recent File"), NULL, NULL, (GCallback)NULL },
2166 { "Append", GTK_STOCK_ADD, N_("Append _File..."), NULL, N_("Append data from a different file"), (GCallback)load_file },
2167 { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 },
2168 { "AcquireGPS", NULL, N_("From _GPS..."), NULL, N_("Transfer data from a GPS device"), (GCallback)acquire_from_gps },
2169 { "AcquireGoogle", NULL, N_("Google _Directions..."), NULL, N_("Get driving directions from Google"), (GCallback)acquire_from_google },
2170 #ifdef VIK_CONFIG_GEOCACHES
2171 { "AcquireGC", NULL, N_("Geo_caches..."), NULL, N_("Get Geocaches from geocaching.com"), (GCallback)acquire_from_gc },
2173 { "Save", GTK_STOCK_SAVE, N_("_Save"), "<control>S", N_("Save the file"), (GCallback)save_file },
2174 { "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), NULL, N_("Save the file under different name"), (GCallback)save_file_as },
2175 { "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 },
2176 { "GenImgDir", GTK_STOCK_DND_MULTIPLE, N_("Generate _Directory of Images..."), NULL, N_("FIXME:IMGDIR"), (GCallback)draw_to_image_dir_cb },
2178 #if GTK_CHECK_VERSION(2,10,0)
2179 { "Print", GTK_STOCK_PRINT, N_("_Print..."), NULL, N_("Print maps"), (GCallback)print_cb },
2182 { "Exit", GTK_STOCK_QUIT, N_("E_xit"), "<control>W", N_("Exit the program"), (GCallback)window_close },
2183 { "SaveExit", GTK_STOCK_QUIT, N_("Save and Exit"), NULL, N_("Save and Exit the program"), (GCallback)save_file_and_exit },
2185 { "GotoDefaultLocation", GTK_STOCK_HOME, N_("Go to the _Default Location"), NULL, N_("Go to the default location"), (GCallback)goto_default_location },
2186 { "GotoSearch", GTK_STOCK_JUMP_TO, N_("Go to Location..."), NULL, N_("Go to address/place using text search"), (GCallback)goto_address },
2187 { "GotoLL", GTK_STOCK_JUMP_TO, N_("_Go to Lat/Lon..."), NULL, N_("Go to arbitrary lat/lon coordinate"), (GCallback)draw_goto_cb },
2188 { "GotoUTM", GTK_STOCK_JUMP_TO, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb },
2189 { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."), NULL, NULL, (GCallback)set_bg_color },
2190 { "ZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus", NULL, (GCallback)draw_zoom_cb },
2191 { "ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus", NULL, (GCallback)draw_zoom_cb },
2192 { "ZoomTo", GTK_STOCK_ZOOM_FIT, N_("Zoom _To..."), "<control>Z", NULL, (GCallback)zoom_to_cb },
2193 { "Zoom0.25", NULL, N_("0.25"), NULL, NULL, (GCallback)draw_zoom_cb },
2194 { "Zoom0.5", NULL, N_("0.5"), NULL, NULL, (GCallback)draw_zoom_cb },
2195 { "Zoom1", NULL, N_("1"), NULL, NULL, (GCallback)draw_zoom_cb },
2196 { "Zoom2", NULL, N_("2"), NULL, NULL, (GCallback)draw_zoom_cb },
2197 { "Zoom4", NULL, N_("4"), NULL, NULL, (GCallback)draw_zoom_cb },
2198 { "Zoom8", NULL, N_("8"), NULL, NULL, (GCallback)draw_zoom_cb },
2199 { "Zoom16", NULL, N_("16"), NULL, NULL, (GCallback)draw_zoom_cb },
2200 { "Zoom32", NULL, N_("32"), NULL, NULL, (GCallback)draw_zoom_cb },
2201 { "Zoom64", NULL, N_("64"), NULL, NULL, (GCallback)draw_zoom_cb },
2202 { "Zoom128", NULL, N_("128"), NULL, NULL, (GCallback)draw_zoom_cb },
2203 { "Zoom256", NULL, N_("256"), NULL, NULL, (GCallback)draw_zoom_cb },
2204 { "Zoom512", NULL, N_("512"), NULL, NULL, (GCallback)draw_zoom_cb },
2205 { "Zoom1024", NULL, N_("1024"), NULL, NULL, (GCallback)draw_zoom_cb },
2206 { "Zoom2048", NULL, N_("2048"), NULL, NULL, (GCallback)draw_zoom_cb },
2207 { "Zoom4096", NULL, N_("4096"), NULL, NULL, (GCallback)draw_zoom_cb },
2208 { "Zoom8192", NULL, N_("8192"), NULL, NULL, (GCallback)draw_zoom_cb },
2209 { "Zoom16384", NULL, N_("16384"), NULL, NULL, (GCallback)draw_zoom_cb },
2210 { "Zoom32768", NULL, N_("32768"), NULL, NULL, (GCallback)draw_zoom_cb },
2211 { "PanNorth", NULL, N_("Pan North"), "<control>Up", NULL, (GCallback)draw_pan_cb },
2212 { "PanEast", NULL, N_("Pan East"), "<control>Right", NULL, (GCallback)draw_pan_cb },
2213 { "PanSouth", NULL, N_("Pan South"), "<control>Down", NULL, (GCallback)draw_pan_cb },
2214 { "PanWest", NULL, N_("Pan West"), "<control>Left", NULL, (GCallback)draw_pan_cb },
2215 { "BGJobs", GTK_STOCK_EXECUTE, N_("Background _Jobs"), NULL, NULL, (GCallback)a_background_show_window },
2217 { "Cut", GTK_STOCK_CUT, N_("Cu_t"), NULL, NULL, (GCallback)menu_cut_layer_cb },
2218 { "Copy", GTK_STOCK_COPY, N_("_Copy"), NULL, NULL, (GCallback)menu_copy_layer_cb },
2219 { "Paste", GTK_STOCK_PASTE, N_("_Paste"), NULL, NULL, (GCallback)menu_paste_layer_cb },
2220 { "Delete", GTK_STOCK_DELETE, N_("_Delete"), NULL, NULL, (GCallback)menu_delete_layer_cb },
2221 { "DeleteAll", NULL, N_("Delete All"), NULL, NULL, (GCallback)clear_cb },
2222 { "MapCacheFlush",NULL, N_("_Flush Map Cache"), NULL, NULL, (GCallback)mapcache_flush_cb },
2223 { "SetDefaultLocation", GTK_STOCK_GO_FORWARD, N_("_Set the Default Location"), NULL, N_("Set the Default Location to the current position"),(GCallback)default_location_cb },
2224 { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences"), NULL, NULL, (GCallback)preferences_cb },
2225 { "Properties",GTK_STOCK_PROPERTIES, N_("_Properties"), NULL, NULL, (GCallback)menu_properties_cb },
2227 { "HelpEntry", GTK_STOCK_HELP, N_("_Help"), "F1", NULL, (GCallback)help_help_cb },
2228 { "About", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, (GCallback)help_about_cb },
2232 static GtkRadioActionEntry mode_entries[] = {
2233 { "ModeUTM", NULL, N_("_UTM Mode"), "<control>u", NULL, 0 },
2234 { "ModeExpedia", NULL, N_("_Expedia Mode"), "<control>e", NULL, 1 },
2235 { "ModeMercator", NULL, N_("_Mercator Mode"), "<control>g", NULL, 4 }
2238 static GtkRadioActionEntry tool_entries[] = {
2239 { "Pan", "vik-icon-pan", N_("_Pan"), "<control><shift>P", N_("Pan Tool"), 0 },
2240 { "Zoom", "vik-icon-zoom", N_("_Zoom"), "<control><shift>Z", N_("Zoom Tool"), 1 },
2241 { "Ruler", "vik-icon-ruler", N_("_Ruler"), "<control><shift>R", N_("Ruler Tool"), 2 }
2244 static GtkToggleActionEntry toggle_entries[] = {
2245 { "ShowScale", NULL, N_("_Show Scale"), "F5", N_("Show Scale"), (GCallback)set_draw_scale, TRUE },
2246 { "ShowCenterMark", NULL, N_("Show _Center Mark"), "F6", N_("Show Center Mark"), (GCallback)set_draw_centermark, TRUE },
2247 { "FullScreen", GTK_STOCK_FULLSCREEN, N_("_Full Screen"), "F11", N_("Activate full screen mode"), (GCallback)full_screen_cb, FALSE },
2248 { "ViewSidePanel", GTK_STOCK_INDEX, N_("Show Side Panel"), "F9", N_("Show Side Panel"), (GCallback)view_side_panel_cb, TRUE },
2251 #include "menu.xml.h"
2252 static void window_create_ui( VikWindow *window )
2255 GtkActionGroup *action_group;
2256 GtkAccelGroup *accel_group;
2259 GtkIconFactory *icon_factory;
2260 GtkIconSet *icon_set;
2261 GtkRadioActionEntry *tools = NULL, *radio;
2264 uim = gtk_ui_manager_new ();
2267 toolbox_add_tool(window->vt, &ruler_tool, TOOL_LAYER_TYPE_NONE);
2268 toolbox_add_tool(window->vt, &zoom_tool, TOOL_LAYER_TYPE_NONE);
2269 toolbox_add_tool(window->vt, &pan_tool, TOOL_LAYER_TYPE_NONE);
2272 if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) {
2273 g_error_free (error);
2277 action_group = gtk_action_group_new ("MenuActions");
2278 gtk_action_group_set_translation_domain(action_group, PACKAGE_NAME);
2279 gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
2280 gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
2281 gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window);
2283 icon_factory = gtk_icon_factory_new ();
2284 gtk_icon_factory_add_default (icon_factory);
2286 register_vik_icons(icon_factory);
2289 for (i=0; i<G_N_ELEMENTS(tool_entries); i++) {
2290 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2291 radio = &tools[ntools];
2293 *radio = tool_entries[i];
2294 radio->value = ntools;
2297 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2298 GtkActionEntry action;
2299 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Layers/",
2300 vik_layer_get_interface(i)->name,
2301 vik_layer_get_interface(i)->name,
2302 GTK_UI_MANAGER_MENUITEM, FALSE);
2304 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (vik_layer_get_interface(i)->icon, FALSE, NULL ));
2305 gtk_icon_factory_add (icon_factory, vik_layer_get_interface(i)->name, icon_set);
2306 gtk_icon_set_unref (icon_set);
2308 action.name = vik_layer_get_interface(i)->name;
2309 action.stock_id = vik_layer_get_interface(i)->name;
2310 action.label = g_strdup_printf( _("New %s Layer"), vik_layer_get_interface(i)->name);
2311 action.accelerator = NULL;
2312 action.tooltip = NULL;
2313 action.callback = (GCallback)menu_addlayer_cb;
2314 gtk_action_group_add_actions(action_group, &action, 1, window);
2316 if ( vik_layer_get_interface(i)->tools_count ) {
2317 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2318 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2321 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2322 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2323 radio = &tools[ntools];
2326 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools",
2327 _(vik_layer_get_interface(i)->tools[j].name),
2328 vik_layer_get_interface(i)->tools[j].name,
2329 GTK_UI_MANAGER_MENUITEM, FALSE);
2330 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems",
2331 _(vik_layer_get_interface(i)->tools[j].name),
2332 vik_layer_get_interface(i)->tools[j].name,
2333 GTK_UI_MANAGER_TOOLITEM, FALSE);
2335 toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i);
2337 radio->name = vik_layer_get_interface(i)->tools[j].name;
2338 radio->stock_id = vik_layer_get_interface(i)->tools[j].name,
2339 radio->label = _(vik_layer_get_interface(i)->tools[j].name);
2340 radio->accelerator = NULL;
2341 radio->tooltip = _(vik_layer_get_interface(i)->tools[j].name);
2342 radio->value = ntools;
2345 g_object_unref (icon_factory);
2347 gtk_action_group_add_radio_actions(action_group, tools, ntools, 0, (GCallback)menu_tool_cb, window);
2350 gtk_ui_manager_insert_action_group (uim, action_group, 0);
2352 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2353 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2354 GtkAction *action = gtk_action_group_get_action(action_group,
2355 vik_layer_get_interface(i)->tools[j].name);
2356 g_object_set(action, "sensitive", FALSE, NULL);
2359 window->action_group = action_group;
2361 accel_group = gtk_ui_manager_get_accel_group (uim);
2362 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
2363 gtk_ui_manager_ensure_update (uim);
2365 setup_recent_files(window);
2371 const GdkPixdata *data;
2374 { &begintr_18_pixbuf, "Begin Track" },
2375 { &iscissors_18_pixbuf, "Magic Scissors" },
2376 { &mover_22_pixbuf, "vik-icon-pan" },
2377 { &demdl_18_pixbuf, "DEM Download/Import" },
2378 { &showpic_18_pixbuf, "Show Picture" },
2379 { &addtr_18_pixbuf, "Create Track" },
2380 { &edtr_18_pixbuf, "Edit Trackpoint" },
2381 { &addwp_18_pixbuf, "Create Waypoint" },
2382 { &edwp_18_pixbuf, "Edit Waypoint" },
2383 { &zoom_18_pixbuf, "vik-icon-zoom" },
2384 { &ruler_18_pixbuf, "vik-icon-ruler" },
2385 { &geozoom_18_pixbuf, "Georef Zoom Tool" },
2386 { &geomove_18_pixbuf, "Georef Move Map" },
2387 { &mapdl_18_pixbuf, "Maps Download" },
2388 { &showpic_18_pixbuf, "Show Picture" },
2391 static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
2394 register_vik_icons (GtkIconFactory *icon_factory)
2396 GtkIconSet *icon_set;
2399 for (i = 0; i < n_stock_icons; i++) {
2400 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (
2401 stock_icons[i].data, FALSE, NULL ));
2402 gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set);
2403 gtk_icon_set_unref (icon_set);