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"
74 struct widget *search_list;
75 struct widget *keyboard;
76 struct widget *button_bar;
78 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
79 struct widget *redisplay_widget;
82 //##############################################################################################################
85 //# Authors: Martin Schaller (04/2008)
86 //##############################################################################################################
88 enum widget_type type;
89 struct graphics_gc *background,*text_background;
90 struct graphics_gc *foreground_frame;
91 struct graphics_gc *foreground;
93 struct graphics_image *img;
95 * A function to be invoked on actions.
96 * @li widget The widget that is receiving the button press.
99 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
104 * @brief A function to deallocate data
106 void (*data_free)(void *data);
109 * @brief a function that will be called as the widget is being destroyed.
110 * This function can act as a destructor for the widget. It allows for
111 * on deallocation actions to be specified on a per widget basis.
112 * This function will call g_free on the widget (if required).
114 void (*free) (struct gui_priv *this_, struct widget * w);
126 int bl,br,bt,bb,spx,spy;
129 * The number of widgets to layout horizontally when doing
130 * a orientation_horizontal_vertical layout
135 int (*set_attr)(void *, struct attr *);
136 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
137 void (*remove_cb)(void *, struct callback *cb);
144 struct menu_data *menu_data;
149 * @brief A structure to store configuration values.
151 * This structure stores configuration values for how gui elements in the internal GUI
154 struct gui_config_settings {
157 * The base size (in fractions of a point) to use for text.
161 * The size (in pixels) that xs style icons should be scaled to.
165 * The size (in pixels) that s style icons (small) should be scaled to
169 * The size (in pixels) that l style icons should be scaled to
173 * The default amount of spacing (in pixels) to place between GUI elements.
180 * Indexes into the config_profiles array.
182 const int LARGE_PROFILE=0;
183 const int MEDIUM_PROFILE=1;
184 const int SMALL_PROFILE=2;
187 * The default config profiles.
189 * [0] => LARGE_PROFILE (screens 640 in one dimension)
190 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
191 * [2] => Small profile (default)
193 static struct gui_config_settings config_profiles[]={
200 struct widget * route_table;
205 //##############################################################################################################
208 //# Authors: Martin Schaller (04/2008)
209 //##############################################################################################################
213 struct graphics *gra;
214 struct graphics_gc *background;
215 struct graphics_gc *background2;
216 struct graphics_gc *highlight_background;
217 struct graphics_gc *foreground;
218 struct graphics_gc *text_foreground;
219 struct graphics_gc *text_background;
220 struct color background_color, background2_color, text_foreground_color, text_background_color;
224 struct graphics_font *font;
225 int icon_xs, icon_s, icon_l;
227 struct widget *widgets;
231 struct widget *highlighted;
232 struct widget *highlighted_menu;
233 int clickp_valid, vehicle_valid;
234 struct pcoord clickp, vehiclep;
235 struct search_list *sl;
237 int menu_on_map_click;
242 * The setting information read from the configuration file.
243 * values of -1 indicate no value was specified in the config file.
245 struct gui_config_settings config;
246 struct event_idle *idle;
247 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*idle_cb, *motion_timeout_callback;
248 struct event_timeout *motion_timeout_event;
249 struct point current;
251 struct callback * vehicle_cb;
253 * Stores information about the route.
255 struct route_data route_data;
257 struct gui_internal_data data;
258 struct callback_list *cbl;
261 struct attr osd_configuration;
267 * @brief A structure to store information about a table.
269 * The table_data widget stores pointers to extra information needed by the
272 * The table_data structure needs to be freed with data_free along with the widget.
278 * A GList pointer into a widget->children list that indicates the row
279 * currently being rendered at the top of the table.
283 * A Glist pointer into a widget->children list that indicates the row
284 * currently being rendered at the bottom of the table.
289 * A list of table_row widgets that mark the
290 * top rows for each page of the table.
291 * This is needed for the 'previous page' function of the table.
293 GList * page_headers;
296 * A container box that is the child of the table widget that contains+groups
297 * the next and previous button.
299 struct widget * button_box;
302 * A button widget to handle 'next page' requests
304 struct widget * next_button;
306 * A button widget to handle 'previous page' requests.
308 struct widget * prev_button;
312 * a pointer to the gui context.
313 * This is needed by the free function to destory the buttons.
315 struct gui_priv * this;
319 * A data structure that holds information about a column that makes up a table.
323 struct table_column_desc
327 * The computed height of a cell in the table.
332 * The computed width of a cell in the table.
338 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
339 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
340 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
341 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
342 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
343 static void gui_internal_apply_config(struct gui_priv *this);
345 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
346 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
347 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
348 static void gui_internal_cmd_tools(struct gui_priv * this, struct widget * w,void *);
349 static void gui_internal_cmd_route(struct gui_priv * this, struct widget * w,void *);
350 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
351 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
352 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
353 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
354 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
355 static void gui_internal_table_data_free(void * d);
356 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
358 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
359 static void gui_internal_populate_route_table(struct gui_priv * this,
360 struct navit * navit);
361 static void gui_internal_search_idle_end(struct gui_priv *this);
362 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
363 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
364 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
365 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
366 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
367 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
368 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
369 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
370 static void gui_internal_check_exit(struct gui_priv *this);
371 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
373 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
374 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
376 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
379 * * Display image scaled to specific size
380 * * searches for scaleable and pre-scaled image
381 * * @param this Our gui context
382 * * @param name image name
383 * * @param w desired width of image
384 * * @param h desired height of image
385 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
387 static struct graphics_image *
388 image_new_scaled(struct gui_priv *this, char *name, int w, int h)
390 struct graphics_image *ret=NULL;
391 char *full_name=NULL;
392 char *full_path=NULL;
395 for (i = 1 ; i < 6 ; i++) {
399 full_name=g_strdup_printf("%s.svg", name);
402 full_name=g_strdup_printf("%s.svgz", name);
405 if (w != -1 && h != -1) {
406 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
410 full_name=g_strdup_printf("%s.png", name);
413 full_name=g_strdup_printf("%s.xpm", name);
416 dbg(1,"trying '%s'\n", full_name);
420 /* needs to be checked in the driver */
421 if (!file_exists(full_name)) {
426 full_path=graphics_icon_path(full_name);
427 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
428 dbg(1,"ret=%p\n", ret);
434 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
439 static struct graphics_image *
440 image_new_o(struct gui_priv *this, char *name)
442 return image_new_scaled(this, name, -1, -1);
446 static struct graphics_image *
447 image_new_xs(struct gui_priv *this, char *name)
449 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
453 static struct graphics_image *
454 image_new_s(struct gui_priv *this, char *name)
456 return image_new_scaled(this, name, this->icon_s, this->icon_s);
459 static struct graphics_image *
460 image_new_l(struct gui_priv *this, char *name)
462 return image_new_scaled(this, name, this->icon_l, this->icon_l);
466 coordinates(struct pcoord *pc, char sep)
468 char latc='N',lngc='E';
469 int lat_deg,lat_min,lat_sec;
470 int lng_deg,lng_min,lng_sec;
475 transform_to_geo(pc->pro, &c, &g);
486 lat_min=fmod(g.lat*60,60);
487 lat_sec=fmod(g.lat*3600,60);
489 lng_min=fmod(g.lng*60,60);
490 lng_sec=fmod(g.lng*3600,60);
491 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);
495 gui_internal_background_render(struct gui_priv *this, struct widget *w)
497 struct point pnt=w->p;
498 if (w->state & STATE_HIGHLIGHTED)
499 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
502 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
505 static struct widget *
506 gui_internal_label_new(struct gui_priv *this, char *text)
512 struct widget *widget=g_new0(struct widget, 1);
513 widget->type=widget_label;
515 widget->text=g_strdup(text);
516 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
520 widget->h=h+this->spacing;
522 widget->w=w+this->spacing;
524 widget->flags=gravity_center;
525 widget->foreground=this->text_foreground;
526 widget->text_background=this->text_background;
531 static struct widget *
532 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
534 struct widget *ret=NULL;
535 char *tmp=g_malloc(strlen(text)+3);
542 ret=gui_internal_label_new(this, tmp);
543 if (ret->w < maxwidth)
545 gui_internal_widget_destroy(this, ret);
553 static struct widget *
554 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
556 struct widget *widget=g_new0(struct widget, 1);
557 widget->type=widget_image;
560 widget->w=image->width;
561 widget->h=image->height;
567 gui_internal_image_render(struct gui_priv *this, struct widget *w)
571 gui_internal_background_render(this, w);
574 pnt.x+=w->w/2-w->img->hot.x;
575 pnt.y+=w->h/2-w->img->hot.y;
576 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
581 gui_internal_label_render(struct gui_priv *this, struct widget *w)
583 struct point pnt=w->p;
584 gui_internal_background_render(this, w);
586 if (w->flags & gravity_right) {
587 pnt.y+=w->h-this->spacing;
588 pnt.x+=w->w-w->textw-this->spacing;
589 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
591 pnt.y+=w->h-this->spacing;
592 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
598 * @brief A text box is a widget that renders a text string containing newlines.
599 * The string will be broken up into label widgets at each newline with a vertical layout.
602 static struct widget *
603 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
605 char *s=g_strdup(text),*s2,*tok;
606 struct widget *ret=gui_internal_box_new(this, flags);
608 while ((tok=strtok(s2,"\n"))) {
609 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
612 gui_internal_widget_pack(this,ret);
617 static struct widget *
618 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)
620 struct widget *ret=NULL;
621 ret=gui_internal_box_new(this, flags);
624 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
626 gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
630 ret->state |= STATE_SENSITIVE;
631 ret->speech=g_strdup(text);
639 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
646 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
647 is_on=curr.u.data == w->on.u.data;
650 if (is_on != w->is_on) {
654 l=g_list_first(w->children);
658 graphics_image_free(this->gra, wi->img);
659 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
661 if (w->is_on && w->off.type == attr_none)
662 w->state &= ~STATE_SENSITIVE;
664 w->state |= STATE_SENSITIVE;
671 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
673 if (gui_internal_button_attr_update(this, w))
674 gui_internal_widget_render(this, w);
677 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
680 w->set_attr(w->instance, &w->off);
682 w->set_attr(w->instance, &w->on);
683 gui_internal_button_attr_update(this, w);
687 static struct widget *
688 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
690 struct graphics_image *image=NULL;
694 image=image_new_xs(this, "gui_inactive");
695 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
700 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
701 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
702 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
703 ret->instance=this->nav;
704 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
705 navit_add_callback(this->nav, ret->cb);
706 gui_internal_button_attr_update(this, ret);
710 static struct widget *
711 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)
713 struct graphics_image *image=NULL;
715 image=image_new_xs(this, "gui_inactive");
718 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
724 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
725 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
726 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
729 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
730 map_add_callback(map, ret->cb);
731 gui_internal_button_attr_update(this, ret);
735 static struct widget *
736 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
738 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
742 //##############################################################################################################
745 //# Authors: Martin Schaller (04/2008)
746 //##############################################################################################################
747 static void gui_internal_clear(struct gui_priv *this)
749 struct graphics *gra=this->gra;
753 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
757 static struct widget *
758 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
760 struct widget *ret,*child;
761 GList *l=wi->children;
768 if ( wi->p.x + wi->w < p->x)
770 if ( wi->p.y + wi->h < p->y)
773 if (wi->state & flags)
777 ret=gui_internal_find_widget(child, p, flags);
788 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
790 if (found == this->highlighted)
793 graphics_draw_mode(this->gra, draw_mode_begin);
794 if (this->highlighted) {
795 this->highlighted->state &= ~STATE_HIGHLIGHTED;
796 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
797 gui_internal_widget_render(this, this->highlighted);
798 this->highlighted=NULL;
799 this->highlighted_menu=NULL;
802 this->highlighted=found;
803 this->highlighted_menu=g_list_last(this->root.children)->data;
804 this->highlighted->state |= STATE_HIGHLIGHTED;
805 gui_internal_widget_render(this, this->highlighted);
806 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
808 graphics_draw_mode(this->gra, draw_mode_end);
810 //##############################################################################################################
813 //# Authors: Martin Schaller (04/2008)
814 //##############################################################################################################
815 static void gui_internal_highlight(struct gui_priv *this)
817 struct widget *menu,*found=NULL;
818 if (this->current.x > -1 && this->current.y > -1) {
819 menu=g_list_last(this->root.children)->data;
820 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
822 gui_internal_highlight_do(this, found);
823 this->motion_timeout_event=NULL;
826 static struct widget *
827 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, char *label)
829 struct widget *widget=g_new0(struct widget, 1);
832 widget->text=g_strdup(label);
833 widget->type=widget_box;
838 static struct widget *
839 gui_internal_box_new(struct gui_priv *this, enum flags flags)
841 return gui_internal_box_new_with_label(this, flags, NULL);
845 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
850 gui_internal_background_render(this, w);
852 if (w->foreground && w->border) {
855 pnt[1].x=pnt[0].x+w->w;
857 pnt[2].x=pnt[0].x+w->w;
858 pnt[2].y=pnt[0].y+w->h;
860 pnt[3].y=pnt[0].y+w->h;
862 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
863 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
864 graphics_gc_set_linewidth(w->foreground, 1);
871 gui_internal_widget_render(this, wc);
878 * @brief Compute the size and location for the widget.
882 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
885 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;
887 int orientation=w->flags & 0xffff0000;
892 if ( this->root.w > this->root.h )
902 * count the number of children
909 if (orientation == orientation_horizontal_vertical && count <= cols)
910 orientation=orientation_horizontal;
911 switch (orientation) {
912 case orientation_horizontal:
914 * For horizontal orientation:
915 * pack each child and find the largest height and
916 * compute the total width. x spacing (spx) is considered
918 * If any children want to be expanded
919 * we keep track of this
924 gui_internal_widget_pack(this, wc);
928 if (wc->flags & flags_expand)
929 expand+=wc->w ? wc->w : 1;
935 if (expand && w->w) {
936 expand=100*(w->w-width+expand)/expand;
941 case orientation_vertical:
943 * For vertical layouts:
944 * We pack each child and compute the largest width and
945 * the total height. y spacing (spy) is considered
947 * If the expand flag is set then teh expansion amount
953 gui_internal_widget_pack(this, wc);
957 if (wc->flags & flags_expand)
958 expand+=wc->h ? wc->h : 1;
964 if (expand && w->h) {
965 expand=100*(w->h-height+expand)/expand;
970 case orientation_horizontal_vertical:
972 * For horizontal_vertical orientation
974 * Compute the largest height and largest width.
975 * Layout the widgets based on having the
976 * number of columns specified by (cols)
982 gui_internal_widget_pack(this, wc);
992 rows=(count+cols-1)/cols;
995 width+=w->spx*(cols-1);
996 height+=w->spy*(rows-1);
1003 * No orientation was specified.
1004 * width and height are both 0.
1005 * The width & height of this widget
1009 dbg(0,"Warning width and height of a widget are 0");
1012 if (! w->w && ! w->h) {
1013 w->w=w->bl+w->br+width;
1014 w->h=w->bt+w->bb+height;
1020 * At this stage the width and height of this
1021 * widget has been computed.
1022 * We now make a second pass assigning heights,
1023 * widths and coordinates to each child widget.
1026 if (w->flags & gravity_left)
1028 if (w->flags & gravity_xcenter)
1029 x=w->p.x+w->w/2-owidth/2;
1030 if (w->flags & gravity_right)
1031 x=w->p.x+w->w-w->br-owidth;
1032 if (w->flags & gravity_top)
1034 if (w->flags & gravity_ycenter)
1035 y=w->p.y+w->h/2-oheight/2;
1036 if (w->flags & gravity_bottom)
1037 y=w->p.y+w->h-w->bb-oheight;
1039 switch (orientation) {
1040 case orientation_horizontal:
1045 if (wc->flags & flags_fill)
1047 if (wc->flags & flags_expand) {
1050 wc->w=wc->w*expand/100;
1052 if (w->flags & gravity_top)
1054 if (w->flags & gravity_ycenter)
1056 if (w->flags & gravity_bottom)
1062 case orientation_vertical:
1067 if (wc->flags & flags_fill)
1069 if (wc->flags & flags_expand) {
1072 wc->h=wc->h*expand/100;
1074 if (w->flags & gravity_left)
1076 if (w->flags & gravity_xcenter)
1078 if (w->flags & gravity_right)
1084 case orientation_horizontal_vertical:
1094 if (wc->flags & flags_fill) {
1098 if (w->flags & gravity_left)
1100 if (w->flags & gravity_xcenter)
1101 wc->p.x=x+(width-wc->w)/2;
1102 if (w->flags & gravity_right)
1103 wc->p.x=x+width-wc->w;
1104 if (w->flags & gravity_top)
1106 if (w->flags & gravity_ycenter)
1107 wc->p.y=y+(height-wc->h)/2;
1108 if (w->flags & gravity_bottom)
1109 wc->p.y=y-height-wc->h;
1111 if (++count == cols) {
1123 * Call pack again on each child,
1124 * the child has now had its size and coordinates
1125 * set so they can repack their children.
1130 gui_internal_widget_pack(this, wc);
1136 gui_internal_widget_append(struct widget *parent, struct widget *child)
1140 if (! child->background)
1141 child->background=parent->background;
1142 parent->children=g_list_append(parent->children, child);
1145 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1147 if (! child->background)
1148 child->background=parent->background;
1149 parent->children=g_list_prepend(parent->children, child);
1152 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1160 gui_internal_widget_destroy(this, wc);
1163 g_list_free(w->children);
1167 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1169 gui_internal_widget_children_destroy(this, w);
1173 graphics_image_free(this->gra, w->img);
1179 w->data_free(w->data);
1180 if (w->cb && w->remove_cb)
1181 w->remove_cb(w->instance, w->cb);
1190 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1192 if(w->p.x > this->root.w || w->p.y > this->root.h)
1197 gui_internal_box_render(this, w);
1200 gui_internal_label_render(this, w);
1203 gui_internal_image_render(this, w);
1206 gui_internal_table_render(this,w);
1214 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1218 gui_internal_box_pack(this, w);
1221 gui_internal_table_pack(this,w);
1227 //##############################################################################################################
1230 //# Authors: Martin Schaller (04/2008)
1231 //##############################################################################################################
1232 static void gui_internal_call_highlighted(struct gui_priv *this)
1234 if (! this->highlighted || ! this->highlighted->func)
1236 this->highlighted->reason=1;
1237 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1241 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1243 char *text=w->speech;
1251 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1252 navit_say(this->nav, text);
1258 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1262 gui_internal_search_idle_end(this);
1263 while ((l = g_list_last(this->root.children))) {
1265 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1266 gui_internal_say(this, w, 0);
1267 redisplay=w->menu_data->redisplay;
1268 wr=w->menu_data->redisplay_widget;
1269 if (!w->menu_data->redisplay) {
1270 gui_internal_widget_render(this, w);
1273 gui_internal_widget_destroy(this, l->data);
1274 this->root.children=g_list_remove(this->root.children, l->data);
1275 redisplay(this, wr, wr->data);
1278 gui_internal_widget_destroy(this, l->data);
1279 this->root.children=g_list_remove(this->root.children, l->data);
1284 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1287 gui_internal_search_idle_end(this);
1288 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1289 gui_internal_widget_destroy(this, l->data);
1290 this->root.children=g_list_remove(this->root.children, l->data);
1293 gui_internal_say(this, l->data, 0);
1294 gui_internal_widget_render(this, l->data);
1299 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1301 gui_internal_prune_menu_count(this, 1, 1);
1305 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1307 gui_internal_prune_menu(this, wm->data);
1311 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1313 gui_internal_prune_menu(this, this->root.children->data);
1316 static struct widget *
1317 gui_internal_top_bar(struct gui_priv *this)
1319 struct widget *w,*wm,*wh,*wc,*wcn;
1320 int dots_len, sep_len;
1322 int width,width_used=0,use_sep=0,incomplete=0;
1323 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1325 1:Don't expand bar to screen width
1326 2:Don't show Map Icon
1327 4:Don't show Home Icon
1328 8:Show only current menu
1329 16:Don't use menu titles as button
1330 32:Show navit version
1333 256:Use background for menu headline
1334 512:Set osd_configuration and zoom to route when setting position
1337 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1338 w->bl=this->spacing;
1339 w->spx=this->spacing;
1340 w->background=this->background2;
1341 if ((this->flags & 6) == 6) {
1347 width=this->root.w-w->bl;
1348 if (! (this->flags & 2)) {
1349 wm=gui_internal_button_new_with_callback(this, NULL,
1350 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1351 gui_internal_cmd_return, NULL);
1352 wm->speech=g_strdup(_("Back to map"));
1353 gui_internal_widget_pack(this, wm);
1354 gui_internal_widget_append(w, wm);
1357 if (! (this->flags & 4)) {
1358 wh=gui_internal_button_new_with_callback(this, NULL,
1359 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1360 gui_internal_cmd_main_menu, NULL);
1361 wh->speech=g_strdup(_("Main Menu"));
1362 gui_internal_widget_pack(this, wh);
1363 gui_internal_widget_append(w, wh);
1366 if (!(this->flags & 6))
1368 l=g_list_last(this->root.children);
1369 wcn=gui_internal_label_new(this,".. »");
1370 wcn->foreground=foreground;
1372 gui_internal_widget_destroy(this, wcn);
1373 wcn=gui_internal_label_new(this,"»");
1374 wcn->foreground=foreground;
1376 gui_internal_widget_destroy(this, wcn);
1378 if (g_list_previous(l) || !g_list_next(l)) {
1380 wcn=gui_internal_label_new(this, wc->text);
1381 wcn->foreground=foreground;
1386 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1387 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1389 gui_internal_widget_destroy(this, wcn);
1393 struct widget *wct=gui_internal_label_new(this, "»");
1394 wct->foreground=foreground;
1395 res=g_list_prepend(res, wct);
1396 width_used+=sep_len+w->spx;
1399 if (!(this->flags & 16)) {
1400 wcn->func=gui_internal_cmd_return;
1402 wcn->state |= STATE_SENSITIVE;
1404 res=g_list_prepend(res, wcn);
1405 if (this->flags & 8)
1408 l=g_list_previous(l);
1412 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1413 wcn->foreground=foreground;
1414 wcn->func=gui_internal_cmd_return;
1416 wcn->state |= STATE_SENSITIVE;
1417 res=g_list_prepend(res, wcn);
1418 l=g_list_previous(l);
1421 wcn=gui_internal_label_new(this, ".. »");
1422 wcn->foreground=foreground;
1423 wcn->func=gui_internal_cmd_return;
1425 wcn->state |= STATE_SENSITIVE;
1426 res=g_list_prepend(res, wcn);
1430 gui_internal_widget_append(w, l->data);
1433 if (this->flags & 32) {
1434 extern char *version;
1435 char *version_text=g_strdup_printf("Navit %s",version);
1436 wcn=gui_internal_label_new(this, version_text);
1437 g_free(version_text);
1438 wcn->flags=gravity_right_center|flags_expand;
1439 gui_internal_widget_append(w, wcn);
1443 gui_internal_widget_destroy(this, dots);
1448 static struct widget *
1449 gui_internal_time_help(struct gui_priv *this)
1451 struct widget *w,*wc,*wcn;
1456 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1457 w->bl=this->spacing;
1458 w->spx=this->spacing;
1464 if (this->flags & 64) {
1465 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1471 tm=localtime(&timep);
1472 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1473 wcn=gui_internal_label_new(this, timestr);
1474 gui_internal_widget_append(wc, wcn);
1475 gui_internal_widget_append(w, wc);
1477 if (this->flags & 128) {
1478 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1479 gui_internal_widget_append(w, wcn);
1486 * Applys the configuration values to this based on the settings
1487 * specified in the configuration file (this->config) and
1488 * the most approriate default profile based on screen resolution.
1490 * This function should be run after this->root is setup and could
1491 * be rerun after the window is resized.
1493 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1495 static void gui_internal_apply_config(struct gui_priv *this)
1497 struct gui_config_settings * current_config=0;
1499 dbg(0,"w=%d h=%d\n", this->root.w, this->root.h);
1501 * Select default values from profile based on the screen.
1503 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1505 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1507 current_config = &config_profiles[LARGE_PROFILE];
1511 current_config = &config_profiles[MEDIUM_PROFILE];
1516 current_config = &config_profiles[SMALL_PROFILE];
1520 * Apply override values from config file
1522 if(this->config.font_size == -1 )
1524 this->font_size = current_config->font_size;
1528 this->font_size = this->config.font_size;
1531 if(this->config.icon_xs == -1 )
1533 this->icon_xs = current_config->icon_xs;
1537 this->icon_xs = this->config.icon_xs;
1540 if(this->config.icon_s == -1 )
1542 this->icon_s = current_config->icon_s;
1546 this->icon_s = this->config.icon_s;
1548 if(this->config.icon_l == -1 )
1550 this->icon_l = current_config->icon_l;
1554 this->icon_l = this->config.icon_l;
1556 if(this->config.spacing == -1 )
1558 this->spacing = current_config->spacing;
1562 this->spacing = current_config->spacing;
1567 static struct widget *
1568 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1570 struct widget *wl,*wlb;
1571 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1572 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1573 wl=gui_internal_label_new(this, label);
1575 wlb->foreground=this->text_foreground;
1580 gui_internal_widget_append(wlb, wl);
1582 gui_internal_widget_prepend(wb, wlb);
1584 gui_internal_widget_append(wb, wlb);
1590 static struct widget *
1591 gui_internal_menu(struct gui_priv *this, char *label)
1593 struct widget *menu,*w,*w1,*topbox;
1595 gui_internal_search_idle_end(this);
1596 topbox=gui_internal_box_new_with_label(this, 0, label);
1597 topbox->w=this->root.w;
1598 topbox->h=this->root.h;
1599 gui_internal_widget_append(&this->root, topbox);
1600 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1601 menu->w=this->root.w;
1602 menu->h=this->root.h;
1603 menu->background=this->background;
1604 gui_internal_apply_config(this);
1605 this->font=graphics_font_new(this->gra,this->font_size,1);
1606 topbox->menu_data=g_new0(struct menu_data, 1);
1607 gui_internal_widget_append(topbox, menu);
1608 w=gui_internal_top_bar(this);
1609 gui_internal_widget_append(menu, w);
1610 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1611 w->spx=4*this->spacing;
1613 gui_internal_widget_append(menu, w);
1614 if (this->flags & 16) {
1615 struct widget *wlb,*wb,*wm=w;
1616 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1617 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1618 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1619 gui_internal_widget_append(wm, w);
1620 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1626 topbox->menu_data->button_bar=wb;
1627 gui_internal_widget_append(wm, wb);
1628 wlb=gui_internal_button_label(this,_("Back"),1);
1629 wlb->func=gui_internal_back;
1630 wlb->state |= STATE_SENSITIVE;
1632 if (this->flags & 192) {
1633 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1634 menu->w=this->root.w;
1635 menu->h=this->root.h;
1636 w1=gui_internal_time_help(this);
1637 gui_internal_widget_append(menu, w1);
1638 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1639 gui_internal_widget_append(menu, w1);
1640 gui_internal_widget_append(topbox, menu);
1641 menu->background=NULL;
1646 static struct menu_data *
1647 gui_internal_menu_data(struct gui_priv *this)
1650 struct widget *menu;
1652 l=g_list_last(this->root.children);
1654 return menu->menu_data;
1658 gui_internal_menu_render(struct gui_priv *this)
1661 struct widget *menu;
1663 l=g_list_last(this->root.children);
1665 gui_internal_say(this, menu, 0);
1666 gui_internal_widget_pack(this, menu);
1667 gui_internal_widget_render(this, menu);
1671 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1673 struct widget *w=wm->data;
1674 dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
1675 navit_set_destination(this->nav, &w->c, w->name, 1);
1676 if (this->flags & 512) {
1678 follow.type=attr_follow;
1680 navit_set_attr(this->nav, &this->osd_configuration);
1681 navit_set_attr(this->nav, &follow);
1682 navit_zoom_to_route(this->nav, 0);
1684 gui_internal_prune_menu(this, NULL);
1688 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1690 struct widget *w=wm->data;
1691 navit_set_position(this->nav, &w->c);
1692 gui_internal_prune_menu(this, NULL);
1696 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1699 dbg(0,"text='%s'\n", widget->text);
1700 if (widget->text && strlen(widget->text))
1701 navit_add_bookmark(this->nav, &widget->c, widget->text);
1702 g_free(widget->text);
1704 l=g_list_previous(g_list_last(this->root.children));
1705 gui_internal_prune_menu(this, l->data);
1709 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1711 gui_internal_cmd_add_bookmark_do(this, widget->data);
1715 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1720 len=strlen(wm->text);
1721 dbg(1,"len=%d\n", len);
1722 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1723 wm->text[len-1]='\0';
1724 gui_internal_cmd_add_bookmark_do(this, wm);
1730 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1733 gui_internal_cmd_add_bookmark(struct gui_priv *this, struct widget *wm, void *data)
1735 struct widget *w,*wb,*wk,*wl,*we,*wnext,*wp=wm->data;
1736 wb=gui_internal_menu(this,_("Add Bookmark"));
1737 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1738 gui_internal_widget_append(wb, w);
1739 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1740 gui_internal_widget_append(w, we);
1741 gui_internal_widget_append(we, wk=gui_internal_label_new(this, wp->name ? wp->name : wp->text));
1742 wk->state |= STATE_EDIT|STATE_CLEAR;
1743 wk->background=this->background;
1744 wk->flags |= flags_expand|flags_fill;
1745 wk->func = gui_internal_cmd_add_bookmark_changed;
1747 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1748 wnext->state |= STATE_SENSITIVE;
1749 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1751 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1752 gui_internal_widget_append(w, wl);
1754 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1755 gui_internal_menu_render(this);
1760 get_direction(char *buffer, int angle, int mode)
1765 sprintf(buffer,"%d",angle);
1768 if (angle < 69 || angle > 291)
1770 if (angle > 111 && angle < 249)
1772 if (angle > 22 && angle < 158)
1774 if (angle > 202 && angle < 338)
1779 angle=(angle+15)/30;
1782 sprintf(buffer,"%d H", angle);
1790 enum item_type *types;
1792 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1793 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1794 {"hotel","Hotel",(enum item_type []) {
1795 type_poi_hotel,type_poi_camp_rv,
1796 type_poi_camping,type_poi_camping,
1797 type_poi_resort,type_poi_resort,
1798 type_poi_motel,type_poi_hostel,
1800 {"restaurant","Restaurant",(enum item_type []) {
1801 type_poi_bar,type_poi_picnic,
1802 type_poi_burgerking,type_poi_fastfood,
1803 type_poi_restaurant,type_poi_restaurant,
1805 {"shopping","Shopping",(enum item_type []) {
1806 type_poi_mall,type_poi_mall,
1807 type_poi_shop_grocery,type_poi_shop_grocery,
1809 {"hospital","Service",(enum item_type []) {
1810 type_poi_marina,type_poi_marina,
1811 type_poi_hospital,type_poi_hospital,
1812 type_poi_public_utilities,type_poi_public_utilities,
1813 type_poi_police,type_poi_autoservice,
1814 type_poi_information,type_poi_information,
1815 type_poi_personal_service,type_poi_repair_service,
1816 type_poi_restroom,type_poi_restroom,
1818 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1819 {"peak","Land Features",(enum item_type []){
1820 type_poi_land_feature,type_poi_rock,
1821 type_poi_dam,type_poi_dam,
1823 {"unknown","Other",(enum item_type []){
1824 type_point_unspecified,type_point_unkn-1,
1825 type_point_unkn+1,type_poi_land_feature-1,
1826 type_poi_rock+1,type_poi_fuel-1,
1827 type_poi_marina+1,type_poi_car_parking-1,
1828 type_poi_car_parking+1,type_poi_bar-1,
1829 type_poi_bank+1,type_poi_dam-1,
1830 type_poi_dam+1,type_poi_information-1,
1831 type_poi_information+1,type_poi_mall-1,
1832 type_poi_mall+1,type_poi_personal_service-1,
1833 type_poi_restaurant+1,type_poi_restroom-1,
1834 type_poi_restroom+1,type_poi_shop_grocery-1,
1835 type_poi_shop_grocery+1,type_poi_motel-1,
1836 type_poi_hostel+1,type_selected_point,
1838 {"unknown","Unknown",(enum item_type []){
1839 type_point_unkn,type_point_unkn,
1843 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1845 static struct widget *
1846 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1848 struct widget *wl,*wb;
1850 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1851 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1852 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1853 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1854 gui_internal_cmd_pois, &selectors[i]));
1861 static struct widget *
1862 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1868 struct widget *wl,*wt;
1871 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1873 sprintf(distbuf,"%d", dist/1000);
1874 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1875 type=item_to_name(item->type);
1876 if (item_attr_get(item, attr_label, &attr)) {
1877 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1880 wl->name=g_strdup(type);
1882 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
1883 wt=gui_internal_label_new(this, text);
1885 gui_internal_widget_append(wl, wt);
1892 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1894 const struct widget *wa=a;
1895 const struct widget *wb=b;
1896 struct widget *wac=wa->children->data;
1897 struct widget *wbc=wb->children->data;
1905 return wac->datai-wbc->datai;
1910 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1912 enum item_type *types;
1913 if (type >= type_line)
1915 if (! sel || !sel->types)
1918 while (*types != type_none) {
1919 if (type >= types[0] && type <= types[1]) {
1927 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
1930 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
1932 struct map_selection *sel,*selm;
1933 struct coord c,center;
1934 struct mapset_handle *h;
1936 struct map_rect *mr;
1938 int idist,dist=20000;
1939 struct widget *wi,*w,*w2,*wb;
1940 enum projection pro=wm->c.pro;
1941 struct selector *isel=wm->data;
1943 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
1944 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1945 gui_internal_widget_append(wb, w);
1947 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
1948 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1949 gui_internal_widget_append(w, w2);
1951 sel=map_selection_rect_new(&wm->c, dist, 18);
1954 h=mapset_open(navit_get_mapset(this->nav));
1955 while ((m=mapset_next(h, 1))) {
1956 selm=map_selection_dup_pro(sel, pro, map_projection(m));
1957 mr=map_rect_new(m, selm);
1958 dbg(2,"mr=%p\n", mr);
1960 while ((item=map_rect_get_item(mr))) {
1961 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
1962 item_coord_get_pro(item, &c, 1, pro) &&
1963 coord_rect_contains(&sel->u.c_rect, &c) &&
1964 (idist=transform_distance(pro, ¢er, &c)) < dist) {
1965 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
1966 wi->func=gui_internal_cmd_position;
1969 wi->state |= STATE_SENSITIVE;
1975 map_rect_destroy(mr);
1977 map_selection_destroy(selm);
1979 map_selection_destroy(sel);
1981 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
1982 gui_internal_menu_render(this);
1986 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
1988 struct widget *w=wm->data;
1989 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
1991 graphics_clear_selection(this->gra, NULL);
1992 graphics_add_selection(this->gra, &w->item, NULL);
1994 navit_set_center(this->nav, &w->c, 1);
1995 gui_internal_prune_menu(this, NULL);
2000 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2002 struct widget *w,*wb;
2003 struct map_rect *mr;
2009 text=g_strdup_printf("Attribute %s",wm->name);
2010 wb=gui_internal_menu(this, text);
2012 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2013 gui_internal_widget_append(wb, w);
2014 mr=map_rect_new(wm->item.map, NULL);
2015 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2016 for (i = 0 ; i < wm->datai ; i++) {
2017 item_attr_get(item, attr_any, &attr);
2019 if (item_attr_get(item, attr_any, &attr)) {
2021 switch (attr.type) {
2022 case attr_osm_nodeid:
2023 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2025 case attr_osm_wayid:
2026 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2028 case attr_osm_relationid:
2029 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2035 gui_internal_widget_append(w,
2036 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2037 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2038 gui_internal_cmd_view_in_browser, NULL));
2042 map_rect_destroy(mr);
2043 gui_internal_menu_render(this);
2047 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2049 struct widget *w,*wb;
2050 struct map_rect *mr;
2056 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2057 wb=gui_internal_menu(this, "Attributes");
2058 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2059 gui_internal_widget_append(wb, w);
2060 mr=map_rect_new(wm->item.map, NULL);
2061 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2062 dbg(0,"item=%p\n", item);
2064 while(item_attr_get(item, attr_any, &attr)) {
2065 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2066 gui_internal_widget_append(w,
2067 wb=gui_internal_button_new_with_callback(this, text,
2068 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2069 gui_internal_cmd_view_attribute_details, NULL));
2070 wb->name=g_strdup(text);
2076 map_rect_destroy(mr);
2077 gui_internal_menu_render(this);
2081 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2083 struct map_rect *mr;
2089 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2090 mr=map_rect_new(wm->item.map, NULL);
2091 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2092 dbg(0,"item=%p\n", item);
2094 while(item_attr_get(item, attr_url_local, &attr)) {
2096 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2099 map_rect_destroy(mr);
2101 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2107 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2113 /* wm->data: 0 Nothing special
2123 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2125 struct widget *wb,*w,*wc,*wbc;
2129 int display_attributes=(wm->data == (void *)2);
2130 int display_view_on_map=(wm->data != (void *)1);
2131 int display_items=(wm->data == (void *)1);
2132 int display_streets=(wm->data == (void *)3);
2133 int display_house_numbers=(wm->data == (void *)5);
2134 if (wm->data == (void *)4) {
2135 gui_internal_search_town_in_country(this, wm);
2139 switch ((int)wm->data) {
2144 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2145 transform_to_geo(wm->c.pro, &c, &g);
2156 name=wm->name ? wm->name : wm->text;
2157 wb=gui_internal_menu(this, name);
2158 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2159 gui_internal_widget_append(wb, w);
2160 coord=coordinates(&wm->c, ' ');
2161 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2163 if (display_streets) {
2164 gui_internal_widget_append(w,
2165 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2166 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2167 gui_internal_search_street_in_town, wm));
2169 wc->selection_id=wm->selection_id;
2171 if (display_house_numbers) {
2172 gui_internal_widget_append(w,
2173 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2174 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2175 gui_internal_search_house_number_in_street, wm));
2177 wc->selection_id=wm->selection_id;
2179 if (display_attributes) {
2180 struct map_rect *mr;
2183 mr=map_rect_new(wm->item.map, NULL);
2184 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2186 if (item_attr_get(item, attr_description, &attr))
2187 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2188 if (item_attr_get(item, attr_url_local, &attr)) {
2189 gui_internal_widget_append(w,
2190 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2191 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2192 gui_internal_cmd_view_in_browser, NULL));
2195 gui_internal_widget_append(w,
2196 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2197 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2198 gui_internal_cmd_view_attributes, NULL));
2201 map_rect_destroy(mr);
2203 gui_internal_widget_append(w,
2204 gui_internal_button_new_with_callback(this, _("Set as destination"),
2205 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2206 gui_internal_cmd_set_destination, wm));
2207 gui_internal_widget_append(w,
2208 gui_internal_button_new_with_callback(this, _("Set as position"),
2209 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2210 gui_internal_cmd_set_position, wm));
2211 gui_internal_widget_append(w,
2212 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2213 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2214 gui_internal_cmd_add_bookmark, wm));
2216 gui_internal_widget_append(w,
2217 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2218 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2219 gui_internal_cmd_pois, NULL));
2222 gui_internal_widget_append(w,
2223 gui_internal_button_new(this, "Add to tour",
2224 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2225 gui_internal_widget_append(w,
2226 gui_internal_button_new(this, "Add as bookmark",
2227 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2229 if (display_view_on_map) {
2230 gui_internal_widget_append(w,
2231 gui_internal_button_new_with_callback(this, _("View on map"),
2232 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2233 gui_internal_cmd_view_on_map, wm));
2235 if (display_items) {
2238 struct mapset_handle *h;
2239 struct map_rect *mr;
2242 struct street_data *data;
2243 struct map_selection sel;
2244 struct transformation *trans;
2245 enum projection pro;
2249 trans=navit_get_trans(this->nav);
2250 pro=transform_get_projection(trans);
2251 transform_from_geo(pro, &g, &c);
2252 ms=navit_get_mapset(this->nav);
2254 sel.u.c_rect.lu.x=c.x-dist;
2255 sel.u.c_rect.lu.y=c.y+dist;
2256 sel.u.c_rect.rl.x=c.x+dist;
2257 sel.u.c_rect.rl.y=c.y-dist;
2259 sel.range=item_range_all;
2261 while ((m=mapset_next(h,1))) {
2262 mr=map_rect_new(m, &sel);
2265 while ((item=map_rect_get_item(mr))) {
2266 data=street_get_data(item);
2267 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2268 if (item_attr_get(item, attr_label, &attr)) {
2269 label=map_convert_string(m, attr.u.str);
2270 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2271 map_convert_free(label);
2273 text=g_strdup_printf("%s", item_to_name(item->type));
2274 gui_internal_widget_append(w,
2275 wc=gui_internal_button_new_with_callback(this, text,
2276 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2277 gui_internal_cmd_position, (void *)2));
2278 wc->c.x=data->c[0].x;
2279 wc->c.y=data->c[0].y;
2281 wc->name=g_strdup(text);
2285 street_data_free(data);
2287 map_rect_destroy(mr);
2292 gui_internal_menu_render(this);
2296 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2298 struct attr attr,mattr;
2299 struct map_rect *mr=NULL;
2301 char *label_full,*l,*prefix,*pos;
2302 int len,plen,hassub;
2303 struct widget *wb,*w,*wbm;
2308 wb=gui_internal_menu(this, wm->text ? wm->text : _("Bookmarks"));
2309 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2310 w->spy=this->spacing*3;
2311 gui_internal_widget_append(wb, w);
2316 plen=strlen(prefix);
2318 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2319 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2320 while ((item=map_rect_get_item(mr))) {
2321 if (item->type != type_bookmark) continue;
2322 if (!item_attr_get(item, attr_label, &attr)) continue;
2323 label_full=attr.u.str;
2324 if (!strncmp(label_full, prefix, plen)) {
2325 pos=strchr(label_full+plen, '/');
2331 len=strlen(label_full);
2333 l=g_malloc(len-plen+1);
2334 strncpy(l, label_full+plen, len-plen);
2336 if (!g_hash_table_lookup(hash, l)) {
2337 wbm=gui_internal_button_new_with_callback(this, l,
2338 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2339 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2340 if (item_coord_get(item, &c, 1)) {
2343 wbm->c.pro=map_projection(mattr.u.map);
2344 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2345 wbm->text=g_strdup(l);
2346 gui_internal_widget_append(w, wbm);
2347 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2348 wbm->prefix=g_malloc(len+2);
2349 strncpy(wbm->prefix, label_full, len+1);
2350 wbm->prefix[len+1]='\0';
2352 gui_internal_widget_destroy(this, wbm);
2359 g_hash_table_destroy(hash);
2361 gui_internal_menu_render(this);
2364 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2366 struct widget *wi,*menu;
2370 menu=g_list_last(this->root.children)->data;
2371 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2373 if (*key == NAVIT_KEY_BACKSPACE) {
2374 dbg(0,"backspace\n");
2375 if (wi->text && wi->text[0]) {
2376 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2378 text=g_strdup_printf("%s ", wi->text);
2381 if (wi->state & STATE_CLEAR) {
2382 dbg(0,"wi->state=0x%x\n", wi->state);
2385 wi->state &= ~STATE_CLEAR;
2386 dbg(0,"wi->state=0x%x\n", wi->state);
2388 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2392 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2393 gui_internal_widget_render(this, wi);
2398 wi->func(this, wi, wi->data);
2400 gui_internal_widget_render(this, wi);
2406 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2408 struct menu_data *md=gui_internal_menu_data(this);
2409 gui_internal_keypress_do(this, (char *) wm->data);
2410 if (md->keyboard_mode == 2)
2411 gui_internal_keyboard_do(this, md->keyboard, 10);
2412 if (md->keyboard_mode == 26)
2413 gui_internal_keyboard_do(this, md->keyboard, 34);
2417 gui_internal_search_idle_end(struct gui_priv *this)
2420 event_remove_idle(this->idle);
2423 if (this->idle_cb) {
2424 callback_destroy(this->idle_cb);
2430 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2432 char *text=NULL,*name=NULL;
2433 struct search_list_result *res;
2435 struct item *item=NULL;
2437 static char possible_keys[256]="";
2439 res=search_list_get_result(this->sl);
2441 gchar* trunk_name = NULL;
2443 struct widget *menu=g_list_last(this->root.children)->data;
2444 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2446 if (! strcmp(wm_name,"Town"))
2447 trunk_name = g_strrstr(res->town->name, wi->text);
2448 if (! strcmp(wm_name,"Street"))
2449 trunk_name = g_strrstr(name=res->street->name, wi->text);
2452 char next_char = trunk_name[strlen(wi->text)];
2454 int len = strlen(possible_keys);
2455 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2456 if (i==len || !len) {
2457 possible_keys[len]=trunk_name[strlen(wi->text)];
2458 possible_keys[len+1]='\0';
2461 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->name, possible_keys);
2466 gui_internal_search_idle_end(this);
2468 struct menu_data *md=gui_internal_menu_data(this);
2469 if (md && md->keyboard) {
2470 GList *lk=md->keyboard->children;
2471 graphics_draw_mode(this->gra, draw_mode_begin);
2473 struct widget *child=lk->data;
2474 GList *lk2=child->children;
2476 struct widget *child_=lk2->data;
2477 lk2=g_list_next(lk2);
2478 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2479 if (strlen(possible_keys) == 0)
2480 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2481 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2482 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2484 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2486 gui_internal_widget_render(this,child_);
2491 gui_internal_widget_render(this,md->keyboard);
2492 graphics_draw_mode(this->gra, draw_mode_end);
2495 possible_keys[0]='\0';
2499 if (! strcmp(wm_name,"Country")) {
2500 name=res->country->name;
2501 item=&res->country->common.item;
2502 text=g_strdup_printf("%s", res->country->name);
2504 if (! strcmp(wm_name,"Town")) {
2505 name=res->town->name;
2506 item=&res->town->common.item;
2507 if (res->town->name && res->town->district)
2508 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);
2510 text=g_strdup_printf("%s%s%s", res->town->common.postal ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name);
2512 if (! strcmp(wm_name,"Street")) {
2513 name=res->street->name;
2514 item=&res->street->common.item;
2515 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
2517 dbg(1,"res->country->flag=%s\n", res->country->flag);
2518 gui_internal_widget_append(search_list,
2519 wc=gui_internal_button_new_with_callback(this, text,
2520 image_new_xs(this, res->country->flag),
2521 gravity_left_center|orientation_horizontal|flags_fill,
2522 gui_internal_cmd_position, param));
2523 wc->name=g_strdup(name);
2526 wc->selection_id=res->id;
2529 gui_internal_widget_pack(this, search_list);
2530 l=g_list_last(this->root.children);
2531 graphics_draw_mode(this->gra, draw_mode_begin);
2532 gui_internal_widget_render(this, l->data);
2533 graphics_draw_mode(this->gra, draw_mode_end);
2538 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2540 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2541 this->idle=event_add_idle(50,this->idle_cb);
2542 callback_call_0(this->idle_cb);
2548 * @param wm The widget that generated the event for the search changed,
2549 * if this was generated by a key on the virtual keyboard then
2550 * wm is the key button widget.
2553 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2556 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2557 gui_internal_widget_children_destroy(this, search_list);
2559 void *param=(void *)3;
2561 if (! strcmp(wm->name,"Country"))
2563 if (! strcmp(wm->name,"Street"))
2565 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2567 gui_internal_search_idle_end(this);
2568 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2569 struct attr search_attr;
2572 if (! strcmp(wm->name,"Country"))
2573 search_attr.type=attr_country_all;
2574 if (! strcmp(wm->name,"Town"))
2575 search_attr.type=attr_town_or_district_name;
2576 if (! strcmp(wm->name,"Street"))
2577 search_attr.type=attr_street_name;
2578 if (! strcmp(wm->name,"House number"))
2579 search_attr.type=attr_house_number;
2580 search_attr.u.str=wm->text;
2581 search_list_search(this->sl, &search_attr, 1);
2582 gui_internal_search_idle_start(this, wm->name, search_list, param);
2584 l=g_list_last(this->root.children);
2585 gui_internal_widget_render(this, l->data);
2588 static struct widget *
2589 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)
2592 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2593 NULL, gravity_center|orientation_vertical, func, data));
2594 wk->data_free=data_free;
2595 wk->background=this->background;
2603 static struct widget *
2604 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2606 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2609 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2611 // Some macros that make the keyboard layout easier to visualise in
2612 // the source code. The macros are #undef'd after this function.
2613 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2614 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h)
2615 static struct widget *
2616 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2618 struct widget *wkbd,*wk;
2619 struct menu_data *md=gui_internal_menu_data(this);
2620 int i, max_w=this->root.w, max_h=this->root.h;
2626 gui_internal_highlight(this);
2628 gui_internal_widget_children_destroy(this, wkbdb);
2630 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2632 md->keyboard_mode=mode;
2633 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2634 wkbd->background=this->background;
2641 if (mode >= 0 && mode < 8) {
2642 for (i = 0 ; i < 26 ; i++) {
2643 char text[]={'A'+i,'\0'};
2646 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2653 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2655 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2658 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2660 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2662 if (mode >= 8 && mode < 16) {
2663 for (i = 0 ; i < 26 ; i++) {
2664 char text[]={'a'+i,'\0'};
2667 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2674 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2676 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2679 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2681 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2683 if (mode >= 16 && mode < 24) {
2684 for (i = 0 ; i < 10 ; i++) {
2685 char text[]={'0'+i,'\0'};
2688 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
2689 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
2691 for (i = 0 ; i < 5 ; i++) SPACER();
2699 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2701 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2704 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2706 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2708 if (mode >= 24 && mode < 32) {
2709 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
2710 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
2711 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
2712 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
2714 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2717 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2719 if (mode >= 32 && mode < 40) {
2720 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
2721 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
2722 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
2723 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
2725 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2728 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2730 gui_internal_widget_append(wkbdb, wkbd);
2732 gui_internal_widget_pack(this, wkbdb);
2733 gui_internal_widget_render(this, wkbdb);
2740 static struct widget *
2741 gui_internal_keyboard(struct gui_priv *this, int mode)
2743 if (! this->keyboard)
2745 return gui_internal_keyboard_do(this, NULL, mode);
2749 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2751 gui_internal_keyboard_do(this, key->data, key->datai);
2755 gui_internal_search_list_set_default_country(struct gui_priv *this)
2757 struct attr search_attr, country_name, country_iso2, *country_attr;
2759 struct country_search *cs;
2760 struct tracking *tracking;
2761 struct search_list_result *res;
2763 country_attr=country_default();
2764 tracking=navit_get_tracking(this->nav);
2765 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
2766 country_attr=&search_attr;
2768 cs=country_search_new(country_attr, 0);
2769 item=country_search_get_item(cs);
2770 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2771 search_attr.type=attr_country_all;
2772 dbg(0,"country %s\n", country_name.u.str);
2773 search_attr.u.str=country_name.u.str;
2774 search_list_search(this->sl, &search_attr, 0);
2775 while((res=search_list_get_result(this->sl)));
2776 g_free(this->country_iso2);
2777 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2778 this->country_iso2=g_strdup(country_iso2.u.str);
2780 country_search_destroy(cs);
2782 dbg(0,"warning: no default country found\n");
2783 if (this->country_iso2) {
2784 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2785 search_attr.type=attr_country_iso2;
2786 search_attr.u.str=this->country_iso2;
2787 search_list_search(this->sl, &search_attr, 0);
2788 while((res=search_list_get_result(this->sl)));
2794 gui_internal_search_list_new(struct gui_priv *this)
2796 struct mapset *ms=navit_get_mapset(this->nav);
2798 this->sl=search_list_new(ms);
2799 gui_internal_search_list_set_default_country(this);
2804 gui_internal_search_list_destroy(struct gui_priv *this)
2807 search_list_destroy(this->sl);
2814 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2816 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2818 gui_internal_search_list_new(this);
2819 wb=gui_internal_menu(this, what);
2820 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2821 gui_internal_widget_append(wb, w);
2822 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2823 gui_internal_widget_append(w, wr);
2824 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2825 gui_internal_widget_append(wr, we);
2827 if (!strcmp(type,"Country")) {
2828 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2829 wnext->func=gui_internal_search_town;
2830 } else if (!strcmp(type,"Town")) {
2831 if (this->country_iso2) {
2832 #if HAVE_API_ANDROID
2833 char country_iso2[strlen(this->country_iso2)+1];
2834 strtolower(country_iso2, this->country_iso2);
2835 country=g_strdup_printf("country_%s", country_iso2);
2837 country=g_strdup_printf("country_%s", this->country_iso2);
2840 country=strdup("gui_select_country");
2841 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
2842 wb->state |= STATE_SENSITIVE;
2844 wb->func = gui_internal_search_country;
2846 wb->func = gui_internal_back;
2847 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
2848 wnext->func=gui_internal_search_street;
2850 } else if (!strcmp(type,"Street")) {
2851 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
2852 wb->state |= STATE_SENSITIVE;
2853 wb->func = gui_internal_back;
2854 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
2855 wnext->func=gui_internal_search_house_number;
2856 } else if (!strcmp(type,"House number")) {
2857 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
2858 wb->state |= STATE_SENSITIVE;
2859 wb->func = gui_internal_back;
2861 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2863 gui_internal_widget_append(we, wnext);
2864 wnext->state |= STATE_SENSITIVE;
2866 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2867 gui_internal_widget_append(wr, wl);
2868 gui_internal_menu_data(this)->search_list=wl;
2869 wk->state |= STATE_EDIT;
2870 wk->background=this->background;
2871 wk->flags |= flags_expand|flags_fill;
2872 wk->func = gui_internal_search_changed;
2873 wk->name=g_strdup(type);
2875 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2876 gui_internal_menu_render(this);
2880 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
2882 search_list_select(this->sl, attr_street_name, 0, 0);
2883 gui_internal_search(this,_("House number"),"House number",0);
2887 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
2889 dbg(0,"id %d\n", widget->selection_id);
2890 search_list_select(this->sl, attr_street_name, 0, 0);
2891 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
2892 gui_internal_search(this,_("House number"),"House number",0);
2896 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
2898 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
2899 gui_internal_search(this,_("Street"),"Street",0);
2903 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
2905 dbg(0,"id %d\n", widget->selection_id);
2906 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
2907 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
2908 gui_internal_search(this,_("Street"),"Street",0);
2912 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
2915 search_list_select(this->sl, attr_country_all, 0, 0);
2916 g_free(this->country_iso2);
2917 this->country_iso2=NULL;
2918 gui_internal_search(this,_("Town"),"Town",0);
2922 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
2924 struct search_list_common *slc;
2925 dbg(0,"id %d\n", widget->selection_id);
2926 search_list_select(this->sl, attr_country_all, 0, 0);
2927 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
2929 g_free(this->country_iso2);
2930 this->country_iso2=((struct search_list_country *)slc)->iso2;
2932 gui_internal_search(this,widget->name,"Town",0);
2936 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
2938 gui_internal_prune_menu_count(this, 1, 0);
2939 gui_internal_search(this,_("Country"),"Country",0);
2943 gui_internal_cmd_town(struct gui_priv *this, struct widget *wm, void *data)
2946 search_list_select(this->sl, attr_country_all, 0, 0);
2947 gui_internal_search(this,_("Town"),"Town",1);
2951 gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm, void *data)
2954 struct widget *w,*wb,*wl;
2955 struct attr_iter *iter;
2958 wb=gui_internal_menu(this, _("Layout"));
2959 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2960 w->spy=this->spacing*3;
2961 gui_internal_widget_append(wb, w);
2962 iter=navit_attr_iter_new();
2963 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
2964 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
2966 gui_internal_widget_append(w, wl);
2968 navit_attr_iter_destroy(iter);
2969 gui_internal_menu_render(this);
2973 gui_internal_cmd_fullscreen(struct gui_priv *this, struct widget *wm, void *data)
2975 graphics_draw_mode(this->gra, draw_mode_end);
2976 if (this->fullscreen != 2)
2977 this->fullscreen=!this->fullscreen;
2978 this->win->fullscreen(this->win, this->fullscreen != 0);
2979 graphics_draw_mode(this->gra, draw_mode_begin);
2983 gui_internal_cmd_2d(struct gui_priv *this, struct widget *wm, void *data)
2985 struct transformation *trans=navit_get_trans(this->nav);
2986 transform_set_pitch(trans, 0);
2988 gui_internal_prune_menu(this, NULL);
2992 gui_internal_cmd_3d(struct gui_priv *this, struct widget *wm, void *data)
2994 struct transformation *trans=navit_get_trans(this->nav);
2995 transform_set_pitch(trans, this->pitch);
2997 gui_internal_prune_menu(this, NULL);
3001 gui_internal_cmd_display(struct gui_priv *this, struct widget *wm, void *data)
3004 struct transformation *trans;
3006 w=gui_internal_menu(this, _("Display"));
3007 gui_internal_widget_append(w,
3008 gui_internal_button_new_with_callback(this, _("Layout"),
3009 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
3010 gui_internal_cmd_layout, NULL));
3012 if(this->fullscreen != 2) {
3013 if (this->fullscreen) {
3014 gui_internal_widget_append(w,
3015 gui_internal_button_new_with_callback(this, _("Window Mode"),
3016 image_new_l(this, "gui_leave_fullscreen"), gravity_center|orientation_vertical,
3017 gui_internal_cmd_fullscreen, NULL));
3019 gui_internal_widget_append(w,
3020 gui_internal_button_new_with_callback(this, _("Fullscreen"),
3021 image_new_l(this, "gui_fullscreen"), gravity_center|orientation_vertical,
3022 gui_internal_cmd_fullscreen, NULL));
3025 trans=navit_get_trans(this->nav);
3026 if (transform_get_pitch(trans)) {
3027 gui_internal_widget_append(w,
3028 gui_internal_button_new_with_callback(this, _("2D"),
3029 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3030 gui_internal_cmd_2d, NULL));
3033 gui_internal_widget_append(w,
3034 gui_internal_button_new_with_callback(this, _("3D"),
3035 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3036 gui_internal_cmd_3d, NULL));
3038 gui_internal_menu_render(this);
3042 gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm, void *data)
3045 navit.type=attr_navit;
3046 navit.u.navit=this->nav;
3047 navit_destroy(navit.u.navit);
3048 config_remove_attr(config, &navit);
3052 gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm, void *data)
3054 navit_set_destination(this->nav, NULL, NULL, 0);
3059 gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm, void *data)
3061 struct widget *w,*wc;
3064 w=gui_internal_menu(this, _("Actions"));
3065 gui_internal_widget_append(w,
3066 gui_internal_button_new_with_callback(this, _("Bookmarks"),
3067 image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
3068 gui_internal_cmd_bookmarks, NULL));
3069 if (this->clickp_valid) {
3070 coord=coordinates(&this->clickp, '\n');
3071 gui_internal_widget_append(w,
3072 wc=gui_internal_button_new_with_callback(this, coord,
3073 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3074 gui_internal_cmd_position, (void *)1));
3075 wc->name=g_strdup(_("Map Point"));
3079 if (this->vehicle_valid) {
3080 coord=coordinates(&this->vehiclep, '\n');
3081 gui_internal_widget_append(w,
3082 wc=gui_internal_button_new_with_callback(this, coord,
3083 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3084 gui_internal_cmd_position, NULL));
3085 wc->name=g_strdup(_("Vehicle Position"));
3086 wc->c=this->vehiclep;
3089 gui_internal_widget_append(w,
3090 gui_internal_button_new_with_callback(this, _("Town"),
3091 image_new_l(this, "gui_town"), gravity_center|orientation_vertical,
3092 gui_internal_cmd_town, NULL));
3093 gui_internal_widget_append(w,
3094 gui_internal_button_new_with_callback(this, _("Quit"),
3095 image_new_l(this, "gui_quit"), gravity_center|orientation_vertical,
3096 gui_internal_cmd_quit, NULL));
3098 if (navit_check_route(this->nav)) {
3099 gui_internal_widget_append(w,
3100 gui_internal_button_new_with_callback(this, _("Stop\nNavigation"),
3101 image_new_l(this, "gui_stop"), gravity_center|orientation_vertical,
3102 gui_internal_cmd_abort_navigation, NULL));
3104 gui_internal_menu_render(this);
3108 gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm, void *wdata)
3110 struct attr attr, on, off, description, type, data;
3111 struct widget *w,*wb,*wma;
3113 struct attr_iter *iter;
3116 wb=gui_internal_menu(this, _("Maps"));
3117 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3118 w->spy=this->spacing*3;
3119 gui_internal_widget_append(wb, w);
3120 iter=navit_attr_iter_new();
3121 on.type=off.type=attr_active;
3124 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3125 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3126 label=g_strdup(description.u.str);
3128 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3130 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3132 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3134 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3135 attr.u.map, &on, &off, 1);
3136 gui_internal_widget_append(w, wma);
3139 navit_attr_iter_destroy(iter);
3140 gui_internal_menu_render(this);
3144 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3146 struct attr vehicle = {attr_vehicle,{wm->data}};
3147 navit_set_attr(this->nav, &vehicle);
3151 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3153 struct widget *w,*wb,*row;
3154 struct attr attr,sat_attr;
3155 struct vehicle *v=wm->data;
3158 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3160 wb=gui_internal_menu(this, _("Show Satellite Status"));
3161 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3162 gui_internal_menu_data(this)->redisplay_widget=wm;
3163 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3164 gui_internal_widget_append(wb, w);
3165 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3166 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3167 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3168 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3169 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3170 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3171 gui_internal_widget_append(w,row);
3172 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3173 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3174 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3175 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3176 str=g_strdup_printf("%d", sat_attr.u.num);
3179 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3182 gui_internal_widget_append(w,row);
3184 gui_internal_widget_append(wb, w);
3185 gui_internal_menu_render(this);
3189 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3191 struct widget *w,*wb;
3193 struct vehicle *v=wm->data;
3194 wb=gui_internal_menu(this, _("Show NMEA Data"));
3195 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3196 gui_internal_menu_data(this)->redisplay_widget=wm;
3197 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3198 gui_internal_widget_append(wb, w);
3199 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3200 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3201 gui_internal_menu_render(this);
3205 * A container to hold the selected vehicle and the desired profile in
3208 struct vehicle_and_profilename {
3209 struct vehicle *vehicle;
3214 * Figures out whether the given vehicle is the active vehicle.
3216 * @return true if the vehicle is active, false otherwise.
3219 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3222 struct attr active_vehicle;
3224 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3225 active_vehicle.u.vehicle=NULL;
3227 return active_vehicle.u.vehicle == vehicle;
3231 save_vehicle_xml(struct vehicle *v)
3234 struct attr_iter *iter=vehicle_attr_iter_new();
3238 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3239 if (attr_type_begin(attr.type) == attr_type_object_begin)
3242 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3246 printf("</vehicle>\n");
3249 vehicle_attr_iter_destroy(iter);
3254 * Reacts to a button press that changes a vehicle's active profile.
3256 * @see gui_internal_add_vehicle_profile
3259 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3260 widget *wm, void *data)
3262 struct vehicle_and_profilename *vapn = data;
3263 struct vehicle *v = vapn->vehicle;
3264 char *profilename = vapn->profilename;
3265 struct attr vehicle_name_attr;
3266 char *vehicle_name = NULL;
3268 // Get the vehicle name
3269 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3270 vehicle_name = vehicle_name_attr.u.str;
3272 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3275 // Change the profile name
3276 struct attr profilename_attr = {attr_profilename, {profilename}};
3277 if(!vehicle_set_attr(v, &profilename_attr, NULL)) {
3278 dbg(0, "Unable to set the vehicle's profile name\n");
3281 // Notify Navit that the routing should be re-done if this is the
3283 if(gui_internal_is_active_vehicle(this, v)) {
3284 struct attr vehicle = {attr_vehicle, {v}};
3285 navit_set_attr(this->nav, &vehicle);
3287 save_vehicle_xml(v);
3293 * Adds the vehicle profile to the GUI, allowing the user to pick a
3294 * profile for the currently selected vehicle.
3297 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3298 *parent, struct vehicle *v, struct vehicleprofile *profile)
3300 // Just here to show up in the translation file, nice and close to
3301 // where the translations are actually used.
3302 struct attr profile_attr;
3303 struct attr *attr = NULL;
3305 char *active_profile = NULL;
3308 struct vehicle_and_profilename *context = NULL;
3310 static char *__profile_translations[] = {
3311 _n("car"), _n("bike"), _n("pedestrian")
3314 // Figure out the profile name
3315 attr = attr_search(profile->attrs, NULL, attr_name);
3318 // Determine whether the profile is the active one
3319 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3320 active_profile = profile_attr.u.str;
3321 active = strcmp(name, active_profile) == 0;
3323 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3324 active_profile, active);
3326 // Build a translatable label.
3328 label = g_strdup_printf(_("Current profile: %s"), _(name));
3330 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3333 // Create the context object (the vehicle and the desired profile)
3334 context = g_new0(struct vehicle_and_profilename, 1);
3335 context->vehicle = v;
3336 context->profilename = name;
3339 gui_internal_widget_append(parent,
3340 gui_internal_button_new_with_callback(
3342 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3343 gravity_left_center|orientation_horizontal|flags_fill,
3344 gui_internal_cmd_set_active_profile, context));
3350 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3352 struct widget *w,*wb;
3354 struct vehicle *v=wm->data;
3355 struct vehicleprofile *profile = NULL;
3357 wb=gui_internal_menu(this, wm->text);
3358 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3359 gui_internal_widget_append(wb, w);
3361 // Add the "Set as active" button if this isn't the active
3363 if (!gui_internal_is_active_vehicle(this, v)) {
3364 gui_internal_widget_append(w,
3365 gui_internal_button_new_with_callback(this, _("Set as active"),
3366 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3367 gui_internal_cmd_set_active_vehicle, wm->data));
3370 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3371 gui_internal_widget_append(w,
3372 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3373 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3374 gui_internal_cmd_show_satellite_status, wm->data));
3376 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3377 gui_internal_widget_append(w,
3378 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3379 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3380 gui_internal_cmd_show_nmea_data, wm->data));
3383 // Add all the possible vehicle profiles to the menu
3384 GList *profiles = navit_get_vehicleprofiles(this->nav);
3386 profile = (struct vehicleprofile *)profiles->data;
3387 gui_internal_add_vehicle_profile(this, w, v, profile);
3388 profiles = g_list_next(profiles);
3391 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3392 gui_internal_menu_render(this);
3396 gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3398 struct attr attr,vattr;
3399 struct widget *w,*wb,*wl;
3400 struct attr_iter *iter;
3401 struct attr active_vehicle;
3404 wb=gui_internal_menu(this, _("Vehicle"));
3405 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3406 w->spy=this->spacing*3;
3407 gui_internal_widget_append(wb, w);
3408 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3409 active_vehicle.u.vehicle=NULL;
3410 iter=navit_attr_iter_new();
3411 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3412 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3413 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3414 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3415 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3416 wl->text=g_strdup(vattr.u.str);
3417 gui_internal_widget_append(w, wl);
3419 navit_attr_iter_destroy(iter);
3420 gui_internal_menu_render(this);
3425 gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm, void *data)
3427 struct widget *wb,*w;
3429 wb=gui_internal_menu(this, _("Rules"));
3430 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3431 w->spy=this->spacing*3;
3432 gui_internal_widget_append(wb, w);
3435 on.type=off.type=attr_tracking;
3436 gui_internal_widget_append(w,
3437 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3441 on.type=off.type=attr_orientation;
3442 gui_internal_widget_append(w,
3443 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3447 on.type=off.type=attr_follow_cursor;
3448 gui_internal_widget_append(w,
3449 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3451 gui_internal_menu_render(this);
3455 gui_internal_cmd_settings(struct gui_priv *this, struct widget *wm, void *data)
3459 w=gui_internal_menu(this, _("Settings"));
3460 gui_internal_widget_append(w,
3461 gui_internal_button_new_with_callback(this, _("Display"),
3462 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
3463 gui_internal_cmd_display, NULL));
3464 gui_internal_widget_append(w,
3465 gui_internal_button_new_with_callback(this, _("Maps"),
3466 image_new_l(this, "gui_maps"), gravity_center|orientation_vertical,
3467 gui_internal_cmd_maps, NULL));
3468 gui_internal_widget_append(w,
3469 gui_internal_button_new_with_callback(this, _("Vehicle"),
3470 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3471 gui_internal_cmd_vehicle, NULL));
3472 gui_internal_widget_append(w,
3473 gui_internal_button_new_with_callback(this, _("Rules"),
3474 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
3475 gui_internal_cmd_rules, NULL));
3476 gui_internal_menu_render(this);
3479 //##############################################################################################################
3482 //# Authors: Martin Schaller (04/2008)
3483 //##############################################################################################################
3484 static void gui_internal_motion(void *data, struct point *p)
3487 struct gui_priv *this=data;
3488 if (!this->root.children) {
3489 navit_handle_motion(this->nav, p);
3495 if(!this->motion_timeout_callback)
3496 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3497 if(!this->motion_timeout_event)
3498 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3503 static void gui_internal_menu_root(struct gui_priv *this)
3507 graphics_draw_mode(this->gra, draw_mode_begin);
3508 w=gui_internal_menu(this, _("Main menu"));
3509 w->spx=this->spacing*10;
3510 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Actions"),
3511 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
3512 gui_internal_cmd_actions, NULL));
3513 if (this->flags & 2) {
3514 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Show\nMap"),
3515 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3516 gui_internal_cmd_settings, NULL));
3518 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Settings"),
3519 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
3520 gui_internal_cmd_settings, NULL));
3521 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Tools"),
3522 image_new_l(this, "gui_tools"), gravity_center|orientation_vertical,
3523 gui_internal_cmd_tools, NULL));
3525 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Route"),
3526 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
3527 gui_internal_cmd_route, NULL));
3530 callback_list_call_attr_1(this->cbl, attr_gui, w);
3532 gui_internal_menu_render(this);
3533 graphics_draw_mode(this->gra, draw_mode_end);
3537 gui_internal_enter(struct gui_priv *this, int ignore)
3539 struct graphics *gra=this->gra;
3540 this->ignore_button=ignore;
3541 this->clickp_valid=this->vehicle_valid=0;
3543 navit_block(this->nav, 1);
3544 graphics_overlay_disable(gra, 1);
3547 this->root.background=this->background;
3551 gui_internal_leave(struct gui_priv *this)
3553 graphics_draw_mode(this->gra, draw_mode_end);
3557 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3559 struct transformation *trans;
3561 struct attr attr,attrp;
3564 gui_internal_enter(this, ignore);
3565 trans=navit_get_trans(this->nav);
3567 transform_reverse(trans, p, &c);
3568 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3569 this->clickp.pro=transform_get_projection(trans);
3572 this->clickp_valid=1;
3574 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3575 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3576 this->vehiclep.pro=transform_get_projection(trans);
3577 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3578 this->vehiclep.x=c.x;
3579 this->vehiclep.y=c.y;
3580 this->vehicle_valid=1;
3583 gui_internal_menu_root(this);
3587 gui_internal_cmd_menu2(struct gui_priv *this)
3589 gui_internal_cmd_menu(this, NULL, 1);
3594 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
3596 if (widget->text && strlen(widget->text))
3597 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
3598 g_free(widget->text);
3600 gui_internal_prune_menu(this, NULL);
3601 gui_internal_check_exit(this);
3605 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
3607 gui_internal_cmd_log_do(this, widget->data);
3611 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
3615 len=strlen(wm->text);
3616 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
3617 wm->text[len-1]='\0';
3618 gui_internal_cmd_log_do(this, wm);
3625 gui_internal_cmd_log(struct gui_priv *this)
3627 struct widget *w,*wb,*wk,*wl,*we,*wnext;
3628 gui_internal_enter(this, 1);
3629 wb=gui_internal_menu(this, "Log Message");
3630 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3631 gui_internal_widget_append(wb, w);
3632 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3633 gui_internal_widget_append(w, we);
3634 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
3635 wk->state |= STATE_EDIT|STATE_CLEAR;
3636 wk->background=this->background;
3637 wk->flags |= flags_expand|flags_fill;
3638 wk->func = gui_internal_cmd_log_changed;
3639 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3640 wnext->state |= STATE_SENSITIVE;
3641 wnext->func = gui_internal_cmd_log_clicked;
3643 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3644 gui_internal_widget_append(w, wl);
3646 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3647 gui_internal_menu_render(this);
3648 gui_internal_leave(this);
3652 gui_internal_check_exit(struct gui_priv *this)
3654 struct graphics *gra=this->gra;
3655 if (! this->root.children) {
3656 gui_internal_search_idle_end(this);
3657 gui_internal_search_list_destroy(this);
3658 graphics_overlay_disable(gra, 0);
3659 if (!navit_block(this->nav, 0)) {
3661 navit_draw(this->nav);
3663 navit_draw_displaylist(this->nav);
3668 //##############################################################################################################
3669 //# Description: Function to handle mouse clicks and scroll wheel movement
3671 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3672 //##############################################################################################################
3673 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3675 struct gui_priv *this=data;
3676 struct graphics *gra=this->gra;
3678 dbg(1,"enter %d %d\n", pressed, button);
3679 // if still on the map (not in the menu, yet):
3680 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
3681 if (!this->root.children || this->ignore_button) {
3682 this->ignore_button=0;
3683 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3684 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
3685 dbg(1,"navit has handled button\n");
3688 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
3689 if (this->menu_on_map_click && button == 1)
3690 gui_internal_cmd_menu(this, p, 0);
3695 // if already in the menu:
3699 gui_internal_highlight(this);
3704 graphics_draw_mode(gra, draw_mode_begin);
3705 gui_internal_call_highlighted(this);
3706 gui_internal_highlight(this);
3707 graphics_draw_mode(gra, draw_mode_end);
3708 gui_internal_check_exit(this);
3713 gui_internal_setup_gc(struct gui_priv *this)
3715 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
3716 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
3717 struct graphics *gra=this->gra;
3719 if (this->background)
3721 this->background=graphics_gc_new(gra);
3722 this->background2=graphics_gc_new(gra);
3723 this->highlight_background=graphics_gc_new(gra);
3724 graphics_gc_set_foreground(this->highlight_background, &cbh);
3725 this->foreground=graphics_gc_new(gra);
3726 graphics_gc_set_foreground(this->foreground, &cf);
3727 this->text_background=graphics_gc_new(gra);
3728 this->text_foreground=graphics_gc_new(gra);
3729 graphics_gc_set_foreground(this->background, &this->background_color);
3730 graphics_gc_set_foreground(this->background2, &this->background2_color);
3731 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
3732 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
3735 //##############################################################################################################
3738 //# Authors: Martin Schaller (04/2008)
3739 //##############################################################################################################
3740 static void gui_internal_resize(void *data, int w, int h)
3742 struct gui_priv *this=data;
3744 gui_internal_setup_gc(this);
3745 if( this->root.w==w && this->root.h==h)
3750 dbg(0,"w=%d h=%d children=%p\n", w, h, this->root.children);
3751 navit_handle_resize(this->nav, w, h);
3752 if (this->root.children) {
3753 gui_internal_prune_menu(this, NULL);
3754 gui_internal_menu_root(this);
3759 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
3774 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
3776 GList *l=wi->children;
3777 if (wi->state & STATE_SENSITIVE) {
3780 gui_internal_keynav_point(wi, -dx, -dy, &wp);
3782 dist1=(wp.x-p->x)*dx;
3785 dist1=(wp.y-p->y)*dy;
3793 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);
3799 if (dist1 < *distance) {
3806 struct widget *child=l->data;
3807 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
3813 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
3815 struct widget *result,*menu=g_list_last(this->root.children)->data;
3818 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3819 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
3825 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
3827 gui_internal_keynav_point(result, dx, dy, &p);
3828 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
3833 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3834 dbg(1,"result=%p\n", result);
3846 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3847 dbg(1,"wraparound result=%p\n", result);
3849 gui_internal_highlight_do(this, result);
3851 gui_internal_say(this, result, 1);
3854 //##############################################################################################################
3857 //# Authors: Martin Schaller (04/2008)
3858 //##############################################################################################################
3859 static void gui_internal_keypress(void *data, char *key)
3861 struct gui_priv *this=data;
3864 if (!this->root.children) {
3865 transform_get_size(navit_get_trans(this->nav), &w, &h);
3870 navit_set_center_screen(this->nav, &p, 1);
3872 case NAVIT_KEY_DOWN:
3875 navit_set_center_screen(this->nav, &p, 1);
3877 case NAVIT_KEY_LEFT:
3880 navit_set_center_screen(this->nav, &p, 1);
3882 case NAVIT_KEY_RIGHT:
3885 navit_set_center_screen(this->nav, &p, 1);
3887 case NAVIT_KEY_ZOOM_IN:
3888 navit_zoom_in(this->nav, 2, NULL);
3890 case NAVIT_KEY_ZOOM_OUT:
3891 navit_zoom_out(this->nav, 2, NULL);
3893 case NAVIT_KEY_RETURN:
3894 case NAVIT_KEY_MENU:
3895 gui_internal_cmd_menu(this, NULL, 0);
3900 graphics_draw_mode(this->gra, draw_mode_begin);
3902 case NAVIT_KEY_LEFT:
3903 gui_internal_keynav_highlight_next(this,-1,0);
3905 case NAVIT_KEY_RIGHT:
3906 gui_internal_keynav_highlight_next(this,1,0);
3909 gui_internal_keynav_highlight_next(this,0,-1);
3911 case NAVIT_KEY_DOWN:
3912 gui_internal_keynav_highlight_next(this,0,1);
3914 case NAVIT_KEY_BACK:
3916 case NAVIT_KEY_RETURN:
3917 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3918 gui_internal_call_highlighted(this);
3920 gui_internal_keypress_do(this, key);
3923 gui_internal_keypress_do(this, key);
3925 graphics_draw_mode(this->gra, draw_mode_end);
3926 gui_internal_check_exit(this);
3930 //##############################################################################################################
3933 //# Authors: Martin Schaller (04/2008)
3934 //##############################################################################################################
3935 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
3938 struct transformation *trans=navit_get_trans(this->nav);
3940 win=graphics_get_data(gra, "window");
3943 navit_ignore_graphics_events(this->nav, 1);
3946 navit_ignore_graphics_events(this->nav, 1);
3947 transform_get_size(trans, &this->root.w, &this->root.h);
3948 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
3949 graphics_add_callback(gra, this->resize_cb);
3950 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
3951 graphics_add_callback(gra, this->button_cb);
3952 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
3953 graphics_add_callback(gra, this->motion_cb);
3954 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
3955 graphics_add_callback(gra, this->keypress_cb);
3957 // set fullscreen if needed
3958 if (this->fullscreen)
3959 this->win->fullscreen(this->win, this->fullscreen != 0);
3960 /* Was resize callback already issued? */
3961 if (navit_get_ready(this->nav) & 2)
3962 gui_internal_setup_gc(this);
3966 static void gui_internal_disable_suspend(struct gui_priv *this)
3968 if (this->win->disable_suspend)
3969 this->win->disable_suspend(this->win);
3972 //##############################################################################################################
3975 //# Authors: Martin Schaller (04/2008)
3976 //##############################################################################################################
3977 struct gui_methods gui_internal_methods = {
3980 gui_internal_set_graphics,
3984 gui_internal_disable_suspend,
3988 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
3990 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
3992 *out=attr_generic_add_attr(*out, &private_data);
3996 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
3998 callback_list_add(priv->cbl, cb);
4002 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4004 callback_list_remove(priv->cbl, cb);
4008 static struct gui_internal_methods gui_internal_methods_ext = {
4009 gui_internal_add_callback,
4010 gui_internal_remove_callback,
4011 gui_internal_menu_render,
4018 gui_internal_get_flags(struct widget *widget)
4020 return widget->flags;
4024 gui_internal_set_flags(struct widget *widget, enum flags flags)
4026 widget->flags=flags;
4030 gui_internal_get_state(struct widget *widget)
4032 return widget->state;
4036 gui_internal_set_state(struct widget *widget, int state)
4038 widget->state=state;
4042 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4048 gui_internal_set_data(struct widget *widget, void *data)
4054 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4056 widget->background=this->background;
4059 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4060 gui_internal_widget_append,
4061 gui_internal_button_new,
4062 gui_internal_button_new_with_callback,
4063 gui_internal_box_new,
4064 gui_internal_label_new,
4065 gui_internal_image_new,
4066 gui_internal_keyboard,
4068 gui_internal_get_flags,
4069 gui_internal_set_flags,
4070 gui_internal_get_state,
4071 gui_internal_set_state,
4072 gui_internal_set_func,
4073 gui_internal_set_data,
4074 gui_internal_set_default_background,
4077 static struct command_table commands[] = {
4078 {"menu",command_cast(gui_internal_cmd_menu2)},
4079 {"fullscreen",command_cast(gui_internal_cmd_fullscreen)},
4080 {"get_data",command_cast(gui_internal_get_data)},
4081 {"log",command_cast(gui_internal_cmd_log)},
4085 //##############################################################################################################
4088 //# Authors: Martin Schaller (04/2008)
4089 //##############################################################################################################
4090 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
4092 struct gui_priv *this;
4094 *meth=gui_internal_methods;
4095 this=g_new0(struct gui_priv, 1);
4097 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
4098 this->menu_on_map_click=attr->u.num;
4100 this->menu_on_map_click=1;
4101 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
4102 dbg(0,"register\n");
4103 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
4106 if( (attr=attr_search(attrs,NULL,attr_font_size)))
4108 this->config.font_size=attr->u.num;
4112 this->config.font_size=-1;
4114 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
4116 this->config.icon_xs=attr->u.num;
4120 this->config.icon_xs=-1;
4122 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
4124 this->config.icon_l=attr->u.num;
4128 this->config.icon_l=-1;
4130 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
4132 this->config.icon_s=attr->u.num;
4136 this->config.icon_s=-1;
4138 if( (attr=attr_search(attrs,NULL,attr_spacing)))
4140 this->config.spacing=attr->u.num;
4144 this->config.spacing=-1;
4146 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
4148 this->speech=attr->u.num;
4150 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
4151 this->keyboard=attr->u.num;
4155 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
4156 this->fullscreen=attr->u.num;
4158 if( (attr=attr_search(attrs,NULL,attr_flags)))
4159 this->flags=attr->u.num;
4160 if( (attr=attr_search(attrs,NULL,attr_background_color)))
4161 this->background_color=*attr->u.color;
4163 this->background_color=(struct color){0x0,0x0,0x0,0xffff};
4164 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
4165 this->background2_color=*attr->u.color;
4167 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
4168 if( (attr=attr_search(attrs,NULL,attr_text_color)))
4169 this->text_foreground_color=*attr->u.color;
4171 this->text_foreground_color=(struct color){0xffff,0xffff,0xffff,0xffff};
4172 if( (attr=attr_search(attrs,NULL,attr_columns)))
4173 this->cols=attr->u.num;
4174 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
4175 this->osd_configuration=*attr;
4177 if( (attr=attr_search(attrs,NULL,attr_pitch)))
4178 this->pitch=attr->u.num;
4181 this->data.priv=this;
4182 this->data.gui=&gui_internal_methods_ext;
4183 this->data.widget=&gui_internal_widget_methods;
4184 this->cbl=callback_list_new();
4189 //##############################################################################################################
4192 //# Authors: Martin Schaller (04/2008)
4193 //##############################################################################################################
4194 void plugin_init(void)
4196 plugin_register_gui_type("internal", gui_internal_new);
4200 * @brief Creates a new table widget.
4202 * Creates and returns a new table widget. This function will
4203 * setup next/previous buttons as children.
4205 * @param this The graphics context.
4206 * @param flags widget sizing flags.
4207 * @returns The newly created widget
4209 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4211 struct widget * widget = g_new0(struct widget,1);
4212 struct table_data * data = NULL;
4213 widget->type=widget_table;
4214 widget->flags=flags;
4215 widget->data = g_new0(struct table_data,1);
4216 widget->data_free=gui_internal_table_data_free;
4217 data = (struct table_data*)widget->data;
4221 data->next_button = gui_internal_button_new_with_callback
4222 (this,"Next",image_new_xs(this, "gui_active") ,
4223 gravity_left_center |orientation_vertical,
4224 gui_internal_table_button_next,NULL);
4225 data->next_button->data=widget;
4228 data->prev_button = gui_internal_button_new_with_callback
4230 image_new_xs(this, "gui_active")
4231 ,gravity_right_center |orientation_vertical,
4232 gui_internal_table_button_prev,NULL);
4234 data->prev_button->data=widget;
4238 data->button_box=gui_internal_box_new(this,
4239 gravity_center|orientation_horizontal);
4240 data->button_box->children=g_list_append(data->button_box->children,
4242 data->button_box->children=g_list_append(data->button_box->children,
4244 //data->button_box->background=this->background2;
4245 data->button_box->bl=this->spacing;
4246 widget->children=g_list_append(widget->children,data->button_box);
4247 gui_internal_widget_pack(this,data->button_box);
4255 * @brief Clears all the rows from the table.
4256 * This function removes all rows from a table.
4257 * New rows can later be added to the table.
4259 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4262 struct table_data * table_data = (struct table_data* ) table->data;
4264 iter = table->children;
4266 if(iter->data != table_data->button_box) {
4267 struct widget * child = (struct widget*)iter->data;
4268 gui_internal_widget_destroy(this,child);
4269 if(table->children == iter) {
4270 table->children = g_list_remove(iter,iter->data);
4271 iter=table->children;
4274 iter = g_list_remove(iter,iter->data);
4277 iter = g_list_next(iter);
4281 table_data->top_row=NULL;
4282 table_data->bottom_row=NULL;
4283 if(table_data->page_headers)
4284 g_list_free(table_data->page_headers);
4285 table_data->page_headers=NULL;
4290 * Creates a new table_row widget.
4291 * @param this The graphics context
4292 * @param flags Sizing flags for the row
4293 * @returns The new table_row widget.
4295 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4297 struct widget * widget = g_new0(struct widget,1);
4298 widget->type=widget_table_row;
4299 widget->flags=flags;
4306 * @brief Computes the column dimensions for the table.
4308 * @param w The table widget to compute dimensions for.
4310 * This function examines all of the rows and columns for the table w
4311 * and returns a list (GList) of table_column_desc elements that
4312 * describe each column of the table.
4314 * The caller is responsible for freeing the returned list.
4316 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4319 GList * column_desc = NULL;
4320 GList * current_desc=NULL;
4321 GList * cur_row = w->children;
4322 struct widget * cur_row_widget=NULL;
4323 GList * cur_column=NULL;
4324 struct widget * cell_w=NULL;
4325 struct table_column_desc * current_cell=NULL;
4326 struct table_data * table_data=NULL;
4333 * Scroll through the the table and
4334 * 1. Compute the maximum width + height of each column across all rows.
4336 table_data = (struct table_data*) w->data;
4337 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4339 cur_row_widget = (struct widget*) cur_row->data;
4340 current_desc = column_desc;
4341 if(cur_row_widget == table_data->button_box)
4346 for(cur_column = cur_row_widget->children; cur_column;
4347 cur_column=g_list_next(cur_column))
4349 cell_w = (struct widget*) cur_column->data;
4350 gui_internal_widget_pack(this,cell_w);
4351 if(current_desc == 0)
4353 current_cell = g_new0(struct table_column_desc,1);
4354 column_desc = g_list_append(column_desc,current_cell);
4355 current_desc = g_list_last(column_desc);
4356 current_cell->height=cell_w->h;
4357 current_cell->width=cell_w->w;
4358 total_width+=cell_w->w;
4363 current_cell = current_desc->data;
4366 if(current_cell->height < height )
4368 current_cell->height = height;
4370 if(current_cell->width < width)
4372 total_width += (width-current_cell->width);
4373 current_cell->width = width;
4378 current_desc = g_list_next(current_desc);
4388 * If the width of all columns is less than the width off
4389 * the table expand each cell proportionally.
4392 if(total_width+(this->spacing*column_count) < w->w ) {
4393 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4394 current_cell = (struct table_column_desc*) current_desc->data;
4395 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4404 * @brief Computes the height and width for the table.
4406 * The height and widht are computed to display all cells in the table
4407 * at the requested height/width.
4409 * @param this The graphics context
4410 * @param w The widget to pack.
4413 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4419 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4421 struct table_column_desc * cell_desc=0;
4422 struct table_data * table_data = (struct table_data*)w->data;
4424 for(current = column_data; current; current=g_list_next(current))
4426 if(table_data->button_box == current->data )
4430 cell_desc = (struct table_column_desc *) current->data;
4431 width = width + cell_desc->width + this->spacing;
4432 if(height < cell_desc->height)
4434 height = cell_desc->height ;
4440 for(current=w->children; current; current=g_list_next(current))
4442 if(current->data!= table_data->button_box)
4447 if (table_data->button_box)
4448 gui_internal_widget_pack(this,table_data->button_box);
4452 if(w->h + w->c.y > this->root.h )
4455 * Do not allow the widget to exceed the screen.
4458 w->h = this->root.h- w->c.y - height;
4463 * Deallocate column descriptions.
4465 current = column_data;
4466 while( (current = g_list_last(current)) )
4468 current = g_list_remove(current,current->data);
4476 * @brief Renders a table widget.
4478 * @param this The graphics context
4479 * @param w The table widget to render.
4481 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4486 GList * column_desc=NULL;
4487 GList * cur_row = NULL;
4488 GList * current_desc=NULL;
4489 struct table_data * table_data = (struct table_data*)w->data;
4491 int is_first_page=1;
4492 struct table_column_desc * dim=NULL;
4494 dbg_assert(table_data);
4495 column_desc = gui_internal_compute_table_dimensions(this,w);
4499 * Skip rows that are on previous pages.
4501 cur_row = w->children;
4502 if(table_data->top_row && table_data->top_row != w->children )
4504 cur_row = table_data->top_row;
4510 * Loop through each row. Drawing each cell with the proper sizes,
4511 * at the proper positions.
4513 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4515 GList * cur_column=NULL;
4516 current_desc = column_desc;
4517 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4519 x =w->p.x+this->spacing;
4520 if(cur_row_widget == table_data->button_box )
4524 dim = (struct table_column_desc*)current_desc->data;
4526 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4529 * No more drawing space left.
4535 for(cur_column = cur_row_widget->children; cur_column;
4536 cur_column=g_list_next(cur_column))
4538 struct widget * cur_widget = (struct widget*) cur_column->data;
4539 dim = (struct table_column_desc*)current_desc->data;
4542 cur_widget->w=dim->width;
4544 cur_widget->h=dim->height;
4546 max_height = dim->height;
4547 /* We pack the widget before rendering to ensure that the x and y
4548 * coordinates get pushed down.
4550 gui_internal_widget_pack(this,cur_widget);
4551 gui_internal_widget_render(this,cur_widget);
4553 if(dim->height > max_height)
4555 max_height = dim->height;
4559 table_data->bottom_row=cur_row;
4560 current_desc = g_list_next(current_desc);
4562 if(table_data->button_box && (is_skipped || !is_first_page) )
4564 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4566 if(table_data->button_box->p.y < y )
4568 table_data->button_box->p.y=y;
4570 table_data->button_box->p.x = w->p.x;
4571 table_data->button_box->w = w->w;
4572 // table_data->button_box->h = w->h - y;
4573 // table_data->next_button->h=table_data->button_box->h;
4574 // table_data->prev_button->h=table_data->button_box->h;
4575 // table_data->next_button->c.y=table_data->button_box->c.y;
4576 // table_data->prev_button->c.y=table_data->button_box->c.y;
4578 gui_internal_widget_pack(this,table_data->button_box);
4579 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4582 table_data->button_box->p.y = w->p.y + w->h -
4583 table_data->button_box->h;
4587 table_data->next_button->state|= STATE_SENSITIVE;
4591 table_data->next_button->state&= ~STATE_SENSITIVE;
4594 if(table_data->top_row != w->children)
4596 table_data->prev_button->state|= STATE_SENSITIVE;
4600 table_data->prev_button->state&= ~STATE_SENSITIVE;
4602 gui_internal_widget_render(this,table_data->button_box);
4608 * Deallocate column descriptions.
4610 current_desc = column_desc;
4611 while( (current_desc = g_list_last(current_desc)) )
4613 current_desc = g_list_remove(current_desc,current_desc->data);
4619 * @brief Displays Route information
4621 * @li The name of the active vehicle
4622 * @param wm The button that was pressed.
4626 gui_internal_cmd_route_description(struct gui_priv * this, struct widget * wm,void *v)
4630 struct widget * menu;
4631 struct widget * row;
4634 if(! this->vehicle_cb)
4637 * Register the callback on vehicle updates.
4639 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4640 attr_position_coord_geo,this);
4641 navit_add_callback(this->nav,this->vehicle_cb);
4644 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4645 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4647 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4650 menu=gui_internal_menu(this,_("Route Description"));
4652 menu->free=gui_internal_route_screen_free;
4653 this->route_data.route_showing=1;
4654 this->route_data.route_table->spx = this->spacing;
4657 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4659 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4660 gui_internal_widget_append(box,this->route_data.route_table);
4662 box->spx = this->spacing;
4663 this->route_data.route_table->w=box->w;
4664 gui_internal_widget_append(menu,box);
4665 gui_internal_populate_route_table(this,this->nav);
4666 gui_internal_menu_render(this);
4671 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4674 int adx=a2->x-a1->x;
4675 int ady=a2->y-a1->y;
4676 int bdx=b2->x-b1->x;
4677 int bdy=b2->y-b1->y;
4678 n = bdy * adx - bdx * ady;
4679 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4680 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4691 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4692 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4693 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4696 res->x = a1->x + a * adx / n;
4697 res->y = a1->y + a * ady / n;
4702 struct heightline *next;
4704 struct coord_rect bbox;
4709 struct diagram_point {
4710 struct diagram_point *next;
4714 static struct heightline *
4715 item_get_heightline(struct item *item)
4717 struct heightline *ret=NULL;
4718 struct street_data *sd;
4722 if (item_attr_get(item, attr_label, &attr)) {
4723 height=atoi(attr.u.str);
4724 sd=street_get_data(item);
4725 if (sd && sd->count > 1) {
4726 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4727 ret->bbox.lu=sd->c[0];
4728 ret->bbox.rl=sd->c[0];
4729 ret->count=sd->count;
4731 for (i = 0 ; i < sd->count ; i++) {
4733 coord_rect_extend(&ret->bbox, sd->c+i);
4736 street_data_free(sd);
4743 * @brief Displays Route Height Profile
4745 * @li The name of the active vehicle
4746 * @param wm The button that was pressed.
4749 static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct widget * wm,void *v)
4753 struct widget * menu, *box;
4755 struct map * map=NULL;
4756 struct map_rect * mr=NULL;
4757 struct route * route;
4758 struct item * item =NULL;
4760 struct mapset_handle *msh;
4761 int x,i,first=1,dist=0;
4762 struct coord c,last,res;
4763 struct coord_rect rbbox,dbbox;
4764 struct map_selection sel;
4765 struct heightline *heightline,*heightlines=NULL;
4766 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4769 sel.range.min=type_height_line_1;
4770 sel.range.max=type_height_line_3;
4773 menu=gui_internal_menu(this,_("Height Profile"));
4774 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4775 gui_internal_widget_append(menu, box);
4776 route = navit_get_route(this->nav);
4778 map = route_get_map(route);
4780 mr = map_rect_new(map,NULL);
4782 while((item = map_rect_get_item(mr))) {
4783 while (item_coord_get(item, &c, 1)) {
4789 coord_rect_extend(&sel.u.c_rect, &c);
4792 map_rect_destroy(mr);
4793 ms=navit_get_mapset(this->nav);
4795 msh=mapset_open(ms);
4796 while ((map=mapset_next(msh, 1))) {
4797 mr=map_rect_new(map, &sel);
4799 while((item = map_rect_get_item(mr))) {
4800 if (item->type >= sel.range.min && item->type <= sel.range.max) {
4801 heightline=item_get_heightline(item);
4803 heightline->next=heightlines;
4804 heightlines=heightline;
4808 map_rect_destroy(mr);
4817 map = route_get_map(route);
4819 mr = map_rect_new(map,NULL);
4820 if(mr && heightlines) {
4821 while((item = map_rect_get_item(mr))) {
4823 while (item_coord_get(item, &c, 1)) {
4827 heightline=heightlines;
4830 coord_rect_extend(&rbbox, &c);
4831 while (heightline) {
4832 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
4833 for (i = 0 ; i < heightline->count - 1; i++) {
4834 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
4835 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
4836 diagram_point=g_new(struct diagram_point, 1);
4837 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
4838 diagram_point->c.y=heightline->height;
4839 diagram_point->next=diagram_points;
4840 diagram_points=diagram_point;
4841 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
4846 heightline=heightline->next;
4848 dist+=transform_distance(projection_mg, &last, &c);
4854 map_rect_destroy(mr);
4858 gui_internal_menu_render(this);
4860 diagram_point=diagram_points;
4861 while (diagram_point) {
4863 dbbox.lu=diagram_point->c;
4864 dbbox.rl=diagram_point->c;
4867 coord_rect_extend(&dbbox, &diagram_point->c);
4868 diagram_point=diagram_point->next;
4870 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
4871 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
4873 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
4875 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
4881 diagram_point=diagram_points;
4882 while (diagram_point) {
4883 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
4885 diagram_point=diagram_point->next;
4889 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
4890 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
4891 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
4892 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
4896 graphics_draw_lines(this->gra, this->foreground, p, 2);
4905 * @brief Displays Route information
4907 * @li The name of the active vehicle
4908 * @param wm The button that was pressed.
4911 void gui_internal_cmd_route(struct gui_priv * this, struct widget * wm,void *v)
4915 graphics_draw_mode(this->gra, draw_mode_begin);
4916 w=gui_internal_menu(this, _("Route"));
4917 w->spx=this->spacing*10;
4918 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Description"),
4919 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4920 gui_internal_cmd_route_description, NULL));
4921 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Height Profile"),
4922 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4923 gui_internal_cmd_route_height_profile, NULL));
4924 gui_internal_menu_render(this);
4925 graphics_draw_mode(this->gra, draw_mode_end);
4930 gui_internal_cmd_show_locale(struct gui_priv * this, struct widget * wm,void *v)
4932 struct widget *menu,*wb,*w;
4935 graphics_draw_mode(this->gra, draw_mode_begin);
4936 menu=gui_internal_menu(this, _("Show Locale"));
4937 menu->spx=this->spacing*10;
4938 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4939 gui_internal_widget_append(menu, wb);
4940 text=g_strdup_printf("LANG=%s",getenv("LANG"));
4941 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
4942 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
4944 #ifdef HAVE_API_WIN32_BASE
4946 wchar_t wcountry[32],wlang[32];
4947 char country[32],lang[32];
4949 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
4950 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
4951 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
4952 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
4953 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
4955 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
4956 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
4957 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
4958 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
4959 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
4964 gui_internal_menu_render(this);
4965 graphics_draw_mode(this->gra, draw_mode_end);
4970 gui_internal_cmd_tools(struct gui_priv * this, struct widget * wm,void *v)
4974 graphics_draw_mode(this->gra, draw_mode_begin);
4975 w=gui_internal_menu(this, _("Tools"));
4976 w->spx=this->spacing*10;
4977 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Show Locale"),
4978 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4979 gui_internal_cmd_show_locale, NULL));
4980 gui_internal_menu_render(this);
4981 graphics_draw_mode(this->gra, draw_mode_end);
4985 * @brief handles the 'next page' table event.
4986 * A callback function that is invoked when the 'next page' button is pressed
4987 * to advance the contents of a table widget.
4989 * @param this The graphics context.
4990 * @param wm The button widget that was pressed.
4992 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
4994 struct widget * table_widget = (struct widget * ) wm->data;
4995 struct table_data * table_data = NULL;
5001 table_data = (struct table_data*) table_widget->data;
5007 * Before advancing to the next page we need to ensure
5008 * that the current top_row is in the list of previous top_rows
5009 * so previous page can work.
5012 for(iterator=table_data->page_headers; iterator != NULL;
5013 iterator = g_list_next(iterator) )
5015 if(iterator->data == table_data->top_row)
5024 table_data->page_headers=g_list_append(table_data->page_headers,
5025 table_data->top_row);
5028 table_data->top_row = g_list_next(table_data->bottom_row);
5030 wm->state&= ~STATE_HIGHLIGHTED;
5031 gui_internal_menu_render(this);
5037 * @brief handles the 'previous page' table event.
5038 * A callback function that is invoked when the 'previous page' button is pressed
5039 * to go back in the contents of a table widget.
5041 * @param this The graphics context.
5042 * @param wm The button widget that was pressed.
5044 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5046 struct widget * table_widget = (struct widget * ) wm->data;
5047 struct table_data * table_data = NULL;
5048 GList * current_page_top=NULL;
5053 table_data = (struct table_data*) table_widget->data;
5056 current_page_top = table_data->top_row;
5057 for(iterator = table_data->page_headers; iterator != NULL;
5058 iterator = g_list_next(iterator))
5060 if(current_page_top == iterator->data)
5064 table_data->top_row = (GList*) iterator->data;
5068 wm->state&= ~STATE_HIGHLIGHTED;
5069 gui_internal_menu_render(this);
5074 * @brief deallocates a table_data structure.
5077 void gui_internal_table_data_free(void * p)
5082 * @note button_box and its children (next_button,prev_button)
5083 * have their memory managed by the table itself.
5085 struct table_data * table_data = (struct table_data*) p;
5086 g_list_free(table_data->page_headers);
5094 * @brief Called when the route is updated.
5096 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5099 if(this->route_data.route_showing) {
5100 gui_internal_populate_route_table(this,navit);
5101 graphics_draw_mode(this->gra, draw_mode_begin);
5102 gui_internal_menu_render(this);
5103 graphics_draw_mode(this->gra, draw_mode_end);
5111 * @brief Called when the route screen is closed (deallocated).
5113 * The main purpose of this function is to remove the widgets from
5114 * references route_data because those widgets are about to be freed.
5116 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5119 this_->route_data.route_showing=0;
5120 this_->route_data.route_table=NULL;
5127 * @brief Populates the route table with route information
5129 * @param this The gui context
5130 * @param navit The navit object
5132 void gui_internal_populate_route_table(struct gui_priv * this,
5133 struct navit * navit)
5135 struct map * map=NULL;
5136 struct map_rect * mr=NULL;
5137 struct navigation * nav = NULL;
5138 struct item * item =NULL;
5140 struct widget * label = NULL;
5141 struct widget * row = NULL;
5142 nav = navit_get_navigation(navit);
5146 map = navigation_get_map(nav);
5148 mr = map_rect_new(map,NULL);
5150 gui_internal_widget_table_clear(this,this->route_data.route_table);
5151 while((item = map_rect_get_item(mr))) {
5152 if(item_attr_get(item,attr_navigation_long,&attr)) {
5153 label = gui_internal_label_new(this,attr.u.str);
5154 row = gui_internal_widget_table_row_new(this,
5157 | orientation_horizontal);
5158 row->children=g_list_append(row->children,label);
5159 gui_internal_widget_append(this->route_data.route_table,row);