Contents of /trunk/src/area_edit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 293 - (show annotations)
Fri Sep 18 15:58:52 2009 UTC (14 years, 8 months ago) by harbaum
File MIME type: text/plain
File size: 27989 byte(s)
Updated osm-gps-map
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 #include "osm-gps-map-osd-classic.h"
25 #endif
26
27 #define TAB_LABEL_MAP "Map"
28 #define TAB_LABEL_DIRECT "Direct"
29 #define TAB_LABEL_EXTENT "Extent"
30
31 /* maemo5 currently has no maemo mapper */
32 #if defined(USE_HILDON) && (MAEMO_VERSION_MAJOR < 5)
33 #define HAS_MAEMO_MAPPER
34 #define TAB_LABEL_MM "Maemo Mapper"
35 #endif
36
37 /* limit of square kilometers above the warning is enabled */
38 #define WARN_OVER 5.0
39
40 typedef struct {
41 GtkWidget *dialog, *notebook;
42 area_edit_t *area;
43 pos_t min, max; /* local copy to work on */
44 GtkWidget *minlat, *maxlat, *minlon, *maxlon;
45 GtkWidget *warning;
46
47 struct {
48 GtkWidget *minlat, *maxlat, *minlon, *maxlon;
49 GtkWidget *error;
50 } direct;
51
52 struct {
53 GtkWidget *lat, *lon, *height, *width, *mil_km;
54 gboolean is_mil;
55 GtkWidget *error;
56 } extent;
57
58 #ifdef HAS_MAEMO_MAPPER
59 struct {
60 GtkWidget *fetch;
61 } mmapper;
62 #endif
63
64 #ifdef ENABLE_OSM_GPS_MAP
65 struct {
66 GtkWidget *widget;
67 gboolean needs_redraw;
68 gint handler_id;
69 coord_t start;
70 } map;
71 #endif
72 } context_t;
73
74 static void parse_and_set_lat(GtkWidget *src, pos_float_t *store) {
75 pos_float_t i = pos_parse_lat((char*)gtk_entry_get_text(GTK_ENTRY(src)));
76 if(pos_lat_valid(i))
77 *store = i;
78 }
79
80 static void parse_and_set_lon(GtkWidget *src, pos_float_t *store) {
81 pos_float_t i = pos_parse_lon((char*)gtk_entry_get_text(GTK_ENTRY(src)));
82 if(pos_lon_valid(i))
83 *store = i;
84 }
85
86 static gboolean current_tab_is(context_t *context, gint page_num, char *str) {
87 if(page_num < 0)
88 page_num =
89 gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook));
90
91 if(page_num < 0) return FALSE;
92
93 GtkWidget *w =
94 gtk_notebook_get_nth_page(GTK_NOTEBOOK(context->notebook), page_num);
95 const char *name =
96 gtk_notebook_get_tab_label_text(GTK_NOTEBOOK(context->notebook), w);
97
98 return(strcasecmp(name, _(str)) == 0);
99 }
100
101 static char *warn_text(context_t *context) {
102 /* compute area size */
103 pos_float_t center_lat = (context->max.lat + context->min.lat)/2;
104 double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0);
105 double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0);
106
107 double area = vscale * (context->max.lat - context->min.lat) *
108 hscale * (context->max.lon - context->min.lon);
109
110 return g_strdup_printf(
111 _("The currently selected area is %.02f km² (%.02f mi²) in size. "
112 "This is more than the recommended %.02f km² (%.02f mi²).\n\n"
113 "Continuing may result in a big or failing download and low "
114 "mapping performance in a densly mapped area (e.g. cities)!"),
115 area, area/(KMPMIL*KMPMIL),
116 WARN_OVER, WARN_OVER/(KMPMIL*KMPMIL)
117 );
118 }
119
120 static void on_area_warning_clicked(GtkButton *button, gpointer data) {
121 context_t *context = (context_t*)data;
122
123 char *wtext = warn_text(context);
124 warningf(context->dialog, wtext);
125 g_free(wtext);
126 }
127
128 static gboolean area_warning(context_t *context) {
129 gboolean ret = TRUE;
130
131 /* check if area size exceeds recommended values */
132 pos_float_t center_lat = (context->max.lat + context->min.lat)/2;
133 double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0);
134 double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0);
135
136 double area = vscale * (context->max.lat - context->min.lat) *
137 hscale * (context->max.lon - context->min.lon);
138
139 if(area > WARN_OVER) {
140 char *wtext = warn_text(context);
141
142 ret = yes_no_f(context->dialog, context->area->appdata,
143 MISC_AGAIN_ID_AREA_TOO_BIG, MISC_AGAIN_FLAG_DONT_SAVE_NO,
144 _("Area size warning!"),
145 _("%s Do you really want to continue?"), wtext);
146
147 g_free(wtext);
148 }
149
150 return ret;
151 }
152
153 static void area_main_update(context_t *context) {
154 pos_lat_label_set(context->minlat, context->min.lat);
155 pos_lat_label_set(context->maxlat, context->max.lat);
156 pos_lon_label_set(context->minlon, context->min.lon);
157 pos_lon_label_set(context->maxlon, context->max.lon);
158
159 /* also setup the local error messages here, so they are */
160 /* updated for all entries at once */
161 if(context->min.lat >= context->max.lat ||
162 context->min.lon >= context->max.lon) {
163 gtk_label_set(GTK_LABEL(context->direct.error),
164 _("\"From\" must be smaller than \"to\" value!"));
165 gtk_label_set(GTK_LABEL(context->extent.error),
166 _("Extents must be positive!"));
167
168 gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog),
169 GTK_RESPONSE_ACCEPT, FALSE);
170
171 } else {
172 gtk_label_set(GTK_LABEL(context->direct.error), "");
173 gtk_label_set(GTK_LABEL(context->extent.error), "");
174
175 gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog),
176 GTK_RESPONSE_ACCEPT, TRUE);
177 }
178
179 /* check if area size exceeds recommended values */
180 pos_float_t center_lat = (context->max.lat + context->min.lat)/2;
181 double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0);
182 double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0);
183
184 double area = vscale * (context->max.lat - context->min.lat) *
185 hscale * (context->max.lon - context->min.lon);
186
187 if(area > WARN_OVER)
188 gtk_widget_show(context->warning);
189 else
190 gtk_widget_hide(context->warning);
191 }
192
193 #ifdef ENABLE_OSM_GPS_MAP
194 #define LOG2(x) (log(x) / log(2))
195
196 static GSList *pos_append_rad(GSList *list, pos_float_t lat, pos_float_t lon) {
197 coord_t *coo = g_new0(coord_t, 1);
198 coo->rlat = lat;
199 coo->rlon = lon;
200 list = g_slist_append(list, coo);
201 return list;
202 }
203
204 static GSList *pos_append(GSList *list, pos_float_t lat, pos_float_t lon) {
205 return pos_append_rad(list, DEG2RAD(lat), DEG2RAD(lon));
206 }
207
208 /* the contents of the map tab have been changed */
209 static void map_update(context_t *context, gboolean forced) {
210
211 /* map is first tab (page 0) */
212 if(!forced && !current_tab_is(context, -1, TAB_LABEL_MAP)) {
213 context->map.needs_redraw = TRUE;
214 return;
215 }
216
217 /* check if the position is invalid */
218 if(isnan(context->min.lat) || isnan(context->min.lon) ||
219 isnan(context->min.lat) || isnan(context->min.lon)) {
220
221 /* no coordinates given: display the entire world */
222 osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->map.widget),
223 0.0, 0.0, 1);
224
225 osm_gps_map_clear_tracks(OSM_GPS_MAP(context->map.widget));
226 } else {
227
228 pos_float_t center_lat = (context->max.lat + context->min.lat)/2;
229 pos_float_t center_lon = (context->max.lon + context->min.lon)/2;
230
231 /* we know the widgets pixel size, we know the required real size, */
232 /* we want the zoom! */
233 double vzoom = LOG2((45.0 * context->map.widget->allocation.height)/
234 ((context->max.lat - context->min.lat)*32.0)) -1;
235
236 double hzoom = LOG2((45.0 * context->map.widget->allocation.width)/
237 ((context->max.lon - context->min.lon)*32.0)) -1;
238
239 osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget),
240 center_lat, center_lon);
241
242 /* use smallest zoom, so everything fits on screen */
243 osm_gps_map_set_zoom(OSM_GPS_MAP(context->map.widget),
244 (vzoom < hzoom)?vzoom:hzoom);
245
246 /* ---------- draw border (as a gps track) -------------- */
247 osm_gps_map_clear_tracks(OSM_GPS_MAP(context->map.widget));
248
249 if(context->max.lat > context->min.lat &&
250 context->max.lon > context->min.lon) {
251 GSList *box = pos_append(NULL, context->min.lat, context->min.lon);
252 box = pos_append(box, context->max.lat, context->min.lon);
253 box = pos_append(box, context->max.lat, context->max.lon);
254 box = pos_append(box, context->min.lat, context->max.lon);
255 box = pos_append(box, context->min.lat, context->min.lon);
256
257 osm_gps_map_add_track(OSM_GPS_MAP(context->map.widget), box);
258 }
259 }
260
261 context->map.needs_redraw = FALSE;
262 }
263
264 static gboolean on_map_configure(GtkWidget *widget,
265 GdkEventConfigure *event,
266 context_t *context) {
267 map_update(context, FALSE);
268 return FALSE;
269 }
270 #endif
271
272 /* the contents of the direct tab have been changed */
273 static void direct_update(context_t *context) {
274 pos_lat_entry_set(context->direct.minlat, context->min.lat);
275 pos_lon_entry_set(context->direct.minlon, context->min.lon);
276 pos_lat_entry_set(context->direct.maxlat, context->max.lat);
277 pos_lon_entry_set(context->direct.maxlon, context->max.lon);
278 }
279
280 /* update the contents of the extent tab */
281 static void extent_update(context_t *context) {
282 pos_float_t center_lat = (context->max.lat + context->min.lat)/2;
283 pos_float_t center_lon = (context->max.lon + context->min.lon)/2;
284
285 pos_lat_entry_set(context->extent.lat, center_lat);
286 pos_lat_entry_set(context->extent.lon, center_lon);
287
288 double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0);
289 double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0);
290
291 double height = vscale * (context->max.lat - context->min.lat);
292 double width = hscale * (context->max.lon - context->min.lon);
293
294 pos_dist_entry_set(context->extent.width, width, context->extent.is_mil);
295 pos_dist_entry_set(context->extent.height, height, context->extent.is_mil);
296 }
297
298 static void callback_modified_direct(GtkWidget *widget, gpointer data) {
299 context_t *context = (context_t*)data;
300
301 /* direct is second tab (page 1) */
302 if(!current_tab_is(context, -1, TAB_LABEL_DIRECT))
303 return;
304
305 /* parse the fields from the direct entry pad */
306 parse_and_set_lat(context->direct.minlat, &context->min.lat);
307 parse_and_set_lon(context->direct.minlon, &context->min.lon);
308 parse_and_set_lat(context->direct.maxlat, &context->max.lat);
309 parse_and_set_lon(context->direct.maxlon, &context->max.lon);
310
311 area_main_update(context);
312
313 /* also adjust other views */
314 extent_update(context);
315 #ifdef ENABLE_OSM_GPS_MAP
316 map_update(context, FALSE);
317 #endif
318 }
319
320 static void callback_modified_extent(GtkWidget *widget, gpointer data) {
321 context_t *context = (context_t*)data;
322
323 /* extent is third tab (page 2) */
324 if(!current_tab_is(context, -1, TAB_LABEL_EXTENT))
325 return;
326
327 pos_float_t center_lat = pos_lat_get(context->extent.lat);
328 pos_float_t center_lon = pos_lon_get(context->extent.lon);
329
330 if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon))
331 return;
332
333 double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0);
334 double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0);
335
336 double height = pos_dist_get(context->extent.height, context->extent.is_mil);
337 double width = pos_dist_get(context->extent.width, context->extent.is_mil);
338
339 height /= 2 * vscale;
340 context->min.lat = center_lat - height;
341 context->max.lat = center_lat + height;
342
343 width /= 2 * hscale;
344 context->min.lon = center_lon - width;
345 context->max.lon = center_lon + width;
346
347 area_main_update(context);
348
349 /* also update other tabs */
350 direct_update(context);
351 #ifdef ENABLE_OSM_GPS_MAP
352 map_update(context, FALSE);
353 #endif
354 }
355
356 static void callback_modified_unit(GtkWidget *widget, gpointer data) {
357 context_t *context = (context_t*)data;
358
359 /* get current values */
360 double height = pos_dist_get(context->extent.height, context->extent.is_mil);
361 double width = pos_dist_get(context->extent.width, context->extent.is_mil);
362
363 /* adjust unit flag */
364 context->extent.is_mil = gtk_combo_box_get_active(
365 GTK_COMBO_BOX(context->extent.mil_km)) == 0;
366
367 /* save values */
368 pos_dist_entry_set(context->extent.width, width, context->extent.is_mil);
369 pos_dist_entry_set(context->extent.height, height, context->extent.is_mil);
370 }
371
372 #ifdef HAS_MAEMO_MAPPER
373 static void callback_fetch_mm_clicked(GtkButton *button, gpointer data) {
374 context_t *context = (context_t*)data;
375
376 if(!dbus_mm_set_position(context->area->appdata->osso_context, NULL)) {
377 errorf(context->dialog,
378 _("Unable to communicate with Maemo Mapper. "
379 "You need to have Maemo Mapper installed "
380 "to use this feature."));
381 return;
382 }
383
384 if(!context->area->appdata->mmpos.valid) {
385 errorf(context->dialog,
386 _("No valid position received yet. You need "
387 "to scroll or zoom the Maemo Mapper view "
388 "in order to force it to send its current "
389 "view position to osm2go."));
390 return;
391 }
392
393 /* maemo mapper is fourth tab (page 3) */
394 if(!current_tab_is(context, -1, TAB_LABEL_MM))
395 return;
396
397 /* maemo mapper pos data ... */
398 pos_float_t center_lat = context->area->appdata->mmpos.pos.lat;
399 pos_float_t center_lon = context->area->appdata->mmpos.pos.lon;
400 int zoom = context->area->appdata->mmpos.zoom;
401
402 if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon))
403 return;
404
405 double vscale = DEG2RAD(POS_EQ_RADIUS);
406 double height = 8 * (1<<zoom) / vscale;
407 context->min.lat = center_lat - height;
408 context->max.lat = center_lat + height;
409
410 double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS);
411 double width = 16 * (1<<zoom) / hscale;
412 context->min.lon = center_lon - width;
413 context->max.lon = center_lon + width;
414
415 area_main_update(context);
416
417 /* also update other tabs */
418 direct_update(context);
419 extent_update(context);
420 #ifdef ENABLE_OSM_GPS_MAP
421 map_update(context, FALSE);
422 #endif
423 }
424 #endif
425
426 #ifdef ENABLE_OSM_GPS_MAP
427
428 static gboolean
429 on_map_button_press_event(GtkWidget *widget,
430 GdkEventButton *event, context_t *context) {
431 OsmGpsMap *map = OSM_GPS_MAP(context->map.widget);
432 osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
433
434 /* osm-gps-map needs this event to handle the OSD */
435 if(osd->check(osd, TRUE, (int)event->x, (int)event->y))
436 return FALSE;
437
438 /* remove existing marker */
439 osm_gps_map_clear_tracks(map);
440
441 /* and remember this location as the start */
442 context->map.start =
443 osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y);
444
445 return TRUE;
446 }
447
448 static gboolean
449 on_map_motion_notify_event(GtkWidget *widget,
450 GdkEventMotion *event, context_t *context) {
451 if(!isnan(context->map.start.rlon) &&
452 !isnan(context->map.start.rlat)) {
453 OsmGpsMap *map = OSM_GPS_MAP(context->map.widget);
454
455 /* remove existing marker */
456 osm_gps_map_clear_tracks(map);
457
458 coord_t start = context->map.start, end =
459 osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y);
460
461 GSList *box = pos_append_rad(NULL, start.rlat, start.rlon);
462 box = pos_append_rad(box, end.rlat, start.rlon);
463 box = pos_append_rad(box, end.rlat, end.rlon);
464 box = pos_append_rad(box, start.rlat, end.rlon);
465 box = pos_append_rad(box, start.rlat, start.rlon);
466
467 osm_gps_map_add_track(map, box);
468 }
469
470 /* always returning true here disables dragging in osm-gps-map */
471 return TRUE;
472 }
473
474 static gboolean
475 on_map_button_release_event(GtkWidget *widget,
476 GdkEventButton *event, context_t *context) {
477
478 OsmGpsMap *map = OSM_GPS_MAP(context->map.widget);
479 osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
480
481 if(!isnan(context->map.start.rlon) &&
482 !isnan(context->map.start.rlat)) {
483
484 coord_t start = context->map.start, end =
485 osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y);
486
487 GSList *box = pos_append_rad(NULL, start.rlat, start.rlon);
488 box = pos_append_rad(box, end.rlat, start.rlon);
489 box = pos_append_rad(box, end.rlat, end.rlon);
490 box = pos_append_rad(box, start.rlat, end.rlon);
491 box = pos_append_rad(box, start.rlat, start.rlon);
492
493 osm_gps_map_add_track(map, box);
494
495 if(start.rlat < end.rlat) {
496 context->min.lat = RAD2DEG(start.rlat);
497 context->max.lat = RAD2DEG(end.rlat);
498 } else {
499 context->min.lat = RAD2DEG(end.rlat);
500 context->max.lat = RAD2DEG(start.rlat);
501 }
502
503 if(start.rlon < end.rlon) {
504 context->min.lon = RAD2DEG(start.rlon);
505 context->max.lon = RAD2DEG(end.rlon);
506 } else {
507 context->min.lon = RAD2DEG(end.rlon);
508 context->max.lon = RAD2DEG(start.rlon);
509 }
510
511 area_main_update(context);
512 direct_update(context);
513 extent_update(context);
514
515 context->map.start.rlon = context->map.start.rlat = NAN;
516 }
517
518 /* osm-gps-map needs this event to handle the OSD */
519 if(osd->check(osd, TRUE, (int)event->x, (int)event->y))
520 return FALSE;
521
522 return TRUE;
523 }
524
525 static void
526 cb_map_gps(osd_button_t but, context_t *context) {
527 if(but == OSD_GPS) {
528 pos_t pos;
529
530 /* user clicked "gps" button -> jump to position */
531 gboolean gps_on =
532 context->area->appdata->settings &&
533 context->area->appdata->settings->enable_gps;
534
535 if(gps_on && gps_get_pos(context->area->appdata, &pos, NULL)) {
536 osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget),
537 pos.lat, pos.lon);
538
539 /* re-enable centering */
540 g_object_set(context->map.widget, "auto-center", TRUE, NULL);
541 }
542 }
543 }
544
545 static void on_page_switch(GtkNotebook *notebook, GtkNotebookPage *page,
546 guint page_num, context_t *context) {
547
548 /* updating the map while the user manually changes some coordinates */
549 /* may confuse the map. so we delay those updates until the map tab */
550 /* is becoming visible */
551 if(current_tab_is(context, page_num, TAB_LABEL_MAP) &&
552 context->map.needs_redraw)
553 map_update(context, TRUE);
554 }
555
556 static gboolean map_gps_update(gpointer data) {
557 context_t *context = (context_t*)data;
558
559 gboolean gps_on =
560 context->area->appdata->settings &&
561 context->area->appdata->settings->enable_gps;
562
563 pos_t pos = { NAN, NAN };
564 gboolean gps_fix = gps_on &&
565 gps_get_pos(context->area->appdata, &pos, NULL);
566
567 /* ... and enable "goto" button if it's valid */
568 osm_gps_map_osd_enable_gps(OSM_GPS_MAP(context->map.widget),
569 OSM_GPS_MAP_OSD_CALLBACK(gps_fix?cb_map_gps:NULL), context);
570
571 if(gps_fix) {
572 g_object_set(context->map.widget, "gps-track-highlight-radius", 0, NULL);
573 osm_gps_map_draw_gps(OSM_GPS_MAP(context->map.widget),
574 pos.lat, pos.lon, NAN);
575 } else
576 osm_gps_map_clear_gps(OSM_GPS_MAP(context->map.widget));
577
578 return TRUE;
579 }
580
581 #endif
582
583 gboolean area_edit(area_edit_t *area) {
584 GtkWidget *vbox;
585 GdkColor color;
586 gdk_color_parse("red", &color);
587
588 context_t context;
589 memset(&context, 0, sizeof(context_t));
590 context.area = area;
591 context.min.lat = area->min->lat;
592 context.min.lon = area->min->lon;
593 context.max.lat = area->max->lat;
594 context.max.lon = area->max->lon;
595
596 context.dialog =
597 misc_dialog_new(MISC_DIALOG_HIGH, _("Area editor"),
598 GTK_WINDOW(area->parent),
599 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
600 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
601 NULL);
602
603 GtkWidget *table = gtk_table_new(5, 2, FALSE); // x, y
604
605 GtkWidget *label = gtk_label_new(_("Latitude:"));
606 misc_table_attach(table, label, 0, 0);
607 context.minlat = pos_lat_label_new(area->min->lat);
608 misc_table_attach(table, context.minlat, 1, 0);
609 label = gtk_label_new(_("to"));
610 misc_table_attach(table, label, 2, 0);
611 context.maxlat = pos_lat_label_new(area->max->lat);
612 misc_table_attach(table, context.maxlat, 3, 0);
613
614 label = gtk_label_new(_("Longitude:"));
615 misc_table_attach(table, label, 0, 1);
616 context.minlon = pos_lon_label_new(area->min->lon);
617 misc_table_attach(table, context.minlon, 1, 1);
618 label = gtk_label_new(_("to"));
619 misc_table_attach(table, label, 2, 1);
620 context.maxlon = pos_lon_label_new(area->max->lon);
621 misc_table_attach(table, context.maxlon, 3, 1);
622
623 context.warning = gtk_button_new();
624 gtk_button_set_image(GTK_BUTTON(context.warning),
625 gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
626 GTK_ICON_SIZE_BUTTON));
627 g_signal_connect(context.warning, "clicked",
628 G_CALLBACK(on_area_warning_clicked), &context);
629 gtk_table_attach_defaults(GTK_TABLE(table), context.warning, 4, 5, 0, 2);
630
631 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context.dialog)->vbox),
632 table, FALSE, FALSE, 0);
633
634 context.notebook = gtk_notebook_new();
635
636 #ifdef ENABLE_OSM_GPS_MAP
637 /* ------------- fetch from map ------------------------ */
638
639 context.map.needs_redraw = FALSE;
640 context.map.widget = g_object_new(OSM_TYPE_GPS_MAP,
641 "map-source", OSM_GPS_MAP_SOURCE_OPENSTREETMAP,
642 "proxy-uri", misc_get_proxy_uri(area->settings),
643 "auto-center", FALSE,
644 "tile-cache", NULL,
645 NULL);
646
647 osm_gps_map_osd_classic_init(OSM_GPS_MAP(context.map.widget));
648
649 g_signal_connect(G_OBJECT(context.map.widget), "configure-event",
650 G_CALLBACK(on_map_configure), &context);
651 g_signal_connect(G_OBJECT(context.map.widget), "button-press-event",
652 G_CALLBACK(on_map_button_press_event), &context);
653 g_signal_connect(G_OBJECT(context.map.widget), "motion-notify-event",
654 G_CALLBACK(on_map_motion_notify_event), &context);
655 g_signal_connect(G_OBJECT(context.map.widget), "button-release-event",
656 G_CALLBACK(on_map_button_release_event), &context);
657
658 /* install handler for timed updates of the gps button */
659 context.map.handler_id = gtk_timeout_add(1000, map_gps_update, &context);
660 context.map.start.rlon = context.map.start.rlat = NAN;
661
662 gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook),
663 context.map.widget, gtk_label_new(_(TAB_LABEL_MAP)));
664 #endif
665
666 /* ------------ direct min/max edit --------------- */
667
668 vbox = gtk_vbox_new(FALSE, 10);
669 table = gtk_table_new(3, 4, FALSE); // x, y
670 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
671 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
672
673 context.direct.minlat = pos_lat_entry_new(0.0);
674 misc_table_attach(table, context.direct.minlat, 0, 0);
675 label = gtk_label_new(_("to"));
676 misc_table_attach(table, label, 1, 0);
677 context.direct.maxlat = pos_lat_entry_new(0.0);
678 misc_table_attach(table, context.direct.maxlat, 2, 0);
679
680 context.direct.minlon = pos_lon_entry_new(area->min->lon);
681 misc_table_attach(table, context.direct.minlon, 0, 1);
682 label = gtk_label_new(_("to"));
683 misc_table_attach(table, label, 1, 1);
684 context.direct.maxlon = pos_lon_entry_new(0.0);
685 misc_table_attach(table, context.direct.maxlon, 2, 1);
686
687 /* setup this page */
688 direct_update(&context);
689
690 g_signal_connect(G_OBJECT(context.direct.minlat), "changed",
691 G_CALLBACK(callback_modified_direct), &context);
692 g_signal_connect(G_OBJECT(context.direct.minlon), "changed",
693 G_CALLBACK(callback_modified_direct), &context);
694 g_signal_connect(G_OBJECT(context.direct.maxlat), "changed",
695 G_CALLBACK(callback_modified_direct), &context);
696 g_signal_connect(G_OBJECT(context.direct.maxlon), "changed",
697 G_CALLBACK(callback_modified_direct), &context);
698
699
700 /* --- hint --- */
701 label = gtk_label_new(_("(recommended min/max diff <0.03 degrees)"));
702 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 3, 2, 3);
703
704 /* error label */
705 context.direct.error = gtk_label_new("");
706 gtk_widget_modify_fg(context.direct.error, GTK_STATE_NORMAL, &color);
707 gtk_table_attach_defaults(GTK_TABLE(table), context.direct.error, 0, 3, 3, 4);
708
709 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
710 gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook),
711 vbox, gtk_label_new(_(TAB_LABEL_DIRECT)));
712
713 /* ------------- center/extent edit ------------------------ */
714
715 vbox = gtk_vbox_new(FALSE, 10);
716 table = gtk_table_new(3, 5, FALSE); // x, y
717 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
718 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
719
720 label = gtk_label_new(_("Center:"));
721 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
722 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
723 context.extent.lat = pos_lat_entry_new(0.0);
724 gtk_table_attach_defaults(GTK_TABLE(table), context.extent.lat, 1, 2, 0, 1);
725 context.extent.lon = pos_lon_entry_new(0.0);
726 gtk_table_attach_defaults(GTK_TABLE(table), context.extent.lon, 2, 3, 0, 1);
727
728 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 10);
729
730 label = gtk_label_new(_("Width:"));
731 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
732 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
733 context.extent.width = gtk_entry_new();
734 gtk_table_attach_defaults(GTK_TABLE(table), context.extent.width, 1, 2, 1, 2);
735
736 label = gtk_label_new(_("Height:"));
737 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
738 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
739 context.extent.height = gtk_entry_new();
740 gtk_table_attach_defaults(GTK_TABLE(table),
741 context.extent.height, 1, 2, 2, 3);
742
743 context.extent.mil_km = gtk_combo_box_new_text();
744 gtk_combo_box_append_text(GTK_COMBO_BOX(context.extent.mil_km), _("mi"));
745 gtk_combo_box_append_text(GTK_COMBO_BOX(context.extent.mil_km), _("km"));
746 gtk_combo_box_set_active(GTK_COMBO_BOX(context.extent.mil_km), 1); // km
747
748 gtk_table_attach(GTK_TABLE(table), context.extent.mil_km, 2, 3, 1, 3,
749 0, 0, 0, 0);
750
751 /* setup this page */
752 extent_update(&context);
753
754 /* connect signals after inital update to avoid confusion */
755 g_signal_connect(G_OBJECT(context.extent.lat), "changed",
756 G_CALLBACK(callback_modified_extent), &context);
757 g_signal_connect(G_OBJECT(context.extent.lon), "changed",
758 G_CALLBACK(callback_modified_extent), &context);
759 g_signal_connect(G_OBJECT(context.extent.width), "changed",
760 G_CALLBACK(callback_modified_extent), &context);
761 g_signal_connect(G_OBJECT(context.extent.height), "changed",
762 G_CALLBACK(callback_modified_extent), &context);
763 g_signal_connect(G_OBJECT(context.extent.mil_km), "changed",
764 G_CALLBACK(callback_modified_unit), &context);
765
766 /* --- hint --- */
767 label = gtk_label_new(_("(recommended width/height < 2km/1.25mi)"));
768 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 3, 3, 4);
769
770 /* error label */
771 context.extent.error = gtk_label_new("");
772 gtk_widget_modify_fg(context.extent.error, GTK_STATE_NORMAL, &color);
773 gtk_table_attach_defaults(GTK_TABLE(table), context.extent.error, 0, 3, 4, 5);
774
775 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
776 gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook),
777 vbox, gtk_label_new(_(TAB_LABEL_EXTENT)));
778
779 #ifdef HAS_MAEMO_MAPPER
780 /* ------------- fetch from maemo mapper ------------------------ */
781
782 vbox = gtk_vbox_new(FALSE, 8);
783 context.mmapper.fetch =
784 gtk_button_new_with_label(_("Get from Maemo Mapper"));
785 gtk_box_pack_start(GTK_BOX(vbox), context.mmapper.fetch, FALSE, FALSE, 0);
786
787 g_signal_connect(G_OBJECT(context.mmapper.fetch), "clicked",
788 G_CALLBACK(callback_fetch_mm_clicked), &context);
789
790 /* --- hint --- */
791 label = gtk_label_new(_("(recommended MM zoom level < 7)"));
792 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
793
794
795 gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook),
796 vbox, gtk_label_new(_(TAB_LABEL_MM)));
797 #endif
798
799 /* ------------------------------------------------------ */
800
801 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context.dialog)->vbox),
802 context.notebook);
803
804 #ifdef ENABLE_OSM_GPS_MAP
805 g_signal_connect(G_OBJECT(context.notebook), "switch-page",
806 G_CALLBACK(on_page_switch), &context);
807 #endif
808
809 gtk_widget_show_all(context.dialog);
810
811 area_main_update(&context);
812
813 gboolean leave = FALSE, ok = FALSE;
814 do {
815 if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(context.dialog))) {
816 if(area_warning(&context)) {
817 leave = TRUE;
818 ok = TRUE;
819 }
820 } else
821 leave = TRUE;
822 } while(!leave);
823
824 if(ok) {
825 /* copy modified values back to given storage */
826 area->min->lat = context.min.lat;
827 area->min->lon = context.min.lon;
828 area->max->lat = context.max.lat;
829 area->max->lon = context.max.lon;
830 }
831
832 #ifdef ENABLE_OSM_GPS_MAP
833 gtk_timeout_remove(context.map.handler_id);
834 #endif
835
836 gtk_widget_destroy(context.dialog);
837
838 return ok;
839 }