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 //##############################################################################################################
46 #include "transform.h"
62 #include "navit_nls.h"
63 #include "navigation.h"
64 #include "gui_internal.h"
68 struct widget *search_list;
69 struct widget *keyboard;
70 struct widget *button_bar;
72 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
73 struct widget *redisplay_widget;
76 //##############################################################################################################
79 //# Authors: Martin Schaller (04/2008)
80 //##############################################################################################################
82 enum widget_type type;
83 struct graphics_gc *background,*text_background;
84 struct graphics_gc *foreground_frame;
85 struct graphics_gc *foreground;
87 struct graphics_image *img;
89 * A function to be invoked on actions.
90 * @li widget The widget that is receiving the button press.
93 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
98 * @brief A function to deallocate data
100 void (*data_free)(void *data);
103 * @brief a function that will be called as the widget is being destroyed.
104 * This function can act as a destructor for the widget. It allows for
105 * on deallocation actions to be specified on a per widget basis.
106 * This function will call g_free on the widget (if required).
108 void (*free) (struct gui_priv *this_, struct widget * w);
120 int bl,br,bt,bb,spx,spy;
123 * The number of widgets to layout horizontally when doing
124 * a orientation_horizontal_vertical layout
129 int (*set_attr)(void *, struct attr *);
130 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
131 void (*remove_cb)(void *, struct callback *cb);
138 struct menu_data *menu_data;
143 * @brief A structure to store configuration values.
145 * This structure stores configuration values for how gui elements in the internal GUI
148 struct gui_config_settings {
151 * The base size (in fractions of a point) to use for text.
155 * The size (in pixels) that xs style icons should be scaled to.
159 * The size (in pixels) that s style icons (small) should be scaled to
163 * The size (in pixels) that l style icons should be scaled to
167 * The default amount of spacing (in pixels) to place between GUI elements.
174 * Indexes into the config_profiles array.
176 const int LARGE_PROFILE=0;
177 const int MEDIUM_PROFILE=1;
178 const int SMALL_PROFILE=2;
181 * The default config profiles.
183 * [0] => LARGE_PROFILE (screens 640 in one dimension)
184 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
185 * [2] => Small profile (default)
187 static struct gui_config_settings config_profiles[]={
194 struct widget * route_table;
199 //##############################################################################################################
202 //# Authors: Martin Schaller (04/2008)
203 //##############################################################################################################
207 struct graphics *gra;
208 struct graphics_gc *background;
209 struct graphics_gc *background2;
210 struct graphics_gc *highlight_background;
211 struct graphics_gc *foreground;
212 struct graphics_gc *text_foreground;
213 struct graphics_gc *text_background;
214 struct color background_color, background2_color, text_foreground_color, text_background_color;
218 struct graphics_font *font;
219 int icon_xs, icon_s, icon_l;
221 struct widget *widgets;
225 struct widget *highlighted;
226 struct widget *highlighted_menu;
227 int clickp_valid, vehicle_valid;
228 struct pcoord clickp, vehiclep;
229 struct search_list *sl;
231 int menu_on_map_click;
236 * The setting information read from the configuration file.
237 * values of -1 indicate no value was specified in the config file.
239 struct gui_config_settings config;
240 struct event_idle *idle;
241 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*idle_cb, *motion_timeout_callback;
242 struct event_timeout *motion_timeout_event;
243 struct point current;
245 struct callback * vehicle_cb;
247 * Stores information about the route.
249 struct route_data route_data;
251 struct gui_internal_data data;
252 struct callback_list *cbl;
255 struct attr osd_configuration;
261 * @brief A structure to store information about a table.
263 * The table_data widget stores pointers to extra information needed by the
266 * The table_data structure needs to be freed with data_free along with the widget.
272 * A GList pointer into a widget->children list that indicates the row
273 * currently being rendered at the top of the table.
277 * A Glist pointer into a widget->children list that indicates the row
278 * currently being rendered at the bottom of the table.
283 * A list of table_row widgets that mark the
284 * top rows for each page of the table.
285 * This is needed for the 'previous page' function of the table.
287 GList * page_headers;
290 * A container box that is the child of the table widget that contains+groups
291 * the next and previous button.
293 struct widget * button_box;
296 * A button widget to handle 'next page' requests
298 struct widget * next_button;
300 * A button widget to handle 'previous page' requests.
302 struct widget * prev_button;
306 * a pointer to the gui context.
307 * This is needed by the free function to destory the buttons.
309 struct gui_priv * this;
313 * A data structure that holds information about a column that makes up a table.
317 struct table_column_desc
321 * The computed height of a cell in the table.
326 * The computed width of a cell in the table.
332 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
333 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
334 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
335 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
336 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
337 static void gui_internal_apply_config(struct gui_priv *this);
339 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
340 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
341 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
342 static void gui_internal_cmd_route(struct gui_priv * this, struct widget * w,void *);
343 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
344 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
345 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
346 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
347 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
348 static void gui_internal_table_data_free(void * d);
349 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
351 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
352 static void gui_internal_populate_route_table(struct gui_priv * this,
353 struct navit * navit);
354 static void gui_internal_search_idle_end(struct gui_priv *this);
355 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
356 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
357 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
358 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
359 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
360 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
362 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
363 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
365 * * Display image scaled to specific size
366 * * searches for scaleable and pre-scaled image
367 * * @param this Our gui context
368 * * @param name image name
369 * * @param w desired width of image
370 * * @param h desired height of image
371 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
373 static struct graphics_image *
374 image_new_scaled(struct gui_priv *this, char *name, int w, int h)
376 struct graphics_image *ret=NULL;
377 char *full_name=NULL;
380 for (i = 1 ; i < 6 ; i++) {
384 full_name=g_strdup_printf("%s/xpm/%s.svg", getenv("NAVIT_SHAREDIR"), name);
387 full_name=g_strdup_printf("%s/xpm/%s.svgz", getenv("NAVIT_SHAREDIR"), name);
390 if (w != -1 && h != -1) {
391 full_name=g_strdup_printf("%s/xpm/%s_%d_%d.png", getenv("NAVIT_SHAREDIR"), name, w, h);
395 full_name=g_strdup_printf("%s/xpm/%s.png", getenv("NAVIT_SHAREDIR"), name);
398 full_name=g_strdup_printf("%s/xpm/%s.xpm", getenv("NAVIT_SHAREDIR"), name);
401 dbg(1,"trying '%s'\n", full_name);
404 if (!file_exists(full_name)) {
408 ret=graphics_image_new_scaled(this->gra, full_name, w, h);
409 dbg(1,"ret=%p\n", ret);
414 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
419 static struct graphics_image *
420 image_new_o(struct gui_priv *this, char *name)
422 return image_new_scaled(this, name, -1, -1);
425 static struct graphics_image *
426 image_new_xs(struct gui_priv *this, char *name)
428 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
432 static struct graphics_image *
433 image_new_s(struct gui_priv *this, char *name)
435 return image_new_scaled(this, name, this->icon_s, this->icon_s);
438 static struct graphics_image *
439 image_new_l(struct gui_priv *this, char *name)
441 return image_new_scaled(this, name, this->icon_l, this->icon_l);
445 coordinates(struct pcoord *pc, char sep)
447 char latc='N',lngc='E';
448 int lat_deg,lat_min,lat_sec;
449 int lng_deg,lng_min,lng_sec;
454 transform_to_geo(pc->pro, &c, &g);
465 lat_min=fmod(g.lat*60,60);
466 lat_sec=fmod(g.lat*3600,60);
468 lng_min=fmod(g.lng*60,60);
469 lng_sec=fmod(g.lng*3600,60);
470 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);
474 gui_internal_background_render(struct gui_priv *this, struct widget *w)
476 struct point pnt=w->p;
477 if (w->state & STATE_HIGHLIGHTED)
478 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
481 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
484 static struct widget *
485 gui_internal_label_new(struct gui_priv *this, char *text)
491 struct widget *widget=g_new0(struct widget, 1);
492 widget->type=widget_label;
494 widget->text=g_strdup(text);
495 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
499 widget->h=h+this->spacing;
501 widget->w=w+this->spacing;
503 widget->flags=gravity_center;
504 widget->foreground=this->text_foreground;
505 widget->text_background=this->text_background;
510 static struct widget *
511 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
513 struct widget *ret=NULL;
514 char *tmp=g_malloc(strlen(text)+3);
521 ret=gui_internal_label_new(this, tmp);
522 if (ret->w < maxwidth)
524 gui_internal_widget_destroy(this, ret);
532 static struct widget *
533 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
535 struct widget *widget=g_new0(struct widget, 1);
536 widget->type=widget_image;
539 widget->w=image->width;
540 widget->h=image->height;
546 gui_internal_image_render(struct gui_priv *this, struct widget *w)
550 gui_internal_background_render(this, w);
553 pnt.x+=w->w/2-w->img->hot.x;
554 pnt.y+=w->h/2-w->img->hot.y;
555 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
560 gui_internal_label_render(struct gui_priv *this, struct widget *w)
562 struct point pnt=w->p;
563 gui_internal_background_render(this, w);
565 if (w->flags & gravity_right) {
566 pnt.y+=w->h-this->spacing;
567 pnt.x+=w->w-w->textw-this->spacing;
568 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
570 pnt.y+=w->h-this->spacing;
571 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
577 * @brief A text box is a widget that renders a text string containing newlines.
578 * The string will be broken up into label widgets at each newline with a vertical layout.
581 static struct widget *
582 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
584 char *s=g_strdup(text),*s2,*tok;
585 struct widget *ret=gui_internal_box_new(this, flags);
587 while ((tok=strtok(s2,"\n"))) {
588 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
591 gui_internal_widget_pack(this,ret);
596 static struct widget *
597 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)
599 struct widget *ret=NULL;
600 ret=gui_internal_box_new(this, flags);
603 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
605 gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
609 ret->state |= STATE_SENSITIVE;
610 ret->speech=g_strdup(text);
618 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
625 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
626 is_on=curr.u.data == w->on.u.data;
629 if (is_on != w->is_on) {
633 l=g_list_first(w->children);
637 graphics_image_free(this->gra, wi->img);
638 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
640 if (w->is_on && w->off.type == attr_none)
641 w->state &= ~STATE_SENSITIVE;
643 w->state |= STATE_SENSITIVE;
650 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
652 if (gui_internal_button_attr_update(this, w))
653 gui_internal_widget_render(this, w);
656 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
659 w->set_attr(w->instance, &w->off);
661 w->set_attr(w->instance, &w->on);
662 gui_internal_button_attr_update(this, w);
666 static struct widget *
667 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
669 struct graphics_image *image=image_new_xs(this, "gui_inactive");
671 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
676 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
677 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
678 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
679 ret->instance=this->nav;
680 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on->type, this, ret);
681 navit_add_callback(this->nav, ret->cb);
682 gui_internal_button_attr_update(this, ret);
686 static struct widget *
687 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)
689 struct graphics_image *image=image_new_xs(this, "gui_inactive");
691 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
697 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
698 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
699 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
702 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on->type, this, ret);
703 map_add_callback(map, ret->cb);
704 gui_internal_button_attr_update(this, ret);
708 static struct widget *
709 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
711 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
714 //##############################################################################################################
717 //# Authors: Martin Schaller (04/2008)
718 //##############################################################################################################
719 static void gui_internal_clear(struct gui_priv *this)
721 struct graphics *gra=this->gra;
725 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
728 static struct widget *
729 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
731 struct widget *ret,*child;
732 GList *l=wi->children;
739 if ( wi->p.x + wi->w < p->x)
741 if ( wi->p.y + wi->h < p->y)
744 if (wi->state & flags)
748 ret=gui_internal_find_widget(child, p, flags);
759 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
761 if (found == this->highlighted)
764 graphics_draw_mode(this->gra, draw_mode_begin);
765 if (this->highlighted) {
766 this->highlighted->state &= ~STATE_HIGHLIGHTED;
767 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
768 gui_internal_widget_render(this, this->highlighted);
769 this->highlighted=NULL;
770 this->highlighted_menu=NULL;
773 this->highlighted=found;
774 this->highlighted_menu=g_list_last(this->root.children)->data;
775 this->highlighted->state |= STATE_HIGHLIGHTED;
776 gui_internal_widget_render(this, this->highlighted);
777 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
779 graphics_draw_mode(this->gra, draw_mode_end);
781 //##############################################################################################################
784 //# Authors: Martin Schaller (04/2008)
785 //##############################################################################################################
786 static void gui_internal_highlight(struct gui_priv *this)
788 struct widget *menu,*found=NULL;
789 if (this->current.x > -1 && this->current.y > -1) {
790 menu=g_list_last(this->root.children)->data;
791 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
793 gui_internal_highlight_do(this, found);
794 this->motion_timeout_event=NULL;
797 static struct widget *
798 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, char *label)
800 struct widget *widget=g_new0(struct widget, 1);
803 widget->text=g_strdup(label);
804 widget->type=widget_box;
809 static struct widget *
810 gui_internal_box_new(struct gui_priv *this, enum flags flags)
812 return gui_internal_box_new_with_label(this, flags, NULL);
816 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
821 gui_internal_background_render(this, w);
823 if (w->foreground && w->border) {
826 pnt[1].x=pnt[0].x+w->w;
828 pnt[2].x=pnt[0].x+w->w;
829 pnt[2].y=pnt[0].y+w->h;
831 pnt[3].y=pnt[0].y+w->h;
833 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
834 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
835 graphics_gc_set_linewidth(w->foreground, 1);
842 gui_internal_widget_render(this, wc);
849 * @brief Compute the size and location for the widget.
853 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
856 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;
858 int orientation=w->flags & 0xffff0000;
863 height=navit_get_height(this->nav);
864 width=navit_get_width(this->nav);
865 if ( (height/width) > 1.0 )
875 * count the number of children
882 if (orientation == orientation_horizontal_vertical && count <= cols)
883 orientation=orientation_horizontal;
884 switch (orientation) {
885 case orientation_horizontal:
887 * For horizontal orientation:
888 * pack each child and find the largest height and
889 * compute the total width. x spacing (spx) is considered
891 * If any children want to be expanded
892 * we keep track of this
897 gui_internal_widget_pack(this, wc);
901 if (wc->flags & flags_expand)
902 expand+=wc->w ? wc->w : 1;
908 if (expand && w->w) {
909 expand=100*(w->w-width+expand)/expand;
914 case orientation_vertical:
916 * For vertical layouts:
917 * We pack each child and compute the largest width and
918 * the total height. y spacing (spy) is considered
920 * If the expand flag is set then teh expansion amount
926 gui_internal_widget_pack(this, wc);
930 if (wc->flags & flags_expand)
931 expand+=wc->h ? wc->h : 1;
937 if (expand && w->h) {
938 expand=100*(w->h-height+expand)/expand;
943 case orientation_horizontal_vertical:
945 * For horizontal_vertical orientation
947 * Compute the largest height and largest width.
948 * Layout the widgets based on having the
949 * number of columns specified by (cols)
955 gui_internal_widget_pack(this, wc);
965 rows=(count+cols-1)/cols;
968 width+=w->spx*(cols-1);
969 height+=w->spy*(rows-1);
976 * No orientation was specified.
977 * width and height are both 0.
978 * The width & height of this widget
982 dbg(0,"Warning width and height of a widget are 0");
985 if (! w->w && ! w->h) {
986 w->w=w->bl+w->br+width;
987 w->h=w->bt+w->bb+height;
991 * At this stage the width and height of this
992 * widget has been computed.
993 * We now make a second pass assigning heights,
994 * widths and coordinates to each child widget.
997 if (w->flags & gravity_left)
999 if (w->flags & gravity_xcenter)
1000 x=w->p.x+w->w/2-owidth/2;
1001 if (w->flags & gravity_right)
1002 x=w->p.x+w->w-w->br-owidth;
1003 if (w->flags & gravity_top)
1005 if (w->flags & gravity_ycenter)
1006 y=w->p.y+w->h/2-oheight/2;
1007 if (w->flags & gravity_bottom)
1008 y=w->p.y+w->h-w->bb-oheight;
1010 switch (orientation) {
1011 case orientation_horizontal:
1016 if (wc->flags & flags_fill)
1018 if (wc->flags & flags_expand) {
1021 wc->w=wc->w*expand/100;
1023 if (w->flags & gravity_top)
1025 if (w->flags & gravity_ycenter)
1027 if (w->flags & gravity_bottom)
1033 case orientation_vertical:
1038 if (wc->flags & flags_fill)
1040 if (wc->flags & flags_expand) {
1043 wc->h=wc->h*expand/100;
1045 if (w->flags & gravity_left)
1047 if (w->flags & gravity_xcenter)
1049 if (w->flags & gravity_right)
1055 case orientation_horizontal_vertical:
1065 if (wc->flags & flags_fill) {
1069 if (w->flags & gravity_left)
1071 if (w->flags & gravity_xcenter)
1072 wc->p.x=x+(width-wc->w)/2;
1073 if (w->flags & gravity_right)
1074 wc->p.x=x+width-wc->w;
1075 if (w->flags & gravity_top)
1077 if (w->flags & gravity_ycenter)
1078 wc->p.y=y+(height-wc->h)/2;
1079 if (w->flags & gravity_bottom)
1080 wc->p.y=y-height-wc->h;
1082 if (++count == cols) {
1094 * Call pack again on each child,
1095 * the child has now had its size and coordinates
1096 * set so they can repack their children.
1101 gui_internal_widget_pack(this, wc);
1107 gui_internal_widget_append(struct widget *parent, struct widget *child)
1111 if (! child->background)
1112 child->background=parent->background;
1113 parent->children=g_list_append(parent->children, child);
1116 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1118 if (! child->background)
1119 child->background=parent->background;
1120 parent->children=g_list_prepend(parent->children, child);
1123 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1131 gui_internal_widget_destroy(this, wc);
1134 g_list_free(w->children);
1138 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1140 gui_internal_widget_children_destroy(this, w);
1144 graphics_image_free(this->gra, w->img);
1150 w->data_free(w->data);
1151 if (w->cb && w->remove_cb)
1152 w->remove_cb(w->instance, w->cb);
1161 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1163 if(w->p.x > navit_get_width(this->nav) || w->p.y > navit_get_height(this->nav))
1168 gui_internal_box_render(this, w);
1171 gui_internal_label_render(this, w);
1174 gui_internal_image_render(this, w);
1177 gui_internal_table_render(this,w);
1185 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1189 gui_internal_box_pack(this, w);
1192 gui_internal_table_pack(this,w);
1198 //##############################################################################################################
1201 //# Authors: Martin Schaller (04/2008)
1202 //##############################################################################################################
1203 static void gui_internal_call_highlighted(struct gui_priv *this)
1205 if (! this->highlighted || ! this->highlighted->func)
1207 this->highlighted->reason=1;
1208 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1212 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1214 char *text=w->speech;
1222 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1223 navit_say(this->nav, text);
1229 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1233 gui_internal_search_idle_end(this);
1234 while ((l = g_list_last(this->root.children))) {
1236 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1237 gui_internal_say(this, w, 0);
1238 redisplay=w->menu_data->redisplay;
1239 wr=w->menu_data->redisplay_widget;
1240 if (!w->menu_data->redisplay) {
1241 gui_internal_widget_render(this, w);
1244 gui_internal_widget_destroy(this, l->data);
1245 this->root.children=g_list_remove(this->root.children, l->data);
1246 redisplay(this, wr, wr->data);
1249 gui_internal_widget_destroy(this, l->data);
1250 this->root.children=g_list_remove(this->root.children, l->data);
1255 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1258 gui_internal_search_idle_end(this);
1259 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1260 gui_internal_widget_destroy(this, l->data);
1261 this->root.children=g_list_remove(this->root.children, l->data);
1264 gui_internal_say(this, l->data, 0);
1265 gui_internal_widget_render(this, l->data);
1270 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1272 gui_internal_prune_menu_count(this, 1, 1);
1276 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1278 gui_internal_prune_menu(this, wm->data);
1282 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1284 gui_internal_prune_menu(this, this->root.children->data);
1287 static struct widget *
1288 gui_internal_top_bar(struct gui_priv *this)
1290 struct widget *w,*wm,*wh,*wc,*wcn;
1291 int dots_len, sep_len;
1293 int width,width_used=0,use_sep=0,incomplete=0;
1294 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1296 1:Don't expand bar to screen width
1297 2:Don't show Map Icon
1298 4:Don't show Home Icon
1299 8:Show only current menu
1300 16:Don't use menu titles as button
1301 32:Show navit version
1304 256:Use background for menu headline
1305 512:Set osd_configuration and zoom to route when setting position
1308 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1309 w->bl=this->spacing;
1310 w->spx=this->spacing;
1311 w->background=this->background2;
1312 if ((this->flags & 6) == 6) {
1318 width=this->root.w-w->bl;
1319 if (! (this->flags & 2)) {
1320 wm=gui_internal_button_new_with_callback(this, NULL,
1321 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1322 gui_internal_cmd_return, NULL);
1323 wm->speech=g_strdup(_("Back to map"));
1324 gui_internal_widget_pack(this, wm);
1325 gui_internal_widget_append(w, wm);
1328 if (! (this->flags & 4)) {
1329 wh=gui_internal_button_new_with_callback(this, NULL,
1330 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1331 gui_internal_cmd_main_menu, NULL);
1332 wh->speech=g_strdup(_("Main Menu"));
1333 gui_internal_widget_pack(this, wh);
1334 gui_internal_widget_append(w, wh);
1337 if (!(this->flags & 6))
1339 l=g_list_last(this->root.children);
1340 wcn=gui_internal_label_new(this,".. »");
1341 wcn->foreground=foreground;
1343 gui_internal_widget_destroy(this, wcn);
1344 wcn=gui_internal_label_new(this,"»");
1345 wcn->foreground=foreground;
1347 gui_internal_widget_destroy(this, wcn);
1349 if (g_list_previous(l) || !g_list_next(l)) {
1351 wcn=gui_internal_label_new(this, wc->text);
1352 wcn->foreground=foreground;
1357 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1358 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1360 gui_internal_widget_destroy(this, wcn);
1364 struct widget *wct=gui_internal_label_new(this, "»");
1365 wct->foreground=foreground;
1366 res=g_list_prepend(res, wct);
1367 width_used+=sep_len+w->spx;
1370 if (!(this->flags & 16)) {
1371 wcn->func=gui_internal_cmd_return;
1373 wcn->state |= STATE_SENSITIVE;
1375 res=g_list_prepend(res, wcn);
1376 if (this->flags & 8)
1379 l=g_list_previous(l);
1383 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1384 wcn->foreground=foreground;
1385 wcn->func=gui_internal_cmd_return;
1387 wcn->state |= STATE_SENSITIVE;
1388 res=g_list_prepend(res, wcn);
1389 l=g_list_previous(l);
1392 wcn=gui_internal_label_new(this, ".. »");
1393 wcn->foreground=foreground;
1394 wcn->func=gui_internal_cmd_return;
1396 wcn->state |= STATE_SENSITIVE;
1397 res=g_list_prepend(res, wcn);
1401 gui_internal_widget_append(w, l->data);
1404 if (this->flags & 32) {
1405 extern char *version;
1406 char *version_text=g_strdup_printf("Navit %s",version);
1407 wcn=gui_internal_label_new(this, version_text);
1408 g_free(version_text);
1409 wcn->flags=gravity_right_center|flags_expand;
1410 gui_internal_widget_append(w, wcn);
1414 gui_internal_widget_destroy(this, dots);
1419 static struct widget *
1420 gui_internal_time_help(struct gui_priv *this)
1422 struct widget *w,*wm,*wh,*wc,*wcn;
1423 int dots_len, sep_len;
1425 int width,width_used=0,use_sep,incomplete=0;
1430 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1431 w->bl=this->spacing;
1432 w->spx=this->spacing;
1438 if (this->flags & 64) {
1439 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1445 tm=localtime(&timep);
1446 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1447 wcn=gui_internal_label_new(this, timestr);
1448 gui_internal_widget_append(wc, wcn);
1449 gui_internal_widget_append(w, wc);
1451 if (this->flags & 128) {
1452 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1453 gui_internal_widget_append(w, wcn);
1460 * Applys the configuration values to this based on the settings
1461 * specified in the configuration file (this->config) and
1462 * the most approriate default profile based on screen resolution.
1464 * This function should be run after this->root is setup and could
1465 * be rerun after the window is resized.
1467 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1469 static void gui_internal_apply_config(struct gui_priv *this)
1471 struct gui_config_settings * current_config=0;
1473 dbg(0,"w=%d h=%d\n", this->root.w, this->root.h);
1475 * Select default values from profile based on the screen.
1477 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1479 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1481 current_config = &config_profiles[LARGE_PROFILE];
1485 current_config = &config_profiles[MEDIUM_PROFILE];
1490 current_config = &config_profiles[SMALL_PROFILE];
1494 * Apply override values from config file
1496 if(this->config.font_size == -1 )
1498 this->font_size = current_config->font_size;
1502 this->font_size = this->config.font_size;
1505 if(this->config.icon_xs == -1 )
1507 this->icon_xs = current_config->icon_xs;
1511 this->icon_xs = this->config.icon_xs;
1514 if(this->config.icon_s == -1 )
1516 this->icon_s = current_config->icon_s;
1520 this->icon_s = this->config.icon_s;
1522 if(this->config.icon_l == -1 )
1524 this->icon_l = current_config->icon_l;
1528 this->icon_l = this->config.icon_l;
1530 if(this->config.spacing == -1 )
1532 this->spacing = current_config->spacing;
1536 this->spacing = current_config->spacing;
1541 static struct widget *
1542 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1544 struct widget *wl,*wlb;
1545 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1546 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1547 wl=gui_internal_label_new(this, label);
1549 wlb->foreground=this->text_foreground;
1554 gui_internal_widget_append(wlb, wl);
1556 gui_internal_widget_prepend(wb, wlb);
1558 gui_internal_widget_append(wb, wlb);
1564 static struct widget *
1565 gui_internal_menu(struct gui_priv *this, char *label)
1567 struct widget *menu,*w,*w1,*topbox;
1569 gui_internal_search_idle_end(this);
1570 topbox=gui_internal_box_new_with_label(this, 0, label);
1571 topbox->w=this->root.w;
1572 topbox->h=this->root.h;
1573 gui_internal_widget_append(&this->root, topbox);
1574 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1575 menu->w=this->root.w;
1576 menu->h=this->root.h;
1577 menu->background=this->background;
1578 gui_internal_apply_config(this);
1579 this->font=graphics_font_new(this->gra,this->font_size,1);
1580 topbox->menu_data=g_new0(struct menu_data, 1);
1581 gui_internal_widget_append(topbox, menu);
1582 w=gui_internal_top_bar(this);
1583 gui_internal_widget_append(menu, w);
1584 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1585 w->spx=4*this->spacing;
1587 gui_internal_widget_append(menu, w);
1588 if (this->flags & 16) {
1589 struct widget *wl,*wlb,*wb,*wm=w;
1590 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1591 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1592 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1593 gui_internal_widget_append(wm, w);
1594 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1600 topbox->menu_data->button_bar=wb;
1601 gui_internal_widget_append(wm, wb);
1602 wlb=gui_internal_button_label(this,_("Back"),1);
1603 wlb->func=gui_internal_back;
1604 wlb->state |= STATE_SENSITIVE;
1606 if (this->flags & 192) {
1607 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1608 menu->w=this->root.w;
1609 menu->h=this->root.h;
1610 w1=gui_internal_time_help(this);
1611 gui_internal_widget_append(menu, w1);
1612 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1613 gui_internal_widget_append(menu, w1);
1614 gui_internal_widget_append(topbox, menu);
1615 menu->background=NULL;
1620 static struct menu_data *
1621 gui_internal_menu_data(struct gui_priv *this)
1624 struct widget *menu;
1626 l=g_list_last(this->root.children);
1628 return menu->menu_data;
1632 gui_internal_menu_render(struct gui_priv *this)
1635 struct widget *menu;
1637 l=g_list_last(this->root.children);
1639 gui_internal_say(this, menu, 0);
1640 gui_internal_widget_pack(this, menu);
1641 gui_internal_widget_render(this, menu);
1645 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1647 struct widget *w=wm->data;
1648 dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
1649 navit_set_destination(this->nav, &w->c, w->name);
1650 if (this->flags & 512) {
1652 follow.type=attr_follow;
1654 navit_set_attr(this->nav, &this->osd_configuration);
1655 navit_set_attr(this->nav, &follow);
1656 navit_zoom_to_route(this->nav, 0);
1658 gui_internal_prune_menu(this, NULL);
1662 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1664 struct widget *w=wm->data;
1665 navit_set_position(this->nav, &w->c);
1666 gui_internal_prune_menu(this, NULL);
1670 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1673 dbg(0,"text='%s'\n", widget->text);
1674 if (widget->text && strlen(widget->text))
1675 navit_add_bookmark(this->nav, &widget->c, widget->text);
1676 g_free(widget->text);
1678 l=g_list_previous(g_list_last(this->root.children));
1679 gui_internal_prune_menu(this, l->data);
1683 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1685 gui_internal_cmd_add_bookmark_do(this, widget->data);
1689 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1694 len=strlen(wm->text);
1695 dbg(1,"len=%d\n", len);
1696 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1697 wm->text[len-1]='\0';
1698 gui_internal_cmd_add_bookmark_do(this, wm);
1704 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1707 gui_internal_cmd_add_bookmark(struct gui_priv *this, struct widget *wm, void *data)
1709 struct widget *w,*wb,*wk,*wl,*we,*wnext,*wp=wm->data;
1710 wb=gui_internal_menu(this, "Add Bookmark");
1711 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1712 gui_internal_widget_append(wb, w);
1713 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1714 gui_internal_widget_append(w, we);
1715 gui_internal_widget_append(we, wk=gui_internal_label_new(this, wp->name ? wp->name : wp->text));
1716 wk->state |= STATE_EDIT|STATE_CLEAR;
1717 wk->background=this->background;
1718 wk->flags |= flags_expand|flags_fill;
1719 wk->func = gui_internal_cmd_add_bookmark_changed;
1721 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1722 wnext->state |= STATE_SENSITIVE;
1723 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1725 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1726 gui_internal_widget_append(w, wl);
1728 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1729 gui_internal_menu_render(this);
1734 get_direction(char *buffer, int angle, int mode)
1739 sprintf(buffer,"%d",angle);
1742 if (angle < 69 || angle > 291)
1744 if (angle > 111 && angle < 249)
1746 if (angle > 22 && angle < 158)
1748 if (angle > 202 && angle < 338)
1753 angle=(angle+15)/30;
1756 sprintf(buffer,"%d H", angle);
1764 enum item_type *types;
1766 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1767 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1768 {"hotel","Hotel",(enum item_type []) {
1769 type_poi_hotel,type_poi_camp_rv,
1770 type_poi_camping,type_poi_camping,
1771 type_poi_resort,type_poi_resort,
1772 type_poi_motel,type_poi_hostel,
1774 {"restaurant","Restaurant",(enum item_type []) {
1775 type_poi_bar,type_poi_picnic,
1776 type_poi_burgerking,type_poi_fastfood,
1777 type_poi_restaurant,type_poi_restaurant,
1779 {"shopping","Shopping",(enum item_type []) {
1780 type_poi_mall,type_poi_mall,
1781 type_poi_shop_grocery,type_poi_shop_grocery,
1783 {"hospital","Service",(enum item_type []) {
1784 type_poi_marina,type_poi_marina,
1785 type_poi_hospital,type_poi_hospital,
1786 type_poi_public_utilities,type_poi_public_utilities,
1787 type_poi_police,type_poi_autoservice,
1788 type_poi_information,type_poi_information,
1789 type_poi_personal_service,type_poi_repair_service,
1790 type_poi_rest_room,type_poi_rest_room,
1791 type_poi_restroom,type_poi_restroom,
1793 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1794 {"peak","Land Features",(enum item_type []){
1795 type_poi_land_feature,type_poi_rock,
1796 type_poi_dam,type_poi_dam,
1798 {"unknown","Other",(enum item_type []){
1799 type_point_unspecified,type_poi_land_feature-1,
1800 type_poi_rock+1,type_poi_fuel-1,
1801 type_poi_marina+1,type_poi_car_parking-1,
1802 type_poi_car_parking+1,type_poi_bar-1,
1803 type_poi_bank+1,type_poi_dam-1,
1804 type_poi_dam+1,type_poi_information-1,
1805 type_poi_information+1,type_poi_mall-1,
1806 type_poi_mall+1,type_poi_personal_service-1,
1807 type_poi_restaurant+1,type_poi_restroom-1,
1808 type_poi_restroom+1,type_poi_shop_grocery-1,
1809 type_poi_shop_grocery+1,type_poi_motel-1,
1810 type_poi_hostel+1,type_selected_point,
1814 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1816 static struct widget *
1817 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1819 struct widget *wl,*wb;
1821 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1822 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1823 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1824 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1825 gui_internal_cmd_pois, &selectors[i]));
1832 static struct widget *
1833 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1842 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1844 sprintf(distbuf,"%d", dist/1000);
1845 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1846 type=item_to_name(item->type);
1847 if (item_attr_get(item, attr_label, &attr)) {
1848 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1851 wl->name=g_strdup(type);
1853 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
1854 gui_internal_widget_append(wl, gui_internal_label_new(this, text));
1861 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1863 const struct widget *wa=a;
1864 const struct widget *wb=b;
1865 struct widget *wac=wa->children->data;
1866 struct widget *wbc=wb->children->data;
1875 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1877 enum item_type *types;
1878 if (type >= type_line)
1880 if (! sel || !sel->types)
1883 while (*types != type_none) {
1884 if (type >= types[0] && type <= types[1]) {
1892 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
1895 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
1897 struct map_selection *sel,*selm;
1898 struct coord c,center;
1899 struct mapset_handle *h;
1901 struct map_rect *mr;
1903 int idist,dist=20000;
1904 struct widget *wi,*w,*w2,*wb;
1905 enum projection pro=wm->c.pro;
1906 struct selector *isel=wm->data;
1908 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
1909 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1910 gui_internal_widget_append(wb, w);
1912 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
1913 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1914 gui_internal_widget_append(w, w2);
1916 sel=map_selection_rect_new(&wm->c, dist, 18);
1919 h=mapset_open(navit_get_mapset(this->nav));
1920 while ((m=mapset_next(h, 1))) {
1921 selm=map_selection_dup_pro(sel, pro, map_projection(m));
1922 mr=map_rect_new(m, selm);
1923 dbg(2,"mr=%p\n", mr);
1925 while ((item=map_rect_get_item(mr))) {
1926 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
1927 item_coord_get_pro(item, &c, 1, pro) &&
1928 coord_rect_contains(&sel->u.c_rect, &c) &&
1929 (idist=transform_distance(pro, ¢er, &c)) < dist) {
1930 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
1931 wi->func=gui_internal_cmd_position;
1934 wi->state |= STATE_SENSITIVE;
1940 map_rect_destroy(mr);
1942 map_selection_destroy(selm);
1944 map_selection_destroy(sel);
1946 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
1947 gui_internal_menu_render(this);
1951 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
1953 struct widget *w=wm->data;
1954 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
1956 graphics_clear_selection(this->gra, NULL);
1957 graphics_add_selection(this->gra, &w->item, NULL);
1959 navit_set_center(this->nav, &w->c);
1960 gui_internal_prune_menu(this, NULL);
1965 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
1967 struct widget *w,*wb;
1968 struct map_rect *mr;
1973 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
1974 wb=gui_internal_menu(this, "Attributes");
1975 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1976 gui_internal_widget_append(wb, w);
1977 mr=map_rect_new(wm->item.map, NULL);
1978 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
1979 dbg(0,"item=%p\n", item);
1981 while(item_attr_get(item, attr_any, &attr)) {
1982 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
1983 gui_internal_widget_append(w,
1984 wb=gui_internal_button_new_with_callback(this, text,
1985 NULL, gravity_left_center|orientation_horizontal|flags_fill,
1986 gui_internal_cmd_view_attributes, NULL));
1990 map_rect_destroy(mr);
1991 gui_internal_menu_render(this);
1995 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
1997 struct map_rect *mr;
2002 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2003 mr=map_rect_new(wm->item.map, NULL);
2004 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2005 dbg(0,"item=%p\n", item);
2007 while(item_attr_get(item, attr_url_local, &attr)) {
2009 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2012 map_rect_destroy(mr);
2017 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2023 /* wm->data: 0 Nothing special
2031 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2033 struct widget *wb,*w,*wc,*wbc;
2037 int display_attributes=(wm->data == (void *)2);
2038 int display_view_on_map=(wm->data != (void *)1);
2039 int display_items=(wm->data == (void *)1);
2040 int display_streets=(wm->data == (void *)3);
2041 if (wm->data == (void *)4) {
2042 gui_internal_search_town_in_country(this, wm);
2046 switch ((int)wm->data) {
2051 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2052 transform_to_geo(wm->c.pro, &c, &g);
2063 name=wm->name ? wm->name : wm->text;
2064 wb=gui_internal_menu(this, name);
2065 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2066 gui_internal_widget_append(wb, w);
2067 coord=coordinates(&wm->c, ' ');
2068 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2070 if (display_streets) {
2071 gui_internal_widget_append(w,
2072 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2073 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2074 gui_internal_search_street_in_town, wm));
2077 if (display_attributes) {
2078 struct map_rect *mr;
2081 mr=map_rect_new(wm->item.map, NULL);
2082 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2084 if (item_attr_get(item, attr_description, &attr))
2085 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2086 if (item_attr_get(item, attr_url_local, &attr)) {
2087 gui_internal_widget_append(w,
2088 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2089 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2090 gui_internal_cmd_view_in_browser, NULL));
2093 gui_internal_widget_append(w,
2094 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2095 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2096 gui_internal_cmd_view_attributes, NULL));
2099 map_rect_destroy(mr);
2101 gui_internal_widget_append(w,
2102 gui_internal_button_new_with_callback(this, _("Set as destination"),
2103 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2104 gui_internal_cmd_set_destination, wm));
2105 gui_internal_widget_append(w,
2106 gui_internal_button_new_with_callback(this, _("Set as position"),
2107 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2108 gui_internal_cmd_set_position, wm));
2109 gui_internal_widget_append(w,
2110 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2111 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2112 gui_internal_cmd_add_bookmark, wm));
2114 gui_internal_widget_append(w,
2115 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2116 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2117 gui_internal_cmd_pois, NULL));
2120 gui_internal_widget_append(w,
2121 gui_internal_button_new(this, "Add to tour",
2122 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2123 gui_internal_widget_append(w,
2124 gui_internal_button_new(this, "Add as bookmark",
2125 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2127 if (display_view_on_map) {
2128 gui_internal_widget_append(w,
2129 gui_internal_button_new_with_callback(this, _("View on map"),
2130 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2131 gui_internal_cmd_view_on_map, wm));
2133 if (display_items) {
2136 struct mapset_handle *h;
2137 struct map_rect *mr;
2140 struct street_data *data;
2141 struct map_selection sel;
2142 struct transformation *trans;
2143 enum projection pro;
2147 trans=navit_get_trans(this->nav);
2148 pro=transform_get_projection(trans);
2149 transform_from_geo(pro, &g, &c);
2150 ms=navit_get_mapset(this->nav);
2152 sel.u.c_rect.lu.x=c.x-dist;
2153 sel.u.c_rect.lu.y=c.y+dist;
2154 sel.u.c_rect.rl.x=c.x+dist;
2155 sel.u.c_rect.rl.y=c.y-dist;
2157 sel.range=item_range_all;
2159 while ((m=mapset_next(h,1))) {
2160 mr=map_rect_new(m, &sel);
2163 while ((item=map_rect_get_item(mr))) {
2164 data=street_get_data(item);
2165 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2166 if (item_attr_get(item, attr_label, &attr)) {
2167 label=map_convert_string(m, attr.u.str);
2168 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2169 map_convert_free(label);
2171 text=g_strdup_printf("%s", item_to_name(item->type));
2172 gui_internal_widget_append(w,
2173 wc=gui_internal_button_new_with_callback(this, text,
2174 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2175 gui_internal_cmd_position, (void *)2));
2176 wc->c.x=data->c[0].x;
2177 wc->c.y=data->c[0].y;
2179 wc->name=g_strdup(text);
2183 street_data_free(data);
2185 map_rect_destroy(mr);
2190 gui_internal_menu_render(this);
2194 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2196 struct attr attr,mattr;
2197 struct map_rect *mr=NULL;
2199 char *label_full,*l,*prefix,*pos;
2200 int len,plen,hassub;
2201 struct widget *wb,*w,*wbm;
2206 wb=gui_internal_menu(this, wm->text ? wm->text : _("Bookmarks"));
2207 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2208 w->spy=this->spacing*3;
2209 gui_internal_widget_append(wb, w);
2214 plen=strlen(prefix);
2216 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2217 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2218 while ((item=map_rect_get_item(mr))) {
2219 if (item->type != type_bookmark) continue;
2220 if (!item_attr_get(item, attr_label, &attr)) continue;
2221 label_full=attr.u.str;
2222 if (!strncmp(label_full, prefix, plen)) {
2223 pos=strchr(label_full+plen, '/');
2229 len=strlen(label_full);
2231 l=g_malloc(len-plen+1);
2232 strncpy(l, label_full+plen, len-plen);
2234 if (!g_hash_table_lookup(hash, l)) {
2235 wbm=gui_internal_button_new_with_callback(this, l,
2236 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2237 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2238 if (item_coord_get(item, &c, 1)) {
2241 wbm->c.pro=map_projection(mattr.u.map);
2242 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2243 wbm->text=g_strdup(l);
2244 gui_internal_widget_append(w, wbm);
2245 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2246 wbm->prefix=g_malloc(len+2);
2247 strncpy(wbm->prefix, label_full, len+1);
2248 wbm->prefix[len+1]='\0';
2250 gui_internal_widget_destroy(this, wbm);
2257 g_hash_table_destroy(hash);
2259 gui_internal_menu_render(this);
2262 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2264 struct widget *wi,*menu;
2268 menu=g_list_last(this->root.children)->data;
2269 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2271 if (*key == NAVIT_KEY_BACKSPACE) {
2272 dbg(0,"backspace\n");
2273 if (wi->text && wi->text[0]) {
2274 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2276 text=g_strdup_printf("%s ", wi->text);
2279 if (wi->state & STATE_CLEAR) {
2280 dbg(0,"wi->state=0x%x\n", wi->state);
2283 wi->state &= ~STATE_CLEAR;
2284 dbg(0,"wi->state=0x%x\n", wi->state);
2286 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2290 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2291 gui_internal_widget_render(this, wi);
2296 wi->func(this, wi, wi->data);
2298 gui_internal_widget_render(this, wi);
2304 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2306 struct menu_data *md=gui_internal_menu_data(this);
2307 gui_internal_keypress_do(this, (char *) wm->data);
2308 if (md->keyboard_mode == 2)
2309 gui_internal_keyboard_do(this, md->keyboard, 10);
2313 gui_internal_search_idle_end(struct gui_priv *this)
2316 event_remove_idle(this->idle);
2319 if (this->idle_cb) {
2320 callback_destroy(this->idle_cb);
2326 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2328 char *text=NULL,*name=NULL;
2329 struct search_list_result *res;
2331 struct item *item=NULL;
2334 res=search_list_get_result(this->sl);
2336 gui_internal_search_idle_end(this);
2340 if (! strcmp(wm_name,"Country")) {
2341 name=res->country->name;
2342 item=&res->country->item;
2343 text=g_strdup_printf("%s", res->country->name);
2345 if (! strcmp(wm_name,"Town")) {
2346 name=res->town->name;
2347 item=&res->town->item;
2348 text=g_strdup(name);
2350 if (! strcmp(wm_name,"Street")) {
2351 name=res->street->name;
2352 item=&res->street->item;
2353 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
2356 dbg(0,"res=%s\n", res->town->name);
2358 dbg(1,"res->country->flag=%s\n", res->country->flag);
2359 gui_internal_widget_append(search_list,
2360 wc=gui_internal_button_new_with_callback(this, text,
2361 image_new_xs(this, res->country->flag), gravity_left_center|orientation_horizontal|flags_fill,
2362 gui_internal_cmd_position, param));
2365 wc->name=g_strdup(name);
2368 wc->selection_id=res->id;
2371 gui_internal_widget_pack(this, search_list);
2372 l=g_list_last(this->root.children);
2373 graphics_draw_mode(this->gra, draw_mode_begin);
2374 gui_internal_widget_render(this, l->data);
2375 graphics_draw_mode(this->gra, draw_mode_end);
2379 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2381 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2382 this->idle=event_add_idle(50,this->idle_cb);
2383 callback_call_0(this->idle_cb);
2389 * @param wm The widget that generated the event for the search changed,
2390 * if this was generated by a key on the virtual keyboard then
2391 * wm is the key button widget.
2394 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2397 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2398 gui_internal_widget_children_destroy(this, search_list);
2400 void *param=(void *)3;
2402 if (! strcmp(wm->name,"Country")) {
2406 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2408 gui_internal_search_idle_end(this);
2409 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2410 struct attr search_attr;
2413 if (! strcmp(wm->name,"Country"))
2414 search_attr.type=attr_country_all;
2415 if (! strcmp(wm->name,"Town"))
2416 search_attr.type=attr_town_name;
2417 if (! strcmp(wm->name,"Street"))
2418 search_attr.type=attr_street_name;
2419 search_attr.u.str=wm->text;
2420 search_list_search(this->sl, &search_attr, 1);
2421 gui_internal_search_idle_start(this, wm->name, search_list, param);
2423 l=g_list_last(this->root.children);
2424 gui_internal_widget_render(this, l->data);
2427 static struct widget *
2428 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)
2431 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2432 NULL, gravity_center|orientation_vertical, func, data));
2433 wk->data_free=data_free;
2434 wk->background=this->background;
2442 static struct widget *
2443 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2445 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2448 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2450 static struct widget *
2451 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2453 struct widget *wkbd,*wk;
2454 struct menu_data *md=gui_internal_menu_data(this);
2455 int i, max_w=navit_get_width(this->nav), max_h=navit_get_height(this->nav);
2461 gui_internal_highlight(this);
2463 gui_internal_widget_children_destroy(this, wkbdb);
2465 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2467 md->keyboard_mode=mode;
2468 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2469 wkbd->background=this->background;
2476 if (mode >= 0 && mode < 8) {
2477 for (i = 0 ; i < 26 ; i++) {
2478 char text[]={'A'+i,'\0'};
2479 gui_internal_keyboard_key(this, wkbd, text, text,max_w,max_h);
2481 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2483 gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
2484 gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
2485 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2487 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2488 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2490 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2493 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2495 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2497 if (mode >= 8 && mode < 16) {
2498 for (i = 0 ; i < 26 ; i++) {
2499 char text[]={'a'+i,'\0'};
2500 gui_internal_keyboard_key(this, wkbd, text, text,max_w,max_h);
2502 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2504 gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
2505 gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
2506 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2508 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2509 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2511 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2514 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2516 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2518 if (mode >= 16 && mode < 24) {
2519 for (i = 0 ; i < 10 ; i++) {
2520 char text[]={'0'+i,'\0'};
2521 gui_internal_keyboard_key(this, wkbd, text, text,max_w,max_h);
2523 gui_internal_keyboard_key(this, wkbd, ".",".",max_w,max_h);
2524 gui_internal_keyboard_key(this, wkbd, "°","°",max_w,max_h);
2525 gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
2526 gui_internal_keyboard_key(this, wkbd, "\"","\"",max_w,max_h);
2527 gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
2528 gui_internal_keyboard_key(this, wkbd, "+","+",max_w,max_h);
2529 gui_internal_keyboard_key(this, wkbd, "*","*",max_w,max_h);
2530 gui_internal_keyboard_key(this, wkbd, "/","/",max_w,max_h);
2531 gui_internal_keyboard_key(this, wkbd, "(","(",max_w,max_h);
2532 gui_internal_keyboard_key(this, wkbd, ")",")",max_w,max_h);
2533 gui_internal_keyboard_key(this, wkbd, "=","=",max_w,max_h);
2534 gui_internal_keyboard_key(this, wkbd, "?","?",max_w,max_h);
2535 for (i = 0 ; i < 5 ; i++) {
2536 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2539 gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
2540 gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
2541 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2543 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2544 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2546 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2549 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2551 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2553 if (mode >= 24 && mode < 32) {
2554 gui_internal_keyboard_key(this, wkbd, "Ä","Ä",max_w,max_h);
2555 gui_internal_keyboard_key(this, wkbd, "Ö","Ö",max_w,max_h);
2556 gui_internal_keyboard_key(this, wkbd, "Ü","Ü",max_w,max_h);
2557 gui_internal_keyboard_key(this, wkbd, "Æ","Æ",max_w,max_h);
2558 gui_internal_keyboard_key(this, wkbd, "Ø","Ø",max_w,max_h);
2559 gui_internal_keyboard_key(this, wkbd, "Ã…","Ã…",max_w,max_h);
2560 for (i = 0 ; i < 23 ; i++) {
2561 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2563 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2565 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2567 if (mode >= 32 && mode < 40) {
2568 gui_internal_keyboard_key(this, wkbd, "ä","ä",max_w,max_h);
2569 gui_internal_keyboard_key(this, wkbd, "ö","ö",max_w,max_h);
2570 gui_internal_keyboard_key(this, wkbd, "ü","ü",max_w,max_h);
2571 gui_internal_keyboard_key(this, wkbd, "æ","æ",max_w,max_h);
2572 gui_internal_keyboard_key(this, wkbd, "ø","ø",max_w,max_h);
2573 gui_internal_keyboard_key(this, wkbd, "Ã¥","Ã¥",max_w,max_h);
2574 for (i = 0 ; i < 23 ; i++) {
2575 gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
2577 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2579 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2581 gui_internal_widget_append(wkbdb, wkbd);
2583 gui_internal_widget_pack(this, wkbdb);
2584 gui_internal_widget_render(this, wkbdb);
2589 static struct widget *
2590 gui_internal_keyboard(struct gui_priv *this, int mode)
2592 if (! this->keyboard)
2594 return gui_internal_keyboard_do(this, NULL, mode);
2598 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2600 gui_internal_keyboard_do(this, key->data, key->datai);
2604 gui_internal_search_list_set_default_country(struct gui_priv *this)
2606 struct attr search_attr, country_name, country_iso2, *country_attr;
2608 struct country_search *cs;
2609 struct tracking *tracking;
2610 struct search_list_result *res;
2612 country_attr=country_default();
2613 tracking=navit_get_tracking(this->nav);
2614 if (tracking && tracking_get_current_attr(tracking, attr_country_id, &search_attr))
2615 country_attr=&search_attr;
2617 cs=country_search_new(country_attr, 0);
2618 item=country_search_get_item(cs);
2619 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2620 search_attr.type=attr_country_all;
2621 dbg(0,"country %s\n", country_name.u.str);
2622 search_attr.u.str=country_name.u.str;
2623 search_list_search(this->sl, &search_attr, 0);
2624 while((res=search_list_get_result(this->sl)));
2625 g_free(this->country_iso2);
2626 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2627 this->country_iso2=g_strdup(country_iso2.u.str);
2629 country_search_destroy(cs);
2631 dbg(0,"warning: no default country found\n");
2632 if (this->country_iso2) {
2633 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2634 search_attr.type=attr_country_iso2;
2635 search_attr.u.str=this->country_iso2;
2636 search_list_search(this->sl, &search_attr, 0);
2637 while((res=search_list_get_result(this->sl)));
2643 gui_internal_search_list_new(struct gui_priv *this)
2645 struct mapset *ms=navit_get_mapset(this->nav);
2647 this->sl=search_list_new(ms);
2648 gui_internal_search_list_set_default_country(this);
2653 gui_internal_search_list_destroy(struct gui_priv *this)
2656 search_list_destroy(this->sl);
2663 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2665 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2667 gui_internal_search_list_new(this);
2668 wb=gui_internal_menu(this, what);
2669 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2670 gui_internal_widget_append(wb, w);
2671 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2672 gui_internal_widget_append(w, wr);
2673 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2674 gui_internal_widget_append(wr, we);
2676 if (!strcmp(type,"Country")) {
2677 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2678 wnext->func=gui_internal_search_town;
2679 } else if (!strcmp(type,"Town")) {
2680 if (this->country_iso2)
2681 country=g_strdup_printf("country_%s", this->country_iso2);
2683 country=strdup("gui_select_country");
2684 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
2685 wb->state |= STATE_SENSITIVE;
2687 wb->func = gui_internal_search_country;
2689 wb->func = gui_internal_back;
2690 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
2691 wnext->func=gui_internal_search_street;
2693 } else if (!strcmp(type,"Street")) {
2694 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
2695 wb->state |= STATE_SENSITIVE;
2696 wb->func = gui_internal_back;
2698 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2700 gui_internal_widget_append(we, wnext);
2701 wnext->state |= STATE_SENSITIVE;
2703 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2704 gui_internal_widget_append(wr, wl);
2705 gui_internal_menu_data(this)->search_list=wl;
2706 wk->state |= STATE_EDIT;
2707 wk->background=this->background;
2708 wk->flags |= flags_expand|flags_fill;
2709 wk->func = gui_internal_search_changed;
2710 wk->name=g_strdup(type);
2712 gui_internal_widget_append(w, gui_internal_keyboard(this,0));
2713 gui_internal_menu_render(this);
2717 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
2719 search_list_select(this->sl, attr_town_name, 0, 0);
2720 gui_internal_search(this,_("Street"),"Street",0);
2724 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
2726 dbg(0,"id %d\n", widget->selection_id);
2727 search_list_select(this->sl, attr_town_name, 0, 0);
2728 search_list_select(this->sl, attr_town_name, widget->selection_id, 1);
2729 gui_internal_search(this,_("Street"),"Street",0);
2733 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
2736 search_list_select(this->sl, attr_country_all, 0, 0);
2737 g_free(this->country_iso2);
2738 this->country_iso2=NULL;
2739 gui_internal_search(this,_("Town"),"Town",0);
2743 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
2745 struct search_list_common *slc;
2746 dbg(0,"id %d\n", widget->selection_id);
2747 search_list_select(this->sl, attr_country_all, 0, 0);
2748 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
2750 g_free(this->country_iso2);
2751 this->country_iso2=((struct search_list_country *)slc)->iso2;
2753 gui_internal_search(this,widget->name,"Town",0);
2757 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
2759 gui_internal_prune_menu_count(this, 1, 0);
2760 gui_internal_search(this,_("Country"),"Country",0);
2764 gui_internal_cmd_town(struct gui_priv *this, struct widget *wm, void *data)
2767 search_list_select(this->sl, attr_country_all, 0, 0);
2768 gui_internal_search(this,_("Town"),"Town",1);
2772 gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm, void *data)
2775 struct widget *w,*wb,*wl;
2776 struct attr_iter *iter;
2779 wb=gui_internal_menu(this, _("Layout"));
2780 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2781 w->spy=this->spacing*3;
2782 gui_internal_widget_append(wb, w);
2783 iter=navit_attr_iter_new();
2784 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
2785 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
2787 gui_internal_widget_append(w, wl);
2789 navit_attr_iter_destroy(iter);
2790 gui_internal_menu_render(this);
2794 gui_internal_cmd_fullscreen(struct gui_priv *this, struct widget *wm, void *data)
2796 graphics_draw_mode(this->gra, draw_mode_end);
2797 this->fullscreen=!this->fullscreen;
2798 this->win->fullscreen(this->win, this->fullscreen);
2799 graphics_draw_mode(this->gra, draw_mode_begin);
2803 gui_internal_cmd_2d(struct gui_priv *this, struct widget *wm, void *data)
2805 struct transformation *trans=navit_get_trans(this->nav);
2806 transform_set_pitch(trans, 0);
2811 gui_internal_cmd_3d(struct gui_priv *this, struct widget *wm, void *data)
2813 struct transformation *trans=navit_get_trans(this->nav);
2814 transform_set_pitch(trans, this->pitch);
2819 gui_internal_cmd_display(struct gui_priv *this, struct widget *wm, void *data)
2822 struct transformation *trans;
2824 w=gui_internal_menu(this, _("Display"));
2825 gui_internal_widget_append(w,
2826 gui_internal_button_new_with_callback(this, _("Layout"),
2827 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
2828 gui_internal_cmd_layout, NULL));
2829 if (this->fullscreen) {
2830 gui_internal_widget_append(w,
2831 gui_internal_button_new_with_callback(this, _("Window Mode"),
2832 image_new_l(this, "gui_leave_fullscreen"), gravity_center|orientation_vertical,
2833 gui_internal_cmd_fullscreen, NULL));
2835 gui_internal_widget_append(w,
2836 gui_internal_button_new_with_callback(this, _("Fullscreen"),
2837 image_new_l(this, "gui_fullscreen"), gravity_center|orientation_vertical,
2838 gui_internal_cmd_fullscreen, NULL));
2840 trans=navit_get_trans(this->nav);
2841 if (transform_get_pitch(trans)) {
2842 gui_internal_widget_append(w,
2843 gui_internal_button_new_with_callback(this, _("2D"),
2844 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2845 gui_internal_cmd_2d, NULL));
2848 gui_internal_widget_append(w,
2849 gui_internal_button_new_with_callback(this, _("3D"),
2850 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2851 gui_internal_cmd_3d, NULL));
2853 gui_internal_menu_render(this);
2857 gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm, void *data)
2859 struct navit *nav=this->nav;
2861 main_remove_navit(nav);
2865 gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm, void *data)
2867 navit_set_destination(this->nav, NULL, NULL);
2872 gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm, void *data)
2874 struct widget *w,*wc;
2877 w=gui_internal_menu(this, _("Actions"));
2878 gui_internal_widget_append(w,
2879 gui_internal_button_new_with_callback(this, _("Bookmarks"),
2880 image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
2881 gui_internal_cmd_bookmarks, NULL));
2882 if (this->clickp_valid) {
2883 coord=coordinates(&this->clickp, '\n');
2884 gui_internal_widget_append(w,
2885 wc=gui_internal_button_new_with_callback(this, coord,
2886 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2887 gui_internal_cmd_position, (void *)1));
2888 wc->name=g_strdup(_("Map Point"));
2892 if (this->vehicle_valid) {
2893 coord=coordinates(&this->vehiclep, '\n');
2894 gui_internal_widget_append(w,
2895 wc=gui_internal_button_new_with_callback(this, coord,
2896 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
2897 gui_internal_cmd_position, NULL));
2898 wc->name=g_strdup(_("Vehicle Position"));
2899 wc->c=this->vehiclep;
2902 gui_internal_widget_append(w,
2903 gui_internal_button_new_with_callback(this, _("Town"),
2904 image_new_l(this, "gui_town"), gravity_center|orientation_vertical,
2905 gui_internal_cmd_town, NULL));
2906 gui_internal_widget_append(w,
2907 gui_internal_button_new_with_callback(this, _("Quit"),
2908 image_new_l(this, "gui_quit"), gravity_center|orientation_vertical,
2909 gui_internal_cmd_quit, NULL));
2911 if (navit_check_route(this->nav)) {
2912 gui_internal_widget_append(w,
2913 gui_internal_button_new_with_callback(this, _("Stop\nNavigation"),
2914 image_new_l(this, "gui_stop"), gravity_center|orientation_vertical,
2915 gui_internal_cmd_abort_navigation, NULL));
2917 gui_internal_menu_render(this);
2921 gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm, void *wdata)
2923 struct attr attr, on, off, description, type, data;
2924 struct widget *w,*wb,*wma;
2926 struct attr_iter *iter;
2929 wb=gui_internal_menu(this, _("Maps"));
2930 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2931 w->spy=this->spacing*3;
2932 gui_internal_widget_append(wb, w);
2933 iter=navit_attr_iter_new();
2934 on.type=off.type=attr_active;
2937 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
2938 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
2939 label=g_strdup(description.u.str);
2941 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
2943 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
2945 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
2947 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
2948 attr.u.map, &on, &off, 1);
2949 gui_internal_widget_append(w, wma);
2952 navit_attr_iter_destroy(iter);
2953 gui_internal_menu_render(this);
2957 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
2959 struct attr vehicle = {attr_vehicle,{wm->data}};
2960 navit_set_attr(this->nav, &vehicle);
2964 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
2966 struct widget *w,*wb,*row;
2967 struct attr attr,sat_attr;
2968 struct vehicle *v=wm->data;
2971 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
2973 wb=gui_internal_menu(this, _("Show Satellite Status"));
2974 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
2975 gui_internal_menu_data(this)->redisplay_widget=wm;
2976 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2977 gui_internal_widget_append(wb, w);
2978 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
2979 row = gui_internal_widget_table_row_new(this,gravity_left_top);
2980 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
2981 gui_internal_widget_append(row, gui_internal_label_new(this, " Elevation "));
2982 gui_internal_widget_append(row, gui_internal_label_new(this, " Azimuth "));
2983 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
2984 gui_internal_widget_append(w,row);
2985 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
2986 row = gui_internal_widget_table_row_new(this,gravity_left_top);
2987 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
2988 if (item_attr_get(attr.u.item, types[i], &sat_attr))
2989 str=g_strdup_printf("%d", sat_attr.u.num);
2992 gui_internal_widget_append(row, gui_internal_label_new(this, str));
2995 gui_internal_widget_append(w,row);
2997 gui_internal_widget_append(wb, w);
2998 gui_internal_menu_render(this);
3002 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3004 struct widget *w,*wb;
3006 struct vehicle *v=wm->data;
3007 wb=gui_internal_menu(this, _("Show NMEA Data"));
3008 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3009 gui_internal_menu_data(this)->redisplay_widget=wm;
3010 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3011 gui_internal_widget_append(wb, w);
3012 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3013 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3014 gui_internal_menu_render(this);
3019 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3021 struct widget *w,*wb;
3022 struct attr attr,active_vehicle;
3023 struct vehicle *v=wm->data;
3024 wb=gui_internal_menu(this, wm->text);
3025 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3026 gui_internal_widget_append(wb, w);
3027 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3028 active_vehicle.u.vehicle=NULL;
3029 if (active_vehicle.u.vehicle != v) {
3030 gui_internal_widget_append(w,
3031 gui_internal_button_new_with_callback(this, _("Set as active"),
3032 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3033 gui_internal_cmd_set_active_vehicle, wm->data));
3035 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3036 gui_internal_widget_append(w,
3037 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3038 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3039 gui_internal_cmd_show_satellite_status, wm->data));
3041 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3042 gui_internal_widget_append(w,
3043 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3044 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3045 gui_internal_cmd_show_nmea_data, wm->data));
3047 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3048 gui_internal_menu_render(this);
3052 gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3054 struct attr attr,vattr;
3055 struct widget *w,*wb,*wl;
3056 struct attr_iter *iter;
3057 struct attr active_vehicle;
3060 wb=gui_internal_menu(this, _("Vehicle"));
3061 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3062 w->spy=this->spacing*3;
3063 gui_internal_widget_append(wb, w);
3064 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3065 active_vehicle.u.vehicle=NULL;
3066 iter=navit_attr_iter_new();
3067 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3068 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3069 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3070 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3071 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3072 wl->text=g_strdup(vattr.u.str);
3073 gui_internal_widget_append(w, wl);
3075 navit_attr_iter_destroy(iter);
3076 gui_internal_menu_render(this);
3081 gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm, void *data)
3083 struct widget *wb,*w;
3085 wb=gui_internal_menu(this, _("Rules"));
3086 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3087 w->spy=this->spacing*3;
3088 gui_internal_widget_append(wb, w);
3091 on.type=off.type=attr_tracking;
3092 gui_internal_widget_append(w,
3093 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3097 on.type=off.type=attr_orientation;
3098 gui_internal_widget_append(w,
3099 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3103 on.type=off.type=attr_cursor;
3104 gui_internal_widget_append(w,
3105 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3107 gui_internal_menu_render(this);
3111 gui_internal_cmd_settings(struct gui_priv *this, struct widget *wm, void *data)
3115 w=gui_internal_menu(this, _("Settings"));
3116 gui_internal_widget_append(w,
3117 gui_internal_button_new_with_callback(this, _("Display"),
3118 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
3119 gui_internal_cmd_display, NULL));
3120 gui_internal_widget_append(w,
3121 gui_internal_button_new_with_callback(this, _("Maps"),
3122 image_new_l(this, "gui_maps"), gravity_center|orientation_vertical,
3123 gui_internal_cmd_maps, NULL));
3124 gui_internal_widget_append(w,
3125 gui_internal_button_new_with_callback(this, _("Vehicle"),
3126 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3127 gui_internal_cmd_vehicle, NULL));
3128 gui_internal_widget_append(w,
3129 gui_internal_button_new_with_callback(this, _("Rules"),
3130 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
3131 gui_internal_cmd_rules, NULL));
3132 gui_internal_menu_render(this);
3135 //##############################################################################################################
3138 //# Authors: Martin Schaller (04/2008)
3139 //##############################################################################################################
3140 static void gui_internal_motion(void *data, struct point *p)
3143 struct gui_priv *this=data;
3144 if (!this->root.children) {
3145 navit_handle_motion(this->nav, p);
3151 if(!this->motion_timeout_callback)
3152 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3153 if(!this->motion_timeout_event)
3154 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3158 static void gui_internal_menu_root(struct gui_priv *this)
3162 graphics_draw_mode(this->gra, draw_mode_begin);
3163 w=gui_internal_menu(this, _("Main menu"));
3164 w->spx=this->spacing*10;
3165 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Actions"),
3166 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
3167 gui_internal_cmd_actions, NULL));
3168 if (this->flags & 2) {
3169 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Show\nMap"),
3170 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3171 gui_internal_cmd_settings, NULL));
3173 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Settings"),
3174 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
3175 gui_internal_cmd_settings, NULL));
3176 gui_internal_widget_append(w, gui_internal_button_new(this, _("Tools"),
3177 image_new_l(this, "gui_tools"), gravity_center|orientation_vertical));
3179 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, "Route",
3180 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
3181 gui_internal_cmd_route, NULL));
3184 callback_list_call_attr_1(this->cbl, attr_gui, w);
3186 gui_internal_menu_render(this);
3187 graphics_draw_mode(this->gra, draw_mode_end);
3191 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3193 struct graphics *gra=this->gra;
3194 struct transformation *trans;
3196 struct attr attr,attrp;
3198 this->ignore_button=ignore;
3199 this->clickp_valid=this->vehicle_valid=0;
3201 navit_block(this->nav, 1);
3202 graphics_overlay_disable(gra, 1);
3203 trans=navit_get_trans(this->nav);
3205 transform_reverse(trans, p, &c);
3206 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3207 this->clickp.pro=transform_get_projection(trans);
3210 this->clickp_valid=1;
3212 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3213 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3214 this->vehiclep.pro=transform_get_projection(trans);
3215 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3216 this->vehiclep.x=c.x;
3217 this->vehiclep.y=c.y;
3218 this->vehicle_valid=1;
3223 this->root.background=this->background;
3224 gui_internal_menu_root(this);
3228 gui_internal_cmd_menu2(struct gui_priv *this)
3230 gui_internal_cmd_menu(this, NULL, 1);
3234 gui_internal_check_exit(struct gui_priv *this)
3236 struct graphics *gra=this->gra;
3237 if (! this->root.children) {
3238 gui_internal_search_idle_end(this);
3239 gui_internal_search_list_destroy(this);
3240 graphics_overlay_disable(gra, 0);
3241 if (!navit_block(this->nav, 0)) {
3243 navit_draw(this->nav);
3245 navit_draw_displaylist(this->nav);
3250 //##############################################################################################################
3251 //# Description: Function to handle mouse clicks and scroll wheel movement
3253 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3254 //##############################################################################################################
3255 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3257 struct gui_priv *this=data;
3258 struct graphics *gra=this->gra;
3260 dbg(1,"enter %d %d\n", pressed, button);
3261 // if still on the map (not in the menu, yet):
3262 if (!this->root.children || this->ignore_button) {
3263 this->ignore_button=0;
3264 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3265 if (!navit_handle_button(this->nav, pressed, button, p, NULL) || button >=4) // Maybe there's a better way to do this
3267 if (this->menu_on_map_click)
3268 gui_internal_cmd_menu(this, p, 0);
3273 // if already in the menu:
3277 gui_internal_highlight(this);
3282 graphics_draw_mode(gra, draw_mode_begin);
3283 gui_internal_call_highlighted(this);
3284 gui_internal_highlight(this);
3285 graphics_draw_mode(gra, draw_mode_end);
3286 gui_internal_check_exit(this);
3290 //##############################################################################################################
3293 //# Authors: Martin Schaller (04/2008)
3294 //##############################################################################################################
3295 static void gui_internal_resize(void *data, int w, int h)
3297 struct gui_priv *this=data;
3299 if( this->root.w==w && this->root.h==h)
3304 dbg(0,"w=%d h=%d children=%p\n", w, h, this->root.children);
3305 navit_handle_resize(this->nav, w, h);
3306 if (this->root.children) {
3307 gui_internal_prune_menu(this, NULL);
3308 gui_internal_menu_root(this);
3313 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
3328 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
3330 GList *l=wi->children;
3331 if (wi->state & STATE_SENSITIVE) {
3334 gui_internal_keynav_point(wi, -dx, -dy, &wp);
3336 dist1=(wp.x-p->x)*dx;
3339 dist1=(wp.y-p->y)*dy;
3347 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);
3353 if (dist1 < *distance) {
3360 struct widget *child=l->data;
3361 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
3367 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
3369 struct widget *result,*menu=g_list_last(this->root.children)->data;
3372 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3373 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
3379 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
3381 gui_internal_keynav_point(result, dx, dy, &p);
3382 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
3387 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3388 dbg(1,"result=%p\n", result);
3400 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3401 dbg(1,"wraparound result=%p\n", result);
3403 gui_internal_highlight_do(this, result);
3405 gui_internal_say(this, result, 1);
3408 //##############################################################################################################
3411 //# Authors: Martin Schaller (04/2008)
3412 //##############################################################################################################
3413 static void gui_internal_keypress(void *data, char *key)
3415 struct gui_priv *this=data;
3418 if (!this->root.children) {
3419 transform_get_size(navit_get_trans(this->nav), &w, &h);
3424 navit_set_center_screen(this->nav, &p);
3426 case NAVIT_KEY_DOWN:
3429 navit_set_center_screen(this->nav, &p);
3431 case NAVIT_KEY_LEFT:
3434 navit_set_center_screen(this->nav, &p);
3436 case NAVIT_KEY_RIGHT:
3439 navit_set_center_screen(this->nav, &p);
3441 case NAVIT_KEY_ZOOM_IN:
3442 navit_zoom_in(this->nav, 2, NULL);
3444 case NAVIT_KEY_ZOOM_OUT:
3445 navit_zoom_out(this->nav, 2, NULL);
3447 case NAVIT_KEY_RETURN:
3448 gui_internal_cmd_menu(this, NULL, 0);
3453 graphics_draw_mode(this->gra, draw_mode_begin);
3455 case NAVIT_KEY_LEFT:
3456 gui_internal_keynav_highlight_next(this,-1,0);
3458 case NAVIT_KEY_RIGHT:
3459 gui_internal_keynav_highlight_next(this,1,0);
3462 gui_internal_keynav_highlight_next(this,0,-1);
3464 case NAVIT_KEY_DOWN:
3465 gui_internal_keynav_highlight_next(this,0,1);
3467 case NAVIT_KEY_RETURN:
3468 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3469 gui_internal_call_highlighted(this);
3471 gui_internal_keypress_do(this, key);
3474 gui_internal_keypress_do(this, key);
3476 graphics_draw_mode(this->gra, draw_mode_end);
3477 gui_internal_check_exit(this);
3481 //##############################################################################################################
3484 //# Authors: Martin Schaller (04/2008)
3485 //##############################################################################################################
3486 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
3489 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
3490 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
3491 struct color cw={0xffff,0xffff,0xffff,0xffff};
3492 struct color cbl={0x0000,0x0000,0x0000,0xffff};
3493 struct transformation *trans=navit_get_trans(this->nav);
3495 win=graphics_get_data(gra, "window");
3498 navit_ignore_graphics_events(this->nav, 1);
3501 navit_ignore_graphics_events(this->nav, 1);
3502 transform_get_size(trans, &this->root.w, &this->root.h);
3503 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
3504 graphics_add_callback(gra, this->resize_cb);
3505 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
3506 graphics_add_callback(gra, this->button_cb);
3507 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
3508 graphics_add_callback(gra, this->motion_cb);
3509 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
3510 graphics_add_callback(gra, this->keypress_cb);
3511 this->background=graphics_gc_new(gra);
3512 this->background2=graphics_gc_new(gra);
3513 this->highlight_background=graphics_gc_new(gra);
3514 graphics_gc_set_foreground(this->highlight_background, &cbh);
3515 this->foreground=graphics_gc_new(gra);
3516 graphics_gc_set_foreground(this->foreground, &cf);
3517 this->text_background=graphics_gc_new(gra);
3518 this->text_foreground=graphics_gc_new(gra);
3519 graphics_gc_set_foreground(this->background, &this->background_color);
3520 graphics_gc_set_foreground(this->background2, &this->background2_color);
3521 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
3522 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
3524 // set fullscreen if needed
3525 if (this->fullscreen)
3526 this->win->fullscreen(this->win, this->fullscreen);
3530 static int gui_internal_disable_suspend(struct gui_priv *this)
3532 if (this->win->disable_suspend)
3533 this->win->disable_suspend(this->win);
3536 //##############################################################################################################
3539 //# Authors: Martin Schaller (04/2008)
3540 //##############################################################################################################
3541 struct gui_methods gui_internal_methods = {
3544 gui_internal_set_graphics,
3548 gui_internal_disable_suspend,
3552 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
3554 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
3556 *out=attr_generic_add_attr(*out, &private_data);
3560 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
3562 callback_list_add(priv->cbl, cb);
3566 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
3568 callback_list_remove(priv->cbl, cb);
3572 static struct gui_internal_methods gui_internal_methods_ext = {
3573 gui_internal_add_callback,
3574 gui_internal_remove_callback,
3575 gui_internal_menu_render,
3582 gui_internal_get_flags(struct widget *widget)
3584 return widget->flags;
3588 gui_internal_set_flags(struct widget *widget, enum flags flags)
3590 widget->flags=flags;
3594 gui_internal_get_state(struct widget *widget)
3596 return widget->state;
3600 gui_internal_set_state(struct widget *widget, int state)
3602 widget->state=state;
3606 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
3612 gui_internal_set_data(struct widget *widget, void *data)
3618 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
3620 widget->background=this->background;
3623 static struct gui_internal_widget_methods gui_internal_widget_methods = {
3624 gui_internal_widget_append,
3625 gui_internal_button_new,
3626 gui_internal_button_new_with_callback,
3627 gui_internal_box_new,
3628 gui_internal_label_new,
3629 gui_internal_image_new,
3630 gui_internal_keyboard,
3632 gui_internal_get_flags,
3633 gui_internal_set_flags,
3634 gui_internal_get_state,
3635 gui_internal_set_state,
3636 gui_internal_set_func,
3637 gui_internal_set_data,
3638 gui_internal_set_default_background,
3641 static struct command_table commands[] = {
3642 {"menu",gui_internal_cmd_menu2},
3643 {"fullscreen",gui_internal_cmd_fullscreen},
3644 {"get_data",gui_internal_get_data},
3648 //##############################################################################################################
3651 //# Authors: Martin Schaller (04/2008)
3652 //##############################################################################################################
3653 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
3655 struct gui_priv *this;
3657 *meth=gui_internal_methods;
3658 this=g_new0(struct gui_priv, 1);
3660 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
3661 this->menu_on_map_click=attr->u.num;
3663 this->menu_on_map_click=1;
3664 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
3665 dbg(0,"register\n");
3666 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
3669 if( (attr=attr_search(attrs,NULL,attr_font_size)))
3671 this->config.font_size=attr->u.num;
3675 this->config.font_size=-1;
3677 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
3679 this->config.icon_xs=attr->u.num;
3683 this->config.icon_xs=-1;
3685 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
3687 this->config.icon_l=attr->u.num;
3691 this->config.icon_l=-1;
3693 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
3695 this->config.icon_s=attr->u.num;
3699 this->config.icon_s=-1;
3701 if( (attr=attr_search(attrs,NULL,attr_spacing)))
3703 this->config.spacing=attr->u.num;
3707 this->config.spacing=-1;
3709 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
3711 this->speech=attr->u.num;
3713 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
3714 this->keyboard=attr->u.num;
3718 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
3719 this->fullscreen=attr->u.num;
3721 if( (attr=attr_search(attrs,NULL,attr_flags)))
3722 this->flags=attr->u.num;
3723 if( (attr=attr_search(attrs,NULL,attr_background_color)))
3724 this->background_color=*attr->u.color;
3726 this->background_color=(struct color){0x0,0x0,0x0,0xffff};
3727 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
3728 this->background2_color=*attr->u.color;
3730 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
3731 if( (attr=attr_search(attrs,NULL,attr_text_color)))
3732 this->text_foreground_color=*attr->u.color;
3734 this->text_foreground_color=(struct color){0xffff,0xffff,0xffff,0xffff};
3735 if( (attr=attr_search(attrs,NULL,attr_columns)))
3736 this->cols=attr->u.num;
3737 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
3738 this->osd_configuration=*attr;
3740 if( (attr=attr_search(attrs,NULL,attr_pitch)))
3741 this->pitch=attr->u.num;
3744 this->data.priv=this;
3745 this->data.gui=&gui_internal_methods_ext;
3746 this->data.widget=&gui_internal_widget_methods;
3747 this->cbl=callback_list_new();
3752 //##############################################################################################################
3755 //# Authors: Martin Schaller (04/2008)
3756 //##############################################################################################################
3757 void plugin_init(void)
3759 plugin_register_gui_type("internal", gui_internal_new);
3763 * @brief Creates a new table widget.
3765 * Creates and returns a new table widget. This function will
3766 * setup next/previous buttons as children.
3768 * @param this The graphics context.
3769 * @param flags widget sizing flags.
3770 * @returns The newly created widget
3772 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
3774 struct widget * widget = g_new0(struct widget,1);
3775 struct table_data * data = NULL;
3776 widget->type=widget_table;
3777 widget->flags=flags;
3778 widget->data = g_new0(struct table_data,1);
3779 widget->data_free=gui_internal_table_data_free;
3780 data = (struct table_data*)widget->data;
3784 data->next_button = gui_internal_button_new_with_callback
3785 (this,"Next",image_new_xs(this, "gui_active") ,
3786 gravity_left_center |orientation_vertical,
3787 gui_internal_table_button_next,NULL);
3788 data->next_button->data=widget;
3791 data->prev_button = gui_internal_button_new_with_callback
3793 image_new_xs(this, "gui_active")
3794 ,gravity_right_center |orientation_vertical,
3795 gui_internal_table_button_prev,NULL);
3797 data->prev_button->data=widget;
3801 data->button_box=gui_internal_box_new(this,
3802 gravity_center|orientation_horizontal);
3803 data->button_box->children=g_list_append(data->button_box->children,
3805 data->button_box->children=g_list_append(data->button_box->children,
3807 //data->button_box->background=this->background2;
3808 data->button_box->bl=this->spacing;
3809 widget->children=g_list_append(widget->children,data->button_box);
3810 gui_internal_widget_pack(this,data->button_box);
3818 * @brief Clears all the rows from the table.
3819 * This function removes all rows from a table.
3820 * New rows can later be added to the table.
3822 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
3825 struct table_data * table_data = (struct table_data* ) table->data;
3827 iter = table->children;
3829 if(iter->data != table_data->button_box) {
3830 struct widget * child = (struct widget*)iter->data;
3831 gui_internal_widget_destroy(this,child);
3832 if(table->children == iter) {
3833 table->children = g_list_remove(iter,iter->data);
3834 iter=table->children;
3837 iter = g_list_remove(iter,iter->data);
3840 iter = g_list_next(iter);
3844 table_data->top_row=NULL;
3845 table_data->bottom_row=NULL;
3846 if(table_data->page_headers)
3847 g_list_free(table_data->page_headers);
3848 table_data->page_headers=NULL;
3853 * Creates a new table_row widget.
3854 * @param this The graphics context
3855 * @param flags Sizing flags for the row
3856 * @returns The new table_row widget.
3858 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
3860 struct widget * widget = g_new0(struct widget,1);
3861 widget->type=widget_table_row;
3862 widget->flags=flags;
3869 * @brief Computes the column dimensions for the table.
3871 * @param w The table widget to compute dimensions for.
3873 * This function examines all of the rows and columns for the table w
3874 * and returns a list (GList) of table_column_desc elements that
3875 * describe each column of the table.
3877 * The caller is responsible for freeing the returned list.
3879 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
3882 GList * column_desc = NULL;
3883 GList * current_desc=NULL;
3884 GList * cur_row = w->children;
3885 struct widget * cur_row_widget=NULL;
3886 GList * cur_column=NULL;
3887 struct widget * cell_w=NULL;
3888 struct table_column_desc * current_cell=NULL;
3889 struct table_data * table_data=NULL;
3896 * Scroll through the the table and
3897 * 1. Compute the maximum width + height of each column across all rows.
3899 table_data = (struct table_data*) w->data;
3900 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
3902 cur_row_widget = (struct widget*) cur_row->data;
3903 current_desc = column_desc;
3904 if(cur_row_widget == table_data->button_box)
3909 for(cur_column = cur_row_widget->children; cur_column;
3910 cur_column=g_list_next(cur_column))
3912 cell_w = (struct widget*) cur_column->data;
3913 gui_internal_widget_pack(this,cell_w);
3914 if(current_desc == 0)
3916 current_cell = g_new0(struct table_column_desc,1);
3917 column_desc = g_list_append(column_desc,current_cell);
3918 current_desc = g_list_last(column_desc);
3919 current_cell->height=cell_w->h;
3920 current_cell->width=cell_w->w;
3921 total_width+=cell_w->w;
3926 current_cell = current_desc->data;
3929 if(current_cell->height < height )
3931 current_cell->height = height;
3933 if(current_cell->width < width)
3935 total_width += (width-current_cell->width);
3936 current_cell->width = width;
3941 current_desc = g_list_next(current_desc);
3951 * If the width of all columns is less than the width off
3952 * the table expand each cell proportionally.
3955 if(total_width+(this->spacing*column_count) < w->w ) {
3956 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
3957 current_cell = (struct table_column_desc*) current_desc->data;
3958 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
3967 * @brief Computes the height and width for the table.
3969 * The height and widht are computed to display all cells in the table
3970 * at the requested height/width.
3972 * @param this The graphics context
3973 * @param w The widget to pack.
3976 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
3982 GList * column_data = gui_internal_compute_table_dimensions(this,w);
3984 struct table_column_desc * cell_desc=0;
3985 struct table_data * table_data = (struct table_data*)w->data;
3987 for(current = column_data; current; current=g_list_next(current))
3989 if(table_data->button_box == current->data )
3993 cell_desc = (struct table_column_desc *) current->data;
3994 width = width + cell_desc->width + this->spacing;
3995 if(height < cell_desc->height)
3997 height = cell_desc->height ;
4003 for(current=w->children; current; current=g_list_next(current))
4005 if(current->data!= table_data->button_box)
4010 if (table_data->button_box)
4011 gui_internal_widget_pack(this,table_data->button_box);
4015 if(w->h + w->c.y > this->root.h )
4018 * Do not allow the widget to exceed the screen.
4021 w->h = this->root.h- w->c.y - height;
4026 * Deallocate column descriptions.
4028 current = column_data;
4029 while( (current = g_list_last(current)) )
4031 current = g_list_remove(current,current->data);
4039 * @brief Renders a table widget.
4041 * @param this The graphics context
4042 * @param w The table widget to render.
4044 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4049 GList * column_desc=NULL;
4050 GList * cur_row = NULL;
4051 GList * current_desc=NULL;
4052 struct table_data * table_data = (struct table_data*)w->data;
4054 int is_first_page=1;
4055 struct table_column_desc * dim=NULL;
4057 column_desc = gui_internal_compute_table_dimensions(this,w);
4061 * Skip rows that are on previous pages.
4063 cur_row = w->children;
4064 if(table_data->top_row && table_data->top_row != w->children )
4066 cur_row = table_data->top_row;
4072 * Loop through each row. Drawing each cell with the proper sizes,
4073 * at the proper positions.
4075 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4077 GList * cur_column=NULL;
4078 current_desc = column_desc;
4079 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4081 x =w->p.x+this->spacing;
4082 if(cur_row_widget == table_data->button_box )
4086 dim = (struct table_column_desc*)current_desc->data;
4088 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4091 * No more drawing space left.
4097 for(cur_column = cur_row_widget->children; cur_column;
4098 cur_column=g_list_next(cur_column))
4100 struct widget * cur_widget = (struct widget*) cur_column->data;
4101 dim = (struct table_column_desc*)current_desc->data;
4104 cur_widget->w=dim->width;
4106 cur_widget->h=dim->height;
4108 max_height = dim->height;
4109 /* We pack the widget before rendering to ensure that the x and y
4110 * coordinates get pushed down.
4112 gui_internal_widget_pack(this,cur_widget);
4113 gui_internal_widget_render(this,cur_widget);
4115 if(dim->height > max_height)
4117 max_height = dim->height;
4121 table_data->bottom_row=cur_row;
4122 current_desc = g_list_next(current_desc);
4124 if(table_data && table_data->button_box && (is_skipped || !is_first_page) )
4126 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4128 if(table_data->button_box->p.y < y )
4130 table_data->button_box->p.y=y;
4132 table_data->button_box->p.x = w->p.x;
4133 table_data->button_box->w = w->w;
4134 // table_data->button_box->h = w->h - y;
4135 // table_data->next_button->h=table_data->button_box->h;
4136 // table_data->prev_button->h=table_data->button_box->h;
4137 // table_data->next_button->c.y=table_data->button_box->c.y;
4138 // table_data->prev_button->c.y=table_data->button_box->c.y;
4140 gui_internal_widget_pack(this,table_data->button_box);
4141 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4144 table_data->button_box->p.y = w->p.y + w->h -
4145 table_data->button_box->h;
4149 table_data->next_button->state|= STATE_SENSITIVE;
4153 table_data->next_button->state&= ~STATE_SENSITIVE;
4156 if(table_data->top_row != w->children)
4158 table_data->prev_button->state|= STATE_SENSITIVE;
4162 table_data->prev_button->state&= ~STATE_SENSITIVE;
4164 gui_internal_widget_render(this,table_data->button_box);
4170 * Deallocate column descriptions.
4172 current_desc = column_desc;
4173 while( (current_desc = g_list_last(current_desc)) )
4175 current_desc = g_list_remove(current_desc,current_desc->data);
4181 * @brief Displays Route information
4183 * @li The name of the active vehicle
4184 * @param wm The button that was pressed.
4188 gui_internal_cmd_route_description(struct gui_priv * this, struct widget * wm,void *v)
4192 struct widget * menu;
4193 struct widget * row;
4196 if(! this->vehicle_cb)
4199 * Register the callback on vehicle updates.
4201 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4202 attr_position_coord_geo,this);
4203 navit_add_callback(this->nav,this->vehicle_cb);
4206 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4207 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4209 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4212 menu=gui_internal_menu(this,"Route Description");
4214 menu->free=gui_internal_route_screen_free;
4215 this->route_data.route_showing=1;
4216 this->route_data.route_table->spx = this->spacing;
4219 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4221 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4222 gui_internal_widget_append(box,this->route_data.route_table);
4224 box->spx = this->spacing;
4225 this->route_data.route_table->w=box->w;
4226 gui_internal_widget_append(menu,box);
4227 gui_internal_populate_route_table(this,this->nav);
4228 gui_internal_menu_render(this);
4233 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4236 int adx=a2->x-a1->x;
4237 int ady=a2->y-a1->y;
4238 int bdx=b2->x-b1->x;
4239 int bdy=b2->y-b1->y;
4240 n = bdy * adx - bdx * ady;
4241 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4242 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4253 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4254 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4255 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4258 res->x = a1->x + a * adx / n;
4259 res->y = a1->y + a * ady / n;
4264 struct heightline *next;
4266 struct coord_rect bbox;
4271 struct diagram_point {
4272 struct diagram_point *next;
4276 static struct heightline *
4277 item_get_heightline(struct item *item)
4279 struct heightline *ret=NULL;
4280 struct street_data *sd;
4284 if (item_attr_get(item, attr_label, &attr)) {
4285 height=atoi(attr.u.str);
4286 sd=street_get_data(item);
4287 if (sd && sd->count > 1) {
4288 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4289 ret->bbox.lu=sd->c[0];
4290 ret->bbox.rl=sd->c[0];
4291 ret->count=sd->count;
4293 for (i = 0 ; i < sd->count ; i++) {
4295 coord_rect_extend(&ret->bbox, sd->c+i);
4298 street_data_free(sd);
4305 * @brief Displays Route Height Profile
4307 * @li The name of the active vehicle
4308 * @param wm The button that was pressed.
4311 static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct widget * wm,void *v)
4315 struct widget * menu, *box;
4317 struct map * map=NULL;
4318 struct map_rect * mr=NULL;
4319 struct route * route;
4320 struct item * item =NULL;
4322 struct mapset_handle *msh;
4323 int x,i,first=1,dist=0;
4324 struct coord c,last,res;
4325 struct coord_rect rbbox,dbbox;
4326 struct map_selection sel;
4327 struct heightline *heightline,*heightlines=NULL;
4328 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4331 sel.range.min=type_height_line_1;
4332 sel.range.max=type_height_line_3;
4335 menu=gui_internal_menu(this,_("Height Profile"));
4336 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4337 gui_internal_widget_append(menu, box);
4338 route = navit_get_route(this->nav);
4340 map = route_get_map(route);
4342 mr = map_rect_new(map,NULL);
4344 while((item = map_rect_get_item(mr))) {
4345 while (item_coord_get(item, &c, 1)) {
4351 coord_rect_extend(&sel.u.c_rect, &c);
4354 map_rect_destroy(mr);
4355 ms=navit_get_mapset(this->nav);
4357 msh=mapset_open(ms);
4358 while ((map=mapset_next(msh, 1))) {
4359 mr=map_rect_new(map, &sel);
4361 while((item = map_rect_get_item(mr))) {
4362 if (item->type >= sel.range.min && item->type <= sel.range.max) {
4363 heightline=item_get_heightline(item);
4365 heightline->next=heightlines;
4366 heightlines=heightline;
4370 map_rect_destroy(mr);
4379 map = route_get_map(route);
4381 mr = map_rect_new(map,NULL);
4382 if(mr && heightlines) {
4383 while((item = map_rect_get_item(mr))) {
4385 while (item_coord_get(item, &c, 1)) {
4389 heightline=heightlines;
4392 coord_rect_extend(&rbbox, &c);
4393 while (heightline) {
4394 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
4395 for (i = 0 ; i < heightline->count - 1; i++) {
4396 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
4397 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
4398 diagram_point=g_new(struct diagram_point, 1);
4399 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
4400 diagram_point->c.y=heightline->height;
4401 diagram_point->next=diagram_points;
4402 diagram_points=diagram_point;
4403 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
4408 heightline=heightline->next;
4410 dist+=transform_distance(projection_mg, &last, &c);
4416 map_rect_destroy(mr);
4420 gui_internal_menu_render(this);
4422 diagram_point=diagram_points;
4423 while (diagram_point) {
4425 dbbox.lu=diagram_point->c;
4426 dbbox.rl=diagram_point->c;
4429 coord_rect_extend(&dbbox, &diagram_point->c);
4430 diagram_point=diagram_point->next;
4432 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
4433 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
4435 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
4437 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
4443 diagram_point=diagram_points;
4444 while (diagram_point) {
4445 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
4447 diagram_point=diagram_point->next;
4451 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
4452 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
4453 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
4454 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
4458 graphics_draw_lines(this->gra, this->foreground, p, 2);
4467 * @brief Displays Route information
4469 * @li The name of the active vehicle
4470 * @param wm The button that was pressed.
4473 void gui_internal_cmd_route(struct gui_priv * this, struct widget * wm,void *v)
4477 graphics_draw_mode(this->gra, draw_mode_begin);
4478 w=gui_internal_menu(this, _("Route"));
4479 w->spx=this->spacing*10;
4480 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Description"),
4481 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4482 gui_internal_cmd_route_description, NULL));
4483 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Height Profile"),
4484 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4485 gui_internal_cmd_route_height_profile, NULL));
4486 gui_internal_menu_render(this);
4487 gui_internal_menu_render(this);
4488 graphics_draw_mode(this->gra, draw_mode_end);
4495 * @brief handles the 'next page' table event.
4496 * A callback function that is invoked when the 'next page' button is pressed
4497 * to advance the contents of a table widget.
4499 * @param this The graphics context.
4500 * @param wm The button widget that was pressed.
4502 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
4504 struct widget * table_widget = (struct widget * ) wm->data;
4505 struct table_data * table_data = NULL;
4511 table_data = (struct table_data*) table_widget->data;
4517 * Before advancing to the next page we need to ensure
4518 * that the current top_row is in the list of previous top_rows
4519 * so previous page can work.
4522 for(iterator=table_data->page_headers; iterator != NULL;
4523 iterator = g_list_next(iterator) )
4525 if(iterator->data == table_data->top_row)
4534 table_data->page_headers=g_list_append(table_data->page_headers,
4535 table_data->top_row);
4538 table_data->top_row = g_list_next(table_data->bottom_row);
4540 wm->state&= ~STATE_HIGHLIGHTED;
4541 gui_internal_menu_render(this);
4547 * @brief handles the 'previous page' table event.
4548 * A callback function that is invoked when the 'previous page' button is pressed
4549 * to go back in the contents of a table widget.
4551 * @param this The graphics context.
4552 * @param wm The button widget that was pressed.
4554 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
4556 struct widget * table_widget = (struct widget * ) wm->data;
4557 struct table_data * table_data = NULL;
4558 GList * current_page_top=NULL;
4563 table_data = (struct table_data*) table_widget->data;
4564 current_page_top = table_data->top_row;
4567 for(iterator = table_data->page_headers; iterator != NULL;
4568 iterator = g_list_next(iterator))
4570 if(current_page_top == iterator->data)
4574 table_data->top_row = (GList*) iterator->data;
4578 wm->state&= ~STATE_HIGHLIGHTED;
4579 gui_internal_menu_render(this);
4584 * @brief deallocates a table_data structure.
4587 void gui_internal_table_data_free(void * p)
4592 * @note button_box and its children (next_button,prev_button)
4593 * have their memory managed by the table itself.
4595 struct table_data * table_data = (struct table_data*) p;
4596 g_list_free(table_data->page_headers);
4604 * @brief Called when the route is updated.
4606 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
4609 if(this->route_data.route_showing) {
4610 gui_internal_populate_route_table(this,navit);
4611 graphics_draw_mode(this->gra, draw_mode_begin);
4612 gui_internal_menu_render(this);
4613 graphics_draw_mode(this->gra, draw_mode_end);
4621 * @brief Called when the route screen is closed (deallocated).
4623 * The main purpose of this function is to remove the widgets from
4624 * references route_data because those widgets are about to be freed.
4626 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
4629 this_->route_data.route_showing=0;
4630 this_->route_data.route_table=NULL;
4637 * @brief Populates the route table with route information
4639 * @param this The gui context
4640 * @param navit The navit object
4642 void gui_internal_populate_route_table(struct gui_priv * this,
4643 struct navit * navit)
4645 struct map * map=NULL;
4646 struct map_rect * mr=NULL;
4647 struct navigation * nav = NULL;
4648 struct item * item =NULL;
4650 struct widget * label = NULL;
4651 struct widget * row = NULL;
4652 nav = navit_get_navigation(navit);
4656 map = navigation_get_map(nav);
4658 mr = map_rect_new(map,NULL);
4660 gui_internal_widget_table_clear(this,this->route_data.route_table);
4661 while((item = map_rect_get_item(mr))) {
4662 if(item_attr_get(item,attr_navigation_long,&attr)) {
4663 label = gui_internal_label_new(this,attr.u.str);
4664 row = gui_internal_widget_table_row_new(this,
4667 | orientation_horizontal);
4668 row->children=g_list_append(row->children,label);
4669 gui_internal_widget_append(this->route_data.route_table,row);