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