]> git.itanic.dy.fi Git - maemo-mapper/blob - src/cmenu.c
42791ae96ee0bdfbda97b17340b840ca6b22a77f
[maemo-mapper] / src / cmenu.c
1 /*
2  * Copyright (C) 2006, 2007 John Costigan.
3  *
4  * POI and GPS-Info code originally written by Cezary Jackiewicz.
5  *
6  * Default map data provided by http://www.openstreetmap.org/
7  *
8  * This file is part of Maemo Mapper.
9  *
10  * Maemo Mapper is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * Maemo Mapper is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Maemo Mapper.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #    include "config.h"
26 #endif
27
28 #define _GNU_SOURCE
29
30 #include <string.h>
31 #include <math.h>
32 #include <gtk/gtk.h>
33
34 #ifndef LEGACY
35 #    include <hildon/hildon-note.h>
36 #    include <hildon/hildon-banner.h>
37 #else
38 #    include <hildon-widgets/hildon-note.h>
39 #    include <hildon-widgets/hildon-banner.h>
40 #endif
41
42 #include "types.h"
43 #include "data.h"
44 #include "defines.h"
45
46 #include "cmenu.h"
47 #include "display.h"
48 #include "gdk-pixbuf-rotate.h"
49 #include "menu.h"
50 #include "path.h"
51 #include "poi.h"
52 #include "util.h"
53
54
55 static void
56 cmenu_show_latlon(gint unitx, gint unity)
57 {
58   gdouble lat, lon;
59   gchar buffer[80], tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
60   printf("%s()\n", __PRETTY_FUNCTION__);
61
62   unit2latlon(unitx, unity, lat, lon);
63   lat_format(lat, tmp1);
64   lon_format(lon, tmp2);
65
66   snprintf(buffer, sizeof(buffer),
67             "%s: %s\n"
68           "%s: %s",
69           _("Latitude"), tmp1,
70           _("Longitude"), tmp2);
71
72   MACRO_BANNER_SHOW_INFO(_window, buffer);
73
74   vprintf("%s(): return\n", __PRETTY_FUNCTION__);
75 }
76
77 static void
78 cmenu_clip_latlon(gint unitx, gint unity)
79 {
80     gchar buffer[80];
81     gdouble lat, lon;
82     printf("%s()\n", __PRETTY_FUNCTION__);
83
84     unit2latlon(unitx, unity, lat, lon);
85
86     snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
87
88     gtk_clipboard_set_text(
89             gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
90
91     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
92 }
93
94 static void
95 cmenu_route_to(gint unitx, gint unity)
96 {
97     gchar buffer[80];
98     gchar strlat[32];
99     gchar strlon[32];
100     gdouble lat, lon;
101     printf("%s()\n", __PRETTY_FUNCTION__);
102
103     unit2latlon(unitx, unity, lat, lon);
104
105     g_ascii_formatd(strlat, 32, "%.06f", lat);
106     g_ascii_formatd(strlon, 32, "%.06f", lon);
107     snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
108
109     route_download(buffer);
110
111     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
112 }
113
114 static void
115 cmenu_distance_to(gint unitx, gint unity)
116 {
117     gchar buffer[80];
118     gdouble lat, lon;
119     printf("%s()\n", __PRETTY_FUNCTION__);
120
121     unit2latlon(unitx, unity, lat, lon);
122
123     snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
124             calculate_distance(_gps.lat, _gps.lon, lat, lon)
125               * UNITS_CONVERT[_units],
126             UNITS_ENUM_TEXT[_units]);
127     MACRO_BANNER_SHOW_INFO(_window, buffer);
128
129     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
130 }
131
132 static void
133 cmenu_add_route(gint unitx, gint unity)
134 {
135     printf("%s()\n", __PRETTY_FUNCTION__);
136     MACRO_PATH_INCREMENT_TAIL(_route);
137     screen2unit(_cmenu_position_x, _cmenu_position_y,
138             _route.tail->unitx, _route.tail->unity);
139     route_find_nearest_point();
140     map_force_redraw();
141     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
142 }
143
144 static gboolean
145 cmenu_cb_loc_show_latlon(GtkMenuItem *item)
146 {
147     gint unitx, unity;
148     gdouble lat, lon;
149     printf("%s()\n", __PRETTY_FUNCTION__);
150
151     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
152     unit2latlon(unitx, unity, lat, lon);
153
154     latlon_dialog(lat, lon);
155
156     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
157     return TRUE;
158 }
159
160 static gboolean
161 cmenu_cb_loc_route_to(GtkMenuItem *item)
162 {
163     gint unitx, unity;
164     printf("%s()\n", __PRETTY_FUNCTION__);
165
166     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
167     cmenu_route_to(unitx, unity);
168
169     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
170     return TRUE;
171 }
172
173 static gboolean
174 cmenu_cb_loc_download_poi(GtkMenuItem *item)
175 {
176     gint unitx, unity;
177     printf("%s()\n", __PRETTY_FUNCTION__);
178
179     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
180     poi_download_dialog(unitx, unity);
181
182     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
183     return TRUE;
184 }
185
186 static gboolean
187 cmenu_cb_loc_browse_poi(GtkMenuItem *item)
188 {
189     gint unitx, unity;
190     printf("%s()\n", __PRETTY_FUNCTION__);
191
192     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
193     poi_browse_dialog(unitx, unity);
194
195     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
196     return TRUE;
197 }
198
199 static gboolean
200 cmenu_cb_loc_distance_to(GtkMenuItem *item)
201 {
202     gint unitx, unity;
203     printf("%s()\n", __PRETTY_FUNCTION__);
204
205     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
206     cmenu_distance_to(unitx, unity);
207
208     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
209     return TRUE;
210 }
211
212 static gboolean
213 cmenu_cb_loc_add_route(GtkMenuItem *item)
214 {
215     gint unitx, unity;
216     printf("%s()\n", __PRETTY_FUNCTION__);
217
218     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
219     cmenu_add_route(unitx, unity);
220
221     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
222     return TRUE;
223 }
224
225 static gboolean
226 cmenu_cb_loc_add_way(GtkMenuItem *item)
227 {
228     gint unitx, unity;
229     printf("%s()\n", __PRETTY_FUNCTION__);
230
231     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
232     route_add_way_dialog(unitx, unity);
233
234     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
235     return TRUE;
236 }
237
238 static gboolean
239 cmenu_cb_loc_add_poi(GtkMenuItem *item)
240 {
241     gint unitx, unity;
242     printf("%s()\n", __PRETTY_FUNCTION__);
243
244     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
245     poi_add_dialog(_window, unitx, unity);
246
247     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
248     return TRUE;
249 }
250
251 static gboolean
252 cmenu_cb_loc_set_gps(GtkMenuItem *item)
253 {
254     printf("%s()\n", __PRETTY_FUNCTION__);
255
256     screen2unit(_cmenu_position_x, _cmenu_position_y, _pos.unitx, _pos.unity);
257     unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
258
259     /* Move mark to new location. */
260     map_refresh_mark(_center_mode > 0);
261
262     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
263     return TRUE;
264 }
265
266 static gboolean
267 cmenu_cb_way_show_latlon(GtkMenuItem *item)
268 {
269     gint unitx, unity;
270     WayPoint *way;
271     printf("%s()\n", __PRETTY_FUNCTION__);
272
273     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
274     if((way = find_nearest_waypoint(unitx, unity)))
275         cmenu_show_latlon(way->point->unitx, way->point->unity);
276     else
277     {
278         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
279     }
280
281
282     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
283     return TRUE;
284 }
285
286 static gboolean
287 cmenu_cb_way_show_desc(GtkMenuItem *item)
288 {
289     gint unitx, unity;
290     WayPoint *way;
291     printf("%s()\n", __PRETTY_FUNCTION__);
292
293     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
294     if((way = find_nearest_waypoint(unitx, unity)))
295     {
296         MACRO_BANNER_SHOW_INFO(_window, way->desc);
297     }
298     else
299     {
300         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
301     }
302
303     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
304     return TRUE;
305 }
306
307 static gboolean
308 cmenu_cb_way_clip_latlon(GtkMenuItem *item)
309 {
310     gint unitx, unity;
311     WayPoint *way;
312     printf("%s()\n", __PRETTY_FUNCTION__);
313
314     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
315     if((way = find_nearest_waypoint(unitx, unity)))
316         cmenu_clip_latlon(way->point->unitx, way->point->unity);
317     else
318     {
319         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
320     }
321
322     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
323     return TRUE;
324 }
325
326 static gboolean
327 cmenu_cb_way_clip_desc(GtkMenuItem *item)
328 {
329     gint unitx, unity;
330     WayPoint *way;
331     printf("%s()\n", __PRETTY_FUNCTION__);
332
333     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
334     if((way = find_nearest_waypoint(unitx, unity)))
335         gtk_clipboard_set_text(
336                 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
337     else
338     {
339         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
340     }
341
342     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
343     return TRUE;
344 }
345
346 static gboolean
347 cmenu_cb_way_route_to(GtkMenuItem *item)
348 {
349     gint unitx, unity;
350     WayPoint *way;
351     printf("%s()\n", __PRETTY_FUNCTION__);
352
353     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
354     if((way = find_nearest_waypoint(unitx, unity)))
355         cmenu_route_to(way->point->unitx, way->point->unity);
356     else
357     {
358         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
359     }
360
361     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
362     return TRUE;
363 }
364
365 static gboolean
366 cmenu_cb_way_distance_to(GtkMenuItem *item)
367 {
368     gint unitx, unity;
369     WayPoint *way;
370     printf("%s()\n", __PRETTY_FUNCTION__);
371
372     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
373     if((way = find_nearest_waypoint(unitx, unity)))
374         route_show_distance_to(way->point);
375     else
376     {
377         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
378     }
379
380     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
381     return TRUE;
382 }
383
384 static gboolean
385 cmenu_cb_way_delete(GtkMenuItem *item)
386 {
387     gint unitx, unity;
388     WayPoint *way;
389     printf("%s()\n", __PRETTY_FUNCTION__);
390
391     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
392     if((way = find_nearest_waypoint(unitx, unity)))
393     {
394         gchar buffer[BUFFER_SIZE];
395         GtkWidget *confirm;
396
397         snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
398                 _("Confirm delete of waypoint"), way->desc);
399         confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
400
401         if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
402         {
403             Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
404             gint num_del;
405
406             /* Delete surrounding route data, too. */
407             if(way == _route.whead)
408                 pdel_min = _route.head;
409             else
410                 pdel_min = way[-1].point;
411
412             if(way == _route.wtail)
413                 pdel_max = _route.tail;
414             else
415                 pdel_max = way[1].point;
416
417             /* Find largest continuous segment around the waypoint, EXCLUDING
418              * pdel_min and pdel_max. */
419             for(pdel_start = way->point - 1; pdel_start->unity
420                     && pdel_start > pdel_min; pdel_start--) { }
421             for(pdel_end = way->point + 1; pdel_end->unity
422                     && pdel_end < pdel_max; pdel_end++) { }
423
424             /* If pdel_end is set to _route.tail, and if _route.tail is a
425              * non-zero point, then delete _route.tail. */
426             if(pdel_end == _route.tail && pdel_end->unity)
427                 pdel_end++; /* delete _route.tail too */
428             /* else, if *both* endpoints are zero points, delete one. */
429             else if(!pdel_start->unity && !pdel_end->unity)
430                 pdel_start--;
431
432             /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
433             num_del = pdel_end - pdel_start - 1;
434
435             memmove(pdel_start + 1, pdel_end,
436                     (_route.tail - pdel_end + 1) * sizeof(Point));
437             _route.tail -= num_del;
438
439             /* Remove waypoint and move/adjust subsequent waypoints. */
440             g_free(way->desc);
441             while(way++ != _route.wtail)
442             {
443                 way[-1] = *way;
444                 way[-1].point -= num_del;
445             }
446             _route.wtail--;
447
448             route_find_nearest_point();
449             map_force_redraw();
450         }
451         gtk_widget_destroy(confirm);
452     }
453     else
454     {
455         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
456     }
457
458     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
459     return TRUE;
460 }
461
462 static gboolean
463 cmenu_cb_way_add_poi(GtkMenuItem *item)
464 {
465     gint unitx, unity;
466     WayPoint *way;
467     printf("%s()\n", __PRETTY_FUNCTION__);
468
469     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
470     if((way = find_nearest_waypoint(unitx, unity)))
471         poi_add_dialog(_window, way->point->unitx, way->point->unity);
472     else
473     {
474         MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
475     }
476
477     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
478     return TRUE;
479 }
480
481 static gboolean
482 cmenu_cb_poi_route_to(GtkMenuItem *item)
483 {
484     gint unitx, unity;
485     PoiInfo poi;
486     printf("%s()\n", __PRETTY_FUNCTION__);
487
488     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
489     if(select_poi(unitx, unity, &poi, FALSE)) /* FALSE = not quick */
490     {
491         gint unitx, unity;
492         latlon2unit(poi.lat, poi.lon, unitx, unity);
493         cmenu_route_to(unitx, unity);
494     }
495
496     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
497     return TRUE;
498 }
499
500 static gboolean
501 cmenu_cb_poi_distance_to(GtkMenuItem *item)
502 {
503     gint unitx, unity;
504     PoiInfo poi;
505     printf("%s()\n", __PRETTY_FUNCTION__);
506
507     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
508     if(select_poi(unitx, unity, &poi, FALSE)) /* FALSE = not quick */
509     {
510         gint unitx, unity;
511         latlon2unit(poi.lat, poi.lon, unitx, unity);
512         cmenu_distance_to(unitx, unity);
513     }
514
515     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
516     return TRUE;
517 }
518
519 static gboolean
520 cmenu_cb_poi_add_route(GtkMenuItem *item)
521 {
522     gint unitx, unity;
523     PoiInfo poi;
524     printf("%s()\n", __PRETTY_FUNCTION__);
525
526     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
527     if(select_poi(unitx, unity, &poi, FALSE)) /* FALSE = not quick */
528     {
529         gint unitx, unity;
530         latlon2unit(poi.lat, poi.lon, unitx, unity);
531         cmenu_add_route(unitx, unity);
532     }
533
534     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
535     return TRUE;
536 }
537
538 static gboolean
539 cmenu_cb_poi_add_way(GtkMenuItem *item)
540 {
541     gint unitx, unity;
542     PoiInfo poi;
543     printf("%s()\n", __PRETTY_FUNCTION__);
544
545     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
546     if(select_poi(unitx, unity, &poi, FALSE)) /* FALSE = not quick */
547     {
548         gint unitx, unity;
549         latlon2unit(poi.lat, poi.lon, unitx, unity);
550         route_add_way_dialog(unitx, unity);
551     }
552
553     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
554     return TRUE;
555 }
556
557 static gboolean
558 cmenu_cb_poi_edit_poi(GtkMenuItem *item)
559 {
560     PoiInfo poi;
561     gint unitx, unity;
562     printf("%s()\n", __PRETTY_FUNCTION__);
563
564     memset(&poi, 0, sizeof(poi));
565     screen2unit(_cmenu_position_x, _cmenu_position_y, unitx, unity);
566     select_poi(unitx, unity, &poi, FALSE); /* FALSE = not quick */
567     poi_view_dialog(_window, &poi);
568     if(poi.label)
569         g_free(poi.label);
570     if(poi.desc)
571         g_free(poi.desc);
572     if(poi.clabel)
573         g_free(poi.clabel);
574
575     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
576     return TRUE;
577 }
578
579 static gboolean
580 cmenu_cb_hide(GtkMenuItem *item)
581 {
582     printf("%s()\n", __PRETTY_FUNCTION__);
583
584     if(_mouse_is_down)
585         g_mutex_unlock(_mouse_mutex);
586     _mouse_is_down = _mouse_is_dragging = FALSE;
587
588     vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
589     return TRUE;
590 }
591
592 void cmenu_init()
593 {
594     /* Create needed handles. */
595     GtkMenu *menu;
596     GtkWidget *submenu;
597     GtkWidget *menu_item;
598     printf("%s()\n", __PRETTY_FUNCTION__);
599
600     /* Setup the context menu. */
601     menu = GTK_MENU(gtk_menu_new());
602
603     /* Setup the map context menu. */
604     gtk_menu_append(menu, menu_item
605             = gtk_menu_item_new_with_label(_("Tap Point")));
606     gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item),
607             submenu = gtk_menu_new());
608
609     /* Setup the map context menu. */
610     gtk_menu_append(submenu, _cmenu_loc_show_latlon_item
611             = gtk_menu_item_new_with_label(_("Show Lat/Lon")));
612     gtk_menu_append(submenu, gtk_separator_menu_item_new());
613     gtk_menu_append(submenu, _cmenu_loc_distance_to_item
614             = gtk_menu_item_new_with_label(_("Show Distance to")));
615     gtk_menu_append(submenu, _cmenu_loc_route_to_item
616             = gtk_menu_item_new_with_label(_("Download Route to...")));
617     gtk_menu_append(submenu, _cmenu_loc_download_poi_item
618                 = gtk_menu_item_new_with_label(_("Download POI...")));
619     gtk_menu_append(submenu, _cmenu_loc_browse_poi_item
620                 = gtk_menu_item_new_with_label(_("Browse POI...")));
621     gtk_menu_append(submenu, gtk_separator_menu_item_new());
622     gtk_menu_append(submenu, _cmenu_loc_add_route_item
623                 = gtk_menu_item_new_with_label(_("Add Route Point")));
624     gtk_menu_append(submenu, _cmenu_loc_add_way_item
625                 = gtk_menu_item_new_with_label(_("Add Waypoint...")));
626     gtk_menu_append(submenu, _cmenu_loc_add_poi_item
627                 = gtk_menu_item_new_with_label(_("Add POI...")));
628     gtk_menu_append(submenu, gtk_separator_menu_item_new());
629     gtk_menu_append(submenu, _cmenu_loc_set_gps_item
630                 = gtk_menu_item_new_with_label(_("Set as GPS Location")));
631
632     /* Setup the waypoint context menu. */
633     gtk_menu_append(menu, menu_item
634             = gtk_menu_item_new_with_label(_("Waypoint")));
635     gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item),
636             submenu = gtk_menu_new());
637
638     gtk_menu_append(submenu, _cmenu_way_show_latlon_item
639             = gtk_menu_item_new_with_label(_("Show Lat/Lon")));
640     gtk_menu_append(submenu, _cmenu_way_show_desc_item
641             = gtk_menu_item_new_with_label(_("Show Description")));
642     gtk_menu_append(submenu, _cmenu_way_clip_latlon_item
643             = gtk_menu_item_new_with_label(_("Copy Lat/Lon")));
644     gtk_menu_append(submenu, _cmenu_way_clip_desc_item
645             = gtk_menu_item_new_with_label(_("Copy Description")));
646     gtk_menu_append(submenu, gtk_separator_menu_item_new());
647     gtk_menu_append(submenu, _cmenu_way_distance_to_item
648             = gtk_menu_item_new_with_label(_("Show Distance to")));
649     gtk_menu_append(submenu, _cmenu_way_route_to_item
650             = gtk_menu_item_new_with_label(_("Download Route to...")));
651     gtk_menu_append(submenu, _cmenu_way_delete_item
652             = gtk_menu_item_new_with_label(_("Delete...")));
653     gtk_menu_append(submenu, gtk_separator_menu_item_new());
654     gtk_menu_append(submenu, _cmenu_way_add_poi_item
655                 = gtk_menu_item_new_with_label(_("Add POI...")));
656     gtk_menu_append(submenu, gtk_separator_menu_item_new());
657     gtk_menu_append(submenu, _cmenu_way_goto_nextway_item
658                 = gtk_menu_item_new_with_label(_("Go to Next")));
659
660     /* Setup the POI context menu. */
661     gtk_menu_append(menu, _cmenu_poi_submenu
662             = gtk_menu_item_new_with_label(_("POI")));
663     gtk_menu_item_set_submenu(GTK_MENU_ITEM(_cmenu_poi_submenu),
664             submenu = gtk_menu_new());
665
666     gtk_menu_append(submenu, _cmenu_poi_edit_poi_item
667                 = gtk_menu_item_new_with_label(_("View/Edit...")));
668     gtk_menu_append(submenu, gtk_separator_menu_item_new());
669     gtk_menu_append(submenu, _cmenu_poi_distance_to_item
670             = gtk_menu_item_new_with_label(_("Show Distance to")));
671     gtk_menu_append(submenu, _cmenu_poi_route_to_item
672             = gtk_menu_item_new_with_label(_("Download Route to...")));
673     gtk_menu_append(submenu, gtk_separator_menu_item_new());
674     gtk_menu_append(submenu, _cmenu_poi_add_route_item
675                 = gtk_menu_item_new_with_label(_("Add Route Point")));
676     gtk_menu_append(submenu, _cmenu_poi_add_way_item
677                 = gtk_menu_item_new_with_label(_("Add Waypoint...")));
678     gtk_menu_append(submenu, gtk_separator_menu_item_new());
679     gtk_menu_append(submenu, _cmenu_poi_goto_nearpoi_item
680                 = gtk_menu_item_new_with_label(_("Go to Nearest")));
681
682     /* Connect signals for context menu. */
683     g_signal_connect(G_OBJECT(_cmenu_loc_show_latlon_item), "activate",
684                       G_CALLBACK(cmenu_cb_loc_show_latlon), NULL);
685     g_signal_connect(G_OBJECT(_cmenu_loc_route_to_item), "activate",
686                       G_CALLBACK(cmenu_cb_loc_route_to), NULL);
687     g_signal_connect(G_OBJECT(_cmenu_loc_download_poi_item), "activate",
688                       G_CALLBACK(cmenu_cb_loc_download_poi), NULL);
689     g_signal_connect(G_OBJECT(_cmenu_loc_browse_poi_item), "activate",
690                       G_CALLBACK(cmenu_cb_loc_browse_poi), NULL);
691     g_signal_connect(G_OBJECT(_cmenu_loc_distance_to_item), "activate",
692                       G_CALLBACK(cmenu_cb_loc_distance_to), NULL);
693     g_signal_connect(G_OBJECT(_cmenu_loc_add_route_item), "activate",
694                         G_CALLBACK(cmenu_cb_loc_add_route), NULL);
695     g_signal_connect(G_OBJECT(_cmenu_loc_add_way_item), "activate",
696                         G_CALLBACK(cmenu_cb_loc_add_way), NULL);
697     g_signal_connect(G_OBJECT(_cmenu_loc_add_poi_item), "activate",
698                         G_CALLBACK(cmenu_cb_loc_add_poi), NULL);
699     g_signal_connect(G_OBJECT(_cmenu_loc_set_gps_item), "activate",
700                         G_CALLBACK(cmenu_cb_loc_set_gps), NULL);
701
702     g_signal_connect(G_OBJECT(_cmenu_way_show_latlon_item), "activate",
703                       G_CALLBACK(cmenu_cb_way_show_latlon), NULL);
704     g_signal_connect(G_OBJECT(_cmenu_way_show_desc_item), "activate",
705                       G_CALLBACK(cmenu_cb_way_show_desc), NULL);
706     g_signal_connect(G_OBJECT(_cmenu_way_clip_latlon_item), "activate",
707                       G_CALLBACK(cmenu_cb_way_clip_latlon), NULL);
708     g_signal_connect(G_OBJECT(_cmenu_way_clip_desc_item), "activate",
709                       G_CALLBACK(cmenu_cb_way_clip_desc), NULL);
710     g_signal_connect(G_OBJECT(_cmenu_way_route_to_item), "activate",
711                       G_CALLBACK(cmenu_cb_way_route_to), NULL);
712     g_signal_connect(G_OBJECT(_cmenu_way_distance_to_item), "activate",
713                       G_CALLBACK(cmenu_cb_way_distance_to), NULL);
714     g_signal_connect(G_OBJECT(_cmenu_way_delete_item), "activate",
715                       G_CALLBACK(cmenu_cb_way_delete), NULL);
716     g_signal_connect(G_OBJECT(_cmenu_way_add_poi_item), "activate",
717                         G_CALLBACK(cmenu_cb_way_add_poi), NULL);
718     g_signal_connect(G_OBJECT(_cmenu_way_goto_nextway_item), "activate",
719                         G_CALLBACK(menu_cb_view_goto_nextway), NULL);
720
721     g_signal_connect(G_OBJECT(_cmenu_poi_edit_poi_item), "activate",
722                         G_CALLBACK(cmenu_cb_poi_edit_poi), NULL);
723     g_signal_connect(G_OBJECT(_cmenu_poi_route_to_item), "activate",
724                       G_CALLBACK(cmenu_cb_poi_route_to), NULL);
725     g_signal_connect(G_OBJECT(_cmenu_poi_distance_to_item), "activate",
726                       G_CALLBACK(cmenu_cb_poi_distance_to), NULL);
727     g_signal_connect(G_OBJECT(_cmenu_poi_add_route_item), "activate",
728                         G_CALLBACK(cmenu_cb_poi_add_route), NULL);
729     g_signal_connect(G_OBJECT(_cmenu_poi_add_way_item), "activate",
730                         G_CALLBACK(cmenu_cb_poi_add_way), NULL);
731     g_signal_connect(G_OBJECT(_cmenu_poi_goto_nearpoi_item), "activate",
732                         G_CALLBACK(menu_cb_view_goto_nearpoi), NULL);
733
734     gtk_widget_show_all(GTK_WIDGET(menu));
735
736     gtk_widget_tap_and_hold_setup(_map_widget, GTK_WIDGET(menu), NULL, 0);
737
738     /* Add a "hide" signal event handler to handle dismissing the context
739      * menu. */
740     g_signal_connect(GTK_WIDGET(menu), "hide",
741             G_CALLBACK(cmenu_cb_hide), NULL);
742
743     vprintf("%s(): return\n", __PRETTY_FUNCTION__);
744 }