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;
2375 flags &= this->flags_town;
2378 gui_internal_search_town_in_country(this, wm);
2382 flags &= this->flags_street;
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 dbg(1,"res->country->flag=%s\n", res->country->flag);
2671 gui_internal_widget_append(search_list,
2672 wc=gui_internal_button_new_with_callback(this, text,
2673 image_new_xs(this, res->country->flag),
2674 gravity_left_center|orientation_horizontal|flags_fill,
2675 gui_internal_cmd_position, param));
2676 wc->name=g_strdup(name);
2679 wc->selection_id=res->id;
2682 gui_internal_widget_pack(this, search_list);
2683 l=g_list_last(this->root.children);
2684 graphics_draw_mode(this->gra, draw_mode_begin);
2685 gui_internal_widget_render(this, l->data);
2686 graphics_draw_mode(this->gra, draw_mode_end);
2691 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2693 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2694 this->idle=event_add_idle(50,this->idle_cb);
2695 callback_call_0(this->idle_cb);
2701 * @param wm The widget that generated the event for the search changed,
2702 * if this was generated by a key on the virtual keyboard then
2703 * wm is the key button widget.
2706 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2709 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2710 gui_internal_widget_children_destroy(this, search_list);
2712 void *param=(void *)3;
2714 if (! strcmp(wm->name,"Country"))
2716 if (! strcmp(wm->name,"Street"))
2718 if (! strcmp(wm->name,"House number"))
2720 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2722 gui_internal_search_idle_end(this);
2723 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2724 struct attr search_attr;
2727 if (! strcmp(wm->name,"Country"))
2728 search_attr.type=attr_country_all;
2729 if (! strcmp(wm->name,"Town"))
2730 search_attr.type=attr_town_or_district_name;
2731 if (! strcmp(wm->name,"Street"))
2732 search_attr.type=attr_street_name;
2733 if (! strcmp(wm->name,"House number"))
2734 search_attr.type=attr_house_number;
2735 search_attr.u.str=wm->text;
2736 search_list_search(this->sl, &search_attr, 1);
2737 gui_internal_search_idle_start(this, wm->name, search_list, param);
2739 l=g_list_last(this->root.children);
2740 gui_internal_widget_render(this, l->data);
2743 static struct widget *
2744 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)
2747 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2748 NULL, gravity_center|orientation_vertical, func, data));
2749 wk->data_free=data_free;
2750 wk->background=this->background;
2758 static struct widget *
2759 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2761 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2764 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2766 // Some macros that make the keyboard layout easier to visualise in
2767 // the source code. The macros are #undef'd after this function.
2768 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2769 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h)
2770 static struct widget *
2771 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2773 struct widget *wkbd,*wk;
2774 struct menu_data *md=gui_internal_menu_data(this);
2775 int i, max_w=this->root.w, max_h=this->root.h;
2781 gui_internal_highlight(this);
2783 gui_internal_widget_children_destroy(this, wkbdb);
2785 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2787 md->keyboard_mode=mode;
2788 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2789 wkbd->background=this->background;
2796 if (mode >= 0 && mode < 8) {
2797 for (i = 0 ; i < 26 ; i++) {
2798 char text[]={'A'+i,'\0'};
2801 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2808 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2810 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2813 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2815 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2817 if (mode >= 8 && mode < 16) {
2818 for (i = 0 ; i < 26 ; i++) {
2819 char text[]={'a'+i,'\0'};
2822 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2829 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2831 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2834 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2836 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2838 if (mode >= 16 && mode < 24) {
2839 for (i = 0 ; i < 10 ; i++) {
2840 char text[]={'0'+i,'\0'};
2843 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
2844 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
2846 for (i = 0 ; i < 5 ; i++) SPACER();
2854 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2856 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2859 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2861 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2863 if (mode >= 24 && mode < 32) {
2864 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
2865 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
2866 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
2867 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
2869 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2872 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2874 if (mode >= 32 && mode < 40) {
2875 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
2876 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
2877 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
2878 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
2880 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2883 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2885 gui_internal_widget_append(wkbdb, wkbd);
2887 gui_internal_widget_pack(this, wkbdb);
2888 gui_internal_widget_render(this, wkbdb);
2895 static struct widget *
2896 gui_internal_keyboard(struct gui_priv *this, int mode)
2898 if (! this->keyboard)
2900 return gui_internal_keyboard_do(this, NULL, mode);
2904 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2906 gui_internal_keyboard_do(this, key->data, key->datai);
2910 gui_internal_search_list_set_default_country(struct gui_priv *this)
2912 struct attr search_attr, country_name, country_iso2, *country_attr;
2914 struct country_search *cs;
2915 struct tracking *tracking;
2916 struct search_list_result *res;
2918 country_attr=country_default();
2919 tracking=navit_get_tracking(this->nav);
2920 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
2921 country_attr=&search_attr;
2923 cs=country_search_new(country_attr, 0);
2924 item=country_search_get_item(cs);
2925 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2926 search_attr.type=attr_country_all;
2927 dbg(0,"country %s\n", country_name.u.str);
2928 search_attr.u.str=country_name.u.str;
2929 search_list_search(this->sl, &search_attr, 0);
2930 while((res=search_list_get_result(this->sl)));
2931 g_free(this->country_iso2);
2932 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2933 this->country_iso2=g_strdup(country_iso2.u.str);
2935 country_search_destroy(cs);
2937 dbg(0,"warning: no default country found\n");
2938 if (this->country_iso2) {
2939 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2940 search_attr.type=attr_country_iso2;
2941 search_attr.u.str=this->country_iso2;
2942 search_list_search(this->sl, &search_attr, 0);
2943 while((res=search_list_get_result(this->sl)));
2949 gui_internal_search_list_new(struct gui_priv *this)
2951 struct mapset *ms=navit_get_mapset(this->nav);
2953 this->sl=search_list_new(ms);
2954 gui_internal_search_list_set_default_country(this);
2959 gui_internal_search_list_destroy(struct gui_priv *this)
2962 search_list_destroy(this->sl);
2969 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2971 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2973 gui_internal_search_list_new(this);
2974 wb=gui_internal_menu(this, what);
2975 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2976 gui_internal_widget_append(wb, w);
2977 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2978 gui_internal_widget_append(w, wr);
2979 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2980 gui_internal_widget_append(wr, we);
2982 if (!strcmp(type,"Country")) {
2983 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2984 wnext->func=gui_internal_search_town;
2985 } else if (!strcmp(type,"Town")) {
2986 if (this->country_iso2) {
2987 #if HAVE_API_ANDROID
2988 char country_iso2[strlen(this->country_iso2)+1];
2989 strtolower(country_iso2, this->country_iso2);
2990 country=g_strdup_printf("country_%s", country_iso2);
2992 country=g_strdup_printf("country_%s", this->country_iso2);
2995 country=strdup("gui_select_country");
2996 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
2997 wb->state |= STATE_SENSITIVE;
2999 wb->func = gui_internal_search_country;
3001 wb->func = gui_internal_back;
3002 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
3003 wnext->func=gui_internal_search_street;
3005 } else if (!strcmp(type,"Street")) {
3006 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
3007 wb->state |= STATE_SENSITIVE;
3008 wb->func = gui_internal_back;
3009 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
3010 wnext->func=gui_internal_search_house_number;
3011 } else if (!strcmp(type,"House number")) {
3012 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
3013 wb->state |= STATE_SENSITIVE;
3014 wb->func = gui_internal_back;
3016 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3018 gui_internal_widget_append(we, wnext);
3019 wnext->state |= STATE_SENSITIVE;
3021 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3022 gui_internal_widget_append(wr, wl);
3023 gui_internal_menu_data(this)->search_list=wl;
3024 wk->state |= STATE_EDIT;
3025 wk->background=this->background;
3026 wk->flags |= flags_expand|flags_fill;
3027 wk->func = gui_internal_search_changed;
3028 wk->name=g_strdup(type);
3030 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3031 gui_internal_menu_render(this);
3035 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3037 search_list_select(this->sl, attr_street_name, 0, 0);
3038 gui_internal_search(this,_("House number"),"House number",0);
3042 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3044 dbg(0,"id %d\n", widget->selection_id);
3045 search_list_select(this->sl, attr_street_name, 0, 0);
3046 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3047 gui_internal_search(this,_("House number"),"House number",0);
3051 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3053 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3054 gui_internal_search(this,_("Street"),"Street",0);
3058 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3060 dbg(0,"id %d\n", widget->selection_id);
3061 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3062 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3063 gui_internal_search(this,_("Street"),"Street",0);
3067 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3070 search_list_select(this->sl, attr_country_all, 0, 0);
3071 g_free(this->country_iso2);
3072 this->country_iso2=NULL;
3073 gui_internal_search(this,_("Town"),"Town",0);
3077 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3079 struct search_list_common *slc;
3080 dbg(0,"id %d\n", widget->selection_id);
3081 search_list_select(this->sl, attr_country_all, 0, 0);
3082 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3084 g_free(this->country_iso2);
3085 this->country_iso2=((struct search_list_country *)slc)->iso2;
3087 gui_internal_search(this,widget->name,"Town",0);
3091 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3093 gui_internal_prune_menu_count(this, 1, 0);
3094 gui_internal_search(this,_("Country"),"Country",0);
3098 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3101 search_list_select(this->sl, attr_country_all, 0, 0);
3102 gui_internal_search(this,_("Town"),"Town",1);
3106 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3109 struct widget *w,*wb,*wl;
3110 struct attr_iter *iter;
3113 wb=gui_internal_menu(this, _("Layout"));
3114 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3115 w->spy=this->spacing*3;
3116 gui_internal_widget_append(wb, w);
3117 iter=navit_attr_iter_new();
3118 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3119 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3121 gui_internal_widget_append(w, wl);
3123 navit_attr_iter_destroy(iter);
3124 gui_internal_menu_render(this);
3128 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3131 navit.type=attr_navit;
3132 navit.u.navit=this->nav;
3133 navit_destroy(navit.u.navit);
3134 config_remove_attr(config, &navit);
3135 event_main_loop_quit();
3139 gui_internal_window_closed(struct gui_priv *this)
3141 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3145 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3147 navit_set_destination(this->nav, NULL, NULL, 0);
3152 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3154 struct attr attr, on, off, description, type, data;
3155 struct widget *w,*wb,*wma;
3157 struct attr_iter *iter;
3160 wb=gui_internal_menu(this, _("Maps"));
3161 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3162 w->spy=this->spacing*3;
3163 gui_internal_widget_append(wb, w);
3164 iter=navit_attr_iter_new();
3165 on.type=off.type=attr_active;
3168 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3169 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3170 label=g_strdup(description.u.str);
3172 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3174 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3176 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3178 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3179 attr.u.map, &on, &off, 1);
3180 gui_internal_widget_append(w, wma);
3183 navit_attr_iter_destroy(iter);
3184 gui_internal_menu_render(this);
3188 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3190 struct attr vehicle = {attr_vehicle,{wm->data}};
3191 navit_set_attr(this->nav, &vehicle);
3195 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3197 struct widget *w,*wb,*row;
3198 struct attr attr,sat_attr;
3199 struct vehicle *v=wm->data;
3202 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3204 wb=gui_internal_menu(this, _("Show Satellite Status"));
3205 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3206 gui_internal_menu_data(this)->redisplay_widget=wm;
3207 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3208 gui_internal_widget_append(wb, w);
3209 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3210 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3211 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3212 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3213 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3214 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3215 gui_internal_widget_append(w,row);
3216 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3217 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3218 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3219 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3220 str=g_strdup_printf("%d", sat_attr.u.num);
3223 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3226 gui_internal_widget_append(w,row);
3228 gui_internal_widget_append(wb, w);
3229 gui_internal_menu_render(this);
3233 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3235 struct widget *w,*wb;
3237 struct vehicle *v=wm->data;
3238 wb=gui_internal_menu(this, _("Show NMEA Data"));
3239 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3240 gui_internal_menu_data(this)->redisplay_widget=wm;
3241 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3242 gui_internal_widget_append(wb, w);
3243 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3244 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3245 gui_internal_menu_render(this);
3249 * A container to hold the selected vehicle and the desired profile in
3252 struct vehicle_and_profilename {
3253 struct vehicle *vehicle;
3258 * Figures out whether the given vehicle is the active vehicle.
3260 * @return true if the vehicle is active, false otherwise.
3263 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3266 struct attr active_vehicle;
3268 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3269 active_vehicle.u.vehicle=NULL;
3271 return active_vehicle.u.vehicle == vehicle;
3275 save_vehicle_xml(struct vehicle *v)
3278 struct attr_iter *iter=vehicle_attr_iter_new();
3282 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3283 if (ATTR_IS_OBJECT(attr.type))
3286 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3290 printf("</vehicle>\n");
3293 vehicle_attr_iter_destroy(iter);
3298 * Reacts to a button press that changes a vehicle's active profile.
3300 * @see gui_internal_add_vehicle_profile
3303 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3304 widget *wm, void *data)
3306 struct vehicle_and_profilename *vapn = data;
3307 struct vehicle *v = vapn->vehicle;
3308 char *profilename = vapn->profilename;
3309 struct attr vehicle_name_attr;
3310 char *vehicle_name = NULL;
3312 // Get the vehicle name
3313 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3314 vehicle_name = vehicle_name_attr.u.str;
3316 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3319 // Change the profile name
3320 struct attr profilename_attr = {attr_profilename, {profilename}};
3321 if(!vehicle_set_attr(v, &profilename_attr)) {
3322 dbg(0, "Unable to set the vehicle's profile name\n");
3325 // Notify Navit that the routing should be re-done if this is the
3327 if (gui_internal_is_active_vehicle(this, v)) {
3328 struct attr vehicle;
3329 vehicle.type=attr_vehicle;
3330 vehicle.u.vehicle=v;
3331 navit_set_attr(this->nav, &vehicle);
3333 save_vehicle_xml(v);
3337 * Adds the vehicle profile to the GUI, allowing the user to pick a
3338 * profile for the currently selected vehicle.
3341 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3342 *parent, struct vehicle *v, struct vehicleprofile *profile)
3344 // Just here to show up in the translation file, nice and close to
3345 // where the translations are actually used.
3346 struct attr profile_attr;
3347 struct attr *attr = NULL;
3349 char *active_profile = NULL;
3352 struct vehicle_and_profilename *context = NULL;
3354 #ifdef ONLY_FOR_TRANSLATION
3355 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3358 // Figure out the profile name
3359 attr = attr_search(profile->attrs, NULL, attr_name);
3362 // Determine whether the profile is the active one
3363 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3364 active_profile = profile_attr.u.str;
3365 active = strcmp(name, active_profile) == 0;
3367 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3368 active_profile, active);
3370 // Build a translatable label.
3372 label = g_strdup_printf(_("Current profile: %s"), _(name));
3374 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3377 // Create the context object (the vehicle and the desired profile)
3378 context = g_new0(struct vehicle_and_profilename, 1);
3379 context->vehicle = v;
3380 context->profilename = name;
3383 gui_internal_widget_append(parent,
3384 gui_internal_button_new_with_callback(
3386 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3387 gravity_left_center|orientation_horizontal|flags_fill,
3388 gui_internal_cmd_set_active_profile, context));
3394 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3396 struct widget *w,*wb;
3398 struct vehicle *v=wm->data;
3399 struct vehicleprofile *profile = NULL;
3401 wb=gui_internal_menu(this, wm->text);
3402 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3403 gui_internal_widget_append(wb, w);
3405 // Add the "Set as active" button if this isn't the active
3407 if (!gui_internal_is_active_vehicle(this, v)) {
3408 gui_internal_widget_append(w,
3409 gui_internal_button_new_with_callback(this, _("Set as active"),
3410 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3411 gui_internal_cmd_set_active_vehicle, wm->data));
3414 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3415 gui_internal_widget_append(w,
3416 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3417 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3418 gui_internal_cmd_show_satellite_status, wm->data));
3420 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3421 gui_internal_widget_append(w,
3422 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3423 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3424 gui_internal_cmd_show_nmea_data, wm->data));
3427 // Add all the possible vehicle profiles to the menu
3428 GList *profiles = navit_get_vehicleprofiles(this->nav);
3430 profile = (struct vehicleprofile *)profiles->data;
3431 gui_internal_add_vehicle_profile(this, w, v, profile);
3432 profiles = g_list_next(profiles);
3435 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3436 gui_internal_menu_render(this);
3440 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3442 struct attr attr,vattr;
3443 struct widget *w,*wb,*wl;
3444 struct attr_iter *iter;
3445 struct attr active_vehicle;
3448 wb=gui_internal_menu(this, _("Vehicle"));
3449 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3450 w->spy=this->spacing*3;
3451 gui_internal_widget_append(wb, w);
3452 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3453 active_vehicle.u.vehicle=NULL;
3454 iter=navit_attr_iter_new();
3455 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3456 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3457 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3458 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3459 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3460 wl->text=g_strdup(vattr.u.str);
3461 gui_internal_widget_append(w, wl);
3463 navit_attr_iter_destroy(iter);
3464 gui_internal_menu_render(this);
3469 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3471 struct widget *wb,*w;
3473 wb=gui_internal_menu(this, _("Rules"));
3474 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3475 w->spy=this->spacing*3;
3476 gui_internal_widget_append(wb, w);
3479 on.type=off.type=attr_tracking;
3480 gui_internal_widget_append(w,
3481 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3485 on.type=off.type=attr_orientation;
3486 gui_internal_widget_append(w,
3487 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3491 on.type=off.type=attr_follow_cursor;
3492 gui_internal_widget_append(w,
3493 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3495 gui_internal_menu_render(this);
3498 //##############################################################################################################
3501 //# Authors: Martin Schaller (04/2008)
3502 //##############################################################################################################
3503 static void gui_internal_motion(void *data, struct point *p)
3506 struct gui_priv *this=data;
3507 if (!this->root.children) {
3508 navit_handle_motion(this->nav, p);
3514 if(!this->motion_timeout_callback)
3515 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3516 if(!this->motion_timeout_event)
3517 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3521 find_attr(const char **names, const char **values, const char *name)
3524 if (!strcasecmp(*names, name))
3526 names+=xml_attr_distance;
3527 values+=xml_attr_distance;
3533 find_attr_dup(const char **names, const char **values, const char *name)
3535 return g_strdup(find_attr(names, values, name));
3539 gui_internal_evaluate(struct gui_priv *this, const char *command)
3542 command_evaluate(&this->self, command);
3547 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
3549 gui_internal_evaluate(this,w->command);
3553 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
3555 if (w->command && w->command[0] == '#') {
3556 dbg(1,"href=%s\n",w->command);
3557 gui_internal_html_menu(this, this->html_text, w->command+1);
3563 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
3565 struct gui_priv *this=data;
3567 enum html_tag tag=html_tag_none;
3568 struct html *html=&this->html[this->html_depth];
3569 const char *src, *cond;
3571 if (!strcasecmp(tag_name,"text"))
3577 cond=find_attr(names, values, "cond");
3579 if (cond && !this->html_skip) {
3580 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
3584 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
3585 if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
3586 tag=html_tag_map[i].tag;
3591 if (!this->html_skip && !html->skip) {
3594 html->name=find_attr_dup(names, values, "name");
3596 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
3598 this->html_anchor_found=1;
3600 html->href=find_attr_dup(names, values, "href");
3603 html->command=find_attr_dup(names, values, "onclick");
3604 src=find_attr(names, values, "src");
3606 html->w=gui_internal_image_new(this, image_new_l(this, src));
3612 this->html_skip+=html->skip;
3617 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
3619 struct gui_priv *this=data;
3621 struct html *parent=NULL;
3623 if (!strcasecmp(tag_name,"text"))
3626 html=&this->html[this->html_depth];
3627 if (this->html_depth > 0)
3628 parent=&this->html[this->html_depth-1];
3631 if (!this->html_skip) {
3632 if (html->command && html->w) {
3633 html->w->state |= STATE_SENSITIVE;
3634 html->w->command=html->command;
3635 html->w->func=gui_internal_html_command;
3638 if (parent && parent->href && html->w) {
3639 html->w->state |= STATE_SENSITIVE;
3640 html->w->command=g_strdup(parent->href);
3641 html->w->func=gui_internal_html_href;
3643 switch (html->tag) {
3645 gui_internal_widget_append(this->html_container, html->w);
3651 this->html_skip-=html->skip;
3652 g_free(html->command);
3658 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
3660 struct gui_priv *this=data;
3662 int depth=this->html_depth-1;
3663 struct html *html=&this->html[depth];
3664 char *text_stripped;
3666 if (this->html_skip)
3668 while (isspace(text[0])) {
3672 while (len > 0 && isspace(text[len-1]))
3674 text_stripped=g_malloc(len+1);
3675 strncpy(text_stripped, text, len);
3676 text_stripped[len]='\0';
3677 if (html->tag == html_tag_html && depth > 2) {
3678 if (this->html[depth-1].tag == html_tag_script) {
3679 html=&this->html[depth-2];
3682 switch (html->tag) {
3684 if (html->name && len) {
3685 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3686 this->html_container->spx=this->spacing*10;
3690 if (!this->html_container) {
3691 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3692 this->html_container->spx=this->spacing*10;
3697 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
3698 gui_internal_widget_append(w, html->w);
3699 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
3703 case html_tag_script:
3704 dbg(1,"execute %s\n",text_stripped);
3705 gui_internal_evaluate(this,text_stripped);
3713 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
3715 graphics_draw_mode(this->gra, draw_mode_begin);
3716 this->html_container=NULL;
3718 this->html_anchor=anchor;
3719 this->html_anchor_found=0;
3720 xml_parse_text(document, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
3721 gui_internal_menu_render(this);
3722 graphics_draw_mode(this->gra, draw_mode_end);
3726 static void gui_internal_menu_root(struct gui_priv *this)
3728 gui_internal_html_menu(this, this->html_text, "Main Menu");
3732 gui_internal_enter(struct gui_priv *this, int ignore)
3734 struct graphics *gra=this->gra;
3735 this->ignore_button=ignore;
3736 this->clickp_valid=this->vehicle_valid=0;
3738 navit_block(this->nav, 1);
3739 graphics_overlay_disable(gra, 1);
3742 this->root.background=this->background;
3746 gui_internal_leave(struct gui_priv *this)
3748 graphics_draw_mode(this->gra, draw_mode_end);
3752 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3754 struct transformation *trans;
3757 struct attr attr,attrp;
3760 gui_internal_enter(this, ignore);
3761 trans=navit_get_trans(this->nav);
3762 attr_free(this->click_coord_geo);
3763 this->click_coord_geo=NULL;
3764 attr_free(this->position_coord_geo);
3765 this->position_coord_geo=NULL;
3767 transform_reverse(trans, p, &c);
3768 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
3769 this->clickp.pro=transform_get_projection(trans);
3772 transform_to_geo(this->clickp.pro, &c, &g);
3773 attr.u.coord_geo=&g;
3774 attr.type=attr_click_coord_geo;
3775 this->click_coord_geo=attr_dup(&attr);
3777 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3778 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3779 this->position_coord_geo=attr_dup(&attrp);
3780 this->vehiclep.pro=transform_get_projection(trans);
3781 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3782 this->vehiclep.x=c.x;
3783 this->vehiclep.y=c.y;
3784 this->vehicle_valid=1;
3787 gui_internal_menu_root(this);
3791 gui_internal_cmd_menu2(struct gui_priv *this)
3793 gui_internal_cmd_menu(this, NULL, 1);
3798 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
3800 if (widget->text && strlen(widget->text))
3801 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
3802 g_free(widget->text);
3804 gui_internal_prune_menu(this, NULL);
3805 gui_internal_check_exit(this);
3809 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
3811 gui_internal_cmd_log_do(this, widget->data);
3815 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
3819 len=strlen(wm->text);
3820 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
3821 wm->text[len-1]='\0';
3822 gui_internal_cmd_log_do(this, wm);
3829 gui_internal_cmd_log(struct gui_priv *this)
3831 struct widget *w,*wb,*wk,*wl,*we,*wnext;
3832 gui_internal_enter(this, 1);
3833 wb=gui_internal_menu(this, "Log Message");
3834 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3835 gui_internal_widget_append(wb, w);
3836 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3837 gui_internal_widget_append(w, we);
3838 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
3839 wk->state |= STATE_EDIT|STATE_CLEAR;
3840 wk->background=this->background;
3841 wk->flags |= flags_expand|flags_fill;
3842 wk->func = gui_internal_cmd_log_changed;
3843 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3844 wnext->state |= STATE_SENSITIVE;
3845 wnext->func = gui_internal_cmd_log_clicked;
3847 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3848 gui_internal_widget_append(w, wl);
3850 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3851 gui_internal_menu_render(this);
3852 gui_internal_leave(this);
3856 gui_internal_check_exit(struct gui_priv *this)
3858 struct graphics *gra=this->gra;
3859 if (! this->root.children) {
3860 gui_internal_search_idle_end(this);
3861 gui_internal_search_list_destroy(this);
3862 graphics_overlay_disable(gra, 0);
3863 if (!navit_block(this->nav, 0)) {
3865 navit_draw(this->nav);
3867 navit_draw_displaylist(this->nav);
3873 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
3877 attr->u.num=this->root.children != NULL;
3879 case attr_click_coord_geo:
3880 if (!this->click_coord_geo)
3882 *attr=*this->click_coord_geo;
3884 case attr_position_coord_geo:
3885 if (!this->position_coord_geo)
3887 *attr=*this->position_coord_geo;
3890 attr->u.num=this->pitch;
3900 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
3902 switch (attr->type) {
3904 g_free(this->html_text);
3905 this->html_text=g_strdup(attr->u.str);
3913 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
3915 switch (attr->type) {
3916 case attr_fullscreen:
3917 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
3918 graphics_draw_mode(this->gra, draw_mode_end);
3919 this->win->fullscreen(this->win, attr->u.num > 0);
3920 graphics_draw_mode(this->gra, draw_mode_begin);
3922 this->fullscreen=attr->u.num;
3925 dbg(0,"%s\n",attr_to_name(attr->type));
3930 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
3932 struct displaylist_handle *dlh;
3933 struct displaylist *display;
3934 struct displayitem *di;
3936 display=navit_get_displaylist(this->nav);
3937 dlh=graphics_displaylist_open(display);
3938 while ((di=graphics_displaylist_next(dlh))) {
3939 struct item *item=graphics_displayitem_get_item(di);
3940 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
3941 graphics_displayitem_within_dist(display, di, p, 10)) {
3942 struct map_rect *mr=map_rect_new(item->map, NULL);
3943 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
3945 if (item_attr_get(itemo, attr_data, &attr)) {
3946 struct attr cb,*attr_list[2];
3948 attr.type=attr_data;
3951 if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
3952 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
3954 map_rect_destroy(mr);
3957 graphics_displaylist_close(dlh);
3961 //##############################################################################################################
3962 //# Description: Function to handle mouse clicks and scroll wheel movement
3964 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3965 //##############################################################################################################
3966 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3968 struct gui_priv *this=data;
3969 struct graphics *gra=this->gra;
3971 dbg(1,"enter %d %d\n", pressed, button);
3972 // if still on the map (not in the menu, yet):
3973 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
3974 if (!this->root.children || this->ignore_button) {
3976 this->ignore_button=0;
3977 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3978 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
3979 dbg(1,"navit has handled button\n");
3982 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
3985 if (this->menu_on_map_click) {
3986 gui_internal_cmd_menu(this, p, 0);
3989 if (this->signal_on_map_click) {
3990 gui_internal_dbus_signal(this, p);
3997 // if already in the menu:
4001 gui_internal_highlight(this);
4006 graphics_draw_mode(gra, draw_mode_begin);
4007 gui_internal_call_highlighted(this);
4008 gui_internal_highlight(this);
4009 graphics_draw_mode(gra, draw_mode_end);
4010 gui_internal_check_exit(this);
4015 gui_internal_setup_gc(struct gui_priv *this)
4017 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
4018 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
4019 struct graphics *gra=this->gra;
4021 if (this->background)
4023 this->background=graphics_gc_new(gra);
4024 this->background2=graphics_gc_new(gra);
4025 this->highlight_background=graphics_gc_new(gra);
4026 graphics_gc_set_foreground(this->highlight_background, &cbh);
4027 this->foreground=graphics_gc_new(gra);
4028 graphics_gc_set_foreground(this->foreground, &cf);
4029 this->text_background=graphics_gc_new(gra);
4030 this->text_foreground=graphics_gc_new(gra);
4031 graphics_gc_set_foreground(this->background, &this->background_color);
4032 graphics_gc_set_foreground(this->background2, &this->background2_color);
4033 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
4034 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
4037 //##############################################################################################################
4040 //# Authors: Martin Schaller (04/2008)
4041 //##############################################################################################################
4042 static void gui_internal_resize(void *data, int w, int h)
4044 struct gui_priv *this=data;
4047 gui_internal_setup_gc(this);
4049 if (this->root.w != w || this->root.h != h) {
4054 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
4055 navit_handle_resize(this->nav, w, h);
4056 if (this->root.children && changed) {
4057 gui_internal_prune_menu(this, NULL);
4058 gui_internal_menu_root(this);
4063 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
4078 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
4080 GList *l=wi->children;
4081 if (wi->state & STATE_SENSITIVE) {
4084 gui_internal_keynav_point(wi, -dx, -dy, &wp);
4086 dist1=(wp.x-p->x)*dx;
4089 dist1=(wp.y-p->y)*dy;
4097 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);
4103 if (dist1 < *distance) {
4110 struct widget *child=l->data;
4111 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
4117 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
4119 struct widget *result,*menu=g_list_last(this->root.children)->data;
4122 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4123 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
4129 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
4131 gui_internal_keynav_point(result, dx, dy, &p);
4132 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
4137 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4138 dbg(1,"result=%p\n", result);
4150 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4151 dbg(1,"wraparound result=%p\n", result);
4153 gui_internal_highlight_do(this, result);
4155 gui_internal_say(this, result, 1);
4158 //##############################################################################################################
4161 //# Authors: Martin Schaller (04/2008)
4162 //##############################################################################################################
4163 static void gui_internal_keypress(void *data, char *key)
4165 struct gui_priv *this=data;
4168 if (!this->root.children) {
4169 transform_get_size(navit_get_trans(this->nav), &w, &h);
4174 navit_set_center_screen(this->nav, &p, 1);
4176 case NAVIT_KEY_DOWN:
4179 navit_set_center_screen(this->nav, &p, 1);
4181 case NAVIT_KEY_LEFT:
4184 navit_set_center_screen(this->nav, &p, 1);
4186 case NAVIT_KEY_RIGHT:
4189 navit_set_center_screen(this->nav, &p, 1);
4191 case NAVIT_KEY_ZOOM_IN:
4192 navit_zoom_in(this->nav, 2, NULL);
4194 case NAVIT_KEY_ZOOM_OUT:
4195 navit_zoom_out(this->nav, 2, NULL);
4197 case NAVIT_KEY_RETURN:
4198 case NAVIT_KEY_MENU:
4199 gui_internal_cmd_menu(this, NULL, 0);
4204 graphics_draw_mode(this->gra, draw_mode_begin);
4206 case NAVIT_KEY_LEFT:
4207 gui_internal_keynav_highlight_next(this,-1,0);
4209 case NAVIT_KEY_RIGHT:
4210 gui_internal_keynav_highlight_next(this,1,0);
4213 gui_internal_keynav_highlight_next(this,0,-1);
4215 case NAVIT_KEY_DOWN:
4216 gui_internal_keynav_highlight_next(this,0,1);
4218 case NAVIT_KEY_BACK:
4220 case NAVIT_KEY_RETURN:
4221 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4222 gui_internal_call_highlighted(this);
4224 gui_internal_keypress_do(this, key);
4227 gui_internal_keypress_do(this, key);
4229 graphics_draw_mode(this->gra, draw_mode_end);
4230 gui_internal_check_exit(this);
4234 //##############################################################################################################
4237 //# Authors: Martin Schaller (04/2008)
4238 //##############################################################################################################
4239 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4242 struct transformation *trans=navit_get_trans(this->nav);
4244 win=graphics_get_data(gra, "window");
4247 navit_ignore_graphics_events(this->nav, 1);
4250 navit_ignore_graphics_events(this->nav, 1);
4251 transform_get_size(trans, &this->root.w, &this->root.h);
4252 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4253 graphics_add_callback(gra, this->resize_cb);
4254 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4255 graphics_add_callback(gra, this->button_cb);
4256 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4257 graphics_add_callback(gra, this->motion_cb);
4258 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4259 graphics_add_callback(gra, this->keypress_cb);
4260 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
4261 graphics_add_callback(gra, this->window_closed_cb);
4263 // set fullscreen if needed
4264 if (this->fullscreen)
4265 this->win->fullscreen(this->win, this->fullscreen != 0);
4266 /* Was resize callback already issued? */
4267 if (navit_get_ready(this->nav) & 2)
4268 gui_internal_setup_gc(this);
4272 static void gui_internal_disable_suspend(struct gui_priv *this)
4274 if (this->win->disable_suspend)
4275 this->win->disable_suspend(this->win);
4278 //##############################################################################################################
4281 //# Authors: Martin Schaller (04/2008)
4282 //##############################################################################################################
4283 struct gui_methods gui_internal_methods = {
4286 gui_internal_set_graphics,
4290 gui_internal_disable_suspend,
4291 gui_internal_get_attr,
4292 gui_internal_add_attr,
4293 gui_internal_set_attr,
4297 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4299 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4301 *out=attr_generic_add_attr(*out, &private_data);
4305 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4307 callback_list_add(priv->cbl, cb);
4311 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4313 callback_list_remove(priv->cbl, cb);
4317 static struct gui_internal_methods gui_internal_methods_ext = {
4318 gui_internal_add_callback,
4319 gui_internal_remove_callback,
4320 gui_internal_menu_render,
4327 gui_internal_get_flags(struct widget *widget)
4329 return widget->flags;
4333 gui_internal_set_flags(struct widget *widget, enum flags flags)
4335 widget->flags=flags;
4339 gui_internal_get_state(struct widget *widget)
4341 return widget->state;
4345 gui_internal_set_state(struct widget *widget, int state)
4347 widget->state=state;
4351 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4357 gui_internal_set_data(struct widget *widget, void *data)
4363 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4365 widget->background=this->background;
4368 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4369 gui_internal_widget_append,
4370 gui_internal_button_new,
4371 gui_internal_button_new_with_callback,
4372 gui_internal_box_new,
4373 gui_internal_label_new,
4374 gui_internal_image_new,
4375 gui_internal_keyboard,
4377 gui_internal_get_flags,
4378 gui_internal_set_flags,
4379 gui_internal_get_state,
4380 gui_internal_set_state,
4381 gui_internal_set_func,
4382 gui_internal_set_data,
4383 gui_internal_set_default_background,
4387 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
4389 char *str=NULL,*str2=NULL;
4390 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
4393 dbg(1,"%s\n",attr_to_name(in[0]->type));
4394 if (ATTR_IS_STRING(in[0]->type)) {
4397 if (ATTR_IS_COORD_GEO(in[0]->type)) {
4398 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
4401 str=g_strdup_printf("<html>%s</html>\n",str);
4402 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4410 * @brief Creates a new table widget.
4412 * Creates and returns a new table widget. This function will
4413 * setup next/previous buttons as children.
4415 * @param this The graphics context.
4416 * @param flags widget sizing flags.
4417 * @returns The newly created widget
4419 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4421 struct widget * widget = g_new0(struct widget,1);
4422 struct table_data * data = NULL;
4423 widget->type=widget_table;
4424 widget->flags=flags;
4425 widget->data = g_new0(struct table_data,1);
4426 widget->data_free=gui_internal_table_data_free;
4427 data = (struct table_data*)widget->data;
4431 data->next_button = gui_internal_button_new_with_callback
4432 (this,"Next",image_new_xs(this, "gui_active") ,
4433 gravity_left_center |orientation_vertical,
4434 gui_internal_table_button_next,NULL);
4435 data->next_button->data=widget;
4438 data->prev_button = gui_internal_button_new_with_callback
4440 image_new_xs(this, "gui_active")
4441 ,gravity_right_center |orientation_vertical,
4442 gui_internal_table_button_prev,NULL);
4444 data->prev_button->data=widget;
4448 data->button_box=gui_internal_box_new(this,
4449 gravity_center|orientation_horizontal);
4450 data->button_box->children=g_list_append(data->button_box->children,
4452 data->button_box->children=g_list_append(data->button_box->children,
4454 //data->button_box->background=this->background2;
4455 data->button_box->bl=this->spacing;
4456 widget->children=g_list_append(widget->children,data->button_box);
4457 gui_internal_widget_pack(this,data->button_box);
4465 * @brief Clears all the rows from the table.
4466 * This function removes all rows from a table.
4467 * New rows can later be added to the table.
4469 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4472 struct table_data * table_data = (struct table_data* ) table->data;
4474 iter = table->children;
4476 if(iter->data != table_data->button_box) {
4477 struct widget * child = (struct widget*)iter->data;
4478 gui_internal_widget_destroy(this,child);
4479 if(table->children == iter) {
4480 table->children = g_list_remove(iter,iter->data);
4481 iter=table->children;
4484 iter = g_list_remove(iter,iter->data);
4487 iter = g_list_next(iter);
4491 table_data->top_row=NULL;
4492 table_data->bottom_row=NULL;
4493 if(table_data->page_headers)
4494 g_list_free(table_data->page_headers);
4495 table_data->page_headers=NULL;
4500 * Creates a new table_row widget.
4501 * @param this The graphics context
4502 * @param flags Sizing flags for the row
4503 * @returns The new table_row widget.
4505 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4507 struct widget * widget = g_new0(struct widget,1);
4508 widget->type=widget_table_row;
4509 widget->flags=flags;
4516 * @brief Computes the column dimensions for the table.
4518 * @param w The table widget to compute dimensions for.
4520 * This function examines all of the rows and columns for the table w
4521 * and returns a list (GList) of table_column_desc elements that
4522 * describe each column of the table.
4524 * The caller is responsible for freeing the returned list.
4526 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4529 GList * column_desc = NULL;
4530 GList * current_desc=NULL;
4531 GList * cur_row = w->children;
4532 struct widget * cur_row_widget=NULL;
4533 GList * cur_column=NULL;
4534 struct widget * cell_w=NULL;
4535 struct table_column_desc * current_cell=NULL;
4536 struct table_data * table_data=NULL;
4543 * Scroll through the the table and
4544 * 1. Compute the maximum width + height of each column across all rows.
4546 table_data = (struct table_data*) w->data;
4547 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4549 cur_row_widget = (struct widget*) cur_row->data;
4550 current_desc = column_desc;
4551 if(cur_row_widget == table_data->button_box)
4556 for(cur_column = cur_row_widget->children; cur_column;
4557 cur_column=g_list_next(cur_column))
4559 cell_w = (struct widget*) cur_column->data;
4560 gui_internal_widget_pack(this,cell_w);
4561 if(current_desc == 0)
4563 current_cell = g_new0(struct table_column_desc,1);
4564 column_desc = g_list_append(column_desc,current_cell);
4565 current_desc = g_list_last(column_desc);
4566 current_cell->height=cell_w->h;
4567 current_cell->width=cell_w->w;
4568 total_width+=cell_w->w;
4573 current_cell = current_desc->data;
4576 if(current_cell->height < height )
4578 current_cell->height = height;
4580 if(current_cell->width < width)
4582 total_width += (width-current_cell->width);
4583 current_cell->width = width;
4588 current_desc = g_list_next(current_desc);
4598 * If the width of all columns is less than the width off
4599 * the table expand each cell proportionally.
4602 if(total_width+(this->spacing*column_count) < w->w ) {
4603 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4604 current_cell = (struct table_column_desc*) current_desc->data;
4605 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4614 * @brief Computes the height and width for the table.
4616 * The height and widht are computed to display all cells in the table
4617 * at the requested height/width.
4619 * @param this The graphics context
4620 * @param w The widget to pack.
4623 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4629 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4631 struct table_column_desc * cell_desc=0;
4632 struct table_data * table_data = (struct table_data*)w->data;
4634 for(current = column_data; current; current=g_list_next(current))
4636 if(table_data->button_box == current->data )
4640 cell_desc = (struct table_column_desc *) current->data;
4641 width = width + cell_desc->width + this->spacing;
4642 if(height < cell_desc->height)
4644 height = cell_desc->height ;
4650 for(current=w->children; current; current=g_list_next(current))
4652 if(current->data!= table_data->button_box)
4657 if (table_data->button_box)
4658 gui_internal_widget_pack(this,table_data->button_box);
4662 if(w->h + w->c.y > this->root.h )
4665 * Do not allow the widget to exceed the screen.
4668 w->h = this->root.h- w->c.y - height;
4673 * Deallocate column descriptions.
4675 current = column_data;
4676 while( (current = g_list_last(current)) )
4678 current = g_list_remove(current,current->data);
4686 * @brief Renders a table widget.
4688 * @param this The graphics context
4689 * @param w The table widget to render.
4691 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4696 GList * column_desc=NULL;
4697 GList * cur_row = NULL;
4698 GList * current_desc=NULL;
4699 struct table_data * table_data = (struct table_data*)w->data;
4701 int is_first_page=1;
4702 struct table_column_desc * dim=NULL;
4704 dbg_assert(table_data);
4705 column_desc = gui_internal_compute_table_dimensions(this,w);
4709 * Skip rows that are on previous pages.
4711 cur_row = w->children;
4712 if(table_data->top_row && table_data->top_row != w->children )
4714 cur_row = table_data->top_row;
4720 * Loop through each row. Drawing each cell with the proper sizes,
4721 * at the proper positions.
4723 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4725 GList * cur_column=NULL;
4726 current_desc = column_desc;
4727 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4729 x =w->p.x+this->spacing;
4730 if(cur_row_widget == table_data->button_box )
4734 dim = (struct table_column_desc*)current_desc->data;
4736 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4739 * No more drawing space left.
4745 for(cur_column = cur_row_widget->children; cur_column;
4746 cur_column=g_list_next(cur_column))
4748 struct widget * cur_widget = (struct widget*) cur_column->data;
4749 dim = (struct table_column_desc*)current_desc->data;
4752 cur_widget->w=dim->width;
4754 cur_widget->h=dim->height;
4756 max_height = dim->height;
4757 /* We pack the widget before rendering to ensure that the x and y
4758 * coordinates get pushed down.
4760 gui_internal_widget_pack(this,cur_widget);
4761 gui_internal_widget_render(this,cur_widget);
4763 if(dim->height > max_height)
4765 max_height = dim->height;
4769 table_data->bottom_row=cur_row;
4770 current_desc = g_list_next(current_desc);
4772 if(table_data->button_box && (is_skipped || !is_first_page) )
4774 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4776 if(table_data->button_box->p.y < y )
4778 table_data->button_box->p.y=y;
4780 table_data->button_box->p.x = w->p.x;
4781 table_data->button_box->w = w->w;
4782 // table_data->button_box->h = w->h - y;
4783 // table_data->next_button->h=table_data->button_box->h;
4784 // table_data->prev_button->h=table_data->button_box->h;
4785 // table_data->next_button->c.y=table_data->button_box->c.y;
4786 // table_data->prev_button->c.y=table_data->button_box->c.y;
4788 gui_internal_widget_pack(this,table_data->button_box);
4789 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4792 table_data->button_box->p.y = w->p.y + w->h -
4793 table_data->button_box->h;
4797 table_data->next_button->state|= STATE_SENSITIVE;
4801 table_data->next_button->state&= ~STATE_SENSITIVE;
4804 if(table_data->top_row != w->children)
4806 table_data->prev_button->state|= STATE_SENSITIVE;
4810 table_data->prev_button->state&= ~STATE_SENSITIVE;
4812 gui_internal_widget_render(this,table_data->button_box);
4818 * Deallocate column descriptions.
4820 current_desc = column_desc;
4821 while( (current_desc = g_list_last(current_desc)) )
4823 current_desc = g_list_remove(current_desc,current_desc->data);
4829 * @brief Displays Route information
4831 * @li The name of the active vehicle
4832 * @param wm The button that was pressed.
4836 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4840 struct widget * menu;
4841 struct widget * row;
4844 if(! this->vehicle_cb)
4847 * Register the callback on vehicle updates.
4849 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4850 attr_position_coord_geo,this);
4851 navit_add_callback(this->nav,this->vehicle_cb);
4854 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4855 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4857 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4860 menu=gui_internal_menu(this,_("Route Description"));
4862 menu->free=gui_internal_route_screen_free;
4863 this->route_data.route_showing=1;
4864 this->route_data.route_table->spx = this->spacing;
4867 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4869 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4870 gui_internal_widget_append(box,this->route_data.route_table);
4872 box->spx = this->spacing;
4873 this->route_data.route_table->w=box->w;
4874 gui_internal_widget_append(menu,box);
4875 gui_internal_populate_route_table(this,this->nav);
4876 gui_internal_menu_render(this);
4881 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4884 int adx=a2->x-a1->x;
4885 int ady=a2->y-a1->y;
4886 int bdx=b2->x-b1->x;
4887 int bdy=b2->y-b1->y;
4888 n = bdy * adx - bdx * ady;
4889 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4890 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4901 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4902 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4903 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4906 res->x = a1->x + a * adx / n;
4907 res->y = a1->y + a * ady / n;
4912 struct heightline *next;
4914 struct coord_rect bbox;
4919 struct diagram_point {
4920 struct diagram_point *next;
4924 static struct heightline *
4925 item_get_heightline(struct item *item)
4927 struct heightline *ret=NULL;
4928 struct street_data *sd;
4932 if (item_attr_get(item, attr_label, &attr)) {
4933 height=atoi(attr.u.str);
4934 sd=street_get_data(item);
4935 if (sd && sd->count > 1) {
4936 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4937 ret->bbox.lu=sd->c[0];
4938 ret->bbox.rl=sd->c[0];
4939 ret->count=sd->count;
4941 for (i = 0 ; i < sd->count ; i++) {
4943 coord_rect_extend(&ret->bbox, sd->c+i);
4946 street_data_free(sd);
4953 * @brief Displays Route Height Profile
4955 * @li The name of the active vehicle
4956 * @param wm The button that was pressed.
4960 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4964 struct widget * menu, *box;
4966 struct map * map=NULL;
4967 struct map_rect * mr=NULL;
4968 struct route * route;
4969 struct item * item =NULL;
4971 struct mapset_handle *msh;
4972 int x,i,first=1,dist=0;
4973 struct coord c,last,res;
4974 struct coord_rect rbbox,dbbox;
4975 struct map_selection sel;
4976 struct heightline *heightline,*heightlines=NULL;
4977 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4980 sel.range.min=type_height_line_1;
4981 sel.range.max=type_height_line_3;
4984 menu=gui_internal_menu(this,_("Height Profile"));
4985 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4986 gui_internal_widget_append(menu, box);
4987 route = navit_get_route(this->nav);
4989 map = route_get_map(route);
4991 mr = map_rect_new(map,NULL);
4993 while((item = map_rect_get_item(mr))) {
4994 while (item_coord_get(item, &c, 1)) {
5000 coord_rect_extend(&sel.u.c_rect, &c);
5003 map_rect_destroy(mr);
5004 ms=navit_get_mapset(this->nav);
5006 msh=mapset_open(ms);
5007 while ((map=mapset_next(msh, 1))) {
5008 mr=map_rect_new(map, &sel);
5010 while((item = map_rect_get_item(mr))) {
5011 if (item->type >= sel.range.min && item->type <= sel.range.max) {
5012 heightline=item_get_heightline(item);
5014 heightline->next=heightlines;
5015 heightlines=heightline;
5019 map_rect_destroy(mr);
5028 map = route_get_map(route);
5030 mr = map_rect_new(map,NULL);
5031 if(mr && heightlines) {
5032 while((item = map_rect_get_item(mr))) {
5034 while (item_coord_get(item, &c, 1)) {
5038 heightline=heightlines;
5041 coord_rect_extend(&rbbox, &c);
5042 while (heightline) {
5043 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
5044 for (i = 0 ; i < heightline->count - 1; i++) {
5045 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
5046 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
5047 diagram_point=g_new(struct diagram_point, 1);
5048 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
5049 diagram_point->c.y=heightline->height;
5050 diagram_point->next=diagram_points;
5051 diagram_points=diagram_point;
5052 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
5057 heightline=heightline->next;
5059 dist+=transform_distance(projection_mg, &last, &c);
5065 map_rect_destroy(mr);
5069 gui_internal_menu_render(this);
5071 diagram_point=diagram_points;
5072 while (diagram_point) {
5074 dbbox.lu=diagram_point->c;
5075 dbbox.rl=diagram_point->c;
5078 coord_rect_extend(&dbbox, &diagram_point->c);
5079 diagram_point=diagram_point->next;
5081 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
5082 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
5084 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
5086 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
5092 diagram_point=diagram_points;
5093 while (diagram_point) {
5094 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
5096 diagram_point=diagram_point->next;
5100 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
5101 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
5102 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
5103 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
5107 graphics_draw_lines(this->gra, this->foreground, p, 2);
5116 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5118 struct widget *menu,*wb,*w;
5121 graphics_draw_mode(this->gra, draw_mode_begin);
5122 menu=gui_internal_menu(this, _("Show Locale"));
5123 menu->spx=this->spacing*10;
5124 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5125 gui_internal_widget_append(menu, wb);
5126 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5127 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5128 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5130 #ifdef HAVE_API_WIN32_BASE
5132 wchar_t wcountry[32],wlang[32];
5133 char country[32],lang[32];
5135 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5136 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5137 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5138 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5139 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5141 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5142 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5143 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5144 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5145 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5150 gui_internal_menu_render(this);
5151 graphics_draw_mode(this->gra, draw_mode_end);
5156 * @brief handles the 'next page' table event.
5157 * A callback function that is invoked when the 'next page' button is pressed
5158 * to advance the contents of a table widget.
5160 * @param this The graphics context.
5161 * @param wm The button widget that was pressed.
5163 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5165 struct widget * table_widget = (struct widget * ) wm->data;
5166 struct table_data * table_data = NULL;
5172 table_data = (struct table_data*) table_widget->data;
5178 * Before advancing to the next page we need to ensure
5179 * that the current top_row is in the list of previous top_rows
5180 * so previous page can work.
5183 for(iterator=table_data->page_headers; iterator != NULL;
5184 iterator = g_list_next(iterator) )
5186 if(iterator->data == table_data->top_row)
5195 table_data->page_headers=g_list_append(table_data->page_headers,
5196 table_data->top_row);
5199 table_data->top_row = g_list_next(table_data->bottom_row);
5201 wm->state&= ~STATE_HIGHLIGHTED;
5202 gui_internal_menu_render(this);
5208 * @brief handles the 'previous page' table event.
5209 * A callback function that is invoked when the 'previous page' button is pressed
5210 * to go back in the contents of a table widget.
5212 * @param this The graphics context.
5213 * @param wm The button widget that was pressed.
5215 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5217 struct widget * table_widget = (struct widget * ) wm->data;
5218 struct table_data * table_data = NULL;
5219 GList * current_page_top=NULL;
5224 table_data = (struct table_data*) table_widget->data;
5227 current_page_top = table_data->top_row;
5228 for(iterator = table_data->page_headers; iterator != NULL;
5229 iterator = g_list_next(iterator))
5231 if(current_page_top == iterator->data)
5235 table_data->top_row = (GList*) iterator->data;
5239 wm->state&= ~STATE_HIGHLIGHTED;
5240 gui_internal_menu_render(this);
5245 * @brief deallocates a table_data structure.
5248 void gui_internal_table_data_free(void * p)
5253 * @note button_box and its children (next_button,prev_button)
5254 * have their memory managed by the table itself.
5256 struct table_data * table_data = (struct table_data*) p;
5257 g_list_free(table_data->page_headers);
5265 * @brief Called when the route is updated.
5267 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5270 if(this->route_data.route_showing) {
5271 gui_internal_populate_route_table(this,navit);
5272 graphics_draw_mode(this->gra, draw_mode_begin);
5273 gui_internal_menu_render(this);
5274 graphics_draw_mode(this->gra, draw_mode_end);
5282 * @brief Called when the route screen is closed (deallocated).
5284 * The main purpose of this function is to remove the widgets from
5285 * references route_data because those widgets are about to be freed.
5287 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5290 this_->route_data.route_showing=0;
5291 this_->route_data.route_table=NULL;
5298 * @brief Populates the route table with route information
5300 * @param this The gui context
5301 * @param navit The navit object
5303 void gui_internal_populate_route_table(struct gui_priv * this,
5304 struct navit * navit)
5306 struct map * map=NULL;
5307 struct map_rect * mr=NULL;
5308 struct navigation * nav = NULL;
5309 struct item * item =NULL;
5311 struct widget * label = NULL;
5312 struct widget * row = NULL;
5313 nav = navit_get_navigation(navit);
5317 map = navigation_get_map(nav);
5319 mr = map_rect_new(map,NULL);
5321 gui_internal_widget_table_clear(this,this->route_data.route_table);
5322 while((item = map_rect_get_item(mr))) {
5323 if(item_attr_get(item,attr_navigation_long,&attr)) {
5324 label = gui_internal_label_new(this,attr.u.str);
5325 row = gui_internal_widget_table_row_new(this,
5328 | orientation_horizontal);
5329 row->children=g_list_append(row->children,label);
5330 gui_internal_widget_append(this->route_data.route_table,row);
5338 static struct command_table commands[] = {
5339 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
5340 {"back",command_cast(gui_internal_cmd2_back)},
5341 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
5342 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
5343 {"get_data",command_cast(gui_internal_get_data)},
5344 {"locale",command_cast(gui_internal_cmd2_locale)},
5345 {"log",command_cast(gui_internal_cmd_log)},
5346 {"menu",command_cast(gui_internal_cmd_menu2)},
5347 {"position",command_cast(gui_internal_cmd2_position)},
5348 {"route_description",command_cast(gui_internal_cmd2_route_description)},
5349 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
5350 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
5351 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
5352 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
5353 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
5354 {"town",command_cast(gui_internal_cmd2_town)},
5355 {"quit",command_cast(gui_internal_cmd2_quit)},
5356 {"write",command_cast(gui_internal_cmd_write)},
5360 //##############################################################################################################
5363 //# Authors: Martin Schaller (04/2008)
5364 //##############################################################################################################
5365 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
5367 struct gui_priv *this;
5369 *meth=gui_internal_methods;
5370 this=g_new0(struct gui_priv, 1);
5373 this->self.type=attr_gui;
5374 this->self.u.gui=gui;
5376 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
5377 this->menu_on_map_click=attr->u.num;
5379 this->menu_on_map_click=1;
5380 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
5381 this->signal_on_map_click=attr->u.num;
5383 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
5384 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
5387 if( (attr=attr_search(attrs,NULL,attr_font_size)))
5389 this->config.font_size=attr->u.num;
5393 this->config.font_size=-1;
5395 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
5397 this->config.icon_xs=attr->u.num;
5401 this->config.icon_xs=-1;
5403 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
5405 this->config.icon_l=attr->u.num;
5409 this->config.icon_l=-1;
5411 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
5413 this->config.icon_s=attr->u.num;
5417 this->config.icon_s=-1;
5419 if( (attr=attr_search(attrs,NULL,attr_spacing)))
5421 this->config.spacing=attr->u.num;
5425 this->config.spacing=-1;
5427 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
5429 this->speech=attr->u.num;
5431 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
5432 this->keyboard=attr->u.num;
5436 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
5437 this->fullscreen=attr->u.num;
5439 if( (attr=attr_search(attrs,NULL,attr_flags)))
5440 this->flags=attr->u.num;
5441 if( (attr=attr_search(attrs,NULL,attr_background_color)))
5442 this->background_color=*attr->u.color;
5444 this->background_color=COLOR_BLACK;
5445 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
5446 this->background2_color=*attr->u.color;
5448 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
5449 if( (attr=attr_search(attrs,NULL,attr_text_color)))
5450 this->text_foreground_color=*attr->u.color;
5452 this->text_foreground_color=COLOR_WHITE;
5453 this->text_background_color=COLOR_BLACK;
5454 if( (attr=attr_search(attrs,NULL,attr_columns)))
5455 this->cols=attr->u.num;
5456 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
5457 this->osd_configuration=*attr;
5459 if( (attr=attr_search(attrs,NULL,attr_pitch)))
5460 this->pitch=attr->u.num;
5463 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
5464 this->flags_town=attr->u.num;
5466 this->flags_town=-1;
5467 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
5468 this->flags_street=attr->u.num;
5470 this->flags_street=-1;
5471 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
5472 this->flags_house_number=attr->u.num;
5474 this->flags_house_number=-1;
5475 this->data.priv=this;
5476 this->data.gui=&gui_internal_methods_ext;
5477 this->data.widget=&gui_internal_widget_methods;
5478 this->cbl=callback_list_new();
5483 //##############################################################################################################
5486 //# Authors: Martin Schaller (04/2008)
5487 //##############################################################################################################
5488 void plugin_init(void)
5490 plugin_register_gui_type("internal", gui_internal_new);