Parent Directory | Revision Log
Version increase
1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
3 | * |
4 | * This file is part of OSM2Go. |
5 | * |
6 | * OSM2Go 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 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * OSM2Go 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 OSM2Go. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include "appdata.h" |
21 | |
22 | #ifdef ENABLE_OSM_GPS_MAP |
23 | #include "osm-gps-map.h" |
24 | #endif |
25 | |
26 | #define TAB_LABEL_MAP "Map" |
27 | #define TAB_LABEL_DIRECT "Direct" |
28 | #define TAB_LABEL_EXTENT "Extent" |
29 | #define TAB_LABEL_MM "Maemo Mapper" |
30 | |
31 | /* limit of square kilometers above the warning is enabled */ |
32 | #define WARN_OVER 5.0 |
33 | |
34 | typedef struct { |
35 | GtkWidget *dialog, *notebook; |
36 | area_edit_t *area; |
37 | pos_t min, max; /* local copy to work on */ |
38 | GtkWidget *minlat, *maxlat, *minlon, *maxlon; |
39 | GtkWidget *warning; |
40 | |
41 | struct { |
42 | GtkWidget *minlat, *maxlat, *minlon, *maxlon; |
43 | } direct; |
44 | |
45 | struct { |
46 | GtkWidget *lat, *lon, *height, *width, *mil_km; |
47 | gboolean is_mil; |
48 | } extent; |
49 | |
50 | #ifdef USE_HILDON |
51 | struct { |
52 | GtkWidget *fetch; |
53 | } mmapper; |
54 | #endif |
55 | |
56 | struct { |
57 | GtkWidget *widget; |
58 | GtkWidget *zoomin, *zoomout; |
59 | gboolean needs_redraw; |
60 | } map; |
61 | |
62 | } context_t; |
63 | |
64 | static void parse_and_set_lat(GtkWidget *src, pos_float_t *store) { |
65 | pos_float_t i = pos_parse_lat((char*)gtk_entry_get_text(GTK_ENTRY(src))); |
66 | if(pos_lat_valid(i)) |
67 | *store = i; |
68 | } |
69 | |
70 | static void parse_and_set_lon(GtkWidget *src, pos_float_t *store) { |
71 | pos_float_t i = pos_parse_lon((char*)gtk_entry_get_text(GTK_ENTRY(src))); |
72 | if(pos_lon_valid(i)) |
73 | *store = i; |
74 | } |
75 | |
76 | #define LOG2(x) (log(x) / log(2)) |
77 | |
78 | static gboolean current_tab_is(context_t *context, gint page_num, char *str) { |
79 | if(page_num < 0) |
80 | page_num = |
81 | gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook)); |
82 | |
83 | if(page_num < 0) return FALSE; |
84 | |
85 | GtkWidget *w = |
86 | gtk_notebook_get_nth_page(GTK_NOTEBOOK(context->notebook), page_num); |
87 | const char *name = |
88 | gtk_notebook_get_tab_label_text(GTK_NOTEBOOK(context->notebook), w); |
89 | |
90 | return(strcasecmp(name, _(str)) == 0); |
91 | } |
92 | |
93 | static void on_area_warning_clicked(GtkButton *button, gpointer data) { |
94 | context_t *context = (context_t*)data; |
95 | |
96 | /* compute area size */ |
97 | pos_float_t center_lat = (context->max.lat + context->min.lat)/2; |
98 | double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0); |
99 | double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0); |
100 | |
101 | double area = vscale * (context->max.lat - context->min.lat) * |
102 | hscale * (context->max.lon - context->min.lon); |
103 | |
104 | warningf(context->dialog, |
105 | _("The currently selected area is %.02f km² (%.02f mil²) in size. " |
106 | "This is more than the recommended %.02f km² (%.02f mil²).\n\n" |
107 | "Continuing may result in a big download and low mapping performance " |
108 | "in a densly mapped area (e.g. cities)!"), |
109 | area, area/(KMPMIL*KMPMIL), |
110 | WARN_OVER, WARN_OVER/(KMPMIL*KMPMIL) |
111 | ); |
112 | |
113 | } |
114 | |
115 | static void area_main_update(context_t *context) { |
116 | pos_lat_label_set(context->minlat, context->min.lat); |
117 | pos_lat_label_set(context->maxlat, context->max.lat); |
118 | pos_lon_label_set(context->minlon, context->min.lon); |
119 | pos_lon_label_set(context->maxlon, context->max.lon); |
120 | |
121 | /* check if area size exceeds recommended values */ |
122 | pos_float_t center_lat = (context->max.lat + context->min.lat)/2; |
123 | double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0); |
124 | double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0); |
125 | |
126 | double area = vscale * (context->max.lat - context->min.lat) * |
127 | hscale * (context->max.lon - context->min.lon); |
128 | |
129 | if(area > WARN_OVER) |
130 | gtk_widget_show(context->warning); |
131 | else |
132 | gtk_widget_hide(context->warning); |
133 | } |
134 | |
135 | #ifdef ENABLE_OSM_GPS_MAP |
136 | /* the contents of the map tab have been changed */ |
137 | static void map_update(context_t *context, gboolean forced) { |
138 | |
139 | /* map is first tab (page 0) */ |
140 | if(!forced && !current_tab_is(context, -1, TAB_LABEL_MAP)) { |
141 | context->map.needs_redraw = TRUE; |
142 | return; |
143 | } |
144 | |
145 | pos_float_t center_lat = (context->max.lat + context->min.lat)/2; |
146 | pos_float_t center_lon = (context->max.lon + context->min.lon)/2; |
147 | |
148 | /* we know the widgets pixel size, we know the required real size, */ |
149 | /* we want the zoom! */ |
150 | double vzoom = LOG2((45.0 * context->map.widget->allocation.height)/ |
151 | ((context->max.lat - context->min.lat)*32.0)); |
152 | |
153 | double hzoom = LOG2((45.0 * context->map.widget->allocation.width)/ |
154 | ((context->max.lon - context->min.lon)*32.0)); |
155 | |
156 | osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
157 | center_lat, center_lon); |
158 | |
159 | osm_gps_map_set_zoom(OSM_GPS_MAP(context->map.widget), (hzoom+vzoom+0.5)/2); |
160 | |
161 | context->map.needs_redraw = FALSE; |
162 | } |
163 | |
164 | static gboolean on_map_configure(GtkWidget *widget, |
165 | GdkEventConfigure *event, |
166 | context_t *context) { |
167 | map_update(context, FALSE); |
168 | return FALSE; |
169 | } |
170 | #endif |
171 | |
172 | /* the contents of the direct tab have been changed */ |
173 | static void direct_update(context_t *context) { |
174 | pos_lat_entry_set(context->direct.minlat, context->min.lat); |
175 | pos_lon_entry_set(context->direct.minlon, context->min.lon); |
176 | pos_lat_entry_set(context->direct.maxlat, context->max.lat); |
177 | pos_lon_entry_set(context->direct.maxlon, context->max.lon); |
178 | } |
179 | |
180 | /* update the contents of the extent tab */ |
181 | static void extent_update(context_t *context) { |
182 | pos_float_t center_lat = (context->max.lat + context->min.lat)/2; |
183 | pos_float_t center_lon = (context->max.lon + context->min.lon)/2; |
184 | |
185 | pos_lat_entry_set(context->extent.lat, center_lat); |
186 | pos_lat_entry_set(context->extent.lon, center_lon); |
187 | |
188 | double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0); |
189 | double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0); |
190 | |
191 | double height = vscale * (context->max.lat - context->min.lat); |
192 | double width = hscale * (context->max.lon - context->min.lon); |
193 | |
194 | pos_dist_entry_set(context->extent.width, width, context->extent.is_mil); |
195 | pos_dist_entry_set(context->extent.height, height, context->extent.is_mil); |
196 | } |
197 | |
198 | static void callback_modified_direct(GtkWidget *widget, gpointer data) { |
199 | context_t *context = (context_t*)data; |
200 | |
201 | /* direct is second tab (page 1) */ |
202 | if(!current_tab_is(context, -1, TAB_LABEL_DIRECT)) |
203 | return; |
204 | |
205 | /* parse the fields from the direct entry pad */ |
206 | parse_and_set_lat(context->direct.minlat, &context->min.lat); |
207 | parse_and_set_lon(context->direct.minlon, &context->min.lon); |
208 | parse_and_set_lat(context->direct.maxlat, &context->max.lat); |
209 | parse_and_set_lon(context->direct.maxlon, &context->max.lon); |
210 | |
211 | area_main_update(context); |
212 | |
213 | /* also adjust other views */ |
214 | extent_update(context); |
215 | #ifdef ENABLE_OSM_GPS_MAP |
216 | map_update(context, FALSE); |
217 | #endif |
218 | } |
219 | |
220 | static void callback_modified_extent(GtkWidget *widget, gpointer data) { |
221 | context_t *context = (context_t*)data; |
222 | |
223 | /* extent is third tab (page 2) */ |
224 | if(!current_tab_is(context, -1, TAB_LABEL_EXTENT)) |
225 | return; |
226 | |
227 | pos_float_t center_lat = pos_lat_get(context->extent.lat); |
228 | pos_float_t center_lon = pos_lon_get(context->extent.lon); |
229 | |
230 | if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon)) |
231 | return; |
232 | |
233 | double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0); |
234 | double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0); |
235 | |
236 | double height = pos_dist_get(context->extent.height, context->extent.is_mil); |
237 | double width = pos_dist_get(context->extent.width, context->extent.is_mil); |
238 | |
239 | height /= 2 * vscale; |
240 | context->min.lat = center_lat - height; |
241 | context->max.lat = center_lat + height; |
242 | |
243 | width /= 2 * hscale; |
244 | context->min.lon = center_lon - width; |
245 | context->max.lon = center_lon + width; |
246 | |
247 | area_main_update(context); |
248 | |
249 | /* also update other tabs */ |
250 | direct_update(context); |
251 | #ifdef ENABLE_OSM_GPS_MAP |
252 | map_update(context, FALSE); |
253 | #endif |
254 | } |
255 | |
256 | static void callback_modified_unit(GtkWidget *widget, gpointer data) { |
257 | context_t *context = (context_t*)data; |
258 | |
259 | /* get current values */ |
260 | double height = pos_dist_get(context->extent.height, context->extent.is_mil); |
261 | double width = pos_dist_get(context->extent.width, context->extent.is_mil); |
262 | |
263 | /* adjust unit flag */ |
264 | context->extent.is_mil = gtk_combo_box_get_active( |
265 | GTK_COMBO_BOX(context->extent.mil_km)) == 0; |
266 | |
267 | /* save values */ |
268 | pos_dist_entry_set(context->extent.width, width, context->extent.is_mil); |
269 | pos_dist_entry_set(context->extent.height, height, context->extent.is_mil); |
270 | } |
271 | |
272 | #ifdef USE_HILDON |
273 | static void callback_fetch_mm_clicked(GtkButton *button, gpointer data) { |
274 | context_t *context = (context_t*)data; |
275 | |
276 | if(!dbus_mm_set_position(context->area->osso_context, NULL)) { |
277 | errorf(context->dialog, |
278 | _("Unable to communicate with Maemo Mapper. " |
279 | "You need to have Maemo Mapper installed " |
280 | "to use this feature.")); |
281 | return; |
282 | } |
283 | |
284 | if(!context->area->mmpos->valid) { |
285 | errorf(context->dialog, |
286 | _("No valid position received yet. You need " |
287 | "to scroll or zoom the Maemo Mapper view " |
288 | "in order to force it to send its current " |
289 | "view position to osm2go.")); |
290 | return; |
291 | } |
292 | |
293 | /* maemo mapper is fourth tab (page 3) */ |
294 | if(!current_tab_is(context, -1, TAB_LABEL_MM)) |
295 | return; |
296 | |
297 | /* maemo mapper pos data ... */ |
298 | pos_float_t center_lat = context->area->mmpos->pos.lat; |
299 | pos_float_t center_lon = context->area->mmpos->pos.lon; |
300 | int zoom = context->area->mmpos->zoom; |
301 | |
302 | if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon)) |
303 | return; |
304 | |
305 | double vscale = DEG2RAD(POS_EQ_RADIUS); |
306 | double height = 8 * (1<<zoom) / vscale; |
307 | context->min.lat = center_lat - height; |
308 | context->max.lat = center_lat + height; |
309 | |
310 | double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS); |
311 | double width = 16 * (1<<zoom) / hscale; |
312 | context->min.lon = center_lon - width; |
313 | context->max.lon = center_lon + width; |
314 | |
315 | area_main_update(context); |
316 | |
317 | /* also update other tabs */ |
318 | direct_update(context); |
319 | extent_update(context); |
320 | #ifdef ENABLE_OSM_GPS_MAP |
321 | map_update(context, FALSE); |
322 | #endif |
323 | } |
324 | #endif |
325 | |
326 | #ifdef ENABLE_OSM_GPS_MAP |
327 | /* the user has changed the map view, update other views accordingly */ |
328 | static void map_has_changed(context_t *context) { |
329 | coord_t pt1, pt2; |
330 | |
331 | /* get maps bounding box */ |
332 | osm_gps_map_get_bbox(OSM_GPS_MAP(context->map.widget), &pt1, &pt2); |
333 | |
334 | context->min.lat = RAD2DEG(pt2.rlat); |
335 | context->max.lat = RAD2DEG(pt1.rlat); |
336 | |
337 | context->min.lon = RAD2DEG(pt1.rlon); |
338 | context->max.lon = RAD2DEG(pt2.rlon); |
339 | |
340 | area_main_update(context); |
341 | direct_update(context); |
342 | extent_update(context); |
343 | } |
344 | |
345 | static gboolean |
346 | on_map_button_release_event(GtkWidget *widget, |
347 | GdkEventButton *event, context_t *context) { |
348 | map_has_changed(context); |
349 | return FALSE; |
350 | } |
351 | |
352 | static void map_zoom(context_t *context, int step) { |
353 | int zoom; |
354 | OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
355 | g_object_get(map, "zoom", &zoom, NULL); |
356 | zoom = osm_gps_map_set_zoom(map, zoom+step); |
357 | |
358 | /* enable/disable zoom buttons as required */ |
359 | gtk_widget_set_sensitive(context->map.zoomin, zoom<17); |
360 | gtk_widget_set_sensitive(context->map.zoomout, zoom>1); |
361 | |
362 | map_has_changed(context); |
363 | } |
364 | |
365 | static gboolean |
366 | cb_map_zoomin(GtkButton *button, context_t *context) { |
367 | map_zoom(context, +1); |
368 | return FALSE; |
369 | } |
370 | |
371 | static gboolean |
372 | cb_map_zoomout(GtkButton *button, context_t *context) { |
373 | map_zoom(context, -1); |
374 | return FALSE; |
375 | } |
376 | |
377 | static void on_page_switch(GtkNotebook *notebook, GtkNotebookPage *page, |
378 | guint page_num, context_t *context) { |
379 | |
380 | /* updating the map while the user manually changes some coordinates */ |
381 | /* may confuse the map. so we delay those updates until the map tab */ |
382 | /* is becoming visible */ |
383 | if(current_tab_is(context, page_num, TAB_LABEL_MAP) && |
384 | context->map.needs_redraw) |
385 | map_update(context, TRUE); |
386 | } |
387 | #endif |
388 | |
389 | gboolean area_edit(area_edit_t *area) { |
390 | GtkWidget *vbox; |
391 | gboolean ok = FALSE; |
392 | |
393 | context_t context; |
394 | memset(&context, 0, sizeof(context_t)); |
395 | context.area = area; |
396 | context.min.lat = area->min->lat; |
397 | context.min.lon = area->min->lon; |
398 | context.max.lat = area->max->lat; |
399 | context.max.lon = area->max->lon; |
400 | |
401 | context.dialog = |
402 | misc_dialog_new(MISC_DIALOG_HIGH, _("Area editor"), |
403 | GTK_WINDOW(area->parent), |
404 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
405 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
406 | NULL); |
407 | |
408 | GtkWidget *table = gtk_table_new(5, 2, FALSE); // x, y |
409 | |
410 | GtkWidget *label = gtk_label_new(_("Latitude:")); |
411 | misc_table_attach(table, label, 0, 0); |
412 | context.minlat = pos_lat_label_new(area->min->lat); |
413 | misc_table_attach(table, context.minlat, 1, 0); |
414 | label = gtk_label_new(_("to")); |
415 | misc_table_attach(table, label, 2, 0); |
416 | context.maxlat = pos_lat_label_new(area->max->lat); |
417 | misc_table_attach(table, context.maxlat, 3, 0); |
418 | |
419 | label = gtk_label_new(_("Longitude:")); |
420 | misc_table_attach(table, label, 0, 1); |
421 | context.minlon = pos_lon_label_new(area->min->lon); |
422 | misc_table_attach(table, context.minlon, 1, 1); |
423 | label = gtk_label_new(_("to")); |
424 | misc_table_attach(table, label, 2, 1); |
425 | context.maxlon = pos_lon_label_new(area->max->lon); |
426 | misc_table_attach(table, context.maxlon, 3, 1); |
427 | |
428 | context.warning = gtk_button_new(); |
429 | gtk_button_set_image(GTK_BUTTON(context.warning), |
430 | gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING, |
431 | GTK_ICON_SIZE_BUTTON)); |
432 | g_signal_connect(context.warning, "clicked", |
433 | G_CALLBACK(on_area_warning_clicked), &context); |
434 | gtk_table_attach_defaults(GTK_TABLE(table), context.warning, 4, 5, 0, 2); |
435 | |
436 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
437 | table, FALSE, FALSE, 0); |
438 | |
439 | context.notebook = gtk_notebook_new(); |
440 | |
441 | #ifdef ENABLE_OSM_GPS_MAP |
442 | /* ------------- fetch from map ------------------------ */ |
443 | |
444 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
445 | |
446 | context.map.needs_redraw = FALSE; |
447 | context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
448 | "repo-uri", MAP_SOURCE_OPENSTREETMAP, |
449 | "proxy-uri", misc_get_proxy_uri(area->settings), |
450 | NULL); |
451 | |
452 | g_signal_connect(G_OBJECT(context.map.widget), "configure-event", |
453 | G_CALLBACK(on_map_configure), &context); |
454 | g_signal_connect(G_OBJECT(context.map.widget), "button-release-event", |
455 | G_CALLBACK(on_map_button_release_event), &context); |
456 | |
457 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context.map.widget); |
458 | |
459 | /* zoom button box */ |
460 | vbox = gtk_vbox_new(FALSE,0); |
461 | |
462 | context.map.zoomin = gtk_button_new(); |
463 | gtk_button_set_image(GTK_BUTTON(context.map.zoomin), |
464 | gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU)); |
465 | g_signal_connect(context.map.zoomin, "clicked", |
466 | G_CALLBACK(cb_map_zoomin), &context); |
467 | gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomin, FALSE, FALSE, 0); |
468 | |
469 | context.map.zoomout = gtk_button_new(); |
470 | gtk_button_set_image(GTK_BUTTON(context.map.zoomout), |
471 | gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU)); |
472 | g_signal_connect(context.map.zoomout, "clicked", |
473 | G_CALLBACK(cb_map_zoomout), &context); |
474 | gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomout, FALSE, FALSE, 0); |
475 | |
476 | gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
477 | |
478 | gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
479 | hbox, gtk_label_new(_(TAB_LABEL_MAP))); |
480 | #endif |
481 | |
482 | /* ------------ direct min/max edit --------------- */ |
483 | |
484 | vbox = gtk_vbox_new(FALSE, 10); |
485 | table = gtk_table_new(3, 3, FALSE); // x, y |
486 | gtk_table_set_col_spacings(GTK_TABLE(table), 10); |
487 | gtk_table_set_row_spacings(GTK_TABLE(table), 5); |
488 | |
489 | context.direct.minlat = pos_lat_entry_new(0.0); |
490 | misc_table_attach(table, context.direct.minlat, 0, 0); |
491 | label = gtk_label_new(_("to")); |
492 | misc_table_attach(table, label, 1, 0); |
493 | context.direct.maxlat = pos_lat_entry_new(0.0); |
494 | misc_table_attach(table, context.direct.maxlat, 2, 0); |
495 | |
496 | context.direct.minlon = pos_lon_entry_new(area->min->lon); |
497 | misc_table_attach(table, context.direct.minlon, 0, 1); |
498 | label = gtk_label_new(_("to")); |
499 | misc_table_attach(table, label, 1, 1); |
500 | context.direct.maxlon = pos_lon_entry_new(0.0); |
501 | misc_table_attach(table, context.direct.maxlon, 2, 1); |
502 | |
503 | /* setup this page */ |
504 | direct_update(&context); |
505 | |
506 | g_signal_connect(G_OBJECT(context.direct.minlat), "changed", |
507 | G_CALLBACK(callback_modified_direct), &context); |
508 | g_signal_connect(G_OBJECT(context.direct.minlon), "changed", |
509 | G_CALLBACK(callback_modified_direct), &context); |
510 | g_signal_connect(G_OBJECT(context.direct.maxlat), "changed", |
511 | G_CALLBACK(callback_modified_direct), &context); |
512 | g_signal_connect(G_OBJECT(context.direct.maxlon), "changed", |
513 | G_CALLBACK(callback_modified_direct), &context); |
514 | |
515 | |
516 | /* --- hint --- */ |
517 | label = gtk_label_new(_("(recommended min/max diff <0.03 degrees)")); |
518 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 3, 2, 3); |
519 | |
520 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
521 | gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
522 | vbox, gtk_label_new(_(TAB_LABEL_DIRECT))); |
523 | |
524 | /* ------------- center/extent edit ------------------------ */ |
525 | |
526 | vbox = gtk_vbox_new(FALSE, 10); |
527 | table = gtk_table_new(3, 4, FALSE); // x, y |
528 | gtk_table_set_col_spacings(GTK_TABLE(table), 10); |
529 | gtk_table_set_row_spacings(GTK_TABLE(table), 5); |
530 | |
531 | label = gtk_label_new(_("Center:")); |
532 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
533 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); |
534 | context.extent.lat = pos_lat_entry_new(0.0); |
535 | gtk_table_attach_defaults(GTK_TABLE(table), context.extent.lat, 1, 2, 0, 1); |
536 | context.extent.lon = pos_lon_entry_new(0.0); |
537 | gtk_table_attach_defaults(GTK_TABLE(table), context.extent.lon, 2, 3, 0, 1); |
538 | |
539 | gtk_table_set_row_spacing(GTK_TABLE(table), 0, 10); |
540 | |
541 | label = gtk_label_new(_("Width:")); |
542 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
543 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); |
544 | context.extent.width = gtk_entry_new(); |
545 | gtk_table_attach_defaults(GTK_TABLE(table), context.extent.width, 1, 2, 1, 2); |
546 | |
547 | label = gtk_label_new(_("Height:")); |
548 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
549 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); |
550 | context.extent.height = gtk_entry_new(); |
551 | gtk_table_attach_defaults(GTK_TABLE(table), context.extent.height, 1, 2, 2, 3); |
552 | |
553 | context.extent.mil_km = gtk_combo_box_new_text(); |
554 | gtk_combo_box_append_text(GTK_COMBO_BOX(context.extent.mil_km), _("mi")); |
555 | gtk_combo_box_append_text(GTK_COMBO_BOX(context.extent.mil_km), _("km")); |
556 | gtk_combo_box_set_active(GTK_COMBO_BOX(context.extent.mil_km), 1); // km |
557 | |
558 | gtk_table_attach(GTK_TABLE(table), context.extent.mil_km, 2, 3, 1, 3, |
559 | 0, 0, 0, 0); |
560 | |
561 | /* setup this page */ |
562 | extent_update(&context); |
563 | |
564 | /* connect signals after inital update to avoid confusion */ |
565 | g_signal_connect(G_OBJECT(context.extent.lat), "changed", |
566 | G_CALLBACK(callback_modified_extent), &context); |
567 | g_signal_connect(G_OBJECT(context.extent.lon), "changed", |
568 | G_CALLBACK(callback_modified_extent), &context); |
569 | g_signal_connect(G_OBJECT(context.extent.width), "changed", |
570 | G_CALLBACK(callback_modified_extent), &context); |
571 | g_signal_connect(G_OBJECT(context.extent.height), "changed", |
572 | G_CALLBACK(callback_modified_extent), &context); |
573 | g_signal_connect(G_OBJECT(context.extent.mil_km), "changed", |
574 | G_CALLBACK(callback_modified_unit), &context); |
575 | |
576 | /* --- hint --- */ |
577 | label = gtk_label_new(_("(recommended width/height < 2km/1.25mi)")); |
578 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 3, 3, 4); |
579 | |
580 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
581 | gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
582 | vbox, gtk_label_new(_(TAB_LABEL_EXTENT))); |
583 | |
584 | #ifdef USE_HILDON |
585 | /* ------------- fetch from maemo mapper ------------------------ */ |
586 | |
587 | vbox = gtk_vbox_new(FALSE, 8); |
588 | context.mmapper.fetch = |
589 | gtk_button_new_with_label(_("Get from Maemo Mapper")); |
590 | gtk_box_pack_start(GTK_BOX(vbox), context.mmapper.fetch, FALSE, FALSE, 0); |
591 | |
592 | g_signal_connect(G_OBJECT(context.mmapper.fetch), "clicked", |
593 | G_CALLBACK(callback_fetch_mm_clicked), &context); |
594 | |
595 | /* --- hint --- */ |
596 | label = gtk_label_new(_("(recommended MM zoom level < 7)")); |
597 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
598 | |
599 | |
600 | gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
601 | vbox, gtk_label_new(_(TAB_LABEL_MM))); |
602 | #endif |
603 | |
604 | /* ------------------------------------------------------ */ |
605 | |
606 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
607 | context.notebook); |
608 | |
609 | #ifdef ENABLE_OSM_GPS_MAP |
610 | g_signal_connect(G_OBJECT(context.notebook), "switch-page", |
611 | G_CALLBACK(on_page_switch), &context); |
612 | #endif |
613 | |
614 | gtk_widget_show_all(context.dialog); |
615 | |
616 | area_main_update(&context); |
617 | |
618 | if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(context.dialog))) { |
619 | /* copy modified values back to given storage */ |
620 | area->min->lat = context.min.lat; |
621 | area->min->lon = context.min.lon; |
622 | area->max->lat = context.max.lat; |
623 | area->max->lon = context.max.lon; |
624 | ok = TRUE; |
625 | } |
626 | |
627 | gtk_widget_destroy(context.dialog); |
628 | |
629 | return ok; |
630 | } |