2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 //##############################################################################################################
22 //# File: gui_internal.c
23 //# Description: New "internal" GUI for use with any graphics library
24 //# Comment: Trying to make a touchscreen friendly GUI
25 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
27 //##############################################################################################################
36 #ifdef HAVE_API_WIN32_BASE
43 #include "navit_nls.h"
50 #include "transform.h"
56 #include "vehicleprofile.h"
67 #include "navit_nls.h"
68 #include "navigation.h"
69 #include "gui_internal.h"
71 #include "xmlconfig.h"
75 struct widget *search_list;
76 struct widget *keyboard;
77 struct widget *button_bar;
80 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
81 struct widget *redisplay_widget;
84 //##############################################################################################################
87 //# Authors: Martin Schaller (04/2008)
88 //##############################################################################################################
90 enum widget_type type;
91 struct graphics_gc *background,*text_background;
92 struct graphics_gc *foreground_frame;
93 struct graphics_gc *foreground;
95 struct graphics_image *img;
97 * A function to be invoked on actions.
98 * @li widget The widget that is receiving the button press.
101 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
106 * @brief A function to deallocate data
108 void (*data_free)(void *data);
111 * @brief a function that will be called as the widget is being destroyed.
112 * This function can act as a destructor for the widget. It allows for
113 * on deallocation actions to be specified on a per widget basis.
114 * This function will call g_free on the widget (if required).
116 void (*free) (struct gui_priv *this_, struct widget * w);
130 int bl,br,bt,bb,spx,spy;
134 * The number of widgets to layout horizontally when doing
135 * a orientation_horizontal_vertical layout
140 int (*set_attr)(void *, struct attr *);
141 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
142 void (*remove_cb)(void *, struct callback *cb);
149 struct menu_data *menu_data;
154 * @brief A structure to store configuration values.
156 * This structure stores configuration values for how gui elements in the internal GUI
159 struct gui_config_settings {
162 * The base size (in fractions of a point) to use for text.
166 * The size (in pixels) that xs style icons should be scaled to.
170 * The size (in pixels) that s style icons (small) should be scaled to
174 * The size (in pixels) that l style icons should be scaled to
178 * The default amount of spacing (in pixels) to place between GUI elements.
185 * Indexes into the config_profiles array.
187 const int LARGE_PROFILE=0;
188 const int MEDIUM_PROFILE=1;
189 const int SMALL_PROFILE=2;
192 * The default config profiles.
194 * [0] => LARGE_PROFILE (screens 640 in one dimension)
195 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
196 * [2] => Small profile (default)
198 static struct gui_config_settings config_profiles[]={
205 struct widget * route_table;
210 //##############################################################################################################
213 //# Authors: Martin Schaller (04/2008)
214 //##############################################################################################################
219 struct graphics *gra;
220 struct graphics_gc *background;
221 struct graphics_gc *background2;
222 struct graphics_gc *highlight_background;
223 struct graphics_gc *foreground;
224 struct graphics_gc *text_foreground;
225 struct graphics_gc *text_background;
226 struct color background_color, background2_color, text_foreground_color, text_background_color;
230 struct graphics_font *fonts[3];
231 int icon_xs, icon_s, icon_l;
233 struct widget *widgets;
237 struct widget *highlighted;
238 struct widget *highlighted_menu;
239 int clickp_valid, vehicle_valid;
240 struct pcoord clickp, vehiclep;
241 struct attr *click_coord_geo, *position_coord_geo;
242 struct search_list *sl;
244 int menu_on_map_click;
245 int signal_on_map_click;
250 * The setting information read from the configuration file.
251 * values of -1 indicate no value was specified in the config file.
253 struct gui_config_settings config;
254 struct event_idle *idle;
255 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
256 struct event_timeout *motion_timeout_event;
257 struct point current;
259 struct callback * vehicle_cb;
261 * Stores information about the route.
263 struct route_data route_data;
265 struct gui_internal_data data;
266 struct callback_list *cbl;
269 struct attr osd_configuration;
271 int flags_town,flags_street,flags_house_number;
275 struct widget *html_container;
278 int html_anchor_found;
296 struct html_tag_map {
302 {"html",html_tag_html},
303 {"img",html_tag_img},
304 {"script",html_tag_script},
309 * @brief A structure to store information about a table.
311 * The table_data widget stores pointers to extra information needed by the
314 * The table_data structure needs to be freed with data_free along with the widget.
320 * A GList pointer into a widget->children list that indicates the row
321 * currently being rendered at the top of the table.
325 * A Glist pointer into a widget->children list that indicates the row
326 * currently being rendered at the bottom of the table.
331 * A list of table_row widgets that mark the
332 * top rows for each page of the table.
333 * This is needed for the 'previous page' function of the table.
335 GList * page_headers;
338 * A container box that is the child of the table widget that contains+groups
339 * the next and previous button.
341 struct widget * button_box;
344 * A button widget to handle 'next page' requests
346 struct widget * next_button;
348 * A button widget to handle 'previous page' requests.
350 struct widget * prev_button;
354 * a pointer to the gui context.
355 * This is needed by the free function to destory the buttons.
357 struct gui_priv * this;
361 * A data structure that holds information about a column that makes up a table.
365 struct table_column_desc
369 * The computed height of a cell in the table.
374 * The computed width of a cell in the table.
380 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
381 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
382 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
383 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
384 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
385 static void gui_internal_apply_config(struct gui_priv *this);
387 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
388 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
389 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
390 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
391 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
392 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
393 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
394 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
395 static void gui_internal_table_data_free(void * d);
396 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
398 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
399 static void gui_internal_populate_route_table(struct gui_priv * this,
400 struct navit * navit);
401 static void gui_internal_search_idle_end(struct gui_priv *this);
402 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
403 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
404 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
405 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
406 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
407 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
408 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
409 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
410 static void gui_internal_check_exit(struct gui_priv *this);
411 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
413 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
414 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
416 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
417 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
420 * * Display image scaled to specific size
421 * * searches for scaleable and pre-scaled image
422 * * @param this Our gui context
423 * * @param name image name
424 * * @param w desired width of image
425 * * @param h desired height of image
426 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
428 static struct graphics_image *
429 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
431 struct graphics_image *ret=NULL;
432 char *full_name=NULL;
433 char *full_path=NULL;
436 for (i = 1 ; i < 6 ; i++) {
440 full_name=g_strdup_printf("%s.svg", name);
443 full_name=g_strdup_printf("%s.svgz", name);
446 if (w != -1 && h != -1) {
447 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
451 full_name=g_strdup_printf("%s.png", name);
454 full_name=g_strdup_printf("%s.xpm", name);
457 dbg(1,"trying '%s'\n", full_name);
461 /* needs to be checked in the driver */
462 if (!file_exists(full_name)) {
467 full_path=graphics_icon_path(full_name);
468 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
469 dbg(1,"ret=%p\n", ret);
475 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
480 static struct graphics_image *
481 image_new_o(struct gui_priv *this, char *name)
483 return image_new_scaled(this, name, -1, -1);
487 static struct graphics_image *
488 image_new_xs(struct gui_priv *this, const char *name)
490 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
494 static struct graphics_image *
495 image_new_s(struct gui_priv *this, const char *name)
497 return image_new_scaled(this, name, this->icon_s, this->icon_s);
500 static struct graphics_image *
501 image_new_l(struct gui_priv *this, const char *name)
503 return image_new_scaled(this, name, this->icon_l, this->icon_l);
507 coordinates_geo(const struct coord_geo *gc, char sep)
509 char latc='N',lngc='E';
510 int lat_deg,lat_min,lat_sec;
511 int lng_deg,lng_min,lng_sec;
512 struct coord_geo g=*gc;
523 lat_min=fmod(g.lat*60,60);
524 lat_sec=fmod(g.lat*3600,60);
526 lng_min=fmod(g.lng*60,60);
527 lng_sec=fmod(g.lng*3600,60);
528 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);
532 coordinates(struct pcoord *pc, char sep)
538 transform_to_geo(pc->pro, &c, &g);
539 return coordinates_geo(&g, sep);
544 gui_internal_background_render(struct gui_priv *this, struct widget *w)
546 struct point pnt=w->p;
547 if (w->state & STATE_HIGHLIGHTED)
548 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
551 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
555 static struct widget *
556 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
562 struct widget *widget=g_new0(struct widget, 1);
563 widget->type=widget_label;
564 widget->font_idx=font;
566 widget->text=g_strdup(text);
567 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
571 widget->h=h+this->spacing;
573 widget->w=w+this->spacing;
575 widget->flags=gravity_center;
576 widget->foreground=this->text_foreground;
577 widget->text_background=this->text_background;
582 static struct widget *
583 gui_internal_label_new(struct gui_priv *this, char *text)
585 return gui_internal_label_font_new(this, text, 0);
588 static struct widget *
589 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
591 struct widget *ret=NULL;
592 char *tmp=g_malloc(strlen(text)+3);
599 ret=gui_internal_label_new(this, tmp);
600 if (ret->w < maxwidth)
602 gui_internal_widget_destroy(this, ret);
610 static struct widget *
611 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
613 struct widget *widget=g_new0(struct widget, 1);
614 widget->type=widget_image;
617 widget->w=image->width;
618 widget->h=image->height;
624 gui_internal_image_render(struct gui_priv *this, struct widget *w)
628 gui_internal_background_render(this, w);
631 pnt.x+=w->w/2-w->img->hot.x;
632 pnt.y+=w->h/2-w->img->hot.y;
633 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
638 gui_internal_label_render(struct gui_priv *this, struct widget *w)
640 struct point pnt=w->p;
641 gui_internal_background_render(this, w);
643 if (w->flags & gravity_right) {
644 pnt.y+=w->h-this->spacing;
645 pnt.x+=w->w-w->textw-this->spacing;
646 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], w->text, &pnt, 0x10000, 0x0);
648 pnt.y+=w->h-this->spacing;
649 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], w->text, &pnt, 0x10000, 0x0);
655 * @brief A text box is a widget that renders a text string containing newlines.
656 * The string will be broken up into label widgets at each newline with a vertical layout.
659 static struct widget *
660 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
662 char *s=g_strdup(text),*s2,*tok;
663 struct widget *ret=gui_internal_box_new(this, flags);
665 while ((tok=strtok(s2,"\n"))) {
666 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
669 gui_internal_widget_pack(this,ret);
673 static struct widget *
674 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
676 return gui_internal_text_font_new(this, text, 0, flags);
680 static struct widget *
681 gui_internal_button_font_new_with_callback(struct gui_priv *this, char *text, int font, struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data)
683 struct widget *ret=NULL;
684 ret=gui_internal_box_new(this, flags);
687 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
689 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
693 ret->state |= STATE_SENSITIVE;
694 ret->speech=g_strdup(text);
701 static struct widget *
702 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)
704 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
708 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
715 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
716 is_on=curr.u.data == w->on.u.data;
719 if (is_on != w->is_on) {
723 l=g_list_first(w->children);
727 graphics_image_free(this->gra, wi->img);
728 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
730 if (w->is_on && w->off.type == attr_none)
731 w->state &= ~STATE_SENSITIVE;
733 w->state |= STATE_SENSITIVE;
740 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
742 if (gui_internal_button_attr_update(this, w))
743 gui_internal_widget_render(this, w);
746 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
749 w->set_attr(w->instance, &w->off);
751 w->set_attr(w->instance, &w->on);
752 gui_internal_button_attr_update(this, w);
756 static struct widget *
757 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
759 struct graphics_image *image=NULL;
763 image=image_new_xs(this, "gui_inactive");
764 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
769 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
770 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
771 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
772 ret->instance=this->nav;
773 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
774 navit_add_callback(this->nav, ret->cb);
775 gui_internal_button_attr_update(this, ret);
779 static struct widget *
780 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)
782 struct graphics_image *image=NULL;
784 image=image_new_xs(this, "gui_inactive");
787 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
793 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
794 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
795 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
798 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
799 map_add_callback(map, ret->cb);
800 gui_internal_button_attr_update(this, ret);
804 static struct widget *
805 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
807 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
811 //##############################################################################################################
814 //# Authors: Martin Schaller (04/2008)
815 //##############################################################################################################
816 static void gui_internal_clear(struct gui_priv *this)
818 struct graphics *gra=this->gra;
822 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
826 static struct widget *
827 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
829 struct widget *ret,*child;
830 GList *l=wi->children;
837 if ( wi->p.x + wi->w < p->x)
839 if ( wi->p.y + wi->h < p->y)
842 if (wi->state & flags)
846 ret=gui_internal_find_widget(child, p, flags);
857 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
859 if (found == this->highlighted)
862 graphics_draw_mode(this->gra, draw_mode_begin);
863 if (this->highlighted) {
864 this->highlighted->state &= ~STATE_HIGHLIGHTED;
865 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
866 gui_internal_widget_render(this, this->highlighted);
867 this->highlighted=NULL;
868 this->highlighted_menu=NULL;
871 this->highlighted=found;
872 this->highlighted_menu=g_list_last(this->root.children)->data;
873 this->highlighted->state |= STATE_HIGHLIGHTED;
874 gui_internal_widget_render(this, this->highlighted);
875 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
877 graphics_draw_mode(this->gra, draw_mode_end);
879 //##############################################################################################################
882 //# Authors: Martin Schaller (04/2008)
883 //##############################################################################################################
884 static void gui_internal_highlight(struct gui_priv *this)
886 struct widget *menu,*found=NULL;
887 if (this->current.x > -1 && this->current.y > -1) {
888 menu=g_list_last(this->root.children)->data;
889 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
891 gui_internal_highlight_do(this, found);
892 this->motion_timeout_event=NULL;
895 static struct widget *
896 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
898 struct widget *widget=g_new0(struct widget, 1);
901 widget->text=g_strdup(label);
902 widget->type=widget_box;
907 static struct widget *
908 gui_internal_box_new(struct gui_priv *this, enum flags flags)
910 return gui_internal_box_new_with_label(this, flags, NULL);
914 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
919 gui_internal_background_render(this, w);
922 w->foreground=this->foreground;
925 if (w->foreground && w->border) {
928 pnt[1].x=pnt[0].x+w->w;
930 pnt[2].x=pnt[0].x+w->w;
931 pnt[2].y=pnt[0].y+w->h;
933 pnt[3].y=pnt[0].y+w->h;
935 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
936 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
937 graphics_gc_set_linewidth(w->foreground, 1);
944 gui_internal_widget_render(this, wc);
951 * @brief Compute the size and location for the widget.
955 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
958 int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0;
960 int orientation=w->flags & 0xffff0000;
965 if ( this->root.w > this->root.h )
975 * count the number of children
982 if (orientation == orientation_horizontal_vertical && count <= cols)
983 orientation=orientation_horizontal;
984 switch (orientation) {
985 case orientation_horizontal:
987 * For horizontal orientation:
988 * pack each child and find the largest height and
989 * compute the total width. x spacing (spx) is considered
991 * If any children want to be expanded
992 * we keep track of this
997 gui_internal_widget_pack(this, wc);
1001 if (wc->flags & flags_expand)
1002 expand+=wc->w ? wc->w : 1;
1008 if (expand && w->w) {
1009 expandd=w->w-width+expand;
1014 case orientation_vertical:
1016 * For vertical layouts:
1017 * We pack each child and compute the largest width and
1018 * the total height. y spacing (spy) is considered
1020 * If the expand flag is set then teh expansion amount
1026 gui_internal_widget_pack(this, wc);
1030 if (wc->flags & flags_expand)
1031 expand+=wc->h ? wc->h : 1;
1037 if (expand && w->h) {
1038 expandd=w->h-height+expand;
1043 case orientation_horizontal_vertical:
1045 * For horizontal_vertical orientation
1046 * pack the children.
1047 * Compute the largest height and largest width.
1048 * Layout the widgets based on having the
1049 * number of columns specified by (cols)
1055 gui_internal_widget_pack(this, wc);
1065 rows=(count+cols-1)/cols;
1068 width+=w->spx*(cols-1);
1069 height+=w->spy*(rows-1);
1076 * No orientation was specified.
1077 * width and height are both 0.
1078 * The width & height of this widget
1082 dbg(0,"Warning width and height of a widget are 0");
1085 if (! w->w && ! w->h) {
1086 w->w=w->bl+w->br+width;
1087 w->h=w->bt+w->bb+height;
1096 * At this stage the width and height of this
1097 * widget has been computed.
1098 * We now make a second pass assigning heights,
1099 * widths and coordinates to each child widget.
1102 if (w->flags & gravity_left)
1104 if (w->flags & gravity_xcenter)
1105 x=w->p.x+w->w/2-owidth/2;
1106 if (w->flags & gravity_right)
1107 x=w->p.x+w->w-w->br-owidth;
1108 if (w->flags & gravity_top)
1110 if (w->flags & gravity_ycenter)
1111 y=w->p.y+w->h/2-oheight/2;
1112 if (w->flags & gravity_bottom)
1113 y=w->p.y+w->h-w->bb-oheight;
1115 switch (orientation) {
1116 case orientation_horizontal:
1121 if (wc->flags & flags_fill)
1123 if (wc->flags & flags_expand) {
1126 wc->w=wc->w*expandd/expand;
1128 if (w->flags & gravity_top)
1130 if (w->flags & gravity_ycenter)
1132 if (w->flags & gravity_bottom)
1138 case orientation_vertical:
1143 if (wc->flags & flags_fill)
1145 if (wc->flags & flags_expand) {
1148 wc->h=wc->h*expandd/expand;
1150 if (w->flags & gravity_left)
1152 if (w->flags & gravity_xcenter)
1154 if (w->flags & gravity_right)
1160 case orientation_horizontal_vertical:
1170 if (wc->flags & flags_fill) {
1174 if (w->flags & gravity_left)
1176 if (w->flags & gravity_xcenter)
1177 wc->p.x=x+(width-wc->w)/2;
1178 if (w->flags & gravity_right)
1179 wc->p.x=x+width-wc->w;
1180 if (w->flags & gravity_top)
1182 if (w->flags & gravity_ycenter)
1183 wc->p.y=y+(height-wc->h)/2;
1184 if (w->flags & gravity_bottom)
1185 wc->p.y=y-height-wc->h;
1187 if (++count == cols) {
1199 * Call pack again on each child,
1200 * the child has now had its size and coordinates
1201 * set so they can repack their children.
1206 gui_internal_widget_pack(this, wc);
1212 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1220 gui_internal_widget_reset_pack(this, wc);
1230 gui_internal_widget_append(struct widget *parent, struct widget *child)
1234 if (! child->background)
1235 child->background=parent->background;
1236 parent->children=g_list_append(parent->children, child);
1239 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1241 if (! child->background)
1242 child->background=parent->background;
1243 parent->children=g_list_prepend(parent->children, child);
1246 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1254 gui_internal_widget_destroy(this, wc);
1257 g_list_free(w->children);
1261 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1263 gui_internal_widget_children_destroy(this, w);
1268 graphics_image_free(this->gra, w->img);
1274 w->data_free(w->data);
1275 if (w->cb && w->remove_cb)
1276 w->remove_cb(w->instance, w->cb);
1285 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1287 if(w->p.x > this->root.w || w->p.y > this->root.h)
1292 gui_internal_box_render(this, w);
1295 gui_internal_label_render(this, w);
1298 gui_internal_image_render(this, w);
1301 gui_internal_table_render(this,w);
1309 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1313 gui_internal_box_pack(this, w);
1316 gui_internal_table_pack(this,w);
1322 //##############################################################################################################
1325 //# Authors: Martin Schaller (04/2008)
1326 //##############################################################################################################
1327 static void gui_internal_call_highlighted(struct gui_priv *this)
1329 if (! this->highlighted || ! this->highlighted->func)
1331 this->highlighted->reason=1;
1332 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1336 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1338 char *text=w->speech;
1346 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1347 navit_say(this->nav, text);
1353 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1357 gui_internal_search_idle_end(this);
1358 while ((l = g_list_last(this->root.children))) {
1360 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1361 gui_internal_say(this, w, 0);
1362 redisplay=w->menu_data->redisplay;
1363 wr=w->menu_data->redisplay_widget;
1364 if (!w->menu_data->redisplay) {
1365 gui_internal_widget_render(this, w);
1368 gui_internal_widget_destroy(this, l->data);
1369 this->root.children=g_list_remove(this->root.children, l->data);
1370 redisplay(this, wr, wr->data);
1373 gui_internal_widget_destroy(this, l->data);
1374 this->root.children=g_list_remove(this->root.children, l->data);
1379 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1382 gui_internal_search_idle_end(this);
1383 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1384 gui_internal_widget_destroy(this, l->data);
1385 this->root.children=g_list_remove(this->root.children, l->data);
1388 gui_internal_say(this, l->data, 0);
1389 gui_internal_widget_render(this, l->data);
1394 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1396 gui_internal_prune_menu_count(this, 1, 1);
1400 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1402 gui_internal_prune_menu(this, wm->data);
1406 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1408 graphics_draw_mode(this->gra, draw_mode_begin);
1409 gui_internal_back(this, NULL, NULL);
1410 graphics_draw_mode(this->gra, draw_mode_end);
1411 gui_internal_check_exit(this);
1415 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1417 gui_internal_prune_menu(this, NULL);
1421 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1423 gui_internal_prune_menu(this, this->root.children->data);
1426 static struct widget *
1427 gui_internal_top_bar(struct gui_priv *this)
1429 struct widget *w,*wm,*wh,*wc,*wcn;
1430 int dots_len, sep_len;
1432 int width,width_used=0,use_sep=0,incomplete=0;
1433 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1435 1:Don't expand bar to screen width
1436 2:Don't show Map Icon
1437 4:Don't show Home Icon
1438 8:Show only current menu
1439 16:Don't use menu titles as button
1440 32:Show navit version
1443 256:Use background for menu headline
1444 512:Set osd_configuration and zoom to route when setting position
1445 1024:Don't show back button
1446 2048:No highlighting of keyboard
1449 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1450 w->bl=this->spacing;
1451 w->spx=this->spacing;
1452 w->background=this->background2;
1453 if ((this->flags & 6) == 6) {
1459 width=this->root.w-w->bl;
1460 if (! (this->flags & 2)) {
1461 wm=gui_internal_button_new_with_callback(this, NULL,
1462 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1463 gui_internal_cmd_return, NULL);
1464 wm->speech=g_strdup(_("Back to map"));
1465 gui_internal_widget_pack(this, wm);
1466 gui_internal_widget_append(w, wm);
1469 if (! (this->flags & 4)) {
1470 wh=gui_internal_button_new_with_callback(this, NULL,
1471 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1472 gui_internal_cmd_main_menu, NULL);
1473 wh->speech=g_strdup(_("Main Menu"));
1474 gui_internal_widget_pack(this, wh);
1475 gui_internal_widget_append(w, wh);
1478 if (!(this->flags & 6))
1480 l=g_list_last(this->root.children);
1481 wcn=gui_internal_label_new(this,".. »");
1482 wcn->foreground=foreground;
1484 gui_internal_widget_destroy(this, wcn);
1485 wcn=gui_internal_label_new(this,"»");
1486 wcn->foreground=foreground;
1488 gui_internal_widget_destroy(this, wcn);
1490 if (g_list_previous(l) || !g_list_next(l)) {
1492 wcn=gui_internal_label_new(this, wc->text);
1493 wcn->foreground=foreground;
1498 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1499 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1501 gui_internal_widget_destroy(this, wcn);
1505 struct widget *wct=gui_internal_label_new(this, "»");
1506 wct->foreground=foreground;
1507 res=g_list_prepend(res, wct);
1508 width_used+=sep_len+w->spx;
1511 if (!(this->flags & 16)) {
1512 wcn->func=gui_internal_cmd_return;
1514 wcn->state |= STATE_SENSITIVE;
1516 res=g_list_prepend(res, wcn);
1517 if (this->flags & 8)
1520 l=g_list_previous(l);
1524 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1525 wcn->foreground=foreground;
1526 wcn->func=gui_internal_cmd_return;
1528 wcn->state |= STATE_SENSITIVE;
1529 res=g_list_prepend(res, wcn);
1530 l=g_list_previous(l);
1533 wcn=gui_internal_label_new(this, ".. »");
1534 wcn->foreground=foreground;
1535 wcn->func=gui_internal_cmd_return;
1537 wcn->state |= STATE_SENSITIVE;
1538 res=g_list_prepend(res, wcn);
1542 gui_internal_widget_append(w, l->data);
1545 if (this->flags & 32) {
1546 extern char *version;
1547 char *version_text=g_strdup_printf("Navit %s",version);
1548 wcn=gui_internal_label_new(this, version_text);
1549 g_free(version_text);
1550 wcn->flags=gravity_right_center|flags_expand;
1551 gui_internal_widget_append(w, wcn);
1555 gui_internal_widget_destroy(this, dots);
1560 static struct widget *
1561 gui_internal_time_help(struct gui_priv *this)
1563 struct widget *w,*wc,*wcn;
1568 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1569 w->bl=this->spacing;
1570 w->spx=this->spacing;
1576 if (this->flags & 64) {
1577 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1583 tm=localtime(&timep);
1584 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1585 wcn=gui_internal_label_new(this, timestr);
1586 gui_internal_widget_append(wc, wcn);
1587 gui_internal_widget_append(w, wc);
1589 if (this->flags & 128) {
1590 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1591 gui_internal_widget_append(w, wcn);
1598 * Applys the configuration values to this based on the settings
1599 * specified in the configuration file (this->config) and
1600 * the most approriate default profile based on screen resolution.
1602 * This function should be run after this->root is setup and could
1603 * be rerun after the window is resized.
1605 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1607 static void gui_internal_apply_config(struct gui_priv *this)
1609 struct gui_config_settings * current_config=0;
1611 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1613 * Select default values from profile based on the screen.
1615 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1617 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1619 current_config = &config_profiles[LARGE_PROFILE];
1623 current_config = &config_profiles[MEDIUM_PROFILE];
1628 current_config = &config_profiles[SMALL_PROFILE];
1632 * Apply override values from config file
1634 if(this->config.font_size == -1 )
1636 this->font_size = current_config->font_size;
1640 this->font_size = this->config.font_size;
1643 if(this->config.icon_xs == -1 )
1645 this->icon_xs = current_config->icon_xs;
1649 this->icon_xs = this->config.icon_xs;
1652 if(this->config.icon_s == -1 )
1654 this->icon_s = current_config->icon_s;
1658 this->icon_s = this->config.icon_s;
1660 if(this->config.icon_l == -1 )
1662 this->icon_l = current_config->icon_l;
1666 this->icon_l = this->config.icon_l;
1668 if(this->config.spacing == -1 )
1670 this->spacing = current_config->spacing;
1674 this->spacing = current_config->spacing;
1679 static struct widget *
1680 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1682 struct widget *wl,*wlb;
1683 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1684 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1685 wl=gui_internal_label_new(this, label);
1687 wlb->foreground=this->text_foreground;
1692 gui_internal_widget_append(wlb, wl);
1694 gui_internal_widget_prepend(wb, wlb);
1696 gui_internal_widget_append(wb, wlb);
1702 static struct widget *
1703 gui_internal_menu(struct gui_priv *this, const char *label)
1705 struct widget *menu,*w,*w1,*topbox;
1707 gui_internal_search_idle_end(this);
1708 topbox=gui_internal_box_new_with_label(this, 0, label);
1709 topbox->w=this->root.w;
1710 topbox->h=this->root.h;
1711 gui_internal_widget_append(&this->root, topbox);
1712 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1713 menu->w=this->root.w;
1714 menu->h=this->root.h;
1715 menu->background=this->background;
1716 gui_internal_apply_config(this);
1717 if (!this->fonts[0]) {
1718 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
1719 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
1720 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
1722 topbox->menu_data=g_new0(struct menu_data, 1);
1723 gui_internal_widget_append(topbox, menu);
1724 w=gui_internal_top_bar(this);
1725 gui_internal_widget_append(menu, w);
1726 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1727 w->spx=4*this->spacing;
1729 gui_internal_widget_append(menu, w);
1730 if (this->flags & 16 && (!this->flags & 1024)) {
1731 struct widget *wlb,*wb,*wm=w;
1732 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1733 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1734 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1735 gui_internal_widget_append(wm, w);
1736 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1742 topbox->menu_data->button_bar=wb;
1743 gui_internal_widget_append(wm, wb);
1744 wlb=gui_internal_button_label(this,_("Back"),1);
1745 wlb->func=gui_internal_back;
1746 wlb->state |= STATE_SENSITIVE;
1748 if (this->flags & 192) {
1749 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1750 menu->w=this->root.w;
1751 menu->h=this->root.h;
1752 w1=gui_internal_time_help(this);
1753 gui_internal_widget_append(menu, w1);
1754 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1755 gui_internal_widget_append(menu, w1);
1756 gui_internal_widget_append(topbox, menu);
1757 menu->background=NULL;
1759 gui_internal_widget_pack(this, topbox);
1760 gui_internal_widget_reset_pack(this, topbox);
1761 topbox->w=this->root.w;
1762 topbox->h=this->root.h;
1763 menu->w=this->root.w;
1764 menu->h=this->root.h;
1768 static struct menu_data *
1769 gui_internal_menu_data(struct gui_priv *this)
1772 struct widget *menu;
1774 l=g_list_last(this->root.children);
1776 return menu->menu_data;
1780 gui_internal_menu_reset_pack(struct gui_priv *this)
1783 struct widget *top_box;
1785 l=g_list_last(this->root.children);
1787 gui_internal_widget_reset_pack(this, top_box);
1791 gui_internal_menu_render(struct gui_priv *this)
1794 struct widget *menu;
1796 l=g_list_last(this->root.children);
1798 gui_internal_say(this, menu, 0);
1799 gui_internal_widget_pack(this, menu);
1800 gui_internal_widget_render(this, menu);
1804 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1807 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1808 navit_set_destination(this->nav, &wm->c, name, 1);
1809 if (this->flags & 512) {
1811 follow.type=attr_follow;
1813 navit_set_attr(this->nav, &this->osd_configuration);
1814 navit_set_attr(this->nav, &follow);
1815 navit_zoom_to_route(this->nav, 0);
1817 gui_internal_prune_menu(this, NULL);
1821 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1823 navit_set_position(this->nav, &wm->c);
1824 gui_internal_prune_menu(this, NULL);
1828 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1831 dbg(0,"text='%s'\n", widget->text);
1832 if (widget->text && strlen(widget->text))
1833 navit_add_bookmark(this->nav, &widget->c, widget->text);
1834 g_free(widget->text);
1836 l=g_list_previous(g_list_last(this->root.children));
1837 gui_internal_prune_menu(this, l->data);
1841 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1843 gui_internal_cmd_add_bookmark_do(this, widget->data);
1847 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1852 len=strlen(wm->text);
1853 dbg(1,"len=%d\n", len);
1854 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1855 wm->text[len-1]='\0';
1856 gui_internal_cmd_add_bookmark_do(this, wm);
1862 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1865 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
1867 struct widget *w,*wb,*wk,*wl,*we,*wnext;
1869 wb=gui_internal_menu(this,_("Add Bookmark"));
1870 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1871 gui_internal_widget_append(wb, w);
1872 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1873 gui_internal_widget_append(w, we);
1874 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
1875 wk->state |= STATE_EDIT|STATE_CLEAR;
1876 wk->background=this->background;
1877 wk->flags |= flags_expand|flags_fill;
1878 wk->func = gui_internal_cmd_add_bookmark_changed;
1880 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1881 wnext->state |= STATE_SENSITIVE;
1882 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1884 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1885 gui_internal_widget_append(w, wl);
1887 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1888 gui_internal_menu_render(this);
1893 get_direction(char *buffer, int angle, int mode)
1898 sprintf(buffer,"%d",angle);
1901 if (angle < 69 || angle > 291)
1903 if (angle > 111 && angle < 249)
1905 if (angle > 22 && angle < 158)
1907 if (angle > 202 && angle < 338)
1912 angle=(angle+15)/30;
1915 sprintf(buffer,"%d H", angle);
1923 enum item_type *types;
1925 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1926 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1927 {"hotel","Hotel",(enum item_type []) {
1928 type_poi_hotel,type_poi_camp_rv,
1929 type_poi_camping,type_poi_camping,
1930 type_poi_resort,type_poi_resort,
1931 type_poi_motel,type_poi_hostel,
1933 {"restaurant","Restaurant",(enum item_type []) {
1934 type_poi_bar,type_poi_picnic,
1935 type_poi_burgerking,type_poi_fastfood,
1936 type_poi_restaurant,type_poi_restaurant,
1938 {"shopping","Shopping",(enum item_type []) {
1939 type_poi_mall,type_poi_mall,
1940 type_poi_shop_grocery,type_poi_shop_grocery,
1942 {"hospital","Service",(enum item_type []) {
1943 type_poi_marina,type_poi_marina,
1944 type_poi_hospital,type_poi_hospital,
1945 type_poi_public_utilities,type_poi_public_utilities,
1946 type_poi_police,type_poi_autoservice,
1947 type_poi_information,type_poi_information,
1948 type_poi_personal_service,type_poi_repair_service,
1949 type_poi_restroom,type_poi_restroom,
1951 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1952 {"peak","Land Features",(enum item_type []){
1953 type_poi_land_feature,type_poi_rock,
1954 type_poi_dam,type_poi_dam,
1956 {"unknown","Other",(enum item_type []){
1957 type_point_unspecified,type_point_unkn-1,
1958 type_point_unkn+1,type_poi_land_feature-1,
1959 type_poi_rock+1,type_poi_fuel-1,
1960 type_poi_marina+1,type_poi_car_parking-1,
1961 type_poi_car_parking+1,type_poi_bar-1,
1962 type_poi_bank+1,type_poi_dam-1,
1963 type_poi_dam+1,type_poi_information-1,
1964 type_poi_information+1,type_poi_mall-1,
1965 type_poi_mall+1,type_poi_personal_service-1,
1966 type_poi_restaurant+1,type_poi_restroom-1,
1967 type_poi_restroom+1,type_poi_shop_grocery-1,
1968 type_poi_shop_grocery+1,type_poi_motel-1,
1969 type_poi_hostel+1,type_selected_point,
1971 {"unknown","Unknown",(enum item_type []){
1972 type_point_unkn,type_point_unkn,
1976 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1978 static struct widget *
1979 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1981 struct widget *wl,*wb;
1983 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1984 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1985 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1986 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1987 gui_internal_cmd_pois, &selectors[i]));
1994 static struct widget *
1995 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
2001 struct widget *wl,*wt;
2004 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2006 sprintf(distbuf,"%d", dist/1000);
2007 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2008 type=item_to_name(item->type);
2009 if (item_attr_get(item, attr_label, &attr)) {
2010 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
2013 wl->name=g_strdup(type);
2015 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
2016 wt=gui_internal_label_new(this, text);
2018 gui_internal_widget_append(wl, wt);
2025 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
2027 const struct widget *wa=a;
2028 const struct widget *wb=b;
2029 struct widget *wac=wa->children->data;
2030 struct widget *wbc=wb->children->data;
2038 return wac->datai-wbc->datai;
2043 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
2045 enum item_type *types;
2046 if (type >= type_line)
2048 if (! sel || !sel->types)
2051 while (*types != type_none) {
2052 if (type >= types[0] && type <= types[1]) {
2060 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2063 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
2065 struct map_selection *sel,*selm;
2066 struct coord c,center;
2067 struct mapset_handle *h;
2069 struct map_rect *mr;
2071 int idist,dist=20000;
2072 struct widget *wi,*w,*w2,*wb;
2073 enum projection pro=wm->c.pro;
2074 struct selector *isel=wm->data;
2076 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2077 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2078 gui_internal_widget_append(wb, w);
2080 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
2081 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2082 gui_internal_widget_append(w, w2);
2084 sel=map_selection_rect_new(&wm->c, dist, 18);
2087 h=mapset_open(navit_get_mapset(this->nav));
2088 while ((m=mapset_next(h, 1))) {
2089 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2090 mr=map_rect_new(m, selm);
2091 dbg(2,"mr=%p\n", mr);
2093 while ((item=map_rect_get_item(mr))) {
2094 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
2095 item_coord_get_pro(item, &c, 1, pro) &&
2096 coord_rect_contains(&sel->u.c_rect, &c) &&
2097 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2098 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
2099 wi->func=gui_internal_cmd_position;
2102 wi->state |= STATE_SENSITIVE;
2108 map_rect_destroy(mr);
2110 map_selection_destroy(selm);
2112 map_selection_destroy(sel);
2114 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
2115 gui_internal_menu_render(this);
2119 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2121 struct widget *w=wm->data;
2122 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
2124 graphics_clear_selection(this->gra, NULL);
2125 graphics_add_selection(this->gra, &w->item, NULL);
2127 navit_set_center(this->nav, &w->c, 1);
2128 gui_internal_prune_menu(this, NULL);
2133 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2135 struct widget *w,*wb;
2136 struct map_rect *mr;
2142 text=g_strdup_printf("Attribute %s",wm->name);
2143 wb=gui_internal_menu(this, text);
2145 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2146 gui_internal_widget_append(wb, w);
2147 mr=map_rect_new(wm->item.map, NULL);
2148 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2149 for (i = 0 ; i < wm->datai ; i++) {
2150 item_attr_get(item, attr_any, &attr);
2152 if (item_attr_get(item, attr_any, &attr)) {
2154 switch (attr.type) {
2155 case attr_osm_nodeid:
2156 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2158 case attr_osm_wayid:
2159 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2161 case attr_osm_relationid:
2162 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2168 gui_internal_widget_append(w,
2169 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2170 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2171 gui_internal_cmd_view_in_browser, NULL));
2175 map_rect_destroy(mr);
2176 gui_internal_menu_render(this);
2180 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2182 struct widget *w,*wb;
2183 struct map_rect *mr;
2189 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2190 wb=gui_internal_menu(this, "Attributes");
2191 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2192 gui_internal_widget_append(wb, w);
2193 mr=map_rect_new(wm->item.map, NULL);
2194 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2195 dbg(0,"item=%p\n", item);
2197 while(item_attr_get(item, attr_any, &attr)) {
2198 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2199 gui_internal_widget_append(w,
2200 wb=gui_internal_button_new_with_callback(this, text,
2201 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2202 gui_internal_cmd_view_attribute_details, NULL));
2203 wb->name=g_strdup(text);
2209 map_rect_destroy(mr);
2210 gui_internal_menu_render(this);
2214 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2216 struct map_rect *mr;
2222 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2223 mr=map_rect_new(wm->item.map, NULL);
2224 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2225 dbg(0,"item=%p\n", item);
2227 while(item_attr_get(item, attr_url_local, &attr)) {
2229 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2232 map_rect_destroy(mr);
2234 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2240 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2247 gui_internal_cmd_position_do(struct gui_priv *this, struct pcoord *pc_in, struct coord_geo *g_in, struct widget *wm, char *name, int flags)
2249 struct widget *wb,*w,*wc,*wbc;
2259 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2260 transform_to_geo(pc.pro, &c, &g);
2263 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
2266 pc.pro=attr.u.projection;
2267 transform_from_geo(pc.pro, &g, &c);
2273 wb=gui_internal_menu(this, name);
2274 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2275 gui_internal_widget_append(wb, w);
2276 coord=coordinates(&pc, ' ');
2277 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2279 if ((flags & 1) && wm) {
2280 gui_internal_widget_append(w,
2281 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2282 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2283 gui_internal_search_street_in_town, wm));
2285 wc->selection_id=wm->selection_id;
2287 if ((flags & 2) && wm) {
2288 gui_internal_widget_append(w,
2289 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2290 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2291 gui_internal_search_house_number_in_street, wm));
2293 wc->selection_id=wm->selection_id;
2295 if ((flags & 4) && wm) {
2296 struct map_rect *mr;
2299 mr=map_rect_new(wm->item.map, NULL);
2300 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2302 if (item_attr_get(item, attr_description, &attr))
2303 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2304 if (item_attr_get(item, attr_url_local, &attr)) {
2305 gui_internal_widget_append(w,
2306 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2307 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2308 gui_internal_cmd_view_in_browser, NULL));
2311 gui_internal_widget_append(w,
2312 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2313 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2314 gui_internal_cmd_view_attributes, NULL));
2317 map_rect_destroy(mr);
2320 gui_internal_widget_append(w,
2321 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
2322 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2323 gui_internal_cmd_set_destination, g_strdup(name)));
2324 wbc->data_free=g_free;
2328 gui_internal_widget_append(w,
2329 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
2330 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2331 gui_internal_cmd_set_position, wm));
2335 gui_internal_widget_append(w,
2336 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2337 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2338 gui_internal_cmd_add_bookmark2, g_strdup(name)));
2339 wbc->data_free=g_free;
2343 gui_internal_widget_append(w,
2344 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2345 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2346 gui_internal_cmd_pois, NULL));
2350 gui_internal_widget_append(w,
2351 gui_internal_button_new(this, "Add to tour",
2352 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2355 gui_internal_widget_append(w,
2356 gui_internal_button_new_with_callback(this, _("View on map"),
2357 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2358 gui_internal_cmd_view_on_map, wm));
2363 struct mapset_handle *h;
2364 struct map_rect *mr;
2367 struct street_data *data;
2368 struct map_selection sel;
2369 struct transformation *trans;
2370 enum projection pro;
2374 trans=navit_get_trans(this->nav);
2375 pro=transform_get_projection(trans);
2376 transform_from_geo(pro, &g, &c);
2377 ms=navit_get_mapset(this->nav);
2379 sel.u.c_rect.lu.x=c.x-dist;
2380 sel.u.c_rect.lu.y=c.y+dist;
2381 sel.u.c_rect.rl.x=c.x+dist;
2382 sel.u.c_rect.rl.y=c.y-dist;
2384 sel.range=item_range_all;
2386 while ((m=mapset_next(h,1))) {
2387 mr=map_rect_new(m, &sel);
2390 while ((item=map_rect_get_item(mr))) {
2391 data=street_get_data(item);
2392 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2393 if (item_attr_get(item, attr_label, &attr)) {
2394 label=map_convert_string(m, attr.u.str);
2395 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2396 map_convert_free(label);
2398 text=g_strdup_printf("%s", item_to_name(item->type));
2399 gui_internal_widget_append(w,
2400 wc=gui_internal_button_new_with_callback(this, text,
2401 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2402 gui_internal_cmd_position, (void *)2));
2403 wc->c.x=data->c[0].x;
2404 wc->c.y=data->c[0].y;
2406 wc->name=g_strdup(text);
2410 street_data_free(data);
2412 map_rect_destroy(mr);
2416 gui_internal_menu_render(this);
2420 /* wm->data: 0 Nothing special
2430 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2433 switch ((int) wm->data) {
2435 flags=8|16|32|64|128|256;
2438 flags=8|16|32|64|256;
2444 flags=1|8|16|32|64|128;
2445 flags &= this->flags_town;
2448 gui_internal_search_town_in_country(this, wm);
2451 flags=2|8|16|32|64|128;
2452 flags &= this->flags_street;
2455 flags=8|16|32|64|128;
2456 flags &= this->flags_house_number;
2463 gui_internal_search_house_number_in_street(this, wm, NULL);
2466 gui_internal_cmd_set_destination(this, wm, NULL);
2469 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
2473 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2475 char *name=_("Position");
2481 if (!ATTR_IS_COORD_GEO(in[0]->type))
2483 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
2485 if (in[2] && ATTR_IS_INT(in[2]->type))
2488 dbg(1,"flags=0x%x\n",flags);
2489 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
2493 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2495 struct attr attr,mattr;
2496 struct map_rect *mr=NULL;
2498 char *label_full,*l,*prefix="",*pos;
2499 int len,plen,hassub,found=0;
2500 struct widget *wb,*w,*wbm;
2503 char *text=_("Bookmarks");
2507 wb=gui_internal_menu(this, text);
2508 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2509 w->spy=this->spacing*3;
2510 gui_internal_widget_append(wb, w);
2515 if (wm && wm->prefix)
2518 plen=strlen(prefix);
2520 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2521 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2522 while ((item=map_rect_get_item(mr))) {
2523 if (item->type != type_bookmark) continue;
2524 if (!item_attr_get(item, attr_label, &attr)) continue;
2525 label_full=attr.u.str;
2526 if (!strncmp(label_full, prefix, plen)) {
2527 pos=strchr(label_full+plen, '/');
2533 len=strlen(label_full);
2535 l=g_malloc(len-plen+1);
2536 strncpy(l, label_full+plen, len-plen);
2538 if (!g_hash_table_lookup(hash, l)) {
2539 wbm=gui_internal_button_new_with_callback(this, l,
2540 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2541 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2542 if (item_coord_get(item, &c, 1)) {
2545 wbm->c.pro=map_projection(mattr.u.map);
2546 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2547 wbm->text=g_strdup(l);
2548 gui_internal_widget_append(w, wbm);
2549 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2550 wbm->prefix=g_malloc(len+2);
2551 strncpy(wbm->prefix, label_full, len+1);
2552 wbm->prefix[len+1]='\0';
2554 gui_internal_cmd_set_destination(this, wbm, wbm->name);
2559 gui_internal_widget_destroy(this, wbm);
2566 g_hash_table_destroy(hash);
2569 gui_internal_check_exit(this);
2571 gui_internal_menu_render(this);
2575 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2578 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
2581 gui_internal_cmd_bookmarks(this, NULL, str);
2584 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2586 struct widget *wi,*menu;
2590 menu=g_list_last(this->root.children)->data;
2591 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2593 if (*key == NAVIT_KEY_BACKSPACE) {
2594 dbg(0,"backspace\n");
2595 if (wi->text && wi->text[0]) {
2596 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2598 text=g_strdup_printf("%s ", wi->text);
2601 if (wi->state & STATE_CLEAR) {
2602 dbg(0,"wi->state=0x%x\n", wi->state);
2605 wi->state &= ~STATE_CLEAR;
2606 dbg(0,"wi->state=0x%x\n", wi->state);
2608 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2612 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2613 gui_internal_widget_render(this, wi);
2618 wi->func(this, wi, wi->data);
2620 gui_internal_widget_render(this, wi);
2626 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2628 struct menu_data *md=gui_internal_menu_data(this);
2629 gui_internal_keypress_do(this, (char *) wm->data);
2630 if (md->keyboard_mode == 2)
2631 gui_internal_keyboard_do(this, md->keyboard, 10);
2632 if (md->keyboard_mode == 26)
2633 gui_internal_keyboard_do(this, md->keyboard, 34);
2637 gui_internal_search_idle_end(struct gui_priv *this)
2640 event_remove_idle(this->idle);
2643 if (this->idle_cb) {
2644 callback_destroy(this->idle_cb);
2650 postal_str(struct search_list_result *res, int level)
2653 if (res->town->common.postal)
2654 ret=res->town->common.postal;
2655 if (res->town->common.postal_mask)
2656 ret=res->town->common.postal_mask;
2659 if (res->street->common.postal)
2660 ret=res->street->common.postal;
2661 if (res->street->common.postal_mask)
2662 ret=res->street->common.postal_mask;
2665 if (res->house_number->common.postal)
2666 ret=res->house_number->common.postal;
2667 if (res->house_number->common.postal_mask)
2668 ret=res->house_number->common.postal_mask;
2673 district_str(struct search_list_result *res, int level)
2676 if (res->town->common.district_name)
2677 ret=res->town->common.district_name;
2680 if (res->street->common.district_name)
2681 ret=res->street->common.district_name;
2684 if (res->house_number->common.district_name)
2685 ret=res->house_number->common.district_name;
2690 town_str(struct search_list_result *res, int level, int flags)
2692 char *town=res->town->common.town_name;
2693 char *district=district_str(res, level);
2694 char *postal=postal_str(res, level);
2695 char *postal_sep=" ";
2696 char *district_begin=" (";
2697 char *district_end=")";
2699 postal_sep=postal="";
2700 if (!district || (flags & 1))
2701 district_begin=district_end=district="";
2703 return g_strdup_printf("%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end);
2707 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2709 char *text=NULL,*text2=NULL,*name=NULL;
2710 struct search_list_result *res;
2712 struct item *item=NULL;
2714 static char possible_keys[256]="";
2716 res=search_list_get_result(this->sl);
2718 gchar* trunk_name = NULL;
2720 struct widget *menu=g_list_last(this->root.children)->data;
2721 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2723 if (! strcmp(wm_name,"Town"))
2724 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
2725 if (! strcmp(wm_name,"Street"))
2726 trunk_name = g_strrstr(name=res->street->name, wi->text);
2729 char next_char = trunk_name[strlen(wi->text)];
2731 int len = strlen(possible_keys);
2732 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2733 if (i==len || !len) {
2734 possible_keys[len]=trunk_name[strlen(wi->text)];
2735 possible_keys[len+1]='\0';
2738 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
2743 gui_internal_search_idle_end(this);
2745 struct menu_data *md=gui_internal_menu_data(this);
2746 if (md && md->keyboard && !(this->flags & 2048)) {
2747 GList *lk=md->keyboard->children;
2748 graphics_draw_mode(this->gra, draw_mode_begin);
2750 struct widget *child=lk->data;
2751 GList *lk2=child->children;
2753 struct widget *child_=lk2->data;
2754 lk2=g_list_next(lk2);
2755 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2756 if (strlen(possible_keys) == 0)
2757 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2758 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2759 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2761 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2763 gui_internal_widget_render(this,child_);
2768 gui_internal_widget_render(this,md->keyboard);
2769 graphics_draw_mode(this->gra, draw_mode_end);
2772 possible_keys[0]='\0';
2776 if (! strcmp(wm_name,"Country")) {
2777 name=res->country->name;
2778 item=&res->country->common.item;
2779 text=g_strdup_printf("%s", res->country->name);
2781 if (! strcmp(wm_name,"Town")) {
2782 item=&res->town->common.item;
2783 name=res->town->common.town_name;
2784 text=town_str(res, 1, 0);
2786 if (! strcmp(wm_name,"Street")) {
2787 name=res->street->name;
2788 item=&res->street->common.item;
2789 text=g_strdup(res->street->name);
2790 text2=town_str(res, 2, 1);
2792 if (! strcmp(wm_name,"House number")) {
2793 name=res->house_number->house_number;
2794 text=g_strdup_printf("%s %s", res->street->name, name);
2795 text2=town_str(res, 3, 0);
2797 dbg(1,"res->country->flag=%s\n", res->country->flag);
2799 gui_internal_widget_append(search_list,
2800 wc=gui_internal_button_new_with_callback(this, text,
2801 image_new_xs(this, res->country->flag),
2802 gravity_left_center|orientation_horizontal|flags_fill,
2803 gui_internal_cmd_position, param));
2806 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2807 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
2808 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
2809 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
2810 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
2811 gui_internal_widget_append(wc, wb);
2812 wc->func=gui_internal_cmd_position;
2814 wc->state |= STATE_SENSITIVE;
2815 wc->speech=g_strdup(text);
2816 gui_internal_widget_append(search_list, wc);
2818 wc->name=g_strdup(name);
2821 wc->selection_id=res->id;
2824 gui_internal_widget_pack(this, search_list);
2825 l=g_list_last(this->root.children);
2826 graphics_draw_mode(this->gra, draw_mode_begin);
2827 gui_internal_widget_render(this, l->data);
2828 graphics_draw_mode(this->gra, draw_mode_end);
2834 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2836 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2837 this->idle=event_add_idle(50,this->idle_cb);
2838 callback_call_0(this->idle_cb);
2844 * @param wm The widget that generated the event for the search changed,
2845 * if this was generated by a key on the virtual keyboard then
2846 * wm is the key button widget.
2849 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2852 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2853 gui_internal_widget_children_destroy(this, search_list);
2855 void *param=(void *)3;
2857 if (! strcmp(wm->name,"Country"))
2859 if (! strcmp(wm->name,"Street"))
2861 if (! strcmp(wm->name,"House number"))
2863 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2865 gui_internal_search_idle_end(this);
2866 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2867 struct attr search_attr;
2870 if (! strcmp(wm->name,"Country"))
2871 search_attr.type=attr_country_all;
2872 if (! strcmp(wm->name,"Town"))
2873 search_attr.type=attr_town_or_district_name;
2874 if (! strcmp(wm->name,"Street"))
2875 search_attr.type=attr_street_name;
2876 if (! strcmp(wm->name,"House number"))
2877 search_attr.type=attr_house_number;
2878 search_attr.u.str=wm->text;
2879 search_list_search(this->sl, &search_attr, 1);
2880 gui_internal_search_idle_start(this, wm->name, search_list, param);
2882 l=g_list_last(this->root.children);
2883 gui_internal_widget_render(this, l->data);
2886 static struct widget *
2887 gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, int font, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w, int h)
2890 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
2891 NULL, gravity_center|orientation_vertical, func, data));
2892 wk->data_free=data_free;
2893 wk->background=this->background;
2901 static struct widget *
2902 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2904 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2907 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2909 // Some macros that make the keyboard layout easier to visualise in
2910 // the source code. The macros are #undef'd after this function.
2911 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2912 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
2913 static struct widget *
2914 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2916 struct widget *wkbd,*wk;
2917 struct menu_data *md=gui_internal_menu_data(this);
2918 int i, max_w=this->root.w, max_h=this->root.h;
2921 char *backspace="←";
2926 char *numeric="123";
2928 char *umlauts_ucase="ÄÖÜ";
2929 int umlauts_ucase_font=2;
2930 char *umlauts_lcase="äöü";
2931 int umlauts_lcase_font=2;
2938 gui_internal_highlight(this);
2939 if (md->keyboard_mode >= 1024)
2943 gui_internal_widget_children_destroy(this, wkbdb);
2945 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2947 md->keyboard_mode=mode;
2948 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2949 wkbd->background=this->background;
2956 if (mode >= 0 && mode < 8) {
2957 for (i = 0 ; i < 26 ; i++) {
2958 char text[]={'A'+i,'\0'};
2961 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
2965 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2966 wk->datai=mode+1024;
2968 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2969 wk->datai=mode+1024;
2970 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2972 wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2975 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2977 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
2979 if (mode >= 8 && mode < 16) {
2980 for (i = 0 ; i < 26 ; i++) {
2981 char text[]={'a'+i,'\0'};
2984 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
2988 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2989 wk->datai=mode+1024;
2991 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2992 wk->datai=mode+1024;
2993 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2995 wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
2998 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_lcase, umlauts_lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3000 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3002 if (mode >= 16 && mode < 24) {
3003 for (i = 0 ; i < 10 ; i++) {
3004 char text[]={'0'+i,'\0'};
3007 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
3008 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
3010 for (i = 0 ; i < 5 ; i++) SPACER();
3015 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3016 wk->datai=mode+1024;
3018 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3019 wk->datai=mode+1024;
3020 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3022 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3025 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3027 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3029 if (mode >= 24 && mode < 32) {
3030 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
3031 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
3032 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
3033 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
3035 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3038 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3040 if (mode >= 32 && mode < 40) {
3041 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
3042 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
3043 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
3044 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
3046 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3049 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3056 if (mode >= 0 && mode < 8) {
3060 if (mode >= 8 && mode < 16) {
3064 if (mode >= 16 && mode < 24) {
3068 if (mode >= 24 && mode < 32) {
3070 font=umlauts_ucase_font;
3072 if (mode >= 32 && mode < 40) {
3074 font=umlauts_lcase_font;
3076 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
3077 wk->func=gui_internal_keyboard_change;
3079 wk->background=this->background;
3085 wk->state |= STATE_SENSITIVE;
3086 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
3087 wkl->background=NULL;
3088 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text,font));
3089 wkl->background=NULL;
3090 gui_internal_widget_append(wkbd, wk);
3094 gui_internal_widget_append(wkbdb, wkbd);
3096 gui_internal_widget_pack(this, wkbdb);
3097 gui_internal_widget_render(this, wkbdb);
3098 } else if (render == 2) {
3099 gui_internal_menu_reset_pack(this);
3100 gui_internal_menu_render(this);
3107 static struct widget *
3108 gui_internal_keyboard(struct gui_priv *this, int mode)
3110 if (! this->keyboard)
3112 return gui_internal_keyboard_do(this, NULL, mode);
3116 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
3118 gui_internal_keyboard_do(this, key->data, key->datai);
3122 gui_internal_search_list_set_default_country(struct gui_priv *this)
3124 struct attr search_attr, country_name, country_iso2, *country_attr;
3126 struct country_search *cs;
3127 struct tracking *tracking;
3128 struct search_list_result *res;
3130 country_attr=country_default();
3131 tracking=navit_get_tracking(this->nav);
3132 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
3133 country_attr=&search_attr;
3135 cs=country_search_new(country_attr, 0);
3136 item=country_search_get_item(cs);
3137 if (item && item_attr_get(item, attr_country_name, &country_name)) {
3138 search_attr.type=attr_country_all;
3139 dbg(0,"country %s\n", country_name.u.str);
3140 search_attr.u.str=country_name.u.str;
3141 search_list_search(this->sl, &search_attr, 0);
3142 while((res=search_list_get_result(this->sl)));
3143 g_free(this->country_iso2);
3144 if (item_attr_get(item, attr_country_iso2, &country_iso2))
3145 this->country_iso2=g_strdup(country_iso2.u.str);
3147 country_search_destroy(cs);
3149 dbg(0,"warning: no default country found\n");
3150 if (this->country_iso2) {
3151 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
3152 search_attr.type=attr_country_iso2;
3153 search_attr.u.str=this->country_iso2;
3154 search_list_search(this->sl, &search_attr, 0);
3155 while((res=search_list_get_result(this->sl)));
3161 gui_internal_search_list_new(struct gui_priv *this)
3163 struct mapset *ms=navit_get_mapset(this->nav);
3165 this->sl=search_list_new(ms);
3166 gui_internal_search_list_set_default_country(this);
3171 gui_internal_search_list_destroy(struct gui_priv *this)
3174 search_list_destroy(this->sl);
3181 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
3183 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
3185 int keyboard_mode=2;
3186 gui_internal_search_list_new(this);
3187 wb=gui_internal_menu(this, what);
3188 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
3189 gui_internal_widget_append(wb, w);
3190 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3191 gui_internal_widget_append(w, wr);
3192 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3193 gui_internal_widget_append(wr, we);
3195 if (!strcmp(type,"Country")) {
3196 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
3197 wnext->func=gui_internal_search_town;
3198 } else if (!strcmp(type,"Town")) {
3199 if (this->country_iso2) {
3200 #if HAVE_API_ANDROID
3201 char country_iso2[strlen(this->country_iso2)+1];
3202 strtolower(country_iso2, this->country_iso2);
3203 country=g_strdup_printf("country_%s", country_iso2);
3205 country=g_strdup_printf("country_%s", this->country_iso2);
3208 country=strdup("gui_select_country");
3209 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
3210 wb->state |= STATE_SENSITIVE;
3212 wb->func = gui_internal_search_country;
3214 wb->func = gui_internal_back;
3215 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
3216 wnext->func=gui_internal_search_street;
3218 } else if (!strcmp(type,"Street")) {
3219 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
3220 wb->state |= STATE_SENSITIVE;
3221 wb->func = gui_internal_back;
3222 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
3223 wnext->func=gui_internal_search_house_number;
3224 } else if (!strcmp(type,"House number")) {
3225 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
3226 wb->state |= STATE_SENSITIVE;
3227 wb->func = gui_internal_back;
3230 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3232 gui_internal_widget_append(we, wnext);
3233 wnext->state |= STATE_SENSITIVE;
3235 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3236 gui_internal_widget_append(wr, wl);
3237 gui_internal_menu_data(this)->search_list=wl;
3238 wk->state |= STATE_EDIT;
3239 wk->background=this->background;
3240 wk->flags |= flags_expand|flags_fill;
3241 wk->func = gui_internal_search_changed;
3242 wk->name=g_strdup(type);
3244 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
3245 gui_internal_menu_render(this);
3249 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3251 search_list_select(this->sl, attr_street_name, 0, 0);
3252 gui_internal_search(this,_("House number"),"House number",0);
3256 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3258 dbg(0,"id %d\n", widget->selection_id);
3259 search_list_select(this->sl, attr_street_name, 0, 0);
3260 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3261 gui_internal_search(this,_("House number"),"House number",0);
3265 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3267 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3268 gui_internal_search(this,_("Street"),"Street",0);
3272 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3274 dbg(0,"id %d\n", widget->selection_id);
3275 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3276 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3277 gui_internal_search(this,_("Street"),"Street",0);
3281 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3284 search_list_select(this->sl, attr_country_all, 0, 0);
3285 g_free(this->country_iso2);
3286 this->country_iso2=NULL;
3287 gui_internal_search(this,_("Town"),"Town",0);
3291 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3293 struct search_list_common *slc;
3294 dbg(0,"id %d\n", widget->selection_id);
3295 search_list_select(this->sl, attr_country_all, 0, 0);
3296 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3298 g_free(this->country_iso2);
3299 this->country_iso2=((struct search_list_country *)slc)->iso2;
3301 gui_internal_search(this,widget->name,"Town",0);
3305 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3307 gui_internal_prune_menu_count(this, 1, 0);
3308 gui_internal_search(this,_("Country"),"Country",0);
3312 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3315 search_list_select(this->sl, attr_country_all, 0, 0);
3316 gui_internal_search(this,_("Town"),"Town",1);
3320 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3323 struct widget *w,*wb,*wl;
3324 struct attr_iter *iter;
3327 wb=gui_internal_menu(this, _("Layout"));
3328 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3329 w->spy=this->spacing*3;
3330 gui_internal_widget_append(wb, w);
3331 iter=navit_attr_iter_new();
3332 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3333 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3335 gui_internal_widget_append(w, wl);
3337 navit_attr_iter_destroy(iter);
3338 gui_internal_menu_render(this);
3342 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3345 navit.type=attr_navit;
3346 navit.u.navit=this->nav;
3347 navit_destroy(navit.u.navit);
3348 config_remove_attr(config, &navit);
3349 event_main_loop_quit();
3353 gui_internal_window_closed(struct gui_priv *this)
3355 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3359 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3361 navit_set_destination(this->nav, NULL, NULL, 0);
3366 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3368 struct attr attr, on, off, description, type, data;
3369 struct widget *w,*wb,*wma;
3371 struct attr_iter *iter;
3374 wb=gui_internal_menu(this, _("Maps"));
3375 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3376 w->spy=this->spacing*3;
3377 gui_internal_widget_append(wb, w);
3378 iter=navit_attr_iter_new();
3379 on.type=off.type=attr_active;
3382 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3383 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3384 label=g_strdup(description.u.str);
3386 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3388 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3390 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3392 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3393 attr.u.map, &on, &off, 1);
3394 gui_internal_widget_append(w, wma);
3397 navit_attr_iter_destroy(iter);
3398 gui_internal_menu_render(this);
3402 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3404 struct attr vehicle = {attr_vehicle,{wm->data}};
3405 navit_set_attr(this->nav, &vehicle);
3409 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3411 struct widget *w,*wb,*row;
3412 struct attr attr,sat_attr;
3413 struct vehicle *v=wm->data;
3416 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3418 wb=gui_internal_menu(this, _("Show Satellite Status"));
3419 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3420 gui_internal_menu_data(this)->redisplay_widget=wm;
3421 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3422 gui_internal_widget_append(wb, w);
3423 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3424 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3425 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3426 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3427 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3428 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3429 gui_internal_widget_append(w,row);
3430 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3431 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3432 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3433 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3434 str=g_strdup_printf("%d", sat_attr.u.num);
3437 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3440 gui_internal_widget_append(w,row);
3442 gui_internal_widget_append(wb, w);
3443 gui_internal_menu_render(this);
3447 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3449 struct widget *w,*wb;
3451 struct vehicle *v=wm->data;
3452 wb=gui_internal_menu(this, _("Show NMEA Data"));
3453 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3454 gui_internal_menu_data(this)->redisplay_widget=wm;
3455 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3456 gui_internal_widget_append(wb, w);
3457 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3458 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3459 gui_internal_menu_render(this);
3463 * A container to hold the selected vehicle and the desired profile in
3466 struct vehicle_and_profilename {
3467 struct vehicle *vehicle;
3472 * Figures out whether the given vehicle is the active vehicle.
3474 * @return true if the vehicle is active, false otherwise.
3477 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3480 struct attr active_vehicle;
3482 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3483 active_vehicle.u.vehicle=NULL;
3485 return active_vehicle.u.vehicle == vehicle;
3489 save_vehicle_xml(struct vehicle *v)
3492 struct attr_iter *iter=vehicle_attr_iter_new();
3496 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3497 if (ATTR_IS_OBJECT(attr.type))
3500 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3504 printf("</vehicle>\n");
3507 vehicle_attr_iter_destroy(iter);
3512 * Reacts to a button press that changes a vehicle's active profile.
3514 * @see gui_internal_add_vehicle_profile
3517 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3518 widget *wm, void *data)
3520 struct vehicle_and_profilename *vapn = data;
3521 struct vehicle *v = vapn->vehicle;
3522 char *profilename = vapn->profilename;
3523 struct attr vehicle_name_attr;
3524 char *vehicle_name = NULL;
3526 // Get the vehicle name
3527 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3528 vehicle_name = vehicle_name_attr.u.str;
3530 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3533 // Change the profile name
3534 struct attr profilename_attr = {attr_profilename, {profilename}};
3535 if(!vehicle_set_attr(v, &profilename_attr)) {
3536 dbg(0, "Unable to set the vehicle's profile name\n");
3539 // Notify Navit that the routing should be re-done if this is the
3541 if (gui_internal_is_active_vehicle(this, v)) {
3542 struct attr vehicle;
3543 vehicle.type=attr_vehicle;
3544 vehicle.u.vehicle=v;
3545 navit_set_attr(this->nav, &vehicle);
3547 save_vehicle_xml(v);
3551 * Adds the vehicle profile to the GUI, allowing the user to pick a
3552 * profile for the currently selected vehicle.
3555 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3556 *parent, struct vehicle *v, struct vehicleprofile *profile)
3558 // Just here to show up in the translation file, nice and close to
3559 // where the translations are actually used.
3560 struct attr profile_attr;
3561 struct attr *attr = NULL;
3563 char *active_profile = NULL;
3566 struct vehicle_and_profilename *context = NULL;
3568 #ifdef ONLY_FOR_TRANSLATION
3569 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3572 // Figure out the profile name
3573 attr = attr_search(profile->attrs, NULL, attr_name);
3576 // Determine whether the profile is the active one
3577 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3578 active_profile = profile_attr.u.str;
3579 active = strcmp(name, active_profile) == 0;
3581 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3582 active_profile, active);
3584 // Build a translatable label.
3586 label = g_strdup_printf(_("Current profile: %s"), _(name));
3588 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3591 // Create the context object (the vehicle and the desired profile)
3592 context = g_new0(struct vehicle_and_profilename, 1);
3593 context->vehicle = v;
3594 context->profilename = name;
3597 gui_internal_widget_append(parent,
3598 gui_internal_button_new_with_callback(
3600 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3601 gravity_left_center|orientation_horizontal|flags_fill,
3602 gui_internal_cmd_set_active_profile, context));
3608 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3610 struct widget *w,*wb;
3612 struct vehicle *v=wm->data;
3613 struct vehicleprofile *profile = NULL;
3615 wb=gui_internal_menu(this, wm->text);
3616 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3617 gui_internal_widget_append(wb, w);
3619 // Add the "Set as active" button if this isn't the active
3621 if (!gui_internal_is_active_vehicle(this, v)) {
3622 gui_internal_widget_append(w,
3623 gui_internal_button_new_with_callback(this, _("Set as active"),
3624 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3625 gui_internal_cmd_set_active_vehicle, wm->data));
3628 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3629 gui_internal_widget_append(w,
3630 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3631 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3632 gui_internal_cmd_show_satellite_status, wm->data));
3634 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3635 gui_internal_widget_append(w,
3636 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3637 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3638 gui_internal_cmd_show_nmea_data, wm->data));
3641 // Add all the possible vehicle profiles to the menu
3642 GList *profiles = navit_get_vehicleprofiles(this->nav);
3644 profile = (struct vehicleprofile *)profiles->data;
3645 gui_internal_add_vehicle_profile(this, w, v, profile);
3646 profiles = g_list_next(profiles);
3649 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3650 gui_internal_menu_render(this);
3654 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3656 struct attr attr,vattr;
3657 struct widget *w,*wb,*wl;
3658 struct attr_iter *iter;
3659 struct attr active_vehicle;
3662 wb=gui_internal_menu(this, _("Vehicle"));
3663 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3664 w->spy=this->spacing*3;
3665 gui_internal_widget_append(wb, w);
3666 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3667 active_vehicle.u.vehicle=NULL;
3668 iter=navit_attr_iter_new();
3669 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3670 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3671 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3672 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3673 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3674 wl->text=g_strdup(vattr.u.str);
3675 gui_internal_widget_append(w, wl);
3677 navit_attr_iter_destroy(iter);
3678 gui_internal_menu_render(this);
3683 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3685 struct widget *wb,*w;
3687 wb=gui_internal_menu(this, _("Rules"));
3688 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3689 w->spy=this->spacing*3;
3690 gui_internal_widget_append(wb, w);
3693 on.type=off.type=attr_tracking;
3694 gui_internal_widget_append(w,
3695 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3699 on.type=off.type=attr_orientation;
3700 gui_internal_widget_append(w,
3701 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3705 on.type=off.type=attr_follow_cursor;
3706 gui_internal_widget_append(w,
3707 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3709 gui_internal_menu_render(this);
3712 //##############################################################################################################
3715 //# Authors: Martin Schaller (04/2008)
3716 //##############################################################################################################
3717 static void gui_internal_motion(void *data, struct point *p)
3720 struct gui_priv *this=data;
3721 if (!this->root.children) {
3722 navit_handle_motion(this->nav, p);
3728 if(!this->motion_timeout_callback)
3729 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3730 if(!this->motion_timeout_event)
3731 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3735 find_attr(const char **names, const char **values, const char *name)
3738 if (!strcasecmp(*names, name))
3740 names+=xml_attr_distance;
3741 values+=xml_attr_distance;
3747 find_attr_dup(const char **names, const char **values, const char *name)
3749 return g_strdup(find_attr(names, values, name));
3753 gui_internal_evaluate(struct gui_priv *this, const char *command)
3756 command_evaluate(&this->self, command);
3761 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
3763 gui_internal_evaluate(this,w->command);
3767 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
3769 if (w->command && w->command[0] == '#') {
3770 dbg(1,"href=%s\n",w->command);
3771 gui_internal_html_menu(this, this->html_text, w->command+1);
3777 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
3779 struct gui_priv *this=data;
3781 enum html_tag tag=html_tag_none;
3782 struct html *html=&this->html[this->html_depth];
3783 const char *src, *cond;
3785 if (!strcasecmp(tag_name,"text"))
3791 cond=find_attr(names, values, "cond");
3793 if (cond && !this->html_skip) {
3794 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
3798 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
3799 if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
3800 tag=html_tag_map[i].tag;
3805 if (!this->html_skip && !html->skip) {
3808 html->name=find_attr_dup(names, values, "name");
3810 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
3812 this->html_anchor_found=1;
3814 html->href=find_attr_dup(names, values, "href");
3817 html->command=find_attr_dup(names, values, "onclick");
3818 src=find_attr(names, values, "src");
3820 html->w=gui_internal_image_new(this, image_new_l(this, src));
3826 this->html_skip+=html->skip;
3831 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
3833 struct gui_priv *this=data;
3835 struct html *parent=NULL;
3837 if (!strcasecmp(tag_name,"text"))
3840 html=&this->html[this->html_depth];
3841 if (this->html_depth > 0)
3842 parent=&this->html[this->html_depth-1];
3845 if (!this->html_skip) {
3846 if (html->command && html->w) {
3847 html->w->state |= STATE_SENSITIVE;
3848 html->w->command=html->command;
3849 html->w->func=gui_internal_html_command;
3852 if (parent && parent->href && html->w) {
3853 html->w->state |= STATE_SENSITIVE;
3854 html->w->command=g_strdup(parent->href);
3855 html->w->func=gui_internal_html_href;
3857 switch (html->tag) {
3859 gui_internal_widget_append(this->html_container, html->w);
3865 this->html_skip-=html->skip;
3866 g_free(html->command);
3872 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
3874 struct gui_priv *this=data;
3876 int depth=this->html_depth-1;
3877 struct html *html=&this->html[depth];
3878 char *text_stripped;
3880 if (this->html_skip)
3882 while (isspace(text[0])) {
3886 while (len > 0 && isspace(text[len-1]))
3888 text_stripped=g_malloc(len+1);
3889 strncpy(text_stripped, text, len);
3890 text_stripped[len]='\0';
3891 if (html->tag == html_tag_html && depth > 2) {
3892 if (this->html[depth-1].tag == html_tag_script) {
3893 html=&this->html[depth-2];
3896 switch (html->tag) {
3898 if (html->name && len) {
3899 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3900 this->html_container->spx=this->spacing*10;
3904 if (!this->html_container) {
3905 this->html_container=gui_internal_menu(this, gettext(text_stripped));
3906 this->html_container->spx=this->spacing*10;
3911 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
3912 gui_internal_widget_append(w, html->w);
3913 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
3917 case html_tag_script:
3918 dbg(1,"execute %s\n",text_stripped);
3919 gui_internal_evaluate(this,text_stripped);
3927 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
3929 graphics_draw_mode(this->gra, draw_mode_begin);
3930 this->html_container=NULL;
3932 this->html_anchor=anchor;
3933 this->html_anchor_found=0;
3934 xml_parse_text(document, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
3935 gui_internal_menu_render(this);
3936 graphics_draw_mode(this->gra, draw_mode_end);
3940 static void gui_internal_menu_root(struct gui_priv *this)
3942 gui_internal_html_menu(this, this->html_text, "Main Menu");
3946 gui_internal_enter(struct gui_priv *this, int ignore)
3948 struct graphics *gra=this->gra;
3949 this->ignore_button=ignore;
3950 this->clickp_valid=this->vehicle_valid=0;
3952 navit_block(this->nav, 1);
3953 graphics_overlay_disable(gra, 1);
3956 this->root.background=this->background;
3960 gui_internal_leave(struct gui_priv *this)
3962 graphics_draw_mode(this->gra, draw_mode_end);
3966 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3968 struct transformation *trans;
3971 struct attr attr,attrp;
3974 gui_internal_enter(this, ignore);
3975 trans=navit_get_trans(this->nav);
3976 attr_free(this->click_coord_geo);
3977 this->click_coord_geo=NULL;
3978 attr_free(this->position_coord_geo);
3979 this->position_coord_geo=NULL;
3981 transform_reverse(trans, p, &c);
3982 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
3983 this->clickp.pro=transform_get_projection(trans);
3986 transform_to_geo(this->clickp.pro, &c, &g);
3987 attr.u.coord_geo=&g;
3988 attr.type=attr_click_coord_geo;
3989 this->click_coord_geo=attr_dup(&attr);
3991 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3992 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3993 this->position_coord_geo=attr_dup(&attrp);
3994 this->vehiclep.pro=transform_get_projection(trans);
3995 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3996 this->vehiclep.x=c.x;
3997 this->vehiclep.y=c.y;
3998 this->vehicle_valid=1;
4001 gui_internal_menu_root(this);
4005 gui_internal_cmd_menu2(struct gui_priv *this)
4007 gui_internal_cmd_menu(this, NULL, 1);
4012 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
4014 if (widget->text && strlen(widget->text))
4015 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
4016 g_free(widget->text);
4018 gui_internal_prune_menu(this, NULL);
4019 gui_internal_check_exit(this);
4023 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
4025 gui_internal_cmd_log_do(this, widget->data);
4029 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
4033 len=strlen(wm->text);
4034 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
4035 wm->text[len-1]='\0';
4036 gui_internal_cmd_log_do(this, wm);
4043 gui_internal_cmd_log(struct gui_priv *this)
4045 struct widget *w,*wb,*wk,*wl,*we,*wnext;
4046 gui_internal_enter(this, 1);
4047 wb=gui_internal_menu(this, "Log Message");
4048 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4049 gui_internal_widget_append(wb, w);
4050 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4051 gui_internal_widget_append(w, we);
4052 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
4053 wk->state |= STATE_EDIT|STATE_CLEAR;
4054 wk->background=this->background;
4055 wk->flags |= flags_expand|flags_fill;
4056 wk->func = gui_internal_cmd_log_changed;
4057 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
4058 wnext->state |= STATE_SENSITIVE;
4059 wnext->func = gui_internal_cmd_log_clicked;
4061 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4062 gui_internal_widget_append(w, wl);
4064 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
4065 gui_internal_menu_render(this);
4066 gui_internal_leave(this);
4070 gui_internal_check_exit(struct gui_priv *this)
4072 struct graphics *gra=this->gra;
4073 if (! this->root.children) {
4074 gui_internal_search_idle_end(this);
4075 gui_internal_search_list_destroy(this);
4076 graphics_overlay_disable(gra, 0);
4077 if (!navit_block(this->nav, 0)) {
4079 navit_draw(this->nav);
4081 navit_draw_displaylist(this->nav);
4087 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
4091 attr->u.num=this->root.children != NULL;
4093 case attr_click_coord_geo:
4094 if (!this->click_coord_geo)
4096 *attr=*this->click_coord_geo;
4098 case attr_position_coord_geo:
4099 if (!this->position_coord_geo)
4101 *attr=*this->position_coord_geo;
4104 attr->u.num=this->pitch;
4114 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
4116 switch (attr->type) {
4118 g_free(this->html_text);
4119 this->html_text=g_strdup(attr->u.str);
4127 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
4129 switch (attr->type) {
4130 case attr_fullscreen:
4131 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
4132 graphics_draw_mode(this->gra, draw_mode_end);
4133 this->win->fullscreen(this->win, attr->u.num > 0);
4134 graphics_draw_mode(this->gra, draw_mode_begin);
4136 this->fullscreen=attr->u.num;
4139 dbg(0,"%s\n",attr_to_name(attr->type));
4144 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
4146 struct displaylist_handle *dlh;
4147 struct displaylist *display;
4148 struct displayitem *di;
4150 display=navit_get_displaylist(this->nav);
4151 dlh=graphics_displaylist_open(display);
4152 while ((di=graphics_displaylist_next(dlh))) {
4153 struct item *item=graphics_displayitem_get_item(di);
4154 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
4155 graphics_displayitem_within_dist(display, di, p, 10)) {
4156 struct map_rect *mr=map_rect_new(item->map, NULL);
4157 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
4159 if (item_attr_get(itemo, attr_data, &attr)) {
4160 struct attr cb,*attr_list[2];
4162 attr.type=attr_data;
4165 if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
4166 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
4168 map_rect_destroy(mr);
4171 graphics_displaylist_close(dlh);
4175 //##############################################################################################################
4176 //# Description: Function to handle mouse clicks and scroll wheel movement
4178 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
4179 //##############################################################################################################
4180 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
4182 struct gui_priv *this=data;
4183 struct graphics *gra=this->gra;
4185 dbg(1,"enter %d %d\n", pressed, button);
4186 // if still on the map (not in the menu, yet):
4187 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
4188 if (!this->root.children || this->ignore_button) {
4190 this->ignore_button=0;
4191 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
4192 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
4193 dbg(1,"navit has handled button\n");
4196 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
4199 if (this->menu_on_map_click) {
4200 gui_internal_cmd_menu(this, p, 0);
4203 if (this->signal_on_map_click) {
4204 gui_internal_dbus_signal(this, p);
4211 // if already in the menu:
4215 gui_internal_highlight(this);
4220 graphics_draw_mode(gra, draw_mode_begin);
4221 gui_internal_call_highlighted(this);
4222 gui_internal_highlight(this);
4223 graphics_draw_mode(gra, draw_mode_end);
4224 gui_internal_check_exit(this);
4229 gui_internal_setup_gc(struct gui_priv *this)
4231 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
4232 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
4233 struct graphics *gra=this->gra;
4235 if (this->background)
4237 this->background=graphics_gc_new(gra);
4238 this->background2=graphics_gc_new(gra);
4239 this->highlight_background=graphics_gc_new(gra);
4240 graphics_gc_set_foreground(this->highlight_background, &cbh);
4241 this->foreground=graphics_gc_new(gra);
4242 graphics_gc_set_foreground(this->foreground, &cf);
4243 this->text_background=graphics_gc_new(gra);
4244 this->text_foreground=graphics_gc_new(gra);
4245 graphics_gc_set_foreground(this->background, &this->background_color);
4246 graphics_gc_set_foreground(this->background2, &this->background2_color);
4247 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
4248 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
4251 //##############################################################################################################
4254 //# Authors: Martin Schaller (04/2008)
4255 //##############################################################################################################
4256 static void gui_internal_resize(void *data, int w, int h)
4258 struct gui_priv *this=data;
4261 gui_internal_setup_gc(this);
4263 if (this->root.w != w || this->root.h != h) {
4268 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
4269 navit_handle_resize(this->nav, w, h);
4270 if (this->root.children && changed) {
4271 gui_internal_prune_menu(this, NULL);
4272 gui_internal_menu_root(this);
4277 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
4292 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
4294 GList *l=wi->children;
4295 if (wi->state & STATE_SENSITIVE) {
4298 gui_internal_keynav_point(wi, -dx, -dy, &wp);
4300 dist1=(wp.x-p->x)*dx;
4303 dist1=(wp.y-p->y)*dy;
4311 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);
4317 if (dist1 < *distance) {
4324 struct widget *child=l->data;
4325 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
4331 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
4333 struct widget *result,*menu=g_list_last(this->root.children)->data;
4336 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4337 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
4343 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
4345 gui_internal_keynav_point(result, dx, dy, &p);
4346 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
4351 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4352 dbg(1,"result=%p\n", result);
4364 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4365 dbg(1,"wraparound result=%p\n", result);
4367 gui_internal_highlight_do(this, result);
4369 gui_internal_say(this, result, 1);
4372 //##############################################################################################################
4375 //# Authors: Martin Schaller (04/2008)
4376 //##############################################################################################################
4377 static void gui_internal_keypress(void *data, char *key)
4379 struct gui_priv *this=data;
4382 if (!this->root.children) {
4383 transform_get_size(navit_get_trans(this->nav), &w, &h);
4388 navit_set_center_screen(this->nav, &p, 1);
4390 case NAVIT_KEY_DOWN:
4393 navit_set_center_screen(this->nav, &p, 1);
4395 case NAVIT_KEY_LEFT:
4398 navit_set_center_screen(this->nav, &p, 1);
4400 case NAVIT_KEY_RIGHT:
4403 navit_set_center_screen(this->nav, &p, 1);
4405 case NAVIT_KEY_ZOOM_IN:
4406 navit_zoom_in(this->nav, 2, NULL);
4408 case NAVIT_KEY_ZOOM_OUT:
4409 navit_zoom_out(this->nav, 2, NULL);
4411 case NAVIT_KEY_RETURN:
4412 case NAVIT_KEY_MENU:
4413 gui_internal_cmd_menu(this, NULL, 0);
4418 graphics_draw_mode(this->gra, draw_mode_begin);
4420 case NAVIT_KEY_LEFT:
4421 gui_internal_keynav_highlight_next(this,-1,0);
4423 case NAVIT_KEY_RIGHT:
4424 gui_internal_keynav_highlight_next(this,1,0);
4427 gui_internal_keynav_highlight_next(this,0,-1);
4429 case NAVIT_KEY_DOWN:
4430 gui_internal_keynav_highlight_next(this,0,1);
4432 case NAVIT_KEY_BACK:
4434 case NAVIT_KEY_RETURN:
4435 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4436 gui_internal_call_highlighted(this);
4438 gui_internal_keypress_do(this, key);
4441 gui_internal_keypress_do(this, key);
4443 graphics_draw_mode(this->gra, draw_mode_end);
4444 gui_internal_check_exit(this);
4448 //##############################################################################################################
4451 //# Authors: Martin Schaller (04/2008)
4452 //##############################################################################################################
4453 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4456 struct transformation *trans=navit_get_trans(this->nav);
4458 win=graphics_get_data(gra, "window");
4461 navit_ignore_graphics_events(this->nav, 1);
4464 navit_ignore_graphics_events(this->nav, 1);
4465 transform_get_size(trans, &this->root.w, &this->root.h);
4466 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4467 graphics_add_callback(gra, this->resize_cb);
4468 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4469 graphics_add_callback(gra, this->button_cb);
4470 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4471 graphics_add_callback(gra, this->motion_cb);
4472 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4473 graphics_add_callback(gra, this->keypress_cb);
4474 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
4475 graphics_add_callback(gra, this->window_closed_cb);
4477 // set fullscreen if needed
4478 if (this->fullscreen)
4479 this->win->fullscreen(this->win, this->fullscreen != 0);
4480 /* Was resize callback already issued? */
4481 if (navit_get_ready(this->nav) & 2)
4482 gui_internal_setup_gc(this);
4486 static void gui_internal_disable_suspend(struct gui_priv *this)
4488 if (this->win->disable_suspend)
4489 this->win->disable_suspend(this->win);
4492 //##############################################################################################################
4495 //# Authors: Martin Schaller (04/2008)
4496 //##############################################################################################################
4497 struct gui_methods gui_internal_methods = {
4500 gui_internal_set_graphics,
4504 gui_internal_disable_suspend,
4505 gui_internal_get_attr,
4506 gui_internal_add_attr,
4507 gui_internal_set_attr,
4511 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4513 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4515 *out=attr_generic_add_attr(*out, &private_data);
4519 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4521 callback_list_add(priv->cbl, cb);
4525 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4527 callback_list_remove(priv->cbl, cb);
4531 static struct gui_internal_methods gui_internal_methods_ext = {
4532 gui_internal_add_callback,
4533 gui_internal_remove_callback,
4534 gui_internal_menu_render,
4541 gui_internal_get_flags(struct widget *widget)
4543 return widget->flags;
4547 gui_internal_set_flags(struct widget *widget, enum flags flags)
4549 widget->flags=flags;
4553 gui_internal_get_state(struct widget *widget)
4555 return widget->state;
4559 gui_internal_set_state(struct widget *widget, int state)
4561 widget->state=state;
4565 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4571 gui_internal_set_data(struct widget *widget, void *data)
4577 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4579 widget->background=this->background;
4582 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4583 gui_internal_widget_append,
4584 gui_internal_button_new,
4585 gui_internal_button_new_with_callback,
4586 gui_internal_box_new,
4587 gui_internal_label_new,
4588 gui_internal_image_new,
4589 gui_internal_keyboard,
4591 gui_internal_get_flags,
4592 gui_internal_set_flags,
4593 gui_internal_get_state,
4594 gui_internal_set_state,
4595 gui_internal_set_func,
4596 gui_internal_set_data,
4597 gui_internal_set_default_background,
4601 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
4603 char *str=NULL,*str2=NULL;
4604 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
4607 dbg(1,"%s\n",attr_to_name(in[0]->type));
4608 if (ATTR_IS_STRING(in[0]->type)) {
4611 if (ATTR_IS_COORD_GEO(in[0]->type)) {
4612 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
4615 str=g_strdup_printf("<html>%s</html>\n",str);
4616 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4624 * @brief Creates a new table widget.
4626 * Creates and returns a new table widget. This function will
4627 * setup next/previous buttons as children.
4629 * @param this The graphics context.
4630 * @param flags widget sizing flags.
4631 * @returns The newly created widget
4633 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4635 struct widget * widget = g_new0(struct widget,1);
4636 struct table_data * data = NULL;
4637 widget->type=widget_table;
4638 widget->flags=flags;
4639 widget->data = g_new0(struct table_data,1);
4640 widget->data_free=gui_internal_table_data_free;
4641 data = (struct table_data*)widget->data;
4645 data->next_button = gui_internal_button_new_with_callback
4646 (this,"Next",image_new_xs(this, "gui_active") ,
4647 gravity_left_center |orientation_vertical,
4648 gui_internal_table_button_next,NULL);
4649 data->next_button->data=widget;
4652 data->prev_button = gui_internal_button_new_with_callback
4654 image_new_xs(this, "gui_active")
4655 ,gravity_right_center |orientation_vertical,
4656 gui_internal_table_button_prev,NULL);
4658 data->prev_button->data=widget;
4662 data->button_box=gui_internal_box_new(this,
4663 gravity_center|orientation_horizontal);
4664 data->button_box->children=g_list_append(data->button_box->children,
4666 data->button_box->children=g_list_append(data->button_box->children,
4668 //data->button_box->background=this->background2;
4669 data->button_box->bl=this->spacing;
4670 widget->children=g_list_append(widget->children,data->button_box);
4671 gui_internal_widget_pack(this,data->button_box);
4679 * @brief Clears all the rows from the table.
4680 * This function removes all rows from a table.
4681 * New rows can later be added to the table.
4683 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4686 struct table_data * table_data = (struct table_data* ) table->data;
4688 iter = table->children;
4690 if(iter->data != table_data->button_box) {
4691 struct widget * child = (struct widget*)iter->data;
4692 gui_internal_widget_destroy(this,child);
4693 if(table->children == iter) {
4694 table->children = g_list_remove(iter,iter->data);
4695 iter=table->children;
4698 iter = g_list_remove(iter,iter->data);
4701 iter = g_list_next(iter);
4705 table_data->top_row=NULL;
4706 table_data->bottom_row=NULL;
4707 if(table_data->page_headers)
4708 g_list_free(table_data->page_headers);
4709 table_data->page_headers=NULL;
4714 * Creates a new table_row widget.
4715 * @param this The graphics context
4716 * @param flags Sizing flags for the row
4717 * @returns The new table_row widget.
4719 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4721 struct widget * widget = g_new0(struct widget,1);
4722 widget->type=widget_table_row;
4723 widget->flags=flags;
4730 * @brief Computes the column dimensions for the table.
4732 * @param w The table widget to compute dimensions for.
4734 * This function examines all of the rows and columns for the table w
4735 * and returns a list (GList) of table_column_desc elements that
4736 * describe each column of the table.
4738 * The caller is responsible for freeing the returned list.
4740 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4743 GList * column_desc = NULL;
4744 GList * current_desc=NULL;
4745 GList * cur_row = w->children;
4746 struct widget * cur_row_widget=NULL;
4747 GList * cur_column=NULL;
4748 struct widget * cell_w=NULL;
4749 struct table_column_desc * current_cell=NULL;
4750 struct table_data * table_data=NULL;
4757 * Scroll through the the table and
4758 * 1. Compute the maximum width + height of each column across all rows.
4760 table_data = (struct table_data*) w->data;
4761 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4763 cur_row_widget = (struct widget*) cur_row->data;
4764 current_desc = column_desc;
4765 if(cur_row_widget == table_data->button_box)
4770 for(cur_column = cur_row_widget->children; cur_column;
4771 cur_column=g_list_next(cur_column))
4773 cell_w = (struct widget*) cur_column->data;
4774 gui_internal_widget_pack(this,cell_w);
4775 if(current_desc == 0)
4777 current_cell = g_new0(struct table_column_desc,1);
4778 column_desc = g_list_append(column_desc,current_cell);
4779 current_desc = g_list_last(column_desc);
4780 current_cell->height=cell_w->h;
4781 current_cell->width=cell_w->w;
4782 total_width+=cell_w->w;
4787 current_cell = current_desc->data;
4790 if(current_cell->height < height )
4792 current_cell->height = height;
4794 if(current_cell->width < width)
4796 total_width += (width-current_cell->width);
4797 current_cell->width = width;
4802 current_desc = g_list_next(current_desc);
4812 * If the width of all columns is less than the width off
4813 * the table expand each cell proportionally.
4816 if(total_width+(this->spacing*column_count) < w->w ) {
4817 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4818 current_cell = (struct table_column_desc*) current_desc->data;
4819 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4828 * @brief Computes the height and width for the table.
4830 * The height and widht are computed to display all cells in the table
4831 * at the requested height/width.
4833 * @param this The graphics context
4834 * @param w The widget to pack.
4837 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4843 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4845 struct table_column_desc * cell_desc=0;
4846 struct table_data * table_data = (struct table_data*)w->data;
4848 for(current = column_data; current; current=g_list_next(current))
4850 if(table_data->button_box == current->data )
4854 cell_desc = (struct table_column_desc *) current->data;
4855 width = width + cell_desc->width + this->spacing;
4856 if(height < cell_desc->height)
4858 height = cell_desc->height ;
4864 for(current=w->children; current; current=g_list_next(current))
4866 if(current->data!= table_data->button_box)
4871 if (table_data->button_box)
4872 gui_internal_widget_pack(this,table_data->button_box);
4876 if(w->h + w->c.y > this->root.h )
4879 * Do not allow the widget to exceed the screen.
4882 w->h = this->root.h- w->c.y - height;
4887 * Deallocate column descriptions.
4889 current = column_data;
4890 while( (current = g_list_last(current)) )
4892 current = g_list_remove(current,current->data);
4900 * @brief Renders a table widget.
4902 * @param this The graphics context
4903 * @param w The table widget to render.
4905 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4910 GList * column_desc=NULL;
4911 GList * cur_row = NULL;
4912 GList * current_desc=NULL;
4913 struct table_data * table_data = (struct table_data*)w->data;
4915 int is_first_page=1;
4916 struct table_column_desc * dim=NULL;
4918 dbg_assert(table_data);
4919 column_desc = gui_internal_compute_table_dimensions(this,w);
4923 * Skip rows that are on previous pages.
4925 cur_row = w->children;
4926 if(table_data->top_row && table_data->top_row != w->children )
4928 cur_row = table_data->top_row;
4934 * Loop through each row. Drawing each cell with the proper sizes,
4935 * at the proper positions.
4937 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4939 GList * cur_column=NULL;
4940 current_desc = column_desc;
4941 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4943 x =w->p.x+this->spacing;
4944 if(cur_row_widget == table_data->button_box )
4948 dim = (struct table_column_desc*)current_desc->data;
4950 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4953 * No more drawing space left.
4959 for(cur_column = cur_row_widget->children; cur_column;
4960 cur_column=g_list_next(cur_column))
4962 struct widget * cur_widget = (struct widget*) cur_column->data;
4963 dim = (struct table_column_desc*)current_desc->data;
4966 cur_widget->w=dim->width;
4968 cur_widget->h=dim->height;
4970 max_height = dim->height;
4971 /* We pack the widget before rendering to ensure that the x and y
4972 * coordinates get pushed down.
4974 gui_internal_widget_pack(this,cur_widget);
4975 gui_internal_widget_render(this,cur_widget);
4977 if(dim->height > max_height)
4979 max_height = dim->height;
4983 table_data->bottom_row=cur_row;
4984 current_desc = g_list_next(current_desc);
4986 if(table_data->button_box && (is_skipped || !is_first_page) )
4988 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4990 if(table_data->button_box->p.y < y )
4992 table_data->button_box->p.y=y;
4994 table_data->button_box->p.x = w->p.x;
4995 table_data->button_box->w = w->w;
4996 // table_data->button_box->h = w->h - y;
4997 // table_data->next_button->h=table_data->button_box->h;
4998 // table_data->prev_button->h=table_data->button_box->h;
4999 // table_data->next_button->c.y=table_data->button_box->c.y;
5000 // table_data->prev_button->c.y=table_data->button_box->c.y;
5002 gui_internal_widget_pack(this,table_data->button_box);
5003 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
5006 table_data->button_box->p.y = w->p.y + w->h -
5007 table_data->button_box->h;
5011 table_data->next_button->state|= STATE_SENSITIVE;
5015 table_data->next_button->state&= ~STATE_SENSITIVE;
5018 if(table_data->top_row != w->children)
5020 table_data->prev_button->state|= STATE_SENSITIVE;
5024 table_data->prev_button->state&= ~STATE_SENSITIVE;
5026 gui_internal_widget_render(this,table_data->button_box);
5032 * Deallocate column descriptions.
5034 current_desc = column_desc;
5035 while( (current_desc = g_list_last(current_desc)) )
5037 current_desc = g_list_remove(current_desc,current_desc->data);
5043 * @brief Displays Route information
5045 * @li The name of the active vehicle
5046 * @param wm The button that was pressed.
5050 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5054 struct widget * menu;
5055 struct widget * row;
5058 if(! this->vehicle_cb)
5061 * Register the callback on vehicle updates.
5063 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
5064 attr_position_coord_geo,this);
5065 navit_add_callback(this->nav,this->vehicle_cb);
5068 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
5069 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
5071 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
5074 menu=gui_internal_menu(this,_("Route Description"));
5076 menu->free=gui_internal_route_screen_free;
5077 this->route_data.route_showing=1;
5078 this->route_data.route_table->spx = this->spacing;
5081 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
5083 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
5084 gui_internal_widget_append(box,this->route_data.route_table);
5086 box->spx = this->spacing;
5087 this->route_data.route_table->w=box->w;
5088 gui_internal_widget_append(menu,box);
5089 gui_internal_populate_route_table(this,this->nav);
5090 gui_internal_menu_render(this);
5095 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
5098 int adx=a2->x-a1->x;
5099 int ady=a2->y-a1->y;
5100 int bdx=b2->x-b1->x;
5101 int bdy=b2->y-b1->y;
5102 n = bdy * adx - bdx * ady;
5103 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
5104 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
5115 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
5116 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
5117 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
5120 res->x = a1->x + a * adx / n;
5121 res->y = a1->y + a * ady / n;
5126 struct heightline *next;
5128 struct coord_rect bbox;
5133 struct diagram_point {
5134 struct diagram_point *next;
5138 static struct heightline *
5139 item_get_heightline(struct item *item)
5141 struct heightline *ret=NULL;
5142 struct street_data *sd;
5146 if (item_attr_get(item, attr_label, &attr)) {
5147 height=atoi(attr.u.str);
5148 sd=street_get_data(item);
5149 if (sd && sd->count > 1) {
5150 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
5151 ret->bbox.lu=sd->c[0];
5152 ret->bbox.rl=sd->c[0];
5153 ret->count=sd->count;
5155 for (i = 0 ; i < sd->count ; i++) {
5157 coord_rect_extend(&ret->bbox, sd->c+i);
5160 street_data_free(sd);
5167 * @brief Displays Route Height Profile
5169 * @li The name of the active vehicle
5170 * @param wm The button that was pressed.
5174 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5178 struct widget * menu, *box;
5180 struct map * map=NULL;
5181 struct map_rect * mr=NULL;
5182 struct route * route;
5183 struct item * item =NULL;
5185 struct mapset_handle *msh;
5186 int x,i,first=1,dist=0;
5187 struct coord c,last,res;
5188 struct coord_rect rbbox,dbbox;
5189 struct map_selection sel;
5190 struct heightline *heightline,*heightlines=NULL;
5191 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
5194 sel.range.min=type_height_line_1;
5195 sel.range.max=type_height_line_3;
5198 menu=gui_internal_menu(this,_("Height Profile"));
5199 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
5200 gui_internal_widget_append(menu, box);
5201 route = navit_get_route(this->nav);
5203 map = route_get_map(route);
5205 mr = map_rect_new(map,NULL);
5207 while((item = map_rect_get_item(mr))) {
5208 while (item_coord_get(item, &c, 1)) {
5214 coord_rect_extend(&sel.u.c_rect, &c);
5217 map_rect_destroy(mr);
5218 ms=navit_get_mapset(this->nav);
5220 msh=mapset_open(ms);
5221 while ((map=mapset_next(msh, 1))) {
5222 mr=map_rect_new(map, &sel);
5224 while((item = map_rect_get_item(mr))) {
5225 if (item->type >= sel.range.min && item->type <= sel.range.max) {
5226 heightline=item_get_heightline(item);
5228 heightline->next=heightlines;
5229 heightlines=heightline;
5233 map_rect_destroy(mr);
5242 map = route_get_map(route);
5244 mr = map_rect_new(map,NULL);
5245 if(mr && heightlines) {
5246 while((item = map_rect_get_item(mr))) {
5248 while (item_coord_get(item, &c, 1)) {
5252 heightline=heightlines;
5255 coord_rect_extend(&rbbox, &c);
5256 while (heightline) {
5257 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
5258 for (i = 0 ; i < heightline->count - 1; i++) {
5259 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
5260 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
5261 diagram_point=g_new(struct diagram_point, 1);
5262 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
5263 diagram_point->c.y=heightline->height;
5264 diagram_point->next=diagram_points;
5265 diagram_points=diagram_point;
5266 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
5271 heightline=heightline->next;
5273 dist+=transform_distance(projection_mg, &last, &c);
5279 map_rect_destroy(mr);
5283 gui_internal_menu_render(this);
5285 diagram_point=diagram_points;
5286 while (diagram_point) {
5288 dbbox.lu=diagram_point->c;
5289 dbbox.rl=diagram_point->c;
5292 coord_rect_extend(&dbbox, &diagram_point->c);
5293 diagram_point=diagram_point->next;
5295 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
5296 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
5298 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
5300 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
5306 diagram_point=diagram_points;
5307 while (diagram_point) {
5308 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
5310 diagram_point=diagram_point->next;
5314 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
5315 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
5316 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
5317 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
5321 graphics_draw_lines(this->gra, this->foreground, p, 2);
5330 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5332 struct widget *menu,*wb,*w;
5335 graphics_draw_mode(this->gra, draw_mode_begin);
5336 menu=gui_internal_menu(this, _("Show Locale"));
5337 menu->spx=this->spacing*10;
5338 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5339 gui_internal_widget_append(menu, wb);
5340 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5341 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5342 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5344 #ifdef HAVE_API_WIN32_BASE
5346 wchar_t wcountry[32],wlang[32];
5347 char country[32],lang[32];
5349 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5350 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5351 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5352 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5353 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5355 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5356 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5357 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5358 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5359 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5364 gui_internal_menu_render(this);
5365 graphics_draw_mode(this->gra, draw_mode_end);
5370 * @brief handles the 'next page' table event.
5371 * A callback function that is invoked when the 'next page' button is pressed
5372 * to advance the contents of a table widget.
5374 * @param this The graphics context.
5375 * @param wm The button widget that was pressed.
5377 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5379 struct widget * table_widget = (struct widget * ) wm->data;
5380 struct table_data * table_data = NULL;
5386 table_data = (struct table_data*) table_widget->data;
5392 * Before advancing to the next page we need to ensure
5393 * that the current top_row is in the list of previous top_rows
5394 * so previous page can work.
5397 for(iterator=table_data->page_headers; iterator != NULL;
5398 iterator = g_list_next(iterator) )
5400 if(iterator->data == table_data->top_row)
5409 table_data->page_headers=g_list_append(table_data->page_headers,
5410 table_data->top_row);
5413 table_data->top_row = g_list_next(table_data->bottom_row);
5415 wm->state&= ~STATE_HIGHLIGHTED;
5416 gui_internal_menu_render(this);
5422 * @brief handles the 'previous page' table event.
5423 * A callback function that is invoked when the 'previous page' button is pressed
5424 * to go back in the contents of a table widget.
5426 * @param this The graphics context.
5427 * @param wm The button widget that was pressed.
5429 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5431 struct widget * table_widget = (struct widget * ) wm->data;
5432 struct table_data * table_data = NULL;
5433 GList * current_page_top=NULL;
5438 table_data = (struct table_data*) table_widget->data;
5441 current_page_top = table_data->top_row;
5442 for(iterator = table_data->page_headers; iterator != NULL;
5443 iterator = g_list_next(iterator))
5445 if(current_page_top == iterator->data)
5449 table_data->top_row = (GList*) iterator->data;
5453 wm->state&= ~STATE_HIGHLIGHTED;
5454 gui_internal_menu_render(this);
5459 * @brief deallocates a table_data structure.
5462 void gui_internal_table_data_free(void * p)
5467 * @note button_box and its children (next_button,prev_button)
5468 * have their memory managed by the table itself.
5470 struct table_data * table_data = (struct table_data*) p;
5471 g_list_free(table_data->page_headers);
5479 * @brief Called when the route is updated.
5481 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5484 if(this->route_data.route_showing) {
5485 gui_internal_populate_route_table(this,navit);
5486 graphics_draw_mode(this->gra, draw_mode_begin);
5487 gui_internal_menu_render(this);
5488 graphics_draw_mode(this->gra, draw_mode_end);
5496 * @brief Called when the route screen is closed (deallocated).
5498 * The main purpose of this function is to remove the widgets from
5499 * references route_data because those widgets are about to be freed.
5501 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5504 this_->route_data.route_showing=0;
5505 this_->route_data.route_table=NULL;
5512 * @brief Populates the route table with route information
5514 * @param this The gui context
5515 * @param navit The navit object
5517 void gui_internal_populate_route_table(struct gui_priv * this,
5518 struct navit * navit)
5520 struct map * map=NULL;
5521 struct map_rect * mr=NULL;
5522 struct navigation * nav = NULL;
5523 struct item * item =NULL;
5525 struct widget * label = NULL;
5526 struct widget * row = NULL;
5527 nav = navit_get_navigation(navit);
5531 map = navigation_get_map(nav);
5533 mr = map_rect_new(map,NULL);
5535 gui_internal_widget_table_clear(this,this->route_data.route_table);
5536 while((item = map_rect_get_item(mr))) {
5537 if(item_attr_get(item,attr_navigation_long,&attr)) {
5538 label = gui_internal_label_new(this,attr.u.str);
5539 row = gui_internal_widget_table_row_new(this,
5542 | orientation_horizontal);
5543 row->children=g_list_append(row->children,label);
5544 gui_internal_widget_append(this->route_data.route_table,row);
5552 static struct command_table commands[] = {
5553 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
5554 {"back",command_cast(gui_internal_cmd2_back)},
5555 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
5556 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
5557 {"get_data",command_cast(gui_internal_get_data)},
5558 {"locale",command_cast(gui_internal_cmd2_locale)},
5559 {"log",command_cast(gui_internal_cmd_log)},
5560 {"menu",command_cast(gui_internal_cmd_menu2)},
5561 {"position",command_cast(gui_internal_cmd2_position)},
5562 {"route_description",command_cast(gui_internal_cmd2_route_description)},
5563 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
5564 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
5565 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
5566 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
5567 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
5568 {"town",command_cast(gui_internal_cmd2_town)},
5569 {"quit",command_cast(gui_internal_cmd2_quit)},
5570 {"write",command_cast(gui_internal_cmd_write)},
5574 //##############################################################################################################
5577 //# Authors: Martin Schaller (04/2008)
5578 //##############################################################################################################
5579 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
5581 struct gui_priv *this;
5583 *meth=gui_internal_methods;
5584 this=g_new0(struct gui_priv, 1);
5587 this->self.type=attr_gui;
5588 this->self.u.gui=gui;
5590 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
5591 this->menu_on_map_click=attr->u.num;
5593 this->menu_on_map_click=1;
5594 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
5595 this->signal_on_map_click=attr->u.num;
5597 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
5598 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
5601 if( (attr=attr_search(attrs,NULL,attr_font_size)))
5603 this->config.font_size=attr->u.num;
5607 this->config.font_size=-1;
5609 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
5611 this->config.icon_xs=attr->u.num;
5615 this->config.icon_xs=-1;
5617 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
5619 this->config.icon_l=attr->u.num;
5623 this->config.icon_l=-1;
5625 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
5627 this->config.icon_s=attr->u.num;
5631 this->config.icon_s=-1;
5633 if( (attr=attr_search(attrs,NULL,attr_spacing)))
5635 this->config.spacing=attr->u.num;
5639 this->config.spacing=-1;
5641 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
5643 this->speech=attr->u.num;
5645 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
5646 this->keyboard=attr->u.num;
5650 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
5651 this->fullscreen=attr->u.num;
5653 if( (attr=attr_search(attrs,NULL,attr_flags)))
5654 this->flags=attr->u.num;
5655 if( (attr=attr_search(attrs,NULL,attr_background_color)))
5656 this->background_color=*attr->u.color;
5658 this->background_color=COLOR_BLACK;
5659 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
5660 this->background2_color=*attr->u.color;
5662 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
5663 if( (attr=attr_search(attrs,NULL,attr_text_color)))
5664 this->text_foreground_color=*attr->u.color;
5666 this->text_foreground_color=COLOR_WHITE;
5667 this->text_background_color=COLOR_BLACK;
5668 if( (attr=attr_search(attrs,NULL,attr_columns)))
5669 this->cols=attr->u.num;
5670 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
5671 this->osd_configuration=*attr;
5673 if( (attr=attr_search(attrs,NULL,attr_pitch)))
5674 this->pitch=attr->u.num;
5677 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
5678 this->flags_town=attr->u.num;
5680 this->flags_town=-1;
5681 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
5682 this->flags_street=attr->u.num;
5684 this->flags_street=-1;
5685 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
5686 this->flags_house_number=attr->u.num;
5688 this->flags_house_number=-1;
5689 this->data.priv=this;
5690 this->data.gui=&gui_internal_methods_ext;
5691 this->data.widget=&gui_internal_widget_methods;
5692 this->cbl=callback_list_new();
5697 //##############################################################################################################
5700 //# Authors: Martin Schaller (04/2008)
5701 //##############################################################################################################
5702 void plugin_init(void)
5704 plugin_register_gui_type("internal", gui_internal_new);