2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2010 Navit Team
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.
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.
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.
20 //##############################################################################################################
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)
27 //##############################################################################################################
37 #ifdef HAVE_API_WIN32_BASE
43 #define snprintf sprintf_s
48 #include "navit_nls.h"
54 #include "transform.h"
60 #include "vehicleprofile.h"
66 #include "navit/search.h"
71 #include "navit_nls.h"
72 #include "navigation.h"
73 #include "gui_internal.h"
75 #include "xmlconfig.h"
77 #include "bookmarks.h"
91 struct widget *search_list;
92 struct widget *keyboard;
93 struct widget *button_bar;
96 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
97 struct widget *redisplay_widget;
99 struct attr refresh_callback_obj,refresh_callback;
102 enum gui_internal_reason {
103 gui_internal_reason_click=1,
104 gui_internal_reason_keypress,
105 gui_internal_reason_keypress_finish
108 //##############################################################################################################
111 //# Authors: Martin Schaller (04/2008)
112 //##############################################################################################################
114 enum widget_type type;
115 struct graphics_gc *background,*text_background;
116 struct graphics_gc *foreground_frame;
117 struct graphics_gc *foreground;
119 struct graphics_image *img;
121 * A function to be invoked on actions.
122 * @li widget The widget that is receiving the button press.
125 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
126 enum gui_internal_reason reason;
130 * @brief A function to deallocate data
132 void (*data_free)(void *data);
135 * @brief a function that will be called as the widget is being destroyed.
136 * This function can act as a destructor for the widget. It allows for
137 * on deallocation actions to be specified on a per widget basis.
138 * This function will call g_free on the widget (if required).
140 void (*wfree) (struct gui_priv *this_, struct widget * w);
154 int bl,br,bt,bb,spx,spy;
158 * The number of widgets to layout horizontally when doing
159 * a orientation_horizontal_vertical layout
165 int (*set_attr)(void *, struct attr *);
166 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
167 void (*remove_cb)(void *, struct callback *cb);
174 struct menu_data *menu_data;
177 struct widget *parent;
181 * @brief A structure to store configuration values.
183 * This structure stores configuration values for how gui elements in the internal GUI
186 struct gui_config_settings {
189 * The base size (in fractions of a point) to use for text.
193 * The size (in pixels) that xs style icons should be scaled to.
194 * This icon size is typically used in various lists and should be set to value which allows a list row to be easily cliked or dragged.
198 * The size (in pixels) that s style icons (small) should be scaled to, used for the menu top row icons
202 * The size (in pixels) that l style icons should be scaled to, used for icons defined in the menu html
206 * The default amount of spacing (in pixels) to place between GUI elements.
213 * Indexes into the config_profiles array.
215 const int LARGE_PROFILE=0;
216 const int MEDIUM_PROFILE=1;
217 const int SMALL_PROFILE=2;
220 * The default config profiles.
222 * [0] => LARGE_PROFILE (screens 640 in one dimension)
223 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
224 * [2] => Small profile (default)
226 static struct gui_config_settings config_profiles[]={
233 struct widget * route_table;
238 //##############################################################################################################
241 //# Authors: Martin Schaller (04/2008)
242 //##############################################################################################################
247 struct graphics *gra;
248 struct graphics_gc *background;
249 struct graphics_gc *background2;
250 struct graphics_gc *highlight_background;
251 struct graphics_gc *foreground;
252 struct graphics_gc *text_foreground;
253 struct graphics_gc *text_background;
254 struct color background_color, background2_color, text_foreground_color, text_background_color;
258 struct graphics_font *fonts[3];
260 * The size (in pixels) that xs style icons should be scaled to.
261 * This icon size can be too small to click it on some devices.
265 * The size (in pixels) that s style icons (small) should be scaled to
269 * The size (in pixels) that l style icons should be scaled to
273 struct widget *widgets;
277 struct widget *highlighted,*editable;
278 struct widget *highlighted_menu;
279 struct pcoord clickp, vehiclep;
280 struct attr *click_coord_geo, *position_coord_geo;
281 struct search_list *sl;
283 int menu_on_map_click;
285 int signal_on_map_click;
289 int keyboard_required;
291 * The setting information read from the configuration file.
292 * values of -1 indicate no value was specified in the config file.
294 struct gui_config_settings config;
295 struct event_idle *idle;
296 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
297 struct event_timeout *motion_timeout_event;
298 struct point current;
300 struct callback * vehicle_cb;
302 * Stores information about the route.
304 struct route_data route_data;
306 struct gui_internal_data data;
307 struct callback_list *cbl;
310 struct attr osd_configuration;
312 int flags_town,flags_street,flags_house_number;
314 int mouse_button_clicked_on_map;
318 struct widget *html_container;
322 int html_anchor_found;
342 struct widget *container;
347 struct gesture_elem {
350 } gesture_ring[GESTURE_RINGSIZE];
351 int gesture_ring_last, gesture_ring_first;
354 int results_map_population;
361 struct html_tag_map {
367 {"html",html_tag_html},
368 {"img",html_tag_img},
369 {"script",html_tag_script},
370 {"form",html_tag_form},
371 {"input",html_tag_input},
372 {"div",html_tag_div},
377 * @brief A structure to store information about a table.
379 * The table_data widget stores pointers to extra information needed by the
382 * The table_data structure needs to be freed with data_free along with the widget.
388 * A GList pointer into a widget->children list that indicates the row
389 * currently being rendered at the top of the table.
393 * A Glist pointer into a widget->children list that indicates the row
394 * currently being rendered at the bottom of the table.
399 * A container box that is the child of the table widget that contains+groups
400 * the next and previous button.
402 struct widget * button_box;
405 * Button box should not be displayed if button_box_hide is not zero.
410 * A button widget to handle 'next page' requests
412 struct widget * next_button;
414 * A button widget to handle 'previous page' requests.
416 struct widget * prev_button;
420 * a pointer to the gui context.
421 * This is needed by the free function to destory the buttons.
423 struct gui_priv * this;
427 * A data structure that holds information about a column that makes up a table.
431 struct table_column_desc
435 * The computed height of a cell in the table.
440 * The computed width of a cell in the table.
446 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
447 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
448 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
449 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
450 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child);
451 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child);
452 static void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func);
453 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
454 static void gui_internal_apply_config(struct gui_priv *this);
456 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
457 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
458 static void gui_internal_table_hide_rows(struct table_data * table_data);
459 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
460 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
461 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
462 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
463 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
464 static int gui_internal_widget_table_is_empty(struct gui_priv *this,struct widget * table);
465 static GList * gui_internal_widget_table_top_row(struct gui_priv *this, struct widget * table);
466 static GList * gui_internal_widget_table_next_row(GList * row);
467 static GList * gui_internal_widget_table_prev_row(GList * row);
468 static GList * gui_internal_widget_table_first_row(GList * row);
469 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
470 static void gui_internal_table_data_free(void * d);
471 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
473 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
474 static void gui_internal_populate_route_table(struct gui_priv * this,
475 struct navit * navit);
476 static void gui_internal_search_idle_end(struct gui_priv *this);
477 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
478 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
479 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
480 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
481 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
482 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
483 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
484 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
485 static void gui_internal_check_exit(struct gui_priv *this);
486 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
488 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
489 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
491 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
492 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
493 static void gui_internal_html_load_href(struct gui_priv *this, char *href, int replace);
494 static void gui_internal_destroy(struct gui_priv *this);
495 static void gui_internal_enter(struct gui_priv *this, int ignore);
496 static void gui_internal_enter_setup(struct gui_priv *this);
497 static void gui_internal_html_main_menu(struct gui_priv *this);
498 static void gui_internal_menu_vehicle_settings(struct gui_priv *this, struct vehicle *v, char *name);
502 * * Display image scaled to specific size
503 * * searches for scaleable and pre-scaled image
504 * * @param this Our gui context
505 * * @param name image name
506 * * @param w desired width of image
507 * * @param h desired height of image
508 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
510 static struct graphics_image *
511 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
513 struct graphics_image *ret=NULL;
514 char *full_path=NULL;
515 full_path=graphics_icon_path(name);
516 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
517 dbg(1,"Trying to load image '%s' (w=%d, h=%d): %s\n", name, w, h, ret ? "OK" : "NOT FOUND");
520 dbg(0,"Failed to load image for '%s' (w=%d, h=%d)\n", name, w, h);
525 static struct graphics_image *
526 image_new_o(struct gui_priv *this, char *name)
528 return image_new_scaled(this, name, -1, -1);
533 * * Display image scaled to xs (extra small) size
534 * * This image size can be too small to click it on some devices.
535 * * @param this Our gui context
536 * * @param name image name
537 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
539 static struct graphics_image *
540 image_new_xs(struct gui_priv *this, const char *name)
542 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
546 * * Display image scaled to s (small) size
547 * * @param this Our gui context
548 * * @param name image name
549 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
552 static struct graphics_image *
553 image_new_s(struct gui_priv *this, const char *name)
555 return image_new_scaled(this, name, this->icon_s, this->icon_s);
559 * * Display image scaled to l (large) size
560 * * @param this Our gui context
561 * * @param name image name
562 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
564 static struct graphics_image *
565 image_new_l(struct gui_priv *this, const char *name)
567 return image_new_scaled(this, name, this->icon_l, this->icon_l);
571 coordinates_geo(const struct coord_geo *gc, char sep)
573 char latc='N',lngc='E';
574 int lat_deg,lat_min,lat_sec;
575 int lng_deg,lng_min,lng_sec;
576 struct coord_geo g=*gc;
586 lat_sec=fmod(g.lat*3600+0.5,60);
587 lat_min=fmod(g.lat*60-lat_sec/60.0+0.5,60);
588 lat_deg=g.lat-lat_min/60.0-lat_sec/3600.0+0.5;
589 lng_sec=fmod(g.lng*3600+0.5,60);
590 lng_min=fmod(g.lng*60-lng_sec/60.0+0.5,60);
591 lng_deg=g.lng-lng_min/60.0-lng_sec/3600.0+0.5;;
592 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);
596 coordinates(struct pcoord *pc, char sep)
602 transform_to_geo(pc->pro, &c, &g);
603 return coordinates_geo(&g, sep);
608 gui_internal_background_render(struct gui_priv *this, struct widget *w)
610 struct point pnt=w->p;
611 if (w->state & STATE_HIGHLIGHTED)
612 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
615 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
619 static struct widget *
620 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
626 struct widget *widget=g_new0(struct widget, 1);
627 widget->type=widget_label;
628 widget->font_idx=font;
630 widget->text=g_strdup(text);
631 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
635 widget->h=h+this->spacing;
637 widget->w=w+this->spacing;
639 widget->flags=gravity_center;
640 widget->foreground=this->text_foreground;
641 widget->text_background=this->text_background;
646 static struct widget *
647 gui_internal_label_new(struct gui_priv *this, char *text)
649 return gui_internal_label_font_new(this, text, 0);
652 static struct widget *
653 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
655 struct widget *ret=NULL;
656 char *tmp=g_malloc(strlen(text)+3), *p;
658 while ((p=g_utf8_find_prev_char(text, p)) >= text) {
662 ret=gui_internal_label_new(this, tmp);
663 if (ret->w < maxwidth)
665 gui_internal_widget_destroy(this, ret);
669 ret=gui_internal_label_new(this, "");
674 static struct widget *
675 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
677 struct widget *widget=g_new0(struct widget, 1);
678 widget->type=widget_image;
681 widget->w=image->width;
682 widget->h=image->height;
688 gui_internal_image_render(struct gui_priv *this, struct widget *w)
692 gui_internal_background_render(this, w);
695 pnt.x+=w->w/2-w->img->hot.x;
696 pnt.y+=w->h/2-w->img->hot.y;
697 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
702 gui_internal_label_render(struct gui_priv *this, struct widget *w)
704 struct point pnt=w->p;
705 gui_internal_background_render(this, w);
706 if (w->state & STATE_EDIT)
707 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
710 char *startext=(char*)g_alloca(strlen(w->text)+1);
714 for (i = 0 ; i < strlen(text); i++)
719 if (w->flags & gravity_right) {
720 pnt.y+=w->h-this->spacing;
721 pnt.x+=w->w-w->textw-this->spacing;
722 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
724 pnt.y+=w->h-this->spacing;
725 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
731 * @brief A text box is a widget that renders a text string containing newlines.
732 * The string will be broken up into label widgets at each newline with a vertical layout.
735 static struct widget *
736 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
738 char *s=g_strdup(text),*s2,*tok;
739 struct widget *ret=gui_internal_box_new(this, flags);
741 while ((tok=strtok(s2,"\n"))) {
742 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
745 gui_internal_widget_pack(this,ret);
750 static struct widget *
751 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
753 return gui_internal_text_font_new(this, text, 0, flags);
757 static struct widget *
758 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)
760 struct widget *ret=NULL;
761 ret=gui_internal_box_new(this, flags);
764 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
766 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
770 ret->state |= STATE_SENSITIVE;
771 ret->speech=g_strdup(text);
778 static struct widget *
779 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)
781 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
785 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
792 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
793 is_on=curr.u.data == w->on.u.data;
796 if (is_on != w->is_on) {
800 l=g_list_first(w->children);
804 graphics_image_free(this->gra, wi->img);
805 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
807 if (w->is_on && w->off.type == attr_none)
808 w->state &= ~STATE_SENSITIVE;
810 w->state |= STATE_SENSITIVE;
817 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
819 if (gui_internal_button_attr_update(this, w))
820 gui_internal_widget_render(this, w);
823 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
826 w->set_attr(w->instance, &w->off);
828 w->set_attr(w->instance, &w->on);
829 gui_internal_button_attr_update(this, w);
833 static struct widget *
834 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
836 struct graphics_image *image=NULL;
840 image=image_new_xs(this, "gui_inactive");
841 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
846 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
847 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
848 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
849 ret->instance=this->nav;
850 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
851 navit_add_callback(this->nav, ret->cb);
852 gui_internal_button_attr_update(this, ret);
856 static struct widget *
857 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)
859 struct graphics_image *image=NULL;
861 image=image_new_xs(this, "gui_inactive");
864 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
870 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
871 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
872 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
875 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
876 map_add_callback(map, ret->cb);
877 gui_internal_button_attr_update(this, ret);
881 static struct widget *
882 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
884 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
888 //##############################################################################################################
891 //# Authors: Martin Schaller (04/2008)
892 //##############################################################################################################
893 static void gui_internal_clear(struct gui_priv *this)
895 struct graphics *gra=this->gra;
899 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
903 static struct widget *
904 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
906 struct widget *ret,*child;
907 GList *l=wi->children;
914 if ( wi->p.x + wi->w < p->x)
916 if ( wi->p.y + wi->h < p->y)
919 if (wi->state & flags)
923 ret=gui_internal_find_widget(child, p, flags);
934 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
936 if (found == this->highlighted)
939 graphics_draw_mode(this->gra, draw_mode_begin);
940 if (this->highlighted) {
941 this->highlighted->state &= ~STATE_HIGHLIGHTED;
942 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
943 gui_internal_widget_render(this, this->highlighted);
944 this->highlighted=NULL;
945 this->highlighted_menu=NULL;
948 this->highlighted=found;
949 this->highlighted_menu=g_list_last(this->root.children)->data;
950 this->highlighted->state |= STATE_HIGHLIGHTED;
951 gui_internal_widget_render(this, this->highlighted);
952 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
954 graphics_draw_mode(this->gra, draw_mode_end);
956 //##############################################################################################################
959 //# Authors: Martin Schaller (04/2008)
960 //##############################################################################################################
961 static void gui_internal_highlight(struct gui_priv *this)
963 struct widget *menu,*found=NULL;
964 if (this->current.x > -1 && this->current.y > -1) {
965 menu=g_list_last(this->root.children)->data;
966 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
968 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
970 if (this->editable && this->editable != found) {
971 this->editable->state &= ~ STATE_EDIT;
972 gui_internal_widget_render(this, this->editable);
974 found->state |= STATE_EDIT;
975 gui_internal_widget_render(this, found);
976 this->editable=found;
981 gui_internal_highlight_do(this, found);
982 this->motion_timeout_event=NULL;
986 static void gui_internal_gesture_ring_clear(struct gui_priv *this)
988 this->gesture_ring_last=this->gesture_ring_first=0;
992 static struct gesture_elem * gui_internal_gesture_ring_get(struct gui_priv *this, int i)
994 int n=(this->gesture_ring_last-i)%GESTURE_RINGSIZE;
995 if(n==this->gesture_ring_first)
997 return this->gesture_ring+n;
1000 static void gui_internal_gesture_ring_add(struct gui_priv *this, struct point *p)
1003 #ifndef HAVE_API_WIN32_CE
1005 gettimeofday(&tv,NULL);
1006 msec=tv.tv_sec*1000+tv.tv_usec/1000;
1008 msec=GetTickCount();
1010 this->gesture_ring_last++;
1011 this->gesture_ring_last%=GESTURE_RINGSIZE;
1012 if(this->gesture_ring_last==this->gesture_ring_first) {
1013 this->gesture_ring_first++;
1014 this->gesture_ring_first%=GESTURE_RINGSIZE;
1016 this->gesture_ring[this->gesture_ring_last].p=*p;
1017 this->gesture_ring[this->gesture_ring_last].msec=msec;
1018 dbg(2,"msec=%d x=%d y=%d\n",msec,p->x,p->y);
1023 * @brief Calculate movement vector and timing of the gesture.
1024 * @param in this gui context
1025 * @param in msec time in milliseconds to find gesture within
1026 * @param out p0 pointer to the point object, where gesture starting point coordinates should be placed. Can be NULL.
1027 * @param out dx pointer to variable to store horizontal movement of the gesture.
1028 * @param out dy pointer to variable to store vertical movement of the gesture.
1029 * @returns amount of time the actual movement took.
1031 static int gui_internal_gesture_get_vector(struct gui_priv *this, int msec, struct point *p0, int *dx, int *dy)
1033 struct gesture_elem *g;
1046 g=gui_internal_gesture_ring_get(this,0);
1055 dbg(2,"%d %d %d\n",g->msec, g->p.x, g->p.y);
1056 for(i=1;(g=gui_internal_gesture_ring_get(this,i))!=NULL;i++) {
1057 if( msec-g->msec > 1000 )
1060 if(dx) *dx=x-g->p.x;
1061 if(dy) *dy=y-g->p.y;
1065 dbg(2,"%d %d %d\n",g->msec, g->p.x, g->p.y);
1070 static int gui_internal_gesture_do(struct gui_priv *this)
1075 dt=gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
1077 if( abs(dx) > this->icon_s*3 && abs(dy) < this->icon_s ) {
1079 dbg(1,"horizontal dx=%d dy=%d\n",dx,dy);
1081 /* Prevent swiping if widget was scrolled beforehand */
1082 if(this->pressed==2)
1085 for(wt=this->highlighted;wt && wt->type!=widget_table;wt=wt->parent);
1086 if(!wt || wt->type!=widget_table || !wt->data)
1088 if(this->highlighted) {
1089 this->highlighted->state &= ~STATE_HIGHLIGHTED;
1090 this->highlighted=NULL;
1093 gui_internal_table_button_next(this,NULL,wt);
1095 gui_internal_table_button_prev(this,NULL,wt);
1097 } else if( abs(dy) > this->icon_s*3 && abs(dx) < this->icon_s ) {
1098 dbg(1,"vertical dx=%d dy=%d\n",dx,dy);
1099 } else if (dt>300 && abs(dx) <this->icon_s && abs(dy) <this->icon_s ) {
1100 dbg(1,"longtap dx=%d dy=%d\n",dx,dy);
1102 dbg(1,"none dx=%d dy=%d\n",dx,dy);
1109 static void gui_internal_motion_cb(struct gui_priv *this)
1111 this->motion_timeout_event=NULL;
1112 gui_internal_gesture_ring_add(this, &(this->current));
1114 /* Check for scrollable table below the highligted item if there's a movement with the button pressed */
1115 if (this->pressed && this->highlighted) {
1116 struct widget *wt=NULL;
1117 struct widget *wr=NULL;
1120 /* Guard against accidental scrolling when user is likely going to swipe */
1121 gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
1122 if(abs(dx)>abs(dy) || abs(dy)<this->icon_s)
1125 if(this->highlighted)
1126 for(wr=this->highlighted;wr && wr->type!=widget_table_row;wr=wr->parent);
1130 if(wt && wt->type==widget_table && (wt->state & STATE_SCROLLABLE)) {
1131 struct table_data *td=wt->data;
1141 if(this->current.y < wr->p.y && wr!=td->top_row->data ) {
1142 int n=(wr->p.y-this->current.y)/wr->h+1;
1147 while(n-->0 && (tbtm=gui_internal_widget_table_next_row(btm))!=NULL && (ttop=gui_internal_widget_table_next_row(top))!=NULL) {
1154 } else if (this->current.y > wr->p.y + wr->h ) {
1155 int y=wt->p.y+wt->h-wr->h;
1158 if(td->button_box && td->button_box->p.y!=0)
1159 y=td->button_box->p.y - td->button_box->h;
1161 if(y>this->current.y)
1164 n=(y - wr->p.y )/wr->h;
1169 while(n-->0 && (ttop=gui_internal_widget_table_prev_row(top))!=NULL && (tbtm=gui_internal_widget_table_prev_row(btm))!=NULL) {
1177 if( top && btm && (td->top_row!=top || td->bottom_row!=btm) ) {
1178 gui_internal_table_hide_rows(wt->data);
1181 graphics_draw_mode(this->gra, draw_mode_begin);
1182 gui_internal_widget_render(this,wt);
1183 graphics_draw_mode(this->gra, draw_mode_end);
1190 /* Else, just move highlight after pointer if there's nothing to scroll */
1191 gui_internal_highlight(this);
1194 static struct widget *
1195 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
1197 struct widget *widget=g_new0(struct widget, 1);
1200 widget->text=g_strdup(label);
1201 widget->type=widget_box;
1202 widget->flags=flags;
1206 static struct widget *
1207 gui_internal_box_new(struct gui_priv *this, enum flags flags)
1209 return gui_internal_box_new_with_label(this, flags, NULL);
1213 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
1218 gui_internal_background_render(this, w);
1221 w->foreground=this->foreground;
1224 if (w->foreground && w->border) {
1225 struct point pnt[5];
1227 pnt[1].x=pnt[0].x+w->w;
1229 pnt[2].x=pnt[0].x+w->w;
1230 pnt[2].y=pnt[0].y+w->h;
1232 pnt[3].y=pnt[0].y+w->h;
1234 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
1235 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
1236 graphics_gc_set_linewidth(w->foreground, 1);
1243 gui_internal_widget_render(this, wc);
1250 * @brief Compute the size and location for the widget.
1254 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
1257 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;
1259 int orientation=w->flags & 0xffff0000;
1264 if ( this->root.w > this->root.h )
1274 * count the number of children
1281 if (orientation == orientation_horizontal_vertical && count <= cols)
1282 orientation=orientation_horizontal;
1283 switch (orientation) {
1284 case orientation_horizontal:
1286 * For horizontal orientation:
1287 * pack each child and find the largest height and
1288 * compute the total width. x spacing (spx) is considered
1290 * If any children want to be expanded
1291 * we keep track of this
1296 gui_internal_widget_pack(this, wc);
1300 if (wc->flags & flags_expand)
1301 expand+=wc->w ? wc->w : 1;
1307 if (expand && w->w) {
1308 expandd=w->w-width+expand;
1313 case orientation_vertical:
1315 * For vertical layouts:
1316 * We pack each child and compute the largest width and
1317 * the total height. y spacing (spy) is considered
1319 * If the expand flag is set then teh expansion amount
1325 gui_internal_widget_pack(this, wc);
1329 if (wc->flags & flags_expand)
1330 expand+=wc->h ? wc->h : 1;
1336 if (expand && w->h) {
1337 expandd=w->h-height+expand;
1342 case orientation_horizontal_vertical:
1344 * For horizontal_vertical orientation
1345 * pack the children.
1346 * Compute the largest height and largest width.
1347 * Layout the widgets based on having the
1348 * number of columns specified by (cols)
1354 gui_internal_widget_pack(this, wc);
1364 rows=(count+cols-1)/cols;
1367 width+=w->spx*(cols-1);
1368 height+=w->spy*(rows-1);
1375 * No orientation was specified.
1376 * width and height are both 0.
1377 * The width & height of this widget
1381 dbg(0,"Warning width and height of a widget are 0");
1384 if (! w->w && ! w->h) {
1385 w->w=w->bl+w->br+width;
1386 w->h=w->bt+w->bb+height;
1395 * At this stage the width and height of this
1396 * widget has been computed.
1397 * We now make a second pass assigning heights,
1398 * widths and coordinates to each child widget.
1401 if (w->flags & gravity_left)
1403 if (w->flags & gravity_xcenter)
1404 x=w->p.x+w->w/2-owidth/2;
1405 if (w->flags & gravity_right)
1406 x=w->p.x+w->w-w->br-owidth;
1407 if (w->flags & gravity_top)
1409 if (w->flags & gravity_ycenter)
1410 y=w->p.y+w->h/2-oheight/2;
1411 if (w->flags & gravity_bottom)
1412 y=w->p.y+w->h-w->bb-oheight;
1414 switch (orientation) {
1415 case orientation_horizontal:
1420 if (wc->flags & flags_fill)
1422 if (wc->flags & flags_expand) {
1425 wc->w=wc->w*expandd/expand;
1427 if (w->flags & gravity_top)
1429 if (w->flags & gravity_ycenter)
1431 if (w->flags & gravity_bottom)
1437 case orientation_vertical:
1442 if (wc->flags & flags_fill)
1444 if (wc->flags & flags_expand) {
1447 wc->h=wc->h*expandd/expand;
1449 if (w->flags & gravity_left)
1451 if (w->flags & gravity_xcenter)
1453 if (w->flags & gravity_right)
1459 case orientation_horizontal_vertical:
1469 if (wc->flags & flags_fill) {
1473 if (w->flags & gravity_left)
1475 if (w->flags & gravity_xcenter)
1476 wc->p.x=x+(width-wc->w)/2;
1477 if (w->flags & gravity_right)
1478 wc->p.x=x+width-wc->w;
1479 if (w->flags & gravity_top)
1481 if (w->flags & gravity_ycenter)
1482 wc->p.y=y+(height-wc->h)/2;
1483 if (w->flags & gravity_bottom)
1484 wc->p.y=y-height-wc->h;
1486 if (++count == cols) {
1498 * Call pack again on each child,
1499 * the child has now had its size and coordinates
1500 * set so they can repack their children.
1505 gui_internal_widget_pack(this, wc);
1511 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1519 gui_internal_widget_reset_pack(this, wc);
1529 gui_internal_widget_append(struct widget *parent, struct widget *child)
1533 if (! child->background)
1534 child->background=parent->background;
1535 parent->children=g_list_append(parent->children, child);
1536 child->parent=parent;
1539 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1541 if (! child->background)
1542 child->background=parent->background;
1543 parent->children=g_list_prepend(parent->children, child);
1544 child->parent=parent;
1547 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child)
1550 if (! child->background)
1551 child->background=parent->background;
1554 sib=g_list_find(parent->children,sibling);
1555 parent->children=g_list_insert_before(parent->children, sib, child);
1556 child->parent=parent;
1559 static void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func)
1561 if (! child->background)
1562 child->background=parent->background;
1564 parent->children=g_list_insert_sorted(parent->children, child, func);
1565 child->parent=parent;
1569 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1577 gui_internal_widget_destroy(this, wc);
1580 g_list_free(w->children);
1585 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1587 gui_internal_widget_children_destroy(this, w);
1592 graphics_image_free(this->gra, w->img);
1598 w->data_free(w->data);
1599 if (w->cb && w->remove_cb)
1600 w->remove_cb(w->instance, w->cb);
1601 if (w==this->highlighted)
1602 this->highlighted=NULL;
1611 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1613 if(w->p.x > this->root.w || w->p.y > this->root.h)
1618 gui_internal_box_render(this, w);
1621 gui_internal_label_render(this, w);
1624 gui_internal_image_render(this, w);
1627 gui_internal_table_render(this,w);
1635 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1639 gui_internal_box_pack(this, w);
1642 gui_internal_table_pack(this,w);
1648 //##############################################################################################################
1651 //# Authors: Martin Schaller (04/2008)
1652 //##############################################################################################################
1653 static void gui_internal_call_highlighted(struct gui_priv *this)
1655 if (! this->highlighted || ! this->highlighted->func)
1657 this->highlighted->reason=gui_internal_reason_click;
1658 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1662 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1664 char *text=w->speech;
1672 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1673 navit_say(this->nav, text);
1679 gui_internal_menu_destroy(struct gui_priv *this, struct widget *w)
1681 struct menu_data *menu_data=w->menu_data;
1683 if (menu_data->refresh_callback_obj.type) {
1684 struct object_func *func;
1685 func=object_func_lookup(menu_data->refresh_callback_obj.type);
1686 if (func && func->remove_attr)
1687 func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
1689 if (menu_data->refresh_callback.u.callback)
1690 callback_destroy(menu_data->refresh_callback.u.callback);
1692 g_free(menu_data->href);
1695 gui_internal_widget_destroy(this, w);
1696 this->root.children=g_list_remove(this->root.children, w);
1700 gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render)
1703 struct widget *wr,*wd;
1704 gui_internal_search_idle_end(this);
1705 while ((l = g_list_last(this->root.children))) {
1708 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1711 gui_internal_say(this, w, 0);
1712 redisplay=w->menu_data->redisplay;
1713 wr=w->menu_data->redisplay_widget;
1714 if (!w->menu_data->redisplay && !w->menu_data->href) {
1715 gui_internal_widget_render(this, w);
1719 gui_internal_menu_destroy(this, w);
1720 redisplay(this, wr, wr->data);
1722 char *href=g_strdup(w->menu_data->href);
1723 gui_internal_menu_destroy(this, w);
1724 gui_internal_html_load_href(this, href, 0);
1729 gui_internal_menu_destroy(this, wd);
1734 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1736 gui_internal_prune_menu_do(this, w, 1);
1740 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1742 GList *l=g_list_last(this->root.children);
1743 struct widget *w=NULL;
1744 while (l && count-- > 0)
1745 l=g_list_previous(l);
1748 gui_internal_prune_menu_do(this, w, render);
1753 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1755 gui_internal_prune_menu_count(this, 1, 1);
1759 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1761 gui_internal_prune_menu(this, wm->data);
1765 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1767 graphics_draw_mode(this->gra, draw_mode_begin);
1768 gui_internal_back(this, NULL, NULL);
1769 graphics_draw_mode(this->gra, draw_mode_end);
1770 gui_internal_check_exit(this);
1774 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1776 gui_internal_prune_menu(this, NULL);
1780 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1782 struct widget *w=this->root.children->data;
1783 if (w && w->menu_data && w->menu_data->href && !strcmp(w->menu_data->href,"#Main Menu"))
1784 gui_internal_prune_menu(this, w);
1786 gui_internal_html_main_menu(this);
1789 static struct widget *
1790 gui_internal_top_bar(struct gui_priv *this)
1792 struct widget *w,*wm,*wh,*wc,*wcn;
1793 int dots_len, sep_len;
1795 int width,width_used=0,use_sep=0,incomplete=0;
1796 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1798 1:Don't expand bar to screen width
1799 2:Don't show Map Icon
1800 4:Don't show Home Icon
1801 8:Show only current menu
1802 16:Don't use menu titles as button
1803 32:Show navit version
1806 256:Use background for menu headline
1807 512:Set osd_configuration and zoom to route when setting position
1808 1024:Don't show back button
1809 2048:No highlighting of keyboard
1812 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1813 w->bl=this->spacing;
1814 w->spx=this->spacing;
1815 w->background=this->background2;
1816 if ((this->flags & 6) == 6) {
1822 width=this->root.w-w->bl;
1823 if (! (this->flags & 2)) {
1824 wm=gui_internal_button_new_with_callback(this, NULL,
1825 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1826 gui_internal_cmd_return, NULL);
1827 wm->speech=g_strdup(_("Back to map"));
1828 gui_internal_widget_pack(this, wm);
1829 gui_internal_widget_append(w, wm);
1832 if (! (this->flags & 4)) {
1833 wh=gui_internal_button_new_with_callback(this, NULL,
1834 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1835 gui_internal_cmd_main_menu, NULL);
1836 wh->speech=g_strdup(_("Main Menu"));
1837 gui_internal_widget_pack(this, wh);
1838 gui_internal_widget_append(w, wh);
1841 if (!(this->flags & 6))
1843 l=g_list_last(this->root.children);
1844 wcn=gui_internal_label_new(this,".. »");
1845 wcn->foreground=foreground;
1847 gui_internal_widget_destroy(this, wcn);
1848 wcn=gui_internal_label_new(this,"»");
1849 wcn->foreground=foreground;
1851 gui_internal_widget_destroy(this, wcn);
1853 if (g_list_previous(l) || !g_list_next(l)) {
1855 wcn=gui_internal_label_new(this, wc->text);
1856 wcn->foreground=foreground;
1861 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1862 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1864 gui_internal_widget_destroy(this, wcn);
1868 struct widget *wct=gui_internal_label_new(this, "»");
1869 wct->foreground=foreground;
1870 res=g_list_prepend(res, wct);
1871 width_used+=sep_len+w->spx;
1874 if (!(this->flags & 16)) {
1875 wcn->func=gui_internal_cmd_return;
1877 wcn->state |= STATE_SENSITIVE;
1879 res=g_list_prepend(res, wcn);
1880 if (this->flags & 8)
1883 l=g_list_previous(l);
1887 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1888 wcn->foreground=foreground;
1889 wcn->func=gui_internal_cmd_return;
1891 wcn->state |= STATE_SENSITIVE;
1892 res=g_list_prepend(res, wcn);
1893 l=g_list_previous(l);
1897 wcn=gui_internal_label_new(this, ".. »");
1898 wcn->foreground=foreground;
1899 wcn->func=gui_internal_cmd_return;
1901 wcn->state |= STATE_SENSITIVE;
1902 res=g_list_prepend(res, wcn);
1907 gui_internal_widget_append(w, l->data);
1910 if (this->flags & 32) {
1911 char *version_text=g_strdup_printf("Navit %s",version);
1912 wcn=gui_internal_label_new(this, version_text);
1913 g_free(version_text);
1914 wcn->flags=gravity_right_center|flags_expand;
1915 gui_internal_widget_append(w, wcn);
1919 gui_internal_widget_destroy(this, dots);
1924 static struct widget *
1925 gui_internal_time_help(struct gui_priv *this)
1927 struct widget *w,*wc,*wcn;
1932 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1933 w->bl=this->spacing;
1934 w->spx=this->spacing;
1940 if (this->flags & 64) {
1941 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1947 tm=localtime(&timep);
1948 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1949 wcn=gui_internal_label_new(this, timestr);
1950 gui_internal_widget_append(wc, wcn);
1951 gui_internal_widget_append(w, wc);
1953 if (this->flags & 128) {
1954 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1955 gui_internal_widget_append(w, wcn);
1962 * Applys the configuration values to this based on the settings
1963 * specified in the configuration file (this->config) and
1964 * the most approriate default profile based on screen resolution.
1966 * This function should be run after this->root is setup and could
1967 * be rerun after the window is resized.
1969 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1971 static void gui_internal_apply_config(struct gui_priv *this)
1973 struct gui_config_settings * current_config=0;
1975 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1977 * Select default values from profile based on the screen.
1979 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1981 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1983 current_config = &config_profiles[LARGE_PROFILE];
1987 current_config = &config_profiles[MEDIUM_PROFILE];
1992 current_config = &config_profiles[SMALL_PROFILE];
1996 * Apply override values from config file
1998 if(this->config.font_size == -1 )
2000 this->font_size = current_config->font_size;
2004 this->font_size = this->config.font_size;
2007 if(this->config.icon_xs == -1 )
2009 this->icon_xs = current_config->icon_xs;
2013 this->icon_xs = this->config.icon_xs;
2016 if(this->config.icon_s == -1 )
2018 this->icon_s = current_config->icon_s;
2022 this->icon_s = this->config.icon_s;
2024 if(this->config.icon_l == -1 )
2026 this->icon_l = current_config->icon_l;
2030 this->icon_l = this->config.icon_l;
2032 if(this->config.spacing == -1 )
2034 this->spacing = current_config->spacing;
2038 this->spacing = current_config->spacing;
2043 static struct widget *
2044 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
2046 struct widget *wl,*wlb;
2047 struct widget *wb=gui_internal_menu_data(this)->button_bar;
2048 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
2049 wl=gui_internal_label_new(this, label);
2051 wlb->foreground=this->text_foreground;
2056 gui_internal_widget_append(wlb, wl);
2058 gui_internal_widget_prepend(wb, wlb);
2060 gui_internal_widget_append(wb, wlb);
2066 static struct widget *
2067 gui_internal_menu(struct gui_priv *this, const char *label)
2069 struct widget *menu,*w,*w1,*topbox;
2071 gui_internal_search_idle_end(this);
2072 topbox=gui_internal_box_new_with_label(this, 0, label);
2073 topbox->w=this->root.w;
2074 topbox->h=this->root.h;
2075 gui_internal_widget_append(&this->root, topbox);
2076 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
2077 menu->w=this->root.w;
2078 menu->h=this->root.h;
2079 menu->background=this->background;
2080 gui_internal_apply_config(this);
2081 if (!this->fonts[0]) {
2082 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
2083 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
2084 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
2086 topbox->menu_data=g_new0(struct menu_data, 1);
2087 gui_internal_widget_append(topbox, menu);
2088 w=gui_internal_top_bar(this);
2089 gui_internal_widget_append(menu, w);
2090 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
2091 w->spx=4*this->spacing;
2093 gui_internal_widget_append(menu, w);
2094 if (this->flags & 16 && !(this->flags & 1024)) {
2095 struct widget *wlb,*wb,*wm=w;
2096 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
2097 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
2098 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
2099 gui_internal_widget_append(wm, w);
2100 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
2106 topbox->menu_data->button_bar=wb;
2107 gui_internal_widget_append(wm, wb);
2108 wlb=gui_internal_button_label(this,_("Back"),1);
2109 wlb->func=gui_internal_back;
2110 wlb->state |= STATE_SENSITIVE;
2112 if (this->flags & 192) {
2113 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
2114 menu->w=this->root.w;
2115 menu->h=this->root.h;
2116 w1=gui_internal_time_help(this);
2117 gui_internal_widget_append(menu, w1);
2118 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
2119 gui_internal_widget_append(menu, w1);
2120 gui_internal_widget_append(topbox, menu);
2121 menu->background=NULL;
2123 gui_internal_widget_pack(this, topbox);
2124 gui_internal_widget_reset_pack(this, topbox);
2125 topbox->w=this->root.w;
2126 topbox->h=this->root.h;
2127 menu->w=this->root.w;
2128 menu->h=this->root.h;
2132 static struct menu_data *
2133 gui_internal_menu_data(struct gui_priv *this)
2136 struct widget *menu;
2138 l=g_list_last(this->root.children);
2140 return menu->menu_data;
2144 gui_internal_menu_reset_pack(struct gui_priv *this)
2147 struct widget *top_box;
2149 l=g_list_last(this->root.children);
2151 gui_internal_widget_reset_pack(this, top_box);
2155 gui_internal_menu_render(struct gui_priv *this)
2158 struct widget *menu;
2160 l=g_list_last(this->root.children);
2162 gui_internal_say(this, menu, 0);
2163 gui_internal_widget_pack(this, menu);
2164 gui_internal_widget_render(this, menu);
2168 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
2171 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
2172 navit_set_destination(this->nav, &wm->c, name, 1);
2173 if (this->flags & 512) {
2175 follow.type=attr_follow;
2177 navit_set_attr(this->nav, &this->osd_configuration);
2178 navit_set_attr(this->nav, &follow);
2179 navit_zoom_to_route(this->nav, 0);
2181 gui_internal_prune_menu(this, NULL);
2185 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
2189 v.type=attr_vehicle;
2191 navit_set_attr(this->nav, &v);
2193 navit_set_position(this->nav, &wm->c);
2194 gui_internal_prune_menu(this, NULL);
2198 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
2202 dbg(0,"text='%s'\n", widget->text);
2203 if (widget->text && strlen(widget->text)){
2204 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2205 bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
2207 g_free(widget->text);
2209 l=g_list_previous(g_list_last(this->root.children));
2210 gui_internal_prune_menu(this, l->data);
2214 gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
2218 dbg(0,"text='%s'\n", widget->text);
2219 if (widget->text && strlen(widget->text)){
2220 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2221 bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
2223 g_free(widget->text);
2225 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2226 gui_internal_prune_menu(this, l->data);
2230 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
2232 gui_internal_cmd_add_bookmark_do(this, widget->data);
2236 gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
2238 gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
2242 gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
2244 struct widget *w=(struct widget*)widget->data;
2247 dbg(0,"text='%s'\n", w->text);
2248 if (w->text && strlen(w->text)){
2249 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2250 bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
2256 l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
2257 gui_internal_prune_menu(this, l->data);
2261 * @brief Generic notification function for Editable widgets to call Another widget notification function when Enter is pressed in editable field.
2262 * The Editable widget should have data member pointing to the Another widget.
2265 gui_internal_call_linked_on_finish(struct gui_priv *this, struct widget *wm, void *data)
2267 if (wm->reason==gui_internal_reason_keypress_finish && data) {
2268 struct widget *w=data;
2270 w->func(this, w, w->data);
2274 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
2277 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
2279 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2281 wb=gui_internal_menu(this,_("Add Bookmark"));
2282 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2283 gui_internal_widget_append(wb, w);
2284 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2285 gui_internal_widget_append(w, we);
2286 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2287 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2288 wk->background=this->background;
2289 wk->flags |= flags_expand|flags_fill;
2290 wk->func = gui_internal_call_linked_on_finish;
2292 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2293 wnext->state |= STATE_SENSITIVE;
2294 wnext->func = gui_internal_cmd_add_bookmark_clicked;
2297 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2298 gui_internal_widget_append(w, wl);
2300 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2301 gui_internal_menu_render(this);
2305 gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
2307 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2309 wb=gui_internal_menu(this,_("Add Bookmark folder"));
2310 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2311 gui_internal_widget_append(wb, w);
2312 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2313 gui_internal_widget_append(w, we);
2314 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2315 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2316 wk->background=this->background;
2317 wk->flags |= flags_expand|flags_fill;
2318 wk->func = gui_internal_call_linked_on_finish;
2320 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2321 wnext->state |= STATE_SENSITIVE;
2322 wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
2325 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2326 gui_internal_widget_append(w, wl);
2328 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2329 gui_internal_menu_render(this);
2333 gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2335 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2336 char *name=wm->text;
2337 wb=gui_internal_menu(this,_("Rename"));
2338 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2339 gui_internal_widget_append(wb, w);
2340 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2341 gui_internal_widget_append(w, we);
2342 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2343 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2344 wk->background=this->background;
2345 wk->flags |= flags_expand|flags_fill;
2346 wk->func = gui_internal_call_linked_on_finish;
2348 wk->name=g_strdup(name);
2349 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2350 wnext->state |= STATE_SENSITIVE;
2351 wnext->func = gui_internal_cmd_rename_bookmark_clicked;
2354 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2355 gui_internal_widget_append(w, wl);
2357 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2358 gui_internal_menu_render(this);
2362 gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2366 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2367 bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
2368 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2369 gui_internal_prune_menu(this, l->data);
2373 gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2377 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2378 bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
2379 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2380 gui_internal_prune_menu(this, l->data);
2384 gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2388 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2389 bookmarks_paste_bookmark(mattr.u.bookmarks);
2390 l=g_list_previous(g_list_last(this->root.children));
2391 gui_internal_prune_menu(this, l->data);
2395 gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2399 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2400 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
2401 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2402 gui_internal_prune_menu(this, l->data);
2406 gui_internal_cmd_delete_bookmark_folder(struct gui_priv *this, struct widget *wm, void *data)
2410 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2411 bookmarks_move_up(mattr.u.bookmarks);
2412 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->prefix);
2413 l=g_list_first(this->root.children);
2414 gui_internal_prune_menu(this, l->data);
2418 gui_internal_cmd_load_bookmarks_as_waypoints(struct gui_priv *this, struct widget *wm, void *data)
2422 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
2427 enum projection pro=bookmarks_get_projection(mattr.u.bookmarks);
2430 navit_set_destination(this->nav, NULL, NULL, 0);
2432 bm_count=bookmarks_get_bookmark_count(mattr.u.bookmarks);
2433 pc=g_alloca(bm_count*sizeof(struct pcoord));
2434 bookmarks_item_rewind(mattr.u.bookmarks);
2436 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
2437 if (!item_attr_get(item, attr_label, &attr))
2439 if (item->type == type_bookmark) {
2440 if (item_coord_get(item, &c, 1)) {
2451 navit_set_destinations(this->nav, pc, bm_count, wm->prefix, 1);
2452 if (this->flags & 512) {
2454 follow.type=attr_follow;
2456 navit_set_attr(this->nav, &this->osd_configuration);
2457 navit_set_attr(this->nav, &follow);
2458 navit_zoom_to_route(this->nav, 0);
2463 gui_internal_prune_menu(this, NULL);
2467 gui_internal_cmd_replace_bookmarks_from_waypoints(struct gui_priv *this, struct widget *wm, void *data)
2471 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
2477 if (bookmarks_get_bookmark_count(mattr.u.bookmarks)>0){
2479 bookmarks_item_rewind(mattr.u.bookmarks);
2481 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
2483 if (!item_attr_get(item, attr_label, &attr))
2486 if (item->type == type_bookmark)
2487 bookmarks_delete_bookmark(mattr.u.bookmarks, attr.u.str);
2489 bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
2492 bookmarks_item_rewind(mattr.u.bookmarks);
2494 bm_count=navit_get_destination_count(this->nav);
2495 pc=g_alloca(bm_count*sizeof(struct pcoord));
2496 navit_get_destinations(this->nav, pc, bm_count);
2498 for (i=0; i<bm_count; i++){
2499 desc=g_strdup_printf("%s WP%d", navit_get_destination_description(this->nav, i), i+1);
2500 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2501 bookmarks_add_bookmark(attr.u.bookmarks, &pc[i], desc);
2502 bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
2507 gui_internal_prune_menu(this, NULL);
2511 get_direction(char *buffer, int angle, int mode)
2516 sprintf(buffer,"%d",angle);
2519 if (angle < 69 || angle > 291)
2521 if (angle > 111 && angle < 249)
2523 if (angle > 22 && angle < 158)
2525 if (angle > 202 && angle < 338)
2530 angle=(angle+15)/30;
2533 sprintf(buffer,"%d H", angle);
2538 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2543 enum item_type *types;
2545 static enum item_type selectors_BankTypes[]={type_poi_bank,type_poi_bank, type_poi_atm,type_poi_atm, type_none};
2546 static enum item_type selectors_FuelTypes[]={type_poi_fuel,type_poi_fuel,type_none};
2547 static enum item_type selectors_HotelTypes[]={type_poi_hotel,type_poi_camp_rv,type_poi_camping,type_poi_camping,
2548 type_poi_resort,type_poi_resort,type_poi_motel,type_poi_hostel,type_none};
2549 static enum item_type selectors_RestaurantTypes[]={type_poi_bar,type_poi_picnic,type_poi_burgerking,type_poi_fastfood,
2550 type_poi_restaurant,type_poi_restaurant,type_poi_cafe,type_poi_cafe,type_poi_pub,type_poi_pub,type_none};
2551 static enum item_type selectors_ShoppingTypes[]={type_poi_mall,type_poi_mall,type_poi_shop_grocery,type_poi_shop_grocery,
2552 type_poi_shopping,type_poi_shopping,type_poi_shop_butcher,type_poi_shop_baker,type_poi_shop_fruit,
2553 type_poi_shop_fruit,type_poi_shop_beverages,type_poi_shop_beverages,type_none};
2554 static enum item_type selectors_ServiceTypes[]={type_poi_marina,type_poi_marina,type_poi_hospital,type_poi_hospital,
2555 type_poi_public_utilities,type_poi_public_utilities,type_poi_police,type_poi_autoservice,type_poi_information,
2556 type_poi_information,type_poi_pharmacy,type_poi_pharmacy,type_poi_personal_service,type_poi_repair_service,
2557 type_poi_restroom,type_poi_restroom,type_none};
2558 static enum item_type selectors_ParkingTypes[]={type_poi_car_parking,type_poi_car_parking,type_none};
2559 static enum item_type selectors_LandFeaturesTypes[]={type_poi_land_feature,type_poi_rock,type_poi_dam,type_poi_dam,
2560 type_poi_peak,type_poi_peak,type_none};
2561 static enum item_type selectors_OtherTypes[]={type_point_unspecified,type_poi_land_feature-1,type_poi_rock+1,type_poi_fuel-1,
2562 type_poi_marina+1,type_poi_shopping-1,type_poi_shopping+1,type_poi_car_parking-1,type_poi_car_parking+1,
2563 type_poi_bar-1,type_poi_bank+1,type_poi_dam-1,type_poi_dam+1,type_poi_information-1,type_poi_information+1,
2564 type_poi_mall-1,type_poi_mall+1,type_poi_personal_service-1,type_poi_pharmacy+1,type_poi_repair_service-1,
2565 type_poi_repair_service+1,type_poi_restaurant-1,type_poi_restaurant+1,type_poi_restroom-1,type_poi_restroom+1,
2566 type_poi_shop_grocery-1,type_poi_shop_grocery+1,type_poi_peak-1,type_poi_peak+1,type_poi_motel-1,type_poi_hostel+1,
2567 type_poi_shop_butcher-1,type_poi_shop_baker+1,type_poi_shop_fruit-1,type_poi_shop_fruit+1,type_poi_shop_beverages-1,
2568 type_poi_shop_beverages+1,type_poi_pub-1,type_poi_atm+1,type_line-1,type_none};
2569 /*static enum item_type selectors_UnknownTypes[]={type_point_unkn,type_point_unkn,type_none};*/
2570 struct selector selectors[]={
2571 {"bank","Bank",selectors_BankTypes},
2572 {"fuel","Fuel",selectors_FuelTypes},
2573 {"hotel","Hotel",selectors_HotelTypes},
2574 {"restaurant","Restaurant",selectors_RestaurantTypes},
2575 {"shopping","Shopping",selectors_ShoppingTypes},
2576 {"hospital","Service",selectors_ServiceTypes},
2577 {"parking","Parking",selectors_ParkingTypes},
2578 {"peak","Land Features",selectors_LandFeaturesTypes},
2579 {"unknown","Other",selectors_OtherTypes},
2580 /* {"unknown","Unknown",selectors_UnknownTypes},*/
2585 * Get a utf-8 string, return the same prepared for case insensetive search. Result shoud be g_free()d after use.
2592 r=g_utf8_casefold(s,-1);
2597 * POI search/filtering parameters.
2604 * =1 if selnb is defined, 0 otherwize.
2609 * Index to struct selector selectors[], shows what type of POIs is defined.
2611 unsigned char selnb;
2613 * Page number to display.
2615 unsigned char pagenb;
2617 * Radius (number of 10-kilometer intervals) to search for POIs.
2621 * Should filter phrase be compared to postal address of the POI.
2622 * =1 - address filter, =0 - name filter
2624 unsigned char isAddressFilter;
2626 * Filter string, casefold()ed and divided into substrings at the spaces, which are replaced by ASCII 0*.
2630 * list of pointers to individual substrings of filterstr.
2634 * Number of POIs in this list
2641 * @brief Free poi_param structure.
2643 * @param p reference to the object to be freed.
2646 gui_internal_poi_param_free(void *p)
2648 if(((struct poi_param *)p)->filterstr)
2649 g_free(((struct poi_param *)p)->filterstr);
2650 if(((struct poi_param *)p)->filter)
2651 g_list_free(((struct poi_param *)p)->filter);
2656 * @brief Clone poi_param structure.
2658 * @param p reference to the object to be cloned.
2659 * @return Cloned object reference.
2661 static struct poi_param *
2662 gui_internal_poi_param_clone(struct poi_param *p)
2664 struct poi_param *r=g_new(struct poi_param,1);
2666 memcpy(r,p,sizeof(struct poi_param));
2670 char *last=g_list_last(l)->data;
2671 int len=(last - p->filterstr) + strlen(last)+1;
2672 r->filterstr=g_memdup(p->filterstr,len);
2675 r->filter=g_list_append(r->filter, r->filterstr + ((char*)(l->data) - p->filterstr) );
2682 * @brief Set POIs filter data in poi_param structure.
2683 * @param param poi_param structure with unset filter data.
2684 * @param text filter text.
2687 gui_internal_poi_param_set_filter(struct poi_param *param, char *text)
2691 param->filterstr=removecase(text);
2692 s1=param->filterstr;
2694 s2=g_utf8_strchr(s1,-1,' ');
2697 param->filter=g_list_append(param->filter,s1);
2707 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2708 static void gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data);
2711 static struct widget *
2712 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb)
2714 struct widget *wl,*wb;
2717 //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2718 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
2719 wl->background=this->background;
2721 wl->cols=this->root.w/this->icon_s;
2722 nitems=sizeof(selectors)/sizeof(struct selector);
2723 nrows=nitems/wl->cols + (nitems%wl->cols>0);
2724 wl->h=this->icon_l*nrows;
2725 for (i = 0 ; i < nitems ; i++) {
2726 struct poi_param *p=g_new0(struct poi_param,1);
2733 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2734 image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2735 gui_internal_cmd_pois, p));
2737 wb->data_free=gui_internal_poi_param_free;
2741 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2742 image_new_s(this, "gui_search"), gravity_left_center|orientation_vertical,
2743 gui_internal_cmd_pois_filter, NULL));
2747 gui_internal_widget_pack(this,wl);
2752 * @brief Get icon for given POI type.
2754 * @param this pointer to gui context
2755 * @param type POI type
2756 * @return Pointer to graphics_image object, or NULL if no picture available.
2758 static struct graphics_image * gui_internal_poi_icon(struct gui_priv *this, enum item_type type)
2762 navit_get_attr(this->nav, attr_layout, &layout, NULL);
2763 layer=layout.u.layout->layers;
2765 GList *itemgra=((struct layer *)layer->data)->itemgras;
2767 GList *types=((struct itemgra *)itemgra->data)->type;
2769 if((long)types->data==type) {
2770 GList *element=((struct itemgra *)itemgra->data)->elements;
2772 struct element * el=element->data;
2773 if(el->type==element_icon) {
2774 struct graphics_image *img;
2775 char *icon=g_strdup(el->u.icon.src);
2776 char *dot=g_strrstr(icon,".");
2777 dbg(0,"%s %s\n", item_to_name(type),icon);
2780 img=image_new_xs(this,icon);
2785 element=g_list_next(element);
2788 types=g_list_next(types);
2790 itemgra=g_list_next(itemgra);
2792 layer=g_list_next(layer);
2798 * @brief Widget to display POI item.
2800 * @param this pointer to gui context
2801 * @param center reference to the standing point where angle to be counted from
2802 * @param item POI item reference
2803 * @param c POI coordinates
2804 * @param dist precomputed distance to POI (or -1 if it's not to be displayed)
2805 * @param name POI name
2806 * @return Pointer to new widget.
2808 static struct widget *
2809 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist, char* name)
2811 char distbuf[32]="";
2816 struct graphics_image *icon;
2819 sprintf(distbuf,"%d ", dist/1000);
2821 sprintf(distbuf,"%d.%d ", dist/1000, (dist%1000)/100);
2824 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2830 type=item_to_name(item->type);
2832 icon=gui_internal_poi_icon(this,item->type);
2834 icon=image_new_xs(this,"gui_inactive");
2835 text=g_strdup_printf("%s%s%s %s", distbuf, dirbuf, type, name);
2836 } else if(strlen(name)>0)
2837 text=g_strdup_printf("%s%s%s", distbuf, dirbuf, name);
2839 text=g_strdup_printf("%s%s%s", distbuf, dirbuf, type);
2841 wl=gui_internal_button_new_with_callback(this, text, icon, gravity_left_center|orientation_horizontal|flags_fill, NULL, NULL);
2845 wl->name=g_strdup_printf("%s %s",type,name);
2847 wl->name=g_strdup(type);
2849 wl->func=gui_internal_cmd_position;
2852 wl->state|= STATE_SENSITIVE;
2857 * @brief Get string representation of item address suitable for doing search and for display in POI list.
2859 * @param item reference to item.
2860 * @return Pointer to string representation of address. To be g_free()d after use.
2863 gui_internal_compose_item_address_string(struct item *item)
2865 char *s=g_strdup("");
2867 if(item_attr_get(item, attr_house_number, &attr))
2868 s=g_strjoin(" ",s,attr.u.str,NULL);
2869 if(item_attr_get(item, attr_street_name, &attr))
2870 s=g_strjoin(" ",s,attr.u.str,NULL);
2871 if(item_attr_get(item, attr_street_name_systematic, &attr))
2872 s=g_strjoin(" ",s,attr.u.str,NULL);
2873 if(item_attr_get(item, attr_district_name, &attr))
2874 s=g_strjoin(" ",s,attr.u.str,NULL);
2875 if(item_attr_get(item, attr_town_name, &attr))
2876 s=g_strjoin(" ",s,attr.u.str,NULL);
2877 if(item_attr_get(item, attr_county_name, &attr))
2878 s=g_strjoin(" ",s,attr.u.str,NULL);
2879 if(item_attr_get(item, attr_country_name, &attr))
2880 s=g_strjoin(" ",s,attr.u.str,NULL);
2882 if(item_attr_get(item, attr_address, &attr))
2883 s=g_strjoin(" ",s,"|",attr.u.str,NULL);
2888 gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item)
2890 enum item_type *types;
2891 struct selector *sel = param->sel? &selectors[param->selnb]: NULL;
2892 enum item_type type=item->type;
2895 if (type >= type_line && param->filter==NULL)
2897 if (! sel || !sel->types) {
2901 while (*types != type_none) {
2902 if (item->type >= types[0] && item->type <= types[1]) {
2908 if (param->filter) {
2909 char *long_name, *s;
2911 if (param->isAddressFilter) {
2912 s=gui_internal_compose_item_address_string(item);
2913 } else if (item_attr_get(item, attr_label, &attr)) {
2914 s=g_strdup_printf("%s %s", item_to_name(item->type), attr.u.str);
2916 s=g_strdup(item_to_name(item->type));
2918 long_name=removecase(s);
2920 item_attr_rewind(item);
2922 for(s=long_name,f=param->filter;f && s;f=g_list_next(f)) {
2923 s=strstr(s,f->data);
2926 s=g_utf8_strchr(s,-1,' ');
2943 * @brief Event handler for POIs list "more" element.
2945 * @param this The graphics context.
2946 * @param wm called widget.
2947 * @param data event data.
2950 gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
2952 struct widget *w=g_new0(struct widget,1);
2957 gui_internal_back(this, NULL, NULL);
2958 gui_internal_cmd_pois(this, w, w->data);
2964 * @brief Event to apply POIs text filter.
2966 * @param this The graphics context.
2967 * @param wm called widget.
2968 * @param data event data (pointer to editor widget containg filter text).
2971 gui_internal_cmd_pois_filter_do(struct gui_priv *this, struct widget *wm, void *data)
2973 struct widget *w=data;
2974 struct poi_param *param;
2980 param=gui_internal_poi_param_clone(w->data);
2983 param=g_new0(struct poi_param,1);
2985 param->isAddressFilter=strcmp(wm->name,"AddressFilter")==0;
2987 gui_internal_poi_param_set_filter(param, w->text);
2989 gui_internal_cmd_pois(this,w,param);
2990 gui_internal_poi_param_free(param);
2994 * @brief POIs filter dialog.
2995 * Event to handle '\r' '\n' keys pressed.
3000 gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, void *data)
3002 if (wm->text && wm->reason==gui_internal_reason_keypress_finish) {
3003 gui_internal_cmd_pois_filter_do(this, wm, wm);
3009 * @brief POIs filter dialog.
3011 * @param this The graphics context.
3012 * @param wm called widget.
3013 * @param data event data.
3016 gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data)
3018 struct widget *wb, *w, *wr, *wk, *we;
3019 int keyboard_mode=2;
3020 wb=gui_internal_menu(this,"Filter");
3021 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
3022 gui_internal_widget_append(wb, w);
3023 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3024 gui_internal_widget_append(w, wr);
3025 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3026 gui_internal_widget_append(wr, we);
3028 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3029 wk->state |= STATE_EDIT|STATE_EDITABLE;
3030 wk->func=gui_internal_cmd_pois_filter_changed;
3031 wk->background=this->background;
3032 wk->flags |= flags_expand|flags_fill;
3033 wk->name=g_strdup("POIsFilter");
3035 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3036 wb->state |= STATE_SENSITIVE;
3037 wb->func = gui_internal_cmd_pois_filter_do;
3038 wb->name=g_strdup("NameFilter");
3040 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "post")));
3041 wb->state |= STATE_SENSITIVE;
3042 wb->name=g_strdup("AddressFilter");
3043 wb->func = gui_internal_cmd_pois_filter_do;
3047 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
3048 gui_internal_menu_render(this);
3054 * @brief Do POI search specified by poi_param and display POIs found
3056 * @param this The graphics context.
3057 * @param wm called widget.
3058 * @param data event data, reference to poi_param or NULL.
3061 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
3063 struct map_selection *sel,*selm;
3064 struct coord c,center;
3065 struct mapset_handle *h;
3067 struct map_rect *mr;
3069 struct widget *wi,*w,*w2,*wb, *wtable, *row;
3070 enum projection pro=wm->c.pro;
3071 struct poi_param *param;
3074 struct selector *isel;
3077 // Starting value and increment of count of items to be extracted
3078 const int pagesize = 50;
3079 int maxitem, it = 0, i;
3080 struct item_data *items;
3081 struct fibheap* fh = fh_makekeyheap();
3083 struct table_data *td;
3084 struct widget *wl,*wt;
3086 struct poi_param *paramnew;
3091 param = g_new0(struct poi_param,1);
3095 dist=10000*(param->dist+1);
3096 isel = param->sel? &selectors[param->selnb]: NULL;
3097 pagenb = param->pagenb;
3098 prevdist=param->dist*10000;
3099 maxitem = pagesize*(pagenb+1);
3100 items= g_new0( struct item_data, maxitem);
3103 dbg(0, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i, filterstr = %s, isAddressFilter= %d\n",
3104 param->sel, param->selnb, param->pagenb, param->dist, param->filterstr, param->isAddressFilter);
3106 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
3107 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3108 gui_internal_widget_append(wb, w);
3109 if (!isel && !param->filter)
3110 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
3111 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3112 gui_internal_widget_append(w, w2);
3114 sel=map_selection_rect_new(&wm->c,dist*transform_scale(abs(wm->c.y)+dist*1.5),18);
3117 h=mapset_open(navit_get_mapset(this->nav));
3118 while ((m=mapset_next(h, 1))) {
3119 selm=map_selection_dup_pro(sel, pro, map_projection(m));
3120 mr=map_rect_new(m, selm);
3121 dbg(2,"mr=%p\n", mr);
3123 while ((item=map_rect_get_item(mr))) {
3124 if (gui_internal_cmd_pois_item_selected(param, item) &&
3125 item_coord_get_pro(item, &c, 1, pro) &&
3126 coord_rect_contains(&sel->u.c_rect, &c) &&
3127 (idist=transform_distance(pro, ¢er, &c)) < dist) {
3128 struct item_data *data;
3132 if (item->type==type_house_number) {
3133 label=gui_internal_compose_item_address_string(item);
3134 } else if (item_attr_get(item, attr_label, &attr)) {
3135 label=g_strdup(attr.u.str);
3136 // Buildings which label is equal to addr:housenumber value
3137 // are duplicated by item_house_number. Don't include such
3138 // buildings into the list. This is true for OSM maps created with
3139 // maptool patched with #859 latest patch.
3140 // FIXME: For non-OSM maps, we probably would better don't skip these items.
3141 if(item->type==type_poly_building && item_attr_get(item, attr_house_number, &attr) ) {
3142 if(strcmp(label,attr.u.str)==0) {
3153 data = fh_extractmin(fh);
3154 g_free(data->label);
3157 data = &items[it++];
3163 // Key expression is a workaround to fight
3164 // probable heap collisions when two objects
3165 // are at the same distance. But it destroys
3166 // right order of POIs 2048 km away from cener
3167 // and if table grows more than 1024 rows.
3168 fh_insertkey(fh, -((idist<<10) + cnt++), data);
3170 dist = (-fh_minkey(fh))>>10;
3173 map_rect_destroy(mr);
3175 map_selection_destroy(selm);
3177 map_selection_destroy(sel);
3180 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3183 gui_internal_widget_append(w2,wtable);
3185 // Move items from heap to the table
3188 int key = fh_minkey(fh);
3189 struct item_data *data = fh_extractmin(fh);
3192 dbg(2, "Empty heap: maxitem = %i, it = %i, dist = %i\n", maxitem, it, dist);
3195 dbg(2, "dist1: %i, dist2: %i\n", data->dist, (-key)>>10);
3196 if(i==(it-pagesize*pagenb) && data->dist>prevdist)
3197 prevdist=data->dist;
3198 wi=gui_internal_cmd_pois_item(this, ¢er, &data->item, &data->c, data->dist, data->label);
3202 wi->background=this->background;
3203 row = gui_internal_widget_table_row_new(this,
3206 | orientation_horizontal);
3207 gui_internal_widget_append(row,wi);
3208 row->datai=data->dist;
3209 gui_internal_widget_prepend(wtable,row);
3216 // Add an entry for more POI
3217 row = gui_internal_widget_table_row_new(this,
3220 | orientation_horizontal);
3221 row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
3222 gui_internal_widget_append(wtable,row);
3223 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3224 gui_internal_widget_append(row,wl);
3225 if (it == maxitem) {
3226 paramnew=gui_internal_poi_param_clone(param);
3229 snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (paramnew->pagenb+1)*pagesize);
3230 wt=gui_internal_label_new(this, buffer);
3231 gui_internal_widget_append(wl, wt);
3232 wt->func=gui_internal_cmd_pois_more;
3234 wt->data_free=gui_internal_poi_param_free;
3235 wt->state |= STATE_SENSITIVE;
3238 static int dist[]={1,5,10,0};
3239 wt=gui_internal_label_new(this, "Set distance to");
3240 gui_internal_widget_append(wl, wt);
3241 for(i=0;dist[i];i++) {
3242 paramnew=gui_internal_poi_param_clone(param);
3243 paramnew->dist+=dist[i];
3245 snprintf(buffer, sizeof(buffer), " %i ", 10*(paramnew->dist+1));
3246 wt=gui_internal_label_new(this, buffer);
3247 gui_internal_widget_append(wl, wt);
3248 wt->func=gui_internal_cmd_pois_more;
3250 wt->data_free=gui_internal_poi_param_free;
3251 wt->state |= STATE_SENSITIVE;
3254 wt=gui_internal_label_new(this, "km.");
3255 gui_internal_widget_append(wl, wt);
3258 // Rendering now is needed to have table_data->bottomrow filled in.
3259 gui_internal_menu_render(this);
3261 if(td->bottom_row!=NULL)
3264 while(((struct widget*)td->bottom_row->data)->datai<=prevdist
3265 && (td->next_button->state & STATE_SENSITIVE))
3267 gui_internal_table_button_next(this, td->next_button, NULL);
3270 int firstrow=g_list_index(wtable->children, td->top_row->data);
3271 while(firstrow>=0) {
3272 int currow=g_list_index(wtable->children, td->bottom_row->data) - firstrow;
3274 dbg(0,"Can't find bottom row in children list. Stop paging.\n");
3277 if(currow>=param->count)
3279 if(!(td->next_button->state & STATE_SENSITIVE)) {
3280 dbg(0,"Reached last page but item %i not found. Stop paging.\n",param->count);
3283 gui_internal_table_button_next(this, td->next_button, NULL);
3287 gui_internal_menu_render(this);
3293 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
3295 if (wm->item.type != type_none) {
3296 enum item_type type;
3297 if (wm->item.type < type_line)
3298 type=type_selected_point;
3299 else if (wm->item.type < type_area)
3300 type=type_selected_point;
3302 type=type_selected_area;
3303 graphics_clear_selection(this->gra, NULL);
3304 graphics_add_selection(this->gra, &wm->item, type, NULL);
3306 navit_set_center(this->nav, &wm->c, 1);
3307 gui_internal_prune_menu(this, NULL);
3312 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
3314 struct widget *w,*wb;
3315 struct map_rect *mr;
3321 text=g_strdup_printf("Attribute %s",wm->name);
3322 wb=gui_internal_menu(this, text);
3324 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3325 gui_internal_widget_append(wb, w);
3326 mr=map_rect_new(wm->item.map, NULL);
3327 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3328 for (i = 0 ; i < wm->datai ; i++) {
3329 item_attr_get(item, attr_any, &attr);
3331 if (item_attr_get(item, attr_any, &attr)) {
3333 switch (attr.type) {
3334 case attr_osm_nodeid:
3335 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
3337 case attr_osm_wayid:
3338 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
3340 case attr_osm_relationid:
3341 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
3347 gui_internal_widget_append(w,
3348 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3349 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3350 gui_internal_cmd_view_in_browser, NULL));
3354 map_rect_destroy(mr);
3355 gui_internal_menu_render(this);
3359 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
3361 struct widget *w,*wb;
3362 struct map_rect *mr;
3368 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3369 wb=gui_internal_menu(this, "Attributes");
3370 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3371 gui_internal_widget_append(wb, w);
3372 mr=map_rect_new(wm->item.map, NULL);
3373 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3374 dbg(0,"item=%p\n", item);
3376 text=g_strdup_printf("%s:%s", _("Item type"), item_to_name(item->type));
3377 gui_internal_widget_append(w,
3378 wb=gui_internal_button_new(this, text,
3379 NULL, gravity_left_center|orientation_horizontal|flags_fill));
3380 wb->name=g_strdup(text);
3383 while(item_attr_get(item, attr_any, &attr)) {
3385 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attrtxt=attr_to_text(&attr, wm->item.map, 1));
3387 gui_internal_widget_append(w,
3388 wb=gui_internal_button_new_with_callback(this, text,
3389 NULL, gravity_left_center|orientation_horizontal|flags_fill,
3390 gui_internal_cmd_view_attribute_details, NULL));
3391 wb->name=g_strdup(text);
3397 map_rect_destroy(mr);
3398 gui_internal_menu_render(this);
3402 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
3404 struct map_rect *mr;
3410 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3411 mr=map_rect_new(wm->item.map, NULL);
3412 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3413 dbg(0,"item=%p\n", item);
3415 while(item_attr_get(item, attr_url_local, &attr)) {
3417 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
3420 map_rect_destroy(mr);
3422 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
3428 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
3436 * @brief Event to transfer search results to a map.
3438 * @param this The graphics context.
3439 * @param wm called widget.
3440 * @param data event data (pointer to the table widget containing results, or NULL if results map is only have to be cleaned).
3443 gui_internal_cmd_results_to_map(struct gui_priv *this, struct widget *wm, void *data)
3448 struct map_selection sel;
3449 struct map_rect *mr;
3452 struct coord_rect r;
3456 ms=navit_get_mapset(this->nav);
3461 map=mapset_get_map_by_name(ms, "search_results");
3463 struct attr *attrs[10], attrmap;
3464 enum attr_type types[]={attr_position_longitude,attr_position_latitude,attr_label,attr_none};
3467 attrs[0]=g_new0(struct attr,1);
3468 attrs[0]->type=attr_type;
3469 attrs[0]->u.str="csv";
3471 attrs[1]=g_new0(struct attr,1);
3472 attrs[1]->type=attr_name;
3473 attrs[1]->u.str="search_results";
3475 attrs[2]=g_new0(struct attr,1);
3476 attrs[2]->type=attr_charset;
3477 attrs[2]->u.str="utf-8";
3479 attrs[3]=g_new0(struct attr,1);
3480 attrs[3]->type=attr_item_type;
3481 attrs[3]->u.num=type_found_item;
3483 attrs[4]=g_new0(struct attr,1);
3484 attrs[4]->type=attr_attr_types;
3485 attrs[4]->u.attr_types=types;
3488 attrmap.type=attr_map;
3489 map=attrmap.u.map=map_new(NULL,attrs);
3491 mapset_add_attr(ms,&attrmap);
3493 for(i=0;attrs[i];i++)
3503 sel.range.min=type_none;
3504 sel.range.max=type_tec_common;
3507 mr = map_rect_new(map, NULL);
3513 while((item = map_rect_get_item(mr))!=NULL) {
3514 item_type_set(item,type_none);
3517 this->results_map_population=0;
3519 /* Find the table to pupulate the map */
3520 for(w=data; w && w->type!=widget_table;w=w->parent);
3523 map_rect_destroy(mr);
3524 dbg(1,"Can't find the results table - only map clean up is done.\n");
3528 /* Populate the map with search results*/
3529 for(l=w->children, count=0;l;l=g_list_next(l)) {
3530 struct widget *wr=l->data;
3531 if(wr->type==widget_table_row) {
3532 struct widget *wi=wr->children->data;
3536 dbg(0,"%s\n",wi->name);
3537 it=map_rect_create_item(mr,type_found_item);
3543 item_coord_set(it, &c, 1, change_mode_modify);
3546 item_attr_set(it, &a, change_mode_modify);
3550 coord_rect_extend(&r,&c);
3554 map_rect_destroy(mr);
3557 a.type=attr_orientation;
3559 navit_set_attr(this->nav,&a);
3560 navit_zoom_to_rect(this->nav,&r);
3561 gui_internal_prune_menu(this, NULL);
3562 this->results_map_population=count;
3566 * @brief Event to remove search results from the a map.
3568 * @param this The graphics context.
3569 * @param wm called widget.
3570 * @param data event data
3573 gui_internal_cmd_results_map_clean(struct gui_priv *this, struct widget *wm, void *data)
3575 gui_internal_cmd_results_to_map(this,wm,NULL);
3576 gui_internal_prune_menu(this, NULL);
3577 navit_draw(this->nav);
3581 /* meaning of the bits in "flags":
3583 * 2: "House numbers"
3584 * 4: "View in Browser", "View Attributes"
3587 * 32: "Add as bookm."
3589 * 128: "View on Map"
3590 * 256: POIs around this point, "Drop search results from the map"
3591 * 512: "Cut/Copy... bookmark"
3592 * 1024: "Jump to attributes of top item within this->radius pixels of this point (implies flags|=256)"
3593 * 2048: "Show search results on the map"
3594 * TODO define constants for these values
3597 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)
3599 struct widget *wb,*w,*wtable,*row,*wc,*wbc,*wclosest=NULL;
3609 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3610 transform_to_geo(pc.pro, &c, &g);
3613 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
3616 pc.pro=attr.u.projection;
3617 transform_from_geo(pc.pro, &g, &c);
3623 wb=gui_internal_menu(this, name);
3624 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3625 gui_internal_widget_append(wb, w);
3626 coord=coordinates(&pc, ' ');
3627 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
3629 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3630 gui_internal_widget_append(w,wtable);
3632 if ((flags & 1) && wm) {
3633 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3634 gui_internal_widget_append(row,
3635 wc=gui_internal_button_new_with_callback(this, _("Streets"),
3636 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3637 gui_internal_search_street_in_town, wm));
3639 wc->selection_id=wm->selection_id;
3641 if ((flags & 2) && wm) {
3642 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3643 gui_internal_widget_append(row,
3644 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
3645 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3646 gui_internal_search_house_number_in_street, wm));
3648 wc->selection_id=wm->selection_id;
3650 if ((flags & 4) && wm) {
3651 struct map_rect *mr;
3654 mr=map_rect_new(wm->item.map, NULL);
3655 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3657 if (item_attr_get(item, attr_description, &attr))
3658 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
3659 if (item_attr_get(item, attr_url_local, &attr)) {
3660 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3661 gui_internal_widget_append(row,
3662 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3663 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3664 gui_internal_cmd_view_in_browser, NULL));
3667 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3668 gui_internal_widget_append(row,
3669 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
3670 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3671 gui_internal_cmd_view_attributes, NULL));
3674 map_rect_destroy(mr);
3677 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3678 gui_internal_widget_append(row,
3679 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
3680 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3681 gui_internal_cmd_set_destination, g_strdup(name)));
3682 wbc->data_free=g_free_func;
3687 struct attr vehicle, source;
3689 if (navit_get_attr(this->nav, attr_vehicle, &vehicle, NULL) && vehicle.u.vehicle &&
3690 !(vehicle_get_attr(vehicle.u.vehicle, attr_source, &source, NULL) && source.u.str && !strcmp("demo://",source.u.str)))
3693 text=deactivate? _("Set as position (and deactivate vehicle)") : _("Set as position");
3695 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3696 gui_internal_widget_append(row,
3697 wbc=gui_internal_button_new_with_callback(this, text,
3698 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3699 gui_internal_cmd_set_position, (void*)deactivate));
3703 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3704 gui_internal_widget_append(row,
3705 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
3706 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3707 gui_internal_cmd_add_bookmark2, g_strdup(name)));
3708 wbc->data_free=g_free_func;
3712 //POIs are not operational under MSVC yet
3714 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3715 gui_internal_widget_append(row,
3716 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
3717 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3718 gui_internal_cmd_pois, NULL));
3721 #endif /* _MSC_VER */
3723 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3724 gui_internal_widget_append(row,
3725 gui_internal_button_new(this, "Add to tour",
3726 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
3729 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3730 gui_internal_widget_append(row,
3731 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
3732 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3733 gui_internal_cmd_view_on_map, NULL));
3735 if ((flags & 4) && wm)
3738 wbc->item.type=type_none;
3740 if(flags & 256 && this->results_map_population) {
3741 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3742 gui_internal_widget_append(row,
3743 wbc=gui_internal_button_new_with_callback(this, _("Remove search results from the map"),
3744 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3745 gui_internal_cmd_results_map_clean, NULL));
3749 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3750 gui_internal_widget_append(row,
3751 wbc=gui_internal_button_new_with_callback(this, _("Show results on the map"),
3752 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3753 gui_internal_cmd_results_to_map, NULL));
3756 if ((flags & 256) || (flags & 1024)) {
3757 struct displaylist_handle *dlh;
3758 struct displaylist *display;
3761 struct transformation *trans;
3764 struct map_selection *sel;
3770 trans=navit_get_trans(this->nav);
3771 transform(trans,pc.pro,&c,&p,1,0,0,0);
3772 display=navit_get_displaylist(this->nav);
3773 dlh=graphics_displaylist_open(display);
3774 sel=displaylist_get_selection(display);
3775 l=displaylist_get_clicked_list(display, &p, this->radius);
3776 for(ll=l;ll;ll=g_list_next(ll)) {
3777 struct displayitem *di;
3779 struct map_rect *mr;
3782 di=(struct displayitem*)ll->data;
3783 item=graphics_displayitem_get_item(di);
3785 mr=map_rect_new(item->map, sel);
3786 itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
3788 if (item_attr_get(itemo, attr_label, &attr)) {
3789 label=map_convert_string(itemo->map, attr.u.str);
3790 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
3791 map_convert_free(label);
3793 text=g_strdup_printf("%s", item_to_name(item->type));
3794 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3795 gui_internal_widget_append(row, wc=gui_internal_cmd_pois_item(this, NULL, itemo, NULL, -1, text));
3798 wc->name=g_strdup(text);
3801 map_rect_destroy(mr);
3807 map_selection_destroy(sel);
3808 graphics_displaylist_close(dlh);
3811 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3812 gui_internal_widget_append(row,
3813 wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
3814 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3815 gui_internal_cmd_cut_bookmark, NULL));
3816 wbc->text=g_strdup(wm->text);
3817 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3818 gui_internal_widget_append(row,
3819 wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
3820 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3821 gui_internal_cmd_copy_bookmark, NULL));
3822 wbc->text=g_strdup(wm->text);
3823 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3824 gui_internal_widget_append(row,
3825 wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
3826 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3827 gui_internal_cmd_rename_bookmark, NULL));
3828 wbc->text=g_strdup(wm->text);
3829 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3830 gui_internal_widget_append(row,
3831 wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
3832 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3833 gui_internal_cmd_paste_bookmark, NULL));
3834 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3835 gui_internal_widget_append(row,
3836 wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
3837 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3838 gui_internal_cmd_delete_bookmark, NULL));
3839 wbc->text=g_strdup(wm->text);
3842 gui_internal_menu_render(this);
3844 if((flags & 1024) && wclosest)
3845 gui_internal_cmd_view_attributes(this,wclosest,wclosest->data);
3849 /* wm->data: 0 Nothing special
3857 8 Former destination
3858 9 Item from the POI list
3862 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
3869 switch ((long) data) {
3871 flags=8|16|32|64|128|256;
3874 flags=8|16|32|64|256;
3877 flags=4|8|16|32|64|128;
3880 flags=1|8|16|32|64|128|2048;
3881 flags &= this->flags_town;
3884 gui_internal_search_town_in_country(this, wm);
3887 flags=2|8|16|32|64|128|2048;
3888 flags &= this->flags_street;
3891 flags=8|16|32|64|128|2048;
3892 flags &= this->flags_house_number;
3895 flags=8|16|64|128|512;
3898 flags=8|16|32|64|128;
3901 flags=4|8|16|32|64|128|2048;
3908 gui_internal_search_house_number_in_street(this, wm, NULL);
3911 gui_internal_cmd_set_destination(this, wm, NULL);
3914 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
3918 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3920 char *name=_("Position");
3926 if (!ATTR_IS_COORD_GEO(in[0]->type))
3928 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3930 if (in[2] && ATTR_IS_INT(in[2]->type))
3933 dbg(1,"flags=0x%x\n",flags);
3934 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
3938 gui_internal_cmd2_pois(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3941 struct poi_param *param;
3948 if (!ATTR_IS_COORD_GEO(in[0]->type))
3950 if (!navit_get_attr(this->nav, attr_projection, &pro, NULL))
3952 w=g_new0(struct widget,1);
3953 param=g_new0(struct poi_param,1);
3954 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3955 gui_internal_poi_param_set_filter(param, in[1]->u.str);
3956 if (in[2] && ATTR_IS_INT(in[2]->type))
3957 param->isAddressFilter=in[2]->u.num;
3960 transform_from_geo(pro.u.projection,in[0]->u.coord_geo,&c);
3963 w->c.pro=pro.u.projection;
3964 gui_internal_cmd_pois(this, w, param);
3966 gui_internal_poi_param_free(param);
3970 gui_internal_cmd2_refresh(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3972 char *href=g_strdup(this->href);
3973 gui_internal_html_load_href(this, href, 1);
3979 * The "Bookmarks" section of the OSD
3984 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
3986 struct attr attr,mattr;
3988 char *label_full,*prefix=0;
3989 int plen=0,hassub,found=0;
3990 struct widget *wb,*w,*wbm;
3992 struct widget *tbl, *row;
3995 prefix=g_strdup(data);
3997 if (wm && wm->prefix)
3998 prefix=g_strdup(wm->prefix);
4001 plen=strlen(prefix);
4003 gui_internal_prune_menu_count(this, 1, 0);
4004 wb=gui_internal_menu(this, _("Bookmarks"));
4005 wb->background=this->background;
4006 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4007 //w->spy=this->spacing*3;
4008 gui_internal_widget_append(wb, w);
4010 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
4012 bookmarks_move_root(mattr.u.bookmarks);
4014 if (!strcmp(prefix,"..")) {
4015 bookmarks_move_up(mattr.u.bookmarks);
4017 prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
4019 plen=strlen(prefix);
4024 bookmarks_move_down(mattr.u.bookmarks,prefix);
4027 // "Back" button, when inside a bookmark folder
4030 wbm=gui_internal_button_new_with_callback(this, "..",
4031 image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
4032 gui_internal_cmd_bookmarks, NULL);
4033 wbm->prefix=g_strdup("..");
4034 gui_internal_widget_append(w, wbm);
4036 // load bookmark folder as Waypoints, if any
4037 if (bookmarks_get_bookmark_count(mattr.u.bookmarks) > 0){
4038 wbm=gui_internal_button_new_with_callback(this, _("Bookmarks as Waypoints"),
4039 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4040 gui_internal_cmd_load_bookmarks_as_waypoints, NULL);
4041 wbm->prefix=g_strdup(prefix);
4042 gui_internal_widget_append(w, wbm);
4045 // save Waypoints in bookmark folder, if route exists
4046 if (navit_get_destination_count(this->nav) > 0){
4047 if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0){
4048 wbm=gui_internal_button_new_with_callback(this, _("Save Waypoints"),
4049 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4050 gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
4052 wbm=gui_internal_button_new_with_callback(this, _("Replace Waypoints"),
4053 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4054 gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
4056 wbm->prefix=g_strdup(prefix);
4057 gui_internal_widget_append(w, wbm);
4060 // delete empty folder
4061 if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0){
4062 gui_internal_widget_append(w,
4063 wbm=gui_internal_button_new_with_callback(this, _("Delete Folder"),
4064 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4065 gui_internal_cmd_delete_bookmark_folder, NULL));
4066 wbm->prefix=g_strdup(prefix);
4072 // Adds the Bookmark folders
4073 wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
4074 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4075 gui_internal_cmd_add_bookmark_folder2, NULL);
4076 gui_internal_widget_append(w, wbm);
4078 // Pastes the Bookmark
4079 wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
4080 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4081 gui_internal_cmd_paste_bookmark, NULL);
4082 gui_internal_widget_append(w, wbm);
4084 bookmarks_item_rewind(mattr.u.bookmarks);
4086 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4087 gui_internal_widget_append(w,tbl);
4089 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
4090 if (!item_attr_get(item, attr_label, &attr)) continue;
4091 label_full=attr.u.str;
4092 dbg(0,"full_labled: %s\n",label_full);
4094 // hassub == 1 if the item type is a sub-folder
4095 if (item->type == type_bookmark_folder) {
4101 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
4102 gui_internal_widget_append(tbl, row);
4103 wbm=gui_internal_button_new_with_callback(this, label_full,
4104 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
4105 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
4107 gui_internal_widget_append(row,wbm);
4108 if (item_coord_get(item, &c, 1)) {
4111 wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
4112 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
4113 wbm->text=g_strdup(label_full);
4115 wbm->data=(void*)7;//Mark us as a bookmark
4117 wbm->prefix=g_strdup(label_full);
4119 gui_internal_widget_destroy(this, row);
4127 gui_internal_check_exit(this);
4129 gui_internal_menu_render(this);
4133 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4136 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
4139 gui_internal_cmd_bookmarks(this, NULL, str);
4144 gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4146 struct widget *wb,*w,*wbm,*tbl=NULL;
4147 struct map *formerdests;
4148 struct map_rect *mr_formerdests;
4152 enum projection projection;
4154 gui_internal_prune_menu_count(this, 1, 0);
4155 wb=gui_internal_menu(this, _("Former Destinations"));
4156 wb->background=this->background;
4158 w=gui_internal_box_new(this,
4159 gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4160 w->spy=this->spacing*2;
4161 gui_internal_widget_append(wb, w);
4163 formerdests=read_former_destinations_from_file();
4164 mr_formerdests=map_rect_new(formerdests, NULL);
4165 projection = map_projection(formerdests);
4166 while ((item=map_rect_get_item(mr_formerdests))) {
4169 if (!item_attr_get(item, attr_label, &attr)) continue;
4171 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand | orientation_vertical,1);
4172 gui_internal_widget_append(w,tbl);
4174 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_vertical);
4175 gui_internal_widget_prepend(tbl, row);
4176 label_full=attr.u.str;
4177 wbm=gui_internal_button_new_with_callback(this, label_full,
4178 image_new_xs(this, "gui_active"),
4179 gravity_left_center|orientation_horizontal|flags_fill,
4180 gui_internal_cmd_position, NULL);
4181 gui_internal_widget_append(row,wbm);
4182 if (item_coord_get(item, &c, 1)) {
4185 wbm->c.pro=projection;
4186 wbm->name=g_strdup(label_full);
4187 wbm->text=g_strdup(label_full);
4188 wbm->data=(void*)8; //Mark us as a former destination
4189 wbm->prefix=g_strdup(label_full);
4193 wbm=gui_internal_text_new(this, _("- No former destinations available -"),
4194 gravity_left_center|orientation_horizontal|flags_fill);
4195 gui_internal_widget_append(w, wbm);
4197 gui_internal_menu_render(this);
4198 map_rect_destroy(mr_formerdests);
4202 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy);
4204 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
4206 struct widget *wi,*menu,*search_list;
4210 menu=g_list_last(this->root.children)->data;
4211 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
4213 /* select first item of the searchlist */
4214 if (*key == NAVIT_KEY_RETURN) {
4215 search_list=gui_internal_menu_data(this)->search_list;
4217 GList *l=gui_internal_widget_table_top_row(this, search_list);
4219 struct widget *w=l->data;
4220 this->current.x=w->p.x+w->w/2;
4221 this->current.y=w->p.y+w->h/2;
4222 gui_internal_highlight(this);
4225 wi->reason=gui_internal_reason_keypress_finish;
4226 wi->func(this, wi, wi->data);
4229 } else if (*key == NAVIT_KEY_BACKSPACE) {
4230 dbg(0,"backspace\n");
4231 if (wi->text && wi->text[0]) {
4232 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
4234 text=g_strdup_printf("%s ", wi->text);
4237 if (wi->state & STATE_CLEAR) {
4238 dbg(0,"wi->state=0x%x\n", wi->state);
4241 wi->state &= ~STATE_CLEAR;
4242 dbg(0,"wi->state=0x%x\n", wi->state);
4244 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
4248 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
4249 gui_internal_widget_render(this, wi);
4253 wi->reason=gui_internal_reason_keypress;
4254 wi->func(this, wi, wi->data);
4256 gui_internal_widget_render(this, wi);
4262 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
4264 struct menu_data *md;
4265 gui_internal_keypress_do(this, (char *) wm->data);
4266 md=gui_internal_menu_data(this);
4267 // Switch to lowercase after the first key is pressed
4268 if (md->keyboard_mode == 2) // Latin
4269 gui_internal_keyboard_do(this, md->keyboard, 10);
4270 if (md->keyboard_mode == 26) // Umlaut
4271 gui_internal_keyboard_do(this, md->keyboard, 34);
4272 if (md->keyboard_mode == 42) // Russian/Ukrainian/Belorussian
4273 gui_internal_keyboard_do(this, md->keyboard, 50);
4277 gui_internal_search_idle_end(struct gui_priv *this)
4280 event_remove_idle(this->idle);
4283 if (this->idle_cb) {
4284 callback_destroy(this->idle_cb);
4290 postal_str(struct search_list_result *res, int level)
4293 if (res->town->common.postal)
4294 ret=res->town->common.postal;
4295 if (res->town->common.postal_mask)
4296 ret=res->town->common.postal_mask;
4299 if (res->street->common.postal)
4300 ret=res->street->common.postal;
4301 if (res->street->common.postal_mask)
4302 ret=res->street->common.postal_mask;
4305 if (res->house_number->common.postal)
4306 ret=res->house_number->common.postal;
4307 if (res->house_number->common.postal_mask)
4308 ret=res->house_number->common.postal_mask;
4313 district_str(struct search_list_result *res, int level)
4316 if (res->town->common.district_name)
4317 ret=res->town->common.district_name;
4320 if (res->street->common.district_name)
4321 ret=res->street->common.district_name;
4324 if (res->house_number->common.district_name)
4325 ret=res->house_number->common.district_name;
4330 town_str(struct search_list_result *res, int level, int flags)
4332 char *town=res->town->common.town_name;
4333 char *district=district_str(res, level);
4334 char *postal=postal_str(res, level);
4335 char *postal_sep=" ";
4336 char *district_begin=" (";
4337 char *district_end=")";
4338 char *county_sep = ", Co. ";
4339 char *county = res->town->common.county_name;
4341 postal_sep=postal="";
4342 if (!district || (flags & 1))
4343 district_begin=district_end=district="";
4345 county_sep=county="";
4347 return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
4350 static int gui_internal_search_cmp(gconstpointer _a, gconstpointer _b)
4352 struct widget *a=(struct widget *)_a, *b=(struct widget *)_b;
4356 if((!a || a->type!=widget_table_row || !a->text) && (!b || b->type!=widget_table_row || !b->text))
4358 if(!a || a->type!=widget_table_row || !a->text)
4360 if(!b || b->type!=widget_table_row || !b->text)
4362 r=a->datai-b->datai;
4367 sa=removecase(a->text);
4368 sb=removecase(b->text);
4376 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
4378 char *text=NULL,*text2=NULL,*name=NULL;
4379 struct search_list_result *res;
4381 struct item *item=NULL;
4383 static char possible_keys[256]="";
4384 struct widget *wi=NULL;
4387 res=search_list_get_result(this->sl);
4389 gchar* trunk_name = NULL;
4391 struct widget *menu=g_list_last(this->root.children)->data;
4392 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
4395 if (! strcmp(wm_name,"Town"))
4396 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
4397 if (! strcmp(wm_name,"Street"))
4399 name=res->street->name;
4401 trunk_name = g_strrstr(name, wi->text);
4407 char next_char = trunk_name[strlen(wi->text)];
4409 int len = strlen(possible_keys);
4410 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
4411 if (i==len || !len) {
4412 possible_keys[len]=trunk_name[strlen(wi->text)];
4413 possible_keys[len+1]='\0';
4415 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
4418 dbg(0, "Unable to find widget");
4423 struct menu_data *md;
4424 gui_internal_search_idle_end(this);
4426 md=gui_internal_menu_data(this);
4427 if (md && md->keyboard && !(this->flags & 2048)) {
4428 GList *lk=md->keyboard->children;
4429 graphics_draw_mode(this->gra, draw_mode_begin);
4431 struct widget *child=lk->data;
4432 GList *lk2=child->children;
4434 struct widget *child_=lk2->data;
4435 lk2=g_list_next(lk2);
4436 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
4437 if (strlen(possible_keys) == 0)
4438 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
4439 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
4440 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
4442 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
4444 gui_internal_widget_render(this,child_);
4449 gui_internal_widget_render(this,md->keyboard);
4450 graphics_draw_mode(this->gra, draw_mode_end);
4453 possible_keys[0]='\0';
4457 if (! strcmp(wm_name,"Country")) {
4458 name=res->country->name;
4459 item=&res->country->common.item;
4460 text=g_strdup_printf("%s", res->country->name);
4462 if (! strcmp(wm_name,"Town")) {
4463 item=&res->town->common.item;
4464 name=res->town->common.town_name;
4465 text=town_str(res, 1, 0);
4467 if (! strcmp(wm_name,"Street")) {
4468 name=res->street->name;
4469 item=&res->street->common.item;
4470 text=g_strdup(res->street->name);
4471 text2=town_str(res, 2, 1);
4473 if (! strcmp(wm_name,"House number")) {
4474 name=res->house_number->house_number;
4475 text=g_strdup_printf("%s %s", res->street->name, name);
4476 text2=town_str(res, 3, 0);
4478 dbg(1,"res->country->flag=%s\n", res->country->flag);
4479 wr=gui_internal_widget_table_row_new(this, gravity_left|orientation_horizontal|flags_fill);
4482 wr->text=g_strdup(text);
4483 gui_internal_widget_insert_sorted(search_list, wr, gui_internal_search_cmp);
4484 gui_internal_widget_append(wr,
4485 wc=gui_internal_button_new_with_callback(this, text,
4486 image_new_xs(this, res->country->flag),
4487 gravity_left_center|orientation_horizontal|flags_fill,
4488 gui_internal_cmd_position, param));
4491 wr->text=g_strdup_printf("%s %s",text,text2);
4493 if (! strcmp(wm_name,"House number") && !res->street->name) {
4497 dbg(0,"search text widget is NULL\n");
4498 if(wi && strlen(name)==strlen(wi->text)) {
4499 dbg(1,"xact %s %s\n",name, wi->text);
4502 dbg(1,"not xact %s %s\n",name, wi->text);
4506 gui_internal_widget_insert_sorted(search_list, wr, gui_internal_search_cmp);
4508 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4509 gui_internal_widget_append(wr, wc);
4510 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
4511 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
4512 gui_internal_widget_append(wc, wb);
4513 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
4514 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
4515 wc->func=gui_internal_cmd_position;
4517 wc->state |= STATE_SENSITIVE;
4518 wc->speech=g_strdup(text);
4520 wc->name=g_strdup(name);
4523 wc->selection_id=res->id;
4526 gui_internal_widget_pack(this, search_list);
4527 l=g_list_last(this->root.children);
4528 graphics_draw_mode(this->gra, draw_mode_begin);
4529 gui_internal_widget_render(this, l->data);
4530 graphics_draw_mode(this->gra, draw_mode_end);
4536 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
4538 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
4539 this->idle=event_add_idle(50,this->idle_cb);
4540 callback_call_0(this->idle_cb);
4546 * @param wm The widget that generated the event for the search changed,
4547 * if this was generated by a key on the virtual keyboard then
4548 * wm is the key button widget.
4551 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
4554 struct widget *search_list=gui_internal_menu_data(this)->search_list;
4555 void *param=(void *)3;
4558 gui_internal_widget_table_clear(this, search_list);
4560 if (! strcmp(wm->name,"Country"))
4562 if (! strcmp(wm->name,"Street"))
4564 if (! strcmp(wm->name,"House number"))
4566 dbg(0,"%s now '%s'\n", wm->name, wm->text);
4568 gui_internal_search_idle_end(this);
4569 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
4570 struct attr search_attr;
4573 if (! strcmp(wm->name,"Country"))
4574 search_attr.type=attr_country_all;
4575 if (! strcmp(wm->name,"Town"))
4576 search_attr.type=attr_town_or_district_name;
4577 if (! strcmp(wm->name,"Street"))
4578 search_attr.type=attr_street_name;
4579 if (! strcmp(wm->name,"House number"))
4580 search_attr.type=attr_house_number;
4581 search_attr.u.str=wm->text;
4582 search_list_search(this->sl, &search_attr, 1);
4583 gui_internal_search_idle_start(this, wm->name, search_list, param);
4585 l=g_list_last(this->root.children);
4586 gui_internal_widget_render(this, l->data);
4589 static struct widget *
4590 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)
4593 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
4594 NULL, gravity_center|orientation_vertical, func, data));
4595 wk->data_free=data_free;
4596 wk->background=this->background;
4606 static struct widget *
4607 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
4609 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
4612 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
4615 // A list of availiable keyboard modes.
4616 struct gui_internal_keyb_mode {
4617 char title[16]; // Label to be displayed on keys that switch to it
4618 int font; // Font size of label
4619 int case_mode; // Mode to switch to when case CHANGE() key is pressed.
4620 int umlaut_mode; // Mode to switch to when UMLAUT() key is pressed.
4621 } gui_internal_keyb_modes[]= {
4622 /* 0*/ {"ABC", 2, 8, 24},
4623 /* 8*/ {"abc", 2, 0, 32},
4624 /*16*/ {"123", 2, 0, 24},
4625 /*24*/ {"ÄÖÜ", 2, 40, 0},
4626 /*32*/ {"äöü", 2, 32, 8},
4627 /*40*/ {"АБВ", 2, 48, 0},
4628 /*48*/ {"абв", 2, 40, 8},
4629 /*56*/ {"DEG", 2, 2, 2}
4633 // Some macros that make the keyboard layout easier to visualise in
4634 // the source code. The macros are #undef'd after this function.
4635 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
4636 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
4637 #define MODE(x) gui_internal_keyboard_key_data(this, wkbd, \
4638 gui_internal_keyb_modes[(x)/8].title, \
4639 gui_internal_keyb_modes[(x)/8].font, \
4640 gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h) \
4641 -> datai=(mode&7)+((x)&~7)
4642 #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode)
4643 #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode)
4644 static struct widget *
4645 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
4647 struct widget *wkbd,*wk;
4648 struct menu_data *md=gui_internal_menu_data(this);
4649 int i, max_w=this->root.w, max_h=this->root.h;
4652 char *backspace="←";
4659 gui_internal_highlight(this);
4660 if (md->keyboard_mode >= 1024)
4664 gui_internal_widget_children_destroy(this, wkbdb);
4666 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
4668 md->keyboard_mode=mode;
4669 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
4670 wkbd->background=this->background;
4675 max_h=max_h/8; // Allows 3 results in the list when searching for Towns
4677 if(mode>=40&&mode<56) { // Russian/Ukrainian/Belarussian layout needs more space...
4683 if (mode >= 0 && mode < 8) {
4684 for (i = 0 ; i < 26 ; i++) {
4685 char text[]={'A'+i,'\0'};
4688 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4692 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4693 wk->datai=mode+1024;
4695 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4696 wk->datai=mode+1024;
4702 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4704 if (mode >= 8 && mode < 16) {
4705 for (i = 0 ; i < 26 ; i++) {
4706 char text[]={'a'+i,'\0'};
4709 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4713 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4714 wk->datai=mode+1024;
4716 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4717 wk->datai=mode+1024;
4723 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4725 if (mode >= 16 && mode < 24) {
4726 for (i = 0 ; i < 10 ; i++) {
4727 char text[]={'0'+i,'\0'};
4730 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
4731 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
4736 for (i = 0 ; i < 5 ; i++) SPACER();
4739 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4740 wk->datai=mode+1024;
4742 for (i = 0 ; i < 3 ; i++) SPACER();
4745 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4746 wk->datai=mode+1024;
4751 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4753 if (mode >= 24 && mode < 32) {
4754 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
4755 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
4756 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
4757 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
4761 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4763 if (mode >= 32 && mode < 40) {
4764 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
4765 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
4766 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
4767 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
4771 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4773 if (mode >= 40 && mode < 48) {
4774 KEY("А"); KEY("Б"); KEY("В"); KEY("Г"); KEY("Д"); KEY("Е"); KEY("Ж"); KEY("З"); KEY("И");
4775 KEY("Й"); KEY("К"); KEY("Л"); KEY("М"); KEY("Н"); KEY("О"); KEY("П"); KEY("Р"); KEY("С");
4776 KEY("Т"); KEY("У"); KEY("Ф"); KEY("Х"); KEY("Ц"); KEY("Ч"); KEY("Ш"); KEY("Щ"); KEY("Ъ");
4777 KEY("Ы"); KEY("Ь"); KEY("Э"); KEY("Ю"); KEY("Я"); KEY("Ё"); KEY("І"); KEY("Ї"); KEY("Ў");
4778 SPACER(); SPACER(); SPACER();
4779 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4781 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4782 wk->datai=mode+1024;
4790 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4792 if (mode >= 48 && mode < 56) {
4793 KEY("а"); KEY("б"); KEY("в"); KEY("г"); KEY("д"); KEY("е"); KEY("ж"); KEY("з"); KEY("и");
4794 KEY("й"); KEY("к"); KEY("л"); KEY("м"); KEY("н"); KEY("о"); KEY("п"); KEY("р"); KEY("с");
4795 KEY("т"); KEY("у"); KEY("ф"); KEY("х"); KEY("ц"); KEY("ч"); KEY("ш"); KEY("щ"); KEY("ъ");
4796 KEY("ы"); KEY("ь"); KEY("э"); KEY("ю"); KEY("я"); KEY("ё"); KEY("і"); KEY("ї"); KEY("ў");
4797 SPACER(); SPACER(); SPACER();
4798 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4800 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4801 wk->datai=mode+1024;
4809 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4813 if(md->search_list && md->search_list->type==widget_table) {
4814 struct table_data *td=(struct table_data*)(md->search_list->data);
4815 td->button_box_hide=mode<1024;
4818 if (mode >= 56 && mode < 64) { /* special case for coordinates input screen (enter_coord) */
4819 KEY("0"); KEY("1"); KEY("2"); KEY("3"); KEY("4"); SPACER(); KEY("N"); KEY("S");
4820 KEY("5"); KEY("6"); KEY("7"); KEY("8"); KEY("9"); SPACER(); KEY("E"); KEY("W");
4821 KEY("°"); KEY("."); KEY("'");
4822 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4825 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4826 wk->datai=mode+1024;
4829 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4837 text=gui_internal_keyb_modes[mode/8].title;
4838 font=gui_internal_keyb_modes[mode/8].font;
4839 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
4840 wk->func=gui_internal_keyboard_change;
4842 wk->background=this->background;
4850 wk->state |= STATE_SENSITIVE;
4851 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
4852 wkl->background=NULL;
4853 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
4854 wkl->background=NULL;
4855 gui_internal_widget_append(wkbd, wk);
4859 gui_internal_widget_append(wkbdb, wkbd);
4861 gui_internal_widget_pack(this, wkbdb);
4862 gui_internal_widget_render(this, wkbdb);
4863 } else if (render == 2) {
4864 gui_internal_menu_reset_pack(this);
4865 gui_internal_menu_render(this);
4875 static struct widget *
4876 gui_internal_keyboard(struct gui_priv *this, int mode)
4878 if (! this->keyboard)
4880 return gui_internal_keyboard_do(this, NULL, mode);
4884 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
4886 gui_internal_keyboard_do(this, key->data, key->datai);
4890 gui_internal_search_list_set_default_country(struct gui_priv *this)
4892 struct attr search_attr, country_name, country_iso2, *country_attr;
4894 struct country_search *cs;
4895 struct tracking *tracking;
4896 struct search_list_result *res;
4898 country_attr=country_default();
4899 tracking=navit_get_tracking(this->nav);
4900 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
4901 country_attr=&search_attr;
4903 cs=country_search_new(country_attr, 0);
4904 item=country_search_get_item(cs);
4905 if (item && item_attr_get(item, attr_country_name, &country_name)) {
4906 search_attr.type=attr_country_all;
4907 dbg(0,"country %s\n", country_name.u.str);
4908 search_attr.u.str=country_name.u.str;
4909 search_list_search(this->sl, &search_attr, 0);
4910 while((res=search_list_get_result(this->sl)));
4911 if(this->country_iso2) {
4912 g_free(this->country_iso2);
4913 this->country_iso2=NULL;
4915 if (item_attr_get(item, attr_country_iso2, &country_iso2))
4916 this->country_iso2=g_strdup(country_iso2.u.str);
4918 country_search_destroy(cs);
4920 dbg(0,"warning: no default country found\n");
4921 if (this->country_iso2) {
4922 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
4923 search_attr.type=attr_country_iso2;
4924 search_attr.u.str=this->country_iso2;
4925 search_list_search(this->sl, &search_attr, 0);
4926 while((res=search_list_get_result(this->sl)));
4932 gui_internal_search_list_new(struct gui_priv *this)
4934 struct mapset *ms=navit_get_mapset(this->nav);
4936 this->sl=search_list_new(ms);
4937 gui_internal_search_list_set_default_country(this);
4942 gui_internal_search_list_destroy(struct gui_priv *this)
4945 search_list_destroy(this->sl);
4952 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
4954 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
4956 int keyboard_mode=2;
4957 gui_internal_search_list_new(this);
4958 wb=gui_internal_menu(this, what);
4959 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
4960 gui_internal_widget_append(wb, w);
4961 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4962 gui_internal_widget_append(w, wr);
4963 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4964 gui_internal_widget_append(wr, we);
4965 if (!strcmp(type,"Country")) {
4966 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
4967 wnext->func=gui_internal_search_town;
4968 } else if (!strcmp(type,"Town")) {
4969 if (this->country_iso2) {
4970 #if HAVE_API_ANDROID
4971 char country_iso2[strlen(this->country_iso2)+1];
4972 strtolower(country_iso2, this->country_iso2);
4973 country=g_strdup_printf("country_%s", country_iso2);
4975 country=g_strdup_printf("country_%s", this->country_iso2);
4978 country=g_strdup("gui_select_country");
4979 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
4980 wb->state |= STATE_SENSITIVE;
4982 wb->func = gui_internal_search_country;
4984 wb->func = gui_internal_back;
4985 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
4986 wnext->func=gui_internal_search_street;
4988 } else if (!strcmp(type,"Street")) {
4989 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
4990 wb->state |= STATE_SENSITIVE;
4991 wb->func = gui_internal_back;
4992 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
4993 wnext->func=gui_internal_search_house_number;
4994 } else if (!strcmp(type,"House number")) {
4995 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
4996 wb->state |= STATE_SENSITIVE;
4997 wb->func = gui_internal_back;
5000 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
5002 gui_internal_widget_append(we, wnext);
5003 wnext->state |= STATE_SENSITIVE;
5005 wl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);//gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5006 gui_internal_widget_append(wr, wl);
5007 gui_internal_menu_data(this)->search_list=wl;
5008 wk->state |= STATE_EDIT|STATE_EDITABLE;
5009 wk->background=this->background;
5010 wk->flags |= flags_expand|flags_fill;
5011 wk->func = gui_internal_search_changed;
5012 wk->name=g_strdup(type);
5014 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
5015 gui_internal_menu_render(this);
5019 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
5021 search_list_select(this->sl, attr_street_name, 0, 0);
5022 gui_internal_search(this,_("House number"),"House number",0);
5026 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
5028 dbg(0,"id %d\n", widget->selection_id);
5029 search_list_select(this->sl, attr_street_name, 0, 0);
5030 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
5031 gui_internal_search(this,_("House number"),"House number",0);
5035 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
5037 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
5038 gui_internal_search(this,_("Street"),"Street",0);
5042 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
5044 dbg(0,"id %d\n", widget->selection_id);
5045 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
5046 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
5047 gui_internal_search(this,_("Street"),"Street",0);
5051 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
5054 search_list_select(this->sl, attr_country_all, 0, 0);
5055 g_free(this->country_iso2);
5056 this->country_iso2=NULL;
5057 gui_internal_search(this,_("Town"),"Town",0);
5061 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
5063 struct search_list_common *slc;
5064 dbg(0,"id %d\n", widget->selection_id);
5065 search_list_select(this->sl, attr_country_all, 0, 0);
5066 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
5068 g_free(this->country_iso2);
5069 this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
5071 gui_internal_search(this,widget->name,"Town",0);
5075 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
5077 gui_internal_prune_menu_count(this, 1, 0);
5078 gui_internal_search(this,_("Country"),"Country",0);
5082 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5085 search_list_select(this->sl, attr_country_all, 0, 0);
5086 gui_internal_search(this,_("Town"),"Town",1);
5090 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5093 struct widget *w,*wb,*wl,*row;
5094 struct attr_iter *iter;
5097 wb=gui_internal_menu(this, _("Layout"));
5098 w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
5099 gui_internal_widget_append(wb, w);
5100 iter=navit_attr_iter_new();
5101 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
5102 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5103 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
5105 gui_internal_widget_append(row, wl);
5107 navit_attr_iter_destroy(iter);
5108 gui_internal_menu_render(this);
5112 gui_internal_cmd_match_expand(char *pattern, struct attr **in)
5114 char p,*ret=g_strdup(pattern),*r=ret,*a;
5116 while ((p=*pattern++)) {
5120 a=attr_to_text(*in++,NULL,0);
5121 len=strlen(ret)+strlen(a)+strlen(pattern)+1;
5141 gui_internal_match(const char *pattern, const char *string)
5144 while ((p=*pattern++)) {
5147 while ((s=*string)) {
5148 if (gui_internal_match(pattern,string))
5164 gui_internal_set(char *remove, char *add)
5166 char *gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
5167 char *gui_file_new=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal_new.txt", NULL);
5168 FILE *fo=fopen(gui_file_new,"w");
5169 FILE *fi=fopen(gui_file,"r");
5174 while (getline(&line,&size,fi) > 0) {
5175 int len=strlen(line);
5176 if (len > 0 && line[len-1] == '\n')
5178 dbg(1,"line=%s\n",line);
5179 if (!gui_internal_match(remove, line))
5180 fprintf(fo,"%s\n",line);
5186 fprintf(fo,"%s;\n",add);
5188 ret=(rename(gui_file_new, gui_file)==0);
5189 g_free(gui_file_new);
5196 gui_internal_cmd2_set(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5198 char *pattern,*command=NULL;
5199 if (!in || !in[0] || !ATTR_IS_STRING(in[0]->type)) {
5200 dbg(0,"first parameter missing or wrong type\n");
5203 pattern=in[0]->u.str;
5204 dbg(0,"pattern %s\n",pattern);
5206 command=gui_internal_cmd_match_expand(pattern, in+1);
5207 dbg(0,"expand %s\n",command);
5208 gui_internal_set(pattern, command);
5209 command_evaluate(&this->self, command);
5216 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5219 gui_internal_prune_menu(this, NULL);
5220 navit.type=attr_navit;
5221 navit.u.navit=this->nav;
5222 config_remove_attr(config, &navit);
5223 gui_internal_destroy(this);
5224 event_main_loop_quit();
5228 gui_internal_window_closed(struct gui_priv *this)
5230 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
5234 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5236 navit_set_destination(this->nav, NULL, NULL, 0);
5240 gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data)
5242 char *text=g_strdup_printf(_("Download %s"),wm->name);
5243 struct widget *w, *wb;
5244 struct map *map=data;
5245 double bllon,bllat,trlon,trlat;
5247 wb=gui_internal_menu(this, text);
5249 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5250 w->spy=this->spacing*3;
5251 gui_internal_widget_append(wb, w);
5252 if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
5254 struct map_selection sel;
5255 struct map_rect *mr;
5262 transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
5265 transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
5266 sel.range.min=type_none;
5267 sel.range.max=type_last;
5268 mr=map_rect_new(map, &sel);
5269 while ((item=map_rect_get_item(mr))) {
5272 map_rect_destroy(mr);
5275 dbg(0,"bbox=%s\n",wm->prefix);
5276 gui_internal_menu_render(this);
5280 gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data)
5282 struct attr on, off, download_enabled, download_disabled;
5283 struct widget *w,*wb,*wma;
5284 struct map *map=data;
5286 char *search,buffer[256];
5287 int found,sp_match=0;
5289 dbg(1,"wm=%p prefix=%s\n",wm,wm->prefix);
5294 while(search[sp_match] == ' ')
5300 on.type=off.type=attr_active;
5303 wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
5304 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5305 w->spy=this->spacing*3;
5306 gui_internal_widget_append(wb, w);
5308 wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on, &off, 1);
5309 gui_internal_widget_append(w, wma);
5312 download_enabled.type=download_disabled.type=attr_update;
5313 download_enabled.u.num=1;
5314 download_disabled.u.num=0;
5315 wma=gui_internal_button_map_attr_new(this
5316 , _("Download Enabled")
5317 , gravity_left_center|orientation_horizontal|flags_fill
5320 , &download_disabled
5322 gui_internal_widget_append(w, wma);
5325 f=fopen("maps/areas.tsv","r");
5326 while (f && fgets(buffer, sizeof(buffer), f)) {
5327 char *nl,*description,*description_size,*bbox,*size=NULL;
5329 if ((nl=strchr(buffer,'\n')))
5331 if ((nl=strchr(buffer,'\r')))
5333 while(buffer[sp] == ' ')
5335 if ((bbox=strchr(buffer,'\t')))
5337 if (bbox && (size=strchr(bbox,'\t')))
5339 if (search && !strcmp(buffer, search)) {
5340 wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
5341 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
5342 wma->name=g_strdup(buffer+sp);
5343 wma->prefix=g_strdup(bbox);
5344 gui_internal_widget_append(w, wma);
5346 } else if (sp < sp_match)
5348 if (sp == sp_match && found && buffer[sp]) {
5349 description=g_strdup(buffer+sp);
5351 description_size=g_strdup_printf("%s (%s)",description,size);
5353 description_size=g_strdup(description);
5354 wma=gui_internal_button_new_with_callback(this, description_size, NULL,
5355 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
5356 g_free(description_size);
5357 wma->prefix=g_strdup(buffer);
5358 wma->name=description;
5359 gui_internal_widget_append(w, wma);
5363 gui_internal_menu_render(this);
5367 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5369 struct attr attr, on, off, description, type, data, url, active;
5370 struct widget *w,*wb,*row,*wma;
5372 struct attr_iter *iter;
5374 wb=gui_internal_menu(this, _("Maps"));
5375 //w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5376 //w->spy=this->spacing*3;
5377 w = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
5378 gui_internal_widget_append(wb, w);
5379 iter=navit_attr_iter_new();
5380 on.type=off.type=attr_active;
5383 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
5384 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
5385 label=g_strdup(description.u.str);
5387 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
5389 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
5391 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
5393 if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
5394 if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
5396 wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
5397 gravity_left_center|orientation_horizontal|flags_fill,
5398 gui_internal_cmd_map_download, attr.u.map);
5400 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
5401 attr.u.map, &on, &off, 1);
5403 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5404 gui_internal_widget_append(row, wma);
5407 navit_attr_iter_destroy(iter);
5408 gui_internal_menu_render(this);
5412 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
5414 struct attr vehicle = {attr_vehicle,{wm->data}};
5415 navit_set_attr(this->nav, &vehicle);
5419 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
5421 struct widget *w,*wb,*row;
5422 struct attr attr,sat_attr;
5423 struct vehicle *v=wm->data;
5426 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
5428 wb=gui_internal_menu(this, _("Show Satellite Status"));
5429 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
5430 gui_internal_menu_data(this)->redisplay_widget=wm;
5431 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5432 gui_internal_widget_append(wb, w);
5433 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
5434 row = gui_internal_widget_table_row_new(this,gravity_left_top);
5435 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
5436 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
5437 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
5438 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
5439 gui_internal_widget_append(w,row);
5440 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
5441 row = gui_internal_widget_table_row_new(this,gravity_left_top);
5442 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
5443 if (item_attr_get(attr.u.item, types[i], &sat_attr))
5444 str=g_strdup_printf("%ld", sat_attr.u.num);
5447 gui_internal_widget_append(row, gui_internal_label_new(this, str));
5450 gui_internal_widget_append(w,row);
5452 gui_internal_widget_append(wb, w);
5453 gui_internal_menu_render(this);
5457 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
5459 struct widget *w,*wb;
5461 struct vehicle *v=wm->data;
5462 wb=gui_internal_menu(this, _("Show NMEA Data"));
5463 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
5464 gui_internal_menu_data(this)->redisplay_widget=wm;
5465 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5466 gui_internal_widget_append(wb, w);
5467 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
5468 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
5469 gui_internal_menu_render(this);
5473 * A container to hold the selected vehicle and the desired profile in
5476 struct vehicle_and_profilename {
5477 struct vehicle *vehicle;
5482 * Figures out whether the given vehicle is the active vehicle.
5484 * @return true if the vehicle is active, false otherwise.
5487 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
5490 struct attr active_vehicle;
5492 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
5493 active_vehicle.u.vehicle=NULL;
5495 return active_vehicle.u.vehicle == vehicle;
5499 save_vehicle_xml(struct vehicle *v)
5502 struct attr_iter *iter=vehicle_attr_iter_new();
5506 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
5507 if (ATTR_IS_OBJECT(attr.type))
5511 printf(" %s=\"%s\"",attr_to_name(attr.type),attrtxt=attr_to_text(&attr, NULL, 1));
5517 printf("</vehicle>\n");
5520 vehicle_attr_iter_destroy(iter);
5525 * Reacts to a button press that changes a vehicle's active profile.
5527 * @see gui_internal_add_vehicle_profile
5530 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
5531 widget *wm, void *data)
5533 struct vehicle_and_profilename *vapn = data;
5534 struct vehicle *v = vapn->vehicle;
5535 char *profilename = vapn->profilename;
5536 struct attr vehicle_name_attr;
5537 char *vehicle_name = NULL;
5538 struct attr profilename_attr;
5540 // Get the vehicle name
5541 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
5542 vehicle_name = vehicle_name_attr.u.str;
5544 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
5547 // Change the profile name
5548 profilename_attr.type = attr_profilename;
5549 profilename_attr.u.str = profilename;
5550 if(!vehicle_set_attr(v, &profilename_attr)) {
5551 dbg(0, "Unable to set the vehicle's profile name\n");
5554 // Notify Navit that the routing should be re-done if this is the
5556 if (gui_internal_is_active_vehicle(this, v)) {
5557 struct attr vehicle;
5558 vehicle.type=attr_vehicle;
5559 vehicle.u.vehicle=v;
5560 navit_set_attr(this->nav, &vehicle);
5562 save_vehicle_xml(v);
5564 gui_internal_prune_menu_count(this, 1, 0);
5565 gui_internal_menu_vehicle_settings(this, v, vehicle_name);
5569 * Adds the vehicle profile to the GUI, allowing the user to pick a
5570 * profile for the currently selected vehicle.
5573 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
5574 *parent, struct vehicle *v, struct vehicleprofile *profile)
5576 // Just here to show up in the translation file, nice and close to
5577 // where the translations are actually used.
5578 struct attr profile_attr;
5579 struct attr *attr = NULL;
5581 char *active_profile = NULL;
5584 struct vehicle_and_profilename *context = NULL;
5586 #ifdef ONLY_FOR_TRANSLATION
5587 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
5590 // Figure out the profile name
5591 attr = attr_search(profile->attrs, NULL, attr_name);
5593 dbg(0, "Adding vehicle profile failed. attr==NULL");
5598 // Determine whether the profile is the active one
5599 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
5600 active_profile = profile_attr.u.str;
5601 active = active_profile != NULL && !strcmp(name, active_profile);
5603 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
5604 active_profile, active);
5606 // Build a translatable label.
5608 label = g_strdup_printf(_("Current profile: %s"), _(name));
5610 label = g_strdup_printf(_("Change profile to: %s"), _(name));
5613 // Create the context object (the vehicle and the desired profile)
5614 context = g_new0(struct vehicle_and_profilename, 1);
5615 context->vehicle = v;
5616 context->profilename = name;
5619 gui_internal_widget_append(parent,
5620 gui_internal_button_new_with_callback(
5622 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
5623 gravity_left_center|orientation_horizontal|flags_fill,
5624 gui_internal_cmd_set_active_profile, context));
5630 gui_internal_menu_vehicle_settings(struct gui_priv *this, struct vehicle *v, char *name)
5632 struct widget *w,*wb,*row;
5634 struct vehicleprofile *profile = NULL;
5637 wb=gui_internal_menu(this, name);
5638 w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
5639 gui_internal_widget_append(wb, w);
5641 // Add the "Set as active" button if this isn't the active
5643 if (!gui_internal_is_active_vehicle(this, v)) {
5644 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5645 gui_internal_widget_append(row,
5646 gui_internal_button_new_with_callback(this, _("Set as active"),
5647 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5648 gui_internal_cmd_set_active_vehicle, v));
5651 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
5652 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5653 gui_internal_widget_append(row,
5654 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
5655 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5656 gui_internal_cmd_show_satellite_status, v));
5658 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
5659 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5660 gui_internal_widget_append(row,
5661 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
5662 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5663 gui_internal_cmd_show_nmea_data, v));
5666 // Add all the possible vehicle profiles to the menu
5667 profiles = navit_get_vehicleprofiles(this->nav);
5669 profile = (struct vehicleprofile *)profiles->data;
5670 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5671 gui_internal_add_vehicle_profile(this, row, v, profile);
5672 profiles = g_list_next(profiles);
5675 callback_list_call_attr_2(this->cbl, attr_vehicle, w, v);
5676 gui_internal_menu_render(this);
5680 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
5682 gui_internal_menu_vehicle_settings(this, wm->data, wm->text);
5686 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5688 struct attr attr,attr2,vattr;
5689 struct widget *w,*wb,*wl;
5690 struct attr_iter *iter;
5691 struct attr active_vehicle;
5693 iter=navit_attr_iter_new();
5694 if (navit_get_attr(this->nav, attr_vehicle, &attr, iter) && !navit_get_attr(this->nav, attr_vehicle, &attr2, iter)) {
5695 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
5696 navit_attr_iter_destroy(iter);
5697 gui_internal_menu_vehicle_settings(this, attr.u.vehicle, vattr.u.str);
5700 navit_attr_iter_destroy(iter);
5702 wb=gui_internal_menu(this, _("Vehicle"));
5703 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5704 w->spy=this->spacing*3;
5705 gui_internal_widget_append(wb, w);
5706 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
5707 active_vehicle.u.vehicle=NULL;
5708 iter=navit_attr_iter_new();
5709 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
5710 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
5711 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
5712 image_new_xs(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
5713 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
5714 wl->text=g_strdup(vattr.u.str);
5715 gui_internal_widget_append(w, wl);
5717 navit_attr_iter_destroy(iter);
5718 gui_internal_menu_render(this);
5723 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5725 struct widget *wb,*w;
5727 wb=gui_internal_menu(this, _("Rules"));
5728 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5729 w->spy=this->spacing*3;
5730 gui_internal_widget_append(wb, w);
5733 on.type=off.type=attr_tracking;
5734 gui_internal_widget_append(w,
5735 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
5739 on.type=off.type=attr_orientation;
5740 gui_internal_widget_append(w,
5741 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
5745 on.type=off.type=attr_follow_cursor;
5746 gui_internal_widget_append(w,
5747 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
5751 on.type=off.type=attr_waypoints_flag;
5752 gui_internal_widget_append(w,
5753 gui_internal_button_navit_attr_new(this, _("Plan with Waypoints"), gravity_left_center|orientation_horizontal|flags_fill,
5755 gui_internal_menu_render(this);
5758 //##############################################################################################################
5761 //# Authors: Martin Schaller (04/2008)
5762 //##############################################################################################################
5763 static void gui_internal_motion(void *data, struct point *p)
5766 struct gui_priv *this=data;
5767 if (!this->root.children) {
5768 navit_handle_motion(this->nav, p);
5774 if(!this->motion_timeout_callback)
5775 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_motion_cb), this);
5776 if(!this->motion_timeout_event)
5777 this->motion_timeout_event=event_add_timeout(30,0, this->motion_timeout_callback);
5781 find_attr(const char **names, const char **values, const char *name)
5784 if (!g_strcasecmp(*names, name))
5786 names+=xml_attr_distance;
5787 values+=xml_attr_distance;
5793 find_attr_dup(const char **names, const char **values, const char *name)
5795 return g_strdup(find_attr(names, values, name));
5799 gui_internal_evaluate(struct gui_priv *this, const char *command)
5802 command_evaluate(&this->self, command);
5807 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
5809 gui_internal_evaluate(this,w->command);
5813 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
5816 if (w->form == form && w->name) {
5817 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
5819 gui_set_attr(this->self.u.gui, attr);
5825 gui_internal_html_submit_set(this, w, form);
5832 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
5834 struct widget *menu;
5837 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
5838 l=g_list_last(this->root.children);
5840 graphics_draw_mode(this->gra, draw_mode_begin);
5841 gui_internal_highlight_do(this, NULL);
5842 gui_internal_menu_render(this);
5843 graphics_draw_mode(this->gra, draw_mode_end);
5844 gui_internal_html_submit_set(this, menu, w->form);
5845 gui_internal_evaluate(this,w->form->onsubmit);
5849 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
5852 gui_internal_prune_menu_count(this, 1, 0);
5853 if (href && href[0] == '#') {
5854 dbg(1,"href=%s\n",href);
5856 this->href=g_strdup(href);
5857 gui_internal_html_menu(this, this->html_text, href+1);
5862 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
5864 gui_internal_html_load_href(this, w->command, 0);
5867 struct div_flags_map {
5871 } div_flags_map[] = {
5872 {"gravity","none",gravity_none},
5873 {"gravity","left",gravity_left},
5874 {"gravity","xcenter",gravity_xcenter},
5875 {"gravity","right",gravity_right},
5876 {"gravity","top",gravity_top},
5877 {"gravity","ycenter",gravity_ycenter},
5878 {"gravity","bottom",gravity_bottom},
5879 {"gravity","left_top",gravity_left_top},
5880 {"gravity","top_center",gravity_top_center},
5881 {"gravity","right_top",gravity_right_top},
5882 {"gravity","left_center",gravity_left_center},
5883 {"gravity","center",gravity_center},
5884 {"gravity","right_center",gravity_right_center},
5885 {"gravity","left_bottom",gravity_left_bottom},
5886 {"gravity","bottom_center",gravity_bottom_center},
5887 {"gravity","right_bottom",gravity_right_bottom},
5888 {"expand","1",flags_expand},
5889 {"fill","1",flags_fill},
5890 {"orientation","horizontal",orientation_horizontal},
5891 {"orientation","vertical",orientation_vertical},
5892 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
5896 div_flag(const char **names, const char **values, char *name)
5900 const char *value=find_attr(names, values, name);
5903 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
5904 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
5905 ret|=div_flags_map[i].flags;
5911 div_flags(const char **names, const char **values)
5914 flags = div_flag(names, values, "gravity");
5915 flags |= div_flag(names, values, "orientation");
5916 flags |= div_flag(names, values, "expand");
5917 flags |= div_flag(names, values, "fill");
5921 static struct widget *
5922 html_image(struct gui_priv *this, const char **names, const char **values)
5924 const char *src, *size;
5925 struct graphics_image *img=NULL;
5927 src=find_attr(names, values, "src");
5930 size=find_attr(names, values, "size");
5933 if (!strcmp(size,"l"))
5934 img=image_new_l(this, src);
5935 else if (!strcmp(size,"s"))
5936 img=image_new_s(this, src);
5937 else if (!strcmp(size,"xs"))
5938 img=image_new_xs(this, src);
5941 return gui_internal_image_new(this, img);
5945 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
5947 struct gui_priv *this=data;
5949 enum html_tag tag=html_tag_none;
5950 struct html *html=&this->html[this->html_depth];
5951 const char *cond, *type;
5953 if (!g_strcasecmp(tag_name,"text"))
5959 html->refresh_cond=NULL;
5961 html->container=NULL;
5962 cond=find_attr(names, values, "cond");
5964 if (cond && !this->html_skip) {
5965 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
5969 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
5970 if (!g_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
5971 tag=html_tag_map[i].tag;
5976 if (!this->html_skip && !html->skip) {
5979 html->name=find_attr_dup(names, values, "name");
5981 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
5983 this->html_anchor_found=1;
5985 html->command=find_attr_dup(names, values, "onclick");
5986 html->href=find_attr_dup(names, values, "href");
5987 html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
5990 html->command=find_attr_dup(names, values, "onclick");
5991 html->w=html_image(this, names, values);
5994 this->form=g_new0(struct form, 1);
5995 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
5997 case html_tag_input:
5998 type=find_attr_dup(names, values, "type");
6001 if (!strcmp(type,"image")) {
6002 html->w=html_image(this, names, values);
6004 html->w->state|=STATE_SENSITIVE;
6005 html->w->func=gui_internal_html_submit;
6008 if (!strcmp(type,"text") || !strcmp(type,"password")) {
6009 html->w=gui_internal_label_new(this, NULL);
6010 html->w->background=this->background;
6011 html->w->flags |= div_flags(names, values);
6012 html->w->state|=STATE_EDITABLE;
6013 if (!this->editable) {
6014 this->editable=html->w;
6015 html->w->state|=STATE_EDIT;
6017 this->keyboard_required=1;
6018 if (!strcmp(type,"password"))
6019 html->w->flags2 |= 1;
6022 html->w->form=this->form;
6023 html->w->name=find_attr_dup(names, values, "name");
6027 html->w=gui_internal_box_new(this, div_flags(names, values));
6028 html->container=this->html_container;
6029 this->html_container=html->w;
6035 this->html_skip+=html->skip;
6040 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
6042 struct gui_priv *this=data;
6044 struct html *parent=NULL;
6046 if (!g_strcasecmp(tag_name,"text"))
6049 html=&this->html[this->html_depth];
6050 if (this->html_depth > 0)
6051 parent=&this->html[this->html_depth-1];
6054 if (!this->html_skip) {
6055 if (html->command && html->w) {
6056 html->w->state |= STATE_SENSITIVE;
6057 html->w->command=html->command;
6058 html->w->func=gui_internal_html_command;
6061 if (parent && (parent->href || parent->command) && html->w) {
6062 html->w->state |= STATE_SENSITIVE;
6063 if (parent->command) {
6064 html->w->command=g_strdup(parent->command);
6065 html->w->func=gui_internal_html_command;
6067 html->w->command=g_strdup(parent->href);
6068 html->w->func=gui_internal_html_href;
6071 switch (html->tag) {
6073 this->html_container=html->container;
6075 case html_tag_input:
6076 gui_internal_widget_append(this->html_container, html->w);
6085 this->html_skip-=html->skip;
6086 g_free(html->command);
6089 g_free(html->refresh_cond);
6093 gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data)
6095 if (gui_internal_menu_data(this) == menu_data) {
6096 char *href=g_strdup(menu_data->href);
6097 gui_internal_html_load_href(this, href, 1);
6103 gui_internal_set_refresh_callback(struct gui_priv *this, char *cond)
6105 dbg(0,"cond=%s\n",cond);
6107 enum attr_type type;
6108 struct object_func *func;
6109 struct menu_data *menu_data=gui_internal_menu_data(this);
6110 dbg(0,"navit=%p\n",this->nav);
6111 type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
6112 if (type == attr_none)
6114 func=object_func_lookup(menu_data->refresh_callback_obj.type);
6115 if (!func || !func->add_attr)
6117 menu_data->refresh_callback.type=attr_callback;
6118 menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,this,menu_data);
6119 func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
6124 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
6126 struct gui_priv *this=data;
6128 int depth=this->html_depth-1;
6129 struct html *html=&this->html[depth];
6130 gchar *text_stripped;
6132 if (this->html_skip)
6134 while (isspace(text[0])) {
6138 while (len > 0 && isspace(text[len-1]))
6141 text_stripped = g_strndup(text, len);
6142 if (html->tag == html_tag_html && depth > 2) {
6143 if (this->html[depth-1].tag == html_tag_script) {
6144 html=&this->html[depth-2];
6147 switch (html->tag) {
6149 if (html->name && len) {
6150 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
6151 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
6152 gui_internal_menu_data(this)->href=g_strdup(this->href);
6153 gui_internal_set_refresh_callback(this, html->refresh_cond);
6154 this->html_container->spx=this->spacing*10;
6158 if (!this->html_container) {
6159 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
6160 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
6161 this->html_container->spx=this->spacing*10;
6166 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
6167 gui_internal_widget_append(w, html->w);
6168 gui_internal_widget_append(w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
6174 gui_internal_widget_append(html->w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
6177 case html_tag_script:
6178 dbg(1,"execute %s\n",text_stripped);
6179 gui_internal_evaluate(this,text_stripped);
6184 g_free(text_stripped);
6188 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
6190 char *doc=g_strdup(document);
6191 graphics_draw_mode(this->gra, draw_mode_begin);
6192 this->html_container=NULL;
6194 this->html_anchor=anchor;
6195 this->html_anchor_found=0;
6197 this->keyboard_required=0;
6198 this->editable=NULL;
6199 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
6200 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
6202 if (this->keyboard_required && this->keyboard) {
6203 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
6204 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
6206 gui_internal_menu_render(this);
6207 graphics_draw_mode(this->gra, draw_mode_end);
6212 gui_internal_enter(struct gui_priv *this, int ignore)
6214 struct graphics *gra=this->gra;
6216 this->ignore_button=ignore;
6218 navit_block(this->nav, 1);
6219 graphics_overlay_disable(gra, 1);
6222 this->root.background=this->background;
6226 gui_internal_leave(struct gui_priv *this)
6228 graphics_draw_mode(this->gra, draw_mode_end);
6232 gui_internal_set_click_coord(struct gui_priv *this, struct point *p)
6237 struct transformation *trans;
6238 attr_free(this->click_coord_geo);
6239 this->click_coord_geo=NULL;
6241 trans=navit_get_trans(this->nav);
6242 transform_reverse(trans, p, &c);
6243 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
6244 this->clickp.pro=transform_get_projection(trans);
6247 transform_to_geo(this->clickp.pro, &c, &g);
6248 attr.u.coord_geo=&g;
6249 attr.type=attr_click_coord_geo;
6250 this->click_coord_geo=attr_dup(&attr);
6255 gui_internal_set_position_coord(struct gui_priv *this)
6257 struct transformation *trans;
6258 struct attr attr,attrp;
6261 attr_free(this->position_coord_geo);
6262 this->position_coord_geo=NULL;
6263 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
6264 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
6265 trans=navit_get_trans(this->nav);
6266 this->position_coord_geo=attr_dup(&attrp);
6267 this->vehiclep.pro=transform_get_projection(trans);
6268 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
6269 this->vehiclep.x=c.x;
6270 this->vehiclep.y=c.y;
6275 gui_internal_enter_setup(struct gui_priv *this)
6277 if (!this->mouse_button_clicked_on_map)
6278 gui_internal_set_position_coord(this);
6282 gui_internal_html_main_menu(struct gui_priv *this)
6284 gui_internal_prune_menu(this, NULL);
6285 gui_internal_html_load_href(this, "#Main Menu", 0);
6289 gui_internal_cmd_menu(struct gui_priv *this, int ignore, char *href)
6292 gui_internal_enter(this, ignore);
6293 gui_internal_enter_setup(this);
6296 gui_internal_html_load_href(this, href, 0);
6298 gui_internal_html_main_menu(this);
6302 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6305 int i=0, ignore=0, replace=0;
6307 if (in && in[i] && ATTR_IS_INT(in[i]->type))
6308 ignore=in[i++]->u.num;
6310 if (in && in[i] && ATTR_IS_STRING(in[i]->type)) {
6311 href=in[i++]->u.str;
6312 if (in[i] && ATTR_IS_INT(in[i]->type))
6313 replace=in[i++]->u.num;
6316 if (this->root.children) {
6319 gui_internal_html_load_href(this, href, replace);
6322 gui_internal_cmd_menu(this, ignore, href);
6327 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
6329 if (widget->text && strlen(widget->text)) {
6330 if (this->position_coord_geo)
6331 navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
6333 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
6335 g_free(widget->text);
6337 gui_internal_prune_menu(this, NULL);
6338 gui_internal_check_exit(this);
6342 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
6344 gui_internal_cmd_log_do(this, widget->data);
6348 gui_internal_cmd_log(struct gui_priv *this)
6350 struct widget *w,*wb,*wk,*wl,*we,*wnext;
6351 gui_internal_enter(this, 1);
6352 gui_internal_set_click_coord(this, NULL);
6353 gui_internal_enter_setup(this);
6354 wb=gui_internal_menu(this, "Log Message");
6355 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
6356 gui_internal_widget_append(wb, w);
6357 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
6358 gui_internal_widget_append(w, we);
6359 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
6360 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
6361 wk->background=this->background;
6362 wk->flags |= flags_expand|flags_fill;
6363 wk->func = gui_internal_call_linked_on_finish;
6364 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
6365 wnext->state |= STATE_SENSITIVE;
6366 wnext->func = gui_internal_cmd_log_clicked;
6369 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
6370 gui_internal_widget_append(w, wl);
6372 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
6373 gui_internal_menu_render(this);
6374 gui_internal_leave(this);
6378 gui_internal_check_exit(struct gui_priv *this)
6380 struct graphics *gra=this->gra;
6381 if (! this->root.children) {
6382 gui_internal_search_idle_end(this);
6383 gui_internal_search_list_destroy(this);
6384 graphics_overlay_disable(gra, 0);
6385 if (!navit_block(this->nav, 0)) {
6387 navit_draw(this->nav);
6389 navit_draw_displaylist(this->nav);
6395 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
6399 attr->u.num=this->root.children != NULL;
6401 case attr_click_coord_geo:
6402 if (!this->click_coord_geo)
6404 *attr=*this->click_coord_geo;
6406 case attr_position_coord_geo:
6407 if (!this->position_coord_geo)
6409 *attr=*this->position_coord_geo;
6412 attr->u.num=this->pitch;
6415 attr->u.num=this->mouse_button_clicked_on_map;
6425 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
6427 switch (attr->type) {
6429 g_free(this->html_text);
6430 this->html_text=g_strdup(attr->u.str);
6438 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
6440 switch (attr->type) {
6441 case attr_fullscreen:
6442 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
6443 graphics_draw_mode(this->gra, draw_mode_end);
6444 this->win->fullscreen(this->win, attr->u.num > 0);
6445 graphics_draw_mode(this->gra, draw_mode_begin);
6447 this->fullscreen=attr->u.num;
6449 case attr_menu_on_map_click:
6450 this->menu_on_map_click=attr->u.num;
6452 case attr_on_map_click:
6453 g_free(this->on_map_click);
6454 this->on_map_click=g_strdup(attr->u.str);
6457 dbg(0,"%s\n",attr_to_name(attr->type));
6462 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
6464 struct displaylist_handle *dlh;
6465 struct displaylist *display;
6466 struct displayitem *di;
6467 struct attr cb,**attr_list=NULL;
6470 display=navit_get_displaylist(this->nav);
6471 dlh=graphics_displaylist_open(display);
6472 while ((di=graphics_displaylist_next(dlh))) {
6473 struct item *item=graphics_displayitem_get_item(di);
6474 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
6475 graphics_displayitem_within_dist(display, di, p, this->radius)) {
6476 struct map_rect *mr=map_rect_new(item->map, NULL);
6477 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
6479 if (itemo && item_attr_get(itemo, attr_data, &attr))
6480 attr_list=attr_generic_add_attr(attr_list, &attr);
6481 map_rect_destroy(mr);
6484 graphics_displaylist_close(dlh);
6485 if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
6486 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
6487 attr_list_free(attr_list);
6490 //##############################################################################################################
6491 //# Description: Convert one geo coordinate in human readable form to double value.
6493 //# Authors: Martin Bruns (05/2012), mdankov
6494 //##############################################################################################################
6496 gui_internal_coordinate_parse(char *s, char plus, char minus, double *x)
6499 char *degree, *minute, *second;
6505 if (strchr(s, minus)!=NULL)
6507 else if (strchr(s, plus)!=NULL)
6514 /* Can't just use strtok here because ° is multibyte sequence in utf8 */
6516 minute=strstr(s,"°");
6519 minute+=strlen("°");
6522 sscanf(degree, "%lf", x);
6524 if(strchr(degree, plus) || strchr(degree, minus)) {
6525 dbg(3,"degree %c/%c found\n",plus,minus);
6526 } else {/* DEGREES_MINUTES */
6529 minute = strtok(minute,"'");
6530 sscanf(minute, "%lf", &tmp);
6532 if(strchr(minute, plus) || strchr(minute, minus)) {
6533 dbg(3,"minute %c/%c found\n",plus,minus);
6534 } else { /* DEGREES_MINUTES_SECONDS */
6535 second=strtok(NULL,"");
6538 sscanf(second, "%lf", &tmp);
6546 //##############################################################################################################
6549 //# Authors: Martin Bruns (05/2012)
6550 //##############################################################################################################
6552 gui_internal_cmd_enter_coord_do(struct gui_priv *this, struct widget *widget)
6556 double latitude, longitude;
6557 dbg(1,"text entered:%s\n", widget->text);
6559 /* possible entry can be identical to coord_format output but only space between lat and lng is allowed */
6560 widgettext=g_ascii_strup(widget->text,-1);
6562 lat=strtok(widgettext," ");
6563 lng=strtok(NULL,"");
6569 if( gui_internal_coordinate_parse(lat, 'N', 'S', &latitude) && gui_internal_coordinate_parse(lng, 'E', 'W', &longitude) ) {
6571 widgettext=g_strdup_printf("%lf %lf", longitude, latitude);
6572 pcoord_parse(widgettext, projection_mg, &widget->c );
6573 } else if(!pcoord_parse(widget->text, projection_mg, &widget->c )) {
6579 gui_internal_cmd_position(this, widget, (void*)8);
6582 //##############################################################################################################
6585 //# Authors: Martin Bruns (05/2012)
6586 //##############################################################################################################
6588 gui_internal_cmd_enter_coord_clicked(struct gui_priv *this, struct widget *widget, void *data)
6591 gui_internal_cmd_enter_coord_do(this, widget->data);
6594 //##############################################################################################################
6597 //# Authors: Martin Bruns (05/2012)
6598 //##############################################################################################################
6600 gui_internal_cmd_enter_coord(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6602 struct widget *w, *wb, *wk, *wr, *we, *wnext, *row;
6603 wb=gui_internal_menu(this, _("Enter Coordinates"));
6604 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
6605 gui_internal_widget_append(wb, w);
6606 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
6607 gui_internal_widget_append(w, wr);
6608 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
6609 gui_internal_widget_append(wr, we);
6612 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
6613 gui_internal_widget_append(wb, w);
6615 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
6616 gui_internal_widget_append(w, we);*/
6617 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Longitude Latitude")));
6618 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
6619 wk->background=this->background;
6620 wk->flags |= flags_expand|flags_fill;
6621 wk->func = gui_internal_call_linked_on_finish;
6622 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
6623 wnext->state |= STATE_SENSITIVE;
6624 wnext->func = gui_internal_cmd_enter_coord_clicked;
6627 row=gui_internal_text_new(this, _("Enter coordinates, for example:"), gravity_top_center|flags_fill|orientation_vertical);
6628 gui_internal_widget_append(wr,row);
6629 row=gui_internal_text_new(this, "52.5219N 19.4127E", gravity_top_center|flags_fill|orientation_vertical);
6630 gui_internal_widget_append(wr,row);
6631 row=gui_internal_text_new(this, "52°31.3167N 19°24.7667E", gravity_top_center|flags_fill|orientation_vertical);
6632 gui_internal_widget_append(wr,row);
6633 row=gui_internal_text_new(this, "52°31'19N 19°24'46E", gravity_top_center|flags_fill|orientation_vertical);
6634 gui_internal_widget_append(wr,row);
6637 gui_internal_widget_append(w, gui_internal_keyboard(this,56));
6638 gui_internal_menu_render(this);
6641 //##############################################################################################################
6642 //# Description: Function to handle mouse clicks and scroll wheel movement
6644 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
6645 //##############################################################################################################
6646 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
6648 struct gui_priv *this=data;
6649 struct graphics *gra=this->gra;
6651 dbg(1,"enter %d %d\n", pressed, button);
6652 // if still on the map (not in the menu, yet):
6653 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
6654 if (!this->root.children || this->ignore_button) {
6656 this->ignore_button=0;
6657 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
6658 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
6659 dbg(1,"navit has handled button\n");
6662 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
6665 if (this->on_map_click || this->menu_on_map_click) {
6666 this->mouse_button_clicked_on_map=1;
6667 gui_internal_set_click_coord(this, p);
6668 gui_internal_set_position_coord(this);
6669 if (this->on_map_click)
6670 command_evaluate(&this->self, this->on_map_click);
6672 gui_internal_cmd_menu(this, 0, NULL);
6673 this->mouse_button_clicked_on_map=0;
6674 } else if (this->signal_on_map_click) {
6675 gui_internal_dbus_signal(this, p);
6683 * If already in the menu:
6689 gui_internal_gesture_ring_clear(this);
6690 gui_internal_gesture_ring_add(this, p);
6691 gui_internal_highlight(this);
6694 gui_internal_gesture_ring_add(this, p);
6695 gui_internal_gesture_get_vector(this, 300, NULL, &dx, &dy);
6698 graphics_draw_mode(gra, draw_mode_begin);
6699 if(!gui_internal_gesture_do(this) && this->pressed!=2 && abs(dx)<this->icon_s && abs(dy)<this->icon_s)
6700 gui_internal_call_highlighted(this);
6702 if (!event_main_loop_has_quit()) {
6703 gui_internal_highlight(this);
6704 graphics_draw_mode(gra, draw_mode_end);
6705 gui_internal_check_exit(this);
6711 gui_internal_setup(struct gui_priv *this)
6713 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
6714 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
6715 struct graphics *gra=this->gra;
6716 unsigned char *buffer;
6720 if (this->background)
6722 this->background=graphics_gc_new(gra);
6723 this->background2=graphics_gc_new(gra);
6724 this->highlight_background=graphics_gc_new(gra);
6725 graphics_gc_set_foreground(this->highlight_background, &cbh);
6726 this->foreground=graphics_gc_new(gra);
6727 graphics_gc_set_foreground(this->foreground, &cf);
6728 this->text_background=graphics_gc_new(gra);
6729 this->text_foreground=graphics_gc_new(gra);
6730 graphics_gc_set_foreground(this->background, &this->background_color);
6731 graphics_gc_set_foreground(this->background2, &this->background2_color);
6732 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
6733 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
6734 gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
6735 if (file_get_contents(gui_file,&buffer,&size)) {
6736 char *command=g_malloc(size+1);
6737 strncpy(command,(const char *)buffer,size);
6739 command_evaluate(&this->self, command);
6746 //##############################################################################################################
6749 //# Authors: Martin Schaller (04/2008)
6750 //##############################################################################################################
6751 static void gui_internal_resize(void *data, int w, int h)
6753 struct gui_priv *this=data;
6756 gui_internal_setup(this);
6758 if (this->root.w != w || this->root.h != h) {
6763 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
6764 navit_handle_resize(this->nav, w, h);
6765 if (this->root.children) {
6767 gui_internal_html_main_menu(this);
6769 gui_internal_menu_render(this);
6775 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
6790 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
6792 GList *l=wi->children;
6793 // Skip hidden elements
6794 if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
6796 if ((wi->state & STATE_SENSITIVE) ) {
6799 gui_internal_keynav_point(wi, -dx, -dy, &wp);
6801 dist1=(wp.x-p->x)*dx;
6804 dist1=(wp.y-p->y)*dy;
6812 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);
6818 if (dist1 < *distance) {
6825 struct widget *child=l->data;
6826 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
6832 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
6834 struct widget *result,*menu=g_list_last(this->root.children)->data;
6837 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6838 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
6844 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
6846 gui_internal_keynav_point(result, dx, dy, &p);
6847 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
6852 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
6853 dbg(1,"result=%p\n", result);
6865 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
6866 dbg(1,"wraparound result=%p\n", result);
6868 gui_internal_highlight_do(this, result);
6870 gui_internal_say(this, result, 1);
6873 //##############################################################################################################
6876 //# Authors: Martin Schaller (04/2008)
6877 //##############################################################################################################
6878 static void gui_internal_keypress(void *data, char *key)
6880 struct gui_priv *this=data;
6883 if (!this->root.children) {
6884 transform_get_size(navit_get_trans(this->nav), &w, &h);
6889 navit_set_center_screen(this->nav, &p, 1);
6891 case NAVIT_KEY_DOWN:
6894 navit_set_center_screen(this->nav, &p, 1);
6896 case NAVIT_KEY_LEFT:
6899 navit_set_center_screen(this->nav, &p, 1);
6901 case NAVIT_KEY_RIGHT:
6904 navit_set_center_screen(this->nav, &p, 1);
6906 case NAVIT_KEY_ZOOM_IN:
6907 navit_zoom_in(this->nav, 2, NULL);
6909 case NAVIT_KEY_ZOOM_OUT:
6910 navit_zoom_out(this->nav, 2, NULL);
6912 case NAVIT_KEY_RETURN:
6913 case NAVIT_KEY_MENU:
6914 gui_internal_set_click_coord(this, NULL);
6915 gui_internal_cmd_menu(this, 0, NULL);
6920 graphics_draw_mode(this->gra, draw_mode_begin);
6922 case NAVIT_KEY_LEFT:
6923 gui_internal_keynav_highlight_next(this,-1,0);
6925 case NAVIT_KEY_RIGHT:
6926 gui_internal_keynav_highlight_next(this,1,0);
6929 gui_internal_keynav_highlight_next(this,0,-1);
6931 case NAVIT_KEY_DOWN:
6932 gui_internal_keynav_highlight_next(this,0,1);
6934 case NAVIT_KEY_BACK:
6935 if (g_list_length(this->root.children) > 1)
6936 gui_internal_back(this, NULL, NULL);
6938 gui_internal_prune_menu(this, NULL);
6940 case NAVIT_KEY_RETURN:
6941 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6942 gui_internal_call_highlighted(this);
6944 gui_internal_keypress_do(this, key);
6947 gui_internal_keypress_do(this, key);
6949 if (!event_main_loop_has_quit()) {
6950 graphics_draw_mode(this->gra, draw_mode_end);
6951 gui_internal_check_exit(this);
6956 //##############################################################################################################
6959 //# Authors: Martin Schaller (04/2008)
6960 //##############################################################################################################
6961 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
6964 struct transformation *trans=navit_get_trans(this->nav);
6966 win=graphics_get_data(gra, "window");
6969 navit_ignore_graphics_events(this->nav, 1);
6972 navit_ignore_graphics_events(this->nav, 1);
6973 transform_get_size(trans, &this->root.w, &this->root.h);
6974 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
6975 graphics_add_callback(gra, this->resize_cb);
6976 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
6977 graphics_add_callback(gra, this->button_cb);
6978 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
6979 graphics_add_callback(gra, this->motion_cb);
6980 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
6981 graphics_add_callback(gra, this->keypress_cb);
6982 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
6983 graphics_add_callback(gra, this->window_closed_cb);
6985 // set fullscreen if needed
6986 if (this->fullscreen)
6987 this->win->fullscreen(this->win, this->fullscreen != 0);
6988 /* Was resize callback already issued? */
6989 if (navit_get_ready(this->nav) & 2)
6990 gui_internal_setup(this);
6994 static void gui_internal_disable_suspend(struct gui_priv *this)
6996 if (this->win->disable_suspend)
6997 this->win->disable_suspend(this->win);
7000 //##############################################################################################################
7003 //# Authors: Martin Schaller (04/2008)
7004 //##############################################################################################################
7005 struct gui_methods gui_internal_methods = {
7008 gui_internal_set_graphics,
7012 gui_internal_disable_suspend,
7013 gui_internal_get_attr,
7014 gui_internal_add_attr,
7015 gui_internal_set_attr,
7019 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
7021 struct attr private_data = { attr_private_data, {(void *)&priv->data}};
7023 *out=attr_generic_add_attr(*out, &private_data);
7027 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
7029 callback_list_add(priv->cbl, cb);
7033 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
7035 callback_list_remove(priv->cbl, cb);
7039 static struct gui_internal_methods gui_internal_methods_ext = {
7040 gui_internal_add_callback,
7041 gui_internal_remove_callback,
7042 gui_internal_menu_render,
7049 gui_internal_get_flags(struct widget *widget)
7051 return widget->flags;
7055 gui_internal_set_flags(struct widget *widget, enum flags flags)
7057 widget->flags=flags;
7061 gui_internal_get_state(struct widget *widget)
7063 return widget->state;
7067 gui_internal_set_state(struct widget *widget, int state)
7069 widget->state=state;
7073 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
7079 gui_internal_set_data(struct widget *widget, void *data)
7085 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
7087 widget->background=this->background;
7090 static struct gui_internal_widget_methods gui_internal_widget_methods = {
7091 gui_internal_widget_append,
7092 gui_internal_button_new,
7093 gui_internal_button_new_with_callback,
7094 gui_internal_box_new,
7095 gui_internal_label_new,
7096 gui_internal_image_new,
7097 gui_internal_keyboard,
7099 gui_internal_get_flags,
7100 gui_internal_set_flags,
7101 gui_internal_get_state,
7102 gui_internal_set_state,
7103 gui_internal_set_func,
7104 gui_internal_set_data,
7105 gui_internal_set_default_background,
7109 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
7111 char *str=NULL,*str2=NULL;
7112 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
7115 dbg(1,"%s\n",attr_to_name(in[0]->type));
7116 if (ATTR_IS_STRING(in[0]->type)) {
7119 if (ATTR_IS_COORD_GEO(in[0]->type)) {
7120 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
7123 str=g_strdup_printf("<html>%s</html>\n",str);
7124 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
7132 * @brief Creates a new table widget.
7134 * Creates and returns a new table widget. This function will
7135 * setup next/previous buttons as children.
7137 * @param this The graphics context.
7138 * @param flags widget sizing flags.
7139 * @returns The newly created widget
7141 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
7143 struct widget * widget = g_new0(struct widget,1);
7144 struct table_data * data = NULL;
7145 widget->type=widget_table;
7146 widget->flags=flags;
7147 widget->state=STATE_SCROLLABLE;
7148 widget->data=g_new0(struct table_data,1);
7149 widget->data_free=gui_internal_table_data_free;
7151 // We have to set background here explicitly
7152 // because it will be used by inner elements created later in this
7153 // function (navigation buttons). Else that elements won't have
7155 widget->background=this->background;
7156 data = (struct table_data*)widget->data;
7159 data->next_button=gui_internal_box_new(this, gravity_center|orientation_horizontal);
7160 gui_internal_widget_append(data->next_button, gui_internal_text_new(this,_("Next"),gravity_center|orientation_horizontal));
7161 gui_internal_widget_append(data->next_button, gui_internal_image_new(this, image_new_xs(this, "gui_arrow_right")));
7162 data->next_button->func=gui_internal_table_button_next;
7163 data->next_button->data=widget;
7166 data->prev_button = gui_internal_button_new_with_callback
7168 image_new_xs(this, "gui_arrow_left"),
7169 gravity_center |orientation_horizontal,
7170 gui_internal_table_button_prev,NULL);
7172 data->prev_button->data=widget;
7176 data->button_box=gui_internal_box_new(this,
7177 gravity_center|orientation_horizontal);
7178 gui_internal_widget_append(widget, data->button_box);
7179 gui_internal_widget_append(data->button_box, data->prev_button);
7180 gui_internal_widget_append(data->button_box, data->next_button);
7182 data->button_box->bl=this->spacing;
7183 gui_internal_widget_pack(this,data->button_box);
7191 * @brief Clears all the rows from the table.
7192 * This function removes all rows from a table.
7193 * New rows can later be added to the table.
7195 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
7198 struct table_data * table_data = (struct table_data* ) table->data;
7200 iter = table->children;
7202 if(iter->data != table_data->button_box) {
7203 struct widget * child = (struct widget*)iter->data;
7204 gui_internal_widget_destroy(this,child);
7205 if(table->children == iter) {
7206 table->children = g_list_remove(iter,iter->data);
7207 iter=table->children;
7210 iter = g_list_remove(iter,iter->data);
7213 iter = g_list_next(iter);
7217 table_data->top_row=NULL;
7218 table_data->bottom_row=NULL;
7222 * @brief Check if table has any data rows filled.
7223 * @param this The graphics context
7224 * @param table table widget
7225 * @returns 1 if the table is empty, 0 if there any data rows present.
7227 static int gui_internal_widget_table_is_empty(struct gui_priv *this, struct widget * table)
7230 struct table_data *td=(struct table_data*) table->data;
7232 for(l=table->children;l;l=g_list_next(l)) {
7233 if(l->data != td->button_box)
7242 * @brief Move GList pointer to the next table row, skipping other table children (button box, for example).
7243 * @param row GList pointer into the children list
7244 * @returns GList pointer to the next row in the children list, or NULL if there are no any rows left.
7246 static GList * gui_internal_widget_table_next_row(GList * row)
7248 while((row=g_list_next(row))!=NULL) {
7249 if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
7256 * @brief Move GList pointer to the previous table row, skipping other table children (button box, for example).
7257 * @param row GList pointer into the children list
7258 * @returns GList pointer to the previous row in the children list, or NULL if there are no any rows left.
7260 static GList * gui_internal_widget_table_prev_row(GList * row)
7262 while((row=g_list_previous(row))!=NULL) {
7263 if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
7270 * @brief Move GList pointer to the first table row, skipping other table children (button box, for example).
7271 * @param row GList pointer into the children list
7272 * @returns GList pointer to the first row in the children list, or NULL if table is empty.
7274 static GList * gui_internal_widget_table_first_row(GList * row)
7279 if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
7282 return gui_internal_widget_table_next_row(row);
7286 * @brief Get GList pointer to the table row drawn on the top of the screen.
7287 * @returns GList pointer to the first row in the children list, or NULL.
7289 static GList * gui_internal_widget_table_top_row(struct gui_priv *this, struct widget * table)
7291 if(table && table->type==widget_table) {
7292 struct table_data *d=table->data;
7294 return gui_internal_widget_table_first_row(d->top_row);
7303 * Creates a new table_row widget.
7304 * @param this The graphics context
7305 * @param flags Sizing flags for the row
7306 * @returns The new table_row widget.
7308 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
7310 struct widget * widget = g_new0(struct widget,1);
7311 widget->type=widget_table_row;
7312 widget->flags=flags;
7319 * @brief Computes the column dimensions for the table.
7321 * @param w The table widget to compute dimensions for.
7323 * This function examines all of the rows and columns for the table w
7324 * and returns a list (GList) of table_column_desc elements that
7325 * describe each column of the table.
7327 * The caller is responsible for freeing the returned list.
7329 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
7332 GList * column_desc = NULL;
7333 GList * current_desc=NULL;
7334 GList * cur_row = w->children;
7335 struct widget * cur_row_widget=NULL;
7336 GList * cur_column=NULL;
7337 struct widget * cell_w=NULL;
7338 struct table_column_desc * current_cell=NULL;
7339 struct table_data * table_data=NULL;
7346 * Scroll through the the table and
7347 * 1. Compute the maximum width + height of each column across all rows.
7349 table_data = (struct table_data*) w->data;
7350 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
7352 cur_row_widget = (struct widget*) cur_row->data;
7353 current_desc = column_desc;
7354 if(cur_row_widget == table_data->button_box)
7359 for(cur_column = cur_row_widget->children; cur_column;
7360 cur_column=g_list_next(cur_column))
7362 cell_w = (struct widget*) cur_column->data;
7363 gui_internal_widget_pack(this,cell_w);
7364 if(current_desc == 0)
7366 current_cell = g_new0(struct table_column_desc,1);
7367 column_desc = g_list_append(column_desc,current_cell);
7368 current_desc = g_list_last(column_desc);
7369 current_cell->height=cell_w->h;
7370 current_cell->width=cell_w->w;
7371 total_width+=cell_w->w;
7376 current_cell = current_desc->data;
7379 if(current_cell->height < height )
7381 current_cell->height = height;
7383 if(current_cell->width < width)
7385 total_width += (width-current_cell->width);
7386 current_cell->width = width;
7391 current_desc = g_list_next(current_desc);
7401 * If the width of all columns is less than the width off
7402 * the table expand each cell proportionally.
7405 if(total_width+(this->spacing*column_count) < w->w ) {
7406 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
7407 current_cell = (struct table_column_desc*) current_desc->data;
7408 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
7417 * @brief Computes the height and width for the table.
7419 * The height and widht are computed to display all cells in the table
7420 * at the requested height/width.
7422 * @param this The graphics context
7423 * @param w The widget to pack.
7426 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
7432 GList * column_data = gui_internal_compute_table_dimensions(this,w);
7434 struct table_column_desc * cell_desc=0;
7435 struct table_data * table_data = (struct table_data*)w->data;
7437 for(current = column_data; current; current=g_list_next(current))
7439 if(table_data->button_box == current->data )
7443 cell_desc = (struct table_column_desc *) current->data;
7444 width = width + cell_desc->width + this->spacing;
7445 if(height < cell_desc->height)
7447 height = cell_desc->height ;
7453 for(current=w->children; current; current=g_list_next(current))
7455 if(current->data!= table_data->button_box)
7462 if(w->w + w->c.x > this->root.w)
7464 w->w = this->root.w - w->c.x;
7468 if(w->h + w->c.y > this->root.h )
7471 * Do not allow the widget to exceed the screen.
7474 w->h = this->root.h- w->c.y - height;
7477 if (table_data->button_box)
7479 gui_internal_widget_pack(this,table_data->button_box);
7484 * Deallocate column descriptions.
7486 g_list_foreach(column_data,(GFunc)g_free,NULL);
7487 g_list_free(column_data);
7494 * @brief Invalidates coordinates for previosly rendered table widget rows.
7496 * @param table_data Data from the table object.
7498 static void gui_internal_table_hide_rows(struct table_data * table_data)
7501 for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row))
7503 struct widget * cur_row_widget = (struct widget*)cur_row->data;
7504 if (cur_row_widget->type!=widget_table_row)
7506 cur_row_widget->p.x=0;
7507 cur_row_widget->p.y=0;
7508 cur_row_widget->w=0;
7509 cur_row_widget->h=0;
7510 if(cur_row==table_data->bottom_row)
7517 * @brief Renders a table widget.
7519 * @param this The graphics context
7520 * @param w The table widget to render.
7522 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
7527 GList * column_desc=NULL;
7528 GList * cur_row = NULL;
7529 GList * current_desc=NULL;
7530 struct table_data * table_data = (struct table_data*)w->data;
7532 int is_first_page=1;
7533 struct table_column_desc * dim=NULL;
7535 dbg_assert(table_data);
7536 column_desc = gui_internal_compute_table_dimensions(this,w);
7540 gui_internal_table_hide_rows(table_data);
7542 * Skip rows that are on previous pages.
7544 cur_row = w->children;
7545 if(table_data->top_row && table_data->top_row != w->children && !table_data->button_box_hide)
7547 cur_row = table_data->top_row;
7550 table_data->top_row=NULL;
7553 * Loop through each row. Drawing each cell with the proper sizes,
7554 * at the proper positions.
7556 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
7558 int max_height=0, bbox_height=0;
7559 struct widget * cur_row_widget;
7560 GList * cur_column=NULL;
7561 current_desc = column_desc;
7562 cur_row_widget = (struct widget*)cur_row->data;
7563 x =w->p.x+this->spacing;
7564 if(cur_row_widget == table_data->button_box )
7568 dim = (struct table_column_desc*)current_desc->data;
7570 if (table_data->button_box && !table_data->button_box_hide)
7571 bbox_height=table_data->button_box->h;
7573 if( y + dim->height + bbox_height + this->spacing >= w->p.y + w->h )
7576 * No more drawing space left.
7581 for(cur_column = cur_row_widget->children; cur_column;
7582 cur_column=g_list_next(cur_column))
7584 struct widget * cur_widget = (struct widget*) cur_column->data;
7585 dim = (struct table_column_desc*)current_desc->data;
7588 cur_widget->w=dim->width;
7590 cur_widget->h=dim->height;
7592 max_height = dim->height;
7593 /* We pack the widget before rendering to ensure that the x and y
7594 * coordinates get pushed down.
7596 gui_internal_widget_pack(this,cur_widget);
7597 gui_internal_widget_render(this,cur_widget);
7599 if(dim->height > max_height)
7601 max_height = dim->height;
7605 /* Row object should have its coordinates in actual
7606 * state to be able to pass mouse clicks to Column objects
7608 cur_row_widget->p.x=w->p.x;
7609 cur_row_widget->w=w->w;
7610 cur_row_widget->p.y=y;
7611 cur_row_widget->h=max_height;
7613 table_data->bottom_row=cur_row;
7614 current_desc = g_list_next(current_desc);
7616 if(table_data->button_box && (is_skipped || !is_first_page) && !table_data->button_box_hide )
7618 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
7620 if(table_data->button_box->p.y < y )
7622 table_data->button_box->p.y=y;
7624 table_data->button_box->p.x = w->p.x;
7625 table_data->button_box->w = w->w;
7626 // table_data->button_box->h = w->h - y;
7627 // table_data->next_button->h=table_data->button_box->h;
7628 // table_data->prev_button->h=table_data->button_box->h;
7629 // table_data->next_button->c.y=table_data->button_box->c.y;
7630 // table_data->prev_button->c.y=table_data->button_box->c.y;
7631 gui_internal_widget_pack(this,table_data->button_box);
7632 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
7634 table_data->button_box->p.y = w->p.y + w->h -
7635 table_data->button_box->h;
7639 table_data->next_button->state|= STATE_SENSITIVE;
7643 table_data->next_button->state&= ~STATE_SENSITIVE;
7646 if(table_data->top_row != w->children)
7648 table_data->prev_button->state|= STATE_SENSITIVE;
7652 table_data->prev_button->state&= ~STATE_SENSITIVE;
7654 gui_internal_widget_render(this,table_data->button_box);
7658 * Deallocate column descriptions.
7660 g_list_foreach(column_desc,(GFunc)g_free,NULL);
7661 g_list_free(column_desc);
7666 * @brief Displays Route information
7668 * @li The name of the active vehicle
7669 * @param wm The button that was pressed.
7673 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7677 struct widget * menu;
7678 struct widget * row;
7679 struct widget * box;
7682 if(! this->vehicle_cb)
7685 * Register the callback on vehicle updates.
7687 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
7688 attr_position_coord_geo,this);
7689 navit_add_callback(this->nav,this->vehicle_cb);
7692 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
7694 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
7697 menu=gui_internal_menu(this,_("Route Description"));
7699 menu->wfree=gui_internal_route_screen_free;
7700 this->route_data.route_showing=1;
7701 this->route_data.route_table->spx = this->spacing;
7704 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
7706 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
7707 gui_internal_widget_append(box,this->route_data.route_table);
7709 box->spx = this->spacing;
7710 this->route_data.route_table->w=box->w;
7711 gui_internal_widget_append(menu,box);
7712 gui_internal_populate_route_table(this,this->nav);
7713 gui_internal_menu_render(this);
7718 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
7721 int adx=a2->x-a1->x;
7722 int ady=a2->y-a1->y;
7723 int bdx=b2->x-b1->x;
7724 int bdy=b2->y-b1->y;
7725 n = bdy * adx - bdx * ady;
7726 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
7727 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
7738 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
7739 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
7740 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
7743 res->x = a1->x + a * adx / n;
7744 res->y = a1->y + a * ady / n;
7749 struct heightline *next;
7751 struct coord_rect bbox;
7756 struct diagram_point {
7757 struct diagram_point *next;
7761 static struct heightline *
7762 item_get_heightline(struct item *item)
7764 struct heightline *ret=NULL;
7765 struct street_data *sd;
7769 if (item_attr_get(item, attr_label, &attr)) {
7770 height=atoi(attr.u.str);
7771 sd=street_get_data(item);
7772 if (sd && sd->count > 1) {
7773 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
7774 ret->bbox.lu=sd->c[0];
7775 ret->bbox.rl=sd->c[0];
7776 ret->count=sd->count;
7778 for (i = 0 ; i < sd->count ; i++) {
7780 coord_rect_extend(&ret->bbox, sd->c+i);
7783 street_data_free(sd);
7790 * @brief Displays Route Height Profile
7792 * @li The name of the active vehicle
7793 * @param wm The button that was pressed.
7797 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7801 struct widget * menu, *box;
7803 struct map * map=NULL;
7804 struct map_rect * mr=NULL;
7805 struct route * route;
7806 struct item * item =NULL;
7808 struct mapset_handle *msh;
7809 int x,i,first=1,dist=0;
7810 struct coord c,last,res;
7811 struct coord_rect rbbox,dbbox;
7812 struct map_selection sel;
7813 struct heightline *heightline,*heightlines=NULL;
7814 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
7817 sel.range.min=type_height_line_1;
7818 sel.range.max=type_height_line_3;
7821 menu=gui_internal_menu(this,_("Height Profile"));
7822 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
7823 gui_internal_widget_append(menu, box);
7824 route = navit_get_route(this->nav);
7826 map = route_get_map(route);
7828 mr = map_rect_new(map,NULL);
7830 while((item = map_rect_get_item(mr))) {
7831 while (item_coord_get(item, &c, 1)) {
7837 coord_rect_extend(&sel.u.c_rect, &c);
7840 map_rect_destroy(mr);
7841 ms=navit_get_mapset(this->nav);
7843 msh=mapset_open(ms);
7844 while ((map=mapset_next(msh, 1))) {
7845 mr=map_rect_new(map, &sel);
7847 while((item = map_rect_get_item(mr))) {
7848 if (item->type >= sel.range.min && item->type <= sel.range.max) {
7849 heightline=item_get_heightline(item);
7851 heightline->next=heightlines;
7852 heightlines=heightline;
7856 map_rect_destroy(mr);
7865 map = route_get_map(route);
7867 mr = map_rect_new(map,NULL);
7868 if(mr && heightlines) {
7869 while((item = map_rect_get_item(mr))) {
7871 while (item_coord_get(item, &c, 1)) {
7875 heightline=heightlines;
7878 coord_rect_extend(&rbbox, &c);
7879 while (heightline) {
7880 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
7881 for (i = 0 ; i < heightline->count - 1; i++) {
7882 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
7883 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
7884 diagram_point=g_new(struct diagram_point, 1);
7885 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
7886 diagram_point->c.y=heightline->height;
7887 diagram_point->next=diagram_points;
7888 diagram_points=diagram_point;
7889 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
7894 heightline=heightline->next;
7896 dist+=transform_distance(projection_mg, &last, &c);
7902 map_rect_destroy(mr);
7906 gui_internal_menu_render(this);
7908 diagram_point=diagram_points;
7909 while (diagram_point) {
7911 dbbox.lu=diagram_point->c;
7912 dbbox.rl=diagram_point->c;
7915 coord_rect_extend(&dbbox, &diagram_point->c);
7916 diagram_point=diagram_point->next;
7918 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
7919 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
7921 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
7923 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
7929 diagram_point=diagram_points;
7930 while (diagram_point) {
7931 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
7933 diagram_point=diagram_point->next;
7937 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
7938 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
7939 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
7940 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
7944 graphics_draw_lines(this->gra, this->foreground, p, 2);
7954 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7956 struct widget *menu,*wb,*w;
7959 graphics_draw_mode(this->gra, draw_mode_begin);
7960 menu=gui_internal_menu(this, _("Show Locale"));
7961 menu->spx=this->spacing*10;
7962 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
7963 gui_internal_widget_append(menu, wb);
7964 text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
7965 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7966 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7968 #ifdef HAVE_API_WIN32_BASE
7970 char country[32],lang[32];
7971 #ifdef HAVE_API_WIN32_CE
7972 wchar_t wcountry[32],wlang[32];
7974 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
7975 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
7977 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
7979 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
7980 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7981 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7983 #ifdef HAVE_API_WIN32_CE
7984 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
7985 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
7987 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
7989 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
7990 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7991 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7996 gui_internal_menu_render(this);
7997 graphics_draw_mode(this->gra, draw_mode_end);
8001 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
8003 struct widget *menu,*wb,*w;
8006 graphics_draw_mode(this->gra, draw_mode_begin);
8007 menu=gui_internal_menu(this, _("About Navit"));
8008 menu->spx=this->spacing*10;
8009 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
8010 gui_internal_widget_append(menu, wb);
8013 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
8014 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
8017 text=g_strdup_printf("%s",PACKAGE_NAME);
8018 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8019 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
8023 text=g_strdup_printf("%s",version);
8024 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8025 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
8029 text=g_strdup_printf("http://www.navit-project.org/");
8030 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8031 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
8035 text=g_strdup_printf("%s:",_("By"));
8036 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8037 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8039 text=g_strdup_printf("Martin Schaller");
8040 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8041 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8043 text=g_strdup_printf("Michael Farmbauer");
8044 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8045 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8047 text=g_strdup_printf("Alexander Atanasov");
8048 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8049 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8051 text=g_strdup_printf("Pierre Grandin");
8052 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8053 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8057 text=g_strdup_printf("%s",_("And all the Navit Team"));
8058 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8059 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8061 text=g_strdup_printf("%s",_("members and contributors."));
8062 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
8063 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
8066 gui_internal_menu_render(this);
8067 graphics_draw_mode(this->gra, draw_mode_end);
8071 * @brief handles the 'next page' table event.
8072 * A callback function that is invoked when the 'next page' button is pressed
8073 * to advance the contents of a table widget.
8075 * @param this The graphics context.
8076 * @param wm The button widget that was pressed.
8078 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
8080 struct widget * table_widget=NULL;
8081 struct table_data * table_data = NULL;
8084 table_widget = (struct widget * ) wm->data;
8086 table_widget = data;
8088 if(table_widget && table_widget->type==widget_table)
8089 table_data = (struct table_data*) table_widget->data;
8093 GList *l=g_list_next(table_data->bottom_row);
8095 gui_internal_table_hide_rows(table_data);
8096 table_data->top_row=l;
8101 wm->state&= ~STATE_HIGHLIGHTED;
8103 gui_internal_menu_render(this);
8109 * @brief handles the 'previous page' table event.
8110 * A callback function that is invoked when the 'previous page' button is pressed
8111 * to go back in the contents of a table widget.
8113 * @param this The graphics context.
8114 * @param wm The button widget that was pressed.
8116 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
8118 struct widget * table_widget = NULL;
8119 struct table_data * table_data = NULL;
8122 table_widget=(struct widget * ) wm->data;
8124 table_widget=(struct widget * ) data;
8126 if(table_widget && table_widget->type==widget_table)
8127 table_data = (struct table_data*) table_widget->data;
8130 int bottomy=table_widget->p.y+table_widget->h;
8132 GList *top=table_data->top_row;
8133 struct widget *w=(struct widget*)top->data;
8134 if(table_data->button_box->p.y!=0) {
8135 bottomy=table_data->button_box->p.y;
8137 n=(bottomy-w->p.y)/w->h;
8138 while(n-- > 0 && (top=g_list_previous(top))!=NULL);
8139 gui_internal_table_hide_rows(table_data);
8140 table_data->top_row=top;
8143 wm->state&= ~STATE_HIGHLIGHTED;
8144 gui_internal_menu_render(this);
8149 * @brief deallocates a table_data structure.
8152 void gui_internal_table_data_free(void * p)
8157 * @note button_box and its children (next_button,prev_button)
8158 * have their memory managed by the table itself.
8167 * @brief Called when the route is updated.
8169 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
8172 if(this->route_data.route_showing) {
8173 gui_internal_populate_route_table(this,navit);
8174 graphics_draw_mode(this->gra, draw_mode_begin);
8175 gui_internal_menu_render(this);
8176 graphics_draw_mode(this->gra, draw_mode_end);
8184 * @brief Called when the route screen is closed (deallocated).
8186 * The main purpose of this function is to remove the widgets from
8187 * references route_data because those widgets are about to be freed.
8189 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
8192 this_->route_data.route_showing=0;
8193 this_->route_data.route_table=NULL;
8200 * @brief Populates the route table with route information
8202 * @param this The gui context
8203 * @param navit The navit object
8205 void gui_internal_populate_route_table(struct gui_priv * this,
8206 struct navit * navit)
8208 struct map * map=NULL;
8209 struct map_rect * mr=NULL;
8210 struct navigation * nav = NULL;
8211 struct item * item =NULL;
8213 struct widget * label = NULL;
8214 struct widget * row = NULL;
8216 nav = navit_get_navigation(navit);
8220 map = navigation_get_map(nav);
8222 mr = map_rect_new(map,NULL);
8224 gui_internal_widget_table_clear(this,this->route_data.route_table);
8225 while((item = map_rect_get_item(mr))) {
8226 if(item_attr_get(item,attr_navigation_long,&attr)) {
8227 row = gui_internal_widget_table_row_new(this,
8230 | orientation_horizontal);
8231 gui_internal_widget_append(this->route_data.route_table,row);
8233 label = gui_internal_label_new(this,attr.u.str);
8234 gui_internal_widget_append(row,label);
8237 item_coord_get(item, &c, 1);
8240 label->c.pro=map_projection(map);
8241 label->func=gui_internal_cmd_position;
8242 label->state|=STATE_SENSITIVE;
8243 label->data=(void*)2;
8251 static struct command_table commands[] = {
8252 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
8253 {"back",command_cast(gui_internal_cmd2_back)},
8254 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
8255 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
8256 {"formerdests",command_cast(gui_internal_cmd_formerdests)},
8257 {"get_data",command_cast(gui_internal_get_data)},
8258 {"locale",command_cast(gui_internal_cmd2_locale)},
8259 {"log",command_cast(gui_internal_cmd_log)},
8260 {"menu",command_cast(gui_internal_cmd_menu2)},
8261 {"position",command_cast(gui_internal_cmd2_position)},
8262 {"pois",command_cast(gui_internal_cmd2_pois)},
8263 {"refresh",command_cast(gui_internal_cmd2_refresh)},
8264 {"route_description",command_cast(gui_internal_cmd2_route_description)},
8265 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
8266 {"set",command_cast(gui_internal_cmd2_set)},
8267 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
8268 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
8269 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
8270 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
8271 {"town",command_cast(gui_internal_cmd2_town)},
8272 {"enter_coord",command_cast(gui_internal_cmd_enter_coord)},
8273 {"quit",command_cast(gui_internal_cmd2_quit)},
8274 {"write",command_cast(gui_internal_cmd_write)},
8275 {"about",command_cast(gui_internal_cmd2_about)},
8280 //##############################################################################################################
8283 //# Authors: Martin Schaller (04/2008)
8284 //##############################################################################################################
8285 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
8287 struct color color_white={0xffff,0xffff,0xffff,0xffff};
8288 struct color color_black={0x0,0x0,0x0,0xffff};
8289 struct color back2_color={0x4141,0x4141,0x4141,0xffff};
8291 struct gui_priv *this;
8293 *meth=gui_internal_methods;
8294 this=g_new0(struct gui_priv, 1);
8297 this->self.type=attr_gui;
8298 this->self.u.gui=gui;
8300 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
8301 this->menu_on_map_click=attr->u.num;
8303 this->menu_on_map_click=1;
8305 if ((attr=attr_search(attrs, NULL, attr_on_map_click)))
8306 this->on_map_click=g_strdup(attr->u.str);
8308 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
8309 this->signal_on_map_click=attr->u.num;
8311 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
8312 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
8315 if( (attr=attr_search(attrs,NULL,attr_font_size)))
8317 this->config.font_size=attr->u.num;
8321 this->config.font_size=-1;
8323 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
8325 this->config.icon_xs=attr->u.num;
8329 this->config.icon_xs=-1;
8331 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
8333 this->config.icon_l=attr->u.num;
8337 this->config.icon_l=-1;
8339 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
8341 this->config.icon_s=attr->u.num;
8345 this->config.icon_s=-1;
8347 if( (attr=attr_search(attrs,NULL,attr_spacing)))
8349 this->config.spacing=attr->u.num;
8353 this->config.spacing=-1;
8355 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
8357 this->speech=attr->u.num;
8359 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
8360 this->keyboard=attr->u.num;
8364 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
8365 this->fullscreen=attr->u.num;
8367 if( (attr=attr_search(attrs,NULL,attr_flags)))
8368 this->flags=attr->u.num;
8369 if( (attr=attr_search(attrs,NULL,attr_background_color)))
8370 this->background_color=*attr->u.color;
8372 this->background_color=color_black;
8373 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
8374 this->background2_color=*attr->u.color;
8376 this->background2_color=back2_color;
8377 if( (attr=attr_search(attrs,NULL,attr_text_color)))
8378 this->text_foreground_color=*attr->u.color;
8380 this->text_foreground_color=color_white;
8381 this->text_background_color=color_black;
8382 if( (attr=attr_search(attrs,NULL,attr_columns)))
8383 this->cols=attr->u.num;
8384 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
8385 this->osd_configuration=*attr;
8387 if( (attr=attr_search(attrs,NULL,attr_pitch)))
8388 this->pitch=attr->u.num;
8391 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
8392 this->flags_town=attr->u.num;
8394 this->flags_town=-1;
8395 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
8396 this->flags_street=attr->u.num;
8398 this->flags_street=-1;
8399 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
8400 this->flags_house_number=attr->u.num;
8402 this->flags_house_number=-1;
8403 if( (attr=attr_search(attrs,NULL,attr_radius)))
8404 this->radius=attr->u.num;
8407 this->data.priv=this;
8408 this->data.gui=&gui_internal_methods_ext;
8409 this->data.widget=&gui_internal_widget_methods;
8410 this->cbl=callback_list_new();
8415 //##############################################################################################################
8418 //# Authors: Martin Schaller (04/2008)
8419 //##############################################################################################################
8420 void plugin_init(void)
8422 plugin_register_gui_type("internal", gui_internal_new);
8426 gui_internal_destroy(struct gui_priv *this)
8429 graphics_font_destroy(this->fonts[0]);
8430 graphics_font_destroy(this->fonts[1]);
8431 graphics_font_destroy(this->fonts[2]);
8432 attr_free(this->click_coord_geo);
8433 attr_free(this->position_coord_geo);
8434 g_free(this->country_iso2);
8436 g_free(this->html_text);
8437 g_free(this->on_map_click);