2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "background.h"
24 #include "datasources.h"
26 #define VIKING_TITLE " - Viking " VIKING_VERSION " " VIKING_VERSION_NAME " " VIKING_URL
28 #include <glib/gprintf.h>
33 #include <glib/gprintf.h>
35 /* TODO IMPORTANT: mkdir for windows header? is it called 'mkdir' */
36 #define make_dir(dir) mkdir(dir)
38 #include <sys/types.h>
40 #define make_dir(dir) mkdir(dir,0777)
43 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
44 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024
45 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
47 static void window_finalize ( GObject *gob );
48 static GObjectClass *parent_class;
50 static void window_init ( VikWindow *vw );
51 static void window_class_init ( VikWindowClass *klass );
53 static void draw_update ( VikWindow *vw );
55 static void newwindow_cb ( GtkAction *a, VikWindow *vw );
59 static gboolean delete_event( VikWindow *vw );
61 static void draw_sync ( VikWindow *vw );
62 static void draw_redraw ( VikWindow *vw );
63 static void draw_scroll ( VikWindow *vw, GdkEventScroll *event );
64 static void draw_click ( VikWindow *vw, GdkEventButton *event );
65 static void draw_release ( VikWindow *vw, GdkEventButton *event );
66 static void draw_mouse_motion ( VikWindow *vw, GdkEventMotion *event );
67 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw );
68 static void draw_goto_cb ( GtkAction *a, VikWindow *vw );
70 static void draw_status ();
72 /* End Drawing Functions */
74 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw );
75 static void menu_properties_cb ( GtkAction *a, VikWindow *vw );
76 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw );
87 toolbox_tool_t *tools;
91 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw );
92 static toolbox_tools_t* toolbox_create(VikWindow *vw);
93 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti);
94 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
95 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
96 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
97 static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event);
98 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
102 static void window_create_ui( VikWindow *window );
103 static void register_vik_icons (GtkIconFactory *icon_factory);
106 static void load_file ( GtkAction *a, VikWindow *vw );
107 static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
108 static gboolean save_file ( GtkAction *a, VikWindow *vw );
109 static gboolean window_save ( VikWindow *vw );
113 VikViewport *viking_vvp;
114 VikLayersPanel *viking_vlp;
115 VikStatusbar *viking_vs;
119 GtkItemFactory *item_factory;
121 /* tool management state */
124 guint16 tool_layer_id;
125 guint16 tool_tool_id;
129 guint draw_image_width, draw_image_height;
130 gboolean draw_image_save_as_png;
135 GtkWidget *open_dia, *save_dia;
137 gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
150 VW_OPENWINDOW_SIGNAL,
154 static guint window_signals[VW_LAST_SIGNAL] = { 0 };
156 static gchar *tool_names[NUMBER_OF_TOOLS] = { "Zoom", "Ruler", "Pan" };
158 GType vik_window_get_type (void)
160 static GType vw_type = 0;
164 static const GTypeInfo vw_info =
166 sizeof (VikWindowClass),
167 NULL, /* base_init */
168 NULL, /* base_finalize */
169 (GClassInitFunc) window_class_init, /* class_init */
170 NULL, /* class_finalize */
171 NULL, /* class_data */
174 (GInstanceInitFunc) window_init,
176 vw_type = g_type_register_static ( GTK_TYPE_WINDOW, "VikWindow", &vw_info, 0 );
182 static void window_finalize ( GObject *gob )
184 VikWindow *vw = VIK_WINDOW(gob);
185 g_return_if_fail ( vw != NULL );
187 a_background_remove_status ( vw->viking_vs );
189 G_OBJECT_CLASS(parent_class)->finalize(gob);
192 static void window_class_init ( VikWindowClass *klass )
195 GObjectClass *object_class;
197 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);
198 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);
200 object_class = G_OBJECT_CLASS (klass);
202 object_class->finalize = window_finalize;
204 parent_class = g_type_class_peek_parent (klass);
208 static void window_init ( VikWindow *vw )
210 GtkWidget *main_vbox;
214 vw->viking_vvp = vik_viewport_new();
215 vw->viking_vlp = vik_layers_panel_new();
216 vik_layers_panel_set_viewport ( vw->viking_vlp, vw->viking_vvp );
217 vw->viking_vs = vik_statusbar_new();
219 vw->vt = toolbox_create(vw);
220 window_create_ui(vw);
221 gtk_window_set_title ( GTK_WINDOW(vw), "Untitled" VIKING_TITLE );
223 toolbox_activate(vw->vt, "Zoom");
226 vw->item_factory = NULL;
228 vw->modified = FALSE;
229 vw->only_updating_coord_mode_ui = FALSE;
232 vw->pan_x = vw->pan_y = -1;
233 vw->draw_image_width = DRAW_IMAGE_DEFAULT_WIDTH;
234 vw->draw_image_height = DRAW_IMAGE_DEFAULT_HEIGHT;
235 vw->draw_image_save_as_png = DRAW_IMAGE_DEFAULT_SAVE_AS_PNG;
237 main_vbox = gtk_vbox_new(FALSE, 1);
238 gtk_container_add (GTK_CONTAINER (vw), main_vbox);
240 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainMenu"), FALSE, TRUE, 0);
241 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainToolbar"), FALSE, TRUE, 0);
242 gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
243 gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
245 g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
247 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw);
248 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(draw_redraw), vw);
249 gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
250 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw);
251 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw);
252 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw);
253 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
254 g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
256 gtk_window_set_default_size ( GTK_WINDOW(vw), 1000, 800);
258 hpaned = gtk_hpaned_new ();
259 gtk_paned_add1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp) );
260 gtk_paned_add2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp) );
262 /* This packs the button into the window (a gtk container). */
263 gtk_box_pack_start (GTK_BOX(main_vbox), hpaned, TRUE, TRUE, 0);
265 gtk_box_pack_end (GTK_BOX(main_vbox), GTK_WIDGET(vw->viking_vs), FALSE, TRUE, 0);
267 a_background_add_status(vw->viking_vs);
273 VikWindow *vik_window_new ()
275 return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
278 static gboolean delete_event( VikWindow *vw )
283 dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
284 "Do you want to save the changes you made to the document \"%s\"?\n\nYour changes will be lost if you don't save them.",
285 vw->filename ? a_file_basename ( vw->filename ) : "Untitled" ) );
286 gtk_dialog_add_buttons ( dia, "Don't Save", GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
287 switch ( gtk_dialog_run ( dia ) )
289 case GTK_RESPONSE_NO: gtk_widget_destroy ( GTK_WIDGET(dia) ); return FALSE;
290 case GTK_RESPONSE_CANCEL: gtk_widget_destroy ( GTK_WIDGET(dia) ); return TRUE;
291 default: gtk_widget_destroy ( GTK_WIDGET(dia) ); return ! save_file(NULL, vw);
298 static void newwindow_cb ( GtkAction *a, VikWindow *vw )
300 g_signal_emit ( G_OBJECT(vw), window_signals[VW_NEWWINDOW_SIGNAL], 0 );
303 static void draw_update ( VikWindow *vw )
309 static void draw_sync ( VikWindow *vw )
311 vik_viewport_sync(vw->viking_vvp);
313 /* other things may be necc here later. */
316 static void draw_status ( VikWindow *vw )
318 static gchar zoom_level[22];
319 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" );
320 if ( vw->current_tool == TOOL_LAYER )
321 vik_statusbar_set_message ( vw->viking_vs, 0, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name );
323 vik_statusbar_set_message ( vw->viking_vs, 0, tool_names[vw->current_tool] );
325 vik_statusbar_set_message ( vw->viking_vs, 2, zoom_level );
328 static void draw_redraw ( VikWindow *vw )
330 vik_viewport_clear ( vw->viking_vvp);
331 vik_layers_panel_draw_all ( vw->viking_vlp );
332 vik_viewport_draw_scale ( vw->viking_vvp );
335 gboolean draw_buf_done = TRUE;
337 static gboolean draw_buf(gpointer data)
339 gpointer *pass_along = data;
341 gdk_draw_drawable (pass_along[0], pass_along[1],
342 pass_along[2], 0, 0, 0, 0, -1, -1);
343 draw_buf_done = TRUE;
349 /* Mouse event handlers ************************************************************************/
351 static void draw_click (VikWindow *vw, GdkEventButton *event)
354 /* middle button pressed. we reserve all middle button and scroll events
355 * for panning and zooming; tools only get left/right/movement
357 if ( event->button == 2) {
358 /* set panning origin */
359 vw->pan_x = (gint) event->x;
360 vw->pan_y = (gint) event->y;
363 toolbox_click(vw->vt, event);
367 static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
369 static VikCoord coord;
370 static struct UTM utm;
371 static struct LatLon ll;
372 static char pointer_buf[36];
374 toolbox_move(vw->vt, (GdkEventButton *)event);
376 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
377 vik_coord_to_utm ( &coord, &utm );
378 a_coords_utm_to_latlon ( &utm, &ll );
379 g_snprintf ( pointer_buf, 36, "Cursor: %f %f", ll.lat, ll.lon );
380 vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
382 if ( vw->pan_x != -1 ) {
383 vik_viewport_pan_sync ( vw->viking_vvp, event->x - vw->pan_x, event->y - vw->pan_y );
387 static void draw_release ( VikWindow *vw, GdkEventButton *event )
389 if ( event->button == 2 ) { /* move / pan */
390 if ( ABS(vw->pan_x - event->x) <= 1 && ABS(vw->pan_y - event->y) <= 1 )
391 vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
393 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
394 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
396 vw->pan_x = vw->pan_y = -1;
399 toolbox_release(vw->vt, event);
403 static void draw_scroll (VikWindow *vw, GdkEventScroll *event)
405 if ( event->direction == GDK_SCROLL_UP )
406 vik_viewport_zoom_in (vw->viking_vvp);
408 vik_viewport_zoom_out(vw->viking_vvp);
414 /********************************************************************************
416 ********************************************************************************/
417 static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gdouble distance)
419 PangoFontDescription *pfd;
422 GdkGC *labgc = vik_viewport_new_gc ( vvp, "#cccccc", 1);
423 GdkGC *thickgc = gdk_gc_new(d);
425 gdouble len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
426 gdouble dx = (x2-x1)/len*10;
427 gdouble dy = (y2-y1)/len*10;
428 gdouble c = cos(15.0 * M_PI/180.0);
429 gdouble s = sin(15.0 * M_PI/180.0);
431 gdouble baseangle = 0;
434 /* draw line with arrow ends */
436 gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
437 a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
438 gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
441 a_viewport_clip_line(&x1, &y1, &x2, &y2);
442 gdk_draw_line(d, gc, x1, y1, x2, y2);
444 gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
445 gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
446 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));
447 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c - dy * s), y2 - (dy * c + dx * s));
448 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c + dy * s), y1 + (dy * c - dx * s));
449 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c - dy * s), y1 + (dy * c + dx * s));
454 angle = atan2(dy, dx) + M_PI_2;
456 if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
462 vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
463 vik_coord_to_latlon ( &test, &ll );
464 ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
465 a_coords_latlon_to_utm ( &ll, &u );
466 vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
467 vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
469 baseangle = M_PI - atan2(tx-x1, ty-y1);
480 gdk_gc_copy(thickgc, gc);
481 gdk_gc_set_line_attributes(thickgc, CW, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
482 gdk_color_parse("#2255cc", &color);
483 gdk_gc_set_rgb_fg_color(thickgc, &color);
485 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);
488 gdk_gc_copy(thickgc, gc);
489 gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
490 for (i=0; i<180; i++) {
491 c = cos(i*M_PI/90.0 + baseangle);
492 s = sin(i*M_PI/90.0 + baseangle);
495 gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
497 gdouble ticksize = 2*CW;
498 gdk_draw_line (d, thickgc, x1 + (CR-CW)*c, y1 + (CR-CW)*s, x1 + (CR+ticksize)*c, y1 + (CR+ticksize)*s);
502 gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
503 gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
504 gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
505 c = (CR+CW*2)*cos(baseangle);
506 s = (CR+CW*2)*sin(baseangle);
507 gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
508 gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
511 #define LABEL(x, y, w, h) { \
512 gdk_draw_rectangle(d, labgc, TRUE, (x)-2, (y)-1, (w)+4, (h)+1); \
513 gdk_draw_rectangle(d, gc, FALSE, (x)-2, (y)-1, (w)+4, (h)+1); \
514 gdk_draw_layout(d, gc, (x), (y), pl); }
519 pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
521 pfd = pango_font_description_from_string ("Sans 8"); // FIXME: settable option? global variable?
522 pango_layout_set_font_description (pl, pfd);
523 pango_font_description_free (pfd);
525 pango_layout_set_text(pl, "N", -1);
526 gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
528 /* draw label with distance */
529 if (distance >= 1000 && distance < 100000) {
530 g_sprintf(str, "%3.2f km", distance/1000.0);
531 } else if (distance < 1000) {
532 g_sprintf(str, "%d m", (int)distance);
534 g_sprintf(str, "%d km", (int)distance/1000);
536 pango_layout_set_text(pl, str, -1);
538 pango_layout_get_pixel_size ( pl, &wd, &hd );
541 yd = (y1+y2)/2 - hd/2 - dx;
544 yd = (y1+y2)/2 - hd/2 + dx;
547 if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
552 LABEL(xd, yd, wd, hd);
554 /* draw label with bearing */
555 g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
556 pango_layout_set_text(pl, str, -1);
557 pango_layout_get_pixel_size ( pl, &wb, &hb );
558 xb = x1 + CR*cos(angle-M_PI_2);
559 yb = y1 + CR*sin(angle-M_PI_2);
561 if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
567 GdkRectangle r1 = {xd-2, yd-1, wd+4, hd+1}, r2 = {xb-2, yb-1, wb+4, hb+1};
568 if (gdk_rectangle_intersect(&r1, &r2, &r2)) {
572 LABEL(xb, yb, wb, hb);
576 g_object_unref ( G_OBJECT ( pl ) );
577 g_object_unref ( G_OBJECT ( labgc ) );
578 g_object_unref ( G_OBJECT ( thickgc ) );
584 gboolean has_oldcoord;
586 } ruler_tool_state_t;
588 static gpointer ruler_create (VikWindow *vw, VikViewport *vvp)
590 ruler_tool_state_t *s = g_new(ruler_tool_state_t, 1);
593 s->has_oldcoord = FALSE;
597 static void ruler_destroy (ruler_tool_state_t *s)
602 static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
607 if ( event->button == 1 ) {
608 vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
609 vik_coord_to_latlon ( &coord, &ll );
610 if ( s->has_oldcoord ) {
611 temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
612 s->has_oldcoord = FALSE;
615 temp = g_strdup_printf ( "%f %f", ll.lat, ll.lon );
616 s->has_oldcoord = TRUE;
619 vik_statusbar_set_message ( s->vw->viking_vs, 3, temp );
625 vik_viewport_set_center_screen ( s->vvp, (gint) event->x, (gint) event->y );
626 draw_update ( s->vw );
628 return VIK_LAYER_TOOL_ACK;
631 static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
633 VikViewport *vvp = s->vvp;
634 VikWindow *vw = s->vw;
640 if ( s->has_oldcoord ) {
641 int oldx, oldy, w1, h1, w2, h2;
642 static GdkPixmap *buf = NULL;
643 w1 = vik_viewport_get_width(vvp);
644 h1 = vik_viewport_get_height(vvp);
646 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
648 gdk_drawable_get_size(buf, &w2, &h2);
649 if (w1 != w2 || h1 != h2) {
650 g_object_unref ( G_OBJECT ( buf ) );
651 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
654 vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
655 vik_coord_to_latlon ( &coord, &ll );
656 vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
658 gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc,
659 vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
660 draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
662 static gpointer pass_along[3];
663 pass_along[0] = GTK_WIDGET(vvp)->window;
664 pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
666 g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
667 draw_buf_done = FALSE;
670 temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
671 vik_statusbar_set_message ( vw->viking_vs, 3, temp );
674 return VIK_LAYER_TOOL_ACK;
677 static VikLayerToolFuncStatus ruler_release (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
679 return VIK_LAYER_TOOL_ACK;
682 static void ruler_deactivate (VikLayer *vl, ruler_tool_state_t *s)
684 draw_update ( s->vw );
687 static VikToolInterface ruler_tool =
689 (VikToolConstructorFunc) ruler_create,
690 (VikToolDestructorFunc) ruler_destroy,
691 (VikToolActivationFunc) NULL,
692 (VikToolActivationFunc) ruler_deactivate,
693 (VikToolMouseFunc) ruler_click,
694 (VikToolMouseFunc) ruler_move,
695 (VikToolMouseFunc) ruler_release };
696 /*** end ruler code ********************************************************/
700 /********************************************************************************
702 ********************************************************************************/
703 static gpointer zoomtool_create (VikWindow *vw, VikViewport *vvp)
708 static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
711 vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
712 if ( event->button == 1 )
713 vik_viewport_zoom_in (vw->viking_vvp);
714 else if ( event->button == 3 )
715 vik_viewport_zoom_out (vw->viking_vvp);
717 return VIK_LAYER_TOOL_ACK;
720 static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
722 return VIK_LAYER_TOOL_ACK;
725 static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
727 return VIK_LAYER_TOOL_ACK;
730 static VikToolInterface zoom_tool =
732 (VikToolConstructorFunc) zoomtool_create,
733 (VikToolDestructorFunc) NULL,
734 (VikToolActivationFunc) NULL,
735 (VikToolActivationFunc) NULL,
736 (VikToolMouseFunc) zoomtool_click,
737 (VikToolMouseFunc) zoomtool_move,
738 (VikToolMouseFunc) zoomtool_release };
739 /*** end ruler code ********************************************************/
743 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw )
747 if (!strcmp(gtk_action_get_name(a), "ZoomIn")) {
750 else if (!strcmp(gtk_action_get_name(a), "ZoomOut")) {
753 else if (!strcmp(gtk_action_get_name(a), "Zoom0.25")) {
756 else if (!strcmp(gtk_action_get_name(a), "Zoom0.5")) {
760 gchar *s = (gchar *)gtk_action_get_name(a);
766 case -3: vik_viewport_zoom_in ( vw->viking_vvp ); break;
767 case -4: vik_viewport_zoom_out ( vw->viking_vvp ); break;
768 case -1: vik_viewport_set_zoom ( vw->viking_vvp, 0.5 ); break;
769 case -2: vik_viewport_set_zoom ( vw->viking_vvp, 0.25 ); break;
770 default: vik_viewport_set_zoom ( vw->viking_vvp, what );
775 void draw_goto_cb ( GtkAction *a, VikWindow *vw )
779 if (!strcmp(gtk_action_get_name(a), "GotoLL")) {
780 struct LatLon ll, llold;
781 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &llold );
782 if ( a_dialog_goto_latlon ( GTK_WINDOW(vw), &ll, &llold ) )
783 vik_coord_load_from_latlon ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &ll );
787 else if (!strcmp(gtk_action_get_name(a), "GotoUTM")) {
788 struct UTM utm, utmold;
789 vik_coord_to_utm ( vik_viewport_get_center ( vw->viking_vvp ), &utmold );
790 if ( a_dialog_goto_utm ( GTK_WINDOW(vw), &utm, &utmold ) )
791 vik_coord_load_from_utm ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &utm );
796 fprintf(stderr, "Houston we have a problem\n");
800 vik_viewport_set_center_coord ( vw->viking_vvp, &new_center );
804 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw )
807 for ( type = 0; type < VIK_LAYER_NUM_TYPES; type++ ) {
808 if (!strcmp(vik_layer_get_interface(type)->name, gtk_action_get_name(a))) {
809 if ( vik_layers_panel_new_layer ( vw->viking_vlp, type ) ) {
817 static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw )
819 a_clipboard_copy ( vw->viking_vlp );
822 static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw )
824 a_clipboard_copy ( vw->viking_vlp );
825 menu_delete_layer_cb ( a, vw );
828 static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw )
830 if ( a_clipboard_paste ( vw->viking_vlp ) )
837 static void menu_properties_cb ( GtkAction *a, VikWindow *vw )
839 if ( ! vik_layers_panel_properties ( vw->viking_vlp ) )
840 a_dialog_info_msg ( GTK_WINDOW(vw), "You must select a layer to show its properties." );
843 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
845 if ( vik_layers_panel_get_selected ( vw->viking_vlp ) )
847 vik_layers_panel_delete_selected ( vw->viking_vlp );
851 a_dialog_info_msg ( GTK_WINDOW(vw), "You must select a layer to delete." );
854 /***************************************
855 ** tool management routines
857 ***************************************/
859 static toolbox_tools_t* toolbox_create(VikWindow *vw)
861 toolbox_tools_t *vt = g_new(toolbox_tools_t, 1);
864 vt->active_tool = -1;
866 if (!vw->viking_vvp) {
867 printf("Error: no viewport found.\n");
873 static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti)
875 vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1);
876 vt->tools[vt->n_tools].ti = *vti;
878 vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp);
881 vt->tools[vt->n_tools].state = NULL;
886 static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name)
889 for (i=0; i<vt->n_tools; i++) {
890 if (!strcmp(tool_name, vt->tools[i].ti.name)) {
897 static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name)
899 int tool = toolbox_get_tool(vt, tool_name);
900 toolbox_tool_t *t = &vt->tools[tool];
901 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
903 if (tool == vt->n_tools) {
904 printf("panic: trying to activate a non-existent tool... \n");
907 /* is the tool already active? */
908 if (vt->active_tool == tool) {
912 if (vt->active_tool != -1) {
913 if (vt->tools[vt->active_tool].ti.deactivate) {
914 vt->tools[vt->active_tool].ti.deactivate(NULL, vt->tools[vt->active_tool].state);
917 if (t->ti.activate) {
918 t->ti.activate(vl, t->state);
920 vt->active_tool = tool;
923 static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
925 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
926 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) {
927 vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state);
931 static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event)
933 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
934 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) {
935 vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state);
939 static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event)
941 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
942 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release) {
943 vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state);
946 /** End tool management ************************************/
950 /* this function gets called whenever a toolbar tool is clicked */
951 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
953 /* White Magic, my friends ... White Magic... */
956 toolbox_activate(vw->vt, gtk_action_get_name(a));
958 if (!strcmp(gtk_action_get_name(a), "Zoom")) {
959 vw->current_tool = TOOL_ZOOM;
961 else if (!strcmp(gtk_action_get_name(a), "Ruler")) {
962 vw->current_tool = TOOL_RULER;
965 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
966 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
967 if (!strcmp(vik_layer_get_interface(i)->tools[j].name, gtk_action_get_name(a))) {
968 vw->current_tool = TOOL_LAYER;
969 vw->tool_layer_id = i;
970 vw->tool_tool_id = j;
978 static void window_set_filename ( VikWindow *vw, const gchar *filename )
982 g_free ( vw->filename );
983 if ( filename == NULL )
986 gtk_window_set_title ( GTK_WINDOW(vw), "Untitled" VIKING_TITLE );
990 vw->filename = g_strdup(filename);
991 title = g_strconcat ( a_file_basename ( filename ), VIKING_TITLE, NULL );
992 gtk_window_set_title ( GTK_WINDOW(vw), title );
997 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename )
999 switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) )
1002 a_dialog_error_msg ( GTK_WINDOW(vw), "The file you requested could not be opened." );
1006 GtkWidget *mode_button;
1008 if ( change_filename )
1009 window_set_filename ( vw, filename );
1010 switch ( vik_viewport_get_drawmode ( vw->viking_vvp ) ) {
1011 case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break;
1012 case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
1013 case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break;
1014 default: buttonname = "/ui/MainMenu/View/ModeKH";
1016 mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
1017 g_assert ( mode_button );
1018 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. */
1019 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE );
1020 vw->only_updating_coord_mode_ui = FALSE;
1022 vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) );
1024 default: draw_update ( vw );
1028 static void load_file ( GtkAction *a, VikWindow *vw )
1031 if (!strcmp(gtk_action_get_name(a), "Open")) {
1034 else if (!strcmp(gtk_action_get_name(a), "Append")) {
1038 fprintf(stderr, "Houston we got a problem\n");
1042 if ( ! vw->open_dia )
1044 vw->open_dia = gtk_file_selection_new ("Please select a GPS data file to open. " );
1045 gtk_file_selection_set_select_multiple ( GTK_FILE_SELECTION(vw->open_dia), TRUE );
1046 gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) );
1047 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE );
1049 if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_OK )
1051 gtk_widget_hide ( vw->open_dia );
1052 if ( (vw->modified || vw->filename) && newwindow )
1053 g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ) );
1055 gchar **files = gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) );
1056 gboolean change_fn = newwindow && (!files[1]); /* only change fn if one file */
1058 vik_window_open_file ( vw, *files, change_fn );
1064 gtk_widget_hide ( vw->open_dia );
1067 static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
1069 gboolean rv = FALSE;
1071 if ( ! vw->save_dia )
1073 vw->save_dia = gtk_file_selection_new ("Save as Viking File. " );
1074 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) );
1075 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
1078 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_OK )
1080 fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_dia) );
1081 if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_dia), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn ) ) )
1083 window_set_filename ( vw, fn );
1084 rv = window_save ( vw );
1085 vw->modified = FALSE;
1089 gtk_widget_hide ( vw->save_dia );
1093 static gboolean window_save ( VikWindow *vw )
1095 if ( a_file_save ( vik_layers_panel_get_top_layer ( vw->viking_vlp ), vw->viking_vvp, vw->filename ) )
1099 a_dialog_error_msg ( GTK_WINDOW(vw), "The filename you requested could not be opened for writing." );
1104 static gboolean save_file ( GtkAction *a, VikWindow *vw )
1106 if ( ! vw->filename )
1107 return save_file_as ( NULL, vw );
1110 vw->modified = FALSE;
1111 return window_save ( vw );
1115 static void acquire_from_gps ( GtkAction *a, VikWindow *vw )
1117 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface );
1120 static void acquire_from_google ( GtkAction *a, VikWindow *vw )
1122 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
1125 static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
1127 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface );
1130 static void clear_cb ( GtkAction *a, VikWindow *vw )
1132 vik_layers_panel_clear ( vw->viking_vlp );
1133 window_set_filename ( vw, NULL );
1137 static void window_close ( GtkAction *a, VikWindow *vw )
1139 if ( ! delete_event ( vw ) )
1140 gtk_widget_destroy ( GTK_WIDGET(vw) );
1143 static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
1145 gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1146 if ( a_dialog_custom_zoom ( GTK_WINDOW(vw), &xmpp, &ympp ) )
1148 vik_viewport_set_xmpp ( vw->viking_vvp, xmpp );
1149 vik_viewport_set_ympp ( vw->viking_vvp, ympp );
1154 static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h, gdouble zoom, gboolean save_as_png )
1156 /* more efficient way: stuff draws directly to pixbuf (fork viewport) */
1157 GdkPixbuf *pixbuf_to_save;
1158 gdouble old_xmpp, old_ympp;
1159 GError *error = NULL;
1161 /* backup old zoom & set new */
1162 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1163 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1164 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1166 /* reset width and height: */
1167 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1169 /* draw all layers */
1172 /* save buffer as file. */
1173 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);
1174 gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL );
1177 fprintf(stderr, "Unable to write to file %s: %s", fn, error->message );
1178 g_error_free (error);
1180 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1182 /* pretend like nothing happened ;) */
1183 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1184 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1185 vik_viewport_configure ( vw->viking_vvp );
1189 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 )
1191 gulong size = sizeof(gchar) * (strlen(fn) + 15);
1192 gchar *name_of_file = g_malloc ( size );
1194 struct UTM utm_orig, utm;
1196 /* *** copied from above *** */
1197 GdkPixbuf *pixbuf_to_save;
1198 gdouble old_xmpp, old_ympp;
1199 GError *error = NULL;
1201 /* backup old zoom & set new */
1202 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1203 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1204 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1206 /* reset width and height: do this only once for all images (same size) */
1207 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1208 /* *** end copy from above *** */
1210 g_assert ( vik_viewport_get_coord_mode ( vw->viking_vvp ) == VIK_COORD_UTM );
1214 utm_orig = *((const struct UTM *)vik_viewport_get_center ( vw->viking_vvp ));
1216 for ( y = 1; y <= tiles_h; y++ )
1218 for ( x = 1; x <= tiles_w; x++ )
1220 g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, VIKING_FILE_SEP, y, x, save_as_png ? "png" : "jpg" );
1222 if ( tiles_w & 0x1 )
1223 utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom);
1225 utm.easting += ((gdouble)x - (((gdouble)tiles_w)+1)/2) * (w*zoom);
1226 if ( tiles_h & 0x1 ) /* odd */
1227 utm.northing -= ((gdouble)y - ceil(((gdouble)tiles_h)/2)) * (h*zoom);
1229 utm.northing -= ((gdouble)y - (((gdouble)tiles_h)+1)/2) * (h*zoom);
1231 /* move to correct place. */
1232 vik_viewport_set_center_utm ( vw->viking_vvp, &utm );
1236 /* save buffer as file. */
1237 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);
1238 gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL );
1241 fprintf(stderr, "Unable to write to file %s: %s", name_of_file, error->message );
1242 g_error_free (error);
1245 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1249 vik_viewport_set_center_utm ( vw->viking_vvp, &utm_orig );
1250 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1251 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1252 vik_viewport_configure ( vw->viking_vvp );
1255 g_free ( name_of_file );
1258 static void draw_to_image_file_current_window_cb(GtkWidget* widget,GdkEventButton *event,gpointer *pass_along)
1260 VikWindow *vw = VIK_WINDOW(pass_along[0]);
1261 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1262 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1263 gdouble width_min, width_max, height_min, height_max;
1266 gtk_spin_button_get_range ( width_spin, &width_min, &width_max );
1267 gtk_spin_button_get_range ( height_spin, &height_min, &height_max );
1269 /* TODO: support for xzoom and yzoom values */
1270 width = vik_viewport_get_width ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1271 height = vik_viewport_get_height ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1273 if ( width > width_max || width < width_min || height > height_max || height < height_min )
1274 a_dialog_info_msg ( GTK_WINDOW(vw), "Viewable region outside allowable pixel size bounds for image. Clipping width/height values." );
1276 gtk_spin_button_set_value ( width_spin, width );
1277 gtk_spin_button_set_value ( height_spin, height );
1280 static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
1282 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1283 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1286 w = gtk_spin_button_get_value(width_spin) * gtk_spin_button_get_value(zoom_spin);
1287 h = gtk_spin_button_get_value(height_spin) * gtk_spin_button_get_value(zoom_spin);
1288 if (pass_along[4]) /* save many images; find TOTAL area covered */
1290 w *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[4]));
1291 h *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[5]));
1293 label_text = g_strdup_printf ( "Total area: %ldm x %ldm (%.3f sq. km)", (glong)w, (glong)h, (w*h/1000000));
1294 gtk_label_set_text(GTK_LABEL(pass_along[6]), label_text);
1295 g_free ( label_text );
1298 static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_image_only )
1300 /* todo: default for answers inside VikWindow or static (thruout instance) */
1301 GtkWidget *dialog = gtk_dialog_new_with_buttons ( "Save to Image File", GTK_WINDOW(vw),
1302 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1304 GTK_RESPONSE_REJECT,
1306 GTK_RESPONSE_ACCEPT,
1308 GtkWidget *width_label, *width_spin, *height_label, *height_spin;
1309 GtkWidget *png_radio, *jpeg_radio;
1310 GtkWidget *current_window_button;
1311 gpointer current_window_pass_along[7];
1312 GtkWidget *zoom_label, *zoom_spin;
1313 GtkWidget *total_size_label;
1315 /* only used if (!one_image_only) */
1316 GtkWidget *tiles_width_spin = NULL, *tiles_height_spin = NULL;
1319 width_label = gtk_label_new ( "Width (pixels):" );
1320 width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_width, 10, 5000, 10, 100, 0 )), 10, 0 );
1321 height_label = gtk_label_new ( "Height (pixels):" );
1322 height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_height, 10, 5000, 10, 100, 0 )), 10, 0 );
1324 zoom_label = gtk_label_new ( "Zoom (meters per pixel):" );
1325 /* TODO: separate xzoom and yzoom factors */
1326 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);
1328 total_size_label = gtk_label_new ( NULL );
1330 current_window_button = gtk_button_new_with_label ( "Area in current viewable window" );
1331 current_window_pass_along [0] = vw;
1332 current_window_pass_along [1] = width_spin;
1333 current_window_pass_along [2] = height_spin;
1334 current_window_pass_along [3] = zoom_spin;
1335 current_window_pass_along [4] = NULL; /* used for one_image_only != 1 */
1336 current_window_pass_along [5] = NULL;
1337 current_window_pass_along [6] = total_size_label;
1338 g_signal_connect ( G_OBJECT(current_window_button), "button_press_event", G_CALLBACK(draw_to_image_file_current_window_cb), current_window_pass_along );
1340 png_radio = gtk_radio_button_new_with_label ( NULL, "Save as PNG" );
1341 jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), "Save as JPEG" );
1343 if ( ! vw->draw_image_save_as_png )
1344 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE );
1346 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_label, FALSE, FALSE, 0);
1347 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_spin, FALSE, FALSE, 0);
1348 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_label, FALSE, FALSE, 0);
1349 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_spin, FALSE, FALSE, 0);
1350 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), current_window_button, FALSE, FALSE, 0);
1351 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), png_radio, FALSE, FALSE, 0);
1352 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), jpeg_radio, FALSE, FALSE, 0);
1353 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_label, FALSE, FALSE, 0);
1354 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_spin, FALSE, FALSE, 0);
1356 if ( ! one_image_only )
1358 GtkWidget *tiles_width_label, *tiles_height_label;
1361 tiles_width_label = gtk_label_new ( "East-west image tiles:" );
1362 tiles_width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1363 tiles_height_label = gtk_label_new ( "North-south image tiles:" );
1364 tiles_height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1365 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_label, FALSE, FALSE, 0);
1366 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_spin, FALSE, FALSE, 0);
1367 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_label, FALSE, FALSE, 0);
1368 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_spin, FALSE, FALSE, 0);
1370 current_window_pass_along [4] = tiles_width_spin;
1371 current_window_pass_along [5] = tiles_height_spin;
1372 g_signal_connect ( G_OBJECT(tiles_width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1373 g_signal_connect ( G_OBJECT(tiles_height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1375 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), total_size_label, FALSE, FALSE, 0);
1376 g_signal_connect ( G_OBJECT(width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1377 g_signal_connect ( G_OBJECT(height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1378 g_signal_connect ( G_OBJECT(zoom_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1380 draw_to_image_file_total_area_cb ( NULL, current_window_pass_along ); /* set correct size info now */
1382 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
1384 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
1386 gtk_widget_hide ( GTK_WIDGET(dialog) );
1387 if ( one_image_only )
1388 save_image_file ( vw, fn,
1389 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1390 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1391 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1392 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ) );
1394 if ( vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM )
1395 save_image_dir ( vw, fn,
1396 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1397 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1398 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1399 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ),
1400 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_width_spin) ),
1401 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_height_spin) ) );
1403 a_dialog_error_msg ( GTK_WINDOW(vw), "You must be in UTM mode to use this feature" );
1406 gtk_widget_destroy ( GTK_WIDGET(dialog) );
1410 static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw )
1412 GtkWidget *file_selector;
1414 file_selector = gtk_file_selection_new ("Save Image");
1416 while ( gtk_dialog_run ( GTK_DIALOG(file_selector) ) == GTK_RESPONSE_OK )
1418 fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector) );
1419 if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(file_selector), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn ) ) )
1421 gtk_widget_hide ( file_selector );
1422 draw_to_image_file ( vw, fn, TRUE );
1426 gtk_widget_destroy ( file_selector );
1429 static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw )
1431 GtkWidget *file_selector;
1433 file_selector = gtk_file_selection_new ("Choose a name for a new directory to hold images");
1435 while ( gtk_dialog_run ( GTK_DIALOG(file_selector) ) == GTK_RESPONSE_OK )
1437 fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector) );
1438 if ( access ( fn, F_OK ) == 0 )
1439 a_dialog_info_msg_extra ( GTK_WINDOW(file_selector), "The file %s exists. Please choose a name for a new directory to hold images in that does not exist.", a_file_basename(fn) );
1442 gtk_widget_hide ( file_selector );
1443 draw_to_image_file ( vw, fn, FALSE );
1447 gtk_widget_destroy ( file_selector );
1450 /* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */
1451 static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWindow *vw )
1453 VikViewportDrawMode drawmode;
1454 if (!strcmp(gtk_action_get_name(a), "ModeUTM")) {
1455 drawmode = VIK_VIEWPORT_DRAWMODE_UTM;
1457 else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) {
1458 drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA;
1460 else if (!strcmp(gtk_action_get_name(a), "ModeGoogle")) {
1461 drawmode = VIK_VIEWPORT_DRAWMODE_GOOGLE;
1463 else if (!strcmp(gtk_action_get_name(a), "ModeKH")) {
1464 drawmode = VIK_VIEWPORT_DRAWMODE_KH;
1466 else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) {
1467 drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
1470 fprintf(stderr, "Houston, we got a problem!\n");
1474 if ( !vw->only_updating_coord_mode_ui )
1476 VikViewportDrawMode olddrawmode = vik_viewport_get_drawmode ( vw->viking_vvp );
1477 if ( olddrawmode != drawmode )
1479 /* this takes care of coord mode too */
1480 vik_viewport_set_drawmode ( vw->viking_vvp, drawmode );
1481 if ( drawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
1482 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_UTM );
1483 } else if ( olddrawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
1484 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_LATLON );
1491 static void set_draw_scale ( GtkAction *a, VikWindow *vw )
1493 vik_viewport_set_draw_scale ( vw->viking_vvp, !vik_viewport_get_draw_scale(vw->viking_vvp) );
1497 static void set_bg_color ( GtkAction *a, VikWindow *vw )
1499 GtkWidget *colorsd = gtk_color_selection_dialog_new ("Choose a background color");
1500 GdkColor *color = vik_viewport_get_background_gdkcolor ( vw->viking_vvp );
1501 gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
1502 gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
1503 if ( gtk_dialog_run ( GTK_DIALOG(colorsd) ) == GTK_RESPONSE_OK )
1505 gtk_color_selection_get_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
1506 vik_viewport_set_background_gdkcolor ( vw->viking_vvp, color );
1510 gtk_widget_destroy ( colorsd );
1515 /***********************************************************************************************
1517 ***********************************************************************************************/
1519 static GtkActionEntry entries[] = {
1520 { "File", NULL, "_File", 0, 0, 0 },
1521 { "View", NULL, "_View", 0, 0, 0 },
1522 { "SetZoom", NULL, "_Zoom", 0, 0, 0 },
1523 { "Layers", NULL, "_Layers", 0, 0, 0 },
1524 { "Tools", NULL, "_Tools", 0, 0, 0 },
1526 { "New", GTK_STOCK_NEW, "_New", "<control>N", "New file", (GCallback)newwindow_cb },
1527 { "Open", GTK_STOCK_OPEN, "_Open", "<control>O", "Open a file", (GCallback)load_file },
1528 { "Append", GTK_STOCK_ADD, "A_ppend File", NULL, "Append data from a different file", (GCallback)load_file },
1529 { "Acquire", NULL, "A_cquire", 0, 0, 0 },
1530 { "AcquireGPS", NULL, "From _GPS", NULL, "Transfer data from a GPS device", (GCallback)acquire_from_gps },
1531 { "AcquireGoogle", NULL, "Google _Directions", NULL, "Get driving directions from Google", (GCallback)acquire_from_google },
1532 { "AcquireGC", NULL, "Geo_caches", NULL, "Get Geocaches from geocaching.com", (GCallback)acquire_from_gc },
1533 { "Save", GTK_STOCK_SAVE, "_Save", "<control>S", "Save the file", (GCallback)save_file },
1534 { "SaveAs", GTK_STOCK_SAVE_AS, "Save _As", NULL, "Save the file under different name", (GCallback)save_file_as },
1535 { "GenImg", GTK_STOCK_CLEAR, "_Generate Image File", NULL, "Save a snapshot of the workspace into a file", (GCallback)draw_to_image_file_cb },
1536 { "GenImgDir", GTK_STOCK_DND_MULTIPLE, "Generate _Directory of Images", NULL, "FIXME:IMGDIR", (GCallback)draw_to_image_dir_cb },
1537 { "Exit", GTK_STOCK_QUIT, "E_xit", "<control>W", "Exit the program", (GCallback)window_close },
1539 { "GotoLL", GTK_STOCK_QUIT, "_Go to Lat\\/Lon...", NULL, "Go to arbitrary lat\\/lon coordinate", (GCallback)draw_goto_cb },
1540 { "GotoUTM", GTK_STOCK_QUIT, "Go to UTM...", NULL, "Go to arbitrary UTM coordinate", (GCallback)draw_goto_cb },
1541 { "SetBGColor",GTK_STOCK_SELECT_COLOR, "Set Background Color...", NULL, NULL, (GCallback)set_bg_color },
1542 { "ZoomIn", GTK_STOCK_ZOOM_IN, "Zoom _In", "<control>plus", NULL, (GCallback)draw_zoom_cb },
1543 { "ZoomOut", GTK_STOCK_ZOOM_OUT, "Zoom _Out", "<control>minus", NULL, (GCallback)draw_zoom_cb },
1544 { "ZoomTo", GTK_STOCK_ZOOM_FIT, "Zoom _To", "<control><shift>Z", NULL, (GCallback)zoom_to_cb },
1545 { "Zoom0.25", NULL, "0.25", NULL, NULL, (GCallback)draw_zoom_cb },
1546 { "Zoom0.5", NULL, "0.5", NULL, NULL, (GCallback)draw_zoom_cb },
1547 { "Zoom1", NULL, "1", NULL, NULL, (GCallback)draw_zoom_cb },
1548 { "Zoom2", NULL, "2", NULL, NULL, (GCallback)draw_zoom_cb },
1549 { "Zoom4", NULL, "4", NULL, NULL, (GCallback)draw_zoom_cb },
1550 { "Zoom8", NULL, "8", NULL, NULL, (GCallback)draw_zoom_cb },
1551 { "Zoom16", NULL, "16", NULL, NULL, (GCallback)draw_zoom_cb },
1552 { "Zoom32", NULL, "32", NULL, NULL, (GCallback)draw_zoom_cb },
1553 { "Zoom64", NULL, "64", NULL, NULL, (GCallback)draw_zoom_cb },
1554 { "Zoom128", NULL, "128", NULL, NULL, (GCallback)draw_zoom_cb },
1555 { "BGJobs", GTK_STOCK_EXECUTE, "Background _Jobs", NULL, NULL, (GCallback)a_background_show_window },
1557 { "Cut", GTK_STOCK_CUT, "Cu_t", NULL, NULL, (GCallback)menu_cut_layer_cb },
1558 { "Copy", GTK_STOCK_COPY, "_Copy", NULL, NULL, (GCallback)menu_copy_layer_cb },
1559 { "Paste", GTK_STOCK_PASTE, "_Paste", NULL, NULL, (GCallback)menu_paste_layer_cb },
1560 { "Delete", GTK_STOCK_DELETE, "_Delete", NULL, NULL, (GCallback)menu_delete_layer_cb },
1561 { "DeleteAll", NULL, "Delete All", NULL, NULL, (GCallback)clear_cb },
1562 { "Properties",GTK_STOCK_PROPERTIES, "_Properties", NULL, NULL, (GCallback)menu_properties_cb },
1566 static GtkRadioActionEntry mode_entries[] = {
1567 { "ModeUTM", NULL, "_UTM Mode", "<control>u", NULL, 0 },
1568 { "ModeExpedia", NULL, "_Expedia Mode", "<control>e", NULL, 1 },
1569 { "ModeGoogle", NULL, "_Old Google Mode", "<control>o", NULL, 2 },
1570 { "ModeKH", NULL, "Old _KH Mode", "<control>k", NULL, 3 },
1571 { "ModeMercator", NULL, "_Google Mode", "<control>g", NULL, 4 }
1574 static GtkRadioActionEntry tool_entries[] = {
1575 { "Zoom", "vik-icon-zoom", "_Zoom", "<control><shift>Z", "Zoom Tool", 0 },
1576 { "Ruler", "vik-icon-ruler", "_Ruler", "<control><shift>R", "Ruler Tool", 1 }
1579 static GtkToggleActionEntry toggle_entries[] = {
1580 { "ShowScale", NULL, "Show Scale", NULL, NULL, (GCallback)set_draw_scale, TRUE },
1583 #include "menu.xml.h"
1584 static void window_create_ui( VikWindow *window )
1587 GtkActionGroup *action_group;
1588 GtkAccelGroup *accel_group;
1591 GtkIconFactory *icon_factory;
1592 GtkIconSet *icon_set;
1593 GtkRadioActionEntry *tools = NULL, *radio;
1596 uim = gtk_ui_manager_new ();
1599 toolbox_add_tool(window->vt, &ruler_tool);
1600 toolbox_add_tool(window->vt, &zoom_tool);
1603 if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) {
1604 g_error_free (error);
1608 action_group = gtk_action_group_new ("MenuActions");
1609 gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
1610 gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
1611 gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 0, (GCallback)window_change_coord_mode_cb, window);
1613 icon_factory = gtk_icon_factory_new ();
1614 gtk_icon_factory_add_default (icon_factory);
1616 register_vik_icons(icon_factory);
1619 for (i=0; i<G_N_ELEMENTS(tool_entries); i++) {
1620 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
1621 radio = &tools[ntools];
1623 *radio = tool_entries[i];
1624 radio->value = ntools;
1627 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
1628 GtkActionEntry action;
1629 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Layers/",
1630 vik_layer_get_interface(i)->name,
1631 vik_layer_get_interface(i)->name,
1632 GTK_UI_MANAGER_MENUITEM, FALSE);
1634 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (vik_layer_get_interface(i)->icon, FALSE, NULL ));
1635 gtk_icon_factory_add (icon_factory, vik_layer_get_interface(i)->name, icon_set);
1636 gtk_icon_set_unref (icon_set);
1638 action.name = vik_layer_get_interface(i)->name;
1639 action.stock_id = vik_layer_get_interface(i)->name;
1640 action.label = g_strdup_printf("New %s Layer", vik_layer_get_interface(i)->name);
1641 action.accelerator = NULL;
1642 action.tooltip = NULL;
1643 action.callback = (GCallback)menu_addlayer_cb;
1644 gtk_action_group_add_actions(action_group, &action, 1, window);
1646 if ( vik_layer_get_interface(i)->tools_count ) {
1647 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
1648 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
1651 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
1652 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
1653 radio = &tools[ntools];
1656 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools",
1657 vik_layer_get_interface(i)->tools[j].name,
1658 vik_layer_get_interface(i)->tools[j].name,
1659 GTK_UI_MANAGER_MENUITEM, FALSE);
1660 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems",
1661 vik_layer_get_interface(i)->tools[j].name,
1662 vik_layer_get_interface(i)->tools[j].name,
1663 GTK_UI_MANAGER_TOOLITEM, FALSE);
1665 toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]));
1667 radio->name = vik_layer_get_interface(i)->tools[j].name;
1668 radio->stock_id = vik_layer_get_interface(i)->tools[j].name,
1669 radio->label = vik_layer_get_interface(i)->tools[j].name;
1670 radio->accelerator = NULL;
1671 radio->tooltip = vik_layer_get_interface(i)->tools[j].name;
1672 radio->value = ntools;
1675 g_object_unref (icon_factory);
1677 gtk_action_group_add_radio_actions(action_group, tools, ntools, 0, (GCallback)menu_tool_cb, window);
1680 gtk_ui_manager_insert_action_group (uim, action_group, 0);
1682 accel_group = gtk_ui_manager_get_accel_group (uim);
1683 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
1684 gtk_ui_manager_ensure_update (uim);
1689 #include "icons/icons.h"
1691 const GdkPixdata *data;
1694 { &addtr_18, "Create Track" },
1695 { &edtr_18, "Edit Trackpoint" },
1696 { &addwp_18, "Create Waypoint" },
1697 { &edwp_18, "Edit Waypoint" },
1698 { &zoom_18, "vik-icon-zoom" },
1699 { &ruler_18, "vik-icon-ruler" },
1700 { &geozoom_18, "Georef Zoom Tool" },
1701 { &geomove_18, "Georef Move Map" },
1702 { &mapdl_18, "Maps Download" },
1703 { &showpic_18, "Show Picture" },
1706 static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
1709 register_vik_icons (GtkIconFactory *icon_factory)
1711 GtkIconSet *icon_set;
1714 for (i = 0; i < n_stock_icons; i++) {
1715 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (
1716 stock_icons[i].data, FALSE, NULL ));
1717 gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set);
1718 gtk_icon_set_unref (icon_set);