]> git.street.me.uk Git - andy/viking.git/blame - src/vikwindow.c
Document Fix #1947260
[andy/viking.git] / src / vikwindow.c
CommitLineData
50a14534
EB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 *
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.
10 *
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.
15 *
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
19 *
20 */
4c77d5e0
GB
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
50a14534
EB
26#include "viking.h"
27#include "background.h"
1d1bc3c1 28#include "acquire.h"
7b3479e3 29#include "datasources.h"
369126f3 30#include "googlesearch.h"
071da616 31#include "dems.h"
42f34743 32#include "print.h"
17a1f8f9 33#include "preferences.h"
f2f2f7bf 34#include "icons/icons.h"
50a14534 35
e4afc73a 36#include <stdlib.h>
50a14534
EB
37#include <math.h>
38#include <string.h>
39#include <ctype.h>
f83131b9
MA
40#include <glib.h>
41#include <glib/gstdio.h>
1d1bc3c1 42#include <glib/gprintf.h>
4c77d5e0 43#include <glib/gi18n.h>
50a14534 44
3570ad57
QT
45#define VIKING_WINDOW_WIDTH 1000
46#define VIKING_WINDOW_HEIGHT 800
50a14534
EB
47#define DRAW_IMAGE_DEFAULT_WIDTH 1280
48#define DRAW_IMAGE_DEFAULT_HEIGHT 1024
49#define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
50
51static void window_finalize ( GObject *gob );
52static GObjectClass *parent_class;
53
54static void window_init ( VikWindow *vw );
55static void window_class_init ( VikWindowClass *klass );
4c77d5e0 56static void window_set_filename ( VikWindow *vw, const gchar *filename );
50a14534
EB
57
58static void draw_update ( VikWindow *vw );
59
e4afc73a 60static void newwindow_cb ( GtkAction *a, VikWindow *vw );
50a14534
EB
61
62/* Drawing & stuff */
63
64static gboolean delete_event( VikWindow *vw );
65
777e2d4d
EB
66static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data );
67
bce3a7b0 68static void window_configure_event ( VikWindow *vw );
50a14534
EB
69static void draw_sync ( VikWindow *vw );
70static void draw_redraw ( VikWindow *vw );
941aa6e9 71static void draw_scroll ( VikWindow *vw, GdkEventScroll *event );
50a14534
EB
72static void draw_click ( VikWindow *vw, GdkEventButton *event );
73static void draw_release ( VikWindow *vw, GdkEventButton *event );
74static void draw_mouse_motion ( VikWindow *vw, GdkEventMotion *event );
e4afc73a
EB
75static void draw_zoom_cb ( GtkAction *a, VikWindow *vw );
76static void draw_goto_cb ( GtkAction *a, VikWindow *vw );
50a14534
EB
77
78static void draw_status ();
79
80/* End Drawing Functions */
81
e4afc73a
EB
82static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw );
83static void menu_properties_cb ( GtkAction *a, VikWindow *vw );
84static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw );
941aa6e9
AF
85
86/* tool management */
87typedef struct {
88 VikToolInterface ti;
89 gpointer state;
9593a4c9 90 gint layer_type;
941aa6e9 91} toolbox_tool_t;
9593a4c9 92#define TOOL_LAYER_TYPE_NONE -1
941aa6e9
AF
93
94typedef struct {
95 int active_tool;
96 int n_tools;
97 toolbox_tool_t *tools;
98 VikWindow *vw;
99} toolbox_tools_t;
100
e4afc73a 101static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw );
941aa6e9 102static toolbox_tools_t* toolbox_create(VikWindow *vw);
9593a4c9 103static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type );
941aa6e9
AF
104static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
105static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
f2f2f7bf 106static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name);
941aa6e9 107static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
dc2c040e 108static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event);
941aa6e9
AF
109static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
110
50a14534 111
941aa6e9 112/* ui creation */
e4afc73a 113static void window_create_ui( VikWindow *window );
941aa6e9 114static void register_vik_icons (GtkIconFactory *icon_factory);
50a14534 115
941aa6e9 116/* i/o */
e4afc73a
EB
117static void load_file ( GtkAction *a, VikWindow *vw );
118static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
119static gboolean save_file ( GtkAction *a, VikWindow *vw );
2bf7cadd 120static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw );
50a14534
EB
121static gboolean window_save ( VikWindow *vw );
122
123struct _VikWindow {
124 GtkWindow gtkwindow;
125 VikViewport *viking_vvp;
126 VikLayersPanel *viking_vlp;
127 VikStatusbar *viking_vs;
128
e4afc73a
EB
129 GtkToolbar *toolbar;
130
50a14534
EB
131 GtkItemFactory *item_factory;
132
941aa6e9 133 /* tool management state */
50a14534 134 guint current_tool;
941aa6e9 135 toolbox_tools_t *vt;
50a14534
EB
136 guint16 tool_layer_id;
137 guint16 tool_tool_id;
138
79845167
QT
139 GtkActionGroup *action_group;
140
50a14534
EB
141 gint pan_x, pan_y;
142
143 guint draw_image_width, draw_image_height;
144 gboolean draw_image_save_as_png;
145
146 gchar *filename;
147 gboolean modified;
148
149 GtkWidget *open_dia, *save_dia;
f2a1ca71 150 GtkWidget *save_img_dia, *save_img_dir_dia;
50a14534
EB
151
152 gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
e4afc73a 153 GtkUIManager *uim;
c9177aae
QT
154
155 /* half-drawn update */
156 VikLayer *trigger;
157 VikCoord trigger_center;
50a14534
EB
158};
159
160enum {
576cbd17
GB
161 TOOL_PAN = 0,
162 TOOL_ZOOM,
50a14534
EB
163 TOOL_RULER,
164 TOOL_LAYER,
165 NUMBER_OF_TOOLS
166};
167
168enum {
169 VW_NEWWINDOW_SIGNAL,
170 VW_OPENWINDOW_SIGNAL,
171 VW_LAST_SIGNAL
172};
173
174static guint window_signals[VW_LAST_SIGNAL] = { 0 };
175
576cbd17 176static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler") };
50a14534
EB
177
178GType vik_window_get_type (void)
179{
180 static GType vw_type = 0;
181
182 if (!vw_type)
183 {
184 static const GTypeInfo vw_info =
185 {
186 sizeof (VikWindowClass),
187 NULL, /* base_init */
188 NULL, /* base_finalize */
189 (GClassInitFunc) window_class_init, /* class_init */
190 NULL, /* class_finalize */
191 NULL, /* class_data */
192 sizeof (VikWindow),
193 0,
194 (GInstanceInitFunc) window_init,
195 };
196 vw_type = g_type_register_static ( GTK_TYPE_WINDOW, "VikWindow", &vw_info, 0 );
197 }
198
199 return vw_type;
200}
201
014128f6
QT
202VikViewport * vik_window_viewport(VikWindow *vw)
203{
204 return(vw->viking_vvp);
205}
206
79845167
QT
207void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
208{
209 int i, j, tool_count;
210 VikLayerInterface *layer_interface;
211
212 if (!vw->action_group) return;
213
214 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
215 GtkAction *action;
216 layer_interface = vik_layer_get_interface(i);
217 tool_count = layer_interface->tools_count;
218
219 for (j = 0; j < tool_count; j++) {
220 action = gtk_action_group_get_action(vw->action_group,
221 layer_interface->tools[j].name);
222 g_object_set(action, "sensitive", i == vl->type, NULL);
223 }
224 }
225}
226
50a14534
EB
227static void window_finalize ( GObject *gob )
228{
229 VikWindow *vw = VIK_WINDOW(gob);
230 g_return_if_fail ( vw != NULL );
231
232 a_background_remove_status ( vw->viking_vs );
233
234 G_OBJECT_CLASS(parent_class)->finalize(gob);
235}
236
bce3a7b0 237
50a14534
EB
238static void window_class_init ( VikWindowClass *klass )
239{
240 /* destructor */
241 GObjectClass *object_class;
242
243 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);
8c4f1350 244 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);
50a14534
EB
245
246 object_class = G_OBJECT_CLASS (klass);
247
248 object_class->finalize = window_finalize;
249
250 parent_class = g_type_class_peek_parent (klass);
251
252}
253
254static void window_init ( VikWindow *vw )
255{
256 GtkWidget *main_vbox;
257 GtkWidget *hpaned;
258
79845167 259 vw->action_group = NULL;
50a14534 260
24277274 261 vw->viking_vvp = vik_viewport_new();
50a14534
EB
262 vw->viking_vlp = vik_layers_panel_new();
263 vik_layers_panel_set_viewport ( vw->viking_vlp, vw->viking_vvp );
264 vw->viking_vs = vik_statusbar_new();
265
941aa6e9
AF
266 vw->vt = toolbox_create(vw);
267 window_create_ui(vw);
4c77d5e0 268 window_set_filename (vw, NULL);
941aa6e9 269
576cbd17 270 toolbox_activate(vw->vt, "Pan");
941aa6e9 271
50a14534 272 vw->filename = NULL;
e4afc73a 273 vw->item_factory = NULL;
50a14534 274
50a14534
EB
275 vw->modified = FALSE;
276 vw->only_updating_coord_mode_ui = FALSE;
941aa6e9 277
50a14534
EB
278 vw->pan_x = vw->pan_y = -1;
279 vw->draw_image_width = DRAW_IMAGE_DEFAULT_WIDTH;
280 vw->draw_image_height = DRAW_IMAGE_DEFAULT_HEIGHT;
281 vw->draw_image_save_as_png = DRAW_IMAGE_DEFAULT_SAVE_AS_PNG;
282
283 main_vbox = gtk_vbox_new(FALSE, 1);
284 gtk_container_add (GTK_CONTAINER (vw), main_vbox);
285
e4afc73a
EB
286 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainMenu"), FALSE, TRUE, 0);
287 gtk_box_pack_start (GTK_BOX(main_vbox), gtk_ui_manager_get_widget (vw->uim, "/MainToolbar"), FALSE, TRUE, 0);
886031df
AF
288 gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
289 gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
50a14534 290
777e2d4d 291
50a14534
EB
292 g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
293
294 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw);
bce3a7b0 295 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw);
777e2d4d 296 gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK );
50a14534
EB
297 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw);
298 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw);
299 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw);
300 g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
301 g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
302
165d30aa 303 g_signal_connect_swapped (G_OBJECT (vw->viking_vvp), "key_press_event", G_CALLBACK (key_press_event), vw);
777e2d4d 304
9a3cdf12 305 gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT);
50a14534
EB
306
307 hpaned = gtk_hpaned_new ();
181f5d0c
MA
308 gtk_paned_pack1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp), FALSE, FALSE );
309 gtk_paned_pack2 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vvp), TRUE, TRUE );
50a14534
EB
310
311 /* This packs the button into the window (a gtk container). */
312 gtk_box_pack_start (GTK_BOX(main_vbox), hpaned, TRUE, TRUE, 0);
313
314 gtk_box_pack_end (GTK_BOX(main_vbox), GTK_WIDGET(vw->viking_vs), FALSE, TRUE, 0);
315
316 a_background_add_status(vw->viking_vs);
317
318 vw->open_dia = NULL;
319 vw->save_dia = NULL;
f2a1ca71
QT
320 vw->save_img_dia = NULL;
321 vw->save_img_dir_dia = NULL;
50a14534
EB
322}
323
324VikWindow *vik_window_new ()
325{
326 return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
327}
328
777e2d4d
EB
329static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data )
330{
331 VikLayer *vl = vik_layers_panel_get_selected ( vw->viking_vlp );
332 if (vl && vw->vt->active_tool != -1 && vw->vt->tools[vw->vt->active_tool].ti.key_press ) {
333 gint ltype = vw->vt->tools[vw->vt->active_tool].layer_type;
334 if ( vl && ltype == vl->type )
335 return vw->vt->tools[vw->vt->active_tool].ti.key_press(vl, event, vw->vt->tools[vw->vt->active_tool].state);
336 }
337 return FALSE; /* don't handle the keypress */
338}
339
50a14534
EB
340static gboolean delete_event( VikWindow *vw )
341{
a5fd2196 342#ifdef VIKING_PROMPT_IF_MODIFIED
50a14534 343 if ( vw->modified )
a5fd2196
QT
344#else
345 if (0)
346#endif
50a14534
EB
347 {
348 GtkDialog *dia;
349 dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
4c77d5e0
GB
350 _("Do you want to save the changes you made to the document \"%s\"?\n"
351 "\n"
352 "Your changes will be lost if you don't save them."),
353 vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") ) );
354 gtk_dialog_add_buttons ( dia, _("Don't Save"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
50a14534
EB
355 switch ( gtk_dialog_run ( dia ) )
356 {
357 case GTK_RESPONSE_NO: gtk_widget_destroy ( GTK_WIDGET(dia) ); return FALSE;
358 case GTK_RESPONSE_CANCEL: gtk_widget_destroy ( GTK_WIDGET(dia) ); return TRUE;
e4afc73a 359 default: gtk_widget_destroy ( GTK_WIDGET(dia) ); return ! save_file(NULL, vw);
50a14534
EB
360 }
361 }
362 return FALSE;
363}
364
365/* Drawing stuff */
e4afc73a 366static void newwindow_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
367{
368 g_signal_emit ( G_OBJECT(vw), window_signals[VW_NEWWINDOW_SIGNAL], 0 );
369}
370
371static void draw_update ( VikWindow *vw )
372{
373 draw_redraw (vw);
374 draw_sync (vw);
375}
376
377static void draw_sync ( VikWindow *vw )
378{
379 vik_viewport_sync(vw->viking_vvp);
380 draw_status ( vw );
381 /* other things may be necc here later. */
382}
383
384static void draw_status ( VikWindow *vw )
385{
386 static gchar zoom_level[22];
4c77d5e0 387 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") );
50a14534
EB
388 if ( vw->current_tool == TOOL_LAYER )
389 vik_statusbar_set_message ( vw->viking_vs, 0, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name );
390 else
4c77d5e0 391 vik_statusbar_set_message ( vw->viking_vs, 0, _(tool_names[vw->current_tool]) );
50a14534
EB
392
393 vik_statusbar_set_message ( vw->viking_vs, 2, zoom_level );
394}
395
c9177aae
QT
396void vik_window_set_redraw_trigger(VikLayer *vl)
397{
730a38c1 398 VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl));
be3b5803
GB
399 if (NULL != vw)
400 vw->trigger = vl;
c9177aae
QT
401}
402
bce3a7b0
EB
403static void window_configure_event ( VikWindow *vw )
404{
f2f2f7bf 405 static int first = 1;
bce3a7b0 406 draw_redraw ( vw );
372132a6
GB
407 if (first) {
408 // This is a hack to set the cursor corresponding to the first tool
409 // FIXME find the correct way to initialize both tool and its cursor
f2f2f7bf 410 const GdkCursor *cursor = NULL;
372132a6 411 first = 0;
f2f2f7bf
GB
412 cursor = toolbox_get_cursor(vw->vt, "Pan");
413 /* We set cursor, even if it is NULL: it resets to default */
414 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor );
372132a6 415 }
bce3a7b0
EB
416}
417
50a14534
EB
418static void draw_redraw ( VikWindow *vw )
419{
c9177aae
QT
420 VikCoord old_center = vw->trigger_center;
421 vw->trigger_center = *(vik_viewport_get_center(vw->viking_vvp));
422 VikLayer *new_trigger = vw->trigger;
423 vw->trigger = NULL;
0df66d57
EB
424 VikLayer *old_trigger = VIK_LAYER(vik_viewport_get_trigger(vw->viking_vvp));
425
426 if ( ! new_trigger )
427 ; /* do nothing -- have to redraw everything. */
c9177aae 428 else if ( (old_trigger != new_trigger) || !vik_coord_equals(&old_center, &vw->trigger_center) )
0df66d57
EB
429 vik_viewport_set_trigger ( vw->viking_vvp, new_trigger ); /* todo: set to half_drawn mode if new trigger is above old */
430 else
431 vik_viewport_set_half_drawn ( vw->viking_vvp, TRUE );
432
433 /* actually draw */
50a14534 434 vik_viewport_clear ( vw->viking_vvp);
50a14534 435 vik_layers_panel_draw_all ( vw->viking_vlp );
acaf7113 436 vik_viewport_draw_scale ( vw->viking_vvp );
c933487f 437 vik_viewport_draw_centermark ( vw->viking_vvp );
0df66d57
EB
438
439 vik_viewport_set_half_drawn ( vw->viking_vvp, FALSE ); /* just in case. */
50a14534
EB
440}
441
941aa6e9
AF
442gboolean draw_buf_done = TRUE;
443
444static gboolean draw_buf(gpointer data)
445{
446 gpointer *pass_along = data;
447 gdk_threads_enter();
448 gdk_draw_drawable (pass_along[0], pass_along[1],
449 pass_along[2], 0, 0, 0, 0, -1, -1);
450 draw_buf_done = TRUE;
451 gdk_threads_leave();
452 return FALSE;
453}
454
455
456/* Mouse event handlers ************************************************************************/
457
b57126a3
GB
458static void vik_window_pan_click (VikWindow *vw, GdkEventButton *event)
459{
460 /* set panning origin */
461 vw->pan_x = (gint) event->x;
462 vw->pan_y = (gint) event->y;
463}
464
941aa6e9
AF
465static void draw_click (VikWindow *vw, GdkEventButton *event)
466{
165d30aa 467 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
941aa6e9
AF
468
469 /* middle button pressed. we reserve all middle button and scroll events
470 * for panning and zooming; tools only get left/right/movement
471 */
472 if ( event->button == 2) {
b57126a3 473 vik_window_pan_click ( vw, event );
941aa6e9
AF
474 }
475 else {
476 toolbox_click(vw->vt, event);
477 }
478}
479
b57126a3
GB
480static void vik_window_pan_move (VikWindow *vw, GdkEventMotion *event)
481{
482 if ( vw->pan_x != -1 ) {
483 vik_viewport_pan_sync ( vw->viking_vvp, event->x - vw->pan_x, event->y - vw->pan_y );
484 }
485}
486
941aa6e9
AF
487static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
488{
489 static VikCoord coord;
490 static struct UTM utm;
491 static struct LatLon ll;
a58aaed4
GB
492 #define BUFFER_SIZE 50
493 static char pointer_buf[BUFFER_SIZE];
494 gchar *lat = NULL, *lon = NULL;
071da616 495 gint16 alt;
228213c5
QT
496 gdouble zoom;
497 VikDemInterpol interpol_method;
941aa6e9 498
576cbd17 499 toolbox_move(vw->vt, event);
941aa6e9
AF
500
501 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
502 vik_coord_to_utm ( &coord, &utm );
503 a_coords_utm_to_latlon ( &utm, &ll );
a58aaed4 504 a_coords_latlon_to_string ( &ll, &lat, &lon );
228213c5
QT
505 /* Change interpolate method according to scale */
506 zoom = vik_viewport_get_zoom(vw->viking_vvp);
507 if (zoom > 2.0)
508 interpol_method = VIK_DEM_INTERPOL_NONE;
509 else if (zoom >= 1.0)
510 interpol_method = VIK_DEM_INTERPOL_SIMPLE;
511 else
512 interpol_method = VIK_DEM_INTERPOL_BEST;
513 if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION)
a58aaed4 514 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s %dm"), lat, lon, alt );
071da616 515 else
a58aaed4
GB
516 g_snprintf ( pointer_buf, BUFFER_SIZE, _("%s %s"), lat, lon );
517 g_free (lat);
518 lat = NULL;
519 g_free (lon);
520 lon = NULL;
941aa6e9
AF
521 vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
522
b57126a3
GB
523 vik_window_pan_move ( vw, event );
524}
525
526static void vik_window_pan_release ( VikWindow *vw, GdkEventButton *event )
527{
528 if ( ABS(vw->pan_x - event->x) <= 1 && ABS(vw->pan_y - event->y) <= 1 )
529 vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
530 else
531 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
532 vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
533 draw_update ( vw );
534 vw->pan_x = vw->pan_y = -1;
941aa6e9
AF
535}
536
537static void draw_release ( VikWindow *vw, GdkEventButton *event )
538{
165d30aa
EB
539 gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
540
941aa6e9 541 if ( event->button == 2 ) { /* move / pan */
b57126a3 542 vik_window_pan_release(vw, event);
941aa6e9
AF
543 }
544 else {
545 toolbox_release(vw->vt, event);
546 }
547}
548
549static void draw_scroll (VikWindow *vw, GdkEventScroll *event)
550{
bddd2056 551 if ( event->state == GDK_CONTROL_MASK ) {
8c721f83
EB
552 /* control == pan up & down */
553 if ( event->direction == GDK_SCROLL_UP )
554 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 );
555 else
556 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 );
e086b16d 557 } else if ( event->state == GDK_SHIFT_MASK ) {
8c721f83
EB
558 /* control-shift == pan left & right */
559 if ( event->direction == GDK_SCROLL_UP )
560 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 );
561 else
562 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 );
e086b16d 563 } else if ( event->state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) {
9a30122d
EB
564 if ( event->direction == GDK_SCROLL_UP ) {
565 /* make sure mouse is still over the same point on the map when we zoom */
566 VikCoord coord;
567 gint x, y;
568 gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
569 gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
570 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
8c721f83 571 vik_viewport_zoom_in (vw->viking_vvp);
9a30122d
EB
572 vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
573 vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
574 center_y + (y - event->y) );
575 }
576 else {
577 VikCoord coord;
578 gint x, y;
579 gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
580 gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
581 vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
8c721f83 582 vik_viewport_zoom_out(vw->viking_vvp);
9a30122d
EB
583 vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
584 vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
585 center_y + (y - event->y) );
586 }
e086b16d
EB
587 } else {
588 if ( event->direction == GDK_SCROLL_UP )
589 vik_viewport_zoom_in (vw->viking_vvp);
590 else
591 vik_viewport_zoom_out (vw->viking_vvp);
8c721f83
EB
592 }
593
941aa6e9
AF
594 draw_update(vw);
595}
596
597
598
599/********************************************************************************
600 ** Ruler tool code
601 ********************************************************************************/
e4847ce9
AF
602static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gdouble distance)
603{
604 PangoFontDescription *pfd;
605 PangoLayout *pl;
606 gchar str[128];
0dff88ea
AF
607 GdkGC *labgc = vik_viewport_new_gc ( vvp, "#cccccc", 1);
608 GdkGC *thickgc = gdk_gc_new(d);
609
e4847ce9
AF
610 gdouble len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
611 gdouble dx = (x2-x1)/len*10;
612 gdouble dy = (y2-y1)/len*10;
613 gdouble c = cos(15.0 * M_PI/180.0);
614 gdouble s = sin(15.0 * M_PI/180.0);
0dff88ea 615 gdouble angle;
15614495 616 gdouble baseangle = 0;
0dff88ea 617 gint i;
e4847ce9 618
0dff88ea 619 /* draw line with arrow ends */
d9ffd267
EB
620 {
621 gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
622 a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
623 gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
624 }
625
15614495
AF
626 a_viewport_clip_line(&x1, &y1, &x2, &y2);
627 gdk_draw_line(d, gc, x1, y1, x2, y2);
d9ffd267 628
e4847ce9
AF
629 gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
630 gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
631 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));
632 gdk_draw_line(d, gc, x2, y2, x2 - (dx * c - dy * s), y2 - (dy * c + dx * s));
633 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c + dy * s), y1 + (dy * c - dx * s));
634 gdk_draw_line(d, gc, x1, y1, x1 + (dx * c - dy * s), y1 + (dy * c + dx * s));
635
0dff88ea
AF
636 /* draw compass */
637#define CR 80
638#define CW 4
15614495
AF
639 angle = atan2(dy, dx) + M_PI_2;
640
641 if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
642 VikCoord test;
643 struct LatLon ll;
644 struct UTM u;
645 gint tx, ty;
646
647 vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
648 vik_coord_to_latlon ( &test, &ll );
649 ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
650 a_coords_latlon_to_utm ( &ll, &u );
651 vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
652 vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
653
654 baseangle = M_PI - atan2(tx-x1, ty-y1);
655 angle -= baseangle;
656 }
657
0dff88ea
AF
658 if (angle<0)
659 angle+=2*M_PI;
660 if (angle>2*M_PI)
661 angle-=2*M_PI;
662
663 {
664 GdkColor color;
665 gdk_gc_copy(thickgc, gc);
666 gdk_gc_set_line_attributes(thickgc, CW, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
667 gdk_color_parse("#2255cc", &color);
668 gdk_gc_set_rgb_fg_color(thickgc, &color);
669 }
15614495 670 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);
0dff88ea 671
e4847ce9 672
0dff88ea
AF
673 gdk_gc_copy(thickgc, gc);
674 gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
675 for (i=0; i<180; i++) {
15614495
AF
676 c = cos(i*M_PI/90.0 + baseangle);
677 s = sin(i*M_PI/90.0 + baseangle);
e4847ce9 678
0dff88ea
AF
679 if (i%5) {
680 gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
681 } else {
682 gdouble ticksize = 2*CW;
683 gdk_draw_line (d, thickgc, x1 + (CR-CW)*c, y1 + (CR-CW)*s, x1 + (CR+ticksize)*c, y1 + (CR+ticksize)*s);
684 }
e4847ce9 685 }
0dff88ea
AF
686
687 gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
688 gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
689 gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
15614495
AF
690 c = (CR+CW*2)*cos(baseangle);
691 s = (CR+CW*2)*sin(baseangle);
692 gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
693 gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
0dff88ea
AF
694
695 /* draw labels */
696#define LABEL(x, y, w, h) { \
697 gdk_draw_rectangle(d, labgc, TRUE, (x)-2, (y)-1, (w)+4, (h)+1); \
698 gdk_draw_rectangle(d, gc, FALSE, (x)-2, (y)-1, (w)+4, (h)+1); \
699 gdk_draw_layout(d, gc, (x), (y), pl); }
700 {
701 gint wd, hd, xd, yd;
702 gint wb, hb, xb, yb;
703
704 pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
705
706 pfd = pango_font_description_from_string ("Sans 8"); // FIXME: settable option? global variable?
707 pango_layout_set_font_description (pl, pfd);
708 pango_font_description_free (pfd);
709
710 pango_layout_set_text(pl, "N", -1);
711 gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
712
713 /* draw label with distance */
714 if (distance >= 1000 && distance < 100000) {
15614495 715 g_sprintf(str, "%3.2f km", distance/1000.0);
0dff88ea 716 } else if (distance < 1000) {
15614495 717 g_sprintf(str, "%d m", (int)distance);
0dff88ea 718 } else {
15614495 719 g_sprintf(str, "%d km", (int)distance/1000);
0dff88ea
AF
720 }
721 pango_layout_set_text(pl, str, -1);
722
723 pango_layout_get_pixel_size ( pl, &wd, &hd );
724 if (dy>0) {
725 xd = (x1+x2)/2 + dy;
726 yd = (y1+y2)/2 - hd/2 - dx;
727 } else {
728 xd = (x1+x2)/2 - dy;
729 yd = (y1+y2)/2 - hd/2 + dx;
730 }
024f32c1
EB
731
732 if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
733 xd = x2 + 10;
734 yd = y2 - 5;
735 }
736
0dff88ea
AF
737 LABEL(xd, yd, wd, hd);
738
739 /* draw label with bearing */
15614495 740 g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
0dff88ea
AF
741 pango_layout_set_text(pl, str, -1);
742 pango_layout_get_pixel_size ( pl, &wb, &hb );
743 xb = x1 + CR*cos(angle-M_PI_2);
744 yb = y1 + CR*sin(angle-M_PI_2);
745
024f32c1
EB
746 if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
747 xb = x2 + 10;
748 yb = y2 + 10;
749 }
750
0dff88ea
AF
751 {
752 GdkRectangle r1 = {xd-2, yd-1, wd+4, hd+1}, r2 = {xb-2, yb-1, wb+4, hb+1};
753 if (gdk_rectangle_intersect(&r1, &r2, &r2)) {
754 xb = xd + wd + 5;
755 }
756 }
757 LABEL(xb, yb, wb, hb);
e4847ce9 758 }
03d62e57 759#undef LABEL
e4847ce9 760
024f32c1 761 g_object_unref ( G_OBJECT ( pl ) );
0dff88ea
AF
762 g_object_unref ( G_OBJECT ( labgc ) );
763 g_object_unref ( G_OBJECT ( thickgc ) );
e4847ce9
AF
764}
765
941aa6e9
AF
766typedef struct {
767 VikWindow *vw;
768 VikViewport *vvp;
769 gboolean has_oldcoord;
770 VikCoord oldcoord;
771} ruler_tool_state_t;
03d62e57 772
941aa6e9 773static gpointer ruler_create (VikWindow *vw, VikViewport *vvp)
03d62e57 774{
941aa6e9
AF
775 ruler_tool_state_t *s = g_new(ruler_tool_state_t, 1);
776 s->vw = vw;
777 s->vvp = vvp;
778 s->has_oldcoord = FALSE;
779 return s;
03d62e57
AF
780}
781
941aa6e9 782static void ruler_destroy (ruler_tool_state_t *s)
50a14534 783{
941aa6e9
AF
784 g_free(s);
785}
50a14534 786
941aa6e9
AF
787static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
788{
789 struct LatLon ll;
790 VikCoord coord;
791 gchar *temp;
792 if ( event->button == 1 ) {
a58aaed4 793 gchar *lat=NULL, *lon=NULL;
941aa6e9
AF
794 vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
795 vik_coord_to_latlon ( &coord, &ll );
a58aaed4 796 a_coords_latlon_to_string ( &ll, &lat, &lon );
941aa6e9 797 if ( s->has_oldcoord ) {
a58aaed4 798 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
941aa6e9
AF
799 s->has_oldcoord = FALSE;
800 }
801 else {
a58aaed4 802 temp = g_strdup_printf ( "%s %s", lat, lon );
941aa6e9
AF
803 s->has_oldcoord = TRUE;
804 }
50a14534 805
941aa6e9
AF
806 vik_statusbar_set_message ( s->vw->viking_vs, 3, temp );
807 g_free ( temp );
e4847ce9 808
941aa6e9
AF
809 s->oldcoord = coord;
810 }
811 else {
812 vik_viewport_set_center_screen ( s->vvp, (gint) event->x, (gint) event->y );
813 draw_update ( s->vw );
814 }
815 return VIK_LAYER_TOOL_ACK;
816}
e4847ce9 817
dc2c040e 818static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, ruler_tool_state_t *s)
941aa6e9
AF
819{
820 VikViewport *vvp = s->vvp;
821 VikWindow *vw = s->vw;
822
823 struct LatLon ll;
824 VikCoord coord;
825 gchar *temp;
826
827 if ( s->has_oldcoord ) {
828 int oldx, oldy, w1, h1, w2, h2;
829 static GdkPixmap *buf = NULL;
a58aaed4 830 gchar *lat=NULL, *lon=NULL;
941aa6e9
AF
831 w1 = vik_viewport_get_width(vvp);
832 h1 = vik_viewport_get_height(vvp);
833 if (!buf) {
834 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
835 }
836 gdk_drawable_get_size(buf, &w2, &h2);
837 if (w1 != w2 || h1 != h2) {
838 g_object_unref ( G_OBJECT ( buf ) );
839 buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
e4847ce9 840 }
e4847ce9 841
941aa6e9
AF
842 vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
843 vik_coord_to_latlon ( &coord, &ll );
844 vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
845
846 gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc,
847 vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
848 draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
849 if (draw_buf_done) {
850 static gpointer pass_along[3];
851 pass_along[0] = GTK_WIDGET(vvp)->window;
852 pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
853 pass_along[2] = buf;
854 g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
855 draw_buf_done = FALSE;
856 }
a58aaed4
GB
857 a_coords_latlon_to_string(&ll, &lat, &lon);
858 temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
941aa6e9
AF
859 vik_statusbar_set_message ( vw->viking_vs, 3, temp );
860 g_free ( temp );
acaf7113 861 }
941aa6e9
AF
862 return VIK_LAYER_TOOL_ACK;
863}
50a14534 864
941aa6e9
AF
865static VikLayerToolFuncStatus ruler_release (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
866{
867 return VIK_LAYER_TOOL_ACK;
50a14534
EB
868}
869
941aa6e9 870static void ruler_deactivate (VikLayer *vl, ruler_tool_state_t *s)
50a14534 871{
941aa6e9 872 draw_update ( s->vw );
50a14534
EB
873}
874
941aa6e9
AF
875static VikToolInterface ruler_tool =
876 { "Ruler",
877 (VikToolConstructorFunc) ruler_create,
878 (VikToolDestructorFunc) ruler_destroy,
879 (VikToolActivationFunc) NULL,
880 (VikToolActivationFunc) ruler_deactivate,
881 (VikToolMouseFunc) ruler_click,
dc2c040e 882 (VikToolMouseMoveFunc) ruler_move,
f2f2f7bf
GB
883 (VikToolMouseFunc) ruler_release,
884 NULL,
885 GDK_CURSOR_IS_PIXMAP,
5bfafde9 886 &cursor_ruler_pixbuf };
941aa6e9
AF
887/*** end ruler code ********************************************************/
888
889
890
891/********************************************************************************
892 ** Zoom tool code
893 ********************************************************************************/
894static gpointer zoomtool_create (VikWindow *vw, VikViewport *vvp)
50a14534 895{
941aa6e9 896 return vw;
50a14534
EB
897}
898
941aa6e9 899static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
50a14534 900{
941aa6e9
AF
901 vw->modified = TRUE;
902 vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
903 if ( event->button == 1 )
904 vik_viewport_zoom_in (vw->viking_vvp);
905 else if ( event->button == 3 )
906 vik_viewport_zoom_out (vw->viking_vvp);
907 draw_update ( vw );
908 return VIK_LAYER_TOOL_ACK;
909}
50a14534 910
dc2c040e 911static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event, VikViewport *vvp)
941aa6e9
AF
912{
913 return VIK_LAYER_TOOL_ACK;
914}
50a14534 915
941aa6e9
AF
916static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
917{
918 return VIK_LAYER_TOOL_ACK;
50a14534
EB
919}
920
941aa6e9
AF
921static VikToolInterface zoom_tool =
922 { "Zoom",
923 (VikToolConstructorFunc) zoomtool_create,
924 (VikToolDestructorFunc) NULL,
925 (VikToolActivationFunc) NULL,
926 (VikToolActivationFunc) NULL,
927 (VikToolMouseFunc) zoomtool_click,
dc2c040e 928 (VikToolMouseMoveFunc) zoomtool_move,
f2f2f7bf
GB
929 (VikToolMouseFunc) zoomtool_release,
930 NULL,
931 GDK_CURSOR_IS_PIXMAP,
5bfafde9 932 &cursor_zoom_pixbuf };
463f9d07 933/*** end zoom code ********************************************************/
941aa6e9 934
576cbd17
GB
935/********************************************************************************
936 ** Pan tool code
937 ********************************************************************************/
938static gpointer pantool_create (VikWindow *vw, VikViewport *vvp)
939{
940 return vw;
941}
942
943static VikLayerToolFuncStatus pantool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
944{
945 vw->modified = TRUE;
946 if ( event->button == 1 )
947 vik_window_pan_click ( vw, event );
948 draw_update ( vw );
949 return VIK_LAYER_TOOL_ACK;
950}
951
dc2c040e 952static VikLayerToolFuncStatus pantool_move (VikLayer *vl, GdkEventMotion *event, VikWindow *vw)
576cbd17
GB
953{
954 vik_window_pan_move ( vw, event );
955 return VIK_LAYER_TOOL_ACK;
956}
957
958static VikLayerToolFuncStatus pantool_release (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
959{
960 if ( event->button == 1 )
961 vik_window_pan_release ( vw, event );
962 return VIK_LAYER_TOOL_ACK;
963}
964
965static VikToolInterface pan_tool =
966 { "Pan",
967 (VikToolConstructorFunc) pantool_create,
968 (VikToolDestructorFunc) NULL,
969 (VikToolActivationFunc) NULL,
970 (VikToolActivationFunc) NULL,
971 (VikToolMouseFunc) pantool_click,
dc2c040e 972 (VikToolMouseMoveFunc) pantool_move,
f2f2f7bf
GB
973 (VikToolMouseFunc) pantool_release,
974 NULL,
975 GDK_FLEUR };
576cbd17
GB
976/*** end pan code ********************************************************/
977
8c721f83
EB
978static void draw_pan_cb ( GtkAction *a, VikWindow *vw )
979{
980 if (!strcmp(gtk_action_get_name(a), "PanNorth")) {
981 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, 0 );
982 } else if (!strcmp(gtk_action_get_name(a), "PanEast")) {
983 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp), vik_viewport_get_height(vw->viking_vvp)/2 );
984 } else if (!strcmp(gtk_action_get_name(a), "PanSouth")) {
985 vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp) );
986 } else if (!strcmp(gtk_action_get_name(a), "PanWest")) {
987 vik_viewport_set_center_screen ( vw->viking_vvp, 0, vik_viewport_get_height(vw->viking_vvp)/2 );
988 }
989 draw_update ( vw );
990}
941aa6e9 991
7de42638
EB
992static void full_screen_cb ( GtkAction *a, VikWindow *vw )
993{
994 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/FullScreen" );
995 g_assert(check_box);
996 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
997 if ( state )
998 gtk_window_fullscreen ( GTK_WINDOW(vw) );
999 else
1000 gtk_window_unfullscreen ( GTK_WINDOW(vw) );
1001}
941aa6e9 1002
e4afc73a 1003static void draw_zoom_cb ( GtkAction *a, VikWindow *vw )
50a14534 1004{
e4afc73a
EB
1005 guint what = 128;
1006
1007 if (!strcmp(gtk_action_get_name(a), "ZoomIn")) {
1008 what = -3;
1009 }
1010 else if (!strcmp(gtk_action_get_name(a), "ZoomOut")) {
1011 what = -4;
1012 }
1013 else if (!strcmp(gtk_action_get_name(a), "Zoom0.25")) {
1014 what = -2;
1015 }
1016 else if (!strcmp(gtk_action_get_name(a), "Zoom0.5")) {
1017 what = -1;
1018 }
1019 else {
1020 gchar *s = (gchar *)gtk_action_get_name(a);
1021 what = atoi(s+4);
1022 }
1023
50a14534
EB
1024 switch (what)
1025 {
1026 case -3: vik_viewport_zoom_in ( vw->viking_vvp ); break;
1027 case -4: vik_viewport_zoom_out ( vw->viking_vvp ); break;
1028 case -1: vik_viewport_set_zoom ( vw->viking_vvp, 0.5 ); break;
1029 case -2: vik_viewport_set_zoom ( vw->viking_vvp, 0.25 ); break;
1030 default: vik_viewport_set_zoom ( vw->viking_vvp, what );
1031 }
1032 draw_update ( vw );
1033}
1034
e4afc73a 1035void draw_goto_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
1036{
1037 VikCoord new_center;
e4afc73a
EB
1038
1039 if (!strcmp(gtk_action_get_name(a), "GotoLL")) {
50a14534
EB
1040 struct LatLon ll, llold;
1041 vik_coord_to_latlon ( vik_viewport_get_center ( vw->viking_vvp ), &llold );
1042 if ( a_dialog_goto_latlon ( GTK_WINDOW(vw), &ll, &llold ) )
1043 vik_coord_load_from_latlon ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &ll );
1044 else
1045 return;
1046 }
e4afc73a 1047 else if (!strcmp(gtk_action_get_name(a), "GotoUTM")) {
50a14534
EB
1048 struct UTM utm, utmold;
1049 vik_coord_to_utm ( vik_viewport_get_center ( vw->viking_vvp ), &utmold );
1050 if ( a_dialog_goto_utm ( GTK_WINDOW(vw), &utm, &utmold ) )
1051 vik_coord_load_from_utm ( &new_center, vik_viewport_get_coord_mode(vw->viking_vvp), &utm );
1052 else
1053 return;
1054 }
e4afc73a 1055 else {
8dc8da82 1056 g_critical("Houston, we've had a problem.");
e4afc73a
EB
1057 return;
1058 }
50a14534
EB
1059
1060 vik_viewport_set_center_coord ( vw->viking_vvp, &new_center );
1061 draw_update ( vw );
1062}
1063
e4afc73a 1064static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw )
50a14534 1065{
e4afc73a
EB
1066 gint type;
1067 for ( type = 0; type < VIK_LAYER_NUM_TYPES; type++ ) {
1068 if (!strcmp(vik_layer_get_interface(type)->name, gtk_action_get_name(a))) {
1069 if ( vik_layers_panel_new_layer ( vw->viking_vlp, type ) ) {
1070 draw_update ( vw );
1071 vw->modified = TRUE;
1072 }
1073 }
50a14534
EB
1074 }
1075}
1076
e4afc73a 1077static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw )
50a14534 1078{
2cebc318 1079 a_clipboard_copy_selected ( vw->viking_vlp );
50a14534
EB
1080}
1081
e4afc73a 1082static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw )
50a14534 1083{
2cebc318 1084 a_clipboard_copy_selected ( vw->viking_vlp );
e4afc73a 1085 menu_delete_layer_cb ( a, vw );
50a14534
EB
1086}
1087
e4afc73a 1088static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
1089{
1090 if ( a_clipboard_paste ( vw->viking_vlp ) )
1091 {
1092 draw_update ( vw );
1093 vw->modified = TRUE;
1094 }
1095}
1096
e4afc73a 1097static void menu_properties_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
1098{
1099 if ( ! vik_layers_panel_properties ( vw->viking_vlp ) )
4c77d5e0 1100 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to show its properties.") );
50a14534
EB
1101}
1102
d0a5f320
AF
1103static void help_about_cb ( GtkAction *a, VikWindow *vw )
1104{
1105 a_dialog_about(GTK_WINDOW(vw));
1106}
1107
e4afc73a 1108static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
1109{
1110 if ( vik_layers_panel_get_selected ( vw->viking_vlp ) )
1111 {
1112 vik_layers_panel_delete_selected ( vw->viking_vlp );
1113 vw->modified = TRUE;
1114 }
1115 else
4c77d5e0 1116 a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to delete.") );
50a14534
EB
1117}
1118
181f5d0c
MA
1119static void view_side_panel_cb ( GtkAction *a, VikWindow *vw )
1120{
1121 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ViewSidePanel" );
1122 g_assert(check_box);
1123 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1124 if ( state )
1125 gtk_widget_show(GTK_WIDGET(vw->viking_vlp));
1126 else
1127 gtk_widget_hide(GTK_WIDGET(vw->viking_vlp));
1128}
1129
941aa6e9
AF
1130/***************************************
1131 ** tool management routines
1132 **
1133 ***************************************/
1134
1135static toolbox_tools_t* toolbox_create(VikWindow *vw)
1136{
1137 toolbox_tools_t *vt = g_new(toolbox_tools_t, 1);
1138 vt->tools = NULL;
1139 vt->n_tools = 0;
1140 vt->active_tool = -1;
1141 vt->vw = vw;
1142 if (!vw->viking_vvp) {
7742da66 1143 g_critical("no viewport found.");
941aa6e9
AF
1144 exit(1);
1145 }
1146 return vt;
1147}
1148
9593a4c9 1149static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type )
941aa6e9
AF
1150{
1151 vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1);
1152 vt->tools[vt->n_tools].ti = *vti;
9593a4c9 1153 vt->tools[vt->n_tools].layer_type = layer_type;
941aa6e9
AF
1154 if (vti->create) {
1155 vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp);
1156 }
1157 else {
1158 vt->tools[vt->n_tools].state = NULL;
1159 }
1160 vt->n_tools++;
1161}
1162
1163static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name)
1164{
1165 int i;
1166 for (i=0; i<vt->n_tools; i++) {
1167 if (!strcmp(tool_name, vt->tools[i].ti.name)) {
1168 break;
1169 }
1170 }
1171 return i;
1172}
1173
1174static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name)
1175{
1176 int tool = toolbox_get_tool(vt, tool_name);
1177 toolbox_tool_t *t = &vt->tools[tool];
1178 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1179
1180 if (tool == vt->n_tools) {
7742da66 1181 g_critical("trying to activate a non-existent tool...");
941aa6e9
AF
1182 exit(1);
1183 }
1184 /* is the tool already active? */
1185 if (vt->active_tool == tool) {
1186 return;
1187 }
1188
1189 if (vt->active_tool != -1) {
1190 if (vt->tools[vt->active_tool].ti.deactivate) {
1191 vt->tools[vt->active_tool].ti.deactivate(NULL, vt->tools[vt->active_tool].state);
1192 }
1193 }
1194 if (t->ti.activate) {
1195 t->ti.activate(vl, t->state);
1196 }
1197 vt->active_tool = tool;
1198}
1199
f2f2f7bf
GB
1200static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name)
1201{
1202 int tool = toolbox_get_tool(vt, tool_name);
1203 toolbox_tool_t *t = &vt->tools[tool];
1204 if (t->ti.cursor == NULL) {
1205 if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) {
1206 GError *cursor_load_err = NULL;
1207 GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err);
1208 /* TODO: settable offeset */
1209 t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
1210 g_object_unref ( G_OBJECT(cursor_pixbuf) );
1211 } else {
1212 t->ti.cursor = gdk_cursor_new ( t->ti.cursor_type );
1213 }
1214 }
1215 return t->ti.cursor;
1216}
1217
941aa6e9
AF
1218static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
1219{
1220 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1221 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) {
9593a4c9
EB
1222 gint ltype = vt->tools[vt->active_tool].layer_type;
1223 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1224 vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state);
941aa6e9
AF
1225 }
1226}
1227
dc2c040e 1228static void toolbox_move (toolbox_tools_t *vt, GdkEventMotion *event)
941aa6e9
AF
1229{
1230 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
1231 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) {
9593a4c9
EB
1232 gint ltype = vt->tools[vt->active_tool].layer_type;
1233 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
165d30aa
EB
1234 if ( VIK_LAYER_TOOL_ACK_GRAB_FOCUS == vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state) )
1235 gtk_widget_grab_focus ( GTK_WIDGET(vt->vw->viking_vvp) );
941aa6e9
AF
1236 }
1237}
1238
1239static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event)
1240{
1241 VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
9593a4c9
EB
1242 if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release ) {
1243 gint ltype = vt->tools[vt->active_tool].layer_type;
1244 if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
1245 vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state);
941aa6e9
AF
1246 }
1247}
1248/** End tool management ************************************/
1249
8fb71d6c
EB
1250void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id )
1251{
1252 gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].name ) );
1253}
941aa6e9
AF
1254
1255/* this function gets called whenever a toolbar tool is clicked */
e4afc73a 1256static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
50a14534
EB
1257{
1258 /* White Magic, my friends ... White Magic... */
8fb71d6c 1259 int layer_id, tool_id;
f2f2f7bf 1260 const GdkCursor *cursor = NULL;
e4afc73a 1261
941aa6e9
AF
1262 toolbox_activate(vw->vt, gtk_action_get_name(a));
1263
f2f2f7bf
GB
1264 cursor = toolbox_get_cursor(vw->vt, gtk_action_get_name(a));
1265 /* We set cursor, even if it is NULL: it resets to default */
1266 gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor );
1267
576cbd17
GB
1268 if (!strcmp(gtk_action_get_name(a), "Pan")) {
1269 vw->current_tool = TOOL_PAN;
576cbd17
GB
1270 }
1271 else if (!strcmp(gtk_action_get_name(a), "Zoom")) {
e4afc73a
EB
1272 vw->current_tool = TOOL_ZOOM;
1273 }
1274 else if (!strcmp(gtk_action_get_name(a), "Ruler")) {
1275 vw->current_tool = TOOL_RULER;
1276 }
1277 else {
79845167 1278 /* TODO: only enable tools from active layer */
8fb71d6c
EB
1279 for (layer_id=0; layer_id<VIK_LAYER_NUM_TYPES; layer_id++) {
1280 for ( tool_id = 0; tool_id < vik_layer_get_interface(layer_id)->tools_count; tool_id++ ) {
1281 if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].name, gtk_action_get_name(a))) {
1282 vw->current_tool = TOOL_LAYER;
1283 vw->tool_layer_id = layer_id;
1284 vw->tool_tool_id = tool_id;
e4afc73a
EB
1285 }
1286 }
1287 }
1288 }
50a14534
EB
1289 draw_status ( vw );
1290}
1291
1292static void window_set_filename ( VikWindow *vw, const gchar *filename )
1293{
1294 gchar *title;
4c77d5e0 1295 const gchar *file;
50a14534
EB
1296 if ( vw->filename )
1297 g_free ( vw->filename );
1298 if ( filename == NULL )
1299 {
1300 vw->filename = NULL;
4c77d5e0 1301 file = _("Untitled");
50a14534
EB
1302 }
1303 else
1304 {
1305 vw->filename = g_strdup(filename);
4c77d5e0 1306 file = a_file_basename ( filename );
50a14534 1307 }
4c77d5e0
GB
1308 title = g_strdup_printf( "%s - Viking", file );
1309 gtk_window_set_title ( GTK_WINDOW(vw), title );
1310 g_free ( title );
50a14534
EB
1311}
1312
7bc965c0
GB
1313GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode )
1314{
1315 GtkWidget *mode_button;
1316 gchar *buttonname;
1317 switch ( mode ) {
794c8f18 1318#ifdef VIK_CONFIG_EXPEDIA
7bc965c0 1319 case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
794c8f18
RN
1320#endif
1321#ifdef VIK_CONFIG_OLD_GOOGLE
7bc965c0 1322 case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break;
e262c0a4 1323 case VIK_VIEWPORT_DRAWMODE_KH: buttonname = "/ui/MainMenu/View/ModeKH"; break;
794c8f18 1324#endif
7bc965c0 1325 case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break;
794c8f18 1326 default: buttonname = "/ui/MainMenu/View/ModeUTM";
7bc965c0
GB
1327 }
1328 mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
1329 g_assert ( mode_button );
1330 return mode_button;
1331}
1332
50a14534
EB
1333void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename )
1334{
1335 switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) )
1336 {
1337 case 0:
4c77d5e0 1338 a_dialog_error_msg ( GTK_WINDOW(vw), _("The file you requested could not be opened.") );
50a14534
EB
1339 break;
1340 case 1:
1341 {
1342 GtkWidget *mode_button;
50a14534
EB
1343 if ( change_filename )
1344 window_set_filename ( vw, filename );
7bc965c0 1345 mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) );
50a14534
EB
1346 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. */
1347 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE );
1348 vw->only_updating_coord_mode_ui = FALSE;
1349
1350 vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) );
1657065a
QT
1351
1352 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
1353 g_assert ( mode_button );
1354 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_scale(vw->viking_vvp) );
1355
1356 mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
1357 g_assert ( mode_button );
1358 gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) );
50a14534
EB
1359 }
1360 default: draw_update ( vw );
1361 }
1362}
e4afc73a 1363static void load_file ( GtkAction *a, VikWindow *vw )
50a14534 1364{
6e4a49aa
MA
1365 GSList *files = NULL;
1366 GSList *cur_file = NULL;
e4afc73a
EB
1367 gboolean newwindow;
1368 if (!strcmp(gtk_action_get_name(a), "Open")) {
1369 newwindow = TRUE;
1370 }
1371 else if (!strcmp(gtk_action_get_name(a), "Append")) {
1372 newwindow = FALSE;
1373 }
1374 else {
8dc8da82 1375 g_critical("Houston, we've had a problem.");
e4afc73a
EB
1376 return;
1377 }
1378
50a14534
EB
1379 if ( ! vw->open_dia )
1380 {
6e4a49aa
MA
1381 vw->open_dia = gtk_file_chooser_dialog_new (_("Please select a GPS data file to open. "),
1382 GTK_WINDOW(vw),
1383 GTK_FILE_CHOOSER_ACTION_OPEN,
1384 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1385 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1386 NULL);
1387 gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(vw->open_dia), TRUE );
50a14534
EB
1388 gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) );
1389 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE );
1390 }
6e4a49aa 1391 if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_ACCEPT )
50a14534
EB
1392 {
1393 gtk_widget_hide ( vw->open_dia );
a5fd2196 1394#ifdef VIKING_PROMPT_IF_MODIFIED
50a14534 1395 if ( (vw->modified || vw->filename) && newwindow )
a5fd2196
QT
1396#else
1397 if ( vw->filename && newwindow )
1398#endif
6e4a49aa 1399 g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) ) );
50a14534 1400 else {
6e4a49aa
MA
1401 files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(vw->open_dia) );
1402 gboolean change_fn = newwindow && (g_slist_length(files)==1); /* only change fn if one file */
1403
1404 cur_file = files;
1405 while ( cur_file ) {
1406 gchar *file_name = cur_file->data;
1407 vik_window_open_file ( vw, file_name, change_fn );
1408 g_free (file_name);
1409 cur_file = g_slist_next (cur_file);
50a14534 1410 }
6e4a49aa 1411 g_slist_free (files);
50a14534
EB
1412 }
1413 }
1414 else
1415 gtk_widget_hide ( vw->open_dia );
1416}
1417
e4afc73a 1418static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
50a14534
EB
1419{
1420 gboolean rv = FALSE;
1421 const gchar *fn;
1422 if ( ! vw->save_dia )
1423 {
6e4a49aa
MA
1424 vw->save_dia = gtk_file_chooser_dialog_new (_("Save as Viking File."),
1425 GTK_WINDOW(vw),
1426 GTK_FILE_CHOOSER_ACTION_SAVE,
1427 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1428 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1429 NULL);
50a14534
EB
1430 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) );
1431 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
1432 }
1433
6e4a49aa 1434 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_ACCEPT )
50a14534 1435 {
6e4a49aa 1436 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_dia) );
45acf79e 1437 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 ) ) )
50a14534
EB
1438 {
1439 window_set_filename ( vw, fn );
1440 rv = window_save ( vw );
1441 vw->modified = FALSE;
1442 break;
1443 }
1444 }
1445 gtk_widget_hide ( vw->save_dia );
1446 return rv;
1447}
1448
1449static gboolean window_save ( VikWindow *vw )
1450{
1451 if ( a_file_save ( vik_layers_panel_get_top_layer ( vw->viking_vlp ), vw->viking_vvp, vw->filename ) )
1452 return TRUE;
1453 else
1454 {
4c77d5e0 1455 a_dialog_error_msg ( GTK_WINDOW(vw), _("The filename you requested could not be opened for writing.") );
50a14534
EB
1456 return FALSE;
1457 }
1458}
1459
e4afc73a 1460static gboolean save_file ( GtkAction *a, VikWindow *vw )
50a14534
EB
1461{
1462 if ( ! vw->filename )
e4afc73a 1463 return save_file_as ( NULL, vw );
50a14534
EB
1464 else
1465 {
1466 vw->modified = FALSE;
1467 return window_save ( vw );
1468 }
1469}
1470
1d1bc3c1
EB
1471static void acquire_from_gps ( GtkAction *a, VikWindow *vw )
1472{
7b3479e3
EB
1473 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface );
1474}
1475
1476static void acquire_from_google ( GtkAction *a, VikWindow *vw )
1477{
1478 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
1d1bc3c1
EB
1479}
1480
1ef9e637 1481#ifdef VIK_CONFIG_GEOCACHES
3333c069
EB
1482static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
1483{
1484 a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface );
1485}
1ef9e637 1486#endif
3333c069 1487
369126f3
QT
1488static void goto_address( GtkAction *a, VikWindow *vw)
1489{
1490 a_google_search(vw, vw->viking_vlp, vw->viking_vvp);
1491}
1492
17a1f8f9
EB
1493static void preferences_cb ( GtkAction *a, VikWindow *vw )
1494{
1495 a_preferences_show_window ( GTK_WINDOW(vw) );
1496}
1497
e4afc73a 1498static void clear_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
1499{
1500 vik_layers_panel_clear ( vw->viking_vlp );
1501 window_set_filename ( vw, NULL );
1502 draw_update ( vw );
1503}
1504
e4afc73a 1505static void window_close ( GtkAction *a, VikWindow *vw )
50a14534
EB
1506{
1507 if ( ! delete_event ( vw ) )
1508 gtk_widget_destroy ( GTK_WIDGET(vw) );
1509}
1510
2bf7cadd
QT
1511static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw )
1512{
7bb60307 1513 if (save_file( NULL, vw)) {
2bf7cadd 1514 window_close( NULL, vw);
7bb60307
QT
1515 return(TRUE);
1516 }
2bf7cadd
QT
1517 else
1518 return(FALSE);
1519}
1520
e4afc73a 1521static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
50a14534
EB
1522{
1523 gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1524 if ( a_dialog_custom_zoom ( GTK_WINDOW(vw), &xmpp, &ympp ) )
1525 {
1526 vik_viewport_set_xmpp ( vw->viking_vvp, xmpp );
1527 vik_viewport_set_ympp ( vw->viking_vvp, ympp );
1528 draw_update ( vw );
1529 }
1530}
1531
1532static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h, gdouble zoom, gboolean save_as_png )
1533{
1534 /* more efficient way: stuff draws directly to pixbuf (fork viewport) */
1535 GdkPixbuf *pixbuf_to_save;
1536 gdouble old_xmpp, old_ympp;
1537 GError *error = NULL;
1538
1539 /* backup old zoom & set new */
1540 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1541 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1542 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1543
1544 /* reset width and height: */
1545 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1546
1547 /* draw all layers */
1548 draw_redraw ( vw );
1549
1550 /* save buffer as file. */
1551 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);
1552 gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL );
1553 if (error)
1554 {
7742da66 1555 g_warning("Unable to write to file %s: %s", fn, error->message );
50a14534
EB
1556 g_error_free (error);
1557 }
1558 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1559
1560 /* pretend like nothing happened ;) */
1561 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1562 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1563 vik_viewport_configure ( vw->viking_vvp );
1564 draw_update ( vw );
1565}
1566
1567static 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 )
1568{
1569 gulong size = sizeof(gchar) * (strlen(fn) + 15);
1570 gchar *name_of_file = g_malloc ( size );
1571 guint x = 1, y = 1;
1572 struct UTM utm_orig, utm;
1573
1574 /* *** copied from above *** */
1575 GdkPixbuf *pixbuf_to_save;
1576 gdouble old_xmpp, old_ympp;
1577 GError *error = NULL;
1578
1579 /* backup old zoom & set new */
1580 old_xmpp = vik_viewport_get_xmpp ( vw->viking_vvp );
1581 old_ympp = vik_viewport_get_ympp ( vw->viking_vvp );
1582 vik_viewport_set_zoom ( vw->viking_vvp, zoom );
1583
1584 /* reset width and height: do this only once for all images (same size) */
1585 vik_viewport_configure_manually ( vw->viking_vvp, w, h );
1586 /* *** end copy from above *** */
1587
1588 g_assert ( vik_viewport_get_coord_mode ( vw->viking_vvp ) == VIK_COORD_UTM );
1589
f83131b9 1590 g_mkdir(fn,0777);
50a14534
EB
1591
1592 utm_orig = *((const struct UTM *)vik_viewport_get_center ( vw->viking_vvp ));
1593
1594 for ( y = 1; y <= tiles_h; y++ )
1595 {
1596 for ( x = 1; x <= tiles_w; x++ )
1597 {
3d9454e6 1598 g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, G_DIR_SEPARATOR, y, x, save_as_png ? "png" : "jpg" );
50a14534
EB
1599 utm = utm_orig;
1600 if ( tiles_w & 0x1 )
1601 utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom);
1602 else
1603 utm.easting += ((gdouble)x - (((gdouble)tiles_w)+1)/2) * (w*zoom);
1604 if ( tiles_h & 0x1 ) /* odd */
1605 utm.northing -= ((gdouble)y - ceil(((gdouble)tiles_h)/2)) * (h*zoom);
1606 else /* even */
1607 utm.northing -= ((gdouble)y - (((gdouble)tiles_h)+1)/2) * (h*zoom);
1608
1609 /* move to correct place. */
1610 vik_viewport_set_center_utm ( vw->viking_vvp, &utm );
1611
1612 draw_redraw ( vw );
1613
1614 /* save buffer as file. */
1615 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);
1616 gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL );
1617 if (error)
1618 {
7742da66 1619 g_warning("Unable to write to file %s: %s", name_of_file, error->message );
50a14534
EB
1620 g_error_free (error);
1621 }
1622
1623 g_object_unref ( G_OBJECT(pixbuf_to_save) );
1624 }
1625 }
1626
1627 vik_viewport_set_center_utm ( vw->viking_vvp, &utm_orig );
1628 vik_viewport_set_xmpp ( vw->viking_vvp, old_xmpp );
1629 vik_viewport_set_ympp ( vw->viking_vvp, old_ympp );
1630 vik_viewport_configure ( vw->viking_vvp );
1631 draw_update ( vw );
1632
1633 g_free ( name_of_file );
1634}
1635
1636static void draw_to_image_file_current_window_cb(GtkWidget* widget,GdkEventButton *event,gpointer *pass_along)
1637{
1638 VikWindow *vw = VIK_WINDOW(pass_along[0]);
1639 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1640 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1641 gdouble width_min, width_max, height_min, height_max;
1642 gint width, height;
1643
1644 gtk_spin_button_get_range ( width_spin, &width_min, &width_max );
1645 gtk_spin_button_get_range ( height_spin, &height_min, &height_max );
1646
1647 /* TODO: support for xzoom and yzoom values */
1648 width = vik_viewport_get_width ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1649 height = vik_viewport_get_height ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
1650
1651 if ( width > width_max || width < width_min || height > height_max || height < height_min )
4c77d5e0 1652 a_dialog_info_msg ( GTK_WINDOW(vw), _("Viewable region outside allowable pixel size bounds for image. Clipping width/height values.") );
50a14534
EB
1653
1654 gtk_spin_button_set_value ( width_spin, width );
1655 gtk_spin_button_set_value ( height_spin, height );
1656}
1657
1658static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
1659{
1660 GtkSpinButton *width_spin = GTK_SPIN_BUTTON(pass_along[1]), *height_spin = GTK_SPIN_BUTTON(pass_along[2]);
1661 GtkSpinButton *zoom_spin = GTK_SPIN_BUTTON(pass_along[3]);
1662 gchar *label_text;
1663 gdouble w, h;
1664 w = gtk_spin_button_get_value(width_spin) * gtk_spin_button_get_value(zoom_spin);
1665 h = gtk_spin_button_get_value(height_spin) * gtk_spin_button_get_value(zoom_spin);
1666 if (pass_along[4]) /* save many images; find TOTAL area covered */
1667 {
1668 w *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[4]));
1669 h *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[5]));
1670 }
4c77d5e0 1671 label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. km)"), (glong)w, (glong)h, (w*h/1000000));
50a14534
EB
1672 gtk_label_set_text(GTK_LABEL(pass_along[6]), label_text);
1673 g_free ( label_text );
1674}
1675
1676static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_image_only )
1677{
1678 /* todo: default for answers inside VikWindow or static (thruout instance) */
4c77d5e0 1679 GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Save to Image File"), GTK_WINDOW(vw),
50a14534
EB
1680 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1681 GTK_STOCK_CANCEL,
1682 GTK_RESPONSE_REJECT,
1683 GTK_STOCK_OK,
1684 GTK_RESPONSE_ACCEPT,
10888930 1685 NULL );
50a14534
EB
1686 GtkWidget *width_label, *width_spin, *height_label, *height_spin;
1687 GtkWidget *png_radio, *jpeg_radio;
1688 GtkWidget *current_window_button;
1689 gpointer current_window_pass_along[7];
1690 GtkWidget *zoom_label, *zoom_spin;
1691 GtkWidget *total_size_label;
1692
1693 /* only used if (!one_image_only) */
886031df 1694 GtkWidget *tiles_width_spin = NULL, *tiles_height_spin = NULL;
50a14534
EB
1695
1696
4c77d5e0 1697 width_label = gtk_label_new ( _("Width (pixels):") );
50a14534 1698 width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_width, 10, 5000, 10, 100, 0 )), 10, 0 );
4c77d5e0 1699 height_label = gtk_label_new ( _("Height (pixels):") );
50a14534
EB
1700 height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_height, 10, 5000, 10, 100, 0 )), 10, 0 );
1701
4c77d5e0 1702 zoom_label = gtk_label_new ( _("Zoom (meters per pixel):") );
50a14534
EB
1703 /* TODO: separate xzoom and yzoom factors */
1704 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);
1705
1706 total_size_label = gtk_label_new ( NULL );
1707
4c77d5e0 1708 current_window_button = gtk_button_new_with_label ( _("Area in current viewable window") );
50a14534
EB
1709 current_window_pass_along [0] = vw;
1710 current_window_pass_along [1] = width_spin;
1711 current_window_pass_along [2] = height_spin;
1712 current_window_pass_along [3] = zoom_spin;
1713 current_window_pass_along [4] = NULL; /* used for one_image_only != 1 */
1714 current_window_pass_along [5] = NULL;
1715 current_window_pass_along [6] = total_size_label;
1716 g_signal_connect ( G_OBJECT(current_window_button), "button_press_event", G_CALLBACK(draw_to_image_file_current_window_cb), current_window_pass_along );
1717
4c77d5e0
GB
1718 png_radio = gtk_radio_button_new_with_label ( NULL, _("Save as PNG") );
1719 jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), _("Save as JPEG") );
50a14534
EB
1720
1721 if ( ! vw->draw_image_save_as_png )
1722 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE );
1723
1724 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_label, FALSE, FALSE, 0);
1725 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), width_spin, FALSE, FALSE, 0);
1726 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_label, FALSE, FALSE, 0);
1727 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), height_spin, FALSE, FALSE, 0);
1728 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), current_window_button, FALSE, FALSE, 0);
1729 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), png_radio, FALSE, FALSE, 0);
1730 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), jpeg_radio, FALSE, FALSE, 0);
1731 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_label, FALSE, FALSE, 0);
1732 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), zoom_spin, FALSE, FALSE, 0);
1733
1734 if ( ! one_image_only )
1735 {
1736 GtkWidget *tiles_width_label, *tiles_height_label;
1737
1738
4c77d5e0 1739 tiles_width_label = gtk_label_new ( _("East-west image tiles:") );
50a14534 1740 tiles_width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
4c77d5e0 1741 tiles_height_label = gtk_label_new ( _("North-south image tiles:") );
50a14534
EB
1742 tiles_height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
1743 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_label, FALSE, FALSE, 0);
1744 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_spin, FALSE, FALSE, 0);
1745 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_label, FALSE, FALSE, 0);
1746 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_height_spin, FALSE, FALSE, 0);
1747
1748 current_window_pass_along [4] = tiles_width_spin;
1749 current_window_pass_along [5] = tiles_height_spin;
1750 g_signal_connect ( G_OBJECT(tiles_width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1751 g_signal_connect ( G_OBJECT(tiles_height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1752 }
1753 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), total_size_label, FALSE, FALSE, 0);
1754 g_signal_connect ( G_OBJECT(width_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1755 g_signal_connect ( G_OBJECT(height_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1756 g_signal_connect ( G_OBJECT(zoom_spin), "value-changed", G_CALLBACK(draw_to_image_file_total_area_cb), current_window_pass_along );
1757
1758 draw_to_image_file_total_area_cb ( NULL, current_window_pass_along ); /* set correct size info now */
1759
1760 gtk_widget_show_all ( GTK_DIALOG(dialog)->vbox );
1761
1762 if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT )
1763 {
1764 gtk_widget_hide ( GTK_WIDGET(dialog) );
1765 if ( one_image_only )
1766 save_image_file ( vw, fn,
1767 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1768 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1769 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1770 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ) );
1771 else {
1772 if ( vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM )
1773 save_image_dir ( vw, fn,
1774 vw->draw_image_width = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(width_spin) ),
1775 vw->draw_image_height = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(height_spin) ),
1776 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(zoom_spin) ), /* do not save this value, default is current zoom */
1777 vw->draw_image_save_as_png = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(png_radio) ),
1778 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_width_spin) ),
1779 gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_height_spin) ) );
1780 else
4c77d5e0 1781 a_dialog_error_msg ( GTK_WINDOW(vw), _("You must be in UTM mode to use this feature") );
50a14534
EB
1782 }
1783 }
1784 gtk_widget_destroy ( GTK_WIDGET(dialog) );
1785}
1786
1787
e4afc73a 1788static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw )
50a14534 1789{
50a14534 1790 const gchar *fn;
f2a1ca71 1791 if (!vw->save_img_dia) {
6e4a49aa
MA
1792 vw->save_img_dia = gtk_file_chooser_dialog_new (_("Save Image"),
1793 GTK_WINDOW(vw),
1794 GTK_FILE_CHOOSER_ACTION_SAVE,
1795 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1796 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1797 NULL);
f2a1ca71
QT
1798 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) );
1799 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE );
1800 }
50a14534 1801
6e4a49aa 1802 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_ACCEPT )
50a14534 1803 {
6e4a49aa 1804 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dia) );
45acf79e 1805 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 ) ) )
50a14534 1806 {
50a14534
EB
1807 draw_to_image_file ( vw, fn, TRUE );
1808 break;
1809 }
1810 }
f2a1ca71 1811 gtk_widget_hide ( vw->save_img_dia );
50a14534
EB
1812}
1813
e4afc73a 1814static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw )
50a14534 1815{
6e4a49aa
MA
1816 gchar *fn = NULL;
1817
f2a1ca71 1818 if (!vw->save_img_dir_dia) {
6e4a49aa
MA
1819 vw->save_img_dir_dia = gtk_file_chooser_dialog_new (_("Choose a directory to hold images"),
1820 GTK_WINDOW(vw),
1821 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1822 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1823 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1824 NULL);
f2a1ca71
QT
1825 gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) );
1826 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE );
1827 }
6e4a49aa
MA
1828
1829 while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_ACCEPT )
50a14534 1830 {
6e4a49aa
MA
1831 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(vw->save_img_dir_dia) );
1832 if ( fn )
50a14534 1833 {
50a14534 1834 draw_to_image_file ( vw, fn, FALSE );
6e4a49aa
MA
1835 g_free(fn);
1836 fn = NULL;
50a14534
EB
1837 break;
1838 }
1839 }
f2a1ca71 1840 gtk_widget_hide ( vw->save_img_dir_dia );
50a14534
EB
1841}
1842
9a995996 1843#if GTK_CHECK_VERSION(2,10,0)
42f34743
QT
1844static void print_cb ( GtkAction *a, VikWindow *vw )
1845{
1846 a_print(vw, vw->viking_vvp);
1847}
9a995996 1848#endif
42f34743 1849
50a14534 1850/* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */
e4afc73a 1851static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWindow *vw )
50a14534 1852{
e4afc73a
EB
1853 VikViewportDrawMode drawmode;
1854 if (!strcmp(gtk_action_get_name(a), "ModeUTM")) {
1855 drawmode = VIK_VIEWPORT_DRAWMODE_UTM;
1856 }
1857 else if (!strcmp(gtk_action_get_name(a), "ModeExpedia")) {
1858 drawmode = VIK_VIEWPORT_DRAWMODE_EXPEDIA;
1859 }
1860 else if (!strcmp(gtk_action_get_name(a), "ModeGoogle")) {
1861 drawmode = VIK_VIEWPORT_DRAWMODE_GOOGLE;
1862 }
1863 else if (!strcmp(gtk_action_get_name(a), "ModeKH")) {
1864 drawmode = VIK_VIEWPORT_DRAWMODE_KH;
1865 }
1866 else if (!strcmp(gtk_action_get_name(a), "ModeMercator")) {
1867 drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
1868 }
1869 else {
8dc8da82 1870 g_critical("Houston, we've had a problem.");
e4afc73a
EB
1871 return;
1872 }
1873
50a14534
EB
1874 if ( !vw->only_updating_coord_mode_ui )
1875 {
1876 VikViewportDrawMode olddrawmode = vik_viewport_get_drawmode ( vw->viking_vvp );
1877 if ( olddrawmode != drawmode )
1878 {
1879 /* this takes care of coord mode too */
1880 vik_viewport_set_drawmode ( vw->viking_vvp, drawmode );
1881 if ( drawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
1882 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_UTM );
1883 } else if ( olddrawmode == VIK_VIEWPORT_DRAWMODE_UTM ) {
1884 vik_layers_panel_change_coord_mode ( vw->viking_vlp, VIK_COORD_LATLON );
1885 }
1886 draw_update ( vw );
1887 }
1888 }
1889}
1890
35c7c0ba
EB
1891static void set_draw_scale ( GtkAction *a, VikWindow *vw )
1892{
1657065a
QT
1893 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
1894 g_assert(check_box);
1895 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1896 vik_viewport_set_draw_scale ( vw->viking_vvp, state );
35c7c0ba
EB
1897 draw_update ( vw );
1898}
1899
c933487f
QT
1900static void set_draw_centermark ( GtkAction *a, VikWindow *vw )
1901{
1657065a
QT
1902 GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
1903 g_assert(check_box);
1904 gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
1905 vik_viewport_set_draw_centermark ( vw->viking_vvp, state );
c933487f
QT
1906 draw_update ( vw );
1907}
1908
e4afc73a 1909static void set_bg_color ( GtkAction *a, VikWindow *vw )
50a14534 1910{
4c77d5e0 1911 GtkWidget *colorsd = gtk_color_selection_dialog_new ( _("Choose a background color") );
50a14534
EB
1912 GdkColor *color = vik_viewport_get_background_gdkcolor ( vw->viking_vvp );
1913 gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
1914 gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
1915 if ( gtk_dialog_run ( GTK_DIALOG(colorsd) ) == GTK_RESPONSE_OK )
1916 {
1917 gtk_color_selection_get_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
1918 vik_viewport_set_background_gdkcolor ( vw->viking_vvp, color );
1919 draw_update ( vw );
1920 }
1921 g_free ( color );
1922 gtk_widget_destroy ( colorsd );
1923}
1924
941aa6e9
AF
1925
1926
1927/***********************************************************************************************
1928 ** GUI Creation
1929 ***********************************************************************************************/
1930
e4afc73a 1931static GtkActionEntry entries[] = {
5515e2d3
JJ
1932 { "File", NULL, N_("_File"), 0, 0, 0 },
1933 { "Edit", NULL, N_("_Edit"), 0, 0, 0 },
1934 { "View", NULL, N_("_View"), 0, 0, 0 },
1935 { "SetZoom", NULL, N_("_Zoom"), 0, 0, 0 },
1936 { "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
1937 { "Layers", NULL, N_("_Layers"), 0, 0, 0 },
1938 { "Tools", NULL, N_("_Tools"), 0, 0, 0 },
1939 { "Help", NULL, N_("_Help"), 0, 0, 0 },
1940
1941 { "New", GTK_STOCK_NEW, N_("_New"), "<control>N", N_("New file"), (GCallback)newwindow_cb },
1942 { "Open", GTK_STOCK_OPEN, N_("_Open"), "<control>O", N_("Open a file"), (GCallback)load_file },
1943 { "Append", GTK_STOCK_ADD, N_("A_ppend File"), NULL, N_("Append data from a different file"), (GCallback)load_file },
1944 { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 },
1945 { "AcquireGPS", NULL, N_("From _GPS"), NULL, N_("Transfer data from a GPS device"), (GCallback)acquire_from_gps },
1946 { "AcquireGoogle", NULL, N_("Google _Directions"), NULL, N_("Get driving directions from Google"), (GCallback)acquire_from_google },
1ef9e637 1947#ifdef VIK_CONFIG_GEOCACHES
5515e2d3 1948 { "AcquireGC", NULL, N_("Geo_caches"), NULL, N_("Get Geocaches from geocaching.com"), (GCallback)acquire_from_gc },
1ef9e637 1949#endif
5515e2d3
JJ
1950 { "Save", GTK_STOCK_SAVE, N_("_Save"), "<control>S", N_("Save the file"), (GCallback)save_file },
1951 { "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As"), NULL, N_("Save the file under different name"), (GCallback)save_file_as },
1952 { "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 },
1953 { "GenImgDir", GTK_STOCK_DND_MULTIPLE, N_("Generate _Directory of Images"), NULL, N_("FIXME:IMGDIR"), (GCallback)draw_to_image_dir_cb },
9a995996
EB
1954
1955#if GTK_CHECK_VERSION(2,10,0)
5515e2d3 1956 { "Print", GTK_STOCK_PRINT, N_("_Print..."), NULL, N_("Print maps"), (GCallback)print_cb },
9a995996
EB
1957#endif
1958
5515e2d3
JJ
1959 { "Exit", GTK_STOCK_QUIT, N_("E_xit"), "<control>W", N_("Exit the program"), (GCallback)window_close },
1960 { "SaveExit", GTK_STOCK_QUIT, N_("Save and Exit"), NULL, N_("Save and Exit the program"), (GCallback)save_file_and_exit },
1961
3ddcc049 1962 { "GoogleMapsSearch", GTK_STOCK_JUMP_TO, N_("Go To Google Maps location"), NULL, N_("Go to address/place using Google Maps search"), (GCallback)goto_address },
5515e2d3
JJ
1963 { "GotoLL", GTK_STOCK_QUIT, N_("_Go to Lat\\/Lon..."), NULL, N_("Go to arbitrary lat\\/lon coordinate"), (GCallback)draw_goto_cb },
1964 { "GotoUTM", GTK_STOCK_QUIT, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb },
1965 { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."), NULL, NULL, (GCallback)set_bg_color },
1966 { "ZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus", NULL, (GCallback)draw_zoom_cb },
1967 { "ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus", NULL, (GCallback)draw_zoom_cb },
7f9f736d 1968 { "ZoomTo", GTK_STOCK_ZOOM_FIT, N_("Zoom _To"), "<control>Z", NULL, (GCallback)zoom_to_cb },
5515e2d3
JJ
1969 { "Zoom0.25", NULL, N_("0.25"), NULL, NULL, (GCallback)draw_zoom_cb },
1970 { "Zoom0.5", NULL, N_("0.5"), NULL, NULL, (GCallback)draw_zoom_cb },
1971 { "Zoom1", NULL, N_("1"), NULL, NULL, (GCallback)draw_zoom_cb },
1972 { "Zoom2", NULL, N_("2"), NULL, NULL, (GCallback)draw_zoom_cb },
1973 { "Zoom4", NULL, N_("4"), NULL, NULL, (GCallback)draw_zoom_cb },
1974 { "Zoom8", NULL, N_("8"), NULL, NULL, (GCallback)draw_zoom_cb },
1975 { "Zoom16", NULL, N_("16"), NULL, NULL, (GCallback)draw_zoom_cb },
1976 { "Zoom32", NULL, N_("32"), NULL, NULL, (GCallback)draw_zoom_cb },
1977 { "Zoom64", NULL, N_("64"), NULL, NULL, (GCallback)draw_zoom_cb },
1978 { "Zoom128", NULL, N_("128"), NULL, NULL, (GCallback)draw_zoom_cb },
1979 { "PanNorth", NULL, N_("Pan North"), "<control>Up", NULL, (GCallback)draw_pan_cb },
1980 { "PanEast", NULL, N_("Pan East"), "<control>Right", NULL, (GCallback)draw_pan_cb },
1981 { "PanSouth", NULL, N_("Pan South"), "<control>Down", NULL, (GCallback)draw_pan_cb },
1982 { "PanWest", NULL, N_("Pan West"), "<control>Left", NULL, (GCallback)draw_pan_cb },
1983 { "BGJobs", GTK_STOCK_EXECUTE, N_("Background _Jobs"), NULL, NULL, (GCallback)a_background_show_window },
1984
1985 { "Cut", GTK_STOCK_CUT, N_("Cu_t"), NULL, NULL, (GCallback)menu_cut_layer_cb },
1986 { "Copy", GTK_STOCK_COPY, N_("_Copy"), NULL, NULL, (GCallback)menu_copy_layer_cb },
1987 { "Paste", GTK_STOCK_PASTE, N_("_Paste"), NULL, NULL, (GCallback)menu_paste_layer_cb },
1988 { "Delete", GTK_STOCK_DELETE, N_("_Delete"), NULL, NULL, (GCallback)menu_delete_layer_cb },
1989 { "DeleteAll", NULL, N_("Delete All"), NULL, NULL, (GCallback)clear_cb },
17a1f8f9 1990 { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences..."), NULL, NULL, (GCallback)preferences_cb },
5515e2d3
JJ
1991 { "Properties",GTK_STOCK_PROPERTIES, N_("_Properties"), NULL, NULL, (GCallback)menu_properties_cb },
1992
1993 { "About", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, (GCallback)help_about_cb },
e4afc73a
EB
1994};
1995
1996/* Radio items */
1997static GtkRadioActionEntry mode_entries[] = {
5515e2d3
JJ
1998 { "ModeUTM", NULL, N_("_UTM Mode"), "<control>u", NULL, 0 },
1999 { "ModeExpedia", NULL, N_("_Expedia Mode"), "<control>e", NULL, 1 },
2000 { "ModeGoogle", NULL, N_("_Old Google Mode"), "<control>o", NULL, 2 },
2001 { "ModeKH", NULL, N_("Old _KH Mode"), "<control>k", NULL, 3 },
2002 { "ModeMercator", NULL, N_("_Google Mode"), "<control>g", NULL, 4 }
50a14534
EB
2003};
2004
e4afc73a 2005static GtkRadioActionEntry tool_entries[] = {
576cbd17
GB
2006 { "Pan", "vik-icon-pan", N_("_Pan"), "<control><shift>P", N_("Pan Tool"), 0 },
2007 { "Zoom", "vik-icon-zoom", N_("_Zoom"), "<control><shift>Z", N_("Zoom Tool"), 1 },
2008 { "Ruler", "vik-icon-ruler", N_("_Ruler"), "<control><shift>R", N_("Ruler Tool"), 2 }
e4afc73a 2009};
50a14534 2010
35c7c0ba 2011static GtkToggleActionEntry toggle_entries[] = {
94807fab
GB
2012 { "ShowScale", NULL, N_("Show Scale"), NULL, N_("Show Scale"), (GCallback)set_draw_scale, TRUE },
2013 { "ShowCenterMark", NULL, N_("Show Center Mark"), NULL, N_("Show Center Mark"), (GCallback)set_draw_centermark, TRUE },
2014 { "FullScreen", GTK_STOCK_FULLSCREEN, N_("Full Screen"), "F11", N_("Activate full screen mode"), (GCallback)full_screen_cb, FALSE },
2015 { "ViewSidePanel", GTK_STOCK_INDEX, N_("Show Side Panel"), "F9", N_("Show Side Panel"), (GCallback)view_side_panel_cb, TRUE },
35c7c0ba
EB
2016};
2017
a527cfff 2018#include "menu.xml.h"
e4afc73a 2019static void window_create_ui( VikWindow *window )
50a14534 2020{
e4afc73a
EB
2021 GtkUIManager *uim;
2022 GtkActionGroup *action_group;
50a14534 2023 GtkAccelGroup *accel_group;
e4afc73a 2024 GError *error;
e4afc73a
EB
2025 guint i, j, mid;
2026 GtkIconFactory *icon_factory;
2027 GtkIconSet *icon_set;
e4afc73a
EB
2028 GtkRadioActionEntry *tools = NULL, *radio;
2029 guint ntools;
2030
2031 uim = gtk_ui_manager_new ();
2032 window->uim = uim;
2033
9593a4c9
EB
2034 toolbox_add_tool(window->vt, &ruler_tool, TOOL_LAYER_TYPE_NONE);
2035 toolbox_add_tool(window->vt, &zoom_tool, TOOL_LAYER_TYPE_NONE);
576cbd17 2036 toolbox_add_tool(window->vt, &pan_tool, TOOL_LAYER_TYPE_NONE);
941aa6e9 2037
e4afc73a 2038 error = NULL;
a527cfff 2039 if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) {
e4afc73a
EB
2040 g_error_free (error);
2041 exit (1);
2042 }
2043
2044 action_group = gtk_action_group_new ("MenuActions");
5515e2d3 2045 gtk_action_group_set_translation_domain(action_group, PACKAGE_NAME);
e4afc73a 2046 gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
35c7c0ba 2047 gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
6a9ff0ee 2048 gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window);
e4afc73a
EB
2049
2050 icon_factory = gtk_icon_factory_new ();
ee36ac4f 2051 gtk_icon_factory_add_default (icon_factory);
e4afc73a
EB
2052
2053 register_vik_icons(icon_factory);
2054
2055 ntools = 0;
2056 for (i=0; i<G_N_ELEMENTS(tool_entries); i++) {
2057 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2058 radio = &tools[ntools];
2059 ntools++;
2060 *radio = tool_entries[i];
2061 radio->value = ntools;
2062 }
2063
2064 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2065 GtkActionEntry action;
2066 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Layers/",
2067 vik_layer_get_interface(i)->name,
2068 vik_layer_get_interface(i)->name,
2069 GTK_UI_MANAGER_MENUITEM, FALSE);
2070
2071 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (vik_layer_get_interface(i)->icon, FALSE, NULL ));
2072 gtk_icon_factory_add (icon_factory, vik_layer_get_interface(i)->name, icon_set);
2073 gtk_icon_set_unref (icon_set);
2074
2075 action.name = vik_layer_get_interface(i)->name;
2076 action.stock_id = vik_layer_get_interface(i)->name;
4c77d5e0 2077 action.label = g_strdup_printf( _("New %s Layer"), vik_layer_get_interface(i)->name);
e4afc73a
EB
2078 action.accelerator = NULL;
2079 action.tooltip = NULL;
2080 action.callback = (GCallback)menu_addlayer_cb;
2081 gtk_action_group_add_actions(action_group, &action, 1, window);
2082
2083 if ( vik_layer_get_interface(i)->tools_count ) {
2084 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2085 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE);
2086 }
2087
2088 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2089 tools = g_renew(GtkRadioActionEntry, tools, ntools+1);
2090 radio = &tools[ntools];
2091 ntools++;
2092
e4afc73a 2093 gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools",
4c77d5e0 2094 _(vik_layer_get_interface(i)->tools[j].name),
e4afc73a
EB
2095 vik_layer_get_interface(i)->tools[j].name,
2096 GTK_UI_MANAGER_MENUITEM, FALSE);
2097 gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems",
4c77d5e0 2098 _(vik_layer_get_interface(i)->tools[j].name),
e4afc73a
EB
2099 vik_layer_get_interface(i)->tools[j].name,
2100 GTK_UI_MANAGER_TOOLITEM, FALSE);
2101
9593a4c9 2102 toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i);
941aa6e9 2103
e4afc73a
EB
2104 radio->name = vik_layer_get_interface(i)->tools[j].name;
2105 radio->stock_id = vik_layer_get_interface(i)->tools[j].name,
4c77d5e0 2106 radio->label = _(vik_layer_get_interface(i)->tools[j].name);
e4afc73a 2107 radio->accelerator = NULL;
4c77d5e0 2108 radio->tooltip = _(vik_layer_get_interface(i)->tools[j].name);
e4afc73a
EB
2109 radio->value = ntools;
2110 }
2111 }
ee36ac4f 2112 g_object_unref (icon_factory);
50a14534 2113
e4afc73a
EB
2114 gtk_action_group_add_radio_actions(action_group, tools, ntools, 0, (GCallback)menu_tool_cb, window);
2115 g_free(tools);
50a14534 2116
e4afc73a 2117 gtk_ui_manager_insert_action_group (uim, action_group, 0);
50a14534 2118
79845167
QT
2119 for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
2120 for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
2121 GtkAction *action = gtk_action_group_get_action(action_group,
2122 vik_layer_get_interface(i)->tools[j].name);
2123 g_object_set(action, "sensitive", FALSE, NULL);
2124 }
2125 }
2126 window->action_group = action_group;
2127
e4afc73a
EB
2128 accel_group = gtk_ui_manager_get_accel_group (uim);
2129 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
2130 gtk_ui_manager_ensure_update (uim);
e4afc73a 2131}
50a14534 2132
50a14534 2133
941aa6e9 2134
e4afc73a 2135static struct {
4bd45256 2136 const GdkPixdata *data;
e4afc73a
EB
2137 gchar *stock_id;
2138} stock_icons[] = {
5bfafde9
GB
2139 { &begintr_18_pixbuf, "Begin Track" },
2140 { &iscissors_18_pixbuf, "Magic Scissors" },
2141 { &mover_22_pixbuf, "vik-icon-pan" },
2142 { &demdl_18_pixbuf, "DEM Download/Import" },
2143 { &showpic_18_pixbuf, "Show Picture" },
2144 { &addtr_18_pixbuf, "Create Track" },
2145 { &edtr_18_pixbuf, "Edit Trackpoint" },
2146 { &addwp_18_pixbuf, "Create Waypoint" },
2147 { &edwp_18_pixbuf, "Edit Waypoint" },
2148 { &zoom_18_pixbuf, "vik-icon-zoom" },
2149 { &ruler_18_pixbuf, "vik-icon-ruler" },
2150 { &geozoom_18_pixbuf, "Georef Zoom Tool" },
2151 { &geomove_18_pixbuf, "Georef Move Map" },
2152 { &mapdl_18_pixbuf, "Maps Download" },
2153 { &showpic_18_pixbuf, "Show Picture" },
e4afc73a
EB
2154};
2155
e4afc73a
EB
2156static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
2157
2158static void
2159register_vik_icons (GtkIconFactory *icon_factory)
2160{
2161 GtkIconSet *icon_set;
e4afc73a 2162 gint i;
e4afc73a
EB
2163
2164 for (i = 0; i < n_stock_icons; i++) {
4bd45256
EB
2165 icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (
2166 stock_icons[i].data, FALSE, NULL ));
e4afc73a
EB
2167 gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set);
2168 gtk_icon_set_unref (icon_set);
2169 }
50a14534 2170}
bce3a7b0 2171