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;
242 int signal_on_map_click;
247 * The setting information read from the configuration file.
248 * values of -1 indicate no value was specified in the config file.
250 struct gui_config_settings config;
251 struct event_idle *idle;
252 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
253 struct event_timeout *motion_timeout_event;
254 struct point current;
256 struct callback * vehicle_cb;
258 * Stores information about the route.
260 struct route_data route_data;
262 struct gui_internal_data data;
263 struct callback_list *cbl;
266 struct attr osd_configuration;
268 int flags_town,flags_street,flags_house_number;
272 struct widget *html_container;
275 int html_anchor_found;
293 struct html_tag_map {
299 {"html",html_tag_html},
300 {"img",html_tag_img},
301 {"script",html_tag_script},
306 * @brief A structure to store information about a table.
308 * The table_data widget stores pointers to extra information needed by the
311 * The table_data structure needs to be freed with data_free along with the widget.
317 * A GList pointer into a widget->children list that indicates the row
318 * currently being rendered at the top of the table.
322 * A Glist pointer into a widget->children list that indicates the row
323 * currently being rendered at the bottom of the table.
328 * A list of table_row widgets that mark the
329 * top rows for each page of the table.
330 * This is needed for the 'previous page' function of the table.
332 GList * page_headers;
335 * A container box that is the child of the table widget that contains+groups
336 * the next and previous button.
338 struct widget * button_box;
341 * A button widget to handle 'next page' requests
343 struct widget * next_button;
345 * A button widget to handle 'previous page' requests.
347 struct widget * prev_button;
351 * a pointer to the gui context.
352 * This is needed by the free function to destory the buttons.
354 struct gui_priv * this;
358 * A data structure that holds information about a column that makes up a table.
362 struct table_column_desc
366 * The computed height of a cell in the table.
371 * The computed width of a cell in the table.
377 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
378 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
379 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
380 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
381 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
382 static void gui_internal_apply_config(struct gui_priv *this);
384 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
385 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
386 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
387 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
388 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
389 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
390 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
391 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
392 static void gui_internal_table_data_free(void * d);
393 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
395 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
396 static void gui_internal_populate_route_table(struct gui_priv * this,
397 struct navit * navit);
398 static void gui_internal_search_idle_end(struct gui_priv *this);
399 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
400 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
401 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
402 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
403 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
404 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
405 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
406 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
407 static void gui_internal_check_exit(struct gui_priv *this);
408 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
410 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
411 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
413 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
414 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
417 * * Display image scaled to specific size
418 * * searches for scaleable and pre-scaled image
419 * * @param this Our gui context
420 * * @param name image name
421 * * @param w desired width of image
422 * * @param h desired height of image
423 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
425 static struct graphics_image *
426 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
428 struct graphics_image *ret=NULL;
429 char *full_name=NULL;
430 char *full_path=NULL;
433 for (i = 1 ; i < 6 ; i++) {
437 full_name=g_strdup_printf("%s.svg", name);
440 full_name=g_strdup_printf("%s.svgz", name);
443 if (w != -1 && h != -1) {
444 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
448 full_name=g_strdup_printf("%s.png", name);
451 full_name=g_strdup_printf("%s.xpm", name);
454 dbg(1,"trying '%s'\n", full_name);
458 /* needs to be checked in the driver */
459 if (!file_exists(full_name)) {
464 full_path=graphics_icon_path(full_name);
465 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
466 dbg(1,"ret=%p\n", ret);
472 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
477 static struct graphics_image *
478 image_new_o(struct gui_priv *this, char *name)
480 return image_new_scaled(this, name, -1, -1);
484 static struct graphics_image *
485 image_new_xs(struct gui_priv *this, const char *name)
487 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
491 static struct graphics_image *
492 image_new_s(struct gui_priv *this, const char *name)
494 return image_new_scaled(this, name, this->icon_s, this->icon_s);
497 static struct graphics_image *
498 image_new_l(struct gui_priv *this, const char *name)
500 return image_new_scaled(this, name, this->icon_l, this->icon_l);
504 coordinates_geo(const struct coord_geo *gc, char sep)
506 char latc='N',lngc='E';
507 int lat_deg,lat_min,lat_sec;
508 int lng_deg,lng_min,lng_sec;
509 struct coord_geo g=*gc;
520 lat_min=fmod(g.lat*60,60);
521 lat_sec=fmod(g.lat*3600,60);
523 lng_min=fmod(g.lng*60,60);
524 lng_sec=fmod(g.lng*3600,60);
525 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);
529 coordinates(struct pcoord *pc, char sep)
535 transform_to_geo(pc->pro, &c, &g);
536 return coordinates_geo(&g, sep);
541 gui_internal_background_render(struct gui_priv *this, struct widget *w)
543 struct point pnt=w->p;
544 if (w->state & STATE_HIGHLIGHTED)
545 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
548 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
551 static struct widget *
552 gui_internal_label_new(struct gui_priv *this, char *text)
558 struct widget *widget=g_new0(struct widget, 1);
559 widget->type=widget_label;
561 widget->text=g_strdup(text);
562 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
566 widget->h=h+this->spacing;
568 widget->w=w+this->spacing;
570 widget->flags=gravity_center;
571 widget->foreground=this->text_foreground;
572 widget->text_background=this->text_background;
577 static struct widget *
578 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
580 struct widget *ret=NULL;
581 char *tmp=g_malloc(strlen(text)+3);
588 ret=gui_internal_label_new(this, tmp);
589 if (ret->w < maxwidth)
591 gui_internal_widget_destroy(this, ret);
599 static struct widget *
600 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
602 struct widget *widget=g_new0(struct widget, 1);
603 widget->type=widget_image;
606 widget->w=image->width;
607 widget->h=image->height;
613 gui_internal_image_render(struct gui_priv *this, struct widget *w)
617 gui_internal_background_render(this, w);
620 pnt.x+=w->w/2-w->img->hot.x;
621 pnt.y+=w->h/2-w->img->hot.y;
622 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
627 gui_internal_label_render(struct gui_priv *this, struct widget *w)
629 struct point pnt=w->p;
630 gui_internal_background_render(this, w);
632 if (w->flags & gravity_right) {
633 pnt.y+=w->h-this->spacing;
634 pnt.x+=w->w-w->textw-this->spacing;
635 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
637 pnt.y+=w->h-this->spacing;
638 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
644 * @brief A text box is a widget that renders a text string containing newlines.
645 * The string will be broken up into label widgets at each newline with a vertical layout.
648 static struct widget *
649 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
651 char *s=g_strdup(text),*s2,*tok;
652 struct widget *ret=gui_internal_box_new(this, flags);
654 while ((tok=strtok(s2,"\n"))) {
655 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
658 gui_internal_widget_pack(this,ret);
663 static struct widget *
664 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)
666 struct widget *ret=NULL;
667 ret=gui_internal_box_new(this, flags);
670 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
672 gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
676 ret->state |= STATE_SENSITIVE;
677 ret->speech=g_strdup(text);
685 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
692 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
693 is_on=curr.u.data == w->on.u.data;
696 if (is_on != w->is_on) {
700 l=g_list_first(w->children);
704 graphics_image_free(this->gra, wi->img);
705 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
707 if (w->is_on && w->off.type == attr_none)
708 w->state &= ~STATE_SENSITIVE;
710 w->state |= STATE_SENSITIVE;
717 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
719 if (gui_internal_button_attr_update(this, w))
720 gui_internal_widget_render(this, w);
723 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
726 w->set_attr(w->instance, &w->off);
728 w->set_attr(w->instance, &w->on);
729 gui_internal_button_attr_update(this, w);
733 static struct widget *
734 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
736 struct graphics_image *image=NULL;
740 image=image_new_xs(this, "gui_inactive");
741 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
746 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
747 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
748 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
749 ret->instance=this->nav;
750 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
751 navit_add_callback(this->nav, ret->cb);
752 gui_internal_button_attr_update(this, ret);
756 static struct widget *
757 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)
759 struct graphics_image *image=NULL;
761 image=image_new_xs(this, "gui_inactive");
764 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
770 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
771 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
772 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
775 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
776 map_add_callback(map, ret->cb);
777 gui_internal_button_attr_update(this, ret);
781 static struct widget *
782 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
784 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
788 //##############################################################################################################
791 //# Authors: Martin Schaller (04/2008)
792 //##############################################################################################################
793 static void gui_internal_clear(struct gui_priv *this)
795 struct graphics *gra=this->gra;
799 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
803 static struct widget *
804 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
806 struct widget *ret,*child;
807 GList *l=wi->children;
814 if ( wi->p.x + wi->w < p->x)
816 if ( wi->p.y + wi->h < p->y)
819 if (wi->state & flags)
823 ret=gui_internal_find_widget(child, p, flags);
834 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
836 if (found == this->highlighted)
839 graphics_draw_mode(this->gra, draw_mode_begin);
840 if (this->highlighted) {
841 this->highlighted->state &= ~STATE_HIGHLIGHTED;
842 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
843 gui_internal_widget_render(this, this->highlighted);
844 this->highlighted=NULL;
845 this->highlighted_menu=NULL;
848 this->highlighted=found;
849 this->highlighted_menu=g_list_last(this->root.children)->data;
850 this->highlighted->state |= STATE_HIGHLIGHTED;
851 gui_internal_widget_render(this, this->highlighted);
852 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
854 graphics_draw_mode(this->gra, draw_mode_end);
856 //##############################################################################################################
859 //# Authors: Martin Schaller (04/2008)
860 //##############################################################################################################
861 static void gui_internal_highlight(struct gui_priv *this)
863 struct widget *menu,*found=NULL;
864 if (this->current.x > -1 && this->current.y > -1) {
865 menu=g_list_last(this->root.children)->data;
866 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
868 gui_internal_highlight_do(this, found);
869 this->motion_timeout_event=NULL;
872 static struct widget *
873 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
875 struct widget *widget=g_new0(struct widget, 1);
878 widget->text=g_strdup(label);
879 widget->type=widget_box;
884 static struct widget *
885 gui_internal_box_new(struct gui_priv *this, enum flags flags)
887 return gui_internal_box_new_with_label(this, flags, NULL);
891 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
896 gui_internal_background_render(this, w);
898 if (w->foreground && w->border) {
901 pnt[1].x=pnt[0].x+w->w;
903 pnt[2].x=pnt[0].x+w->w;
904 pnt[2].y=pnt[0].y+w->h;
906 pnt[3].y=pnt[0].y+w->h;
908 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
909 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
910 graphics_gc_set_linewidth(w->foreground, 1);
917 gui_internal_widget_render(this, wc);
924 * @brief Compute the size and location for the widget.
928 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
931 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;
933 int orientation=w->flags & 0xffff0000;
938 if ( this->root.w > this->root.h )
948 * count the number of children
955 if (orientation == orientation_horizontal_vertical && count <= cols)
956 orientation=orientation_horizontal;
957 switch (orientation) {
958 case orientation_horizontal:
960 * For horizontal orientation:
961 * pack each child and find the largest height and
962 * compute the total width. x spacing (spx) is considered
964 * If any children want to be expanded
965 * we keep track of this
970 gui_internal_widget_pack(this, wc);
974 if (wc->flags & flags_expand)
975 expand+=wc->w ? wc->w : 1;
981 if (expand && w->w) {
982 expand=100*(w->w-width+expand)/expand;
987 case orientation_vertical:
989 * For vertical layouts:
990 * We pack each child and compute the largest width and
991 * the total height. y spacing (spy) is considered
993 * If the expand flag is set then teh expansion amount
999 gui_internal_widget_pack(this, wc);
1003 if (wc->flags & flags_expand)
1004 expand+=wc->h ? wc->h : 1;
1010 if (expand && w->h) {
1011 expand=100*(w->h-height+expand)/expand;
1016 case orientation_horizontal_vertical:
1018 * For horizontal_vertical orientation
1019 * pack the children.
1020 * Compute the largest height and largest width.
1021 * Layout the widgets based on having the
1022 * number of columns specified by (cols)
1028 gui_internal_widget_pack(this, wc);
1038 rows=(count+cols-1)/cols;
1041 width+=w->spx*(cols-1);
1042 height+=w->spy*(rows-1);
1049 * No orientation was specified.
1050 * width and height are both 0.
1051 * The width & height of this widget
1055 dbg(0,"Warning width and height of a widget are 0");
1058 if (! w->w && ! w->h) {
1059 w->w=w->bl+w->br+width;
1060 w->h=w->bt+w->bb+height;
1066 * At this stage the width and height of this
1067 * widget has been computed.
1068 * We now make a second pass assigning heights,
1069 * widths and coordinates to each child widget.
1072 if (w->flags & gravity_left)
1074 if (w->flags & gravity_xcenter)
1075 x=w->p.x+w->w/2-owidth/2;
1076 if (w->flags & gravity_right)
1077 x=w->p.x+w->w-w->br-owidth;
1078 if (w->flags & gravity_top)
1080 if (w->flags & gravity_ycenter)
1081 y=w->p.y+w->h/2-oheight/2;
1082 if (w->flags & gravity_bottom)
1083 y=w->p.y+w->h-w->bb-oheight;
1085 switch (orientation) {
1086 case orientation_horizontal:
1091 if (wc->flags & flags_fill)
1093 if (wc->flags & flags_expand) {
1096 wc->w=wc->w*expand/100;
1098 if (w->flags & gravity_top)
1100 if (w->flags & gravity_ycenter)
1102 if (w->flags & gravity_bottom)
1108 case orientation_vertical:
1113 if (wc->flags & flags_fill)
1115 if (wc->flags & flags_expand) {
1118 wc->h=wc->h*expand/100;
1120 if (w->flags & gravity_left)
1122 if (w->flags & gravity_xcenter)
1124 if (w->flags & gravity_right)
1130 case orientation_horizontal_vertical:
1140 if (wc->flags & flags_fill) {
1144 if (w->flags & gravity_left)
1146 if (w->flags & gravity_xcenter)
1147 wc->p.x=x+(width-wc->w)/2;
1148 if (w->flags & gravity_right)
1149 wc->p.x=x+width-wc->w;
1150 if (w->flags & gravity_top)
1152 if (w->flags & gravity_ycenter)
1153 wc->p.y=y+(height-wc->h)/2;
1154 if (w->flags & gravity_bottom)
1155 wc->p.y=y-height-wc->h;
1157 if (++count == cols) {
1169 * Call pack again on each child,
1170 * the child has now had its size and coordinates
1171 * set so they can repack their children.
1176 gui_internal_widget_pack(this, wc);
1182 gui_internal_widget_append(struct widget *parent, struct widget *child)
1186 if (! child->background)
1187 child->background=parent->background;
1188 parent->children=g_list_append(parent->children, child);
1191 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1193 if (! child->background)
1194 child->background=parent->background;
1195 parent->children=g_list_prepend(parent->children, child);
1198 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1206 gui_internal_widget_destroy(this, wc);
1209 g_list_free(w->children);
1213 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1215 gui_internal_widget_children_destroy(this, w);
1220 graphics_image_free(this->gra, w->img);
1226 w->data_free(w->data);
1227 if (w->cb && w->remove_cb)
1228 w->remove_cb(w->instance, w->cb);
1237 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1239 if(w->p.x > this->root.w || w->p.y > this->root.h)
1244 gui_internal_box_render(this, w);
1247 gui_internal_label_render(this, w);
1250 gui_internal_image_render(this, w);
1253 gui_internal_table_render(this,w);
1261 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1265 gui_internal_box_pack(this, w);
1268 gui_internal_table_pack(this,w);
1274 //##############################################################################################################
1277 //# Authors: Martin Schaller (04/2008)
1278 //##############################################################################################################
1279 static void gui_internal_call_highlighted(struct gui_priv *this)
1281 if (! this->highlighted || ! this->highlighted->func)
1283 this->highlighted->reason=1;
1284 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1288 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1290 char *text=w->speech;
1298 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1299 navit_say(this->nav, text);
1305 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1309 gui_internal_search_idle_end(this);
1310 while ((l = g_list_last(this->root.children))) {
1312 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1313 gui_internal_say(this, w, 0);
1314 redisplay=w->menu_data->redisplay;
1315 wr=w->menu_data->redisplay_widget;
1316 if (!w->menu_data->redisplay) {
1317 gui_internal_widget_render(this, w);
1320 gui_internal_widget_destroy(this, l->data);
1321 this->root.children=g_list_remove(this->root.children, l->data);
1322 redisplay(this, wr, wr->data);
1325 gui_internal_widget_destroy(this, l->data);
1326 this->root.children=g_list_remove(this->root.children, l->data);
1331 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1334 gui_internal_search_idle_end(this);
1335 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1336 gui_internal_widget_destroy(this, l->data);
1337 this->root.children=g_list_remove(this->root.children, l->data);
1340 gui_internal_say(this, l->data, 0);
1341 gui_internal_widget_render(this, l->data);
1346 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1348 gui_internal_prune_menu_count(this, 1, 1);
1352 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1354 gui_internal_prune_menu(this, wm->data);
1358 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1360 graphics_draw_mode(this->gra, draw_mode_begin);
1361 gui_internal_back(this, NULL, NULL);
1362 graphics_draw_mode(this->gra, draw_mode_end);
1363 gui_internal_check_exit(this);
1367 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1369 gui_internal_prune_menu(this, NULL);
1373 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1375 gui_internal_prune_menu(this, this->root.children->data);
1378 static struct widget *
1379 gui_internal_top_bar(struct gui_priv *this)
1381 struct widget *w,*wm,*wh,*wc,*wcn;
1382 int dots_len, sep_len;
1384 int width,width_used=0,use_sep=0,incomplete=0;
1385 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1387 1:Don't expand bar to screen width
1388 2:Don't show Map Icon
1389 4:Don't show Home Icon
1390 8:Show only current menu
1391 16:Don't use menu titles as button
1392 32:Show navit version
1395 256:Use background for menu headline
1396 512:Set osd_configuration and zoom to route when setting position
1397 1024:Don't show back button
1400 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1401 w->bl=this->spacing;
1402 w->spx=this->spacing;
1403 w->background=this->background2;
1404 if ((this->flags & 6) == 6) {
1410 width=this->root.w-w->bl;
1411 if (! (this->flags & 2)) {
1412 wm=gui_internal_button_new_with_callback(this, NULL,
1413 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1414 gui_internal_cmd_return, NULL);
1415 wm->speech=g_strdup(_("Back to map"));
1416 gui_internal_widget_pack(this, wm);
1417 gui_internal_widget_append(w, wm);
1420 if (! (this->flags & 4)) {
1421 wh=gui_internal_button_new_with_callback(this, NULL,
1422 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1423 gui_internal_cmd_main_menu, NULL);
1424 wh->speech=g_strdup(_("Main Menu"));
1425 gui_internal_widget_pack(this, wh);
1426 gui_internal_widget_append(w, wh);
1429 if (!(this->flags & 6))
1431 l=g_list_last(this->root.children);
1432 wcn=gui_internal_label_new(this,".. »");
1433 wcn->foreground=foreground;
1435 gui_internal_widget_destroy(this, wcn);
1436 wcn=gui_internal_label_new(this,"»");
1437 wcn->foreground=foreground;
1439 gui_internal_widget_destroy(this, wcn);
1441 if (g_list_previous(l) || !g_list_next(l)) {
1443 wcn=gui_internal_label_new(this, wc->text);
1444 wcn->foreground=foreground;
1449 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1450 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1452 gui_internal_widget_destroy(this, wcn);
1456 struct widget *wct=gui_internal_label_new(this, "»");
1457 wct->foreground=foreground;
1458 res=g_list_prepend(res, wct);
1459 width_used+=sep_len+w->spx;
1462 if (!(this->flags & 16)) {
1463 wcn->func=gui_internal_cmd_return;
1465 wcn->state |= STATE_SENSITIVE;
1467 res=g_list_prepend(res, wcn);
1468 if (this->flags & 8)
1471 l=g_list_previous(l);
1475 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1476 wcn->foreground=foreground;
1477 wcn->func=gui_internal_cmd_return;
1479 wcn->state |= STATE_SENSITIVE;
1480 res=g_list_prepend(res, wcn);
1481 l=g_list_previous(l);
1484 wcn=gui_internal_label_new(this, ".. »");
1485 wcn->foreground=foreground;
1486 wcn->func=gui_internal_cmd_return;
1488 wcn->state |= STATE_SENSITIVE;
1489 res=g_list_prepend(res, wcn);
1493 gui_internal_widget_append(w, l->data);
1496 if (this->flags & 32) {
1497 extern char *version;
1498 char *version_text=g_strdup_printf("Navit %s",version);
1499 wcn=gui_internal_label_new(this, version_text);
1500 g_free(version_text);
1501 wcn->flags=gravity_right_center|flags_expand;
1502 gui_internal_widget_append(w, wcn);
1506 gui_internal_widget_destroy(this, dots);
1511 static struct widget *
1512 gui_internal_time_help(struct gui_priv *this)
1514 struct widget *w,*wc,*wcn;
1519 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1520 w->bl=this->spacing;
1521 w->spx=this->spacing;
1527 if (this->flags & 64) {
1528 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1534 tm=localtime(&timep);
1535 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1536 wcn=gui_internal_label_new(this, timestr);
1537 gui_internal_widget_append(wc, wcn);
1538 gui_internal_widget_append(w, wc);
1540 if (this->flags & 128) {
1541 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1542 gui_internal_widget_append(w, wcn);
1549 * Applys the configuration values to this based on the settings
1550 * specified in the configuration file (this->config) and
1551 * the most approriate default profile based on screen resolution.
1553 * This function should be run after this->root is setup and could
1554 * be rerun after the window is resized.
1556 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1558 static void gui_internal_apply_config(struct gui_priv *this)
1560 struct gui_config_settings * current_config=0;
1562 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1564 * Select default values from profile based on the screen.
1566 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1568 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1570 current_config = &config_profiles[LARGE_PROFILE];
1574 current_config = &config_profiles[MEDIUM_PROFILE];
1579 current_config = &config_profiles[SMALL_PROFILE];
1583 * Apply override values from config file
1585 if(this->config.font_size == -1 )
1587 this->font_size = current_config->font_size;
1591 this->font_size = this->config.font_size;
1594 if(this->config.icon_xs == -1 )
1596 this->icon_xs = current_config->icon_xs;
1600 this->icon_xs = this->config.icon_xs;
1603 if(this->config.icon_s == -1 )
1605 this->icon_s = current_config->icon_s;
1609 this->icon_s = this->config.icon_s;
1611 if(this->config.icon_l == -1 )
1613 this->icon_l = current_config->icon_l;
1617 this->icon_l = this->config.icon_l;
1619 if(this->config.spacing == -1 )
1621 this->spacing = current_config->spacing;
1625 this->spacing = current_config->spacing;
1630 static struct widget *
1631 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1633 struct widget *wl,*wlb;
1634 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1635 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1636 wl=gui_internal_label_new(this, label);
1638 wlb->foreground=this->text_foreground;
1643 gui_internal_widget_append(wlb, wl);
1645 gui_internal_widget_prepend(wb, wlb);
1647 gui_internal_widget_append(wb, wlb);
1653 static struct widget *
1654 gui_internal_menu(struct gui_priv *this, const char *label)
1656 struct widget *menu,*w,*w1,*topbox;
1658 gui_internal_search_idle_end(this);
1659 topbox=gui_internal_box_new_with_label(this, 0, label);
1660 topbox->w=this->root.w;
1661 topbox->h=this->root.h;
1662 gui_internal_widget_append(&this->root, topbox);
1663 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1664 menu->w=this->root.w;
1665 menu->h=this->root.h;
1666 menu->background=this->background;
1667 gui_internal_apply_config(this);
1668 this->font=graphics_font_new(this->gra,this->font_size,1);
1669 topbox->menu_data=g_new0(struct menu_data, 1);
1670 gui_internal_widget_append(topbox, menu);
1671 w=gui_internal_top_bar(this);
1672 gui_internal_widget_append(menu, w);
1673 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1674 w->spx=4*this->spacing;
1676 gui_internal_widget_append(menu, w);
1677 if (this->flags & 16 && (!this->flags & 1024)) {
1678 struct widget *wlb,*wb,*wm=w;
1679 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1680 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1681 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1682 gui_internal_widget_append(wm, w);
1683 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1689 topbox->menu_data->button_bar=wb;
1690 gui_internal_widget_append(wm, wb);
1691 wlb=gui_internal_button_label(this,_("Back"),1);
1692 wlb->func=gui_internal_back;
1693 wlb->state |= STATE_SENSITIVE;
1695 if (this->flags & 192) {
1696 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1697 menu->w=this->root.w;
1698 menu->h=this->root.h;
1699 w1=gui_internal_time_help(this);
1700 gui_internal_widget_append(menu, w1);
1701 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1702 gui_internal_widget_append(menu, w1);
1703 gui_internal_widget_append(topbox, menu);
1704 menu->background=NULL;
1709 static struct menu_data *
1710 gui_internal_menu_data(struct gui_priv *this)
1713 struct widget *menu;
1715 l=g_list_last(this->root.children);
1717 return menu->menu_data;
1721 gui_internal_menu_render(struct gui_priv *this)
1724 struct widget *menu;
1726 l=g_list_last(this->root.children);
1728 gui_internal_say(this, menu, 0);
1729 gui_internal_widget_pack(this, menu);
1730 gui_internal_widget_render(this, menu);
1734 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1737 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1738 navit_set_destination(this->nav, &wm->c, name, 1);
1739 if (this->flags & 512) {
1741 follow.type=attr_follow;
1743 navit_set_attr(this->nav, &this->osd_configuration);
1744 navit_set_attr(this->nav, &follow);
1745 navit_zoom_to_route(this->nav, 0);
1747 gui_internal_prune_menu(this, NULL);
1751 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1753 navit_set_position(this->nav, &wm->c);
1754 gui_internal_prune_menu(this, NULL);
1758 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1761 dbg(0,"text='%s'\n", widget->text);
1762 if (widget->text && strlen(widget->text))
1763 navit_add_bookmark(this->nav, &widget->c, widget->text);
1764 g_free(widget->text);
1766 l=g_list_previous(g_list_last(this->root.children));
1767 gui_internal_prune_menu(this, l->data);
1771 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1773 gui_internal_cmd_add_bookmark_do(this, widget->data);
1777 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1782 len=strlen(wm->text);
1783 dbg(1,"len=%d\n", len);
1784 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1785 wm->text[len-1]='\0';
1786 gui_internal_cmd_add_bookmark_do(this, wm);
1792 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1795 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
1797 struct widget *w,*wb,*wk,*wl,*we,*wnext;
1799 wb=gui_internal_menu(this,_("Add Bookmark"));
1800 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1801 gui_internal_widget_append(wb, w);
1802 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1803 gui_internal_widget_append(w, we);
1804 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
1805 wk->state |= STATE_EDIT|STATE_CLEAR;
1806 wk->background=this->background;
1807 wk->flags |= flags_expand|flags_fill;
1808 wk->func = gui_internal_cmd_add_bookmark_changed;
1810 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1811 wnext->state |= STATE_SENSITIVE;
1812 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1814 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1815 gui_internal_widget_append(w, wl);
1817 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1818 gui_internal_menu_render(this);
1823 get_direction(char *buffer, int angle, int mode)
1828 sprintf(buffer,"%d",angle);
1831 if (angle < 69 || angle > 291)
1833 if (angle > 111 && angle < 249)
1835 if (angle > 22 && angle < 158)
1837 if (angle > 202 && angle < 338)
1842 angle=(angle+15)/30;
1845 sprintf(buffer,"%d H", angle);
1853 enum item_type *types;
1855 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1856 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1857 {"hotel","Hotel",(enum item_type []) {
1858 type_poi_hotel,type_poi_camp_rv,
1859 type_poi_camping,type_poi_camping,
1860 type_poi_resort,type_poi_resort,
1861 type_poi_motel,type_poi_hostel,
1863 {"restaurant","Restaurant",(enum item_type []) {
1864 type_poi_bar,type_poi_picnic,
1865 type_poi_burgerking,type_poi_fastfood,
1866 type_poi_restaurant,type_poi_restaurant,
1868 {"shopping","Shopping",(enum item_type []) {
1869 type_poi_mall,type_poi_mall,
1870 type_poi_shop_grocery,type_poi_shop_grocery,
1872 {"hospital","Service",(enum item_type []) {
1873 type_poi_marina,type_poi_marina,
1874 type_poi_hospital,type_poi_hospital,
1875 type_poi_public_utilities,type_poi_public_utilities,
1876 type_poi_police,type_poi_autoservice,
1877 type_poi_information,type_poi_information,
1878 type_poi_personal_service,type_poi_repair_service,
1879 type_poi_restroom,type_poi_restroom,
1881 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1882 {"peak","Land Features",(enum item_type []){
1883 type_poi_land_feature,type_poi_rock,
1884 type_poi_dam,type_poi_dam,
1886 {"unknown","Other",(enum item_type []){
1887 type_point_unspecified,type_point_unkn-1,
1888 type_point_unkn+1,type_poi_land_feature-1,
1889 type_poi_rock+1,type_poi_fuel-1,
1890 type_poi_marina+1,type_poi_car_parking-1,
1891 type_poi_car_parking+1,type_poi_bar-1,
1892 type_poi_bank+1,type_poi_dam-1,
1893 type_poi_dam+1,type_poi_information-1,
1894 type_poi_information+1,type_poi_mall-1,
1895 type_poi_mall+1,type_poi_personal_service-1,
1896 type_poi_restaurant+1,type_poi_restroom-1,
1897 type_poi_restroom+1,type_poi_shop_grocery-1,
1898 type_poi_shop_grocery+1,type_poi_motel-1,
1899 type_poi_hostel+1,type_selected_point,
1901 {"unknown","Unknown",(enum item_type []){
1902 type_point_unkn,type_point_unkn,
1906 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1908 static struct widget *
1909 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1911 struct widget *wl,*wb;
1913 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1914 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1915 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1916 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1917 gui_internal_cmd_pois, &selectors[i]));
1924 static struct widget *
1925 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1931 struct widget *wl,*wt;
1934 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1936 sprintf(distbuf,"%d", dist/1000);
1937 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1938 type=item_to_name(item->type);
1939 if (item_attr_get(item, attr_label, &attr)) {
1940 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1943 wl->name=g_strdup(type);
1945 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
1946 wt=gui_internal_label_new(this, text);
1948 gui_internal_widget_append(wl, wt);
1955 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1957 const struct widget *wa=a;
1958 const struct widget *wb=b;
1959 struct widget *wac=wa->children->data;
1960 struct widget *wbc=wb->children->data;
1968 return wac->datai-wbc->datai;
1973 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1975 enum item_type *types;
1976 if (type >= type_line)
1978 if (! sel || !sel->types)
1981 while (*types != type_none) {
1982 if (type >= types[0] && type <= types[1]) {
1990 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
1993 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
1995 struct map_selection *sel,*selm;
1996 struct coord c,center;
1997 struct mapset_handle *h;
1999 struct map_rect *mr;
2001 int idist,dist=20000;
2002 struct widget *wi,*w,*w2,*wb;
2003 enum projection pro=wm->c.pro;
2004 struct selector *isel=wm->data;
2006 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2007 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2008 gui_internal_widget_append(wb, w);
2010 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
2011 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2012 gui_internal_widget_append(w, w2);
2014 sel=map_selection_rect_new(&wm->c, dist, 18);
2017 h=mapset_open(navit_get_mapset(this->nav));
2018 while ((m=mapset_next(h, 1))) {
2019 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2020 mr=map_rect_new(m, selm);
2021 dbg(2,"mr=%p\n", mr);
2023 while ((item=map_rect_get_item(mr))) {
2024 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
2025 item_coord_get_pro(item, &c, 1, pro) &&
2026 coord_rect_contains(&sel->u.c_rect, &c) &&
2027 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2028 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
2029 wi->func=gui_internal_cmd_position;
2032 wi->state |= STATE_SENSITIVE;
2038 map_rect_destroy(mr);
2040 map_selection_destroy(selm);
2042 map_selection_destroy(sel);
2044 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
2045 gui_internal_menu_render(this);
2049 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2051 struct widget *w=wm->data;
2052 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
2054 graphics_clear_selection(this->gra, NULL);
2055 graphics_add_selection(this->gra, &w->item, NULL);
2057 navit_set_center(this->nav, &w->c, 1);
2058 gui_internal_prune_menu(this, NULL);
2063 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2065 struct widget *w,*wb;
2066 struct map_rect *mr;
2072 text=g_strdup_printf("Attribute %s",wm->name);
2073 wb=gui_internal_menu(this, text);
2075 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2076 gui_internal_widget_append(wb, w);
2077 mr=map_rect_new(wm->item.map, NULL);
2078 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2079 for (i = 0 ; i < wm->datai ; i++) {
2080 item_attr_get(item, attr_any, &attr);
2082 if (item_attr_get(item, attr_any, &attr)) {
2084 switch (attr.type) {
2085 case attr_osm_nodeid:
2086 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2088 case attr_osm_wayid:
2089 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2091 case attr_osm_relationid:
2092 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2098 gui_internal_widget_append(w,
2099 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2100 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2101 gui_internal_cmd_view_in_browser, NULL));
2105 map_rect_destroy(mr);
2106 gui_internal_menu_render(this);
2110 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2112 struct widget *w,*wb;
2113 struct map_rect *mr;
2119 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2120 wb=gui_internal_menu(this, "Attributes");
2121 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2122 gui_internal_widget_append(wb, w);
2123 mr=map_rect_new(wm->item.map, NULL);
2124 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2125 dbg(0,"item=%p\n", item);
2127 while(item_attr_get(item, attr_any, &attr)) {
2128 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2129 gui_internal_widget_append(w,
2130 wb=gui_internal_button_new_with_callback(this, text,
2131 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2132 gui_internal_cmd_view_attribute_details, NULL));
2133 wb->name=g_strdup(text);
2139 map_rect_destroy(mr);
2140 gui_internal_menu_render(this);
2144 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2146 struct map_rect *mr;
2152 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2153 mr=map_rect_new(wm->item.map, NULL);
2154 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2155 dbg(0,"item=%p\n", item);
2157 while(item_attr_get(item, attr_url_local, &attr)) {
2159 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2162 map_rect_destroy(mr);
2164 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2170 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2177 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)
2179 struct widget *wb,*w,*wc,*wbc;
2189 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2190 transform_to_geo(pc.pro, &c, &g);
2193 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
2196 pc.pro=attr.u.projection;
2197 transform_from_geo(pc.pro, &g, &c);
2203 wb=gui_internal_menu(this, name);
2204 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2205 gui_internal_widget_append(wb, w);
2206 coord=coordinates(&pc, ' ');
2207 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2209 if ((flags & 1) && wm) {
2210 gui_internal_widget_append(w,
2211 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2212 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2213 gui_internal_search_street_in_town, wm));
2215 wc->selection_id=wm->selection_id;
2217 if ((flags & 2) && wm) {
2218 gui_internal_widget_append(w,
2219 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2220 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2221 gui_internal_search_house_number_in_street, wm));
2223 wc->selection_id=wm->selection_id;
2225 if ((flags & 4) && wm) {
2226 struct map_rect *mr;
2229 mr=map_rect_new(wm->item.map, NULL);
2230 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2232 if (item_attr_get(item, attr_description, &attr))
2233 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2234 if (item_attr_get(item, attr_url_local, &attr)) {
2235 gui_internal_widget_append(w,
2236 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2237 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2238 gui_internal_cmd_view_in_browser, NULL));
2241 gui_internal_widget_append(w,
2242 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2243 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2244 gui_internal_cmd_view_attributes, NULL));
2247 map_rect_destroy(mr);
2250 gui_internal_widget_append(w,
2251 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
2252 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2253 gui_internal_cmd_set_destination, g_strdup(name)));
2254 wbc->data_free=g_free;
2258 gui_internal_widget_append(w,
2259 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
2260 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2261 gui_internal_cmd_set_position, wm));
2265 gui_internal_widget_append(w,
2266 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2267 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2268 gui_internal_cmd_add_bookmark2, g_strdup(name)));
2269 wbc->data_free=g_free;
2273 gui_internal_widget_append(w,
2274 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2275 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2276 gui_internal_cmd_pois, NULL));
2280 gui_internal_widget_append(w,
2281 gui_internal_button_new(this, "Add to tour",
2282 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2285 gui_internal_widget_append(w,
2286 gui_internal_button_new_with_callback(this, _("View on map"),
2287 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2288 gui_internal_cmd_view_on_map, wm));
2293 struct mapset_handle *h;
2294 struct map_rect *mr;
2297 struct street_data *data;
2298 struct map_selection sel;
2299 struct transformation *trans;
2300 enum projection pro;
2304 trans=navit_get_trans(this->nav);
2305 pro=transform_get_projection(trans);
2306 transform_from_geo(pro, &g, &c);
2307 ms=navit_get_mapset(this->nav);
2309 sel.u.c_rect.lu.x=c.x-dist;
2310 sel.u.c_rect.lu.y=c.y+dist;
2311 sel.u.c_rect.rl.x=c.x+dist;
2312 sel.u.c_rect.rl.y=c.y-dist;
2314 sel.range=item_range_all;
2316 while ((m=mapset_next(h,1))) {
2317 mr=map_rect_new(m, &sel);
2320 while ((item=map_rect_get_item(mr))) {
2321 data=street_get_data(item);
2322 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2323 if (item_attr_get(item, attr_label, &attr)) {
2324 label=map_convert_string(m, attr.u.str);
2325 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2326 map_convert_free(label);
2328 text=g_strdup_printf("%s", item_to_name(item->type));
2329 gui_internal_widget_append(w,
2330 wc=gui_internal_button_new_with_callback(this, text,
2331 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2332 gui_internal_cmd_position, (void *)2));
2333 wc->c.x=data->c[0].x;
2334 wc->c.y=data->c[0].y;
2336 wc->name=g_strdup(text);
2340 street_data_free(data);
2342 map_rect_destroy(mr);
2346 gui_internal_menu_render(this);
2350 /* wm->data: 0 Nothing special
2360 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2363 switch ((int) wm->data) {
2365 flags=8|16|32|64|128|256;
2368 flags=8|16|32|64|256;
2374 flags=1|8|16|32|64|128;
2375 flags &= this->flags_town;
2378 gui_internal_search_town_in_country(this, wm);
2381 flags=2|8|16|32|64|128;
2382 flags &= this->flags_street;
2385 flags=8|16|32|64|128;
2386 flags &= this->flags_house_number;
2393 gui_internal_search_house_number_in_street(this, wm, NULL);
2396 gui_internal_cmd_set_destination(this, wm, NULL);
2399 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
2403 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2405 char *name=_("Position");
2411 if (!ATTR_IS_COORD_GEO(in[0]->type))
2413 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
2415 if (in[2] && ATTR_IS_INT(in[2]->type))
2418 dbg(1,"flags=0x%x\n",flags);
2419 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
2423 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2425 struct attr attr,mattr;
2426 struct map_rect *mr=NULL;
2428 char *label_full,*l,*prefix="",*pos;
2429 int len,plen,hassub,found=0;
2430 struct widget *wb,*w,*wbm;
2433 char *text=_("Bookmarks");
2437 wb=gui_internal_menu(this, text);
2438 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2439 w->spy=this->spacing*3;
2440 gui_internal_widget_append(wb, w);
2445 if (wm && wm->prefix)
2448 plen=strlen(prefix);
2450 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2451 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2452 while ((item=map_rect_get_item(mr))) {
2453 if (item->type != type_bookmark) continue;
2454 if (!item_attr_get(item, attr_label, &attr)) continue;
2455 label_full=attr.u.str;
2456 if (!strncmp(label_full, prefix, plen)) {
2457 pos=strchr(label_full+plen, '/');
2463 len=strlen(label_full);
2465 l=g_malloc(len-plen+1);
2466 strncpy(l, label_full+plen, len-plen);
2468 if (!g_hash_table_lookup(hash, l)) {
2469 wbm=gui_internal_button_new_with_callback(this, l,
2470 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2471 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2472 if (item_coord_get(item, &c, 1)) {
2475 wbm->c.pro=map_projection(mattr.u.map);
2476 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2477 wbm->text=g_strdup(l);
2478 gui_internal_widget_append(w, wbm);
2479 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2480 wbm->prefix=g_malloc(len+2);
2481 strncpy(wbm->prefix, label_full, len+1);
2482 wbm->prefix[len+1]='\0';
2484 gui_internal_cmd_set_destination(this, wbm, wbm->name);
2489 gui_internal_widget_destroy(this, wbm);
2496 g_hash_table_destroy(hash);
2499 gui_internal_check_exit(this);
2501 gui_internal_menu_render(this);
2505 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2508 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
2511 gui_internal_cmd_bookmarks(this, NULL, str);
2514 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2516 struct widget *wi,*menu;
2520 menu=g_list_last(this->root.children)->data;
2521 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2523 if (*key == NAVIT_KEY_BACKSPACE) {
2524 dbg(0,"backspace\n");
2525 if (wi->text && wi->text[0]) {
2526 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2528 text=g_strdup_printf("%s ", wi->text);
2531 if (wi->state & STATE_CLEAR) {
2532 dbg(0,"wi->state=0x%x\n", wi->state);
2535 wi->state &= ~STATE_CLEAR;
2536 dbg(0,"wi->state=0x%x\n", wi->state);
2538 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2542 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2543 gui_internal_widget_render(this, wi);
2548 wi->func(this, wi, wi->data);
2550 gui_internal_widget_render(this, wi);
2556 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2558 struct menu_data *md=gui_internal_menu_data(this);
2559 gui_internal_keypress_do(this, (char *) wm->data);
2560 if (md->keyboard_mode == 2)
2561 gui_internal_keyboard_do(this, md->keyboard, 10);
2562 if (md->keyboard_mode == 26)
2563 gui_internal_keyboard_do(this, md->keyboard, 34);
2567 gui_internal_search_idle_end(struct gui_priv *this)
2570 event_remove_idle(this->idle);
2573 if (this->idle_cb) {
2574 callback_destroy(this->idle_cb);
2580 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2582 char *text=NULL,*name=NULL;
2583 struct search_list_result *res;
2585 struct item *item=NULL;
2587 static char possible_keys[256]="";
2589 res=search_list_get_result(this->sl);
2591 gchar* trunk_name = NULL;
2593 struct widget *menu=g_list_last(this->root.children)->data;
2594 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2596 if (! strcmp(wm_name,"Town"))
2597 trunk_name = g_strrstr(res->town->name, wi->text);
2598 if (! strcmp(wm_name,"Street"))
2599 trunk_name = g_strrstr(name=res->street->name, wi->text);
2602 char next_char = trunk_name[strlen(wi->text)];
2604 int len = strlen(possible_keys);
2605 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2606 if (i==len || !len) {
2607 possible_keys[len]=trunk_name[strlen(wi->text)];
2608 possible_keys[len+1]='\0';
2611 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->name, possible_keys);
2616 gui_internal_search_idle_end(this);
2618 struct menu_data *md=gui_internal_menu_data(this);
2619 if (md && md->keyboard) {
2620 GList *lk=md->keyboard->children;
2621 graphics_draw_mode(this->gra, draw_mode_begin);
2623 struct widget *child=lk->data;
2624 GList *lk2=child->children;
2626 struct widget *child_=lk2->data;
2627 lk2=g_list_next(lk2);
2628 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2629 if (strlen(possible_keys) == 0)
2630 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2631 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2632 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2634 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2636 gui_internal_widget_render(this,child_);
2641 gui_internal_widget_render(this,md->keyboard);
2642 graphics_draw_mode(this->gra, draw_mode_end);
2645 possible_keys[0]='\0';
2649 if (! strcmp(wm_name,"Country")) {
2650 name=res->country->name;
2651 item=&res->country->common.item;
2652 text=g_strdup_printf("%s", res->country->name);
2654 if (! strcmp(wm_name,"Town")) {
2655 char *postal=res->town->common.postal;
2656 if (res->town->common.postal_mask)
2657 postal=res->town->common.postal_mask;
2658 name=res->town->name;
2659 item=&res->town->common.item;
2660 if (res->town->name && res->town->district)
2661 text=g_strdup_printf("%s%s%s (%s)", postal ? postal : "", postal ? " ":"", res->town->name, res->town->district);
2663 text=g_strdup_printf("%s%s%s", postal ? postal : "", postal ? " ":"", res->town->name);
2665 if (! strcmp(wm_name,"Street")) {
2666 name=res->street->name;
2667 item=&res->street->common.item;
2668 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
2670 if (! strcmp(wm_name,"House number")) {
2671 name=res->house_number->house_number;
2672 text=g_strdup_printf("%s", name);
2674 dbg(1,"res->country->flag=%s\n", res->country->flag);
2675 gui_internal_widget_append(search_list,
2676 wc=gui_internal_button_new_with_callback(this, text,
2677 image_new_xs(this, res->country->flag),
2678 gravity_left_center|orientation_horizontal|flags_fill,
2679 gui_internal_cmd_position, param));
2680 wc->name=g_strdup(name);
2683 wc->selection_id=res->id;
2686 gui_internal_widget_pack(this, search_list);
2687 l=g_list_last(this->root.children);
2688 graphics_draw_mode(this->gra, draw_mode_begin);
2689 gui_internal_widget_render(this, l->data);
2690 graphics_draw_mode(this->gra, draw_mode_end);
2695 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2697 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2698 this->idle=event_add_idle(50,this->idle_cb);
2699 callback_call_0(this->idle_cb);
2705 * @param wm The widget that generated the event for the search changed,
2706 * if this was generated by a key on the virtual keyboard then
2707 * wm is the key button widget.
2710 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2713 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2714 gui_internal_widget_children_destroy(this, search_list);
2716 void *param=(void *)3;
2718 if (! strcmp(wm->name,"Country"))
2720 if (! strcmp(wm->name,"Street"))
2722 if (! strcmp(wm->name,"House number"))
2724 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2726 gui_internal_search_idle_end(this);
2727 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2728 struct attr search_attr;
2731 if (! strcmp(wm->name,"Country"))
2732 search_attr.type=attr_country_all;
2733 if (! strcmp(wm->name,"Town"))
2734 search_attr.type=attr_town_or_district_name;
2735 if (! strcmp(wm->name,"Street"))
2736 search_attr.type=attr_street_name;
2737 if (! strcmp(wm->name,"House number"))
2738 search_attr.type=attr_house_number;
2739 search_attr.u.str=wm->text;
2740 search_list_search(this->sl, &search_attr, 1);
2741 gui_internal_search_idle_start(this, wm->name, search_list, param);
2743 l=g_list_last(this->root.children);
2744 gui_internal_widget_render(this, l->data);
2747 static struct widget *
2748 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)
2751 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2752 NULL, gravity_center|orientation_vertical, func, data));
2753 wk->data_free=data_free;
2754 wk->background=this->background;
2762 static struct widget *
2763 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2765 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2768 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2770 // Some macros that make the keyboard layout easier to visualise in
2771 // the source code. The macros are #undef'd after this function.
2772 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2773 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h)
2774 static struct widget *
2775 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2777 struct widget *wkbd,*wk;
2778 struct menu_data *md=gui_internal_menu_data(this);
2779 int i, max_w=this->root.w, max_h=this->root.h;
2785 gui_internal_highlight(this);
2787 gui_internal_widget_children_destroy(this, wkbdb);
2789 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2791 md->keyboard_mode=mode;
2792 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2793 wkbd->background=this->background;
2800 if (mode >= 0 && mode < 8) {
2801 for (i = 0 ; i < 26 ; i++) {
2802 char text[]={'A'+i,'\0'};
2805 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2812 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2814 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2817 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2819 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2821 if (mode >= 8 && mode < 16) {
2822 for (i = 0 ; i < 26 ; i++) {
2823 char text[]={'a'+i,'\0'};
2826 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2833 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2835 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2838 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2840 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2842 if (mode >= 16 && mode < 24) {
2843 for (i = 0 ; i < 10 ; i++) {
2844 char text[]={'0'+i,'\0'};
2847 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
2848 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
2850 for (i = 0 ; i < 5 ; i++) SPACER();
2858 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2860 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2863 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2865 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2867 if (mode >= 24 && mode < 32) {
2868 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
2869 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
2870 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
2871 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
2873 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2876 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2878 if (mode >= 32 && mode < 40) {
2879 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
2880 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
2881 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
2882 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
2884 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2887 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2889 gui_internal_widget_append(wkbdb, wkbd);
2891 gui_internal_widget_pack(this, wkbdb);
2892 gui_internal_widget_render(this, wkbdb);
2899 static struct widget *
2900 gui_internal_keyboard(struct gui_priv *this, int mode)
2902 if (! this->keyboard)
2904 return gui_internal_keyboard_do(this, NULL, mode);
2908 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2910 gui_internal_keyboard_do(this, key->data, key->datai);
2914 gui_internal_search_list_set_default_country(struct gui_priv *this)
2916 struct attr search_attr, country_name, country_iso2, *country_attr;
2918 struct country_search *cs;
2919 struct tracking *tracking;
2920 struct search_list_result *res;
2922 country_attr=country_default();
2923 tracking=navit_get_tracking(this->nav);
2924 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
2925 country_attr=&search_attr;
2927 cs=country_search_new(country_attr, 0);
2928 item=country_search_get_item(cs);
2929 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2930 search_attr.type=attr_country_all;
2931 dbg(0,"country %s\n", country_name.u.str);
2932 search_attr.u.str=country_name.u.str;
2933 search_list_search(this->sl, &search_attr, 0);
2934 while((res=search_list_get_result(this->sl)));
2935 g_free(this->country_iso2);
2936 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2937 this->country_iso2=g_strdup(country_iso2.u.str);
2939 country_search_destroy(cs);
2941 dbg(0,"warning: no default country found\n");
2942 if (this->country_iso2) {
2943 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2944 search_attr.type=attr_country_iso2;
2945 search_attr.u.str=this->country_iso2;
2946 search_list_search(this->sl, &search_attr, 0);
2947 while((res=search_list_get_result(this->sl)));
2953 gui_internal_search_list_new(struct gui_priv *this)
2955 struct mapset *ms=navit_get_mapset(this->nav);
2957 this->sl=search_list_new(ms);
2958 gui_internal_search_list_set_default_country(this);
2963 gui_internal_search_list_destroy(struct gui_priv *this)
2966 search_list_destroy(this->sl);
2973 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2975 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2977 gui_internal_search_list_new(this);
2978 wb=gui_internal_menu(this, what);
2979 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2980 gui_internal_widget_append(wb, w);
2981 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2982 gui_internal_widget_append(w, wr);
2983 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2984 gui_internal_widget_append(wr, we);
2986 if (!strcmp(type,"Country")) {
2987 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2988 wnext->func=gui_internal_search_town;
2989 } else if (!strcmp(type,"Town")) {
2990 if (this->country_iso2) {
2991 #if HAVE_API_ANDROID
2992 char country_iso2[strlen(this->country_iso2)+1];
2993 strtolower(country_iso2, this->country_iso2);
2994 country=g_strdup_printf("country_%s", country_iso2);
2996 country=g_strdup_printf("country_%s", this->country_iso2);
2999 country=strdup("gui_select_country");
3000 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
3001 wb->state |= STATE_SENSITIVE;
3003 wb->func = gui_internal_search_country;
3005 wb->func = gui_internal_back;
3006 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
3007 wnext->func=gui_internal_search_street;
3009 } else if (!strcmp(type,"Street")) {
3010 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
3011 wb->state |= STATE_SENSITIVE;
3012 wb->func = gui_internal_back;
3013 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
3014 wnext->func=gui_internal_search_house_number;
3015 } else if (!strcmp(type,"House number")) {
3016 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
3017 wb->state |= STATE_SENSITIVE;
3018 wb->func = gui_internal_back;
3020 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3022 gui_internal_widget_append(we, wnext);
3023 wnext->state |= STATE_SENSITIVE;
3025 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3026 gui_internal_widget_append(wr, wl);
3027 gui_internal_menu_data(this)->search_list=wl;
3028 wk->state |= STATE_EDIT;
3029 wk->background=this->background;
3030 wk->flags |= flags_expand|flags_fill;
3031 wk->func = gui_internal_search_changed;
3032 wk->name=g_strdup(type);
3034 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3035 gui_internal_menu_render(this);
3039 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3041 search_list_select(this->sl, attr_street_name, 0, 0);
3042 gui_internal_search(this,_("House number"),"House number",0);
3046 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3048 dbg(0,"id %d\n", widget->selection_id);
3049 search_list_select(this->sl, attr_street_name, 0, 0);
3050 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3051 gui_internal_search(this,_("House number"),"House number",0);
3055 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3057 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3058 gui_internal_search(this,_("Street"),"Street",0);
3062 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3064 dbg(0,"id %d\n", widget->selection_id);
3065 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3066 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3067 gui_internal_search(this,_("Street"),"Street",0);
3071 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3074 search_list_select(this->sl, attr_country_all, 0, 0);
3075 g_free(this->country_iso2);
3076 this->country_iso2=NULL;
3077 gui_internal_search(this,_("Town"),"Town",0);
3081 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3083 struct search_list_common *slc;
3084 dbg(0,"id %d\n", widget->selection_id);
3085 search_list_select(this->sl, attr_country_all, 0, 0);
3086 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3088 g_free(this->country_iso2);
3089 this->country_iso2=((struct search_list_country *)slc)->iso2;
3091 gui_internal_search(this,widget->name,"Town",0);
3095 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3097 gui_internal_prune_menu_count(this, 1, 0);
3098 gui_internal_search(this,_("Country"),"Country",0);
3102 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3105 search_list_select(this->sl, attr_country_all, 0, 0);
3106 gui_internal_search(this,_("Town"),"Town",1);
3110 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3113 struct widget *w,*wb,*wl;
3114 struct attr_iter *iter;
3117 wb=gui_internal_menu(this, _("Layout"));
3118 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3119 w->spy=this->spacing*3;
3120 gui_internal_widget_append(wb, w);
3121 iter=navit_attr_iter_new();
3122 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3123 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3125 gui_internal_widget_append(w, wl);
3127 navit_attr_iter_destroy(iter);
3128 gui_internal_menu_render(this);
3132 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3135 navit.type=attr_navit;
3136 navit.u.navit=this->nav;
3137 navit_destroy(navit.u.navit);
3138 config_remove_attr(config, &navit);
3139 event_main_loop_quit();
3143 gui_internal_window_closed(struct gui_priv *this)
3145 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3149 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3151 navit_set_destination(this->nav, NULL, NULL, 0);
3156 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3158 struct attr attr, on, off, description, type, data;
3159 struct widget *w,*wb,*wma;
3161 struct attr_iter *iter;
3164 wb=gui_internal_menu(this, _("Maps"));
3165 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3166 w->spy=this->spacing*3;
3167 gui_internal_widget_append(wb, w);
3168 iter=navit_attr_iter_new();
3169 on.type=off.type=attr_active;
3172 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3173 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3174 label=g_strdup(description.u.str);
3176 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3178 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3180 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3182 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3183 attr.u.map, &on, &off, 1);
3184 gui_internal_widget_append(w, wma);
3187 navit_attr_iter_destroy(iter);
3188 gui_internal_menu_render(this);
3192 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3194 struct attr vehicle = {attr_vehicle,{wm->data}};
3195 navit_set_attr(this->nav, &vehicle);
3199 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3201 struct widget *w,*wb,*row;
3202 struct attr attr,sat_attr;
3203 struct vehicle *v=wm->data;
3206 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3208 wb=gui_internal_menu(this, _("Show Satellite Status"));
3209 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3210 gui_internal_menu_data(this)->redisplay_widget=wm;
3211 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3212 gui_internal_widget_append(wb, w);
3213 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3214 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3215 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3216 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3217 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3218 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3219 gui_internal_widget_append(w,row);
3220 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3221 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3222 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3223 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3224 str=g_strdup_printf("%d", sat_attr.u.num);
3227 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3230 gui_internal_widget_append(w,row);
3232 gui_internal_widget_append(wb, w);
3233 gui_internal_menu_render(this);
3237 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3239 struct widget *w,*wb;
3241 struct vehicle *v=wm->data;
3242 wb=gui_internal_menu(this, _("Show NMEA Data"));
3243 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3244 gui_internal_menu_data(this)->redisplay_widget=wm;
3245 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3246 gui_internal_widget_append(wb, w);
3247 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3248 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3249 gui_internal_menu_render(this);
3253 * A container to hold the selected vehicle and the desired profile in
3256 struct vehicle_and_profilename {
3257 struct vehicle *vehicle;
3262 * Figures out whether the given vehicle is the active vehicle.
3264 * @return true if the vehicle is active, false otherwise.
3267 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3270 struct attr active_vehicle;
3272 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3273 active_vehicle.u.vehicle=NULL;
3275 return active_vehicle.u.vehicle == vehicle;
3279 save_vehicle_xml(struct vehicle *v)
3282 struct attr_iter *iter=vehicle_attr_iter_new();
3286 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3287 if (ATTR_IS_OBJECT(attr.type))
3290 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3294 printf("</vehicle>\n");
3297 vehicle_attr_iter_destroy(iter);
3302 * Reacts to a button press that changes a vehicle's active profile.
3304 * @see gui_internal_add_vehicle_profile
3307 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3308 widget *wm, void *data)
3310 struct vehicle_and_profilename *vapn = data;
3311 struct vehicle *v = vapn->vehicle;
3312 char *profilename = vapn->profilename;
3313 struct attr vehicle_name_attr;
3314 char *vehicle_name = NULL;
3316 // Get the vehicle name
3317 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3318 vehicle_name = vehicle_name_attr.u.str;
3320 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3323 // Change the profile name
3324 struct attr profilename_attr = {attr_profilename, {profilename}};
3325 if(!vehicle_set_attr(v, &profilename_attr)) {
3326 dbg(0, "Unable to set the vehicle's profile name\n");
3329 // Notify Navit that the routing should be re-done if this is the
3331 if (gui_internal_is_active_vehicle(this, v)) {
3332 struct attr vehicle;
3333 vehicle.type=attr_vehicle;
3334 vehicle.u.vehicle=v;
3335 navit_set_attr(this->nav, &vehicle);
3337 save_vehicle_xml(v);
3341 * Adds the vehicle profile to the GUI, allowing the user to pick a
3342 * profile for the currently selected vehicle.
3345 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3346 *parent, struct vehicle *v, struct vehicleprofile *profile)
3348 // Just here to show up in the translation file, nice and close to
3349 // where the translations are actually used.
3350 struct attr profile_attr;
3351 struct attr *attr = NULL;
3353 char *active_profile = NULL;
3356 struct vehicle_and_profilename *context = NULL;
3358 #ifdef ONLY_FOR_TRANSLATION
3359 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3362 // Figure out the profile name
3363 attr = attr_search(profile->attrs, NULL, attr_name);
3366 // Determine whether the profile is the active one
3367 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3368 active_profile = profile_attr.u.str;
3369 active = strcmp(name, active_profile) == 0;
3371 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3372 active_profile, active);
3374 // Build a translatable label.
3376 label = g_strdup_printf(_("Current profile: %s"), _(name));
3378 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3381 // Create the context object (the vehicle and the desired profile)
3382 context = g_new0(struct vehicle_and_profilename, 1);
3383 context->vehicle = v;
3384 context->profilename = name;
3387 gui_internal_widget_append(parent,
3388 gui_internal_button_new_with_callback(
3390 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3391 gravity_left_center|orientation_horizontal|flags_fill,
3392 gui_internal_cmd_set_active_profile, context));
3398 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3400 struct widget *w,*wb;
3402 struct vehicle *v=wm->data;
3403 struct vehicleprofile *profile = NULL;
3405 wb=gui_internal_menu(this, wm->text);
3406 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3407 gui_internal_widget_append(wb, w);
3409 // Add the "Set as active" button if this isn't the active
3411 if (!gui_internal_is_active_vehicle(this, v)) {
3412 gui_internal_widget_append(w,
3413 gui_internal_button_new_with_callback(this, _("Set as active"),
3414 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3415 gui_internal_cmd_set_active_vehicle, wm->data));
3418 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3419 gui_internal_widget_append(w,
3420 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3421 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3422 gui_internal_cmd_show_satellite_status, wm->data));
3424 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3425 gui_internal_widget_append(w,
3426 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3427 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3428 gui_internal_cmd_show_nmea_data, wm->data));
3431 // Add all the possible vehicle profiles to the menu
3432 GList *profiles = navit_get_vehicleprofiles(this->nav);
3434 profile = (struct vehicleprofile *)profiles->data;
3435 gui_internal_add_vehicle_profile(this, w, v, profile);
3436 profiles = g_list_next(profiles);
3439 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3440 gui_internal_menu_render(this);
3444 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3446 struct attr attr,vattr;
3447 struct widget *w,*wb,*wl;
3448 struct attr_iter *iter;
3449 struct attr active_vehicle;
3452 wb=gui_internal_menu(this, _("Vehicle"));
3453 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3454 w->spy=this->spacing*3;
3455 gui_internal_widget_append(wb, w);
3456 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3457 active_vehicle.u.vehicle=NULL;
3458 iter=navit_attr_iter_new();
3459 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3460 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3461 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3462 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3463 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3464 wl->text=g_strdup(vattr.u.str);
3465 gui_internal_widget_append(w, wl);
3467 navit_attr_iter_destroy(iter);
3468 gui_internal_menu_render(this);
3473 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3475 struct widget *wb,*w;
3477 wb=gui_internal_menu(this, _("Rules"));
3478 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3479 w->spy=this->spacing*3;
3480 gui_internal_widget_append(wb, w);
3483 on.type=off.type=attr_tracking;
3484 gui_internal_widget_append(w,
3485 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3489 on.type=off.type=attr_orientation;
3490 gui_internal_widget_append(w,
3491 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3495 on.type=off.type=attr_follow_cursor;
3496 gui_internal_widget_append(w,
3497 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3499 gui_internal_menu_render(this);
3502 //##############################################################################################################
3505 //# Authors: Martin Schaller (04/2008)
3506 //##############################################################################################################
3507 static void gui_internal_motion(void *data, struct point *p)
3510 struct gui_priv *this=data;
3511 if (!this->root.children) {
3512 navit_handle_motion(this->nav, p);
3518 if(!this->motion_timeout_callback)
3519 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3520 if(!this->motion_timeout_event)
3521 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3525 find_attr(const char **names, const char **values, const char *name)
3528 if (!strcasecmp(*names, name))
3530 names+=xml_attr_distance;
3531 values+=xml_attr_distance;
3537 find_attr_dup(const char **names, const char **values, const char *name)
3539 return g_strdup(find_attr(names, values, name));
3543 gui_internal_evaluate(struct gui_priv *this, const char *command)
3546 command_evaluate(&this->self, command);
3551 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
3553 gui_internal_evaluate(this,w->command);
3557 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
3559 if (w->command && w->command[0] == '#') {
3560 dbg(1,"href=%s\n",w->command);
3561 gui_internal_html_menu(this, this->html_text, w->command+1);
3567 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
3569 struct gui_priv *this=data;
3571 enum html_tag tag=html_tag_none;
3572 struct html *html=&this->html[this->html_depth];
3573 const char *src, *cond;
3575 if (!strcasecmp(tag_name,"text"))
3581 cond=find_attr(names, values, "cond");
3583 if (cond && !this->html_skip) {
3584 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
3588 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
3589 if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
3590 tag=html_tag_map[i].tag;
3595 if (!this->html_skip && !html->skip) {
3598 html->name=find_attr_dup(names, values, "name");
3600 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
3602 this->html_anchor_found=1;
3604 html->href=find_attr_dup(names, values, "href");
3607 html->command=find_attr_dup(names, values, "onclick");
3608 src=find_attr(names, values, "src");
3610 html->w=gui_internal_image_new(this, image_new_l(this, src));
3616 this->html_skip+=html->skip;
3621 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
3623 struct gui_priv *this=data;
3625 struct html *parent=NULL;
3627 if (!strcasecmp(tag_name,"text"))
3630 html=&this->html[this->html_depth];
3631 if (this->html_depth > 0)
3632 parent=&this->html[this->html_depth-1];
3635 if (!this->html_skip) {
3636 if (html->command && html->w) {
3637 html->w->state |= STATE_SENSITIVE;
3638 html->w->command=html->command;
3639 html->w->func=gui_internal_html_command;
3642 if (parent && parent->href && html->w) {
3643 html->w->state |= STATE_SENSITIVE;
3644 html->w->command=g_strdup(parent->href);
3645 html->w->func=gui_internal_html_href;
3647 switch (html->tag) {
3649 gui_internal_widget_append(this->html_container, html->w);
3655 this->html_skip-=html->skip;
3656 g_free(html->command);
3662 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
3664 struct gui_priv *this=data;
3666 int depth=this->html_depth-1;
3667 struct html *html=&this->html[depth];
3668 char *text_stripped;
3670 if (this->html_skip)
3672 while (isspace(text[0])) {
3676 while (len > 0 && isspace(text[len-1]))
3678 text_stripped=g_malloc(len+1);
3679 strncpy(text_stripped, text, len);
3680 text_stripped[len]='\0';
3681 if (html->tag == html_tag_html && depth > 2) {
3682 if (this->html[depth-1].tag == html_tag_script) {
3683 html=&this->html[depth-2];
3686 switch (html->tag) {
3688 if (html->name && len) {
3689 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3690 this->html_container->spx=this->spacing*10;
3694 if (!this->html_container) {
3695 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3696 this->html_container->spx=this->spacing*10;
3701 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
3702 gui_internal_widget_append(w, html->w);
3703 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
3707 case html_tag_script:
3708 dbg(1,"execute %s\n",text_stripped);
3709 gui_internal_evaluate(this,text_stripped);
3717 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
3719 graphics_draw_mode(this->gra, draw_mode_begin);
3720 this->html_container=NULL;
3722 this->html_anchor=anchor;
3723 this->html_anchor_found=0;
3724 xml_parse_text(document, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
3725 gui_internal_menu_render(this);
3726 graphics_draw_mode(this->gra, draw_mode_end);
3730 static void gui_internal_menu_root(struct gui_priv *this)
3732 gui_internal_html_menu(this, this->html_text, "Main Menu");
3736 gui_internal_enter(struct gui_priv *this, int ignore)
3738 struct graphics *gra=this->gra;
3739 this->ignore_button=ignore;
3740 this->clickp_valid=this->vehicle_valid=0;
3742 navit_block(this->nav, 1);
3743 graphics_overlay_disable(gra, 1);
3746 this->root.background=this->background;
3750 gui_internal_leave(struct gui_priv *this)
3752 graphics_draw_mode(this->gra, draw_mode_end);
3756 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3758 struct transformation *trans;
3761 struct attr attr,attrp;
3764 gui_internal_enter(this, ignore);
3765 trans=navit_get_trans(this->nav);
3766 attr_free(this->click_coord_geo);
3767 this->click_coord_geo=NULL;
3768 attr_free(this->position_coord_geo);
3769 this->position_coord_geo=NULL;
3771 transform_reverse(trans, p, &c);
3772 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
3773 this->clickp.pro=transform_get_projection(trans);
3776 transform_to_geo(this->clickp.pro, &c, &g);
3777 attr.u.coord_geo=&g;
3778 attr.type=attr_click_coord_geo;
3779 this->click_coord_geo=attr_dup(&attr);
3781 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3782 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3783 this->position_coord_geo=attr_dup(&attrp);
3784 this->vehiclep.pro=transform_get_projection(trans);
3785 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3786 this->vehiclep.x=c.x;
3787 this->vehiclep.y=c.y;
3788 this->vehicle_valid=1;
3791 gui_internal_menu_root(this);
3795 gui_internal_cmd_menu2(struct gui_priv *this)
3797 gui_internal_cmd_menu(this, NULL, 1);
3802 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
3804 if (widget->text && strlen(widget->text))
3805 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
3806 g_free(widget->text);
3808 gui_internal_prune_menu(this, NULL);
3809 gui_internal_check_exit(this);
3813 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
3815 gui_internal_cmd_log_do(this, widget->data);
3819 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
3823 len=strlen(wm->text);
3824 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
3825 wm->text[len-1]='\0';
3826 gui_internal_cmd_log_do(this, wm);
3833 gui_internal_cmd_log(struct gui_priv *this)
3835 struct widget *w,*wb,*wk,*wl,*we,*wnext;
3836 gui_internal_enter(this, 1);
3837 wb=gui_internal_menu(this, "Log Message");
3838 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3839 gui_internal_widget_append(wb, w);
3840 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3841 gui_internal_widget_append(w, we);
3842 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
3843 wk->state |= STATE_EDIT|STATE_CLEAR;
3844 wk->background=this->background;
3845 wk->flags |= flags_expand|flags_fill;
3846 wk->func = gui_internal_cmd_log_changed;
3847 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3848 wnext->state |= STATE_SENSITIVE;
3849 wnext->func = gui_internal_cmd_log_clicked;
3851 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3852 gui_internal_widget_append(w, wl);
3854 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3855 gui_internal_menu_render(this);
3856 gui_internal_leave(this);
3860 gui_internal_check_exit(struct gui_priv *this)
3862 struct graphics *gra=this->gra;
3863 if (! this->root.children) {
3864 gui_internal_search_idle_end(this);
3865 gui_internal_search_list_destroy(this);
3866 graphics_overlay_disable(gra, 0);
3867 if (!navit_block(this->nav, 0)) {
3869 navit_draw(this->nav);
3871 navit_draw_displaylist(this->nav);
3877 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
3881 attr->u.num=this->root.children != NULL;
3883 case attr_click_coord_geo:
3884 if (!this->click_coord_geo)
3886 *attr=*this->click_coord_geo;
3888 case attr_position_coord_geo:
3889 if (!this->position_coord_geo)
3891 *attr=*this->position_coord_geo;
3894 attr->u.num=this->pitch;
3904 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
3906 switch (attr->type) {
3908 g_free(this->html_text);
3909 this->html_text=g_strdup(attr->u.str);
3917 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
3919 switch (attr->type) {
3920 case attr_fullscreen:
3921 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
3922 graphics_draw_mode(this->gra, draw_mode_end);
3923 this->win->fullscreen(this->win, attr->u.num > 0);
3924 graphics_draw_mode(this->gra, draw_mode_begin);
3926 this->fullscreen=attr->u.num;
3929 dbg(0,"%s\n",attr_to_name(attr->type));
3934 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
3936 struct displaylist_handle *dlh;
3937 struct displaylist *display;
3938 struct displayitem *di;
3940 display=navit_get_displaylist(this->nav);
3941 dlh=graphics_displaylist_open(display);
3942 while ((di=graphics_displaylist_next(dlh))) {
3943 struct item *item=graphics_displayitem_get_item(di);
3944 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
3945 graphics_displayitem_within_dist(display, di, p, 10)) {
3946 struct map_rect *mr=map_rect_new(item->map, NULL);
3947 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
3949 if (item_attr_get(itemo, attr_data, &attr)) {
3950 struct attr cb,*attr_list[2];
3952 attr.type=attr_data;
3955 if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
3956 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
3958 map_rect_destroy(mr);
3961 graphics_displaylist_close(dlh);
3965 //##############################################################################################################
3966 //# Description: Function to handle mouse clicks and scroll wheel movement
3968 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3969 //##############################################################################################################
3970 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3972 struct gui_priv *this=data;
3973 struct graphics *gra=this->gra;
3975 dbg(1,"enter %d %d\n", pressed, button);
3976 // if still on the map (not in the menu, yet):
3977 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
3978 if (!this->root.children || this->ignore_button) {
3980 this->ignore_button=0;
3981 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3982 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
3983 dbg(1,"navit has handled button\n");
3986 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
3989 if (this->menu_on_map_click) {
3990 gui_internal_cmd_menu(this, p, 0);
3993 if (this->signal_on_map_click) {
3994 gui_internal_dbus_signal(this, p);
4001 // if already in the menu:
4005 gui_internal_highlight(this);
4010 graphics_draw_mode(gra, draw_mode_begin);
4011 gui_internal_call_highlighted(this);
4012 gui_internal_highlight(this);
4013 graphics_draw_mode(gra, draw_mode_end);
4014 gui_internal_check_exit(this);
4019 gui_internal_setup_gc(struct gui_priv *this)
4021 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
4022 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
4023 struct graphics *gra=this->gra;
4025 if (this->background)
4027 this->background=graphics_gc_new(gra);
4028 this->background2=graphics_gc_new(gra);
4029 this->highlight_background=graphics_gc_new(gra);
4030 graphics_gc_set_foreground(this->highlight_background, &cbh);
4031 this->foreground=graphics_gc_new(gra);
4032 graphics_gc_set_foreground(this->foreground, &cf);
4033 this->text_background=graphics_gc_new(gra);
4034 this->text_foreground=graphics_gc_new(gra);
4035 graphics_gc_set_foreground(this->background, &this->background_color);
4036 graphics_gc_set_foreground(this->background2, &this->background2_color);
4037 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
4038 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
4041 //##############################################################################################################
4044 //# Authors: Martin Schaller (04/2008)
4045 //##############################################################################################################
4046 static void gui_internal_resize(void *data, int w, int h)
4048 struct gui_priv *this=data;
4051 gui_internal_setup_gc(this);
4053 if (this->root.w != w || this->root.h != h) {
4058 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
4059 navit_handle_resize(this->nav, w, h);
4060 if (this->root.children && changed) {
4061 gui_internal_prune_menu(this, NULL);
4062 gui_internal_menu_root(this);
4067 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
4082 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
4084 GList *l=wi->children;
4085 if (wi->state & STATE_SENSITIVE) {
4088 gui_internal_keynav_point(wi, -dx, -dy, &wp);
4090 dist1=(wp.x-p->x)*dx;
4093 dist1=(wp.y-p->y)*dy;
4101 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);
4107 if (dist1 < *distance) {
4114 struct widget *child=l->data;
4115 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
4121 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
4123 struct widget *result,*menu=g_list_last(this->root.children)->data;
4126 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4127 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
4133 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
4135 gui_internal_keynav_point(result, dx, dy, &p);
4136 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
4141 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4142 dbg(1,"result=%p\n", result);
4154 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4155 dbg(1,"wraparound result=%p\n", result);
4157 gui_internal_highlight_do(this, result);
4159 gui_internal_say(this, result, 1);
4162 //##############################################################################################################
4165 //# Authors: Martin Schaller (04/2008)
4166 //##############################################################################################################
4167 static void gui_internal_keypress(void *data, char *key)
4169 struct gui_priv *this=data;
4172 if (!this->root.children) {
4173 transform_get_size(navit_get_trans(this->nav), &w, &h);
4178 navit_set_center_screen(this->nav, &p, 1);
4180 case NAVIT_KEY_DOWN:
4183 navit_set_center_screen(this->nav, &p, 1);
4185 case NAVIT_KEY_LEFT:
4188 navit_set_center_screen(this->nav, &p, 1);
4190 case NAVIT_KEY_RIGHT:
4193 navit_set_center_screen(this->nav, &p, 1);
4195 case NAVIT_KEY_ZOOM_IN:
4196 navit_zoom_in(this->nav, 2, NULL);
4198 case NAVIT_KEY_ZOOM_OUT:
4199 navit_zoom_out(this->nav, 2, NULL);
4201 case NAVIT_KEY_RETURN:
4202 case NAVIT_KEY_MENU:
4203 gui_internal_cmd_menu(this, NULL, 0);
4208 graphics_draw_mode(this->gra, draw_mode_begin);
4210 case NAVIT_KEY_LEFT:
4211 gui_internal_keynav_highlight_next(this,-1,0);
4213 case NAVIT_KEY_RIGHT:
4214 gui_internal_keynav_highlight_next(this,1,0);
4217 gui_internal_keynav_highlight_next(this,0,-1);
4219 case NAVIT_KEY_DOWN:
4220 gui_internal_keynav_highlight_next(this,0,1);
4222 case NAVIT_KEY_BACK:
4224 case NAVIT_KEY_RETURN:
4225 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4226 gui_internal_call_highlighted(this);
4228 gui_internal_keypress_do(this, key);
4231 gui_internal_keypress_do(this, key);
4233 graphics_draw_mode(this->gra, draw_mode_end);
4234 gui_internal_check_exit(this);
4238 //##############################################################################################################
4241 //# Authors: Martin Schaller (04/2008)
4242 //##############################################################################################################
4243 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4246 struct transformation *trans=navit_get_trans(this->nav);
4248 win=graphics_get_data(gra, "window");
4251 navit_ignore_graphics_events(this->nav, 1);
4254 navit_ignore_graphics_events(this->nav, 1);
4255 transform_get_size(trans, &this->root.w, &this->root.h);
4256 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4257 graphics_add_callback(gra, this->resize_cb);
4258 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4259 graphics_add_callback(gra, this->button_cb);
4260 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4261 graphics_add_callback(gra, this->motion_cb);
4262 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4263 graphics_add_callback(gra, this->keypress_cb);
4264 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
4265 graphics_add_callback(gra, this->window_closed_cb);
4267 // set fullscreen if needed
4268 if (this->fullscreen)
4269 this->win->fullscreen(this->win, this->fullscreen != 0);
4270 /* Was resize callback already issued? */
4271 if (navit_get_ready(this->nav) & 2)
4272 gui_internal_setup_gc(this);
4276 static void gui_internal_disable_suspend(struct gui_priv *this)
4278 if (this->win->disable_suspend)
4279 this->win->disable_suspend(this->win);
4282 //##############################################################################################################
4285 //# Authors: Martin Schaller (04/2008)
4286 //##############################################################################################################
4287 struct gui_methods gui_internal_methods = {
4290 gui_internal_set_graphics,
4294 gui_internal_disable_suspend,
4295 gui_internal_get_attr,
4296 gui_internal_add_attr,
4297 gui_internal_set_attr,
4301 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4303 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4305 *out=attr_generic_add_attr(*out, &private_data);
4309 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4311 callback_list_add(priv->cbl, cb);
4315 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4317 callback_list_remove(priv->cbl, cb);
4321 static struct gui_internal_methods gui_internal_methods_ext = {
4322 gui_internal_add_callback,
4323 gui_internal_remove_callback,
4324 gui_internal_menu_render,
4331 gui_internal_get_flags(struct widget *widget)
4333 return widget->flags;
4337 gui_internal_set_flags(struct widget *widget, enum flags flags)
4339 widget->flags=flags;
4343 gui_internal_get_state(struct widget *widget)
4345 return widget->state;
4349 gui_internal_set_state(struct widget *widget, int state)
4351 widget->state=state;
4355 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4361 gui_internal_set_data(struct widget *widget, void *data)
4367 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4369 widget->background=this->background;
4372 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4373 gui_internal_widget_append,
4374 gui_internal_button_new,
4375 gui_internal_button_new_with_callback,
4376 gui_internal_box_new,
4377 gui_internal_label_new,
4378 gui_internal_image_new,
4379 gui_internal_keyboard,
4381 gui_internal_get_flags,
4382 gui_internal_set_flags,
4383 gui_internal_get_state,
4384 gui_internal_set_state,
4385 gui_internal_set_func,
4386 gui_internal_set_data,
4387 gui_internal_set_default_background,
4391 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
4393 char *str=NULL,*str2=NULL;
4394 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
4397 dbg(1,"%s\n",attr_to_name(in[0]->type));
4398 if (ATTR_IS_STRING(in[0]->type)) {
4401 if (ATTR_IS_COORD_GEO(in[0]->type)) {
4402 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
4405 str=g_strdup_printf("<html>%s</html>\n",str);
4406 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4414 * @brief Creates a new table widget.
4416 * Creates and returns a new table widget. This function will
4417 * setup next/previous buttons as children.
4419 * @param this The graphics context.
4420 * @param flags widget sizing flags.
4421 * @returns The newly created widget
4423 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4425 struct widget * widget = g_new0(struct widget,1);
4426 struct table_data * data = NULL;
4427 widget->type=widget_table;
4428 widget->flags=flags;
4429 widget->data = g_new0(struct table_data,1);
4430 widget->data_free=gui_internal_table_data_free;
4431 data = (struct table_data*)widget->data;
4435 data->next_button = gui_internal_button_new_with_callback
4436 (this,"Next",image_new_xs(this, "gui_active") ,
4437 gravity_left_center |orientation_vertical,
4438 gui_internal_table_button_next,NULL);
4439 data->next_button->data=widget;
4442 data->prev_button = gui_internal_button_new_with_callback
4444 image_new_xs(this, "gui_active")
4445 ,gravity_right_center |orientation_vertical,
4446 gui_internal_table_button_prev,NULL);
4448 data->prev_button->data=widget;
4452 data->button_box=gui_internal_box_new(this,
4453 gravity_center|orientation_horizontal);
4454 data->button_box->children=g_list_append(data->button_box->children,
4456 data->button_box->children=g_list_append(data->button_box->children,
4458 //data->button_box->background=this->background2;
4459 data->button_box->bl=this->spacing;
4460 widget->children=g_list_append(widget->children,data->button_box);
4461 gui_internal_widget_pack(this,data->button_box);
4469 * @brief Clears all the rows from the table.
4470 * This function removes all rows from a table.
4471 * New rows can later be added to the table.
4473 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4476 struct table_data * table_data = (struct table_data* ) table->data;
4478 iter = table->children;
4480 if(iter->data != table_data->button_box) {
4481 struct widget * child = (struct widget*)iter->data;
4482 gui_internal_widget_destroy(this,child);
4483 if(table->children == iter) {
4484 table->children = g_list_remove(iter,iter->data);
4485 iter=table->children;
4488 iter = g_list_remove(iter,iter->data);
4491 iter = g_list_next(iter);
4495 table_data->top_row=NULL;
4496 table_data->bottom_row=NULL;
4497 if(table_data->page_headers)
4498 g_list_free(table_data->page_headers);
4499 table_data->page_headers=NULL;
4504 * Creates a new table_row widget.
4505 * @param this The graphics context
4506 * @param flags Sizing flags for the row
4507 * @returns The new table_row widget.
4509 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4511 struct widget * widget = g_new0(struct widget,1);
4512 widget->type=widget_table_row;
4513 widget->flags=flags;
4520 * @brief Computes the column dimensions for the table.
4522 * @param w The table widget to compute dimensions for.
4524 * This function examines all of the rows and columns for the table w
4525 * and returns a list (GList) of table_column_desc elements that
4526 * describe each column of the table.
4528 * The caller is responsible for freeing the returned list.
4530 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4533 GList * column_desc = NULL;
4534 GList * current_desc=NULL;
4535 GList * cur_row = w->children;
4536 struct widget * cur_row_widget=NULL;
4537 GList * cur_column=NULL;
4538 struct widget * cell_w=NULL;
4539 struct table_column_desc * current_cell=NULL;
4540 struct table_data * table_data=NULL;
4547 * Scroll through the the table and
4548 * 1. Compute the maximum width + height of each column across all rows.
4550 table_data = (struct table_data*) w->data;
4551 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4553 cur_row_widget = (struct widget*) cur_row->data;
4554 current_desc = column_desc;
4555 if(cur_row_widget == table_data->button_box)
4560 for(cur_column = cur_row_widget->children; cur_column;
4561 cur_column=g_list_next(cur_column))
4563 cell_w = (struct widget*) cur_column->data;
4564 gui_internal_widget_pack(this,cell_w);
4565 if(current_desc == 0)
4567 current_cell = g_new0(struct table_column_desc,1);
4568 column_desc = g_list_append(column_desc,current_cell);
4569 current_desc = g_list_last(column_desc);
4570 current_cell->height=cell_w->h;
4571 current_cell->width=cell_w->w;
4572 total_width+=cell_w->w;
4577 current_cell = current_desc->data;
4580 if(current_cell->height < height )
4582 current_cell->height = height;
4584 if(current_cell->width < width)
4586 total_width += (width-current_cell->width);
4587 current_cell->width = width;
4592 current_desc = g_list_next(current_desc);
4602 * If the width of all columns is less than the width off
4603 * the table expand each cell proportionally.
4606 if(total_width+(this->spacing*column_count) < w->w ) {
4607 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4608 current_cell = (struct table_column_desc*) current_desc->data;
4609 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4618 * @brief Computes the height and width for the table.
4620 * The height and widht are computed to display all cells in the table
4621 * at the requested height/width.
4623 * @param this The graphics context
4624 * @param w The widget to pack.
4627 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4633 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4635 struct table_column_desc * cell_desc=0;
4636 struct table_data * table_data = (struct table_data*)w->data;
4638 for(current = column_data; current; current=g_list_next(current))
4640 if(table_data->button_box == current->data )
4644 cell_desc = (struct table_column_desc *) current->data;
4645 width = width + cell_desc->width + this->spacing;
4646 if(height < cell_desc->height)
4648 height = cell_desc->height ;
4654 for(current=w->children; current; current=g_list_next(current))
4656 if(current->data!= table_data->button_box)
4661 if (table_data->button_box)
4662 gui_internal_widget_pack(this,table_data->button_box);
4666 if(w->h + w->c.y > this->root.h )
4669 * Do not allow the widget to exceed the screen.
4672 w->h = this->root.h- w->c.y - height;
4677 * Deallocate column descriptions.
4679 current = column_data;
4680 while( (current = g_list_last(current)) )
4682 current = g_list_remove(current,current->data);
4690 * @brief Renders a table widget.
4692 * @param this The graphics context
4693 * @param w The table widget to render.
4695 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4700 GList * column_desc=NULL;
4701 GList * cur_row = NULL;
4702 GList * current_desc=NULL;
4703 struct table_data * table_data = (struct table_data*)w->data;
4705 int is_first_page=1;
4706 struct table_column_desc * dim=NULL;
4708 dbg_assert(table_data);
4709 column_desc = gui_internal_compute_table_dimensions(this,w);
4713 * Skip rows that are on previous pages.
4715 cur_row = w->children;
4716 if(table_data->top_row && table_data->top_row != w->children )
4718 cur_row = table_data->top_row;
4724 * Loop through each row. Drawing each cell with the proper sizes,
4725 * at the proper positions.
4727 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4729 GList * cur_column=NULL;
4730 current_desc = column_desc;
4731 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4733 x =w->p.x+this->spacing;
4734 if(cur_row_widget == table_data->button_box )
4738 dim = (struct table_column_desc*)current_desc->data;
4740 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4743 * No more drawing space left.
4749 for(cur_column = cur_row_widget->children; cur_column;
4750 cur_column=g_list_next(cur_column))
4752 struct widget * cur_widget = (struct widget*) cur_column->data;
4753 dim = (struct table_column_desc*)current_desc->data;
4756 cur_widget->w=dim->width;
4758 cur_widget->h=dim->height;
4760 max_height = dim->height;
4761 /* We pack the widget before rendering to ensure that the x and y
4762 * coordinates get pushed down.
4764 gui_internal_widget_pack(this,cur_widget);
4765 gui_internal_widget_render(this,cur_widget);
4767 if(dim->height > max_height)
4769 max_height = dim->height;
4773 table_data->bottom_row=cur_row;
4774 current_desc = g_list_next(current_desc);
4776 if(table_data->button_box && (is_skipped || !is_first_page) )
4778 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4780 if(table_data->button_box->p.y < y )
4782 table_data->button_box->p.y=y;
4784 table_data->button_box->p.x = w->p.x;
4785 table_data->button_box->w = w->w;
4786 // table_data->button_box->h = w->h - y;
4787 // table_data->next_button->h=table_data->button_box->h;
4788 // table_data->prev_button->h=table_data->button_box->h;
4789 // table_data->next_button->c.y=table_data->button_box->c.y;
4790 // table_data->prev_button->c.y=table_data->button_box->c.y;
4792 gui_internal_widget_pack(this,table_data->button_box);
4793 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4796 table_data->button_box->p.y = w->p.y + w->h -
4797 table_data->button_box->h;
4801 table_data->next_button->state|= STATE_SENSITIVE;
4805 table_data->next_button->state&= ~STATE_SENSITIVE;
4808 if(table_data->top_row != w->children)
4810 table_data->prev_button->state|= STATE_SENSITIVE;
4814 table_data->prev_button->state&= ~STATE_SENSITIVE;
4816 gui_internal_widget_render(this,table_data->button_box);
4822 * Deallocate column descriptions.
4824 current_desc = column_desc;
4825 while( (current_desc = g_list_last(current_desc)) )
4827 current_desc = g_list_remove(current_desc,current_desc->data);
4833 * @brief Displays Route information
4835 * @li The name of the active vehicle
4836 * @param wm The button that was pressed.
4840 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4844 struct widget * menu;
4845 struct widget * row;
4848 if(! this->vehicle_cb)
4851 * Register the callback on vehicle updates.
4853 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4854 attr_position_coord_geo,this);
4855 navit_add_callback(this->nav,this->vehicle_cb);
4858 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4859 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4861 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4864 menu=gui_internal_menu(this,_("Route Description"));
4866 menu->free=gui_internal_route_screen_free;
4867 this->route_data.route_showing=1;
4868 this->route_data.route_table->spx = this->spacing;
4871 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4873 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4874 gui_internal_widget_append(box,this->route_data.route_table);
4876 box->spx = this->spacing;
4877 this->route_data.route_table->w=box->w;
4878 gui_internal_widget_append(menu,box);
4879 gui_internal_populate_route_table(this,this->nav);
4880 gui_internal_menu_render(this);
4885 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4888 int adx=a2->x-a1->x;
4889 int ady=a2->y-a1->y;
4890 int bdx=b2->x-b1->x;
4891 int bdy=b2->y-b1->y;
4892 n = bdy * adx - bdx * ady;
4893 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4894 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4905 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4906 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4907 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4910 res->x = a1->x + a * adx / n;
4911 res->y = a1->y + a * ady / n;
4916 struct heightline *next;
4918 struct coord_rect bbox;
4923 struct diagram_point {
4924 struct diagram_point *next;
4928 static struct heightline *
4929 item_get_heightline(struct item *item)
4931 struct heightline *ret=NULL;
4932 struct street_data *sd;
4936 if (item_attr_get(item, attr_label, &attr)) {
4937 height=atoi(attr.u.str);
4938 sd=street_get_data(item);
4939 if (sd && sd->count > 1) {
4940 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4941 ret->bbox.lu=sd->c[0];
4942 ret->bbox.rl=sd->c[0];
4943 ret->count=sd->count;
4945 for (i = 0 ; i < sd->count ; i++) {
4947 coord_rect_extend(&ret->bbox, sd->c+i);
4950 street_data_free(sd);
4957 * @brief Displays Route Height Profile
4959 * @li The name of the active vehicle
4960 * @param wm The button that was pressed.
4964 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4968 struct widget * menu, *box;
4970 struct map * map=NULL;
4971 struct map_rect * mr=NULL;
4972 struct route * route;
4973 struct item * item =NULL;
4975 struct mapset_handle *msh;
4976 int x,i,first=1,dist=0;
4977 struct coord c,last,res;
4978 struct coord_rect rbbox,dbbox;
4979 struct map_selection sel;
4980 struct heightline *heightline,*heightlines=NULL;
4981 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4984 sel.range.min=type_height_line_1;
4985 sel.range.max=type_height_line_3;
4988 menu=gui_internal_menu(this,_("Height Profile"));
4989 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4990 gui_internal_widget_append(menu, box);
4991 route = navit_get_route(this->nav);
4993 map = route_get_map(route);
4995 mr = map_rect_new(map,NULL);
4997 while((item = map_rect_get_item(mr))) {
4998 while (item_coord_get(item, &c, 1)) {
5004 coord_rect_extend(&sel.u.c_rect, &c);
5007 map_rect_destroy(mr);
5008 ms=navit_get_mapset(this->nav);
5010 msh=mapset_open(ms);
5011 while ((map=mapset_next(msh, 1))) {
5012 mr=map_rect_new(map, &sel);
5014 while((item = map_rect_get_item(mr))) {
5015 if (item->type >= sel.range.min && item->type <= sel.range.max) {
5016 heightline=item_get_heightline(item);
5018 heightline->next=heightlines;
5019 heightlines=heightline;
5023 map_rect_destroy(mr);
5032 map = route_get_map(route);
5034 mr = map_rect_new(map,NULL);
5035 if(mr && heightlines) {
5036 while((item = map_rect_get_item(mr))) {
5038 while (item_coord_get(item, &c, 1)) {
5042 heightline=heightlines;
5045 coord_rect_extend(&rbbox, &c);
5046 while (heightline) {
5047 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
5048 for (i = 0 ; i < heightline->count - 1; i++) {
5049 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
5050 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
5051 diagram_point=g_new(struct diagram_point, 1);
5052 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
5053 diagram_point->c.y=heightline->height;
5054 diagram_point->next=diagram_points;
5055 diagram_points=diagram_point;
5056 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
5061 heightline=heightline->next;
5063 dist+=transform_distance(projection_mg, &last, &c);
5069 map_rect_destroy(mr);
5073 gui_internal_menu_render(this);
5075 diagram_point=diagram_points;
5076 while (diagram_point) {
5078 dbbox.lu=diagram_point->c;
5079 dbbox.rl=diagram_point->c;
5082 coord_rect_extend(&dbbox, &diagram_point->c);
5083 diagram_point=diagram_point->next;
5085 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
5086 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
5088 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
5090 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
5096 diagram_point=diagram_points;
5097 while (diagram_point) {
5098 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
5100 diagram_point=diagram_point->next;
5104 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
5105 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
5106 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
5107 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
5111 graphics_draw_lines(this->gra, this->foreground, p, 2);
5120 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5122 struct widget *menu,*wb,*w;
5125 graphics_draw_mode(this->gra, draw_mode_begin);
5126 menu=gui_internal_menu(this, _("Show Locale"));
5127 menu->spx=this->spacing*10;
5128 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5129 gui_internal_widget_append(menu, wb);
5130 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5131 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5132 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5134 #ifdef HAVE_API_WIN32_BASE
5136 wchar_t wcountry[32],wlang[32];
5137 char country[32],lang[32];
5139 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5140 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5141 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5142 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5143 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5145 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5146 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5147 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5148 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5149 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5154 gui_internal_menu_render(this);
5155 graphics_draw_mode(this->gra, draw_mode_end);
5160 * @brief handles the 'next page' table event.
5161 * A callback function that is invoked when the 'next page' button is pressed
5162 * to advance the contents of a table widget.
5164 * @param this The graphics context.
5165 * @param wm The button widget that was pressed.
5167 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5169 struct widget * table_widget = (struct widget * ) wm->data;
5170 struct table_data * table_data = NULL;
5176 table_data = (struct table_data*) table_widget->data;
5182 * Before advancing to the next page we need to ensure
5183 * that the current top_row is in the list of previous top_rows
5184 * so previous page can work.
5187 for(iterator=table_data->page_headers; iterator != NULL;
5188 iterator = g_list_next(iterator) )
5190 if(iterator->data == table_data->top_row)
5199 table_data->page_headers=g_list_append(table_data->page_headers,
5200 table_data->top_row);
5203 table_data->top_row = g_list_next(table_data->bottom_row);
5205 wm->state&= ~STATE_HIGHLIGHTED;
5206 gui_internal_menu_render(this);
5212 * @brief handles the 'previous page' table event.
5213 * A callback function that is invoked when the 'previous page' button is pressed
5214 * to go back in the contents of a table widget.
5216 * @param this The graphics context.
5217 * @param wm The button widget that was pressed.
5219 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5221 struct widget * table_widget = (struct widget * ) wm->data;
5222 struct table_data * table_data = NULL;
5223 GList * current_page_top=NULL;
5228 table_data = (struct table_data*) table_widget->data;
5231 current_page_top = table_data->top_row;
5232 for(iterator = table_data->page_headers; iterator != NULL;
5233 iterator = g_list_next(iterator))
5235 if(current_page_top == iterator->data)
5239 table_data->top_row = (GList*) iterator->data;
5243 wm->state&= ~STATE_HIGHLIGHTED;
5244 gui_internal_menu_render(this);
5249 * @brief deallocates a table_data structure.
5252 void gui_internal_table_data_free(void * p)
5257 * @note button_box and its children (next_button,prev_button)
5258 * have their memory managed by the table itself.
5260 struct table_data * table_data = (struct table_data*) p;
5261 g_list_free(table_data->page_headers);
5269 * @brief Called when the route is updated.
5271 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5274 if(this->route_data.route_showing) {
5275 gui_internal_populate_route_table(this,navit);
5276 graphics_draw_mode(this->gra, draw_mode_begin);
5277 gui_internal_menu_render(this);
5278 graphics_draw_mode(this->gra, draw_mode_end);
5286 * @brief Called when the route screen is closed (deallocated).
5288 * The main purpose of this function is to remove the widgets from
5289 * references route_data because those widgets are about to be freed.
5291 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5294 this_->route_data.route_showing=0;
5295 this_->route_data.route_table=NULL;
5302 * @brief Populates the route table with route information
5304 * @param this The gui context
5305 * @param navit The navit object
5307 void gui_internal_populate_route_table(struct gui_priv * this,
5308 struct navit * navit)
5310 struct map * map=NULL;
5311 struct map_rect * mr=NULL;
5312 struct navigation * nav = NULL;
5313 struct item * item =NULL;
5315 struct widget * label = NULL;
5316 struct widget * row = NULL;
5317 nav = navit_get_navigation(navit);
5321 map = navigation_get_map(nav);
5323 mr = map_rect_new(map,NULL);
5325 gui_internal_widget_table_clear(this,this->route_data.route_table);
5326 while((item = map_rect_get_item(mr))) {
5327 if(item_attr_get(item,attr_navigation_long,&attr)) {
5328 label = gui_internal_label_new(this,attr.u.str);
5329 row = gui_internal_widget_table_row_new(this,
5332 | orientation_horizontal);
5333 row->children=g_list_append(row->children,label);
5334 gui_internal_widget_append(this->route_data.route_table,row);
5342 static struct command_table commands[] = {
5343 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
5344 {"back",command_cast(gui_internal_cmd2_back)},
5345 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
5346 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
5347 {"get_data",command_cast(gui_internal_get_data)},
5348 {"locale",command_cast(gui_internal_cmd2_locale)},
5349 {"log",command_cast(gui_internal_cmd_log)},
5350 {"menu",command_cast(gui_internal_cmd_menu2)},
5351 {"position",command_cast(gui_internal_cmd2_position)},
5352 {"route_description",command_cast(gui_internal_cmd2_route_description)},
5353 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
5354 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
5355 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
5356 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
5357 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
5358 {"town",command_cast(gui_internal_cmd2_town)},
5359 {"quit",command_cast(gui_internal_cmd2_quit)},
5360 {"write",command_cast(gui_internal_cmd_write)},
5364 //##############################################################################################################
5367 //# Authors: Martin Schaller (04/2008)
5368 //##############################################################################################################
5369 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
5371 struct gui_priv *this;
5373 *meth=gui_internal_methods;
5374 this=g_new0(struct gui_priv, 1);
5377 this->self.type=attr_gui;
5378 this->self.u.gui=gui;
5380 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
5381 this->menu_on_map_click=attr->u.num;
5383 this->menu_on_map_click=1;
5384 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
5385 this->signal_on_map_click=attr->u.num;
5387 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
5388 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
5391 if( (attr=attr_search(attrs,NULL,attr_font_size)))
5393 this->config.font_size=attr->u.num;
5397 this->config.font_size=-1;
5399 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
5401 this->config.icon_xs=attr->u.num;
5405 this->config.icon_xs=-1;
5407 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
5409 this->config.icon_l=attr->u.num;
5413 this->config.icon_l=-1;
5415 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
5417 this->config.icon_s=attr->u.num;
5421 this->config.icon_s=-1;
5423 if( (attr=attr_search(attrs,NULL,attr_spacing)))
5425 this->config.spacing=attr->u.num;
5429 this->config.spacing=-1;
5431 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
5433 this->speech=attr->u.num;
5435 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
5436 this->keyboard=attr->u.num;
5440 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
5441 this->fullscreen=attr->u.num;
5443 if( (attr=attr_search(attrs,NULL,attr_flags)))
5444 this->flags=attr->u.num;
5445 if( (attr=attr_search(attrs,NULL,attr_background_color)))
5446 this->background_color=*attr->u.color;
5448 this->background_color=COLOR_BLACK;
5449 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
5450 this->background2_color=*attr->u.color;
5452 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
5453 if( (attr=attr_search(attrs,NULL,attr_text_color)))
5454 this->text_foreground_color=*attr->u.color;
5456 this->text_foreground_color=COLOR_WHITE;
5457 this->text_background_color=COLOR_BLACK;
5458 if( (attr=attr_search(attrs,NULL,attr_columns)))
5459 this->cols=attr->u.num;
5460 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
5461 this->osd_configuration=*attr;
5463 if( (attr=attr_search(attrs,NULL,attr_pitch)))
5464 this->pitch=attr->u.num;
5467 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
5468 this->flags_town=attr->u.num;
5470 this->flags_town=-1;
5471 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
5472 this->flags_street=attr->u.num;
5474 this->flags_street=-1;
5475 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
5476 this->flags_house_number=attr->u.num;
5478 this->flags_house_number=-1;
5479 this->data.priv=this;
5480 this->data.gui=&gui_internal_methods_ext;
5481 this->data.widget=&gui_internal_widget_methods;
5482 this->cbl=callback_list_new();
5487 //##############################################################################################################
5490 //# Authors: Martin Schaller (04/2008)
5491 //##############################################################################################################
5492 void plugin_init(void)
5494 plugin_register_gui_type("internal", gui_internal_new);