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 //##############################################################################################################
45 #include "transform.h"
60 #include "navit_nls.h"
62 #define STATE_VISIBLE 1
63 #define STATE_SELECTED 2
64 #define STATE_HIGHLIGHTED 4
65 #define STATE_SENSITIVE 8
67 #define STATE_CLEAR 32
86 gravity_left_top=gravity_left|gravity_top,
87 gravity_top_center=gravity_xcenter|gravity_top,
88 gravity_right_top=gravity_right|gravity_top,
89 gravity_left_center=gravity_left|gravity_ycenter,
90 gravity_center=gravity_xcenter|gravity_ycenter,
91 gravity_right_center=gravity_right|gravity_ycenter,
92 gravity_left_bottom=gravity_left|gravity_bottom,
93 gravity_bottom_center=gravity_xcenter|gravity_bottom,
94 gravity_right_bottom=gravity_right|gravity_bottom,
97 orientation_horizontal=0x10000,
98 orientation_vertical=0x20000,
99 orientation_horizontal_vertical=0x40000,
103 //##############################################################################################################
106 //# Authors: Martin Schaller (04/2008)
107 //##############################################################################################################
109 enum widget_type type;
110 struct graphics_gc *background;
111 struct graphics_gc *foreground_frame;
113 struct graphics_image *img;
115 * A function to be invoked on actions.
116 * @li widget The widget that is receiving the button press.
119 void (*func)(struct gui_priv *priv, struct widget *widget);
123 void (*data_free)(void *data);
133 int bl,br,bt,bb,spx,spy;
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);
150 * @brief A structure to store configuration values.
152 * This structure stores configuration values for how gui elements in the internal GUI
155 struct gui_config_settings {
158 * The base size (in fractions of a point) to use for text.
162 * The size (in pixels) that xs style icons should be scaled to.
166 * The size (in pixels) that s style icons (small) should be scaled to
170 * The size (in pixels) that l style icons should be scaled to
174 * The default amount of spacing (in pixels) to place between GUI elements.
181 * Indexes into the config_profiles array.
183 const int LARGE_PROFILE=0;
184 const int MEDIUM_PROFILE=1;
185 const int SMALL_PROFILE=2;
188 * The default config profiles.
190 * [0] => LARGE_PROFILE (screens 640 in one dimension)
191 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
192 * [2] => Small profile (default)
194 static struct gui_config_settings config_profiles[]={
200 //##############################################################################################################
203 //# Authors: Martin Schaller (04/2008)
204 //##############################################################################################################
208 struct graphics *gra;
209 struct graphics_gc *background;
210 struct graphics_gc *background2;
211 struct graphics_gc *highlight_background;
212 struct graphics_gc *foreground;
213 struct graphics_gc *text_foreground;
214 struct graphics_gc *text_background;
218 struct graphics_font *font;
219 int icon_xs, icon_s, icon_l;
221 struct widget *widgets;
225 struct widget *highlighted;
226 struct widget *highlighted_menu;
228 int clickp_valid, vehicle_valid;
229 struct pcoord clickp, vehiclep;
230 struct search_list *sl;
232 int menu_on_map_click;
236 * The setting information read from the configuration file.
237 * values of -1 indicate no value was specified in the config file.
239 struct gui_config_settings config;
240 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb;
245 * @brief A structure to store information about a table.
247 * The table_data widget stores pointers to extra information needed by the
250 * The table_data structure needs to be freed with data_free along with the widget.
256 * A GList pointer into a widget->children list that indicates the row
257 * currently being rendered at the top of the table.
261 * A Glist pointer into a widget->children list that indicates the row
262 * currently being rendered at the bottom of the table.
267 * A list of table_row widgets that mark the
268 * top rows for each page of the table.
269 * This is needed for the 'previous page' function of the table.
271 GList * page_headers;
274 * A container box that is the child of the table widget that contains+groups
275 * the next and previous button.
277 struct widget * button_box;
280 * A button widget to handle 'next page' requests
282 struct widget * next_button;
284 * A button widget to handle 'previous page' requests.
286 struct widget * prev_button;
290 * a pointer to the gui context.
291 * This is needed by the free function to destory the buttons.
293 struct gui_priv * this;
297 * A data structure that holds information about a column that makes up a table.
301 struct table_column_desc
305 * The computed height of a cell in the table.
310 * The computed width of a cell in the table.
315 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
316 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
317 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
318 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
319 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
320 static void gui_internal_apply_config(struct gui_priv *this);
322 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags);
323 static void gui_internal_widget_table_add_row(struct widget * table, struct widget * row);
324 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
325 static void gui_internal_cmd_route(struct gui_priv * this, struct widget * w);
326 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
327 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm);
328 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm);
329 static void gui_internal_table_data_free(void * d);
331 static struct graphics_image *
332 image_new_scaled(struct gui_priv *this, char *name, int w, int h)
334 struct graphics_image *ret=NULL;
335 char *full_name=NULL;
338 for (i = 1 ; i < 6 ; i++) {
342 full_name=g_strdup_printf("%s/xpm/%s.svg", getenv("NAVIT_SHAREDIR"), name);
345 full_name=g_strdup_printf("%s/xpm/%s.svgz", getenv("NAVIT_SHAREDIR"), name);
348 if (w != -1 && h != -1) {
349 full_name=g_strdup_printf("%s/xpm/%s_%d_%d.png", getenv("NAVIT_SHAREDIR"), name, w, h);
353 full_name=g_strdup_printf("%s/xpm/%s.png", getenv("NAVIT_SHAREDIR"), name);
356 full_name=g_strdup_printf("%s/xpm/%s.xpm", getenv("NAVIT_SHAREDIR"), name);
359 dbg(1,"trying '%s'\n", full_name);
362 if (!file_exists(full_name)) {
366 ret=graphics_image_new_scaled(this->gra, full_name, w, h);
367 dbg(1,"ret=%p\n", ret);
372 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
377 static struct graphics_image *
378 image_new_o(struct gui_priv *this, char *name)
380 return image_new_scaled(this, name, -1, -1);
383 static struct graphics_image *
384 image_new_xs(struct gui_priv *this, char *name)
386 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
390 static struct graphics_image *
391 image_new_s(struct gui_priv *this, char *name)
393 return image_new_scaled(this, name, this->icon_s, this->icon_s);
396 static struct graphics_image *
397 image_new_l(struct gui_priv *this, char *name)
399 return image_new_scaled(this, name, this->icon_l, this->icon_l);
403 coordinates(struct pcoord *pc, char sep)
405 char latc='N',lngc='E';
406 int lat_deg,lat_min,lat_sec;
407 int lng_deg,lng_min,lng_sec;
412 transform_to_geo(pc->pro, &c, &g);
423 lat_min=fmod(g.lat*60,60);
424 lat_sec=fmod(g.lat*3600,60);
426 lng_min=fmod(g.lng*60,60);
427 lng_sec=fmod(g.lng*3600,60);
428 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);
432 gui_internal_background_render(struct gui_priv *this, struct widget *w)
434 struct point pnt=w->p;
435 if (w->state & STATE_HIGHLIGHTED)
436 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
439 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
442 static struct widget *
443 gui_internal_label_new(struct gui_priv *this, char *text)
449 struct widget *widget=g_new0(struct widget, 1);
450 widget->type=widget_label;
452 widget->text=g_strdup(text);
453 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p);
457 widget->h=h+this->spacing;
458 widget->w=w+this->spacing;
459 widget->flags=gravity_center;
464 static struct widget *
465 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
467 struct widget *ret=NULL;
468 char *tmp=g_malloc(strlen(text)+3);
475 ret=gui_internal_label_new(this, tmp);
476 if (ret->w < maxwidth)
478 gui_internal_widget_destroy(this, ret);
486 static struct widget *
487 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
489 struct widget *widget=g_new0(struct widget, 1);
490 widget->type=widget_image;
493 widget->w=image->width;
494 widget->h=image->height;
500 gui_internal_image_render(struct gui_priv *this, struct widget *w)
504 gui_internal_background_render(this, w);
507 pnt.x+=w->w/2-w->img->hot.x;
508 pnt.y+=w->h/2-w->img->hot.y;
509 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
514 gui_internal_label_render(struct gui_priv *this, struct widget *w)
516 struct point pnt=w->p;
517 gui_internal_background_render(this, w);
519 pnt.y+=w->h-this->spacing;
520 graphics_draw_text(this->gra, this->text_foreground, this->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
524 static struct widget *
525 gui_internal_text_new(struct gui_priv *this, char *text)
527 char *s=g_strdup(text),*s2,*tok;
528 struct widget *ret=gui_internal_box_new(this, gravity_center|orientation_vertical);
530 while ((tok=strtok(s2,"\n"))) {
531 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
538 static struct widget *
539 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)
541 struct widget *ret=NULL;
542 ret=gui_internal_box_new(this, flags);
545 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
547 gui_internal_widget_append(ret, gui_internal_text_new(this, text));
551 ret->state |= STATE_SENSITIVE;
552 ret->speech=g_strdup(text);
560 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
567 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
568 is_on=curr.u.data == w->on.u.data;
571 if (is_on != w->is_on) {
575 l=g_list_first(w->children);
579 graphics_image_free(this->gra, wi->img);
580 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
582 if (w->is_on && w->off.type == attr_none)
583 w->state &= ~STATE_SENSITIVE;
585 w->state |= STATE_SENSITIVE;
592 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
594 if (gui_internal_button_attr_update(this, w))
595 gui_internal_widget_render(this, w);
598 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w)
601 w->set_attr(w->instance, &w->off);
603 w->set_attr(w->instance, &w->on);
604 gui_internal_button_attr_update(this, w);
608 static struct widget *
609 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
611 struct graphics_image *image=image_new_xs(this, "gui_inactive");
613 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
618 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
619 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
620 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
621 ret->instance=this->nav;
622 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on->type, this, ret);
623 navit_add_callback(this->nav, ret->cb);
624 gui_internal_button_attr_update(this, ret);
628 static struct widget *
629 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)
631 struct graphics_image *image=image_new_xs(this, "gui_inactive");
633 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
639 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
640 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
641 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
644 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on->type, this, ret);
645 map_add_callback(map, ret->cb);
646 gui_internal_button_attr_update(this, ret);
650 static struct widget *
651 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
653 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
656 //##############################################################################################################
659 //# Authors: Martin Schaller (04/2008)
660 //##############################################################################################################
661 static void gui_internal_clear(struct gui_priv *this)
663 struct graphics *gra=this->gra;
667 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
670 static struct widget *
671 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
673 struct widget *ret,*child;
674 GList *l=wi->children;
677 if (p && (wi->p.x > p->x || wi->p.y > p->y || wi->p.x + wi->w < p->x || wi->p.y + wi->h < p->y)) {
680 if (wi->state & flags)
684 ret=gui_internal_find_widget(child, p, flags);
695 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
697 if (found == this->highlighted)
699 if (this->highlighted) {
700 this->highlighted->state &= ~STATE_HIGHLIGHTED;
701 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
702 gui_internal_widget_render(this, this->highlighted);
703 this->highlighted=NULL;
704 this->highlighted_menu=NULL;
707 this->highlighted=found;
708 this->highlighted_menu=g_list_last(this->root.children)->data;
709 this->highlighted->state |= STATE_HIGHLIGHTED;
710 gui_internal_widget_render(this, this->highlighted);
711 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
714 //##############################################################################################################
717 //# Authors: Martin Schaller (04/2008)
718 //##############################################################################################################
719 static void gui_internal_highlight(struct gui_priv *this, struct point *p)
721 struct widget *menu,*found=NULL;
724 menu=g_list_last(this->root.children)->data;
725 found=gui_internal_find_widget(menu, p, STATE_SENSITIVE);
727 gui_internal_highlight_do(this, found);
730 static struct widget *
731 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, char *label)
733 struct widget *widget=g_new0(struct widget, 1);
736 widget->text=g_strdup(label);
737 widget->type=widget_box;
742 static struct widget *
743 gui_internal_box_new(struct gui_priv *this, enum flags flags)
745 return gui_internal_box_new_with_label(this, flags, NULL);
749 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
754 gui_internal_background_render(this, w);
758 pnt[1].x=pnt[0].x+w->w;
760 pnt[2].x=pnt[0].x+w->w;
761 pnt[2].y=pnt[0].y+w->h;
763 pnt[3].y=pnt[0].y+w->h;
765 graphics_draw_lines(this->gra, this->foreground, pnt, 5);
771 gui_internal_widget_render(this, wc);
776 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
779 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 : 3;
781 int orientation=w->flags & 0xffff0000;
789 if (orientation == orientation_horizontal_vertical && count <= cols)
790 orientation=orientation_horizontal;
791 switch (orientation) {
792 case orientation_horizontal:
796 gui_internal_widget_pack(this, wc);
800 if (wc->flags & flags_expand)
801 expand+=wc->w ? wc->w : 1;
807 if (expand && w->w) {
808 expand=100*(w->w-width+expand)/expand;
813 case orientation_vertical:
817 gui_internal_widget_pack(this, wc);
821 if (wc->flags & flags_expand)
822 expand+=wc->h ? wc->h : 1;
828 if (expand && w->h) {
829 expand=100*(w->h-height+expand)/expand;
834 case orientation_horizontal_vertical:
839 gui_internal_widget_pack(this, wc);
849 rows=(count+cols-1)/cols;
852 width+=w->spx*(cols-1);
853 height+=w->spy*(rows-1);
861 if (! w->w && ! w->h) {
862 w->w=w->bl+w->br+width;
863 w->h=w->bt+w->bb+height;
865 if (w->flags & gravity_left)
867 if (w->flags & gravity_xcenter)
868 x=w->p.x+w->w/2-owidth/2;
869 if (w->flags & gravity_right)
870 x=w->p.x+w->w-w->br-owidth;
871 if (w->flags & gravity_top)
873 if (w->flags & gravity_ycenter)
874 y=w->p.y+w->h/2-oheight/2;
875 if (w->flags & gravity_bottom)
876 y=w->p.y+w->h-w->bb-oheight;
878 switch (orientation) {
879 case orientation_horizontal:
884 if (wc->flags & flags_fill)
886 if (wc->flags & flags_expand) {
889 wc->w=wc->w*expand/100;
891 if (w->flags & gravity_top)
893 if (w->flags & gravity_ycenter)
895 if (w->flags & gravity_bottom)
901 case orientation_vertical:
906 if (wc->flags & flags_fill)
908 if (wc->flags & flags_expand) {
911 wc->h=wc->h*expand/100;
913 if (w->flags & gravity_left)
915 if (w->flags & gravity_xcenter)
917 if (w->flags & gravity_right)
923 case orientation_horizontal_vertical:
933 if (wc->flags & flags_fill) {
937 if (w->flags & gravity_left)
939 if (w->flags & gravity_xcenter)
940 wc->p.x=x+(width-wc->w)/2;
941 if (w->flags & gravity_right)
942 wc->p.x=x+width-wc->w;
943 if (w->flags & gravity_top)
945 if (w->flags & gravity_ycenter)
946 wc->p.y=y+(height-wc->h)/2;
947 if (w->flags & gravity_bottom)
948 wc->p.y=y-height-wc->h;
950 if (++count == cols) {
964 gui_internal_widget_pack(this, wc);
969 static void gui_internal_widget_append(struct widget *parent, struct widget *child)
971 if (! child->background)
972 child->background=parent->background;
973 parent->children=g_list_append(parent->children, child);
976 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
984 gui_internal_widget_destroy(this, wc);
987 g_list_free(w->children);
991 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
993 gui_internal_widget_children_destroy(this, w);
997 graphics_image_free(this->gra, w->img);
1003 w->data_free(w->data);
1004 if (w->cb && w->remove_cb)
1005 w->remove_cb(w->instance, w->cb);
1011 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1015 gui_internal_box_render(this, w);
1018 gui_internal_label_render(this, w);
1021 gui_internal_image_render(this, w);
1024 gui_internal_table_render(this,w);
1032 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1036 gui_internal_box_pack(this, w);
1039 gui_internal_table_pack(this,w);
1045 //##############################################################################################################
1048 //# Authors: Martin Schaller (04/2008)
1049 //##############################################################################################################
1050 static void gui_internal_call_highlighted(struct gui_priv *this)
1052 if (! this->highlighted || ! this->highlighted->func)
1054 this->highlighted->reason=1;
1055 this->highlighted->func(this, this->highlighted);
1059 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1061 char *text=w->speech;
1069 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1070 navit_say(this->nav, text);
1076 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1079 while ((l = g_list_last(this->root.children))) {
1081 gui_internal_say(this, w, 0);
1082 gui_internal_widget_render(this, w);
1085 gui_internal_widget_destroy(this, l->data);
1086 this->root.children=g_list_remove(this->root.children, l->data);
1091 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm)
1093 gui_internal_prune_menu(this, wm->data);
1097 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm)
1099 gui_internal_prune_menu(this, this->root.children->data);
1102 static struct widget *
1103 gui_internal_top_bar(struct gui_priv *this)
1105 struct widget *w,*wm,*wh,*wc,*wcn;
1106 int dots_len, sep_len;
1108 int width,width_used=0,use_sep,incomplete=0;
1110 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1111 w->bl=this->spacing;
1112 w->spx=this->spacing;
1113 w->background=this->background2;
1114 wm=gui_internal_button_new_with_callback(this, NULL,
1115 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1116 gui_internal_cmd_return, NULL);
1117 wm->speech=g_strdup(_("Back to map"));
1118 gui_internal_widget_pack(this, wm);
1119 wh=gui_internal_button_new_with_callback(this, NULL,
1120 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1121 gui_internal_cmd_main_menu, NULL);
1122 wh->speech=g_strdup(_("Main Menu"));
1123 gui_internal_widget_pack(this, wh);
1124 gui_internal_widget_append(w, wm);
1125 gui_internal_widget_append(w, wh);
1126 width=this->root.w-w->bl-wm->w-w->spx-wh->w;
1127 l=g_list_last(this->root.children);
1128 wcn=gui_internal_label_new(this,".. »");
1130 gui_internal_widget_destroy(this, wcn);
1131 wcn=gui_internal_label_new(this,"»");
1133 gui_internal_widget_destroy(this, wcn);
1135 if (g_list_previous(l) || !g_list_next(l)) {
1137 wcn=gui_internal_label_new(this, wc->text);
1142 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1143 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1145 gui_internal_widget_destroy(this, wcn);
1149 res=g_list_prepend(res, gui_internal_label_new(this, "»"));
1150 width_used+=sep_len+w->spx;
1153 wcn->func=gui_internal_cmd_return;
1155 wcn->state |= STATE_SENSITIVE;
1156 res=g_list_prepend(res, wcn);
1159 l=g_list_previous(l);
1163 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1164 wcn->func=gui_internal_cmd_return;
1166 wcn->state |= STATE_SENSITIVE;
1167 res=g_list_prepend(res, wcn);
1168 l=g_list_previous(l);
1171 wcn=gui_internal_label_new(this, ".. »");
1172 wcn->func=gui_internal_cmd_return;
1174 wcn->state |= STATE_SENSITIVE;
1175 res=g_list_prepend(res, wcn);
1179 gui_internal_widget_append(w, l->data);
1184 gui_internal_widget_destroy(this, dots);
1191 * Applys the configuration values to this based on the settings
1192 * specified in the configuration file (this->config) and
1193 * the most approriate default profile based on screen resolution.
1195 * This function should be run after this->root is setup and could
1196 * be rerun after the window is resized.
1198 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1200 static void gui_internal_apply_config(struct gui_priv *this)
1202 struct gui_config_settings * current_config=0;
1205 * Select default values from profile based on the screen.
1207 if(this->root.w > 320 || this->root.h > 320)
1209 if(this->root.w > 640 || this->root.h > 640)
1211 current_config = &config_profiles[LARGE_PROFILE];
1215 current_config = &config_profiles[MEDIUM_PROFILE];
1220 current_config = &config_profiles[SMALL_PROFILE];
1224 * Apply override values from config file
1226 if(this->config.font_size == -1 )
1228 this->font_size = current_config->font_size;
1232 this->font_size = this->config.font_size;
1235 if(this->config.icon_xs == -1 )
1237 this->icon_xs = current_config->icon_xs;
1241 this->icon_xs = this->config.icon_xs;
1244 if(this->config.icon_s == -1 )
1246 this->icon_s = current_config->icon_s;
1250 this->icon_s = this->config.icon_s;
1252 if(this->config.icon_l == -1 )
1254 this->icon_l = current_config->icon_l;
1258 this->icon_l = this->config.icon_l;
1260 if(this->config.spacing == -1 )
1262 this->spacing = current_config->spacing;
1266 this->spacing = current_config->spacing;
1271 static struct widget *
1272 gui_internal_menu(struct gui_priv *this, char *label)
1274 struct widget *menu,*w;
1277 menu=gui_internal_box_new_with_label(this, gravity_center|orientation_vertical, label);
1278 menu->w=this->root.w;
1279 menu->h=this->root.h;
1280 menu->background=this->background;
1281 gui_internal_apply_config(this);
1282 this->font=graphics_font_new(this->gra,this->font_size,1);
1284 gui_internal_widget_append(&this->root, menu);
1285 w=gui_internal_top_bar(this);
1286 gui_internal_widget_append(menu, w);
1287 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1288 w->spx=4*this->spacing;
1289 gui_internal_widget_append(menu, w);
1295 gui_internal_menu_render(struct gui_priv *this)
1298 struct widget *menu;
1300 l=g_list_last(this->root.children);
1302 gui_internal_say(this, menu, 0);
1303 gui_internal_widget_pack(this, menu);
1304 gui_internal_widget_render(this, menu);
1308 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm)
1310 struct widget *w=wm->data;
1311 dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
1312 navit_set_destination(this->nav, &w->c, w->name);
1313 gui_internal_prune_menu(this, NULL);
1317 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm)
1319 struct widget *w=wm->data;
1320 navit_set_position(this->nav, &w->c);
1321 gui_internal_prune_menu(this, NULL);
1325 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1328 dbg(0,"text='%s'\n", widget->text);
1329 if (widget->text && strlen(widget->text))
1330 navit_add_bookmark(this->nav, &widget->c, widget->text);
1331 g_free(widget->text);
1333 l=g_list_previous(g_list_last(this->root.children));
1334 gui_internal_prune_menu(this, l->data);
1338 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget)
1340 gui_internal_cmd_add_bookmark_do(this, widget->data);
1344 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm)
1349 len=strlen(wm->text);
1350 dbg(1,"len=%d\n", len);
1351 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1352 wm->text[len-1]='\0';
1353 gui_internal_cmd_add_bookmark_do(this, wm);
1359 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1362 gui_internal_cmd_add_bookmark(struct gui_priv *this, struct widget *wm)
1364 struct widget *w,*wb,*wk,*wl,*we,*wnext,*wp=wm->data;
1365 wb=gui_internal_menu(this, "Add Bookmark");
1366 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1367 gui_internal_widget_append(wb, w);
1368 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1369 gui_internal_widget_append(w, we);
1370 gui_internal_widget_append(we, wk=gui_internal_label_new(this, wp->name ? wp->name : wp->text));
1371 wk->state |= STATE_EDIT|STATE_CLEAR;
1372 wk->background=this->background;
1373 wk->flags |= flags_expand|flags_fill;
1374 wk->func = gui_internal_cmd_add_bookmark_changed;
1376 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1377 wnext->state |= STATE_SENSITIVE;
1378 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1380 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1381 gui_internal_widget_append(w, wl);
1382 gui_internal_widget_append(w, gui_internal_keyboard(this,0));
1383 gui_internal_menu_render(this);
1388 get_direction(char *buffer, int angle, int mode)
1393 sprintf(buffer,"%d",angle);
1396 if (angle < 69 || angle > 291)
1398 if (angle > 111 && angle < 249)
1400 if (angle > 22 && angle < 158)
1402 if (angle > 202 && angle < 338)
1407 angle=(angle+15)/30;
1410 sprintf(buffer,"%d H", angle);
1418 enum item_type *types;
1420 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1421 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1422 {"hotel","Hotel",(enum item_type []) {
1423 type_poi_hotel,type_poi_camp_rv,
1424 type_poi_camping,type_poi_camping,
1425 type_poi_resort,type_poi_resort,
1427 {"restaurant","Restaurant",(enum item_type []) {
1428 type_poi_bar,type_poi_picnic,
1429 type_poi_burgerking,type_poi_fastfood,
1430 type_poi_restaurant,type_poi_restaurant,
1432 {"shopping","Shopping",(enum item_type []) {
1433 type_poi_mall,type_poi_mall,
1434 type_poi_shop_grocery,type_poi_shop_grocery,
1436 {"hospital","Service",(enum item_type []) {
1437 type_poi_marina,type_poi_marina,
1438 type_poi_hospital,type_poi_hospital,
1439 type_poi_public_utilities,type_poi_public_utilities,
1440 type_poi_police,type_poi_autoservice,
1441 type_poi_information,type_poi_information,
1442 type_poi_personal_service,type_poi_repair_service,
1443 type_poi_rest_room,type_poi_rest_room,
1444 type_poi_restroom,type_poi_restroom,
1446 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1447 {"peak","Land Features",(enum item_type []){
1448 type_poi_land_feature,type_poi_rock,
1449 type_poi_dam,type_poi_dam,
1451 {"unknown","Other",(enum item_type []){
1452 type_point_unspecified,type_poi_land_feature-1,
1453 type_poi_rock+1,type_poi_fuel-1,
1454 type_poi_marina+1,type_poi_car_parking-1,
1455 type_poi_car_parking+1,type_poi_bar-1,
1456 type_poi_bank+1,type_poi_dam-1,
1457 type_poi_dam+1,type_poi_information-1,
1458 type_poi_information+1,type_poi_mall-1,
1459 type_poi_mall+1,type_poi_personal_service-1,
1460 type_poi_restaurant+1,type_poi_restroom-1,
1461 type_poi_restroom+1,type_poi_shop_grocery-1,
1462 type_poi_shop_grocery+1,type_poi_wifi,
1466 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm);
1468 static struct widget *
1469 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1471 struct widget *wl,*wb;
1473 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1474 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1475 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1476 image_new_xs(this, selectors[i].icon), gravity_center|orientation_vertical,
1477 gui_internal_cmd_pois, &selectors[i]));
1483 static struct widget *
1484 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1492 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1494 sprintf(distbuf,"%d", dist/1000);
1495 gui_internal_widget_append(wl, gui_internal_label_new(this, distbuf));
1496 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1497 gui_internal_widget_append(wl, gui_internal_label_new(this, dirbuf));
1498 type=item_to_name(item->type);
1499 gui_internal_widget_append(wl, gui_internal_label_new(this, type));
1500 if (item_attr_get(item, attr_label, &attr)) {
1501 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1504 wl->name=g_strdup(type);
1506 gui_internal_widget_append(wl, gui_internal_label_new(this, attr.u.str));
1512 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1514 const struct widget *wa=a;
1515 const struct widget *wb=b;
1516 struct widget *wac=wa->children->data;
1517 struct widget *wbc=wb->children->data;
1526 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1528 enum item_type *types;
1529 if (type >= type_line)
1531 if (! sel || !sel->types)
1534 while (*types != type_none) {
1535 if (type >= types[0] && type <= types[1]) {
1543 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm);
1546 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm)
1548 struct map_selection *sel,*selm;
1549 struct coord c,center;
1550 struct mapset_handle *h;
1552 struct map_rect *mr;
1554 int idist,dist=400000;
1555 struct widget *wi,*w,*w2,*wb;
1556 enum projection pro=wm->c.pro;
1557 struct selector *isel=wm->data;
1559 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
1560 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1561 gui_internal_widget_append(wb, w);
1563 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
1564 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1565 gui_internal_widget_append(w, w2);
1567 sel=map_selection_rect_new(&wm->c, dist, 18);
1570 h=mapset_open(navit_get_mapset(this->nav));
1571 while ((m=mapset_next(h, 1))) {
1572 selm=map_selection_dup_pro(sel, pro, map_projection(m));
1573 mr=map_rect_new(m, selm);
1574 dbg(2,"mr=%p\n", mr);
1576 while ((item=map_rect_get_item(mr))) {
1577 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
1578 item_coord_get_pro(item, &c, 1, pro) &&
1579 coord_rect_contains(&sel->u.c_rect, &c) &&
1580 (idist=transform_distance(pro, ¢er, &c)) < dist) {
1581 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
1582 wi->func=gui_internal_cmd_position;
1583 wi->state |= STATE_SENSITIVE;
1589 map_rect_destroy(mr);
1591 map_selection_destroy(selm);
1593 map_selection_destroy(sel);
1595 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
1596 gui_internal_menu_render(this);
1600 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm)
1602 struct widget *w=wm->data;
1603 navit_set_center(this->nav, &w->c);
1604 gui_internal_prune_menu(this, NULL);
1609 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm)
1611 struct widget *w,*wb;
1612 struct map_rect *mr;
1617 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
1618 wb=gui_internal_menu(this, "Attributes");
1619 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1620 gui_internal_widget_append(wb, w);
1621 mr=map_rect_new(wm->item.map, NULL);
1622 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
1623 dbg(0,"item=%p\n", item);
1625 while(item_attr_get(item, attr_any, &attr)) {
1626 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
1627 gui_internal_widget_append(w,
1628 wb=gui_internal_button_new_with_callback(this, text,
1629 NULL, gravity_left_center|orientation_horizontal|flags_fill,
1630 gui_internal_cmd_view_attributes, NULL));
1634 map_rect_destroy(mr);
1635 gui_internal_menu_render(this);
1639 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm)
1641 struct map_rect *mr;
1646 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
1647 mr=map_rect_new(wm->item.map, NULL);
1648 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
1649 dbg(0,"item=%p\n", item);
1651 while(item_attr_get(item, attr_url_local, &attr)) {
1653 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
1656 map_rect_destroy(mr);
1661 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
1667 /* wm->data: 0 Nothing special
1673 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget);
1676 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm)
1678 struct widget *wb,*w,*wc,*wbc;
1682 int display_attributes=(wm->data == (void *)2);
1683 int display_view_on_map=(wm->data != (void *)1);
1684 int display_items=(wm->data == (void *)1);
1685 int display_streets=(wm->data == (void *)3);
1688 switch ((int)wm->data) {
1693 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
1694 transform_to_geo(wm->c.pro, &c, &g);
1705 name=wm->name ? wm->name : wm->text;
1706 wb=gui_internal_menu(this, name);
1707 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1708 gui_internal_widget_append(wb, w);
1709 coord=coordinates(&wm->c, ' ');
1710 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
1712 if (display_streets) {
1713 gui_internal_widget_append(w,
1714 wc=gui_internal_button_new_with_callback(this, _("Streets"),
1715 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1716 gui_internal_search_street_in_town, wm));
1719 if (display_attributes) {
1720 struct map_rect *mr;
1723 mr=map_rect_new(wm->item.map, NULL);
1724 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
1726 if (item_attr_get(item, attr_description, &attr))
1727 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
1728 if (item_attr_get(item, attr_url_local, &attr)) {
1729 gui_internal_widget_append(w,
1730 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
1731 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1732 gui_internal_cmd_view_in_browser, NULL));
1735 gui_internal_widget_append(w,
1736 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
1737 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1738 gui_internal_cmd_view_attributes, NULL));
1741 map_rect_destroy(mr);
1743 gui_internal_widget_append(w,
1744 gui_internal_button_new_with_callback(this, _("Set as destination"),
1745 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1746 gui_internal_cmd_set_destination, wm));
1747 gui_internal_widget_append(w,
1748 gui_internal_button_new_with_callback(this, _("Set as position"),
1749 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1750 gui_internal_cmd_set_position, wm));
1751 gui_internal_widget_append(w,
1752 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
1753 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1754 gui_internal_cmd_add_bookmark, wm));
1756 gui_internal_widget_append(w,
1757 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
1758 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1759 gui_internal_cmd_pois, NULL));
1762 gui_internal_widget_append(w,
1763 gui_internal_button_new(this, "Add to tour",
1764 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
1765 gui_internal_widget_append(w,
1766 gui_internal_button_new(this, "Add as bookmark",
1767 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
1769 if (display_view_on_map) {
1770 gui_internal_widget_append(w,
1771 gui_internal_button_new_with_callback(this, _("View on map"),
1772 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1773 gui_internal_cmd_view_on_map, wm));
1775 if (display_items) {
1778 struct mapset_handle *h;
1779 struct map_rect *mr;
1782 struct street_data *data;
1783 struct map_selection sel;
1784 struct transformation *trans;
1785 enum projection pro;
1789 trans=navit_get_trans(this->nav);
1790 pro=transform_get_projection(trans);
1791 transform_from_geo(pro, &g, &c);
1792 ms=navit_get_mapset(this->nav);
1794 sel.u.c_rect.lu.x=c.x-dist;
1795 sel.u.c_rect.lu.y=c.y+dist;
1796 sel.u.c_rect.rl.x=c.x+dist;
1797 sel.u.c_rect.rl.y=c.y-dist;
1798 for (i = 0 ; i < layer_end ; i++) {
1802 while ((m=mapset_next(h,1))) {
1803 mr=map_rect_new(m, &sel);
1806 while ((item=map_rect_get_item(mr))) {
1807 data=street_get_data(item);
1808 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
1809 if (item_attr_get(item, attr_label, &attr)) {
1810 label=map_convert_string(m, attr.u.str);
1811 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
1812 map_convert_free(label);
1814 text=g_strdup_printf("%s", item_to_name(item->type));
1815 gui_internal_widget_append(w,
1816 wc=gui_internal_button_new_with_callback(this, text,
1817 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
1818 gui_internal_cmd_position, (void *)2));
1819 wc->c.x=data->c[0].x;
1820 wc->c.y=data->c[0].y;
1822 wc->name=g_strdup(text);
1826 street_data_free(data);
1828 map_rect_destroy(mr);
1833 gui_internal_menu_render(this);
1837 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm)
1839 struct attr attr,mattr;
1840 struct map_rect *mr=NULL;
1842 char *label_full,*l,*prefix,*pos;
1843 int len,plen,hassub;
1844 struct widget *wb,*w,*wbm;
1849 wb=gui_internal_menu(this, wm->text ? wm->text : _("Bookmarks"));
1850 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1851 w->spy=this->spacing*3;
1852 gui_internal_widget_append(wb, w);
1857 plen=strlen(prefix);
1859 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
1860 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
1861 while ((item=map_rect_get_item(mr))) {
1862 if (item->type != type_bookmark) continue;
1863 if (!item_attr_get(item, attr_label, &attr)) continue;
1864 label_full=attr.u.str;
1865 if (!strncmp(label_full, prefix, plen)) {
1866 pos=strchr(label_full+plen, '/');
1872 len=strlen(label_full);
1874 l=g_malloc(len-plen+1);
1875 strncpy(l, label_full+plen, len-plen);
1877 if (!g_hash_table_lookup(hash, l)) {
1878 wbm=gui_internal_button_new_with_callback(this, l,
1879 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
1880 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
1881 if (item_coord_get(item, &c, 1)) {
1884 wbm->c.pro=map_projection(mattr.u.map);
1885 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
1886 wbm->text=g_strdup(l);
1887 gui_internal_widget_append(w, wbm);
1888 g_hash_table_insert(hash, g_strdup(l), (void *)1);
1889 wbm->prefix=g_malloc(len+2);
1890 strncpy(wbm->prefix, label_full, len+1);
1891 wbm->prefix[len+1]='\0';
1893 gui_internal_widget_destroy(this, wbm);
1900 g_hash_table_destroy(hash);
1902 gui_internal_menu_render(this);
1905 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
1907 struct widget *wi,*menu;
1911 menu=g_list_last(this->root.children)->data;
1912 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
1914 if (*key == NAVIT_KEY_BACKSPACE) {
1915 if (wi->text && wi->text[0]) {
1916 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
1918 text=g_strdup_printf("%s ", wi->text);
1921 if (wi->state & STATE_CLEAR) {
1922 dbg(0,"wi->state=0x%x\n", wi->state);
1925 wi->state &= ~STATE_CLEAR;
1926 dbg(0,"wi->state=0x%x\n", wi->state);
1928 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
1932 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
1933 gui_internal_widget_render(this, wi);
1940 gui_internal_widget_render(this, wi);
1946 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm)
1948 gui_internal_keypress_do(this, (char *) wm->data);
1952 gui_internal_search_changed(struct gui_priv *this, struct widget *wm)
1955 gui_internal_widget_children_destroy(this, this->list);
1956 char *text=NULL, *name=NULL;
1957 dbg(0,"%s now '%s'\n", wm->name, wm->text);
1958 if (wm->text && g_utf8_strlen(wm->text, -1) >= 2) {
1959 struct attr search_attr;
1960 struct search_list_result *res;
1964 if (! strcmp(wm->name,_("Town")))
1965 search_attr.type=attr_town_name;
1966 if (! strcmp(wm->name,_("Street")))
1967 search_attr.type=attr_street_name;
1968 search_attr.u.str=wm->text;
1969 search_list_search(this->sl, &search_attr, 1);
1970 while((res=search_list_get_result(this->sl))) {
1971 if (! strcmp(wm->name,_("Town"))) {
1972 name=res->town->name;
1973 text=g_strdup(name);
1975 if (! strcmp(wm->name,_("Street"))) {
1976 name=res->street->name;
1977 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
1979 dbg(0,"res=%s\n", res->town->name);
1980 gui_internal_widget_append(this->list,
1981 wc=gui_internal_button_new_with_callback(this, text,
1982 image_new_xs(this, res->country->flag), gravity_left_center|orientation_horizontal|flags_fill,
1983 gui_internal_cmd_position, (void *)3));
1985 wc->name=g_strdup(name);
1987 wc->item.id_lo=res->id;
1989 gui_internal_widget_pack(this, this->list);
1991 l=g_list_last(this->root.children);
1992 gui_internal_widget_render(this, l->data);
1995 static struct widget *
1996 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_free)(void *data))
2000 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2001 NULL, gravity_center|orientation_vertical, func, data));
2002 wk->data_free=data_free;
2003 wk->background=this->background;
2011 static struct widget *
2012 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key)
2014 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free);
2017 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key);
2019 static struct widget *
2020 gui_internal_keyboard_do(struct gui_priv *this, struct widget *key, int mode)
2022 struct widget *wkbdb,*wkbd,*wk;
2027 gui_internal_highlight(this, NULL);
2031 gui_internal_widget_children_destroy(this, wkbdb);
2033 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2034 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2035 wkbd->background=this->background;
2039 if (mode >= 0 && mode < 8) {
2040 for (i = 0 ; i < 26 ; i++) {
2041 char text[]={'A'+i,'\0'};
2042 gui_internal_keyboard_key(this, wkbd, text, text);
2044 gui_internal_keyboard_key(this, wkbd, "_"," ");
2046 gui_internal_keyboard_key(this, wkbd, "-","-");
2047 gui_internal_keyboard_key(this, wkbd, "'","'");
2048 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2050 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2051 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL);
2053 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL);
2056 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL);
2058 gui_internal_keyboard_key(this, wkbd, "<-","\b");
2060 if (mode >= 8 && mode < 16) {
2061 for (i = 0 ; i < 26 ; i++) {
2062 char text[]={'a'+i,'\0'};
2063 gui_internal_keyboard_key(this, wkbd, text, text);
2065 gui_internal_keyboard_key(this, wkbd, "_"," ");
2067 gui_internal_keyboard_key(this, wkbd, "-","-");
2068 gui_internal_keyboard_key(this, wkbd, "'","'");
2069 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2071 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2072 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL);
2074 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL);
2077 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL);
2079 gui_internal_keyboard_key(this, wkbd, "<-","\b");
2081 if (mode >= 16 && mode < 24) {
2082 for (i = 0 ; i < 10 ; i++) {
2083 char text[]={'0'+i,'\0'};
2084 gui_internal_keyboard_key(this, wkbd, text, text);
2086 gui_internal_keyboard_key(this, wkbd, ".",".");
2087 gui_internal_keyboard_key(this, wkbd, "°","°");
2088 gui_internal_keyboard_key(this, wkbd, "'","'");
2089 gui_internal_keyboard_key(this, wkbd, "\"","\"");
2090 gui_internal_keyboard_key(this, wkbd, "-","-");
2091 gui_internal_keyboard_key(this, wkbd, "+","+");
2092 gui_internal_keyboard_key(this, wkbd, "*","*");
2093 gui_internal_keyboard_key(this, wkbd, "/","/");
2094 gui_internal_keyboard_key(this, wkbd, "(","(");
2095 gui_internal_keyboard_key(this, wkbd, ")",")");
2096 gui_internal_keyboard_key(this, wkbd, "=","=");
2097 gui_internal_keyboard_key(this, wkbd, "?","?");
2098 for (i = 0 ; i < 5 ; i++) {
2099 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2102 gui_internal_keyboard_key(this, wkbd, "-","-");
2103 gui_internal_keyboard_key(this, wkbd, "'","'");
2104 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2106 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2107 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL);
2109 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL);
2112 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL);
2114 gui_internal_keyboard_key(this, wkbd, "<-","\b");
2116 if (mode >= 24 && mode < 32) {
2117 gui_internal_keyboard_key(this, wkbd, "Ä","Ä");
2118 gui_internal_keyboard_key(this, wkbd, "Ö","Ö");
2119 gui_internal_keyboard_key(this, wkbd, "Ü","Ü");
2120 for (i = 0 ; i < 27 ; i++) {
2121 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL);
2123 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL);
2125 gui_internal_keyboard_key(this, wkbd, "<-","\b");
2127 gui_internal_widget_append(wkbdb, wkbd);
2129 gui_internal_widget_pack(this, wkbdb);
2130 gui_internal_widget_render(this, wkbdb);
2135 static struct widget *
2136 gui_internal_keyboard(struct gui_priv *this, int mode)
2138 return gui_internal_keyboard_do(this, NULL, mode);
2142 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key)
2144 gui_internal_keyboard_do(this, key, 0);
2148 gui_internal_search_list_set_default_country(struct gui_priv *this)
2150 struct attr search_attr, country_name, country_iso2, *country_attr;
2152 struct country_search *cs;
2153 struct tracking *tracking;
2154 struct search_list_result *res;
2156 country_attr=country_default();
2157 tracking=navit_get_tracking(this->nav);
2158 if (tracking && tracking_get_current_attr(tracking, attr_country_id, &search_attr))
2159 country_attr=&search_attr;
2161 cs=country_search_new(country_attr, 0);
2162 item=country_search_get_item(cs);
2163 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2164 search_attr.type=attr_country_all;
2165 dbg(0,"country %s\n", country_name.u.str);
2166 search_attr.u.str=country_name.u.str;
2167 search_list_search(this->sl, &search_attr, 0);
2168 while((res=search_list_get_result(this->sl)));
2169 g_free(this->country_iso2);
2170 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2171 this->country_iso2=g_strdup(country_iso2.u.str);
2173 country_search_destroy(cs);
2175 dbg(0,"warning: no default country found\n");
2180 gui_internal_search_list_new(struct gui_priv *this)
2182 struct mapset *ms=navit_get_mapset(this->nav);
2184 this->sl=search_list_new(ms);
2185 gui_internal_search_list_set_default_country(this);
2190 gui_internal_search_list_destroy(struct gui_priv *this)
2193 search_list_destroy(this->sl);
2198 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget);
2201 gui_internal_search(struct gui_priv *this, char *what, char *type)
2203 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext;
2205 gui_internal_search_list_new(this);
2206 wb=gui_internal_menu(this, what);
2207 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2208 gui_internal_widget_append(wb, w);
2209 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2210 gui_internal_widget_append(w, wr);
2211 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2212 gui_internal_widget_append(wr, we);
2214 country=g_strdup_printf("country_%s", this->country_iso2);
2215 gui_internal_widget_append(we, gui_internal_image_new(this, image_new_xs(this, country)));
2218 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2219 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2220 wnext->state |= STATE_SENSITIVE;
2221 wnext->func = gui_internal_search_street;
2222 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2223 gui_internal_widget_append(wr, wl);
2225 wk->state |= STATE_EDIT;
2226 wk->background=this->background;
2227 wk->flags |= flags_expand|flags_fill;
2228 wk->func = gui_internal_search_changed;
2229 wk->name=g_strdup(type);
2230 gui_internal_widget_append(w, gui_internal_keyboard(this,0));
2231 gui_internal_menu_render(this);
2235 gui_internal_search_street(struct gui_priv *this, struct widget *widget)
2237 gui_internal_search(this,"Street","Street");
2241 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget)
2243 dbg(0,"id %d\n", widget->item.id_lo);
2244 search_list_select(this->sl, attr_town_name, 0, 0);
2245 search_list_select(this->sl, attr_town_name, widget->item.id_lo, 1);
2246 gui_internal_search(this,"Street","Street");
2250 gui_internal_cmd_town(struct gui_priv *this, struct widget *wm)
2252 gui_internal_search(this,"Town","Town");
2256 gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm)
2259 struct widget *w,*wb,*wl;
2260 struct attr_iter *iter;
2263 wb=gui_internal_menu(this, _("Layout"));
2264 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2265 w->spy=this->spacing*3;
2266 gui_internal_widget_append(wb, w);
2267 iter=navit_attr_iter_new();
2268 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
2269 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
2271 gui_internal_widget_append(w, wl);
2273 navit_attr_iter_destroy(iter);
2274 gui_internal_menu_render(this);
2278 gui_internal_cmd_fullscreen(struct gui_priv *this, struct widget *wm)
2280 this->fullscreen=!this->fullscreen;
2281 this->win->fullscreen(this->win, this->fullscreen);
2286 gui_internal_cmd_display(struct gui_priv *this, struct widget *wm)
2290 w=gui_internal_menu(this, _("Display"));
2291 gui_internal_widget_append(w,
2292 gui_internal_button_new_with_callback(this, _("Layout"),
2293 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
2294 gui_internal_cmd_layout, NULL));
2295 if (this->fullscreen) {
2296 gui_internal_widget_append(w,
2297 gui_internal_button_new_with_callback(this, _("Window Mode"),
2298 image_new_l(this, "gui_leave_fullscreen"), gravity_center|orientation_vertical,
2299 gui_internal_cmd_fullscreen, NULL));
2301 gui_internal_widget_append(w,
2302 gui_internal_button_new_with_callback(this, _("Fullscreen"),
2303 image_new_l(this, "gui_fullscreen"), gravity_center|orientation_vertical,
2304 gui_internal_cmd_fullscreen, NULL));
2306 gui_internal_menu_render(this);
2310 gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm)
2312 struct navit *nav=this->nav;
2314 main_remove_navit(nav);
2318 gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm)
2320 navit_set_destination(this->nav, NULL, NULL);
2325 gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm)
2327 struct widget *w,*wc;
2330 w=gui_internal_menu(this, _("Actions"));
2331 gui_internal_widget_append(w,
2332 gui_internal_button_new_with_callback(this, _("Bookmarks"),
2333 image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
2334 gui_internal_cmd_bookmarks, NULL));
2335 if (this->clickp_valid) {
2336 coord=coordinates(&this->clickp, '\n');
2337 gui_internal_widget_append(w,
2338 wc=gui_internal_button_new_with_callback(this, coord,
2339 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2340 gui_internal_cmd_position, (void *)1));
2341 wc->name=g_strdup(_("Map Point"));
2345 if (this->vehicle_valid) {
2346 coord=coordinates(&this->vehiclep, '\n');
2347 gui_internal_widget_append(w,
2348 wc=gui_internal_button_new_with_callback(this, coord,
2349 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
2350 gui_internal_cmd_position, NULL));
2351 wc->name=g_strdup(_("Vehicle Position"));
2352 wc->c=this->vehiclep;
2355 gui_internal_widget_append(w,
2356 gui_internal_button_new_with_callback(this, _("Town"),
2357 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
2358 gui_internal_cmd_town, NULL));
2359 gui_internal_widget_append(w,
2360 gui_internal_button_new_with_callback(this, _("Quit"),
2361 image_new_l(this, "gui_quit"), gravity_center|orientation_vertical,
2362 gui_internal_cmd_quit, NULL));
2364 if (navit_check_route(this->nav)) {
2365 gui_internal_widget_append(w,
2366 gui_internal_button_new_with_callback(this, _("Stop\nNavigation"),
2367 image_new_l(this, "gui_stop"), gravity_center|orientation_vertical,
2368 gui_internal_cmd_abort_navigation, NULL));
2370 gui_internal_menu_render(this);
2374 gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm)
2376 struct attr attr, on, off, description, type, data;
2377 struct widget *w,*wb,*wma;
2379 struct attr_iter *iter;
2382 wb=gui_internal_menu(this, _("Maps"));
2383 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2384 w->spy=this->spacing*3;
2385 gui_internal_widget_append(wb, w);
2386 iter=navit_attr_iter_new();
2387 on.type=off.type=attr_active;
2390 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
2391 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
2392 label=g_strdup(description.u.str);
2394 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
2396 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
2398 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
2400 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
2401 attr.u.map, &on, &off, 1);
2402 gui_internal_widget_append(w, wma);
2405 navit_attr_iter_destroy(iter);
2406 gui_internal_menu_render(this);
2411 gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm)
2413 struct attr attr,vattr;
2414 struct widget *w,*wb,*wl;
2415 struct attr_iter *iter;
2418 wb=gui_internal_menu(this, _("Vehicle"));
2419 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2420 w->spy=this->spacing*3;
2421 gui_internal_widget_append(wb, w);
2422 iter=navit_attr_iter_new();
2423 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
2424 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
2425 wl=gui_internal_button_navit_attr_new(this, vattr.u.str, gravity_left_center|orientation_horizontal|flags_fill,
2427 gui_internal_widget_append(w, wl);
2429 navit_attr_iter_destroy(iter);
2430 gui_internal_menu_render(this);
2435 gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm)
2437 struct widget *wb,*w;
2439 wb=gui_internal_menu(this, _("Rules"));
2440 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2441 w->spy=this->spacing*3;
2442 gui_internal_widget_append(wb, w);
2445 on.type=off.type=attr_tracking;
2446 gui_internal_widget_append(w,
2447 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
2449 on.type=off.type=attr_orientation;
2450 gui_internal_widget_append(w,
2451 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
2453 on.type=off.type=attr_cursor;
2454 gui_internal_widget_append(w,
2455 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
2457 gui_internal_menu_render(this);
2461 gui_internal_cmd_settings(struct gui_priv *this, struct widget *wm)
2465 w=gui_internal_menu(this, _("Settings"));
2466 gui_internal_widget_append(w,
2467 gui_internal_button_new_with_callback(this, _("Display"),
2468 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
2469 gui_internal_cmd_display, NULL));
2470 gui_internal_widget_append(w,
2471 gui_internal_button_new_with_callback(this, _("Maps"),
2472 image_new_l(this, "gui_maps"), gravity_center|orientation_vertical,
2473 gui_internal_cmd_maps, NULL));
2474 gui_internal_widget_append(w,
2475 gui_internal_button_new_with_callback(this, _("Vehicle"),
2476 image_new_l(this, "gui_sound"), gravity_center|orientation_vertical,
2477 gui_internal_cmd_vehicle, NULL));
2478 gui_internal_widget_append(w,
2479 gui_internal_button_new_with_callback(this, _("Rules"),
2480 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
2481 gui_internal_cmd_rules, NULL));
2482 gui_internal_menu_render(this);
2485 //##############################################################################################################
2488 //# Authors: Martin Schaller (04/2008)
2489 //##############################################################################################################
2490 static void gui_internal_motion(void *data, struct point *p)
2492 struct gui_priv *this=data;
2493 if (!this->root.children) {
2494 navit_handle_motion(this->nav, p);
2499 graphics_draw_mode(this->gra, draw_mode_begin);
2500 gui_internal_highlight(this, p);
2501 graphics_draw_mode(this->gra, draw_mode_end);
2506 static void gui_internal_menu_root(struct gui_priv *this)
2510 graphics_draw_mode(this->gra, draw_mode_begin);
2511 w=gui_internal_menu(this, _("Main menu"));
2512 w->spx=this->spacing*10;
2513 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Actions"),
2514 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
2515 gui_internal_cmd_actions, NULL));
2516 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Settings"),
2517 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
2518 gui_internal_cmd_settings, NULL));
2519 gui_internal_widget_append(w, gui_internal_button_new(this, _("Tools"),
2520 image_new_l(this, "gui_tools"), gravity_center|orientation_vertical));
2522 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, "Table Test",
2523 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
2524 gui_internal_cmd_route, NULL));
2527 gui_internal_menu_render(this);
2528 graphics_draw_mode(this->gra, draw_mode_end);
2532 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
2534 struct graphics *gra=this->gra;
2535 struct transformation *trans;
2537 struct attr attr,attrp;
2539 this->ignore_button=ignore;
2540 this->clickp_valid=this->vehicle_valid=0;
2542 navit_block(this->nav, 1);
2543 graphics_overlay_disable(gra, 1);
2544 trans=navit_get_trans(this->nav);
2546 transform_reverse(trans, p, &c);
2547 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2548 this->clickp.pro=transform_get_projection(trans);
2551 this->clickp_valid=1;
2553 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
2554 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
2555 this->vehiclep.pro=transform_get_projection(trans);
2556 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
2557 this->vehiclep.x=c.x;
2558 this->vehiclep.y=c.y;
2559 this->vehicle_valid=1;
2564 this->root.background=this->background;
2565 gui_internal_menu_root(this);
2569 gui_internal_check_exit(struct gui_priv *this)
2571 struct graphics *gra=this->gra;
2572 if (! this->root.children) {
2573 gui_internal_search_list_destroy(this);
2574 graphics_overlay_disable(gra, 0);
2575 if (!navit_block(this->nav, 0)) {
2577 navit_draw(this->nav);
2579 navit_draw_displaylist(this->nav);
2584 //##############################################################################################################
2585 //# Description: Function to handle mouse clicks and scroll wheel movement
2587 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
2588 //##############################################################################################################
2589 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
2591 struct gui_priv *this=data;
2592 struct graphics *gra=this->gra;
2594 // if still on the map (not in the menu, yet):
2595 if (!this->root.children || this->ignore_button) {
2596 this->ignore_button=0;
2597 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
2598 if (!navit_handle_button(this->nav, pressed, button, p, NULL) || button >=4) // Maybe there's a better way to do this
2600 if (this->menu_on_map_click)
2601 gui_internal_cmd_menu(this, p, 0);
2605 // if already in the menu:
2608 graphics_draw_mode(gra, draw_mode_begin);
2609 gui_internal_highlight(this, p);
2610 graphics_draw_mode(gra, draw_mode_end);
2613 graphics_draw_mode(gra, draw_mode_begin);
2614 gui_internal_call_highlighted(this);
2615 gui_internal_highlight(this, NULL);
2616 graphics_draw_mode(gra, draw_mode_end);
2617 gui_internal_check_exit(this);
2621 //##############################################################################################################
2624 //# Authors: Martin Schaller (04/2008)
2625 //##############################################################################################################
2626 static void gui_internal_resize(void *data, int w, int h)
2628 struct gui_priv *this=data;
2631 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
2632 navit_resize(this->nav, w, h);
2633 if (this->root.children) {
2634 gui_internal_prune_menu(this, NULL);
2635 gui_internal_menu_root(this);
2640 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
2655 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
2657 GList *l=wi->children;
2658 if (wi->state & STATE_SENSITIVE) {
2661 gui_internal_keynav_point(wi, -dx, -dy, &wp);
2663 dist1=(wp.x-p->x)*dx;
2666 dist1=(wp.y-p->y)*dy;
2674 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);
2680 if (dist1 < *distance) {
2687 struct widget *child=l->data;
2688 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
2694 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
2696 struct widget *result,*menu=g_list_last(this->root.children)->data;
2699 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
2700 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
2706 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
2708 gui_internal_keynav_point(result, dx, dy, &p);
2709 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
2714 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
2715 dbg(1,"result=%p\n", result);
2727 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
2728 dbg(1,"wraparound result=%p\n", result);
2730 gui_internal_highlight_do(this, result);
2732 gui_internal_say(this, result, 1);
2735 //##############################################################################################################
2738 //# Authors: Martin Schaller (04/2008)
2739 //##############################################################################################################
2740 static void gui_internal_keypress(void *data, char *key)
2742 struct gui_priv *this=data;
2745 if (!this->root.children) {
2746 transform_get_size(navit_get_trans(this->nav), &w, &h);
2751 navit_set_center_screen(this->nav, &p);
2753 case NAVIT_KEY_DOWN:
2756 navit_set_center_screen(this->nav, &p);
2758 case NAVIT_KEY_LEFT:
2761 navit_set_center_screen(this->nav, &p);
2763 case NAVIT_KEY_RIGHT:
2766 navit_set_center_screen(this->nav, &p);
2768 case NAVIT_KEY_ZOOM_IN:
2769 navit_zoom_in(this->nav, 2, NULL);
2771 case NAVIT_KEY_ZOOM_OUT:
2772 navit_zoom_out(this->nav, 2, NULL);
2774 case NAVIT_KEY_RETURN:
2775 gui_internal_cmd_menu(this, NULL, 0);
2780 graphics_draw_mode(this->gra, draw_mode_begin);
2782 case NAVIT_KEY_LEFT:
2783 gui_internal_keynav_highlight_next(this,-1,0);
2785 case NAVIT_KEY_RIGHT:
2786 gui_internal_keynav_highlight_next(this,1,0);
2789 gui_internal_keynav_highlight_next(this,0,-1);
2791 case NAVIT_KEY_DOWN:
2792 gui_internal_keynav_highlight_next(this,0,1);
2794 case NAVIT_KEY_RETURN:
2795 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
2796 gui_internal_call_highlighted(this);
2798 gui_internal_keypress_do(this, key);
2801 gui_internal_keypress_do(this, key);
2803 graphics_draw_mode(this->gra, draw_mode_end);
2804 gui_internal_check_exit(this);
2808 //##############################################################################################################
2811 //# Authors: Martin Schaller (04/2008)
2812 //##############################################################################################################
2813 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
2817 struct color cb={0x7fff,0x7fff,0x7fff,0xffff};
2819 struct color cb={0x0,0x0,0x0,0xffff};
2820 struct color cb2={0x4141,0x4141,0x4141,0xffff};
2821 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
2822 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
2823 struct color cw={0xffff,0xffff,0xffff,0xffff};
2824 struct transformation *trans=navit_get_trans(this->nav);
2826 win=graphics_get_data(gra, "window");
2831 transform_get_size(trans, &this->root.w, &this->root.h);
2832 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
2833 graphics_add_callback(gra, this->resize_cb);
2834 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
2835 graphics_add_callback(gra, this->button_cb);
2836 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
2837 graphics_add_callback(gra, this->motion_cb);
2838 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
2839 graphics_add_callback(gra, this->keypress_cb);
2840 this->background=graphics_gc_new(gra);
2841 graphics_gc_set_foreground(this->background, &cb);
2842 this->background2=graphics_gc_new(gra);
2843 graphics_gc_set_foreground(this->background2, &cb2);
2844 this->highlight_background=graphics_gc_new(gra);
2845 graphics_gc_set_foreground(this->highlight_background, &cbh);
2846 this->foreground=graphics_gc_new(gra);
2847 graphics_gc_set_foreground(this->foreground, &cf);
2848 this->text_background=graphics_gc_new(gra);
2849 graphics_gc_set_foreground(this->text_background, &cb);
2850 this->text_foreground=graphics_gc_new(gra);
2851 graphics_gc_set_foreground(this->text_foreground, &cw);
2855 //##############################################################################################################
2858 //# Authors: Martin Schaller (04/2008)
2859 //##############################################################################################################
2860 struct gui_methods gui_internal_methods = {
2863 gui_internal_set_graphics,
2866 //##############################################################################################################
2869 //# Authors: Martin Schaller (04/2008)
2870 //##############################################################################################################
2871 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
2873 struct gui_priv *this;
2875 *meth=gui_internal_methods;
2876 this=g_new0(struct gui_priv, 1);
2878 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
2879 this->menu_on_map_click=attr->u.num;
2881 this->menu_on_map_click=1;
2882 navit_command_register(nav,"gui_internal_menu",callback_new_3(callback_cast(gui_internal_cmd_menu),this,NULL,(void *)1));
2883 navit_command_register(nav,"gui_internal_fullscreen",callback_new_2(callback_cast(gui_internal_cmd_fullscreen),this,NULL));
2885 if( (attr=attr_search(attrs,NULL,attr_font_size)))
2887 this->config.font_size=attr->u.num;
2891 this->config.font_size=-1;
2893 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
2895 this->config.icon_xs=attr->u.num;
2899 this->config.icon_xs=-1;
2901 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
2903 this->config.icon_l=attr->u.num;
2907 this->config.icon_l=-1;
2909 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
2911 this->config.icon_s=attr->u.num;
2915 this->config.icon_s=-1;
2917 if( (attr=attr_search(attrs,NULL,attr_spacing)))
2919 this->config.spacing=attr->u.num;
2923 this->config.spacing=-1;
2925 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
2927 this->speech=attr->u.num;
2933 //##############################################################################################################
2936 //# Authors: Martin Schaller (04/2008)
2937 //##############################################################################################################
2938 void plugin_init(void)
2940 plugin_register_gui_type("internal", gui_internal_new);
2944 * @brief Creates a new table widget.
2946 * Creates and returns a new table widget. This function will
2947 * setup next/previous buttons as children.
2949 * @param this The graphics context.
2950 * @param flags widget sizing flags.
2951 * @returns The newly created widget
2953 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags)
2955 struct widget * widget = g_new0(struct widget,1);
2956 struct table_data * data = NULL;
2957 widget->type=widget_table;
2958 widget->flags=flags;
2959 widget->data = g_new0(struct table_data,1);
2960 widget->data_free=gui_internal_table_data_free;
2961 data = (struct table_data*)widget->data;
2964 data->next_button = gui_internal_button_new_with_callback
2965 (this,"Next",image_new_xs(this, "gui_active") ,
2966 gravity_left_center |orientation_vertical,
2967 gui_internal_table_button_next,NULL);
2968 data->next_button->data=widget;
2971 data->prev_button = gui_internal_button_new_with_callback
2973 image_new_xs(this, "gui_active")
2974 ,gravity_right_center |orientation_vertical,
2975 gui_internal_table_button_prev,NULL);
2977 data->prev_button->data=widget;
2981 data->button_box=gui_internal_box_new(this,
2982 gravity_center|orientation_horizontal);
2983 data->button_box->children=g_list_append(data->button_box->children,
2985 data->button_box->children=g_list_append(data->button_box->children,
2987 data->button_box->background=this->background2;
2988 data->button_box->bl=this->spacing;
2989 widget->children=g_list_append(widget->children,data->button_box);
2990 gui_internal_widget_pack(this,data->button_box);
2998 * @brief Adds a row to a table_widget.
3000 * @param table The table to add the row to.
3001 * @param row A table_row widget that will be added to the table.
3003 void gui_internal_widget_table_add_row(struct widget * table, struct widget * row)
3005 table->children=g_list_append(table->children,row);
3010 * Creates a new table_row widget.
3011 * @param this The graphics context
3012 * @param flags Sizing flags for the row
3013 * @returns The new table_row widget.
3015 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
3017 struct widget * widget = g_new0(struct widget,1);
3018 widget->type=widget_table_row;
3019 widget->flags=flags;
3026 * @brief Computes the column dimensions for the table.
3028 * @param w The table widget to compute dimensions for.
3030 * This function examines all of the rows and columns for the table w
3031 * and returns a list (GList) of table_column_desc elements that
3032 * describe each column of the table.
3034 * The caller is responsible for freeing the returned list.
3036 static GList * gui_internal_compute_table_dimensions(struct widget * w)
3039 GList * column_desc = NULL;
3040 GList * current_desc=NULL;
3041 GList * cur_row = w->children;
3042 struct widget * cur_row_widget=NULL;
3043 GList * cur_column=NULL;
3044 struct widget * cell_w=NULL;
3045 struct table_column_desc * current_cell=NULL;
3046 struct table_data * table_data=NULL;
3052 * Scroll through the the table and
3053 * 1. Compute the maximum width + height of each column across all rows.
3055 table_data = (struct table_data*) w->data;
3056 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
3058 cur_row_widget = (struct widget*) cur_row->data;
3059 current_desc = column_desc;
3060 if(cur_row_widget == table_data->button_box)
3064 for(cur_column = cur_row_widget->children; cur_column;
3065 cur_column=g_list_next(cur_column))
3067 cell_w = (struct widget*) cur_column->data;
3068 if(current_desc == 0)
3070 current_cell = g_new0(struct table_column_desc,1);
3071 column_desc = g_list_append(column_desc,current_cell);
3072 current_desc = g_list_last(column_desc);
3073 current_cell->height=cell_w->h;
3074 current_cell->width=cell_w->w;
3079 current_cell = current_desc->data;
3082 if(current_cell->height < height )
3084 current_cell->height = height;
3086 if(current_cell->width < width)
3088 current_cell->width = width;
3090 current_desc = g_list_next(current_desc);
3101 * @brief Computes the height and width for the table.
3103 * The height and widht are computed to display all cells in the table
3104 * at the requested height/width.
3106 * @param this The graphics context
3107 * @param w The widget to pack.
3110 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
3116 GList * column_data = gui_internal_compute_table_dimensions(w);
3118 struct table_column_desc * cell_desc=0;
3119 struct table_data * table_data = (struct table_data*)w->data;
3121 for(current = column_data; current; current=g_list_next(current))
3123 if(table_data->button_box == current->data )
3127 cell_desc = (struct table_column_desc *) current->data;
3128 width = width + cell_desc->width + this->spacing;
3129 if(height < cell_desc->height)
3131 height = cell_desc->height ;
3135 for(current=w->children; current; current=g_list_next(current))
3137 if(current->data!= table_data->button_box)
3142 gui_internal_widget_pack(this,table_data->button_box);
3143 w->h = count * (height+this->spacing) + table_data->button_box + this->spacing;
3145 if(w->h + w->c.y > this->root.h )
3148 * Do not allow the widget to exceed the screen.
3151 w->h = this->root.h- w->c.y - height;
3156 * Deallocate column descriptions.
3158 current = column_data;
3159 while( (current = g_list_last(current)) )
3161 current = g_list_remove(current,current->data);
3169 * @brief Renders a table widget.
3171 * @param this The graphics context
3172 * @param w The table widget to render.
3174 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
3179 GList * column_desc=NULL;
3180 GList * cur_row = NULL;
3181 GList * current_desc=NULL;
3182 struct table_data * table_data = (struct table_data*)w->data;
3184 struct table_column_desc * dim=NULL;
3186 column_desc = gui_internal_compute_table_dimensions(w);
3191 * Skip rows that are on previous pages.
3193 cur_row = w->children;
3194 if(table_data->top_row )
3196 cur_row = table_data->top_row;
3201 * Loop through each row. Drawing each cell with the proper sizes,
3202 * at the proper positions.
3204 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
3206 GList * cur_column=NULL;
3207 current_desc = column_desc;
3208 struct widget * cur_row_widget = (struct widget*)cur_row->data;
3210 x =w->p.x+this->spacing;
3211 if(cur_row_widget == table_data->button_box )
3215 dim = (struct table_column_desc*)current_desc->data;
3217 if( y + dim->height + table_data->button_box->h + this->spacing >= w->p.y + w->h )
3220 * No more drawing space left.
3226 for(cur_column = cur_row_widget->children; cur_column;
3227 cur_column=g_list_next(cur_column))
3229 struct widget * cur_widget = (struct widget*) cur_column->data;
3230 dim = (struct table_column_desc*)current_desc->data;
3233 cur_widget->w=dim->width;
3235 cur_widget->h=dim->height;
3237 max_height = dim->height;
3238 gui_internal_widget_render(this,cur_widget);
3240 if(dim->height > max_height)
3242 max_height = dim->height;
3246 table_data->bottom_row=cur_row;
3247 current_desc = g_list_next(current_desc);
3249 if(table_data && table_data->button_box )
3251 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
3253 if(table_data->button_box->p.y < y )
3255 table_data->button_box->p.y=y;
3257 table_data->button_box->p.x = w->p.x;
3258 table_data->button_box->w = w->w;
3259 // table_data->button_box->h = w->h - y;
3260 // table_data->next_button->h=table_data->button_box->h;
3261 // table_data->prev_button->h=table_data->button_box->h;
3262 // table_data->next_button->c.y=table_data->button_box->c.y;
3263 // table_data->prev_button->c.y=table_data->button_box->c.y;
3265 gui_internal_widget_pack(this,table_data->button_box);
3266 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
3269 table_data->button_box->p.y = w->p.y + w->h -
3270 table_data->button_box->h;
3274 table_data->next_button->state|= STATE_SENSITIVE;
3278 table_data->next_button->state&= ~STATE_SENSITIVE;
3281 if(table_data->top_row != w->children)
3283 table_data->prev_button->state|= STATE_SENSITIVE;
3287 table_data->prev_button->state&= ~STATE_SENSITIVE;
3289 gui_internal_widget_render(this,table_data->button_box);
3295 * Deallocate column descriptions.
3297 current_desc = column_desc;
3298 while( (current_desc = g_list_last(current_desc)) )
3300 current_desc = g_list_remove(current_desc,current_desc->data);
3306 * TEST function for demonstrating table.
3308 void gui_internal_cmd_route(struct gui_priv * this, struct widget * wm)
3312 struct widget * menu;
3317 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical);
3319 for(idx=0; idx < 52; idx++)
3321 struct widget * row = gui_internal_widget_table_row_new
3322 (this,gravity_left_top);
3323 sprintf(buffer, "Test %d",idx);
3324 row->children = g_list_append(row->children,
3325 gui_internal_label_new(this,buffer));
3326 row->children= g_list_append(row->children,
3327 gui_internal_label_new(this,"column 2 4 6 8"));
3328 gui_internal_widget_table_add_row(w,row);
3330 menu=gui_internal_menu(this,"Route");
3331 gui_internal_widget_append(menu,w);
3332 gui_internal_menu_render(this);
3339 * @brief handles the 'next page' table event.
3340 * A callback function that is invoked when the 'next page' button is pressed
3341 * to advance the contents of a table widget.
3343 * @param this The graphics context.
3344 * @param wm The button widget that was pressed.
3346 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm)
3348 struct widget * table_widget = (struct widget * ) wm->data;
3349 struct table_data * table_data = NULL;
3355 table_data = (struct table_data*) table_widget->data;
3361 * Before advancing to the next page we need to ensure
3362 * that the current top_row is in the list of previous top_rows
3363 * so previous page can work.
3366 for(iterator=table_data->page_headers; iterator != NULL;
3367 iterator = g_list_next(iterator) )
3369 if(iterator->data == table_data->top_row)
3378 table_data->page_headers=g_list_append(table_data->page_headers,
3379 table_data->top_row);
3382 table_data->top_row = g_list_next(table_data->bottom_row);
3384 wm->state&= ~STATE_HIGHLIGHTED;
3385 gui_internal_menu_render(this);
3391 * @brief handles the 'previous page' table event.
3392 * A callback function that is invoked when the 'previous page' button is pressed
3393 * to go back in the contents of a table widget.
3395 * @param this The graphics context.
3396 * @param wm The button widget that was pressed.
3398 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm)
3400 struct widget * table_widget = (struct widget * ) wm->data;
3401 struct table_data * table_data = NULL;
3402 GList * current_page_top=NULL;
3407 table_data = (struct table_data*) table_widget->data;
3408 current_page_top = table_data->top_row;
3411 for(iterator = table_data->page_headers; iterator != NULL;
3412 iterator = g_list_next(iterator))
3414 if(current_page_top == iterator->data)
3418 table_data->top_row = (GList*) iterator->data;
3422 wm->state&= ~STATE_HIGHLIGHTED;
3423 gui_internal_menu_render(this);
3428 * @brief deallocates a table_data structure.
3431 void gui_internal_table_data_free(void * p)
3436 * @note button_box and its children (next_button,prev_button)
3437 * have their memory managed by the table itself.
3439 struct table_data * table_data = (struct table_data*) p;
3440 g_list_free(table_data->page_headers);