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"
81 struct widget *search_list;
82 struct widget *keyboard;
83 struct widget *button_bar;
86 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
87 struct widget *redisplay_widget;
90 //##############################################################################################################
93 //# Authors: Martin Schaller (04/2008)
94 //##############################################################################################################
96 enum widget_type type;
97 struct graphics_gc *background,*text_background;
98 struct graphics_gc *foreground_frame;
99 struct graphics_gc *foreground;
101 struct graphics_image *img;
103 * A function to be invoked on actions.
104 * @li widget The widget that is receiving the button press.
107 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
112 * @brief A function to deallocate data
114 void (*data_free)(void *data);
117 * @brief a function that will be called as the widget is being destroyed.
118 * This function can act as a destructor for the widget. It allows for
119 * on deallocation actions to be specified on a per widget basis.
120 * This function will call g_free on the widget (if required).
122 void (*free) (struct gui_priv *this_, struct widget * w);
136 int bl,br,bt,bb,spx,spy;
140 * The number of widgets to layout horizontally when doing
141 * a orientation_horizontal_vertical layout
147 int (*set_attr)(void *, struct attr *);
148 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
149 void (*remove_cb)(void *, struct callback *cb);
156 struct menu_data *menu_data;
162 * @brief A structure to store configuration values.
164 * This structure stores configuration values for how gui elements in the internal GUI
167 struct gui_config_settings {
170 * The base size (in fractions of a point) to use for text.
174 * The size (in pixels) that xs style icons should be scaled to.
178 * The size (in pixels) that s style icons (small) should be scaled to
182 * The size (in pixels) that l style icons should be scaled to
186 * The default amount of spacing (in pixels) to place between GUI elements.
193 * Indexes into the config_profiles array.
195 const int LARGE_PROFILE=0;
196 const int MEDIUM_PROFILE=1;
197 const int SMALL_PROFILE=2;
200 * The default config profiles.
202 * [0] => LARGE_PROFILE (screens 640 in one dimension)
203 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
204 * [2] => Small profile (default)
206 static struct gui_config_settings config_profiles[]={
213 struct widget * route_table;
218 //##############################################################################################################
221 //# Authors: Martin Schaller (04/2008)
222 //##############################################################################################################
227 struct graphics *gra;
228 struct graphics_gc *background;
229 struct graphics_gc *background2;
230 struct graphics_gc *highlight_background;
231 struct graphics_gc *foreground;
232 struct graphics_gc *text_foreground;
233 struct graphics_gc *text_background;
234 struct color background_color, background2_color, text_foreground_color, text_background_color;
238 struct graphics_font *fonts[3];
239 int icon_xs, icon_s, icon_l;
241 struct widget *widgets;
245 struct widget *highlighted,*editable;
246 struct widget *highlighted_menu;
247 int clickp_valid, vehicle_valid;
248 struct pcoord clickp, vehiclep;
249 struct attr *click_coord_geo, *position_coord_geo;
250 struct search_list *sl;
252 int menu_on_map_click;
253 int signal_on_map_click;
257 int keyboard_required;
259 * The setting information read from the configuration file.
260 * values of -1 indicate no value was specified in the config file.
262 struct gui_config_settings config;
263 struct event_idle *idle;
264 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
265 struct event_timeout *motion_timeout_event;
266 struct point current;
268 struct callback * vehicle_cb;
270 * Stores information about the route.
272 struct route_data route_data;
274 struct gui_internal_data data;
275 struct callback_list *cbl;
278 struct attr osd_configuration;
280 int flags_town,flags_street,flags_house_number;
284 struct widget *html_container;
287 int html_anchor_found;
306 struct widget *container;
310 struct html_tag_map {
316 {"html",html_tag_html},
317 {"img",html_tag_img},
318 {"script",html_tag_script},
319 {"form",html_tag_form},
320 {"input",html_tag_input},
321 {"div",html_tag_div},
326 * @brief A structure to store information about a table.
328 * The table_data widget stores pointers to extra information needed by the
331 * The table_data structure needs to be freed with data_free along with the widget.
337 * A GList pointer into a widget->children list that indicates the row
338 * currently being rendered at the top of the table.
342 * A Glist pointer into a widget->children list that indicates the row
343 * currently being rendered at the bottom of the table.
348 * A list of table_row widgets that mark the
349 * top rows for each page of the table.
350 * This is needed for the 'previous page' function of the table.
352 GList * page_headers;
355 * A container box that is the child of the table widget that contains+groups
356 * the next and previous button.
358 struct widget * button_box;
361 * A button widget to handle 'next page' requests
363 struct widget * next_button;
365 * A button widget to handle 'previous page' requests.
367 struct widget * prev_button;
371 * a pointer to the gui context.
372 * This is needed by the free function to destory the buttons.
374 struct gui_priv * this;
378 * A data structure that holds information about a column that makes up a table.
382 struct table_column_desc
386 * The computed height of a cell in the table.
391 * The computed width of a cell in the table.
397 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
398 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
399 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
400 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
401 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
402 static void gui_internal_apply_config(struct gui_priv *this);
404 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
405 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
406 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
407 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
408 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
409 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
410 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
411 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
412 static void gui_internal_table_data_free(void * d);
413 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
415 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
416 static void gui_internal_populate_route_table(struct gui_priv * this,
417 struct navit * navit);
418 static void gui_internal_search_idle_end(struct gui_priv *this);
419 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
420 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
421 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
422 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
423 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
424 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
425 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
426 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
427 static void gui_internal_check_exit(struct gui_priv *this);
428 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
430 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
431 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
433 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
434 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
437 * * Display image scaled to specific size
438 * * searches for scaleable and pre-scaled image
439 * * @param this Our gui context
440 * * @param name image name
441 * * @param w desired width of image
442 * * @param h desired height of image
443 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
445 static struct graphics_image *
446 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
448 struct graphics_image *ret=NULL;
449 char *full_name=NULL;
450 char *full_path=NULL;
453 for (i = 1 ; i < 6 ; i++) {
457 full_name=g_strdup_printf("%s.svg", name);
460 full_name=g_strdup_printf("%s.svgz", name);
463 if (w != -1 && h != -1) {
464 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
468 full_name=g_strdup_printf("%s.png", name);
471 full_name=g_strdup_printf("%s.xpm", name);
474 dbg(1,"trying '%s'\n", full_name);
478 /* needs to be checked in the driver */
479 if (!file_exists(full_name)) {
484 full_path=graphics_icon_path(full_name);
485 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
486 dbg(1,"ret=%p\n", ret);
492 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
497 static struct graphics_image *
498 image_new_o(struct gui_priv *this, char *name)
500 return image_new_scaled(this, name, -1, -1);
504 static struct graphics_image *
505 image_new_xs(struct gui_priv *this, const char *name)
507 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
511 static struct graphics_image *
512 image_new_s(struct gui_priv *this, const char *name)
514 return image_new_scaled(this, name, this->icon_s, this->icon_s);
517 static struct graphics_image *
518 image_new_l(struct gui_priv *this, const char *name)
520 return image_new_scaled(this, name, this->icon_l, this->icon_l);
524 coordinates_geo(const struct coord_geo *gc, char sep)
526 char latc='N',lngc='E';
527 int lat_deg,lat_min,lat_sec;
528 int lng_deg,lng_min,lng_sec;
529 struct coord_geo g=*gc;
540 lat_min=fmod(g.lat*60,60);
541 lat_sec=fmod(g.lat*3600,60);
543 lng_min=fmod(g.lng*60,60);
544 lng_sec=fmod(g.lng*3600,60);
545 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);
549 coordinates(struct pcoord *pc, char sep)
555 transform_to_geo(pc->pro, &c, &g);
556 return coordinates_geo(&g, sep);
561 gui_internal_background_render(struct gui_priv *this, struct widget *w)
563 struct point pnt=w->p;
564 if (w->state & STATE_HIGHLIGHTED)
565 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
568 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
572 static struct widget *
573 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
579 struct widget *widget=g_new0(struct widget, 1);
580 widget->type=widget_label;
581 widget->font_idx=font;
583 widget->text=g_strdup(text);
584 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
588 widget->h=h+this->spacing;
590 widget->w=w+this->spacing;
592 widget->flags=gravity_center;
593 widget->foreground=this->text_foreground;
594 widget->text_background=this->text_background;
599 static struct widget *
600 gui_internal_label_new(struct gui_priv *this, char *text)
602 return gui_internal_label_font_new(this, text, 0);
605 static struct widget *
606 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
608 struct widget *ret=NULL;
609 char *tmp=g_malloc(strlen(text)+3);
616 ret=gui_internal_label_new(this, tmp);
617 if (ret->w < maxwidth)
619 gui_internal_widget_destroy(this, ret);
627 static struct widget *
628 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
630 struct widget *widget=g_new0(struct widget, 1);
631 widget->type=widget_image;
634 widget->w=image->width;
635 widget->h=image->height;
641 gui_internal_image_render(struct gui_priv *this, struct widget *w)
645 gui_internal_background_render(this, w);
648 pnt.x+=w->w/2-w->img->hot.x;
649 pnt.y+=w->h/2-w->img->hot.y;
650 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
655 gui_internal_label_render(struct gui_priv *this, struct widget *w)
657 struct point pnt=w->p;
658 gui_internal_background_render(this, w);
659 if (w->state & STATE_EDIT)
660 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
662 char *text,startext[strlen(w->text)+1];
666 for (i = 0 ; i < strlen(text); i++)
671 if (w->flags & gravity_right) {
672 pnt.y+=w->h-this->spacing;
673 pnt.x+=w->w-w->textw-this->spacing;
674 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
676 pnt.y+=w->h-this->spacing;
677 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
683 * @brief A text box is a widget that renders a text string containing newlines.
684 * The string will be broken up into label widgets at each newline with a vertical layout.
687 static struct widget *
688 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
690 char *s=g_strdup(text),*s2,*tok;
691 struct widget *ret=gui_internal_box_new(this, flags);
693 while ((tok=strtok(s2,"\n"))) {
694 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
697 gui_internal_widget_pack(this,ret);
701 static struct widget *
702 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
704 return gui_internal_text_font_new(this, text, 0, flags);
708 static struct widget *
709 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)
711 struct widget *ret=NULL;
712 ret=gui_internal_box_new(this, flags);
715 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
717 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
721 ret->state |= STATE_SENSITIVE;
722 ret->speech=g_strdup(text);
729 static struct widget *
730 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)
732 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
736 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
743 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
744 is_on=curr.u.data == w->on.u.data;
747 if (is_on != w->is_on) {
751 l=g_list_first(w->children);
755 graphics_image_free(this->gra, wi->img);
756 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
758 if (w->is_on && w->off.type == attr_none)
759 w->state &= ~STATE_SENSITIVE;
761 w->state |= STATE_SENSITIVE;
768 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
770 if (gui_internal_button_attr_update(this, w))
771 gui_internal_widget_render(this, w);
774 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
777 w->set_attr(w->instance, &w->off);
779 w->set_attr(w->instance, &w->on);
780 gui_internal_button_attr_update(this, w);
784 static struct widget *
785 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
787 struct graphics_image *image=NULL;
791 image=image_new_xs(this, "gui_inactive");
792 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
797 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
798 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
799 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
800 ret->instance=this->nav;
801 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
802 navit_add_callback(this->nav, ret->cb);
803 gui_internal_button_attr_update(this, ret);
807 static struct widget *
808 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)
810 struct graphics_image *image=NULL;
812 image=image_new_xs(this, "gui_inactive");
815 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
821 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
822 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
823 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
826 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
827 map_add_callback(map, ret->cb);
828 gui_internal_button_attr_update(this, ret);
832 static struct widget *
833 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
835 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
839 //##############################################################################################################
842 //# Authors: Martin Schaller (04/2008)
843 //##############################################################################################################
844 static void gui_internal_clear(struct gui_priv *this)
846 struct graphics *gra=this->gra;
850 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
854 static struct widget *
855 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
857 struct widget *ret,*child;
858 GList *l=wi->children;
865 if ( wi->p.x + wi->w < p->x)
867 if ( wi->p.y + wi->h < p->y)
870 if (wi->state & flags)
874 ret=gui_internal_find_widget(child, p, flags);
885 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
887 if (found == this->highlighted)
890 graphics_draw_mode(this->gra, draw_mode_begin);
891 if (this->highlighted) {
892 this->highlighted->state &= ~STATE_HIGHLIGHTED;
893 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
894 gui_internal_widget_render(this, this->highlighted);
895 this->highlighted=NULL;
896 this->highlighted_menu=NULL;
899 this->highlighted=found;
900 this->highlighted_menu=g_list_last(this->root.children)->data;
901 this->highlighted->state |= STATE_HIGHLIGHTED;
902 gui_internal_widget_render(this, this->highlighted);
903 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
905 graphics_draw_mode(this->gra, draw_mode_end);
907 //##############################################################################################################
910 //# Authors: Martin Schaller (04/2008)
911 //##############################################################################################################
912 static void gui_internal_highlight(struct gui_priv *this)
914 struct widget *menu,*found=NULL;
915 if (this->current.x > -1 && this->current.y > -1) {
916 menu=g_list_last(this->root.children)->data;
917 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
919 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
921 if (this->editable && this->editable != found) {
922 this->editable->state &= ~ STATE_EDIT;
923 gui_internal_widget_render(this, this->editable);
925 found->state |= STATE_EDIT;
926 gui_internal_widget_render(this, found);
927 this->editable=found;
932 gui_internal_highlight_do(this, found);
933 this->motion_timeout_event=NULL;
936 static struct widget *
937 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
939 struct widget *widget=g_new0(struct widget, 1);
942 widget->text=g_strdup(label);
943 widget->type=widget_box;
948 static struct widget *
949 gui_internal_box_new(struct gui_priv *this, enum flags flags)
951 return gui_internal_box_new_with_label(this, flags, NULL);
955 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
960 gui_internal_background_render(this, w);
963 w->foreground=this->foreground;
966 if (w->foreground && w->border) {
969 pnt[1].x=pnt[0].x+w->w;
971 pnt[2].x=pnt[0].x+w->w;
972 pnt[2].y=pnt[0].y+w->h;
974 pnt[3].y=pnt[0].y+w->h;
976 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
977 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
978 graphics_gc_set_linewidth(w->foreground, 1);
985 gui_internal_widget_render(this, wc);
992 * @brief Compute the size and location for the widget.
996 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
999 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;
1001 int orientation=w->flags & 0xffff0000;
1006 if ( this->root.w > this->root.h )
1016 * count the number of children
1023 if (orientation == orientation_horizontal_vertical && count <= cols)
1024 orientation=orientation_horizontal;
1025 switch (orientation) {
1026 case orientation_horizontal:
1028 * For horizontal orientation:
1029 * pack each child and find the largest height and
1030 * compute the total width. x spacing (spx) is considered
1032 * If any children want to be expanded
1033 * we keep track of this
1038 gui_internal_widget_pack(this, wc);
1042 if (wc->flags & flags_expand)
1043 expand+=wc->w ? wc->w : 1;
1049 if (expand && w->w) {
1050 expandd=w->w-width+expand;
1055 case orientation_vertical:
1057 * For vertical layouts:
1058 * We pack each child and compute the largest width and
1059 * the total height. y spacing (spy) is considered
1061 * If the expand flag is set then teh expansion amount
1067 gui_internal_widget_pack(this, wc);
1071 if (wc->flags & flags_expand)
1072 expand+=wc->h ? wc->h : 1;
1078 if (expand && w->h) {
1079 expandd=w->h-height+expand;
1084 case orientation_horizontal_vertical:
1086 * For horizontal_vertical orientation
1087 * pack the children.
1088 * Compute the largest height and largest width.
1089 * Layout the widgets based on having the
1090 * number of columns specified by (cols)
1096 gui_internal_widget_pack(this, wc);
1106 rows=(count+cols-1)/cols;
1109 width+=w->spx*(cols-1);
1110 height+=w->spy*(rows-1);
1117 * No orientation was specified.
1118 * width and height are both 0.
1119 * The width & height of this widget
1123 dbg(0,"Warning width and height of a widget are 0");
1126 if (! w->w && ! w->h) {
1127 w->w=w->bl+w->br+width;
1128 w->h=w->bt+w->bb+height;
1137 * At this stage the width and height of this
1138 * widget has been computed.
1139 * We now make a second pass assigning heights,
1140 * widths and coordinates to each child widget.
1143 if (w->flags & gravity_left)
1145 if (w->flags & gravity_xcenter)
1146 x=w->p.x+w->w/2-owidth/2;
1147 if (w->flags & gravity_right)
1148 x=w->p.x+w->w-w->br-owidth;
1149 if (w->flags & gravity_top)
1151 if (w->flags & gravity_ycenter)
1152 y=w->p.y+w->h/2-oheight/2;
1153 if (w->flags & gravity_bottom)
1154 y=w->p.y+w->h-w->bb-oheight;
1156 switch (orientation) {
1157 case orientation_horizontal:
1162 if (wc->flags & flags_fill)
1164 if (wc->flags & flags_expand) {
1167 wc->w=wc->w*expandd/expand;
1169 if (w->flags & gravity_top)
1171 if (w->flags & gravity_ycenter)
1173 if (w->flags & gravity_bottom)
1179 case orientation_vertical:
1184 if (wc->flags & flags_fill)
1186 if (wc->flags & flags_expand) {
1189 wc->h=wc->h*expandd/expand;
1191 if (w->flags & gravity_left)
1193 if (w->flags & gravity_xcenter)
1195 if (w->flags & gravity_right)
1201 case orientation_horizontal_vertical:
1211 if (wc->flags & flags_fill) {
1215 if (w->flags & gravity_left)
1217 if (w->flags & gravity_xcenter)
1218 wc->p.x=x+(width-wc->w)/2;
1219 if (w->flags & gravity_right)
1220 wc->p.x=x+width-wc->w;
1221 if (w->flags & gravity_top)
1223 if (w->flags & gravity_ycenter)
1224 wc->p.y=y+(height-wc->h)/2;
1225 if (w->flags & gravity_bottom)
1226 wc->p.y=y-height-wc->h;
1228 if (++count == cols) {
1240 * Call pack again on each child,
1241 * the child has now had its size and coordinates
1242 * set so they can repack their children.
1247 gui_internal_widget_pack(this, wc);
1253 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1261 gui_internal_widget_reset_pack(this, wc);
1271 gui_internal_widget_append(struct widget *parent, struct widget *child)
1275 if (! child->background)
1276 child->background=parent->background;
1277 parent->children=g_list_append(parent->children, child);
1280 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1282 if (! child->background)
1283 child->background=parent->background;
1284 parent->children=g_list_prepend(parent->children, child);
1287 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1295 gui_internal_widget_destroy(this, wc);
1298 g_list_free(w->children);
1302 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1304 gui_internal_widget_children_destroy(this, w);
1309 graphics_image_free(this->gra, w->img);
1315 w->data_free(w->data);
1316 if (w->cb && w->remove_cb)
1317 w->remove_cb(w->instance, w->cb);
1326 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1328 if(w->p.x > this->root.w || w->p.y > this->root.h)
1333 gui_internal_box_render(this, w);
1336 gui_internal_label_render(this, w);
1339 gui_internal_image_render(this, w);
1342 gui_internal_table_render(this,w);
1350 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1354 gui_internal_box_pack(this, w);
1357 gui_internal_table_pack(this,w);
1363 //##############################################################################################################
1366 //# Authors: Martin Schaller (04/2008)
1367 //##############################################################################################################
1368 static void gui_internal_call_highlighted(struct gui_priv *this)
1370 if (! this->highlighted || ! this->highlighted->func)
1372 this->highlighted->reason=1;
1373 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1377 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1379 char *text=w->speech;
1387 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1388 navit_say(this->nav, text);
1394 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1398 gui_internal_search_idle_end(this);
1399 while ((l = g_list_last(this->root.children))) {
1401 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1402 gui_internal_say(this, w, 0);
1403 redisplay=w->menu_data->redisplay;
1404 wr=w->menu_data->redisplay_widget;
1405 if (!w->menu_data->redisplay) {
1406 gui_internal_widget_render(this, w);
1409 gui_internal_widget_destroy(this, l->data);
1410 this->root.children=g_list_remove(this->root.children, l->data);
1411 redisplay(this, wr, wr->data);
1414 gui_internal_widget_destroy(this, l->data);
1415 this->root.children=g_list_remove(this->root.children, l->data);
1420 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1423 gui_internal_search_idle_end(this);
1424 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1425 gui_internal_widget_destroy(this, l->data);
1426 this->root.children=g_list_remove(this->root.children, l->data);
1429 gui_internal_say(this, l->data, 0);
1430 gui_internal_widget_render(this, l->data);
1435 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1437 gui_internal_prune_menu_count(this, 1, 1);
1441 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1443 gui_internal_prune_menu(this, wm->data);
1447 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1449 graphics_draw_mode(this->gra, draw_mode_begin);
1450 gui_internal_back(this, NULL, NULL);
1451 graphics_draw_mode(this->gra, draw_mode_end);
1452 gui_internal_check_exit(this);
1456 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1458 gui_internal_prune_menu(this, NULL);
1462 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1464 gui_internal_prune_menu(this, this->root.children->data);
1467 static struct widget *
1468 gui_internal_top_bar(struct gui_priv *this)
1470 struct widget *w,*wm,*wh,*wc,*wcn;
1471 int dots_len, sep_len;
1473 int width,width_used=0,use_sep=0,incomplete=0;
1474 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1476 1:Don't expand bar to screen width
1477 2:Don't show Map Icon
1478 4:Don't show Home Icon
1479 8:Show only current menu
1480 16:Don't use menu titles as button
1481 32:Show navit version
1484 256:Use background for menu headline
1485 512:Set osd_configuration and zoom to route when setting position
1486 1024:Don't show back button
1487 2048:No highlighting of keyboard
1490 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1491 w->bl=this->spacing;
1492 w->spx=this->spacing;
1493 w->background=this->background2;
1494 if ((this->flags & 6) == 6) {
1500 width=this->root.w-w->bl;
1501 if (! (this->flags & 2)) {
1502 wm=gui_internal_button_new_with_callback(this, NULL,
1503 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1504 gui_internal_cmd_return, NULL);
1505 wm->speech=g_strdup(_("Back to map"));
1506 gui_internal_widget_pack(this, wm);
1507 gui_internal_widget_append(w, wm);
1510 if (! (this->flags & 4)) {
1511 wh=gui_internal_button_new_with_callback(this, NULL,
1512 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1513 gui_internal_cmd_main_menu, NULL);
1514 wh->speech=g_strdup(_("Main Menu"));
1515 gui_internal_widget_pack(this, wh);
1516 gui_internal_widget_append(w, wh);
1519 if (!(this->flags & 6))
1521 l=g_list_last(this->root.children);
1522 wcn=gui_internal_label_new(this,".. »");
1523 wcn->foreground=foreground;
1525 gui_internal_widget_destroy(this, wcn);
1526 wcn=gui_internal_label_new(this,"»");
1527 wcn->foreground=foreground;
1529 gui_internal_widget_destroy(this, wcn);
1531 if (g_list_previous(l) || !g_list_next(l)) {
1533 wcn=gui_internal_label_new(this, wc->text);
1534 wcn->foreground=foreground;
1539 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1540 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1542 gui_internal_widget_destroy(this, wcn);
1546 struct widget *wct=gui_internal_label_new(this, "»");
1547 wct->foreground=foreground;
1548 res=g_list_prepend(res, wct);
1549 width_used+=sep_len+w->spx;
1552 if (!(this->flags & 16)) {
1553 wcn->func=gui_internal_cmd_return;
1555 wcn->state |= STATE_SENSITIVE;
1557 res=g_list_prepend(res, wcn);
1558 if (this->flags & 8)
1561 l=g_list_previous(l);
1565 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1566 wcn->foreground=foreground;
1567 wcn->func=gui_internal_cmd_return;
1569 wcn->state |= STATE_SENSITIVE;
1570 res=g_list_prepend(res, wcn);
1571 l=g_list_previous(l);
1574 wcn=gui_internal_label_new(this, ".. »");
1575 wcn->foreground=foreground;
1576 wcn->func=gui_internal_cmd_return;
1578 wcn->state |= STATE_SENSITIVE;
1579 res=g_list_prepend(res, wcn);
1583 gui_internal_widget_append(w, l->data);
1586 if (this->flags & 32) {
1587 char *version_text=g_strdup_printf("Navit %s",version);
1588 wcn=gui_internal_label_new(this, version_text);
1589 g_free(version_text);
1590 wcn->flags=gravity_right_center|flags_expand;
1591 gui_internal_widget_append(w, wcn);
1595 gui_internal_widget_destroy(this, dots);
1600 static struct widget *
1601 gui_internal_time_help(struct gui_priv *this)
1603 struct widget *w,*wc,*wcn;
1608 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1609 w->bl=this->spacing;
1610 w->spx=this->spacing;
1616 if (this->flags & 64) {
1617 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1623 tm=localtime(&timep);
1624 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1625 wcn=gui_internal_label_new(this, timestr);
1626 gui_internal_widget_append(wc, wcn);
1627 gui_internal_widget_append(w, wc);
1629 if (this->flags & 128) {
1630 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1631 gui_internal_widget_append(w, wcn);
1638 * Applys the configuration values to this based on the settings
1639 * specified in the configuration file (this->config) and
1640 * the most approriate default profile based on screen resolution.
1642 * This function should be run after this->root is setup and could
1643 * be rerun after the window is resized.
1645 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1647 static void gui_internal_apply_config(struct gui_priv *this)
1649 struct gui_config_settings * current_config=0;
1651 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1653 * Select default values from profile based on the screen.
1655 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1657 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1659 current_config = &config_profiles[LARGE_PROFILE];
1663 current_config = &config_profiles[MEDIUM_PROFILE];
1668 current_config = &config_profiles[SMALL_PROFILE];
1672 * Apply override values from config file
1674 if(this->config.font_size == -1 )
1676 this->font_size = current_config->font_size;
1680 this->font_size = this->config.font_size;
1683 if(this->config.icon_xs == -1 )
1685 this->icon_xs = current_config->icon_xs;
1689 this->icon_xs = this->config.icon_xs;
1692 if(this->config.icon_s == -1 )
1694 this->icon_s = current_config->icon_s;
1698 this->icon_s = this->config.icon_s;
1700 if(this->config.icon_l == -1 )
1702 this->icon_l = current_config->icon_l;
1706 this->icon_l = this->config.icon_l;
1708 if(this->config.spacing == -1 )
1710 this->spacing = current_config->spacing;
1714 this->spacing = current_config->spacing;
1719 static struct widget *
1720 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1722 struct widget *wl,*wlb;
1723 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1724 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1725 wl=gui_internal_label_new(this, label);
1727 wlb->foreground=this->text_foreground;
1732 gui_internal_widget_append(wlb, wl);
1734 gui_internal_widget_prepend(wb, wlb);
1736 gui_internal_widget_append(wb, wlb);
1742 static struct widget *
1743 gui_internal_menu(struct gui_priv *this, const char *label)
1745 struct widget *menu,*w,*w1,*topbox;
1747 gui_internal_search_idle_end(this);
1748 topbox=gui_internal_box_new_with_label(this, 0, label);
1749 topbox->w=this->root.w;
1750 topbox->h=this->root.h;
1751 gui_internal_widget_append(&this->root, topbox);
1752 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1753 menu->w=this->root.w;
1754 menu->h=this->root.h;
1755 menu->background=this->background;
1756 gui_internal_apply_config(this);
1757 if (!this->fonts[0]) {
1758 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
1759 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
1760 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
1762 topbox->menu_data=g_new0(struct menu_data, 1);
1763 gui_internal_widget_append(topbox, menu);
1764 w=gui_internal_top_bar(this);
1765 gui_internal_widget_append(menu, w);
1766 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1767 w->spx=4*this->spacing;
1769 gui_internal_widget_append(menu, w);
1770 if (this->flags & 16 && (!this->flags & 1024)) {
1771 struct widget *wlb,*wb,*wm=w;
1772 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1773 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1774 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1775 gui_internal_widget_append(wm, w);
1776 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1782 topbox->menu_data->button_bar=wb;
1783 gui_internal_widget_append(wm, wb);
1784 wlb=gui_internal_button_label(this,_("Back"),1);
1785 wlb->func=gui_internal_back;
1786 wlb->state |= STATE_SENSITIVE;
1788 if (this->flags & 192) {
1789 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1790 menu->w=this->root.w;
1791 menu->h=this->root.h;
1792 w1=gui_internal_time_help(this);
1793 gui_internal_widget_append(menu, w1);
1794 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1795 gui_internal_widget_append(menu, w1);
1796 gui_internal_widget_append(topbox, menu);
1797 menu->background=NULL;
1799 gui_internal_widget_pack(this, topbox);
1800 gui_internal_widget_reset_pack(this, topbox);
1801 topbox->w=this->root.w;
1802 topbox->h=this->root.h;
1803 menu->w=this->root.w;
1804 menu->h=this->root.h;
1808 static struct menu_data *
1809 gui_internal_menu_data(struct gui_priv *this)
1812 struct widget *menu;
1814 l=g_list_last(this->root.children);
1816 return menu->menu_data;
1820 gui_internal_menu_reset_pack(struct gui_priv *this)
1823 struct widget *top_box;
1825 l=g_list_last(this->root.children);
1827 gui_internal_widget_reset_pack(this, top_box);
1831 gui_internal_menu_render(struct gui_priv *this)
1834 struct widget *menu;
1836 l=g_list_last(this->root.children);
1838 gui_internal_say(this, menu, 0);
1839 gui_internal_widget_pack(this, menu);
1840 gui_internal_widget_render(this, menu);
1844 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1847 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1848 navit_set_destination(this->nav, &wm->c, name, 1);
1849 if (this->flags & 512) {
1851 follow.type=attr_follow;
1853 navit_set_attr(this->nav, &this->osd_configuration);
1854 navit_set_attr(this->nav, &follow);
1855 navit_zoom_to_route(this->nav, 0);
1857 gui_internal_prune_menu(this, NULL);
1861 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1863 navit_set_position(this->nav, &wm->c);
1864 gui_internal_prune_menu(this, NULL);
1868 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1871 dbg(0,"text='%s'\n", widget->text);
1872 if (widget->text && strlen(widget->text))
1873 navit_add_bookmark(this->nav, &widget->c, widget->text);
1874 g_free(widget->text);
1876 l=g_list_previous(g_list_last(this->root.children));
1877 gui_internal_prune_menu(this, l->data);
1881 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1883 gui_internal_cmd_add_bookmark_do(this, widget->data);
1887 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1892 len=strlen(wm->text);
1893 dbg(1,"len=%d\n", len);
1894 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1895 wm->text[len-1]='\0';
1896 gui_internal_cmd_add_bookmark_do(this, wm);
1902 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1905 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
1907 struct widget *w,*wb,*wk,*wl,*we,*wnext;
1909 wb=gui_internal_menu(this,_("Add Bookmark"));
1910 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1911 gui_internal_widget_append(wb, w);
1912 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1913 gui_internal_widget_append(w, we);
1914 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
1915 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
1916 wk->background=this->background;
1917 wk->flags |= flags_expand|flags_fill;
1918 wk->func = gui_internal_cmd_add_bookmark_changed;
1920 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1921 wnext->state |= STATE_SENSITIVE;
1922 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1924 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1925 gui_internal_widget_append(w, wl);
1927 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1928 gui_internal_menu_render(this);
1933 get_direction(char *buffer, int angle, int mode)
1938 sprintf(buffer,"%d",angle);
1941 if (angle < 69 || angle > 291)
1943 if (angle > 111 && angle < 249)
1945 if (angle > 22 && angle < 158)
1947 if (angle > 202 && angle < 338)
1952 angle=(angle+15)/30;
1955 sprintf(buffer,"%d H", angle);
1963 enum item_type *types;
1965 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1966 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1967 {"hotel","Hotel",(enum item_type []) {
1968 type_poi_hotel,type_poi_camp_rv,
1969 type_poi_camping,type_poi_camping,
1970 type_poi_resort,type_poi_resort,
1971 type_poi_motel,type_poi_hostel,
1973 {"restaurant","Restaurant",(enum item_type []) {
1974 type_poi_bar,type_poi_picnic,
1975 type_poi_burgerking,type_poi_fastfood,
1976 type_poi_restaurant,type_poi_restaurant,
1978 {"shopping","Shopping",(enum item_type []) {
1979 type_poi_mall,type_poi_mall,
1980 type_poi_shop_grocery,type_poi_shop_grocery,
1982 {"hospital","Service",(enum item_type []) {
1983 type_poi_marina,type_poi_marina,
1984 type_poi_hospital,type_poi_hospital,
1985 type_poi_public_utilities,type_poi_public_utilities,
1986 type_poi_police,type_poi_autoservice,
1987 type_poi_information,type_poi_information,
1988 type_poi_personal_service,type_poi_repair_service,
1989 type_poi_restroom,type_poi_restroom,
1991 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1992 {"peak","Land Features",(enum item_type []){
1993 type_poi_land_feature,type_poi_rock,
1994 type_poi_dam,type_poi_dam,
1996 {"unknown","Other",(enum item_type []){
1997 type_point_unspecified,type_point_unkn-1,
1998 type_point_unkn+1,type_poi_land_feature-1,
1999 type_poi_rock+1,type_poi_fuel-1,
2000 type_poi_marina+1,type_poi_car_parking-1,
2001 type_poi_car_parking+1,type_poi_bar-1,
2002 type_poi_bank+1,type_poi_dam-1,
2003 type_poi_dam+1,type_poi_information-1,
2004 type_poi_information+1,type_poi_mall-1,
2005 type_poi_mall+1,type_poi_personal_service-1,
2006 type_poi_restaurant+1,type_poi_restroom-1,
2007 type_poi_restroom+1,type_poi_shop_grocery-1,
2008 type_poi_shop_grocery+1,type_poi_motel-1,
2009 type_poi_hostel+1,type_selected_point,
2011 {"unknown","Unknown",(enum item_type []){
2012 type_point_unkn,type_point_unkn,
2016 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2018 static struct widget *
2019 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
2021 struct widget *wl,*wb;
2023 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2024 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
2025 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2026 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2027 gui_internal_cmd_pois, &selectors[i]));
2034 static struct widget *
2035 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
2041 struct widget *wl,*wt;
2044 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2046 sprintf(distbuf,"%d", dist/1000);
2047 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2048 type=item_to_name(item->type);
2049 if (item_attr_get(item, attr_label, &attr)) {
2050 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
2053 wl->name=g_strdup(type);
2055 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
2056 wt=gui_internal_label_new(this, text);
2058 gui_internal_widget_append(wl, wt);
2065 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
2067 const struct widget *wa=a;
2068 const struct widget *wb=b;
2069 struct widget *wac=wa->children->data;
2070 struct widget *wbc=wb->children->data;
2078 return wac->datai-wbc->datai;
2083 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
2085 enum item_type *types;
2086 if (type >= type_line)
2088 if (! sel || !sel->types)
2091 while (*types != type_none) {
2092 if (type >= types[0] && type <= types[1]) {
2100 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2103 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
2105 struct map_selection *sel,*selm;
2106 struct coord c,center;
2107 struct mapset_handle *h;
2109 struct map_rect *mr;
2111 int idist,dist=20000;
2112 struct widget *wi,*w,*w2,*wb;
2113 enum projection pro=wm->c.pro;
2114 struct selector *isel=wm->data;
2116 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2117 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2118 gui_internal_widget_append(wb, w);
2120 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
2121 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2122 gui_internal_widget_append(w, w2);
2124 sel=map_selection_rect_new(&wm->c, dist, 18);
2127 h=mapset_open(navit_get_mapset(this->nav));
2128 while ((m=mapset_next(h, 1))) {
2129 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2130 mr=map_rect_new(m, selm);
2131 dbg(2,"mr=%p\n", mr);
2133 while ((item=map_rect_get_item(mr))) {
2134 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
2135 item_coord_get_pro(item, &c, 1, pro) &&
2136 coord_rect_contains(&sel->u.c_rect, &c) &&
2137 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2138 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
2139 wi->func=gui_internal_cmd_position;
2142 wi->state |= STATE_SENSITIVE;
2148 map_rect_destroy(mr);
2150 map_selection_destroy(selm);
2152 map_selection_destroy(sel);
2154 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
2155 gui_internal_menu_render(this);
2159 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2161 if (wm->item.type != type_none) {
2162 enum item_type type;
2163 if (wm->item.type < type_line)
2164 type=type_selected_point;
2165 else if (wm->item.type < type_area)
2166 type=type_selected_point;
2168 type=type_selected_area;
2169 graphics_clear_selection(this->gra, NULL);
2170 graphics_add_selection(this->gra, &wm->item, type, NULL);
2172 navit_set_center(this->nav, &wm->c, 1);
2173 gui_internal_prune_menu(this, NULL);
2178 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2180 struct widget *w,*wb;
2181 struct map_rect *mr;
2187 text=g_strdup_printf("Attribute %s",wm->name);
2188 wb=gui_internal_menu(this, text);
2190 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2191 gui_internal_widget_append(wb, w);
2192 mr=map_rect_new(wm->item.map, NULL);
2193 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2194 for (i = 0 ; i < wm->datai ; i++) {
2195 item_attr_get(item, attr_any, &attr);
2197 if (item_attr_get(item, attr_any, &attr)) {
2199 switch (attr.type) {
2200 case attr_osm_nodeid:
2201 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
2203 case attr_osm_wayid:
2204 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
2206 case attr_osm_relationid:
2207 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
2213 gui_internal_widget_append(w,
2214 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2215 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2216 gui_internal_cmd_view_in_browser, NULL));
2220 map_rect_destroy(mr);
2221 gui_internal_menu_render(this);
2225 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
2227 struct widget *w,*wb;
2228 struct map_rect *mr;
2234 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2235 wb=gui_internal_menu(this, "Attributes");
2236 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2237 gui_internal_widget_append(wb, w);
2238 mr=map_rect_new(wm->item.map, NULL);
2239 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2240 dbg(0,"item=%p\n", item);
2242 while(item_attr_get(item, attr_any, &attr)) {
2243 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2244 gui_internal_widget_append(w,
2245 wb=gui_internal_button_new_with_callback(this, text,
2246 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2247 gui_internal_cmd_view_attribute_details, NULL));
2248 wb->name=g_strdup(text);
2254 map_rect_destroy(mr);
2255 gui_internal_menu_render(this);
2259 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2261 struct map_rect *mr;
2267 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2268 mr=map_rect_new(wm->item.map, NULL);
2269 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2270 dbg(0,"item=%p\n", item);
2272 while(item_attr_get(item, attr_url_local, &attr)) {
2274 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2277 map_rect_destroy(mr);
2279 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
2285 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2292 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)
2294 struct widget *wb,*w,*wc,*wbc;
2304 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2305 transform_to_geo(pc.pro, &c, &g);
2308 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
2311 pc.pro=attr.u.projection;
2312 transform_from_geo(pc.pro, &g, &c);
2318 wb=gui_internal_menu(this, name);
2319 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2320 gui_internal_widget_append(wb, w);
2321 coord=coordinates(&pc, ' ');
2322 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2324 if ((flags & 1) && wm) {
2325 gui_internal_widget_append(w,
2326 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2327 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2328 gui_internal_search_street_in_town, wm));
2330 wc->selection_id=wm->selection_id;
2332 if ((flags & 2) && wm) {
2333 gui_internal_widget_append(w,
2334 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2335 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2336 gui_internal_search_house_number_in_street, wm));
2338 wc->selection_id=wm->selection_id;
2340 if ((flags & 4) && wm) {
2341 struct map_rect *mr;
2344 mr=map_rect_new(wm->item.map, NULL);
2345 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2347 if (item_attr_get(item, attr_description, &attr))
2348 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2349 if (item_attr_get(item, attr_url_local, &attr)) {
2350 gui_internal_widget_append(w,
2351 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2352 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2353 gui_internal_cmd_view_in_browser, NULL));
2356 gui_internal_widget_append(w,
2357 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2358 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2359 gui_internal_cmd_view_attributes, NULL));
2362 map_rect_destroy(mr);
2365 gui_internal_widget_append(w,
2366 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
2367 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2368 gui_internal_cmd_set_destination, g_strdup(name)));
2369 wbc->data_free=g_free;
2373 gui_internal_widget_append(w,
2374 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
2375 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2376 gui_internal_cmd_set_position, wm));
2380 gui_internal_widget_append(w,
2381 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2382 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2383 gui_internal_cmd_add_bookmark2, g_strdup(name)));
2384 wbc->data_free=g_free;
2388 gui_internal_widget_append(w,
2389 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2390 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2391 gui_internal_cmd_pois, NULL));
2395 gui_internal_widget_append(w,
2396 gui_internal_button_new(this, "Add to tour",
2397 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2400 gui_internal_widget_append(w,
2401 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
2402 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2403 gui_internal_cmd_view_on_map, NULL));
2405 if ((flags & 4) && wm)
2408 wbc->item.type=type_none;
2413 struct mapset_handle *h;
2414 struct map_rect *mr;
2417 struct street_data *data;
2418 struct map_selection sel;
2419 struct transformation *trans;
2420 enum projection pro;
2424 trans=navit_get_trans(this->nav);
2425 pro=transform_get_projection(trans);
2426 transform_from_geo(pro, &g, &c);
2427 ms=navit_get_mapset(this->nav);
2429 sel.u.c_rect.lu.x=c.x-dist;
2430 sel.u.c_rect.lu.y=c.y+dist;
2431 sel.u.c_rect.rl.x=c.x+dist;
2432 sel.u.c_rect.rl.y=c.y-dist;
2434 sel.range=item_range_all;
2436 while ((m=mapset_next(h,1))) {
2437 mr=map_rect_new(m, &sel);
2440 while ((item=map_rect_get_item(mr))) {
2441 data=street_get_data(item);
2442 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2443 if (item_attr_get(item, attr_label, &attr)) {
2444 label=map_convert_string(m, attr.u.str);
2445 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2446 map_convert_free(label);
2448 text=g_strdup_printf("%s", item_to_name(item->type));
2449 gui_internal_widget_append(w,
2450 wc=gui_internal_button_new_with_callback(this, text,
2451 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2452 gui_internal_cmd_position, (void *)2));
2453 wc->c.x=data->c[0].x;
2454 wc->c.y=data->c[0].y;
2456 wc->name=g_strdup(text);
2460 street_data_free(data);
2462 map_rect_destroy(mr);
2466 gui_internal_menu_render(this);
2470 /* wm->data: 0 Nothing special
2480 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2483 switch ((int) wm->data) {
2485 flags=8|16|32|64|128|256;
2488 flags=8|16|32|64|256;
2494 flags=1|8|16|32|64|128;
2495 flags &= this->flags_town;
2498 gui_internal_search_town_in_country(this, wm);
2501 flags=2|8|16|32|64|128;
2502 flags &= this->flags_street;
2505 flags=8|16|32|64|128;
2506 flags &= this->flags_house_number;
2513 gui_internal_search_house_number_in_street(this, wm, NULL);
2516 gui_internal_cmd_set_destination(this, wm, NULL);
2519 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
2523 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2525 char *name=_("Position");
2531 if (!ATTR_IS_COORD_GEO(in[0]->type))
2533 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
2535 if (in[2] && ATTR_IS_INT(in[2]->type))
2538 dbg(1,"flags=0x%x\n",flags);
2539 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
2543 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2545 struct attr attr,mattr;
2546 struct map_rect *mr=NULL;
2548 char *label_full,*l,*prefix="",*pos;
2549 int len,plen,hassub,found=0;
2550 struct widget *wb,*w,*wbm;
2553 char *text=_("Bookmarks");
2557 wb=gui_internal_menu(this, text);
2558 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2559 w->spy=this->spacing*3;
2560 gui_internal_widget_append(wb, w);
2565 if (wm && wm->prefix)
2568 plen=strlen(prefix);
2570 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2571 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2572 while ((item=map_rect_get_item(mr))) {
2573 if (item->type != type_bookmark) continue;
2574 if (!item_attr_get(item, attr_label, &attr)) continue;
2575 label_full=attr.u.str;
2576 if (!strncmp(label_full, prefix, plen)) {
2577 pos=strchr(label_full+plen, '/');
2583 len=strlen(label_full);
2585 l=g_malloc(len-plen+1);
2586 strncpy(l, label_full+plen, len-plen);
2588 if (!g_hash_table_lookup(hash, l)) {
2589 wbm=gui_internal_button_new_with_callback(this, l,
2590 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2591 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2592 if (item_coord_get(item, &c, 1)) {
2595 wbm->c.pro=map_projection(mattr.u.map);
2596 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2597 wbm->text=g_strdup(l);
2598 gui_internal_widget_append(w, wbm);
2599 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2600 wbm->prefix=g_malloc(len+2);
2601 strncpy(wbm->prefix, label_full, len+1);
2602 wbm->prefix[len+1]='\0';
2604 gui_internal_cmd_set_destination(this, wbm, wbm->name);
2609 gui_internal_widget_destroy(this, wbm);
2616 g_hash_table_destroy(hash);
2619 gui_internal_check_exit(this);
2621 gui_internal_menu_render(this);
2625 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
2628 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
2631 gui_internal_cmd_bookmarks(this, NULL, str);
2634 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2636 struct widget *wi,*menu;
2640 menu=g_list_last(this->root.children)->data;
2641 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2643 if (*key == NAVIT_KEY_BACKSPACE) {
2644 dbg(0,"backspace\n");
2645 if (wi->text && wi->text[0]) {
2646 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2648 text=g_strdup_printf("%s ", wi->text);
2651 if (wi->state & STATE_CLEAR) {
2652 dbg(0,"wi->state=0x%x\n", wi->state);
2655 wi->state &= ~STATE_CLEAR;
2656 dbg(0,"wi->state=0x%x\n", wi->state);
2658 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2662 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2663 gui_internal_widget_render(this, wi);
2668 wi->func(this, wi, wi->data);
2670 gui_internal_widget_render(this, wi);
2676 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2678 struct menu_data *md=gui_internal_menu_data(this);
2679 gui_internal_keypress_do(this, (char *) wm->data);
2680 if (md->keyboard_mode == 2)
2681 gui_internal_keyboard_do(this, md->keyboard, 10);
2682 if (md->keyboard_mode == 26)
2683 gui_internal_keyboard_do(this, md->keyboard, 34);
2687 gui_internal_search_idle_end(struct gui_priv *this)
2690 event_remove_idle(this->idle);
2693 if (this->idle_cb) {
2694 callback_destroy(this->idle_cb);
2700 postal_str(struct search_list_result *res, int level)
2703 if (res->town->common.postal)
2704 ret=res->town->common.postal;
2705 if (res->town->common.postal_mask)
2706 ret=res->town->common.postal_mask;
2709 if (res->street->common.postal)
2710 ret=res->street->common.postal;
2711 if (res->street->common.postal_mask)
2712 ret=res->street->common.postal_mask;
2715 if (res->house_number->common.postal)
2716 ret=res->house_number->common.postal;
2717 if (res->house_number->common.postal_mask)
2718 ret=res->house_number->common.postal_mask;
2723 district_str(struct search_list_result *res, int level)
2726 if (res->town->common.district_name)
2727 ret=res->town->common.district_name;
2730 if (res->street->common.district_name)
2731 ret=res->street->common.district_name;
2734 if (res->house_number->common.district_name)
2735 ret=res->house_number->common.district_name;
2740 town_str(struct search_list_result *res, int level, int flags)
2742 char *town=res->town->common.town_name;
2743 char *district=district_str(res, level);
2744 char *postal=postal_str(res, level);
2745 char *postal_sep=" ";
2746 char *district_begin=" (";
2747 char *district_end=")";
2749 postal_sep=postal="";
2750 if (!district || (flags & 1))
2751 district_begin=district_end=district="";
2753 return g_strdup_printf("%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end);
2757 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2759 char *text=NULL,*text2=NULL,*name=NULL;
2760 struct search_list_result *res;
2762 struct item *item=NULL;
2764 static char possible_keys[256]="";
2766 res=search_list_get_result(this->sl);
2768 gchar* trunk_name = NULL;
2770 struct widget *menu=g_list_last(this->root.children)->data;
2771 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2773 if (! strcmp(wm_name,"Town"))
2774 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
2775 if (! strcmp(wm_name,"Street"))
2776 trunk_name = g_strrstr(name=res->street->name, wi->text);
2779 char next_char = trunk_name[strlen(wi->text)];
2781 int len = strlen(possible_keys);
2782 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2783 if (i==len || !len) {
2784 possible_keys[len]=trunk_name[strlen(wi->text)];
2785 possible_keys[len+1]='\0';
2788 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
2793 gui_internal_search_idle_end(this);
2795 struct menu_data *md=gui_internal_menu_data(this);
2796 if (md && md->keyboard && !(this->flags & 2048)) {
2797 GList *lk=md->keyboard->children;
2798 graphics_draw_mode(this->gra, draw_mode_begin);
2800 struct widget *child=lk->data;
2801 GList *lk2=child->children;
2803 struct widget *child_=lk2->data;
2804 lk2=g_list_next(lk2);
2805 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2806 if (strlen(possible_keys) == 0)
2807 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2808 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2809 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2811 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2813 gui_internal_widget_render(this,child_);
2818 gui_internal_widget_render(this,md->keyboard);
2819 graphics_draw_mode(this->gra, draw_mode_end);
2822 possible_keys[0]='\0';
2826 if (! strcmp(wm_name,"Country")) {
2827 name=res->country->name;
2828 item=&res->country->common.item;
2829 text=g_strdup_printf("%s", res->country->name);
2831 if (! strcmp(wm_name,"Town")) {
2832 item=&res->town->common.item;
2833 name=res->town->common.town_name;
2834 text=town_str(res, 1, 0);
2836 if (! strcmp(wm_name,"Street")) {
2837 name=res->street->name;
2838 item=&res->street->common.item;
2839 text=g_strdup(res->street->name);
2840 text2=town_str(res, 2, 1);
2842 if (! strcmp(wm_name,"House number")) {
2843 name=res->house_number->house_number;
2844 text=g_strdup_printf("%s %s", res->street->name, name);
2845 text2=town_str(res, 3, 0);
2847 dbg(1,"res->country->flag=%s\n", res->country->flag);
2849 gui_internal_widget_append(search_list,
2850 wc=gui_internal_button_new_with_callback(this, text,
2851 image_new_xs(this, res->country->flag),
2852 gravity_left_center|orientation_horizontal|flags_fill,
2853 gui_internal_cmd_position, param));
2856 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2857 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
2858 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
2859 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
2860 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
2861 gui_internal_widget_append(wc, wb);
2862 wc->func=gui_internal_cmd_position;
2864 wc->state |= STATE_SENSITIVE;
2865 wc->speech=g_strdup(text);
2866 gui_internal_widget_append(search_list, wc);
2868 wc->name=g_strdup(name);
2871 wc->selection_id=res->id;
2874 gui_internal_widget_pack(this, search_list);
2875 l=g_list_last(this->root.children);
2876 graphics_draw_mode(this->gra, draw_mode_begin);
2877 gui_internal_widget_render(this, l->data);
2878 graphics_draw_mode(this->gra, draw_mode_end);
2884 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2886 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2887 this->idle=event_add_idle(50,this->idle_cb);
2888 callback_call_0(this->idle_cb);
2894 * @param wm The widget that generated the event for the search changed,
2895 * if this was generated by a key on the virtual keyboard then
2896 * wm is the key button widget.
2899 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2902 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2903 gui_internal_widget_children_destroy(this, search_list);
2905 void *param=(void *)3;
2907 if (! strcmp(wm->name,"Country"))
2909 if (! strcmp(wm->name,"Street"))
2911 if (! strcmp(wm->name,"House number"))
2913 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2915 gui_internal_search_idle_end(this);
2916 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2917 struct attr search_attr;
2920 if (! strcmp(wm->name,"Country"))
2921 search_attr.type=attr_country_all;
2922 if (! strcmp(wm->name,"Town"))
2923 search_attr.type=attr_town_or_district_name;
2924 if (! strcmp(wm->name,"Street"))
2925 search_attr.type=attr_street_name;
2926 if (! strcmp(wm->name,"House number"))
2927 search_attr.type=attr_house_number;
2928 search_attr.u.str=wm->text;
2929 search_list_search(this->sl, &search_attr, 1);
2930 gui_internal_search_idle_start(this, wm->name, search_list, param);
2932 l=g_list_last(this->root.children);
2933 gui_internal_widget_render(this, l->data);
2936 static struct widget *
2937 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)
2940 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
2941 NULL, gravity_center|orientation_vertical, func, data));
2942 wk->data_free=data_free;
2943 wk->background=this->background;
2951 static struct widget *
2952 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2954 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2957 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2959 // Some macros that make the keyboard layout easier to visualise in
2960 // the source code. The macros are #undef'd after this function.
2961 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2962 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
2963 static struct widget *
2964 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2966 struct widget *wkbd,*wk;
2967 struct menu_data *md=gui_internal_menu_data(this);
2968 int i, max_w=this->root.w, max_h=this->root.h;
2971 char *backspace="←";
2976 char *numeric="123";
2978 char *umlauts_ucase="ÄÖÜ";
2979 int umlauts_ucase_font=2;
2980 char *umlauts_lcase="äöü";
2981 int umlauts_lcase_font=2;
2988 gui_internal_highlight(this);
2989 if (md->keyboard_mode >= 1024)
2993 gui_internal_widget_children_destroy(this, wkbdb);
2995 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2997 md->keyboard_mode=mode;
2998 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2999 wkbd->background=this->background;
3006 if (mode >= 0 && mode < 8) {
3007 for (i = 0 ; i < 26 ; i++) {
3008 char text[]={'A'+i,'\0'};
3011 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
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, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3022 wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_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 >= 8 && mode < 16) {
3030 for (i = 0 ; i < 26 ; i++) {
3031 char text[]={'a'+i,'\0'};
3034 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
3038 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3039 wk->datai=mode+1024;
3041 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3042 wk->datai=mode+1024;
3043 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3045 wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3048 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_lcase, umlauts_lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3050 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3052 if (mode >= 16 && mode < 24) {
3053 for (i = 0 ; i < 10 ; i++) {
3054 char text[]={'0'+i,'\0'};
3057 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
3058 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
3060 for (i = 0 ; i < 5 ; i++) SPACER();
3065 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3066 wk->datai=mode+1024;
3068 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3069 wk->datai=mode+1024;
3070 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3072 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
3075 wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3077 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3079 if (mode >= 24 && mode < 32) {
3080 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
3081 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
3082 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
3083 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
3085 wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3088 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3090 if (mode >= 32 && mode < 40) {
3091 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
3092 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
3093 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
3094 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
3096 wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
3099 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
3106 if (mode >= 0 && mode < 8) {
3110 if (mode >= 8 && mode < 16) {
3114 if (mode >= 16 && mode < 24) {
3118 if (mode >= 24 && mode < 32) {
3120 font=umlauts_ucase_font;
3122 if (mode >= 32 && mode < 40) {
3124 font=umlauts_lcase_font;
3126 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
3127 wk->func=gui_internal_keyboard_change;
3129 wk->background=this->background;
3135 wk->state |= STATE_SENSITIVE;
3136 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
3137 wkl->background=NULL;
3138 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text,font));
3139 wkl->background=NULL;
3140 gui_internal_widget_append(wkbd, wk);
3144 gui_internal_widget_append(wkbdb, wkbd);
3146 gui_internal_widget_pack(this, wkbdb);
3147 gui_internal_widget_render(this, wkbdb);
3148 } else if (render == 2) {
3149 gui_internal_menu_reset_pack(this);
3150 gui_internal_menu_render(this);
3157 static struct widget *
3158 gui_internal_keyboard(struct gui_priv *this, int mode)
3160 if (! this->keyboard)
3162 return gui_internal_keyboard_do(this, NULL, mode);
3166 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
3168 gui_internal_keyboard_do(this, key->data, key->datai);
3172 gui_internal_search_list_set_default_country(struct gui_priv *this)
3174 struct attr search_attr, country_name, country_iso2, *country_attr;
3176 struct country_search *cs;
3177 struct tracking *tracking;
3178 struct search_list_result *res;
3180 country_attr=country_default();
3181 tracking=navit_get_tracking(this->nav);
3182 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
3183 country_attr=&search_attr;
3185 cs=country_search_new(country_attr, 0);
3186 item=country_search_get_item(cs);
3187 if (item && item_attr_get(item, attr_country_name, &country_name)) {
3188 search_attr.type=attr_country_all;
3189 dbg(0,"country %s\n", country_name.u.str);
3190 search_attr.u.str=country_name.u.str;
3191 search_list_search(this->sl, &search_attr, 0);
3192 while((res=search_list_get_result(this->sl)));
3193 g_free(this->country_iso2);
3194 if (item_attr_get(item, attr_country_iso2, &country_iso2))
3195 this->country_iso2=g_strdup(country_iso2.u.str);
3197 country_search_destroy(cs);
3199 dbg(0,"warning: no default country found\n");
3200 if (this->country_iso2) {
3201 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
3202 search_attr.type=attr_country_iso2;
3203 search_attr.u.str=this->country_iso2;
3204 search_list_search(this->sl, &search_attr, 0);
3205 while((res=search_list_get_result(this->sl)));
3211 gui_internal_search_list_new(struct gui_priv *this)
3213 struct mapset *ms=navit_get_mapset(this->nav);
3215 this->sl=search_list_new(ms);
3216 gui_internal_search_list_set_default_country(this);
3221 gui_internal_search_list_destroy(struct gui_priv *this)
3224 search_list_destroy(this->sl);
3231 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
3233 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
3235 int keyboard_mode=2;
3236 gui_internal_search_list_new(this);
3237 wb=gui_internal_menu(this, what);
3238 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
3239 gui_internal_widget_append(wb, w);
3240 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3241 gui_internal_widget_append(w, wr);
3242 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3243 gui_internal_widget_append(wr, we);
3245 if (!strcmp(type,"Country")) {
3246 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
3247 wnext->func=gui_internal_search_town;
3248 } else if (!strcmp(type,"Town")) {
3249 if (this->country_iso2) {
3250 #if HAVE_API_ANDROID
3251 char country_iso2[strlen(this->country_iso2)+1];
3252 strtolower(country_iso2, this->country_iso2);
3253 country=g_strdup_printf("country_%s", country_iso2);
3255 country=g_strdup_printf("country_%s", this->country_iso2);
3258 country=strdup("gui_select_country");
3259 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
3260 wb->state |= STATE_SENSITIVE;
3262 wb->func = gui_internal_search_country;
3264 wb->func = gui_internal_back;
3265 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
3266 wnext->func=gui_internal_search_street;
3268 } else if (!strcmp(type,"Street")) {
3269 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
3270 wb->state |= STATE_SENSITIVE;
3271 wb->func = gui_internal_back;
3272 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
3273 wnext->func=gui_internal_search_house_number;
3274 } else if (!strcmp(type,"House number")) {
3275 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
3276 wb->state |= STATE_SENSITIVE;
3277 wb->func = gui_internal_back;
3280 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3282 gui_internal_widget_append(we, wnext);
3283 wnext->state |= STATE_SENSITIVE;
3285 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3286 gui_internal_widget_append(wr, wl);
3287 gui_internal_menu_data(this)->search_list=wl;
3288 wk->state |= STATE_EDIT|STATE_EDITABLE;
3289 wk->background=this->background;
3290 wk->flags |= flags_expand|flags_fill;
3291 wk->func = gui_internal_search_changed;
3292 wk->name=g_strdup(type);
3294 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
3295 gui_internal_menu_render(this);
3299 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
3301 search_list_select(this->sl, attr_street_name, 0, 0);
3302 gui_internal_search(this,_("House number"),"House number",0);
3306 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
3308 dbg(0,"id %d\n", widget->selection_id);
3309 search_list_select(this->sl, attr_street_name, 0, 0);
3310 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
3311 gui_internal_search(this,_("House number"),"House number",0);
3315 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
3317 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3318 gui_internal_search(this,_("Street"),"Street",0);
3322 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
3324 dbg(0,"id %d\n", widget->selection_id);
3325 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
3326 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
3327 gui_internal_search(this,_("Street"),"Street",0);
3331 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
3334 search_list_select(this->sl, attr_country_all, 0, 0);
3335 g_free(this->country_iso2);
3336 this->country_iso2=NULL;
3337 gui_internal_search(this,_("Town"),"Town",0);
3341 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
3343 struct search_list_common *slc;
3344 dbg(0,"id %d\n", widget->selection_id);
3345 search_list_select(this->sl, attr_country_all, 0, 0);
3346 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
3348 g_free(this->country_iso2);
3349 this->country_iso2=((struct search_list_country *)slc)->iso2;
3351 gui_internal_search(this,widget->name,"Town",0);
3355 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
3357 gui_internal_prune_menu_count(this, 1, 0);
3358 gui_internal_search(this,_("Country"),"Country",0);
3362 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3365 search_list_select(this->sl, attr_country_all, 0, 0);
3366 gui_internal_search(this,_("Town"),"Town",1);
3370 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3373 struct widget *w,*wb,*wl;
3374 struct attr_iter *iter;
3377 wb=gui_internal_menu(this, _("Layout"));
3378 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3379 w->spy=this->spacing*3;
3380 gui_internal_widget_append(wb, w);
3381 iter=navit_attr_iter_new();
3382 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
3383 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
3385 gui_internal_widget_append(w, wl);
3387 navit_attr_iter_destroy(iter);
3388 gui_internal_menu_render(this);
3392 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3395 navit.type=attr_navit;
3396 navit.u.navit=this->nav;
3397 navit_destroy(navit.u.navit);
3398 config_remove_attr(config, &navit);
3399 event_main_loop_quit();
3403 gui_internal_window_closed(struct gui_priv *this)
3405 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
3409 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3411 navit_set_destination(this->nav, NULL, NULL, 0);
3416 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3418 struct attr attr, on, off, description, type, data;
3419 struct widget *w,*wb,*wma;
3421 struct attr_iter *iter;
3424 wb=gui_internal_menu(this, _("Maps"));
3425 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3426 w->spy=this->spacing*3;
3427 gui_internal_widget_append(wb, w);
3428 iter=navit_attr_iter_new();
3429 on.type=off.type=attr_active;
3432 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3433 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3434 label=g_strdup(description.u.str);
3436 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3438 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3440 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3442 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3443 attr.u.map, &on, &off, 1);
3444 gui_internal_widget_append(w, wma);
3447 navit_attr_iter_destroy(iter);
3448 gui_internal_menu_render(this);
3452 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3454 struct attr vehicle = {attr_vehicle,{wm->data}};
3455 navit_set_attr(this->nav, &vehicle);
3459 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3461 struct widget *w,*wb,*row;
3462 struct attr attr,sat_attr;
3463 struct vehicle *v=wm->data;
3466 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3468 wb=gui_internal_menu(this, _("Show Satellite Status"));
3469 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3470 gui_internal_menu_data(this)->redisplay_widget=wm;
3471 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3472 gui_internal_widget_append(wb, w);
3473 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3474 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3475 gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
3476 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
3477 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
3478 gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
3479 gui_internal_widget_append(w,row);
3480 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3481 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3482 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3483 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3484 str=g_strdup_printf("%d", sat_attr.u.num);
3487 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3490 gui_internal_widget_append(w,row);
3492 gui_internal_widget_append(wb, w);
3493 gui_internal_menu_render(this);
3497 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3499 struct widget *w,*wb;
3501 struct vehicle *v=wm->data;
3502 wb=gui_internal_menu(this, _("Show NMEA Data"));
3503 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3504 gui_internal_menu_data(this)->redisplay_widget=wm;
3505 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3506 gui_internal_widget_append(wb, w);
3507 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3508 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3509 gui_internal_menu_render(this);
3513 * A container to hold the selected vehicle and the desired profile in
3516 struct vehicle_and_profilename {
3517 struct vehicle *vehicle;
3522 * Figures out whether the given vehicle is the active vehicle.
3524 * @return true if the vehicle is active, false otherwise.
3527 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3530 struct attr active_vehicle;
3532 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3533 active_vehicle.u.vehicle=NULL;
3535 return active_vehicle.u.vehicle == vehicle;
3539 save_vehicle_xml(struct vehicle *v)
3542 struct attr_iter *iter=vehicle_attr_iter_new();
3546 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3547 if (ATTR_IS_OBJECT(attr.type))
3550 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3554 printf("</vehicle>\n");
3557 vehicle_attr_iter_destroy(iter);
3562 * Reacts to a button press that changes a vehicle's active profile.
3564 * @see gui_internal_add_vehicle_profile
3567 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3568 widget *wm, void *data)
3570 struct vehicle_and_profilename *vapn = data;
3571 struct vehicle *v = vapn->vehicle;
3572 char *profilename = vapn->profilename;
3573 struct attr vehicle_name_attr;
3574 char *vehicle_name = NULL;
3576 // Get the vehicle name
3577 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3578 vehicle_name = vehicle_name_attr.u.str;
3580 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3583 // Change the profile name
3584 struct attr profilename_attr = {attr_profilename, {profilename}};
3585 if(!vehicle_set_attr(v, &profilename_attr)) {
3586 dbg(0, "Unable to set the vehicle's profile name\n");
3589 // Notify Navit that the routing should be re-done if this is the
3591 if (gui_internal_is_active_vehicle(this, v)) {
3592 struct attr vehicle;
3593 vehicle.type=attr_vehicle;
3594 vehicle.u.vehicle=v;
3595 navit_set_attr(this->nav, &vehicle);
3597 save_vehicle_xml(v);
3601 * Adds the vehicle profile to the GUI, allowing the user to pick a
3602 * profile for the currently selected vehicle.
3605 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3606 *parent, struct vehicle *v, struct vehicleprofile *profile)
3608 // Just here to show up in the translation file, nice and close to
3609 // where the translations are actually used.
3610 struct attr profile_attr;
3611 struct attr *attr = NULL;
3613 char *active_profile = NULL;
3616 struct vehicle_and_profilename *context = NULL;
3618 #ifdef ONLY_FOR_TRANSLATION
3619 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
3622 // Figure out the profile name
3623 attr = attr_search(profile->attrs, NULL, attr_name);
3626 // Determine whether the profile is the active one
3627 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
3628 active_profile = profile_attr.u.str;
3629 active = active_profile != NULL && !strcmp(name, active_profile);
3631 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3632 active_profile, active);
3634 // Build a translatable label.
3636 label = g_strdup_printf(_("Current profile: %s"), _(name));
3638 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3641 // Create the context object (the vehicle and the desired profile)
3642 context = g_new0(struct vehicle_and_profilename, 1);
3643 context->vehicle = v;
3644 context->profilename = name;
3647 gui_internal_widget_append(parent,
3648 gui_internal_button_new_with_callback(
3650 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3651 gravity_left_center|orientation_horizontal|flags_fill,
3652 gui_internal_cmd_set_active_profile, context));
3658 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3660 struct widget *w,*wb;
3662 struct vehicle *v=wm->data;
3663 struct vehicleprofile *profile = NULL;
3665 wb=gui_internal_menu(this, wm->text);
3666 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3667 gui_internal_widget_append(wb, w);
3669 // Add the "Set as active" button if this isn't the active
3671 if (!gui_internal_is_active_vehicle(this, v)) {
3672 gui_internal_widget_append(w,
3673 gui_internal_button_new_with_callback(this, _("Set as active"),
3674 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3675 gui_internal_cmd_set_active_vehicle, wm->data));
3678 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3679 gui_internal_widget_append(w,
3680 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3681 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3682 gui_internal_cmd_show_satellite_status, wm->data));
3684 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3685 gui_internal_widget_append(w,
3686 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3687 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3688 gui_internal_cmd_show_nmea_data, wm->data));
3691 // Add all the possible vehicle profiles to the menu
3692 GList *profiles = navit_get_vehicleprofiles(this->nav);
3694 profile = (struct vehicleprofile *)profiles->data;
3695 gui_internal_add_vehicle_profile(this, w, v, profile);
3696 profiles = g_list_next(profiles);
3699 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3700 gui_internal_menu_render(this);
3704 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3706 struct attr attr,vattr;
3707 struct widget *w,*wb,*wl;
3708 struct attr_iter *iter;
3709 struct attr active_vehicle;
3712 wb=gui_internal_menu(this, _("Vehicle"));
3713 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3714 w->spy=this->spacing*3;
3715 gui_internal_widget_append(wb, w);
3716 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3717 active_vehicle.u.vehicle=NULL;
3718 iter=navit_attr_iter_new();
3719 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3720 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3721 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3722 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3723 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3724 wl->text=g_strdup(vattr.u.str);
3725 gui_internal_widget_append(w, wl);
3727 navit_attr_iter_destroy(iter);
3728 gui_internal_menu_render(this);
3733 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3735 struct widget *wb,*w;
3737 wb=gui_internal_menu(this, _("Rules"));
3738 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3739 w->spy=this->spacing*3;
3740 gui_internal_widget_append(wb, w);
3743 on.type=off.type=attr_tracking;
3744 gui_internal_widget_append(w,
3745 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3749 on.type=off.type=attr_orientation;
3750 gui_internal_widget_append(w,
3751 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3755 on.type=off.type=attr_follow_cursor;
3756 gui_internal_widget_append(w,
3757 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3759 gui_internal_menu_render(this);
3762 //##############################################################################################################
3765 //# Authors: Martin Schaller (04/2008)
3766 //##############################################################################################################
3767 static void gui_internal_motion(void *data, struct point *p)
3770 struct gui_priv *this=data;
3771 if (!this->root.children) {
3772 navit_handle_motion(this->nav, p);
3778 if(!this->motion_timeout_callback)
3779 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3780 if(!this->motion_timeout_event)
3781 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3785 find_attr(const char **names, const char **values, const char *name)
3788 if (!strcasecmp(*names, name))
3790 names+=xml_attr_distance;
3791 values+=xml_attr_distance;
3797 find_attr_dup(const char **names, const char **values, const char *name)
3799 return g_strdup(find_attr(names, values, name));
3803 gui_internal_evaluate(struct gui_priv *this, const char *command)
3806 command_evaluate(&this->self, command);
3811 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
3813 gui_internal_evaluate(this,w->command);
3817 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
3820 if (w->form == form && w->name) {
3821 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
3823 gui_set_attr(this->self.u.gui, attr);
3829 gui_internal_html_submit_set(this, w, form);
3836 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
3838 struct widget *menu;
3841 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
3842 l=g_list_last(this->root.children);
3844 graphics_draw_mode(this->gra, draw_mode_begin);
3845 gui_internal_highlight_do(this, NULL);
3846 gui_internal_menu_render(this);
3847 graphics_draw_mode(this->gra, draw_mode_end);
3848 gui_internal_html_submit_set(this, menu, w->form);
3849 gui_internal_evaluate(this,w->form->onsubmit);
3853 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
3856 gui_internal_prune_menu_count(this, 1, 0);
3857 if (href && href[0] == '#') {
3858 dbg(1,"href=%s\n",href);
3859 gui_internal_html_menu(this, this->html_text, href+1);
3864 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
3866 gui_internal_html_load_href(this, w->command, 0);
3869 struct div_flags_map {
3873 } div_flags_map[] = {
3874 {"gravity","none",gravity_none},
3875 {"gravity","left",gravity_left},
3876 {"gravity","xcenter",gravity_xcenter},
3877 {"gravity","right",gravity_right},
3878 {"gravity","top",gravity_top},
3879 {"gravity","ycenter",gravity_ycenter},
3880 {"gravity","bottom",gravity_bottom},
3881 {"gravity","left_top",gravity_left_top},
3882 {"gravity","top_center",gravity_top_center},
3883 {"gravity","right_top",gravity_right_top},
3884 {"gravity","left_center",gravity_left_center},
3885 {"gravity","center",gravity_center},
3886 {"gravity","right_center",gravity_right_center},
3887 {"gravity","left_bottom",gravity_left_bottom},
3888 {"gravity","bottom_center",gravity_bottom_center},
3889 {"gravity","right_bottom",gravity_right_bottom},
3890 {"expand","1",flags_expand},
3891 {"fill","1",flags_fill},
3892 {"orientation","horizontal",orientation_horizontal},
3893 {"orientation","vertical",orientation_vertical},
3894 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
3898 div_flag(const char **names, const char **values, char *name)
3902 const char *value=find_attr(names, values, name);
3905 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
3906 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
3907 ret|=div_flags_map[i].flags;
3913 div_flags(const char **names, const char **values)
3916 flags = div_flag(names, values, "gravity");
3917 flags |= div_flag(names, values, "orientation");
3918 flags |= div_flag(names, values, "expand");
3919 flags |= div_flag(names, values, "fill");
3923 static struct widget *
3924 html_image(struct gui_priv *this, const char **names, const char **values)
3926 const char *src, *size;
3927 struct graphics_image *img=NULL;
3929 src=find_attr(names, values, "src");
3932 size=find_attr(names, values, "size");
3935 if (!strcmp(size,"l"))
3936 img=image_new_l(this, src);
3937 else if (!strcmp(size,"s"))
3938 img=image_new_s(this, src);
3939 else if (!strcmp(size,"xs"))
3940 img=image_new_xs(this, src);
3943 return gui_internal_image_new(this, img);
3947 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
3949 struct gui_priv *this=data;
3951 enum html_tag tag=html_tag_none;
3952 struct html *html=&this->html[this->html_depth];
3953 const char *cond, *type;
3955 if (!strcasecmp(tag_name,"text"))
3961 cond=find_attr(names, values, "cond");
3963 if (cond && !this->html_skip) {
3964 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
3968 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
3969 if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
3970 tag=html_tag_map[i].tag;
3975 if (!this->html_skip && !html->skip) {
3978 html->name=find_attr_dup(names, values, "name");
3980 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
3982 this->html_anchor_found=1;
3984 html->href=find_attr_dup(names, values, "href");
3987 html->command=find_attr_dup(names, values, "onclick");
3988 html->w=html_image(this, names, values);
3991 this->form=g_new0(struct form, 1);
3992 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
3994 case html_tag_input:
3995 type=find_attr_dup(names, values, "type");
3998 if (!strcmp(type,"image")) {
3999 html->w=html_image(this, names, values);
4001 html->w->state|=STATE_SENSITIVE;
4002 html->w->func=gui_internal_html_submit;
4005 if (!strcmp(type,"text") || !strcmp(type,"password")) {
4006 html->w=gui_internal_label_new(this, NULL);
4007 html->w->background=this->background;
4008 html->w->flags |= div_flags(names, values);
4009 html->w->state|=STATE_EDITABLE;
4010 if (!this->editable) {
4011 this->editable=html->w;
4012 html->w->state|=STATE_EDIT;
4014 this->keyboard_required=1;
4015 if (!strcmp(type,"password"))
4016 html->w->flags2 |= 1;
4019 html->w->form=this->form;
4020 html->w->name=find_attr_dup(names, values, "name");
4024 html->w=gui_internal_box_new(this, div_flags(names, values));
4025 html->container=this->html_container;
4026 this->html_container=html->w;
4032 this->html_skip+=html->skip;
4037 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
4039 struct gui_priv *this=data;
4041 struct html *parent=NULL;
4043 if (!strcasecmp(tag_name,"text"))
4046 html=&this->html[this->html_depth];
4047 if (this->html_depth > 0)
4048 parent=&this->html[this->html_depth-1];
4051 if (!this->html_skip) {
4052 if (html->command && html->w) {
4053 html->w->state |= STATE_SENSITIVE;
4054 html->w->command=html->command;
4055 html->w->func=gui_internal_html_command;
4058 if (parent && parent->href && html->w) {
4059 html->w->state |= STATE_SENSITIVE;
4060 html->w->command=g_strdup(parent->href);
4061 html->w->func=gui_internal_html_href;
4063 switch (html->tag) {
4065 this->html_container=html->container;
4067 case html_tag_input:
4068 gui_internal_widget_append(this->html_container, html->w);
4077 this->html_skip-=html->skip;
4078 g_free(html->command);
4084 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
4086 struct gui_priv *this=data;
4088 int depth=this->html_depth-1;
4089 struct html *html=&this->html[depth];
4090 char *text_stripped;
4092 if (this->html_skip)
4094 while (isspace(text[0])) {
4098 while (len > 0 && isspace(text[len-1]))
4100 text_stripped=g_malloc(len+1);
4101 strncpy(text_stripped, text, len);
4102 text_stripped[len]='\0';
4103 if (html->tag == html_tag_html && depth > 2) {
4104 if (this->html[depth-1].tag == html_tag_script) {
4105 html=&this->html[depth-2];
4108 switch (html->tag) {
4110 if (html->name && len) {
4111 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
4112 gui_internal_widget_append(gui_internal_menu(this, gettext(text_stripped)), this->html_container);
4113 this->html_container->spx=this->spacing*10;
4117 if (!this->html_container) {
4118 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
4119 gui_internal_widget_append(gui_internal_menu(this, gettext(text_stripped)), this->html_container);
4120 this->html_container->spx=this->spacing*10;
4125 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
4126 gui_internal_widget_append(w, html->w);
4127 gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
4133 gui_internal_widget_append(html->w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
4136 case html_tag_script:
4137 dbg(1,"execute %s\n",text_stripped);
4138 gui_internal_evaluate(this,text_stripped);
4146 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
4148 char *doc=g_strdup(document);
4149 graphics_draw_mode(this->gra, draw_mode_begin);
4150 this->html_container=NULL;
4152 this->html_anchor=anchor;
4153 this->html_anchor_found=0;
4155 this->keyboard_required=0;
4156 this->editable=NULL;
4157 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
4158 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4160 if (this->keyboard_required && this->keyboard) {
4161 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
4162 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
4164 gui_internal_menu_render(this);
4165 graphics_draw_mode(this->gra, draw_mode_end);
4170 gui_internal_enter(struct gui_priv *this, int ignore)
4172 struct graphics *gra=this->gra;
4173 this->ignore_button=ignore;
4174 this->clickp_valid=this->vehicle_valid=0;
4176 navit_block(this->nav, 1);
4177 graphics_overlay_disable(gra, 1);
4180 this->root.background=this->background;
4184 gui_internal_leave(struct gui_priv *this)
4186 graphics_draw_mode(this->gra, draw_mode_end);
4190 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore, char *href)
4192 struct transformation *trans;
4195 struct attr attr,attrp;
4198 gui_internal_enter(this, ignore);
4199 trans=navit_get_trans(this->nav);
4200 attr_free(this->click_coord_geo);
4201 this->click_coord_geo=NULL;
4202 attr_free(this->position_coord_geo);
4203 this->position_coord_geo=NULL;
4205 transform_reverse(trans, p, &c);
4206 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
4207 this->clickp.pro=transform_get_projection(trans);
4210 transform_to_geo(this->clickp.pro, &c, &g);
4211 attr.u.coord_geo=&g;
4212 attr.type=attr_click_coord_geo;
4213 this->click_coord_geo=attr_dup(&attr);
4215 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
4216 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
4217 this->position_coord_geo=attr_dup(&attrp);
4218 this->vehiclep.pro=transform_get_projection(trans);
4219 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
4220 this->vehiclep.x=c.x;
4221 this->vehiclep.y=c.y;
4222 this->vehicle_valid=1;
4225 gui_internal_html_load_href(this, href?href:"#Main Menu", 0);
4229 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4233 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
4235 if (in[1] && ATTR_IS_INT(in[1]->type))
4236 replace=in[1]->u.num;
4238 if (this->root.children) {
4241 gui_internal_html_load_href(this, href, replace);
4244 gui_internal_cmd_menu(this, NULL, 0, href);
4249 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
4251 if (widget->text && strlen(widget->text))
4252 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
4253 g_free(widget->text);
4255 gui_internal_prune_menu(this, NULL);
4256 gui_internal_check_exit(this);
4260 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
4262 gui_internal_cmd_log_do(this, widget->data);
4266 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
4270 len=strlen(wm->text);
4271 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
4272 wm->text[len-1]='\0';
4273 gui_internal_cmd_log_do(this, wm);
4280 gui_internal_cmd_log(struct gui_priv *this)
4282 struct widget *w,*wb,*wk,*wl,*we,*wnext;
4283 gui_internal_enter(this, 1);
4284 wb=gui_internal_menu(this, "Log Message");
4285 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4286 gui_internal_widget_append(wb, w);
4287 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4288 gui_internal_widget_append(w, we);
4289 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
4290 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
4291 wk->background=this->background;
4292 wk->flags |= flags_expand|flags_fill;
4293 wk->func = gui_internal_cmd_log_changed;
4294 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
4295 wnext->state |= STATE_SENSITIVE;
4296 wnext->func = gui_internal_cmd_log_clicked;
4298 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4299 gui_internal_widget_append(w, wl);
4301 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
4302 gui_internal_menu_render(this);
4303 gui_internal_leave(this);
4307 gui_internal_check_exit(struct gui_priv *this)
4309 struct graphics *gra=this->gra;
4310 if (! this->root.children) {
4311 gui_internal_search_idle_end(this);
4312 gui_internal_search_list_destroy(this);
4313 graphics_overlay_disable(gra, 0);
4314 if (!navit_block(this->nav, 0)) {
4316 navit_draw(this->nav);
4318 navit_draw_displaylist(this->nav);
4324 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
4328 attr->u.num=this->root.children != NULL;
4330 case attr_click_coord_geo:
4331 if (!this->click_coord_geo)
4333 *attr=*this->click_coord_geo;
4335 case attr_position_coord_geo:
4336 if (!this->position_coord_geo)
4338 *attr=*this->position_coord_geo;
4341 attr->u.num=this->pitch;
4351 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
4353 switch (attr->type) {
4355 g_free(this->html_text);
4356 this->html_text=g_strdup(attr->u.str);
4364 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
4366 switch (attr->type) {
4367 case attr_fullscreen:
4368 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
4369 graphics_draw_mode(this->gra, draw_mode_end);
4370 this->win->fullscreen(this->win, attr->u.num > 0);
4371 graphics_draw_mode(this->gra, draw_mode_begin);
4373 this->fullscreen=attr->u.num;
4376 dbg(0,"%s\n",attr_to_name(attr->type));
4381 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
4383 struct displaylist_handle *dlh;
4384 struct displaylist *display;
4385 struct displayitem *di;
4387 display=navit_get_displaylist(this->nav);
4388 dlh=graphics_displaylist_open(display);
4389 while ((di=graphics_displaylist_next(dlh))) {
4390 struct item *item=graphics_displayitem_get_item(di);
4391 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
4392 graphics_displayitem_within_dist(display, di, p, 10)) {
4393 struct map_rect *mr=map_rect_new(item->map, NULL);
4394 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
4396 if (item_attr_get(itemo, attr_data, &attr)) {
4397 struct attr cb,*attr_list[2];
4399 attr.type=attr_data;
4402 if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
4403 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
4405 map_rect_destroy(mr);
4408 graphics_displaylist_close(dlh);
4412 //##############################################################################################################
4413 //# Description: Function to handle mouse clicks and scroll wheel movement
4415 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
4416 //##############################################################################################################
4417 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
4419 struct gui_priv *this=data;
4420 struct graphics *gra=this->gra;
4422 dbg(1,"enter %d %d\n", pressed, button);
4423 // if still on the map (not in the menu, yet):
4424 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
4425 if (!this->root.children || this->ignore_button) {
4427 this->ignore_button=0;
4428 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
4429 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
4430 dbg(1,"navit has handled button\n");
4433 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
4436 if (this->menu_on_map_click) {
4437 gui_internal_cmd_menu(this, p, 0, NULL);
4440 if (this->signal_on_map_click) {
4441 gui_internal_dbus_signal(this, p);
4448 // if already in the menu:
4452 gui_internal_highlight(this);
4457 graphics_draw_mode(gra, draw_mode_begin);
4458 gui_internal_call_highlighted(this);
4459 gui_internal_highlight(this);
4460 graphics_draw_mode(gra, draw_mode_end);
4461 gui_internal_check_exit(this);
4466 gui_internal_setup_gc(struct gui_priv *this)
4468 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
4469 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
4470 struct graphics *gra=this->gra;
4472 if (this->background)
4474 this->background=graphics_gc_new(gra);
4475 this->background2=graphics_gc_new(gra);
4476 this->highlight_background=graphics_gc_new(gra);
4477 graphics_gc_set_foreground(this->highlight_background, &cbh);
4478 this->foreground=graphics_gc_new(gra);
4479 graphics_gc_set_foreground(this->foreground, &cf);
4480 this->text_background=graphics_gc_new(gra);
4481 this->text_foreground=graphics_gc_new(gra);
4482 graphics_gc_set_foreground(this->background, &this->background_color);
4483 graphics_gc_set_foreground(this->background2, &this->background2_color);
4484 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
4485 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
4488 //##############################################################################################################
4491 //# Authors: Martin Schaller (04/2008)
4492 //##############################################################################################################
4493 static void gui_internal_resize(void *data, int w, int h)
4495 struct gui_priv *this=data;
4498 gui_internal_setup_gc(this);
4500 if (this->root.w != w || this->root.h != h) {
4505 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
4506 navit_handle_resize(this->nav, w, h);
4507 if (this->root.children) {
4509 gui_internal_prune_menu(this, NULL);
4510 gui_internal_html_load_href(this, "#Main Menu", 0);
4512 gui_internal_menu_render(this);
4518 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
4533 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
4535 GList *l=wi->children;
4536 if (wi->state & STATE_SENSITIVE) {
4539 gui_internal_keynav_point(wi, -dx, -dy, &wp);
4541 dist1=(wp.x-p->x)*dx;
4544 dist1=(wp.y-p->y)*dy;
4552 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);
4558 if (dist1 < *distance) {
4565 struct widget *child=l->data;
4566 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
4572 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
4574 struct widget *result,*menu=g_list_last(this->root.children)->data;
4577 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4578 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
4584 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
4586 gui_internal_keynav_point(result, dx, dy, &p);
4587 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
4592 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4593 dbg(1,"result=%p\n", result);
4605 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
4606 dbg(1,"wraparound result=%p\n", result);
4608 gui_internal_highlight_do(this, result);
4610 gui_internal_say(this, result, 1);
4613 //##############################################################################################################
4616 //# Authors: Martin Schaller (04/2008)
4617 //##############################################################################################################
4618 static void gui_internal_keypress(void *data, char *key)
4620 struct gui_priv *this=data;
4623 if (!this->root.children) {
4624 transform_get_size(navit_get_trans(this->nav), &w, &h);
4629 navit_set_center_screen(this->nav, &p, 1);
4631 case NAVIT_KEY_DOWN:
4634 navit_set_center_screen(this->nav, &p, 1);
4636 case NAVIT_KEY_LEFT:
4639 navit_set_center_screen(this->nav, &p, 1);
4641 case NAVIT_KEY_RIGHT:
4644 navit_set_center_screen(this->nav, &p, 1);
4646 case NAVIT_KEY_ZOOM_IN:
4647 navit_zoom_in(this->nav, 2, NULL);
4649 case NAVIT_KEY_ZOOM_OUT:
4650 navit_zoom_out(this->nav, 2, NULL);
4652 case NAVIT_KEY_RETURN:
4653 case NAVIT_KEY_MENU:
4654 gui_internal_cmd_menu(this, NULL, 0, NULL);
4659 graphics_draw_mode(this->gra, draw_mode_begin);
4661 case NAVIT_KEY_LEFT:
4662 gui_internal_keynav_highlight_next(this,-1,0);
4664 case NAVIT_KEY_RIGHT:
4665 gui_internal_keynav_highlight_next(this,1,0);
4668 gui_internal_keynav_highlight_next(this,0,-1);
4670 case NAVIT_KEY_DOWN:
4671 gui_internal_keynav_highlight_next(this,0,1);
4673 case NAVIT_KEY_BACK:
4675 case NAVIT_KEY_RETURN:
4676 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
4677 gui_internal_call_highlighted(this);
4679 gui_internal_keypress_do(this, key);
4682 gui_internal_keypress_do(this, key);
4684 graphics_draw_mode(this->gra, draw_mode_end);
4685 gui_internal_check_exit(this);
4689 //##############################################################################################################
4692 //# Authors: Martin Schaller (04/2008)
4693 //##############################################################################################################
4694 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
4697 struct transformation *trans=navit_get_trans(this->nav);
4699 win=graphics_get_data(gra, "window");
4702 navit_ignore_graphics_events(this->nav, 1);
4705 navit_ignore_graphics_events(this->nav, 1);
4706 transform_get_size(trans, &this->root.w, &this->root.h);
4707 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
4708 graphics_add_callback(gra, this->resize_cb);
4709 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
4710 graphics_add_callback(gra, this->button_cb);
4711 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
4712 graphics_add_callback(gra, this->motion_cb);
4713 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
4714 graphics_add_callback(gra, this->keypress_cb);
4715 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
4716 graphics_add_callback(gra, this->window_closed_cb);
4718 // set fullscreen if needed
4719 if (this->fullscreen)
4720 this->win->fullscreen(this->win, this->fullscreen != 0);
4721 /* Was resize callback already issued? */
4722 if (navit_get_ready(this->nav) & 2)
4723 gui_internal_setup_gc(this);
4727 static void gui_internal_disable_suspend(struct gui_priv *this)
4729 if (this->win->disable_suspend)
4730 this->win->disable_suspend(this->win);
4733 //##############################################################################################################
4736 //# Authors: Martin Schaller (04/2008)
4737 //##############################################################################################################
4738 struct gui_methods gui_internal_methods = {
4741 gui_internal_set_graphics,
4745 gui_internal_disable_suspend,
4746 gui_internal_get_attr,
4747 gui_internal_add_attr,
4748 gui_internal_set_attr,
4752 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
4754 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
4756 *out=attr_generic_add_attr(*out, &private_data);
4760 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
4762 callback_list_add(priv->cbl, cb);
4766 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
4768 callback_list_remove(priv->cbl, cb);
4772 static struct gui_internal_methods gui_internal_methods_ext = {
4773 gui_internal_add_callback,
4774 gui_internal_remove_callback,
4775 gui_internal_menu_render,
4782 gui_internal_get_flags(struct widget *widget)
4784 return widget->flags;
4788 gui_internal_set_flags(struct widget *widget, enum flags flags)
4790 widget->flags=flags;
4794 gui_internal_get_state(struct widget *widget)
4796 return widget->state;
4800 gui_internal_set_state(struct widget *widget, int state)
4802 widget->state=state;
4806 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
4812 gui_internal_set_data(struct widget *widget, void *data)
4818 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
4820 widget->background=this->background;
4823 static struct gui_internal_widget_methods gui_internal_widget_methods = {
4824 gui_internal_widget_append,
4825 gui_internal_button_new,
4826 gui_internal_button_new_with_callback,
4827 gui_internal_box_new,
4828 gui_internal_label_new,
4829 gui_internal_image_new,
4830 gui_internal_keyboard,
4832 gui_internal_get_flags,
4833 gui_internal_set_flags,
4834 gui_internal_get_state,
4835 gui_internal_set_state,
4836 gui_internal_set_func,
4837 gui_internal_set_data,
4838 gui_internal_set_default_background,
4842 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
4844 char *str=NULL,*str2=NULL;
4845 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
4848 dbg(1,"%s\n",attr_to_name(in[0]->type));
4849 if (ATTR_IS_STRING(in[0]->type)) {
4852 if (ATTR_IS_COORD_GEO(in[0]->type)) {
4853 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
4856 str=g_strdup_printf("<html>%s</html>\n",str);
4857 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
4865 * @brief Creates a new table widget.
4867 * Creates and returns a new table widget. This function will
4868 * setup next/previous buttons as children.
4870 * @param this The graphics context.
4871 * @param flags widget sizing flags.
4872 * @returns The newly created widget
4874 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4876 struct widget * widget = g_new0(struct widget,1);
4877 struct table_data * data = NULL;
4878 widget->type=widget_table;
4879 widget->flags=flags;
4880 widget->data = g_new0(struct table_data,1);
4881 widget->data_free=gui_internal_table_data_free;
4882 data = (struct table_data*)widget->data;
4886 data->next_button = gui_internal_button_new_with_callback
4887 (this,"Next",image_new_xs(this, "gui_active") ,
4888 gravity_left_center |orientation_vertical,
4889 gui_internal_table_button_next,NULL);
4890 data->next_button->data=widget;
4893 data->prev_button = gui_internal_button_new_with_callback
4895 image_new_xs(this, "gui_active")
4896 ,gravity_right_center |orientation_vertical,
4897 gui_internal_table_button_prev,NULL);
4899 data->prev_button->data=widget;
4903 data->button_box=gui_internal_box_new(this,
4904 gravity_center|orientation_horizontal);
4905 data->button_box->children=g_list_append(data->button_box->children,
4907 data->button_box->children=g_list_append(data->button_box->children,
4909 //data->button_box->background=this->background2;
4910 data->button_box->bl=this->spacing;
4911 widget->children=g_list_append(widget->children,data->button_box);
4912 gui_internal_widget_pack(this,data->button_box);
4920 * @brief Clears all the rows from the table.
4921 * This function removes all rows from a table.
4922 * New rows can later be added to the table.
4924 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4927 struct table_data * table_data = (struct table_data* ) table->data;
4929 iter = table->children;
4931 if(iter->data != table_data->button_box) {
4932 struct widget * child = (struct widget*)iter->data;
4933 gui_internal_widget_destroy(this,child);
4934 if(table->children == iter) {
4935 table->children = g_list_remove(iter,iter->data);
4936 iter=table->children;
4939 iter = g_list_remove(iter,iter->data);
4942 iter = g_list_next(iter);
4946 table_data->top_row=NULL;
4947 table_data->bottom_row=NULL;
4948 if(table_data->page_headers)
4949 g_list_free(table_data->page_headers);
4950 table_data->page_headers=NULL;
4955 * Creates a new table_row widget.
4956 * @param this The graphics context
4957 * @param flags Sizing flags for the row
4958 * @returns The new table_row widget.
4960 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4962 struct widget * widget = g_new0(struct widget,1);
4963 widget->type=widget_table_row;
4964 widget->flags=flags;
4971 * @brief Computes the column dimensions for the table.
4973 * @param w The table widget to compute dimensions for.
4975 * This function examines all of the rows and columns for the table w
4976 * and returns a list (GList) of table_column_desc elements that
4977 * describe each column of the table.
4979 * The caller is responsible for freeing the returned list.
4981 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4984 GList * column_desc = NULL;
4985 GList * current_desc=NULL;
4986 GList * cur_row = w->children;
4987 struct widget * cur_row_widget=NULL;
4988 GList * cur_column=NULL;
4989 struct widget * cell_w=NULL;
4990 struct table_column_desc * current_cell=NULL;
4991 struct table_data * table_data=NULL;
4998 * Scroll through the the table and
4999 * 1. Compute the maximum width + height of each column across all rows.
5001 table_data = (struct table_data*) w->data;
5002 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
5004 cur_row_widget = (struct widget*) cur_row->data;
5005 current_desc = column_desc;
5006 if(cur_row_widget == table_data->button_box)
5011 for(cur_column = cur_row_widget->children; cur_column;
5012 cur_column=g_list_next(cur_column))
5014 cell_w = (struct widget*) cur_column->data;
5015 gui_internal_widget_pack(this,cell_w);
5016 if(current_desc == 0)
5018 current_cell = g_new0(struct table_column_desc,1);
5019 column_desc = g_list_append(column_desc,current_cell);
5020 current_desc = g_list_last(column_desc);
5021 current_cell->height=cell_w->h;
5022 current_cell->width=cell_w->w;
5023 total_width+=cell_w->w;
5028 current_cell = current_desc->data;
5031 if(current_cell->height < height )
5033 current_cell->height = height;
5035 if(current_cell->width < width)
5037 total_width += (width-current_cell->width);
5038 current_cell->width = width;
5043 current_desc = g_list_next(current_desc);
5053 * If the width of all columns is less than the width off
5054 * the table expand each cell proportionally.
5057 if(total_width+(this->spacing*column_count) < w->w ) {
5058 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
5059 current_cell = (struct table_column_desc*) current_desc->data;
5060 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
5069 * @brief Computes the height and width for the table.
5071 * The height and widht are computed to display all cells in the table
5072 * at the requested height/width.
5074 * @param this The graphics context
5075 * @param w The widget to pack.
5078 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
5084 GList * column_data = gui_internal_compute_table_dimensions(this,w);
5086 struct table_column_desc * cell_desc=0;
5087 struct table_data * table_data = (struct table_data*)w->data;
5089 for(current = column_data; current; current=g_list_next(current))
5091 if(table_data->button_box == current->data )
5095 cell_desc = (struct table_column_desc *) current->data;
5096 width = width + cell_desc->width + this->spacing;
5097 if(height < cell_desc->height)
5099 height = cell_desc->height ;
5105 for(current=w->children; current; current=g_list_next(current))
5107 if(current->data!= table_data->button_box)
5112 if (table_data->button_box)
5113 gui_internal_widget_pack(this,table_data->button_box);
5117 if(w->h + w->c.y > this->root.h )
5120 * Do not allow the widget to exceed the screen.
5123 w->h = this->root.h- w->c.y - height;
5128 * Deallocate column descriptions.
5130 current = column_data;
5131 while( (current = g_list_last(current)) )
5133 current = g_list_remove(current,current->data);
5141 * @brief Renders a table widget.
5143 * @param this The graphics context
5144 * @param w The table widget to render.
5146 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
5151 GList * column_desc=NULL;
5152 GList * cur_row = NULL;
5153 GList * current_desc=NULL;
5154 struct table_data * table_data = (struct table_data*)w->data;
5156 int is_first_page=1;
5157 struct table_column_desc * dim=NULL;
5159 dbg_assert(table_data);
5160 column_desc = gui_internal_compute_table_dimensions(this,w);
5164 * Skip rows that are on previous pages.
5166 cur_row = w->children;
5167 if(table_data->top_row && table_data->top_row != w->children )
5169 cur_row = table_data->top_row;
5175 * Loop through each row. Drawing each cell with the proper sizes,
5176 * at the proper positions.
5178 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
5180 GList * cur_column=NULL;
5181 current_desc = column_desc;
5182 struct widget * cur_row_widget = (struct widget*)cur_row->data;
5184 x =w->p.x+this->spacing;
5185 if(cur_row_widget == table_data->button_box )
5189 dim = (struct table_column_desc*)current_desc->data;
5191 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
5194 * No more drawing space left.
5200 for(cur_column = cur_row_widget->children; cur_column;
5201 cur_column=g_list_next(cur_column))
5203 struct widget * cur_widget = (struct widget*) cur_column->data;
5204 dim = (struct table_column_desc*)current_desc->data;
5207 cur_widget->w=dim->width;
5209 cur_widget->h=dim->height;
5211 max_height = dim->height;
5212 /* We pack the widget before rendering to ensure that the x and y
5213 * coordinates get pushed down.
5215 gui_internal_widget_pack(this,cur_widget);
5216 gui_internal_widget_render(this,cur_widget);
5218 if(dim->height > max_height)
5220 max_height = dim->height;
5224 table_data->bottom_row=cur_row;
5225 current_desc = g_list_next(current_desc);
5227 if(table_data->button_box && (is_skipped || !is_first_page) )
5229 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
5231 if(table_data->button_box->p.y < y )
5233 table_data->button_box->p.y=y;
5235 table_data->button_box->p.x = w->p.x;
5236 table_data->button_box->w = w->w;
5237 // table_data->button_box->h = w->h - y;
5238 // table_data->next_button->h=table_data->button_box->h;
5239 // table_data->prev_button->h=table_data->button_box->h;
5240 // table_data->next_button->c.y=table_data->button_box->c.y;
5241 // table_data->prev_button->c.y=table_data->button_box->c.y;
5243 gui_internal_widget_pack(this,table_data->button_box);
5244 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
5247 table_data->button_box->p.y = w->p.y + w->h -
5248 table_data->button_box->h;
5252 table_data->next_button->state|= STATE_SENSITIVE;
5256 table_data->next_button->state&= ~STATE_SENSITIVE;
5259 if(table_data->top_row != w->children)
5261 table_data->prev_button->state|= STATE_SENSITIVE;
5265 table_data->prev_button->state&= ~STATE_SENSITIVE;
5267 gui_internal_widget_render(this,table_data->button_box);
5273 * Deallocate column descriptions.
5275 current_desc = column_desc;
5276 while( (current_desc = g_list_last(current_desc)) )
5278 current_desc = g_list_remove(current_desc,current_desc->data);
5284 * @brief Displays Route information
5286 * @li The name of the active vehicle
5287 * @param wm The button that was pressed.
5291 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5295 struct widget * menu;
5296 struct widget * row;
5299 if(! this->vehicle_cb)
5302 * Register the callback on vehicle updates.
5304 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
5305 attr_position_coord_geo,this);
5306 navit_add_callback(this->nav,this->vehicle_cb);
5309 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
5310 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
5312 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
5315 menu=gui_internal_menu(this,_("Route Description"));
5317 menu->free=gui_internal_route_screen_free;
5318 this->route_data.route_showing=1;
5319 this->route_data.route_table->spx = this->spacing;
5322 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
5324 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
5325 gui_internal_widget_append(box,this->route_data.route_table);
5327 box->spx = this->spacing;
5328 this->route_data.route_table->w=box->w;
5329 gui_internal_widget_append(menu,box);
5330 gui_internal_populate_route_table(this,this->nav);
5331 gui_internal_menu_render(this);
5336 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
5339 int adx=a2->x-a1->x;
5340 int ady=a2->y-a1->y;
5341 int bdx=b2->x-b1->x;
5342 int bdy=b2->y-b1->y;
5343 n = bdy * adx - bdx * ady;
5344 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
5345 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
5356 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
5357 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
5358 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
5361 res->x = a1->x + a * adx / n;
5362 res->y = a1->y + a * ady / n;
5367 struct heightline *next;
5369 struct coord_rect bbox;
5374 struct diagram_point {
5375 struct diagram_point *next;
5379 static struct heightline *
5380 item_get_heightline(struct item *item)
5382 struct heightline *ret=NULL;
5383 struct street_data *sd;
5387 if (item_attr_get(item, attr_label, &attr)) {
5388 height=atoi(attr.u.str);
5389 sd=street_get_data(item);
5390 if (sd && sd->count > 1) {
5391 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
5392 ret->bbox.lu=sd->c[0];
5393 ret->bbox.rl=sd->c[0];
5394 ret->count=sd->count;
5396 for (i = 0 ; i < sd->count ; i++) {
5398 coord_rect_extend(&ret->bbox, sd->c+i);
5401 street_data_free(sd);
5408 * @brief Displays Route Height Profile
5410 * @li The name of the active vehicle
5411 * @param wm The button that was pressed.
5415 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5419 struct widget * menu, *box;
5421 struct map * map=NULL;
5422 struct map_rect * mr=NULL;
5423 struct route * route;
5424 struct item * item =NULL;
5426 struct mapset_handle *msh;
5427 int x,i,first=1,dist=0;
5428 struct coord c,last,res;
5429 struct coord_rect rbbox,dbbox;
5430 struct map_selection sel;
5431 struct heightline *heightline,*heightlines=NULL;
5432 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
5435 sel.range.min=type_height_line_1;
5436 sel.range.max=type_height_line_3;
5439 menu=gui_internal_menu(this,_("Height Profile"));
5440 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
5441 gui_internal_widget_append(menu, box);
5442 route = navit_get_route(this->nav);
5444 map = route_get_map(route);
5446 mr = map_rect_new(map,NULL);
5448 while((item = map_rect_get_item(mr))) {
5449 while (item_coord_get(item, &c, 1)) {
5455 coord_rect_extend(&sel.u.c_rect, &c);
5458 map_rect_destroy(mr);
5459 ms=navit_get_mapset(this->nav);
5461 msh=mapset_open(ms);
5462 while ((map=mapset_next(msh, 1))) {
5463 mr=map_rect_new(map, &sel);
5465 while((item = map_rect_get_item(mr))) {
5466 if (item->type >= sel.range.min && item->type <= sel.range.max) {
5467 heightline=item_get_heightline(item);
5469 heightline->next=heightlines;
5470 heightlines=heightline;
5474 map_rect_destroy(mr);
5483 map = route_get_map(route);
5485 mr = map_rect_new(map,NULL);
5486 if(mr && heightlines) {
5487 while((item = map_rect_get_item(mr))) {
5489 while (item_coord_get(item, &c, 1)) {
5493 heightline=heightlines;
5496 coord_rect_extend(&rbbox, &c);
5497 while (heightline) {
5498 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
5499 for (i = 0 ; i < heightline->count - 1; i++) {
5500 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
5501 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
5502 diagram_point=g_new(struct diagram_point, 1);
5503 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
5504 diagram_point->c.y=heightline->height;
5505 diagram_point->next=diagram_points;
5506 diagram_points=diagram_point;
5507 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
5512 heightline=heightline->next;
5514 dist+=transform_distance(projection_mg, &last, &c);
5520 map_rect_destroy(mr);
5524 gui_internal_menu_render(this);
5526 diagram_point=diagram_points;
5527 while (diagram_point) {
5529 dbbox.lu=diagram_point->c;
5530 dbbox.rl=diagram_point->c;
5533 coord_rect_extend(&dbbox, &diagram_point->c);
5534 diagram_point=diagram_point->next;
5536 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
5537 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
5539 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
5541 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
5547 diagram_point=diagram_points;
5548 while (diagram_point) {
5549 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
5551 diagram_point=diagram_point->next;
5555 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
5556 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
5557 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
5558 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
5562 graphics_draw_lines(this->gra, this->foreground, p, 2);
5571 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5573 struct widget *menu,*wb,*w;
5576 graphics_draw_mode(this->gra, draw_mode_begin);
5577 menu=gui_internal_menu(this, _("Show Locale"));
5578 menu->spx=this->spacing*10;
5579 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5580 gui_internal_widget_append(menu, wb);
5581 text=g_strdup_printf("LANG=%s",getenv("LANG"));
5582 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5583 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5585 #ifdef HAVE_API_WIN32_BASE
5587 wchar_t wcountry[32],wlang[32];
5588 char country[32],lang[32];
5590 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
5591 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
5592 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
5593 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5594 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5596 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
5597 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
5598 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
5599 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5600 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
5605 gui_internal_menu_render(this);
5606 graphics_draw_mode(this->gra, draw_mode_end);
5610 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5612 struct widget *menu,*wb,*w;
5615 graphics_draw_mode(this->gra, draw_mode_begin);
5616 menu=gui_internal_menu(this, _("About Navit"));
5617 menu->spx=this->spacing*10;
5618 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
5619 gui_internal_widget_append(menu, wb);
5622 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
5623 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
5626 text=g_strdup_printf("%s",PACKAGE_NAME);
5627 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5628 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
5632 text=g_strdup_printf("%s",version);
5633 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5634 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
5638 text=g_strdup_printf("http://www.navit-project.org/");
5639 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5640 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
5644 text=g_strdup_printf("%s:",_("By"));
5645 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5646 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5648 text=g_strdup_printf("Martin Schaller");
5649 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5650 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5652 text=g_strdup_printf("Michael Farmbauer");
5653 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5654 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5656 text=g_strdup_printf("Alexander Atanasov");
5657 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5658 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5660 text=g_strdup_printf("Pierre Grandin");
5661 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5662 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5666 text=g_strdup_printf("%s",_("And all the Navit Team"));
5667 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5668 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5670 text=g_strdup_printf("%s",_("members and contributors."));
5671 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
5672 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
5675 gui_internal_menu_render(this);
5676 graphics_draw_mode(this->gra, draw_mode_end);
5681 * @brief handles the 'next page' table event.
5682 * A callback function that is invoked when the 'next page' button is pressed
5683 * to advance the contents of a table widget.
5685 * @param this The graphics context.
5686 * @param wm The button widget that was pressed.
5688 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
5690 struct widget * table_widget = (struct widget * ) wm->data;
5691 struct table_data * table_data = NULL;
5697 table_data = (struct table_data*) table_widget->data;
5703 * Before advancing to the next page we need to ensure
5704 * that the current top_row is in the list of previous top_rows
5705 * so previous page can work.
5708 for(iterator=table_data->page_headers; iterator != NULL;
5709 iterator = g_list_next(iterator) )
5711 if(iterator->data == table_data->top_row)
5720 table_data->page_headers=g_list_append(table_data->page_headers,
5721 table_data->top_row);
5724 table_data->top_row = g_list_next(table_data->bottom_row);
5726 wm->state&= ~STATE_HIGHLIGHTED;
5727 gui_internal_menu_render(this);
5733 * @brief handles the 'previous page' table event.
5734 * A callback function that is invoked when the 'previous page' button is pressed
5735 * to go back in the contents of a table widget.
5737 * @param this The graphics context.
5738 * @param wm The button widget that was pressed.
5740 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
5742 struct widget * table_widget = (struct widget * ) wm->data;
5743 struct table_data * table_data = NULL;
5744 GList * current_page_top=NULL;
5749 table_data = (struct table_data*) table_widget->data;
5752 current_page_top = table_data->top_row;
5753 for(iterator = table_data->page_headers; iterator != NULL;
5754 iterator = g_list_next(iterator))
5756 if(current_page_top == iterator->data)
5760 table_data->top_row = (GList*) iterator->data;
5764 wm->state&= ~STATE_HIGHLIGHTED;
5765 gui_internal_menu_render(this);
5770 * @brief deallocates a table_data structure.
5773 void gui_internal_table_data_free(void * p)
5778 * @note button_box and its children (next_button,prev_button)
5779 * have their memory managed by the table itself.
5781 struct table_data * table_data = (struct table_data*) p;
5782 g_list_free(table_data->page_headers);
5790 * @brief Called when the route is updated.
5792 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
5795 if(this->route_data.route_showing) {
5796 gui_internal_populate_route_table(this,navit);
5797 graphics_draw_mode(this->gra, draw_mode_begin);
5798 gui_internal_menu_render(this);
5799 graphics_draw_mode(this->gra, draw_mode_end);
5807 * @brief Called when the route screen is closed (deallocated).
5809 * The main purpose of this function is to remove the widgets from
5810 * references route_data because those widgets are about to be freed.
5812 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
5815 this_->route_data.route_showing=0;
5816 this_->route_data.route_table=NULL;
5823 * @brief Populates the route table with route information
5825 * @param this The gui context
5826 * @param navit The navit object
5828 void gui_internal_populate_route_table(struct gui_priv * this,
5829 struct navit * navit)
5831 struct map * map=NULL;
5832 struct map_rect * mr=NULL;
5833 struct navigation * nav = NULL;
5834 struct item * item =NULL;
5836 struct widget * label = NULL;
5837 struct widget * row = NULL;
5838 nav = navit_get_navigation(navit);
5842 map = navigation_get_map(nav);
5844 mr = map_rect_new(map,NULL);
5846 gui_internal_widget_table_clear(this,this->route_data.route_table);
5847 while((item = map_rect_get_item(mr))) {
5848 if(item_attr_get(item,attr_navigation_long,&attr)) {
5849 label = gui_internal_label_new(this,attr.u.str);
5850 row = gui_internal_widget_table_row_new(this,
5853 | orientation_horizontal);
5854 row->children=g_list_append(row->children,label);
5855 gui_internal_widget_append(this->route_data.route_table,row);
5863 static struct command_table commands[] = {
5864 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
5865 {"back",command_cast(gui_internal_cmd2_back)},
5866 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
5867 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
5868 {"get_data",command_cast(gui_internal_get_data)},
5869 {"locale",command_cast(gui_internal_cmd2_locale)},
5870 {"log",command_cast(gui_internal_cmd_log)},
5871 {"menu",command_cast(gui_internal_cmd_menu2)},
5872 {"position",command_cast(gui_internal_cmd2_position)},
5873 {"route_description",command_cast(gui_internal_cmd2_route_description)},
5874 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
5875 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
5876 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
5877 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
5878 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
5879 {"town",command_cast(gui_internal_cmd2_town)},
5880 {"quit",command_cast(gui_internal_cmd2_quit)},
5881 {"write",command_cast(gui_internal_cmd_write)},
5882 {"about",command_cast(gui_internal_cmd2_about)},
5886 //##############################################################################################################
5889 //# Authors: Martin Schaller (04/2008)
5890 //##############################################################################################################
5891 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
5893 struct gui_priv *this;
5895 *meth=gui_internal_methods;
5896 this=g_new0(struct gui_priv, 1);
5899 this->self.type=attr_gui;
5900 this->self.u.gui=gui;
5902 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
5903 this->menu_on_map_click=attr->u.num;
5905 this->menu_on_map_click=1;
5906 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
5907 this->signal_on_map_click=attr->u.num;
5909 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
5910 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
5913 if( (attr=attr_search(attrs,NULL,attr_font_size)))
5915 this->config.font_size=attr->u.num;
5919 this->config.font_size=-1;
5921 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
5923 this->config.icon_xs=attr->u.num;
5927 this->config.icon_xs=-1;
5929 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
5931 this->config.icon_l=attr->u.num;
5935 this->config.icon_l=-1;
5937 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
5939 this->config.icon_s=attr->u.num;
5943 this->config.icon_s=-1;
5945 if( (attr=attr_search(attrs,NULL,attr_spacing)))
5947 this->config.spacing=attr->u.num;
5951 this->config.spacing=-1;
5953 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
5955 this->speech=attr->u.num;
5957 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
5958 this->keyboard=attr->u.num;
5962 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
5963 this->fullscreen=attr->u.num;
5965 if( (attr=attr_search(attrs,NULL,attr_flags)))
5966 this->flags=attr->u.num;
5967 if( (attr=attr_search(attrs,NULL,attr_background_color)))
5968 this->background_color=*attr->u.color;
5970 this->background_color=COLOR_BLACK;
5971 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
5972 this->background2_color=*attr->u.color;
5974 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
5975 if( (attr=attr_search(attrs,NULL,attr_text_color)))
5976 this->text_foreground_color=*attr->u.color;
5978 this->text_foreground_color=COLOR_WHITE;
5979 this->text_background_color=COLOR_BLACK;
5980 if( (attr=attr_search(attrs,NULL,attr_columns)))
5981 this->cols=attr->u.num;
5982 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
5983 this->osd_configuration=*attr;
5985 if( (attr=attr_search(attrs,NULL,attr_pitch)))
5986 this->pitch=attr->u.num;
5989 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
5990 this->flags_town=attr->u.num;
5992 this->flags_town=-1;
5993 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
5994 this->flags_street=attr->u.num;
5996 this->flags_street=-1;
5997 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
5998 this->flags_house_number=attr->u.num;
6000 this->flags_house_number=-1;
6001 this->data.priv=this;
6002 this->data.gui=&gui_internal_methods_ext;
6003 this->data.widget=&gui_internal_widget_methods;
6004 this->cbl=callback_list_new();
6009 //##############################################################################################################
6012 //# Authors: Martin Schaller (04/2008)
6013 //##############################################################################################################
6014 void plugin_init(void)
6016 plugin_register_gui_type("internal", gui_internal_new);