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