2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 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 //##############################################################################################################
36 #ifdef HAVE_API_WIN32_BASE
43 #include "navit_nls.h"
50 #include "transform.h"
56 #include "vehicleprofile.h"
67 #include "navit_nls.h"
68 #include "navigation.h"
69 #include "gui_internal.h"
71 #include "xmlconfig.h"
73 #include "bookmarks.h"
82 struct widget *search_list;
83 struct widget *keyboard;
84 struct widget *button_bar;
87 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
88 struct widget *redisplay_widget;
91 //##############################################################################################################
94 //# Authors: Martin Schaller (04/2008)
95 //##############################################################################################################
97 enum widget_type type;
98 struct graphics_gc *background,*text_background;
99 struct graphics_gc *foreground_frame;
100 struct graphics_gc *foreground;
102 struct graphics_image *img;
104 * A function to be invoked on actions.
105 * @li widget The widget that is receiving the button press.
108 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
113 * @brief A function to deallocate data
115 void (*data_free)(void *data);
118 * @brief a function that will be called as the widget is being destroyed.
119 * This function can act as a destructor for the widget. It allows for
120 * on deallocation actions to be specified on a per widget basis.
121 * This function will call g_free on the widget (if required).
123 void (*free) (struct gui_priv *this_, struct widget * w);
137 int bl,br,bt,bb,spx,spy;
141 * The number of widgets to layout horizontally when doing
142 * a orientation_horizontal_vertical layout
148 int (*set_attr)(void *, struct attr *);
149 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
150 void (*remove_cb)(void *, struct callback *cb);
157 struct menu_data *menu_data;
163 * @brief A structure to store configuration values.
165 * This structure stores configuration values for how gui elements in the internal GUI
168 struct gui_config_settings {
171 * The base size (in fractions of a point) to use for text.
175 * The size (in pixels) that xs style icons should be scaled to.
179 * The size (in pixels) that s style icons (small) should be scaled to
183 * The size (in pixels) that l style icons should be scaled to
187 * The default amount of spacing (in pixels) to place between GUI elements.
194 * Indexes into the config_profiles array.
196 const int LARGE_PROFILE=0;
197 const int MEDIUM_PROFILE=1;
198 const int SMALL_PROFILE=2;
201 * The default config profiles.
203 * [0] => LARGE_PROFILE (screens 640 in one dimension)
204 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
205 * [2] => Small profile (default)
207 static struct gui_config_settings config_profiles[]={
214 struct widget * route_table;
219 //##############################################################################################################
222 //# Authors: Martin Schaller (04/2008)
223 //##############################################################################################################
228 struct graphics *gra;
229 struct graphics_gc *background;
230 struct graphics_gc *background2;
231 struct graphics_gc *highlight_background;
232 struct graphics_gc *foreground;
233 struct graphics_gc *text_foreground;
234 struct graphics_gc *text_background;
235 struct color background_color, background2_color, text_foreground_color, text_background_color;
239 struct graphics_font *fonts[3];
240 int icon_xs, icon_s, icon_l;
242 struct widget *widgets;
246 struct widget *highlighted,*editable;
247 struct widget *highlighted_menu;
248 int clickp_valid, vehicle_valid;
249 struct pcoord clickp, vehiclep;
250 struct attr *click_coord_geo, *position_coord_geo;
251 struct search_list *sl;
253 int menu_on_map_click;
254 int signal_on_map_click;
258 int keyboard_required;
260 * The setting information read from the configuration file.
261 * values of -1 indicate no value was specified in the config file.
263 struct gui_config_settings config;
264 struct event_idle *idle;
265 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
266 struct event_timeout *motion_timeout_event;
267 struct point current;
269 struct callback * vehicle_cb;
271 * Stores information about the route.
273 struct route_data route_data;
275 struct gui_internal_data data;
276 struct callback_list *cbl;
279 struct attr osd_configuration;
281 int flags_town,flags_street,flags_house_number;
286 struct widget *html_container;
289 int html_anchor_found;
308 struct widget *container;
312 struct html_tag_map {
318 {"html",html_tag_html},
319 {"img",html_tag_img},
320 {"script",html_tag_script},
321 {"form",html_tag_form},
322 {"input",html_tag_input},
323 {"div",html_tag_div},
328 * @brief A structure to store information about a table.
330 * The table_data widget stores pointers to extra information needed by the
333 * The table_data structure needs to be freed with data_free along with the widget.
339 * A GList pointer into a widget->children list that indicates the row
340 * currently being rendered at the top of the table.
344 * A Glist pointer into a widget->children list that indicates the row
345 * currently being rendered at the bottom of the table.
350 * A list of table_row widgets that mark the
351 * top rows for each page of the table.
352 * This is needed for the 'previous page' function of the table.
354 GList * page_headers;
357 * A container box that is the child of the table widget that contains+groups
358 * the next and previous button.
360 struct widget * button_box;
363 * A button widget to handle 'next page' requests
365 struct widget * next_button;
367 * A button widget to handle 'previous page' requests.
369 struct widget * prev_button;
373 * a pointer to the gui context.
374 * This is needed by the free function to destory the buttons.
376 struct gui_priv * this;
380 * A data structure that holds information about a column that makes up a table.
384 struct table_column_desc
388 * The computed height of a cell in the table.
393 * The computed width of a cell in the table.
399 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
400 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
401 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
402 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
403 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
404 static void gui_internal_apply_config(struct gui_priv *this);
406 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
407 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
408 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
409 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
410 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
411 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
412 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
413 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
414 static void gui_internal_table_data_free(void * d);
415 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
417 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
418 static void gui_internal_populate_route_table(struct gui_priv * this,
419 struct navit * navit);
420 static void gui_internal_search_idle_end(struct gui_priv *this);
421 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
422 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
423 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
424 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
425 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
426 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
427 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
428 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
429 static void gui_internal_check_exit(struct gui_priv *this);
430 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
432 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
433 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
435 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
436 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
439 * * Display image scaled to specific size
440 * * searches for scaleable and pre-scaled image
441 * * @param this Our gui context
442 * * @param name image name
443 * * @param w desired width of image
444 * * @param h desired height of image
445 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
447 static struct graphics_image *
448 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
450 struct graphics_image *ret=NULL;
451 char *full_name=NULL;
452 char *full_path=NULL;
455 for (i = 1 ; i < 6 ; i++) {
459 full_name=g_strdup_printf("%s.svg", name);
462 full_name=g_strdup_printf("%s.svgz", name);
465 if (w != -1 && h != -1) {
466 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
470 full_name=g_strdup_printf("%s.png", name);
473 full_name=g_strdup_printf("%s.xpm", name);
476 dbg(1,"trying '%s'\n", full_name);
480 /* needs to be checked in the driver */
481 if (!file_exists(full_name)) {
486 full_path=graphics_icon_path(full_name);
487 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
488 dbg(1,"ret=%p\n", ret);
494 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
499 static struct graphics_image *
500 image_new_o(struct gui_priv *this, char *name)
502 return image_new_scaled(this, name, -1, -1);
506 static struct graphics_image *
507 image_new_xs(struct gui_priv *this, const char *name)
509 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
513 static struct graphics_image *
514 image_new_s(struct gui_priv *this, const char *name)
516 return image_new_scaled(this, name, this->icon_s, this->icon_s);
519 static struct graphics_image *
520 image_new_l(struct gui_priv *this, const char *name)
522 return image_new_scaled(this, name, this->icon_l, this->icon_l);
526 coordinates_geo(const struct coord_geo *gc, char sep)
528 char latc='N',lngc='E';
529 int lat_deg,lat_min,lat_sec;
530 int lng_deg,lng_min,lng_sec;
531 struct coord_geo g=*gc;
542 lat_min=fmod(g.lat*60,60);
543 lat_sec=fmod(g.lat*3600,60);
545 lng_min=fmod(g.lng*60,60);
546 lng_sec=fmod(g.lng*3600,60);
547 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);
551 coordinates(struct pcoord *pc, char sep)
557 transform_to_geo(pc->pro, &c, &g);
558 return coordinates_geo(&g, sep);
563 gui_internal_background_render(struct gui_priv *this, struct widget *w)
565 struct point pnt=w->p;
566 if (w->state & STATE_HIGHLIGHTED)
567 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
570 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
574 static struct widget *
575 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
581 struct widget *widget=g_new0(struct widget, 1);
582 widget->type=widget_label;
583 widget->font_idx=font;
585 widget->text=g_strdup(text);
586 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
590 widget->h=h+this->spacing;
592 widget->w=w+this->spacing;
594 widget->flags=gravity_center;
595 widget->foreground=this->text_foreground;
596 widget->text_background=this->text_background;
601 static struct widget *
602 gui_internal_label_new(struct gui_priv *this, char *text)
604 return gui_internal_label_font_new(this, text, 0);
607 static struct widget *
608 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
610 struct widget *ret=NULL;
611 char *tmp=g_malloc(strlen(text)+3);
618 ret=gui_internal_label_new(this, tmp);
619 if (ret->w < maxwidth)
621 gui_internal_widget_destroy(this, ret);
629 static struct widget *
630 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
632 struct widget *widget=g_new0(struct widget, 1);
633 widget->type=widget_image;
636 widget->w=image->width;
637 widget->h=image->height;
643 gui_internal_image_render(struct gui_priv *this, struct widget *w)
647 gui_internal_background_render(this, w);
650 pnt.x+=w->w/2-w->img->hot.x;
651 pnt.y+=w->h/2-w->img->hot.y;
652 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
657 gui_internal_label_render(struct gui_priv *this, struct widget *w)
659 struct point pnt=w->p;
660 gui_internal_background_render(this, w);
661 if (w->state & STATE_EDIT)
662 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
664 char *text,startext[strlen(w->text)+1];
668 for (i = 0 ; i < strlen(text); i++)
673 if (w->flags & gravity_right) {
674 pnt.y+=w->h-this->spacing;
675 pnt.x+=w->w-w->textw-this->spacing;
676 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
678 pnt.y+=w->h-this->spacing;
679 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
685 * @brief A text box is a widget that renders a text string containing newlines.
686 * The string will be broken up into label widgets at each newline with a vertical layout.
689 static struct widget *
690 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
692 char *s=g_strdup(text),*s2,*tok;
693 struct widget *ret=gui_internal_box_new(this, flags);
695 while ((tok=strtok(s2,"\n"))) {
696 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
699 gui_internal_widget_pack(this,ret);
703 static struct widget *
704 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
706 return gui_internal_text_font_new(this, text, 0, flags);
710 static struct widget *
711 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)
713 struct widget *ret=NULL;
714 ret=gui_internal_box_new(this, flags);
717 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
719 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
723 ret->state |= STATE_SENSITIVE;
724 ret->speech=g_strdup(text);
731 static struct widget *
732 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)
734 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
738 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
745 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
746 is_on=curr.u.data == w->on.u.data;
749 if (is_on != w->is_on) {
753 l=g_list_first(w->children);
757 graphics_image_free(this->gra, wi->img);
758 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
760 if (w->is_on && w->off.type == attr_none)
761 w->state &= ~STATE_SENSITIVE;
763 w->state |= STATE_SENSITIVE;
770 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
772 if (gui_internal_button_attr_update(this, w))
773 gui_internal_widget_render(this, w);
776 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
779 w->set_attr(w->instance, &w->off);
781 w->set_attr(w->instance, &w->on);
782 gui_internal_button_attr_update(this, w);
786 static struct widget *
787 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
789 struct graphics_image *image=NULL;
793 image=image_new_xs(this, "gui_inactive");
794 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
799 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
800 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
801 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
802 ret->instance=this->nav;
803 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
804 navit_add_callback(this->nav, ret->cb);
805 gui_internal_button_attr_update(this, ret);
809 static struct widget *
810 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)
812 struct graphics_image *image=NULL;
814 image=image_new_xs(this, "gui_inactive");
817 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
823 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
824 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
825 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
828 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
829 map_add_callback(map, ret->cb);
830 gui_internal_button_attr_update(this, ret);
834 static struct widget *
835 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
837 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
841 //##############################################################################################################
844 //# Authors: Martin Schaller (04/2008)
845 //##############################################################################################################
846 static void gui_internal_clear(struct gui_priv *this)
848 struct graphics *gra=this->gra;
852 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
856 static struct widget *
857 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
859 struct widget *ret,*child;
860 GList *l=wi->children;
867 if ( wi->p.x + wi->w < p->x)
869 if ( wi->p.y + wi->h < p->y)
872 if (wi->state & flags)
876 ret=gui_internal_find_widget(child, p, flags);
887 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
889 if (found == this->highlighted)
892 graphics_draw_mode(this->gra, draw_mode_begin);
893 if (this->highlighted) {
894 this->highlighted->state &= ~STATE_HIGHLIGHTED;
895 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
896 gui_internal_widget_render(this, this->highlighted);
897 this->highlighted=NULL;
898 this->highlighted_menu=NULL;
901 this->highlighted=found;
902 this->highlighted_menu=g_list_last(this->root.children)->data;
903 this->highlighted->state |= STATE_HIGHLIGHTED;
904 gui_internal_widget_render(this, this->highlighted);
905 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
907 graphics_draw_mode(this->gra, draw_mode_end);
909 //##############################################################################################################
912 //# Authors: Martin Schaller (04/2008)
913 //##############################################################################################################
914 static void gui_internal_highlight(struct gui_priv *this)
916 struct widget *menu,*found=NULL;
917 if (this->current.x > -1 && this->current.y > -1) {
918 menu=g_list_last(this->root.children)->data;
919 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
921 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
923 if (this->editable && this->editable != found) {
924 this->editable->state &= ~ STATE_EDIT;
925 gui_internal_widget_render(this, this->editable);
927 found->state |= STATE_EDIT;
928 gui_internal_widget_render(this, found);
929 this->editable=found;
934 gui_internal_highlight_do(this, found);
935 this->motion_timeout_event=NULL;
938 static struct widget *
939 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
941 struct widget *widget=g_new0(struct widget, 1);
944 widget->text=g_strdup(label);
945 widget->type=widget_box;
950 static struct widget *
951 gui_internal_box_new(struct gui_priv *this, enum flags flags)
953 return gui_internal_box_new_with_label(this, flags, NULL);
957 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
962 gui_internal_background_render(this, w);
965 w->foreground=this->foreground;
968 if (w->foreground && w->border) {
971 pnt[1].x=pnt[0].x+w->w;
973 pnt[2].x=pnt[0].x+w->w;
974 pnt[2].y=pnt[0].y+w->h;
976 pnt[3].y=pnt[0].y+w->h;
978 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
979 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
980 graphics_gc_set_linewidth(w->foreground, 1);
987 gui_internal_widget_render(this, wc);
994 * @brief Compute the size and location for the widget.
998 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
1001 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;
1003 int orientation=w->flags & 0xffff0000;
1008 if ( this->root.w > this->root.h )
1018 * count the number of children
1025 if (orientation == orientation_horizontal_vertical && count <= cols)
1026 orientation=orientation_horizontal;
1027 switch (orientation) {
1028 case orientation_horizontal:
1030 * For horizontal orientation:
1031 * pack each child and find the largest height and
1032 * compute the total width. x spacing (spx) is considered
1034 * If any children want to be expanded
1035 * we keep track of this
1040 gui_internal_widget_pack(this, wc);
1044 if (wc->flags & flags_expand)
1045 expand+=wc->w ? wc->w : 1;
1051 if (expand && w->w) {
1052 expandd=w->w-width+expand;
1057 case orientation_vertical:
1059 * For vertical layouts:
1060 * We pack each child and compute the largest width and
1061 * the total height. y spacing (spy) is considered
1063 * If the expand flag is set then teh expansion amount
1069 gui_internal_widget_pack(this, wc);
1073 if (wc->flags & flags_expand)
1074 expand+=wc->h ? wc->h : 1;
1080 if (expand && w->h) {
1081 expandd=w->h-height+expand;
1086 case orientation_horizontal_vertical:
1088 * For horizontal_vertical orientation
1089 * pack the children.
1090 * Compute the largest height and largest width.
1091 * Layout the widgets based on having the
1092 * number of columns specified by (cols)
1098 gui_internal_widget_pack(this, wc);
1108 rows=(count+cols-1)/cols;
1111 width+=w->spx*(cols-1);
1112 height+=w->spy*(rows-1);
1119 * No orientation was specified.
1120 * width and height are both 0.
1121 * The width & height of this widget
1125 dbg(0,"Warning width and height of a widget are 0");
1128 if (! w->w && ! w->h) {
1129 w->w=w->bl+w->br+width;
1130 w->h=w->bt+w->bb+height;
1139 * At this stage the width and height of this
1140 * widget has been computed.
1141 * We now make a second pass assigning heights,
1142 * widths and coordinates to each child widget.
1145 if (w->flags & gravity_left)
1147 if (w->flags & gravity_xcenter)
1148 x=w->p.x+w->w/2-owidth/2;
1149 if (w->flags & gravity_right)
1150 x=w->p.x+w->w-w->br-owidth;
1151 if (w->flags & gravity_top)
1153 if (w->flags & gravity_ycenter)
1154 y=w->p.y+w->h/2-oheight/2;
1155 if (w->flags & gravity_bottom)
1156 y=w->p.y+w->h-w->bb-oheight;
1158 switch (orientation) {
1159 case orientation_horizontal:
1164 if (wc->flags & flags_fill)
1166 if (wc->flags & flags_expand) {
1169 wc->w=wc->w*expandd/expand;
1171 if (w->flags & gravity_top)
1173 if (w->flags & gravity_ycenter)
1175 if (w->flags & gravity_bottom)
1181 case orientation_vertical:
1186 if (wc->flags & flags_fill)
1188 if (wc->flags & flags_expand) {
1191 wc->h=wc->h*expandd/expand;
1193 if (w->flags & gravity_left)
1195 if (w->flags & gravity_xcenter)
1197 if (w->flags & gravity_right)
1203 case orientation_horizontal_vertical:
1213 if (wc->flags & flags_fill) {
1217 if (w->flags & gravity_left)
1219 if (w->flags & gravity_xcenter)
1220 wc->p.x=x+(width-wc->w)/2;
1221 if (w->flags & gravity_right)
1222 wc->p.x=x+width-wc->w;
1223 if (w->flags & gravity_top)
1225 if (w->flags & gravity_ycenter)
1226 wc->p.y=y+(height-wc->h)/2;
1227 if (w->flags & gravity_bottom)
1228 wc->p.y=y-height-wc->h;
1230 if (++count == cols) {
1242 * Call pack again on each child,
1243 * the child has now had its size and coordinates
1244 * set so they can repack their children.
1249 gui_internal_widget_pack(this, wc);
1255 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1263 gui_internal_widget_reset_pack(this, wc);
1273 gui_internal_widget_append(struct widget *parent, struct widget *child)
1277 if (! child->background)
1278 child->background=parent->background;
1279 parent->children=g_list_append(parent->children, child);
1282 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1284 if (! child->background)
1285 child->background=parent->background;
1286 parent->children=g_list_prepend(parent->children, child);
1289 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1297 gui_internal_widget_destroy(this, wc);
1300 g_list_free(w->children);
1304 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1306 gui_internal_widget_children_destroy(this, w);
1311 graphics_image_free(this->gra, w->img);
1317 w->data_free(w->data);
1318 if (w->cb && w->remove_cb)
1319 w->remove_cb(w->instance, w->cb);
1328 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1330 if(w->p.x > this->root.w || w->p.y > this->root.h)
1335 gui_internal_box_render(this, w);
1338 gui_internal_label_render(this, w);
1341 gui_internal_image_render(this, w);
1344 gui_internal_table_render(this,w);
1352 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1356 gui_internal_box_pack(this, w);
1359 gui_internal_table_pack(this,w);
1365 //##############################################################################################################
1368 //# Authors: Martin Schaller (04/2008)
1369 //##############################################################################################################
1370 static void gui_internal_call_highlighted(struct gui_priv *this)
1372 if (! this->highlighted || ! this->highlighted->func)
1374 this->highlighted->reason=1;
1375 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1379 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1381 char *text=w->speech;
1389 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1390 navit_say(this->nav, text);
1396 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1400 gui_internal_search_idle_end(this);
1401 while ((l = g_list_last(this->root.children))) {
1403 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1404 gui_internal_say(this, w, 0);
1405 redisplay=w->menu_data->redisplay;
1406 wr=w->menu_data->redisplay_widget;
1407 if (!w->menu_data->redisplay) {
1408 gui_internal_widget_render(this, w);
1411 gui_internal_widget_destroy(this, l->data);
1412 this->root.children=g_list_remove(this->root.children, l->data);
1413 redisplay(this, wr, wr->data);
1416 gui_internal_widget_destroy(this, l->data);
1417 this->root.children=g_list_remove(this->root.children, l->data);
1422 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1425 gui_internal_search_idle_end(this);
1426 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1427 gui_internal_widget_destroy(this, l->data);
1428 this->root.children=g_list_remove(this->root.children, l->data);
1431 gui_internal_say(this, l->data, 0);
1432 gui_internal_widget_render(this, l->data);
1437 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1439 gui_internal_prune_menu_count(this, 1, 1);
1443 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1445 gui_internal_prune_menu(this, wm->data);
1449 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1451 graphics_draw_mode(this->gra, draw_mode_begin);
1452 gui_internal_back(this, NULL, NULL);
1453 graphics_draw_mode(this->gra, draw_mode_end);
1454 gui_internal_check_exit(this);
1458 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1460 gui_internal_prune_menu(this, NULL);
1464 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1466 gui_internal_prune_menu(this, this->root.children->data);
1469 static struct widget *
1470 gui_internal_top_bar(struct gui_priv *this)
1472 struct widget *w,*wm,*wh,*wc,*wcn;
1473 int dots_len, sep_len;
1475 int width,width_used=0,use_sep=0,incomplete=0;
1476 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1478 1:Don't expand bar to screen width
1479 2:Don't show Map Icon
1480 4:Don't show Home Icon
1481 8:Show only current menu
1482 16:Don't use menu titles as button
1483 32:Show navit version
1486 256:Use background for menu headline
1487 512:Set osd_configuration and zoom to route when setting position
1488 1024:Don't show back button
1489 2048:No highlighting of keyboard
1492 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1493 w->bl=this->spacing;
1494 w->spx=this->spacing;
1495 w->background=this->background2;
1496 if ((this->flags & 6) == 6) {
1502 width=this->root.w-w->bl;
1503 if (! (this->flags & 2)) {
1504 wm=gui_internal_button_new_with_callback(this, NULL,
1505 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1506 gui_internal_cmd_return, NULL);
1507 wm->speech=g_strdup(_("Back to map"));
1508 gui_internal_widget_pack(this, wm);
1509 gui_internal_widget_append(w, wm);
1512 if (! (this->flags & 4)) {
1513 wh=gui_internal_button_new_with_callback(this, NULL,
1514 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1515 gui_internal_cmd_main_menu, NULL);
1516 wh->speech=g_strdup(_("Main Menu"));
1517 gui_internal_widget_pack(this, wh);
1518 gui_internal_widget_append(w, wh);
1521 if (!(this->flags & 6))
1523 l=g_list_last(this->root.children);
1524 wcn=gui_internal_label_new(this,".. »");
1525 wcn->foreground=foreground;
1527 gui_internal_widget_destroy(this, wcn);
1528 wcn=gui_internal_label_new(this,"»");
1529 wcn->foreground=foreground;
1531 gui_internal_widget_destroy(this, wcn);
1533 if (g_list_previous(l) || !g_list_next(l)) {
1535 wcn=gui_internal_label_new(this, wc->text);
1536 wcn->foreground=foreground;
1541 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1542 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1544 gui_internal_widget_destroy(this, wcn);
1548 struct widget *wct=gui_internal_label_new(this, "»");
1549 wct->foreground=foreground;
1550 res=g_list_prepend(res, wct);
1551 width_used+=sep_len+w->spx;
1554 if (!(this->flags & 16)) {
1555 wcn->func=gui_internal_cmd_return;
1557 wcn->state |= STATE_SENSITIVE;
1559 res=g_list_prepend(res, wcn);
1560 if (this->flags & 8)
1563 l=g_list_previous(l);
1567 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1568 wcn->foreground=foreground;
1569 wcn->func=gui_internal_cmd_return;
1571 wcn->state |= STATE_SENSITIVE;
1572 res=g_list_prepend(res, wcn);
1573 l=g_list_previous(l);
1576 wcn=gui_internal_label_new(this, ".. »");
1577 wcn->foreground=foreground;
1578 wcn->func=gui_internal_cmd_return;
1580 wcn->state |= STATE_SENSITIVE;
1581 res=g_list_prepend(res, wcn);
1585 gui_internal_widget_append(w, l->data);
1588 if (this->flags & 32) {
1589 char *version_text=g_strdup_printf("Navit %s",version);
1590 wcn=gui_internal_label_new(this, version_text);
1591 g_free(version_text);
1592 wcn->flags=gravity_right_center|flags_expand;
1593 gui_internal_widget_append(w, wcn);
1597 gui_internal_widget_destroy(this, dots);
1602 static struct widget *
1603 gui_internal_time_help(struct gui_priv *this)
1605 struct widget *w,*wc,*wcn;
1610 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1611 w->bl=this->spacing;
1612 w->spx=this->spacing;
1618 if (this->flags & 64) {
1619 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1625 tm=localtime(&timep);
1626 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1627 wcn=gui_internal_label_new(this, timestr);
1628 gui_internal_widget_append(wc, wcn);
1629 gui_internal_widget_append(w, wc);
1631 if (this->flags & 128) {
1632 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1633 gui_internal_widget_append(w, wcn);
1640 * Applys the configuration values to this based on the settings
1641 * specified in the configuration file (this->config) and
1642 * the most approriate default profile based on screen resolution.
1644 * This function should be run after this->root is setup and could
1645 * be rerun after the window is resized.
1647 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1649 static void gui_internal_apply_config(struct gui_priv *this)
1651 struct gui_config_settings * current_config=0;
1653 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1655 * Select default values from profile based on the screen.
1657 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1659 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1661 current_config = &config_profiles[LARGE_PROFILE];
1665 current_config = &config_profiles[MEDIUM_PROFILE];
1670 current_config = &config_profiles[SMALL_PROFILE];
1674 * Apply override values from config file
1676 if(this->config.font_size == -1 )
1678 this->font_size = current_config->font_size;
1682 this->font_size = this->config.font_size;
1685 if(this->config.icon_xs == -1 )
1687 this->icon_xs = current_config->icon_xs;
1691 this->icon_xs = this->config.icon_xs;
1694 if(this->config.icon_s == -1 )
1696 this->icon_s = current_config->icon_s;
1700 this->icon_s = this->config.icon_s;
1702 if(this->config.icon_l == -1 )
1704 this->icon_l = current_config->icon_l;
1708 this->icon_l = this->config.icon_l;
1710 if(this->config.spacing == -1 )
1712 this->spacing = current_config->spacing;
1716 this->spacing = current_config->spacing;
1721 static struct widget *
1722 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1724 struct widget *wl,*wlb;
1725 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1726 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1727 wl=gui_internal_label_new(this, label);
1729 wlb->foreground=this->text_foreground;
1734 gui_internal_widget_append(wlb, wl);
1736 gui_internal_widget_prepend(wb, wlb);
1738 gui_internal_widget_append(wb, wlb);
1744 static struct widget *
1745 gui_internal_menu(struct gui_priv *this, const char *label)
1747 struct widget *menu,*w,*w1,*topbox;
1749 gui_internal_search_idle_end(this);
1750 topbox=gui_internal_box_new_with_label(this, 0, label);
1751 topbox->w=this->root.w;
1752 topbox->h=this->root.h;
1753 gui_internal_widget_append(&this->root, topbox);
1754 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1755 menu->w=this->root.w;
1756 menu->h=this->root.h;
1757 menu->background=this->background;
1758 gui_internal_apply_config(this);
1759 if (!this->fonts[0]) {
1760 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
1761 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
1762 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
1764 topbox->menu_data=g_new0(struct menu_data, 1);
1765 gui_internal_widget_append(topbox, menu);
1766 w=gui_internal_top_bar(this);
1767 gui_internal_widget_append(menu, w);
1768 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1769 w->spx=4*this->spacing;
1771 gui_internal_widget_append(menu, w);
1772 if (this->flags & 16 && !(this->flags & 1024)) {
1773 struct widget *wlb,*wb,*wm=w;
1774 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1775 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1776 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1777 gui_internal_widget_append(wm, w);
1778 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1784 topbox->menu_data->button_bar=wb;
1785 gui_internal_widget_append(wm, wb);
1786 wlb=gui_internal_button_label(this,_("Back"),1);
1787 wlb->func=gui_internal_back;
1788 wlb->state |= STATE_SENSITIVE;
1790 if (this->flags & 192) {
1791 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1792 menu->w=this->root.w;
1793 menu->h=this->root.h;
1794 w1=gui_internal_time_help(this);
1795 gui_internal_widget_append(menu, w1);
1796 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1797 gui_internal_widget_append(menu, w1);
1798 gui_internal_widget_append(topbox, menu);
1799 menu->background=NULL;
1801 gui_internal_widget_pack(this, topbox);
1802 gui_internal_widget_reset_pack(this, topbox);
1803 topbox->w=this->root.w;
1804 topbox->h=this->root.h;
1805 menu->w=this->root.w;
1806 menu->h=this->root.h;
1810 static struct menu_data *
1811 gui_internal_menu_data(struct gui_priv *this)
1814 struct widget *menu;
1816 l=g_list_last(this->root.children);
1818 return menu->menu_data;
1822 gui_internal_menu_reset_pack(struct gui_priv *this)
1825 struct widget *top_box;
1827 l=g_list_last(this->root.children);
1829 gui_internal_widget_reset_pack(this, top_box);
1833 gui_internal_menu_render(struct gui_priv *this)
1836 struct widget *menu;
1838 l=g_list_last(this->root.children);
1840 gui_internal_say(this, menu, 0);
1841 gui_internal_widget_pack(this, menu);
1842 gui_internal_widget_render(this, menu);
1846 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1849 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1850 navit_set_destination(this->nav, &wm->c, name, 1);
1851 if (this->flags & 512) {
1853 follow.type=attr_follow;
1855 navit_set_attr(this->nav, &this->osd_configuration);
1856 navit_set_attr(this->nav, &follow);
1857 navit_zoom_to_route(this->nav, 0);
1859 gui_internal_prune_menu(this, NULL);
1863 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1865 navit_set_position(this->nav, &wm->c);
1866 gui_internal_prune_menu(this, NULL);
1870 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1874 dbg(0,"text='%s'\n", widget->text);
1875 if (widget->text && strlen(widget->text)){
1876 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1877 bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
1879 g_free(widget->text);
1881 l=g_list_previous(g_list_last(this->root.children));
1882 gui_internal_prune_menu(this, l->data);
1886 gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
1890 dbg(0,"text='%s'\n", widget->text);
1891 if (widget->text && strlen(widget->text)){
1892 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1893 bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
1895 g_free(widget->text);
1897 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
1898 gui_internal_prune_menu(this, l->data);
1902 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1904 gui_internal_cmd_add_bookmark_do(this, widget->data);
1908 gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
1910 gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
1914 gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
1916 struct widget *w=(struct widget*)widget->data;
1919 dbg(0,"text='%s'\n", w->text);
1920 if (w->text && strlen(w->text)){
1921 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1922 bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
1928 l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
1929 gui_internal_prune_menu(this, l->data);
1933 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1938 len=strlen(wm->text);
1939 dbg(1,"len=%d\n", len);
1940 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1941 wm->text[len-1]='\0';
1942 gui_internal_cmd_add_bookmark_do(this, wm);
1948 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1951 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
1953 struct widget *w,*wb,*wk,*wl,*we,*wnext;
1955 wb=gui_internal_menu(this,_("Add Bookmark"));
1956 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1957 gui_internal_widget_append(wb, w);
1958 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1959 gui_internal_widget_append(w, we);
1960 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
1961 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
1962 wk->background=this->background;
1963 wk->flags |= flags_expand|flags_fill;
1964 wk->func = gui_internal_cmd_add_bookmark_changed;
1966 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1967 wnext->state |= STATE_SENSITIVE;
1968 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1970 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1971 gui_internal_widget_append(w, wl);
1973 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1974 gui_internal_menu_render(this);
1978 gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
1980 struct widget *w,*wb,*wk,*wl,*we,*wnext;
1982 wb=gui_internal_menu(this,_("Add Bookmark folder"));
1983 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1984 gui_internal_widget_append(wb, w);
1985 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1986 gui_internal_widget_append(w, we);
1987 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
1988 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
1989 wk->background=this->background;
1990 wk->flags |= flags_expand|flags_fill;
1991 wk->func = gui_internal_cmd_add_bookmark_changed;
1993 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1994 wnext->state |= STATE_SENSITIVE;
1995 wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
1997 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1998 gui_internal_widget_append(w, wl);
2000 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2001 gui_internal_menu_render(this);
2005 gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2007 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2008 char *name=wm->text;
2009 wb=gui_internal_menu(this,_("Rename"));
2010 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2011 gui_internal_widget_append(wb, w);
2012 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2013 gui_internal_widget_append(w, we);
2014 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2015 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2016 wk->background=this->background;
2017 wk->flags |= flags_expand|flags_fill;
2018 wk->func = gui_internal_cmd_add_bookmark_changed;
2020 wk->name=g_strdup(name);
2021 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2022 wnext->state |= STATE_SENSITIVE;
2023 wnext->func = gui_internal_cmd_rename_bookmark_clicked;
2025 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2026 gui_internal_widget_append(w, wl);
2028 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2029 gui_internal_menu_render(this);
2033 gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2037 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2038 bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
2039 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2040 gui_internal_prune_menu(this, l->data);
2044 gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2048 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2049 bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
2050 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2051 gui_internal_prune_menu(this, l->data);
2055 gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2059 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2060 bookmarks_paste_bookmark(mattr.u.bookmarks);
2061 l=g_list_previous(g_list_last(this->root.children));
2062 gui_internal_prune_menu(this, l->data);
2066 gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2070 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2071 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
2072 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2073 gui_internal_prune_menu(this, l->data);
2077 get_direction(char *buffer, int angle, int mode)
2082 sprintf(buffer,"%d",angle);
2085 if (angle < 69 || angle > 291)
2087 if (angle > 111 && angle < 249)
2089 if (angle > 22 && angle < 158)
2091 if (angle > 202 && angle < 338)
2096 angle=(angle+15)/30;
2099 sprintf(buffer,"%d H", angle);
2107 enum item_type *types;
2109 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
2110 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
2111 {"hotel","Hotel",(enum item_type []) {
2112 type_poi_hotel,type_poi_camp_rv,
2113 type_poi_camping,type_poi_camping,
2114 type_poi_resort,type_poi_resort,
2115 type_poi_motel,type_poi_hostel,
2117 {"restaurant","Restaurant",(enum item_type []) {
2118 type_poi_bar,type_poi_picnic,
2119 type_poi_burgerking,type_poi_fastfood,
2120 type_poi_restaurant,type_poi_restaurant,
2122 {"shopping","Shopping",(enum item_type []) {
2123 type_poi_mall,type_poi_mall,
2124 type_poi_shop_grocery,type_poi_shop_grocery,
2126 {"hospital","Service",(enum item_type []) {
2127 type_poi_marina,type_poi_marina,
2128 type_poi_hospital,type_poi_hospital,
2129 type_poi_public_utilities,type_poi_public_utilities,
2130 type_poi_police,type_poi_autoservice,
2131 type_poi_information,type_poi_information,
2132 type_poi_personal_service,type_poi_repair_service,
2133 type_poi_restroom,type_poi_restroom,
2135 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
2136 {"peak","Land Features",(enum item_type []){
2137 type_poi_land_feature,type_poi_rock,
2138 type_poi_dam,type_poi_dam,
2140 {"unknown","Other",(enum item_type []){
2141 type_point_unspecified,type_point_unkn-1,
2142 type_point_unkn+1,type_poi_land_feature-1,
2143 type_poi_rock+1,type_poi_fuel-1,
2144 type_poi_marina+1,type_poi_car_parking-1,
2145 type_poi_car_parking+1,type_poi_bar-1,
2146 type_poi_bank+1,type_poi_dam-1,
2147 type_poi_dam+1,type_poi_information-1,
2148 type_poi_information+1,type_poi_mall-1,
2149 type_poi_mall+1,type_poi_personal_service-1,
2150 type_poi_restaurant+1,type_poi_restroom-1,
2151 type_poi_restroom+1,type_poi_shop_grocery-1,
2152 type_poi_shop_grocery+1,type_poi_motel-1,
2153 type_poi_hostel+1,type_selected_point,
2155 {"unknown","Unknown",(enum item_type []){
2156 type_point_unkn,type_point_unkn,
2160 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2162 static struct widget *
2163 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
2165 struct widget *wl,*wb;
2167 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2168 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
2169 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2170 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2171 gui_internal_cmd_pois, &selectors[i]));
2178 static struct widget *
2179 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
2185 struct widget *wl,*wt;
2188 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2190 sprintf(distbuf,"%d", dist/1000);
2191 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2192 type=item_to_name(item->type);
2193 if (item_attr_get(item, attr_label, &attr)) {
2194 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
2197 wl->name=g_strdup(type);
2199 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
2200 wt=gui_internal_label_new(this, text);
2202 gui_internal_widget_append(wl, wt);
2209 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
2211 const struct widget *wa=a;
2212 const struct widget *wb=b;
2213 struct widget *wac=wa->children->data;
2214 struct widget *wbc=wb->children->data;
2222 return wac->datai-wbc->datai;
2227 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
2229 enum item_type *types;
2230 if (type >= type_line)
2232 if (! sel || !sel->types)
2235 while (*types != type_none) {
2236 if (type >= types[0] && type <= types[1]) {
2244 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2247 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
2249 struct map_selection *sel,*selm;
2250 struct coord c,center;
2251 struct mapset_handle *h;
2253 struct map_rect *mr;
2255 int idist,dist=20000;
2256 struct widget *wi,*w,*w2,*wb;
2257 enum projection pro=wm->c.pro;
2258 struct selector *isel=wm->data;
2260 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2261 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2262 gui_internal_widget_append(wb, w);
2264 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
2265 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2266 gui_internal_widget_append(w, w2);
2268 sel=map_selection_rect_new(&wm->c, dist, 18);
2271 h=mapset_open(navit_get_mapset(this->nav));
2272 while ((m=mapset_next(h, 1))) {
2273 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2274 mr=map_rect_new(m, selm);
2275 dbg(2,"mr=%p\n", mr);
2277 while ((item=map_rect_get_item(mr))) {
2278 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
2279 item_coord_get_pro(item, &c, 1, pro) &&
2280 coord_rect_contains(&sel->u.c_rect, &c) &&
2281 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2282 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
2283 wi->func=gui_internal_cmd_position;
2286 wi->state |= STATE_SENSITIVE;
2292 map_rect_destroy(mr);
2294 map_selection_destroy(selm);
2296 map_selection_destroy(sel);
2298 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
2299 gui_internal_menu_render(this);
2303 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2305 if (wm->item.type != type_none) {
2306 enum item_type type;
2307 if (wm->item.type < type_line)
2308 type=type_selected_point;
2309 else if (wm->item.type < type_area)
2310 type=type_selected_point;
2312 type=type_selected_area;
2313 graphics_clear_selection(this->gra, NULL);
2314 graphics_add_selection(this->gra, &wm->item, type, NULL);
2316 navit_set_center(this->nav, &wm->c, 1);
2317 gui_internal_prune_menu(this, NULL);
2322 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2324 struct widget *w,*wb;
2325 struct map_rect *mr;
2331 text=g_strdup_printf("Attribute %s",wm->name);
2332 wb=gui_internal_menu(this, text);
2334 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2335 gui_internal_widget_append(wb, w);
2336 mr=map_rect_new(wm->item.map, NULL);
2337 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2338 for (i = 0 ; i < wm->datai ; i++) {
2339 item_attr_get(item, attr_any, &attr);
2341 if (item_attr_get(item, attr_any, &attr)) {
2343 switch (attr.type) {
2344 case attr_osm_nodeid:
2345 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2347 case attr_osm_wayid:
2348 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2350 case attr_osm_relationid:
2351 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2357 gui_internal_widget_append(w,
2358 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2359 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2360 gui_internal_cmd_view_in_browser, NULL));
2364 map_rect_destroy(mr);
2365 gui_internal_menu_render(this);
2369 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2371 struct widget *w,*wb;
2372 struct map_rect *mr;
2378 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2379 wb=gui_internal_menu(this, "Attributes");
2380 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2381 gui_internal_widget_append(wb, w);
2382 mr=map_rect_new(wm->item.map, NULL);
2383 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2384 dbg(0,"item=%p\n", item);
2386 while(item_attr_get(item, attr_any, &attr)) {
2387 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2388 gui_internal_widget_append(w,
2389 wb=gui_internal_button_new_with_callback(this, text,
2390 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2391 gui_internal_cmd_view_attribute_details, NULL));
2392 wb->name=g_strdup(text);
2398 map_rect_destroy(mr);
2399 gui_internal_menu_render(this);
2403 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2405 struct map_rect *mr;
2411 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2412 mr=map_rect_new(wm->item.map, NULL);
2413 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2414 dbg(0,"item=%p\n", item);
2416 while(item_attr_get(item, attr_url_local, &attr)) {
2418 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2421 map_rect_destroy(mr);
2423 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2429 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2436 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)
2438 struct widget *wb,*w,*wc,*wbc;
2448 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2449 transform_to_geo(pc.pro, &c, &g);
2452 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
2455 pc.pro=attr.u.projection;
2456 transform_from_geo(pc.pro, &g, &c);
2462 wb=gui_internal_menu(this, name);
2463 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2464 gui_internal_widget_append(wb, w);
2465 coord=coordinates(&pc, ' ');
2466 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2468 if ((flags & 1) && wm) {
2469 gui_internal_widget_append(w,
2470 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2471 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2472 gui_internal_search_street_in_town, wm));
2474 wc->selection_id=wm->selection_id;
2476 if ((flags & 2) && wm) {
2477 gui_internal_widget_append(w,
2478 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2479 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2480 gui_internal_search_house_number_in_street, wm));
2482 wc->selection_id=wm->selection_id;
2484 if ((flags & 4) && wm) {
2485 struct map_rect *mr;
2488 mr=map_rect_new(wm->item.map, NULL);
2489 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2491 if (item_attr_get(item, attr_description, &attr))
2492 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2493 if (item_attr_get(item, attr_url_local, &attr)) {
2494 gui_internal_widget_append(w,
2495 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2496 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2497 gui_internal_cmd_view_in_browser, NULL));
2500 gui_internal_widget_append(w,
2501 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2502 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2503 gui_internal_cmd_view_attributes, NULL));
2506 map_rect_destroy(mr);
2509 gui_internal_widget_append(w,
2510 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
2511 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2512 gui_internal_cmd_set_destination, g_strdup(name)));
2513 wbc->data_free=g_free;
2517 gui_internal_widget_append(w,
2518 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
2519 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2520 gui_internal_cmd_set_position, wm));
2524 gui_internal_widget_append(w,
2525 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2526 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2527 gui_internal_cmd_add_bookmark2, g_strdup(name)));
2528 wbc->data_free=g_free;
2532 gui_internal_widget_append(w,
2533 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2534 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2535 gui_internal_cmd_pois, NULL));
2539 gui_internal_widget_append(w,
2540 gui_internal_button_new(this, "Add to tour",
2541 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2544 gui_internal_widget_append(w,
2545 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
2546 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2547 gui_internal_cmd_view_on_map, NULL));
2549 if ((flags & 4) && wm)
2552 wbc->item.type=type_none;
2557 struct mapset_handle *h;
2558 struct map_rect *mr;
2561 struct street_data *data;
2562 struct map_selection sel;
2563 struct transformation *trans;
2564 enum projection pro;
2568 trans=navit_get_trans(this->nav);
2569 pro=transform_get_projection(trans);
2570 transform_from_geo(pro, &g, &c);
2571 ms=navit_get_mapset(this->nav);
2573 sel.u.c_rect.lu.x=c.x-dist;
2574 sel.u.c_rect.lu.y=c.y+dist;
2575 sel.u.c_rect.rl.x=c.x+dist;
2576 sel.u.c_rect.rl.y=c.y-dist;
2578 sel.range=item_range_all;
2580 while ((m=mapset_next(h,1))) {
2581 mr=map_rect_new(m, &sel);
2584 while ((item=map_rect_get_item(mr))) {
2585 data=street_get_data(item);
2586 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2587 if (item_attr_get(item, attr_label, &attr)) {
2588 label=map_convert_string(m, attr.u.str);
2589 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2590 map_convert_free(label);
2592 text=g_strdup_printf("%s", item_to_name(item->type));
2593 gui_internal_widget_append(w,
2594 wc=gui_internal_button_new_with_callback(this, text,
2595 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2596 gui_internal_cmd_position, (void *)2));
2597 wc->c.x=data->c[0].x;
2598 wc->c.y=data->c[0].y;
2600 wc->name=g_strdup(text);
2604 street_data_free(data);
2606 map_rect_destroy(mr);
2611 gui_internal_widget_append(w,
2612 wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
2613 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2614 gui_internal_cmd_cut_bookmark, NULL));
2615 wbc->text=g_strdup(wm->text);
2616 gui_internal_widget_append(w,
2617 wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
2618 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2619 gui_internal_cmd_copy_bookmark, NULL));
2620 wbc->text=g_strdup(wm->text);
2621 gui_internal_widget_append(w,
2622 wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
2623 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2624 gui_internal_cmd_rename_bookmark, NULL));
2625 wbc->text=g_strdup(wm->text);
2626 gui_internal_widget_append(w,
2627 wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
2628 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2629 gui_internal_cmd_paste_bookmark, NULL));
2630 gui_internal_widget_append(w,
2631 wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
2632 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2633 gui_internal_cmd_delete_bookmark, NULL));
2634 wbc->text=g_strdup(wm->text);
2636 gui_internal_menu_render(this);
2640 /* wm->data: 0 Nothing special
2651 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2654 switch ((int) wm->data) {
2656 flags=8|16|32|64|128|256;
2659 flags=8|16|32|64|256;
2665 flags=1|8|16|32|64|128;
2666 flags &= this->flags_town;
2669 gui_internal_search_town_in_country(this, wm);
2672 flags=2|8|16|32|64|128;
2673 flags &= this->flags_street;
2676 flags=8|16|32|64|128;
2677 flags &= this->flags_house_number;
2680 flags=8|16|64|128|512;
2687 gui_internal_search_house_number_in_street(this, wm, NULL);
2690 gui_internal_cmd_set_destination(this, wm, NULL);
2693 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
2697 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2699 char *name=_("Position");
2705 if (!ATTR_IS_COORD_GEO(in[0]->type))
2707 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
2709 if (in[2] && ATTR_IS_INT(in[2]->type))
2712 dbg(1,"flags=0x%x\n",flags);
2713 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
2717 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2719 struct attr attr,mattr;
2721 char *label_full,*prefix="";
2722 int plen,hassub,found=0;
2723 struct widget *wb,*w,*wbm;
2727 prefix=g_strdup(data);
2729 if (wm && wm->prefix)
2730 prefix=g_strdup(wm->prefix);
2732 plen=strlen(prefix);
2734 gui_internal_prune_menu_count(this, 1, 0);
2735 wb=gui_internal_menu(this, _("Bookmarks"));
2736 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2737 w->spy=this->spacing*3;
2738 gui_internal_widget_append(wb, w);
2740 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
2742 bookmarks_move_root(mattr.u.bookmarks);
2744 if (!strcmp(prefix,"..")) {
2745 bookmarks_move_up(mattr.u.bookmarks);
2747 prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
2749 plen=strlen(prefix);
2754 bookmarks_move_down(mattr.u.bookmarks,prefix);
2757 wbm=gui_internal_button_new_with_callback(this, "..",
2758 image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
2759 gui_internal_cmd_bookmarks, NULL);
2760 wbm->prefix=g_strdup("..");
2761 gui_internal_widget_append(w, wbm);
2764 wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
2765 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2766 gui_internal_cmd_add_bookmark_folder2, NULL);
2767 gui_internal_widget_append(w, wbm);
2768 wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
2769 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2770 gui_internal_cmd_paste_bookmark, NULL);
2771 gui_internal_widget_append(w, wbm);
2772 bookmarks_item_rewind(mattr.u.bookmarks);
2773 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
2774 if (!item_attr_get(item, attr_label, &attr)) continue;
2775 label_full=attr.u.str;
2776 dbg(0,"full_labled: %s\n",label_full);
2777 if (item->type == type_bookmark_folder) {
2782 wbm=gui_internal_button_new_with_callback(this, label_full,
2783 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2784 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2785 if (item_coord_get(item, &c, 1)) {
2788 wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
2789 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2790 wbm->text=g_strdup(label_full);
2792 wbm->data=(void*)7;//Mark us as a bookmark
2794 gui_internal_widget_append(w, wbm);
2795 wbm->prefix=g_strdup(label_full);
2797 gui_internal_widget_destroy(this, wbm);
2805 gui_internal_check_exit(this);
2807 gui_internal_menu_render(this);
2811 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2814 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
2817 gui_internal_cmd_bookmarks(this, NULL, str);
2820 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2822 struct widget *wi,*menu;
2826 menu=g_list_last(this->root.children)->data;
2827 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2829 if (*key == NAVIT_KEY_BACKSPACE) {
2830 dbg(0,"backspace\n");
2831 if (wi->text && wi->text[0]) {
2832 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2834 text=g_strdup_printf("%s ", wi->text);
2837 if (wi->state & STATE_CLEAR) {
2838 dbg(0,"wi->state=0x%x\n", wi->state);
2841 wi->state &= ~STATE_CLEAR;
2842 dbg(0,"wi->state=0x%x\n", wi->state);
2844 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2848 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2849 gui_internal_widget_render(this, wi);
2854 wi->func(this, wi, wi->data);
2856 gui_internal_widget_render(this, wi);
2862 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2864 struct menu_data *md=gui_internal_menu_data(this);
2865 gui_internal_keypress_do(this, (char *) wm->data);
2866 if (md->keyboard_mode == 2)
2867 gui_internal_keyboard_do(this, md->keyboard, 10);
2868 if (md->keyboard_mode == 26)
2869 gui_internal_keyboard_do(this, md->keyboard, 34);
2873 gui_internal_search_idle_end(struct gui_priv *this)
2876 event_remove_idle(this->idle);
2879 if (this->idle_cb) {
2880 callback_destroy(this->idle_cb);
2886 postal_str(struct search_list_result *res, int level)
2889 if (res->town->common.postal)
2890 ret=res->town->common.postal;
2891 if (res->town->common.postal_mask)
2892 ret=res->town->common.postal_mask;
2895 if (res->street->common.postal)
2896 ret=res->street->common.postal;
2897 if (res->street->common.postal_mask)
2898 ret=res->street->common.postal_mask;
2901 if (res->house_number->common.postal)
2902 ret=res->house_number->common.postal;
2903 if (res->house_number->common.postal_mask)
2904 ret=res->house_number->common.postal_mask;
2909 district_str(struct search_list_result *res, int level)
2912 if (res->town->common.district_name)
2913 ret=res->town->common.district_name;
2916 if (res->street->common.district_name)
2917 ret=res->street->common.district_name;
2920 if (res->house_number->common.district_name)
2921 ret=res->house_number->common.district_name;
2926 town_str(struct search_list_result *res, int level, int flags)
2928 char *town=res->town->common.town_name;
2929 char *district=district_str(res, level);
2930 char *postal=postal_str(res, level);
2931 char *postal_sep=" ";
2932 char *district_begin=" (";
2933 char *district_end=")";
2935 postal_sep=postal="";
2936 if (!district || (flags & 1))
2937 district_begin=district_end=district="";
2939 return g_strdup_printf("%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end);
2943 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2945 char *text=NULL,*text2=NULL,*name=NULL;
2946 struct search_list_result *res;
2948 struct item *item=NULL;
2950 static char possible_keys[256]="";
2952 res=search_list_get_result(this->sl);
2954 gchar* trunk_name = NULL;
2956 struct widget *menu=g_list_last(this->root.children)->data;
2957 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2960 if (! strcmp(wm_name,"Town"))
2961 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
2962 if (! strcmp(wm_name,"Street"))
2963 trunk_name = g_strrstr(name=res->street->name, wi->text);
2966 char next_char = trunk_name[strlen(wi->text)];
2968 int len = strlen(possible_keys);
2969 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2970 if (i==len || !len) {
2971 possible_keys[len]=trunk_name[strlen(wi->text)];
2972 possible_keys[len+1]='\0';
2974 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
2977 dbg(0, "Unable to find widget");
2982 gui_internal_search_idle_end(this);
2984 struct menu_data *md=gui_internal_menu_data(this);
2985 if (md && md->keyboard && !(this->flags & 2048)) {
2986 GList *lk=md->keyboard->children;
2987 graphics_draw_mode(this->gra, draw_mode_begin);
2989 struct widget *child=lk->data;
2990 GList *lk2=child->children;
2992 struct widget *child_=lk2->data;
2993 lk2=g_list_next(lk2);
2994 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2995 if (strlen(possible_keys) == 0)
2996 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2997 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2998 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3000 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
3002 gui_internal_widget_render(this,child_);
3007 gui_internal_widget_render(this,md->keyboard);
3008 graphics_draw_mode(this->gra, draw_mode_end);
3011 possible_keys[0]='\0';
3015 if (! strcmp(wm_name,"Country")) {
3016 name=res->country->name;
3017 item=&res->country->common.item;
3018 text=g_strdup_printf("%s", res->country->name);
3020 if (! strcmp(wm_name,"Town")) {
3021 item=&res->town->common.item;
3022 name=res->town->common.town_name;
3023 text=town_str(res, 1, 0);
3025 if (! strcmp(wm_name,"Street")) {
3026 name=res->street->name;
3027 item=&res->street->common.item;
3028 text=g_strdup(res->street->name);
3029 text2=town_str(res, 2, 1);
3031 if (! strcmp(wm_name,"House number")) {
3032 name=res->house_number->house_number;
3033 text=g_strdup_printf("%s %s", res->street->name, name);
3034 text2=town_str(res, 3, 0);
3036 dbg(1,"res->country->flag=%s\n", res->country->flag);
3038 gui_internal_widget_append(search_list,
3039 wc=gui_internal_button_new_with_callback(this, text,
3040 image_new_xs(this, res->country->flag),
3041 gravity_left_center|orientation_horizontal|flags_fill,
3042 gui_internal_cmd_position, param));
3045 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3046 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
3047 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
3048 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
3049 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
3050 gui_internal_widget_append(wc, wb);
3051 wc->func=gui_internal_cmd_position;
3053 wc->state |= STATE_SENSITIVE;
3054 wc->speech=g_strdup(text);
3055 gui_internal_widget_append(search_list, wc);
3057 wc->name=g_strdup(name);
3060 wc->selection_id=res->id;
3063 gui_internal_widget_pack(this, search_list);
3064 l=g_list_last(this->root.children);
3065 graphics_draw_mode(this->gra, draw_mode_begin);
3066 gui_internal_widget_render(this, l->data);
3067 graphics_draw_mode(this->gra, draw_mode_end);
3073 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3075 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
3076 this->idle=event_add_idle(50,this->idle_cb);
3077 callback_call_0(this->idle_cb);
3083 * @param wm The widget that generated the event for the search changed,
3084 * if this was generated by a key on the virtual keyboard then
3085 * wm is the key button widget.
3088 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
3091 struct widget *search_list=gui_internal_menu_data(this)->search_list;
3092 gui_internal_widget_children_destroy(this, search_list);
3094 void *param=(void *)3;
3096 if (! strcmp(wm->name,"Country"))
3098 if (! strcmp(wm->name,"Street"))
3100 if (! strcmp(wm->name,"House number"))
3102 dbg(0,"%s now '%s'\n", wm->name, wm->text);
3104 gui_internal_search_idle_end(this);
3105 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
3106 struct attr search_attr;
3109 if (! strcmp(wm->name,"Country"))
3110 search_attr.type=attr_country_all;
3111 if (! strcmp(wm->name,"Town"))
3112 search_attr.type=attr_town_or_district_name;
3113 if (! strcmp(wm->name,"Street"))
3114 search_attr.type=attr_street_name;
3115 if (! strcmp(wm->name,"House number"))
3116 search_attr.type=attr_house_number;
3117 search_attr.u.str=wm->text;
3118 search_list_search(this->sl, &search_attr, 1);
3119 gui_internal_search_idle_start(this, wm->name, search_list, param);
3121 l=g_list_last(this->root.children);
3122 gui_internal_widget_render(this, l->data);
3125 static struct widget *
3126 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)
3129 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
3130 NULL, gravity_center|orientation_vertical, func, data));
3131 wk->data_free=data_free;
3132 wk->background=this->background;
3140 static struct widget *
3141 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
3143 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
3146 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
3148 // Some macros that make the keyboard layout easier to visualise in
3149 // the source code. The macros are #undef'd after this function.
3150 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
3151 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
3152 static struct widget *
3153 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
3155 struct widget *wkbd,*wk;
3156 struct menu_data *md=gui_internal_menu_data(this);
3157 int i, max_w=this->root.w, max_h=this->root.h;
3160 char *backspace="←";
3165 char *numeric="123";
3167 char *umlauts_ucase="ÄÖÜ";
3168 int umlauts_ucase_font=2;
3169 char *umlauts_lcase="äöü";
3170 int umlauts_lcase_font=2;
3177 gui_internal_highlight(this);
3178 if (md->keyboard_mode >= 1024)
3182 gui_internal_widget_children_destroy(this, wkbdb);
3184 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
3186 md->keyboard_mode=mode;
3187 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
3188 wkbd->background=this->background;
3195 if (mode >= 0 && mode < 8) {
3196 for (i = 0 ; i < 26 ; i++) {
3197 char text[]={'A'+i,'\0'};
3200 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3204 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3205 wk->datai=mode+1024;
3207 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3208 wk->datai=mode+1024;
3209 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3211 wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3214 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
3216 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3218 if (mode >= 8 && mode < 16) {
3219 for (i = 0 ; i < 26 ; i++) {
3220 char text[]={'a'+i,'\0'};
3223 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3227 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3228 wk->datai=mode+1024;
3230 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3231 wk->datai=mode+1024;
3232 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3234 wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3237 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_lcase, umlauts_lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3239 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3241 if (mode >= 16 && mode < 24) {
3242 for (i = 0 ; i < 10 ; i++) {
3243 char text[]={'0'+i,'\0'};
3246 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
3247 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
3249 for (i = 0 ; i < 5 ; i++) SPACER();
3254 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3255 wk->datai=mode+1024;
3257 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3258 wk->datai=mode+1024;
3259 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3261 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3264 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3266 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3268 if (mode >= 24 && mode < 32) {
3269 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
3270 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
3271 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
3272 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
3274 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3277 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3279 if (mode >= 32 && mode < 40) {
3280 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
3281 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
3282 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
3283 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
3285 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3288 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3295 if (mode >= 0 && mode < 8) {
3298 } else if (mode >= 8 && mode < 16) {
3301 } else if (mode >= 16 && mode < 24) {
3304 } else if (mode >= 24 && mode < 32) {
3306 font=umlauts_ucase_font;
3307 } else if (mode >= 32 && mode < 40) {
3309 font=umlauts_lcase_font;
3311 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
3312 wk->func=gui_internal_keyboard_change;
3314 wk->background=this->background;
3320 wk->state |= STATE_SENSITIVE;
3321 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
3322 wkl->background=NULL;
3323 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
3324 wkl->background=NULL;
3325 gui_internal_widget_append(wkbd, wk);
3329 gui_internal_widget_append(wkbdb, wkbd);
3331 gui_internal_widget_pack(this, wkbdb);
3332 gui_internal_widget_render(this, wkbdb);
3333 } else if (render == 2) {
3334 gui_internal_menu_reset_pack(this);
3335 gui_internal_menu_render(this);
3342 static struct widget *
3343 gui_internal_keyboard(struct gui_priv *this, int mode)
3345 if (! this->keyboard)
3347 return gui_internal_keyboard_do(this, NULL, mode);
3351 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
3353 gui_internal_keyboard_do(this, key->data, key->datai);
3357 gui_internal_search_list_set_default_country(struct gui_priv *this)
3359 struct attr search_attr, country_name, country_iso2, *country_attr;
3361 struct country_search *cs;
3362 struct tracking *tracking;
3363 struct search_list_result *res;
3365 country_attr=country_default();
3366 tracking=navit_get_tracking(this->nav);
3367 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
3368 country_attr=&search_attr;
3370 cs=country_search_new(country_attr, 0);
3371 item=country_search_get_item(cs);
3372 if (item && item_attr_get(item, attr_country_name, &country_name)) {
3373 search_attr.type=attr_country_all;
3374 dbg(0,"country %s\n", country_name.u.str);
3375 search_attr.u.str=country_name.u.str;
3376 search_list_search(this->sl, &search_attr, 0);
3377 while((res=search_list_get_result(this->sl)));
3378 g_free(this->country_iso2);
3379 if (item_attr_get(item, attr_country_iso2, &country_iso2))
3380 this->country_iso2=g_strdup(country_iso2.u.str);
3382 country_search_destroy(cs);
3384 dbg(0,"warning: no default country found\n");
3385 if (this->country_iso2) {
3386 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
3387 search_attr.type=attr_country_iso2;
3388 search_attr.u.str=this->country_iso2;
3389 search_list_search(this->sl, &search_attr, 0);
3390 while((res=search_list_get_result(this->sl)));
3396 gui_internal_search_list_new(struct gui_priv *this)
3398 struct mapset *ms=navit_get_mapset(this->nav);
3400 this->sl=search_list_new(ms);
3401 gui_internal_search_list_set_default_country(this);
3406 gui_internal_search_list_destroy(struct gui_priv *this)
3409 search_list_destroy(this->sl);
3416 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
3418 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
3420 int keyboard_mode=2;
3421 gui_internal_search_list_new(this);
3422 wb=gui_internal_menu(this, what);
3423 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
3424 gui_internal_widget_append(wb, w);
3425 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3426 gui_internal_widget_append(w, wr);
3427 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3428 gui_internal_widget_append(wr, we);
3430 if (!strcmp(type,"Country")) {
3431 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
3432 wnext->func=gui_internal_search_town;
3433 } else if (!strcmp(type,"Town")) {
3434 if (this->country_iso2) {
3435 #if HAVE_API_ANDROID
3436 char country_iso2[strlen(this->country_iso2)+1];
3437 strtolower(country_iso2, this->country_iso2);
3438 country=g_strdup_printf("country_%s", country_iso2);
3440 country=g_strdup_printf("country_%s", this->country_iso2);
3443 country=strdup("gui_select_country");
3444 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
3445 wb->state |= STATE_SENSITIVE;
3447 wb->func = gui_internal_search_country;
3449 wb->func = gui_internal_back;
3450 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
3451 wnext->func=gui_internal_search_street;
3453 } else if (!strcmp(type,"Street")) {
3454 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
3455 wb->state |= STATE_SENSITIVE;
3456 wb->func = gui_internal_back;
3457 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
3458 wnext->func=gui_internal_search_house_number;
3459 } else if (!strcmp(type,"House number")) {
3460 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
3461 wb->state |= STATE_SENSITIVE;
3462 wb->func = gui_internal_back;
3465 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3467 gui_internal_widget_append(we, wnext);
3468 wnext->state |= STATE_SENSITIVE;
3470 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3471 gui_internal_widget_append(wr, wl);
3472 gui_internal_menu_data(this)->search_list=wl;
3473 wk->state |= STATE_EDIT|STATE_EDITABLE;
3474 wk->background=this->background;
3475 wk->flags |= flags_expand|flags_fill;
3476 wk->func = gui_internal_search_changed;
3477 wk->name=g_strdup(type);
3479 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
3480 gui_internal_menu_render(this);
3484 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3486 search_list_select(this->sl, attr_street_name, 0, 0);
3487 gui_internal_search(this,_("House number"),"House number",0);
3491 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3493 dbg(0,"id %d\n", widget->selection_id);
3494 search_list_select(this->sl, attr_street_name, 0, 0);
3495 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3496 gui_internal_search(this,_("House number"),"House number",0);
3500 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3502 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3503 gui_internal_search(this,_("Street"),"Street",0);
3507 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3509 dbg(0,"id %d\n", widget->selection_id);
3510 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3511 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3512 gui_internal_search(this,_("Street"),"Street",0);
3516 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3519 search_list_select(this->sl, attr_country_all, 0, 0);
3520 g_free(this->country_iso2);
3521 this->country_iso2=NULL;
3522 gui_internal_search(this,_("Town"),"Town",0);
3526 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3528 struct search_list_common *slc;
3529 dbg(0,"id %d\n", widget->selection_id);
3530 search_list_select(this->sl, attr_country_all, 0, 0);
3531 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3533 g_free(this->country_iso2);
3534 this->country_iso2=((struct search_list_country *)slc)->iso2;
3536 gui_internal_search(this,widget->name,"Town",0);
3540 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3542 gui_internal_prune_menu_count(this, 1, 0);
3543 gui_internal_search(this,_("Country"),"Country",0);
3547 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3550 search_list_select(this->sl, attr_country_all, 0, 0);
3551 gui_internal_search(this,_("Town"),"Town",1);
3555 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3558 struct widget *w,*wb,*wl;
3559 struct attr_iter *iter;
3562 wb=gui_internal_menu(this, _("Layout"));
3563 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3564 w->spy=this->spacing*3;
3565 gui_internal_widget_append(wb, w);
3566 iter=navit_attr_iter_new();
3567 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3568 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3570 gui_internal_widget_append(w, wl);
3572 navit_attr_iter_destroy(iter);
3573 gui_internal_menu_render(this);
3577 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3580 navit.type=attr_navit;
3581 navit.u.navit=this->nav;
3582 navit_destroy(navit.u.navit);
3583 config_remove_attr(config, &navit);
3584 event_main_loop_quit();
3588 gui_internal_window_closed(struct gui_priv *this)
3590 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3594 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3596 navit_set_destination(this->nav, NULL, NULL, 0);
3601 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3603 struct attr attr, on, off, description, type, data;
3604 struct widget *w,*wb,*wma;
3606 struct attr_iter *iter;
3609 wb=gui_internal_menu(this, _("Maps"));
3610 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3611 w->spy=this->spacing*3;
3612 gui_internal_widget_append(wb, w);
3613 iter=navit_attr_iter_new();
3614 on.type=off.type=attr_active;
3617 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3618 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3619 label=g_strdup(description.u.str);
3621 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3623 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3625 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3627 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3628 attr.u.map, &on, &off, 1);
3629 gui_internal_widget_append(w, wma);
3632 navit_attr_iter_destroy(iter);
3633 gui_internal_menu_render(this);
3637 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3639 struct attr vehicle = {attr_vehicle,{wm->data}};
3640 navit_set_attr(this->nav, &vehicle);
3644 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3646 struct widget *w,*wb,*row;
3647 struct attr attr,sat_attr;
3648 struct vehicle *v=wm->data;
3651 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3653 wb=gui_internal_menu(this, _("Show Satellite Status"));
3654 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3655 gui_internal_menu_data(this)->redisplay_widget=wm;
3656 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3657 gui_internal_widget_append(wb, w);
3658 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3659 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3660 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
3661 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3662 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3663 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
3664 gui_internal_widget_append(w,row);
3665 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3666 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3667 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3668 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3669 str=g_strdup_printf("%d", sat_attr.u.num);
3672 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3675 gui_internal_widget_append(w,row);
3677 gui_internal_widget_append(wb, w);
3678 gui_internal_menu_render(this);
3682 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3684 struct widget *w,*wb;
3686 struct vehicle *v=wm->data;
3687 wb=gui_internal_menu(this, _("Show NMEA Data"));
3688 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3689 gui_internal_menu_data(this)->redisplay_widget=wm;
3690 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3691 gui_internal_widget_append(wb, w);
3692 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3693 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3694 gui_internal_menu_render(this);
3698 * A container to hold the selected vehicle and the desired profile in
3701 struct vehicle_and_profilename {
3702 struct vehicle *vehicle;
3707 * Figures out whether the given vehicle is the active vehicle.
3709 * @return true if the vehicle is active, false otherwise.
3712 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3715 struct attr active_vehicle;
3717 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3718 active_vehicle.u.vehicle=NULL;
3720 return active_vehicle.u.vehicle == vehicle;
3724 save_vehicle_xml(struct vehicle *v)
3727 struct attr_iter *iter=vehicle_attr_iter_new();
3731 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3732 if (ATTR_IS_OBJECT(attr.type))
3735 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3739 printf("</vehicle>\n");
3742 vehicle_attr_iter_destroy(iter);
3747 * Reacts to a button press that changes a vehicle's active profile.
3749 * @see gui_internal_add_vehicle_profile
3752 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3753 widget *wm, void *data)
3755 struct vehicle_and_profilename *vapn = data;
3756 struct vehicle *v = vapn->vehicle;
3757 char *profilename = vapn->profilename;
3758 struct attr vehicle_name_attr;
3759 char *vehicle_name = NULL;
3761 // Get the vehicle name
3762 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3763 vehicle_name = vehicle_name_attr.u.str;
3765 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3768 // Change the profile name
3769 struct attr profilename_attr = {attr_profilename, {profilename}};
3770 if(!vehicle_set_attr(v, &profilename_attr)) {
3771 dbg(0, "Unable to set the vehicle's profile name\n");
3774 // Notify Navit that the routing should be re-done if this is the
3776 if (gui_internal_is_active_vehicle(this, v)) {
3777 struct attr vehicle;
3778 vehicle.type=attr_vehicle;
3779 vehicle.u.vehicle=v;
3780 navit_set_attr(this->nav, &vehicle);
3782 save_vehicle_xml(v);
3786 * Adds the vehicle profile to the GUI, allowing the user to pick a
3787 * profile for the currently selected vehicle.
3790 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3791 *parent, struct vehicle *v, struct vehicleprofile *profile)
3793 // Just here to show up in the translation file, nice and close to
3794 // where the translations are actually used.
3795 struct attr profile_attr;
3796 struct attr *attr = NULL;
3798 char *active_profile = NULL;
3801 struct vehicle_and_profilename *context = NULL;
3803 #ifdef ONLY_FOR_TRANSLATION
3804 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3807 // Figure out the profile name
3808 attr = attr_search(profile->attrs, NULL, attr_name);
3810 dbg(0, "Adding vehicle profile failed. attr==NULL");
3815 // Determine whether the profile is the active one
3816 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
3817 active_profile = profile_attr.u.str;
3818 active = active_profile != NULL && !strcmp(name, active_profile);
3820 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3821 active_profile, active);
3823 // Build a translatable label.
3825 label = g_strdup_printf(_("Current profile: %s"), _(name));
3827 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3830 // Create the context object (the vehicle and the desired profile)
3831 context = g_new0(struct vehicle_and_profilename, 1);
3832 context->vehicle = v;
3833 context->profilename = name;
3836 gui_internal_widget_append(parent,
3837 gui_internal_button_new_with_callback(
3839 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3840 gravity_left_center|orientation_horizontal|flags_fill,
3841 gui_internal_cmd_set_active_profile, context));
3847 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3849 struct widget *w,*wb;
3851 struct vehicle *v=wm->data;
3852 struct vehicleprofile *profile = NULL;
3854 wb=gui_internal_menu(this, wm->text);
3855 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3856 gui_internal_widget_append(wb, w);
3858 // Add the "Set as active" button if this isn't the active
3860 if (!gui_internal_is_active_vehicle(this, v)) {
3861 gui_internal_widget_append(w,
3862 gui_internal_button_new_with_callback(this, _("Set as active"),
3863 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3864 gui_internal_cmd_set_active_vehicle, wm->data));
3867 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3868 gui_internal_widget_append(w,
3869 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3870 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3871 gui_internal_cmd_show_satellite_status, wm->data));
3873 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3874 gui_internal_widget_append(w,
3875 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3876 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3877 gui_internal_cmd_show_nmea_data, wm->data));
3880 // Add all the possible vehicle profiles to the menu
3881 GList *profiles = navit_get_vehicleprofiles(this->nav);
3883 profile = (struct vehicleprofile *)profiles->data;
3884 gui_internal_add_vehicle_profile(this, w, v, profile);
3885 profiles = g_list_next(profiles);
3888 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3889 gui_internal_menu_render(this);
3893 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3895 struct attr attr,vattr;
3896 struct widget *w,*wb,*wl;
3897 struct attr_iter *iter;
3898 struct attr active_vehicle;
3901 wb=gui_internal_menu(this, _("Vehicle"));
3902 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3903 w->spy=this->spacing*3;
3904 gui_internal_widget_append(wb, w);
3905 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3906 active_vehicle.u.vehicle=NULL;
3907 iter=navit_attr_iter_new();
3908 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3909 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3910 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3911 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3912 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3913 wl->text=g_strdup(vattr.u.str);
3914 gui_internal_widget_append(w, wl);
3916 navit_attr_iter_destroy(iter);
3917 gui_internal_menu_render(this);
3922 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3924 struct widget *wb,*w;
3926 wb=gui_internal_menu(this, _("Rules"));
3927 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3928 w->spy=this->spacing*3;
3929 gui_internal_widget_append(wb, w);
3932 on.type=off.type=attr_tracking;
3933 gui_internal_widget_append(w,
3934 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3938 on.type=off.type=attr_orientation;
3939 gui_internal_widget_append(w,
3940 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3944 on.type=off.type=attr_follow_cursor;
3945 gui_internal_widget_append(w,
3946 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3948 gui_internal_menu_render(this);
3951 //##############################################################################################################
3954 //# Authors: Martin Schaller (04/2008)
3955 //##############################################################################################################
3956 static void gui_internal_motion(void *data, struct point *p)
3959 struct gui_priv *this=data;
3960 if (!this->root.children) {
3961 navit_handle_motion(this->nav, p);
3967 if(!this->motion_timeout_callback)
3968 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3969 if(!this->motion_timeout_event)
3970 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3974 find_attr(const char **names, const char **values, const char *name)
3977 if (!strcasecmp(*names, name))
3979 names+=xml_attr_distance;
3980 values+=xml_attr_distance;
3986 find_attr_dup(const char **names, const char **values, const char *name)
3988 return g_strdup(find_attr(names, values, name));
3992 gui_internal_evaluate(struct gui_priv *this, const char *command)
3995 command_evaluate(&this->self, command);
4000 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
4002 gui_internal_evaluate(this,w->command);
4006 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
4009 if (w->form == form && w->name) {
4010 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
4012 gui_set_attr(this->self.u.gui, attr);
4018 gui_internal_html_submit_set(this, w, form);
4025 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
4027 struct widget *menu;
4030 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
4031 l=g_list_last(this->root.children);
4033 graphics_draw_mode(this->gra, draw_mode_begin);
4034 gui_internal_highlight_do(this, NULL);
4035 gui_internal_menu_render(this);
4036 graphics_draw_mode(this->gra, draw_mode_end);
4037 gui_internal_html_submit_set(this, menu, w->form);
4038 gui_internal_evaluate(this,w->form->onsubmit);
4042 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
4045 gui_internal_prune_menu_count(this, 1, 0);
4046 if (href && href[0] == '#') {
4047 dbg(1,"href=%s\n",href);
4048 gui_internal_html_menu(this, this->html_text, href+1);
4053 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
4055 gui_internal_html_load_href(this, w->command, 0);
4058 struct div_flags_map {
4062 } div_flags_map[] = {
4063 {"gravity","none",gravity_none},
4064 {"gravity","left",gravity_left},
4065 {"gravity","xcenter",gravity_xcenter},
4066 {"gravity","right",gravity_right},
4067 {"gravity","top",gravity_top},
4068 {"gravity","ycenter",gravity_ycenter},
4069 {"gravity","bottom",gravity_bottom},
4070 {"gravity","left_top",gravity_left_top},
4071 {"gravity","top_center",gravity_top_center},
4072 {"gravity","right_top",gravity_right_top},
4073 {"gravity","left_center",gravity_left_center},
4074 {"gravity","center",gravity_center},
4075 {"gravity","right_center",gravity_right_center},
4076 {"gravity","left_bottom",gravity_left_bottom},
4077 {"gravity","bottom_center",gravity_bottom_center},
4078 {"gravity","right_bottom",gravity_right_bottom},
4079 {"expand","1",flags_expand},
4080 {"fill","1",flags_fill},
4081 {"orientation","horizontal",orientation_horizontal},
4082 {"orientation","vertical",orientation_vertical},
4083 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
4087 div_flag(const char **names, const char **values, char *name)
4091 const char *value=find_attr(names, values, name);
4094 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
4095 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
4096 ret|=div_flags_map[i].flags;
4102 div_flags(const char **names, const char **values)
4105 flags = div_flag(names, values, "gravity");
4106 flags |= div_flag(names, values, "orientation");
4107 flags |= div_flag(names, values, "expand");
4108 flags |= div_flag(names, values, "fill");
4112 static struct widget *
4113 html_image(struct gui_priv *this, const char **names, const char **values)
4115 const char *src, *size;
4116 struct graphics_image *img=NULL;
4118 src=find_attr(names, values, "src");
4121 size=find_attr(names, values, "size");
4124 if (!strcmp(size,"l"))
4125 img=image_new_l(this, src);
4126 else if (!strcmp(size,"s"))
4127 img=image_new_s(this, src);
4128 else if (!strcmp(size,"xs"))
4129 img=image_new_xs(this, src);
4132 return gui_internal_image_new(this, img);
4136 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
4138 struct gui_priv *this=data;
4140 enum html_tag tag=html_tag_none;
4141 struct html *html=&this->html[this->html_depth];
4142 const char *cond, *type;
4144 if (!strcasecmp(tag_name,"text"))
4150 cond=find_attr(names, values, "cond");
4152 if (cond && !this->html_skip) {
4153 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
4157 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
4158 if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
4159 tag=html_tag_map[i].tag;
4164 if (!this->html_skip && !html->skip) {
4167 html->name=find_attr_dup(names, values, "name");
4169 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
4171 this->html_anchor_found=1;
4173 html->href=find_attr_dup(names, values, "href");
4176 html->command=find_attr_dup(names, values, "onclick");
4177 html->w=html_image(this, names, values);
4180 this->form=g_new0(struct form, 1);
4181 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
4183 case html_tag_input:
4184 type=find_attr_dup(names, values, "type");
4187 if (!strcmp(type,"image")) {
4188 html->w=html_image(this, names, values);
4190 html->w->state|=STATE_SENSITIVE;
4191 html->w->func=gui_internal_html_submit;
4194 if (!strcmp(type,"text") || !strcmp(type,"password")) {
4195 html->w=gui_internal_label_new(this, NULL);
4196 html->w->background=this->background;
4197 html->w->flags |= div_flags(names, values);
4198 html->w->state|=STATE_EDITABLE;
4199 if (!this->editable) {
4200 this->editable=html->w;
4201 html->w->state|=STATE_EDIT;
4203 this->keyboard_required=1;
4204 if (!strcmp(type,"password"))
4205 html->w->flags2 |= 1;
4208 html->w->form=this->form;
4209 html->w->name=find_attr_dup(names, values, "name");
4213 html->w=gui_internal_box_new(this, div_flags(names, values));
4214 html->container=this->html_container;
4215 this->html_container=html->w;
4221 this->html_skip+=html->skip;
4226 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
4228 struct gui_priv *this=data;
4230 struct html *parent=NULL;
4232 if (!strcasecmp(tag_name,"text"))
4235 html=&this->html[this->html_depth];
4236 if (this->html_depth > 0)
4237 parent=&this->html[this->html_depth-1];
4240 if (!this->html_skip) {
4241 if (html->command && html->w) {
4242 html->w->state |= STATE_SENSITIVE;
4243 html->w->command=html->command;
4244 html->w->func=gui_internal_html_command;
4247 if (parent && parent->href && html->w) {
4248 html->w->state |= STATE_SENSITIVE;
4249 html->w->command=g_strdup(parent->href);
4250 html->w->func=gui_internal_html_href;
4252 switch (html->tag) {
4254 this->html_container=html->container;
4256 case html_tag_input:
4257 gui_internal_widget_append(this->html_container, html->w);
4266 this->html_skip-=html->skip;
4267 g_free(html->command);
4273 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
4275 struct gui_priv *this=data;
4277 int depth=this->html_depth-1;
4278 struct html *html=&this->html[depth];
4279 char *text_stripped;
4281 if (this->html_skip)
4283 while (isspace(text[0])) {
4287 while (len > 0 && isspace(text[len-1]))
4289 text_stripped=g_malloc(len+1);
4290 strncpy(text_stripped, text, len);
4291 text_stripped[len]='\0';
4292 if (html->tag == html_tag_html && depth > 2) {
4293 if (this->html[depth-1].tag == html_tag_script) {
4294 html=&this->html[depth-2];
4297 switch (html->tag) {
4299 if (html->name && len) {
4300 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
4301 gui_internal_widget_append(gui_internal_menu(this, gettext(text_stripped)), this->html_container);
4302 this->html_container->spx=this->spacing*10;
4306 if (!this->html_container) {
4307 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
4308 gui_internal_widget_append(gui_internal_menu(this, gettext(text_stripped)), this->html_container);
4309 this->html_container->spx=this->spacing*10;
4314 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
4315 gui_internal_widget_append(w, html->w);
4316 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
4322 gui_internal_widget_append(html->w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
4325 case html_tag_script:
4326 dbg(1,"execute %s\n",text_stripped);
4327 gui_internal_evaluate(this,text_stripped);
4335 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
4337 char *doc=g_strdup(document);
4338 graphics_draw_mode(this->gra, draw_mode_begin);
4339 this->html_container=NULL;
4341 this->html_anchor=anchor;
4342 this->html_anchor_found=0;
4344 this->keyboard_required=0;
4345 this->editable=NULL;
4346 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
4347 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4349 if (this->keyboard_required && this->keyboard) {
4350 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
4351 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
4353 gui_internal_menu_render(this);
4354 graphics_draw_mode(this->gra, draw_mode_end);
4359 gui_internal_enter(struct gui_priv *this, int ignore)
4361 struct graphics *gra=this->gra;
4362 this->ignore_button=ignore;
4363 this->clickp_valid=this->vehicle_valid=0;
4365 navit_block(this->nav, 1);
4366 graphics_overlay_disable(gra, 1);
4369 this->root.background=this->background;
4373 gui_internal_leave(struct gui_priv *this)
4375 graphics_draw_mode(this->gra, draw_mode_end);
4379 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore, char *href)
4381 struct transformation *trans;
4384 struct attr attr,attrp;
4387 gui_internal_enter(this, ignore);
4388 trans=navit_get_trans(this->nav);
4389 attr_free(this->click_coord_geo);
4390 this->click_coord_geo=NULL;
4391 attr_free(this->position_coord_geo);
4392 this->position_coord_geo=NULL;
4394 transform_reverse(trans, p, &c);
4395 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
4396 this->clickp.pro=transform_get_projection(trans);
4399 transform_to_geo(this->clickp.pro, &c, &g);
4400 attr.u.coord_geo=&g;
4401 attr.type=attr_click_coord_geo;
4402 this->click_coord_geo=attr_dup(&attr);
4404 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
4405 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
4406 this->position_coord_geo=attr_dup(&attrp);
4407 this->vehiclep.pro=transform_get_projection(trans);
4408 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
4409 this->vehiclep.x=c.x;
4410 this->vehiclep.y=c.y;
4411 this->vehicle_valid=1;
4414 gui_internal_html_load_href(this, href?href:"#Main Menu", 0);
4418 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4422 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
4424 if (in[1] && ATTR_IS_INT(in[1]->type))
4425 replace=in[1]->u.num;
4427 if (this->root.children) {
4430 gui_internal_html_load_href(this, href, replace);
4433 gui_internal_cmd_menu(this, NULL, 0, href);
4438 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
4440 if (widget->text && strlen(widget->text))
4441 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
4442 g_free(widget->text);
4444 gui_internal_prune_menu(this, NULL);
4445 gui_internal_check_exit(this);
4449 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
4451 gui_internal_cmd_log_do(this, widget->data);
4455 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
4459 len=strlen(wm->text);
4460 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
4461 wm->text[len-1]='\0';
4462 gui_internal_cmd_log_do(this, wm);
4469 gui_internal_cmd_log(struct gui_priv *this)
4471 struct widget *w,*wb,*wk,*wl,*we,*wnext;
4472 gui_internal_enter(this, 1);
4473 wb=gui_internal_menu(this, "Log Message");
4474 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4475 gui_internal_widget_append(wb, w);
4476 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4477 gui_internal_widget_append(w, we);
4478 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
4479 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
4480 wk->background=this->background;
4481 wk->flags |= flags_expand|flags_fill;
4482 wk->func = gui_internal_cmd_log_changed;
4483 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
4484 wnext->state |= STATE_SENSITIVE;
4485 wnext->func = gui_internal_cmd_log_clicked;
4487 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4488 gui_internal_widget_append(w, wl);
4490 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
4491 gui_internal_menu_render(this);
4492 gui_internal_leave(this);
4496 gui_internal_check_exit(struct gui_priv *this)
4498 struct graphics *gra=this->gra;
4499 if (! this->root.children) {
4500 gui_internal_search_idle_end(this);
4501 gui_internal_search_list_destroy(this);
4502 graphics_overlay_disable(gra, 0);
4503 if (!navit_block(this->nav, 0)) {
4505 navit_draw(this->nav);
4507 navit_draw_displaylist(this->nav);
4513 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
4517 attr->u.num=this->root.children != NULL;
4519 case attr_click_coord_geo:
4520 if (!this->click_coord_geo)
4522 *attr=*this->click_coord_geo;
4524 case attr_position_coord_geo:
4525 if (!this->position_coord_geo)
4527 *attr=*this->position_coord_geo;
4530 attr->u.num=this->pitch;
4540 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
4542 switch (attr->type) {
4544 g_free(this->html_text);
4545 this->html_text=g_strdup(attr->u.str);
4553 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
4555 switch (attr->type) {
4556 case attr_fullscreen:
4557 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
4558 graphics_draw_mode(this->gra, draw_mode_end);
4559 this->win->fullscreen(this->win, attr->u.num > 0);
4560 graphics_draw_mode(this->gra, draw_mode_begin);
4562 this->fullscreen=attr->u.num;
4565 dbg(0,"%s\n",attr_to_name(attr->type));
4570 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
4572 struct displaylist_handle *dlh;
4573 struct displaylist *display;
4574 struct displayitem *di;
4575 struct attr cb,**attr_list=NULL;
4578 display=navit_get_displaylist(this->nav);
4579 dlh=graphics_displaylist_open(display);
4580 while ((di=graphics_displaylist_next(dlh))) {
4581 struct item *item=graphics_displayitem_get_item(di);
4582 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
4583 graphics_displayitem_within_dist(display, di, p, this->radius)) {
4584 struct map_rect *mr=map_rect_new(item->map, NULL);
4585 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
4587 if (item_attr_get(itemo, attr_data, &attr))
4588 attr_list=attr_generic_add_attr(attr_list, &attr);
4589 map_rect_destroy(mr);
4592 graphics_displaylist_close(dlh);
4593 if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
4594 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
4595 attr_list_free(attr_list);
4599 //##############################################################################################################
4600 //# Description: Function to handle mouse clicks and scroll wheel movement
4602 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
4603 //##############################################################################################################
4604 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
4606 struct gui_priv *this=data;
4607 struct graphics *gra=this->gra;
4609 dbg(1,"enter %d %d\n", pressed, button);
4610 // if still on the map (not in the menu, yet):
4611 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
4612 if (!this->root.children || this->ignore_button) {
4614 this->ignore_button=0;
4615 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
4616 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
4617 dbg(1,"navit has handled button\n");
4620 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
4623 if (this->menu_on_map_click) {
4624 gui_internal_cmd_menu(this, p, 0, NULL);
4627 if (this->signal_on_map_click) {
4628 gui_internal_dbus_signal(this, p);
4635 // if already in the menu:
4639 gui_internal_highlight(this);
4644 graphics_draw_mode(gra, draw_mode_begin);
4645 gui_internal_call_highlighted(this);
4646 if (!event_main_loop_has_quit()) {
4647 gui_internal_highlight(this);
4648 graphics_draw_mode(gra, draw_mode_end);
4649 gui_internal_check_exit(this);
4655 gui_internal_setup_gc(struct gui_priv *this)
4657 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
4658 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
4659 struct graphics *gra=this->gra;
4661 if (this->background)
4663 this->background=graphics_gc_new(gra);
4664 this->background2=graphics_gc_new(gra);
4665 this->highlight_background=graphics_gc_new(gra);
4666 graphics_gc_set_foreground(this->highlight_background, &cbh);
4667 this->foreground=graphics_gc_new(gra);
4668 graphics_gc_set_foreground(this->foreground, &cf);
4669 this->text_background=graphics_gc_new(gra);
4670 this->text_foreground=graphics_gc_new(gra);
4671 graphics_gc_set_foreground(this->background, &this->background_color);
4672 graphics_gc_set_foreground(this->background2, &this->background2_color);
4673 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
4674 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
4677 //##############################################################################################################
4680 //# Authors: Martin Schaller (04/2008)
4681 //##############################################################################################################
4682 static void gui_internal_resize(void *data, int w, int h)
4684 struct gui_priv *this=data;
4687 gui_internal_setup_gc(this);
4689 if (this->root.w != w || this->root.h != h) {
4694 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
4695 navit_handle_resize(this->nav, w, h);
4696 if (this->root.children) {
4698 gui_internal_prune_menu(this, NULL);
4699 gui_internal_html_load_href(this, "#Main Menu", 0);
4701 gui_internal_menu_render(this);
4707 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
4722 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
4724 GList *l=wi->children;
4725 if (wi->state & STATE_SENSITIVE) {
4728 gui_internal_keynav_point(wi, -dx, -dy, &wp);
4730 dist1=(wp.x-p->x)*dx;
4733 dist1=(wp.y-p->y)*dy;
4741 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);
4747 if (dist1 < *distance) {
4754 struct widget *child=l->data;
4755 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
4761 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
4763 struct widget *result,*menu=g_list_last(this->root.children)->data;
4766 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4767 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
4773 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
4775 gui_internal_keynav_point(result, dx, dy, &p);
4776 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
4781 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4782 dbg(1,"result=%p\n", result);
4794 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4795 dbg(1,"wraparound result=%p\n", result);
4797 gui_internal_highlight_do(this, result);
4799 gui_internal_say(this, result, 1);
4802 //##############################################################################################################
4805 //# Authors: Martin Schaller (04/2008)
4806 //##############################################################################################################
4807 static void gui_internal_keypress(void *data, char *key)
4809 struct gui_priv *this=data;
4812 if (!this->root.children) {
4813 transform_get_size(navit_get_trans(this->nav), &w, &h);
4818 navit_set_center_screen(this->nav, &p, 1);
4820 case NAVIT_KEY_DOWN:
4823 navit_set_center_screen(this->nav, &p, 1);
4825 case NAVIT_KEY_LEFT:
4828 navit_set_center_screen(this->nav, &p, 1);
4830 case NAVIT_KEY_RIGHT:
4833 navit_set_center_screen(this->nav, &p, 1);
4835 case NAVIT_KEY_ZOOM_IN:
4836 navit_zoom_in(this->nav, 2, NULL);
4838 case NAVIT_KEY_ZOOM_OUT:
4839 navit_zoom_out(this->nav, 2, NULL);
4841 case NAVIT_KEY_RETURN:
4842 case NAVIT_KEY_MENU:
4843 gui_internal_cmd_menu(this, NULL, 0, NULL);
4848 graphics_draw_mode(this->gra, draw_mode_begin);
4850 case NAVIT_KEY_LEFT:
4851 gui_internal_keynav_highlight_next(this,-1,0);
4853 case NAVIT_KEY_RIGHT:
4854 gui_internal_keynav_highlight_next(this,1,0);
4857 gui_internal_keynav_highlight_next(this,0,-1);
4859 case NAVIT_KEY_DOWN:
4860 gui_internal_keynav_highlight_next(this,0,1);
4862 case NAVIT_KEY_BACK:
4864 case NAVIT_KEY_RETURN:
4865 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4866 gui_internal_call_highlighted(this);
4868 gui_internal_keypress_do(this, key);
4871 gui_internal_keypress_do(this, key);
4873 if (!event_main_loop_has_quit()) {
4874 graphics_draw_mode(this->gra, draw_mode_end);
4875 gui_internal_check_exit(this);
4880 //##############################################################################################################
4883 //# Authors: Martin Schaller (04/2008)
4884 //##############################################################################################################
4885 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4888 struct transformation *trans=navit_get_trans(this->nav);
4890 win=graphics_get_data(gra, "window");
4893 navit_ignore_graphics_events(this->nav, 1);
4896 navit_ignore_graphics_events(this->nav, 1);
4897 transform_get_size(trans, &this->root.w, &this->root.h);
4898 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4899 graphics_add_callback(gra, this->resize_cb);
4900 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4901 graphics_add_callback(gra, this->button_cb);
4902 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4903 graphics_add_callback(gra, this->motion_cb);
4904 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4905 graphics_add_callback(gra, this->keypress_cb);
4906 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
4907 graphics_add_callback(gra, this->window_closed_cb);
4909 // set fullscreen if needed
4910 if (this->fullscreen)
4911 this->win->fullscreen(this->win, this->fullscreen != 0);
4912 /* Was resize callback already issued? */
4913 if (navit_get_ready(this->nav) & 2)
4914 gui_internal_setup_gc(this);
4918 static void gui_internal_disable_suspend(struct gui_priv *this)
4920 if (this->win->disable_suspend)
4921 this->win->disable_suspend(this->win);
4924 //##############################################################################################################
4927 //# Authors: Martin Schaller (04/2008)
4928 //##############################################################################################################
4929 struct gui_methods gui_internal_methods = {
4932 gui_internal_set_graphics,
4936 gui_internal_disable_suspend,
4937 gui_internal_get_attr,
4938 gui_internal_add_attr,
4939 gui_internal_set_attr,
4943 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4945 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4947 *out=attr_generic_add_attr(*out, &private_data);
4951 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4953 callback_list_add(priv->cbl, cb);
4957 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4959 callback_list_remove(priv->cbl, cb);
4963 static struct gui_internal_methods gui_internal_methods_ext = {
4964 gui_internal_add_callback,
4965 gui_internal_remove_callback,
4966 gui_internal_menu_render,
4973 gui_internal_get_flags(struct widget *widget)
4975 return widget->flags;
4979 gui_internal_set_flags(struct widget *widget, enum flags flags)
4981 widget->flags=flags;
4985 gui_internal_get_state(struct widget *widget)
4987 return widget->state;
4991 gui_internal_set_state(struct widget *widget, int state)
4993 widget->state=state;
4997 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
5003 gui_internal_set_data(struct widget *widget, void *data)
5009 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
5011 widget->background=this->background;
5014 static struct gui_internal_widget_methods gui_internal_widget_methods = {
5015 gui_internal_widget_append,
5016 gui_internal_button_new,
5017 gui_internal_button_new_with_callback,
5018 gui_internal_box_new,
5019 gui_internal_label_new,
5020 gui_internal_image_new,
5021 gui_internal_keyboard,
5023 gui_internal_get_flags,
5024 gui_internal_set_flags,
5025 gui_internal_get_state,
5026 gui_internal_set_state,
5027 gui_internal_set_func,
5028 gui_internal_set_data,
5029 gui_internal_set_default_background,
5033 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
5035 char *str=NULL,*str2=NULL;
5036 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
5039 dbg(1,"%s\n",attr_to_name(in[0]->type));
5040 if (ATTR_IS_STRING(in[0]->type)) {
5043 if (ATTR_IS_COORD_GEO(in[0]->type)) {
5044 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
5047 str=g_strdup_printf("<html>%s</html>\n",str);
5048 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
5056 * @brief Creates a new table widget.
5058 * Creates and returns a new table widget. This function will
5059 * setup next/previous buttons as children.
5061 * @param this The graphics context.
5062 * @param flags widget sizing flags.
5063 * @returns The newly created widget
5065 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
5067 struct widget * widget = g_new0(struct widget,1);
5068 struct table_data * data = NULL;
5069 widget->type=widget_table;
5070 widget->flags=flags;
5071 widget->data = g_new0(struct table_data,1);
5072 widget->data_free=gui_internal_table_data_free;
5073 data = (struct table_data*)widget->data;
5077 data->next_button = gui_internal_button_new_with_callback
5078 (this,"Next",image_new_xs(this, "gui_active") ,
5079 gravity_left_center |orientation_vertical,
5080 gui_internal_table_button_next,NULL);
5081 data->next_button->data=widget;
5084 data->prev_button = gui_internal_button_new_with_callback
5086 image_new_xs(this, "gui_active")
5087 ,gravity_right_center |orientation_vertical,
5088 gui_internal_table_button_prev,NULL);
5090 data->prev_button->data=widget;
5094 data->button_box=gui_internal_box_new(this,
5095 gravity_center|orientation_horizontal);
5096 data->button_box->children=g_list_append(data->button_box->children,
5098 data->button_box->children=g_list_append(data->button_box->children,
5100 //data->button_box->background=this->background2;
5101 data->button_box->bl=this->spacing;
5102 widget->children=g_list_append(widget->children,data->button_box);
5103 gui_internal_widget_pack(this,data->button_box);
5111 * @brief Clears all the rows from the table.
5112 * This function removes all rows from a table.
5113 * New rows can later be added to the table.
5115 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
5118 struct table_data * table_data = (struct table_data* ) table->data;
5120 iter = table->children;
5122 if(iter->data != table_data->button_box) {
5123 struct widget * child = (struct widget*)iter->data;
5124 gui_internal_widget_destroy(this,child);
5125 if(table->children == iter) {
5126 table->children = g_list_remove(iter,iter->data);
5127 iter=table->children;
5130 iter = g_list_remove(iter,iter->data);
5133 iter = g_list_next(iter);
5137 table_data->top_row=NULL;
5138 table_data->bottom_row=NULL;
5139 if(table_data->page_headers)
5140 g_list_free(table_data->page_headers);
5141 table_data->page_headers=NULL;
5146 * Creates a new table_row widget.
5147 * @param this The graphics context
5148 * @param flags Sizing flags for the row
5149 * @returns The new table_row widget.
5151 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
5153 struct widget * widget = g_new0(struct widget,1);
5154 widget->type=widget_table_row;
5155 widget->flags=flags;
5162 * @brief Computes the column dimensions for the table.
5164 * @param w The table widget to compute dimensions for.
5166 * This function examines all of the rows and columns for the table w
5167 * and returns a list (GList) of table_column_desc elements that
5168 * describe each column of the table.
5170 * The caller is responsible for freeing the returned list.
5172 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
5175 GList * column_desc = NULL;
5176 GList * current_desc=NULL;
5177 GList * cur_row = w->children;
5178 struct widget * cur_row_widget=NULL;
5179 GList * cur_column=NULL;
5180 struct widget * cell_w=NULL;
5181 struct table_column_desc * current_cell=NULL;
5182 struct table_data * table_data=NULL;
5189 * Scroll through the the table and
5190 * 1. Compute the maximum width + height of each column across all rows.
5192 table_data = (struct table_data*) w->data;
5193 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
5195 cur_row_widget = (struct widget*) cur_row->data;
5196 current_desc = column_desc;
5197 if(cur_row_widget == table_data->button_box)
5202 for(cur_column = cur_row_widget->children; cur_column;
5203 cur_column=g_list_next(cur_column))
5205 cell_w = (struct widget*) cur_column->data;
5206 gui_internal_widget_pack(this,cell_w);
5207 if(current_desc == 0)
5209 current_cell = g_new0(struct table_column_desc,1);
5210 column_desc = g_list_append(column_desc,current_cell);
5211 current_desc = g_list_last(column_desc);
5212 current_cell->height=cell_w->h;
5213 current_cell->width=cell_w->w;
5214 total_width+=cell_w->w;
5219 current_cell = current_desc->data;
5222 if(current_cell->height < height )
5224 current_cell->height = height;
5226 if(current_cell->width < width)
5228 total_width += (width-current_cell->width);
5229 current_cell->width = width;
5234 current_desc = g_list_next(current_desc);
5244 * If the width of all columns is less than the width off
5245 * the table expand each cell proportionally.
5248 if(total_width+(this->spacing*column_count) < w->w ) {
5249 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
5250 current_cell = (struct table_column_desc*) current_desc->data;
5251 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
5260 * @brief Computes the height and width for the table.
5262 * The height and widht are computed to display all cells in the table
5263 * at the requested height/width.
5265 * @param this The graphics context
5266 * @param w The widget to pack.
5269 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
5275 GList * column_data = gui_internal_compute_table_dimensions(this,w);
5277 struct table_column_desc * cell_desc=0;
5278 struct table_data * table_data = (struct table_data*)w->data;
5280 for(current = column_data; current; current=g_list_next(current))
5282 if(table_data->button_box == current->data )
5286 cell_desc = (struct table_column_desc *) current->data;
5287 width = width + cell_desc->width + this->spacing;
5288 if(height < cell_desc->height)
5290 height = cell_desc->height ;
5296 for(current=w->children; current; current=g_list_next(current))
5298 if(current->data!= table_data->button_box)
5303 if (table_data->button_box)
5304 gui_internal_widget_pack(this,table_data->button_box);
5308 if(w->h + w->c.y > this->root.h )
5311 * Do not allow the widget to exceed the screen.
5314 w->h = this->root.h- w->c.y - height;
5319 * Deallocate column descriptions.
5321 current = column_data;
5322 while( (current = g_list_last(current)) )
5324 current = g_list_remove(current,current->data);
5332 * @brief Renders a table widget.
5334 * @param this The graphics context
5335 * @param w The table widget to render.
5337 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
5342 GList * column_desc=NULL;
5343 GList * cur_row = NULL;
5344 GList * current_desc=NULL;
5345 struct table_data * table_data = (struct table_data*)w->data;
5347 int is_first_page=1;
5348 struct table_column_desc * dim=NULL;
5350 dbg_assert(table_data);
5351 column_desc = gui_internal_compute_table_dimensions(this,w);
5355 * Skip rows that are on previous pages.
5357 cur_row = w->children;
5358 if(table_data->top_row && table_data->top_row != w->children )
5360 cur_row = table_data->top_row;
5366 * Loop through each row. Drawing each cell with the proper sizes,
5367 * at the proper positions.
5369 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
5371 GList * cur_column=NULL;
5372 current_desc = column_desc;
5373 struct widget * cur_row_widget = (struct widget*)cur_row->data;
5375 x =w->p.x+this->spacing;
5376 if(cur_row_widget == table_data->button_box )
5380 dim = (struct table_column_desc*)current_desc->data;
5382 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
5385 * No more drawing space left.
5391 for(cur_column = cur_row_widget->children; cur_column;
5392 cur_column=g_list_next(cur_column))
5394 struct widget * cur_widget = (struct widget*) cur_column->data;
5395 dim = (struct table_column_desc*)current_desc->data;
5398 cur_widget->w=dim->width;
5400 cur_widget->h=dim->height;
5402 max_height = dim->height;
5403 /* We pack the widget before rendering to ensure that the x and y
5404 * coordinates get pushed down.
5406 gui_internal_widget_pack(this,cur_widget);
5407 gui_internal_widget_render(this,cur_widget);
5409 if(dim->height > max_height)
5411 max_height = dim->height;
5415 table_data->bottom_row=cur_row;
5416 current_desc = g_list_next(current_desc);
5418 if(table_data->button_box && (is_skipped || !is_first_page) )
5420 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
5422 if(table_data->button_box->p.y < y )
5424 table_data->button_box->p.y=y;
5426 table_data->button_box->p.x = w->p.x;
5427 table_data->button_box->w = w->w;
5428 // table_data->button_box->h = w->h - y;
5429 // table_data->next_button->h=table_data->button_box->h;
5430 // table_data->prev_button->h=table_data->button_box->h;
5431 // table_data->next_button->c.y=table_data->button_box->c.y;
5432 // table_data->prev_button->c.y=table_data->button_box->c.y;
5434 gui_internal_widget_pack(this,table_data->button_box);
5435 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
5438 table_data->button_box->p.y = w->p.y + w->h -
5439 table_data->button_box->h;
5443 table_data->next_button->state|= STATE_SENSITIVE;
5447 table_data->next_button->state&= ~STATE_SENSITIVE;
5450 if(table_data->top_row != w->children)
5452 table_data->prev_button->state|= STATE_SENSITIVE;
5456 table_data->prev_button->state&= ~STATE_SENSITIVE;
5458 gui_internal_widget_render(this,table_data->button_box);
5464 * Deallocate column descriptions.
5466 current_desc = column_desc;
5467 while( (current_desc = g_list_last(current_desc)) )
5469 current_desc = g_list_remove(current_desc,current_desc->data);
5475 * @brief Displays Route information
5477 * @li The name of the active vehicle
5478 * @param wm The button that was pressed.
5482 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5486 struct widget * menu;
5487 struct widget * row;
5490 if(! this->vehicle_cb)
5493 * Register the callback on vehicle updates.
5495 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
5496 attr_position_coord_geo,this);
5497 navit_add_callback(this->nav,this->vehicle_cb);
5500 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
5501 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
5503 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
5506 menu=gui_internal_menu(this,_("Route Description"));
5508 menu->free=gui_internal_route_screen_free;
5509 this->route_data.route_showing=1;
5510 this->route_data.route_table->spx = this->spacing;
5513 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
5515 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
5516 gui_internal_widget_append(box,this->route_data.route_table);
5518 box->spx = this->spacing;
5519 this->route_data.route_table->w=box->w;
5520 gui_internal_widget_append(menu,box);
5521 gui_internal_populate_route_table(this,this->nav);
5522 gui_internal_menu_render(this);
5527 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
5530 int adx=a2->x-a1->x;
5531 int ady=a2->y-a1->y;
5532 int bdx=b2->x-b1->x;
5533 int bdy=b2->y-b1->y;
5534 n = bdy * adx - bdx * ady;
5535 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
5536 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
5547 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
5548 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
5549 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
5552 res->x = a1->x + a * adx / n;
5553 res->y = a1->y + a * ady / n;
5558 struct heightline *next;
5560 struct coord_rect bbox;
5565 struct diagram_point {
5566 struct diagram_point *next;
5570 static struct heightline *
5571 item_get_heightline(struct item *item)
5573 struct heightline *ret=NULL;
5574 struct street_data *sd;
5578 if (item_attr_get(item, attr_label, &attr)) {
5579 height=atoi(attr.u.str);
5580 sd=street_get_data(item);
5581 if (sd && sd->count > 1) {
5582 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
5583 ret->bbox.lu=sd->c[0];
5584 ret->bbox.rl=sd->c[0];
5585 ret->count=sd->count;
5587 for (i = 0 ; i < sd->count ; i++) {
5589 coord_rect_extend(&ret->bbox, sd->c+i);
5592 street_data_free(sd);
5599 * @brief Displays Route Height Profile
5601 * @li The name of the active vehicle
5602 * @param wm The button that was pressed.
5606 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5610 struct widget * menu, *box;
5612 struct map * map=NULL;
5613 struct map_rect * mr=NULL;
5614 struct route * route;
5615 struct item * item =NULL;
5617 struct mapset_handle *msh;
5618 int x,i,first=1,dist=0;
5619 struct coord c,last,res;
5620 struct coord_rect rbbox,dbbox;
5621 struct map_selection sel;
5622 struct heightline *heightline,*heightlines=NULL;
5623 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
5626 sel.range.min=type_height_line_1;
5627 sel.range.max=type_height_line_3;
5630 menu=gui_internal_menu(this,_("Height Profile"));
5631 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
5632 gui_internal_widget_append(menu, box);
5633 route = navit_get_route(this->nav);
5635 map = route_get_map(route);
5637 mr = map_rect_new(map,NULL);
5639 while((item = map_rect_get_item(mr))) {
5640 while (item_coord_get(item, &c, 1)) {
5646 coord_rect_extend(&sel.u.c_rect, &c);
5649 map_rect_destroy(mr);
5650 ms=navit_get_mapset(this->nav);
5652 msh=mapset_open(ms);
5653 while ((map=mapset_next(msh, 1))) {
5654 mr=map_rect_new(map, &sel);
5656 while((item = map_rect_get_item(mr))) {
5657 if (item->type >= sel.range.min && item->type <= sel.range.max) {
5658 heightline=item_get_heightline(item);
5660 heightline->next=heightlines;
5661 heightlines=heightline;
5665 map_rect_destroy(mr);
5674 map = route_get_map(route);
5676 mr = map_rect_new(map,NULL);
5677 if(mr && heightlines) {
5678 while((item = map_rect_get_item(mr))) {
5680 while (item_coord_get(item, &c, 1)) {
5684 heightline=heightlines;
5687 coord_rect_extend(&rbbox, &c);
5688 while (heightline) {
5689 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
5690 for (i = 0 ; i < heightline->count - 1; i++) {
5691 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
5692 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
5693 diagram_point=g_new(struct diagram_point, 1);
5694 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
5695 diagram_point->c.y=heightline->height;
5696 diagram_point->next=diagram_points;
5697 diagram_points=diagram_point;
5698 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
5703 heightline=heightline->next;
5705 dist+=transform_distance(projection_mg, &last, &c);
5711 map_rect_destroy(mr);
5715 gui_internal_menu_render(this);
5717 diagram_point=diagram_points;
5718 while (diagram_point) {
5720 dbbox.lu=diagram_point->c;
5721 dbbox.rl=diagram_point->c;
5724 coord_rect_extend(&dbbox, &diagram_point->c);
5725 diagram_point=diagram_point->next;
5727 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
5728 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
5730 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
5732 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
5738 diagram_point=diagram_points;
5739 while (diagram_point) {
5740 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
5742 diagram_point=diagram_point->next;
5746 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
5747 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
5748 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
5749 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
5753 graphics_draw_lines(this->gra, this->foreground, p, 2);
5762 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5764 struct widget *menu,*wb,*w;
5767 graphics_draw_mode(this->gra, draw_mode_begin);
5768 menu=gui_internal_menu(this, _("Show Locale"));
5769 menu->spx=this->spacing*10;
5770 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5771 gui_internal_widget_append(menu, wb);
5772 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5773 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5774 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5776 #ifdef HAVE_API_WIN32_BASE
5778 wchar_t wcountry[32],wlang[32];
5779 char country[32],lang[32];
5781 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5782 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5783 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5784 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5785 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5787 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5788 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5789 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5790 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5791 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5796 gui_internal_menu_render(this);
5797 graphics_draw_mode(this->gra, draw_mode_end);
5801 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5803 struct widget *menu,*wb,*w;
5806 graphics_draw_mode(this->gra, draw_mode_begin);
5807 menu=gui_internal_menu(this, _("About Navit"));
5808 menu->spx=this->spacing*10;
5809 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
5810 gui_internal_widget_append(menu, wb);
5813 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
5814 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
5817 text=g_strdup_printf("%s",PACKAGE_NAME);
5818 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5819 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
5823 text=g_strdup_printf("%s",version);
5824 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5825 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
5829 text=g_strdup_printf("http://www.navit-project.org/");
5830 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5831 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
5835 text=g_strdup_printf("%s:",_("By"));
5836 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5837 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5839 text=g_strdup_printf("Martin Schaller");
5840 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5841 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5843 text=g_strdup_printf("Michael Farmbauer");
5844 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5845 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5847 text=g_strdup_printf("Alexander Atanasov");
5848 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5849 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5851 text=g_strdup_printf("Pierre Grandin");
5852 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5853 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5857 text=g_strdup_printf("%s",_("And all the Navit Team"));
5858 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5859 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5861 text=g_strdup_printf("%s",_("members and contributors."));
5862 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5863 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5866 gui_internal_menu_render(this);
5867 graphics_draw_mode(this->gra, draw_mode_end);
5872 * @brief handles the 'next page' table event.
5873 * A callback function that is invoked when the 'next page' button is pressed
5874 * to advance the contents of a table widget.
5876 * @param this The graphics context.
5877 * @param wm The button widget that was pressed.
5879 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5881 struct widget * table_widget = (struct widget * ) wm->data;
5882 struct table_data * table_data = NULL;
5888 table_data = (struct table_data*) table_widget->data;
5894 * Before advancing to the next page we need to ensure
5895 * that the current top_row is in the list of previous top_rows
5896 * so previous page can work.
5899 for(iterator=table_data->page_headers; iterator != NULL;
5900 iterator = g_list_next(iterator) )
5902 if(iterator->data == table_data->top_row)
5911 table_data->page_headers=g_list_append(table_data->page_headers,
5912 table_data->top_row);
5915 table_data->top_row = g_list_next(table_data->bottom_row);
5917 wm->state&= ~STATE_HIGHLIGHTED;
5918 gui_internal_menu_render(this);
5924 * @brief handles the 'previous page' table event.
5925 * A callback function that is invoked when the 'previous page' button is pressed
5926 * to go back in the contents of a table widget.
5928 * @param this The graphics context.
5929 * @param wm The button widget that was pressed.
5931 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5933 struct widget * table_widget = (struct widget * ) wm->data;
5934 struct table_data * table_data = NULL;
5935 GList * current_page_top=NULL;
5940 table_data = (struct table_data*) table_widget->data;
5943 current_page_top = table_data->top_row;
5944 for(iterator = table_data->page_headers; iterator != NULL;
5945 iterator = g_list_next(iterator))
5947 if(current_page_top == iterator->data)
5951 table_data->top_row = (GList*) iterator->data;
5955 wm->state&= ~STATE_HIGHLIGHTED;
5956 gui_internal_menu_render(this);
5961 * @brief deallocates a table_data structure.
5964 void gui_internal_table_data_free(void * p)
5969 * @note button_box and its children (next_button,prev_button)
5970 * have their memory managed by the table itself.
5972 struct table_data * table_data = (struct table_data*) p;
5973 g_list_free(table_data->page_headers);
5981 * @brief Called when the route is updated.
5983 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5986 if(this->route_data.route_showing) {
5987 gui_internal_populate_route_table(this,navit);
5988 graphics_draw_mode(this->gra, draw_mode_begin);
5989 gui_internal_menu_render(this);
5990 graphics_draw_mode(this->gra, draw_mode_end);
5998 * @brief Called when the route screen is closed (deallocated).
6000 * The main purpose of this function is to remove the widgets from
6001 * references route_data because those widgets are about to be freed.
6003 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
6006 this_->route_data.route_showing=0;
6007 this_->route_data.route_table=NULL;
6014 * @brief Populates the route table with route information
6016 * @param this The gui context
6017 * @param navit The navit object
6019 void gui_internal_populate_route_table(struct gui_priv * this,
6020 struct navit * navit)
6022 struct map * map=NULL;
6023 struct map_rect * mr=NULL;
6024 struct navigation * nav = NULL;
6025 struct item * item =NULL;
6027 struct widget * label = NULL;
6028 struct widget * row = NULL;
6029 nav = navit_get_navigation(navit);
6033 map = navigation_get_map(nav);
6035 mr = map_rect_new(map,NULL);
6037 gui_internal_widget_table_clear(this,this->route_data.route_table);
6038 while((item = map_rect_get_item(mr))) {
6039 if(item_attr_get(item,attr_navigation_long,&attr)) {
6040 label = gui_internal_label_new(this,attr.u.str);
6041 row = gui_internal_widget_table_row_new(this,
6044 | orientation_horizontal);
6045 row->children=g_list_append(row->children,label);
6046 gui_internal_widget_append(this->route_data.route_table,row);
6054 static struct command_table commands[] = {
6055 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
6056 {"back",command_cast(gui_internal_cmd2_back)},
6057 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
6058 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
6059 {"get_data",command_cast(gui_internal_get_data)},
6060 {"locale",command_cast(gui_internal_cmd2_locale)},
6061 {"log",command_cast(gui_internal_cmd_log)},
6062 {"menu",command_cast(gui_internal_cmd_menu2)},
6063 {"position",command_cast(gui_internal_cmd2_position)},
6064 {"route_description",command_cast(gui_internal_cmd2_route_description)},
6065 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
6066 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
6067 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
6068 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
6069 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
6070 {"town",command_cast(gui_internal_cmd2_town)},
6071 {"quit",command_cast(gui_internal_cmd2_quit)},
6072 {"write",command_cast(gui_internal_cmd_write)},
6073 {"about",command_cast(gui_internal_cmd2_about)}
6077 //##############################################################################################################
6080 //# Authors: Martin Schaller (04/2008)
6081 //##############################################################################################################
6082 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
6084 struct gui_priv *this;
6086 *meth=gui_internal_methods;
6087 this=g_new0(struct gui_priv, 1);
6090 this->self.type=attr_gui;
6091 this->self.u.gui=gui;
6093 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
6094 this->menu_on_map_click=attr->u.num;
6096 this->menu_on_map_click=1;
6097 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
6098 this->signal_on_map_click=attr->u.num;
6100 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
6101 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
6104 if( (attr=attr_search(attrs,NULL,attr_font_size)))
6106 this->config.font_size=attr->u.num;
6110 this->config.font_size=-1;
6112 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
6114 this->config.icon_xs=attr->u.num;
6118 this->config.icon_xs=-1;
6120 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
6122 this->config.icon_l=attr->u.num;
6126 this->config.icon_l=-1;
6128 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
6130 this->config.icon_s=attr->u.num;
6134 this->config.icon_s=-1;
6136 if( (attr=attr_search(attrs,NULL,attr_spacing)))
6138 this->config.spacing=attr->u.num;
6142 this->config.spacing=-1;
6144 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
6146 this->speech=attr->u.num;
6148 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
6149 this->keyboard=attr->u.num;
6153 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
6154 this->fullscreen=attr->u.num;
6156 if( (attr=attr_search(attrs,NULL,attr_flags)))
6157 this->flags=attr->u.num;
6158 if( (attr=attr_search(attrs,NULL,attr_background_color)))
6159 this->background_color=*attr->u.color;
6161 this->background_color=COLOR_BLACK;
6162 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
6163 this->background2_color=*attr->u.color;
6165 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
6166 if( (attr=attr_search(attrs,NULL,attr_text_color)))
6167 this->text_foreground_color=*attr->u.color;
6169 this->text_foreground_color=COLOR_WHITE;
6170 this->text_background_color=COLOR_BLACK;
6171 if( (attr=attr_search(attrs,NULL,attr_columns)))
6172 this->cols=attr->u.num;
6173 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
6174 this->osd_configuration=*attr;
6176 if( (attr=attr_search(attrs,NULL,attr_pitch)))
6177 this->pitch=attr->u.num;
6180 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
6181 this->flags_town=attr->u.num;
6183 this->flags_town=-1;
6184 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
6185 this->flags_street=attr->u.num;
6187 this->flags_street=-1;
6188 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
6189 this->flags_house_number=attr->u.num;
6191 this->flags_house_number=-1;
6192 if( (attr=attr_search(attrs,NULL,attr_radius)))
6193 this->radius=attr->u.num;
6196 this->data.priv=this;
6197 this->data.gui=&gui_internal_methods_ext;
6198 this->data.widget=&gui_internal_widget_methods;
6199 this->cbl=callback_list_new();
6204 //##############################################################################################################
6207 //# Authors: Martin Schaller (04/2008)
6208 //##############################################################################################################
6209 void plugin_init(void)
6211 plugin_register_gui_type("internal", gui_internal_new);