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 //##############################################################################################################
215 struct graphics *gra;
216 struct graphics_gc *background;
217 struct graphics_gc *background2;
218 struct graphics_gc *highlight_background;
219 struct graphics_gc *foreground;
220 struct graphics_gc *text_foreground;
221 struct graphics_gc *text_background;
222 struct color background_color, background2_color, text_foreground_color, text_background_color;
226 struct graphics_font *font;
227 int icon_xs, icon_s, icon_l;
229 struct widget *widgets;
233 struct widget *highlighted;
234 struct widget *highlighted_menu;
235 int clickp_valid, vehicle_valid;
236 struct pcoord clickp, vehiclep;
237 struct search_list *sl;
239 int menu_on_map_click;
244 * The setting information read from the configuration file.
245 * values of -1 indicate no value was specified in the config file.
247 struct gui_config_settings config;
248 struct event_idle *idle;
249 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*idle_cb, *motion_timeout_callback;
250 struct event_timeout *motion_timeout_event;
251 struct point current;
253 struct callback * vehicle_cb;
255 * Stores information about the route.
257 struct route_data route_data;
259 struct gui_internal_data data;
260 struct callback_list *cbl;
263 struct attr osd_configuration;
266 char *html_tag,*html_command;
267 struct widget *html_container, *html_curr;
272 * @brief A structure to store information about a table.
274 * The table_data widget stores pointers to extra information needed by the
277 * The table_data structure needs to be freed with data_free along with the widget.
283 * A GList pointer into a widget->children list that indicates the row
284 * currently being rendered at the top of the table.
288 * A Glist pointer into a widget->children list that indicates the row
289 * currently being rendered at the bottom of the table.
294 * A list of table_row widgets that mark the
295 * top rows for each page of the table.
296 * This is needed for the 'previous page' function of the table.
298 GList * page_headers;
301 * A container box that is the child of the table widget that contains+groups
302 * the next and previous button.
304 struct widget * button_box;
307 * A button widget to handle 'next page' requests
309 struct widget * next_button;
311 * A button widget to handle 'previous page' requests.
313 struct widget * prev_button;
317 * a pointer to the gui context.
318 * This is needed by the free function to destory the buttons.
320 struct gui_priv * this;
324 * A data structure that holds information about a column that makes up a table.
328 struct table_column_desc
332 * The computed height of a cell in the table.
337 * The computed width of a cell in the table.
343 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
344 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
345 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
346 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
347 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
348 static void gui_internal_apply_config(struct gui_priv *this);
350 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
351 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
352 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
353 static void gui_internal_cmd_tools(struct gui_priv * this, struct widget * w,void *);
354 static void gui_internal_cmd_route(struct gui_priv * this, struct widget * w,void *);
355 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
356 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
357 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
358 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
359 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
360 static void gui_internal_table_data_free(void * d);
361 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
363 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
364 static void gui_internal_populate_route_table(struct gui_priv * this,
365 struct navit * navit);
366 static void gui_internal_search_idle_end(struct gui_priv *this);
367 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
368 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
369 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
370 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
371 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
372 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
373 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
374 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
375 static void gui_internal_check_exit(struct gui_priv *this);
376 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
378 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
379 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
381 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
384 * * Display image scaled to specific size
385 * * searches for scaleable and pre-scaled image
386 * * @param this Our gui context
387 * * @param name image name
388 * * @param w desired width of image
389 * * @param h desired height of image
390 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
392 static struct graphics_image *
393 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
395 struct graphics_image *ret=NULL;
396 char *full_name=NULL;
397 char *full_path=NULL;
400 for (i = 1 ; i < 6 ; i++) {
404 full_name=g_strdup_printf("%s.svg", name);
407 full_name=g_strdup_printf("%s.svgz", name);
410 if (w != -1 && h != -1) {
411 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
415 full_name=g_strdup_printf("%s.png", name);
418 full_name=g_strdup_printf("%s.xpm", name);
421 dbg(1,"trying '%s'\n", full_name);
425 /* needs to be checked in the driver */
426 if (!file_exists(full_name)) {
431 full_path=graphics_icon_path(full_name);
432 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
433 dbg(1,"ret=%p\n", ret);
439 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
444 static struct graphics_image *
445 image_new_o(struct gui_priv *this, char *name)
447 return image_new_scaled(this, name, -1, -1);
451 static struct graphics_image *
452 image_new_xs(struct gui_priv *this, const char *name)
454 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
458 static struct graphics_image *
459 image_new_s(struct gui_priv *this, const char *name)
461 return image_new_scaled(this, name, this->icon_s, this->icon_s);
464 static struct graphics_image *
465 image_new_l(struct gui_priv *this, const char *name)
467 return image_new_scaled(this, name, this->icon_l, this->icon_l);
471 coordinates(struct pcoord *pc, char sep)
473 char latc='N',lngc='E';
474 int lat_deg,lat_min,lat_sec;
475 int lng_deg,lng_min,lng_sec;
480 transform_to_geo(pc->pro, &c, &g);
491 lat_min=fmod(g.lat*60,60);
492 lat_sec=fmod(g.lat*3600,60);
494 lng_min=fmod(g.lng*60,60);
495 lng_sec=fmod(g.lng*3600,60);
496 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);
500 gui_internal_background_render(struct gui_priv *this, struct widget *w)
502 struct point pnt=w->p;
503 if (w->state & STATE_HIGHLIGHTED)
504 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
507 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
510 static struct widget *
511 gui_internal_label_new(struct gui_priv *this, char *text)
517 struct widget *widget=g_new0(struct widget, 1);
518 widget->type=widget_label;
520 widget->text=g_strdup(text);
521 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
525 widget->h=h+this->spacing;
527 widget->w=w+this->spacing;
529 widget->flags=gravity_center;
530 widget->foreground=this->text_foreground;
531 widget->text_background=this->text_background;
536 static struct widget *
537 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
539 struct widget *ret=NULL;
540 char *tmp=g_malloc(strlen(text)+3);
547 ret=gui_internal_label_new(this, tmp);
548 if (ret->w < maxwidth)
550 gui_internal_widget_destroy(this, ret);
558 static struct widget *
559 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
561 struct widget *widget=g_new0(struct widget, 1);
562 widget->type=widget_image;
565 widget->w=image->width;
566 widget->h=image->height;
572 gui_internal_image_render(struct gui_priv *this, struct widget *w)
576 gui_internal_background_render(this, w);
579 pnt.x+=w->w/2-w->img->hot.x;
580 pnt.y+=w->h/2-w->img->hot.y;
581 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
586 gui_internal_label_render(struct gui_priv *this, struct widget *w)
588 struct point pnt=w->p;
589 gui_internal_background_render(this, w);
591 if (w->flags & gravity_right) {
592 pnt.y+=w->h-this->spacing;
593 pnt.x+=w->w-w->textw-this->spacing;
594 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
596 pnt.y+=w->h-this->spacing;
597 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
603 * @brief A text box is a widget that renders a text string containing newlines.
604 * The string will be broken up into label widgets at each newline with a vertical layout.
607 static struct widget *
608 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
610 char *s=g_strdup(text),*s2,*tok;
611 struct widget *ret=gui_internal_box_new(this, flags);
613 while ((tok=strtok(s2,"\n"))) {
614 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
617 gui_internal_widget_pack(this,ret);
622 static struct widget *
623 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)
625 struct widget *ret=NULL;
626 ret=gui_internal_box_new(this, flags);
629 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
631 gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
635 ret->state |= STATE_SENSITIVE;
636 ret->speech=g_strdup(text);
644 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
651 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
652 is_on=curr.u.data == w->on.u.data;
655 if (is_on != w->is_on) {
659 l=g_list_first(w->children);
663 graphics_image_free(this->gra, wi->img);
664 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
666 if (w->is_on && w->off.type == attr_none)
667 w->state &= ~STATE_SENSITIVE;
669 w->state |= STATE_SENSITIVE;
676 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
678 if (gui_internal_button_attr_update(this, w))
679 gui_internal_widget_render(this, w);
682 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
685 w->set_attr(w->instance, &w->off);
687 w->set_attr(w->instance, &w->on);
688 gui_internal_button_attr_update(this, w);
692 static struct widget *
693 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
695 struct graphics_image *image=NULL;
699 image=image_new_xs(this, "gui_inactive");
700 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
705 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
706 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
707 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
708 ret->instance=this->nav;
709 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
710 navit_add_callback(this->nav, ret->cb);
711 gui_internal_button_attr_update(this, ret);
715 static struct widget *
716 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)
718 struct graphics_image *image=NULL;
720 image=image_new_xs(this, "gui_inactive");
723 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
729 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
730 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
731 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
734 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
735 map_add_callback(map, ret->cb);
736 gui_internal_button_attr_update(this, ret);
740 static struct widget *
741 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
743 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
747 //##############################################################################################################
750 //# Authors: Martin Schaller (04/2008)
751 //##############################################################################################################
752 static void gui_internal_clear(struct gui_priv *this)
754 struct graphics *gra=this->gra;
758 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
762 static struct widget *
763 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
765 struct widget *ret,*child;
766 GList *l=wi->children;
773 if ( wi->p.x + wi->w < p->x)
775 if ( wi->p.y + wi->h < p->y)
778 if (wi->state & flags)
782 ret=gui_internal_find_widget(child, p, flags);
793 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
795 if (found == this->highlighted)
798 graphics_draw_mode(this->gra, draw_mode_begin);
799 if (this->highlighted) {
800 this->highlighted->state &= ~STATE_HIGHLIGHTED;
801 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
802 gui_internal_widget_render(this, this->highlighted);
803 this->highlighted=NULL;
804 this->highlighted_menu=NULL;
807 this->highlighted=found;
808 this->highlighted_menu=g_list_last(this->root.children)->data;
809 this->highlighted->state |= STATE_HIGHLIGHTED;
810 gui_internal_widget_render(this, this->highlighted);
811 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
813 graphics_draw_mode(this->gra, draw_mode_end);
815 //##############################################################################################################
818 //# Authors: Martin Schaller (04/2008)
819 //##############################################################################################################
820 static void gui_internal_highlight(struct gui_priv *this)
822 struct widget *menu,*found=NULL;
823 if (this->current.x > -1 && this->current.y > -1) {
824 menu=g_list_last(this->root.children)->data;
825 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
827 gui_internal_highlight_do(this, found);
828 this->motion_timeout_event=NULL;
831 static struct widget *
832 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, char *label)
834 struct widget *widget=g_new0(struct widget, 1);
837 widget->text=g_strdup(label);
838 widget->type=widget_box;
843 static struct widget *
844 gui_internal_box_new(struct gui_priv *this, enum flags flags)
846 return gui_internal_box_new_with_label(this, flags, NULL);
850 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
855 gui_internal_background_render(this, w);
857 if (w->foreground && w->border) {
860 pnt[1].x=pnt[0].x+w->w;
862 pnt[2].x=pnt[0].x+w->w;
863 pnt[2].y=pnt[0].y+w->h;
865 pnt[3].y=pnt[0].y+w->h;
867 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
868 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
869 graphics_gc_set_linewidth(w->foreground, 1);
876 gui_internal_widget_render(this, wc);
883 * @brief Compute the size and location for the widget.
887 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
890 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;
892 int orientation=w->flags & 0xffff0000;
897 if ( this->root.w > this->root.h )
907 * count the number of children
914 if (orientation == orientation_horizontal_vertical && count <= cols)
915 orientation=orientation_horizontal;
916 switch (orientation) {
917 case orientation_horizontal:
919 * For horizontal orientation:
920 * pack each child and find the largest height and
921 * compute the total width. x spacing (spx) is considered
923 * If any children want to be expanded
924 * we keep track of this
929 gui_internal_widget_pack(this, wc);
933 if (wc->flags & flags_expand)
934 expand+=wc->w ? wc->w : 1;
940 if (expand && w->w) {
941 expand=100*(w->w-width+expand)/expand;
946 case orientation_vertical:
948 * For vertical layouts:
949 * We pack each child and compute the largest width and
950 * the total height. y spacing (spy) is considered
952 * If the expand flag is set then teh expansion amount
958 gui_internal_widget_pack(this, wc);
962 if (wc->flags & flags_expand)
963 expand+=wc->h ? wc->h : 1;
969 if (expand && w->h) {
970 expand=100*(w->h-height+expand)/expand;
975 case orientation_horizontal_vertical:
977 * For horizontal_vertical orientation
979 * Compute the largest height and largest width.
980 * Layout the widgets based on having the
981 * number of columns specified by (cols)
987 gui_internal_widget_pack(this, wc);
997 rows=(count+cols-1)/cols;
1000 width+=w->spx*(cols-1);
1001 height+=w->spy*(rows-1);
1008 * No orientation was specified.
1009 * width and height are both 0.
1010 * The width & height of this widget
1014 dbg(0,"Warning width and height of a widget are 0");
1017 if (! w->w && ! w->h) {
1018 w->w=w->bl+w->br+width;
1019 w->h=w->bt+w->bb+height;
1025 * At this stage the width and height of this
1026 * widget has been computed.
1027 * We now make a second pass assigning heights,
1028 * widths and coordinates to each child widget.
1031 if (w->flags & gravity_left)
1033 if (w->flags & gravity_xcenter)
1034 x=w->p.x+w->w/2-owidth/2;
1035 if (w->flags & gravity_right)
1036 x=w->p.x+w->w-w->br-owidth;
1037 if (w->flags & gravity_top)
1039 if (w->flags & gravity_ycenter)
1040 y=w->p.y+w->h/2-oheight/2;
1041 if (w->flags & gravity_bottom)
1042 y=w->p.y+w->h-w->bb-oheight;
1044 switch (orientation) {
1045 case orientation_horizontal:
1050 if (wc->flags & flags_fill)
1052 if (wc->flags & flags_expand) {
1055 wc->w=wc->w*expand/100;
1057 if (w->flags & gravity_top)
1059 if (w->flags & gravity_ycenter)
1061 if (w->flags & gravity_bottom)
1067 case orientation_vertical:
1072 if (wc->flags & flags_fill)
1074 if (wc->flags & flags_expand) {
1077 wc->h=wc->h*expand/100;
1079 if (w->flags & gravity_left)
1081 if (w->flags & gravity_xcenter)
1083 if (w->flags & gravity_right)
1089 case orientation_horizontal_vertical:
1099 if (wc->flags & flags_fill) {
1103 if (w->flags & gravity_left)
1105 if (w->flags & gravity_xcenter)
1106 wc->p.x=x+(width-wc->w)/2;
1107 if (w->flags & gravity_right)
1108 wc->p.x=x+width-wc->w;
1109 if (w->flags & gravity_top)
1111 if (w->flags & gravity_ycenter)
1112 wc->p.y=y+(height-wc->h)/2;
1113 if (w->flags & gravity_bottom)
1114 wc->p.y=y-height-wc->h;
1116 if (++count == cols) {
1128 * Call pack again on each child,
1129 * the child has now had its size and coordinates
1130 * set so they can repack their children.
1135 gui_internal_widget_pack(this, wc);
1141 gui_internal_widget_append(struct widget *parent, struct widget *child)
1145 if (! child->background)
1146 child->background=parent->background;
1147 parent->children=g_list_append(parent->children, child);
1150 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1152 if (! child->background)
1153 child->background=parent->background;
1154 parent->children=g_list_prepend(parent->children, child);
1157 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1165 gui_internal_widget_destroy(this, wc);
1168 g_list_free(w->children);
1172 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1174 gui_internal_widget_children_destroy(this, w);
1179 graphics_image_free(this->gra, w->img);
1185 w->data_free(w->data);
1186 if (w->cb && w->remove_cb)
1187 w->remove_cb(w->instance, w->cb);
1196 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1198 if(w->p.x > this->root.w || w->p.y > this->root.h)
1203 gui_internal_box_render(this, w);
1206 gui_internal_label_render(this, w);
1209 gui_internal_image_render(this, w);
1212 gui_internal_table_render(this,w);
1220 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1224 gui_internal_box_pack(this, w);
1227 gui_internal_table_pack(this,w);
1233 //##############################################################################################################
1236 //# Authors: Martin Schaller (04/2008)
1237 //##############################################################################################################
1238 static void gui_internal_call_highlighted(struct gui_priv *this)
1240 if (! this->highlighted || ! this->highlighted->func)
1242 this->highlighted->reason=1;
1243 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1247 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1249 char *text=w->speech;
1257 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1258 navit_say(this->nav, text);
1264 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1268 gui_internal_search_idle_end(this);
1269 while ((l = g_list_last(this->root.children))) {
1271 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1272 gui_internal_say(this, w, 0);
1273 redisplay=w->menu_data->redisplay;
1274 wr=w->menu_data->redisplay_widget;
1275 if (!w->menu_data->redisplay) {
1276 gui_internal_widget_render(this, w);
1279 gui_internal_widget_destroy(this, l->data);
1280 this->root.children=g_list_remove(this->root.children, l->data);
1281 redisplay(this, wr, wr->data);
1284 gui_internal_widget_destroy(this, l->data);
1285 this->root.children=g_list_remove(this->root.children, l->data);
1290 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1293 gui_internal_search_idle_end(this);
1294 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1295 gui_internal_widget_destroy(this, l->data);
1296 this->root.children=g_list_remove(this->root.children, l->data);
1299 gui_internal_say(this, l->data, 0);
1300 gui_internal_widget_render(this, l->data);
1305 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1307 gui_internal_prune_menu_count(this, 1, 1);
1311 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1313 gui_internal_prune_menu(this, wm->data);
1317 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1319 gui_internal_prune_menu(this, this->root.children->data);
1322 static struct widget *
1323 gui_internal_top_bar(struct gui_priv *this)
1325 struct widget *w,*wm,*wh,*wc,*wcn;
1326 int dots_len, sep_len;
1328 int width,width_used=0,use_sep=0,incomplete=0;
1329 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1331 1:Don't expand bar to screen width
1332 2:Don't show Map Icon
1333 4:Don't show Home Icon
1334 8:Show only current menu
1335 16:Don't use menu titles as button
1336 32:Show navit version
1339 256:Use background for menu headline
1340 512:Set osd_configuration and zoom to route when setting position
1343 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1344 w->bl=this->spacing;
1345 w->spx=this->spacing;
1346 w->background=this->background2;
1347 if ((this->flags & 6) == 6) {
1353 width=this->root.w-w->bl;
1354 if (! (this->flags & 2)) {
1355 wm=gui_internal_button_new_with_callback(this, NULL,
1356 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1357 gui_internal_cmd_return, NULL);
1358 wm->speech=g_strdup(_("Back to map"));
1359 gui_internal_widget_pack(this, wm);
1360 gui_internal_widget_append(w, wm);
1363 if (! (this->flags & 4)) {
1364 wh=gui_internal_button_new_with_callback(this, NULL,
1365 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1366 gui_internal_cmd_main_menu, NULL);
1367 wh->speech=g_strdup(_("Main Menu"));
1368 gui_internal_widget_pack(this, wh);
1369 gui_internal_widget_append(w, wh);
1372 if (!(this->flags & 6))
1374 l=g_list_last(this->root.children);
1375 wcn=gui_internal_label_new(this,".. »");
1376 wcn->foreground=foreground;
1378 gui_internal_widget_destroy(this, wcn);
1379 wcn=gui_internal_label_new(this,"»");
1380 wcn->foreground=foreground;
1382 gui_internal_widget_destroy(this, wcn);
1384 if (g_list_previous(l) || !g_list_next(l)) {
1386 wcn=gui_internal_label_new(this, wc->text);
1387 wcn->foreground=foreground;
1392 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1393 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1395 gui_internal_widget_destroy(this, wcn);
1399 struct widget *wct=gui_internal_label_new(this, "»");
1400 wct->foreground=foreground;
1401 res=g_list_prepend(res, wct);
1402 width_used+=sep_len+w->spx;
1405 if (!(this->flags & 16)) {
1406 wcn->func=gui_internal_cmd_return;
1408 wcn->state |= STATE_SENSITIVE;
1410 res=g_list_prepend(res, wcn);
1411 if (this->flags & 8)
1414 l=g_list_previous(l);
1418 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1419 wcn->foreground=foreground;
1420 wcn->func=gui_internal_cmd_return;
1422 wcn->state |= STATE_SENSITIVE;
1423 res=g_list_prepend(res, wcn);
1424 l=g_list_previous(l);
1427 wcn=gui_internal_label_new(this, ".. »");
1428 wcn->foreground=foreground;
1429 wcn->func=gui_internal_cmd_return;
1431 wcn->state |= STATE_SENSITIVE;
1432 res=g_list_prepend(res, wcn);
1436 gui_internal_widget_append(w, l->data);
1439 if (this->flags & 32) {
1440 extern char *version;
1441 char *version_text=g_strdup_printf("Navit %s",version);
1442 wcn=gui_internal_label_new(this, version_text);
1443 g_free(version_text);
1444 wcn->flags=gravity_right_center|flags_expand;
1445 gui_internal_widget_append(w, wcn);
1449 gui_internal_widget_destroy(this, dots);
1454 static struct widget *
1455 gui_internal_time_help(struct gui_priv *this)
1457 struct widget *w,*wc,*wcn;
1462 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1463 w->bl=this->spacing;
1464 w->spx=this->spacing;
1470 if (this->flags & 64) {
1471 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1477 tm=localtime(&timep);
1478 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1479 wcn=gui_internal_label_new(this, timestr);
1480 gui_internal_widget_append(wc, wcn);
1481 gui_internal_widget_append(w, wc);
1483 if (this->flags & 128) {
1484 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1485 gui_internal_widget_append(w, wcn);
1492 * Applys the configuration values to this based on the settings
1493 * specified in the configuration file (this->config) and
1494 * the most approriate default profile based on screen resolution.
1496 * This function should be run after this->root is setup and could
1497 * be rerun after the window is resized.
1499 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1501 static void gui_internal_apply_config(struct gui_priv *this)
1503 struct gui_config_settings * current_config=0;
1505 dbg(0,"w=%d h=%d\n", this->root.w, this->root.h);
1507 * Select default values from profile based on the screen.
1509 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1511 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1513 current_config = &config_profiles[LARGE_PROFILE];
1517 current_config = &config_profiles[MEDIUM_PROFILE];
1522 current_config = &config_profiles[SMALL_PROFILE];
1526 * Apply override values from config file
1528 if(this->config.font_size == -1 )
1530 this->font_size = current_config->font_size;
1534 this->font_size = this->config.font_size;
1537 if(this->config.icon_xs == -1 )
1539 this->icon_xs = current_config->icon_xs;
1543 this->icon_xs = this->config.icon_xs;
1546 if(this->config.icon_s == -1 )
1548 this->icon_s = current_config->icon_s;
1552 this->icon_s = this->config.icon_s;
1554 if(this->config.icon_l == -1 )
1556 this->icon_l = current_config->icon_l;
1560 this->icon_l = this->config.icon_l;
1562 if(this->config.spacing == -1 )
1564 this->spacing = current_config->spacing;
1568 this->spacing = current_config->spacing;
1573 static struct widget *
1574 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1576 struct widget *wl,*wlb;
1577 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1578 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1579 wl=gui_internal_label_new(this, label);
1581 wlb->foreground=this->text_foreground;
1586 gui_internal_widget_append(wlb, wl);
1588 gui_internal_widget_prepend(wb, wlb);
1590 gui_internal_widget_append(wb, wlb);
1596 static struct widget *
1597 gui_internal_menu(struct gui_priv *this, char *label)
1599 struct widget *menu,*w,*w1,*topbox;
1601 gui_internal_search_idle_end(this);
1602 topbox=gui_internal_box_new_with_label(this, 0, label);
1603 topbox->w=this->root.w;
1604 topbox->h=this->root.h;
1605 gui_internal_widget_append(&this->root, topbox);
1606 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1607 menu->w=this->root.w;
1608 menu->h=this->root.h;
1609 menu->background=this->background;
1610 gui_internal_apply_config(this);
1611 this->font=graphics_font_new(this->gra,this->font_size,1);
1612 topbox->menu_data=g_new0(struct menu_data, 1);
1613 gui_internal_widget_append(topbox, menu);
1614 w=gui_internal_top_bar(this);
1615 gui_internal_widget_append(menu, w);
1616 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1617 w->spx=4*this->spacing;
1619 gui_internal_widget_append(menu, w);
1620 if (this->flags & 16) {
1621 struct widget *wlb,*wb,*wm=w;
1622 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1623 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1624 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1625 gui_internal_widget_append(wm, w);
1626 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1632 topbox->menu_data->button_bar=wb;
1633 gui_internal_widget_append(wm, wb);
1634 wlb=gui_internal_button_label(this,_("Back"),1);
1635 wlb->func=gui_internal_back;
1636 wlb->state |= STATE_SENSITIVE;
1638 if (this->flags & 192) {
1639 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1640 menu->w=this->root.w;
1641 menu->h=this->root.h;
1642 w1=gui_internal_time_help(this);
1643 gui_internal_widget_append(menu, w1);
1644 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1645 gui_internal_widget_append(menu, w1);
1646 gui_internal_widget_append(topbox, menu);
1647 menu->background=NULL;
1652 static struct menu_data *
1653 gui_internal_menu_data(struct gui_priv *this)
1656 struct widget *menu;
1658 l=g_list_last(this->root.children);
1660 return menu->menu_data;
1664 gui_internal_menu_render(struct gui_priv *this)
1667 struct widget *menu;
1669 l=g_list_last(this->root.children);
1671 gui_internal_say(this, menu, 0);
1672 gui_internal_widget_pack(this, menu);
1673 gui_internal_widget_render(this, menu);
1677 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1679 struct widget *w=wm->data;
1680 dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
1681 navit_set_destination(this->nav, &w->c, w->name, 1);
1682 if (this->flags & 512) {
1684 follow.type=attr_follow;
1686 navit_set_attr(this->nav, &this->osd_configuration);
1687 navit_set_attr(this->nav, &follow);
1688 navit_zoom_to_route(this->nav, 0);
1690 gui_internal_prune_menu(this, NULL);
1694 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1696 struct widget *w=wm->data;
1697 navit_set_position(this->nav, &w->c);
1698 gui_internal_prune_menu(this, NULL);
1702 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1705 dbg(0,"text='%s'\n", widget->text);
1706 if (widget->text && strlen(widget->text))
1707 navit_add_bookmark(this->nav, &widget->c, widget->text);
1708 g_free(widget->text);
1710 l=g_list_previous(g_list_last(this->root.children));
1711 gui_internal_prune_menu(this, l->data);
1715 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1717 gui_internal_cmd_add_bookmark_do(this, widget->data);
1721 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1726 len=strlen(wm->text);
1727 dbg(1,"len=%d\n", len);
1728 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1729 wm->text[len-1]='\0';
1730 gui_internal_cmd_add_bookmark_do(this, wm);
1736 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1739 gui_internal_cmd_add_bookmark(struct gui_priv *this, struct widget *wm, void *data)
1741 struct widget *w,*wb,*wk,*wl,*we,*wnext,*wp=wm->data;
1742 wb=gui_internal_menu(this,_("Add Bookmark"));
1743 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1744 gui_internal_widget_append(wb, w);
1745 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1746 gui_internal_widget_append(w, we);
1747 gui_internal_widget_append(we, wk=gui_internal_label_new(this, wp->name ? wp->name : wp->text));
1748 wk->state |= STATE_EDIT|STATE_CLEAR;
1749 wk->background=this->background;
1750 wk->flags |= flags_expand|flags_fill;
1751 wk->func = gui_internal_cmd_add_bookmark_changed;
1753 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1754 wnext->state |= STATE_SENSITIVE;
1755 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1757 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1758 gui_internal_widget_append(w, wl);
1760 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1761 gui_internal_menu_render(this);
1766 get_direction(char *buffer, int angle, int mode)
1771 sprintf(buffer,"%d",angle);
1774 if (angle < 69 || angle > 291)
1776 if (angle > 111 && angle < 249)
1778 if (angle > 22 && angle < 158)
1780 if (angle > 202 && angle < 338)
1785 angle=(angle+15)/30;
1788 sprintf(buffer,"%d H", angle);
1796 enum item_type *types;
1798 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1799 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1800 {"hotel","Hotel",(enum item_type []) {
1801 type_poi_hotel,type_poi_camp_rv,
1802 type_poi_camping,type_poi_camping,
1803 type_poi_resort,type_poi_resort,
1804 type_poi_motel,type_poi_hostel,
1806 {"restaurant","Restaurant",(enum item_type []) {
1807 type_poi_bar,type_poi_picnic,
1808 type_poi_burgerking,type_poi_fastfood,
1809 type_poi_restaurant,type_poi_restaurant,
1811 {"shopping","Shopping",(enum item_type []) {
1812 type_poi_mall,type_poi_mall,
1813 type_poi_shop_grocery,type_poi_shop_grocery,
1815 {"hospital","Service",(enum item_type []) {
1816 type_poi_marina,type_poi_marina,
1817 type_poi_hospital,type_poi_hospital,
1818 type_poi_public_utilities,type_poi_public_utilities,
1819 type_poi_police,type_poi_autoservice,
1820 type_poi_information,type_poi_information,
1821 type_poi_personal_service,type_poi_repair_service,
1822 type_poi_restroom,type_poi_restroom,
1824 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1825 {"peak","Land Features",(enum item_type []){
1826 type_poi_land_feature,type_poi_rock,
1827 type_poi_dam,type_poi_dam,
1829 {"unknown","Other",(enum item_type []){
1830 type_point_unspecified,type_point_unkn-1,
1831 type_point_unkn+1,type_poi_land_feature-1,
1832 type_poi_rock+1,type_poi_fuel-1,
1833 type_poi_marina+1,type_poi_car_parking-1,
1834 type_poi_car_parking+1,type_poi_bar-1,
1835 type_poi_bank+1,type_poi_dam-1,
1836 type_poi_dam+1,type_poi_information-1,
1837 type_poi_information+1,type_poi_mall-1,
1838 type_poi_mall+1,type_poi_personal_service-1,
1839 type_poi_restaurant+1,type_poi_restroom-1,
1840 type_poi_restroom+1,type_poi_shop_grocery-1,
1841 type_poi_shop_grocery+1,type_poi_motel-1,
1842 type_poi_hostel+1,type_selected_point,
1844 {"unknown","Unknown",(enum item_type []){
1845 type_point_unkn,type_point_unkn,
1849 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1851 static struct widget *
1852 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1854 struct widget *wl,*wb;
1856 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1857 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1858 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1859 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1860 gui_internal_cmd_pois, &selectors[i]));
1867 static struct widget *
1868 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1874 struct widget *wl,*wt;
1877 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1879 sprintf(distbuf,"%d", dist/1000);
1880 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1881 type=item_to_name(item->type);
1882 if (item_attr_get(item, attr_label, &attr)) {
1883 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1886 wl->name=g_strdup(type);
1888 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
1889 wt=gui_internal_label_new(this, text);
1891 gui_internal_widget_append(wl, wt);
1898 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1900 const struct widget *wa=a;
1901 const struct widget *wb=b;
1902 struct widget *wac=wa->children->data;
1903 struct widget *wbc=wb->children->data;
1911 return wac->datai-wbc->datai;
1916 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1918 enum item_type *types;
1919 if (type >= type_line)
1921 if (! sel || !sel->types)
1924 while (*types != type_none) {
1925 if (type >= types[0] && type <= types[1]) {
1933 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
1936 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
1938 struct map_selection *sel,*selm;
1939 struct coord c,center;
1940 struct mapset_handle *h;
1942 struct map_rect *mr;
1944 int idist,dist=20000;
1945 struct widget *wi,*w,*w2,*wb;
1946 enum projection pro=wm->c.pro;
1947 struct selector *isel=wm->data;
1949 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
1950 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1951 gui_internal_widget_append(wb, w);
1953 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
1954 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1955 gui_internal_widget_append(w, w2);
1957 sel=map_selection_rect_new(&wm->c, dist, 18);
1960 h=mapset_open(navit_get_mapset(this->nav));
1961 while ((m=mapset_next(h, 1))) {
1962 selm=map_selection_dup_pro(sel, pro, map_projection(m));
1963 mr=map_rect_new(m, selm);
1964 dbg(2,"mr=%p\n", mr);
1966 while ((item=map_rect_get_item(mr))) {
1967 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
1968 item_coord_get_pro(item, &c, 1, pro) &&
1969 coord_rect_contains(&sel->u.c_rect, &c) &&
1970 (idist=transform_distance(pro, ¢er, &c)) < dist) {
1971 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
1972 wi->func=gui_internal_cmd_position;
1975 wi->state |= STATE_SENSITIVE;
1981 map_rect_destroy(mr);
1983 map_selection_destroy(selm);
1985 map_selection_destroy(sel);
1987 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
1988 gui_internal_menu_render(this);
1992 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
1994 struct widget *w=wm->data;
1995 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
1997 graphics_clear_selection(this->gra, NULL);
1998 graphics_add_selection(this->gra, &w->item, NULL);
2000 navit_set_center(this->nav, &w->c, 1);
2001 gui_internal_prune_menu(this, NULL);
2006 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2008 struct widget *w,*wb;
2009 struct map_rect *mr;
2015 text=g_strdup_printf("Attribute %s",wm->name);
2016 wb=gui_internal_menu(this, text);
2018 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2019 gui_internal_widget_append(wb, w);
2020 mr=map_rect_new(wm->item.map, NULL);
2021 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2022 for (i = 0 ; i < wm->datai ; i++) {
2023 item_attr_get(item, attr_any, &attr);
2025 if (item_attr_get(item, attr_any, &attr)) {
2027 switch (attr.type) {
2028 case attr_osm_nodeid:
2029 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2031 case attr_osm_wayid:
2032 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2034 case attr_osm_relationid:
2035 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2041 gui_internal_widget_append(w,
2042 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2043 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2044 gui_internal_cmd_view_in_browser, NULL));
2048 map_rect_destroy(mr);
2049 gui_internal_menu_render(this);
2053 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2055 struct widget *w,*wb;
2056 struct map_rect *mr;
2062 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2063 wb=gui_internal_menu(this, "Attributes");
2064 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2065 gui_internal_widget_append(wb, w);
2066 mr=map_rect_new(wm->item.map, NULL);
2067 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2068 dbg(0,"item=%p\n", item);
2070 while(item_attr_get(item, attr_any, &attr)) {
2071 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2072 gui_internal_widget_append(w,
2073 wb=gui_internal_button_new_with_callback(this, text,
2074 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2075 gui_internal_cmd_view_attribute_details, NULL));
2076 wb->name=g_strdup(text);
2082 map_rect_destroy(mr);
2083 gui_internal_menu_render(this);
2087 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2089 struct map_rect *mr;
2095 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2096 mr=map_rect_new(wm->item.map, NULL);
2097 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2098 dbg(0,"item=%p\n", item);
2100 while(item_attr_get(item, attr_url_local, &attr)) {
2102 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2105 map_rect_destroy(mr);
2107 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2113 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2119 /* wm->data: 0 Nothing special
2129 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2131 struct widget *wb,*w,*wc,*wbc;
2135 int display_attributes=(wm->data == (void *)2);
2136 int display_view_on_map=(wm->data != (void *)1);
2137 int display_items=(wm->data == (void *)1);
2138 int display_streets=(wm->data == (void *)3);
2139 int display_house_numbers=(wm->data == (void *)5);
2140 if (wm->data == (void *)4) {
2141 gui_internal_search_town_in_country(this, wm);
2145 switch ((int)wm->data) {
2150 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2151 transform_to_geo(wm->c.pro, &c, &g);
2162 name=wm->name ? wm->name : wm->text;
2163 wb=gui_internal_menu(this, name);
2164 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2165 gui_internal_widget_append(wb, w);
2166 coord=coordinates(&wm->c, ' ');
2167 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2169 if (display_streets) {
2170 gui_internal_widget_append(w,
2171 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2172 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2173 gui_internal_search_street_in_town, wm));
2175 wc->selection_id=wm->selection_id;
2177 if (display_house_numbers) {
2178 gui_internal_widget_append(w,
2179 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2180 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2181 gui_internal_search_house_number_in_street, wm));
2183 wc->selection_id=wm->selection_id;
2185 if (display_attributes) {
2186 struct map_rect *mr;
2189 mr=map_rect_new(wm->item.map, NULL);
2190 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2192 if (item_attr_get(item, attr_description, &attr))
2193 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2194 if (item_attr_get(item, attr_url_local, &attr)) {
2195 gui_internal_widget_append(w,
2196 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2197 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2198 gui_internal_cmd_view_in_browser, NULL));
2201 gui_internal_widget_append(w,
2202 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2203 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2204 gui_internal_cmd_view_attributes, NULL));
2207 map_rect_destroy(mr);
2209 gui_internal_widget_append(w,
2210 gui_internal_button_new_with_callback(this, _("Set as destination"),
2211 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2212 gui_internal_cmd_set_destination, wm));
2213 gui_internal_widget_append(w,
2214 gui_internal_button_new_with_callback(this, _("Set as position"),
2215 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2216 gui_internal_cmd_set_position, wm));
2217 gui_internal_widget_append(w,
2218 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2219 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2220 gui_internal_cmd_add_bookmark, wm));
2222 gui_internal_widget_append(w,
2223 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2224 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2225 gui_internal_cmd_pois, NULL));
2228 gui_internal_widget_append(w,
2229 gui_internal_button_new(this, "Add to tour",
2230 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2231 gui_internal_widget_append(w,
2232 gui_internal_button_new(this, "Add as bookmark",
2233 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2235 if (display_view_on_map) {
2236 gui_internal_widget_append(w,
2237 gui_internal_button_new_with_callback(this, _("View on map"),
2238 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2239 gui_internal_cmd_view_on_map, wm));
2241 if (display_items) {
2244 struct mapset_handle *h;
2245 struct map_rect *mr;
2248 struct street_data *data;
2249 struct map_selection sel;
2250 struct transformation *trans;
2251 enum projection pro;
2255 trans=navit_get_trans(this->nav);
2256 pro=transform_get_projection(trans);
2257 transform_from_geo(pro, &g, &c);
2258 ms=navit_get_mapset(this->nav);
2260 sel.u.c_rect.lu.x=c.x-dist;
2261 sel.u.c_rect.lu.y=c.y+dist;
2262 sel.u.c_rect.rl.x=c.x+dist;
2263 sel.u.c_rect.rl.y=c.y-dist;
2265 sel.range=item_range_all;
2267 while ((m=mapset_next(h,1))) {
2268 mr=map_rect_new(m, &sel);
2271 while ((item=map_rect_get_item(mr))) {
2272 data=street_get_data(item);
2273 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2274 if (item_attr_get(item, attr_label, &attr)) {
2275 label=map_convert_string(m, attr.u.str);
2276 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2277 map_convert_free(label);
2279 text=g_strdup_printf("%s", item_to_name(item->type));
2280 gui_internal_widget_append(w,
2281 wc=gui_internal_button_new_with_callback(this, text,
2282 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2283 gui_internal_cmd_position, (void *)2));
2284 wc->c.x=data->c[0].x;
2285 wc->c.y=data->c[0].y;
2287 wc->name=g_strdup(text);
2291 street_data_free(data);
2293 map_rect_destroy(mr);
2298 gui_internal_menu_render(this);
2302 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2304 struct attr attr,mattr;
2305 struct map_rect *mr=NULL;
2307 char *label_full,*l,*prefix,*pos;
2308 int len,plen,hassub;
2309 struct widget *wb,*w,*wbm;
2314 wb=gui_internal_menu(this, wm->text ? wm->text : _("Bookmarks"));
2315 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2316 w->spy=this->spacing*3;
2317 gui_internal_widget_append(wb, w);
2322 plen=strlen(prefix);
2324 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2325 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2326 while ((item=map_rect_get_item(mr))) {
2327 if (item->type != type_bookmark) continue;
2328 if (!item_attr_get(item, attr_label, &attr)) continue;
2329 label_full=attr.u.str;
2330 if (!strncmp(label_full, prefix, plen)) {
2331 pos=strchr(label_full+plen, '/');
2337 len=strlen(label_full);
2339 l=g_malloc(len-plen+1);
2340 strncpy(l, label_full+plen, len-plen);
2342 if (!g_hash_table_lookup(hash, l)) {
2343 wbm=gui_internal_button_new_with_callback(this, l,
2344 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2345 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2346 if (item_coord_get(item, &c, 1)) {
2349 wbm->c.pro=map_projection(mattr.u.map);
2350 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2351 wbm->text=g_strdup(l);
2352 gui_internal_widget_append(w, wbm);
2353 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2354 wbm->prefix=g_malloc(len+2);
2355 strncpy(wbm->prefix, label_full, len+1);
2356 wbm->prefix[len+1]='\0';
2358 gui_internal_widget_destroy(this, wbm);
2365 g_hash_table_destroy(hash);
2367 gui_internal_menu_render(this);
2370 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2372 struct widget *wi,*menu;
2376 menu=g_list_last(this->root.children)->data;
2377 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2379 if (*key == NAVIT_KEY_BACKSPACE) {
2380 dbg(0,"backspace\n");
2381 if (wi->text && wi->text[0]) {
2382 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2384 text=g_strdup_printf("%s ", wi->text);
2387 if (wi->state & STATE_CLEAR) {
2388 dbg(0,"wi->state=0x%x\n", wi->state);
2391 wi->state &= ~STATE_CLEAR;
2392 dbg(0,"wi->state=0x%x\n", wi->state);
2394 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2398 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2399 gui_internal_widget_render(this, wi);
2404 wi->func(this, wi, wi->data);
2406 gui_internal_widget_render(this, wi);
2412 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2414 struct menu_data *md=gui_internal_menu_data(this);
2415 gui_internal_keypress_do(this, (char *) wm->data);
2416 if (md->keyboard_mode == 2)
2417 gui_internal_keyboard_do(this, md->keyboard, 10);
2418 if (md->keyboard_mode == 26)
2419 gui_internal_keyboard_do(this, md->keyboard, 34);
2423 gui_internal_search_idle_end(struct gui_priv *this)
2426 event_remove_idle(this->idle);
2429 if (this->idle_cb) {
2430 callback_destroy(this->idle_cb);
2436 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2438 char *text=NULL,*name=NULL;
2439 struct search_list_result *res;
2441 struct item *item=NULL;
2443 static char possible_keys[256]="";
2445 res=search_list_get_result(this->sl);
2447 gchar* trunk_name = NULL;
2449 struct widget *menu=g_list_last(this->root.children)->data;
2450 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2452 if (! strcmp(wm_name,"Town"))
2453 trunk_name = g_strrstr(res->town->name, wi->text);
2454 if (! strcmp(wm_name,"Street"))
2455 trunk_name = g_strrstr(name=res->street->name, wi->text);
2458 char next_char = trunk_name[strlen(wi->text)];
2460 int len = strlen(possible_keys);
2461 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2462 if (i==len || !len) {
2463 possible_keys[len]=trunk_name[strlen(wi->text)];
2464 possible_keys[len+1]='\0';
2467 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->name, possible_keys);
2472 gui_internal_search_idle_end(this);
2474 struct menu_data *md=gui_internal_menu_data(this);
2475 if (md && md->keyboard) {
2476 GList *lk=md->keyboard->children;
2477 graphics_draw_mode(this->gra, draw_mode_begin);
2479 struct widget *child=lk->data;
2480 GList *lk2=child->children;
2482 struct widget *child_=lk2->data;
2483 lk2=g_list_next(lk2);
2484 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2485 if (strlen(possible_keys) == 0)
2486 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2487 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2488 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2490 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2492 gui_internal_widget_render(this,child_);
2497 gui_internal_widget_render(this,md->keyboard);
2498 graphics_draw_mode(this->gra, draw_mode_end);
2501 possible_keys[0]='\0';
2505 if (! strcmp(wm_name,"Country")) {
2506 name=res->country->name;
2507 item=&res->country->common.item;
2508 text=g_strdup_printf("%s", res->country->name);
2510 if (! strcmp(wm_name,"Town")) {
2511 name=res->town->name;
2512 item=&res->town->common.item;
2513 if (res->town->name && res->town->district)
2514 text=g_strdup_printf("%s%s%s (%s)", res->town->common.postal_mask ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name, res->town->district);
2516 text=g_strdup_printf("%s%s%s", res->town->common.postal ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name);
2518 if (! strcmp(wm_name,"Street")) {
2519 name=res->street->name;
2520 item=&res->street->common.item;
2521 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
2523 dbg(1,"res->country->flag=%s\n", res->country->flag);
2524 gui_internal_widget_append(search_list,
2525 wc=gui_internal_button_new_with_callback(this, text,
2526 image_new_xs(this, res->country->flag),
2527 gravity_left_center|orientation_horizontal|flags_fill,
2528 gui_internal_cmd_position, param));
2529 wc->name=g_strdup(name);
2532 wc->selection_id=res->id;
2535 gui_internal_widget_pack(this, search_list);
2536 l=g_list_last(this->root.children);
2537 graphics_draw_mode(this->gra, draw_mode_begin);
2538 gui_internal_widget_render(this, l->data);
2539 graphics_draw_mode(this->gra, draw_mode_end);
2544 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2546 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2547 this->idle=event_add_idle(50,this->idle_cb);
2548 callback_call_0(this->idle_cb);
2554 * @param wm The widget that generated the event for the search changed,
2555 * if this was generated by a key on the virtual keyboard then
2556 * wm is the key button widget.
2559 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2562 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2563 gui_internal_widget_children_destroy(this, search_list);
2565 void *param=(void *)3;
2567 if (! strcmp(wm->name,"Country"))
2569 if (! strcmp(wm->name,"Street"))
2571 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2573 gui_internal_search_idle_end(this);
2574 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2575 struct attr search_attr;
2578 if (! strcmp(wm->name,"Country"))
2579 search_attr.type=attr_country_all;
2580 if (! strcmp(wm->name,"Town"))
2581 search_attr.type=attr_town_or_district_name;
2582 if (! strcmp(wm->name,"Street"))
2583 search_attr.type=attr_street_name;
2584 if (! strcmp(wm->name,"House number"))
2585 search_attr.type=attr_house_number;
2586 search_attr.u.str=wm->text;
2587 search_list_search(this->sl, &search_attr, 1);
2588 gui_internal_search_idle_start(this, wm->name, search_list, param);
2590 l=g_list_last(this->root.children);
2591 gui_internal_widget_render(this, l->data);
2594 static struct widget *
2595 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)
2598 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2599 NULL, gravity_center|orientation_vertical, func, data));
2600 wk->data_free=data_free;
2601 wk->background=this->background;
2609 static struct widget *
2610 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2612 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2615 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2617 // Some macros that make the keyboard layout easier to visualise in
2618 // the source code. The macros are #undef'd after this function.
2619 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2620 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h)
2621 static struct widget *
2622 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2624 struct widget *wkbd,*wk;
2625 struct menu_data *md=gui_internal_menu_data(this);
2626 int i, max_w=this->root.w, max_h=this->root.h;
2632 gui_internal_highlight(this);
2634 gui_internal_widget_children_destroy(this, wkbdb);
2636 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2638 md->keyboard_mode=mode;
2639 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2640 wkbd->background=this->background;
2647 if (mode >= 0 && mode < 8) {
2648 for (i = 0 ; i < 26 ; i++) {
2649 char text[]={'A'+i,'\0'};
2652 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2659 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2661 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2664 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2666 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2668 if (mode >= 8 && mode < 16) {
2669 for (i = 0 ; i < 26 ; i++) {
2670 char text[]={'a'+i,'\0'};
2673 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2680 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2682 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2685 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2687 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2689 if (mode >= 16 && mode < 24) {
2690 for (i = 0 ; i < 10 ; i++) {
2691 char text[]={'0'+i,'\0'};
2694 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
2695 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
2697 for (i = 0 ; i < 5 ; i++) SPACER();
2705 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2707 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2710 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2712 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2714 if (mode >= 24 && mode < 32) {
2715 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
2716 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
2717 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
2718 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
2720 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2723 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2725 if (mode >= 32 && mode < 40) {
2726 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
2727 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
2728 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
2729 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
2731 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2734 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2736 gui_internal_widget_append(wkbdb, wkbd);
2738 gui_internal_widget_pack(this, wkbdb);
2739 gui_internal_widget_render(this, wkbdb);
2746 static struct widget *
2747 gui_internal_keyboard(struct gui_priv *this, int mode)
2749 if (! this->keyboard)
2751 return gui_internal_keyboard_do(this, NULL, mode);
2755 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2757 gui_internal_keyboard_do(this, key->data, key->datai);
2761 gui_internal_search_list_set_default_country(struct gui_priv *this)
2763 struct attr search_attr, country_name, country_iso2, *country_attr;
2765 struct country_search *cs;
2766 struct tracking *tracking;
2767 struct search_list_result *res;
2769 country_attr=country_default();
2770 tracking=navit_get_tracking(this->nav);
2771 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
2772 country_attr=&search_attr;
2774 cs=country_search_new(country_attr, 0);
2775 item=country_search_get_item(cs);
2776 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2777 search_attr.type=attr_country_all;
2778 dbg(0,"country %s\n", country_name.u.str);
2779 search_attr.u.str=country_name.u.str;
2780 search_list_search(this->sl, &search_attr, 0);
2781 while((res=search_list_get_result(this->sl)));
2782 g_free(this->country_iso2);
2783 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2784 this->country_iso2=g_strdup(country_iso2.u.str);
2786 country_search_destroy(cs);
2788 dbg(0,"warning: no default country found\n");
2789 if (this->country_iso2) {
2790 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2791 search_attr.type=attr_country_iso2;
2792 search_attr.u.str=this->country_iso2;
2793 search_list_search(this->sl, &search_attr, 0);
2794 while((res=search_list_get_result(this->sl)));
2800 gui_internal_search_list_new(struct gui_priv *this)
2802 struct mapset *ms=navit_get_mapset(this->nav);
2804 this->sl=search_list_new(ms);
2805 gui_internal_search_list_set_default_country(this);
2810 gui_internal_search_list_destroy(struct gui_priv *this)
2813 search_list_destroy(this->sl);
2820 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2822 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2824 gui_internal_search_list_new(this);
2825 wb=gui_internal_menu(this, what);
2826 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2827 gui_internal_widget_append(wb, w);
2828 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2829 gui_internal_widget_append(w, wr);
2830 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2831 gui_internal_widget_append(wr, we);
2833 if (!strcmp(type,"Country")) {
2834 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2835 wnext->func=gui_internal_search_town;
2836 } else if (!strcmp(type,"Town")) {
2837 if (this->country_iso2) {
2838 #if HAVE_API_ANDROID
2839 char country_iso2[strlen(this->country_iso2)+1];
2840 strtolower(country_iso2, this->country_iso2);
2841 country=g_strdup_printf("country_%s", country_iso2);
2843 country=g_strdup_printf("country_%s", this->country_iso2);
2846 country=strdup("gui_select_country");
2847 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
2848 wb->state |= STATE_SENSITIVE;
2850 wb->func = gui_internal_search_country;
2852 wb->func = gui_internal_back;
2853 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
2854 wnext->func=gui_internal_search_street;
2856 } else if (!strcmp(type,"Street")) {
2857 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
2858 wb->state |= STATE_SENSITIVE;
2859 wb->func = gui_internal_back;
2860 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
2861 wnext->func=gui_internal_search_house_number;
2862 } else if (!strcmp(type,"House number")) {
2863 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
2864 wb->state |= STATE_SENSITIVE;
2865 wb->func = gui_internal_back;
2867 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2869 gui_internal_widget_append(we, wnext);
2870 wnext->state |= STATE_SENSITIVE;
2872 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2873 gui_internal_widget_append(wr, wl);
2874 gui_internal_menu_data(this)->search_list=wl;
2875 wk->state |= STATE_EDIT;
2876 wk->background=this->background;
2877 wk->flags |= flags_expand|flags_fill;
2878 wk->func = gui_internal_search_changed;
2879 wk->name=g_strdup(type);
2881 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2882 gui_internal_menu_render(this);
2886 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
2888 search_list_select(this->sl, attr_street_name, 0, 0);
2889 gui_internal_search(this,_("House number"),"House number",0);
2893 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
2895 dbg(0,"id %d\n", widget->selection_id);
2896 search_list_select(this->sl, attr_street_name, 0, 0);
2897 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
2898 gui_internal_search(this,_("House number"),"House number",0);
2902 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
2904 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
2905 gui_internal_search(this,_("Street"),"Street",0);
2909 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
2911 dbg(0,"id %d\n", widget->selection_id);
2912 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
2913 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
2914 gui_internal_search(this,_("Street"),"Street",0);
2918 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
2921 search_list_select(this->sl, attr_country_all, 0, 0);
2922 g_free(this->country_iso2);
2923 this->country_iso2=NULL;
2924 gui_internal_search(this,_("Town"),"Town",0);
2928 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
2930 struct search_list_common *slc;
2931 dbg(0,"id %d\n", widget->selection_id);
2932 search_list_select(this->sl, attr_country_all, 0, 0);
2933 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
2935 g_free(this->country_iso2);
2936 this->country_iso2=((struct search_list_country *)slc)->iso2;
2938 gui_internal_search(this,widget->name,"Town",0);
2942 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
2944 gui_internal_prune_menu_count(this, 1, 0);
2945 gui_internal_search(this,_("Country"),"Country",0);
2949 gui_internal_cmd_town(struct gui_priv *this, struct widget *wm, void *data)
2952 search_list_select(this->sl, attr_country_all, 0, 0);
2953 gui_internal_search(this,_("Town"),"Town",1);
2957 gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm, void *data)
2960 struct widget *w,*wb,*wl;
2961 struct attr_iter *iter;
2964 wb=gui_internal_menu(this, _("Layout"));
2965 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2966 w->spy=this->spacing*3;
2967 gui_internal_widget_append(wb, w);
2968 iter=navit_attr_iter_new();
2969 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
2970 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
2972 gui_internal_widget_append(w, wl);
2974 navit_attr_iter_destroy(iter);
2975 gui_internal_menu_render(this);
2979 gui_internal_cmd_fullscreen(struct gui_priv *this, struct widget *wm, void *data)
2981 graphics_draw_mode(this->gra, draw_mode_end);
2982 if (this->fullscreen != 2)
2983 this->fullscreen=!this->fullscreen;
2984 this->win->fullscreen(this->win, this->fullscreen != 0);
2985 graphics_draw_mode(this->gra, draw_mode_begin);
2989 gui_internal_cmd_2d(struct gui_priv *this, struct widget *wm, void *data)
2991 struct transformation *trans=navit_get_trans(this->nav);
2992 transform_set_pitch(trans, 0);
2994 gui_internal_prune_menu(this, NULL);
2998 gui_internal_cmd_3d(struct gui_priv *this, struct widget *wm, void *data)
3000 struct transformation *trans=navit_get_trans(this->nav);
3001 transform_set_pitch(trans, this->pitch);
3003 gui_internal_prune_menu(this, NULL);
3007 gui_internal_cmd_display(struct gui_priv *this, struct widget *wm, void *data)
3010 struct transformation *trans;
3012 w=gui_internal_menu(this, _("Display"));
3013 gui_internal_widget_append(w,
3014 gui_internal_button_new_with_callback(this, _("Layout"),
3015 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
3016 gui_internal_cmd_layout, NULL));
3018 if(this->fullscreen != 2) {
3019 if (this->fullscreen) {
3020 gui_internal_widget_append(w,
3021 gui_internal_button_new_with_callback(this, _("Window Mode"),
3022 image_new_l(this, "gui_leave_fullscreen"), gravity_center|orientation_vertical,
3023 gui_internal_cmd_fullscreen, NULL));
3025 gui_internal_widget_append(w,
3026 gui_internal_button_new_with_callback(this, _("Fullscreen"),
3027 image_new_l(this, "gui_fullscreen"), gravity_center|orientation_vertical,
3028 gui_internal_cmd_fullscreen, NULL));
3031 trans=navit_get_trans(this->nav);
3032 if (transform_get_pitch(trans)) {
3033 gui_internal_widget_append(w,
3034 gui_internal_button_new_with_callback(this, _("2D"),
3035 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3036 gui_internal_cmd_2d, NULL));
3039 gui_internal_widget_append(w,
3040 gui_internal_button_new_with_callback(this, _("3D"),
3041 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3042 gui_internal_cmd_3d, NULL));
3044 gui_internal_menu_render(this);
3048 gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm, void *data)
3051 navit.type=attr_navit;
3052 navit.u.navit=this->nav;
3053 navit_destroy(navit.u.navit);
3054 config_remove_attr(config, &navit);
3055 event_main_loop_quit();
3059 gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm, void *data)
3061 navit_set_destination(this->nav, NULL, NULL, 0);
3066 gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm, void *data)
3068 struct widget *w,*wc;
3071 w=gui_internal_menu(this, _("Actions"));
3072 gui_internal_widget_append(w,
3073 gui_internal_button_new_with_callback(this, _("Bookmarks"),
3074 image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
3075 gui_internal_cmd_bookmarks, NULL));
3076 if (this->clickp_valid) {
3077 coord=coordinates(&this->clickp, '\n');
3078 gui_internal_widget_append(w,
3079 wc=gui_internal_button_new_with_callback(this, coord,
3080 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3081 gui_internal_cmd_position, (void *)1));
3082 wc->name=g_strdup(_("Map Point"));
3086 if (this->vehicle_valid) {
3087 coord=coordinates(&this->vehiclep, '\n');
3088 gui_internal_widget_append(w,
3089 wc=gui_internal_button_new_with_callback(this, coord,
3090 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3091 gui_internal_cmd_position, NULL));
3092 wc->name=g_strdup(_("Vehicle Position"));
3093 wc->c=this->vehiclep;
3096 gui_internal_widget_append(w,
3097 gui_internal_button_new_with_callback(this, _("Town"),
3098 image_new_l(this, "gui_town"), gravity_center|orientation_vertical,
3099 gui_internal_cmd_town, NULL));
3100 gui_internal_widget_append(w,
3101 gui_internal_button_new_with_callback(this, _("Quit"),
3102 image_new_l(this, "gui_quit"), gravity_center|orientation_vertical,
3103 gui_internal_cmd_quit, NULL));
3105 if (navit_check_route(this->nav)) {
3106 gui_internal_widget_append(w,
3107 gui_internal_button_new_with_callback(this, _("Stop\nNavigation"),
3108 image_new_l(this, "gui_stop"), gravity_center|orientation_vertical,
3109 gui_internal_cmd_abort_navigation, NULL));
3111 gui_internal_menu_render(this);
3115 gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm, void *wdata)
3117 struct attr attr, on, off, description, type, data;
3118 struct widget *w,*wb,*wma;
3120 struct attr_iter *iter;
3123 wb=gui_internal_menu(this, _("Maps"));
3124 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3125 w->spy=this->spacing*3;
3126 gui_internal_widget_append(wb, w);
3127 iter=navit_attr_iter_new();
3128 on.type=off.type=attr_active;
3131 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3132 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3133 label=g_strdup(description.u.str);
3135 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3137 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3139 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3141 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3142 attr.u.map, &on, &off, 1);
3143 gui_internal_widget_append(w, wma);
3146 navit_attr_iter_destroy(iter);
3147 gui_internal_menu_render(this);
3151 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3153 struct attr vehicle = {attr_vehicle,{wm->data}};
3154 navit_set_attr(this->nav, &vehicle);
3158 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3160 struct widget *w,*wb,*row;
3161 struct attr attr,sat_attr;
3162 struct vehicle *v=wm->data;
3165 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3167 wb=gui_internal_menu(this, _("Show Satellite Status"));
3168 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3169 gui_internal_menu_data(this)->redisplay_widget=wm;
3170 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3171 gui_internal_widget_append(wb, w);
3172 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3173 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3174 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3175 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3176 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3177 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3178 gui_internal_widget_append(w,row);
3179 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3180 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3181 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3182 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3183 str=g_strdup_printf("%d", sat_attr.u.num);
3186 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3189 gui_internal_widget_append(w,row);
3191 gui_internal_widget_append(wb, w);
3192 gui_internal_menu_render(this);
3196 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3198 struct widget *w,*wb;
3200 struct vehicle *v=wm->data;
3201 wb=gui_internal_menu(this, _("Show NMEA Data"));
3202 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3203 gui_internal_menu_data(this)->redisplay_widget=wm;
3204 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3205 gui_internal_widget_append(wb, w);
3206 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3207 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3208 gui_internal_menu_render(this);
3212 * A container to hold the selected vehicle and the desired profile in
3215 struct vehicle_and_profilename {
3216 struct vehicle *vehicle;
3221 * Figures out whether the given vehicle is the active vehicle.
3223 * @return true if the vehicle is active, false otherwise.
3226 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3229 struct attr active_vehicle;
3231 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3232 active_vehicle.u.vehicle=NULL;
3234 return active_vehicle.u.vehicle == vehicle;
3238 save_vehicle_xml(struct vehicle *v)
3241 struct attr_iter *iter=vehicle_attr_iter_new();
3245 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3246 if (attr_type_begin(attr.type) == attr_type_object_begin)
3249 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3253 printf("</vehicle>\n");
3256 vehicle_attr_iter_destroy(iter);
3261 * Reacts to a button press that changes a vehicle's active profile.
3263 * @see gui_internal_add_vehicle_profile
3266 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3267 widget *wm, void *data)
3269 struct vehicle_and_profilename *vapn = data;
3270 struct vehicle *v = vapn->vehicle;
3271 char *profilename = vapn->profilename;
3272 struct attr vehicle_name_attr;
3273 char *vehicle_name = NULL;
3275 // Get the vehicle name
3276 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3277 vehicle_name = vehicle_name_attr.u.str;
3279 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3282 // Change the profile name
3283 struct attr profilename_attr = {attr_profilename, {profilename}};
3284 if(!vehicle_set_attr(v, &profilename_attr)) {
3285 dbg(0, "Unable to set the vehicle's profile name\n");
3288 // Notify Navit that the routing should be re-done if this is the
3290 if (gui_internal_is_active_vehicle(this, v)) {
3291 struct attr vehicle;
3292 vehicle.type=attr_vehicle;
3293 vehicle.u.vehicle=v;
3294 navit_set_attr(this->nav, &vehicle);
3296 save_vehicle_xml(v);
3300 * Adds the vehicle profile to the GUI, allowing the user to pick a
3301 * profile for the currently selected vehicle.
3304 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3305 *parent, struct vehicle *v, struct vehicleprofile *profile)
3307 // Just here to show up in the translation file, nice and close to
3308 // where the translations are actually used.
3309 struct attr profile_attr;
3310 struct attr *attr = NULL;
3312 char *active_profile = NULL;
3315 struct vehicle_and_profilename *context = NULL;
3317 #ifdef ONLY_FOR_TRANSLATION
3318 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3321 // Figure out the profile name
3322 attr = attr_search(profile->attrs, NULL, attr_name);
3325 // Determine whether the profile is the active one
3326 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3327 active_profile = profile_attr.u.str;
3328 active = strcmp(name, active_profile) == 0;
3330 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3331 active_profile, active);
3333 // Build a translatable label.
3335 label = g_strdup_printf(_("Current profile: %s"), _(name));
3337 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3340 // Create the context object (the vehicle and the desired profile)
3341 context = g_new0(struct vehicle_and_profilename, 1);
3342 context->vehicle = v;
3343 context->profilename = name;
3346 gui_internal_widget_append(parent,
3347 gui_internal_button_new_with_callback(
3349 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3350 gravity_left_center|orientation_horizontal|flags_fill,
3351 gui_internal_cmd_set_active_profile, context));
3357 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3359 struct widget *w,*wb;
3361 struct vehicle *v=wm->data;
3362 struct vehicleprofile *profile = NULL;
3364 wb=gui_internal_menu(this, wm->text);
3365 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3366 gui_internal_widget_append(wb, w);
3368 // Add the "Set as active" button if this isn't the active
3370 if (!gui_internal_is_active_vehicle(this, v)) {
3371 gui_internal_widget_append(w,
3372 gui_internal_button_new_with_callback(this, _("Set as active"),
3373 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3374 gui_internal_cmd_set_active_vehicle, wm->data));
3377 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3378 gui_internal_widget_append(w,
3379 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3380 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3381 gui_internal_cmd_show_satellite_status, wm->data));
3383 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3384 gui_internal_widget_append(w,
3385 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3386 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3387 gui_internal_cmd_show_nmea_data, wm->data));
3390 // Add all the possible vehicle profiles to the menu
3391 GList *profiles = navit_get_vehicleprofiles(this->nav);
3393 profile = (struct vehicleprofile *)profiles->data;
3394 gui_internal_add_vehicle_profile(this, w, v, profile);
3395 profiles = g_list_next(profiles);
3398 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3399 gui_internal_menu_render(this);
3403 gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3405 struct attr attr,vattr;
3406 struct widget *w,*wb,*wl;
3407 struct attr_iter *iter;
3408 struct attr active_vehicle;
3411 wb=gui_internal_menu(this, _("Vehicle"));
3412 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3413 w->spy=this->spacing*3;
3414 gui_internal_widget_append(wb, w);
3415 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3416 active_vehicle.u.vehicle=NULL;
3417 iter=navit_attr_iter_new();
3418 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3419 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3420 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3421 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3422 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3423 wl->text=g_strdup(vattr.u.str);
3424 gui_internal_widget_append(w, wl);
3426 navit_attr_iter_destroy(iter);
3427 gui_internal_menu_render(this);
3432 gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm, void *data)
3434 struct widget *wb,*w;
3436 wb=gui_internal_menu(this, _("Rules"));
3437 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3438 w->spy=this->spacing*3;
3439 gui_internal_widget_append(wb, w);
3442 on.type=off.type=attr_tracking;
3443 gui_internal_widget_append(w,
3444 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3448 on.type=off.type=attr_orientation;
3449 gui_internal_widget_append(w,
3450 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3454 on.type=off.type=attr_follow_cursor;
3455 gui_internal_widget_append(w,
3456 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3458 gui_internal_menu_render(this);
3462 gui_internal_cmd_settings(struct gui_priv *this, struct widget *wm, void *data)
3466 w=gui_internal_menu(this, _("Settings"));
3467 gui_internal_widget_append(w,
3468 gui_internal_button_new_with_callback(this, _("Display"),
3469 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
3470 gui_internal_cmd_display, NULL));
3471 gui_internal_widget_append(w,
3472 gui_internal_button_new_with_callback(this, _("Maps"),
3473 image_new_l(this, "gui_maps"), gravity_center|orientation_vertical,
3474 gui_internal_cmd_maps, NULL));
3475 gui_internal_widget_append(w,
3476 gui_internal_button_new_with_callback(this, _("Vehicle"),
3477 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3478 gui_internal_cmd_vehicle, NULL));
3479 gui_internal_widget_append(w,
3480 gui_internal_button_new_with_callback(this, _("Rules"),
3481 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
3482 gui_internal_cmd_rules, NULL));
3483 gui_internal_menu_render(this);
3486 //##############################################################################################################
3489 //# Authors: Martin Schaller (04/2008)
3490 //##############################################################################################################
3491 static void gui_internal_motion(void *data, struct point *p)
3494 struct gui_priv *this=data;
3495 if (!this->root.children) {
3496 navit_handle_motion(this->nav, p);
3502 if(!this->motion_timeout_callback)
3503 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3504 if(!this->motion_timeout_event)
3505 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3509 find_attr(const char **names, const char **values, const char *name)
3512 if (!strcasecmp(*names, name))
3514 names+=xml_attr_distance;
3515 values+=xml_attr_distance;
3521 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
3525 if (w->command && navit_get_attr(this->nav, attr_gui, &attr, NULL)) {
3526 command_evaluate(&attr, w->command);
3531 gui_internal_html_start(void *dummy, const char *tag, const char **names, const char **values, void *data, void *error)
3533 struct gui_priv *this=data;
3534 g_free(this->html_tag);
3535 g_free(this->html_command);
3536 this->html_tag=g_strdup(tag);
3537 if (!strcasecmp(tag,"img")) {
3538 const char *src=find_attr(names, values, "src");
3539 this->html_command=g_strdup(find_attr(names, values, "onclick"));
3541 this->html_curr=gui_internal_image_new(this, image_new_l(this, src));
3546 gui_internal_html_end(void *dummy, const char *tag, void *data, void *error)
3548 struct gui_priv *this=data;
3549 if (this->html_command && this->html_curr) {
3550 struct widget *w=this->html_curr;
3551 w->state |= STATE_SENSITIVE;
3552 w->command=this->html_command;
3553 w->func=gui_internal_html_command;
3554 this->html_command=NULL;
3556 if (!strcasecmp(this->html_tag, "img")) {
3557 gui_internal_widget_append(this->html_container, this->html_curr);
3559 this->html_curr=NULL;
3563 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
3565 struct gui_priv *this=data;
3566 if (!strcasecmp(this->html_tag, "h1")) {
3567 if (!this->html_container) {
3568 this->html_container=gui_internal_menu(this, gettext(text));
3569 this->html_container->spx=this->spacing*10;
3572 if (!strcasecmp(this->html_tag, "img")) {
3574 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
3575 gui_internal_widget_append(w, this->html_curr);
3576 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text), gravity_center|orientation_vertical));
3582 gui_internal_html_menu(struct gui_priv *this, char *document)
3584 graphics_draw_mode(this->gra, draw_mode_begin);
3585 this->html_container=NULL;
3586 this->html_curr=NULL;
3587 xml_parse_text(document, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
3588 gui_internal_menu_render(this);
3589 graphics_draw_mode(this->gra, draw_mode_end);
3593 static void gui_internal_menu_root(struct gui_priv *this)
3595 gui_internal_html_menu(this,
3597 "<h1>"_n("Main menu")"</h1>"
3598 "<img src='gui_actions' onclick='actions()'>"_n("Actions")"</img>"
3600 "<img src='gui_map' onclick='show_map()'>"_n("Show</br>Map")"</img>"
3602 "<img src='gui_settings' onclick='settings()'>"_n("Settings")"</img>"
3603 "<img src='gui_tools' onclick='tools()'>"_n("Tools")"</img>"
3604 "<img src='gui_settings' onclick='route()'>"_n("Route")"</img>"
3610 gui_internal_enter(struct gui_priv *this, int ignore)
3612 struct graphics *gra=this->gra;
3613 this->ignore_button=ignore;
3614 this->clickp_valid=this->vehicle_valid=0;
3616 navit_block(this->nav, 1);
3617 graphics_overlay_disable(gra, 1);
3620 this->root.background=this->background;
3624 gui_internal_leave(struct gui_priv *this)
3626 graphics_draw_mode(this->gra, draw_mode_end);
3630 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3632 struct transformation *trans;
3634 struct attr attr,attrp;
3637 gui_internal_enter(this, ignore);
3638 trans=navit_get_trans(this->nav);
3640 transform_reverse(trans, p, &c);
3641 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3642 this->clickp.pro=transform_get_projection(trans);
3645 this->clickp_valid=1;
3647 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3648 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3649 this->vehiclep.pro=transform_get_projection(trans);
3650 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3651 this->vehiclep.x=c.x;
3652 this->vehiclep.y=c.y;
3653 this->vehicle_valid=1;
3656 gui_internal_menu_root(this);
3660 gui_internal_cmd_menu2(struct gui_priv *this)
3662 gui_internal_cmd_menu(this, NULL, 1);
3667 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
3669 if (widget->text && strlen(widget->text))
3670 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
3671 g_free(widget->text);
3673 gui_internal_prune_menu(this, NULL);
3674 gui_internal_check_exit(this);
3678 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
3680 gui_internal_cmd_log_do(this, widget->data);
3684 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
3688 len=strlen(wm->text);
3689 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
3690 wm->text[len-1]='\0';
3691 gui_internal_cmd_log_do(this, wm);
3698 gui_internal_cmd_log(struct gui_priv *this)
3700 struct widget *w,*wb,*wk,*wl,*we,*wnext;
3701 gui_internal_enter(this, 1);
3702 wb=gui_internal_menu(this, "Log Message");
3703 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3704 gui_internal_widget_append(wb, w);
3705 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3706 gui_internal_widget_append(w, we);
3707 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
3708 wk->state |= STATE_EDIT|STATE_CLEAR;
3709 wk->background=this->background;
3710 wk->flags |= flags_expand|flags_fill;
3711 wk->func = gui_internal_cmd_log_changed;
3712 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3713 wnext->state |= STATE_SENSITIVE;
3714 wnext->func = gui_internal_cmd_log_clicked;
3716 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3717 gui_internal_widget_append(w, wl);
3719 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3720 gui_internal_menu_render(this);
3721 gui_internal_leave(this);
3725 gui_internal_check_exit(struct gui_priv *this)
3727 struct graphics *gra=this->gra;
3728 if (! this->root.children) {
3729 gui_internal_search_idle_end(this);
3730 gui_internal_search_list_destroy(this);
3731 graphics_overlay_disable(gra, 0);
3732 if (!navit_block(this->nav, 0)) {
3734 navit_draw(this->nav);
3736 navit_draw_displaylist(this->nav);
3741 //##############################################################################################################
3742 //# Description: Function to handle mouse clicks and scroll wheel movement
3744 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3745 //##############################################################################################################
3746 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3748 struct gui_priv *this=data;
3749 struct graphics *gra=this->gra;
3751 dbg(1,"enter %d %d\n", pressed, button);
3752 // if still on the map (not in the menu, yet):
3753 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
3754 if (!this->root.children || this->ignore_button) {
3755 this->ignore_button=0;
3756 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3757 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
3758 dbg(1,"navit has handled button\n");
3761 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
3762 if (this->menu_on_map_click && button == 1)
3763 gui_internal_cmd_menu(this, p, 0);
3768 // if already in the menu:
3772 gui_internal_highlight(this);
3777 graphics_draw_mode(gra, draw_mode_begin);
3778 gui_internal_call_highlighted(this);
3779 gui_internal_highlight(this);
3780 graphics_draw_mode(gra, draw_mode_end);
3781 gui_internal_check_exit(this);
3786 gui_internal_setup_gc(struct gui_priv *this)
3788 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
3789 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
3790 struct graphics *gra=this->gra;
3792 if (this->background)
3794 this->background=graphics_gc_new(gra);
3795 this->background2=graphics_gc_new(gra);
3796 this->highlight_background=graphics_gc_new(gra);
3797 graphics_gc_set_foreground(this->highlight_background, &cbh);
3798 this->foreground=graphics_gc_new(gra);
3799 graphics_gc_set_foreground(this->foreground, &cf);
3800 this->text_background=graphics_gc_new(gra);
3801 this->text_foreground=graphics_gc_new(gra);
3802 graphics_gc_set_foreground(this->background, &this->background_color);
3803 graphics_gc_set_foreground(this->background2, &this->background2_color);
3804 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
3805 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
3808 //##############################################################################################################
3811 //# Authors: Martin Schaller (04/2008)
3812 //##############################################################################################################
3813 static void gui_internal_resize(void *data, int w, int h)
3815 struct gui_priv *this=data;
3818 gui_internal_setup_gc(this);
3820 if (this->root.w != w || this->root.h != h) {
3825 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
3826 navit_handle_resize(this->nav, w, h);
3827 if (this->root.children && changed) {
3828 gui_internal_prune_menu(this, NULL);
3829 gui_internal_menu_root(this);
3834 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
3849 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
3851 GList *l=wi->children;
3852 if (wi->state & STATE_SENSITIVE) {
3855 gui_internal_keynav_point(wi, -dx, -dy, &wp);
3857 dist1=(wp.x-p->x)*dx;
3860 dist1=(wp.y-p->y)*dy;
3868 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);
3874 if (dist1 < *distance) {
3881 struct widget *child=l->data;
3882 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
3888 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
3890 struct widget *result,*menu=g_list_last(this->root.children)->data;
3893 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3894 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
3900 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
3902 gui_internal_keynav_point(result, dx, dy, &p);
3903 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
3908 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3909 dbg(1,"result=%p\n", result);
3921 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3922 dbg(1,"wraparound result=%p\n", result);
3924 gui_internal_highlight_do(this, result);
3926 gui_internal_say(this, result, 1);
3929 //##############################################################################################################
3932 //# Authors: Martin Schaller (04/2008)
3933 //##############################################################################################################
3934 static void gui_internal_keypress(void *data, char *key)
3936 struct gui_priv *this=data;
3939 if (!this->root.children) {
3940 transform_get_size(navit_get_trans(this->nav), &w, &h);
3945 navit_set_center_screen(this->nav, &p, 1);
3947 case NAVIT_KEY_DOWN:
3950 navit_set_center_screen(this->nav, &p, 1);
3952 case NAVIT_KEY_LEFT:
3955 navit_set_center_screen(this->nav, &p, 1);
3957 case NAVIT_KEY_RIGHT:
3960 navit_set_center_screen(this->nav, &p, 1);
3962 case NAVIT_KEY_ZOOM_IN:
3963 navit_zoom_in(this->nav, 2, NULL);
3965 case NAVIT_KEY_ZOOM_OUT:
3966 navit_zoom_out(this->nav, 2, NULL);
3968 case NAVIT_KEY_RETURN:
3969 case NAVIT_KEY_MENU:
3970 gui_internal_cmd_menu(this, NULL, 0);
3975 graphics_draw_mode(this->gra, draw_mode_begin);
3977 case NAVIT_KEY_LEFT:
3978 gui_internal_keynav_highlight_next(this,-1,0);
3980 case NAVIT_KEY_RIGHT:
3981 gui_internal_keynav_highlight_next(this,1,0);
3984 gui_internal_keynav_highlight_next(this,0,-1);
3986 case NAVIT_KEY_DOWN:
3987 gui_internal_keynav_highlight_next(this,0,1);
3989 case NAVIT_KEY_BACK:
3991 case NAVIT_KEY_RETURN:
3992 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3993 gui_internal_call_highlighted(this);
3995 gui_internal_keypress_do(this, key);
3998 gui_internal_keypress_do(this, key);
4000 graphics_draw_mode(this->gra, draw_mode_end);
4001 gui_internal_check_exit(this);
4005 //##############################################################################################################
4008 //# Authors: Martin Schaller (04/2008)
4009 //##############################################################################################################
4010 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4013 struct transformation *trans=navit_get_trans(this->nav);
4015 win=graphics_get_data(gra, "window");
4018 navit_ignore_graphics_events(this->nav, 1);
4021 navit_ignore_graphics_events(this->nav, 1);
4022 transform_get_size(trans, &this->root.w, &this->root.h);
4023 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4024 graphics_add_callback(gra, this->resize_cb);
4025 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4026 graphics_add_callback(gra, this->button_cb);
4027 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4028 graphics_add_callback(gra, this->motion_cb);
4029 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4030 graphics_add_callback(gra, this->keypress_cb);
4032 // set fullscreen if needed
4033 if (this->fullscreen)
4034 this->win->fullscreen(this->win, this->fullscreen != 0);
4035 /* Was resize callback already issued? */
4036 if (navit_get_ready(this->nav) & 2)
4037 gui_internal_setup_gc(this);
4041 static void gui_internal_disable_suspend(struct gui_priv *this)
4043 if (this->win->disable_suspend)
4044 this->win->disable_suspend(this->win);
4047 //##############################################################################################################
4050 //# Authors: Martin Schaller (04/2008)
4051 //##############################################################################################################
4052 struct gui_methods gui_internal_methods = {
4055 gui_internal_set_graphics,
4059 gui_internal_disable_suspend,
4063 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4065 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4067 *out=attr_generic_add_attr(*out, &private_data);
4071 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4073 callback_list_add(priv->cbl, cb);
4077 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4079 callback_list_remove(priv->cbl, cb);
4083 static struct gui_internal_methods gui_internal_methods_ext = {
4084 gui_internal_add_callback,
4085 gui_internal_remove_callback,
4086 gui_internal_menu_render,
4093 gui_internal_get_flags(struct widget *widget)
4095 return widget->flags;
4099 gui_internal_set_flags(struct widget *widget, enum flags flags)
4101 widget->flags=flags;
4105 gui_internal_get_state(struct widget *widget)
4107 return widget->state;
4111 gui_internal_set_state(struct widget *widget, int state)
4113 widget->state=state;
4117 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4123 gui_internal_set_data(struct widget *widget, void *data)
4129 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4131 widget->background=this->background;
4134 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4135 gui_internal_widget_append,
4136 gui_internal_button_new,
4137 gui_internal_button_new_with_callback,
4138 gui_internal_box_new,
4139 gui_internal_label_new,
4140 gui_internal_image_new,
4141 gui_internal_keyboard,
4143 gui_internal_get_flags,
4144 gui_internal_set_flags,
4145 gui_internal_get_state,
4146 gui_internal_set_state,
4147 gui_internal_set_func,
4148 gui_internal_set_data,
4149 gui_internal_set_default_background,
4152 static struct command_table commands[] = {
4153 {"actions",command_cast(gui_internal_cmd_actions)},
4154 {"fullscreen",command_cast(gui_internal_cmd_fullscreen)},
4155 {"get_data",command_cast(gui_internal_get_data)},
4156 {"log",command_cast(gui_internal_cmd_log)},
4157 {"menu",command_cast(gui_internal_cmd_menu2)},
4158 {"route",command_cast(gui_internal_cmd_route)},
4159 {"settings",command_cast(gui_internal_cmd_settings)},
4160 {"tools",command_cast(gui_internal_cmd_tools)},
4164 //##############################################################################################################
4167 //# Authors: Martin Schaller (04/2008)
4168 //##############################################################################################################
4169 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
4171 struct gui_priv *this;
4173 *meth=gui_internal_methods;
4174 this=g_new0(struct gui_priv, 1);
4176 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
4177 this->menu_on_map_click=attr->u.num;
4179 this->menu_on_map_click=1;
4180 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
4181 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
4184 if( (attr=attr_search(attrs,NULL,attr_font_size)))
4186 this->config.font_size=attr->u.num;
4190 this->config.font_size=-1;
4192 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
4194 this->config.icon_xs=attr->u.num;
4198 this->config.icon_xs=-1;
4200 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
4202 this->config.icon_l=attr->u.num;
4206 this->config.icon_l=-1;
4208 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
4210 this->config.icon_s=attr->u.num;
4214 this->config.icon_s=-1;
4216 if( (attr=attr_search(attrs,NULL,attr_spacing)))
4218 this->config.spacing=attr->u.num;
4222 this->config.spacing=-1;
4224 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
4226 this->speech=attr->u.num;
4228 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
4229 this->keyboard=attr->u.num;
4233 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
4234 this->fullscreen=attr->u.num;
4236 if( (attr=attr_search(attrs,NULL,attr_flags)))
4237 this->flags=attr->u.num;
4238 if( (attr=attr_search(attrs,NULL,attr_background_color)))
4239 this->background_color=*attr->u.color;
4241 this->background_color=(struct color){0x0,0x0,0x0,0xffff};
4242 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
4243 this->background2_color=*attr->u.color;
4245 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
4246 if( (attr=attr_search(attrs,NULL,attr_text_color)))
4247 this->text_foreground_color=*attr->u.color;
4249 this->text_foreground_color=(struct color){0xffff,0xffff,0xffff,0xffff};
4250 if( (attr=attr_search(attrs,NULL,attr_columns)))
4251 this->cols=attr->u.num;
4252 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
4253 this->osd_configuration=*attr;
4255 if( (attr=attr_search(attrs,NULL,attr_pitch)))
4256 this->pitch=attr->u.num;
4259 this->data.priv=this;
4260 this->data.gui=&gui_internal_methods_ext;
4261 this->data.widget=&gui_internal_widget_methods;
4262 this->cbl=callback_list_new();
4267 //##############################################################################################################
4270 //# Authors: Martin Schaller (04/2008)
4271 //##############################################################################################################
4272 void plugin_init(void)
4274 plugin_register_gui_type("internal", gui_internal_new);
4278 * @brief Creates a new table widget.
4280 * Creates and returns a new table widget. This function will
4281 * setup next/previous buttons as children.
4283 * @param this The graphics context.
4284 * @param flags widget sizing flags.
4285 * @returns The newly created widget
4287 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4289 struct widget * widget = g_new0(struct widget,1);
4290 struct table_data * data = NULL;
4291 widget->type=widget_table;
4292 widget->flags=flags;
4293 widget->data = g_new0(struct table_data,1);
4294 widget->data_free=gui_internal_table_data_free;
4295 data = (struct table_data*)widget->data;
4299 data->next_button = gui_internal_button_new_with_callback
4300 (this,"Next",image_new_xs(this, "gui_active") ,
4301 gravity_left_center |orientation_vertical,
4302 gui_internal_table_button_next,NULL);
4303 data->next_button->data=widget;
4306 data->prev_button = gui_internal_button_new_with_callback
4308 image_new_xs(this, "gui_active")
4309 ,gravity_right_center |orientation_vertical,
4310 gui_internal_table_button_prev,NULL);
4312 data->prev_button->data=widget;
4316 data->button_box=gui_internal_box_new(this,
4317 gravity_center|orientation_horizontal);
4318 data->button_box->children=g_list_append(data->button_box->children,
4320 data->button_box->children=g_list_append(data->button_box->children,
4322 //data->button_box->background=this->background2;
4323 data->button_box->bl=this->spacing;
4324 widget->children=g_list_append(widget->children,data->button_box);
4325 gui_internal_widget_pack(this,data->button_box);
4333 * @brief Clears all the rows from the table.
4334 * This function removes all rows from a table.
4335 * New rows can later be added to the table.
4337 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4340 struct table_data * table_data = (struct table_data* ) table->data;
4342 iter = table->children;
4344 if(iter->data != table_data->button_box) {
4345 struct widget * child = (struct widget*)iter->data;
4346 gui_internal_widget_destroy(this,child);
4347 if(table->children == iter) {
4348 table->children = g_list_remove(iter,iter->data);
4349 iter=table->children;
4352 iter = g_list_remove(iter,iter->data);
4355 iter = g_list_next(iter);
4359 table_data->top_row=NULL;
4360 table_data->bottom_row=NULL;
4361 if(table_data->page_headers)
4362 g_list_free(table_data->page_headers);
4363 table_data->page_headers=NULL;
4368 * Creates a new table_row widget.
4369 * @param this The graphics context
4370 * @param flags Sizing flags for the row
4371 * @returns The new table_row widget.
4373 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4375 struct widget * widget = g_new0(struct widget,1);
4376 widget->type=widget_table_row;
4377 widget->flags=flags;
4384 * @brief Computes the column dimensions for the table.
4386 * @param w The table widget to compute dimensions for.
4388 * This function examines all of the rows and columns for the table w
4389 * and returns a list (GList) of table_column_desc elements that
4390 * describe each column of the table.
4392 * The caller is responsible for freeing the returned list.
4394 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4397 GList * column_desc = NULL;
4398 GList * current_desc=NULL;
4399 GList * cur_row = w->children;
4400 struct widget * cur_row_widget=NULL;
4401 GList * cur_column=NULL;
4402 struct widget * cell_w=NULL;
4403 struct table_column_desc * current_cell=NULL;
4404 struct table_data * table_data=NULL;
4411 * Scroll through the the table and
4412 * 1. Compute the maximum width + height of each column across all rows.
4414 table_data = (struct table_data*) w->data;
4415 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4417 cur_row_widget = (struct widget*) cur_row->data;
4418 current_desc = column_desc;
4419 if(cur_row_widget == table_data->button_box)
4424 for(cur_column = cur_row_widget->children; cur_column;
4425 cur_column=g_list_next(cur_column))
4427 cell_w = (struct widget*) cur_column->data;
4428 gui_internal_widget_pack(this,cell_w);
4429 if(current_desc == 0)
4431 current_cell = g_new0(struct table_column_desc,1);
4432 column_desc = g_list_append(column_desc,current_cell);
4433 current_desc = g_list_last(column_desc);
4434 current_cell->height=cell_w->h;
4435 current_cell->width=cell_w->w;
4436 total_width+=cell_w->w;
4441 current_cell = current_desc->data;
4444 if(current_cell->height < height )
4446 current_cell->height = height;
4448 if(current_cell->width < width)
4450 total_width += (width-current_cell->width);
4451 current_cell->width = width;
4456 current_desc = g_list_next(current_desc);
4466 * If the width of all columns is less than the width off
4467 * the table expand each cell proportionally.
4470 if(total_width+(this->spacing*column_count) < w->w ) {
4471 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4472 current_cell = (struct table_column_desc*) current_desc->data;
4473 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4482 * @brief Computes the height and width for the table.
4484 * The height and widht are computed to display all cells in the table
4485 * at the requested height/width.
4487 * @param this The graphics context
4488 * @param w The widget to pack.
4491 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4497 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4499 struct table_column_desc * cell_desc=0;
4500 struct table_data * table_data = (struct table_data*)w->data;
4502 for(current = column_data; current; current=g_list_next(current))
4504 if(table_data->button_box == current->data )
4508 cell_desc = (struct table_column_desc *) current->data;
4509 width = width + cell_desc->width + this->spacing;
4510 if(height < cell_desc->height)
4512 height = cell_desc->height ;
4518 for(current=w->children; current; current=g_list_next(current))
4520 if(current->data!= table_data->button_box)
4525 if (table_data->button_box)
4526 gui_internal_widget_pack(this,table_data->button_box);
4530 if(w->h + w->c.y > this->root.h )
4533 * Do not allow the widget to exceed the screen.
4536 w->h = this->root.h- w->c.y - height;
4541 * Deallocate column descriptions.
4543 current = column_data;
4544 while( (current = g_list_last(current)) )
4546 current = g_list_remove(current,current->data);
4554 * @brief Renders a table widget.
4556 * @param this The graphics context
4557 * @param w The table widget to render.
4559 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4564 GList * column_desc=NULL;
4565 GList * cur_row = NULL;
4566 GList * current_desc=NULL;
4567 struct table_data * table_data = (struct table_data*)w->data;
4569 int is_first_page=1;
4570 struct table_column_desc * dim=NULL;
4572 dbg_assert(table_data);
4573 column_desc = gui_internal_compute_table_dimensions(this,w);
4577 * Skip rows that are on previous pages.
4579 cur_row = w->children;
4580 if(table_data->top_row && table_data->top_row != w->children )
4582 cur_row = table_data->top_row;
4588 * Loop through each row. Drawing each cell with the proper sizes,
4589 * at the proper positions.
4591 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4593 GList * cur_column=NULL;
4594 current_desc = column_desc;
4595 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4597 x =w->p.x+this->spacing;
4598 if(cur_row_widget == table_data->button_box )
4602 dim = (struct table_column_desc*)current_desc->data;
4604 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4607 * No more drawing space left.
4613 for(cur_column = cur_row_widget->children; cur_column;
4614 cur_column=g_list_next(cur_column))
4616 struct widget * cur_widget = (struct widget*) cur_column->data;
4617 dim = (struct table_column_desc*)current_desc->data;
4620 cur_widget->w=dim->width;
4622 cur_widget->h=dim->height;
4624 max_height = dim->height;
4625 /* We pack the widget before rendering to ensure that the x and y
4626 * coordinates get pushed down.
4628 gui_internal_widget_pack(this,cur_widget);
4629 gui_internal_widget_render(this,cur_widget);
4631 if(dim->height > max_height)
4633 max_height = dim->height;
4637 table_data->bottom_row=cur_row;
4638 current_desc = g_list_next(current_desc);
4640 if(table_data->button_box && (is_skipped || !is_first_page) )
4642 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4644 if(table_data->button_box->p.y < y )
4646 table_data->button_box->p.y=y;
4648 table_data->button_box->p.x = w->p.x;
4649 table_data->button_box->w = w->w;
4650 // table_data->button_box->h = w->h - y;
4651 // table_data->next_button->h=table_data->button_box->h;
4652 // table_data->prev_button->h=table_data->button_box->h;
4653 // table_data->next_button->c.y=table_data->button_box->c.y;
4654 // table_data->prev_button->c.y=table_data->button_box->c.y;
4656 gui_internal_widget_pack(this,table_data->button_box);
4657 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4660 table_data->button_box->p.y = w->p.y + w->h -
4661 table_data->button_box->h;
4665 table_data->next_button->state|= STATE_SENSITIVE;
4669 table_data->next_button->state&= ~STATE_SENSITIVE;
4672 if(table_data->top_row != w->children)
4674 table_data->prev_button->state|= STATE_SENSITIVE;
4678 table_data->prev_button->state&= ~STATE_SENSITIVE;
4680 gui_internal_widget_render(this,table_data->button_box);
4686 * Deallocate column descriptions.
4688 current_desc = column_desc;
4689 while( (current_desc = g_list_last(current_desc)) )
4691 current_desc = g_list_remove(current_desc,current_desc->data);
4697 * @brief Displays Route information
4699 * @li The name of the active vehicle
4700 * @param wm The button that was pressed.
4704 gui_internal_cmd_route_description(struct gui_priv * this, struct widget * wm,void *v)
4708 struct widget * menu;
4709 struct widget * row;
4712 if(! this->vehicle_cb)
4715 * Register the callback on vehicle updates.
4717 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4718 attr_position_coord_geo,this);
4719 navit_add_callback(this->nav,this->vehicle_cb);
4722 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4723 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4725 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4728 menu=gui_internal_menu(this,_("Route Description"));
4730 menu->free=gui_internal_route_screen_free;
4731 this->route_data.route_showing=1;
4732 this->route_data.route_table->spx = this->spacing;
4735 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4737 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4738 gui_internal_widget_append(box,this->route_data.route_table);
4740 box->spx = this->spacing;
4741 this->route_data.route_table->w=box->w;
4742 gui_internal_widget_append(menu,box);
4743 gui_internal_populate_route_table(this,this->nav);
4744 gui_internal_menu_render(this);
4749 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4752 int adx=a2->x-a1->x;
4753 int ady=a2->y-a1->y;
4754 int bdx=b2->x-b1->x;
4755 int bdy=b2->y-b1->y;
4756 n = bdy * adx - bdx * ady;
4757 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4758 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4769 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4770 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4771 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4774 res->x = a1->x + a * adx / n;
4775 res->y = a1->y + a * ady / n;
4780 struct heightline *next;
4782 struct coord_rect bbox;
4787 struct diagram_point {
4788 struct diagram_point *next;
4792 static struct heightline *
4793 item_get_heightline(struct item *item)
4795 struct heightline *ret=NULL;
4796 struct street_data *sd;
4800 if (item_attr_get(item, attr_label, &attr)) {
4801 height=atoi(attr.u.str);
4802 sd=street_get_data(item);
4803 if (sd && sd->count > 1) {
4804 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4805 ret->bbox.lu=sd->c[0];
4806 ret->bbox.rl=sd->c[0];
4807 ret->count=sd->count;
4809 for (i = 0 ; i < sd->count ; i++) {
4811 coord_rect_extend(&ret->bbox, sd->c+i);
4814 street_data_free(sd);
4821 * @brief Displays Route Height Profile
4823 * @li The name of the active vehicle
4824 * @param wm The button that was pressed.
4827 static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct widget * wm,void *v)
4831 struct widget * menu, *box;
4833 struct map * map=NULL;
4834 struct map_rect * mr=NULL;
4835 struct route * route;
4836 struct item * item =NULL;
4838 struct mapset_handle *msh;
4839 int x,i,first=1,dist=0;
4840 struct coord c,last,res;
4841 struct coord_rect rbbox,dbbox;
4842 struct map_selection sel;
4843 struct heightline *heightline,*heightlines=NULL;
4844 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4847 sel.range.min=type_height_line_1;
4848 sel.range.max=type_height_line_3;
4851 menu=gui_internal_menu(this,_("Height Profile"));
4852 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4853 gui_internal_widget_append(menu, box);
4854 route = navit_get_route(this->nav);
4856 map = route_get_map(route);
4858 mr = map_rect_new(map,NULL);
4860 while((item = map_rect_get_item(mr))) {
4861 while (item_coord_get(item, &c, 1)) {
4867 coord_rect_extend(&sel.u.c_rect, &c);
4870 map_rect_destroy(mr);
4871 ms=navit_get_mapset(this->nav);
4873 msh=mapset_open(ms);
4874 while ((map=mapset_next(msh, 1))) {
4875 mr=map_rect_new(map, &sel);
4877 while((item = map_rect_get_item(mr))) {
4878 if (item->type >= sel.range.min && item->type <= sel.range.max) {
4879 heightline=item_get_heightline(item);
4881 heightline->next=heightlines;
4882 heightlines=heightline;
4886 map_rect_destroy(mr);
4895 map = route_get_map(route);
4897 mr = map_rect_new(map,NULL);
4898 if(mr && heightlines) {
4899 while((item = map_rect_get_item(mr))) {
4901 while (item_coord_get(item, &c, 1)) {
4905 heightline=heightlines;
4908 coord_rect_extend(&rbbox, &c);
4909 while (heightline) {
4910 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
4911 for (i = 0 ; i < heightline->count - 1; i++) {
4912 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
4913 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
4914 diagram_point=g_new(struct diagram_point, 1);
4915 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
4916 diagram_point->c.y=heightline->height;
4917 diagram_point->next=diagram_points;
4918 diagram_points=diagram_point;
4919 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
4924 heightline=heightline->next;
4926 dist+=transform_distance(projection_mg, &last, &c);
4932 map_rect_destroy(mr);
4936 gui_internal_menu_render(this);
4938 diagram_point=diagram_points;
4939 while (diagram_point) {
4941 dbbox.lu=diagram_point->c;
4942 dbbox.rl=diagram_point->c;
4945 coord_rect_extend(&dbbox, &diagram_point->c);
4946 diagram_point=diagram_point->next;
4948 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
4949 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
4951 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
4953 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
4959 diagram_point=diagram_points;
4960 while (diagram_point) {
4961 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
4963 diagram_point=diagram_point->next;
4967 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
4968 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
4969 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
4970 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
4974 graphics_draw_lines(this->gra, this->foreground, p, 2);
4983 * @brief Displays Route information
4985 * @li The name of the active vehicle
4986 * @param wm The button that was pressed.
4989 void gui_internal_cmd_route(struct gui_priv * this, struct widget * wm,void *v)
4993 graphics_draw_mode(this->gra, draw_mode_begin);
4994 w=gui_internal_menu(this, _("Route"));
4995 w->spx=this->spacing*10;
4996 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Description"),
4997 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4998 gui_internal_cmd_route_description, NULL));
4999 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Height Profile"),
5000 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
5001 gui_internal_cmd_route_height_profile, NULL));
5002 gui_internal_menu_render(this);
5003 graphics_draw_mode(this->gra, draw_mode_end);
5008 gui_internal_cmd_show_locale(struct gui_priv * this, struct widget * wm,void *v)
5010 struct widget *menu,*wb,*w;
5013 graphics_draw_mode(this->gra, draw_mode_begin);
5014 menu=gui_internal_menu(this, _("Show Locale"));
5015 menu->spx=this->spacing*10;
5016 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5017 gui_internal_widget_append(menu, wb);
5018 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5019 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5020 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5022 #ifdef HAVE_API_WIN32_BASE
5024 wchar_t wcountry[32],wlang[32];
5025 char country[32],lang[32];
5027 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5028 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5029 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5030 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5031 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5033 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5034 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5035 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5036 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5037 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5042 gui_internal_menu_render(this);
5043 graphics_draw_mode(this->gra, draw_mode_end);
5048 gui_internal_cmd_tools(struct gui_priv * this, struct widget * wm,void *v)
5052 graphics_draw_mode(this->gra, draw_mode_begin);
5053 w=gui_internal_menu(this, _("Tools"));
5054 w->spx=this->spacing*10;
5055 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Show Locale"),
5056 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
5057 gui_internal_cmd_show_locale, NULL));
5058 gui_internal_menu_render(this);
5059 graphics_draw_mode(this->gra, draw_mode_end);
5063 * @brief handles the 'next page' table event.
5064 * A callback function that is invoked when the 'next page' button is pressed
5065 * to advance the contents of a table widget.
5067 * @param this The graphics context.
5068 * @param wm The button widget that was pressed.
5070 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5072 struct widget * table_widget = (struct widget * ) wm->data;
5073 struct table_data * table_data = NULL;
5079 table_data = (struct table_data*) table_widget->data;
5085 * Before advancing to the next page we need to ensure
5086 * that the current top_row is in the list of previous top_rows
5087 * so previous page can work.
5090 for(iterator=table_data->page_headers; iterator != NULL;
5091 iterator = g_list_next(iterator) )
5093 if(iterator->data == table_data->top_row)
5102 table_data->page_headers=g_list_append(table_data->page_headers,
5103 table_data->top_row);
5106 table_data->top_row = g_list_next(table_data->bottom_row);
5108 wm->state&= ~STATE_HIGHLIGHTED;
5109 gui_internal_menu_render(this);
5115 * @brief handles the 'previous page' table event.
5116 * A callback function that is invoked when the 'previous page' button is pressed
5117 * to go back in the contents of a table widget.
5119 * @param this The graphics context.
5120 * @param wm The button widget that was pressed.
5122 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5124 struct widget * table_widget = (struct widget * ) wm->data;
5125 struct table_data * table_data = NULL;
5126 GList * current_page_top=NULL;
5131 table_data = (struct table_data*) table_widget->data;
5134 current_page_top = table_data->top_row;
5135 for(iterator = table_data->page_headers; iterator != NULL;
5136 iterator = g_list_next(iterator))
5138 if(current_page_top == iterator->data)
5142 table_data->top_row = (GList*) iterator->data;
5146 wm->state&= ~STATE_HIGHLIGHTED;
5147 gui_internal_menu_render(this);
5152 * @brief deallocates a table_data structure.
5155 void gui_internal_table_data_free(void * p)
5160 * @note button_box and its children (next_button,prev_button)
5161 * have their memory managed by the table itself.
5163 struct table_data * table_data = (struct table_data*) p;
5164 g_list_free(table_data->page_headers);
5172 * @brief Called when the route is updated.
5174 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5177 if(this->route_data.route_showing) {
5178 gui_internal_populate_route_table(this,navit);
5179 graphics_draw_mode(this->gra, draw_mode_begin);
5180 gui_internal_menu_render(this);
5181 graphics_draw_mode(this->gra, draw_mode_end);
5189 * @brief Called when the route screen is closed (deallocated).
5191 * The main purpose of this function is to remove the widgets from
5192 * references route_data because those widgets are about to be freed.
5194 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5197 this_->route_data.route_showing=0;
5198 this_->route_data.route_table=NULL;
5205 * @brief Populates the route table with route information
5207 * @param this The gui context
5208 * @param navit The navit object
5210 void gui_internal_populate_route_table(struct gui_priv * this,
5211 struct navit * navit)
5213 struct map * map=NULL;
5214 struct map_rect * mr=NULL;
5215 struct navigation * nav = NULL;
5216 struct item * item =NULL;
5218 struct widget * label = NULL;
5219 struct widget * row = NULL;
5220 nav = navit_get_navigation(navit);
5224 map = navigation_get_map(nav);
5226 mr = map_rect_new(map,NULL);
5228 gui_internal_widget_table_clear(this,this->route_data.route_table);
5229 while((item = map_rect_get_item(mr))) {
5230 if(item_attr_get(item,attr_navigation_long,&attr)) {
5231 label = gui_internal_label_new(this,attr.u.str);
5232 row = gui_internal_widget_table_row_new(this,
5235 | orientation_horizontal);
5236 row->children=g_list_append(row->children,label);
5237 gui_internal_widget_append(this->route_data.route_table,row);