/[zanavi_public1]/navit/navit/gui/internal/gui_internal.c
ZANavi

Contents of /navit/navit/gui/internal/gui_internal.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 198294 byte(s)
import files
1 /**
2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2010 Navit Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 //##############################################################################################################
21 //#
22 //# File: gui_internal.c
23 //# Description: New "internal" GUI for use with any graphics library
24 //# Comment: Trying to make a touchscreen friendly GUI
25 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
26 //#
27 //##############################################################################################################
28
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <math.h>
34 #include <glib.h>
35 #include <time.h>
36 #include "config.h"
37 #ifdef HAVE_API_WIN32_BASE
38 #include <windows.h>
39 #endif
40 #include "item.h"
41 #include "file.h"
42 #include "navit.h"
43 #include "navit_nls.h"
44 #include "gui.h"
45 #include "coord.h"
46 #include "point.h"
47 #include "plugin.h"
48 #include "graphics.h"
49 #include "transform.h"
50 #include "color.h"
51 #include "map.h"
52 #include "layout.h"
53 #include "callback.h"
54 #include "vehicle.h"
55 #include "vehicleprofile.h"
56 #include "window.h"
57 #include "config_.h"
58 #include "keys.h"
59 #include "mapset.h"
60 #include "route.h"
61 #include "search.h"
62 #include "track.h"
63 #include "country.h"
64 #include "config.h"
65 #include "event.h"
66 #include "navit_nls.h"
67 #include "navigation.h"
68 #include "gui_internal.h"
69 #include "command.h"
70 #include "xmlconfig.h"
71 #include "util.h"
72 #include "bookmarks.h"
73 #include "debug.h"
74 #include "fib.h"
75 #include "types.h"
76 #include "linguistics.h"
77
78
79 extern char *version;
80
81 struct form {
82 char *onsubmit;
83 };
84
85
86 struct menu_data {
87 struct widget *search_list;
88 struct widget *keyboard;
89 struct widget *button_bar;
90 struct widget *menu;
91 int keyboard_mode;
92 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
93 struct widget *redisplay_widget;
94 char *href;
95 struct attr refresh_callback_obj,refresh_callback;
96 };
97
98 //##############################################################################################################
99 //# Description:
100 //# Comment:
101 //# Authors: Martin Schaller (04/2008)
102 //##############################################################################################################
103 struct widget {
104 enum widget_type type;
105 struct graphics_gc *background,*text_background;
106 struct graphics_gc *foreground_frame;
107 struct graphics_gc *foreground;
108 char *text;
109 struct graphics_image *img;
110 /**
111 * A function to be invoked on actions.
112 * @li widget The widget that is receiving the button press.
113 *
114 */
115 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
116 int reason;
117 int datai;
118 void *data;
119 /**
120 * @brief A function to deallocate data
121 */
122 void (*data_free)(void *data);
123
124 /**
125 * @brief a function that will be called as the widget is being destroyed.
126 * This function can act as a destructor for the widget. It allows for
127 * on deallocation actions to be specified on a per widget basis.
128 * This function will call g_free on the widget (if required).
129 */
130 void (*free) (struct gui_priv *this_, struct widget * w);
131 char *prefix;
132 char *name;
133 char *speech;
134 char *command;
135 struct pcoord c;
136 struct item item;
137 int selection_id;
138 int state;
139 struct point p;
140 int wmin,hmin;
141 int w,h;
142 int textw,texth;
143 int font_idx;
144 int bl,br,bt,bb,spx,spy;
145 int border;
146 int packed;
147 /**
148 * The number of widgets to layout horizontally when doing
149 * a orientation_horizontal_vertical layout
150 */
151 int cols;
152 enum flags flags;
153 int flags2;
154 void *instance;
155 int (*set_attr)(void *, struct attr *);
156 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
157 void (*remove_cb)(void *, struct callback *cb);
158 struct callback *cb;
159 struct attr on;
160 struct attr off;
161 int deflt;
162 int is_on;
163 int redraw;
164 struct menu_data *menu_data;
165 struct form *form;
166 GList *children;
167 };
168
169 /**
170 * @brief A structure to store configuration values.
171 *
172 * This structure stores configuration values for how gui elements in the internal GUI
173 * should be drawn.
174 */
175 struct gui_config_settings {
176
177 /**
178 * The base size (in fractions of a point) to use for text.
179 */
180 int font_size;
181 /**
182 * The size (in pixels) that xs style icons should be scaled to.
183 * This icon size can be too small to click it on some devices.
184 */
185 int icon_xs;
186 /**
187 * The size (in pixels) that s style icons (small) should be scaled to
188 */
189 int icon_s;
190 /**
191 * The size (in pixels) that l style icons should be scaled to
192 */
193 int icon_l;
194 /**
195 * The default amount of spacing (in pixels) to place between GUI elements.
196 */
197 int spacing;
198
199 };
200
201 /**
202 * Indexes into the config_profiles array.
203 */
204 const int LARGE_PROFILE=0;
205 const int MEDIUM_PROFILE=1;
206 const int SMALL_PROFILE=2;
207
208 /**
209 * The default config profiles.
210 *
211 * [0] => LARGE_PROFILE (screens 640 in one dimension)
212 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
213 * [2] => Small profile (default)
214 */
215 static struct gui_config_settings config_profiles[]={
216 {545,32,48,96,10}
217 , {300,32,48,64,3}
218 ,{200,16,32,48,2}
219 };
220
221 struct route_data {
222 struct widget * route_table;
223 int route_showing;
224
225 };
226
227 //##############################################################################################################
228 //# Description:
229 //# Comment:
230 //# Authors: Martin Schaller (04/2008)
231 //##############################################################################################################
232 struct gui_priv {
233 struct navit *nav;
234 struct attr self;
235 struct window *win;
236 struct graphics *gra;
237 struct graphics_gc *background;
238 struct graphics_gc *background2;
239 struct graphics_gc *highlight_background;
240 struct graphics_gc *foreground;
241 struct graphics_gc *text_foreground;
242 struct graphics_gc *text_background;
243 struct color background_color, background2_color, text_foreground_color, text_background_color;
244 int spacing;
245 int font_size;
246 int fullscreen;
247 struct graphics_font *fonts[3];
248 /**
249 * The size (in pixels) that xs style icons should be scaled to.
250 * This icon size can be too small to click it on some devices.
251 */
252 int icon_xs;
253 /**
254 * The size (in pixels) that s style icons (small) should be scaled to
255 */
256 int icon_s;
257 /**
258 * The size (in pixels) that l style icons should be scaled to
259 */
260 int icon_l;
261 int pressed;
262 struct widget *widgets;
263 int widgets_count;
264 int redraw;
265 struct widget root;
266 struct widget *highlighted,*editable;
267 struct widget *highlighted_menu;
268 int clickp_valid, vehicle_valid;
269 struct pcoord clickp, vehiclep;
270 struct attr *click_coord_geo, *position_coord_geo;
271 struct search_list *sl;
272 int ignore_button;
273 int menu_on_map_click;
274 int signal_on_map_click;
275 char *country_iso2;
276 int speech;
277 int keyboard;
278 int keyboard_required;
279 /**
280 * The setting information read from the configuration file.
281 * values of -1 indicate no value was specified in the config file.
282 */
283 struct gui_config_settings config;
284 struct event_idle *idle;
285 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
286 struct event_timeout *motion_timeout_event;
287 struct point current;
288
289 struct callback * vehicle_cb;
290 /**
291 * Stores information about the route.
292 */
293 struct route_data route_data;
294
295 struct gui_internal_data data;
296 struct callback_list *cbl;
297 int flags;
298 int cols;
299 struct attr osd_configuration;
300 int pitch;
301 int flags_town,flags_street,flags_house_number;
302 int radius;
303 /* html */
304 char *html_text;
305 int html_depth;
306 struct widget *html_container;
307 int html_skip;
308 char *html_anchor;
309 char *href;
310 int html_anchor_found;
311 struct form *form;
312 struct html {
313 int skip;
314 enum html_tag {
315 html_tag_none,
316 html_tag_a,
317 html_tag_h1,
318 html_tag_html,
319 html_tag_img,
320 html_tag_script,
321 html_tag_form,
322 html_tag_input,
323 html_tag_div,
324 } tag;
325 char *command;
326 char *name;
327 char *href;
328 char *refresh_cond;
329 struct widget *w;
330 struct widget *container;
331 } html[10];
332 };
333
334 struct html_tag_map {
335 char *tag_name;
336 enum html_tag tag;
337 } html_tag_map[] = {
338 {"a",html_tag_a},
339 {"h1",html_tag_h1},
340 {"html",html_tag_html},
341 {"img",html_tag_img},
342 {"script",html_tag_script},
343 {"form",html_tag_form},
344 {"input",html_tag_input},
345 {"div",html_tag_div},
346 };
347
348
349 /**
350 * @brief A structure to store information about a table.
351 *
352 * The table_data widget stores pointers to extra information needed by the
353 * table widget.
354 *
355 * The table_data structure needs to be freed with data_free along with the widget.
356 *
357 */
358 struct table_data
359 {
360 /**
361 * A GList pointer into a widget->children list that indicates the row
362 * currently being rendered at the top of the table.
363 */
364 GList * top_row;
365 /**
366 * A Glist pointer into a widget->children list that indicates the row
367 * currently being rendered at the bottom of the table.
368 */
369 GList * bottom_row;
370
371 /**
372 * A list of table_row widgets that mark the
373 * top rows for each page of the table.
374 * This is needed for the 'previous page' function of the table.
375 */
376 GList * page_headers;
377
378 /**
379 * A container box that is the child of the table widget that contains+groups
380 * the next and previous button.
381 */
382 struct widget * button_box;
383
384 /**
385 * A button widget to handle 'next page' requests
386 */
387 struct widget * next_button;
388 /**
389 * A button widget to handle 'previous page' requests.
390 */
391 struct widget * prev_button;
392
393
394 /**
395 * a pointer to the gui context.
396 * This is needed by the free function to destory the buttons.
397 */
398 struct gui_priv * this;
399 };
400
401 /**
402 * A data structure that holds information about a column that makes up a table.
403 *
404 *
405 */
406 struct table_column_desc
407 {
408
409 /**
410 * The computed height of a cell in the table.
411 */
412 int height;
413
414 /**
415 * The computed width of a cell in the table.
416 */
417 int width;
418 };
419
420
421 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
422 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
423 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
424 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
425 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
426 static void gui_internal_apply_config(struct gui_priv *this);
427
428 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
429 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
430 static void gui_internal_table_hide_rows(struct table_data * table_data);
431 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
432 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
433 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
434 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
435 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
436 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
437 static void gui_internal_table_data_free(void * d);
438 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
439 struct vehicle * v);
440 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
441 static void gui_internal_populate_route_table(struct gui_priv * this,
442 struct navit * navit);
443 static void gui_internal_search_idle_end(struct gui_priv *this);
444 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
445 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
446 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
447 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
448 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
449 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
450 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
451 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
452 static void gui_internal_check_exit(struct gui_priv *this);
453 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
454
455 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
456 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
457
458 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
459 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
460 static void gui_internal_html_load_href(struct gui_priv *this, char *href, int replace);
461 static void gui_internal_destroy(struct gui_priv *this);
462
463 /*
464 * * Display image scaled to specific size
465 * * searches for scaleable and pre-scaled image
466 * * @param this Our gui context
467 * * @param name image name
468 * * @param w desired width of image
469 * * @param h desired height of image
470 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
471 * */
472 static struct graphics_image *
473 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
474 {
475 struct graphics_image *ret=NULL;
476 char *full_name=NULL;
477 char *full_path=NULL;
478 int i;
479
480 for (i = 1 ; i < 6 ; i++) {
481 full_name=NULL;
482 switch (i) {
483 case 3:
484 full_name=g_strdup_printf("%s.svg", name);
485 break;
486 case 2:
487 full_name=g_strdup_printf("%s.svgz", name);
488 break;
489 case 1:
490 if (w != -1 && h != -1) {
491 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
492 }
493 break;
494 case 4:
495 full_name=g_strdup_printf("%s.png", name);
496 break;
497 case 5:
498 full_name=g_strdup_printf("%s.xpm", name);
499 break;
500 }
501 dbg(1,"trying '%s'\n", full_name);
502 if (! full_name)
503 continue;
504 #if 0
505 /* needs to be checked in the driver */
506 if (!file_exists(full_name)) {
507 g_free(full_name);
508 continue;
509 }
510 #endif
511 full_path=graphics_icon_path(full_name);
512 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
513 dbg(1,"ret=%p\n", ret);
514 g_free(full_path);
515 g_free(full_name);
516 if (ret)
517 return ret;
518 }
519 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
520 return NULL;
521 }
522
523 #if 0
524 static struct graphics_image *
525 image_new_o(struct gui_priv *this, char *name)
526 {
527 return image_new_scaled(this, name, -1, -1);
528 }
529 #endif
530
531 /*
532 * * Display image scaled to xs (extra small) size
533 * * This image size can be too small to click it on some devices.
534 * * @param this Our gui context
535 * * @param name image name
536 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
537 * */
538 static struct graphics_image *
539 image_new_xs(struct gui_priv *this, const char *name)
540 {
541 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
542 }
543
544 /*
545 * * Display image scaled to s (small) size
546 * * @param this Our gui context
547 * * @param name image name
548 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
549 * */
550
551 static struct graphics_image *
552 image_new_s(struct gui_priv *this, const char *name)
553 {
554 return image_new_scaled(this, name, this->icon_s, this->icon_s);
555 }
556
557 /*
558 * * Display image scaled to l (large) size
559 * * @param this Our gui context
560 * * @param name image name
561 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
562 * */
563 static struct graphics_image *
564 image_new_l(struct gui_priv *this, const char *name)
565 {
566 return image_new_scaled(this, name, this->icon_l, this->icon_l);
567 }
568
569 static char *
570 coordinates_geo(const struct coord_geo *gc, char sep)
571 {
572 char latc='N',lngc='E';
573 int lat_deg,lat_min,lat_sec;
574 int lng_deg,lng_min,lng_sec;
575 struct coord_geo g=*gc;
576
577 if (g.lat < 0) {
578 g.lat=-g.lat;
579 latc='S';
580 }
581 if (g.lng < 0) {
582 g.lng=-g.lng;
583 lngc='W';
584 }
585 lat_deg=g.lat;
586 lat_min=fmod(g.lat*60,60);
587 lat_sec=fmod(g.lat*3600,60);
588 lng_deg=g.lng;
589 lng_min=fmod(g.lng*60,60);
590 lng_sec=fmod(g.lng*3600,60);
591 return g_strdup_printf("%d°%d'%d\" %c%c%d°%d'%d\" %c",lat_deg,lat_min,lat_sec,latc,sep,lng_deg,lng_min,lng_sec,lngc);
592 }
593
594 static char *
595 coordinates(struct pcoord *pc, char sep)
596 {
597 struct coord_geo g;
598 struct coord c;
599 c.x=pc->x;
600 c.y=pc->y;
601 transform_to_geo(pc->pro, &c, &g);
602 return coordinates_geo(&g, sep);
603
604 }
605
606 static void
607 gui_internal_background_render(struct gui_priv *this, struct widget *w)
608 {
609 struct point pnt=w->p;
610 if (w->state & STATE_HIGHLIGHTED)
611 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
612 else {
613 if (w->background)
614 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
615 }
616 }
617
618 static struct widget *
619 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
620 {
621 struct point p[4];
622 int w=0;
623 int h=0;
624
625 struct widget *widget=g_new0(struct widget, 1);
626 widget->type=widget_label;
627 widget->font_idx=font;
628 if (text) {
629 widget->text=g_strdup(text);
630 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
631 w=p[2].x-p[0].x;
632 h=p[0].y-p[2].y;
633 }
634 widget->h=h+this->spacing;
635 widget->texth=h;
636 widget->w=w+this->spacing;
637 widget->textw=w;
638 widget->flags=gravity_center;
639 widget->foreground=this->text_foreground;
640 widget->text_background=this->text_background;
641
642 return widget;
643 }
644
645 static struct widget *
646 gui_internal_label_new(struct gui_priv *this, char *text)
647 {
648 return gui_internal_label_font_new(this, text, 0);
649 }
650
651 static struct widget *
652 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
653 {
654 struct widget *ret=NULL;
655 char *tmp=g_malloc(strlen(text)+3);
656 int i;
657
658 i=strlen(text)-1;
659 while (i >= 0) {
660 strcpy(tmp, text);
661 strcpy(tmp+i,"..");
662 ret=gui_internal_label_new(this, tmp);
663 if (ret->w < maxwidth)
664 break;
665 gui_internal_widget_destroy(this, ret);
666 ret=NULL;
667 i--;
668 }
669 g_free(tmp);
670 return ret;
671 }
672
673 static struct widget *
674 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
675 {
676 struct widget *widget=g_new0(struct widget, 1);
677 widget->type=widget_image;
678 widget->img=image;
679 if (image) {
680 widget->w=image->width;
681 widget->h=image->height;
682 }
683 return widget;
684 }
685
686 static void
687 gui_internal_image_render(struct gui_priv *this, struct widget *w)
688 {
689 struct point pnt;
690
691 gui_internal_background_render(this, w);
692 if (w->img) {
693 pnt=w->p;
694 pnt.x+=w->w/2-w->img->hot.x;
695 pnt.y+=w->h/2-w->img->hot.y;
696 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
697 }
698 }
699
700 static void
701 gui_internal_label_render(struct gui_priv *this, struct widget *w)
702 {
703 struct point pnt=w->p;
704 gui_internal_background_render(this, w);
705 if (w->state & STATE_EDIT)
706 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
707 if (w->text) {
708 char *text;
709 char *startext=(char*)g_alloca(strlen(w->text)+1);
710 text=w->text;
711 if (w->flags2 & 1) {
712 int i;
713 for (i = 0 ; i < strlen(text); i++)
714 startext[i]='*';
715 startext[i]='\0';
716 text=startext;
717 }
718 if (w->flags & gravity_right) {
719 pnt.y+=w->h-this->spacing;
720 pnt.x+=w->w-w->textw-this->spacing;
721 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
722 } else {
723 pnt.y+=w->h-this->spacing;
724 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
725 }
726 }
727 }
728
729 /**
730 * @brief A text box is a widget that renders a text string containing newlines.
731 * The string will be broken up into label widgets at each newline with a vertical layout.
732 *
733 */
734 static struct widget *
735 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
736 {
737 char *s=g_strdup(text),*s2,*tok;
738 struct widget *ret=gui_internal_box_new(this, flags);
739 s2=s;
740 while ((tok=strtok(s2,"\n"))) {
741 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
742 s2=NULL;
743 }
744 gui_internal_widget_pack(this,ret);
745 g_free(s);
746 return ret;
747 }
748
749 static struct widget *
750 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
751 {
752 return gui_internal_text_font_new(this, text, 0, flags);
753 }
754
755
756 static struct widget *
757 gui_internal_button_font_new_with_callback(struct gui_priv *this, char *text, int font, struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data)
758 {
759 struct widget *ret=NULL;
760 ret=gui_internal_box_new(this, flags);
761 if (ret) {
762 if (image)
763 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
764 if (text)
765 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
766 ret->func=func;
767 ret->data=data;
768 if (func) {
769 ret->state |= STATE_SENSITIVE;
770 ret->speech=g_strdup(text);
771 }
772 }
773 return ret;
774
775 }
776
777 static struct widget *
778 gui_internal_button_new_with_callback(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data)
779 {
780 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
781 }
782
783 static int
784 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
785 {
786 struct widget *wi;
787 int is_on=0;
788 struct attr curr;
789 GList *l;
790
791 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
792 is_on=curr.u.data == w->on.u.data;
793 else
794 is_on=w->deflt;
795 if (is_on != w->is_on) {
796 if (w->redraw)
797 this->redraw=1;
798 w->is_on=is_on;
799 l=g_list_first(w->children);
800 if (l) {
801 wi=l->data;
802 if (wi->img)
803 graphics_image_free(this->gra, wi->img);
804 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
805 }
806 if (w->is_on && w->off.type == attr_none)
807 w->state &= ~STATE_SENSITIVE;
808 else
809 w->state |= STATE_SENSITIVE;
810 return 1;
811 }
812 return 0;
813 }
814
815 static void
816 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
817 {
818 if (gui_internal_button_attr_update(this, w))
819 gui_internal_widget_render(this, w);
820 }
821 static void
822 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
823 {
824 if (w->is_on)
825 w->set_attr(w->instance, &w->off);
826 else
827 w->set_attr(w->instance, &w->on);
828 gui_internal_button_attr_update(this, w);
829
830 }
831
832 static struct widget *
833 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
834 {
835 struct graphics_image *image=NULL;
836 struct widget *ret;
837 if (!on && !off)
838 return NULL;
839 image=image_new_xs(this, "gui_inactive");
840 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
841 if (on)
842 ret->on=*on;
843 if (off)
844 ret->off=*off;
845 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
846 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
847 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
848 ret->instance=this->nav;
849 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
850 navit_add_callback(this->nav, ret->cb);
851 gui_internal_button_attr_update(this, ret);
852 return ret;
853 }
854
855 static struct widget *
856 gui_internal_button_map_attr_new(struct gui_priv *this, char *text, enum flags flags, struct map *map, struct attr *on, struct attr *off, int deflt)
857 {
858 struct graphics_image *image=NULL;
859 struct widget *ret;
860 image=image_new_xs(this, "gui_inactive");
861 if (!on && !off)
862 return NULL;
863 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
864 if (on)
865 ret->on=*on;
866 if (off)
867 ret->off=*off;
868 ret->deflt=deflt;
869 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
870 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
871 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
872 ret->instance=map;
873 ret->redraw=1;
874 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
875 map_add_callback(map, ret->cb);
876 gui_internal_button_attr_update(this, ret);
877 return ret;
878 }
879
880 static struct widget *
881 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
882 {
883 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
884 }
885
886 #if 0
887 //##############################################################################################################
888 //# Description:
889 //# Comment:
890 //# Authors: Martin Schaller (04/2008)
891 //##############################################################################################################
892 static void gui_internal_clear(struct gui_priv *this)
893 {
894 struct graphics *gra=this->gra;
895 struct point pnt;
896 pnt.x=0;
897 pnt.y=0;
898 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
899 }
900 #endif
901
902 static struct widget *
903 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
904 {
905 struct widget *ret,*child;
906 GList *l=wi->children;
907
908 if (p) {
909 if (wi->p.x > p->x )
910 return NULL;
911 if (wi->p.y > p->y )
912 return NULL;
913 if ( wi->p.x + wi->w < p->x)
914 return NULL;
915 if ( wi->p.y + wi->h < p->y)
916 return NULL;
917 }
918 if (wi->state & flags)
919 return wi;
920 while (l) {
921 child=l->data;
922 ret=gui_internal_find_widget(child, p, flags);
923 if (ret) {
924 return ret;
925 }
926 l=g_list_next(l);
927 }
928 return NULL;
929
930 }
931
932 static void
933 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
934 {
935 if (found == this->highlighted)
936 return;
937
938 graphics_draw_mode(this->gra, draw_mode_begin);
939 if (this->highlighted) {
940 this->highlighted->state &= ~STATE_HIGHLIGHTED;
941 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
942 gui_internal_widget_render(this, this->highlighted);
943 this->highlighted=NULL;
944 this->highlighted_menu=NULL;
945 }
946 if (found) {
947 this->highlighted=found;
948 this->highlighted_menu=g_list_last(this->root.children)->data;
949 this->highlighted->state |= STATE_HIGHLIGHTED;
950 gui_internal_widget_render(this, this->highlighted);
951 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
952 }
953 graphics_draw_mode(this->gra, draw_mode_end);
954 }
955 //##############################################################################################################
956 //# Description:
957 //# Comment:
958 //# Authors: Martin Schaller (04/2008)
959 //##############################################################################################################
960 static void gui_internal_highlight(struct gui_priv *this)
961 {
962 struct widget *menu,*found=NULL;
963 if (this->current.x > -1 && this->current.y > -1) {
964 menu=g_list_last(this->root.children)->data;
965 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
966 if (!found) {
967 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
968 if (found) {
969 if (this->editable && this->editable != found) {
970 this->editable->state &= ~ STATE_EDIT;
971 gui_internal_widget_render(this, this->editable);
972 }
973 found->state |= STATE_EDIT;
974 gui_internal_widget_render(this, found);
975 this->editable=found;
976 found=NULL;
977 }
978 }
979 }
980 gui_internal_highlight_do(this, found);
981 this->motion_timeout_event=NULL;
982 }
983
984 static struct widget *
985 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
986 {
987 struct widget *widget=g_new0(struct widget, 1);
988
989 if (label)
990 widget->text=g_strdup(label);
991 widget->type=widget_box;
992 widget->flags=flags;
993 return widget;
994 }
995
996 static struct widget *
997 gui_internal_box_new(struct gui_priv *this, enum flags flags)
998 {
999 return gui_internal_box_new_with_label(this, flags, NULL);
1000 }
1001
1002
1003 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
1004 {
1005 struct widget *wc;
1006 GList *l;
1007
1008 gui_internal_background_render(this, w);
1009 #if 0
1010 w->border=1;
1011 w->foreground=this->foreground;
1012 #endif
1013 #if 1
1014 if (w->foreground && w->border) {
1015 struct point pnt[5];
1016 pnt[0]=w->p;
1017 pnt[1].x=pnt[0].x+w->w;
1018 pnt[1].y=pnt[0].y;
1019 pnt[2].x=pnt[0].x+w->w;
1020 pnt[2].y=pnt[0].y+w->h;
1021 pnt[3].x=pnt[0].x;
1022 pnt[3].y=pnt[0].y+w->h;
1023 pnt[4]=pnt[0];
1024 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
1025 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
1026 graphics_gc_set_linewidth(w->foreground, 1);
1027 }
1028 #endif
1029
1030 l=w->children;
1031 while (l) {
1032 wc=l->data;
1033 gui_internal_widget_render(this, wc);
1034 l=g_list_next(l);
1035 }
1036 }
1037
1038
1039 /**
1040 * @brief Compute the size and location for the widget.
1041 *
1042 *
1043 */
1044 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
1045 {
1046 struct widget *wc;
1047 int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0;
1048 GList *l;
1049 int orientation=w->flags & 0xffff0000;
1050
1051 if (!cols)
1052 cols=this->cols;
1053 if (!cols) {
1054 if ( this->root.w > this->root.h )
1055 cols=3;
1056 else
1057 cols=2;
1058 width=0;
1059 height=0;
1060 }
1061
1062
1063 /**
1064 * count the number of children
1065 */
1066 l=w->children;
1067 while (l) {
1068 count++;
1069 l=g_list_next(l);
1070 }
1071 if (orientation == orientation_horizontal_vertical && count <= cols)
1072 orientation=orientation_horizontal;
1073 switch (orientation) {
1074 case orientation_horizontal:
1075 /**
1076 * For horizontal orientation:
1077 * pack each child and find the largest height and
1078 * compute the total width. x spacing (spx) is considered
1079 *
1080 * If any children want to be expanded
1081 * we keep track of this
1082 */
1083 l=w->children;
1084 while (l) {
1085 wc=l->data;
1086 gui_internal_widget_pack(this, wc);
1087 if (height < wc->h)
1088 height=wc->h;
1089 width+=wc->w;
1090 if (wc->flags & flags_expand)
1091 expand+=wc->w ? wc->w : 1;
1092 l=g_list_next(l);
1093 if (l)
1094 width+=w->spx;
1095 }
1096 owidth=width;
1097 if (expand && w->w) {
1098 expandd=w->w-width+expand;
1099 owidth=w->w;
1100 } else
1101 expandd=expand=1;
1102 break;
1103 case orientation_vertical:
1104 /**
1105 * For vertical layouts:
1106 * We pack each child and compute the largest width and
1107 * the total height. y spacing (spy) is considered
1108 *
1109 * If the expand flag is set then teh expansion amount
1110 * is computed.
1111 */
1112 l=w->children;
1113 while (l) {
1114 wc=l->data;
1115 gui_internal_widget_pack(this, wc);
1116 if (width < wc->w)
1117 width=wc->w;
1118 height+=wc->h;
1119 if (wc->flags & flags_expand)
1120 expand+=wc->h ? wc->h : 1;
1121 l=g_list_next(l);
1122 if (l)
1123 height+=w->spy;
1124 }
1125 oheight=height;
1126 if (expand && w->h) {
1127 expandd=w->h-height+expand;
1128 oheight=w->h;
1129 } else
1130 expandd=expand=1;
1131 break;
1132 case orientation_horizontal_vertical:
1133 /**
1134 * For horizontal_vertical orientation
1135 * pack the children.
1136 * Compute the largest height and largest width.
1137 * Layout the widgets based on having the
1138 * number of columns specified by (cols)
1139 */
1140 count=0;
1141 l=w->children;
1142 while (l) {
1143 wc=l->data;
1144 gui_internal_widget_pack(this, wc);
1145 if (height < wc->h)
1146 height=wc->h;
1147 if (width < wc->w)
1148 width=wc->w;
1149 l=g_list_next(l);
1150 count++;
1151 }
1152 if (count < cols)
1153 cols=count;
1154 rows=(count+cols-1)/cols;
1155 width*=cols;
1156 height*=rows;
1157 width+=w->spx*(cols-1);
1158 height+=w->spy*(rows-1);
1159 owidth=width;
1160 oheight=height;
1161 expandd=expand=1;
1162 break;
1163 default:
1164 /**
1165 * No orientation was specified.
1166 * width and height are both 0.
1167 * The width & height of this widget
1168 * will be used.
1169 */
1170 if(!w->w && !w->h)
1171 dbg(0,"Warning width and height of a widget are 0");
1172 break;
1173 }
1174 if (! w->w && ! w->h) {
1175 w->w=w->bl+w->br+width;
1176 w->h=w->bt+w->bb+height;
1177 w->packed=1;
1178 }
1179 #if 0
1180 if (expand < 100)
1181 expand=100;
1182 #endif
1183
1184 /**
1185 * At this stage the width and height of this
1186 * widget has been computed.
1187 * We now make a second pass assigning heights,
1188 * widths and coordinates to each child widget.
1189 */
1190
1191 if (w->flags & gravity_left)
1192 x=w->p.x+w->bl;
1193 if (w->flags & gravity_xcenter)
1194 x=w->p.x+w->w/2-owidth/2;
1195 if (w->flags & gravity_right)
1196 x=w->p.x+w->w-w->br-owidth;
1197 if (w->flags & gravity_top)
1198 y=w->p.y+w->bt;
1199 if (w->flags & gravity_ycenter)
1200 y=w->p.y+w->h/2-oheight/2;
1201 if (w->flags & gravity_bottom)
1202 y=w->p.y+w->h-w->bb-oheight;
1203 l=w->children;
1204 switch (orientation) {
1205 case orientation_horizontal:
1206 l=w->children;
1207 while (l) {
1208 wc=l->data;
1209 wc->p.x=x;
1210 if (wc->flags & flags_fill)
1211 wc->h=w->h;
1212 if (wc->flags & flags_expand) {
1213 if (! wc->w)
1214 wc->w=1;
1215 wc->w=wc->w*expandd/expand;
1216 }
1217 if (w->flags & gravity_top)
1218 wc->p.y=y;
1219 if (w->flags & gravity_ycenter)
1220 wc->p.y=y-wc->h/2;
1221 if (w->flags & gravity_bottom)
1222 wc->p.y=y-wc->h;
1223 x+=wc->w+w->spx;
1224 l=g_list_next(l);
1225 }
1226 break;
1227 case orientation_vertical:
1228 l=w->children;
1229 while (l) {
1230 wc=l->data;
1231 wc->p.y=y;
1232 if (wc->flags & flags_fill)
1233 wc->w=w->w;
1234 if (wc->flags & flags_expand) {
1235 if (! wc->h)
1236 wc->h=1;
1237 wc->h=wc->h*expandd/expand;
1238 }
1239 if (w->flags & gravity_left)
1240 wc->p.x=x;
1241 if (w->flags & gravity_xcenter)
1242 wc->p.x=x-wc->w/2;
1243 if (w->flags & gravity_right)
1244 wc->p.x=x-wc->w;
1245 y+=wc->h+w->spy;
1246 l=g_list_next(l);
1247 }
1248 break;
1249 case orientation_horizontal_vertical:
1250 l=w->children;
1251 x0=x;
1252 count=0;
1253 width/=cols;
1254 height/=rows;
1255 while (l) {
1256 wc=l->data;
1257 wc->p.x=x;
1258 wc->p.y=y;
1259 if (wc->flags & flags_fill) {
1260 wc->w=width;
1261 wc->h=height;
1262 }
1263 if (w->flags & gravity_left)
1264 wc->p.x=x;
1265 if (w->flags & gravity_xcenter)
1266 wc->p.x=x+(width-wc->w)/2;
1267 if (w->flags & gravity_right)
1268 wc->p.x=x+width-wc->w;
1269 if (w->flags & gravity_top)
1270 wc->p.y=y;
1271 if (w->flags & gravity_ycenter)
1272 wc->p.y=y+(height-wc->h)/2;
1273 if (w->flags & gravity_bottom)
1274 wc->p.y=y-height-wc->h;
1275 x+=width;
1276 if (++count == cols) {
1277 count=0;
1278 x=x0;
1279 y+=height;
1280 }
1281 l=g_list_next(l);
1282 }
1283 break;
1284 default:
1285 break;
1286 }
1287 /**
1288 * Call pack again on each child,
1289 * the child has now had its size and coordinates
1290 * set so they can repack their children.
1291 */
1292 l=w->children;
1293 while (l) {
1294 wc=l->data;
1295 gui_internal_widget_pack(this, wc);
1296 l=g_list_next(l);
1297 }
1298 }
1299
1300 static void
1301 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1302 {
1303 struct widget *wc;
1304 GList *l;
1305
1306 l=w->children;
1307 while (l) {
1308 wc=l->data;
1309 gui_internal_widget_reset_pack(this, wc);
1310 l=g_list_next(l);
1311 }
1312 if (w->packed) {
1313 w->w=0;
1314 w->h=0;
1315 }
1316 }
1317
1318 static void
1319 gui_internal_widget_append(struct widget *parent, struct widget *child)
1320 {
1321 if (! child)
1322 return;
1323 if (! child->background)
1324 child->background=parent->background;
1325 parent->children=g_list_append(parent->children, child);
1326 }
1327
1328 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1329 {
1330 if (! child->background)
1331 child->background=parent->background;
1332 parent->children=g_list_prepend(parent->children, child);
1333 }
1334
1335 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1336 {
1337 GList *l;
1338 struct widget *wc;
1339
1340 l=w->children;
1341 while (l) {
1342 wc=l->data;
1343 gui_internal_widget_destroy(this, wc);
1344 l=g_list_next(l);
1345 }
1346 g_list_free(w->children);
1347 w->children=NULL;
1348 }
1349
1350 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1351 {
1352 gui_internal_widget_children_destroy(this, w);
1353 g_free(w->command);
1354 g_free(w->speech);
1355 g_free(w->text);
1356 if (w->img)
1357 graphics_image_free(this->gra, w->img);
1358 if (w->prefix)
1359 g_free(w->prefix);
1360 if (w->name)
1361 g_free(w->name);
1362 if (w->data_free)
1363 w->data_free(w->data);
1364 if (w->cb && w->remove_cb)
1365 w->remove_cb(w->instance, w->cb);
1366 if (w==this->highlighted)
1367 this->highlighted=NULL;
1368 if(w->free)
1369 w->free(this,w);
1370 else
1371 g_free(w);
1372 }
1373
1374
1375 static void
1376 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1377 {
1378 if(w->p.x > this->root.w || w->p.y > this->root.h)
1379 return;
1380
1381 switch (w->type) {
1382 case widget_box:
1383 gui_internal_box_render(this, w);
1384 break;
1385 case widget_label:
1386 gui_internal_label_render(this, w);
1387 break;
1388 case widget_image:
1389 gui_internal_image_render(this, w);
1390 break;
1391 case widget_table:
1392 gui_internal_table_render(this,w);
1393 break;
1394 default:
1395 break;
1396 }
1397 }
1398
1399 static void
1400 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1401 {
1402 switch (w->type) {
1403 case widget_box:
1404 gui_internal_box_pack(this, w);
1405 break;
1406 case widget_table:
1407 gui_internal_table_pack(this,w);
1408 default:
1409 break;
1410 }
1411 }
1412
1413 //##############################################################################################################
1414 //# Description:
1415 //# Comment:
1416 //# Authors: Martin Schaller (04/2008)
1417 //##############################################################################################################
1418 static void gui_internal_call_highlighted(struct gui_priv *this)
1419 {
1420 if (! this->highlighted || ! this->highlighted->func)
1421 return;
1422 this->highlighted->reason=1;
1423 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1424 }
1425
1426 static void
1427 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1428 {
1429 char *text=w->speech;
1430 if (! this->speech)
1431 return;
1432 if (!text)
1433 text=w->text;
1434 if (!text)
1435 text=w->name;
1436 if (text) {
1437 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1438 navit_say(this->nav, text);
1439 g_free(text);
1440 }
1441 }
1442
1443 static void
1444 gui_internal_menu_destroy(struct gui_priv *this, struct widget *w)
1445 {
1446 struct menu_data *menu_data=w->menu_data;
1447 if (menu_data) {
1448 if (menu_data->refresh_callback_obj.type) {
1449 struct object_func *func;
1450 func=object_func_lookup(menu_data->refresh_callback_obj.type);
1451 if (func && func->remove_attr)
1452 func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
1453 }
1454 if (menu_data->refresh_callback.u.callback)
1455 callback_destroy(menu_data->refresh_callback.u.callback);
1456
1457 g_free(menu_data->href);
1458 g_free(menu_data);
1459 }
1460 gui_internal_widget_destroy(this, w);
1461 this->root.children=g_list_remove(this->root.children, w);
1462 }
1463
1464 static void
1465 gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render)
1466 {
1467 GList *l;
1468 struct widget *wr,*wd;
1469 gui_internal_search_idle_end(this);
1470 while ((l = g_list_last(this->root.children))) {
1471 wd=l->data;
1472 if (wd == w) {
1473 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1474 if (!render)
1475 return;
1476 gui_internal_say(this, w, 0);
1477 redisplay=w->menu_data->redisplay;
1478 wr=w->menu_data->redisplay_widget;
1479 if (!w->menu_data->redisplay && !w->menu_data->href) {
1480 gui_internal_widget_render(this, w);
1481 return;
1482 }
1483 if (redisplay) {
1484 gui_internal_menu_destroy(this, w);
1485 redisplay(this, wr, wr->data);
1486 } else {
1487 char *href=g_strdup(w->menu_data->href);
1488 gui_internal_menu_destroy(this, w);
1489 gui_internal_html_load_href(this, href, 0);
1490 g_free(href);
1491 }
1492 return;
1493 }
1494 gui_internal_menu_destroy(this, wd);
1495 }
1496 }
1497
1498 static void
1499 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1500 {
1501 gui_internal_prune_menu_do(this, w, 1);
1502 }
1503
1504 static void
1505 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1506 {
1507 GList *l=g_list_last(this->root.children);
1508 struct widget *w=NULL;
1509 while (l && count-- > 0)
1510 l=g_list_previous(l);
1511 if (l) {
1512 w=l->data;
1513 gui_internal_prune_menu_do(this, w, render);
1514 }
1515 }
1516
1517 static void
1518 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1519 {
1520 gui_internal_prune_menu_count(this, 1, 1);
1521 }
1522
1523 static void
1524 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1525 {
1526 gui_internal_prune_menu(this, wm->data);
1527 }
1528
1529 static void
1530 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1531 {
1532 graphics_draw_mode(this->gra, draw_mode_begin);
1533 gui_internal_back(this, NULL, NULL);
1534 graphics_draw_mode(this->gra, draw_mode_end);
1535 gui_internal_check_exit(this);
1536 }
1537
1538 static void
1539 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1540 {
1541 gui_internal_prune_menu(this, NULL);
1542 }
1543
1544 static void
1545 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1546 {
1547 gui_internal_prune_menu(this, this->root.children->data);
1548 }
1549
1550 static struct widget *
1551 gui_internal_top_bar(struct gui_priv *this)
1552 {
1553 struct widget *w,*wm,*wh,*wc,*wcn;
1554 int dots_len, sep_len;
1555 GList *res=NULL,*l;
1556 int width,width_used=0,use_sep=0,incomplete=0;
1557 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1558 /* flags
1559 1:Don't expand bar to screen width
1560 2:Don't show Map Icon
1561 4:Don't show Home Icon
1562 8:Show only current menu
1563 16:Don't use menu titles as button
1564 32:Show navit version
1565 64:Show time
1566 128:Show help
1567 256:Use background for menu headline
1568 512:Set osd_configuration and zoom to route when setting position
1569 1024:Don't show back button
1570 2048:No highlighting of keyboard
1571 */
1572
1573 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1574 w->bl=this->spacing;
1575 w->spx=this->spacing;
1576 w->background=this->background2;
1577 if ((this->flags & 6) == 6) {
1578 w->bl=10;
1579 w->br=10;
1580 w->bt=6;
1581 w->bb=6;
1582 }
1583 width=this->root.w-w->bl;
1584 if (! (this->flags & 2)) {
1585 wm=gui_internal_button_new_with_callback(this, NULL,
1586 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1587 gui_internal_cmd_return, NULL);
1588 wm->speech=g_strdup(_("Back to map"));
1589 gui_internal_widget_pack(this, wm);
1590 gui_internal_widget_append(w, wm);
1591 width-=wm->w;
1592 }
1593 if (! (this->flags & 4)) {
1594 wh=gui_internal_button_new_with_callback(this, NULL,
1595 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1596 gui_internal_cmd_main_menu, NULL);
1597 wh->speech=g_strdup(_("Main Menu"));
1598 gui_internal_widget_pack(this, wh);
1599 gui_internal_widget_append(w, wh);
1600 width-=wh->w;
1601 }
1602 if (!(this->flags & 6))
1603 width-=w->spx;
1604 l=g_list_last(this->root.children);
1605 wcn=gui_internal_label_new(this,".. »");
1606 wcn->foreground=foreground;
1607 dots_len=wcn->w;
1608 gui_internal_widget_destroy(this, wcn);
1609 wcn=gui_internal_label_new(this,"»");
1610 wcn->foreground=foreground;
1611 sep_len=wcn->w;
1612 gui_internal_widget_destroy(this, wcn);
1613 while (l) {
1614 if (g_list_previous(l) || !g_list_next(l)) {
1615 wc=l->data;
1616 wcn=gui_internal_label_new(this, wc->text);
1617 wcn->foreground=foreground;
1618 if (g_list_next(l))
1619 use_sep=1;
1620 else
1621 use_sep=0;
1622 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1623 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1624 incomplete=1;
1625 gui_internal_widget_destroy(this, wcn);
1626 break;
1627 }
1628 if (use_sep) {
1629 struct widget *wct=gui_internal_label_new(this, "»");
1630 wct->foreground=foreground;
1631 res=g_list_prepend(res, wct);
1632 width_used+=sep_len+w->spx;
1633 }
1634 width_used+=wcn->w;
1635 if (!(this->flags & 16)) {
1636 wcn->func=gui_internal_cmd_return;
1637 wcn->data=wc;
1638 wcn->state |= STATE_SENSITIVE;
1639 }
1640 res=g_list_prepend(res, wcn);
1641 if (this->flags & 8)
1642 break;
1643 }
1644 l=g_list_previous(l);
1645 }
1646 if (incomplete) {
1647 if (! res) {
1648 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1649 wcn->foreground=foreground;
1650 wcn->func=gui_internal_cmd_return;
1651 wcn->data=wc;
1652 wcn->state |= STATE_SENSITIVE;
1653 res=g_list_prepend(res, wcn);
1654 l=g_list_previous(l);
1655 wc=l->data;
1656 }
1657 wcn=gui_internal_label_new(this, ".. »");
1658 wcn->foreground=foreground;
1659 wcn->func=gui_internal_cmd_return;
1660 wcn->data=wc;
1661 wcn->state |= STATE_SENSITIVE;
1662 res=g_list_prepend(res, wcn);
1663 }
1664 l=res;
1665 while (l) {
1666 gui_internal_widget_append(w, l->data);
1667 l=g_list_next(l);
1668 }
1669 if (this->flags & 32) {
1670 char *version_text=g_strdup_printf("Navit %s",version);
1671 wcn=gui_internal_label_new(this, version_text);
1672 g_free(version_text);
1673 wcn->flags=gravity_right_center|flags_expand;
1674 gui_internal_widget_append(w, wcn);
1675 }
1676 #if 0
1677 if (dots)
1678 gui_internal_widget_destroy(this, dots);
1679 #endif
1680 return w;
1681 }
1682
1683 static struct widget *
1684 gui_internal_time_help(struct gui_priv *this)
1685 {
1686 struct widget *w,*wc,*wcn;
1687 char timestr[64];
1688 struct tm *tm;
1689 time_t timep;
1690
1691 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1692 w->bl=this->spacing;
1693 w->spx=this->spacing;
1694 w->spx=10;
1695 w->bl=10;
1696 w->br=10;
1697 w->bt=6;
1698 w->bb=6;
1699 if (this->flags & 64) {
1700 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1701 wc->bl=10;
1702 wc->br=20;
1703 wc->bt=6;
1704 wc->bb=6;
1705 timep=time(NULL);
1706 tm=localtime(&timep);
1707 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1708 wcn=gui_internal_label_new(this, timestr);
1709 gui_internal_widget_append(wc, wcn);
1710 gui_internal_widget_append(w, wc);
1711 }
1712 if (this->flags & 128) {
1713 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1714 gui_internal_widget_append(w, wcn);
1715 }
1716 return w;
1717 }
1718
1719
1720 /**
1721 * Applys the configuration values to this based on the settings
1722 * specified in the configuration file (this->config) and
1723 * the most approriate default profile based on screen resolution.
1724 *
1725 * This function should be run after this->root is setup and could
1726 * be rerun after the window is resized.
1727 *
1728 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1729 */
1730 static void gui_internal_apply_config(struct gui_priv *this)
1731 {
1732 struct gui_config_settings * current_config=0;
1733
1734 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1735 /**
1736 * Select default values from profile based on the screen.
1737 */
1738 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1739 {
1740 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1741 {
1742 current_config = &config_profiles[LARGE_PROFILE];
1743 }
1744 else
1745 {
1746 current_config = &config_profiles[MEDIUM_PROFILE];
1747 }
1748 }
1749 else
1750 {
1751 current_config = &config_profiles[SMALL_PROFILE];
1752 }
1753
1754 /**
1755 * Apply override values from config file
1756 */
1757 if(this->config.font_size == -1 )
1758 {
1759 this->font_size = current_config->font_size;
1760 }
1761 else
1762 {
1763 this->font_size = this->config.font_size;
1764 }
1765
1766 if(this->config.icon_xs == -1 )
1767 {
1768 this->icon_xs = current_config->icon_xs;
1769 }
1770 else
1771 {
1772 this->icon_xs = this->config.icon_xs;
1773 }
1774
1775 if(this->config.icon_s == -1 )
1776 {
1777 this->icon_s = current_config->icon_s;
1778 }
1779 else
1780 {
1781 this->icon_s = this->config.icon_s;
1782 }
1783 if(this->config.icon_l == -1 )
1784 {
1785 this->icon_l = current_config->icon_l;
1786 }
1787 else
1788 {
1789 this->icon_l = this->config.icon_l;
1790 }
1791 if(this->config.spacing == -1 )
1792 {
1793 this->spacing = current_config->spacing;
1794 }
1795 else
1796 {
1797 this->spacing = current_config->spacing;
1798 }
1799
1800 }
1801
1802 static struct widget *
1803 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1804 {
1805 struct widget *wl,*wlb;
1806 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1807 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1808 wl=gui_internal_label_new(this, label);
1809 wlb->border=1;
1810 wlb->foreground=this->text_foreground;
1811 wlb->bl=20;
1812 wlb->br=20;
1813 wlb->bb=6;
1814 wlb->bt=6;
1815 gui_internal_widget_append(wlb, wl);
1816 if (mode == 1)
1817 gui_internal_widget_prepend(wb, wlb);
1818 if (mode == -1)
1819 gui_internal_widget_append(wb, wlb);
1820
1821 return wlb;
1822 }
1823
1824
1825 static struct widget *
1826 gui_internal_menu(struct gui_priv *this, const char *label)
1827 {
1828 struct widget *menu,*w,*w1,*topbox;
1829
1830 gui_internal_search_idle_end(this);
1831 topbox=gui_internal_box_new_with_label(this, 0, label);
1832 topbox->w=this->root.w;
1833 topbox->h=this->root.h;
1834 gui_internal_widget_append(&this->root, topbox);
1835 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1836 menu->w=this->root.w;
1837 menu->h=this->root.h;
1838 menu->background=this->background;
1839 gui_internal_apply_config(this);
1840 if (!this->fonts[0]) {
1841 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
1842 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
1843 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
1844 }
1845 topbox->menu_data=g_new0(struct menu_data, 1);
1846 gui_internal_widget_append(topbox, menu);
1847 w=gui_internal_top_bar(this);
1848 gui_internal_widget_append(menu, w);
1849 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1850 w->spx=4*this->spacing;
1851 w->w=menu->w;
1852 gui_internal_widget_append(menu, w);
1853 if (this->flags & 16 && !(this->flags & 1024)) {
1854 struct widget *wlb,*wb,*wm=w;
1855 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1856 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1857 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1858 gui_internal_widget_append(wm, w);
1859 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1860 wb->bl=6;
1861 wb->br=6;
1862 wb->bb=6;
1863 wb->bt=6;
1864 wb->spx=6;
1865 topbox->menu_data->button_bar=wb;
1866 gui_internal_widget_append(wm, wb);
1867 wlb=gui_internal_button_label(this,_("Back"),1);
1868 wlb->func=gui_internal_back;
1869 wlb->state |= STATE_SENSITIVE;
1870 }
1871 if (this->flags & 192) {
1872 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1873 menu->w=this->root.w;
1874 menu->h=this->root.h;
1875 w1=gui_internal_time_help(this);
1876 gui_internal_widget_append(menu, w1);
1877 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1878 gui_internal_widget_append(menu, w1);
1879 gui_internal_widget_append(topbox, menu);
1880 menu->background=NULL;
1881 }
1882 gui_internal_widget_pack(this, topbox);
1883 gui_internal_widget_reset_pack(this, topbox);
1884 topbox->w=this->root.w;
1885 topbox->h=this->root.h;
1886 menu->w=this->root.w;
1887 menu->h=this->root.h;
1888 return w;
1889 }
1890
1891 static struct menu_data *
1892 gui_internal_menu_data(struct gui_priv *this)
1893 {
1894 GList *l;
1895 struct widget *menu;
1896
1897 l=g_list_last(this->root.children);
1898 menu=l->data;
1899 return menu->menu_data;
1900 }
1901
1902 static void
1903 gui_internal_menu_reset_pack(struct gui_priv *this)
1904 {
1905 GList *l;
1906 struct widget *top_box;
1907
1908 l=g_list_last(this->root.children);
1909 top_box=l->data;
1910 gui_internal_widget_reset_pack(this, top_box);
1911 }
1912
1913 static void
1914 gui_internal_menu_render(struct gui_priv *this)
1915 {
1916 GList *l;
1917 struct widget *menu;
1918
1919 l=g_list_last(this->root.children);
1920 menu=l->data;
1921 gui_internal_say(this, menu, 0);
1922 gui_internal_widget_pack(this, menu);
1923 gui_internal_widget_render(this, menu);
1924 }
1925
1926 static void
1927 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1928 {
1929 char *name=data;
1930 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1931 navit_set_destination(this->nav, &wm->c, name, 1);
1932 if (this->flags & 512) {
1933 struct attr follow;
1934 follow.type=attr_follow;
1935 follow.u.num=180;
1936 navit_set_attr(this->nav, &this->osd_configuration);
1937 navit_set_attr(this->nav, &follow);
1938 navit_zoom_to_route(this->nav, 0);
1939 }
1940 gui_internal_prune_menu(this, NULL);
1941 }
1942
1943 static void
1944 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1945 {
1946 navit_set_position(this->nav, &wm->c);
1947 gui_internal_prune_menu(this, NULL);
1948 }
1949
1950 static void
1951 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1952 {
1953 GList *l;
1954 struct attr attr;
1955 dbg(0,"text='%s'\n", widget->text);
1956 if (widget->text && strlen(widget->text)){
1957 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1958 bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
1959 }
1960 g_free(widget->text);
1961 widget->text=NULL;
1962 l=g_list_previous(g_list_last(this->root.children));
1963 gui_internal_prune_menu(this, l->data);
1964 }
1965
1966 static void
1967 gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
1968 {
1969 GList *l;
1970 struct attr attr;
1971 dbg(0,"text='%s'\n", widget->text);
1972 if (widget->text && strlen(widget->text)){
1973 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1974 bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
1975 }
1976 g_free(widget->text);
1977 widget->text=NULL;
1978 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
1979 gui_internal_prune_menu(this, l->data);
1980 }
1981
1982 static void
1983 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1984 {
1985 gui_internal_cmd_add_bookmark_do(this, widget->data);
1986 }
1987
1988 static void
1989 gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
1990 {
1991 gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
1992 }
1993
1994 static void
1995 gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
1996 {
1997 struct widget *w=(struct widget*)widget->data;
1998 GList *l;
1999 struct attr attr;
2000 dbg(0,"text='%s'\n", w->text);
2001 if (w->text && strlen(w->text)){
2002 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2003 bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
2004 }
2005 g_free(w->text);
2006 g_free(w->name);
2007 w->text=NULL;
2008 w->name=NULL;
2009 l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
2010 gui_internal_prune_menu(this, l->data);
2011 }
2012
2013 static void
2014 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
2015 {
2016 int len;
2017 dbg(1,"enter\n");
2018 if (wm->text) {
2019 len=strlen(wm->text);
2020 dbg(1,"len=%d\n", len);
2021 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2022 wm->text[len-1]='\0';
2023 gui_internal_cmd_add_bookmark_do(this, wm);
2024 }
2025 }
2026 }
2027
2028
2029 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
2030
2031 static void
2032 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
2033 {
2034 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2035 char *name=data;
2036 wb=gui_internal_menu(this,_("Add Bookmark"));
2037 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2038 gui_internal_widget_append(wb, w);
2039 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2040 gui_internal_widget_append(w, we);
2041 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2042 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2043 wk->background=this->background;
2044 wk->flags |= flags_expand|flags_fill;
2045 wk->func = gui_internal_cmd_add_bookmark_changed;
2046 wk->c=wm->c;
2047 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2048 wnext->state |= STATE_SENSITIVE;
2049 wnext->func = gui_internal_cmd_add_bookmark_clicked;
2050 wnext->data=wk;
2051 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2052 gui_internal_widget_append(w, wl);
2053 if (this->keyboard)
2054 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2055 gui_internal_menu_render(this);
2056 }
2057
2058 static void
2059 gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
2060 {
2061 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2062 char *name=data;
2063 wb=gui_internal_menu(this,_("Add Bookmark folder"));
2064 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2065 gui_internal_widget_append(wb, w);
2066 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2067 gui_internal_widget_append(w, we);
2068 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2069 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2070 wk->background=this->background;
2071 wk->flags |= flags_expand|flags_fill;
2072 wk->func = gui_internal_cmd_add_bookmark_changed;
2073 wk->c=wm->c;
2074 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2075 wnext->state |= STATE_SENSITIVE;
2076 wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
2077 wnext->data=wk;
2078 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2079 gui_internal_widget_append(w, wl);
2080 if (this->keyboard)
2081 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2082 gui_internal_menu_render(this);
2083 }
2084
2085 static void
2086 gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2087 {
2088 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2089 char *name=wm->text;
2090 wb=gui_internal_menu(this,_("Rename"));
2091 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2092 gui_internal_widget_append(wb, w);
2093 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2094 gui_internal_widget_append(w, we);
2095 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2096 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2097 wk->background=this->background;
2098 wk->flags |= flags_expand|flags_fill;
2099 wk->func = gui_internal_cmd_add_bookmark_changed;
2100 wk->c=wm->c;
2101 wk->name=g_strdup(name);
2102 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2103 wnext->state |= STATE_SENSITIVE;
2104 wnext->func = gui_internal_cmd_rename_bookmark_clicked;
2105 wnext->data=wk;
2106 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2107 gui_internal_widget_append(w, wl);
2108 if (this->keyboard)
2109 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2110 gui_internal_menu_render(this);
2111 }
2112
2113 static void
2114 gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2115 {
2116 struct attr mattr;
2117 GList *l;
2118 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2119 bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
2120 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2121 gui_internal_prune_menu(this, l->data);
2122 }
2123
2124 static void
2125 gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2126 {
2127 struct attr mattr;
2128 GList *l;
2129 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2130 bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
2131 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2132 gui_internal_prune_menu(this, l->data);
2133 }
2134
2135 static void
2136 gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2137 {
2138 struct attr mattr;
2139 GList *l;
2140 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2141 bookmarks_paste_bookmark(mattr.u.bookmarks);
2142 l=g_list_previous(g_list_last(this->root.children));
2143 gui_internal_prune_menu(this, l->data);
2144 }
2145
2146 static void
2147 gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2148 {
2149 struct attr mattr;
2150 GList *l;
2151 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2152 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
2153 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2154 gui_internal_prune_menu(this, l->data);
2155 }
2156
2157 static void
2158 get_direction(char *buffer, int angle, int mode)
2159 {
2160 angle=angle%360;
2161 switch (mode) {
2162 case 0:
2163 sprintf(buffer,"%d",angle);
2164 break;
2165 case 1:
2166 if (angle < 69 || angle > 291)
2167 *buffer++='N';
2168 if (angle > 111 && angle < 249)
2169 *buffer++='S';
2170 if (angle > 22 && angle < 158)
2171 *buffer++='E';
2172 if (angle > 202 && angle < 338)
2173 *buffer++='W';
2174 *buffer++='\0';
2175 break;
2176 case 2:
2177 angle=(angle+15)/30;
2178 if (! angle)
2179 angle=12;
2180 sprintf(buffer,"%d H", angle);
2181 break;
2182 }
2183 }
2184
2185 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2186
2187 #ifndef _MSC_VER
2188 //MSVC doesn't supports this style of initialization and i'm not sure
2189 //how to fix it
2190 struct selector {
2191 char *icon;
2192 char *name;
2193 enum item_type *types;
2194 };
2195 struct selector selectors[]={
2196 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
2197 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
2198 {"hotel","Hotel",(enum item_type []) {
2199 type_poi_hotel,type_poi_camp_rv,
2200 type_poi_camping,type_poi_camping,
2201 type_poi_resort,type_poi_resort,
2202 type_poi_motel,type_poi_hostel,
2203 type_none}},
2204 {"restaurant","Restaurant",(enum item_type []) {
2205 type_poi_bar,type_poi_picnic,
2206 type_poi_burgerking,type_poi_fastfood,
2207 type_poi_restaurant,type_poi_restaurant,
2208 type_none}},
2209 {"shopping","Shopping",(enum item_type []) {
2210 type_poi_mall,type_poi_mall,
2211 type_poi_shop_grocery,type_poi_shop_grocery,
2212 type_none}},
2213 {"hospital","Service",(enum item_type []) {
2214 type_poi_marina,type_poi_marina,
2215 type_poi_hospital,type_poi_hospital,
2216 type_poi_public_utilities,type_poi_public_utilities,
2217 type_poi_police,type_poi_autoservice,
2218 type_poi_information,type_poi_information,
2219 type_poi_personal_service,type_poi_repair_service,
2220 type_poi_restroom,type_poi_restroom,
2221 type_none}},
2222 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
2223 {"peak","Land Features",(enum item_type []){
2224 type_poi_land_feature,type_poi_rock,
2225 type_poi_dam,type_poi_dam,
2226 type_poi_peak,type_poi_peak,
2227 type_none}},
2228 {"unknown","Other",(enum item_type []){
2229 type_point_unspecified,type_poi_land_feature-1,
2230 type_poi_rock+1,type_poi_fuel-1,
2231 type_poi_marina+1,type_poi_car_parking-1,
2232 type_poi_car_parking+1,type_poi_bar-1,
2233 type_poi_bank+1,type_poi_dam-1,
2234 type_poi_dam+1,type_poi_information-1,
2235 type_poi_information+1,type_poi_mall-1,
2236 type_poi_mall+1,type_poi_personal_service-1,
2237 type_poi_repair_service+1,type_poi_restaurant-1,
2238 type_poi_restaurant+1,type_poi_restroom-1,
2239 type_poi_restroom+1,type_poi_shop_grocery-1,
2240 type_poi_shop_grocery+1,type_poi_peak-1,
2241 type_poi_peak+1, type_poi_motel-1,
2242 type_poi_hostel+1,type_line-1,
2243 type_none}},
2244 {"unknown","Unknown",(enum item_type []){
2245 type_point_unkn,type_point_unkn,
2246 type_none}},
2247 };
2248
2249 union poi_param {
2250 guint i;
2251 struct {
2252 unsigned char sel, selnb, pagenb, dist;
2253 } p;
2254 };
2255
2256 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2257
2258 static struct widget *
2259 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb)
2260 {
2261 struct widget *wl,*wb;
2262 int nitems,nrows;
2263 int i;
2264 //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2265 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
2266 wl->background=this->background;
2267 wl->w=this->root.w;
2268 wl->cols=this->root.w/this->icon_s;
2269 nitems=sizeof(selectors)/sizeof(struct selector);
2270 nrows=nitems/wl->cols + (nitems%wl->cols>0);
2271 wl->h=this->icon_l*nrows;
2272 for (i = 0 ; i < nitems ; i++) {
2273 union poi_param p;
2274 p.p.sel = 1;
2275 p.p.selnb = i;
2276 p.p.pagenb = pagenb;
2277 p.p.dist = 0;
2278 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2279 image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2280 gui_internal_cmd_pois, GUINT_TO_POINTER(p.i)));
2281 wb->c=*c;
2282 wb->bt=10;
2283 }
2284 gui_internal_widget_pack(this,wl);
2285 return wl;
2286 }
2287
2288 static struct widget *
2289 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist, char* name)
2290 {
2291 char distbuf[32];
2292 char dirbuf[32];
2293 char *type;
2294 struct widget *wl,*wt;
2295 char *text;
2296
2297 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2298
2299 if (dist > 10000)
2300 sprintf(distbuf,"%d", dist/1000);
2301 else
2302 sprintf(distbuf,"%d.%d", dist/1000, (dist%1000)/100);
2303 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2304 type=item_to_name(item->type);
2305 if (name[0]) {
2306 wl->name=g_strdup_printf("%s %s",type,name);
2307 } else {
2308 wl->name=g_strdup(type);
2309 }
2310 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, name);
2311 wt=gui_internal_label_new(this, text);
2312 wt->datai=dist;
2313 gui_internal_widget_append(wl, wt);
2314 g_free(text);
2315
2316 return wl;
2317 }
2318
2319 static gint
2320 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
2321 {
2322 const struct widget *wa=a;
2323 const struct widget *wb=b;
2324 struct widget *wac=wa->children->data;
2325 struct widget *wbc=wb->children->data;
2326 #if 0
2327 int ia,ib;
2328 ia=atoi(wac->text);
2329 ib=atoi(wbc->text);
2330
2331 return ia-ib;
2332 #else
2333 return wac->datai-wbc->datai;
2334 #endif
2335 }
2336
2337 static int
2338 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
2339 {
2340 enum item_type *types;
2341 if (type >= type_line)
2342 return 0;
2343 if (! sel || !sel->types)
2344 return 1;
2345 types=sel->types;
2346 while (*types != type_none) {
2347 if (type >= types[0] && type <= types[1]) {
2348 return 1;
2349 }
2350 types+=2;
2351 }
2352 return 0;
2353 }
2354
2355 struct item_data {
2356 int dist;
2357 char *label;
2358 struct item item;
2359 struct coord c;
2360 };
2361
2362 /**
2363 * @brief Event handler for POIs list "more" element.
2364 *
2365 * @param this The graphics context.
2366 * @param wm called widget.
2367 * @param data event data.
2368 */
2369 static void
2370 gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
2371 {
2372 struct widget *w=g_new0(struct widget,1);
2373 w->data=wm->data;
2374 w->c=wm->c;
2375 w->w=wm->w;
2376 gui_internal_back(this, NULL, NULL);
2377 gui_internal_cmd_pois(this, w, NULL);
2378 free(w);
2379 }
2380
2381
2382 static void
2383 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
2384 {
2385 struct map_selection *sel,*selm;
2386 struct coord c,center;
2387 struct mapset_handle *h;
2388 struct map *m;
2389 struct map_rect *mr;
2390 struct item *item;
2391 struct widget *wi,*w,*w2,*wb, *wtable, *row;
2392 enum projection pro=wm->c.pro;
2393 union poi_param param = {.i = GPOINTER_TO_UINT(wm->data)};
2394 int idist,dist=10000*(param.p.dist+1);
2395 struct selector *isel = param.p.sel? &selectors[param.p.selnb]: NULL;
2396 int pagenb = param.p.pagenb;
2397 int prevdist=param.p.dist*10000;
2398 const int pagesize = 50; // Starting value and increment of count of items to be extracted
2399 int maxitem = pagesize*(pagenb+1), it = 0, i;
2400 struct item_data *items= g_new0( struct item_data, maxitem);
2401 struct fibheap* fh = fh_makekeyheap();
2402 int cnt = 0;
2403 struct table_data *td;
2404 int width=wm->w;
2405 dbg(2, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i\n",
2406 param.p.sel, param.p.selnb, param.p.pagenb, param.p.dist);
2407
2408 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2409 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2410 gui_internal_widget_append(wb, w);
2411 if (!isel)
2412 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
2413 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2414 gui_internal_widget_append(w, w2);
2415
2416 sel=map_selection_rect_new(&wm->c,dist*transform_scale(wm->c.y),18);
2417 center.x=wm->c.x;
2418 center.y=wm->c.y;
2419 h=mapset_open(navit_get_mapset(this->nav));
2420 while ((m=mapset_next(h, 1))) {
2421 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2422 mr=map_rect_new(m, selm);
2423 dbg(2,"mr=%p\n", mr);
2424 if (mr) {
2425 while ((item=map_rect_get_item(mr))) {
2426 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
2427 item_coord_get_pro(item, &c, 1, pro) &&
2428 coord_rect_contains(&sel->u.c_rect, &c) &&
2429 (idist=transform_distance(pro, &center, &c)) < dist) {
2430 struct item_data *data;
2431 struct attr attr;
2432 if(it>=maxitem) {
2433 data = fh_extractmin(fh);
2434 free(data->label);
2435 data->label=NULL;
2436 } else {
2437 data = &items[it++];
2438 }
2439 data->item = *item;
2440 data->c = c;
2441 data->dist = idist;
2442 if (item_attr_get(item, attr_label, &attr)) {
2443 data->label=g_strdup(attr.u.str);
2444 } else {
2445 data->label=g_strdup("");
2446 }
2447 // Key expression is a workaround to fight
2448 // probable heap collisions when two objects
2449 // are at the same distance. But it destroys
2450 // right order of POIs 2048 km away from cener
2451 // and if table grows more than 1024 rows.
2452 fh_insertkey(fh, -((idist<<10) + cnt++), data);
2453 if (it == maxitem)
2454 dist = (-fh_minkey(fh))>>10;
2455 }
2456 }
2457 map_rect_destroy(mr);
2458 }
2459 map_selection_destroy(selm);
2460 }
2461 map_selection_destroy(sel);
2462 mapset_close(h);
2463
2464 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
2465 td=wtable->data;
2466
2467 gui_internal_widget_append(w2,wtable);
2468
2469 // Move items from heap to the table
2470 for(i=0;;i++)
2471 {
2472 int key = fh_minkey(fh);
2473 struct item_data *data = fh_extractmin(fh);
2474 if (data == NULL)
2475 {
2476 dbg(2, "Empty heap: maxitem = %i, it = %i, dist = %i\n", maxitem, it, dist);
2477 break;
2478 }
2479 dbg(2, "dist1: %i, dist2: %i\n", data->dist, (-key)>>10);
2480 if(i==(it-pagesize*pagenb) && data->dist>prevdist)
2481 prevdist=data->dist;
2482 wi=gui_internal_cmd_pois_item(this, &center, &data->item, &data->c, data->dist, data->label);
2483 wi->func=gui_internal_cmd_position;
2484 wi->data=(void *)2;
2485 wi->item=data->item;
2486 wi->state |= STATE_SENSITIVE;
2487 wi->c.x=data->c.x;
2488 wi->c.y=data->c.y;
2489 wi->c.pro=pro;
2490 wi->w=width;
2491 wi->background=this->background;
2492 row = gui_internal_widget_table_row_new(this,
2493 gravity_left
2494 | flags_fill
2495 | orientation_horizontal);
2496 gui_internal_widget_append(row,wi);
2497 row->datai=data->dist;
2498 gui_internal_widget_prepend(wtable,row);
2499 free(data->label);
2500 }
2501
2502 fh_deleteheap(fh);
2503 free(items);
2504
2505 // Add an entry for more POI
2506 struct widget *wl,*wt;
2507 char buffer[32];
2508 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2509 if (it == maxitem) {
2510 param.p.pagenb++;
2511 snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (param.p.pagenb+1)*pagesize);
2512 } else {
2513 param.p.dist++;
2514 snprintf(buffer, sizeof(buffer), "Set search distance to %i km", 10*(param.p.dist+1));
2515 }
2516 wt=gui_internal_label_new(this, buffer);
2517 gui_internal_widget_append(wl, wt);
2518 wl->func=gui_internal_cmd_pois_more;
2519 wl->data=GUINT_TO_POINTER(param.i);
2520 wl->state |= STATE_SENSITIVE;
2521 wl->c = wm->c;
2522 row = gui_internal_widget_table_row_new(this,
2523 gravity_left
2524 | flags_fill
2525 | orientation_horizontal);
2526 row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
2527 gui_internal_widget_append(wtable,row);
2528 gui_internal_widget_append(row,wl);
2529 // Rendering now is needed to have table_data->bottomrow filled in.
2530 gui_internal_menu_render(this);
2531 td=wtable->data;
2532 if(td->bottom_row!=NULL)
2533 {
2534 while(((struct widget*)td->bottom_row->data)->datai<=prevdist
2535 && (td->next_button->state & STATE_SENSITIVE))
2536 {
2537 gui_internal_table_button_next(this, td->next_button, NULL);
2538 }
2539 }
2540 gui_internal_menu_render(this);
2541
2542 }
2543 #endif /* _MSC_VER */
2544
2545 static void
2546 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2547 {
2548 if (wm->item.type != type_none) {
2549 enum item_type type;
2550 if (wm->item.type < type_line)
2551 type=type_selected_point;
2552 else if (wm->item.type < type_area)
2553 type=type_selected_point;
2554 else
2555 type=type_selected_area;
2556 graphics_clear_selection(this->gra, NULL);
2557 graphics_add_selection(this->gra, &wm->item, type, NULL);
2558 }
2559 navit_set_center(this->nav, &wm->c, 1);
2560 gui_internal_prune_menu(this, NULL);
2561 }
2562
2563
2564 static void
2565 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2566 {
2567 struct widget *w,*wb;
2568 struct map_rect *mr;
2569 struct item *item;
2570 struct attr attr;
2571 char *text,*url;
2572 int i;
2573
2574 text=g_strdup_printf("Attribute %s",wm->name);
2575 wb=gui_internal_menu(this, text);
2576 g_free(text);
2577 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2578 gui_internal_widget_append(wb, w);
2579 mr=map_rect_new(wm->item.map, NULL);
2580 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2581 for (i = 0 ; i < wm->datai ; i++) {
2582 item_attr_get(item, attr_any, &attr);
2583 }
2584 if (item_attr_get(item, attr_any, &attr)) {
2585 url=NULL;
2586 switch (attr.type) {
2587 case attr_osm_nodeid:
2588 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
2589 break;
2590 case attr_osm_wayid:
2591 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
2592 break;
2593 case attr_osm_relationid:
2594 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
2595 break;
2596 default:
2597 break;
2598 }
2599 if (url) {
2600 gui_internal_widget_append(w,
2601 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2602 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2603 gui_internal_cmd_view_in_browser, NULL));
2604 wb->name=url;
2605 }
2606 }
2607 map_rect_destroy(mr);
2608 gui_internal_menu_render(this);
2609 }
2610
2611 static void
2612 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2613 {
2614 struct widget *w,*wb;
2615 struct map_rect *mr;
2616 struct item *item;
2617 struct attr attr;
2618 char *text;
2619 int count=0;
2620
2621 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2622 wb=gui_internal_menu(this, "Attributes");
2623 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2624 gui_internal_widget_append(wb, w);
2625 mr=map_rect_new(wm->item.map, NULL);
2626 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2627 dbg(0,"item=%p\n", item);
2628 if (item) {
2629 while(item_attr_get(item, attr_any, &attr)) {
2630 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2631 gui_internal_widget_append(w,
2632 wb=gui_internal_button_new_with_callback(this, text,
2633 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2634 gui_internal_cmd_view_attribute_details, NULL));
2635 wb->name=g_strdup(text);
2636 wb->item=wm->item;
2637 wb->datai=count++;
2638 g_free(text);
2639 }
2640 }
2641 map_rect_destroy(mr);
2642 gui_internal_menu_render(this);
2643 }
2644
2645 static void
2646 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2647 {
2648 struct map_rect *mr;
2649 struct item *item;
2650 struct attr attr;
2651 char *cmd=NULL;
2652
2653 if (!wm->name) {
2654 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2655 mr=map_rect_new(wm->item.map, NULL);
2656 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2657 dbg(0,"item=%p\n", item);
2658 if (item) {
2659 while(item_attr_get(item, attr_url_local, &attr)) {
2660 if (! cmd)
2661 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2662 }
2663 }
2664 map_rect_destroy(mr);
2665 } else {
2666 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2667 }
2668 if (cmd) {
2669 #ifdef HAVE_SYSTEM
2670 system(cmd);
2671 #else
2672 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2673 #endif
2674 g_free(cmd);
2675 }
2676 }
2677
2678 static void
2679 gui_internal_cmd_position_do(struct gui_priv *this, struct pcoord *pc_in, struct coord_geo *g_in, struct widget *wm, char *name, int flags)
2680 {
2681 struct widget *wb,*w,*wc,*wbc;
2682 struct coord_geo g;
2683 struct pcoord pc;
2684 struct coord c;
2685 char *coord;
2686
2687 if (pc_in) {
2688 pc=*pc_in;
2689 c.x=pc.x;
2690 c.y=pc.y;
2691 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2692 transform_to_geo(pc.pro, &c, &g);
2693 } else if (g_in) {
2694 struct attr attr;
2695 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
2696 return;
2697 g=*g_in;
2698 pc.pro=attr.u.projection;
2699 transform_from_geo(pc.pro, &g, &c);
2700 pc.x=c.x;
2701 pc.y=c.y;
2702 } else
2703 return;
2704
2705 wb=gui_internal_menu(this, name);
2706 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2707 gui_internal_widget_append(wb, w);
2708 coord=coordinates(&pc, ' ');
2709 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2710 g_free(coord);
2711 if ((flags & 1) && wm) {
2712 gui_internal_widget_append(w,
2713 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2714 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2715 gui_internal_search_street_in_town, wm));
2716 wc->item=wm->item;
2717 wc->selection_id=wm->selection_id;
2718 }
2719 if ((flags & 2) && wm) {
2720 gui_internal_widget_append(w,
2721 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2722 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2723 gui_internal_search_house_number_in_street, wm));
2724 wc->item=wm->item;
2725 wc->selection_id=wm->selection_id;
2726 }
2727 if ((flags & 4) && wm) {
2728 struct map_rect *mr;
2729 struct item *item;
2730 struct attr attr;
2731 mr=map_rect_new(wm->item.map, NULL);
2732 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2733 if (item) {
2734 if (item_attr_get(item, attr_description, &attr))
2735 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2736 if (item_attr_get(item, attr_url_local, &attr)) {
2737 gui_internal_widget_append(w,
2738 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2739 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2740 gui_internal_cmd_view_in_browser, NULL));
2741 wb->item=wm->item;
2742 }
2743 gui_internal_widget_append(w,
2744 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2745 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2746 gui_internal_cmd_view_attributes, NULL));
2747 wb->item=wm->item;
2748 }
2749 map_rect_destroy(mr);
2750 }
2751 if (flags & 8) {
2752 gui_internal_widget_append(w,
2753 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
2754 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2755 gui_internal_cmd_set_destination, g_strdup(name)));
2756 wbc->data_free=g_free_func;
2757 wbc->c=pc;
2758 }
2759 if (flags & 16) {
2760 gui_internal_widget_append(w,
2761 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
2762 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2763 gui_internal_cmd_set_position, wm));
2764 wbc->c=pc;
2765 }
2766 if (flags & 32) {
2767 gui_internal_widget_append(w,
2768 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2769 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2770 gui_internal_cmd_add_bookmark2, g_strdup(name)));
2771 wbc->data_free=g_free_func;
2772 wbc->c=pc;
2773 }
2774 #ifndef _MSC_VER
2775 //POIs are not operational under MSVC yet
2776 if (flags & 64) {
2777 gui_internal_widget_append(w,
2778 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2779 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2780 gui_internal_cmd_pois, NULL));
2781 wbc->c=pc;
2782 }
2783 #endif /* _MSC_VER */
2784 #if 0
2785 gui_internal_widget_append(w,
2786 gui_internal_button_new(this, "Add to tour",
2787 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2788 #endif
2789 if (flags & 128) {
2790 gui_internal_widget_append(w,
2791 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
2792 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2793 gui_internal_cmd_view_on_map, NULL));
2794 wbc->c=pc;
2795 if ((flags & 4) && wm)
2796 wbc->item=wm->item;
2797 else
2798 wbc->item.type=type_none;
2799 }
2800 if (flags & 256) {
2801 int dist=10;
2802 struct mapset *ms;
2803 struct mapset_handle *h;
2804 struct map_rect *mr;
2805 struct map *m;
2806 struct item *item;
2807 struct street_data *data;
2808 struct map_selection sel;
2809 struct transformation *trans;
2810 enum projection pro;
2811 struct attr attr;
2812 char *label,*text;
2813
2814 trans=navit_get_trans(this->nav);
2815 pro=transform_get_projection(trans);
2816 transform_from_geo(pro, &g, &c);
2817 ms=navit_get_mapset(this->nav);
2818 sel.next=NULL;
2819 sel.u.c_rect.lu.x=c.x-dist;
2820 sel.u.c_rect.lu.y=c.y+dist;
2821 sel.u.c_rect.rl.x=c.x+dist;
2822 sel.u.c_rect.rl.y=c.y-dist;
2823 sel.order=18;
2824 sel.range=item_range_all;
2825 h=mapset_open(ms);
2826 while ((m=mapset_next(h,1))) {
2827 mr=map_rect_new(m, &sel);
2828 if (! mr)
2829 continue;
2830 while ((item=map_rect_get_item(mr))) {
2831 data=street_get_data(item);
2832 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2833 if (item_attr_get(item, attr_label, &attr)) {
2834 label=map_convert_string(m, attr.u.str);
2835 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2836 map_convert_free(label);
2837 } else
2838 text=g_strdup_printf("%s", item_to_name(item->type));
2839 gui_internal_widget_append(w,
2840 wc=gui_internal_button_new_with_callback(this, text,
2841 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2842 gui_internal_cmd_position, (void *)2));
2843 wc->c.x=data->c[0].x;
2844 wc->c.y=data->c[0].y;
2845 wc->c.pro=pro;
2846 wc->name=g_strdup(text);
2847 wc->item=*item;
2848 g_free(text);
2849 }
2850 street_data_free(data);
2851 }
2852 map_rect_destroy(mr);
2853 }
2854 mapset_close(h);
2855 }
2856 if (flags & 512) {
2857 gui_internal_widget_append(w,
2858 wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
2859 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2860 gui_internal_cmd_cut_bookmark, NULL));
2861 wbc->text=g_strdup(wm->text);
2862 gui_internal_widget_append(w,
2863 wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
2864 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2865 gui_internal_cmd_copy_bookmark, NULL));
2866 wbc->text=g_strdup(wm->text);
2867 gui_internal_widget_append(w,
2868 wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
2869 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2870 gui_internal_cmd_rename_bookmark, NULL));
2871 wbc->text=g_strdup(wm->text);
2872 gui_internal_widget_append(w,
2873 wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
2874 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2875 gui_internal_cmd_paste_bookmark, NULL));
2876 gui_internal_widget_append(w,
2877 wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
2878 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2879 gui_internal_cmd_delete_bookmark, NULL));
2880 wbc->text=g_strdup(wm->text);
2881 }
2882 gui_internal_menu_render(this);
2883 }
2884
2885
2886 /* wm->data: 0 Nothing special
2887 1 Map Point
2888 2 Item
2889 3 Town
2890 4 County
2891 5 Street
2892 6 House number
2893 7 Bookmark
2894 */
2895
2896 static void
2897 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2898 {
2899 int flags;
2900 switch ((long) wm->data) {
2901 case 0:
2902 flags=8|16|32|64|128|256;
2903 break;
2904 case 1:
2905 flags=8|16|32|64|256;
2906 break;
2907 case 2:
2908 flags=4|8|16|32|64|128;
2909 break;
2910 case 3:
2911 flags=1|8|16|32|64|128;
2912 flags &= this->flags_town;
2913 break;
2914 case 4:
2915 gui_internal_search_town_in_country(this, wm);
2916 return;
2917 case 5:
2918 flags=2|8|16|32|64|128;
2919 flags &= this->flags_street;
2920 break;
2921 case 6:
2922 flags=8|16|32|64|128;
2923 flags &= this->flags_house_number;
2924 break;
2925 case 7:
2926 flags=8|16|64|128|512;
2927 break;
2928 default:
2929 return;
2930 }
2931 switch (flags) {
2932 case 2:
2933 gui_internal_search_house_number_in_street(this, wm, NULL);
2934 return;
2935 case 8:
2936 gui_internal_cmd_set_destination(this, wm, NULL);
2937 return;
2938 }
2939 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
2940 }
2941
2942 static void
2943 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2944 {
2945 char *name=_("Position");
2946 int flags=-1;
2947
2948 dbg(1,"enter\n");
2949 if (!in || !in[0])
2950 return;
2951 if (!ATTR_IS_COORD_GEO(in[0]->type))
2952 return;
2953 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
2954 name=in[1]->u.str;
2955 if (in[2] && ATTR_IS_INT(in[2]->type))
2956 flags=in[2]->u.num;
2957 }
2958 dbg(1,"flags=0x%x\n",flags);
2959 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
2960 }
2961
2962 /**
2963 * The "Bookmarks" section of the OSD
2964 *
2965 */
2966
2967 static void
2968 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2969 {
2970 struct attr attr,mattr;
2971 struct item *item;
2972 char *label_full,*prefix=0;
2973 int plen=0,hassub,found=0;
2974 struct widget *wb,*w,*wbm;
2975 struct coord c;
2976 struct widget *tbl, *row;
2977
2978 if (data)
2979 prefix=g_strdup(data);
2980 else {
2981 if (wm && wm->prefix)
2982 prefix=g_strdup(wm->prefix);
2983 }
2984 if ( prefix )
2985 plen=strlen(prefix);
2986
2987 gui_internal_prune_menu_count(this, 1, 0);
2988 wb=gui_internal_menu(this, _("Bookmarks"));
2989 wb->background=this->background;
2990 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2991 w->spy=this->spacing*3;
2992 gui_internal_widget_append(wb, w);
2993
2994 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
2995 if (!plen) {
2996 bookmarks_move_root(mattr.u.bookmarks);
2997 } else {
2998 if (!strcmp(prefix,"..")) {
2999 bookmarks_move_up(mattr.u.bookmarks);
3000 g_free(prefix);
3001 prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
3002 if (prefix) {
3003 plen=strlen(prefix);
3004 } else {
3005 plen=0;
3006 }
3007 } else {
3008 bookmarks_move_down(mattr.u.bookmarks,prefix);
3009 }
3010
3011 // "Back" button, when inside a bookmark folder
3012
3013 if (plen) {
3014 wbm=gui_internal_button_new_with_callback(this, "..",
3015 image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3016 gui_internal_cmd_bookmarks, NULL);
3017 wbm->prefix=g_strdup("..");
3018 gui_internal_widget_append(w, wbm);
3019 }
3020 }
3021
3022 // Adds the Bookmark folders
3023 wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
3024 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3025 gui_internal_cmd_add_bookmark_folder2, NULL);
3026 gui_internal_widget_append(w, wbm);
3027
3028 // Pastes the Bookmark
3029 wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
3030 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3031 gui_internal_cmd_paste_bookmark, NULL);
3032 gui_internal_widget_append(w, wbm);
3033
3034 bookmarks_item_rewind(mattr.u.bookmarks);
3035
3036 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3037 gui_internal_widget_append(w,tbl);
3038
3039 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
3040 if (!item_attr_get(item, attr_label, &attr)) continue;
3041 label_full=attr.u.str;
3042 dbg(0,"full_labled: %s\n",label_full);
3043
3044 // hassub == 1 if the item type is a sub-folder
3045 if (item->type == type_bookmark_folder) {
3046 hassub=1;
3047 } else {
3048 hassub=0;
3049 }
3050
3051 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
3052 gui_internal_widget_append(tbl, row);
3053 wbm=gui_internal_button_new_with_callback(this, label_full,
3054 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
3055 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
3056
3057 gui_internal_widget_append(row,wbm);
3058 if (item_coord_get(item, &c, 1)) {
3059 wbm->c.x=c.x;
3060 wbm->c.y=c.y;
3061 wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
3062 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
3063 wbm->text=g_strdup(label_full);
3064 if (!hassub) {
3065 wbm->data=(void*)7;//Mark us as a bookmark
3066 }
3067 wbm->prefix=g_strdup(label_full);
3068 } else {
3069 gui_internal_widget_destroy(this, row);
3070 }
3071 }
3072 }
3073 if (plen) {
3074 g_free(prefix);
3075 }
3076 if (found)
3077 gui_internal_check_exit(this);
3078 else
3079 gui_internal_menu_render(this);
3080 }
3081
3082 static void
3083 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3084 {
3085 char *str=NULL;
3086 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
3087 str=in[0]->u.str;
3088 }
3089 gui_internal_cmd_bookmarks(this, NULL, str);
3090 }
3091
3092 static void
3093 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy);
3094
3095 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
3096 {
3097 struct widget *wi,*menu,*search_list;
3098 int len=0;
3099 char *text=NULL;
3100
3101 menu=g_list_last(this->root.children)->data;
3102 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
3103 if (wi) {
3104 /* select first item of the searchlist */
3105 if (*key == NAVIT_KEY_RETURN && (search_list=gui_internal_menu_data(this)->search_list)) {
3106 GList *l=search_list->children;
3107 if (l && l->data)
3108 gui_internal_highlight_do(this, l->data);
3109 return;
3110 } else if (*key == NAVIT_KEY_BACKSPACE) {
3111 dbg(0,"backspace\n");
3112 if (wi->text && wi->text[0]) {
3113 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
3114 wi->text[len]=' ';
3115 text=g_strdup_printf("%s ", wi->text);
3116 }
3117 } else {
3118 if (wi->state & STATE_CLEAR) {
3119 dbg(0,"wi->state=0x%x\n", wi->state);
3120 g_free(wi->text);
3121 wi->text=NULL;
3122 wi->state &= ~STATE_CLEAR;
3123 dbg(0,"wi->state=0x%x\n", wi->state);
3124 }
3125 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
3126 }
3127 g_free(wi->text);
3128 wi->text=text;
3129 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
3130 gui_internal_widget_render(this, wi);
3131 wi->text[len]='\0';
3132 }
3133 if (wi->func) {
3134 wi->reason=2;
3135 wi->func(this, wi, wi->data);
3136 }
3137 gui_internal_widget_render(this, wi);
3138 }
3139 }
3140
3141
3142 static void
3143 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
3144 {
3145 struct menu_data *md=gui_internal_menu_data(this);
3146 gui_internal_keypress_do(this, (char *) wm->data);
3147 // Switch to lowercase after the first key is pressed
3148 if (md->keyboard_mode == 2) // Latin
3149 gui_internal_keyboard_do(this, md->keyboard, 10);
3150 if (md->keyboard_mode == 26) // Umlaut
3151 gui_internal_keyboard_do(this, md->keyboard, 34);
3152 if ((md->keyboard_mode & ~7) == 40) // Russian/Ukrainian/Belorussian
3153 gui_internal_keyboard_do(this, md->keyboard, 48);
3154 }
3155
3156 static void
3157 gui_internal_search_idle_end(struct gui_priv *this)
3158 {
3159 if (this->idle) {
3160 event_remove_idle(this->idle);
3161 this->idle=NULL;
3162 }
3163 if (this->idle_cb) {
3164 callback_destroy(this->idle_cb);
3165 this->idle_cb=NULL;
3166 }
3167 }
3168
3169 static char *
3170 postal_str(struct search_list_result *res, int level)
3171 {
3172 char *ret=NULL;
3173 if (res->town->common.postal)
3174 ret=res->town->common.postal;
3175 if (res->town->common.postal_mask)
3176 ret=res->town->common.postal_mask;
3177 if (level == 1)
3178 return ret;
3179 if (res->street->common.postal)
3180 ret=res->street->common.postal;
3181 if (res->street->common.postal_mask)
3182 ret=res->street->common.postal_mask;
3183 if (level == 2)
3184 return ret;
3185 if (res->house_number->common.postal)
3186 ret=res->house_number->common.postal;
3187 if (res->house_number->common.postal_mask)
3188 ret=res->house_number->common.postal_mask;
3189 return ret;
3190 }
3191
3192 static char *
3193 district_str(struct search_list_result *res, int level)
3194 {
3195 char *ret=NULL;
3196 if (res->town->common.district_name)
3197 ret=res->town->common.district_name;
3198 if (level == 1)
3199 return ret;
3200 if (res->street->common.district_name)
3201 ret=res->street->common.district_name;
3202 if (level == 2)
3203 return ret;
3204 if (res->house_number->common.district_name)
3205 ret=res->house_number->common.district_name;
3206 return ret;
3207 }
3208
3209 static char *
3210 town_str(struct search_list_result *res, int level, int flags)
3211 {
3212 char *town=res->town->common.town_name;
3213 char *district=district_str(res, level);
3214 char *postal=postal_str(res, level);
3215 char *postal_sep=" ";
3216 char *district_begin=" (";
3217 char *district_end=")";
3218 char *county_sep = ", Co. ";
3219 char *county = res->town->common.county_name;
3220 if (!postal)
3221 postal_sep=postal="";
3222 if (!district || (flags & 1))
3223 district_begin=district_end=district="";
3224 if (!county)
3225 county_sep=county="";
3226
3227 return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
3228 }
3229
3230 static void
3231 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3232 {
3233 char *text=NULL,*text2=NULL,*name=NULL;
3234 struct search_list_result *res;
3235 struct widget *wc;
3236 struct item *item=NULL;
3237 GList *l;
3238 static char possible_keys[256]="";
3239
3240 res=search_list_get_result(this->sl);
3241 if (res) {
3242 gchar* trunk_name = NULL;
3243
3244 struct widget *menu=g_list_last(this->root.children)->data;
3245 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
3246
3247 if (wi) {
3248 if (! strcmp(wm_name,"Town"))
3249 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
3250 if (! strcmp(wm_name,"Street"))
3251 {
3252 name=res->street->name;
3253 if (name)
3254 trunk_name = g_strrstr(name, wi->text);
3255 else
3256 trunk_name = NULL;
3257 }
3258
3259 if (trunk_name) {
3260 char next_char = trunk_name[strlen(wi->text)];
3261 int i;
3262 int len = strlen(possible_keys);
3263 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
3264 if (i==len || !len) {
3265 possible_keys[len]=trunk_name[strlen(wi->text)];
3266 possible_keys[len+1]='\0';
3267 }
3268 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
3269 }
3270 } else {
3271 dbg(0, "Unable to find widget");
3272 }
3273 }
3274
3275 if (! res) {
3276 struct menu_data *md;
3277 gui_internal_search_idle_end(this);
3278
3279 md=gui_internal_menu_data(this);
3280 if (md && md->keyboard && !(this->flags & 2048)) {
3281 GList *lk=md->keyboard->children;
3282 graphics_draw_mode(this->gra, draw_mode_begin);
3283 while (lk) {
3284 struct widget *child=lk->data;
3285 GList *lk2=child->children;
3286 while (lk2) {
3287 struct widget *child_=lk2->data;
3288 lk2=g_list_next(lk2);
3289 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
3290 if (strlen(possible_keys) == 0)
3291 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3292 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
3293 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3294 } else {
3295 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
3296 }
3297 gui_internal_widget_render(this,child_);
3298 }
3299 }
3300 lk=g_list_next(lk);
3301 }
3302 gui_internal_widget_render(this,md->keyboard);
3303 graphics_draw_mode(this->gra, draw_mode_end);
3304 }
3305
3306 possible_keys[0]='\0';
3307 return;
3308 }
3309
3310 if (! strcmp(wm_name,"Country")) {
3311 name=res->country->name;
3312 item=&res->country->common.item;
3313 text=g_strdup_printf("%s", res->country->name);
3314 }
3315 if (! strcmp(wm_name,"Town")) {
3316 item=&res->town->common.item;
3317 name=res->town->common.town_name;
3318 text=town_str(res, 1, 0);
3319 }
3320 if (! strcmp(wm_name,"Street")) {
3321 name=res->street->name;
3322 item=&res->street->common.item;
3323 text=g_strdup(res->street->name);
3324 text2=town_str(res, 2, 1);
3325 }
3326 if (! strcmp(wm_name,"House number")) {
3327 name=res->house_number->house_number;
3328 text=g_strdup_printf("%s %s", res->street->name, name);
3329 text2=town_str(res, 3, 0);
3330 }
3331 dbg(1,"res->country->flag=%s\n", res->country->flag);
3332 if (!text2) {
3333 gui_internal_widget_append(search_list,
3334 wc=gui_internal_button_new_with_callback(this, text,
3335 image_new_xs(this, res->country->flag),
3336 gravity_left_center|orientation_horizontal|flags_fill,
3337 gui_internal_cmd_position, param));
3338 } else {
3339 struct widget *wb;
3340 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3341 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
3342 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
3343 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
3344 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
3345 gui_internal_widget_append(wc, wb);
3346 wc->func=gui_internal_cmd_position;
3347 wc->data=param;
3348 wc->state |= STATE_SENSITIVE;
3349 wc->speech=g_strdup(text);
3350 gui_internal_widget_append(search_list, wc);
3351 }
3352 wc->name=g_strdup(name);
3353 if (res->c)
3354 wc->c=*res->c;
3355 wc->selection_id=res->id;
3356 if (item)
3357 wc->item=*item;
3358 gui_internal_widget_pack(this, search_list);
3359 l=g_list_last(this->root.children);
3360 graphics_draw_mode(this->gra, draw_mode_begin);
3361 gui_internal_widget_render(this, l->data);
3362 graphics_draw_mode(this->gra, draw_mode_end);
3363 g_free(text);
3364 g_free(text2);
3365 }
3366
3367 static void
3368 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3369 {
3370 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
3371 this->idle=event_add_idle(50,this->idle_cb);
3372 callback_call_0(this->idle_cb);
3373 }
3374
3375
3376 /**
3377 *
3378 * @param wm The widget that generated the event for the search changed,
3379 * if this was generated by a key on the virtual keyboard then
3380 * wm is the key button widget.
3381 */
3382 static void
3383 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
3384 {
3385 GList *l;
3386 struct widget *search_list=gui_internal_menu_data(this)->search_list;
3387 void *param=(void *)3;
3388 int minlen=1;
3389 gui_internal_widget_children_destroy(this, search_list);
3390
3391 if (! strcmp(wm->name,"Country"))
3392 param=(void *)4;
3393 if (! strcmp(wm->name,"Street"))
3394 param=(void *)5;
3395 if (! strcmp(wm->name,"House number"))
3396 param=(void *)6;
3397 dbg(0,"%s now '%s'\n", wm->name, wm->text);
3398
3399 gui_internal_search_idle_end(this);
3400 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
3401 struct attr search_attr;
3402
3403 dbg(0,"process\n");
3404 if (! strcmp(wm->name,"Country"))
3405 search_attr.type=attr_country_all;
3406 if (! strcmp(wm->name,"Town"))
3407 search_attr.type=attr_town_or_district_name;
3408 if (! strcmp(wm->name,"Street"))
3409 search_attr.type=attr_street_name;
3410 if (! strcmp(wm->name,"House number"))
3411 search_attr.type=attr_house_number;
3412 search_attr.u.str=wm->text;
3413 search_list_search(this->sl, &search_attr, 1);
3414 gui_internal_search_idle_start(this, wm->name, search_list, param);
3415 }
3416 l=g_list_last(this->root.children);
3417 gui_internal_widget_render(this, l->data);
3418 }
3419
3420 static struct widget *
3421 gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, int font, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w, int h)
3422 {
3423 struct widget *wk;
3424 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
3425 NULL, gravity_center|orientation_vertical, func, data));
3426 wk->data_free=data_free;
3427 wk->background=this->background;
3428 wk->bl=0;
3429 wk->br=0;
3430 wk->bt=0;
3431 wk->bb=0;
3432 wk->w=w;
3433 wk->h=h;
3434 return wk;
3435 }
3436
3437 static struct widget *
3438 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
3439 {
3440 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
3441 }
3442
3443 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
3444
3445
3446 // A list of availiable keyboard modes.
3447 struct gui_internal_keyb_mode {
3448 char title[16]; // Label to be displayed on keys that switch to it
3449 int font; // Font size of label
3450 int case_mode; // Mode to switch to when case CHANGE() key is pressed.
3451 int umlaut_mode; // Mode to switch to when UMLAUT() key is pressed.
3452 } gui_internal_keyb_modes[]= {
3453 /* 0*/ {"ABC", 2, 8, 24},
3454 /* 8*/ {"abc", 2, 0, 32},
3455 /*16*/ {"123", 2, 0, 24},
3456 /*24*/ {"ÄÖÜ", 2, 40, 0},
3457 /*32*/ {"äöü", 2, 32, 8},
3458 /*40*/ {"АБВ", 2, 48, 0},
3459 /*48*/ {"абв", 2, 40, 8}
3460 };
3461
3462
3463 // Some macros that make the keyboard layout easier to visualise in
3464 // the source code. The macros are #undef'd after this function.
3465 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
3466 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
3467 #define MODE(x) gui_internal_keyboard_key_data(this, wkbd, \
3468 gui_internal_keyb_modes[(x)/8].title, \
3469 gui_internal_keyb_modes[(x)/8].font, \
3470 gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h) \
3471 -> datai=(mode&7)+((x)&~7)
3472 #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode)
3473 #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode)
3474 static struct widget *
3475 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
3476 {
3477 struct widget *wkbd,*wk;
3478 struct menu_data *md=gui_internal_menu_data(this);
3479 int i, max_w=this->root.w, max_h=this->root.h;
3480 int render=0;
3481 char *space="_";
3482 char *backspace="←";
3483 char *hide="▼";
3484 char *unhide="▲";
3485
3486 if (wkbdb) {
3487 this->current.x=-1;
3488 this->current.y=-1;
3489 gui_internal_highlight(this);
3490 if (md->keyboard_mode >= 1024)
3491 render=2;
3492 else
3493 render=1;
3494 gui_internal_widget_children_destroy(this, wkbdb);
3495 } else
3496 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
3497 md->keyboard=wkbdb;
3498 md->keyboard_mode=mode;
3499 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
3500 wkbd->background=this->background;
3501 wkbd->cols=8;
3502 wkbd->spx=0;
3503 wkbd->spy=0;
3504 max_w=max_w/8;
3505 max_h=max_h/8; // Allows 3 results in the list when searching for Towns
3506 wkbd->p.y=max_h*2;
3507 if(mode>=40&&mode<56) { // Russian/Ukrainian/Belarussian layout needs more space...
3508 max_h=max_h*4/5;
3509 max_w=max_w*8/9;
3510 wkbd->cols=9;
3511 }
3512
3513 if (mode >= 0 && mode < 8) {
3514 for (i = 0 ; i < 26 ; i++) {
3515 char text[]={'A'+i,'\0'};
3516 KEY(text);
3517 }
3518 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3519 if (mode == 0) {
3520 KEY("-");
3521 KEY("'");
3522 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3523 wk->datai=mode+1024;
3524 } else {
3525 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3526 wk->datai=mode+1024;
3527 SWCASE();
3528 MODE(16);
3529
3530 }
3531 UMLAUT();
3532 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3533 }
3534 if (mode >= 8 && mode < 16) {
3535 for (i = 0 ; i < 26 ; i++) {
3536 char text[]={'a'+i,'\0'};
3537 KEY(text);
3538 }
3539 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3540 if (mode == 8) {
3541 KEY("-");
3542 KEY("'");
3543 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3544 wk->datai=mode+1024;
3545 } else {
3546 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3547 wk->datai=mode+1024;
3548 SWCASE();
3549
3550 MODE(16);
3551 }
3552 UMLAUT();
3553 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3554 }
3555 if (mode >= 16 && mode < 24) {
3556 for (i = 0 ; i < 10 ; i++) {
3557 char text[]={'0'+i,'\0'};
3558 KEY(text);
3559 }
3560 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
3561 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
3562
3563
3564
3565 if (mode == 16) {
3566 for (i = 0 ; i < 5 ; i++) SPACER();
3567 KEY("-");
3568 KEY("'");
3569 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3570 wk->datai=mode+1024;
3571 } else {
3572 for (i = 0 ; i < 3 ; i++) SPACER();
3573 MODE(40);
3574 MODE(48);
3575 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3576 wk->datai=mode+1024;
3577 MODE(0);
3578 MODE(8);
3579 }
3580 UMLAUT();
3581 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3582 }
3583 if (mode >= 24 && mode < 32) {
3584 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
3585 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
3586 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
3587 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
3588
3589 UMLAUT();
3590
3591 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3592 }
3593 if (mode >= 32 && mode < 40) {
3594 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
3595 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
3596 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
3597 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
3598
3599 UMLAUT();
3600
3601 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3602 }
3603 if (mode >= 40 && mode < 48) {
3604 KEY("А"); KEY("Б"); KEY("В"); KEY("Г"); KEY("Д"); KEY("Е"); KEY("Ж"); KEY("З"); KEY("И");
3605 KEY("Й"); KEY("К"); KEY("Л"); KEY("М"); KEY("Н"); KEY("О"); KEY("П"); KEY("Р"); KEY("С");
3606 KEY("Т"); KEY("У"); KEY("Ф"); KEY("Х"); KEY("Ц"); KEY("Ч"); KEY("Ш"); KEY("Щ"); KEY("Ъ");
3607 KEY("Ы"); KEY("Ь"); KEY("Э"); KEY("Ю"); KEY("Я"); KEY("Ё"); KEY("І"); KEY("Ї"); KEY("Ў");
3608 SPACER(); SPACER(); SPACER();
3609 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3610
3611 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3612 wk->datai=mode+1024;
3613
3614 SWCASE();
3615
3616 MODE(16);
3617
3618 SPACER();
3619
3620 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3621 }
3622 if (mode >= 48 && mode < 56) {
3623 KEY("а"); KEY("б"); KEY("в"); KEY("г"); KEY("д"); KEY("е"); KEY("ж"); KEY("з"); KEY("и");
3624 KEY("й"); KEY("к"); KEY("л"); KEY("м"); KEY("н"); KEY("о"); KEY("п"); KEY("р"); KEY("с");
3625 KEY("т"); KEY("у"); KEY("ф"); KEY("х"); KEY("ц"); KEY("ч"); KEY("ш"); KEY("щ"); KEY("ъ");
3626 KEY("ы"); KEY("ь"); KEY("э"); KEY("ю"); KEY("я"); KEY("ё"); KEY("і"); KEY("ї"); KEY("ў");
3627 SPACER(); SPACER(); SPACER();
3628 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3629
3630 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3631 wk->datai=mode+1024;
3632
3633 SWCASE();
3634
3635 MODE(16);
3636
3637 SPACER();
3638
3639 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3640 }
3641
3642
3643 if (mode >= 1024) {
3644 char *text=NULL;
3645 int font=0;
3646 struct widget *wkl;
3647 mode -= 1024;
3648 text=gui_internal_keyb_modes[mode/8].title;
3649 font=gui_internal_keyb_modes[mode/8].font;
3650 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
3651 wk->func=gui_internal_keyboard_change;
3652 wk->data=wkbdb;
3653 wk->background=this->background;
3654 wk->bl=0;
3655 wk->br=0;
3656 wk->bt=0;
3657 wk->bb=0;
3658 wk->w=max_w;
3659 wk->h=max_h;
3660 wk->datai=mode;
3661 wk->state |= STATE_SENSITIVE;
3662 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
3663 wkl->background=NULL;
3664 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
3665 wkl->background=NULL;
3666 gui_internal_widget_append(wkbd, wk);
3667 if (render)
3668 render=2;
3669 }
3670 gui_internal_widget_append(wkbdb, wkbd);
3671 if (render == 1) {
3672 gui_internal_widget_pack(this, wkbdb);
3673 gui_internal_widget_render(this, wkbdb);
3674 } else if (render == 2) {
3675 gui_internal_menu_reset_pack(this);
3676 gui_internal_menu_render(this);
3677 }
3678 return wkbdb;
3679 }
3680 #undef KEY
3681 #undef SPACER
3682 #undef SWCASE
3683 #undef UMLAUT
3684 #undef MODE
3685
3686 static struct widget *
3687 gui_internal_keyboard(struct gui_priv *this, int mode)
3688 {
3689 if (! this->keyboard)
3690 return NULL;
3691 return gui_internal_keyboard_do(this, NULL, mode);
3692 }
3693
3694 static void
3695 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
3696 {
3697 gui_internal_keyboard_do(this, key->data, key->datai);
3698 }
3699
3700 static void
3701 gui_internal_search_list_set_default_country(struct gui_priv *this)
3702 {
3703 struct attr search_attr, country_name, country_iso2, *country_attr;
3704 struct item *item;
3705 struct country_search *cs;
3706 struct tracking *tracking;
3707 struct search_list_result *res;
3708
3709 country_attr=country_default();
3710 tracking=navit_get_tracking(this->nav);
3711 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
3712 country_attr=&search_attr;
3713 if (country_attr) {
3714 cs=country_search_new(country_attr, 0);
3715 item=country_search_get_item(cs);
3716 if (item && item_attr_get(item, attr_country_name, &country_name)) {
3717 search_attr.type=attr_country_all;
3718 dbg(0,"country %s\n", country_name.u.str);
3719 search_attr.u.str=country_name.u.str;
3720 search_list_search(this->sl, &search_attr, 0);
3721 while((res=search_list_get_result(this->sl)));
3722 if(this->country_iso2) {
3723 g_free(this->country_iso2);
3724 this->country_iso2=NULL;
3725 }
3726 if (item_attr_get(item, attr_country_iso2, &country_iso2))
3727 this->country_iso2=g_strdup(country_iso2.u.str);
3728 }
3729 country_search_destroy(cs);
3730 } else {
3731 dbg(0,"warning: no default country found\n");
3732 if (this->country_iso2) {
3733 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
3734 search_attr.type=attr_country_iso2;
3735 search_attr.u.str=this->country_iso2;
3736 search_list_search(this->sl, &search_attr, 0);
3737 while((res=search_list_get_result(this->sl)));
3738 }
3739 }
3740 }
3741
3742 static void
3743 gui_internal_search_list_new(struct gui_priv *this)
3744 {
3745 struct mapset *ms=navit_get_mapset(this->nav);
3746 if (! this->sl) {
3747 this->sl=search_list_new(ms);
3748 gui_internal_search_list_set_default_country(this);
3749 }
3750 }
3751
3752 static void
3753 gui_internal_search_list_destroy(struct gui_priv *this)
3754 {
3755 if (this->sl) {
3756 search_list_destroy(this->sl);
3757 this->sl=NULL;
3758 }
3759 }
3760
3761
3762 static void
3763 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
3764 {
3765 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
3766 char *country;
3767 int keyboard_mode=2;
3768 gui_internal_search_list_new(this);
3769 wb=gui_internal_menu(this, what);
3770 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
3771 gui_internal_widget_append(wb, w);
3772 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3773 gui_internal_widget_append(w, wr);
3774 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3775 gui_internal_widget_append(wr, we);
3776 if (!strcmp(type,"Country")) {
3777 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
3778 wnext->func=gui_internal_search_town;
3779 } else if (!strcmp(type,"Town")) {
3780 if (this->country_iso2) {
3781 #if HAVE_API_ANDROID
3782 char country_iso2[strlen(this->country_iso2)+1];
3783 strtolower(country_iso2, this->country_iso2);
3784 country=g_strdup_printf("country_%s", country_iso2);
3785 #else
3786 country=g_strdup_printf("country_%s", this->country_iso2);
3787 #endif
3788 } else
3789 country=g_strdup("gui_select_country");
3790 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
3791 wb->state |= STATE_SENSITIVE;
3792 if (flags)
3793 wb->func = gui_internal_search_country;
3794 else
3795 wb->func = gui_internal_back;
3796 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
3797 wnext->func=gui_internal_search_street;
3798 g_free(country);
3799 } else if (!strcmp(type,"Street")) {
3800 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
3801 wb->state |= STATE_SENSITIVE;
3802 wb->func = gui_internal_back;
3803 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
3804 wnext->func=gui_internal_search_house_number;
3805 } else if (!strcmp(type,"House number")) {
3806 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
3807 wb->state |= STATE_SENSITIVE;
3808 wb->func = gui_internal_back;
3809 keyboard_mode=18;
3810 }
3811 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3812 if (wnext) {
3813 gui_internal_widget_append(we, wnext);
3814 wnext->state |= STATE_SENSITIVE;
3815 }
3816 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3817 gui_internal_widget_append(wr, wl);
3818 gui_internal_menu_data(this)->search_list=wl;
3819 wk->state |= STATE_EDIT|STATE_EDITABLE;
3820 wk->background=this->background;
3821 wk->flags |= flags_expand|flags_fill;
3822 wk->func = gui_internal_search_changed;
3823 wk->name=g_strdup(type);
3824 if (this->keyboard)
3825 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
3826 gui_internal_menu_render(this);
3827 }
3828
3829 static void
3830 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3831 {
3832 search_list_select(this->sl, attr_street_name, 0, 0);
3833 gui_internal_search(this,_("House number"),"House number",0);
3834 }
3835
3836 static void
3837 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3838 {
3839 dbg(0,"id %d\n", widget->selection_id);
3840 search_list_select(this->sl, attr_street_name, 0, 0);
3841 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3842 gui_internal_search(this,_("House number"),"House number",0);
3843 }
3844
3845 static void
3846 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3847 {
3848 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3849 gui_internal_search(this,_("Street"),"Street",0);
3850 }
3851
3852 static void
3853 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3854 {
3855 dbg(0,"id %d\n", widget->selection_id);
3856 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3857 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3858 gui_internal_search(this,_("Street"),"Street",0);
3859 }
3860
3861 static void
3862 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3863 {
3864 if (this->sl)
3865 search_list_select(this->sl, attr_country_all, 0, 0);
3866 g_free(this->country_iso2);
3867 this->country_iso2=NULL;
3868 gui_internal_search(this,_("Town"),"Town",0);
3869 }
3870
3871 static void
3872 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3873 {
3874 struct search_list_common *slc;
3875 dbg(0,"id %d\n", widget->selection_id);
3876 search_list_select(this->sl, attr_country_all, 0, 0);
3877 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3878 if (slc) {
3879 g_free(this->country_iso2);
3880 this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
3881 }
3882 gui_internal_search(this,widget->name,"Town",0);
3883 }
3884
3885 static void
3886 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3887 {
3888 gui_internal_prune_menu_count(this, 1, 0);
3889 gui_internal_search(this,_("Country"),"Country",0);
3890 }
3891
3892 static void
3893 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3894 {
3895 if (this->sl)
3896 search_list_select(this->sl, attr_country_all, 0, 0);
3897 gui_internal_search(this,_("Town"),"Town",1);
3898 }
3899
3900 static void
3901 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3902 {
3903 struct attr attr;
3904 struct widget *w,*wb,*wl;
3905 struct attr_iter *iter;
3906
3907
3908 wb=gui_internal_menu(this, _("Layout"));
3909 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3910 w->spy=this->spacing*3;
3911 gui_internal_widget_append(wb, w);
3912 iter=navit_attr_iter_new();
3913 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3914 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3915 &attr, NULL);
3916 gui_internal_widget_append(w, wl);
3917 }
3918 navit_attr_iter_destroy(iter);
3919 gui_internal_menu_render(this);
3920 }
3921
3922 static void
3923 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3924 {
3925 struct attr navit;
3926 gui_internal_prune_menu(this, NULL);
3927 navit.type=attr_navit;
3928 navit.u.navit=this->nav;
3929 navit_destroy(navit.u.navit);
3930 config_remove_attr(config, &navit);
3931 gui_internal_destroy(this);
3932 event_main_loop_quit();
3933 }
3934
3935 static void
3936 gui_internal_window_closed(struct gui_priv *this)
3937 {
3938 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3939 }
3940
3941 static void
3942 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3943 {
3944 navit_set_destination(this->nav, NULL, NULL, 0);
3945 }
3946
3947 static void
3948 gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data)
3949 {
3950 char *text=g_strdup_printf(_("Download %s"),wm->name);
3951 struct widget *w, *wb;
3952 struct map *map=data;
3953 double bllon,bllat,trlon,trlat;
3954
3955 wb=gui_internal_menu(this, text);
3956 g_free(text);
3957 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3958 w->spy=this->spacing*3;
3959 gui_internal_widget_append(wb, w);
3960 if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
3961 struct coord_geo g;
3962 struct map_selection sel;
3963 struct map_rect *mr;
3964 struct item *item;
3965
3966 sel.next=NULL;
3967 sel.order=255;
3968 g.lng=bllon;
3969 g.lat=trlat;
3970 transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
3971 g.lng=trlon;
3972 g.lat=bllat;
3973 transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
3974 sel.range.min=type_none;
3975 sel.range.max=type_last;
3976 mr=map_rect_new(map, &sel);
3977 while ((item=map_rect_get_item(mr))) {
3978 dbg(0,"item\n");
3979 }
3980 map_rect_destroy(mr);
3981 }
3982
3983 dbg(0,"bbox=%s\n",wm->prefix);
3984 gui_internal_menu_render(this);
3985 }
3986
3987 static void
3988 gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data)
3989 {
3990 struct attr on, off, download_enabled, download_disabled;
3991 struct widget *w,*wb,*wma;
3992 struct map *map=data;
3993 FILE *f;
3994 char *search,buffer[256];
3995 int found,sp_match=0;
3996
3997 dbg(1,"wm=%p prefix=%s\n",wm,wm->prefix);
3998
3999 search=wm->prefix;
4000 if (search) {
4001 found=0;
4002 while(search[sp_match] == ' ')
4003 sp_match++;
4004 sp_match++;
4005 } else {
4006 found=1;
4007 }
4008 on.type=off.type=attr_active;
4009 on.u.num=1;
4010 off.u.num=0;
4011 wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
4012 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4013 w->spy=this->spacing*3;
4014 gui_internal_widget_append(wb, w);
4015 if (!search) {
4016 wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on, &off, 1);
4017 gui_internal_widget_append(w, wma);
4018 }
4019
4020 download_enabled.type=download_disabled.type=attr_update;
4021 download_enabled.u.num=1;
4022 download_disabled.u.num=0;
4023 wma=gui_internal_button_map_attr_new(this
4024 , _("Download Enabled")
4025 , gravity_left_center|orientation_horizontal|flags_fill
4026 , map
4027 , &download_enabled
4028 , &download_disabled
4029 , 0);
4030 gui_internal_widget_append(w, wma);
4031
4032
4033 f=fopen("maps/areas.tsv","r");
4034 while (f && fgets(buffer, sizeof(buffer), f)) {
4035 char *nl,*description,*description_size,*bbox,*size=NULL;
4036 int sp=0;
4037 if ((nl=strchr(buffer,'\n')))
4038 *nl='\0';
4039 if ((nl=strchr(buffer,'\r')))
4040 *nl='\0';
4041 while(buffer[sp] == ' ')
4042 sp++;
4043 if ((bbox=strchr(buffer,'\t')))
4044 *bbox++='\0';
4045 if (bbox && (size=strchr(bbox,'\t')))
4046 *size++='\0';
4047 if (search && !strcmp(buffer, search)) {
4048 wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
4049 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
4050 wma->name=g_strdup(buffer+sp);
4051 wma->prefix=g_strdup(bbox);
4052 gui_internal_widget_append(w, wma);
4053 found=1;
4054 } else if (sp < sp_match)
4055 found=0;
4056 if (sp == sp_match && found && buffer[sp]) {
4057 description=g_strdup(buffer+sp);
4058 if (size)
4059 description_size=g_strdup_printf("%s (%s)",description,size);
4060 else
4061 description_size=g_strdup(description);
4062 wma=gui_internal_button_new_with_callback(this, description_size, NULL,
4063 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
4064 g_free(description_size);
4065 wma->prefix=g_strdup(buffer);
4066 wma->name=description;
4067 gui_internal_widget_append(w, wma);
4068 }
4069 }
4070
4071 gui_internal_menu_render(this);
4072 }
4073
4074 static void
4075 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4076 {
4077 struct attr attr, on, off, description, type, data, url, active;
4078 struct widget *w,*wb,*wma;
4079 char *label;
4080 struct attr_iter *iter;
4081
4082 wb=gui_internal_menu(this, _("Maps"));
4083 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4084 w->spy=this->spacing*3;
4085 gui_internal_widget_append(wb, w);
4086 iter=navit_attr_iter_new();
4087 on.type=off.type=attr_active;
4088 on.u.num=1;
4089 off.u.num=0;
4090 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
4091 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
4092 label=g_strdup(description.u.str);
4093 } else {
4094 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
4095 type.u.str="";
4096 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
4097 data.u.str="";
4098 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
4099 }
4100 if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
4101 if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
4102 active.u.num=1;
4103 wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
4104 gravity_left_center|orientation_horizontal|flags_fill,
4105 gui_internal_cmd_map_download, attr.u.map);
4106 } else {
4107 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
4108 attr.u.map, &on, &off, 1);
4109 }
4110 gui_internal_widget_append(w, wma);
4111 g_free(label);
4112 }
4113 navit_attr_iter_destroy(iter);
4114 gui_internal_menu_render(this);
4115
4116 }
4117 static void
4118 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
4119 {
4120 struct attr vehicle = {attr_vehicle,{wm->data}};
4121 navit_set_attr(this->nav, &vehicle);
4122 }
4123
4124 static void
4125 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
4126 {
4127 struct widget *w,*wb,*row;
4128 struct attr attr,sat_attr;
4129 struct vehicle *v=wm->data;
4130 char *str;
4131 int i;
4132 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
4133
4134 wb=gui_internal_menu(this, _("Show Satellite Status"));
4135 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
4136 gui_internal_menu_data(this)->redisplay_widget=wm;
4137 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4138 gui_internal_widget_append(wb, w);
4139 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
4140 row = gui_internal_widget_table_row_new(this,gravity_left_top);
4141 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
4142 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
4143 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
4144 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
4145 gui_internal_widget_append(w,row);
4146 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
4147 row = gui_internal_widget_table_row_new(this,gravity_left_top);
4148 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
4149 if (item_attr_get(attr.u.item, types[i], &sat_attr))
4150 str=g_strdup_printf("%ld", sat_attr.u.num);
4151 else
4152 str=g_strdup("");
4153 gui_internal_widget_append(row, gui_internal_label_new(this, str));
4154 g_free(str);
4155 }
4156 gui_internal_widget_append(w,row);
4157 }
4158 gui_internal_widget_append(wb, w);
4159 gui_internal_menu_render(this);
4160 }
4161
4162 static void
4163 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
4164 {
4165 struct widget *w,*wb;
4166 struct attr attr;
4167 struct vehicle *v=wm->data;
4168 wb=gui_internal_menu(this, _("Show NMEA Data"));
4169 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
4170 gui_internal_menu_data(this)->redisplay_widget=wm;
4171 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4172 gui_internal_widget_append(wb, w);
4173 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
4174 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
4175 gui_internal_menu_render(this);
4176 }
4177
4178 /**
4179 * A container to hold the selected vehicle and the desired profile in
4180 * one data item.
4181 */
4182 struct vehicle_and_profilename {
4183 struct vehicle *vehicle;
4184 char *profilename;
4185 };
4186
4187 /**
4188 * Figures out whether the given vehicle is the active vehicle.
4189 *
4190 * @return true if the vehicle is active, false otherwise.
4191 */
4192 static int
4193 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
4194 *vehicle)
4195 {
4196 struct attr active_vehicle;
4197
4198 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
4199 active_vehicle.u.vehicle=NULL;
4200
4201 return active_vehicle.u.vehicle == vehicle;
4202 }
4203
4204 static void
4205 save_vehicle_xml(struct vehicle *v)
4206 {
4207 struct attr attr;
4208 struct attr_iter *iter=vehicle_attr_iter_new();
4209 int childs=0;
4210 dbg(0,"enter\n");
4211 printf("<vehicle");
4212 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
4213 if (ATTR_IS_OBJECT(attr.type))
4214 childs=1;
4215 else
4216 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
4217 }
4218 if (childs) {
4219 printf(">\n");
4220 printf("</vehicle>\n");
4221 } else
4222 printf(" />\n");
4223 vehicle_attr_iter_destroy(iter);
4224 }
4225
4226
4227 /**
4228 * Reacts to a button press that changes a vehicle's active profile.
4229 *
4230 * @see gui_internal_add_vehicle_profile
4231 */
4232 static void
4233 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
4234 widget *wm, void *data)
4235 {
4236 struct vehicle_and_profilename *vapn = data;
4237 struct vehicle *v = vapn->vehicle;
4238 char *profilename = vapn->profilename;
4239 struct attr vehicle_name_attr;
4240 char *vehicle_name = NULL;
4241 struct attr profilename_attr;
4242
4243 // Get the vehicle name
4244 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
4245 vehicle_name = vehicle_name_attr.u.str;
4246
4247 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
4248 profilename);
4249
4250 // Change the profile name
4251 profilename_attr.type = attr_profilename;
4252 profilename_attr.u.str = profilename;
4253 if(!vehicle_set_attr(v, &profilename_attr)) {
4254 dbg(0, "Unable to set the vehicle's profile name\n");
4255 }
4256
4257 // Notify Navit that the routing should be re-done if this is the
4258 // active vehicle.
4259 if (gui_internal_is_active_vehicle(this, v)) {
4260 struct attr vehicle;
4261 vehicle.type=attr_vehicle;
4262 vehicle.u.vehicle=v;
4263 navit_set_attr(this->nav, &vehicle);
4264 }
4265 save_vehicle_xml(v);
4266 }
4267
4268 /**
4269 * Adds the vehicle profile to the GUI, allowing the user to pick a
4270 * profile for the currently selected vehicle.
4271 */
4272 static void
4273 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
4274 *parent, struct vehicle *v, struct vehicleprofile *profile)
4275 {
4276 // Just here to show up in the translation file, nice and close to
4277 // where the translations are actually used.
4278 struct attr profile_attr;
4279 struct attr *attr = NULL;
4280 char *name = NULL;
4281 char *active_profile = NULL;
4282 char *label = NULL;
4283 int active;
4284 struct vehicle_and_profilename *context = NULL;
4285
4286 #ifdef ONLY_FOR_TRANSLATION
4287 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
4288 #endif
4289
4290 // Figure out the profile name
4291 attr = attr_search(profile->attrs, NULL, attr_name);
4292 if (!attr) {
4293 dbg(0, "Adding vehicle profile failed. attr==NULL");
4294 return;
4295 }
4296 name = attr->u.str;
4297
4298 // Determine whether the profile is the active one
4299 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
4300 active_profile = profile_attr.u.str;
4301 active = active_profile != NULL && !strcmp(name, active_profile);
4302
4303 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
4304 active_profile, active);
4305
4306 // Build a translatable label.
4307 if(active) {
4308 label = g_strdup_printf(_("Current profile: %s"), _(name));
4309 } else {
4310 label = g_strdup_printf(_("Change profile to: %s"), _(name));
4311 }
4312
4313 // Create the context object (the vehicle and the desired profile)
4314 context = g_new0(struct vehicle_and_profilename, 1);
4315 context->vehicle = v;
4316 context->profilename = name;
4317
4318 // Add the button
4319 gui_internal_widget_append(parent,
4320 gui_internal_button_new_with_callback(
4321 this, label,
4322 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
4323 gravity_left_center|orientation_horizontal|flags_fill,
4324 gui_internal_cmd_set_active_profile, context));
4325
4326 free(label);
4327 }
4328
4329 static void
4330 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
4331 {
4332 struct widget *w,*wb;
4333 struct attr attr;
4334 struct vehicle *v=wm->data;
4335 struct vehicleprofile *profile = NULL;
4336 GList *profiles;
4337
4338 wb=gui_internal_menu(this, wm->text);
4339 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4340 gui_internal_widget_append(wb, w);
4341
4342 // Add the "Set as active" button if this isn't the active
4343 // vehicle.
4344 if (!gui_internal_is_active_vehicle(this, v)) {
4345 gui_internal_widget_append(w,
4346 gui_internal_button_new_with_callback(this, _("Set as active"),
4347 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4348 gui_internal_cmd_set_active_vehicle, wm->data));
4349 }
4350
4351 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
4352 gui_internal_widget_append(w,
4353 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
4354 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4355 gui_internal_cmd_show_satellite_status, wm->data));
4356 }
4357 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
4358 gui_internal_widget_append(w,
4359 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
4360 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4361 gui_internal_cmd_show_nmea_data, wm->data));
4362 }
4363
4364 // Add all the possible vehicle profiles to the menu
4365 profiles = navit_get_vehicleprofiles(this->nav);
4366 while(profiles) {
4367 profile = (struct vehicleprofile *)profiles->data;
4368 gui_internal_add_vehicle_profile(this, w, v, profile);
4369 profiles = g_list_next(profiles);
4370 }
4371
4372 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
4373 gui_internal_menu_render(this);
4374 }
4375
4376 static void
4377 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4378 {
4379 struct attr attr,vattr;
4380 struct widget *w,*wb,*wl;
4381 struct attr_iter *iter;
4382 struct attr active_vehicle;
4383
4384
4385 wb=gui_internal_menu(this, _("Vehicle"));
4386 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4387 w->spy=this->spacing*3;
4388 gui_internal_widget_append(wb, w);
4389 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
4390 active_vehicle.u.vehicle=NULL;
4391 iter=navit_attr_iter_new();
4392 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
4393 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
4394 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
4395 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
4396 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
4397 wl->text=g_strdup(vattr.u.str);
4398 gui_internal_widget_append(w, wl);
4399 }
4400 navit_attr_iter_destroy(iter);
4401 gui_internal_menu_render(this);
4402 }
4403
4404
4405 static void
4406 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4407 {
4408 struct widget *wb,*w;
4409 struct attr on,off;
4410 wb=gui_internal_menu(this, _("Rules"));
4411 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4412 w->spy=this->spacing*3;
4413 gui_internal_widget_append(wb, w);
4414 on.u.num=1;
4415 off.u.num=0;
4416 on.type=off.type=attr_tracking;
4417 gui_internal_widget_append(w,
4418 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
4419 &on, &off));
4420 on.u.num=0;
4421 off.u.num=-1;
4422 on.type=off.type=attr_orientation;
4423 gui_internal_widget_append(w,
4424 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
4425 &on, &off));
4426 on.u.num=1;
4427 off.u.num=0;
4428 on.type=off.type=attr_follow_cursor;
4429 gui_internal_widget_append(w,
4430 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
4431 &on, &off));
4432 gui_internal_menu_render(this);
4433 }
4434
4435 //##############################################################################################################
4436 //# Description:
4437 //# Comment:
4438 //# Authors: Martin Schaller (04/2008)
4439 //##############################################################################################################
4440 static void gui_internal_motion(void *data, struct point *p)
4441 {
4442
4443 struct gui_priv *this=data;
4444 if (!this->root.children) {
4445 navit_handle_motion(this->nav, p);
4446 return;
4447 }
4448 if (!this->pressed)
4449 return;
4450 this->current=*p;
4451 if(!this->motion_timeout_callback)
4452 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
4453 if(!this->motion_timeout_event)
4454 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
4455 }
4456
4457 static const char *
4458 find_attr(const char **names, const char **values, const char *name)
4459 {
4460 while (*names) {
4461 if (!g_strcasecmp(*names, name))
4462 return *values;
4463 names+=xml_attr_distance;
4464 values+=xml_attr_distance;
4465 }
4466 return NULL;
4467 }
4468
4469 static char *
4470 find_attr_dup(const char **names, const char **values, const char *name)
4471 {
4472 return g_strdup(find_attr(names, values, name));
4473 }
4474
4475 static void
4476 gui_internal_evaluate(struct gui_priv *this, const char *command)
4477 {
4478 if (command)
4479 command_evaluate(&this->self, command);
4480 }
4481
4482
4483 static void
4484 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
4485 {
4486 gui_internal_evaluate(this,w->command);
4487 }
4488
4489 static void
4490 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
4491 {
4492 GList *l;
4493 if (w->form == form && w->name) {
4494 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
4495 if (attr)
4496 gui_set_attr(this->self.u.gui, attr);
4497 attr_free(attr);
4498 }
4499 l=w->children;
4500 while (l) {
4501 w=l->data;
4502 gui_internal_html_submit_set(this, w, form);
4503 l=g_list_next(l);
4504 }
4505
4506 }
4507
4508 static void
4509 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
4510 {
4511 struct widget *menu;
4512 GList *l;
4513
4514 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
4515 l=g_list_last(this->root.children);
4516 menu=l->data;
4517 graphics_draw_mode(this->gra, draw_mode_begin);
4518 gui_internal_highlight_do(this, NULL);
4519 gui_internal_menu_render(this);
4520 graphics_draw_mode(this->gra, draw_mode_end);
4521 gui_internal_html_submit_set(this, menu, w->form);
4522 gui_internal_evaluate(this,w->form->onsubmit);
4523 }
4524
4525 static void
4526 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
4527 {
4528 if (replace)
4529 gui_internal_prune_menu_count(this, 1, 0);
4530 if (href && href[0] == '#') {
4531 dbg(1,"href=%s\n",href);
4532 g_free(this->href);
4533 this->href=g_strdup(href);
4534 gui_internal_html_menu(this, this->html_text, href+1);
4535 }
4536 }
4537
4538 static void
4539 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
4540 {
4541 gui_internal_html_load_href(this, w->command, 0);
4542 }
4543
4544 struct div_flags_map {
4545 char *attr;
4546 char *val;
4547 enum flags flags;
4548 } div_flags_map[] = {
4549 {"gravity","none",gravity_none},
4550 {"gravity","left",gravity_left},
4551 {"gravity","xcenter",gravity_xcenter},
4552 {"gravity","right",gravity_right},
4553 {"gravity","top",gravity_top},
4554 {"gravity","ycenter",gravity_ycenter},
4555 {"gravity","bottom",gravity_bottom},
4556 {"gravity","left_top",gravity_left_top},
4557 {"gravity","top_center",gravity_top_center},
4558 {"gravity","right_top",gravity_right_top},
4559 {"gravity","left_center",gravity_left_center},
4560 {"gravity","center",gravity_center},
4561 {"gravity","right_center",gravity_right_center},
4562 {"gravity","left_bottom",gravity_left_bottom},
4563 {"gravity","bottom_center",gravity_bottom_center},
4564 {"gravity","right_bottom",gravity_right_bottom},
4565 {"expand","1",flags_expand},
4566 {"fill","1",flags_fill},
4567 {"orientation","horizontal",orientation_horizontal},
4568 {"orientation","vertical",orientation_vertical},
4569 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
4570 };
4571
4572 static enum flags
4573 div_flag(const char **names, const char **values, char *name)
4574 {
4575 int i;
4576 enum flags ret=0;
4577 const char *value=find_attr(names, values, name);
4578 if (!value)
4579 return ret;
4580 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
4581 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
4582 ret|=div_flags_map[i].flags;
4583 }
4584 return ret;
4585 }
4586
4587 static enum flags
4588 div_flags(const char **names, const char **values)
4589 {
4590 enum flags flags;
4591 flags = div_flag(names, values, "gravity");
4592 flags |= div_flag(names, values, "orientation");
4593 flags |= div_flag(names, values, "expand");
4594 flags |= div_flag(names, values, "fill");
4595 return flags;
4596 }
4597
4598 static struct widget *
4599 html_image(struct gui_priv *this, const char **names, const char **values)
4600 {
4601 const char *src, *size;
4602 struct graphics_image *img=NULL;
4603
4604 src=find_attr(names, values, "src");
4605 if (!src)
4606 return NULL;
4607 size=find_attr(names, values, "size");
4608 if (!size)
4609 size="l";
4610 if (!strcmp(size,"l"))
4611 img=image_new_l(this, src);
4612 else if (!strcmp(size,"s"))
4613 img=image_new_s(this, src);
4614 else if (!strcmp(size,"xs"))
4615 img=image_new_xs(this, src);
4616 if (!img)
4617 return NULL;
4618 return gui_internal_image_new(this, img);
4619 }
4620
4621 static void
4622 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
4623 {
4624 struct gui_priv *this=data;
4625 int i;
4626 enum html_tag tag=html_tag_none;
4627 struct html *html=&this->html[this->html_depth];
4628 const char *cond, *type;
4629
4630 if (!g_strcasecmp(tag_name,"text"))
4631 return;
4632 html->command=NULL;
4633 html->name=NULL;
4634 html->href=NULL;
4635 html->skip=0;
4636 cond=find_attr(names, values, "cond");
4637
4638 if (cond && !this->html_skip) {
4639 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
4640 html->skip=1;
4641 }
4642
4643 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
4644 if (!g_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
4645 tag=html_tag_map[i].tag;
4646 break;
4647 }
4648 }
4649 html->tag=tag;
4650 if (!this->html_skip && !html->skip) {
4651 switch (tag) {
4652 case html_tag_a:
4653 html->name=find_attr_dup(names, values, "name");
4654 if (html->name) {
4655 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
4656 if (!html->skip)
4657 this->html_anchor_found=1;
4658 }
4659 html->command=find_attr_dup(names, values, "onclick");
4660 html->href=find_attr_dup(names, values, "href");
4661 html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
4662 break;
4663 case html_tag_img:
4664 html->command=find_attr_dup(names, values, "onclick");
4665 html->w=html_image(this, names, values);
4666 break;
4667 case html_tag_form:
4668 this->form=g_new0(struct form, 1);
4669 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
4670 break;
4671 case html_tag_input:
4672 type=find_attr_dup(names, values, "type");
4673 if (!type)
4674 break;
4675 if (!strcmp(type,"image")) {
4676 html->w=html_image(this, names, values);
4677 if (html->w) {
4678 html->w->state|=STATE_SENSITIVE;
4679 html->w->func=gui_internal_html_submit;
4680 }
4681 }
4682 if (!strcmp(type,"text") || !strcmp(type,"password")) {
4683 html->w=gui_internal_label_new(this, NULL);
4684 html->w->background=this->background;
4685 html->w->flags |= div_flags(names, values);
4686 html->w->state|=STATE_EDITABLE;
4687 if (!this->editable) {
4688 this->editable=html->w;
4689 html->w->state|=STATE_EDIT;
4690 }
4691 this->keyboard_required=1;
4692 if (!strcmp(type,"password"))
4693 html->w->flags2 |= 1;
4694 }
4695 if (html->w) {
4696 html->w->form=this->form;
4697 html->w->name=find_attr_dup(names, values, "name");
4698 }
4699 break;
4700 case html_tag_div:
4701 html->w=gui_internal_box_new(this, div_flags(names, values));
4702 html->container=this->html_container;
4703 this->html_container=html->w;
4704 break;
4705 default:
4706 break;
4707 }
4708 }
4709 this->html_skip+=html->skip;
4710 this->html_depth++;
4711 }
4712
4713 static void
4714 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
4715 {
4716 struct gui_priv *this=data;
4717 struct html *html;
4718 struct html *parent=NULL;
4719
4720 if (!g_strcasecmp(tag_name,"text"))
4721 return;
4722 this->html_depth--;
4723 html=&this->html[this->html_depth];
4724 if (this->html_depth > 0)
4725 parent=&this->html[this->html_depth-1];
4726
4727
4728 if (!this->html_skip) {
4729 if (html->command && html->w) {
4730 html->w->state |= STATE_SENSITIVE;
4731 html->w->command=html->command;
4732 html->w->func=gui_internal_html_command;
4733 html->command=NULL;
4734 }
4735 if (parent && (parent->href || parent->command) && html->w) {
4736 html->w->state |= STATE_SENSITIVE;
4737 if (parent->command) {
4738 html->w->command=g_strdup(parent->command);
4739 html->w->func=gui_internal_html_command;
4740 } else {
4741 html->w->command=g_strdup(parent->href);
4742 html->w->func=gui_internal_html_href;
4743 }
4744 }
4745 switch (html->tag) {
4746 case html_tag_div:
4747 this->html_container=html->container;
4748 case html_tag_img:
4749 case html_tag_input:
4750 gui_internal_widget_append(this->html_container, html->w);
4751 break;
4752 case html_tag_form:
4753 this->form=NULL;
4754 break;
4755 default:
4756 break;
4757 }
4758 }
4759 this->html_skip-=html->skip;
4760 g_free(html->command);
4761 g_free(html->name);
4762 g_free(html->href);
4763 g_free(html->refresh_cond);
4764 }
4765
4766 static void
4767 gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data)
4768 {
4769 if (gui_internal_menu_data(this) == menu_data) {
4770 char *href=g_strdup(menu_data->href);
4771 gui_internal_html_load_href(this, href, 1);
4772 g_free(href);
4773 }
4774 }
4775
4776 static void
4777 gui_internal_set_refresh_callback(struct gui_priv *this, char *cond)
4778 {
4779 dbg(0,"cond=%s\n",cond);
4780 if (cond) {
4781 enum attr_type type;
4782 struct object_func *func;
4783 struct menu_data *menu_data=gui_internal_menu_data(this);
4784 dbg(0,"navit=%p\n",this->nav);
4785 type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
4786 if (type == attr_none)
4787 return;
4788 func=object_func_lookup(menu_data->refresh_callback_obj.type);
4789 if (!func || !func->add_attr)
4790 return;
4791 menu_data->refresh_callback.type=attr_callback;
4792 menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,this,menu_data);
4793 func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
4794 }
4795 }
4796
4797 static void
4798 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
4799 {
4800 struct gui_priv *this=data;
4801 struct widget *w;
4802 int depth=this->html_depth-1;
4803 struct html *html=&this->html[depth];
4804 gchar *text_stripped;
4805
4806 if (this->html_skip)
4807 return;
4808 while (isspace(text[0])) {
4809 text++;
4810 len--;
4811 }
4812 while (len > 0 && isspace(text[len-1]))
4813 len--;
4814
4815 text_stripped = g_strndup(text, len);
4816 if (html->tag == html_tag_html && depth > 2) {
4817 if (this->html[depth-1].tag == html_tag_script) {
4818 html=&this->html[depth-2];
4819 }
4820 }
4821 switch (html->tag) {
4822 case html_tag_a:
4823 if (html->name && len) {
4824 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
4825 gui_internal_widget_append(gui_internal_menu(this, gettext(text_stripped)), this->html_container);
4826 gui_internal_menu_data(this)->href=g_strdup(this->href);
4827 gui_internal_set_refresh_callback(this, html->refresh_cond);
4828 this->html_container->spx=this->spacing*10;
4829 }
4830 break;
4831 case html_tag_h1:
4832 if (!this->html_container) {
4833 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
4834 gui_internal_widget_append(gui_internal_menu(this, gettext(text_stripped)), this->html_container);
4835 this->html_container->spx=this->spacing*10;
4836 }
4837 break;
4838 case html_tag_img:
4839 if (len) {
4840 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
4841 gui_internal_widget_append(w, html->w);
4842 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
4843 html->w=w;
4844 }
4845 break;
4846 case html_tag_div:
4847 if (len) {
4848 gui_internal_widget_append(html->w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
4849 }
4850 break;
4851 case html_tag_script:
4852 dbg(1,"execute %s\n",text_stripped);
4853 gui_internal_evaluate(this,text_stripped);
4854 break;
4855 default:
4856 break;
4857 }
4858 g_free(text_stripped);
4859 }
4860
4861 static void
4862 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
4863 {
4864 char *doc=g_strdup(document);
4865 graphics_draw_mode(this->gra, draw_mode_begin);
4866 this->html_container=NULL;
4867 this->html_depth=0;
4868 this->html_anchor=anchor;
4869 this->html_anchor_found=0;
4870 this->form=NULL;
4871 this->keyboard_required=0;
4872 this->editable=NULL;
4873 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
4874 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4875 g_free(doc);
4876 if (this->keyboard_required && this->keyboard) {
4877 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
4878 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
4879 }
4880 gui_internal_menu_render(this);
4881 graphics_draw_mode(this->gra, draw_mode_end);
4882 }
4883
4884
4885 static void
4886 gui_internal_enter(struct gui_priv *this, int ignore)
4887 {
4888 struct graphics *gra=this->gra;
4889 this->ignore_button=ignore;
4890 this->clickp_valid=this->vehicle_valid=0;
4891
4892 navit_block(this->nav, 1);
4893 graphics_overlay_disable(gra, 1);
4894 this->root.p.x=0;
4895 this->root.p.y=0;
4896 this->root.background=this->background;
4897 }
4898
4899 static void
4900 gui_internal_leave(struct gui_priv *this)
4901 {
4902 graphics_draw_mode(this->gra, draw_mode_end);
4903 }
4904
4905 static void
4906 gui_internal_enter_setup(struct gui_priv *this, struct point *p)
4907 {
4908 struct transformation *trans;
4909 struct coord c;
4910 struct coord_geo g;
4911 struct attr attr,attrp;
4912
4913 trans=navit_get_trans(this->nav);
4914 attr_free(this->click_coord_geo);
4915 this->click_coord_geo=NULL;
4916 attr_free(this->position_coord_geo);
4917 this->position_coord_geo=NULL;
4918 if (p) {
4919 transform_reverse(trans, p, &c);
4920 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
4921 this->clickp.pro=transform_get_projection(trans);
4922 this->clickp.x=c.x;
4923 this->clickp.y=c.y;
4924 transform_to_geo(this->clickp.pro, &c, &g);
4925 attr.u.coord_geo=&g;
4926 attr.type=attr_click_coord_geo;
4927 this->click_coord_geo=attr_dup(&attr);
4928 }
4929 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
4930 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
4931 this->position_coord_geo=attr_dup(&attrp);
4932 this->vehiclep.pro=transform_get_projection(trans);
4933 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
4934 this->vehiclep.x=c.x;
4935 this->vehiclep.y=c.y;
4936 this->vehicle_valid=1;
4937 }
4938 }
4939
4940 static void
4941 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore, char *href)
4942 {
4943 dbg(1,"enter\n");
4944 gui_internal_enter(this, ignore);
4945 gui_internal_enter_setup(this, p);
4946 // draw menu
4947 gui_internal_html_load_href(this, href?href:"#Main Menu", 0);
4948 }
4949
4950 static void
4951 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4952 {
4953 char *href=NULL;
4954 int replace=0;
4955 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
4956 href=in[0]->u.str;
4957 if (in[1] && ATTR_IS_INT(in[1]->type))
4958 replace=in[1]->u.num;
4959 }
4960 if (this->root.children) {
4961 if (!href)
4962 return;
4963 gui_internal_html_load_href(this, href, replace);
4964 return;
4965 }
4966 gui_internal_cmd_menu(this, NULL, 0, href);
4967 }
4968
4969
4970 static void
4971 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
4972 {
4973 if (widget->text && strlen(widget->text)) {
4974 if (this->vehicle_valid)
4975 navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
4976 else
4977 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
4978 }
4979 g_free(widget->text);
4980 widget->text=NULL;
4981 gui_internal_prune_menu(this, NULL);
4982 gui_internal_check_exit(this);
4983 }
4984
4985 static void
4986 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
4987 {
4988 gui_internal_cmd_log_do(this, widget->data);
4989 }
4990
4991 static void
4992 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
4993 {
4994 int len;
4995 if (wm->text) {
4996 len=strlen(wm->text);
4997 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
4998 wm->text[len-1]='\0';
4999 gui_internal_cmd_log_do(this, wm);
5000 }
5001 }
5002 }
5003
5004
5005 static void
5006 gui_internal_cmd_log(struct gui_priv *this)
5007 {
5008 struct widget *w,*wb,*wk,*wl,*we,*wnext;
5009 gui_internal_enter(this, 1);
5010 gui_internal_enter_setup(this, NULL);
5011 wb=gui_internal_menu(this, "Log Message");
5012 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5013 gui_internal_widget_append(wb, w);
5014 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
5015 gui_internal_widget_append(w, we);
5016 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
5017 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
5018 wk->background=this->background;
5019 wk->flags |= flags_expand|flags_fill;
5020 wk->func = gui_internal_cmd_log_changed;
5021 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
5022 wnext->state |= STATE_SENSITIVE;
5023 wnext->func = gui_internal_cmd_log_clicked;
5024 wnext->data=wk;
5025 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5026 gui_internal_widget_append(w, wl);
5027 if (this->keyboard)
5028 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
5029 gui_internal_menu_render(this);
5030 gui_internal_leave(this);
5031 }
5032
5033 static void
5034 gui_internal_check_exit(struct gui_priv *this)
5035 {
5036 struct graphics *gra=this->gra;
5037 if (! this->root.children) {
5038 gui_internal_search_idle_end(this);
5039 gui_internal_search_list_destroy(this);
5040 graphics_overlay_disable(gra, 0);
5041 if (!navit_block(this->nav, 0)) {
5042 if (this->redraw)
5043 navit_draw(this->nav);
5044 else
5045 navit_draw_displaylist(this->nav);
5046 }
5047 }
5048 }
5049
5050 static int
5051 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
5052 {
5053 switch (type) {
5054 case attr_active:
5055 attr->u.num=this->root.children != NULL;
5056 break;
5057 case attr_click_coord_geo:
5058 if (!this->click_coord_geo)
5059 return 0;
5060 *attr=*this->click_coord_geo;
5061 break;
5062 case attr_position_coord_geo:
5063 if (!this->position_coord_geo)
5064 return 0;
5065 *attr=*this->position_coord_geo;
5066 break;
5067 case attr_pitch:
5068 attr->u.num=this->pitch;
5069 break;
5070 default:
5071 return 0;
5072 }
5073 attr->type=type;
5074 return 1;
5075 }
5076
5077 static int
5078 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
5079 {
5080 switch (attr->type) {
5081 case attr_xml_text:
5082 g_free(this->html_text);
5083 this->html_text=g_strdup(attr->u.str);
5084 return 1;
5085 default:
5086 return 0;
5087 }
5088 }
5089
5090 static int
5091 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
5092 {
5093 switch (attr->type) {
5094 case attr_fullscreen:
5095 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
5096 graphics_draw_mode(this->gra, draw_mode_end);
5097 this->win->fullscreen(this->win, attr->u.num > 0);
5098 graphics_draw_mode(this->gra, draw_mode_begin);
5099 }
5100 this->fullscreen=attr->u.num;
5101 return 1;
5102 case attr_menu_on_map_click:
5103 this->menu_on_map_click=attr->u.num;
5104 return 1;
5105 default:
5106 dbg(0,"%s\n",attr_to_name(attr->type));
5107 return 1;
5108 }
5109 }
5110
5111 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
5112 {
5113 struct displaylist_handle *dlh;
5114 struct displaylist *display;
5115 struct displayitem *di;
5116 struct attr cb,**attr_list=NULL;
5117 int valid=0;
5118
5119 display=navit_get_displaylist(this->nav);
5120 dlh=graphics_displaylist_open(display);
5121 while ((di=graphics_displaylist_next(dlh))) {
5122 struct item *item=graphics_displayitem_get_item(di);
5123 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
5124 graphics_displayitem_within_dist(display, di, p, this->radius)) {
5125 struct map_rect *mr=map_rect_new(item->map, NULL);
5126 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
5127 struct attr attr;
5128 if (itemo && item_attr_get(itemo, attr_data, &attr))
5129 attr_list=attr_generic_add_attr(attr_list, &attr);
5130 map_rect_destroy(mr);
5131 }
5132 }
5133 graphics_displaylist_close(dlh);
5134 if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
5135 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
5136 attr_list_free(attr_list);
5137 }
5138
5139 // static int allow_gui_internal;
5140
5141 //##############################################################################################################
5142 //# Description: Function to handle mouse clicks and scroll wheel movement
5143 //# Comment:
5144 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
5145 //##############################################################################################################
5146 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
5147 {
5148 struct gui_priv *this=data;
5149 struct graphics *gra=this->gra;
5150
5151 //dbg(0,"enter @@@@@@@@@@@@@@@@@@@@ %d %d\n", pressed, button);
5152 // if still on the map (not in the menu, yet):
5153 //dbg(0,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
5154 if (!this->root.children || this->ignore_button)
5155 {
5156
5157 this->ignore_button=0;
5158 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
5159 if (!navit_handle_button(this->nav, pressed, button, p, NULL))
5160 {
5161 //dbg(0,"navit has handled button\n");
5162 return;
5163 }
5164 //dbg(0,"menu_on_map_click=%d\n",this->menu_on_map_click);
5165 if (button != 1)
5166 return;
5167 if (this->menu_on_map_click)
5168 {
5169 if (allow_gui_internal == 1)
5170 {
5171 //dbg(0,"@@@@@@@ enter GUI internal!!\n");
5172 gui_internal_cmd_menu(this, p, 0, NULL);
5173 }
5174 else
5175 {
5176 //dbg(0,"+++++++ GUI internal DISABLED!!\n");
5177 }
5178 return;
5179 }
5180 if (this->signal_on_map_click)
5181 {
5182 gui_internal_dbus_signal(this, p);
5183 return;
5184 }
5185 return;
5186 }
5187
5188
5189 // if already in the menu:
5190 if (pressed) {
5191 this->pressed=1;
5192 this->current=*p;
5193 gui_internal_highlight(this);
5194 } else {
5195 this->pressed=0;
5196 this->current.x=-1;
5197 this->current.y=-1;
5198 graphics_draw_mode(gra, draw_mode_begin);
5199 gui_internal_call_highlighted(this);
5200 if (!event_main_loop_has_quit()) {
5201 gui_internal_highlight(this);
5202 graphics_draw_mode(gra, draw_mode_end);
5203 gui_internal_check_exit(this);
5204 }
5205 }
5206 }
5207
5208 static void
5209 gui_internal_setup_gc(struct gui_priv *this)
5210 {
5211 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
5212 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
5213 struct graphics *gra=this->gra;
5214
5215 if (this->background)
5216 return;
5217 this->background=graphics_gc_new(gra);
5218 this->background2=graphics_gc_new(gra);
5219 this->highlight_background=graphics_gc_new(gra);
5220 graphics_gc_set_foreground(this->highlight_background, &cbh);
5221 this->foreground=graphics_gc_new(gra);
5222 graphics_gc_set_foreground(this->foreground, &cf);
5223 this->text_background=graphics_gc_new(gra);
5224 this->text_foreground=graphics_gc_new(gra);
5225 graphics_gc_set_foreground(this->background, &this->background_color);
5226 graphics_gc_set_foreground(this->background2, &this->background2_color);
5227 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
5228 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
5229 }
5230
5231 //##############################################################################################################
5232 //# Description:
5233 //# Comment:
5234 //# Authors: Martin Schaller (04/2008)
5235 //##############################################################################################################
5236 static void gui_internal_resize(void *data, int w, int h)
5237 {
5238 struct gui_priv *this=data;
5239 int changed=0;
5240
5241 gui_internal_setup_gc(this);
5242
5243 if (this->root.w != w || this->root.h != h) {
5244 this->root.w=w;
5245 this->root.h=h;
5246 changed=1;
5247 }
5248 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
5249 navit_handle_resize(this->nav, w, h);
5250 if (this->root.children) {
5251 if (changed) {
5252 gui_internal_prune_menu(this, NULL);
5253 gui_internal_html_load_href(this, "#Main Menu", 0);
5254 } else {
5255 gui_internal_menu_render(this);
5256 }
5257 }
5258 }
5259
5260 static void
5261 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
5262 {
5263 p->x=w->p.x+w->w/2;
5264 p->y=w->p.y+w->h/2;
5265 if (dx < 0)
5266 p->x=w->p.x;
5267 if (dx > 0)
5268 p->x=w->p.x+w->w;
5269 if (dy < 0)
5270 p->y=w->p.y;
5271 if (dy > 0)
5272 p->y=w->p.y+w->h;
5273 }
5274
5275 static void
5276 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
5277 {
5278 GList *l=wi->children;
5279 // Skip hidden elements
5280 if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
5281 return;
5282 if ((wi->state & STATE_SENSITIVE) ) {
5283 int dist1,dist2;
5284 struct point wp;
5285 gui_internal_keynav_point(wi, -dx, -dy, &wp);
5286 if (dx) {
5287 dist1=(wp.x-p->x)*dx;
5288 dist2=wp.y-p->y;
5289 } else if (dy) {
5290 dist1=(wp.y-p->y)*dy;
5291 dist2=wp.x-p->x;
5292 } else {
5293 dist2=wp.x-p->x;
5294 dist1=wp.y-p->y;
5295 if (dist1 < 0)
5296 dist1=-dist1;
5297 }
5298 dbg(1,"checking %d,%d %d %d against %d,%d-%d,%d result %d,%d\n", p->x, p->y, dx, dy, wi->p.x, wi->p.y, wi->p.x+wi->w, wi->p.y+wi->h, dist1, dist2);
5299 if (dist1 >= 0) {
5300 if (dist2 < 0)
5301 dist1-=dist2;
5302 else
5303 dist1+=dist2;
5304 if (dist1 < *distance) {
5305 *result=wi;
5306 *distance=dist1;
5307 }
5308 }
5309 }
5310 while (l) {
5311 struct widget *child=l->data;
5312 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
5313 l=g_list_next(l);
5314 }
5315 }
5316
5317 static void
5318 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
5319 {
5320 struct widget *result,*menu=g_list_last(this->root.children)->data;
5321 struct point p;
5322 int distance;
5323 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
5324 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
5325 else {
5326 p.x=0;
5327 p.y=0;
5328 distance=INT_MAX;
5329 result=NULL;
5330 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
5331 if (result) {
5332 gui_internal_keynav_point(result, dx, dy, &p);
5333 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
5334 }
5335 }
5336 result=NULL;
5337 distance=INT_MAX;
5338 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
5339 dbg(1,"result=%p\n", result);
5340 if (! result) {
5341 if (dx < 0)
5342 p.x=this->root.w;
5343 if (dx > 0)
5344 p.x=0;
5345 if (dy < 0)
5346 p.y=this->root.h;
5347 if (dy > 0)
5348 p.y=0;
5349 result=NULL;
5350 distance=INT_MAX;
5351 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
5352 dbg(1,"wraparound result=%p\n", result);
5353 }
5354 gui_internal_highlight_do(this, result);
5355 if (result)
5356 gui_internal_say(this, result, 1);
5357 }
5358
5359 //##############################################################################################################
5360 //# Description:
5361 //# Comment:
5362 //# Authors: Martin Schaller (04/2008)
5363 //##############################################################################################################
5364 static void gui_internal_keypress(void *data, char *key)
5365 {
5366 struct gui_priv *this=data;
5367 int w,h;
5368 struct point p;
5369 if (!this->root.children) {
5370 transform_get_size(navit_get_trans(this->nav), &w, &h);
5371 switch (*key) {
5372 case NAVIT_KEY_UP:
5373 p.x=w/2;
5374 p.y=0;
5375 navit_set_center_screen(this->nav, &p, 1);
5376 break;
5377 case NAVIT_KEY_DOWN:
5378 p.x=w/2;
5379 p.y=h;
5380 navit_set_center_screen(this->nav, &p, 1);
5381 break;
5382 case NAVIT_KEY_LEFT:
5383 p.x=0;
5384 p.y=h/2;
5385 navit_set_center_screen(this->nav, &p, 1);
5386 break;
5387 case NAVIT_KEY_RIGHT:
5388 p.x=w;
5389 p.y=h/2;
5390 navit_set_center_screen(this->nav, &p, 1);
5391 break;
5392 case NAVIT_KEY_ZOOM_IN:
5393 navit_zoom_in(this->nav, 2, NULL);
5394 break;
5395 case NAVIT_KEY_ZOOM_OUT:
5396 navit_zoom_out(this->nav, 2, NULL);
5397 break;
5398 case NAVIT_KEY_RETURN:
5399 case NAVIT_KEY_MENU:
5400 gui_internal_cmd_menu(this, NULL, 0, NULL);
5401 break;
5402 }
5403 return;
5404 }
5405 graphics_draw_mode(this->gra, draw_mode_begin);
5406 switch (*key) {
5407 case NAVIT_KEY_LEFT:
5408 gui_internal_keynav_highlight_next(this,-1,0);
5409 break;
5410 case NAVIT_KEY_RIGHT:
5411 gui_internal_keynav_highlight_next(this,1,0);
5412 break;
5413 case NAVIT_KEY_UP:
5414 gui_internal_keynav_highlight_next(this,0,-1);
5415 break;
5416 case NAVIT_KEY_DOWN:
5417 gui_internal_keynav_highlight_next(this,0,1);
5418 break;
5419 case NAVIT_KEY_BACK:
5420 if (g_list_length(this->root.children) > 1)
5421 gui_internal_back(this, NULL, NULL);
5422 else
5423 gui_internal_prune_menu(this, NULL);
5424 break;
5425 case NAVIT_KEY_RETURN:
5426 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
5427 gui_internal_call_highlighted(this);
5428 else
5429 gui_internal_keypress_do(this, key);
5430 break;
5431 default:
5432 gui_internal_keypress_do(this, key);
5433 }
5434 if (!event_main_loop_has_quit()) {
5435 graphics_draw_mode(this->gra, draw_mode_end);
5436 gui_internal_check_exit(this);
5437 }
5438 }
5439
5440
5441 //##############################################################################################################
5442 //# Description:
5443 //# Comment:
5444 //# Authors: Martin Schaller (04/2008)
5445 //##############################################################################################################
5446 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
5447 {
5448 struct window *win;
5449 struct transformation *trans=navit_get_trans(this->nav);
5450
5451 win=graphics_get_data(gra, "window");
5452 if (! win)
5453 return 1;
5454 navit_ignore_graphics_events(this->nav, 1);
5455 this->gra=gra;
5456 this->win=win;
5457 navit_ignore_graphics_events(this->nav, 1);
5458 transform_get_size(trans, &this->root.w, &this->root.h);
5459 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
5460 graphics_add_callback(gra, this->resize_cb);
5461 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
5462 graphics_add_callback(gra, this->button_cb);
5463 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
5464 graphics_add_callback(gra, this->motion_cb);
5465 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
5466 graphics_add_callback(gra, this->keypress_cb);
5467 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
5468 graphics_add_callback(gra, this->window_closed_cb);
5469
5470 // set fullscreen if needed
5471 if (this->fullscreen)
5472 this->win->fullscreen(this->win, this->fullscreen != 0);
5473 /* Was resize callback already issued? */
5474 if (navit_get_ready(this->nav) & 2)
5475 gui_internal_setup_gc(this);
5476 return 0;
5477 }
5478
5479 static void gui_internal_disable_suspend(struct gui_priv *this)
5480 {
5481 if (this->win->disable_suspend)
5482 this->win->disable_suspend(this->win);
5483 }
5484
5485 //##############################################################################################################
5486 //# Description:
5487 //# Comment:
5488 //# Authors: Martin Schaller (04/2008)
5489 //##############################################################################################################
5490 struct gui_methods gui_internal_methods = {
5491 NULL,
5492 NULL,
5493 gui_internal_set_graphics,
5494 NULL,
5495 NULL,
5496 NULL,
5497 gui_internal_disable_suspend,
5498 gui_internal_get_attr,
5499 gui_internal_add_attr,
5500 gui_internal_set_attr,
5501 };
5502
5503 static void
5504 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
5505 {
5506 struct attr private_data = { attr_private_data, {(void *)&priv->data}};
5507 if (out)
5508 *out=attr_generic_add_attr(*out, &private_data);
5509 }
5510
5511 static void
5512 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
5513 {
5514 callback_list_add(priv->cbl, cb);
5515 }
5516
5517 static void
5518 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
5519 {
5520 callback_list_remove(priv->cbl, cb);
5521 }
5522
5523
5524 static struct gui_internal_methods gui_internal_methods_ext = {
5525 gui_internal_add_callback,
5526 gui_internal_remove_callback,
5527 gui_internal_menu_render,
5528 image_new_xs,
5529 image_new_l,
5530 };
5531
5532
5533 static enum flags
5534 gui_internal_get_flags(struct widget *widget)
5535 {
5536 return widget->flags;
5537 }
5538
5539 static void
5540 gui_internal_set_flags(struct widget *widget, enum flags flags)
5541 {
5542 widget->flags=flags;
5543 }
5544
5545 static int
5546 gui_internal_get_state(struct widget *widget)
5547 {
5548 return widget->state;
5549 }
5550
5551 static void
5552 gui_internal_set_state(struct widget *widget, int state)
5553 {
5554 widget->state=state;
5555 }
5556
5557 static void
5558 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
5559 {
5560 widget->func=func;
5561 }
5562
5563 static void
5564 gui_internal_set_data(struct widget *widget, void *data)
5565 {
5566 widget->data=data;
5567 }
5568
5569 static void
5570 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
5571 {
5572 widget->background=this->background;
5573 }
5574
5575 static struct gui_internal_widget_methods gui_internal_widget_methods = {
5576 gui_internal_widget_append,
5577 gui_internal_button_new,
5578 gui_internal_button_new_with_callback,
5579 gui_internal_box_new,
5580 gui_internal_label_new,
5581 gui_internal_image_new,
5582 gui_internal_keyboard,
5583 gui_internal_menu,
5584 gui_internal_get_flags,
5585 gui_internal_set_flags,
5586 gui_internal_get_state,
5587 gui_internal_set_state,
5588 gui_internal_set_func,
5589 gui_internal_set_data,
5590 gui_internal_set_default_background,
5591 };
5592
5593 static void
5594 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
5595 {
5596 char *str=NULL,*str2=NULL;
5597 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
5598 if (!in || !in[0])
5599 return;
5600 dbg(1,"%s\n",attr_to_name(in[0]->type));
5601 if (ATTR_IS_STRING(in[0]->type)) {
5602 str=in[0]->u.str;
5603 }
5604 if (ATTR_IS_COORD_GEO(in[0]->type)) {
5605 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
5606 }
5607 if (str) {
5608 str=g_strdup_printf("<html>%s</html>\n",str);
5609 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
5610 }
5611 g_free(str);
5612 g_free(str2);
5613 }
5614
5615
5616 /**
5617 * @brief Creates a new table widget.
5618 *
5619 * Creates and returns a new table widget. This function will
5620 * setup next/previous buttons as children.
5621 *
5622 * @param this The graphics context.
5623 * @param flags widget sizing flags.
5624 * @returns The newly created widget
5625 */
5626 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
5627 {
5628 struct widget * widget = g_new0(struct widget,1);
5629 struct table_data * data = NULL;
5630 widget->type=widget_table;
5631 widget->flags=flags;
5632 widget->data = g_new0(struct table_data,1);
5633 widget->data_free=gui_internal_table_data_free;
5634
5635 // We have to set background here explicitly
5636 // because it will be used by inner elements created later in this
5637 // function (navigation buttons). Else that elements won't have
5638 // any background.
5639 widget->background=this->background;
5640 data = (struct table_data*)widget->data;
5641
5642 if (buttons) {
5643 data->next_button = gui_internal_button_new_with_callback
5644 (this,"Next",image_new_xs(this, "gui_arrow_right") ,
5645 gravity_center |orientation_vertical,
5646 gui_internal_table_button_next,NULL);
5647 data->next_button->data=widget;
5648
5649
5650 data->prev_button = gui_internal_button_new_with_callback
5651 (this,"Prev",
5652 image_new_xs(this, "gui_arrow_left")
5653 ,gravity_center |orientation_vertical,
5654 gui_internal_table_button_prev,NULL);
5655
5656 data->prev_button->data=widget;
5657
5658 data->this=this;
5659
5660 data->button_box=gui_internal_box_new(this,
5661 gravity_center|orientation_horizontal);
5662 gui_internal_widget_append(widget, data->button_box);
5663 gui_internal_widget_append(data->button_box, data->prev_button);
5664 gui_internal_widget_append(data->button_box, data->next_button);
5665
5666 data->button_box->bl=this->spacing;
5667 gui_internal_widget_pack(this,data->button_box);
5668 }
5669
5670 return widget;
5671
5672 }
5673
5674 /**
5675 * @brief Clears all the rows from the table.
5676 * This function removes all rows from a table.
5677 * New rows can later be added to the table.
5678 */
5679 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
5680 {
5681 GList * iter;
5682 struct table_data * table_data = (struct table_data* ) table->data;
5683
5684 iter = table->children;
5685 while(iter ) {
5686 if(iter->data != table_data->button_box) {
5687 struct widget * child = (struct widget*)iter->data;
5688 gui_internal_widget_destroy(this,child);
5689 if(table->children == iter) {
5690 table->children = g_list_remove(iter,iter->data);
5691 iter=table->children;
5692 }
5693 else
5694 iter = g_list_remove(iter,iter->data);
5695 }
5696 else {
5697 iter = g_list_next(iter);
5698 }
5699
5700 }
5701 table_data->top_row=NULL;
5702 table_data->bottom_row=NULL;
5703 if(table_data->page_headers)
5704 g_list_free(table_data->page_headers);
5705 table_data->page_headers=NULL;
5706 }
5707
5708
5709 /**
5710 * Creates a new table_row widget.
5711 * @param this The graphics context
5712 * @param flags Sizing flags for the row
5713 * @returns The new table_row widget.
5714 */
5715 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
5716 {
5717 struct widget * widget = g_new0(struct widget,1);
5718 widget->type=widget_table_row;
5719 widget->flags=flags;
5720 return widget;
5721 }
5722
5723
5724
5725 /**
5726 * @brief Computes the column dimensions for the table.
5727 *
5728 * @param w The table widget to compute dimensions for.
5729 *
5730 * This function examines all of the rows and columns for the table w
5731 * and returns a list (GList) of table_column_desc elements that
5732 * describe each column of the table.
5733 *
5734 * The caller is responsible for freeing the returned list.
5735 */
5736 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
5737 {
5738
5739 GList * column_desc = NULL;
5740 GList * current_desc=NULL;
5741 GList * cur_row = w->children;
5742 struct widget * cur_row_widget=NULL;
5743 GList * cur_column=NULL;
5744 struct widget * cell_w=NULL;
5745 struct table_column_desc * current_cell=NULL;
5746 struct table_data * table_data=NULL;
5747 int height=0;
5748 int width=0;
5749 int total_width=0;
5750 int column_count=0;
5751
5752 /**
5753 * Scroll through the the table and
5754 * 1. Compute the maximum width + height of each column across all rows.
5755 */
5756 table_data = (struct table_data*) w->data;
5757 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
5758 {
5759 cur_row_widget = (struct widget*) cur_row->data;
5760 current_desc = column_desc;
5761 if(cur_row_widget == table_data->button_box)
5762 {
5763 continue;
5764 }
5765 column_count=0;
5766 for(cur_column = cur_row_widget->children; cur_column;
5767 cur_column=g_list_next(cur_column))
5768 {
5769 cell_w = (struct widget*) cur_column->data;
5770 gui_internal_widget_pack(this,cell_w);
5771 if(current_desc == 0)
5772 {
5773 current_cell = g_new0(struct table_column_desc,1);
5774 column_desc = g_list_append(column_desc,current_cell);
5775 current_desc = g_list_last(column_desc);
5776 current_cell->height=cell_w->h;
5777 current_cell->width=cell_w->w;
5778 total_width+=cell_w->w;
5779
5780 }
5781 else
5782 {
5783 current_cell = current_desc->data;
5784 height = cell_w->h;
5785 width = cell_w->w;
5786 if(current_cell->height < height )
5787 {
5788 current_cell->height = height;
5789 }
5790 if(current_cell->width < width)
5791 {
5792 total_width += (width-current_cell->width);
5793 current_cell->width = width;
5794
5795
5796
5797 }
5798 current_desc = g_list_next(current_desc);
5799 }
5800 column_count++;
5801
5802 }/* column loop */
5803
5804 } /*row loop */
5805
5806
5807 /**
5808 * If the width of all columns is less than the width off
5809 * the table expand each cell proportionally.
5810 *
5811 */
5812 if(total_width+(this->spacing*column_count) < w->w ) {
5813 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
5814 current_cell = (struct table_column_desc*) current_desc->data;
5815 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
5816 }
5817 }
5818
5819 return column_desc;
5820 }
5821
5822
5823 /**
5824 * @brief Computes the height and width for the table.
5825 *
5826 * The height and widht are computed to display all cells in the table
5827 * at the requested height/width.
5828 *
5829 * @param this The graphics context
5830 * @param w The widget to pack.
5831 *
5832 */
5833 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
5834 {
5835
5836 int height=0;
5837 int width=0;
5838 int count=0;
5839 GList * column_data = gui_internal_compute_table_dimensions(this,w);
5840 GList * current=0;
5841 struct table_column_desc * cell_desc=0;
5842 struct table_data * table_data = (struct table_data*)w->data;
5843
5844 for(current = column_data; current; current=g_list_next(current))
5845 {
5846 if(table_data->button_box == current->data )
5847 {
5848 continue;
5849 }
5850 cell_desc = (struct table_column_desc *) current->data;
5851 width = width + cell_desc->width + this->spacing;
5852 if(height < cell_desc->height)
5853 {
5854 height = cell_desc->height ;
5855 }
5856 }
5857
5858
5859
5860 for(current=w->children; current; current=g_list_next(current))
5861 {
5862 if(current->data!= table_data->button_box)
5863 {
5864 count++;
5865 }
5866 }
5867 if (table_data->button_box)
5868 gui_internal_widget_pack(this,table_data->button_box);
5869
5870
5871
5872 if(w->h + w->c.y > this->root.h )
5873 {
5874 /**
5875 * Do not allow the widget to exceed the screen.
5876 *
5877 */
5878 w->h = this->root.h- w->c.y - height;
5879 }
5880 w->w = width;
5881
5882 /**
5883 * Deallocate column descriptions.
5884 */
5885 current = column_data;
5886 while( (current = g_list_last(current)) )
5887 {
5888 current = g_list_remove(current,current->data);
5889 }
5890
5891 }
5892
5893 /**
5894 * @brief Invalidates coordinates for previosly rendered table widget rows.
5895 *
5896 * @param table_data Data from the table object.
5897 */
5898 void gui_internal_table_hide_rows(struct table_data * table_data)
5899 {
5900 GList*cur_row;
5901 for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row))
5902 {
5903 struct widget * cur_row_widget = (struct widget*)cur_row->data;
5904 if (cur_row_widget->type!=widget_table_row)
5905 continue;
5906 cur_row_widget->p.x=0;
5907 cur_row_widget->p.y=0;
5908 cur_row_widget->w=0;
5909 cur_row_widget->h=0;
5910 if(cur_row==table_data->bottom_row)
5911 break;
5912 }
5913 }
5914
5915 /**
5916 * @brief Renders a table widget.
5917 *
5918 * @param this The graphics context
5919 * @param w The table widget to render.
5920 */
5921 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
5922 {
5923
5924 int x;
5925 int y;
5926 GList * column_desc=NULL;
5927 GList * cur_row = NULL;
5928 GList * current_desc=NULL;
5929 struct table_data * table_data = (struct table_data*)w->data;
5930 int is_skipped=0;
5931 int is_first_page=1;
5932 struct table_column_desc * dim=NULL;
5933
5934 dbg_assert(table_data);
5935 column_desc = gui_internal_compute_table_dimensions(this,w);
5936 y=w->p.y;
5937 gui_internal_table_hide_rows(table_data);
5938 /**
5939 * Skip rows that are on previous pages.
5940 */
5941 cur_row = w->children;
5942 if(table_data->top_row && table_data->top_row != w->children )
5943 {
5944 cur_row = table_data->top_row;
5945 is_first_page=0;
5946 }
5947 /**
5948 * Loop through each row. Drawing each cell with the proper sizes,
5949 * at the proper positions.
5950 */
5951 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
5952 {
5953 int max_height=0;
5954 struct widget * cur_row_widget;
5955 GList * cur_column=NULL;
5956 current_desc = column_desc;
5957 cur_row_widget = (struct widget*)cur_row->data;
5958 x =w->p.x+this->spacing;
5959 if(cur_row_widget == table_data->button_box )
5960 {
5961 continue;
5962 }
5963 dim = (struct table_column_desc*)current_desc->data;
5964
5965 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
5966 {
5967 /*
5968 * No more drawing space left.
5969 */
5970 is_skipped=1;
5971 break;
5972 }
5973 for(cur_column = cur_row_widget->children; cur_column;
5974 cur_column=g_list_next(cur_column))
5975 {
5976 struct widget * cur_widget = (struct widget*) cur_column->data;
5977 dim = (struct table_column_desc*)current_desc->data;
5978
5979 cur_widget->p.x=x;
5980 cur_widget->w=dim->width;
5981 cur_widget->p.y=y;
5982 cur_widget->h=dim->height;
5983 x=x+cur_widget->w;
5984 max_height = dim->height;
5985 /* We pack the widget before rendering to ensure that the x and y
5986 * coordinates get pushed down.
5987 */
5988 gui_internal_widget_pack(this,cur_widget);
5989 gui_internal_widget_render(this,cur_widget);
5990
5991 if(dim->height > max_height)
5992 {
5993 max_height = dim->height;
5994 }
5995 }
5996
5997 /* Row object should have its coordinates in actual
5998 * state to be able to pass mouse clicks to Column objects
5999 */
6000 cur_row_widget->p.x=w->p.x;
6001 cur_row_widget->w=w->w;
6002 cur_row_widget->p.y=y;
6003 cur_row_widget->h=max_height;
6004 y = y + max_height;
6005 table_data->bottom_row=cur_row;
6006 current_desc = g_list_next(current_desc);
6007 }
6008 if(table_data->button_box && (is_skipped || !is_first_page) )
6009 {
6010 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
6011 this->spacing;
6012 if(table_data->button_box->p.y < y )
6013 {
6014 table_data->button_box->p.y=y;
6015 }
6016 table_data->button_box->p.x = w->p.x;
6017 table_data->button_box->w = w->w;
6018 // table_data->button_box->h = w->h - y;
6019 // table_data->next_button->h=table_data->button_box->h;
6020 // table_data->prev_button->h=table_data->button_box->h;
6021 // table_data->next_button->c.y=table_data->button_box->c.y;
6022 // table_data->prev_button->c.y=table_data->button_box->c.y;
6023 gui_internal_widget_pack(this,table_data->button_box);
6024 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
6025 {
6026 table_data->button_box->p.y = w->p.y + w->h -
6027 table_data->button_box->h;
6028 }
6029 if(is_skipped)
6030 {
6031 table_data->next_button->state|= STATE_SENSITIVE;
6032 }
6033 else
6034 {
6035 table_data->next_button->state&= ~STATE_SENSITIVE;
6036 }
6037
6038 if(table_data->top_row != w->children)
6039 {
6040 table_data->prev_button->state|= STATE_SENSITIVE;
6041 }
6042 else
6043 {
6044 table_data->prev_button->state&= ~STATE_SENSITIVE;
6045 }
6046 gui_internal_widget_render(this,table_data->button_box);
6047
6048
6049 }
6050
6051 /**
6052 * Deallocate column descriptions.
6053 */
6054 current_desc = column_desc;
6055 while( (current_desc = g_list_last(current_desc)) )
6056 {
6057 current_desc = g_list_remove(current_desc,current_desc->data);
6058 }
6059 }
6060
6061
6062 /**
6063 * @brief Displays Route information
6064 *
6065 * @li The name of the active vehicle
6066 * @param wm The button that was pressed.
6067 * @param v Unused
6068 */
6069 static void
6070 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6071 {
6072
6073
6074 struct widget * menu;
6075 struct widget * row;
6076 struct widget * box;
6077
6078
6079 if(! this->vehicle_cb)
6080 {
6081 /**
6082 * Register the callback on vehicle updates.
6083 */
6084 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
6085 attr_position_coord_geo,this);
6086 navit_add_callback(this->nav,this->vehicle_cb);
6087 }
6088
6089 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
6090 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
6091
6092 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
6093
6094
6095 menu=gui_internal_menu(this,_("Route Description"));
6096
6097 menu->free=gui_internal_route_screen_free;
6098 this->route_data.route_showing=1;
6099 this->route_data.route_table->spx = this->spacing;
6100
6101
6102 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
6103
6104 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
6105 gui_internal_widget_append(box,this->route_data.route_table);
6106 box->w=menu->w;
6107 box->spx = this->spacing;
6108 this->route_data.route_table->w=box->w;
6109 gui_internal_widget_append(menu,box);
6110 gui_internal_populate_route_table(this,this->nav);
6111 gui_internal_menu_render(this);
6112
6113 }
6114
6115 static int
6116 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
6117 {
6118 int n, a, b;
6119 int adx=a2->x-a1->x;
6120 int ady=a2->y-a1->y;
6121 int bdx=b2->x-b1->x;
6122 int bdy=b2->y-b1->y;
6123 n = bdy * adx - bdx * ady;
6124 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
6125 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
6126 if (n < 0) {
6127 n = -n;
6128 a = -a;
6129 b = -b;
6130 }
6131 if (a < 0 || b < 0)
6132 return 0;
6133 if (a > n || b > n)
6134 return 0;
6135 if (n == 0) {
6136 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
6137 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
6138 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
6139 dbg_assert(n != 0);
6140 }
6141 res->x = a1->x + a * adx / n;
6142 res->y = a1->y + a * ady / n;
6143 return 1;
6144 }
6145
6146 struct heightline {
6147 struct heightline *next;
6148 int height;
6149 struct coord_rect bbox;
6150 int count;
6151 struct coord c[0];
6152 };
6153
6154 struct diagram_point {
6155 struct diagram_point *next;
6156 struct coord c;
6157 };
6158
6159 static struct heightline *
6160 item_get_heightline(struct item *item)
6161 {
6162 struct heightline *ret=NULL;
6163 struct street_data *sd;
6164 struct attr attr;
6165 int i,height;
6166
6167 if (item_attr_get(item, attr_label, &attr)) {
6168 height=atoi(attr.u.str);
6169 sd=street_get_data(item);
6170 if (sd && sd->count > 1) {
6171 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
6172 ret->bbox.lu=sd->c[0];
6173 ret->bbox.rl=sd->c[0];
6174 ret->count=sd->count;
6175 ret->height=height;
6176 for (i = 0 ; i < sd->count ; i++) {
6177 ret->c[i]=sd->c[i];
6178 coord_rect_extend(&ret->bbox, sd->c+i);
6179 }
6180 }
6181 street_data_free(sd);
6182 }
6183 return ret;
6184 }
6185
6186
6187 /**
6188 * @brief Displays Route Height Profile
6189 *
6190 * @li The name of the active vehicle
6191 * @param wm The button that was pressed.
6192 * @param v Unused
6193 */
6194 static void
6195 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6196 {
6197
6198
6199 struct widget * menu, *box;
6200
6201 struct map * map=NULL;
6202 struct map_rect * mr=NULL;
6203 struct route * route;
6204 struct item * item =NULL;
6205 struct mapset *ms;
6206 struct mapset_handle *msh;
6207 int x,i,first=1,dist=0;
6208 struct coord c,last,res;
6209 struct coord_rect rbbox,dbbox;
6210 struct map_selection sel;
6211 struct heightline *heightline,*heightlines=NULL;
6212 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
6213 sel.next=NULL;
6214 sel.order=18;
6215 sel.range.min=type_height_line_1;
6216 sel.range.max=type_height_line_3;
6217
6218
6219 menu=gui_internal_menu(this,_("Height Profile"));
6220 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
6221 gui_internal_widget_append(menu, box);
6222 route = navit_get_route(this->nav);
6223 if (route)
6224 map = route_get_map(route);
6225 if(map)
6226 mr = map_rect_new(map,NULL);
6227 if(mr) {
6228 while((item = map_rect_get_item(mr))) {
6229 while (item_coord_get(item, &c, 1)) {
6230 if (first) {
6231 first=0;
6232 sel.u.c_rect.lu=c;
6233 sel.u.c_rect.rl=c;
6234 } else
6235 coord_rect_extend(&sel.u.c_rect, &c);
6236 }
6237 }
6238 map_rect_destroy(mr);
6239 ms=navit_get_mapset(this->nav);
6240 if (!first && ms) {
6241 msh=mapset_open(ms);
6242 while ((map=mapset_next(msh, 1))) {
6243 mr=map_rect_new(map, &sel);
6244 if (mr) {
6245 while((item = map_rect_get_item(mr))) {
6246 if (item->type >= sel.range.min && item->type <= sel.range.max) {
6247 heightline=item_get_heightline(item);
6248 if (heightline) {
6249 heightline->next=heightlines;
6250 heightlines=heightline;
6251 }
6252 }
6253 }
6254 map_rect_destroy(mr);
6255 }
6256 }
6257 mapset_close(msh);
6258 }
6259 }
6260 map=NULL;
6261 mr=NULL;
6262 if (route)
6263 map = route_get_map(route);
6264 if(map)
6265 mr = map_rect_new(map,NULL);
6266 if(mr && heightlines) {
6267 while((item = map_rect_get_item(mr))) {
6268 first=1;
6269 while (item_coord_get(item, &c, 1)) {
6270 if (first)
6271 first=0;
6272 else {
6273 heightline=heightlines;
6274 rbbox.lu=last;
6275 rbbox.rl=last;
6276 coord_rect_extend(&rbbox, &c);
6277 while (heightline)
6278 {
6279 dbg(0,"EEnter\n");
6280 if (coord_rect_overlap(&rbbox, &heightline->bbox))
6281 {
6282 for (i = 0 ; i < heightline->count - 1; i++) {
6283 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
6284 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
6285 diagram_point=g_new(struct diagram_point, 1);
6286 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
6287 diagram_point->c.y=heightline->height;
6288 diagram_point->next=diagram_points;
6289 diagram_points=diagram_point;
6290 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
6291 }
6292 }
6293 }
6294 }
6295 heightline=heightline->next;
6296 }
6297 dist+=transform_distance(projection_mg, &last, &c);
6298 }
6299 last=c;
6300 }
6301
6302 }
6303 map_rect_destroy(mr);
6304 }
6305
6306
6307 gui_internal_menu_render(this);
6308 first=1;
6309 diagram_point=diagram_points;
6310 while (diagram_point) {
6311 if (first) {
6312 dbbox.lu=diagram_point->c;
6313 dbbox.rl=diagram_point->c;
6314 first=0;
6315 } else
6316 coord_rect_extend(&dbbox, &diagram_point->c);
6317 diagram_point=diagram_point->next;
6318 }
6319 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
6320 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
6321 dbbox.lu.x=0;
6322 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
6323 dbbox.rl.y=0;
6324 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
6325 x=dbbox.lu.x;
6326 first=1;
6327 for (;;) {
6328 struct point p[2];
6329 min=NULL;
6330 diagram_point=diagram_points;
6331 while (diagram_point) {
6332 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
6333 min=diagram_point;
6334 diagram_point=diagram_point->next;
6335 }
6336 if (! min)
6337 break;
6338 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
6339 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
6340 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
6341 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
6342 if (first)
6343 first=0;
6344 else
6345 graphics_draw_lines(this->gra, this->foreground, p, 2);
6346 p[0]=p[1];
6347 x=min->c.x+1;
6348 }
6349
6350
6351 }
6352
6353 static void
6354 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6355 {
6356 struct widget *menu,*wb,*w;
6357 char *text;
6358
6359 graphics_draw_mode(this->gra, draw_mode_begin);
6360 menu=gui_internal_menu(this, _("Show Locale"));
6361 menu->spx=this->spacing*10;
6362 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
6363 gui_internal_widget_append(menu, wb);
6364 text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
6365 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6366 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
6367 g_free(text);
6368 #ifdef HAVE_API_WIN32_BASE
6369 {
6370 char country[32],lang[32];
6371 #ifdef HAVE_API_WIN32_CE
6372 wchar_t wcountry[32],wlang[32];
6373
6374 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
6375 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
6376 #else
6377 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
6378 #endif
6379 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
6380 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6381 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
6382 g_free(text);
6383 #ifdef HAVE_API_WIN32_CE
6384 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
6385 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
6386 #else
6387 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
6388 #endif
6389 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
6390 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6391 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
6392 g_free(text);
6393 }
6394 #endif
6395
6396 gui_internal_menu_render(this);
6397 graphics_draw_mode(this->gra, draw_mode_end);
6398 }
6399
6400 static void
6401 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6402 {
6403 struct widget *menu,*wb,*w;
6404 char *text;
6405
6406 graphics_draw_mode(this->gra, draw_mode_begin);
6407 menu=gui_internal_menu(this, ("About ZANavi"));
6408 menu->spx=this->spacing*10;
6409 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
6410 gui_internal_widget_append(menu, wb);
6411
6412 //Icon -> seems missing, try icon.png?
6413 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "icon")));
6414 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
6415
6416 //app name
6417 text=g_strdup_printf("%s",(" "));
6418 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6419 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6420 g_free(text);
6421 text=g_strdup_printf("%s",PACKAGE_NAME);
6422 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6423 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
6424 g_free(text);
6425
6426 //Version
6427 text=g_strdup_printf("%s",(" "));
6428 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6429 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6430 g_free(text);
6431 text=g_strdup_printf("%s",version);
6432 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6433 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
6434 g_free(text);
6435
6436 //Site
6437 text=g_strdup_printf("%s",(" "));
6438 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6439 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6440 g_free(text);
6441 text=g_strdup_printf("http://zanavi.cc/");
6442 // gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6443 gui_internal_widget_append(wb, w=gui_internal_label_font_new(this, text,1));
6444 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
6445 g_free(text);
6446
6447 //ZANavi
6448 text=g_strdup_printf("%s",(" "));
6449 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6450 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6451 g_free(text);
6452 text=g_strdup_printf("%s",("ZANavi"));
6453 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6454 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6455 g_free(text);
6456 text=g_strdup_printf("%s",("by Zoff"));
6457 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6458 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6459 g_free(text);
6460 text=g_strdup_printf("%s",(" "));
6461 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6462 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6463 g_free(text);
6464 text=g_strdup_printf("%s",(" "));
6465 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6466 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6467 g_free(text);
6468
6469 //Navit
6470 text=g_strdup_printf("%s:",("based on Navit by"));
6471 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6472 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6473 g_free(text);
6474 text=g_strdup_printf("Martin Schaller");
6475 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6476 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
6477 g_free(text);
6478
6479 gui_internal_menu_render(this);
6480 graphics_draw_mode(this->gra, draw_mode_end);
6481 }
6482
6483 /**
6484 * @brief handles the 'next page' table event.
6485 * A callback function that is invoked when the 'next page' button is pressed
6486 * to advance the contents of a table widget.
6487 *
6488 * @param this The graphics context.
6489 * @param wm The button widget that was pressed.
6490 */
6491 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
6492 {
6493 struct widget * table_widget = (struct widget * ) wm->data;
6494 struct table_data * table_data = NULL;
6495 int found=0;
6496 GList * iterator;
6497
6498 if(table_widget)
6499 {
6500 table_data = (struct table_data*) table_widget->data;
6501
6502 }
6503 if(table_data)
6504 {
6505 /**
6506 * Before advancing to the next page we need to ensure
6507 * that the current top_row is in the list of previous top_rows
6508 * so previous page can work.
6509 *
6510 */
6511 for(iterator=table_data->page_headers; iterator != NULL;
6512 iterator = g_list_next(iterator) )
6513 {
6514 if(iterator->data == table_data->top_row)
6515 {
6516 found=1;
6517 break;
6518 }
6519
6520 }
6521 if( ! found)
6522 {
6523 table_data->page_headers=g_list_append(table_data->page_headers,
6524 table_data->top_row);
6525 }
6526 /**
6527 * Invalidate row coordinates for all rows which were previously rendered
6528
6529 for(iterator=table_data->top_row; iterator && table_data->rows_on_page; iterator = g_list_next(iterator))
6530 {
6531 struct widget * cur_row_widget = (struct widget*)iterator->data;
6532 cur_row_widget->p.x=-1;
6533 cur_row_widget->p.y=-1;
6534 cur_row_widget->w=0;
6535 cur_row_widget->h=0;
6536 table_data->rows_on_page--;
6537 }
6538 */
6539 gui_internal_table_hide_rows(table_data);
6540 table_data->top_row=g_list_next(table_data->bottom_row);
6541 }
6542 wm->state&= ~STATE_HIGHLIGHTED;
6543 gui_internal_menu_render(this);
6544 }
6545
6546
6547
6548 /**
6549 * @brief handles the 'previous page' table event.
6550 * A callback function that is invoked when the 'previous page' button is pressed
6551 * to go back in the contents of a table widget.
6552 *
6553 * @param this The graphics context.
6554 * @param wm The button widget that was pressed.
6555 */
6556 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
6557 {
6558 struct widget * table_widget = (struct widget * ) wm->data;
6559 struct table_data * table_data = NULL;
6560 GList * current_page_top=NULL;
6561
6562 GList * iterator;
6563 if(table_widget)
6564 {
6565 table_data = (struct table_data*) table_widget->data;
6566 if(table_data)
6567 {
6568 gui_internal_table_hide_rows(table_data);
6569 current_page_top = table_data->top_row;
6570 for(iterator = table_data->page_headers; iterator != NULL;
6571 iterator = g_list_next(iterator))
6572 {
6573 if(current_page_top == iterator->data)
6574 {
6575 break;
6576 }
6577 table_data->top_row = (GList*) iterator->data;
6578 }
6579 }
6580 }
6581 wm->state&= ~STATE_HIGHLIGHTED;
6582 gui_internal_menu_render(this);
6583 }
6584
6585
6586 /**
6587 * @brief deallocates a table_data structure.
6588 *
6589 */
6590 void gui_internal_table_data_free(void * p)
6591 {
6592
6593
6594 /**
6595 * @note button_box and its children (next_button,prev_button)
6596 * have their memory managed by the table itself.
6597 */
6598 struct table_data * table_data = (struct table_data*) p;
6599 g_list_free(table_data->page_headers);
6600 g_free(p);
6601
6602
6603 }
6604
6605
6606 /**
6607 * @brief Called when the route is updated.
6608 */
6609 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
6610 {
6611
6612 if(this->route_data.route_showing) {
6613 gui_internal_populate_route_table(this,navit);
6614 graphics_draw_mode(this->gra, draw_mode_begin);
6615 gui_internal_menu_render(this);
6616 graphics_draw_mode(this->gra, draw_mode_end);
6617 }
6618
6619
6620 }
6621
6622
6623 /**
6624 * @brief Called when the route screen is closed (deallocated).
6625 *
6626 * The main purpose of this function is to remove the widgets from
6627 * references route_data because those widgets are about to be freed.
6628 */
6629 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
6630 {
6631 if(this_) {
6632 this_->route_data.route_showing=0;
6633 this_->route_data.route_table=NULL;
6634 g_free(w);
6635 }
6636
6637 }
6638
6639 /**
6640 * @brief Populates the route table with route information
6641 *
6642 * @param this The gui context
6643 * @param navit The navit object
6644 */
6645 void gui_internal_populate_route_table(struct gui_priv * this,
6646 struct navit * navit)
6647 {
6648 struct map * map=NULL;
6649 struct map_rect * mr=NULL;
6650 struct navigation * nav = NULL;
6651 struct item * item =NULL;
6652 struct attr attr;
6653 struct widget * label = NULL;
6654 struct widget * row = NULL;
6655 nav = navit_get_navigation(navit);
6656 if(!nav) {
6657 return;
6658 }
6659 map = navigation_get_map(nav);
6660 if(map)
6661 mr = map_rect_new(map,NULL);
6662 if(mr) {
6663 gui_internal_widget_table_clear(this,this->route_data.route_table);
6664 while((item = map_rect_get_item(mr))) {
6665 if(item_attr_get(item,attr_navigation_long,&attr)) {
6666 label = gui_internal_label_new(this,attr.u.str);
6667 row = gui_internal_widget_table_row_new(this,
6668 gravity_left
6669 | flags_fill
6670 | orientation_horizontal);
6671 row->children=g_list_append(row->children,label);
6672 gui_internal_widget_append(this->route_data.route_table,row);
6673 }
6674
6675 }
6676
6677 }
6678 }
6679
6680 static struct command_table commands[] = {
6681 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
6682 {"back",command_cast(gui_internal_cmd2_back)},
6683 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
6684 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
6685 {"get_data",command_cast(gui_internal_get_data)},
6686 {"locale",command_cast(gui_internal_cmd2_locale)},
6687 {"log",command_cast(gui_internal_cmd_log)},
6688 {"menu",command_cast(gui_internal_cmd_menu2)},
6689 {"position",command_cast(gui_internal_cmd2_position)},
6690 {"route_description",command_cast(gui_internal_cmd2_route_description)},
6691 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
6692 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
6693 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
6694 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
6695 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
6696 {"town",command_cast(gui_internal_cmd2_town)},
6697 {"quit",command_cast(gui_internal_cmd2_quit)},
6698 {"write",command_cast(gui_internal_cmd_write)},
6699 {"about",command_cast(gui_internal_cmd2_about)},
6700 };
6701
6702
6703 //##############################################################################################################
6704 //# Description:
6705 //# Comment:
6706 //# Authors: Martin Schaller (04/2008)
6707 //##############################################################################################################
6708 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
6709 {
6710 struct color color_white={0xffff,0xffff,0xffff,0xffff};
6711 struct color color_black={0x0,0x0,0x0,0xffff};
6712 struct color back2_color={0x4141,0x4141,0x4141,0xffff};
6713
6714 struct gui_priv *this;
6715 struct attr *attr;
6716 *meth=gui_internal_methods;
6717 this=g_new0(struct gui_priv, 1);
6718 this->nav=nav;
6719
6720 this->self.type=attr_gui;
6721 this->self.u.gui=gui;
6722
6723 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
6724 this->menu_on_map_click=attr->u.num;
6725 else
6726 this->menu_on_map_click=1;
6727 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
6728 this->signal_on_map_click=attr->u.num;
6729
6730 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
6731 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
6732 }
6733
6734 if( (attr=attr_search(attrs,NULL,attr_font_size)))
6735 {
6736 this->config.font_size=attr->u.num;
6737 }
6738 else
6739 {
6740 this->config.font_size=-1;
6741 }
6742 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
6743 {
6744 this->config.icon_xs=attr->u.num;
6745 }
6746 else
6747 {
6748 this->config.icon_xs=-1;
6749 }
6750 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
6751 {
6752 this->config.icon_l=attr->u.num;
6753 }
6754 else
6755 {
6756 this->config.icon_l=-1;
6757 }
6758 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
6759 {
6760 this->config.icon_s=attr->u.num;
6761 }
6762 else
6763 {
6764 this->config.icon_s=-1;
6765 }
6766 if( (attr=attr_search(attrs,NULL,attr_spacing)))
6767 {
6768 this->config.spacing=attr->u.num;
6769 }
6770 else
6771 {
6772 this->config.spacing=-1;
6773 }
6774 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
6775 {
6776 this->speech=attr->u.num;
6777 }
6778 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
6779 this->keyboard=attr->u.num;
6780 else
6781 this->keyboard=1;
6782
6783 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
6784 this->fullscreen=attr->u.num;
6785
6786 if( (attr=attr_search(attrs,NULL,attr_flags)))
6787 this->flags=attr->u.num;
6788 if( (attr=attr_search(attrs,NULL,attr_background_color)))
6789 this->background_color=*attr->u.color;
6790 else
6791 this->background_color=color_black;
6792 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
6793 this->background2_color=*attr->u.color;
6794 else
6795 this->background2_color=back2_color;
6796 if( (attr=attr_search(attrs,NULL,attr_text_color)))
6797 this->text_foreground_color=*attr->u.color;
6798 else
6799 this->text_foreground_color=color_white;
6800 this->text_background_color=color_black;
6801 if( (attr=attr_search(attrs,NULL,attr_columns)))
6802 this->cols=attr->u.num;
6803 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
6804 this->osd_configuration=*attr;
6805
6806 if( (attr=attr_search(attrs,NULL,attr_pitch)))
6807 this->pitch=attr->u.num;
6808 else
6809 this->pitch=20;
6810 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
6811 this->flags_town=attr->u.num;
6812 else
6813 this->flags_town=-1;
6814 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
6815 this->flags_street=attr->u.num;
6816 else
6817 this->flags_street=-1;
6818 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
6819 this->flags_house_number=attr->u.num;
6820 else
6821 this->flags_house_number=-1;
6822 if( (attr=attr_search(attrs,NULL,attr_radius)))
6823 this->radius=attr->u.num;
6824 else
6825 this->radius=10;
6826 this->data.priv=this;
6827 this->data.gui=&gui_internal_methods_ext;
6828 this->data.widget=&gui_internal_widget_methods;
6829 this->cbl=callback_list_new();
6830
6831 return this;
6832 }
6833
6834 //##############################################################################################################
6835 //# Description:
6836 //# Comment:
6837 //# Authors: Martin Schaller (04/2008)
6838 //##############################################################################################################
6839 void plugin_init(void)
6840 {
6841 plugin_register_gui_type("internal", gui_internal_new);
6842 }
6843
6844 static void
6845 gui_internal_destroy(struct gui_priv *this)
6846 {
6847 g_free(this->country_iso2);
6848 g_free(this->href);
6849 g_free(this->html_text);
6850 g_free(this);
6851 }

   
Visit the ZANavi Wiki