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"
75 struct widget *search_list;
76 struct widget *keyboard;
77 struct widget *button_bar;
79 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
80 struct widget *redisplay_widget;
83 //##############################################################################################################
86 //# Authors: Martin Schaller (04/2008)
87 //##############################################################################################################
89 enum widget_type type;
90 struct graphics_gc *background,*text_background;
91 struct graphics_gc *foreground_frame;
92 struct graphics_gc *foreground;
94 struct graphics_image *img;
96 * A function to be invoked on actions.
97 * @li widget The widget that is receiving the button press.
100 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
105 * @brief A function to deallocate data
107 void (*data_free)(void *data);
110 * @brief a function that will be called as the widget is being destroyed.
111 * This function can act as a destructor for the widget. It allows for
112 * on deallocation actions to be specified on a per widget basis.
113 * This function will call g_free on the widget (if required).
115 void (*free) (struct gui_priv *this_, struct widget * w);
128 int bl,br,bt,bb,spx,spy;
131 * The number of widgets to layout horizontally when doing
132 * a orientation_horizontal_vertical layout
137 int (*set_attr)(void *, struct attr *);
138 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
139 void (*remove_cb)(void *, struct callback *cb);
146 struct menu_data *menu_data;
151 * @brief A structure to store configuration values.
153 * This structure stores configuration values for how gui elements in the internal GUI
156 struct gui_config_settings {
159 * The base size (in fractions of a point) to use for text.
163 * The size (in pixels) that xs style icons should be scaled to.
167 * The size (in pixels) that s style icons (small) should be scaled to
171 * The size (in pixels) that l style icons should be scaled to
175 * The default amount of spacing (in pixels) to place between GUI elements.
182 * Indexes into the config_profiles array.
184 const int LARGE_PROFILE=0;
185 const int MEDIUM_PROFILE=1;
186 const int SMALL_PROFILE=2;
189 * The default config profiles.
191 * [0] => LARGE_PROFILE (screens 640 in one dimension)
192 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
193 * [2] => Small profile (default)
195 static struct gui_config_settings config_profiles[]={
202 struct widget * route_table;
207 //##############################################################################################################
210 //# Authors: Martin Schaller (04/2008)
211 //##############################################################################################################
216 struct graphics *gra;
217 struct graphics_gc *background;
218 struct graphics_gc *background2;
219 struct graphics_gc *highlight_background;
220 struct graphics_gc *foreground;
221 struct graphics_gc *text_foreground;
222 struct graphics_gc *text_background;
223 struct color background_color, background2_color, text_foreground_color, text_background_color;
227 struct graphics_font *font;
228 int icon_xs, icon_s, icon_l;
230 struct widget *widgets;
234 struct widget *highlighted;
235 struct widget *highlighted_menu;
236 int clickp_valid, vehicle_valid;
237 struct pcoord clickp, vehiclep;
238 struct attr *click_coord_geo, *position_coord_geo;
239 struct search_list *sl;
241 int menu_on_map_click;
246 * The setting information read from the configuration file.
247 * values of -1 indicate no value was specified in the config file.
249 struct gui_config_settings config;
250 struct event_idle *idle;
251 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
252 struct event_timeout *motion_timeout_event;
253 struct point current;
255 struct callback * vehicle_cb;
257 * Stores information about the route.
259 struct route_data route_data;
261 struct gui_internal_data data;
262 struct callback_list *cbl;
265 struct attr osd_configuration;
267 int flags_town,flags_street,flags_house_number;
271 struct widget *html_container;
274 int html_anchor_found;
292 struct html_tag_map {
298 {"html",html_tag_html},
299 {"img",html_tag_img},
300 {"script",html_tag_script},
305 * @brief A structure to store information about a table.
307 * The table_data widget stores pointers to extra information needed by the
310 * The table_data structure needs to be freed with data_free along with the widget.
316 * A GList pointer into a widget->children list that indicates the row
317 * currently being rendered at the top of the table.
321 * A Glist pointer into a widget->children list that indicates the row
322 * currently being rendered at the bottom of the table.
327 * A list of table_row widgets that mark the
328 * top rows for each page of the table.
329 * This is needed for the 'previous page' function of the table.
331 GList * page_headers;
334 * A container box that is the child of the table widget that contains+groups
335 * the next and previous button.
337 struct widget * button_box;
340 * A button widget to handle 'next page' requests
342 struct widget * next_button;
344 * A button widget to handle 'previous page' requests.
346 struct widget * prev_button;
350 * a pointer to the gui context.
351 * This is needed by the free function to destory the buttons.
353 struct gui_priv * this;
357 * A data structure that holds information about a column that makes up a table.
361 struct table_column_desc
365 * The computed height of a cell in the table.
370 * The computed width of a cell in the table.
376 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
377 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
378 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
379 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
380 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
381 static void gui_internal_apply_config(struct gui_priv *this);
383 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
384 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
385 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
386 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
387 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
388 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
389 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
390 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
391 static void gui_internal_table_data_free(void * d);
392 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
394 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
395 static void gui_internal_populate_route_table(struct gui_priv * this,
396 struct navit * navit);
397 static void gui_internal_search_idle_end(struct gui_priv *this);
398 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
399 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
400 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
401 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
402 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
403 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
404 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
405 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
406 static void gui_internal_check_exit(struct gui_priv *this);
407 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
409 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
410 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
412 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
413 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
416 * * Display image scaled to specific size
417 * * searches for scaleable and pre-scaled image
418 * * @param this Our gui context
419 * * @param name image name
420 * * @param w desired width of image
421 * * @param h desired height of image
422 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
424 static struct graphics_image *
425 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
427 struct graphics_image *ret=NULL;
428 char *full_name=NULL;
429 char *full_path=NULL;
432 for (i = 1 ; i < 6 ; i++) {
436 full_name=g_strdup_printf("%s.svg", name);
439 full_name=g_strdup_printf("%s.svgz", name);
442 if (w != -1 && h != -1) {
443 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
447 full_name=g_strdup_printf("%s.png", name);
450 full_name=g_strdup_printf("%s.xpm", name);
453 dbg(1,"trying '%s'\n", full_name);
457 /* needs to be checked in the driver */
458 if (!file_exists(full_name)) {
463 full_path=graphics_icon_path(full_name);
464 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
465 dbg(1,"ret=%p\n", ret);
471 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
476 static struct graphics_image *
477 image_new_o(struct gui_priv *this, char *name)
479 return image_new_scaled(this, name, -1, -1);
483 static struct graphics_image *
484 image_new_xs(struct gui_priv *this, const char *name)
486 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
490 static struct graphics_image *
491 image_new_s(struct gui_priv *this, const char *name)
493 return image_new_scaled(this, name, this->icon_s, this->icon_s);
496 static struct graphics_image *
497 image_new_l(struct gui_priv *this, const char *name)
499 return image_new_scaled(this, name, this->icon_l, this->icon_l);
503 coordinates_geo(const struct coord_geo *gc, char sep)
505 char latc='N',lngc='E';
506 int lat_deg,lat_min,lat_sec;
507 int lng_deg,lng_min,lng_sec;
508 struct coord_geo g=*gc;
519 lat_min=fmod(g.lat*60,60);
520 lat_sec=fmod(g.lat*3600,60);
522 lng_min=fmod(g.lng*60,60);
523 lng_sec=fmod(g.lng*3600,60);
524 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);
528 coordinates(struct pcoord *pc, char sep)
534 transform_to_geo(pc->pro, &c, &g);
535 return coordinates_geo(&g, sep);
540 gui_internal_background_render(struct gui_priv *this, struct widget *w)
542 struct point pnt=w->p;
543 if (w->state & STATE_HIGHLIGHTED)
544 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
547 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
550 static struct widget *
551 gui_internal_label_new(struct gui_priv *this, char *text)
557 struct widget *widget=g_new0(struct widget, 1);
558 widget->type=widget_label;
560 widget->text=g_strdup(text);
561 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
565 widget->h=h+this->spacing;
567 widget->w=w+this->spacing;
569 widget->flags=gravity_center;
570 widget->foreground=this->text_foreground;
571 widget->text_background=this->text_background;
576 static struct widget *
577 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
579 struct widget *ret=NULL;
580 char *tmp=g_malloc(strlen(text)+3);
587 ret=gui_internal_label_new(this, tmp);
588 if (ret->w < maxwidth)
590 gui_internal_widget_destroy(this, ret);
598 static struct widget *
599 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
601 struct widget *widget=g_new0(struct widget, 1);
602 widget->type=widget_image;
605 widget->w=image->width;
606 widget->h=image->height;
612 gui_internal_image_render(struct gui_priv *this, struct widget *w)
616 gui_internal_background_render(this, w);
619 pnt.x+=w->w/2-w->img->hot.x;
620 pnt.y+=w->h/2-w->img->hot.y;
621 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
626 gui_internal_label_render(struct gui_priv *this, struct widget *w)
628 struct point pnt=w->p;
629 gui_internal_background_render(this, w);
631 if (w->flags & gravity_right) {
632 pnt.y+=w->h-this->spacing;
633 pnt.x+=w->w-w->textw-this->spacing;
634 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
636 pnt.y+=w->h-this->spacing;
637 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
643 * @brief A text box is a widget that renders a text string containing newlines.
644 * The string will be broken up into label widgets at each newline with a vertical layout.
647 static struct widget *
648 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
650 char *s=g_strdup(text),*s2,*tok;
651 struct widget *ret=gui_internal_box_new(this, flags);
653 while ((tok=strtok(s2,"\n"))) {
654 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
657 gui_internal_widget_pack(this,ret);
662 static struct widget *
663 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)
665 struct widget *ret=NULL;
666 ret=gui_internal_box_new(this, flags);
669 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
671 gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
675 ret->state |= STATE_SENSITIVE;
676 ret->speech=g_strdup(text);
684 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
691 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
692 is_on=curr.u.data == w->on.u.data;
695 if (is_on != w->is_on) {
699 l=g_list_first(w->children);
703 graphics_image_free(this->gra, wi->img);
704 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
706 if (w->is_on && w->off.type == attr_none)
707 w->state &= ~STATE_SENSITIVE;
709 w->state |= STATE_SENSITIVE;
716 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
718 if (gui_internal_button_attr_update(this, w))
719 gui_internal_widget_render(this, w);
722 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
725 w->set_attr(w->instance, &w->off);
727 w->set_attr(w->instance, &w->on);
728 gui_internal_button_attr_update(this, w);
732 static struct widget *
733 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
735 struct graphics_image *image=NULL;
739 image=image_new_xs(this, "gui_inactive");
740 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
745 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
746 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
747 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
748 ret->instance=this->nav;
749 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
750 navit_add_callback(this->nav, ret->cb);
751 gui_internal_button_attr_update(this, ret);
755 static struct widget *
756 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)
758 struct graphics_image *image=NULL;
760 image=image_new_xs(this, "gui_inactive");
763 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
769 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
770 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
771 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
774 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
775 map_add_callback(map, ret->cb);
776 gui_internal_button_attr_update(this, ret);
780 static struct widget *
781 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
783 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
787 //##############################################################################################################
790 //# Authors: Martin Schaller (04/2008)
791 //##############################################################################################################
792 static void gui_internal_clear(struct gui_priv *this)
794 struct graphics *gra=this->gra;
798 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
802 static struct widget *
803 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
805 struct widget *ret,*child;
806 GList *l=wi->children;
813 if ( wi->p.x + wi->w < p->x)
815 if ( wi->p.y + wi->h < p->y)
818 if (wi->state & flags)
822 ret=gui_internal_find_widget(child, p, flags);
833 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
835 if (found == this->highlighted)
838 graphics_draw_mode(this->gra, draw_mode_begin);
839 if (this->highlighted) {
840 this->highlighted->state &= ~STATE_HIGHLIGHTED;
841 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
842 gui_internal_widget_render(this, this->highlighted);
843 this->highlighted=NULL;
844 this->highlighted_menu=NULL;
847 this->highlighted=found;
848 this->highlighted_menu=g_list_last(this->root.children)->data;
849 this->highlighted->state |= STATE_HIGHLIGHTED;
850 gui_internal_widget_render(this, this->highlighted);
851 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
853 graphics_draw_mode(this->gra, draw_mode_end);
855 //##############################################################################################################
858 //# Authors: Martin Schaller (04/2008)
859 //##############################################################################################################
860 static void gui_internal_highlight(struct gui_priv *this)
862 struct widget *menu,*found=NULL;
863 if (this->current.x > -1 && this->current.y > -1) {
864 menu=g_list_last(this->root.children)->data;
865 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
867 gui_internal_highlight_do(this, found);
868 this->motion_timeout_event=NULL;
871 static struct widget *
872 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
874 struct widget *widget=g_new0(struct widget, 1);
877 widget->text=g_strdup(label);
878 widget->type=widget_box;
883 static struct widget *
884 gui_internal_box_new(struct gui_priv *this, enum flags flags)
886 return gui_internal_box_new_with_label(this, flags, NULL);
890 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
895 gui_internal_background_render(this, w);
897 if (w->foreground && w->border) {
900 pnt[1].x=pnt[0].x+w->w;
902 pnt[2].x=pnt[0].x+w->w;
903 pnt[2].y=pnt[0].y+w->h;
905 pnt[3].y=pnt[0].y+w->h;
907 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
908 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
909 graphics_gc_set_linewidth(w->foreground, 1);
916 gui_internal_widget_render(this, wc);
923 * @brief Compute the size and location for the widget.
927 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
930 int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,count=0,rows=0,cols=w->cols ? w->cols : 0;
932 int orientation=w->flags & 0xffff0000;
937 if ( this->root.w > this->root.h )
947 * count the number of children
954 if (orientation == orientation_horizontal_vertical && count <= cols)
955 orientation=orientation_horizontal;
956 switch (orientation) {
957 case orientation_horizontal:
959 * For horizontal orientation:
960 * pack each child and find the largest height and
961 * compute the total width. x spacing (spx) is considered
963 * If any children want to be expanded
964 * we keep track of this
969 gui_internal_widget_pack(this, wc);
973 if (wc->flags & flags_expand)
974 expand+=wc->w ? wc->w : 1;
980 if (expand && w->w) {
981 expand=100*(w->w-width+expand)/expand;
986 case orientation_vertical:
988 * For vertical layouts:
989 * We pack each child and compute the largest width and
990 * the total height. y spacing (spy) is considered
992 * If the expand flag is set then teh expansion amount
998 gui_internal_widget_pack(this, wc);
1002 if (wc->flags & flags_expand)
1003 expand+=wc->h ? wc->h : 1;
1009 if (expand && w->h) {
1010 expand=100*(w->h-height+expand)/expand;
1015 case orientation_horizontal_vertical:
1017 * For horizontal_vertical orientation
1018 * pack the children.
1019 * Compute the largest height and largest width.
1020 * Layout the widgets based on having the
1021 * number of columns specified by (cols)
1027 gui_internal_widget_pack(this, wc);
1037 rows=(count+cols-1)/cols;
1040 width+=w->spx*(cols-1);
1041 height+=w->spy*(rows-1);
1048 * No orientation was specified.
1049 * width and height are both 0.
1050 * The width & height of this widget
1054 dbg(0,"Warning width and height of a widget are 0");
1057 if (! w->w && ! w->h) {
1058 w->w=w->bl+w->br+width;
1059 w->h=w->bt+w->bb+height;
1065 * At this stage the width and height of this
1066 * widget has been computed.
1067 * We now make a second pass assigning heights,
1068 * widths and coordinates to each child widget.
1071 if (w->flags & gravity_left)
1073 if (w->flags & gravity_xcenter)
1074 x=w->p.x+w->w/2-owidth/2;
1075 if (w->flags & gravity_right)
1076 x=w->p.x+w->w-w->br-owidth;
1077 if (w->flags & gravity_top)
1079 if (w->flags & gravity_ycenter)
1080 y=w->p.y+w->h/2-oheight/2;
1081 if (w->flags & gravity_bottom)
1082 y=w->p.y+w->h-w->bb-oheight;
1084 switch (orientation) {
1085 case orientation_horizontal:
1090 if (wc->flags & flags_fill)
1092 if (wc->flags & flags_expand) {
1095 wc->w=wc->w*expand/100;
1097 if (w->flags & gravity_top)
1099 if (w->flags & gravity_ycenter)
1101 if (w->flags & gravity_bottom)
1107 case orientation_vertical:
1112 if (wc->flags & flags_fill)
1114 if (wc->flags & flags_expand) {
1117 wc->h=wc->h*expand/100;
1119 if (w->flags & gravity_left)
1121 if (w->flags & gravity_xcenter)
1123 if (w->flags & gravity_right)
1129 case orientation_horizontal_vertical:
1139 if (wc->flags & flags_fill) {
1143 if (w->flags & gravity_left)
1145 if (w->flags & gravity_xcenter)
1146 wc->p.x=x+(width-wc->w)/2;
1147 if (w->flags & gravity_right)
1148 wc->p.x=x+width-wc->w;
1149 if (w->flags & gravity_top)
1151 if (w->flags & gravity_ycenter)
1152 wc->p.y=y+(height-wc->h)/2;
1153 if (w->flags & gravity_bottom)
1154 wc->p.y=y-height-wc->h;
1156 if (++count == cols) {
1168 * Call pack again on each child,
1169 * the child has now had its size and coordinates
1170 * set so they can repack their children.
1175 gui_internal_widget_pack(this, wc);
1181 gui_internal_widget_append(struct widget *parent, struct widget *child)
1185 if (! child->background)
1186 child->background=parent->background;
1187 parent->children=g_list_append(parent->children, child);
1190 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1192 if (! child->background)
1193 child->background=parent->background;
1194 parent->children=g_list_prepend(parent->children, child);
1197 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1205 gui_internal_widget_destroy(this, wc);
1208 g_list_free(w->children);
1212 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1214 gui_internal_widget_children_destroy(this, w);
1219 graphics_image_free(this->gra, w->img);
1225 w->data_free(w->data);
1226 if (w->cb && w->remove_cb)
1227 w->remove_cb(w->instance, w->cb);
1236 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1238 if(w->p.x > this->root.w || w->p.y > this->root.h)
1243 gui_internal_box_render(this, w);
1246 gui_internal_label_render(this, w);
1249 gui_internal_image_render(this, w);
1252 gui_internal_table_render(this,w);
1260 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1264 gui_internal_box_pack(this, w);
1267 gui_internal_table_pack(this,w);
1273 //##############################################################################################################
1276 //# Authors: Martin Schaller (04/2008)
1277 //##############################################################################################################
1278 static void gui_internal_call_highlighted(struct gui_priv *this)
1280 if (! this->highlighted || ! this->highlighted->func)
1282 this->highlighted->reason=1;
1283 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1287 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1289 char *text=w->speech;
1297 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1298 navit_say(this->nav, text);
1304 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1308 gui_internal_search_idle_end(this);
1309 while ((l = g_list_last(this->root.children))) {
1311 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1312 gui_internal_say(this, w, 0);
1313 redisplay=w->menu_data->redisplay;
1314 wr=w->menu_data->redisplay_widget;
1315 if (!w->menu_data->redisplay) {
1316 gui_internal_widget_render(this, w);
1319 gui_internal_widget_destroy(this, l->data);
1320 this->root.children=g_list_remove(this->root.children, l->data);
1321 redisplay(this, wr, wr->data);
1324 gui_internal_widget_destroy(this, l->data);
1325 this->root.children=g_list_remove(this->root.children, l->data);
1330 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1333 gui_internal_search_idle_end(this);
1334 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1335 gui_internal_widget_destroy(this, l->data);
1336 this->root.children=g_list_remove(this->root.children, l->data);
1339 gui_internal_say(this, l->data, 0);
1340 gui_internal_widget_render(this, l->data);
1345 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1347 gui_internal_prune_menu_count(this, 1, 1);
1351 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1353 gui_internal_prune_menu(this, wm->data);
1357 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1359 graphics_draw_mode(this->gra, draw_mode_begin);
1360 gui_internal_back(this, NULL, NULL);
1361 graphics_draw_mode(this->gra, draw_mode_end);
1362 gui_internal_check_exit(this);
1366 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1368 gui_internal_prune_menu(this, NULL);
1372 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1374 gui_internal_prune_menu(this, this->root.children->data);
1377 static struct widget *
1378 gui_internal_top_bar(struct gui_priv *this)
1380 struct widget *w,*wm,*wh,*wc,*wcn;
1381 int dots_len, sep_len;
1383 int width,width_used=0,use_sep=0,incomplete=0;
1384 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1386 1:Don't expand bar to screen width
1387 2:Don't show Map Icon
1388 4:Don't show Home Icon
1389 8:Show only current menu
1390 16:Don't use menu titles as button
1391 32:Show navit version
1394 256:Use background for menu headline
1395 512:Set osd_configuration and zoom to route when setting position
1396 1024:Don't show back button
1399 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1400 w->bl=this->spacing;
1401 w->spx=this->spacing;
1402 w->background=this->background2;
1403 if ((this->flags & 6) == 6) {
1409 width=this->root.w-w->bl;
1410 if (! (this->flags & 2)) {
1411 wm=gui_internal_button_new_with_callback(this, NULL,
1412 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1413 gui_internal_cmd_return, NULL);
1414 wm->speech=g_strdup(_("Back to map"));
1415 gui_internal_widget_pack(this, wm);
1416 gui_internal_widget_append(w, wm);
1419 if (! (this->flags & 4)) {
1420 wh=gui_internal_button_new_with_callback(this, NULL,
1421 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1422 gui_internal_cmd_main_menu, NULL);
1423 wh->speech=g_strdup(_("Main Menu"));
1424 gui_internal_widget_pack(this, wh);
1425 gui_internal_widget_append(w, wh);
1428 if (!(this->flags & 6))
1430 l=g_list_last(this->root.children);
1431 wcn=gui_internal_label_new(this,".. »");
1432 wcn->foreground=foreground;
1434 gui_internal_widget_destroy(this, wcn);
1435 wcn=gui_internal_label_new(this,"»");
1436 wcn->foreground=foreground;
1438 gui_internal_widget_destroy(this, wcn);
1440 if (g_list_previous(l) || !g_list_next(l)) {
1442 wcn=gui_internal_label_new(this, wc->text);
1443 wcn->foreground=foreground;
1448 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1449 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1451 gui_internal_widget_destroy(this, wcn);
1455 struct widget *wct=gui_internal_label_new(this, "»");
1456 wct->foreground=foreground;
1457 res=g_list_prepend(res, wct);
1458 width_used+=sep_len+w->spx;
1461 if (!(this->flags & 16)) {
1462 wcn->func=gui_internal_cmd_return;
1464 wcn->state |= STATE_SENSITIVE;
1466 res=g_list_prepend(res, wcn);
1467 if (this->flags & 8)
1470 l=g_list_previous(l);
1474 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1475 wcn->foreground=foreground;
1476 wcn->func=gui_internal_cmd_return;
1478 wcn->state |= STATE_SENSITIVE;
1479 res=g_list_prepend(res, wcn);
1480 l=g_list_previous(l);
1483 wcn=gui_internal_label_new(this, ".. »");
1484 wcn->foreground=foreground;
1485 wcn->func=gui_internal_cmd_return;
1487 wcn->state |= STATE_SENSITIVE;
1488 res=g_list_prepend(res, wcn);
1492 gui_internal_widget_append(w, l->data);
1495 if (this->flags & 32) {
1496 extern char *version;
1497 char *version_text=g_strdup_printf("Navit %s",version);
1498 wcn=gui_internal_label_new(this, version_text);
1499 g_free(version_text);
1500 wcn->flags=gravity_right_center|flags_expand;
1501 gui_internal_widget_append(w, wcn);
1505 gui_internal_widget_destroy(this, dots);
1510 static struct widget *
1511 gui_internal_time_help(struct gui_priv *this)
1513 struct widget *w,*wc,*wcn;
1518 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1519 w->bl=this->spacing;
1520 w->spx=this->spacing;
1526 if (this->flags & 64) {
1527 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1533 tm=localtime(&timep);
1534 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1535 wcn=gui_internal_label_new(this, timestr);
1536 gui_internal_widget_append(wc, wcn);
1537 gui_internal_widget_append(w, wc);
1539 if (this->flags & 128) {
1540 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1541 gui_internal_widget_append(w, wcn);
1548 * Applys the configuration values to this based on the settings
1549 * specified in the configuration file (this->config) and
1550 * the most approriate default profile based on screen resolution.
1552 * This function should be run after this->root is setup and could
1553 * be rerun after the window is resized.
1555 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1557 static void gui_internal_apply_config(struct gui_priv *this)
1559 struct gui_config_settings * current_config=0;
1561 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1563 * Select default values from profile based on the screen.
1565 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1567 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1569 current_config = &config_profiles[LARGE_PROFILE];
1573 current_config = &config_profiles[MEDIUM_PROFILE];
1578 current_config = &config_profiles[SMALL_PROFILE];
1582 * Apply override values from config file
1584 if(this->config.font_size == -1 )
1586 this->font_size = current_config->font_size;
1590 this->font_size = this->config.font_size;
1593 if(this->config.icon_xs == -1 )
1595 this->icon_xs = current_config->icon_xs;
1599 this->icon_xs = this->config.icon_xs;
1602 if(this->config.icon_s == -1 )
1604 this->icon_s = current_config->icon_s;
1608 this->icon_s = this->config.icon_s;
1610 if(this->config.icon_l == -1 )
1612 this->icon_l = current_config->icon_l;
1616 this->icon_l = this->config.icon_l;
1618 if(this->config.spacing == -1 )
1620 this->spacing = current_config->spacing;
1624 this->spacing = current_config->spacing;
1629 static struct widget *
1630 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1632 struct widget *wl,*wlb;
1633 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1634 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1635 wl=gui_internal_label_new(this, label);
1637 wlb->foreground=this->text_foreground;
1642 gui_internal_widget_append(wlb, wl);
1644 gui_internal_widget_prepend(wb, wlb);
1646 gui_internal_widget_append(wb, wlb);
1652 static struct widget *
1653 gui_internal_menu(struct gui_priv *this, const char *label)
1655 struct widget *menu,*w,*w1,*topbox;
1657 gui_internal_search_idle_end(this);
1658 topbox=gui_internal_box_new_with_label(this, 0, label);
1659 topbox->w=this->root.w;
1660 topbox->h=this->root.h;
1661 gui_internal_widget_append(&this->root, topbox);
1662 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1663 menu->w=this->root.w;
1664 menu->h=this->root.h;
1665 menu->background=this->background;
1666 gui_internal_apply_config(this);
1667 this->font=graphics_font_new(this->gra,this->font_size,1);
1668 topbox->menu_data=g_new0(struct menu_data, 1);
1669 gui_internal_widget_append(topbox, menu);
1670 w=gui_internal_top_bar(this);
1671 gui_internal_widget_append(menu, w);
1672 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1673 w->spx=4*this->spacing;
1675 gui_internal_widget_append(menu, w);
1676 if (this->flags & 16 && (!this->flags & 1024)) {
1677 struct widget *wlb,*wb,*wm=w;
1678 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1679 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1680 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1681 gui_internal_widget_append(wm, w);
1682 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1688 topbox->menu_data->button_bar=wb;
1689 gui_internal_widget_append(wm, wb);
1690 wlb=gui_internal_button_label(this,_("Back"),1);
1691 wlb->func=gui_internal_back;
1692 wlb->state |= STATE_SENSITIVE;
1694 if (this->flags & 192) {
1695 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1696 menu->w=this->root.w;
1697 menu->h=this->root.h;
1698 w1=gui_internal_time_help(this);
1699 gui_internal_widget_append(menu, w1);
1700 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1701 gui_internal_widget_append(menu, w1);
1702 gui_internal_widget_append(topbox, menu);
1703 menu->background=NULL;
1708 static struct menu_data *
1709 gui_internal_menu_data(struct gui_priv *this)
1712 struct widget *menu;
1714 l=g_list_last(this->root.children);
1716 return menu->menu_data;
1720 gui_internal_menu_render(struct gui_priv *this)
1723 struct widget *menu;
1725 l=g_list_last(this->root.children);
1727 gui_internal_say(this, menu, 0);
1728 gui_internal_widget_pack(this, menu);
1729 gui_internal_widget_render(this, menu);
1733 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1736 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1737 navit_set_destination(this->nav, &wm->c, name, 1);
1738 if (this->flags & 512) {
1740 follow.type=attr_follow;
1742 navit_set_attr(this->nav, &this->osd_configuration);
1743 navit_set_attr(this->nav, &follow);
1744 navit_zoom_to_route(this->nav, 0);
1746 gui_internal_prune_menu(this, NULL);
1750 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1752 navit_set_position(this->nav, &wm->c);
1753 gui_internal_prune_menu(this, NULL);
1757 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1760 dbg(0,"text='%s'\n", widget->text);
1761 if (widget->text && strlen(widget->text))
1762 navit_add_bookmark(this->nav, &widget->c, widget->text);
1763 g_free(widget->text);
1765 l=g_list_previous(g_list_last(this->root.children));
1766 gui_internal_prune_menu(this, l->data);
1770 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1772 gui_internal_cmd_add_bookmark_do(this, widget->data);
1776 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1781 len=strlen(wm->text);
1782 dbg(1,"len=%d\n", len);
1783 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1784 wm->text[len-1]='\0';
1785 gui_internal_cmd_add_bookmark_do(this, wm);
1791 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1794 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
1796 struct widget *w,*wb,*wk,*wl,*we,*wnext;
1798 wb=gui_internal_menu(this,_("Add Bookmark"));
1799 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1800 gui_internal_widget_append(wb, w);
1801 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1802 gui_internal_widget_append(w, we);
1803 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
1804 wk->state |= STATE_EDIT|STATE_CLEAR;
1805 wk->background=this->background;
1806 wk->flags |= flags_expand|flags_fill;
1807 wk->func = gui_internal_cmd_add_bookmark_changed;
1809 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1810 wnext->state |= STATE_SENSITIVE;
1811 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1813 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1814 gui_internal_widget_append(w, wl);
1816 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1817 gui_internal_menu_render(this);
1822 get_direction(char *buffer, int angle, int mode)
1827 sprintf(buffer,"%d",angle);
1830 if (angle < 69 || angle > 291)
1832 if (angle > 111 && angle < 249)
1834 if (angle > 22 && angle < 158)
1836 if (angle > 202 && angle < 338)
1841 angle=(angle+15)/30;
1844 sprintf(buffer,"%d H", angle);
1852 enum item_type *types;
1854 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1855 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1856 {"hotel","Hotel",(enum item_type []) {
1857 type_poi_hotel,type_poi_camp_rv,
1858 type_poi_camping,type_poi_camping,
1859 type_poi_resort,type_poi_resort,
1860 type_poi_motel,type_poi_hostel,
1862 {"restaurant","Restaurant",(enum item_type []) {
1863 type_poi_bar,type_poi_picnic,
1864 type_poi_burgerking,type_poi_fastfood,
1865 type_poi_restaurant,type_poi_restaurant,
1867 {"shopping","Shopping",(enum item_type []) {
1868 type_poi_mall,type_poi_mall,
1869 type_poi_shop_grocery,type_poi_shop_grocery,
1871 {"hospital","Service",(enum item_type []) {
1872 type_poi_marina,type_poi_marina,
1873 type_poi_hospital,type_poi_hospital,
1874 type_poi_public_utilities,type_poi_public_utilities,
1875 type_poi_police,type_poi_autoservice,
1876 type_poi_information,type_poi_information,
1877 type_poi_personal_service,type_poi_repair_service,
1878 type_poi_restroom,type_poi_restroom,
1880 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1881 {"peak","Land Features",(enum item_type []){
1882 type_poi_land_feature,type_poi_rock,
1883 type_poi_dam,type_poi_dam,
1885 {"unknown","Other",(enum item_type []){
1886 type_point_unspecified,type_point_unkn-1,
1887 type_point_unkn+1,type_poi_land_feature-1,
1888 type_poi_rock+1,type_poi_fuel-1,
1889 type_poi_marina+1,type_poi_car_parking-1,
1890 type_poi_car_parking+1,type_poi_bar-1,
1891 type_poi_bank+1,type_poi_dam-1,
1892 type_poi_dam+1,type_poi_information-1,
1893 type_poi_information+1,type_poi_mall-1,
1894 type_poi_mall+1,type_poi_personal_service-1,
1895 type_poi_restaurant+1,type_poi_restroom-1,
1896 type_poi_restroom+1,type_poi_shop_grocery-1,
1897 type_poi_shop_grocery+1,type_poi_motel-1,
1898 type_poi_hostel+1,type_selected_point,
1900 {"unknown","Unknown",(enum item_type []){
1901 type_point_unkn,type_point_unkn,
1905 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1907 static struct widget *
1908 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1910 struct widget *wl,*wb;
1912 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1913 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1914 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1915 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1916 gui_internal_cmd_pois, &selectors[i]));
1923 static struct widget *
1924 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1930 struct widget *wl,*wt;
1933 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1935 sprintf(distbuf,"%d", dist/1000);
1936 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1937 type=item_to_name(item->type);
1938 if (item_attr_get(item, attr_label, &attr)) {
1939 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1942 wl->name=g_strdup(type);
1944 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
1945 wt=gui_internal_label_new(this, text);
1947 gui_internal_widget_append(wl, wt);
1954 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1956 const struct widget *wa=a;
1957 const struct widget *wb=b;
1958 struct widget *wac=wa->children->data;
1959 struct widget *wbc=wb->children->data;
1967 return wac->datai-wbc->datai;
1972 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1974 enum item_type *types;
1975 if (type >= type_line)
1977 if (! sel || !sel->types)
1980 while (*types != type_none) {
1981 if (type >= types[0] && type <= types[1]) {
1989 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
1992 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
1994 struct map_selection *sel,*selm;
1995 struct coord c,center;
1996 struct mapset_handle *h;
1998 struct map_rect *mr;
2000 int idist,dist=20000;
2001 struct widget *wi,*w,*w2,*wb;
2002 enum projection pro=wm->c.pro;
2003 struct selector *isel=wm->data;
2005 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2006 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2007 gui_internal_widget_append(wb, w);
2009 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
2010 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2011 gui_internal_widget_append(w, w2);
2013 sel=map_selection_rect_new(&wm->c, dist, 18);
2016 h=mapset_open(navit_get_mapset(this->nav));
2017 while ((m=mapset_next(h, 1))) {
2018 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2019 mr=map_rect_new(m, selm);
2020 dbg(2,"mr=%p\n", mr);
2022 while ((item=map_rect_get_item(mr))) {
2023 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
2024 item_coord_get_pro(item, &c, 1, pro) &&
2025 coord_rect_contains(&sel->u.c_rect, &c) &&
2026 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2027 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
2028 wi->func=gui_internal_cmd_position;
2031 wi->state |= STATE_SENSITIVE;
2037 map_rect_destroy(mr);
2039 map_selection_destroy(selm);
2041 map_selection_destroy(sel);
2043 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
2044 gui_internal_menu_render(this);
2048 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2050 struct widget *w=wm->data;
2051 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
2053 graphics_clear_selection(this->gra, NULL);
2054 graphics_add_selection(this->gra, &w->item, NULL);
2056 navit_set_center(this->nav, &w->c, 1);
2057 gui_internal_prune_menu(this, NULL);
2062 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2064 struct widget *w,*wb;
2065 struct map_rect *mr;
2071 text=g_strdup_printf("Attribute %s",wm->name);
2072 wb=gui_internal_menu(this, text);
2074 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2075 gui_internal_widget_append(wb, w);
2076 mr=map_rect_new(wm->item.map, NULL);
2077 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2078 for (i = 0 ; i < wm->datai ; i++) {
2079 item_attr_get(item, attr_any, &attr);
2081 if (item_attr_get(item, attr_any, &attr)) {
2083 switch (attr.type) {
2084 case attr_osm_nodeid:
2085 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2087 case attr_osm_wayid:
2088 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2090 case attr_osm_relationid:
2091 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2097 gui_internal_widget_append(w,
2098 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2099 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2100 gui_internal_cmd_view_in_browser, NULL));
2104 map_rect_destroy(mr);
2105 gui_internal_menu_render(this);
2109 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2111 struct widget *w,*wb;
2112 struct map_rect *mr;
2118 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2119 wb=gui_internal_menu(this, "Attributes");
2120 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2121 gui_internal_widget_append(wb, w);
2122 mr=map_rect_new(wm->item.map, NULL);
2123 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2124 dbg(0,"item=%p\n", item);
2126 while(item_attr_get(item, attr_any, &attr)) {
2127 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2128 gui_internal_widget_append(w,
2129 wb=gui_internal_button_new_with_callback(this, text,
2130 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2131 gui_internal_cmd_view_attribute_details, NULL));
2132 wb->name=g_strdup(text);
2138 map_rect_destroy(mr);
2139 gui_internal_menu_render(this);
2143 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2145 struct map_rect *mr;
2151 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2152 mr=map_rect_new(wm->item.map, NULL);
2153 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2154 dbg(0,"item=%p\n", item);
2156 while(item_attr_get(item, attr_url_local, &attr)) {
2158 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2161 map_rect_destroy(mr);
2163 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2169 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2176 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)
2178 struct widget *wb,*w,*wc,*wbc;
2188 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2189 transform_to_geo(pc.pro, &c, &g);
2192 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
2195 pc.pro=attr.u.projection;
2196 transform_from_geo(pc.pro, &g, &c);
2202 wb=gui_internal_menu(this, name);
2203 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2204 gui_internal_widget_append(wb, w);
2205 coord=coordinates(&pc, ' ');
2206 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2208 if ((flags & 1) && wm) {
2209 gui_internal_widget_append(w,
2210 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2211 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2212 gui_internal_search_street_in_town, wm));
2214 wc->selection_id=wm->selection_id;
2216 if ((flags & 2) && wm) {
2217 gui_internal_widget_append(w,
2218 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2219 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2220 gui_internal_search_house_number_in_street, wm));
2222 wc->selection_id=wm->selection_id;
2224 if ((flags & 4) && wm) {
2225 struct map_rect *mr;
2228 mr=map_rect_new(wm->item.map, NULL);
2229 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2231 if (item_attr_get(item, attr_description, &attr))
2232 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2233 if (item_attr_get(item, attr_url_local, &attr)) {
2234 gui_internal_widget_append(w,
2235 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2236 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2237 gui_internal_cmd_view_in_browser, NULL));
2240 gui_internal_widget_append(w,
2241 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2242 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2243 gui_internal_cmd_view_attributes, NULL));
2246 map_rect_destroy(mr);
2249 gui_internal_widget_append(w,
2250 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
2251 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2252 gui_internal_cmd_set_destination, g_strdup(name)));
2253 wbc->data_free=g_free;
2257 gui_internal_widget_append(w,
2258 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
2259 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2260 gui_internal_cmd_set_position, wm));
2264 gui_internal_widget_append(w,
2265 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2266 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2267 gui_internal_cmd_add_bookmark2, g_strdup(name)));
2268 wbc->data_free=g_free;
2272 gui_internal_widget_append(w,
2273 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2274 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2275 gui_internal_cmd_pois, NULL));
2279 gui_internal_widget_append(w,
2280 gui_internal_button_new(this, "Add to tour",
2281 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2284 gui_internal_widget_append(w,
2285 gui_internal_button_new_with_callback(this, _("View on map"),
2286 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2287 gui_internal_cmd_view_on_map, wm));
2292 struct mapset_handle *h;
2293 struct map_rect *mr;
2296 struct street_data *data;
2297 struct map_selection sel;
2298 struct transformation *trans;
2299 enum projection pro;
2303 trans=navit_get_trans(this->nav);
2304 pro=transform_get_projection(trans);
2305 transform_from_geo(pro, &g, &c);
2306 ms=navit_get_mapset(this->nav);
2308 sel.u.c_rect.lu.x=c.x-dist;
2309 sel.u.c_rect.lu.y=c.y+dist;
2310 sel.u.c_rect.rl.x=c.x+dist;
2311 sel.u.c_rect.rl.y=c.y-dist;
2313 sel.range=item_range_all;
2315 while ((m=mapset_next(h,1))) {
2316 mr=map_rect_new(m, &sel);
2319 while ((item=map_rect_get_item(mr))) {
2320 data=street_get_data(item);
2321 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2322 if (item_attr_get(item, attr_label, &attr)) {
2323 label=map_convert_string(m, attr.u.str);
2324 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2325 map_convert_free(label);
2327 text=g_strdup_printf("%s", item_to_name(item->type));
2328 gui_internal_widget_append(w,
2329 wc=gui_internal_button_new_with_callback(this, text,
2330 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2331 gui_internal_cmd_position, (void *)2));
2332 wc->c.x=data->c[0].x;
2333 wc->c.y=data->c[0].y;
2335 wc->name=g_strdup(text);
2339 street_data_free(data);
2341 map_rect_destroy(mr);
2345 gui_internal_menu_render(this);
2349 /* wm->data: 0 Nothing special
2359 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2362 switch ((int) wm->data) {
2364 flags=8|16|32|64|128|256;
2367 flags=8|16|32|64|256;
2374 flags &= this->flags_town;
2377 gui_internal_search_town_in_country(this, wm);
2381 flags &= this->flags_street;
2385 flags &= this->flags_house_number;
2392 gui_internal_search_house_number_in_street(this, wm, NULL);
2395 gui_internal_cmd_set_destination(this, wm, NULL);
2398 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
2402 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2404 char *name=_("Position");
2410 if (!ATTR_IS_COORD_GEO(in[0]->type))
2412 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
2414 if (in[2] && ATTR_IS_INT(in[2]->type))
2417 dbg(1,"flags=0x%x\n",flags);
2418 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
2422 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2424 struct attr attr,mattr;
2425 struct map_rect *mr=NULL;
2427 char *label_full,*l,*prefix="",*pos;
2428 int len,plen,hassub;
2429 struct widget *wb,*w,*wbm;
2432 char *text=_("Bookmarks");
2436 wb=gui_internal_menu(this, text);
2437 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2438 w->spy=this->spacing*3;
2439 gui_internal_widget_append(wb, w);
2441 if (wm && wm->prefix)
2443 plen=strlen(prefix);
2445 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2446 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2447 while ((item=map_rect_get_item(mr))) {
2448 if (item->type != type_bookmark) continue;
2449 if (!item_attr_get(item, attr_label, &attr)) continue;
2450 label_full=attr.u.str;
2451 if (!strncmp(label_full, prefix, plen)) {
2452 pos=strchr(label_full+plen, '/');
2458 len=strlen(label_full);
2460 l=g_malloc(len-plen+1);
2461 strncpy(l, label_full+plen, len-plen);
2463 if (!g_hash_table_lookup(hash, l)) {
2464 wbm=gui_internal_button_new_with_callback(this, l,
2465 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2466 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2467 if (item_coord_get(item, &c, 1)) {
2470 wbm->c.pro=map_projection(mattr.u.map);
2471 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2472 wbm->text=g_strdup(l);
2473 gui_internal_widget_append(w, wbm);
2474 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2475 wbm->prefix=g_malloc(len+2);
2476 strncpy(wbm->prefix, label_full, len+1);
2477 wbm->prefix[len+1]='\0';
2479 gui_internal_widget_destroy(this, wbm);
2486 g_hash_table_destroy(hash);
2488 gui_internal_menu_render(this);
2492 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2494 gui_internal_cmd_bookmarks(this, NULL, NULL);
2497 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2499 struct widget *wi,*menu;
2503 menu=g_list_last(this->root.children)->data;
2504 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2506 if (*key == NAVIT_KEY_BACKSPACE) {
2507 dbg(0,"backspace\n");
2508 if (wi->text && wi->text[0]) {
2509 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2511 text=g_strdup_printf("%s ", wi->text);
2514 if (wi->state & STATE_CLEAR) {
2515 dbg(0,"wi->state=0x%x\n", wi->state);
2518 wi->state &= ~STATE_CLEAR;
2519 dbg(0,"wi->state=0x%x\n", wi->state);
2521 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2525 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2526 gui_internal_widget_render(this, wi);
2531 wi->func(this, wi, wi->data);
2533 gui_internal_widget_render(this, wi);
2539 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2541 struct menu_data *md=gui_internal_menu_data(this);
2542 gui_internal_keypress_do(this, (char *) wm->data);
2543 if (md->keyboard_mode == 2)
2544 gui_internal_keyboard_do(this, md->keyboard, 10);
2545 if (md->keyboard_mode == 26)
2546 gui_internal_keyboard_do(this, md->keyboard, 34);
2550 gui_internal_search_idle_end(struct gui_priv *this)
2553 event_remove_idle(this->idle);
2556 if (this->idle_cb) {
2557 callback_destroy(this->idle_cb);
2563 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2565 char *text=NULL,*name=NULL;
2566 struct search_list_result *res;
2568 struct item *item=NULL;
2570 static char possible_keys[256]="";
2572 res=search_list_get_result(this->sl);
2574 gchar* trunk_name = NULL;
2576 struct widget *menu=g_list_last(this->root.children)->data;
2577 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2579 if (! strcmp(wm_name,"Town"))
2580 trunk_name = g_strrstr(res->town->name, wi->text);
2581 if (! strcmp(wm_name,"Street"))
2582 trunk_name = g_strrstr(name=res->street->name, wi->text);
2585 char next_char = trunk_name[strlen(wi->text)];
2587 int len = strlen(possible_keys);
2588 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2589 if (i==len || !len) {
2590 possible_keys[len]=trunk_name[strlen(wi->text)];
2591 possible_keys[len+1]='\0';
2594 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->name, possible_keys);
2599 gui_internal_search_idle_end(this);
2601 struct menu_data *md=gui_internal_menu_data(this);
2602 if (md && md->keyboard) {
2603 GList *lk=md->keyboard->children;
2604 graphics_draw_mode(this->gra, draw_mode_begin);
2606 struct widget *child=lk->data;
2607 GList *lk2=child->children;
2609 struct widget *child_=lk2->data;
2610 lk2=g_list_next(lk2);
2611 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2612 if (strlen(possible_keys) == 0)
2613 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2614 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2615 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2617 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2619 gui_internal_widget_render(this,child_);
2624 gui_internal_widget_render(this,md->keyboard);
2625 graphics_draw_mode(this->gra, draw_mode_end);
2628 possible_keys[0]='\0';
2632 if (! strcmp(wm_name,"Country")) {
2633 name=res->country->name;
2634 item=&res->country->common.item;
2635 text=g_strdup_printf("%s", res->country->name);
2637 if (! strcmp(wm_name,"Town")) {
2638 name=res->town->name;
2639 item=&res->town->common.item;
2640 if (res->town->name && res->town->district)
2641 text=g_strdup_printf("%s%s%s (%s)", res->town->common.postal_mask ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name, res->town->district);
2643 text=g_strdup_printf("%s%s%s", res->town->common.postal ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name);
2645 if (! strcmp(wm_name,"Street")) {
2646 name=res->street->name;
2647 item=&res->street->common.item;
2648 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
2650 dbg(1,"res->country->flag=%s\n", res->country->flag);
2651 gui_internal_widget_append(search_list,
2652 wc=gui_internal_button_new_with_callback(this, text,
2653 image_new_xs(this, res->country->flag),
2654 gravity_left_center|orientation_horizontal|flags_fill,
2655 gui_internal_cmd_position, param));
2656 wc->name=g_strdup(name);
2659 wc->selection_id=res->id;
2662 gui_internal_widget_pack(this, search_list);
2663 l=g_list_last(this->root.children);
2664 graphics_draw_mode(this->gra, draw_mode_begin);
2665 gui_internal_widget_render(this, l->data);
2666 graphics_draw_mode(this->gra, draw_mode_end);
2671 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2673 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2674 this->idle=event_add_idle(50,this->idle_cb);
2675 callback_call_0(this->idle_cb);
2681 * @param wm The widget that generated the event for the search changed,
2682 * if this was generated by a key on the virtual keyboard then
2683 * wm is the key button widget.
2686 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2689 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2690 gui_internal_widget_children_destroy(this, search_list);
2692 void *param=(void *)3;
2694 if (! strcmp(wm->name,"Country"))
2696 if (! strcmp(wm->name,"Street"))
2698 if (! strcmp(wm->name,"House number"))
2700 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2702 gui_internal_search_idle_end(this);
2703 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2704 struct attr search_attr;
2707 if (! strcmp(wm->name,"Country"))
2708 search_attr.type=attr_country_all;
2709 if (! strcmp(wm->name,"Town"))
2710 search_attr.type=attr_town_or_district_name;
2711 if (! strcmp(wm->name,"Street"))
2712 search_attr.type=attr_street_name;
2713 if (! strcmp(wm->name,"House number"))
2714 search_attr.type=attr_house_number;
2715 search_attr.u.str=wm->text;
2716 search_list_search(this->sl, &search_attr, 1);
2717 gui_internal_search_idle_start(this, wm->name, search_list, param);
2719 l=g_list_last(this->root.children);
2720 gui_internal_widget_render(this, l->data);
2723 static struct widget *
2724 gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w, int h)
2727 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2728 NULL, gravity_center|orientation_vertical, func, data));
2729 wk->data_free=data_free;
2730 wk->background=this->background;
2738 static struct widget *
2739 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2741 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2744 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2746 // Some macros that make the keyboard layout easier to visualise in
2747 // the source code. The macros are #undef'd after this function.
2748 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2749 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h)
2750 static struct widget *
2751 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2753 struct widget *wkbd,*wk;
2754 struct menu_data *md=gui_internal_menu_data(this);
2755 int i, max_w=this->root.w, max_h=this->root.h;
2761 gui_internal_highlight(this);
2763 gui_internal_widget_children_destroy(this, wkbdb);
2765 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2767 md->keyboard_mode=mode;
2768 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2769 wkbd->background=this->background;
2776 if (mode >= 0 && mode < 8) {
2777 for (i = 0 ; i < 26 ; i++) {
2778 char text[]={'A'+i,'\0'};
2781 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2788 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2790 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2793 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2795 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2797 if (mode >= 8 && mode < 16) {
2798 for (i = 0 ; i < 26 ; i++) {
2799 char text[]={'a'+i,'\0'};
2802 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2809 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2811 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2814 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2816 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2818 if (mode >= 16 && mode < 24) {
2819 for (i = 0 ; i < 10 ; i++) {
2820 char text[]={'0'+i,'\0'};
2823 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
2824 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
2826 for (i = 0 ; i < 5 ; i++) SPACER();
2834 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2836 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2839 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2841 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2843 if (mode >= 24 && mode < 32) {
2844 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
2845 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
2846 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
2847 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
2849 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2852 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2854 if (mode >= 32 && mode < 40) {
2855 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
2856 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
2857 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
2858 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
2860 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2863 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2865 gui_internal_widget_append(wkbdb, wkbd);
2867 gui_internal_widget_pack(this, wkbdb);
2868 gui_internal_widget_render(this, wkbdb);
2875 static struct widget *
2876 gui_internal_keyboard(struct gui_priv *this, int mode)
2878 if (! this->keyboard)
2880 return gui_internal_keyboard_do(this, NULL, mode);
2884 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2886 gui_internal_keyboard_do(this, key->data, key->datai);
2890 gui_internal_search_list_set_default_country(struct gui_priv *this)
2892 struct attr search_attr, country_name, country_iso2, *country_attr;
2894 struct country_search *cs;
2895 struct tracking *tracking;
2896 struct search_list_result *res;
2898 country_attr=country_default();
2899 tracking=navit_get_tracking(this->nav);
2900 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
2901 country_attr=&search_attr;
2903 cs=country_search_new(country_attr, 0);
2904 item=country_search_get_item(cs);
2905 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2906 search_attr.type=attr_country_all;
2907 dbg(0,"country %s\n", country_name.u.str);
2908 search_attr.u.str=country_name.u.str;
2909 search_list_search(this->sl, &search_attr, 0);
2910 while((res=search_list_get_result(this->sl)));
2911 g_free(this->country_iso2);
2912 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2913 this->country_iso2=g_strdup(country_iso2.u.str);
2915 country_search_destroy(cs);
2917 dbg(0,"warning: no default country found\n");
2918 if (this->country_iso2) {
2919 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2920 search_attr.type=attr_country_iso2;
2921 search_attr.u.str=this->country_iso2;
2922 search_list_search(this->sl, &search_attr, 0);
2923 while((res=search_list_get_result(this->sl)));
2929 gui_internal_search_list_new(struct gui_priv *this)
2931 struct mapset *ms=navit_get_mapset(this->nav);
2933 this->sl=search_list_new(ms);
2934 gui_internal_search_list_set_default_country(this);
2939 gui_internal_search_list_destroy(struct gui_priv *this)
2942 search_list_destroy(this->sl);
2949 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2951 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2953 gui_internal_search_list_new(this);
2954 wb=gui_internal_menu(this, what);
2955 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2956 gui_internal_widget_append(wb, w);
2957 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2958 gui_internal_widget_append(w, wr);
2959 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2960 gui_internal_widget_append(wr, we);
2962 if (!strcmp(type,"Country")) {
2963 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2964 wnext->func=gui_internal_search_town;
2965 } else if (!strcmp(type,"Town")) {
2966 if (this->country_iso2) {
2967 #if HAVE_API_ANDROID
2968 char country_iso2[strlen(this->country_iso2)+1];
2969 strtolower(country_iso2, this->country_iso2);
2970 country=g_strdup_printf("country_%s", country_iso2);
2972 country=g_strdup_printf("country_%s", this->country_iso2);
2975 country=strdup("gui_select_country");
2976 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
2977 wb->state |= STATE_SENSITIVE;
2979 wb->func = gui_internal_search_country;
2981 wb->func = gui_internal_back;
2982 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
2983 wnext->func=gui_internal_search_street;
2985 } else if (!strcmp(type,"Street")) {
2986 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
2987 wb->state |= STATE_SENSITIVE;
2988 wb->func = gui_internal_back;
2989 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
2990 wnext->func=gui_internal_search_house_number;
2991 } else if (!strcmp(type,"House number")) {
2992 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
2993 wb->state |= STATE_SENSITIVE;
2994 wb->func = gui_internal_back;
2996 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2998 gui_internal_widget_append(we, wnext);
2999 wnext->state |= STATE_SENSITIVE;
3001 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3002 gui_internal_widget_append(wr, wl);
3003 gui_internal_menu_data(this)->search_list=wl;
3004 wk->state |= STATE_EDIT;
3005 wk->background=this->background;
3006 wk->flags |= flags_expand|flags_fill;
3007 wk->func = gui_internal_search_changed;
3008 wk->name=g_strdup(type);
3010 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3011 gui_internal_menu_render(this);
3015 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3017 search_list_select(this->sl, attr_street_name, 0, 0);
3018 gui_internal_search(this,_("House number"),"House number",0);
3022 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3024 dbg(0,"id %d\n", widget->selection_id);
3025 search_list_select(this->sl, attr_street_name, 0, 0);
3026 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3027 gui_internal_search(this,_("House number"),"House number",0);
3031 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3033 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3034 gui_internal_search(this,_("Street"),"Street",0);
3038 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3040 dbg(0,"id %d\n", widget->selection_id);
3041 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3042 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3043 gui_internal_search(this,_("Street"),"Street",0);
3047 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3050 search_list_select(this->sl, attr_country_all, 0, 0);
3051 g_free(this->country_iso2);
3052 this->country_iso2=NULL;
3053 gui_internal_search(this,_("Town"),"Town",0);
3057 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3059 struct search_list_common *slc;
3060 dbg(0,"id %d\n", widget->selection_id);
3061 search_list_select(this->sl, attr_country_all, 0, 0);
3062 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3064 g_free(this->country_iso2);
3065 this->country_iso2=((struct search_list_country *)slc)->iso2;
3067 gui_internal_search(this,widget->name,"Town",0);
3071 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3073 gui_internal_prune_menu_count(this, 1, 0);
3074 gui_internal_search(this,_("Country"),"Country",0);
3078 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3081 search_list_select(this->sl, attr_country_all, 0, 0);
3082 gui_internal_search(this,_("Town"),"Town",1);
3086 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3089 struct widget *w,*wb,*wl;
3090 struct attr_iter *iter;
3093 wb=gui_internal_menu(this, _("Layout"));
3094 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3095 w->spy=this->spacing*3;
3096 gui_internal_widget_append(wb, w);
3097 iter=navit_attr_iter_new();
3098 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3099 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3101 gui_internal_widget_append(w, wl);
3103 navit_attr_iter_destroy(iter);
3104 gui_internal_menu_render(this);
3108 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3111 navit.type=attr_navit;
3112 navit.u.navit=this->nav;
3113 navit_destroy(navit.u.navit);
3114 config_remove_attr(config, &navit);
3115 event_main_loop_quit();
3119 gui_internal_window_closed(struct gui_priv *this)
3121 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3125 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3127 navit_set_destination(this->nav, NULL, NULL, 0);
3132 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3134 struct attr attr, on, off, description, type, data;
3135 struct widget *w,*wb,*wma;
3137 struct attr_iter *iter;
3140 wb=gui_internal_menu(this, _("Maps"));
3141 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3142 w->spy=this->spacing*3;
3143 gui_internal_widget_append(wb, w);
3144 iter=navit_attr_iter_new();
3145 on.type=off.type=attr_active;
3148 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3149 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3150 label=g_strdup(description.u.str);
3152 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3154 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3156 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3158 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3159 attr.u.map, &on, &off, 1);
3160 gui_internal_widget_append(w, wma);
3163 navit_attr_iter_destroy(iter);
3164 gui_internal_menu_render(this);
3168 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3170 struct attr vehicle = {attr_vehicle,{wm->data}};
3171 navit_set_attr(this->nav, &vehicle);
3175 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3177 struct widget *w,*wb,*row;
3178 struct attr attr,sat_attr;
3179 struct vehicle *v=wm->data;
3182 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3184 wb=gui_internal_menu(this, _("Show Satellite Status"));
3185 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3186 gui_internal_menu_data(this)->redisplay_widget=wm;
3187 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3188 gui_internal_widget_append(wb, w);
3189 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3190 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3191 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3192 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3193 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3194 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3195 gui_internal_widget_append(w,row);
3196 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3197 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3198 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3199 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3200 str=g_strdup_printf("%d", sat_attr.u.num);
3203 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3206 gui_internal_widget_append(w,row);
3208 gui_internal_widget_append(wb, w);
3209 gui_internal_menu_render(this);
3213 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3215 struct widget *w,*wb;
3217 struct vehicle *v=wm->data;
3218 wb=gui_internal_menu(this, _("Show NMEA Data"));
3219 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3220 gui_internal_menu_data(this)->redisplay_widget=wm;
3221 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3222 gui_internal_widget_append(wb, w);
3223 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3224 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3225 gui_internal_menu_render(this);
3229 * A container to hold the selected vehicle and the desired profile in
3232 struct vehicle_and_profilename {
3233 struct vehicle *vehicle;
3238 * Figures out whether the given vehicle is the active vehicle.
3240 * @return true if the vehicle is active, false otherwise.
3243 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3246 struct attr active_vehicle;
3248 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3249 active_vehicle.u.vehicle=NULL;
3251 return active_vehicle.u.vehicle == vehicle;
3255 save_vehicle_xml(struct vehicle *v)
3258 struct attr_iter *iter=vehicle_attr_iter_new();
3262 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3263 if (ATTR_IS_OBJECT(attr.type))
3266 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3270 printf("</vehicle>\n");
3273 vehicle_attr_iter_destroy(iter);
3278 * Reacts to a button press that changes a vehicle's active profile.
3280 * @see gui_internal_add_vehicle_profile
3283 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3284 widget *wm, void *data)
3286 struct vehicle_and_profilename *vapn = data;
3287 struct vehicle *v = vapn->vehicle;
3288 char *profilename = vapn->profilename;
3289 struct attr vehicle_name_attr;
3290 char *vehicle_name = NULL;
3292 // Get the vehicle name
3293 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3294 vehicle_name = vehicle_name_attr.u.str;
3296 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3299 // Change the profile name
3300 struct attr profilename_attr = {attr_profilename, {profilename}};
3301 if(!vehicle_set_attr(v, &profilename_attr)) {
3302 dbg(0, "Unable to set the vehicle's profile name\n");
3305 // Notify Navit that the routing should be re-done if this is the
3307 if (gui_internal_is_active_vehicle(this, v)) {
3308 struct attr vehicle;
3309 vehicle.type=attr_vehicle;
3310 vehicle.u.vehicle=v;
3311 navit_set_attr(this->nav, &vehicle);
3313 save_vehicle_xml(v);
3317 * Adds the vehicle profile to the GUI, allowing the user to pick a
3318 * profile for the currently selected vehicle.
3321 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3322 *parent, struct vehicle *v, struct vehicleprofile *profile)
3324 // Just here to show up in the translation file, nice and close to
3325 // where the translations are actually used.
3326 struct attr profile_attr;
3327 struct attr *attr = NULL;
3329 char *active_profile = NULL;
3332 struct vehicle_and_profilename *context = NULL;
3334 #ifdef ONLY_FOR_TRANSLATION
3335 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3338 // Figure out the profile name
3339 attr = attr_search(profile->attrs, NULL, attr_name);
3342 // Determine whether the profile is the active one
3343 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3344 active_profile = profile_attr.u.str;
3345 active = strcmp(name, active_profile) == 0;
3347 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3348 active_profile, active);
3350 // Build a translatable label.
3352 label = g_strdup_printf(_("Current profile: %s"), _(name));
3354 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3357 // Create the context object (the vehicle and the desired profile)
3358 context = g_new0(struct vehicle_and_profilename, 1);
3359 context->vehicle = v;
3360 context->profilename = name;
3363 gui_internal_widget_append(parent,
3364 gui_internal_button_new_with_callback(
3366 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3367 gravity_left_center|orientation_horizontal|flags_fill,
3368 gui_internal_cmd_set_active_profile, context));
3374 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3376 struct widget *w,*wb;
3378 struct vehicle *v=wm->data;
3379 struct vehicleprofile *profile = NULL;
3381 wb=gui_internal_menu(this, wm->text);
3382 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3383 gui_internal_widget_append(wb, w);
3385 // Add the "Set as active" button if this isn't the active
3387 if (!gui_internal_is_active_vehicle(this, v)) {
3388 gui_internal_widget_append(w,
3389 gui_internal_button_new_with_callback(this, _("Set as active"),
3390 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3391 gui_internal_cmd_set_active_vehicle, wm->data));
3394 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3395 gui_internal_widget_append(w,
3396 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3397 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3398 gui_internal_cmd_show_satellite_status, wm->data));
3400 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3401 gui_internal_widget_append(w,
3402 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3403 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3404 gui_internal_cmd_show_nmea_data, wm->data));
3407 // Add all the possible vehicle profiles to the menu
3408 GList *profiles = navit_get_vehicleprofiles(this->nav);
3410 profile = (struct vehicleprofile *)profiles->data;
3411 gui_internal_add_vehicle_profile(this, w, v, profile);
3412 profiles = g_list_next(profiles);
3415 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3416 gui_internal_menu_render(this);
3420 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3422 struct attr attr,vattr;
3423 struct widget *w,*wb,*wl;
3424 struct attr_iter *iter;
3425 struct attr active_vehicle;
3428 wb=gui_internal_menu(this, _("Vehicle"));
3429 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3430 w->spy=this->spacing*3;
3431 gui_internal_widget_append(wb, w);
3432 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3433 active_vehicle.u.vehicle=NULL;
3434 iter=navit_attr_iter_new();
3435 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3436 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3437 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3438 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3439 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3440 wl->text=g_strdup(vattr.u.str);
3441 gui_internal_widget_append(w, wl);
3443 navit_attr_iter_destroy(iter);
3444 gui_internal_menu_render(this);
3449 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3451 struct widget *wb,*w;
3453 wb=gui_internal_menu(this, _("Rules"));
3454 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3455 w->spy=this->spacing*3;
3456 gui_internal_widget_append(wb, w);
3459 on.type=off.type=attr_tracking;
3460 gui_internal_widget_append(w,
3461 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3465 on.type=off.type=attr_orientation;
3466 gui_internal_widget_append(w,
3467 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3471 on.type=off.type=attr_follow_cursor;
3472 gui_internal_widget_append(w,
3473 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3475 gui_internal_menu_render(this);
3478 //##############################################################################################################
3481 //# Authors: Martin Schaller (04/2008)
3482 //##############################################################################################################
3483 static void gui_internal_motion(void *data, struct point *p)
3486 struct gui_priv *this=data;
3487 if (!this->root.children) {
3488 navit_handle_motion(this->nav, p);
3494 if(!this->motion_timeout_callback)
3495 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3496 if(!this->motion_timeout_event)
3497 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3501 find_attr(const char **names, const char **values, const char *name)
3504 if (!strcasecmp(*names, name))
3506 names+=xml_attr_distance;
3507 values+=xml_attr_distance;
3513 find_attr_dup(const char **names, const char **values, const char *name)
3515 return g_strdup(find_attr(names, values, name));
3519 gui_internal_evaluate(struct gui_priv *this, const char *command)
3522 command_evaluate(&this->self, command);
3527 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
3529 gui_internal_evaluate(this,w->command);
3533 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
3535 if (w->command && w->command[0] == '#') {
3536 dbg(1,"href=%s\n",w->command);
3537 gui_internal_html_menu(this, this->html_text, w->command+1);
3543 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
3545 struct gui_priv *this=data;
3547 enum html_tag tag=html_tag_none;
3548 struct html *html=&this->html[this->html_depth];
3549 const char *src, *cond;
3551 if (!strcasecmp(tag_name,"text"))
3557 cond=find_attr(names, values, "cond");
3559 if (cond && !this->html_skip) {
3560 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
3564 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
3565 if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
3566 tag=html_tag_map[i].tag;
3571 if (!this->html_skip && !html->skip) {
3574 html->name=find_attr_dup(names, values, "name");
3576 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
3578 this->html_anchor_found=1;
3580 html->href=find_attr_dup(names, values, "href");
3583 html->command=find_attr_dup(names, values, "onclick");
3584 src=find_attr(names, values, "src");
3586 html->w=gui_internal_image_new(this, image_new_l(this, src));
3592 this->html_skip+=html->skip;
3597 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
3599 struct gui_priv *this=data;
3601 struct html *parent=NULL;
3603 if (!strcasecmp(tag_name,"text"))
3606 html=&this->html[this->html_depth];
3607 if (this->html_depth > 0)
3608 parent=&this->html[this->html_depth-1];
3611 if (!this->html_skip) {
3612 if (html->command && html->w) {
3613 html->w->state |= STATE_SENSITIVE;
3614 html->w->command=html->command;
3615 html->w->func=gui_internal_html_command;
3618 if (parent && parent->href && html->w) {
3619 html->w->state |= STATE_SENSITIVE;
3620 html->w->command=g_strdup(parent->href);
3621 html->w->func=gui_internal_html_href;
3623 switch (html->tag) {
3625 gui_internal_widget_append(this->html_container, html->w);
3631 this->html_skip-=html->skip;
3632 g_free(html->command);
3638 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
3640 struct gui_priv *this=data;
3642 int depth=this->html_depth-1;
3643 struct html *html=&this->html[depth];
3644 char *text_stripped;
3646 if (this->html_skip)
3648 while (isspace(text[0])) {
3652 while (len > 0 && isspace(text[len-1]))
3654 text_stripped=g_malloc(len+1);
3655 strncpy(text_stripped, text, len);
3656 text_stripped[len]='\0';
3657 if (html->tag == html_tag_html && depth > 2) {
3658 if (this->html[depth-1].tag == html_tag_script) {
3659 html=&this->html[depth-2];
3662 switch (html->tag) {
3664 if (html->name && len) {
3665 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3666 this->html_container->spx=this->spacing*10;
3670 if (!this->html_container) {
3671 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3672 this->html_container->spx=this->spacing*10;
3677 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
3678 gui_internal_widget_append(w, html->w);
3679 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
3683 case html_tag_script:
3684 dbg(1,"execute %s\n",text_stripped);
3685 gui_internal_evaluate(this,text_stripped);
3693 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
3695 graphics_draw_mode(this->gra, draw_mode_begin);
3696 this->html_container=NULL;
3698 this->html_anchor=anchor;
3699 this->html_anchor_found=0;
3700 xml_parse_text(document, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
3701 gui_internal_menu_render(this);
3702 graphics_draw_mode(this->gra, draw_mode_end);
3706 static void gui_internal_menu_root(struct gui_priv *this)
3708 gui_internal_html_menu(this, this->html_text, "Main Menu");
3712 gui_internal_enter(struct gui_priv *this, int ignore)
3714 struct graphics *gra=this->gra;
3715 this->ignore_button=ignore;
3716 this->clickp_valid=this->vehicle_valid=0;
3718 navit_block(this->nav, 1);
3719 graphics_overlay_disable(gra, 1);
3722 this->root.background=this->background;
3726 gui_internal_leave(struct gui_priv *this)
3728 graphics_draw_mode(this->gra, draw_mode_end);
3732 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3734 struct transformation *trans;
3737 struct attr attr,attrp;
3740 gui_internal_enter(this, ignore);
3741 trans=navit_get_trans(this->nav);
3742 attr_free(this->click_coord_geo);
3743 this->click_coord_geo=NULL;
3744 attr_free(this->position_coord_geo);
3745 this->position_coord_geo=NULL;
3747 transform_reverse(trans, p, &c);
3748 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
3749 this->clickp.pro=transform_get_projection(trans);
3752 transform_to_geo(this->clickp.pro, &c, &g);
3753 attr.u.coord_geo=&g;
3754 attr.type=attr_click_coord_geo;
3755 this->click_coord_geo=attr_dup(&attr);
3757 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3758 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3759 this->position_coord_geo=attr_dup(&attrp);
3760 this->vehiclep.pro=transform_get_projection(trans);
3761 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3762 this->vehiclep.x=c.x;
3763 this->vehiclep.y=c.y;
3764 this->vehicle_valid=1;
3767 gui_internal_menu_root(this);
3771 gui_internal_cmd_menu2(struct gui_priv *this)
3773 gui_internal_cmd_menu(this, NULL, 1);
3778 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
3780 if (widget->text && strlen(widget->text))
3781 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
3782 g_free(widget->text);
3784 gui_internal_prune_menu(this, NULL);
3785 gui_internal_check_exit(this);
3789 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
3791 gui_internal_cmd_log_do(this, widget->data);
3795 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
3799 len=strlen(wm->text);
3800 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
3801 wm->text[len-1]='\0';
3802 gui_internal_cmd_log_do(this, wm);
3809 gui_internal_cmd_log(struct gui_priv *this)
3811 struct widget *w,*wb,*wk,*wl,*we,*wnext;
3812 gui_internal_enter(this, 1);
3813 wb=gui_internal_menu(this, "Log Message");
3814 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3815 gui_internal_widget_append(wb, w);
3816 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3817 gui_internal_widget_append(w, we);
3818 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
3819 wk->state |= STATE_EDIT|STATE_CLEAR;
3820 wk->background=this->background;
3821 wk->flags |= flags_expand|flags_fill;
3822 wk->func = gui_internal_cmd_log_changed;
3823 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3824 wnext->state |= STATE_SENSITIVE;
3825 wnext->func = gui_internal_cmd_log_clicked;
3827 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3828 gui_internal_widget_append(w, wl);
3830 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3831 gui_internal_menu_render(this);
3832 gui_internal_leave(this);
3836 gui_internal_check_exit(struct gui_priv *this)
3838 struct graphics *gra=this->gra;
3839 if (! this->root.children) {
3840 gui_internal_search_idle_end(this);
3841 gui_internal_search_list_destroy(this);
3842 graphics_overlay_disable(gra, 0);
3843 if (!navit_block(this->nav, 0)) {
3845 navit_draw(this->nav);
3847 navit_draw_displaylist(this->nav);
3853 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
3857 attr->u.num=this->root.children != NULL;
3859 case attr_click_coord_geo:
3860 if (!this->click_coord_geo)
3862 *attr=*this->click_coord_geo;
3864 case attr_position_coord_geo:
3865 if (!this->position_coord_geo)
3867 *attr=*this->position_coord_geo;
3870 attr->u.num=this->pitch;
3880 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
3882 switch (attr->type) {
3884 g_free(this->html_text);
3885 this->html_text=g_strdup(attr->u.str);
3893 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
3895 switch (attr->type) {
3896 case attr_fullscreen:
3897 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
3898 graphics_draw_mode(this->gra, draw_mode_end);
3899 this->win->fullscreen(this->win, attr->u.num > 0);
3900 graphics_draw_mode(this->gra, draw_mode_begin);
3902 this->fullscreen=attr->u.num;
3905 dbg(0,"%s\n",attr_to_name(attr->type));
3911 //##############################################################################################################
3912 //# Description: Function to handle mouse clicks and scroll wheel movement
3914 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3915 //##############################################################################################################
3916 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3918 struct gui_priv *this=data;
3919 struct graphics *gra=this->gra;
3921 dbg(1,"enter %d %d\n", pressed, button);
3922 // if still on the map (not in the menu, yet):
3923 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
3924 if (!this->root.children || this->ignore_button) {
3925 this->ignore_button=0;
3926 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3927 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
3928 dbg(1,"navit has handled button\n");
3931 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
3932 if (this->menu_on_map_click && button == 1)
3933 gui_internal_cmd_menu(this, p, 0);
3938 // if already in the menu:
3942 gui_internal_highlight(this);
3947 graphics_draw_mode(gra, draw_mode_begin);
3948 gui_internal_call_highlighted(this);
3949 gui_internal_highlight(this);
3950 graphics_draw_mode(gra, draw_mode_end);
3951 gui_internal_check_exit(this);
3956 gui_internal_setup_gc(struct gui_priv *this)
3958 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
3959 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
3960 struct graphics *gra=this->gra;
3962 if (this->background)
3964 this->background=graphics_gc_new(gra);
3965 this->background2=graphics_gc_new(gra);
3966 this->highlight_background=graphics_gc_new(gra);
3967 graphics_gc_set_foreground(this->highlight_background, &cbh);
3968 this->foreground=graphics_gc_new(gra);
3969 graphics_gc_set_foreground(this->foreground, &cf);
3970 this->text_background=graphics_gc_new(gra);
3971 this->text_foreground=graphics_gc_new(gra);
3972 graphics_gc_set_foreground(this->background, &this->background_color);
3973 graphics_gc_set_foreground(this->background2, &this->background2_color);
3974 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
3975 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
3978 //##############################################################################################################
3981 //# Authors: Martin Schaller (04/2008)
3982 //##############################################################################################################
3983 static void gui_internal_resize(void *data, int w, int h)
3985 struct gui_priv *this=data;
3988 gui_internal_setup_gc(this);
3990 if (this->root.w != w || this->root.h != h) {
3995 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
3996 navit_handle_resize(this->nav, w, h);
3997 if (this->root.children && changed) {
3998 gui_internal_prune_menu(this, NULL);
3999 gui_internal_menu_root(this);
4004 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
4019 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
4021 GList *l=wi->children;
4022 if (wi->state & STATE_SENSITIVE) {
4025 gui_internal_keynav_point(wi, -dx, -dy, &wp);
4027 dist1=(wp.x-p->x)*dx;
4030 dist1=(wp.y-p->y)*dy;
4038 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);
4044 if (dist1 < *distance) {
4051 struct widget *child=l->data;
4052 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
4058 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
4060 struct widget *result,*menu=g_list_last(this->root.children)->data;
4063 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4064 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
4070 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
4072 gui_internal_keynav_point(result, dx, dy, &p);
4073 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
4078 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4079 dbg(1,"result=%p\n", result);
4091 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4092 dbg(1,"wraparound result=%p\n", result);
4094 gui_internal_highlight_do(this, result);
4096 gui_internal_say(this, result, 1);
4099 //##############################################################################################################
4102 //# Authors: Martin Schaller (04/2008)
4103 //##############################################################################################################
4104 static void gui_internal_keypress(void *data, char *key)
4106 struct gui_priv *this=data;
4109 if (!this->root.children) {
4110 transform_get_size(navit_get_trans(this->nav), &w, &h);
4115 navit_set_center_screen(this->nav, &p, 1);
4117 case NAVIT_KEY_DOWN:
4120 navit_set_center_screen(this->nav, &p, 1);
4122 case NAVIT_KEY_LEFT:
4125 navit_set_center_screen(this->nav, &p, 1);
4127 case NAVIT_KEY_RIGHT:
4130 navit_set_center_screen(this->nav, &p, 1);
4132 case NAVIT_KEY_ZOOM_IN:
4133 navit_zoom_in(this->nav, 2, NULL);
4135 case NAVIT_KEY_ZOOM_OUT:
4136 navit_zoom_out(this->nav, 2, NULL);
4138 case NAVIT_KEY_RETURN:
4139 case NAVIT_KEY_MENU:
4140 gui_internal_cmd_menu(this, NULL, 0);
4145 graphics_draw_mode(this->gra, draw_mode_begin);
4147 case NAVIT_KEY_LEFT:
4148 gui_internal_keynav_highlight_next(this,-1,0);
4150 case NAVIT_KEY_RIGHT:
4151 gui_internal_keynav_highlight_next(this,1,0);
4154 gui_internal_keynav_highlight_next(this,0,-1);
4156 case NAVIT_KEY_DOWN:
4157 gui_internal_keynav_highlight_next(this,0,1);
4159 case NAVIT_KEY_BACK:
4161 case NAVIT_KEY_RETURN:
4162 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4163 gui_internal_call_highlighted(this);
4165 gui_internal_keypress_do(this, key);
4168 gui_internal_keypress_do(this, key);
4170 graphics_draw_mode(this->gra, draw_mode_end);
4171 gui_internal_check_exit(this);
4175 //##############################################################################################################
4178 //# Authors: Martin Schaller (04/2008)
4179 //##############################################################################################################
4180 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4183 struct transformation *trans=navit_get_trans(this->nav);
4185 win=graphics_get_data(gra, "window");
4188 navit_ignore_graphics_events(this->nav, 1);
4191 navit_ignore_graphics_events(this->nav, 1);
4192 transform_get_size(trans, &this->root.w, &this->root.h);
4193 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4194 graphics_add_callback(gra, this->resize_cb);
4195 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4196 graphics_add_callback(gra, this->button_cb);
4197 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4198 graphics_add_callback(gra, this->motion_cb);
4199 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4200 graphics_add_callback(gra, this->keypress_cb);
4201 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
4202 graphics_add_callback(gra, this->window_closed_cb);
4204 // set fullscreen if needed
4205 if (this->fullscreen)
4206 this->win->fullscreen(this->win, this->fullscreen != 0);
4207 /* Was resize callback already issued? */
4208 if (navit_get_ready(this->nav) & 2)
4209 gui_internal_setup_gc(this);
4213 static void gui_internal_disable_suspend(struct gui_priv *this)
4215 if (this->win->disable_suspend)
4216 this->win->disable_suspend(this->win);
4219 //##############################################################################################################
4222 //# Authors: Martin Schaller (04/2008)
4223 //##############################################################################################################
4224 struct gui_methods gui_internal_methods = {
4227 gui_internal_set_graphics,
4231 gui_internal_disable_suspend,
4232 gui_internal_get_attr,
4233 gui_internal_add_attr,
4234 gui_internal_set_attr,
4238 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4240 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4242 *out=attr_generic_add_attr(*out, &private_data);
4246 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4248 callback_list_add(priv->cbl, cb);
4252 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4254 callback_list_remove(priv->cbl, cb);
4258 static struct gui_internal_methods gui_internal_methods_ext = {
4259 gui_internal_add_callback,
4260 gui_internal_remove_callback,
4261 gui_internal_menu_render,
4268 gui_internal_get_flags(struct widget *widget)
4270 return widget->flags;
4274 gui_internal_set_flags(struct widget *widget, enum flags flags)
4276 widget->flags=flags;
4280 gui_internal_get_state(struct widget *widget)
4282 return widget->state;
4286 gui_internal_set_state(struct widget *widget, int state)
4288 widget->state=state;
4292 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4298 gui_internal_set_data(struct widget *widget, void *data)
4304 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4306 widget->background=this->background;
4309 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4310 gui_internal_widget_append,
4311 gui_internal_button_new,
4312 gui_internal_button_new_with_callback,
4313 gui_internal_box_new,
4314 gui_internal_label_new,
4315 gui_internal_image_new,
4316 gui_internal_keyboard,
4318 gui_internal_get_flags,
4319 gui_internal_set_flags,
4320 gui_internal_get_state,
4321 gui_internal_set_state,
4322 gui_internal_set_func,
4323 gui_internal_set_data,
4324 gui_internal_set_default_background,
4328 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
4330 char *str=NULL,*str2=NULL;
4331 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
4334 dbg(1,"%s\n",attr_to_name(in[0]->type));
4335 if (ATTR_IS_STRING(in[0]->type)) {
4338 if (ATTR_IS_COORD_GEO(in[0]->type)) {
4339 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
4342 str=g_strdup_printf("<html>%s</html>\n",str);
4343 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4351 * @brief Creates a new table widget.
4353 * Creates and returns a new table widget. This function will
4354 * setup next/previous buttons as children.
4356 * @param this The graphics context.
4357 * @param flags widget sizing flags.
4358 * @returns The newly created widget
4360 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4362 struct widget * widget = g_new0(struct widget,1);
4363 struct table_data * data = NULL;
4364 widget->type=widget_table;
4365 widget->flags=flags;
4366 widget->data = g_new0(struct table_data,1);
4367 widget->data_free=gui_internal_table_data_free;
4368 data = (struct table_data*)widget->data;
4372 data->next_button = gui_internal_button_new_with_callback
4373 (this,"Next",image_new_xs(this, "gui_active") ,
4374 gravity_left_center |orientation_vertical,
4375 gui_internal_table_button_next,NULL);
4376 data->next_button->data=widget;
4379 data->prev_button = gui_internal_button_new_with_callback
4381 image_new_xs(this, "gui_active")
4382 ,gravity_right_center |orientation_vertical,
4383 gui_internal_table_button_prev,NULL);
4385 data->prev_button->data=widget;
4389 data->button_box=gui_internal_box_new(this,
4390 gravity_center|orientation_horizontal);
4391 data->button_box->children=g_list_append(data->button_box->children,
4393 data->button_box->children=g_list_append(data->button_box->children,
4395 //data->button_box->background=this->background2;
4396 data->button_box->bl=this->spacing;
4397 widget->children=g_list_append(widget->children,data->button_box);
4398 gui_internal_widget_pack(this,data->button_box);
4406 * @brief Clears all the rows from the table.
4407 * This function removes all rows from a table.
4408 * New rows can later be added to the table.
4410 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4413 struct table_data * table_data = (struct table_data* ) table->data;
4415 iter = table->children;
4417 if(iter->data != table_data->button_box) {
4418 struct widget * child = (struct widget*)iter->data;
4419 gui_internal_widget_destroy(this,child);
4420 if(table->children == iter) {
4421 table->children = g_list_remove(iter,iter->data);
4422 iter=table->children;
4425 iter = g_list_remove(iter,iter->data);
4428 iter = g_list_next(iter);
4432 table_data->top_row=NULL;
4433 table_data->bottom_row=NULL;
4434 if(table_data->page_headers)
4435 g_list_free(table_data->page_headers);
4436 table_data->page_headers=NULL;
4441 * Creates a new table_row widget.
4442 * @param this The graphics context
4443 * @param flags Sizing flags for the row
4444 * @returns The new table_row widget.
4446 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4448 struct widget * widget = g_new0(struct widget,1);
4449 widget->type=widget_table_row;
4450 widget->flags=flags;
4457 * @brief Computes the column dimensions for the table.
4459 * @param w The table widget to compute dimensions for.
4461 * This function examines all of the rows and columns for the table w
4462 * and returns a list (GList) of table_column_desc elements that
4463 * describe each column of the table.
4465 * The caller is responsible for freeing the returned list.
4467 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4470 GList * column_desc = NULL;
4471 GList * current_desc=NULL;
4472 GList * cur_row = w->children;
4473 struct widget * cur_row_widget=NULL;
4474 GList * cur_column=NULL;
4475 struct widget * cell_w=NULL;
4476 struct table_column_desc * current_cell=NULL;
4477 struct table_data * table_data=NULL;
4484 * Scroll through the the table and
4485 * 1. Compute the maximum width + height of each column across all rows.
4487 table_data = (struct table_data*) w->data;
4488 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4490 cur_row_widget = (struct widget*) cur_row->data;
4491 current_desc = column_desc;
4492 if(cur_row_widget == table_data->button_box)
4497 for(cur_column = cur_row_widget->children; cur_column;
4498 cur_column=g_list_next(cur_column))
4500 cell_w = (struct widget*) cur_column->data;
4501 gui_internal_widget_pack(this,cell_w);
4502 if(current_desc == 0)
4504 current_cell = g_new0(struct table_column_desc,1);
4505 column_desc = g_list_append(column_desc,current_cell);
4506 current_desc = g_list_last(column_desc);
4507 current_cell->height=cell_w->h;
4508 current_cell->width=cell_w->w;
4509 total_width+=cell_w->w;
4514 current_cell = current_desc->data;
4517 if(current_cell->height < height )
4519 current_cell->height = height;
4521 if(current_cell->width < width)
4523 total_width += (width-current_cell->width);
4524 current_cell->width = width;
4529 current_desc = g_list_next(current_desc);
4539 * If the width of all columns is less than the width off
4540 * the table expand each cell proportionally.
4543 if(total_width+(this->spacing*column_count) < w->w ) {
4544 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4545 current_cell = (struct table_column_desc*) current_desc->data;
4546 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4555 * @brief Computes the height and width for the table.
4557 * The height and widht are computed to display all cells in the table
4558 * at the requested height/width.
4560 * @param this The graphics context
4561 * @param w The widget to pack.
4564 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4570 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4572 struct table_column_desc * cell_desc=0;
4573 struct table_data * table_data = (struct table_data*)w->data;
4575 for(current = column_data; current; current=g_list_next(current))
4577 if(table_data->button_box == current->data )
4581 cell_desc = (struct table_column_desc *) current->data;
4582 width = width + cell_desc->width + this->spacing;
4583 if(height < cell_desc->height)
4585 height = cell_desc->height ;
4591 for(current=w->children; current; current=g_list_next(current))
4593 if(current->data!= table_data->button_box)
4598 if (table_data->button_box)
4599 gui_internal_widget_pack(this,table_data->button_box);
4603 if(w->h + w->c.y > this->root.h )
4606 * Do not allow the widget to exceed the screen.
4609 w->h = this->root.h- w->c.y - height;
4614 * Deallocate column descriptions.
4616 current = column_data;
4617 while( (current = g_list_last(current)) )
4619 current = g_list_remove(current,current->data);
4627 * @brief Renders a table widget.
4629 * @param this The graphics context
4630 * @param w The table widget to render.
4632 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4637 GList * column_desc=NULL;
4638 GList * cur_row = NULL;
4639 GList * current_desc=NULL;
4640 struct table_data * table_data = (struct table_data*)w->data;
4642 int is_first_page=1;
4643 struct table_column_desc * dim=NULL;
4645 dbg_assert(table_data);
4646 column_desc = gui_internal_compute_table_dimensions(this,w);
4650 * Skip rows that are on previous pages.
4652 cur_row = w->children;
4653 if(table_data->top_row && table_data->top_row != w->children )
4655 cur_row = table_data->top_row;
4661 * Loop through each row. Drawing each cell with the proper sizes,
4662 * at the proper positions.
4664 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4666 GList * cur_column=NULL;
4667 current_desc = column_desc;
4668 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4670 x =w->p.x+this->spacing;
4671 if(cur_row_widget == table_data->button_box )
4675 dim = (struct table_column_desc*)current_desc->data;
4677 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4680 * No more drawing space left.
4686 for(cur_column = cur_row_widget->children; cur_column;
4687 cur_column=g_list_next(cur_column))
4689 struct widget * cur_widget = (struct widget*) cur_column->data;
4690 dim = (struct table_column_desc*)current_desc->data;
4693 cur_widget->w=dim->width;
4695 cur_widget->h=dim->height;
4697 max_height = dim->height;
4698 /* We pack the widget before rendering to ensure that the x and y
4699 * coordinates get pushed down.
4701 gui_internal_widget_pack(this,cur_widget);
4702 gui_internal_widget_render(this,cur_widget);
4704 if(dim->height > max_height)
4706 max_height = dim->height;
4710 table_data->bottom_row=cur_row;
4711 current_desc = g_list_next(current_desc);
4713 if(table_data->button_box && (is_skipped || !is_first_page) )
4715 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4717 if(table_data->button_box->p.y < y )
4719 table_data->button_box->p.y=y;
4721 table_data->button_box->p.x = w->p.x;
4722 table_data->button_box->w = w->w;
4723 // table_data->button_box->h = w->h - y;
4724 // table_data->next_button->h=table_data->button_box->h;
4725 // table_data->prev_button->h=table_data->button_box->h;
4726 // table_data->next_button->c.y=table_data->button_box->c.y;
4727 // table_data->prev_button->c.y=table_data->button_box->c.y;
4729 gui_internal_widget_pack(this,table_data->button_box);
4730 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4733 table_data->button_box->p.y = w->p.y + w->h -
4734 table_data->button_box->h;
4738 table_data->next_button->state|= STATE_SENSITIVE;
4742 table_data->next_button->state&= ~STATE_SENSITIVE;
4745 if(table_data->top_row != w->children)
4747 table_data->prev_button->state|= STATE_SENSITIVE;
4751 table_data->prev_button->state&= ~STATE_SENSITIVE;
4753 gui_internal_widget_render(this,table_data->button_box);
4759 * Deallocate column descriptions.
4761 current_desc = column_desc;
4762 while( (current_desc = g_list_last(current_desc)) )
4764 current_desc = g_list_remove(current_desc,current_desc->data);
4770 * @brief Displays Route information
4772 * @li The name of the active vehicle
4773 * @param wm The button that was pressed.
4777 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4781 struct widget * menu;
4782 struct widget * row;
4785 if(! this->vehicle_cb)
4788 * Register the callback on vehicle updates.
4790 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4791 attr_position_coord_geo,this);
4792 navit_add_callback(this->nav,this->vehicle_cb);
4795 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4796 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4798 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4801 menu=gui_internal_menu(this,_("Route Description"));
4803 menu->free=gui_internal_route_screen_free;
4804 this->route_data.route_showing=1;
4805 this->route_data.route_table->spx = this->spacing;
4808 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4810 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4811 gui_internal_widget_append(box,this->route_data.route_table);
4813 box->spx = this->spacing;
4814 this->route_data.route_table->w=box->w;
4815 gui_internal_widget_append(menu,box);
4816 gui_internal_populate_route_table(this,this->nav);
4817 gui_internal_menu_render(this);
4822 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4825 int adx=a2->x-a1->x;
4826 int ady=a2->y-a1->y;
4827 int bdx=b2->x-b1->x;
4828 int bdy=b2->y-b1->y;
4829 n = bdy * adx - bdx * ady;
4830 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4831 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4842 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4843 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4844 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4847 res->x = a1->x + a * adx / n;
4848 res->y = a1->y + a * ady / n;
4853 struct heightline *next;
4855 struct coord_rect bbox;
4860 struct diagram_point {
4861 struct diagram_point *next;
4865 static struct heightline *
4866 item_get_heightline(struct item *item)
4868 struct heightline *ret=NULL;
4869 struct street_data *sd;
4873 if (item_attr_get(item, attr_label, &attr)) {
4874 height=atoi(attr.u.str);
4875 sd=street_get_data(item);
4876 if (sd && sd->count > 1) {
4877 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4878 ret->bbox.lu=sd->c[0];
4879 ret->bbox.rl=sd->c[0];
4880 ret->count=sd->count;
4882 for (i = 0 ; i < sd->count ; i++) {
4884 coord_rect_extend(&ret->bbox, sd->c+i);
4887 street_data_free(sd);
4894 * @brief Displays Route Height Profile
4896 * @li The name of the active vehicle
4897 * @param wm The button that was pressed.
4901 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4905 struct widget * menu, *box;
4907 struct map * map=NULL;
4908 struct map_rect * mr=NULL;
4909 struct route * route;
4910 struct item * item =NULL;
4912 struct mapset_handle *msh;
4913 int x,i,first=1,dist=0;
4914 struct coord c,last,res;
4915 struct coord_rect rbbox,dbbox;
4916 struct map_selection sel;
4917 struct heightline *heightline,*heightlines=NULL;
4918 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4921 sel.range.min=type_height_line_1;
4922 sel.range.max=type_height_line_3;
4925 menu=gui_internal_menu(this,_("Height Profile"));
4926 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4927 gui_internal_widget_append(menu, box);
4928 route = navit_get_route(this->nav);
4930 map = route_get_map(route);
4932 mr = map_rect_new(map,NULL);
4934 while((item = map_rect_get_item(mr))) {
4935 while (item_coord_get(item, &c, 1)) {
4941 coord_rect_extend(&sel.u.c_rect, &c);
4944 map_rect_destroy(mr);
4945 ms=navit_get_mapset(this->nav);
4947 msh=mapset_open(ms);
4948 while ((map=mapset_next(msh, 1))) {
4949 mr=map_rect_new(map, &sel);
4951 while((item = map_rect_get_item(mr))) {
4952 if (item->type >= sel.range.min && item->type <= sel.range.max) {
4953 heightline=item_get_heightline(item);
4955 heightline->next=heightlines;
4956 heightlines=heightline;
4960 map_rect_destroy(mr);
4969 map = route_get_map(route);
4971 mr = map_rect_new(map,NULL);
4972 if(mr && heightlines) {
4973 while((item = map_rect_get_item(mr))) {
4975 while (item_coord_get(item, &c, 1)) {
4979 heightline=heightlines;
4982 coord_rect_extend(&rbbox, &c);
4983 while (heightline) {
4984 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
4985 for (i = 0 ; i < heightline->count - 1; i++) {
4986 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
4987 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
4988 diagram_point=g_new(struct diagram_point, 1);
4989 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
4990 diagram_point->c.y=heightline->height;
4991 diagram_point->next=diagram_points;
4992 diagram_points=diagram_point;
4993 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
4998 heightline=heightline->next;
5000 dist+=transform_distance(projection_mg, &last, &c);
5006 map_rect_destroy(mr);
5010 gui_internal_menu_render(this);
5012 diagram_point=diagram_points;
5013 while (diagram_point) {
5015 dbbox.lu=diagram_point->c;
5016 dbbox.rl=diagram_point->c;
5019 coord_rect_extend(&dbbox, &diagram_point->c);
5020 diagram_point=diagram_point->next;
5022 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
5023 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
5025 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
5027 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
5033 diagram_point=diagram_points;
5034 while (diagram_point) {
5035 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
5037 diagram_point=diagram_point->next;
5041 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
5042 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
5043 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
5044 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
5048 graphics_draw_lines(this->gra, this->foreground, p, 2);
5057 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5059 struct widget *menu,*wb,*w;
5062 graphics_draw_mode(this->gra, draw_mode_begin);
5063 menu=gui_internal_menu(this, _("Show Locale"));
5064 menu->spx=this->spacing*10;
5065 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5066 gui_internal_widget_append(menu, wb);
5067 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5068 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5069 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5071 #ifdef HAVE_API_WIN32_BASE
5073 wchar_t wcountry[32],wlang[32];
5074 char country[32],lang[32];
5076 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5077 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5078 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5079 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5080 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5082 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5083 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5084 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5085 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5086 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5091 gui_internal_menu_render(this);
5092 graphics_draw_mode(this->gra, draw_mode_end);
5097 * @brief handles the 'next page' table event.
5098 * A callback function that is invoked when the 'next page' button is pressed
5099 * to advance the contents of a table widget.
5101 * @param this The graphics context.
5102 * @param wm The button widget that was pressed.
5104 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5106 struct widget * table_widget = (struct widget * ) wm->data;
5107 struct table_data * table_data = NULL;
5113 table_data = (struct table_data*) table_widget->data;
5119 * Before advancing to the next page we need to ensure
5120 * that the current top_row is in the list of previous top_rows
5121 * so previous page can work.
5124 for(iterator=table_data->page_headers; iterator != NULL;
5125 iterator = g_list_next(iterator) )
5127 if(iterator->data == table_data->top_row)
5136 table_data->page_headers=g_list_append(table_data->page_headers,
5137 table_data->top_row);
5140 table_data->top_row = g_list_next(table_data->bottom_row);
5142 wm->state&= ~STATE_HIGHLIGHTED;
5143 gui_internal_menu_render(this);
5149 * @brief handles the 'previous page' table event.
5150 * A callback function that is invoked when the 'previous page' button is pressed
5151 * to go back in the contents of a table widget.
5153 * @param this The graphics context.
5154 * @param wm The button widget that was pressed.
5156 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5158 struct widget * table_widget = (struct widget * ) wm->data;
5159 struct table_data * table_data = NULL;
5160 GList * current_page_top=NULL;
5165 table_data = (struct table_data*) table_widget->data;
5168 current_page_top = table_data->top_row;
5169 for(iterator = table_data->page_headers; iterator != NULL;
5170 iterator = g_list_next(iterator))
5172 if(current_page_top == iterator->data)
5176 table_data->top_row = (GList*) iterator->data;
5180 wm->state&= ~STATE_HIGHLIGHTED;
5181 gui_internal_menu_render(this);
5186 * @brief deallocates a table_data structure.
5189 void gui_internal_table_data_free(void * p)
5194 * @note button_box and its children (next_button,prev_button)
5195 * have their memory managed by the table itself.
5197 struct table_data * table_data = (struct table_data*) p;
5198 g_list_free(table_data->page_headers);
5206 * @brief Called when the route is updated.
5208 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5211 if(this->route_data.route_showing) {
5212 gui_internal_populate_route_table(this,navit);
5213 graphics_draw_mode(this->gra, draw_mode_begin);
5214 gui_internal_menu_render(this);
5215 graphics_draw_mode(this->gra, draw_mode_end);
5223 * @brief Called when the route screen is closed (deallocated).
5225 * The main purpose of this function is to remove the widgets from
5226 * references route_data because those widgets are about to be freed.
5228 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5231 this_->route_data.route_showing=0;
5232 this_->route_data.route_table=NULL;
5239 * @brief Populates the route table with route information
5241 * @param this The gui context
5242 * @param navit The navit object
5244 void gui_internal_populate_route_table(struct gui_priv * this,
5245 struct navit * navit)
5247 struct map * map=NULL;
5248 struct map_rect * mr=NULL;
5249 struct navigation * nav = NULL;
5250 struct item * item =NULL;
5252 struct widget * label = NULL;
5253 struct widget * row = NULL;
5254 nav = navit_get_navigation(navit);
5258 map = navigation_get_map(nav);
5260 mr = map_rect_new(map,NULL);
5262 gui_internal_widget_table_clear(this,this->route_data.route_table);
5263 while((item = map_rect_get_item(mr))) {
5264 if(item_attr_get(item,attr_navigation_long,&attr)) {
5265 label = gui_internal_label_new(this,attr.u.str);
5266 row = gui_internal_widget_table_row_new(this,
5269 | orientation_horizontal);
5270 row->children=g_list_append(row->children,label);
5271 gui_internal_widget_append(this->route_data.route_table,row);
5279 static struct command_table commands[] = {
5280 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
5281 {"back",command_cast(gui_internal_cmd2_back)},
5282 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
5283 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
5284 {"get_data",command_cast(gui_internal_get_data)},
5285 {"locale",command_cast(gui_internal_cmd2_locale)},
5286 {"log",command_cast(gui_internal_cmd_log)},
5287 {"menu",command_cast(gui_internal_cmd_menu2)},
5288 {"position",command_cast(gui_internal_cmd2_position)},
5289 {"route_description",command_cast(gui_internal_cmd2_route_description)},
5290 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
5291 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
5292 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
5293 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
5294 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
5295 {"town",command_cast(gui_internal_cmd2_town)},
5296 {"quit",command_cast(gui_internal_cmd2_quit)},
5297 {"write",command_cast(gui_internal_cmd_write)},
5301 //##############################################################################################################
5304 //# Authors: Martin Schaller (04/2008)
5305 //##############################################################################################################
5306 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
5308 struct gui_priv *this;
5310 *meth=gui_internal_methods;
5311 this=g_new0(struct gui_priv, 1);
5314 this->self.type=attr_gui;
5315 this->self.u.gui=gui;
5317 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
5318 this->menu_on_map_click=attr->u.num;
5320 this->menu_on_map_click=1;
5321 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
5322 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
5325 if( (attr=attr_search(attrs,NULL,attr_font_size)))
5327 this->config.font_size=attr->u.num;
5331 this->config.font_size=-1;
5333 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
5335 this->config.icon_xs=attr->u.num;
5339 this->config.icon_xs=-1;
5341 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
5343 this->config.icon_l=attr->u.num;
5347 this->config.icon_l=-1;
5349 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
5351 this->config.icon_s=attr->u.num;
5355 this->config.icon_s=-1;
5357 if( (attr=attr_search(attrs,NULL,attr_spacing)))
5359 this->config.spacing=attr->u.num;
5363 this->config.spacing=-1;
5365 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
5367 this->speech=attr->u.num;
5369 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
5370 this->keyboard=attr->u.num;
5374 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
5375 this->fullscreen=attr->u.num;
5377 if( (attr=attr_search(attrs,NULL,attr_flags)))
5378 this->flags=attr->u.num;
5379 if( (attr=attr_search(attrs,NULL,attr_background_color)))
5380 this->background_color=*attr->u.color;
5382 this->background_color=COLOR_BLACK;
5383 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
5384 this->background2_color=*attr->u.color;
5386 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
5387 if( (attr=attr_search(attrs,NULL,attr_text_color)))
5388 this->text_foreground_color=*attr->u.color;
5390 this->text_foreground_color=COLOR_WHITE;
5391 this->text_background_color=COLOR_BLACK;
5392 if( (attr=attr_search(attrs,NULL,attr_columns)))
5393 this->cols=attr->u.num;
5394 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
5395 this->osd_configuration=*attr;
5397 if( (attr=attr_search(attrs,NULL,attr_pitch)))
5398 this->pitch=attr->u.num;
5401 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
5402 this->flags_town=attr->u.num;
5404 this->flags_town=-1;
5405 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
5406 this->flags_street=attr->u.num;
5408 this->flags_street=-1;
5409 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
5410 this->flags_house_number=attr->u.num;
5412 this->flags_house_number=-1;
5413 this->data.priv=this;
5414 this->data.gui=&gui_internal_methods_ext;
5415 this->data.widget=&gui_internal_widget_methods;
5416 this->cbl=callback_list_new();
5421 //##############################################################################################################
5424 //# Authors: Martin Schaller (04/2008)
5425 //##############################################################################################################
5426 void plugin_init(void)
5428 plugin_register_gui_type("internal", gui_internal_new);