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