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