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"
49 #include <glib/gstdio.h>
50 #include <glib/gprintf.h>
51 #include <glib/gi18n.h>
54 #define VIKING_WINDOW_WIDTH 1000
55 #define VIKING_WINDOW_HEIGHT 800
56 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
57 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024
58 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
60 static void window_finalize ( GObject *gob );
61 static GObjectClass *parent_class;
63 static void window_init ( VikWindow *vw );
64 static void window_class_init ( VikWindowClass *klass );
65 static void window_set_filename ( VikWindow *vw, const gchar *filename );
67 static void draw_update ( VikWindow *vw );
69 static void newwindow_cb ( GtkAction *a, VikWindow *vw );
73 static gboolean delete_event( VikWindow *vw );
75 static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data );
77 static void window_configure_event ( VikWindow *vw );
78 static void draw_sync ( VikWindow *vw );
79 static void draw_redraw ( VikWindow *vw );
80 static void draw_scroll ( VikWindow *vw, GdkEventScroll *event );
81 static void draw_click ( VikWindow *vw, GdkEventButton *event );
82 static void draw_release ( VikWindow *vw, GdkEventButton *event );
83 static void draw_mouse_motion ( VikWindow *vw, GdkEventMotion *event );
84 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw );
85 static void draw_goto_cb ( GtkAction *a, VikWindow *vw );
87 static void draw_status ();
89 /* End Drawing Functions */
91 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw );
92 static void menu_properties_cb ( GtkAction *a, VikWindow *vw );
93 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw );
101 #define TOOL_LAYER_TYPE_NONE -1
106 toolbox_tool_t *tools;
110 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw );
111 static toolbox_tools_t* toolbox_create(VikWindow *vw);
112 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type );
113 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
114 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
115 static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name);
116 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
117 static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event);
118 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
122 static void window_create_ui( VikWindow *window );
123 static void register_vik_icons (GtkIconFactory *icon_factory);
126 static void load_file ( GtkAction *a, VikWindow *vw );
127 static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
128 static gboolean save_file ( GtkAction *a, VikWindow *vw );
129 static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw );
130 static gboolean window_save ( VikWindow *vw );
134 VikViewport *viking_vvp;
135 VikLayersPanel *viking_vlp;
136 VikStatusbar *viking_vs;
140 GtkItemFactory *item_factory;
142 /* tool management state */
145 guint16 tool_layer_id;
146 guint16 tool_tool_id;
148 GtkActionGroup *action_group;
152 guint draw_image_width, draw_image_height;
153 gboolean draw_image_save_as_png;
158 GtkWidget *open_dia, *save_dia;
159 GtkWidget *save_img_dia, *save_img_dir_dia;
161 gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
164 /* half-drawn update */
166 VikCoord trigger_center;
179 VW_OPENWINDOW_SIGNAL,
183 static guint window_signals[VW_LAST_SIGNAL] = { 0 };
185 static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler") };
187 GType vik_window_get_type (void)
189 static GType vw_type = 0;
193 static const GTypeInfo vw_info =
195 sizeof (VikWindowClass),
196 NULL, /* base_init */
197 NULL, /* base_finalize */
198 (GClassInitFunc) window_class_init, /* class_init */
199 NULL, /* class_finalize */
200 NULL, /* class_data */
203 (GInstanceInitFunc) window_init,
205 vw_type = g_type_register_static ( GTK_TYPE_WINDOW, "VikWindow", &vw_info, 0 );
211 VikViewport * vik_window_viewport(VikWindow *vw)
213 return(vw->viking_vvp);
216 void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
218 int i, j, tool_count;
219 VikLayerInterface *layer_interface;
221 if (!vw->action_group) return;
223 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
225 layer_interface = vik_layer_get_interface(i);
226 tool_count = layer_interface->tools_count;
228 for (j = 0; j < tool_count; j++) {
229 action = gtk_action_group_get_action(vw->action_group,
230 layer_interface->tools[j].name);
231 g_object_set(action, "sensitive", i == vl->type, NULL);
236 static void window_finalize ( GObject *gob )
238 VikWindow *vw = VIK_WINDOW(gob);
239 g_return_if_fail ( vw != NULL );
241 a_background_remove_status ( vw->viking_vs );
243 G_OBJECT_CLASS(parent_class)->finalize(gob);
247 static void window_class_init ( VikWindowClass *klass )
250 GObjectClass *object_class;
252 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);
253 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);
255 object_class = G_OBJECT_CLASS (klass);
257 object_class->finalize = window_finalize;
259 parent_class = g_type_class_peek_parent (klass);
263 static void window_init ( VikWindow *vw )
265 GtkWidget *main_vbox;
268 vw->action_group = NULL;
270 vw->viking_vvp = vik_viewport_new();
271 vw->viking_vlp = vik_layers_panel_new();
272 vik_layers_panel_set_viewport ( vw->viking_vlp, vw->viking_vvp );
273 vw->viking_vs = vik_statusbar_new();
275 vw->vt = toolbox_create(vw);
276 window_create_ui(vw);
277 window_set_filename (vw, NULL);
279 toolbox_activate(vw->vt, "Pan");
282 vw->item_factory = NULL;
284 vw->modified = FALSE;
285 vw->only_updating_coord_mode_ui = FALSE;
287 vw->pan_x = vw->pan_y = -1;
288 vw->draw_image_width = DRAW_IMAGE_DEFAULT_WIDTH;
289 vw->draw_image_height = DRAW_IMAGE_DEFAULT_HEIGHT;
290 vw->draw_image_save_as_png = DRAW_IMAGE_DEFAULT_SAVE_AS_PNG;
292 main_vbox = gtk_vbox_new(FALSE, 1);
293 gtk_container_add (GTK_CONTAINER (vw), main_vbox);
295 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainMenu"), FALSE, TRUE, 0);
296 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainToolbar"), FALSE, TRUE, 0);
297 gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
298 gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
300 vik_ext_tools_add_menu_items ( vw, vw->uim );
302 g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
304 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw);
305 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw);
306 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 );
307 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw);
308 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw);
309 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw);
310 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
311 g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
313 g_signal_connect_swapped (G_OBJECT (vw->viking_vvp), "key_press_event", G_CALLBACK (key_press_event), vw);
315 gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT);
317 hpaned = gtk_hpaned_new ();
318 gtk_paned_pack1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp), FALSE, FALSE );
319 gtk_paned_pack2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp), TRUE, TRUE );
321 /* This packs the button into the window (a gtk container). */
322 gtk_box_pack_start (GTK_BOX(main_vbox), hpaned, TRUE, TRUE, 0);
324 gtk_box_pack_end (GTK_BOX(main_vbox), GTK_WIDGET(vw->viking_vs), FALSE, TRUE, 0);
326 a_background_add_status(vw->viking_vs);
330 vw->save_img_dia = NULL;
331 vw->save_img_dir_dia = NULL;
334 VikWindow *vik_window_new ()
336 return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
339 static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data )
341 VikLayer *vl = vik_layers_panel_get_selected ( vw->viking_vlp );
342 if (vl && vw->vt->active_tool != -1 && vw->vt->tools[vw->vt->active_tool].ti.key_press ) {
343 gint ltype = vw->vt->tools[vw->vt->active_tool].layer_type;
344 if ( vl && ltype == vl->type )
345 return vw->vt->tools[vw->vt->active_tool].ti.key_press(vl, event, vw->vt->tools[vw->vt->active_tool].state);
347 return FALSE; /* don't handle the keypress */
350 static gboolean delete_event( VikWindow *vw )
352 #ifdef VIKING_PROMPT_IF_MODIFIED
359 dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
360 _("Do you want to save the changes you made to the document \"%s\"?\n"
362 "Your changes will be lost if you don't save them."),
363 vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") ) );
364 gtk_dialog_add_buttons ( dia, _("Don't Save"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
365 switch ( gtk_dialog_run ( dia ) )
367 case GTK_RESPONSE_NO: gtk_widget_destroy ( GTK_WIDGET(dia) ); return FALSE;
368 case GTK_RESPONSE_CANCEL: gtk_widget_destroy ( GTK_WIDGET(dia) ); return TRUE;
369 default: gtk_widget_destroy ( GTK_WIDGET(dia) ); return ! save_file(NULL, vw);
376 static void newwindow_cb ( GtkAction *a, VikWindow *vw )
378 g_signal_emit ( G_OBJECT(vw), window_signals[VW_NEWWINDOW_SIGNAL], 0 );
381 static void draw_update ( VikWindow *vw )
387 static void draw_sync ( VikWindow *vw )
389 vik_viewport_sync(vw->viking_vvp);
391 /* other things may be necc here later. */
394 static void draw_status ( VikWindow *vw )
396 static gchar zoom_level[22];
397 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") );
398 if ( vw->current_tool == TOOL_LAYER )
399 vik_statusbar_set_message ( vw->viking_vs, 0, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name );
401 vik_statusbar_set_message ( vw->viking_vs, 0, _(tool_names[vw->current_tool]) );
403 vik_statusbar_set_message ( vw->viking_vs, 2, zoom_level );
406 void vik_window_set_redraw_trigger(VikLayer *vl)
408 VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl));
413 static void window_configure_event ( VikWindow *vw )
415 static int first = 1;
418 // This is a hack to set the cursor corresponding to the first tool
419 // FIXME find the correct way to initialize both tool and its cursor
420 const GdkCursor *cursor = NULL;
422 cursor = toolbox_get_cursor(vw->vt, "Pan");
423 /* We set cursor, even if it is NULL: it resets to default */
424 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor );
428 static void draw_redraw ( VikWindow *vw )
430 VikCoord old_center = vw->trigger_center;
431 vw->trigger_center = *(vik_viewport_get_center(vw->viking_vvp));
432 VikLayer *new_trigger = vw->trigger;
434 VikLayer *old_trigger = VIK_LAYER(vik_viewport_get_trigger(vw->viking_vvp));
437 ; /* do nothing -- have to redraw everything. */
438 else if ( (old_trigger != new_trigger) || !vik_coord_equals(&old_center, &vw->trigger_center) )
439 vik_viewport_set_trigger ( vw->viking_vvp, new_trigger ); /* todo: set to half_drawn mode if new trigger is above old */
441 vik_viewport_set_half_drawn ( vw->viking_vvp, TRUE );
444 vik_viewport_clear ( vw->viking_vvp);
445 vik_layers_panel_draw_all ( vw->viking_vlp );
446 vik_viewport_draw_scale ( vw->viking_vvp );
447 vik_viewport_draw_centermark ( vw->viking_vvp );
449 vik_viewport_set_half_drawn ( vw->viking_vvp, FALSE ); /* just in case. */
452 gboolean draw_buf_done = TRUE;
454 static gboolean draw_buf(gpointer data)
456 gpointer *pass_along = data;
458 gdk_draw_drawable (pass_along[0], pass_along[1],
459 pass_along[2], 0, 0, 0, 0, -1, -1);
460 draw_buf_done = TRUE;
466 /* Mouse event handlers ************************************************************************/
468 static void vik_window_pan_click (VikWindow *vw, GdkEventButton *event)
470 /* set panning origin */
471 vw->pan_x = (gint) event->x;
472 vw->pan_y = (gint) event->y;
475 static void draw_click (VikWindow *vw, GdkEventButton *event)
477 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
479 /* middle button pressed. we reserve all middle button and scroll events
480 * for panning and zooming; tools only get left/right/movement
482 if ( event->button == 2) {
483 vik_window_pan_click ( vw, event );
486 toolbox_click(vw->vt, event);
490 static void vik_window_pan_move (VikWindow *vw, GdkEventMotion *event)
492 if ( vw->pan_x != -1 ) {
493 vik_viewport_pan_sync ( vw->viking_vvp, event->x - vw->pan_x, event->y - vw->pan_y );
497 static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
499 static VikCoord coord;
500 static struct UTM utm;
501 static struct LatLon ll;
502 #define BUFFER_SIZE 50
503 static char pointer_buf[BUFFER_SIZE];
504 gchar *lat = NULL, *lon = NULL;
507 VikDemInterpol interpol_method;
509 /* This is a hack, but work far the best, at least for single pointer systems.
510 * See http://bugzilla.gnome.org/show_bug.cgi?id=587714 for more. */
512 gdk_window_get_pointer (event->window, &x, &y, NULL);
516 toolbox_move(vw->vt, event);
518 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
519 vik_coord_to_utm ( &coord, &utm );
520 a_coords_utm_to_latlon ( &utm, &ll );
521 a_coords_latlon_to_string ( &ll, &lat, &lon );
522 /* Change interpolate method according to scale */
523 zoom = vik_viewport_get_zoom(vw->viking_vvp);
525 interpol_method = VIK_DEM_INTERPOL_NONE;
526 else if (zoom >= 1.0)
527 interpol_method = VIK_DEM_INTERPOL_SIMPLE;
529 interpol_method = VIK_DEM_INTERPOL_BEST;
530 if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION)
531 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dm"), lat, lon, alt );
533 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s"), lat, lon );
538 vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
540 vik_window_pan_move ( vw, event );
542 /* This is recommended by the GTK+ documentation, but does not work properly.
543 * Use deprecated way until GTK+ gets a solution for correct motion hint handling:
544 * http://bugzilla.gnome.org/show_bug.cgi?id=587714
546 /* gdk_event_request_motions ( event ); */
549 static void vik_window_pan_release ( VikWindow *vw, GdkEventButton *event )
551 if ( ABS(vw->pan_x - event->x) <= 1 && ABS(vw->pan_y - event->y) <= 1 )
552 vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
554 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
555 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
557 vw->pan_x = vw->pan_y = -1;
560 static void draw_release ( VikWindow *vw, GdkEventButton *event )
562 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
564 if ( event->button == 2 ) { /* move / pan */
565 vik_window_pan_release(vw, event);
568 toolbox_release(vw->vt, event);
572 static void draw_scroll (VikWindow *vw, GdkEventScroll *event)
574 guint modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK);
575 if ( modifiers == GDK_CONTROL_MASK ) {
576 /* control == pan up & down */
577 if ( event->direction == GDK_SCROLL_UP )
578 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 );
580 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 );
581 } else if ( modifiers == GDK_SHIFT_MASK ) {
582 /* shift == pan left & right */
583 if ( event->direction == GDK_SCROLL_UP )
584 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 );
586 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 );
587 } else if ( modifiers == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) {
588 /* control+shift == make sure mouse is still over the same point on the map when we zoom */
591 gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
592 gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
593 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
594 if ( event->direction == GDK_SCROLL_UP )
595 vik_viewport_zoom_in (vw->viking_vvp);
597 vik_viewport_zoom_out(vw->viking_vvp);
598 vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
599 vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
600 center_y + (y - event->y) );
602 if ( event->direction == GDK_SCROLL_UP )
603 vik_viewport_zoom_in (vw->viking_vvp);
605 vik_viewport_zoom_out (vw->viking_vvp);
613 /********************************************************************************
615 ********************************************************************************/
616 static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gdouble distance)
618 PangoFontDescription *pfd;
621 GdkGC *labgc = vik_viewport_new_gc ( vvp, "#cccccc", 1);
622 GdkGC *thickgc = gdk_gc_new(d);
624 gdouble len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
625 gdouble dx = (x2-x1)/len*10;
626 gdouble dy = (y2-y1)/len*10;
627 gdouble c = cos(15.0 * M_PI/180.0);
628 gdouble s = sin(15.0 * M_PI/180.0);
630 gdouble baseangle = 0;
633 /* draw line with arrow ends */
635 gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
636 a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
637 gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
640 a_viewport_clip_line(&x1, &y1, &x2, &y2);
641 gdk_draw_line(d, gc, x1, y1, x2, y2);
643 gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
644 gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
645 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));
646 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c - dy * s), y2 - (dy * c + dx * s));
647 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c + dy * s), y1 + (dy * c - dx * s));
648 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c - dy * s), y1 + (dy * c + dx * s));
653 angle = atan2(dy, dx) + M_PI_2;
655 if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
661 vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
662 vik_coord_to_latlon ( &test, &ll );
663 ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
664 a_coords_latlon_to_utm ( &ll, &u );
665 vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
666 vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
668 baseangle = M_PI - atan2(tx-x1, ty-y1);
679 gdk_gc_copy(thickgc, gc);
680 gdk_gc_set_line_attributes(thickgc, CW, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
681 gdk_color_parse("#2255cc", &color);
682 gdk_gc_set_rgb_fg_color(thickgc, &color);
684 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);
687 gdk_gc_copy(thickgc, gc);
688 gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
689 for (i=0; i<180; i++) {
690 c = cos(i*M_PI/90.0 + baseangle);
691 s = sin(i*M_PI/90.0 + baseangle);
694 gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
696 gdouble ticksize = 2*CW;
697 gdk_draw_line (d, thickgc, x1 + (CR-CW)*c, y1 + (CR-CW)*s, x1 + (CR+ticksize)*c, y1 + (CR+ticksize)*s);
701 gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
702 gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
703 gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
704 c = (CR+CW*2)*cos(baseangle);
705 s = (CR+CW*2)*sin(baseangle);
706 gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
707 gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
710 #define LABEL(x, y, w, h) { \
711 gdk_draw_rectangle(d, labgc, TRUE, (x)-2, (y)-1, (w)+4, (h)+1); \
712 gdk_draw_rectangle(d, gc, FALSE, (x)-2, (y)-1, (w)+4, (h)+1); \
713 gdk_draw_layout(d, gc, (x), (y), pl); }
718 pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
720 pfd = pango_font_description_from_string ("Sans 8"); // FIXME: settable option? global variable?
721 pango_layout_set_font_description (pl, pfd);
722 pango_font_description_free (pfd);
724 pango_layout_set_text(pl, "N", -1);
725 gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
727 /* draw label with distance */
728 if (distance >= 1000 && distance < 100000) {
729 g_sprintf(str, "%3.2f km", distance/1000.0);
730 } else if (distance < 1000) {
731 g_sprintf(str, "%d m", (int)distance);
733 g_sprintf(str, "%d km", (int)distance/1000);
735 pango_layout_set_text(pl, str, -1);
737 pango_layout_get_pixel_size ( pl, &wd, &hd );
740 yd = (y1+y2)/2 - hd/2 - dx;
743 yd = (y1+y2)/2 - hd/2 + dx;
746 if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
751 LABEL(xd, yd, wd, hd);
753 /* draw label with bearing */
754 g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
755 pango_layout_set_text(pl, str, -1);
756 pango_layout_get_pixel_size ( pl, &wb, &hb );
757 xb = x1 + CR*cos(angle-M_PI_2);
758 yb = y1 + CR*sin(angle-M_PI_2);
760 if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
766 GdkRectangle r1 = {xd-2, yd-1, wd+4, hd+1}, r2 = {xb-2, yb-1, wb+4, hb+1};
767 if (gdk_rectangle_intersect(&r1, &r2, &r2)) {
771 LABEL(xb, yb, wb, hb);
775 g_object_unref ( G_OBJECT ( pl ) );
776 g_object_unref ( G_OBJECT ( labgc ) );
777 g_object_unref ( G_OBJECT ( thickgc ) );
783 gboolean has_oldcoord;
785 } ruler_tool_state_t;
787 static gpointer ruler_create (VikWindow *vw, VikViewport *vvp)
789 ruler_tool_state_t *s = g_new(ruler_tool_state_t, 1);
792 s->has_oldcoord = FALSE;
796 static void ruler_destroy (ruler_tool_state_t *s)
801 static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
806 if ( event->button == 1 ) {
807 gchar *lat=NULL, *lon=NULL;
808 vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
809 vik_coord_to_latlon ( &coord, &ll );
810 a_coords_latlon_to_string ( &ll, &lat, &lon );
811 if ( s->has_oldcoord ) {
812 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
813 s->has_oldcoord = FALSE;
816 temp = g_strdup_printf ( "%s %s", lat, lon );
817 s->has_oldcoord = TRUE;
820 vik_statusbar_set_message ( s->vw->viking_vs, 3, temp );
826 vik_viewport_set_center_screen ( s->vvp, (gint) event->x, (gint) event->y );
827 draw_update ( s->vw );
829 return VIK_LAYER_TOOL_ACK;
832 static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, ruler_tool_state_t *s)
834 VikViewport *vvp = s->vvp;
835 VikWindow *vw = s->vw;
841 if ( s->has_oldcoord ) {
842 int oldx, oldy, w1, h1, w2, h2;
843 static GdkPixmap *buf = NULL;
844 gchar *lat=NULL, *lon=NULL;
845 w1 = vik_viewport_get_width(vvp);
846 h1 = vik_viewport_get_height(vvp);
848 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
850 gdk_drawable_get_size(buf, &w2, &h2);
851 if (w1 != w2 || h1 != h2) {
852 g_object_unref ( G_OBJECT ( buf ) );
853 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
856 vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
857 vik_coord_to_latlon ( &coord, &ll );
858 vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
860 gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc,
861 vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
862 draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
864 static gpointer pass_along[3];
865 pass_along[0] = GTK_WIDGET(vvp)->window;
866 pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
868 g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
869 draw_buf_done = FALSE;
871 a_coords_latlon_to_string(&ll, &lat, &lon);
872 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
873 vik_statusbar_set_message ( vw->viking_vs, 3, temp );
876 return VIK_LAYER_TOOL_ACK;
879 static VikLayerToolFuncStatus ruler_release (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
881 return VIK_LAYER_TOOL_ACK;
884 static void ruler_deactivate (VikLayer *vl, ruler_tool_state_t *s)
886 draw_update ( s->vw );
889 static VikToolInterface ruler_tool =
891 (VikToolConstructorFunc) ruler_create,
892 (VikToolDestructorFunc) ruler_destroy,
893 (VikToolActivationFunc) NULL,
894 (VikToolActivationFunc) ruler_deactivate,
895 (VikToolMouseFunc) ruler_click,
896 (VikToolMouseMoveFunc) ruler_move,
897 (VikToolMouseFunc) ruler_release,
899 GDK_CURSOR_IS_PIXMAP,
900 &cursor_ruler_pixbuf };
901 /*** end ruler code ********************************************************/
905 /********************************************************************************
907 ********************************************************************************/
908 static gpointer zoomtool_create (VikWindow *vw, VikViewport *vvp)
913 static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
916 vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
917 if ( event->button == 1 )
918 vik_viewport_zoom_in (vw->viking_vvp);
919 else if ( event->button == 3 )
920 vik_viewport_zoom_out (vw->viking_vvp);
922 return VIK_LAYER_TOOL_ACK;
925 static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event, VikViewport *vvp)
927 return VIK_LAYER_TOOL_ACK;
930 static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
932 return VIK_LAYER_TOOL_ACK;
935 static VikToolInterface zoom_tool =
937 (VikToolConstructorFunc) zoomtool_create,
938 (VikToolDestructorFunc) NULL,
939 (VikToolActivationFunc) NULL,
940 (VikToolActivationFunc) NULL,
941 (VikToolMouseFunc) zoomtool_click,
942 (VikToolMouseMoveFunc) zoomtool_move,
943 (VikToolMouseFunc) zoomtool_release,
945 GDK_CURSOR_IS_PIXMAP,
946 &cursor_zoom_pixbuf };
947 /*** end zoom code ********************************************************/
949 /********************************************************************************
951 ********************************************************************************/
952 static gpointer pantool_create (VikWindow *vw, VikViewport *vvp)
957 static VikLayerToolFuncStatus pantool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
960 if ( event->button == 1 )
961 vik_window_pan_click ( vw, event );
963 return VIK_LAYER_TOOL_ACK;
966 static VikLayerToolFuncStatus pantool_move (VikLayer *vl, GdkEventMotion *event, VikWindow *vw)
968 vik_window_pan_move ( vw, event );
969 return VIK_LAYER_TOOL_ACK;
972 static VikLayerToolFuncStatus pantool_release (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
974 if ( event->button == 1 )
975 vik_window_pan_release ( vw, event );
976 return VIK_LAYER_TOOL_ACK;
979 static VikToolInterface pan_tool =
981 (VikToolConstructorFunc) pantool_create,
982 (VikToolDestructorFunc) NULL,
983 (VikToolActivationFunc) NULL,
984 (VikToolActivationFunc) NULL,
985 (VikToolMouseFunc) pantool_click,
986 (VikToolMouseMoveFunc) pantool_move,
987 (VikToolMouseFunc) pantool_release,
990 /*** end pan code ********************************************************/
992 static void draw_pan_cb ( GtkAction *a, VikWindow *vw )
994 if (!strcmp(gtk_action_get_name(a), "PanNorth")) {
995 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, 0 );
996 } else if (!strcmp(gtk_action_get_name(a), "PanEast")) {
997 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp), vik_viewport_get_height(vw->viking_vvp)/2 );
998 } else if (!strcmp(gtk_action_get_name(a), "PanSouth")) {
999 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp) );
1000 } else if (!strcmp(gtk_action_get_name(a), "PanWest")) {
1001 vik_viewport_set_center_screen ( vw->viking_vvp, 0, vik_viewport_get_height(vw->viking_vvp)/2 );
1006 static void full_screen_cb ( GtkAction *a, VikWindow *vw )
1008 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/FullScreen" );
1009 g_assert(check_box);
1010 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1012 gtk_window_fullscreen ( GTK_WINDOW(vw) );
1014 gtk_window_unfullscreen ( GTK_WINDOW(vw) );
1017 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw )
1021 if (!strcmp(gtk_action_get_name(a), "ZoomIn")) {
1024 else if (!strcmp(gtk_action_get_name(a), "ZoomOut")) {
1027 else if (!strcmp(gtk_action_get_name(a), "Zoom0.25")) {
1030 else if (!strcmp(gtk_action_get_name(a), "Zoom0.5")) {
1034 gchar *s = (gchar *)gtk_action_get_name(a);
1040 case -3: vik_viewport_zoom_in ( vw->viking_vvp ); break;
1041 case -4: vik_viewport_zoom_out ( vw->viking_vvp ); break;
1042 case -1: vik_viewport_set_zoom ( vw->viking_vvp, 0.5 ); break;
1043 case -2: vik_viewport_set_zoom ( vw->viking_vvp, 0.25 ); break;
1044 default: vik_viewport_set_zoom ( vw->viking_vvp, what );
1049 void draw_goto_cb ( GtkAction *a, VikWindow *vw )
1051 VikCoord new_center;
1053 if (!strcmp(gtk_action_get_name(a), "GotoLL")) {
1054 struct LatLon ll, llold;
1055 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &llold );
1056 if ( a_dialog_goto_latlon ( GTK_WINDOW(vw), &ll, &llold ) )
1057 vik_coord_load_from_latlon ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &ll );
1061 else if (!strcmp(gtk_action_get_name(a), "GotoUTM")) {
1062 struct UTM utm, utmold;
1063 vik_coord_to_utm ( vik_viewport_get_center ( vw->viking_vvp ), &utmold );
1064 if ( a_dialog_goto_utm ( GTK_WINDOW(vw), &utm, &utmold ) )
1065 vik_coord_load_from_utm ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &utm );
1070 g_critical("Houston, we've had a problem.");
1074 vik_viewport_set_center_coord ( vw->viking_vvp, &new_center );
1078 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw )
1081 for ( type = 0; type < VIK_LAYER_NUM_TYPES; type++ ) {
1082 if (!strcmp(vik_layer_get_interface(type)->name, gtk_action_get_name(a))) {
1083 if ( vik_layers_panel_new_layer ( vw->viking_vlp, type ) ) {
1085 vw->modified = TRUE;
1091 static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw )
1093 a_clipboard_copy_selected ( vw->viking_vlp );
1096 static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw )
1098 a_clipboard_copy_selected ( vw->viking_vlp );
1099 menu_delete_layer_cb ( a, vw );
1102 static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw )
1104 if ( a_clipboard_paste ( vw->viking_vlp ) )
1107 vw->modified = TRUE;
1111 static void menu_properties_cb ( GtkAction *a, VikWindow *vw )
1113 if ( ! vik_layers_panel_properties ( vw->viking_vlp ) )
1114 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to show its properties.") );
1117 static void help_about_cb ( GtkAction *a, VikWindow *vw )
1119 a_dialog_about(GTK_WINDOW(vw));
1122 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
1124 if ( vik_layers_panel_get_selected ( vw->viking_vlp ) )
1126 vik_layers_panel_delete_selected ( vw->viking_vlp );
1127 vw->modified = TRUE;
1130 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to delete.") );
1133 static void view_side_panel_cb ( GtkAction *a, VikWindow *vw )
1135 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ViewSidePanel" );
1136 g_assert(check_box);
1137 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1139 gtk_widget_show(GTK_WIDGET(vw->viking_vlp));
1141 gtk_widget_hide(GTK_WIDGET(vw->viking_vlp));
1144 /***************************************
1145 ** tool management routines
1147 ***************************************/
1149 static toolbox_tools_t* toolbox_create(VikWindow *vw)
1151 toolbox_tools_t *vt = g_new(toolbox_tools_t, 1);
1154 vt->active_tool = -1;
1156 if (!vw->viking_vvp) {
1157 g_critical("no viewport found.");
1163 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type )
1165 vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1);
1166 vt->tools[vt->n_tools].ti = *vti;
1167 vt->tools[vt->n_tools].layer_type = layer_type;
1169 vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp);
1172 vt->tools[vt->n_tools].state = NULL;
1177 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name)
1180 for (i=0; i<vt->n_tools; i++) {
1181 if (!strcmp(tool_name, vt->tools[i].ti.name)) {
1188 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name)
1190 int tool = toolbox_get_tool(vt, tool_name);
1191 toolbox_tool_t *t = &vt->tools[tool];
1192 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1194 if (tool == vt->n_tools) {
1195 g_critical("trying to activate a non-existent tool...");
1198 /* is the tool already active? */
1199 if (vt->active_tool == tool) {
1203 if (vt->active_tool != -1) {
1204 if (vt->tools[vt->active_tool].ti.deactivate) {
1205 vt->tools[vt->active_tool].ti.deactivate(NULL, vt->tools[vt->active_tool].state);
1208 if (t->ti.activate) {
1209 t->ti.activate(vl, t->state);
1211 vt->active_tool = tool;
1214 static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name)
1216 int tool = toolbox_get_tool(vt, tool_name);
1217 toolbox_tool_t *t = &vt->tools[tool];
1218 if (t->ti.cursor == NULL) {
1219 if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) {
1220 GError *cursor_load_err = NULL;
1221 GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err);
1222 /* TODO: settable offeset */
1223 t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
1224 g_object_unref ( G_OBJECT(cursor_pixbuf) );
1226 t->ti.cursor = gdk_cursor_new ( t->ti.cursor_type );
1229 return t->ti.cursor;
1232 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
1234 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1235 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) {
1236 gint ltype = vt->tools[vt->active_tool].layer_type;
1237 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1238 vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state);
1242 static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event)
1244 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1245 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) {
1246 gint ltype = vt->tools[vt->active_tool].layer_type;
1247 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1248 if ( VIK_LAYER_TOOL_ACK_GRAB_FOCUS == vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state) )
1249 gtk_widget_grab_focus ( GTK_WIDGET(vt->vw->viking_vvp) );
1253 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event)
1255 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1256 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release ) {
1257 gint ltype = vt->tools[vt->active_tool].layer_type;
1258 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1259 vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state);
1262 /** End tool management ************************************/
1264 void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id )
1266 gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].name ) );
1269 /* this function gets called whenever a toolbar tool is clicked */
1270 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
1272 /* White Magic, my friends ... White Magic... */
1273 int layer_id, tool_id;
1274 const GdkCursor *cursor = NULL;
1276 toolbox_activate(vw->vt, gtk_action_get_name(a));
1278 cursor = toolbox_get_cursor(vw->vt, gtk_action_get_name(a));
1279 /* We set cursor, even if it is NULL: it resets to default */
1280 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor );
1282 if (!strcmp(gtk_action_get_name(a), "Pan")) {
1283 vw->current_tool = TOOL_PAN;
1285 else if (!strcmp(gtk_action_get_name(a), "Zoom")) {
1286 vw->current_tool = TOOL_ZOOM;
1288 else if (!strcmp(gtk_action_get_name(a), "Ruler")) {
1289 vw->current_tool = TOOL_RULER;
1292 /* TODO: only enable tools from active layer */
1293 for (layer_id=0; layer_id<VIK_LAYER_NUM_TYPES; layer_id++) {
1294 for ( tool_id = 0; tool_id < vik_layer_get_interface(layer_id)->tools_count; tool_id++ ) {
1295 if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].name, gtk_action_get_name(a))) {
1296 vw->current_tool = TOOL_LAYER;
1297 vw->tool_layer_id = layer_id;
1298 vw->tool_tool_id = tool_id;
1306 static void window_set_filename ( VikWindow *vw, const gchar *filename )
1311 g_free ( vw->filename );
1312 if ( filename == NULL )
1314 vw->filename = NULL;
1315 file = _("Untitled");
1319 vw->filename = g_strdup(filename);
1320 file = a_file_basename ( filename );
1322 title = g_strdup_printf( "%s - Viking", file );
1323 gtk_window_set_title ( GTK_WINDOW(vw), title );
1327 GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode )
1329 GtkWidget *mode_button;
1332 #ifdef VIK_CONFIG_EXPEDIA
1333 case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
1335 case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break;
1336 default: buttonname = "/ui/MainMenu/View/ModeUTM";
1338 mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
1339 g_assert ( mode_button );
1343 static void on_activate_recent_item (GtkRecentChooser *chooser,
1348 filename = gtk_recent_chooser_get_current_uri (chooser);
1349 if (filename != NULL)
1351 GFile *file = g_file_new_for_uri ( filename );
1352 gchar *path = g_file_get_path ( file );
1353 g_object_unref ( file );
1354 if ( self->filename )
1356 gchar *filenames[] = { path, NULL };
1357 g_signal_emit ( G_OBJECT(self), window_signals[VW_OPENWINDOW_SIGNAL], 0, filenames );
1360 vik_window_open_file ( self, filename, TRUE );
1367 static void setup_recent_files (VikWindow *self)
1369 GtkRecentManager *manager;
1370 GtkRecentFilter *filter;
1371 GtkWidget *menu, *menu_item;
1373 filter = gtk_recent_filter_new ();
1374 /* gtk_recent_filter_add_application (filter, g_get_application_name()); */
1375 gtk_recent_filter_add_group(filter, "viking");
1377 manager = gtk_recent_manager_get_default ();
1378 menu = gtk_recent_chooser_menu_new_for_manager (manager);
1379 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu), GTK_RECENT_SORT_MRU);
1380 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
1382 menu_item = gtk_ui_manager_get_widget (self->uim, "/ui/MainMenu/File/OpenRecentFile");
1383 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu);
1385 g_signal_connect (G_OBJECT (menu), "item-activated",
1386 G_CALLBACK (on_activate_recent_item), (gpointer) self);
1389 static void update_recently_used_document(const gchar *filename)
1391 /* Update Recently Used Document framework */
1392 GtkRecentManager *manager = gtk_recent_manager_get_default();
1393 GtkRecentData *recent_data = g_slice_new (GtkRecentData);
1394 gchar *groups[] = {"viking", NULL};
1395 GFile *file = g_file_new_for_commandline_arg(filename);
1396 gchar *uri = g_file_get_uri(file);
1397 gchar *basename = g_path_get_basename(filename);
1398 g_object_unref(file);
1401 recent_data->display_name = basename;
1402 recent_data->description = NULL;
1403 recent_data->mime_type = "text/x-gps-data";
1404 recent_data->app_name = (gchar *) g_get_application_name ();
1405 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL);
1406 recent_data->groups = groups;
1407 recent_data->is_private = FALSE;
1408 if (!gtk_recent_manager_add_full (manager, uri, recent_data))
1410 g_warning (_("Unable to add '%s' to the list of recently used documents"), uri);
1415 g_free (recent_data->app_exec);
1416 g_slice_free (GtkRecentData, recent_data);
1419 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename )
1421 switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) )
1424 a_dialog_error_msg ( GTK_WINDOW(vw), _("The file you requested could not be opened.") );
1428 GtkWidget *mode_button;
1430 if ( change_filename )
1431 window_set_filename ( vw, filename );
1432 mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) );
1433 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. */
1434 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE );
1435 vw->only_updating_coord_mode_ui = FALSE;
1437 vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) );
1439 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
1440 g_assert ( mode_button );
1441 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_scale(vw->viking_vvp) );
1443 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
1444 g_assert ( mode_button );
1445 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) );
1448 update_recently_used_document(filename);
1452 static void load_file ( GtkAction *a, VikWindow *vw )
1454 GSList *files = NULL;
1455 GSList *cur_file = NULL;
1457 if (!strcmp(gtk_action_get_name(a), "Open")) {
1460 else if (!strcmp(gtk_action_get_name(a), "Append")) {
1464 g_critical("Houston, we've had a problem.");
1468 if ( ! vw->open_dia )
1470 vw->open_dia = gtk_file_chooser_dialog_new (_("Please select a GPS data file to open. "),
1472 GTK_FILE_CHOOSER_ACTION_OPEN,
1473 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1474 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1476 gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(vw->open_dia), TRUE );
1477 gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) );
1478 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE );
1480 if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_ACCEPT )
1482 gtk_widget_hide ( vw->open_dia );
1483 #ifdef VIKING_PROMPT_IF_MODIFIED
1484 if ( (vw->modified || vw->filename) && newwindow )
1486 if ( vw->filename && newwindow )
1488 g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) ) );
1490 files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) );
1491 gboolean change_fn = newwindow && (g_slist_length(files)==1); /* only change fn if one file */
1494 while ( cur_file ) {
1495 gchar *file_name = cur_file->data;
1496 vik_window_open_file ( vw, file_name, change_fn );
1498 cur_file = g_slist_next (cur_file);
1500 g_slist_free (files);
1504 gtk_widget_hide ( vw->open_dia );
1507 static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
1509 gboolean rv = FALSE;
1511 if ( ! vw->save_dia )
1513 vw->save_dia = gtk_file_chooser_dialog_new (_("Save as Viking File."),
1515 GTK_FILE_CHOOSER_ACTION_SAVE,
1516 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1517 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1519 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) );
1520 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
1523 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_ACCEPT )
1525 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_dia) );
1526 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 ) ) )
1528 window_set_filename ( vw, fn );
1529 rv = window_save ( vw );
1530 vw->modified = FALSE;
1534 gtk_widget_hide ( vw->save_dia );
1538 static gboolean window_save ( VikWindow *vw )
1540 if ( a_file_save ( vik_layers_panel_get_top_layer ( vw->viking_vlp ), vw->viking_vvp, vw->filename ) )
1542 update_recently_used_document ( vw->filename );
1547 a_dialog_error_msg ( GTK_WINDOW(vw), _("The filename you requested could not be opened for writing.") );
1552 static gboolean save_file ( GtkAction *a, VikWindow *vw )
1554 if ( ! vw->filename )
1555 return save_file_as ( NULL, vw );
1558 vw->modified = FALSE;
1559 return window_save ( vw );
1563 static void acquire_from_gps ( GtkAction *a, VikWindow *vw )
1565 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface );
1568 static void acquire_from_google ( GtkAction *a, VikWindow *vw )
1570 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
1573 #ifdef VIK_CONFIG_GEOCACHES
1574 static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
1576 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface );
1580 static void goto_address( GtkAction *a, VikWindow *vw)
1582 a_vik_goto(vw, vw->viking_vlp, vw->viking_vvp);
1585 static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw )
1590 static void preferences_cb ( GtkAction *a, VikWindow *vw )
1592 a_preferences_show_window ( GTK_WINDOW(vw) );
1595 static void clear_cb ( GtkAction *a, VikWindow *vw )
1597 vik_layers_panel_clear ( vw->viking_vlp );
1598 window_set_filename ( vw, NULL );
1602 static void window_close ( GtkAction *a, VikWindow *vw )
1604 if ( ! delete_event ( vw ) )
1605 gtk_widget_destroy ( GTK_WIDGET(vw) );
1608 static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw )
1610 if (save_file( NULL, vw)) {
1611 window_close( NULL, vw);
1618 static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
1620 gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1621 if ( a_dialog_custom_zoom ( GTK_WINDOW(vw), &xmpp, &ympp ) )
1623 vik_viewport_set_xmpp ( vw->viking_vvp, xmpp );
1624 vik_viewport_set_ympp ( vw->viking_vvp, ympp );
1629 static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h, gdouble zoom, gboolean save_as_png )
1631 /* more efficient way: stuff draws directly to pixbuf (fork viewport) */
1632 GdkPixbuf *pixbuf_to_save;
1633 gdouble old_xmpp, old_ympp;
1634 GError *error = NULL;
1636 /* backup old zoom & set new */
1637 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1638 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1639 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1641 /* reset width and height: */
1642 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1644 /* draw all layers */
1647 /* save buffer as file. */
1648 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);
1649 gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL );
1652 g_warning("Unable to write to file %s: %s", fn, error->message );
1653 g_error_free (error);
1655 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1657 /* pretend like nothing happened ;) */
1658 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1659 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1660 vik_viewport_configure ( vw->viking_vvp );
1664 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 )
1666 gulong size = sizeof(gchar) * (strlen(fn) + 15);
1667 gchar *name_of_file = g_malloc ( size );
1669 struct UTM utm_orig, utm;
1671 /* *** copied from above *** */
1672 GdkPixbuf *pixbuf_to_save;
1673 gdouble old_xmpp, old_ympp;
1674 GError *error = NULL;
1676 /* backup old zoom & set new */
1677 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1678 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1679 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1681 /* reset width and height: do this only once for all images (same size) */
1682 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1683 /* *** end copy from above *** */
1685 g_assert ( vik_viewport_get_coord_mode ( vw->viking_vvp ) == VIK_COORD_UTM );
1689 utm_orig = *((const struct UTM *)vik_viewport_get_center ( vw->viking_vvp ));
1691 for ( y = 1; y <= tiles_h; y++ )
1693 for ( x = 1; x <= tiles_w; x++ )
1695 g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, G_DIR_SEPARATOR, y, x, save_as_png ? "png" : "jpg" );
1697 if ( tiles_w & 0x1 )
1698 utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom);
1700 utm.easting += ((gdouble)x - (((gdouble)tiles_w)+1)/2) * (w*zoom);
1701 if ( tiles_h & 0x1 ) /* odd */
1702 utm.northing -= ((gdouble)y - ceil(((gdouble)tiles_h)/2)) * (h*zoom);
1704 utm.northing -= ((gdouble)y - (((gdouble)tiles_h)+1)/2) * (h*zoom);
1706 /* move to correct place. */
1707 vik_viewport_set_center_utm ( vw->viking_vvp, &utm );
1711 /* save buffer as file. */
1712 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);
1713 gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL );
1716 g_warning("Unable to write to file %s: %s", name_of_file, error->message );
1717 g_error_free (error);
1720 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1724 vik_viewport_set_center_utm ( vw->viking_vvp, &utm_orig );
1725 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1726 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1727 vik_viewport_configure ( vw->viking_vvp );
1730 g_free ( name_of_file );
1733 static void draw_to_image_file_current_window_cb(GtkWidget* widget,GdkEventButton *event,gpointer *pass_along)
1735 VikWindow *vw = VIK_WINDOW(pass_along[0]);
1736 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1737 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1738 gdouble width_min, width_max, height_min, height_max;
1741 gtk_spin_button_get_range ( width_spin, &width_min, &width_max );
1742 gtk_spin_button_get_range ( height_spin, &height_min, &height_max );
1744 /* TODO: support for xzoom and yzoom values */
1745 width = vik_viewport_get_width ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1746 height = vik_viewport_get_height ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1748 if ( width > width_max || width < width_min || height > height_max || height < height_min )
1749 a_dialog_info_msg ( GTK_WINDOW(vw), _("Viewable region outside allowable pixel size bounds for image. Clipping width/height values.") );
1751 gtk_spin_button_set_value ( width_spin, width );
1752 gtk_spin_button_set_value ( height_spin, height );
1755 static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
1757 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1758 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1761 w = gtk_spin_button_get_value(width_spin) * gtk_spin_button_get_value(zoom_spin);
1762 h = gtk_spin_button_get_value(height_spin) * gtk_spin_button_get_value(zoom_spin);
1763 if (pass_along[4]) /* save many images; find TOTAL area covered */
1765 w *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[4]));
1766 h *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[5]));
1768 label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. km)"), (glong)w, (glong)h, (w*h/1000000));
1769 gtk_label_set_text(GTK_LABEL(pass_along[6]), label_text);
1770 g_free ( label_text );
1773 static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_image_only )
1775 /* todo: default for answers inside VikWindow or static (thruout instance) */
1776 GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Save to Image File"), GTK_WINDOW(vw),
1777 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1779 GTK_RESPONSE_REJECT,
1781 GTK_RESPONSE_ACCEPT,
1783 GtkWidget *width_label, *width_spin, *height_label, *height_spin;
1784 GtkWidget *png_radio, *jpeg_radio;
1785 GtkWidget *current_window_button;
1786 gpointer current_window_pass_along[7];
1787 GtkWidget *zoom_label, *zoom_spin;
1788 GtkWidget *total_size_label;
1790 /* only used if (!one_image_only) */
1791 GtkWidget *tiles_width_spin = NULL, *tiles_height_spin = NULL;
1794 width_label = gtk_label_new ( _("Width (pixels):") );
1795 width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_width, 10, 5000, 10, 100, 0 )), 10, 0 );
1796 height_label = gtk_label_new ( _("Height (pixels):") );
1797 height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_height, 10, 5000, 10, 100, 0 )), 10, 0 );
1799 zoom_label = gtk_label_new ( _("Zoom (meters per pixel):") );
1800 /* TODO: separate xzoom and yzoom factors */
1801 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, 3 )), 16, 3);
1803 total_size_label = gtk_label_new ( NULL );
1805 current_window_button = gtk_button_new_with_label ( _("Area in current viewable window") );
1806 current_window_pass_along [0] = vw;
1807 current_window_pass_along [1] = width_spin;
1808 current_window_pass_along [2] = height_spin;
1809 current_window_pass_along [3] = zoom_spin;
1810 current_window_pass_along [4] = NULL; /* used for one_image_only != 1 */
1811 current_window_pass_along [5] = NULL;
1812 current_window_pass_along [6] = total_size_label;
1813 g_signal_connect ( G_OBJECT(current_window_button), "button_press_event", G_CALLBACK(draw_to_image_file_current_window_cb), current_window_pass_along );
1815 png_radio = gtk_radio_button_new_with_label ( NULL, _("Save as PNG") );
1816 jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), _("Save as JPEG") );
1818 if ( ! vw->draw_image_save_as_png )
1819 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE );
1821 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_label, FALSE, FALSE, 0);
1822 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_spin, FALSE, FALSE, 0);
1823 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_label, FALSE, FALSE, 0);
1824 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_spin, FALSE, FALSE, 0);
1825 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), current_window_button, FALSE, FALSE, 0);
1826 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), png_radio, FALSE, FALSE, 0);
1827 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), jpeg_radio, FALSE, FALSE, 0);
1828 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_label, FALSE, FALSE, 0);
1829 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_spin, FALSE, FALSE, 0);
1831 if ( ! one_image_only )
1833 GtkWidget *tiles_width_label, *tiles_height_label;
1836 tiles_width_label = gtk_label_new ( _("East-west image tiles:") );
1837 tiles_width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1838 tiles_height_label = gtk_label_new ( _("North-south image tiles:") );
1839 tiles_height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1840 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_label, FALSE, FALSE, 0);
1841 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_spin, FALSE, FALSE, 0);
1842 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_label, FALSE, FALSE, 0);
1843 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_spin, FALSE, FALSE, 0);
1845 current_window_pass_along [4] = tiles_width_spin;
1846 current_window_pass_along [5] = tiles_height_spin;
1847 g_signal_connect ( G_OBJECT(tiles_width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1848 g_signal_connect ( G_OBJECT(tiles_height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1850 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), total_size_label, FALSE, FALSE, 0);
1851 g_signal_connect ( G_OBJECT(width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1852 g_signal_connect ( G_OBJECT(height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1853 g_signal_connect ( G_OBJECT(zoom_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1855 draw_to_image_file_total_area_cb ( NULL, current_window_pass_along ); /* set correct size info now */
1857 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
1859 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
1861 gtk_widget_hide ( GTK_WIDGET(dialog) );
1862 if ( one_image_only )
1863 save_image_file ( vw, fn,
1864 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1865 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1866 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1867 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ) );
1869 if ( vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM )
1870 save_image_dir ( vw, fn,
1871 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1872 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1873 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1874 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ),
1875 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_width_spin) ),
1876 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_height_spin) ) );
1878 a_dialog_error_msg ( GTK_WINDOW(vw), _("You must be in UTM mode to use this feature") );
1881 gtk_widget_destroy ( GTK_WIDGET(dialog) );
1885 static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw )
1888 if (!vw->save_img_dia) {
1889 vw->save_img_dia = gtk_file_chooser_dialog_new (_("Save Image"),
1891 GTK_FILE_CHOOSER_ACTION_SAVE,
1892 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1893 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1895 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) );
1896 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE );
1899 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_ACCEPT )
1901 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dia) );
1902 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 ) ) )
1904 draw_to_image_file ( vw, fn, TRUE );
1908 gtk_widget_hide ( vw->save_img_dia );
1911 static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw )
1915 if (!vw->save_img_dir_dia) {
1916 vw->save_img_dir_dia = gtk_file_chooser_dialog_new (_("Choose a directory to hold images"),
1918 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1919 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1920 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1922 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) );
1923 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE );
1926 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_ACCEPT )
1928 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dir_dia) );
1931 draw_to_image_file ( vw, fn, FALSE );
1937 gtk_widget_hide ( vw->save_img_dir_dia );
1940 #if GTK_CHECK_VERSION(2,10,0)
1941 static void print_cb ( GtkAction *a, VikWindow *vw )
1943 a_print(vw, vw->viking_vvp);
1947 /* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */
1948 static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWindow *vw )
1950 VikViewportDrawMode drawmode;
1951 if (!strcmp(gtk_action_get_name(a), "ModeUTM")) {
1952 drawmode = VIK_VIEWPORT_DRAWMODE_UTM;
1954 else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) {
1955 drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA;
1957 else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) {
1958 drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
1961 g_critical("Houston, we've had a problem.");
1965 if ( !vw->only_updating_coord_mode_ui )
1967 VikViewportDrawMode olddrawmode = vik_viewport_get_drawmode ( vw->viking_vvp );
1968 if ( olddrawmode != drawmode )
1970 /* this takes care of coord mode too */
1971 vik_viewport_set_drawmode ( vw->viking_vvp, drawmode );
1972 if ( drawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
1973 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_UTM );
1974 } else if ( olddrawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
1975 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_LATLON );
1982 static void set_draw_scale ( GtkAction *a, VikWindow *vw )
1984 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
1985 g_assert(check_box);
1986 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1987 vik_viewport_set_draw_scale ( vw->viking_vvp, state );
1991 static void set_draw_centermark ( GtkAction *a, VikWindow *vw )
1993 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
1994 g_assert(check_box);
1995 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1996 vik_viewport_set_draw_centermark ( vw->viking_vvp, state );
2000 static void set_bg_color ( GtkAction *a, VikWindow *vw )
2002 GtkWidget *colorsd = gtk_color_selection_dialog_new ( _("Choose a background color") );
2003 GdkColor *color = vik_viewport_get_background_gdkcolor ( vw->viking_vvp );
2004 gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2005 gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2006 if ( gtk_dialog_run ( GTK_DIALOG(colorsd) ) == GTK_RESPONSE_OK )
2008 gtk_color_selection_get_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
2009 vik_viewport_set_background_gdkcolor ( vw->viking_vvp, color );
2013 gtk_widget_destroy ( colorsd );
2018 /***********************************************************************************************
2020 ***********************************************************************************************/
2022 static GtkActionEntry entries[] = {
2023 { "File", NULL, N_("_File"), 0, 0, 0 },
2024 { "Edit", NULL, N_("_Edit"), 0, 0, 0 },
2025 { "View", NULL, N_("_View"), 0, 0, 0 },
2026 { "SetZoom", NULL, N_("_Zoom"), 0, 0, 0 },
2027 { "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
2028 { "Layers", NULL, N_("_Layers"), 0, 0, 0 },
2029 { "Tools", NULL, N_("_Tools"), 0, 0, 0 },
2030 { "Exttools", NULL, N_("_Webtools"), 0, 0, 0 },
2031 { "Help", NULL, N_("_Help"), 0, 0, 0 },
2033 { "New", GTK_STOCK_NEW, N_("_New"), "<control>N", N_("New file"), (GCallback)newwindow_cb },
2034 { "Open", GTK_STOCK_OPEN, N_("_Open"), "<control>O", N_("Open a file"), (GCallback)load_file },
2035 { "OpenRecentFile", NULL, N_("Open _Recent file"), NULL, NULL, (GCallback)NULL },
2036 { "Append", GTK_STOCK_ADD, N_("A_ppend File"), NULL, N_("Append data from a different file"), (GCallback)load_file },
2037 { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 },
2038 { "AcquireGPS", NULL, N_("From _GPS"), NULL, N_("Transfer data from a GPS device"), (GCallback)acquire_from_gps },
2039 { "AcquireGoogle", NULL, N_("Google _Directions"), NULL, N_("Get driving directions from Google"), (GCallback)acquire_from_google },
2040 #ifdef VIK_CONFIG_GEOCACHES
2041 { "AcquireGC", NULL, N_("Geo_caches"), NULL, N_("Get Geocaches from geocaching.com"), (GCallback)acquire_from_gc },
2043 { "Save", GTK_STOCK_SAVE, N_("_Save"), "<control>S", N_("Save the file"), (GCallback)save_file },
2044 { "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As"), NULL, N_("Save the file under different name"), (GCallback)save_file_as },
2045 { "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 },
2046 { "GenImgDir", GTK_STOCK_DND_MULTIPLE, N_("Generate _Directory of Images"), NULL, N_("FIXME:IMGDIR"), (GCallback)draw_to_image_dir_cb },
2048 #if GTK_CHECK_VERSION(2,10,0)
2049 { "Print", GTK_STOCK_PRINT, N_("_Print..."), NULL, N_("Print maps"), (GCallback)print_cb },
2052 { "Exit", GTK_STOCK_QUIT, N_("E_xit"), "<control>W", N_("Exit the program"), (GCallback)window_close },
2053 { "SaveExit", GTK_STOCK_QUIT, N_("Save and Exit"), NULL, N_("Save and Exit the program"), (GCallback)save_file_and_exit },
2055 { "GotoSearch", GTK_STOCK_JUMP_TO, N_("Go To location"), NULL, N_("Go to address/place using text search"), (GCallback)goto_address },
2056 { "GotoLL", GTK_STOCK_JUMP_TO, N_("_Go to Lat\\/Lon..."), NULL, N_("Go to arbitrary lat\\/lon coordinate"), (GCallback)draw_goto_cb },
2057 { "GotoUTM", GTK_STOCK_JUMP_TO, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb },
2058 { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."), NULL, NULL, (GCallback)set_bg_color },
2059 { "ZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus", NULL, (GCallback)draw_zoom_cb },
2060 { "ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus", NULL, (GCallback)draw_zoom_cb },
2061 { "ZoomTo", GTK_STOCK_ZOOM_FIT, N_("Zoom _To"), "<control>Z", NULL, (GCallback)zoom_to_cb },
2062 { "Zoom0.25", NULL, N_("0.25"), NULL, NULL, (GCallback)draw_zoom_cb },
2063 { "Zoom0.5", NULL, N_("0.5"), NULL, NULL, (GCallback)draw_zoom_cb },
2064 { "Zoom1", NULL, N_("1"), NULL, NULL, (GCallback)draw_zoom_cb },
2065 { "Zoom2", NULL, N_("2"), NULL, NULL, (GCallback)draw_zoom_cb },
2066 { "Zoom4", NULL, N_("4"), NULL, NULL, (GCallback)draw_zoom_cb },
2067 { "Zoom8", NULL, N_("8"), NULL, NULL, (GCallback)draw_zoom_cb },
2068 { "Zoom16", NULL, N_("16"), NULL, NULL, (GCallback)draw_zoom_cb },
2069 { "Zoom32", NULL, N_("32"), NULL, NULL, (GCallback)draw_zoom_cb },
2070 { "Zoom64", NULL, N_("64"), NULL, NULL, (GCallback)draw_zoom_cb },
2071 { "Zoom128", NULL, N_("128"), NULL, NULL, (GCallback)draw_zoom_cb },
2072 { "PanNorth", NULL, N_("Pan North"), "<control>Up", NULL, (GCallback)draw_pan_cb },
2073 { "PanEast", NULL, N_("Pan East"), "<control>Right", NULL, (GCallback)draw_pan_cb },
2074 { "PanSouth", NULL, N_("Pan South"), "<control>Down", NULL, (GCallback)draw_pan_cb },
2075 { "PanWest", NULL, N_("Pan West"), "<control>Left", NULL, (GCallback)draw_pan_cb },
2076 { "BGJobs", GTK_STOCK_EXECUTE, N_("Background _Jobs"), NULL, NULL, (GCallback)a_background_show_window },
2078 { "Cut", GTK_STOCK_CUT, N_("Cu_t"), NULL, NULL, (GCallback)menu_cut_layer_cb },
2079 { "Copy", GTK_STOCK_COPY, N_("_Copy"), NULL, NULL, (GCallback)menu_copy_layer_cb },
2080 { "Paste", GTK_STOCK_PASTE, N_("_Paste"), NULL, NULL, (GCallback)menu_paste_layer_cb },
2081 { "Delete", GTK_STOCK_DELETE, N_("_Delete"), NULL, NULL, (GCallback)menu_delete_layer_cb },
2082 { "DeleteAll", NULL, N_("Delete All"), NULL, NULL, (GCallback)clear_cb },
2083 { "MapCacheFlush",NULL, N_("Flush Map cache"), NULL, NULL, (GCallback)mapcache_flush_cb },
2084 { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences..."), NULL, NULL, (GCallback)preferences_cb },
2085 { "Properties",GTK_STOCK_PROPERTIES, N_("_Properties"), NULL, NULL, (GCallback)menu_properties_cb },
2087 { "About", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, (GCallback)help_about_cb },
2091 static GtkRadioActionEntry mode_entries[] = {
2092 { "ModeUTM", NULL, N_("_UTM Mode"), "<control>u", NULL, 0 },
2093 { "ModeExpedia", NULL, N_("_Expedia Mode"), "<control>e", NULL, 1 },
2094 { "ModeMercator", NULL, N_("_Mercator Mode"), "<control>g", NULL, 4 }
2097 static GtkRadioActionEntry tool_entries[] = {
2098 { "Pan", "vik-icon-pan", N_("_Pan"), "<control><shift>P", N_("Pan Tool"), 0 },
2099 { "Zoom", "vik-icon-zoom", N_("_Zoom"), "<control><shift>Z", N_("Zoom Tool"), 1 },
2100 { "Ruler", "vik-icon-ruler", N_("_Ruler"), "<control><shift>R", N_("Ruler Tool"), 2 }
2103 static GtkToggleActionEntry toggle_entries[] = {
2104 { "ShowScale", NULL, N_("Show Scale"), NULL, N_("Show Scale"), (GCallback)set_draw_scale, TRUE },
2105 { "ShowCenterMark", NULL, N_("Show Center Mark"), NULL, N_("Show Center Mark"), (GCallback)set_draw_centermark, TRUE },
2106 { "FullScreen", GTK_STOCK_FULLSCREEN, N_("Full Screen"), "F11", N_("Activate full screen mode"), (GCallback)full_screen_cb, FALSE },
2107 { "ViewSidePanel", GTK_STOCK_INDEX, N_("Show Side Panel"), "F9", N_("Show Side Panel"), (GCallback)view_side_panel_cb, TRUE },
2110 #include "menu.xml.h"
2111 static void window_create_ui( VikWindow *window )
2114 GtkActionGroup *action_group;
2115 GtkAccelGroup *accel_group;
2118 GtkIconFactory *icon_factory;
2119 GtkIconSet *icon_set;
2120 GtkRadioActionEntry *tools = NULL, *radio;
2123 uim = gtk_ui_manager_new ();
2126 toolbox_add_tool(window->vt, &ruler_tool, TOOL_LAYER_TYPE_NONE);
2127 toolbox_add_tool(window->vt, &zoom_tool, TOOL_LAYER_TYPE_NONE);
2128 toolbox_add_tool(window->vt, &pan_tool, TOOL_LAYER_TYPE_NONE);
2131 if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) {
2132 g_error_free (error);
2136 action_group = gtk_action_group_new ("MenuActions");
2137 gtk_action_group_set_translation_domain(action_group, PACKAGE_NAME);
2138 gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
2139 gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
2140 gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window);
2142 icon_factory = gtk_icon_factory_new ();
2143 gtk_icon_factory_add_default (icon_factory);
2145 register_vik_icons(icon_factory);
2148 for (i=0; i<G_N_ELEMENTS(tool_entries); i++) {
2149 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2150 radio = &tools[ntools];
2152 *radio = tool_entries[i];
2153 radio->value = ntools;
2156 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2157 GtkActionEntry action;
2158 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Layers/",
2159 vik_layer_get_interface(i)->name,
2160 vik_layer_get_interface(i)->name,
2161 GTK_UI_MANAGER_MENUITEM, FALSE);
2163 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (vik_layer_get_interface(i)->icon, FALSE, NULL ));
2164 gtk_icon_factory_add (icon_factory, vik_layer_get_interface(i)->name, icon_set);
2165 gtk_icon_set_unref (icon_set);
2167 action.name = vik_layer_get_interface(i)->name;
2168 action.stock_id = vik_layer_get_interface(i)->name;
2169 action.label = g_strdup_printf( _("New %s Layer"), vik_layer_get_interface(i)->name);
2170 action.accelerator = NULL;
2171 action.tooltip = NULL;
2172 action.callback = (GCallback)menu_addlayer_cb;
2173 gtk_action_group_add_actions(action_group, &action, 1, window);
2175 if ( vik_layer_get_interface(i)->tools_count ) {
2176 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2177 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2180 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2181 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2182 radio = &tools[ntools];
2185 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools",
2186 _(vik_layer_get_interface(i)->tools[j].name),
2187 vik_layer_get_interface(i)->tools[j].name,
2188 GTK_UI_MANAGER_MENUITEM, FALSE);
2189 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems",
2190 _(vik_layer_get_interface(i)->tools[j].name),
2191 vik_layer_get_interface(i)->tools[j].name,
2192 GTK_UI_MANAGER_TOOLITEM, FALSE);
2194 toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i);
2196 radio->name = vik_layer_get_interface(i)->tools[j].name;
2197 radio->stock_id = vik_layer_get_interface(i)->tools[j].name,
2198 radio->label = _(vik_layer_get_interface(i)->tools[j].name);
2199 radio->accelerator = NULL;
2200 radio->tooltip = _(vik_layer_get_interface(i)->tools[j].name);
2201 radio->value = ntools;
2204 g_object_unref (icon_factory);
2206 gtk_action_group_add_radio_actions(action_group, tools, ntools, 0, (GCallback)menu_tool_cb, window);
2209 gtk_ui_manager_insert_action_group (uim, action_group, 0);
2211 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2212 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2213 GtkAction *action = gtk_action_group_get_action(action_group,
2214 vik_layer_get_interface(i)->tools[j].name);
2215 g_object_set(action, "sensitive", FALSE, NULL);
2218 window->action_group = action_group;
2220 accel_group = gtk_ui_manager_get_accel_group (uim);
2221 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
2222 gtk_ui_manager_ensure_update (uim);
2224 setup_recent_files(window);
2230 const GdkPixdata *data;
2233 { &begintr_18_pixbuf, "Begin Track" },
2234 { &iscissors_18_pixbuf, "Magic Scissors" },
2235 { &mover_22_pixbuf, "vik-icon-pan" },
2236 { &demdl_18_pixbuf, "DEM Download/Import" },
2237 { &showpic_18_pixbuf, "Show Picture" },
2238 { &addtr_18_pixbuf, "Create Track" },
2239 { &edtr_18_pixbuf, "Edit Trackpoint" },
2240 { &addwp_18_pixbuf, "Create Waypoint" },
2241 { &edwp_18_pixbuf, "Edit Waypoint" },
2242 { &zoom_18_pixbuf, "vik-icon-zoom" },
2243 { &ruler_18_pixbuf, "vik-icon-ruler" },
2244 { &geozoom_18_pixbuf, "Georef Zoom Tool" },
2245 { &geomove_18_pixbuf, "Georef Move Map" },
2246 { &mapdl_18_pixbuf, "Maps Download" },
2247 { &showpic_18_pixbuf, "Show Picture" },
2250 static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
2253 register_vik_icons (GtkIconFactory *icon_factory)
2255 GtkIconSet *icon_set;
2258 for (i = 0; i < n_stock_icons; i++) {
2259 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (
2260 stock_icons[i].data, FALSE, NULL ));
2261 gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set);
2262 gtk_icon_set_unref (icon_set);