2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2010 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 //##############################################################################################################
37 #ifdef HAVE_API_WIN32_BASE
43 #include "navit_nls.h"
49 #include "transform.h"
55 #include "vehicleprofile.h"
61 #include "navit/search.h"
66 #include "navit_nls.h"
67 #include "navigation.h"
68 #include "gui_internal.h"
70 #include "xmlconfig.h"
72 #include "bookmarks.h"
86 struct widget *search_list;
87 struct widget *keyboard;
88 struct widget *button_bar;
91 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
92 struct widget *redisplay_widget;
94 struct attr refresh_callback_obj,refresh_callback;
97 //##############################################################################################################
100 //# Authors: Martin Schaller (04/2008)
101 //##############################################################################################################
103 enum widget_type type;
104 struct graphics_gc *background,*text_background;
105 struct graphics_gc *foreground_frame;
106 struct graphics_gc *foreground;
108 struct graphics_image *img;
110 * A function to be invoked on actions.
111 * @li widget The widget that is receiving the button press.
114 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
119 * @brief A function to deallocate data
121 void (*data_free)(void *data);
124 * @brief a function that will be called as the widget is being destroyed.
125 * This function can act as a destructor for the widget. It allows for
126 * on deallocation actions to be specified on a per widget basis.
127 * This function will call g_free on the widget (if required).
129 void (*free) (struct gui_priv *this_, struct widget * w);
143 int bl,br,bt,bb,spx,spy;
147 * The number of widgets to layout horizontally when doing
148 * a orientation_horizontal_vertical layout
154 int (*set_attr)(void *, struct attr *);
155 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
156 void (*remove_cb)(void *, struct callback *cb);
163 struct menu_data *menu_data;
169 * @brief A structure to store configuration values.
171 * This structure stores configuration values for how gui elements in the internal GUI
174 struct gui_config_settings {
177 * The base size (in fractions of a point) to use for text.
181 * The size (in pixels) that xs style icons should be scaled to.
182 * This icon size can be too small to click it on some devices.
186 * The size (in pixels) that s style icons (small) should be scaled to
190 * The size (in pixels) that l style icons should be scaled to
194 * The default amount of spacing (in pixels) to place between GUI elements.
201 * Indexes into the config_profiles array.
203 const int LARGE_PROFILE=0;
204 const int MEDIUM_PROFILE=1;
205 const int SMALL_PROFILE=2;
208 * The default config profiles.
210 * [0] => LARGE_PROFILE (screens 640 in one dimension)
211 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
212 * [2] => Small profile (default)
214 static struct gui_config_settings config_profiles[]={
221 struct widget * route_table;
226 //##############################################################################################################
229 //# Authors: Martin Schaller (04/2008)
230 //##############################################################################################################
235 struct graphics *gra;
236 struct graphics_gc *background;
237 struct graphics_gc *background2;
238 struct graphics_gc *highlight_background;
239 struct graphics_gc *foreground;
240 struct graphics_gc *text_foreground;
241 struct graphics_gc *text_background;
242 struct color background_color, background2_color, text_foreground_color, text_background_color;
246 struct graphics_font *fonts[3];
248 * The size (in pixels) that xs style icons should be scaled to.
249 * This icon size can be too small to click it on some devices.
253 * The size (in pixels) that s style icons (small) should be scaled to
257 * The size (in pixels) that l style icons should be scaled to
261 struct widget *widgets;
265 struct widget *highlighted,*editable;
266 struct widget *highlighted_menu;
267 int clickp_valid, vehicle_valid;
268 struct pcoord clickp, vehiclep;
269 struct attr *click_coord_geo, *position_coord_geo;
270 struct search_list *sl;
272 int menu_on_map_click;
273 int signal_on_map_click;
277 int keyboard_required;
279 * The setting information read from the configuration file.
280 * values of -1 indicate no value was specified in the config file.
282 struct gui_config_settings config;
283 struct event_idle *idle;
284 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
285 struct event_timeout *motion_timeout_event;
286 struct point current;
288 struct callback * vehicle_cb;
290 * Stores information about the route.
292 struct route_data route_data;
294 struct gui_internal_data data;
295 struct callback_list *cbl;
298 struct attr osd_configuration;
300 int flags_town,flags_street,flags_house_number;
305 struct widget *html_container;
309 int html_anchor_found;
329 struct widget *container;
333 struct html_tag_map {
339 {"html",html_tag_html},
340 {"img",html_tag_img},
341 {"script",html_tag_script},
342 {"form",html_tag_form},
343 {"input",html_tag_input},
344 {"div",html_tag_div},
349 * @brief A structure to store information about a table.
351 * The table_data widget stores pointers to extra information needed by the
354 * The table_data structure needs to be freed with data_free along with the widget.
360 * A GList pointer into a widget->children list that indicates the row
361 * currently being rendered at the top of the table.
365 * A Glist pointer into a widget->children list that indicates the row
366 * currently being rendered at the bottom of the table.
371 * A list of table_row widgets that mark the
372 * top rows for each page of the table.
373 * This is needed for the 'previous page' function of the table.
375 GList * page_headers;
378 * A container box that is the child of the table widget that contains+groups
379 * the next and previous button.
381 struct widget * button_box;
384 * A button widget to handle 'next page' requests
386 struct widget * next_button;
388 * A button widget to handle 'previous page' requests.
390 struct widget * prev_button;
394 * a pointer to the gui context.
395 * This is needed by the free function to destory the buttons.
397 struct gui_priv * this;
401 * A data structure that holds information about a column that makes up a table.
405 struct table_column_desc
409 * The computed height of a cell in the table.
414 * The computed width of a cell in the table.
420 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
421 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
422 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
423 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
424 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child);
425 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child);
426 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
427 static void gui_internal_apply_config(struct gui_priv *this);
429 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
430 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
431 static void gui_internal_table_hide_rows(struct table_data * table_data);
432 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
433 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
434 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
435 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
436 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
437 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
438 static void gui_internal_table_data_free(void * d);
439 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
441 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
442 static void gui_internal_populate_route_table(struct gui_priv * this,
443 struct navit * navit);
444 static void gui_internal_search_idle_end(struct gui_priv *this);
445 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
446 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
447 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
448 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
449 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
450 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
451 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
452 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
453 static void gui_internal_check_exit(struct gui_priv *this);
454 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
456 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
457 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
459 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
460 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
461 static void gui_internal_html_load_href(struct gui_priv *this, char *href, int replace);
462 static void gui_internal_destroy(struct gui_priv *this);
465 * * Display image scaled to specific size
466 * * searches for scaleable and pre-scaled image
467 * * @param this Our gui context
468 * * @param name image name
469 * * @param w desired width of image
470 * * @param h desired height of image
471 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
473 static struct graphics_image *
474 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
476 struct graphics_image *ret=NULL;
477 char *full_name=NULL;
478 char *full_path=NULL;
481 for (i = 1 ; i < 6 ; i++) {
485 full_name=g_strdup_printf("%s.svg", name);
488 full_name=g_strdup_printf("%s.svgz", name);
491 if (w != -1 && h != -1) {
492 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
496 full_name=g_strdup_printf("%s.png", name);
499 full_name=g_strdup_printf("%s.xpm", name);
502 dbg(1,"trying '%s'\n", full_name);
506 /* needs to be checked in the driver */
507 if (!file_exists(full_name)) {
512 full_path=graphics_icon_path(full_name);
513 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
514 dbg(1,"ret=%p\n", ret);
520 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
525 static struct graphics_image *
526 image_new_o(struct gui_priv *this, char *name)
528 return image_new_scaled(this, name, -1, -1);
533 * * Display image scaled to xs (extra small) size
534 * * This image size can be too small to click it on some devices.
535 * * @param this Our gui context
536 * * @param name image name
537 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
539 static struct graphics_image *
540 image_new_xs(struct gui_priv *this, const char *name)
542 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
546 * * Display image scaled to s (small) size
547 * * @param this Our gui context
548 * * @param name image name
549 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
552 static struct graphics_image *
553 image_new_s(struct gui_priv *this, const char *name)
555 return image_new_scaled(this, name, this->icon_s, this->icon_s);
559 * * Display image scaled to l (large) size
560 * * @param this Our gui context
561 * * @param name image name
562 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
564 static struct graphics_image *
565 image_new_l(struct gui_priv *this, const char *name)
567 return image_new_scaled(this, name, this->icon_l, this->icon_l);
571 coordinates_geo(const struct coord_geo *gc, char sep)
573 char latc='N',lngc='E';
574 int lat_deg,lat_min,lat_sec;
575 int lng_deg,lng_min,lng_sec;
576 struct coord_geo g=*gc;
587 lat_min=fmod(g.lat*60,60);
588 lat_sec=fmod(g.lat*3600,60);
590 lng_min=fmod(g.lng*60,60);
591 lng_sec=fmod(g.lng*3600,60);
592 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);
596 coordinates(struct pcoord *pc, char sep)
602 transform_to_geo(pc->pro, &c, &g);
603 return coordinates_geo(&g, sep);
608 gui_internal_background_render(struct gui_priv *this, struct widget *w)
610 struct point pnt=w->p;
611 if (w->state & STATE_HIGHLIGHTED)
612 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
615 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
619 static struct widget *
620 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
626 struct widget *widget=g_new0(struct widget, 1);
627 widget->type=widget_label;
628 widget->font_idx=font;
630 widget->text=g_strdup(text);
631 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
635 widget->h=h+this->spacing;
637 widget->w=w+this->spacing;
639 widget->flags=gravity_center;
640 widget->foreground=this->text_foreground;
641 widget->text_background=this->text_background;
646 static struct widget *
647 gui_internal_label_new(struct gui_priv *this, char *text)
649 return gui_internal_label_font_new(this, text, 0);
652 static struct widget *
653 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
655 struct widget *ret=NULL;
656 char *tmp=g_malloc(strlen(text)+3);
663 ret=gui_internal_label_new(this, tmp);
664 if (ret->w < maxwidth)
666 gui_internal_widget_destroy(this, ret);
674 static struct widget *
675 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
677 struct widget *widget=g_new0(struct widget, 1);
678 widget->type=widget_image;
681 widget->w=image->width;
682 widget->h=image->height;
688 gui_internal_image_render(struct gui_priv *this, struct widget *w)
692 gui_internal_background_render(this, w);
695 pnt.x+=w->w/2-w->img->hot.x;
696 pnt.y+=w->h/2-w->img->hot.y;
697 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
702 gui_internal_label_render(struct gui_priv *this, struct widget *w)
704 struct point pnt=w->p;
705 gui_internal_background_render(this, w);
706 if (w->state & STATE_EDIT)
707 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
710 char *startext=(char*)g_alloca(strlen(w->text)+1);
714 for (i = 0 ; i < strlen(text); i++)
719 if (w->flags & gravity_right) {
720 pnt.y+=w->h-this->spacing;
721 pnt.x+=w->w-w->textw-this->spacing;
722 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
724 pnt.y+=w->h-this->spacing;
725 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
731 * @brief A text box is a widget that renders a text string containing newlines.
732 * The string will be broken up into label widgets at each newline with a vertical layout.
735 static struct widget *
736 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
738 char *s=g_strdup(text),*s2,*tok;
739 struct widget *ret=gui_internal_box_new(this, flags);
741 while ((tok=strtok(s2,"\n"))) {
742 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
745 gui_internal_widget_pack(this,ret);
750 static struct widget *
751 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
753 return gui_internal_text_font_new(this, text, 0, flags);
757 static struct widget *
758 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)
760 struct widget *ret=NULL;
761 ret=gui_internal_box_new(this, flags);
764 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
766 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
770 ret->state |= STATE_SENSITIVE;
771 ret->speech=g_strdup(text);
778 static struct widget *
779 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)
781 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
785 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
792 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
793 is_on=curr.u.data == w->on.u.data;
796 if (is_on != w->is_on) {
800 l=g_list_first(w->children);
804 graphics_image_free(this->gra, wi->img);
805 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
807 if (w->is_on && w->off.type == attr_none)
808 w->state &= ~STATE_SENSITIVE;
810 w->state |= STATE_SENSITIVE;
817 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
819 if (gui_internal_button_attr_update(this, w))
820 gui_internal_widget_render(this, w);
823 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
826 w->set_attr(w->instance, &w->off);
828 w->set_attr(w->instance, &w->on);
829 gui_internal_button_attr_update(this, w);
833 static struct widget *
834 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
836 struct graphics_image *image=NULL;
840 image=image_new_xs(this, "gui_inactive");
841 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
846 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
847 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
848 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
849 ret->instance=this->nav;
850 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
851 navit_add_callback(this->nav, ret->cb);
852 gui_internal_button_attr_update(this, ret);
856 static struct widget *
857 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)
859 struct graphics_image *image=NULL;
861 image=image_new_xs(this, "gui_inactive");
864 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
870 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
871 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
872 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
875 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
876 map_add_callback(map, ret->cb);
877 gui_internal_button_attr_update(this, ret);
881 static struct widget *
882 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
884 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
888 //##############################################################################################################
891 //# Authors: Martin Schaller (04/2008)
892 //##############################################################################################################
893 static void gui_internal_clear(struct gui_priv *this)
895 struct graphics *gra=this->gra;
899 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
903 static struct widget *
904 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
906 struct widget *ret,*child;
907 GList *l=wi->children;
914 if ( wi->p.x + wi->w < p->x)
916 if ( wi->p.y + wi->h < p->y)
919 if (wi->state & flags)
923 ret=gui_internal_find_widget(child, p, flags);
934 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
936 if (found == this->highlighted)
939 graphics_draw_mode(this->gra, draw_mode_begin);
940 if (this->highlighted) {
941 this->highlighted->state &= ~STATE_HIGHLIGHTED;
942 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
943 gui_internal_widget_render(this, this->highlighted);
944 this->highlighted=NULL;
945 this->highlighted_menu=NULL;
948 this->highlighted=found;
949 this->highlighted_menu=g_list_last(this->root.children)->data;
950 this->highlighted->state |= STATE_HIGHLIGHTED;
951 gui_internal_widget_render(this, this->highlighted);
952 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
954 graphics_draw_mode(this->gra, draw_mode_end);
956 //##############################################################################################################
959 //# Authors: Martin Schaller (04/2008)
960 //##############################################################################################################
961 static void gui_internal_highlight(struct gui_priv *this)
963 struct widget *menu,*found=NULL;
964 if (this->current.x > -1 && this->current.y > -1) {
965 menu=g_list_last(this->root.children)->data;
966 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
968 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
970 if (this->editable && this->editable != found) {
971 this->editable->state &= ~ STATE_EDIT;
972 gui_internal_widget_render(this, this->editable);
974 found->state |= STATE_EDIT;
975 gui_internal_widget_render(this, found);
976 this->editable=found;
981 gui_internal_highlight_do(this, found);
982 this->motion_timeout_event=NULL;
985 static struct widget *
986 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
988 struct widget *widget=g_new0(struct widget, 1);
991 widget->text=g_strdup(label);
992 widget->type=widget_box;
997 static struct widget *
998 gui_internal_box_new(struct gui_priv *this, enum flags flags)
1000 return gui_internal_box_new_with_label(this, flags, NULL);
1004 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
1009 gui_internal_background_render(this, w);
1012 w->foreground=this->foreground;
1015 if (w->foreground && w->border) {
1016 struct point pnt[5];
1018 pnt[1].x=pnt[0].x+w->w;
1020 pnt[2].x=pnt[0].x+w->w;
1021 pnt[2].y=pnt[0].y+w->h;
1023 pnt[3].y=pnt[0].y+w->h;
1025 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
1026 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
1027 graphics_gc_set_linewidth(w->foreground, 1);
1034 gui_internal_widget_render(this, wc);
1041 * @brief Compute the size and location for the widget.
1045 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
1048 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;
1050 int orientation=w->flags & 0xffff0000;
1055 if ( this->root.w > this->root.h )
1065 * count the number of children
1072 if (orientation == orientation_horizontal_vertical && count <= cols)
1073 orientation=orientation_horizontal;
1074 switch (orientation) {
1075 case orientation_horizontal:
1077 * For horizontal orientation:
1078 * pack each child and find the largest height and
1079 * compute the total width. x spacing (spx) is considered
1081 * If any children want to be expanded
1082 * we keep track of this
1087 gui_internal_widget_pack(this, wc);
1091 if (wc->flags & flags_expand)
1092 expand+=wc->w ? wc->w : 1;
1098 if (expand && w->w) {
1099 expandd=w->w-width+expand;
1104 case orientation_vertical:
1106 * For vertical layouts:
1107 * We pack each child and compute the largest width and
1108 * the total height. y spacing (spy) is considered
1110 * If the expand flag is set then teh expansion amount
1116 gui_internal_widget_pack(this, wc);
1120 if (wc->flags & flags_expand)
1121 expand+=wc->h ? wc->h : 1;
1127 if (expand && w->h) {
1128 expandd=w->h-height+expand;
1133 case orientation_horizontal_vertical:
1135 * For horizontal_vertical orientation
1136 * pack the children.
1137 * Compute the largest height and largest width.
1138 * Layout the widgets based on having the
1139 * number of columns specified by (cols)
1145 gui_internal_widget_pack(this, wc);
1155 rows=(count+cols-1)/cols;
1158 width+=w->spx*(cols-1);
1159 height+=w->spy*(rows-1);
1166 * No orientation was specified.
1167 * width and height are both 0.
1168 * The width & height of this widget
1172 dbg(0,"Warning width and height of a widget are 0");
1175 if (! w->w && ! w->h) {
1176 w->w=w->bl+w->br+width;
1177 w->h=w->bt+w->bb+height;
1186 * At this stage the width and height of this
1187 * widget has been computed.
1188 * We now make a second pass assigning heights,
1189 * widths and coordinates to each child widget.
1192 if (w->flags & gravity_left)
1194 if (w->flags & gravity_xcenter)
1195 x=w->p.x+w->w/2-owidth/2;
1196 if (w->flags & gravity_right)
1197 x=w->p.x+w->w-w->br-owidth;
1198 if (w->flags & gravity_top)
1200 if (w->flags & gravity_ycenter)
1201 y=w->p.y+w->h/2-oheight/2;
1202 if (w->flags & gravity_bottom)
1203 y=w->p.y+w->h-w->bb-oheight;
1205 switch (orientation) {
1206 case orientation_horizontal:
1211 if (wc->flags & flags_fill)
1213 if (wc->flags & flags_expand) {
1216 wc->w=wc->w*expandd/expand;
1218 if (w->flags & gravity_top)
1220 if (w->flags & gravity_ycenter)
1222 if (w->flags & gravity_bottom)
1228 case orientation_vertical:
1233 if (wc->flags & flags_fill)
1235 if (wc->flags & flags_expand) {
1238 wc->h=wc->h*expandd/expand;
1240 if (w->flags & gravity_left)
1242 if (w->flags & gravity_xcenter)
1244 if (w->flags & gravity_right)
1250 case orientation_horizontal_vertical:
1260 if (wc->flags & flags_fill) {
1264 if (w->flags & gravity_left)
1266 if (w->flags & gravity_xcenter)
1267 wc->p.x=x+(width-wc->w)/2;
1268 if (w->flags & gravity_right)
1269 wc->p.x=x+width-wc->w;
1270 if (w->flags & gravity_top)
1272 if (w->flags & gravity_ycenter)
1273 wc->p.y=y+(height-wc->h)/2;
1274 if (w->flags & gravity_bottom)
1275 wc->p.y=y-height-wc->h;
1277 if (++count == cols) {
1289 * Call pack again on each child,
1290 * the child has now had its size and coordinates
1291 * set so they can repack their children.
1296 gui_internal_widget_pack(this, wc);
1302 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1310 gui_internal_widget_reset_pack(this, wc);
1320 gui_internal_widget_append(struct widget *parent, struct widget *child)
1324 if (! child->background)
1325 child->background=parent->background;
1326 parent->children=g_list_append(parent->children, child);
1329 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1331 if (! child->background)
1332 child->background=parent->background;
1333 parent->children=g_list_prepend(parent->children, child);
1336 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child)
1339 if (! child->background)
1340 child->background=parent->background;
1343 sib=g_list_find(parent->children,sibling);
1344 parent->children=g_list_insert_before(parent->children, sib, child);
1348 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1356 gui_internal_widget_destroy(this, wc);
1359 g_list_free(w->children);
1363 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1365 gui_internal_widget_children_destroy(this, w);
1370 graphics_image_free(this->gra, w->img);
1376 w->data_free(w->data);
1377 if (w->cb && w->remove_cb)
1378 w->remove_cb(w->instance, w->cb);
1379 if (w==this->highlighted)
1380 this->highlighted=NULL;
1389 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1391 if(w->p.x > this->root.w || w->p.y > this->root.h)
1396 gui_internal_box_render(this, w);
1399 gui_internal_label_render(this, w);
1402 gui_internal_image_render(this, w);
1405 gui_internal_table_render(this,w);
1413 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1417 gui_internal_box_pack(this, w);
1420 gui_internal_table_pack(this,w);
1426 //##############################################################################################################
1429 //# Authors: Martin Schaller (04/2008)
1430 //##############################################################################################################
1431 static void gui_internal_call_highlighted(struct gui_priv *this)
1433 if (! this->highlighted || ! this->highlighted->func)
1435 this->highlighted->reason=1;
1436 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1440 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1442 char *text=w->speech;
1450 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1451 navit_say(this->nav, text);
1457 gui_internal_menu_destroy(struct gui_priv *this, struct widget *w)
1459 struct menu_data *menu_data=w->menu_data;
1461 if (menu_data->refresh_callback_obj.type) {
1462 struct object_func *func;
1463 func=object_func_lookup(menu_data->refresh_callback_obj.type);
1464 if (func && func->remove_attr)
1465 func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
1467 if (menu_data->refresh_callback.u.callback)
1468 callback_destroy(menu_data->refresh_callback.u.callback);
1470 g_free(menu_data->href);
1473 gui_internal_widget_destroy(this, w);
1474 this->root.children=g_list_remove(this->root.children, w);
1478 gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render)
1481 struct widget *wr,*wd;
1482 gui_internal_search_idle_end(this);
1483 while ((l = g_list_last(this->root.children))) {
1486 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1489 gui_internal_say(this, w, 0);
1490 redisplay=w->menu_data->redisplay;
1491 wr=w->menu_data->redisplay_widget;
1492 if (!w->menu_data->redisplay && !w->menu_data->href) {
1493 gui_internal_widget_render(this, w);
1497 gui_internal_menu_destroy(this, w);
1498 redisplay(this, wr, wr->data);
1500 char *href=g_strdup(w->menu_data->href);
1501 gui_internal_menu_destroy(this, w);
1502 gui_internal_html_load_href(this, href, 0);
1507 gui_internal_menu_destroy(this, wd);
1512 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1514 gui_internal_prune_menu_do(this, w, 1);
1518 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1520 GList *l=g_list_last(this->root.children);
1521 struct widget *w=NULL;
1522 while (l && count-- > 0)
1523 l=g_list_previous(l);
1526 gui_internal_prune_menu_do(this, w, render);
1531 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1533 gui_internal_prune_menu_count(this, 1, 1);
1537 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1539 gui_internal_prune_menu(this, wm->data);
1543 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1545 graphics_draw_mode(this->gra, draw_mode_begin);
1546 gui_internal_back(this, NULL, NULL);
1547 graphics_draw_mode(this->gra, draw_mode_end);
1548 gui_internal_check_exit(this);
1552 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1554 gui_internal_prune_menu(this, NULL);
1558 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1560 gui_internal_prune_menu(this, this->root.children->data);
1563 static struct widget *
1564 gui_internal_top_bar(struct gui_priv *this)
1566 struct widget *w,*wm,*wh,*wc,*wcn;
1567 int dots_len, sep_len;
1569 int width,width_used=0,use_sep=0,incomplete=0;
1570 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1572 1:Don't expand bar to screen width
1573 2:Don't show Map Icon
1574 4:Don't show Home Icon
1575 8:Show only current menu
1576 16:Don't use menu titles as button
1577 32:Show navit version
1580 256:Use background for menu headline
1581 512:Set osd_configuration and zoom to route when setting position
1582 1024:Don't show back button
1583 2048:No highlighting of keyboard
1586 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1587 w->bl=this->spacing;
1588 w->spx=this->spacing;
1589 w->background=this->background2;
1590 if ((this->flags & 6) == 6) {
1596 width=this->root.w-w->bl;
1597 if (! (this->flags & 2)) {
1598 wm=gui_internal_button_new_with_callback(this, NULL,
1599 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1600 gui_internal_cmd_return, NULL);
1601 wm->speech=g_strdup(_("Back to map"));
1602 gui_internal_widget_pack(this, wm);
1603 gui_internal_widget_append(w, wm);
1606 if (! (this->flags & 4)) {
1607 wh=gui_internal_button_new_with_callback(this, NULL,
1608 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1609 gui_internal_cmd_main_menu, NULL);
1610 wh->speech=g_strdup(_("Main Menu"));
1611 gui_internal_widget_pack(this, wh);
1612 gui_internal_widget_append(w, wh);
1615 if (!(this->flags & 6))
1617 l=g_list_last(this->root.children);
1618 wcn=gui_internal_label_new(this,".. »");
1619 wcn->foreground=foreground;
1621 gui_internal_widget_destroy(this, wcn);
1622 wcn=gui_internal_label_new(this,"»");
1623 wcn->foreground=foreground;
1625 gui_internal_widget_destroy(this, wcn);
1627 if (g_list_previous(l) || !g_list_next(l)) {
1629 wcn=gui_internal_label_new(this, wc->text);
1630 wcn->foreground=foreground;
1635 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1636 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1638 gui_internal_widget_destroy(this, wcn);
1642 struct widget *wct=gui_internal_label_new(this, "»");
1643 wct->foreground=foreground;
1644 res=g_list_prepend(res, wct);
1645 width_used+=sep_len+w->spx;
1648 if (!(this->flags & 16)) {
1649 wcn->func=gui_internal_cmd_return;
1651 wcn->state |= STATE_SENSITIVE;
1653 res=g_list_prepend(res, wcn);
1654 if (this->flags & 8)
1657 l=g_list_previous(l);
1661 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1662 wcn->foreground=foreground;
1663 wcn->func=gui_internal_cmd_return;
1665 wcn->state |= STATE_SENSITIVE;
1666 res=g_list_prepend(res, wcn);
1667 l=g_list_previous(l);
1670 wcn=gui_internal_label_new(this, ".. »");
1671 wcn->foreground=foreground;
1672 wcn->func=gui_internal_cmd_return;
1674 wcn->state |= STATE_SENSITIVE;
1675 res=g_list_prepend(res, wcn);
1679 gui_internal_widget_append(w, l->data);
1682 if (this->flags & 32) {
1683 char *version_text=g_strdup_printf("Navit %s",version);
1684 wcn=gui_internal_label_new(this, version_text);
1685 g_free(version_text);
1686 wcn->flags=gravity_right_center|flags_expand;
1687 gui_internal_widget_append(w, wcn);
1691 gui_internal_widget_destroy(this, dots);
1696 static struct widget *
1697 gui_internal_time_help(struct gui_priv *this)
1699 struct widget *w,*wc,*wcn;
1704 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1705 w->bl=this->spacing;
1706 w->spx=this->spacing;
1712 if (this->flags & 64) {
1713 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1719 tm=localtime(&timep);
1720 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1721 wcn=gui_internal_label_new(this, timestr);
1722 gui_internal_widget_append(wc, wcn);
1723 gui_internal_widget_append(w, wc);
1725 if (this->flags & 128) {
1726 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1727 gui_internal_widget_append(w, wcn);
1734 * Applys the configuration values to this based on the settings
1735 * specified in the configuration file (this->config) and
1736 * the most approriate default profile based on screen resolution.
1738 * This function should be run after this->root is setup and could
1739 * be rerun after the window is resized.
1741 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1743 static void gui_internal_apply_config(struct gui_priv *this)
1745 struct gui_config_settings * current_config=0;
1747 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1749 * Select default values from profile based on the screen.
1751 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1753 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1755 current_config = &config_profiles[LARGE_PROFILE];
1759 current_config = &config_profiles[MEDIUM_PROFILE];
1764 current_config = &config_profiles[SMALL_PROFILE];
1768 * Apply override values from config file
1770 if(this->config.font_size == -1 )
1772 this->font_size = current_config->font_size;
1776 this->font_size = this->config.font_size;
1779 if(this->config.icon_xs == -1 )
1781 this->icon_xs = current_config->icon_xs;
1785 this->icon_xs = this->config.icon_xs;
1788 if(this->config.icon_s == -1 )
1790 this->icon_s = current_config->icon_s;
1794 this->icon_s = this->config.icon_s;
1796 if(this->config.icon_l == -1 )
1798 this->icon_l = current_config->icon_l;
1802 this->icon_l = this->config.icon_l;
1804 if(this->config.spacing == -1 )
1806 this->spacing = current_config->spacing;
1810 this->spacing = current_config->spacing;
1815 static struct widget *
1816 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1818 struct widget *wl,*wlb;
1819 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1820 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1821 wl=gui_internal_label_new(this, label);
1823 wlb->foreground=this->text_foreground;
1828 gui_internal_widget_append(wlb, wl);
1830 gui_internal_widget_prepend(wb, wlb);
1832 gui_internal_widget_append(wb, wlb);
1838 static struct widget *
1839 gui_internal_menu(struct gui_priv *this, const char *label)
1841 struct widget *menu,*w,*w1,*topbox;
1843 gui_internal_search_idle_end(this);
1844 topbox=gui_internal_box_new_with_label(this, 0, label);
1845 topbox->w=this->root.w;
1846 topbox->h=this->root.h;
1847 gui_internal_widget_append(&this->root, topbox);
1848 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1849 menu->w=this->root.w;
1850 menu->h=this->root.h;
1851 menu->background=this->background;
1852 gui_internal_apply_config(this);
1853 if (!this->fonts[0]) {
1854 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
1855 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
1856 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
1858 topbox->menu_data=g_new0(struct menu_data, 1);
1859 gui_internal_widget_append(topbox, menu);
1860 w=gui_internal_top_bar(this);
1861 gui_internal_widget_append(menu, w);
1862 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1863 w->spx=4*this->spacing;
1865 gui_internal_widget_append(menu, w);
1866 if (this->flags & 16 && !(this->flags & 1024)) {
1867 struct widget *wlb,*wb,*wm=w;
1868 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1869 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1870 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1871 gui_internal_widget_append(wm, w);
1872 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1878 topbox->menu_data->button_bar=wb;
1879 gui_internal_widget_append(wm, wb);
1880 wlb=gui_internal_button_label(this,_("Back"),1);
1881 wlb->func=gui_internal_back;
1882 wlb->state |= STATE_SENSITIVE;
1884 if (this->flags & 192) {
1885 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1886 menu->w=this->root.w;
1887 menu->h=this->root.h;
1888 w1=gui_internal_time_help(this);
1889 gui_internal_widget_append(menu, w1);
1890 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1891 gui_internal_widget_append(menu, w1);
1892 gui_internal_widget_append(topbox, menu);
1893 menu->background=NULL;
1895 gui_internal_widget_pack(this, topbox);
1896 gui_internal_widget_reset_pack(this, topbox);
1897 topbox->w=this->root.w;
1898 topbox->h=this->root.h;
1899 menu->w=this->root.w;
1900 menu->h=this->root.h;
1904 static struct menu_data *
1905 gui_internal_menu_data(struct gui_priv *this)
1908 struct widget *menu;
1910 l=g_list_last(this->root.children);
1912 return menu->menu_data;
1916 gui_internal_menu_reset_pack(struct gui_priv *this)
1919 struct widget *top_box;
1921 l=g_list_last(this->root.children);
1923 gui_internal_widget_reset_pack(this, top_box);
1927 gui_internal_menu_render(struct gui_priv *this)
1930 struct widget *menu;
1932 l=g_list_last(this->root.children);
1934 gui_internal_say(this, menu, 0);
1935 gui_internal_widget_pack(this, menu);
1936 gui_internal_widget_render(this, menu);
1940 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1943 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1944 navit_set_destination(this->nav, &wm->c, name, 1);
1945 if (this->flags & 512) {
1947 follow.type=attr_follow;
1949 navit_set_attr(this->nav, &this->osd_configuration);
1950 navit_set_attr(this->nav, &follow);
1951 navit_zoom_to_route(this->nav, 0);
1953 gui_internal_prune_menu(this, NULL);
1957 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1959 navit_set_position(this->nav, &wm->c);
1960 gui_internal_prune_menu(this, NULL);
1964 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1968 dbg(0,"text='%s'\n", widget->text);
1969 if (widget->text && strlen(widget->text)){
1970 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1971 bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
1973 g_free(widget->text);
1975 l=g_list_previous(g_list_last(this->root.children));
1976 gui_internal_prune_menu(this, l->data);
1980 gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
1984 dbg(0,"text='%s'\n", widget->text);
1985 if (widget->text && strlen(widget->text)){
1986 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1987 bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
1989 g_free(widget->text);
1991 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
1992 gui_internal_prune_menu(this, l->data);
1996 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1998 gui_internal_cmd_add_bookmark_do(this, widget->data);
2002 gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
2004 gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
2008 gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
2010 struct widget *w=(struct widget*)widget->data;
2013 dbg(0,"text='%s'\n", w->text);
2014 if (w->text && strlen(w->text)){
2015 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2016 bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
2022 l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
2023 gui_internal_prune_menu(this, l->data);
2027 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
2032 len=strlen(wm->text);
2033 dbg(1,"len=%d\n", len);
2034 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2035 wm->text[len-1]='\0';
2036 gui_internal_cmd_add_bookmark_do(this, wm);
2042 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
2045 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
2047 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2049 wb=gui_internal_menu(this,_("Add Bookmark"));
2050 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2051 gui_internal_widget_append(wb, w);
2052 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2053 gui_internal_widget_append(w, we);
2054 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2055 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2056 wk->background=this->background;
2057 wk->flags |= flags_expand|flags_fill;
2058 wk->func = gui_internal_cmd_add_bookmark_changed;
2060 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2061 wnext->state |= STATE_SENSITIVE;
2062 wnext->func = gui_internal_cmd_add_bookmark_clicked;
2064 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2065 gui_internal_widget_append(w, wl);
2067 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2068 gui_internal_menu_render(this);
2072 gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
2074 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2076 wb=gui_internal_menu(this,_("Add Bookmark folder"));
2077 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2078 gui_internal_widget_append(wb, w);
2079 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2080 gui_internal_widget_append(w, we);
2081 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2082 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2083 wk->background=this->background;
2084 wk->flags |= flags_expand|flags_fill;
2085 wk->func = gui_internal_cmd_add_bookmark_changed;
2087 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2088 wnext->state |= STATE_SENSITIVE;
2089 wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
2091 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2092 gui_internal_widget_append(w, wl);
2094 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2095 gui_internal_menu_render(this);
2099 gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2101 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2102 char *name=wm->text;
2103 wb=gui_internal_menu(this,_("Rename"));
2104 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2105 gui_internal_widget_append(wb, w);
2106 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2107 gui_internal_widget_append(w, we);
2108 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2109 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2110 wk->background=this->background;
2111 wk->flags |= flags_expand|flags_fill;
2112 wk->func = gui_internal_cmd_add_bookmark_changed;
2114 wk->name=g_strdup(name);
2115 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2116 wnext->state |= STATE_SENSITIVE;
2117 wnext->func = gui_internal_cmd_rename_bookmark_clicked;
2119 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2120 gui_internal_widget_append(w, wl);
2122 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2123 gui_internal_menu_render(this);
2127 gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2131 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2132 bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
2133 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2134 gui_internal_prune_menu(this, l->data);
2138 gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2142 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2143 bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
2144 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2145 gui_internal_prune_menu(this, l->data);
2149 gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2153 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2154 bookmarks_paste_bookmark(mattr.u.bookmarks);
2155 l=g_list_previous(g_list_last(this->root.children));
2156 gui_internal_prune_menu(this, l->data);
2160 gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2164 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2165 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
2166 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2167 gui_internal_prune_menu(this, l->data);
2171 get_direction(char *buffer, int angle, int mode)
2176 sprintf(buffer,"%d",angle);
2179 if (angle < 69 || angle > 291)
2181 if (angle > 111 && angle < 249)
2183 if (angle > 22 && angle < 158)
2185 if (angle > 202 && angle < 338)
2190 angle=(angle+15)/30;
2193 sprintf(buffer,"%d H", angle);
2198 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2201 //MSVC doesn't supports this style of initialization and i'm not sure
2206 enum item_type *types;
2208 struct selector selectors[]={
2209 {"bank","Bank",(enum item_type []){
2210 type_poi_bank,type_poi_bank,
2211 type_poi_atm,type_poi_atm,
2213 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
2214 {"hotel","Hotel",(enum item_type []) {
2215 type_poi_hotel,type_poi_camp_rv,
2216 type_poi_camping,type_poi_camping,
2217 type_poi_resort,type_poi_resort,
2218 type_poi_motel,type_poi_hostel,
2220 {"restaurant","Restaurant",(enum item_type []) {
2221 type_poi_bar,type_poi_picnic,
2222 type_poi_burgerking,type_poi_fastfood,
2223 type_poi_restaurant,type_poi_restaurant,
2224 type_poi_cafe,type_poi_cafe,
2225 type_poi_pub,type_poi_pub,
2227 {"shopping","Shopping",(enum item_type []) {
2228 type_poi_mall,type_poi_mall,
2229 type_poi_shop_grocery,type_poi_shop_grocery,
2230 type_poi_shopping,type_poi_shopping,
2231 type_poi_shop_butcher,type_poi_shop_baker,
2232 type_poi_shop_fruit,type_poi_shop_fruit,
2233 type_poi_shop_beverages,type_poi_shop_beverages,
2235 {"hospital","Service",(enum item_type []) {
2236 type_poi_marina,type_poi_marina,
2237 type_poi_hospital,type_poi_hospital,
2238 type_poi_public_utilities,type_poi_public_utilities,
2239 type_poi_police,type_poi_autoservice,
2240 type_poi_information,type_poi_information,
2241 type_poi_pharmacy,type_poi_pharmacy,
2242 type_poi_personal_service,type_poi_repair_service,
2243 type_poi_restroom,type_poi_restroom,
2245 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
2246 {"peak","Land Features",(enum item_type []){
2247 type_poi_land_feature,type_poi_rock,
2248 type_poi_dam,type_poi_dam,
2249 type_poi_peak,type_poi_peak,
2251 {"unknown","Other",(enum item_type []){
2252 type_point_unspecified,type_poi_land_feature-1,
2253 type_poi_rock+1,type_poi_fuel-1,
2254 type_poi_marina+1,type_poi_shopping-1,
2255 type_poi_shopping+1,type_poi_car_parking-1,
2256 type_poi_car_parking+1,type_poi_bar-1,
2257 type_poi_bank+1,type_poi_dam-1,
2258 type_poi_dam+1,type_poi_information-1,
2259 type_poi_information+1,type_poi_mall-1,
2260 type_poi_mall+1,type_poi_personal_service-1,
2261 type_poi_pharmacy+1,type_poi_repair_service-1,
2262 type_poi_repair_service+1,type_poi_restaurant-1,
2263 type_poi_restaurant+1,type_poi_restroom-1,
2264 type_poi_restroom+1,type_poi_shop_grocery-1,
2265 type_poi_shop_grocery+1,type_poi_peak-1,
2266 type_poi_peak+1, type_poi_motel-1,
2267 type_poi_hostel+1,type_poi_shop_butcher-1,
2268 type_poi_shop_baker+1,type_poi_shop_fruit-1,
2269 type_poi_shop_fruit+1,type_poi_shop_beverages-1,
2270 type_poi_shop_beverages+1,type_poi_pub-1,
2271 type_poi_atm+1,type_line-1,
2273 /* {"unknown","Unknown",(enum item_type []){
2274 type_point_unkn,type_point_unkn,
2280 * Get a utf-8 string, return the same prepared for case insensetive search. Result shoud be g_free()d after use.
2287 r=g_utf8_casefold(s,-1);
2292 * POI search/filtering parameters.
2299 * =1 if selnb is defined, 0 otherwize.
2304 * Index to struct selector selectors[], shows what type of POIs is defined.
2306 unsigned char selnb;
2308 * Page number to display.
2310 unsigned char pagenb;
2312 * Radius (number of 10-kilometer intervals) to search for POIs.
2316 * Should filter phrase be compared to postal address of the POI.
2317 * =1 - address filter, =0 - name filter
2319 unsigned char isAddressFilter;
2321 * Filter string, casefold()ed and divided into substrings at the spaces, which are replaced by ASCII 0*.
2325 * list of pointers to individual substrings of filterstr.
2329 * Number of POIs in this list
2336 * @brief Free poi_param structure.
2338 * @param p reference to the object to be freed.
2341 gui_internal_poi_param_free(void *p)
2343 if(((struct poi_param *)p)->filterstr)
2344 g_free(((struct poi_param *)p)->filterstr);
2345 if(((struct poi_param *)p)->filter)
2346 g_list_free(((struct poi_param *)p)->filter);
2351 * @brief Clone poi_param structure.
2353 * @param p reference to the object to be cloned.
2354 * @return Cloned object reference.
2356 static struct poi_param *
2357 gui_internal_poi_param_clone(struct poi_param *p)
2359 struct poi_param *r=g_new(struct poi_param,1);
2361 memcpy(r,p,sizeof(struct poi_param));
2365 char *last=g_list_last(l)->data;
2366 int len=(last - p->filterstr) + strlen(last)+1;
2367 r->filterstr=g_memdup(p->filterstr,len);
2370 r->filter=g_list_append(r->filter, r->filterstr + ((char*)(l->data) - p->filterstr) );
2377 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2378 static void gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data);
2381 static struct widget *
2382 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb)
2384 struct widget *wl,*wb;
2387 //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2388 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
2389 wl->background=this->background;
2391 wl->cols=this->root.w/this->icon_s;
2392 nitems=sizeof(selectors)/sizeof(struct selector);
2393 nrows=nitems/wl->cols + (nitems%wl->cols>0);
2394 wl->h=this->icon_l*nrows;
2395 for (i = 0 ; i < nitems ; i++) {
2396 struct poi_param *p=g_new0(struct poi_param,1);
2403 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2404 image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2405 gui_internal_cmd_pois, p));
2407 wb->data_free=gui_internal_poi_param_free;
2411 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2412 image_new_s(this, "gui_search"), gravity_left_center|orientation_vertical,
2413 gui_internal_cmd_pois_filter, NULL));
2417 gui_internal_widget_pack(this,wl);
2421 static struct widget *
2422 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist, char* name)
2427 struct widget *wl,*wt;
2430 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2433 sprintf(distbuf,"%d", dist/1000);
2435 sprintf(distbuf,"%d.%d", dist/1000, (dist%1000)/100);
2436 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2437 type=item_to_name(item->type);
2439 wl->name=g_strdup_printf("%s %s",type,name);
2441 wl->name=g_strdup(type);
2443 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, name);
2444 wt=gui_internal_label_new(this, text);
2446 gui_internal_widget_append(wl, wt);
2453 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
2455 const struct widget *wa=a;
2456 const struct widget *wb=b;
2457 struct widget *wac=wa->children->data;
2458 struct widget *wbc=wb->children->data;
2466 return wac->datai-wbc->datai;
2471 * @brief Get string representation of item address suitable for doing search and for display in POI list.
2473 * @param item reference to item.
2474 * @return Pointer to string representation of address. To be g_free()d after use.
2477 gui_internal_compose_item_address_string(struct item *item)
2479 char *s=g_strdup("");
2481 if(item_attr_get(item, attr_house_number, &attr))
2482 s=g_strjoin(" ",s,attr.u.str,NULL);
2483 if(item_attr_get(item, attr_street_name, &attr))
2484 s=g_strjoin(" ",s,attr.u.str,NULL);
2485 if(item_attr_get(item, attr_street_name_systematic, &attr))
2486 s=g_strjoin(" ",s,attr.u.str,NULL);
2487 if(item_attr_get(item, attr_district_name, &attr))
2488 s=g_strjoin(" ",s,attr.u.str,NULL);
2489 if(item_attr_get(item, attr_town_name, &attr))
2490 s=g_strjoin(" ",s,attr.u.str,NULL);
2491 if(item_attr_get(item, attr_county_name, &attr))
2492 s=g_strjoin(" ",s,attr.u.str,NULL);
2493 if(item_attr_get(item, attr_country_name, &attr))
2494 s=g_strjoin(" ",s,attr.u.str,NULL);
2496 if(item_attr_get(item, attr_address, &attr))
2497 s=g_strjoin(" ",s,"|",attr.u.str,NULL);
2502 gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item)
2504 enum item_type *types;
2505 struct selector *sel = param->sel? &selectors[param->selnb]: NULL;
2506 enum item_type type=item->type;
2509 if (type >= type_line && param->filter==NULL)
2511 if (! sel || !sel->types) {
2515 while (*types != type_none) {
2516 if (item->type >= types[0] && item->type <= types[1]) {
2522 if (param->filter) {
2523 char *long_name, *s;
2525 if (param->isAddressFilter) {
2526 s=gui_internal_compose_item_address_string(item);
2527 } else if (item_attr_get(item, attr_label, &attr)) {
2528 s=g_strdup_printf("%s %s", item_to_name(item->type), attr.u.str);
2530 s=g_strdup(item_to_name(item->type));
2532 long_name=removecase(s);
2534 item_attr_rewind(item);
2536 for(s=long_name,f=param->filter;f && s;f=g_list_next(f)) {
2537 s=strstr(s,f->data);
2540 s=g_utf8_strchr(s,-1,' ');
2557 * @brief Event handler for POIs list "more" element.
2559 * @param this The graphics context.
2560 * @param wm called widget.
2561 * @param data event data.
2564 gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
2566 struct widget *w=g_new0(struct widget,1);
2571 gui_internal_back(this, NULL, NULL);
2572 gui_internal_cmd_pois(this, w, w->data);
2577 * @brief apply POIs text filter.
2579 * @param this The graphics context.
2580 * @param wm called widget.
2581 * @param data event data (pointer to editor widget containg filter text).
2584 gui_internal_cmd_pois_filter_do(struct gui_priv *this, struct widget *wm, void *data)
2586 struct widget *w=data;
2587 struct poi_param *param;
2594 param=gui_internal_poi_param_clone(w->data);
2597 param=g_new0(struct poi_param,1);
2599 param->filterstr=removecase(w->text);
2600 param->isAddressFilter=strcmp(wm->name,"AddressFilter")==0;
2601 s1=param->filterstr;
2603 s2=g_utf8_strchr(s1,-1,' ');
2606 param->filter=g_list_append(param->filter,s1);
2614 gui_internal_cmd_pois(this,w,param);
2615 gui_internal_poi_param_free(param);
2619 * @brief POIs filter dialog.
2620 * Event to handle '\r' '\n' keys pressed.
2625 gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, void *data)
2629 len=strlen(wm->text);
2630 dbg(1,"len=%d\n", len);
2631 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2632 wm->text[len-1]='\0';
2633 //gui_internal_cmd_pois_filter_do(this, wm, wm); // Doesnt clean filter editor from the screen. How to disable its redrawal after POI list is drawn?
2640 * @brief POIs filter dialog.
2642 * @param this The graphics context.
2643 * @param wm called widget.
2644 * @param data event data.
2647 gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data)
2649 struct widget *wb, *w, *wr, *wk, *we;
2650 int keyboard_mode=2;
2651 wb=gui_internal_menu(this,"Filter");
2652 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2653 gui_internal_widget_append(wb, w);
2654 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2655 gui_internal_widget_append(w, wr);
2656 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2657 gui_internal_widget_append(wr, we);
2659 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2660 wk->state |= STATE_EDIT|STATE_EDITABLE;
2661 wk->func=gui_internal_cmd_pois_filter_changed;
2662 wk->background=this->background;
2663 wk->flags |= flags_expand|flags_fill;
2664 wk->name=g_strdup("POIsFilter");
2666 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2667 wb->state |= STATE_SENSITIVE;
2668 wb->func = gui_internal_cmd_pois_filter_do;
2669 wb->name=g_strdup("NameFilter");
2671 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "post")));
2672 wb->state |= STATE_SENSITIVE;
2673 wb->name=g_strdup("AddressFilter");
2674 wb->func = gui_internal_cmd_pois_filter_do;
2678 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
2679 gui_internal_menu_render(this);
2685 * @brief Do POI search specified by poi_param and display POIs found
2687 * @param this The graphics context.
2688 * @param wm called widget.
2689 * @param data event data, reference to poi_param or NULL.
2692 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
2694 struct map_selection *sel,*selm;
2695 struct coord c,center;
2696 struct mapset_handle *h;
2698 struct map_rect *mr;
2700 struct widget *wi,*w,*w2,*wb, *wtable, *row;
2701 enum projection pro=wm->c.pro;
2702 struct poi_param *param;
2705 struct selector *isel;
2708 // Starting value and increment of count of items to be extracted
2709 const int pagesize = 50;
2710 int maxitem, it = 0, i;
2711 struct item_data *items;
2712 struct fibheap* fh = fh_makekeyheap();
2714 struct table_data *td;
2721 param = g_new0(struct poi_param,1);
2725 dist=10000*(param->dist+1);
2726 isel = param->sel? &selectors[param->selnb]: NULL;
2727 pagenb = param->pagenb;
2728 prevdist=param->dist*10000;
2729 maxitem = pagesize*(pagenb+1);
2730 items= g_new0( struct item_data, maxitem);
2733 dbg(0, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i, filterstr = %s, isAddressFilter= %d\n",
2734 param->sel, param->selnb, param->pagenb, param->dist, param->filterstr, param->isAddressFilter);
2736 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2737 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2738 gui_internal_widget_append(wb, w);
2739 if (!isel && !param->filter)
2740 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
2741 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2742 gui_internal_widget_append(w, w2);
2744 sel=map_selection_rect_new(&wm->c,dist*transform_scale(abs(wm->c.y)+dist*1.5),18);
2747 h=mapset_open(navit_get_mapset(this->nav));
2748 while ((m=mapset_next(h, 1))) {
2749 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2750 mr=map_rect_new(m, selm);
2751 dbg(2,"mr=%p\n", mr);
2753 while ((item=map_rect_get_item(mr))) {
2754 if (gui_internal_cmd_pois_item_selected(param, item) &&
2755 item_coord_get_pro(item, &c, 1, pro) &&
2756 coord_rect_contains(&sel->u.c_rect, &c) &&
2757 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2758 struct item_data *data;
2762 if (item->type==type_house_number) {
2763 label=gui_internal_compose_item_address_string(item);
2764 } else if (item_attr_get(item, attr_label, &attr)) {
2765 label=g_strdup(attr.u.str);
2766 // Buildings which label is equal to addr:housenumber value
2767 // are duplicated by item_house_number. Don't include such
2768 // buildings into the list. This is true for OSM maps created with
2769 // maptool patched with #859 latest patch.
2770 // FIXME: For non-OSM maps, we probably would better don't skip these items.
2771 if(item->type==type_poly_building && item_attr_get(item, attr_house_number, &attr) ) {
2772 if(strcmp(label,attr.u.str)==0) {
2783 data = fh_extractmin(fh);
2784 g_free(data->label);
2787 data = &items[it++];
2793 // Key expression is a workaround to fight
2794 // probable heap collisions when two objects
2795 // are at the same distance. But it destroys
2796 // right order of POIs 2048 km away from cener
2797 // and if table grows more than 1024 rows.
2798 fh_insertkey(fh, -((idist<<10) + cnt++), data);
2800 dist = (-fh_minkey(fh))>>10;
2803 map_rect_destroy(mr);
2805 map_selection_destroy(selm);
2807 map_selection_destroy(sel);
2810 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
2813 gui_internal_widget_append(w2,wtable);
2815 // Move items from heap to the table
2818 int key = fh_minkey(fh);
2819 struct item_data *data = fh_extractmin(fh);
2822 dbg(2, "Empty heap: maxitem = %i, it = %i, dist = %i\n", maxitem, it, dist);
2825 dbg(2, "dist1: %i, dist2: %i\n", data->dist, (-key)>>10);
2826 if(i==(it-pagesize*pagenb) && data->dist>prevdist)
2827 prevdist=data->dist;
2828 wi=gui_internal_cmd_pois_item(this, ¢er, &data->item, &data->c, data->dist, data->label);
2829 wi->func=gui_internal_cmd_position;
2831 wi->item=data->item;
2832 wi->state |= STATE_SENSITIVE;
2837 wi->background=this->background;
2838 row = gui_internal_widget_table_row_new(this,
2841 | orientation_horizontal);
2842 gui_internal_widget_append(row,wi);
2843 row->datai=data->dist;
2844 gui_internal_widget_prepend(wtable,row);
2851 // Add an entry for more POI
2852 struct widget *wl,*wt;
2854 struct poi_param *paramnew;
2855 row = gui_internal_widget_table_row_new(this,
2858 | orientation_horizontal);
2859 row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
2860 gui_internal_widget_append(wtable,row);
2861 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2862 gui_internal_widget_append(row,wl);
2863 if (it == maxitem) {
2864 paramnew=gui_internal_poi_param_clone(param);
2867 snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (paramnew->pagenb+1)*pagesize);
2868 wt=gui_internal_label_new(this, buffer);
2869 gui_internal_widget_append(wl, wt);
2870 wt->func=gui_internal_cmd_pois_more;
2872 wt->data_free=gui_internal_poi_param_free;
2873 wt->state |= STATE_SENSITIVE;
2876 static int dist[]={1,5,10,0};
2877 wt=gui_internal_label_new(this, "Set distance to");
2878 gui_internal_widget_append(wl, wt);
2879 for(i=0;dist[i];i++) {
2880 paramnew=gui_internal_poi_param_clone(param);
2881 paramnew->dist+=dist[i];
2883 snprintf(buffer, sizeof(buffer), " %i ", 10*(paramnew->dist+1));
2884 wt=gui_internal_label_new(this, buffer);
2885 gui_internal_widget_append(wl, wt);
2886 wt->func=gui_internal_cmd_pois_more;
2888 wt->data_free=gui_internal_poi_param_free;
2889 wt->state |= STATE_SENSITIVE;
2892 wt=gui_internal_label_new(this, "km.");
2893 gui_internal_widget_append(wl, wt);
2896 // Rendering now is needed to have table_data->bottomrow filled in.
2897 gui_internal_menu_render(this);
2899 if(td->bottom_row!=NULL)
2902 while(((struct widget*)td->bottom_row->data)->datai<=prevdist
2903 && (td->next_button->state & STATE_SENSITIVE))
2905 gui_internal_table_button_next(this, td->next_button, NULL);
2908 int firstrow=g_list_index(wtable->children, td->top_row->data);
2909 while(firstrow>=0) {
2910 int currow=g_list_index(wtable->children, td->bottom_row->data) - firstrow;
2912 dbg(0,"Can't find bottom row in children list. Stop paging.\n");
2915 if(currow>=param->count)
2917 if(!(td->next_button->state & STATE_SENSITIVE)) {
2918 dbg(0,"Reached last page but item %i not found. Stop paging.\n",param->count);
2921 gui_internal_table_button_next(this, td->next_button, NULL);
2925 gui_internal_menu_render(this);
2929 #endif /* _MSC_VER */
2932 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2934 if (wm->item.type != type_none) {
2935 enum item_type type;
2936 if (wm->item.type < type_line)
2937 type=type_selected_point;
2938 else if (wm->item.type < type_area)
2939 type=type_selected_point;
2941 type=type_selected_area;
2942 graphics_clear_selection(this->gra, NULL);
2943 graphics_add_selection(this->gra, &wm->item, type, NULL);
2945 navit_set_center(this->nav, &wm->c, 1);
2946 gui_internal_prune_menu(this, NULL);
2951 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2953 struct widget *w,*wb;
2954 struct map_rect *mr;
2960 text=g_strdup_printf("Attribute %s",wm->name);
2961 wb=gui_internal_menu(this, text);
2963 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2964 gui_internal_widget_append(wb, w);
2965 mr=map_rect_new(wm->item.map, NULL);
2966 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2967 for (i = 0 ; i < wm->datai ; i++) {
2968 item_attr_get(item, attr_any, &attr);
2970 if (item_attr_get(item, attr_any, &attr)) {
2972 switch (attr.type) {
2973 case attr_osm_nodeid:
2974 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
2976 case attr_osm_wayid:
2977 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
2979 case attr_osm_relationid:
2980 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
2986 gui_internal_widget_append(w,
2987 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2988 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2989 gui_internal_cmd_view_in_browser, NULL));
2993 map_rect_destroy(mr);
2994 gui_internal_menu_render(this);
2998 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
3000 struct widget *w,*wb;
3001 struct map_rect *mr;
3007 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3008 wb=gui_internal_menu(this, "Attributes");
3009 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3010 gui_internal_widget_append(wb, w);
3011 mr=map_rect_new(wm->item.map, NULL);
3012 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3013 dbg(0,"item=%p\n", item);
3015 while(item_attr_get(item, attr_any, &attr)) {
3016 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
3017 gui_internal_widget_append(w,
3018 wb=gui_internal_button_new_with_callback(this, text,
3019 NULL, gravity_left_center|orientation_horizontal|flags_fill,
3020 gui_internal_cmd_view_attribute_details, NULL));
3021 wb->name=g_strdup(text);
3027 map_rect_destroy(mr);
3028 gui_internal_menu_render(this);
3032 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
3034 struct map_rect *mr;
3040 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3041 mr=map_rect_new(wm->item.map, NULL);
3042 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3043 dbg(0,"item=%p\n", item);
3045 while(item_attr_get(item, attr_url_local, &attr)) {
3047 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
3050 map_rect_destroy(mr);
3052 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
3058 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
3064 // meaning of the bits in "flags":
3066 // 2: "House numbers"
3067 // 4: "View in Browser", "View Attributes"
3068 // 8: "Set as dest."
3069 // 16: "Set as pos."
3070 // 32: "Add as bookm."
3072 // 128: "View on Map"
3073 // 256: POIs around this point
3074 // 512: "Cut/Copy... bookmark"
3075 // TODO define constants for these values
3077 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)
3079 struct widget *wb,*w,*wc,*wbc;
3089 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3090 transform_to_geo(pc.pro, &c, &g);
3093 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
3096 pc.pro=attr.u.projection;
3097 transform_from_geo(pc.pro, &g, &c);
3103 wb=gui_internal_menu(this, name);
3104 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3105 gui_internal_widget_append(wb, w);
3106 coord=coordinates(&pc, ' ');
3107 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
3109 if ((flags & 1) && wm) {
3110 gui_internal_widget_append(w,
3111 wc=gui_internal_button_new_with_callback(this, _("Streets"),
3112 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3113 gui_internal_search_street_in_town, wm));
3115 wc->selection_id=wm->selection_id;
3117 if ((flags & 2) && wm) {
3118 gui_internal_widget_append(w,
3119 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
3120 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3121 gui_internal_search_house_number_in_street, wm));
3123 wc->selection_id=wm->selection_id;
3125 if ((flags & 4) && wm) {
3126 struct map_rect *mr;
3129 mr=map_rect_new(wm->item.map, NULL);
3130 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3132 if (item_attr_get(item, attr_description, &attr))
3133 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
3134 if (item_attr_get(item, attr_url_local, &attr)) {
3135 gui_internal_widget_append(w,
3136 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3137 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3138 gui_internal_cmd_view_in_browser, NULL));
3141 gui_internal_widget_append(w,
3142 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
3143 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3144 gui_internal_cmd_view_attributes, NULL));
3147 map_rect_destroy(mr);
3150 gui_internal_widget_append(w,
3151 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
3152 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3153 gui_internal_cmd_set_destination, g_strdup(name)));
3154 wbc->data_free=g_free_func;
3158 gui_internal_widget_append(w,
3159 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
3160 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3161 gui_internal_cmd_set_position, wm));
3165 gui_internal_widget_append(w,
3166 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
3167 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3168 gui_internal_cmd_add_bookmark2, g_strdup(name)));
3169 wbc->data_free=g_free_func;
3173 //POIs are not operational under MSVC yet
3175 gui_internal_widget_append(w,
3176 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
3177 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3178 gui_internal_cmd_pois, NULL));
3181 #endif /* _MSC_VER */
3183 gui_internal_widget_append(w,
3184 gui_internal_button_new(this, "Add to tour",
3185 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
3188 gui_internal_widget_append(w,
3189 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
3190 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3191 gui_internal_cmd_view_on_map, NULL));
3193 if ((flags & 4) && wm)
3196 wbc->item.type=type_none;
3201 struct mapset_handle *h;
3202 struct map_rect *mr;
3205 struct street_data *data;
3206 struct map_selection sel;
3207 struct transformation *trans;
3208 enum projection pro;
3212 trans=navit_get_trans(this->nav);
3213 pro=transform_get_projection(trans);
3214 transform_from_geo(pro, &g, &c);
3215 ms=navit_get_mapset(this->nav);
3217 sel.u.c_rect.lu.x=c.x-dist;
3218 sel.u.c_rect.lu.y=c.y+dist;
3219 sel.u.c_rect.rl.x=c.x+dist;
3220 sel.u.c_rect.rl.y=c.y-dist;
3222 sel.range=item_range_all;
3224 while ((m=mapset_next(h,1))) {
3225 mr=map_rect_new(m, &sel);
3228 while ((item=map_rect_get_item(mr))) {
3229 data=street_get_data(item);
3230 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
3231 if (item_attr_get(item, attr_label, &attr)) {
3232 label=map_convert_string(m, attr.u.str);
3233 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
3234 map_convert_free(label);
3236 text=g_strdup_printf("%s", item_to_name(item->type));
3237 gui_internal_widget_append(w,
3238 wc=gui_internal_button_new_with_callback(this, text,
3239 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3240 gui_internal_cmd_position, (void *)2));
3241 wc->c.x=data->c[0].x;
3242 wc->c.y=data->c[0].y;
3244 wc->name=g_strdup(text);
3248 street_data_free(data);
3250 map_rect_destroy(mr);
3255 gui_internal_widget_append(w,
3256 wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
3257 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3258 gui_internal_cmd_cut_bookmark, NULL));
3259 wbc->text=g_strdup(wm->text);
3260 gui_internal_widget_append(w,
3261 wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
3262 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3263 gui_internal_cmd_copy_bookmark, NULL));
3264 wbc->text=g_strdup(wm->text);
3265 gui_internal_widget_append(w,
3266 wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
3267 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3268 gui_internal_cmd_rename_bookmark, NULL));
3269 wbc->text=g_strdup(wm->text);
3270 gui_internal_widget_append(w,
3271 wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
3272 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3273 gui_internal_cmd_paste_bookmark, NULL));
3274 gui_internal_widget_append(w,
3275 wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
3276 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3277 gui_internal_cmd_delete_bookmark, NULL));
3278 wbc->text=g_strdup(wm->text);
3280 gui_internal_menu_render(this);
3284 /* wm->data: 0 Nothing special
3292 8 Former destination
3296 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
3299 switch ((long) wm->data) {
3301 flags=8|16|32|64|128|256;
3304 flags=8|16|32|64|256;
3307 flags=4|8|16|32|64|128;
3310 flags=1|8|16|32|64|128;
3311 flags &= this->flags_town;
3314 gui_internal_search_town_in_country(this, wm);
3317 flags=2|8|16|32|64|128;
3318 flags &= this->flags_street;
3321 flags=8|16|32|64|128;
3322 flags &= this->flags_house_number;
3325 flags=8|16|64|128|512;
3328 flags=8|16|32|64|128;
3335 gui_internal_search_house_number_in_street(this, wm, NULL);
3338 gui_internal_cmd_set_destination(this, wm, NULL);
3341 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
3345 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3347 char *name=_("Position");
3353 if (!ATTR_IS_COORD_GEO(in[0]->type))
3355 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3357 if (in[2] && ATTR_IS_INT(in[2]->type))
3360 dbg(1,"flags=0x%x\n",flags);
3361 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
3365 * The "Bookmarks" section of the OSD
3370 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
3372 struct attr attr,mattr;
3374 char *label_full,*prefix=0;
3375 int plen=0,hassub,found=0;
3376 struct widget *wb,*w,*wbm;
3378 struct widget *tbl, *row;
3381 prefix=g_strdup(data);
3383 if (wm && wm->prefix)
3384 prefix=g_strdup(wm->prefix);
3387 plen=strlen(prefix);
3389 gui_internal_prune_menu_count(this, 1, 0);
3390 wb=gui_internal_menu(this, _("Bookmarks"));
3391 wb->background=this->background;
3392 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3393 w->spy=this->spacing*3;
3394 gui_internal_widget_append(wb, w);
3396 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
3398 bookmarks_move_root(mattr.u.bookmarks);
3400 if (!strcmp(prefix,"..")) {
3401 bookmarks_move_up(mattr.u.bookmarks);
3403 prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
3405 plen=strlen(prefix);
3410 bookmarks_move_down(mattr.u.bookmarks,prefix);
3413 // "Back" button, when inside a bookmark folder
3416 wbm=gui_internal_button_new_with_callback(this, "..",
3417 image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3418 gui_internal_cmd_bookmarks, NULL);
3419 wbm->prefix=g_strdup("..");
3420 gui_internal_widget_append(w, wbm);
3424 // Adds the Bookmark folders
3425 wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
3426 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3427 gui_internal_cmd_add_bookmark_folder2, NULL);
3428 gui_internal_widget_append(w, wbm);
3430 // Pastes the Bookmark
3431 wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
3432 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3433 gui_internal_cmd_paste_bookmark, NULL);
3434 gui_internal_widget_append(w, wbm);
3436 bookmarks_item_rewind(mattr.u.bookmarks);
3438 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3439 gui_internal_widget_append(w,tbl);
3441 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
3442 if (!item_attr_get(item, attr_label, &attr)) continue;
3443 label_full=attr.u.str;
3444 dbg(0,"full_labled: %s\n",label_full);
3446 // hassub == 1 if the item type is a sub-folder
3447 if (item->type == type_bookmark_folder) {
3453 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
3454 gui_internal_widget_append(tbl, row);
3455 wbm=gui_internal_button_new_with_callback(this, label_full,
3456 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
3457 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
3459 gui_internal_widget_append(row,wbm);
3460 if (item_coord_get(item, &c, 1)) {
3463 wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
3464 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
3465 wbm->text=g_strdup(label_full);
3467 wbm->data=(void*)7;//Mark us as a bookmark
3469 wbm->prefix=g_strdup(label_full);
3471 gui_internal_widget_destroy(this, row);
3479 gui_internal_check_exit(this);
3481 gui_internal_menu_render(this);
3485 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3488 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
3491 gui_internal_cmd_bookmarks(this, NULL, str);
3496 gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3498 struct widget *wb,*w,*wbm,*tbl=NULL;
3499 struct map *formerdests;
3500 struct map_rect *mr_formerdests;
3504 enum projection projection;
3506 gui_internal_prune_menu_count(this, 1, 0);
3507 wb=gui_internal_menu(this, _("Former Destinations"));
3508 wb->background=this->background;
3510 w=gui_internal_box_new(this,
3511 gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3512 w->spy=this->spacing*2;
3513 gui_internal_widget_append(wb, w);
3515 formerdests=read_former_destinations_from_file();
3516 mr_formerdests=map_rect_new(formerdests, NULL);
3517 projection = map_projection(formerdests);
3518 while ((item=map_rect_get_item(mr_formerdests))) {
3521 if (!item_attr_get(item, attr_label, &attr)) continue;
3523 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand | orientation_vertical,1);
3524 gui_internal_widget_append(w,tbl);
3526 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_vertical);
3527 gui_internal_widget_prepend(tbl, row);
3528 label_full=attr.u.str;
3529 wbm=gui_internal_button_new_with_callback(this, label_full,
3530 image_new_xs(this, "gui_active"),
3531 gravity_left_center|orientation_horizontal|flags_fill,
3532 gui_internal_cmd_position, NULL);
3533 gui_internal_widget_append(row,wbm);
3534 if (item_coord_get(item, &c, 1)) {
3537 wbm->c.pro=projection;
3538 wbm->name=g_strdup(label_full);
3539 wbm->text=g_strdup(label_full);
3540 wbm->data=(void*)8; //Mark us as a former destination
3541 wbm->prefix=g_strdup(label_full);
3545 wbm=gui_internal_text_new(this, _("- No former destinations available -"),
3546 gravity_left_center|orientation_horizontal|flags_fill);
3547 gui_internal_widget_append(w, wbm);
3549 gui_internal_menu_render(this);
3550 map_rect_destroy(mr_formerdests);
3554 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy);
3556 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
3558 struct widget *wi,*menu,*search_list;
3562 menu=g_list_last(this->root.children)->data;
3563 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
3565 /* select first item of the searchlist */
3566 if (*key == NAVIT_KEY_RETURN && (search_list=gui_internal_menu_data(this)->search_list)) {
3567 GList *l=search_list->children;
3569 gui_internal_highlight_do(this, l->data);
3571 } else if (*key == NAVIT_KEY_BACKSPACE) {
3572 dbg(0,"backspace\n");
3573 if (wi->text && wi->text[0]) {
3574 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
3576 text=g_strdup_printf("%s ", wi->text);
3579 if (wi->state & STATE_CLEAR) {
3580 dbg(0,"wi->state=0x%x\n", wi->state);
3583 wi->state &= ~STATE_CLEAR;
3584 dbg(0,"wi->state=0x%x\n", wi->state);
3586 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
3590 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
3591 gui_internal_widget_render(this, wi);
3596 wi->func(this, wi, wi->data);
3598 gui_internal_widget_render(this, wi);
3604 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
3606 struct menu_data *md=gui_internal_menu_data(this);
3607 gui_internal_keypress_do(this, (char *) wm->data);
3608 // Switch to lowercase after the first key is pressed
3609 if (md->keyboard_mode == 2) // Latin
3610 gui_internal_keyboard_do(this, md->keyboard, 10);
3611 if (md->keyboard_mode == 26) // Umlaut
3612 gui_internal_keyboard_do(this, md->keyboard, 34);
3613 if ((md->keyboard_mode & ~7) == 40) // Russian/Ukrainian/Belorussian
3614 gui_internal_keyboard_do(this, md->keyboard, 48);
3618 gui_internal_search_idle_end(struct gui_priv *this)
3621 event_remove_idle(this->idle);
3624 if (this->idle_cb) {
3625 callback_destroy(this->idle_cb);
3631 postal_str(struct search_list_result *res, int level)
3634 if (res->town->common.postal)
3635 ret=res->town->common.postal;
3636 if (res->town->common.postal_mask)
3637 ret=res->town->common.postal_mask;
3640 if (res->street->common.postal)
3641 ret=res->street->common.postal;
3642 if (res->street->common.postal_mask)
3643 ret=res->street->common.postal_mask;
3646 if (res->house_number->common.postal)
3647 ret=res->house_number->common.postal;
3648 if (res->house_number->common.postal_mask)
3649 ret=res->house_number->common.postal_mask;
3654 district_str(struct search_list_result *res, int level)
3657 if (res->town->common.district_name)
3658 ret=res->town->common.district_name;
3661 if (res->street->common.district_name)
3662 ret=res->street->common.district_name;
3665 if (res->house_number->common.district_name)
3666 ret=res->house_number->common.district_name;
3671 town_str(struct search_list_result *res, int level, int flags)
3673 char *town=res->town->common.town_name;
3674 char *district=district_str(res, level);
3675 char *postal=postal_str(res, level);
3676 char *postal_sep=" ";
3677 char *district_begin=" (";
3678 char *district_end=")";
3679 char *county_sep = ", Co. ";
3680 char *county = res->town->common.county_name;
3682 postal_sep=postal="";
3683 if (!district || (flags & 1))
3684 district_begin=district_end=district="";
3686 county_sep=county="";
3688 return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
3692 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3694 static struct widget *partial;
3695 char *text=NULL,*text2=NULL,*name=NULL;
3696 struct search_list_result *res;
3698 struct item *item=NULL;
3700 static char possible_keys[256]="";
3701 struct widget *wi=NULL;
3703 if(!search_list->children) {
3707 res=search_list_get_result(this->sl);
3709 gchar* trunk_name = NULL;
3711 struct widget *menu=g_list_last(this->root.children)->data;
3712 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
3715 if (! strcmp(wm_name,"Town"))
3716 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
3717 if (! strcmp(wm_name,"Street"))
3719 name=res->street->name;
3721 trunk_name = g_strrstr(name, wi->text);
3727 char next_char = trunk_name[strlen(wi->text)];
3729 int len = strlen(possible_keys);
3730 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
3731 if (i==len || !len) {
3732 possible_keys[len]=trunk_name[strlen(wi->text)];
3733 possible_keys[len+1]='\0';
3735 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
3738 dbg(0, "Unable to find widget");
3743 struct menu_data *md;
3744 gui_internal_search_idle_end(this);
3746 md=gui_internal_menu_data(this);
3747 if (md && md->keyboard && !(this->flags & 2048)) {
3748 GList *lk=md->keyboard->children;
3749 graphics_draw_mode(this->gra, draw_mode_begin);
3751 struct widget *child=lk->data;
3752 GList *lk2=child->children;
3754 struct widget *child_=lk2->data;
3755 lk2=g_list_next(lk2);
3756 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
3757 if (strlen(possible_keys) == 0)
3758 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3759 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
3760 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3762 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
3764 gui_internal_widget_render(this,child_);
3769 gui_internal_widget_render(this,md->keyboard);
3770 graphics_draw_mode(this->gra, draw_mode_end);
3773 possible_keys[0]='\0';
3777 if (! strcmp(wm_name,"Country")) {
3778 name=res->country->name;
3779 item=&res->country->common.item;
3780 text=g_strdup_printf("%s", res->country->name);
3782 if (! strcmp(wm_name,"Town")) {
3783 item=&res->town->common.item;
3784 name=res->town->common.town_name;
3785 text=town_str(res, 1, 0);
3787 if (! strcmp(wm_name,"Street")) {
3788 name=res->street->name;
3789 item=&res->street->common.item;
3790 text=g_strdup(res->street->name);
3791 text2=town_str(res, 2, 1);
3793 if (! strcmp(wm_name,"House number")) {
3794 name=res->house_number->house_number;
3795 text=g_strdup_printf("%s %s", res->street->name, name);
3796 text2=town_str(res, 3, 0);
3798 dbg(1,"res->country->flag=%s\n", res->country->flag);
3800 gui_internal_widget_append(search_list,
3801 wc=gui_internal_button_new_with_callback(this, text,
3802 image_new_xs(this, res->country->flag),
3803 gravity_left_center|orientation_horizontal|flags_fill,
3804 gui_internal_cmd_position, param));
3807 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3808 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
3809 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
3810 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
3811 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
3812 gui_internal_widget_append(wc, wb);
3813 wc->func=gui_internal_cmd_position;
3815 wc->state |= STATE_SENSITIVE;
3816 wc->speech=g_strdup(text);
3818 if (! strcmp(wm_name,"House number") && !res->street->name) {
3819 gui_internal_widget_append(search_list, wc);
3825 dbg(0,"search text widget is NULL\n");
3826 if(wi && strlen(name)==strlen(wi->text)) {
3827 dbg(1,"xact %s %s\n",name, wi->text);
3828 gui_internal_widget_prepend(search_list, wc);
3830 dbg(1,"not xact %s %s\n",name, wi->text);
3831 gui_internal_widget_insert_before(search_list, partial, wc);
3836 wc->name=g_strdup(name);
3839 wc->selection_id=res->id;
3842 gui_internal_widget_pack(this, search_list);
3843 l=g_list_last(this->root.children);
3844 graphics_draw_mode(this->gra, draw_mode_begin);
3845 gui_internal_widget_render(this, l->data);
3846 graphics_draw_mode(this->gra, draw_mode_end);
3852 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3854 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
3855 this->idle=event_add_idle(50,this->idle_cb);
3856 callback_call_0(this->idle_cb);
3862 * @param wm The widget that generated the event for the search changed,
3863 * if this was generated by a key on the virtual keyboard then
3864 * wm is the key button widget.
3867 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
3870 struct widget *search_list=gui_internal_menu_data(this)->search_list;
3871 void *param=(void *)3;
3873 gui_internal_widget_children_destroy(this, search_list);
3875 if (! strcmp(wm->name,"Country"))
3877 if (! strcmp(wm->name,"Street"))
3879 if (! strcmp(wm->name,"House number"))
3881 dbg(0,"%s now '%s'\n", wm->name, wm->text);
3883 gui_internal_search_idle_end(this);
3884 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
3885 struct attr search_attr;
3888 if (! strcmp(wm->name,"Country"))
3889 search_attr.type=attr_country_all;
3890 if (! strcmp(wm->name,"Town"))
3891 search_attr.type=attr_town_or_district_name;
3892 if (! strcmp(wm->name,"Street"))
3893 search_attr.type=attr_street_name;
3894 if (! strcmp(wm->name,"House number"))
3895 search_attr.type=attr_house_number;
3896 search_attr.u.str=wm->text;
3897 search_list_search(this->sl, &search_attr, 1);
3898 gui_internal_search_idle_start(this, wm->name, search_list, param);
3900 l=g_list_last(this->root.children);
3901 gui_internal_widget_render(this, l->data);
3904 static struct widget *
3905 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)
3908 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
3909 NULL, gravity_center|orientation_vertical, func, data));
3910 wk->data_free=data_free;
3911 wk->background=this->background;
3921 static struct widget *
3922 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
3924 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
3927 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
3930 // A list of availiable keyboard modes.
3931 struct gui_internal_keyb_mode {
3932 char title[16]; // Label to be displayed on keys that switch to it
3933 int font; // Font size of label
3934 int case_mode; // Mode to switch to when case CHANGE() key is pressed.
3935 int umlaut_mode; // Mode to switch to when UMLAUT() key is pressed.
3936 } gui_internal_keyb_modes[]= {
3937 /* 0*/ {"ABC", 2, 8, 24},
3938 /* 8*/ {"abc", 2, 0, 32},
3939 /*16*/ {"123", 2, 0, 24},
3940 /*24*/ {"ÄÖÜ", 2, 40, 0},
3941 /*32*/ {"äöü", 2, 32, 8},
3942 /*40*/ {"АБВ", 2, 48, 0},
3943 /*48*/ {"абв", 2, 40, 8}
3947 // Some macros that make the keyboard layout easier to visualise in
3948 // the source code. The macros are #undef'd after this function.
3949 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
3950 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
3951 #define MODE(x) gui_internal_keyboard_key_data(this, wkbd, \
3952 gui_internal_keyb_modes[(x)/8].title, \
3953 gui_internal_keyb_modes[(x)/8].font, \
3954 gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h) \
3955 -> datai=(mode&7)+((x)&~7)
3956 #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode)
3957 #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode)
3958 static struct widget *
3959 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
3961 struct widget *wkbd,*wk;
3962 struct menu_data *md=gui_internal_menu_data(this);
3963 int i, max_w=this->root.w, max_h=this->root.h;
3966 char *backspace="←";
3973 gui_internal_highlight(this);
3974 if (md->keyboard_mode >= 1024)
3978 gui_internal_widget_children_destroy(this, wkbdb);
3980 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
3982 md->keyboard_mode=mode;
3983 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
3984 wkbd->background=this->background;
3989 max_h=max_h/8; // Allows 3 results in the list when searching for Towns
3991 if(mode>=40&&mode<56) { // Russian/Ukrainian/Belarussian layout needs more space...
3997 if (mode >= 0 && mode < 8) {
3998 for (i = 0 ; i < 26 ; i++) {
3999 char text[]={'A'+i,'\0'};
4002 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4006 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4007 wk->datai=mode+1024;
4009 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4010 wk->datai=mode+1024;
4016 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4018 if (mode >= 8 && mode < 16) {
4019 for (i = 0 ; i < 26 ; i++) {
4020 char text[]={'a'+i,'\0'};
4023 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4027 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4028 wk->datai=mode+1024;
4030 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4031 wk->datai=mode+1024;
4037 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4039 if (mode >= 16 && mode < 24) {
4040 for (i = 0 ; i < 10 ; i++) {
4041 char text[]={'0'+i,'\0'};
4044 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
4045 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
4050 for (i = 0 ; i < 5 ; i++) SPACER();
4053 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4054 wk->datai=mode+1024;
4056 for (i = 0 ; i < 3 ; i++) SPACER();
4059 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4060 wk->datai=mode+1024;
4065 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4067 if (mode >= 24 && mode < 32) {
4068 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
4069 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
4070 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
4071 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
4075 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4077 if (mode >= 32 && mode < 40) {
4078 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
4079 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
4080 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
4081 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
4085 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4087 if (mode >= 40 && mode < 48) {
4088 KEY("А"); KEY("Б"); KEY("В"); KEY("Г"); KEY("Д"); KEY("Е"); KEY("Ж"); KEY("З"); KEY("И");
4089 KEY("Й"); KEY("К"); KEY("Л"); KEY("М"); KEY("Н"); KEY("О"); KEY("П"); KEY("Р"); KEY("С");
4090 KEY("Т"); KEY("У"); KEY("Ф"); KEY("Х"); KEY("Ц"); KEY("Ч"); KEY("Ш"); KEY("Щ"); KEY("Ъ");
4091 KEY("Ы"); KEY("Ь"); KEY("Э"); KEY("Ю"); KEY("Я"); KEY("Ё"); KEY("І"); KEY("Ї"); KEY("Ў");
4092 SPACER(); SPACER(); SPACER();
4093 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4095 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4096 wk->datai=mode+1024;
4104 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4106 if (mode >= 48 && mode < 56) {
4107 KEY("а"); KEY("б"); KEY("в"); KEY("г"); KEY("д"); KEY("е"); KEY("ж"); KEY("з"); KEY("и");
4108 KEY("й"); KEY("к"); KEY("л"); KEY("м"); KEY("н"); KEY("о"); KEY("п"); KEY("р"); KEY("с");
4109 KEY("т"); KEY("у"); KEY("ф"); KEY("х"); KEY("ц"); KEY("ч"); KEY("ш"); KEY("щ"); KEY("ъ");
4110 KEY("ы"); KEY("ь"); KEY("э"); KEY("ю"); KEY("я"); KEY("ё"); KEY("і"); KEY("ї"); KEY("ў");
4111 SPACER(); SPACER(); SPACER();
4112 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4114 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4115 wk->datai=mode+1024;
4123 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4132 text=gui_internal_keyb_modes[mode/8].title;
4133 font=gui_internal_keyb_modes[mode/8].font;
4134 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
4135 wk->func=gui_internal_keyboard_change;
4137 wk->background=this->background;
4145 wk->state |= STATE_SENSITIVE;
4146 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
4147 wkl->background=NULL;
4148 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
4149 wkl->background=NULL;
4150 gui_internal_widget_append(wkbd, wk);
4154 gui_internal_widget_append(wkbdb, wkbd);
4156 gui_internal_widget_pack(this, wkbdb);
4157 gui_internal_widget_render(this, wkbdb);
4158 } else if (render == 2) {
4159 gui_internal_menu_reset_pack(this);
4160 gui_internal_menu_render(this);
4170 static struct widget *
4171 gui_internal_keyboard(struct gui_priv *this, int mode)
4173 if (! this->keyboard)
4175 return gui_internal_keyboard_do(this, NULL, mode);
4179 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
4181 gui_internal_keyboard_do(this, key->data, key->datai);
4185 gui_internal_search_list_set_default_country(struct gui_priv *this)
4187 struct attr search_attr, country_name, country_iso2, *country_attr;
4189 struct country_search *cs;
4190 struct tracking *tracking;
4191 struct search_list_result *res;
4193 country_attr=country_default();
4194 tracking=navit_get_tracking(this->nav);
4195 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
4196 country_attr=&search_attr;
4198 cs=country_search_new(country_attr, 0);
4199 item=country_search_get_item(cs);
4200 if (item && item_attr_get(item, attr_country_name, &country_name)) {
4201 search_attr.type=attr_country_all;
4202 dbg(0,"country %s\n", country_name.u.str);
4203 search_attr.u.str=country_name.u.str;
4204 search_list_search(this->sl, &search_attr, 0);
4205 while((res=search_list_get_result(this->sl)));
4206 if(this->country_iso2) {
4207 g_free(this->country_iso2);
4208 this->country_iso2=NULL;
4210 if (item_attr_get(item, attr_country_iso2, &country_iso2))
4211 this->country_iso2=g_strdup(country_iso2.u.str);
4213 country_search_destroy(cs);
4215 dbg(0,"warning: no default country found\n");
4216 if (this->country_iso2) {
4217 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
4218 search_attr.type=attr_country_iso2;
4219 search_attr.u.str=this->country_iso2;
4220 search_list_search(this->sl, &search_attr, 0);
4221 while((res=search_list_get_result(this->sl)));
4227 gui_internal_search_list_new(struct gui_priv *this)
4229 struct mapset *ms=navit_get_mapset(this->nav);
4231 this->sl=search_list_new(ms);
4232 gui_internal_search_list_set_default_country(this);
4237 gui_internal_search_list_destroy(struct gui_priv *this)
4240 search_list_destroy(this->sl);
4247 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
4249 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
4251 int keyboard_mode=2;
4252 gui_internal_search_list_new(this);
4253 wb=gui_internal_menu(this, what);
4254 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
4255 gui_internal_widget_append(wb, w);
4256 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4257 gui_internal_widget_append(w, wr);
4258 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4259 gui_internal_widget_append(wr, we);
4260 if (!strcmp(type,"Country")) {
4261 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
4262 wnext->func=gui_internal_search_town;
4263 } else if (!strcmp(type,"Town")) {
4264 if (this->country_iso2) {
4265 #if HAVE_API_ANDROID
4266 char country_iso2[strlen(this->country_iso2)+1];
4267 strtolower(country_iso2, this->country_iso2);
4268 country=g_strdup_printf("country_%s", country_iso2);
4270 country=g_strdup_printf("country_%s", this->country_iso2);
4273 country=g_strdup("gui_select_country");
4274 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
4275 wb->state |= STATE_SENSITIVE;
4277 wb->func = gui_internal_search_country;
4279 wb->func = gui_internal_back;
4280 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
4281 wnext->func=gui_internal_search_street;
4283 } else if (!strcmp(type,"Street")) {
4284 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
4285 wb->state |= STATE_SENSITIVE;
4286 wb->func = gui_internal_back;
4287 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
4288 wnext->func=gui_internal_search_house_number;
4289 } else if (!strcmp(type,"House number")) {
4290 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
4291 wb->state |= STATE_SENSITIVE;
4292 wb->func = gui_internal_back;
4295 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
4297 gui_internal_widget_append(we, wnext);
4298 wnext->state |= STATE_SENSITIVE;
4300 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4301 gui_internal_widget_append(wr, wl);
4302 gui_internal_menu_data(this)->search_list=wl;
4303 wk->state |= STATE_EDIT|STATE_EDITABLE;
4304 wk->background=this->background;
4305 wk->flags |= flags_expand|flags_fill;
4306 wk->func = gui_internal_search_changed;
4307 wk->name=g_strdup(type);
4309 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
4310 gui_internal_menu_render(this);
4314 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
4316 search_list_select(this->sl, attr_street_name, 0, 0);
4317 gui_internal_search(this,_("House number"),"House number",0);
4321 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
4323 dbg(0,"id %d\n", widget->selection_id);
4324 search_list_select(this->sl, attr_street_name, 0, 0);
4325 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
4326 gui_internal_search(this,_("House number"),"House number",0);
4330 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
4332 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
4333 gui_internal_search(this,_("Street"),"Street",0);
4337 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
4339 dbg(0,"id %d\n", widget->selection_id);
4340 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
4341 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
4342 gui_internal_search(this,_("Street"),"Street",0);
4346 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
4349 search_list_select(this->sl, attr_country_all, 0, 0);
4350 g_free(this->country_iso2);
4351 this->country_iso2=NULL;
4352 gui_internal_search(this,_("Town"),"Town",0);
4356 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
4358 struct search_list_common *slc;
4359 dbg(0,"id %d\n", widget->selection_id);
4360 search_list_select(this->sl, attr_country_all, 0, 0);
4361 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
4363 g_free(this->country_iso2);
4364 this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
4366 gui_internal_search(this,widget->name,"Town",0);
4370 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
4372 gui_internal_prune_menu_count(this, 1, 0);
4373 gui_internal_search(this,_("Country"),"Country",0);
4377 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4380 search_list_select(this->sl, attr_country_all, 0, 0);
4381 gui_internal_search(this,_("Town"),"Town",1);
4385 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4388 struct widget *w,*wb,*wl;
4389 struct attr_iter *iter;
4392 wb=gui_internal_menu(this, _("Layout"));
4393 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4394 w->spy=this->spacing*3;
4395 gui_internal_widget_append(wb, w);
4396 iter=navit_attr_iter_new();
4397 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
4398 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
4400 gui_internal_widget_append(w, wl);
4402 navit_attr_iter_destroy(iter);
4403 gui_internal_menu_render(this);
4407 gui_internal_cmd_match_expand(char *pattern, struct attr **in)
4409 char p,*ret=g_strdup(pattern),*r=ret,*a;
4411 while ((p=*pattern++)) {
4415 a=attr_to_text(*in++,NULL,0);
4416 len=strlen(ret)+strlen(a)+strlen(pattern)+1;
4436 gui_internal_match(const char *pattern, const char *string)
4439 while ((p=*pattern++)) {
4442 while ((s=*string)) {
4443 if (gui_internal_match(pattern,string))
4459 gui_internal_set(char *remove, char *add)
4461 char *gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
4462 char *gui_file_new=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal_new.txt", NULL);
4463 FILE *fo=fopen(gui_file_new,"w");
4464 FILE *fi=fopen(gui_file,"r");
4468 while (getline(&line,&size,fi) > 0) {
4469 int len=strlen(line);
4470 if (len > 0 && line[len-1] == '\n')
4472 dbg(0,"line=%s\n",line);
4473 if (!gui_internal_match(remove, line))
4474 fprintf(fo,"%s\n",line);
4478 fprintf(fo,"%s;\n",add);
4481 ret=(rename(gui_file_new, gui_file)==0);
4482 g_free(gui_file_new);
4489 gui_internal_cmd2_set(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4491 char *pattern,*command=NULL;
4492 if (!in || !in[0] || !ATTR_IS_STRING(in[0]->type)) {
4493 dbg(0,"first parameter missing or wrong type\n");
4496 pattern=in[0]->u.str;
4497 dbg(0,"pattern %s\n",pattern);
4499 command=gui_internal_cmd_match_expand(pattern, in+1);
4500 dbg(0,"expand %s\n",command);
4501 gui_internal_set(pattern, command);
4502 command_evaluate(&this->self, command);
4509 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4512 gui_internal_prune_menu(this, NULL);
4513 navit.type=attr_navit;
4514 navit.u.navit=this->nav;
4515 navit_destroy(navit.u.navit);
4516 config_remove_attr(config, &navit);
4517 gui_internal_destroy(this);
4518 event_main_loop_quit();
4522 gui_internal_window_closed(struct gui_priv *this)
4524 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
4528 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4530 navit_set_destination(this->nav, NULL, NULL, 0);
4534 gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data)
4536 char *text=g_strdup_printf(_("Download %s"),wm->name);
4537 struct widget *w, *wb;
4538 struct map *map=data;
4539 double bllon,bllat,trlon,trlat;
4541 wb=gui_internal_menu(this, text);
4543 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4544 w->spy=this->spacing*3;
4545 gui_internal_widget_append(wb, w);
4546 if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
4548 struct map_selection sel;
4549 struct map_rect *mr;
4556 transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
4559 transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
4560 sel.range.min=type_none;
4561 sel.range.max=type_last;
4562 mr=map_rect_new(map, &sel);
4563 while ((item=map_rect_get_item(mr))) {
4566 map_rect_destroy(mr);
4569 dbg(0,"bbox=%s\n",wm->prefix);
4570 gui_internal_menu_render(this);
4574 gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data)
4576 struct attr on, off, download_enabled, download_disabled;
4577 struct widget *w,*wb,*wma;
4578 struct map *map=data;
4580 char *search,buffer[256];
4581 int found,sp_match=0;
4583 dbg(1,"wm=%p prefix=%s\n",wm,wm->prefix);
4588 while(search[sp_match] == ' ')
4594 on.type=off.type=attr_active;
4597 wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
4598 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4599 w->spy=this->spacing*3;
4600 gui_internal_widget_append(wb, w);
4602 wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on, &off, 1);
4603 gui_internal_widget_append(w, wma);
4606 download_enabled.type=download_disabled.type=attr_update;
4607 download_enabled.u.num=1;
4608 download_disabled.u.num=0;
4609 wma=gui_internal_button_map_attr_new(this
4610 , _("Download Enabled")
4611 , gravity_left_center|orientation_horizontal|flags_fill
4614 , &download_disabled
4616 gui_internal_widget_append(w, wma);
4619 f=fopen("maps/areas.tsv","r");
4620 while (f && fgets(buffer, sizeof(buffer), f)) {
4621 char *nl,*description,*description_size,*bbox,*size=NULL;
4623 if ((nl=strchr(buffer,'\n')))
4625 if ((nl=strchr(buffer,'\r')))
4627 while(buffer[sp] == ' ')
4629 if ((bbox=strchr(buffer,'\t')))
4631 if (bbox && (size=strchr(bbox,'\t')))
4633 if (search && !strcmp(buffer, search)) {
4634 wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
4635 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
4636 wma->name=g_strdup(buffer+sp);
4637 wma->prefix=g_strdup(bbox);
4638 gui_internal_widget_append(w, wma);
4640 } else if (sp < sp_match)
4642 if (sp == sp_match && found && buffer[sp]) {
4643 description=g_strdup(buffer+sp);
4645 description_size=g_strdup_printf("%s (%s)",description,size);
4647 description_size=g_strdup(description);
4648 wma=gui_internal_button_new_with_callback(this, description_size, NULL,
4649 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
4650 g_free(description_size);
4651 wma->prefix=g_strdup(buffer);
4652 wma->name=description;
4653 gui_internal_widget_append(w, wma);
4657 gui_internal_menu_render(this);
4661 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4663 struct attr attr, on, off, description, type, data, url, active;
4664 struct widget *w,*wb,*wma;
4666 struct attr_iter *iter;
4668 wb=gui_internal_menu(this, _("Maps"));
4669 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4670 w->spy=this->spacing*3;
4671 gui_internal_widget_append(wb, w);
4672 iter=navit_attr_iter_new();
4673 on.type=off.type=attr_active;
4676 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
4677 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
4678 label=g_strdup(description.u.str);
4680 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
4682 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
4684 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
4686 if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
4687 if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
4689 wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
4690 gravity_left_center|orientation_horizontal|flags_fill,
4691 gui_internal_cmd_map_download, attr.u.map);
4693 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
4694 attr.u.map, &on, &off, 1);
4696 gui_internal_widget_append(w, wma);
4699 navit_attr_iter_destroy(iter);
4700 gui_internal_menu_render(this);
4704 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
4706 struct attr vehicle = {attr_vehicle,{wm->data}};
4707 navit_set_attr(this->nav, &vehicle);
4711 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
4713 struct widget *w,*wb,*row;
4714 struct attr attr,sat_attr;
4715 struct vehicle *v=wm->data;
4718 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
4720 wb=gui_internal_menu(this, _("Show Satellite Status"));
4721 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
4722 gui_internal_menu_data(this)->redisplay_widget=wm;
4723 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4724 gui_internal_widget_append(wb, w);
4725 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
4726 row = gui_internal_widget_table_row_new(this,gravity_left_top);
4727 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
4728 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
4729 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
4730 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
4731 gui_internal_widget_append(w,row);
4732 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
4733 row = gui_internal_widget_table_row_new(this,gravity_left_top);
4734 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
4735 if (item_attr_get(attr.u.item, types[i], &sat_attr))
4736 str=g_strdup_printf("%ld", sat_attr.u.num);
4739 gui_internal_widget_append(row, gui_internal_label_new(this, str));
4742 gui_internal_widget_append(w,row);
4744 gui_internal_widget_append(wb, w);
4745 gui_internal_menu_render(this);
4749 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
4751 struct widget *w,*wb;
4753 struct vehicle *v=wm->data;
4754 wb=gui_internal_menu(this, _("Show NMEA Data"));
4755 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
4756 gui_internal_menu_data(this)->redisplay_widget=wm;
4757 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4758 gui_internal_widget_append(wb, w);
4759 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
4760 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
4761 gui_internal_menu_render(this);
4765 * A container to hold the selected vehicle and the desired profile in
4768 struct vehicle_and_profilename {
4769 struct vehicle *vehicle;
4774 * Figures out whether the given vehicle is the active vehicle.
4776 * @return true if the vehicle is active, false otherwise.
4779 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
4782 struct attr active_vehicle;
4784 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
4785 active_vehicle.u.vehicle=NULL;
4787 return active_vehicle.u.vehicle == vehicle;
4791 save_vehicle_xml(struct vehicle *v)
4794 struct attr_iter *iter=vehicle_attr_iter_new();
4798 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
4799 if (ATTR_IS_OBJECT(attr.type))
4802 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
4806 printf("</vehicle>\n");
4809 vehicle_attr_iter_destroy(iter);
4814 * Reacts to a button press that changes a vehicle's active profile.
4816 * @see gui_internal_add_vehicle_profile
4819 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
4820 widget *wm, void *data)
4822 struct vehicle_and_profilename *vapn = data;
4823 struct vehicle *v = vapn->vehicle;
4824 char *profilename = vapn->profilename;
4825 struct attr vehicle_name_attr;
4826 char *vehicle_name = NULL;
4827 struct attr profilename_attr;
4829 // Get the vehicle name
4830 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
4831 vehicle_name = vehicle_name_attr.u.str;
4833 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
4836 // Change the profile name
4837 profilename_attr.type = attr_profilename;
4838 profilename_attr.u.str = profilename;
4839 if(!vehicle_set_attr(v, &profilename_attr)) {
4840 dbg(0, "Unable to set the vehicle's profile name\n");
4843 // Notify Navit that the routing should be re-done if this is the
4845 if (gui_internal_is_active_vehicle(this, v)) {
4846 struct attr vehicle;
4847 vehicle.type=attr_vehicle;
4848 vehicle.u.vehicle=v;
4849 navit_set_attr(this->nav, &vehicle);
4851 save_vehicle_xml(v);
4855 * Adds the vehicle profile to the GUI, allowing the user to pick a
4856 * profile for the currently selected vehicle.
4859 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
4860 *parent, struct vehicle *v, struct vehicleprofile *profile)
4862 // Just here to show up in the translation file, nice and close to
4863 // where the translations are actually used.
4864 struct attr profile_attr;
4865 struct attr *attr = NULL;
4867 char *active_profile = NULL;
4870 struct vehicle_and_profilename *context = NULL;
4872 #ifdef ONLY_FOR_TRANSLATION
4873 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
4876 // Figure out the profile name
4877 attr = attr_search(profile->attrs, NULL, attr_name);
4879 dbg(0, "Adding vehicle profile failed. attr==NULL");
4884 // Determine whether the profile is the active one
4885 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
4886 active_profile = profile_attr.u.str;
4887 active = active_profile != NULL && !strcmp(name, active_profile);
4889 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
4890 active_profile, active);
4892 // Build a translatable label.
4894 label = g_strdup_printf(_("Current profile: %s"), _(name));
4896 label = g_strdup_printf(_("Change profile to: %s"), _(name));
4899 // Create the context object (the vehicle and the desired profile)
4900 context = g_new0(struct vehicle_and_profilename, 1);
4901 context->vehicle = v;
4902 context->profilename = name;
4905 gui_internal_widget_append(parent,
4906 gui_internal_button_new_with_callback(
4908 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
4909 gravity_left_center|orientation_horizontal|flags_fill,
4910 gui_internal_cmd_set_active_profile, context));
4916 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
4918 struct widget *w,*wb;
4920 struct vehicle *v=wm->data;
4921 struct vehicleprofile *profile = NULL;
4924 wb=gui_internal_menu(this, wm->text);
4925 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4926 gui_internal_widget_append(wb, w);
4928 // Add the "Set as active" button if this isn't the active
4930 if (!gui_internal_is_active_vehicle(this, v)) {
4931 gui_internal_widget_append(w,
4932 gui_internal_button_new_with_callback(this, _("Set as active"),
4933 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4934 gui_internal_cmd_set_active_vehicle, wm->data));
4937 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
4938 gui_internal_widget_append(w,
4939 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
4940 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4941 gui_internal_cmd_show_satellite_status, wm->data));
4943 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
4944 gui_internal_widget_append(w,
4945 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
4946 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4947 gui_internal_cmd_show_nmea_data, wm->data));
4950 // Add all the possible vehicle profiles to the menu
4951 profiles = navit_get_vehicleprofiles(this->nav);
4953 profile = (struct vehicleprofile *)profiles->data;
4954 gui_internal_add_vehicle_profile(this, w, v, profile);
4955 profiles = g_list_next(profiles);
4958 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
4959 gui_internal_menu_render(this);
4963 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4965 struct attr attr,vattr;
4966 struct widget *w,*wb,*wl;
4967 struct attr_iter *iter;
4968 struct attr active_vehicle;
4971 wb=gui_internal_menu(this, _("Vehicle"));
4972 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4973 w->spy=this->spacing*3;
4974 gui_internal_widget_append(wb, w);
4975 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
4976 active_vehicle.u.vehicle=NULL;
4977 iter=navit_attr_iter_new();
4978 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
4979 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
4980 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
4981 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
4982 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
4983 wl->text=g_strdup(vattr.u.str);
4984 gui_internal_widget_append(w, wl);
4986 navit_attr_iter_destroy(iter);
4987 gui_internal_menu_render(this);
4992 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4994 struct widget *wb,*w;
4996 wb=gui_internal_menu(this, _("Rules"));
4997 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4998 w->spy=this->spacing*3;
4999 gui_internal_widget_append(wb, w);
5002 on.type=off.type=attr_tracking;
5003 gui_internal_widget_append(w,
5004 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
5008 on.type=off.type=attr_orientation;
5009 gui_internal_widget_append(w,
5010 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
5014 on.type=off.type=attr_follow_cursor;
5015 gui_internal_widget_append(w,
5016 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
5018 gui_internal_menu_render(this);
5021 //##############################################################################################################
5024 //# Authors: Martin Schaller (04/2008)
5025 //##############################################################################################################
5026 static void gui_internal_motion(void *data, struct point *p)
5029 struct gui_priv *this=data;
5030 if (!this->root.children) {
5031 navit_handle_motion(this->nav, p);
5037 if(!this->motion_timeout_callback)
5038 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
5039 if(!this->motion_timeout_event)
5040 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
5044 find_attr(const char **names, const char **values, const char *name)
5047 if (!g_strcasecmp(*names, name))
5049 names+=xml_attr_distance;
5050 values+=xml_attr_distance;
5056 find_attr_dup(const char **names, const char **values, const char *name)
5058 return g_strdup(find_attr(names, values, name));
5062 gui_internal_evaluate(struct gui_priv *this, const char *command)
5065 command_evaluate(&this->self, command);
5070 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
5072 gui_internal_evaluate(this,w->command);
5076 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
5079 if (w->form == form && w->name) {
5080 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
5082 gui_set_attr(this->self.u.gui, attr);
5088 gui_internal_html_submit_set(this, w, form);
5095 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
5097 struct widget *menu;
5100 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
5101 l=g_list_last(this->root.children);
5103 graphics_draw_mode(this->gra, draw_mode_begin);
5104 gui_internal_highlight_do(this, NULL);
5105 gui_internal_menu_render(this);
5106 graphics_draw_mode(this->gra, draw_mode_end);
5107 gui_internal_html_submit_set(this, menu, w->form);
5108 gui_internal_evaluate(this,w->form->onsubmit);
5112 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
5115 gui_internal_prune_menu_count(this, 1, 0);
5116 if (href && href[0] == '#') {
5117 dbg(1,"href=%s\n",href);
5119 this->href=g_strdup(href);
5120 gui_internal_html_menu(this, this->html_text, href+1);
5125 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
5127 gui_internal_html_load_href(this, w->command, 0);
5130 struct div_flags_map {
5134 } div_flags_map[] = {
5135 {"gravity","none",gravity_none},
5136 {"gravity","left",gravity_left},
5137 {"gravity","xcenter",gravity_xcenter},
5138 {"gravity","right",gravity_right},
5139 {"gravity","top",gravity_top},
5140 {"gravity","ycenter",gravity_ycenter},
5141 {"gravity","bottom",gravity_bottom},
5142 {"gravity","left_top",gravity_left_top},
5143 {"gravity","top_center",gravity_top_center},
5144 {"gravity","right_top",gravity_right_top},
5145 {"gravity","left_center",gravity_left_center},
5146 {"gravity","center",gravity_center},
5147 {"gravity","right_center",gravity_right_center},
5148 {"gravity","left_bottom",gravity_left_bottom},
5149 {"gravity","bottom_center",gravity_bottom_center},
5150 {"gravity","right_bottom",gravity_right_bottom},
5151 {"expand","1",flags_expand},
5152 {"fill","1",flags_fill},
5153 {"orientation","horizontal",orientation_horizontal},
5154 {"orientation","vertical",orientation_vertical},
5155 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
5159 div_flag(const char **names, const char **values, char *name)
5163 const char *value=find_attr(names, values, name);
5166 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
5167 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
5168 ret|=div_flags_map[i].flags;
5174 div_flags(const char **names, const char **values)
5177 flags = div_flag(names, values, "gravity");
5178 flags |= div_flag(names, values, "orientation");
5179 flags |= div_flag(names, values, "expand");
5180 flags |= div_flag(names, values, "fill");
5184 static struct widget *
5185 html_image(struct gui_priv *this, const char **names, const char **values)
5187 const char *src, *size;
5188 struct graphics_image *img=NULL;
5190 src=find_attr(names, values, "src");
5193 size=find_attr(names, values, "size");
5196 if (!strcmp(size,"l"))
5197 img=image_new_l(this, src);
5198 else if (!strcmp(size,"s"))
5199 img=image_new_s(this, src);
5200 else if (!strcmp(size,"xs"))
5201 img=image_new_xs(this, src);
5204 return gui_internal_image_new(this, img);
5208 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
5210 struct gui_priv *this=data;
5212 enum html_tag tag=html_tag_none;
5213 struct html *html=&this->html[this->html_depth];
5214 const char *cond, *type;
5216 if (!g_strcasecmp(tag_name,"text"))
5222 cond=find_attr(names, values, "cond");
5224 if (cond && !this->html_skip) {
5225 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
5229 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
5230 if (!g_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
5231 tag=html_tag_map[i].tag;
5236 if (!this->html_skip && !html->skip) {
5239 html->name=find_attr_dup(names, values, "name");
5241 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
5243 this->html_anchor_found=1;
5245 html->command=find_attr_dup(names, values, "onclick");
5246 html->href=find_attr_dup(names, values, "href");
5247 html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
5250 html->command=find_attr_dup(names, values, "onclick");
5251 html->w=html_image(this, names, values);
5254 this->form=g_new0(struct form, 1);
5255 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
5257 case html_tag_input:
5258 type=find_attr_dup(names, values, "type");
5261 if (!strcmp(type,"image")) {
5262 html->w=html_image(this, names, values);
5264 html->w->state|=STATE_SENSITIVE;
5265 html->w->func=gui_internal_html_submit;
5268 if (!strcmp(type,"text") || !strcmp(type,"password")) {
5269 html->w=gui_internal_label_new(this, NULL);
5270 html->w->background=this->background;
5271 html->w->flags |= div_flags(names, values);
5272 html->w->state|=STATE_EDITABLE;
5273 if (!this->editable) {
5274 this->editable=html->w;
5275 html->w->state|=STATE_EDIT;
5277 this->keyboard_required=1;
5278 if (!strcmp(type,"password"))
5279 html->w->flags2 |= 1;
5282 html->w->form=this->form;
5283 html->w->name=find_attr_dup(names, values, "name");
5287 html->w=gui_internal_box_new(this, div_flags(names, values));
5288 html->container=this->html_container;
5289 this->html_container=html->w;
5295 this->html_skip+=html->skip;
5300 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
5302 struct gui_priv *this=data;
5304 struct html *parent=NULL;
5306 if (!g_strcasecmp(tag_name,"text"))
5309 html=&this->html[this->html_depth];
5310 if (this->html_depth > 0)
5311 parent=&this->html[this->html_depth-1];
5314 if (!this->html_skip) {
5315 if (html->command && html->w) {
5316 html->w->state |= STATE_SENSITIVE;
5317 html->w->command=html->command;
5318 html->w->func=gui_internal_html_command;
5321 if (parent && (parent->href || parent->command) && html->w) {
5322 html->w->state |= STATE_SENSITIVE;
5323 if (parent->command) {
5324 html->w->command=g_strdup(parent->command);
5325 html->w->func=gui_internal_html_command;
5327 html->w->command=g_strdup(parent->href);
5328 html->w->func=gui_internal_html_href;
5331 switch (html->tag) {
5333 this->html_container=html->container;
5335 case html_tag_input:
5336 gui_internal_widget_append(this->html_container, html->w);
5345 this->html_skip-=html->skip;
5346 g_free(html->command);
5349 g_free(html->refresh_cond);
5353 gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data)
5355 if (gui_internal_menu_data(this) == menu_data) {
5356 char *href=g_strdup(menu_data->href);
5357 gui_internal_html_load_href(this, href, 1);
5363 gui_internal_set_refresh_callback(struct gui_priv *this, char *cond)
5365 dbg(0,"cond=%s\n",cond);
5367 enum attr_type type;
5368 struct object_func *func;
5369 struct menu_data *menu_data=gui_internal_menu_data(this);
5370 dbg(0,"navit=%p\n",this->nav);
5371 type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
5372 if (type == attr_none)
5374 func=object_func_lookup(menu_data->refresh_callback_obj.type);
5375 if (!func || !func->add_attr)
5377 menu_data->refresh_callback.type=attr_callback;
5378 menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,this,menu_data);
5379 func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
5384 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
5386 struct gui_priv *this=data;
5388 int depth=this->html_depth-1;
5389 struct html *html=&this->html[depth];
5390 gchar *text_stripped;
5392 if (this->html_skip)
5394 while (isspace(text[0])) {
5398 while (len > 0 && isspace(text[len-1]))
5401 text_stripped = g_strndup(text, len);
5402 if (html->tag == html_tag_html && depth > 2) {
5403 if (this->html[depth-1].tag == html_tag_script) {
5404 html=&this->html[depth-2];
5407 switch (html->tag) {
5409 if (html->name && len) {
5410 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
5411 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
5412 gui_internal_menu_data(this)->href=g_strdup(this->href);
5413 gui_internal_set_refresh_callback(this, html->refresh_cond);
5414 this->html_container->spx=this->spacing*10;
5418 if (!this->html_container) {
5419 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
5420 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
5421 this->html_container->spx=this->spacing*10;
5426 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
5427 gui_internal_widget_append(w, html->w);
5428 gui_internal_widget_append(w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
5434 gui_internal_widget_append(html->w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
5437 case html_tag_script:
5438 dbg(1,"execute %s\n",text_stripped);
5439 gui_internal_evaluate(this,text_stripped);
5444 g_free(text_stripped);
5448 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
5450 char *doc=g_strdup(document);
5451 graphics_draw_mode(this->gra, draw_mode_begin);
5452 this->html_container=NULL;
5454 this->html_anchor=anchor;
5455 this->html_anchor_found=0;
5457 this->keyboard_required=0;
5458 this->editable=NULL;
5459 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
5460 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
5462 if (this->keyboard_required && this->keyboard) {
5463 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
5464 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
5466 gui_internal_menu_render(this);
5467 graphics_draw_mode(this->gra, draw_mode_end);
5472 gui_internal_enter(struct gui_priv *this, int ignore)
5474 struct graphics *gra=this->gra;
5475 this->ignore_button=ignore;
5476 this->clickp_valid=this->vehicle_valid=0;
5478 navit_block(this->nav, 1);
5479 graphics_overlay_disable(gra, 1);
5482 this->root.background=this->background;
5486 gui_internal_leave(struct gui_priv *this)
5488 graphics_draw_mode(this->gra, draw_mode_end);
5492 gui_internal_enter_setup(struct gui_priv *this, struct point *p)
5494 struct transformation *trans;
5497 struct attr attr,attrp;
5499 trans=navit_get_trans(this->nav);
5500 attr_free(this->click_coord_geo);
5501 this->click_coord_geo=NULL;
5502 attr_free(this->position_coord_geo);
5503 this->position_coord_geo=NULL;
5505 transform_reverse(trans, p, &c);
5506 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
5507 this->clickp.pro=transform_get_projection(trans);
5510 transform_to_geo(this->clickp.pro, &c, &g);
5511 attr.u.coord_geo=&g;
5512 attr.type=attr_click_coord_geo;
5513 this->click_coord_geo=attr_dup(&attr);
5515 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
5516 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
5517 this->position_coord_geo=attr_dup(&attrp);
5518 this->vehiclep.pro=transform_get_projection(trans);
5519 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
5520 this->vehiclep.x=c.x;
5521 this->vehiclep.y=c.y;
5522 this->vehicle_valid=1;
5527 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore, char *href)
5530 gui_internal_enter(this, ignore);
5531 gui_internal_enter_setup(this, p);
5533 gui_internal_html_load_href(this, href?href:"#Main Menu", 0);
5537 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5541 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
5543 if (in[1] && ATTR_IS_INT(in[1]->type))
5544 replace=in[1]->u.num;
5546 if (this->root.children) {
5549 gui_internal_html_load_href(this, href, replace);
5552 gui_internal_cmd_menu(this, NULL, 0, href);
5557 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
5559 if (widget->text && strlen(widget->text)) {
5560 if (this->vehicle_valid)
5561 navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
5563 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
5565 g_free(widget->text);
5567 gui_internal_prune_menu(this, NULL);
5568 gui_internal_check_exit(this);
5572 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
5574 gui_internal_cmd_log_do(this, widget->data);
5578 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
5582 len=strlen(wm->text);
5583 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
5584 wm->text[len-1]='\0';
5585 gui_internal_cmd_log_do(this, wm);
5592 gui_internal_cmd_log(struct gui_priv *this)
5594 struct widget *w,*wb,*wk,*wl,*we,*wnext;
5595 gui_internal_enter(this, 1);
5596 gui_internal_enter_setup(this, NULL);
5597 wb=gui_internal_menu(this, "Log Message");
5598 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5599 gui_internal_widget_append(wb, w);
5600 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
5601 gui_internal_widget_append(w, we);
5602 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
5603 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
5604 wk->background=this->background;
5605 wk->flags |= flags_expand|flags_fill;
5606 wk->func = gui_internal_cmd_log_changed;
5607 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
5608 wnext->state |= STATE_SENSITIVE;
5609 wnext->func = gui_internal_cmd_log_clicked;
5611 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5612 gui_internal_widget_append(w, wl);
5614 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
5615 gui_internal_menu_render(this);
5616 gui_internal_leave(this);
5620 gui_internal_check_exit(struct gui_priv *this)
5622 struct graphics *gra=this->gra;
5623 if (! this->root.children) {
5624 gui_internal_search_idle_end(this);
5625 gui_internal_search_list_destroy(this);
5626 graphics_overlay_disable(gra, 0);
5627 if (!navit_block(this->nav, 0)) {
5629 navit_draw(this->nav);
5631 navit_draw_displaylist(this->nav);
5637 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
5641 attr->u.num=this->root.children != NULL;
5643 case attr_click_coord_geo:
5644 if (!this->click_coord_geo)
5646 *attr=*this->click_coord_geo;
5648 case attr_position_coord_geo:
5649 if (!this->position_coord_geo)
5651 *attr=*this->position_coord_geo;
5654 attr->u.num=this->pitch;
5664 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
5666 switch (attr->type) {
5668 g_free(this->html_text);
5669 this->html_text=g_strdup(attr->u.str);
5677 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
5679 switch (attr->type) {
5680 case attr_fullscreen:
5681 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
5682 graphics_draw_mode(this->gra, draw_mode_end);
5683 this->win->fullscreen(this->win, attr->u.num > 0);
5684 graphics_draw_mode(this->gra, draw_mode_begin);
5686 this->fullscreen=attr->u.num;
5688 case attr_menu_on_map_click:
5689 this->menu_on_map_click=attr->u.num;
5692 dbg(0,"%s\n",attr_to_name(attr->type));
5697 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
5699 struct displaylist_handle *dlh;
5700 struct displaylist *display;
5701 struct displayitem *di;
5702 struct attr cb,**attr_list=NULL;
5705 display=navit_get_displaylist(this->nav);
5706 dlh=graphics_displaylist_open(display);
5707 while ((di=graphics_displaylist_next(dlh))) {
5708 struct item *item=graphics_displayitem_get_item(di);
5709 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
5710 graphics_displayitem_within_dist(display, di, p, this->radius)) {
5711 struct map_rect *mr=map_rect_new(item->map, NULL);
5712 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
5714 if (itemo && item_attr_get(itemo, attr_data, &attr))
5715 attr_list=attr_generic_add_attr(attr_list, &attr);
5716 map_rect_destroy(mr);
5719 graphics_displaylist_close(dlh);
5720 if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
5721 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
5722 attr_list_free(attr_list);
5726 //##############################################################################################################
5727 //# Description: Function to handle mouse clicks and scroll wheel movement
5729 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
5730 //##############################################################################################################
5731 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
5733 struct gui_priv *this=data;
5734 struct graphics *gra=this->gra;
5736 dbg(1,"enter %d %d\n", pressed, button);
5737 // if still on the map (not in the menu, yet):
5738 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
5739 if (!this->root.children || this->ignore_button) {
5741 this->ignore_button=0;
5742 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
5743 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
5744 dbg(1,"navit has handled button\n");
5747 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
5750 if (this->menu_on_map_click) {
5751 gui_internal_cmd_menu(this, p, 0, NULL);
5754 if (this->signal_on_map_click) {
5755 gui_internal_dbus_signal(this, p);
5762 // if already in the menu:
5766 gui_internal_highlight(this);
5771 graphics_draw_mode(gra, draw_mode_begin);
5772 gui_internal_call_highlighted(this);
5773 if (!event_main_loop_has_quit()) {
5774 gui_internal_highlight(this);
5775 graphics_draw_mode(gra, draw_mode_end);
5776 gui_internal_check_exit(this);
5782 gui_internal_setup(struct gui_priv *this)
5784 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
5785 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
5786 struct graphics *gra=this->gra;
5787 unsigned char *buffer;
5791 if (this->background)
5793 this->background=graphics_gc_new(gra);
5794 this->background2=graphics_gc_new(gra);
5795 this->highlight_background=graphics_gc_new(gra);
5796 graphics_gc_set_foreground(this->highlight_background, &cbh);
5797 this->foreground=graphics_gc_new(gra);
5798 graphics_gc_set_foreground(this->foreground, &cf);
5799 this->text_background=graphics_gc_new(gra);
5800 this->text_foreground=graphics_gc_new(gra);
5801 graphics_gc_set_foreground(this->background, &this->background_color);
5802 graphics_gc_set_foreground(this->background2, &this->background2_color);
5803 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
5804 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
5805 gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
5806 if (file_get_contents(gui_file,&buffer,&size)) {
5807 char *command=g_malloc(size+1);
5808 strncpy(command,(const char *)buffer,size);
5810 command_evaluate(&this->self, command);
5817 //##############################################################################################################
5820 //# Authors: Martin Schaller (04/2008)
5821 //##############################################################################################################
5822 static void gui_internal_resize(void *data, int w, int h)
5824 struct gui_priv *this=data;
5827 gui_internal_setup(this);
5829 if (this->root.w != w || this->root.h != h) {
5834 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
5835 navit_handle_resize(this->nav, w, h);
5836 if (this->root.children) {
5838 gui_internal_prune_menu(this, NULL);
5839 gui_internal_html_load_href(this, "#Main Menu", 0);
5841 gui_internal_menu_render(this);
5847 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
5862 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
5864 GList *l=wi->children;
5865 // Skip hidden elements
5866 if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
5868 if ((wi->state & STATE_SENSITIVE) ) {
5871 gui_internal_keynav_point(wi, -dx, -dy, &wp);
5873 dist1=(wp.x-p->x)*dx;
5876 dist1=(wp.y-p->y)*dy;
5884 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);
5890 if (dist1 < *distance) {
5897 struct widget *child=l->data;
5898 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
5904 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
5906 struct widget *result,*menu=g_list_last(this->root.children)->data;
5909 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
5910 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
5916 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
5918 gui_internal_keynav_point(result, dx, dy, &p);
5919 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
5924 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
5925 dbg(1,"result=%p\n", result);
5937 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
5938 dbg(1,"wraparound result=%p\n", result);
5940 gui_internal_highlight_do(this, result);
5942 gui_internal_say(this, result, 1);
5945 //##############################################################################################################
5948 //# Authors: Martin Schaller (04/2008)
5949 //##############################################################################################################
5950 static void gui_internal_keypress(void *data, char *key)
5952 struct gui_priv *this=data;
5955 if (!this->root.children) {
5956 transform_get_size(navit_get_trans(this->nav), &w, &h);
5961 navit_set_center_screen(this->nav, &p, 1);
5963 case NAVIT_KEY_DOWN:
5966 navit_set_center_screen(this->nav, &p, 1);
5968 case NAVIT_KEY_LEFT:
5971 navit_set_center_screen(this->nav, &p, 1);
5973 case NAVIT_KEY_RIGHT:
5976 navit_set_center_screen(this->nav, &p, 1);
5978 case NAVIT_KEY_ZOOM_IN:
5979 navit_zoom_in(this->nav, 2, NULL);
5981 case NAVIT_KEY_ZOOM_OUT:
5982 navit_zoom_out(this->nav, 2, NULL);
5984 case NAVIT_KEY_RETURN:
5985 case NAVIT_KEY_MENU:
5986 gui_internal_cmd_menu(this, NULL, 0, NULL);
5991 graphics_draw_mode(this->gra, draw_mode_begin);
5993 case NAVIT_KEY_LEFT:
5994 gui_internal_keynav_highlight_next(this,-1,0);
5996 case NAVIT_KEY_RIGHT:
5997 gui_internal_keynav_highlight_next(this,1,0);
6000 gui_internal_keynav_highlight_next(this,0,-1);
6002 case NAVIT_KEY_DOWN:
6003 gui_internal_keynav_highlight_next(this,0,1);
6005 case NAVIT_KEY_BACK:
6006 if (g_list_length(this->root.children) > 1)
6007 gui_internal_back(this, NULL, NULL);
6009 gui_internal_prune_menu(this, NULL);
6011 case NAVIT_KEY_RETURN:
6012 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6013 gui_internal_call_highlighted(this);
6015 gui_internal_keypress_do(this, key);
6018 gui_internal_keypress_do(this, key);
6020 if (!event_main_loop_has_quit()) {
6021 graphics_draw_mode(this->gra, draw_mode_end);
6022 gui_internal_check_exit(this);
6027 //##############################################################################################################
6030 //# Authors: Martin Schaller (04/2008)
6031 //##############################################################################################################
6032 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
6035 struct transformation *trans=navit_get_trans(this->nav);
6037 win=graphics_get_data(gra, "window");
6040 navit_ignore_graphics_events(this->nav, 1);
6043 navit_ignore_graphics_events(this->nav, 1);
6044 transform_get_size(trans, &this->root.w, &this->root.h);
6045 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
6046 graphics_add_callback(gra, this->resize_cb);
6047 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
6048 graphics_add_callback(gra, this->button_cb);
6049 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
6050 graphics_add_callback(gra, this->motion_cb);
6051 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
6052 graphics_add_callback(gra, this->keypress_cb);
6053 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
6054 graphics_add_callback(gra, this->window_closed_cb);
6056 // set fullscreen if needed
6057 if (this->fullscreen)
6058 this->win->fullscreen(this->win, this->fullscreen != 0);
6059 /* Was resize callback already issued? */
6060 if (navit_get_ready(this->nav) & 2)
6061 gui_internal_setup(this);
6065 static void gui_internal_disable_suspend(struct gui_priv *this)
6067 if (this->win->disable_suspend)
6068 this->win->disable_suspend(this->win);
6071 //##############################################################################################################
6074 //# Authors: Martin Schaller (04/2008)
6075 //##############################################################################################################
6076 struct gui_methods gui_internal_methods = {
6079 gui_internal_set_graphics,
6083 gui_internal_disable_suspend,
6084 gui_internal_get_attr,
6085 gui_internal_add_attr,
6086 gui_internal_set_attr,
6090 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
6092 struct attr private_data = { attr_private_data, {(void *)&priv->data}};
6094 *out=attr_generic_add_attr(*out, &private_data);
6098 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
6100 callback_list_add(priv->cbl, cb);
6104 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
6106 callback_list_remove(priv->cbl, cb);
6110 static struct gui_internal_methods gui_internal_methods_ext = {
6111 gui_internal_add_callback,
6112 gui_internal_remove_callback,
6113 gui_internal_menu_render,
6120 gui_internal_get_flags(struct widget *widget)
6122 return widget->flags;
6126 gui_internal_set_flags(struct widget *widget, enum flags flags)
6128 widget->flags=flags;
6132 gui_internal_get_state(struct widget *widget)
6134 return widget->state;
6138 gui_internal_set_state(struct widget *widget, int state)
6140 widget->state=state;
6144 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
6150 gui_internal_set_data(struct widget *widget, void *data)
6156 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
6158 widget->background=this->background;
6161 static struct gui_internal_widget_methods gui_internal_widget_methods = {
6162 gui_internal_widget_append,
6163 gui_internal_button_new,
6164 gui_internal_button_new_with_callback,
6165 gui_internal_box_new,
6166 gui_internal_label_new,
6167 gui_internal_image_new,
6168 gui_internal_keyboard,
6170 gui_internal_get_flags,
6171 gui_internal_set_flags,
6172 gui_internal_get_state,
6173 gui_internal_set_state,
6174 gui_internal_set_func,
6175 gui_internal_set_data,
6176 gui_internal_set_default_background,
6180 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
6182 char *str=NULL,*str2=NULL;
6183 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
6186 dbg(1,"%s\n",attr_to_name(in[0]->type));
6187 if (ATTR_IS_STRING(in[0]->type)) {
6190 if (ATTR_IS_COORD_GEO(in[0]->type)) {
6191 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
6194 str=g_strdup_printf("<html>%s</html>\n",str);
6195 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
6203 * @brief Creates a new table widget.
6205 * Creates and returns a new table widget. This function will
6206 * setup next/previous buttons as children.
6208 * @param this The graphics context.
6209 * @param flags widget sizing flags.
6210 * @returns The newly created widget
6212 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
6214 struct widget * widget = g_new0(struct widget,1);
6215 struct table_data * data = NULL;
6216 widget->type=widget_table;
6217 widget->flags=flags;
6218 widget->data = g_new0(struct table_data,1);
6219 widget->data_free=gui_internal_table_data_free;
6221 // We have to set background here explicitly
6222 // because it will be used by inner elements created later in this
6223 // function (navigation buttons). Else that elements won't have
6225 widget->background=this->background;
6226 data = (struct table_data*)widget->data;
6229 data->next_button = gui_internal_button_new_with_callback
6230 (this, _("Next"),image_new_xs(this, "gui_arrow_right") ,
6231 gravity_center |orientation_vertical,
6232 gui_internal_table_button_next,NULL);
6233 data->next_button->data=widget;
6236 data->prev_button = gui_internal_button_new_with_callback
6238 image_new_xs(this, "gui_arrow_left")
6239 ,gravity_center |orientation_vertical,
6240 gui_internal_table_button_prev,NULL);
6242 data->prev_button->data=widget;
6246 data->button_box=gui_internal_box_new(this,
6247 gravity_center|orientation_horizontal);
6248 gui_internal_widget_append(widget, data->button_box);
6249 gui_internal_widget_append(data->button_box, data->prev_button);
6250 gui_internal_widget_append(data->button_box, data->next_button);
6252 data->button_box->bl=this->spacing;
6253 gui_internal_widget_pack(this,data->button_box);
6261 * @brief Clears all the rows from the table.
6262 * This function removes all rows from a table.
6263 * New rows can later be added to the table.
6265 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
6268 struct table_data * table_data = (struct table_data* ) table->data;
6270 iter = table->children;
6272 if(iter->data != table_data->button_box) {
6273 struct widget * child = (struct widget*)iter->data;
6274 gui_internal_widget_destroy(this,child);
6275 if(table->children == iter) {
6276 table->children = g_list_remove(iter,iter->data);
6277 iter=table->children;
6280 iter = g_list_remove(iter,iter->data);
6283 iter = g_list_next(iter);
6287 table_data->top_row=NULL;
6288 table_data->bottom_row=NULL;
6289 if(table_data->page_headers)
6290 g_list_free(table_data->page_headers);
6291 table_data->page_headers=NULL;
6296 * Creates a new table_row widget.
6297 * @param this The graphics context
6298 * @param flags Sizing flags for the row
6299 * @returns The new table_row widget.
6301 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
6303 struct widget * widget = g_new0(struct widget,1);
6304 widget->type=widget_table_row;
6305 widget->flags=flags;
6312 * @brief Computes the column dimensions for the table.
6314 * @param w The table widget to compute dimensions for.
6316 * This function examines all of the rows and columns for the table w
6317 * and returns a list (GList) of table_column_desc elements that
6318 * describe each column of the table.
6320 * The caller is responsible for freeing the returned list.
6322 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
6325 GList * column_desc = NULL;
6326 GList * current_desc=NULL;
6327 GList * cur_row = w->children;
6328 struct widget * cur_row_widget=NULL;
6329 GList * cur_column=NULL;
6330 struct widget * cell_w=NULL;
6331 struct table_column_desc * current_cell=NULL;
6332 struct table_data * table_data=NULL;
6339 * Scroll through the the table and
6340 * 1. Compute the maximum width + height of each column across all rows.
6342 table_data = (struct table_data*) w->data;
6343 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
6345 cur_row_widget = (struct widget*) cur_row->data;
6346 current_desc = column_desc;
6347 if(cur_row_widget == table_data->button_box)
6352 for(cur_column = cur_row_widget->children; cur_column;
6353 cur_column=g_list_next(cur_column))
6355 cell_w = (struct widget*) cur_column->data;
6356 gui_internal_widget_pack(this,cell_w);
6357 if(current_desc == 0)
6359 current_cell = g_new0(struct table_column_desc,1);
6360 column_desc = g_list_append(column_desc,current_cell);
6361 current_desc = g_list_last(column_desc);
6362 current_cell->height=cell_w->h;
6363 current_cell->width=cell_w->w;
6364 total_width+=cell_w->w;
6369 current_cell = current_desc->data;
6372 if(current_cell->height < height )
6374 current_cell->height = height;
6376 if(current_cell->width < width)
6378 total_width += (width-current_cell->width);
6379 current_cell->width = width;
6384 current_desc = g_list_next(current_desc);
6394 * If the width of all columns is less than the width off
6395 * the table expand each cell proportionally.
6398 if(total_width+(this->spacing*column_count) < w->w ) {
6399 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
6400 current_cell = (struct table_column_desc*) current_desc->data;
6401 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
6410 * @brief Computes the height and width for the table.
6412 * The height and widht are computed to display all cells in the table
6413 * at the requested height/width.
6415 * @param this The graphics context
6416 * @param w The widget to pack.
6419 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
6425 GList * column_data = gui_internal_compute_table_dimensions(this,w);
6427 struct table_column_desc * cell_desc=0;
6428 struct table_data * table_data = (struct table_data*)w->data;
6430 for(current = column_data; current; current=g_list_next(current))
6432 if(table_data->button_box == current->data )
6436 cell_desc = (struct table_column_desc *) current->data;
6437 width = width + cell_desc->width + this->spacing;
6438 if(height < cell_desc->height)
6440 height = cell_desc->height ;
6446 for(current=w->children; current; current=g_list_next(current))
6448 if(current->data!= table_data->button_box)
6455 if(w->w + w->c.x > this->root.w)
6457 w->w = this->root.w - w->c.x;
6461 if(w->h + w->c.y > this->root.h )
6464 * Do not allow the widget to exceed the screen.
6467 w->h = this->root.h- w->c.y - height;
6470 if (table_data->button_box)
6472 gui_internal_widget_pack(this,table_data->button_box);
6477 * Deallocate column descriptions.
6479 current = column_data;
6480 while( (current = g_list_last(current)) )
6482 current = g_list_remove(current,current->data);
6488 * @brief Invalidates coordinates for previosly rendered table widget rows.
6490 * @param table_data Data from the table object.
6492 void gui_internal_table_hide_rows(struct table_data * table_data)
6495 for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row))
6497 struct widget * cur_row_widget = (struct widget*)cur_row->data;
6498 if (cur_row_widget->type!=widget_table_row)
6500 cur_row_widget->p.x=0;
6501 cur_row_widget->p.y=0;
6502 cur_row_widget->w=0;
6503 cur_row_widget->h=0;
6504 if(cur_row==table_data->bottom_row)
6510 * @brief Renders a table widget.
6512 * @param this The graphics context
6513 * @param w The table widget to render.
6515 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
6520 GList * column_desc=NULL;
6521 GList * cur_row = NULL;
6522 GList * current_desc=NULL;
6523 struct table_data * table_data = (struct table_data*)w->data;
6525 int is_first_page=1;
6526 struct table_column_desc * dim=NULL;
6528 dbg_assert(table_data);
6529 column_desc = gui_internal_compute_table_dimensions(this,w);
6531 gui_internal_table_hide_rows(table_data);
6533 * Skip rows that are on previous pages.
6535 cur_row = w->children;
6536 if(table_data->top_row && table_data->top_row != w->children )
6538 cur_row = table_data->top_row;
6542 * Loop through each row. Drawing each cell with the proper sizes,
6543 * at the proper positions.
6545 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
6548 struct widget * cur_row_widget;
6549 GList * cur_column=NULL;
6550 current_desc = column_desc;
6551 cur_row_widget = (struct widget*)cur_row->data;
6552 x =w->p.x+this->spacing;
6553 if(cur_row_widget == table_data->button_box )
6557 dim = (struct table_column_desc*)current_desc->data;
6559 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
6562 * No more drawing space left.
6567 for(cur_column = cur_row_widget->children; cur_column;
6568 cur_column=g_list_next(cur_column))
6570 struct widget * cur_widget = (struct widget*) cur_column->data;
6571 dim = (struct table_column_desc*)current_desc->data;
6574 cur_widget->w=dim->width;
6576 cur_widget->h=dim->height;
6578 max_height = dim->height;
6579 /* We pack the widget before rendering to ensure that the x and y
6580 * coordinates get pushed down.
6582 gui_internal_widget_pack(this,cur_widget);
6583 gui_internal_widget_render(this,cur_widget);
6585 if(dim->height > max_height)
6587 max_height = dim->height;
6591 /* Row object should have its coordinates in actual
6592 * state to be able to pass mouse clicks to Column objects
6594 cur_row_widget->p.x=w->p.x;
6595 cur_row_widget->w=w->w;
6596 cur_row_widget->p.y=y;
6597 cur_row_widget->h=max_height;
6599 table_data->bottom_row=cur_row;
6600 current_desc = g_list_next(current_desc);
6602 if(table_data->button_box && (is_skipped || !is_first_page) )
6604 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
6606 if(table_data->button_box->p.y < y )
6608 table_data->button_box->p.y=y;
6610 table_data->button_box->p.x = w->p.x;
6611 table_data->button_box->w = w->w;
6612 // table_data->button_box->h = w->h - y;
6613 // table_data->next_button->h=table_data->button_box->h;
6614 // table_data->prev_button->h=table_data->button_box->h;
6615 // table_data->next_button->c.y=table_data->button_box->c.y;
6616 // table_data->prev_button->c.y=table_data->button_box->c.y;
6617 gui_internal_widget_pack(this,table_data->button_box);
6618 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
6620 table_data->button_box->p.y = w->p.y + w->h -
6621 table_data->button_box->h;
6625 table_data->next_button->state|= STATE_SENSITIVE;
6629 table_data->next_button->state&= ~STATE_SENSITIVE;
6632 if(table_data->top_row != w->children)
6634 table_data->prev_button->state|= STATE_SENSITIVE;
6638 table_data->prev_button->state&= ~STATE_SENSITIVE;
6640 gui_internal_widget_render(this,table_data->button_box);
6644 * Deallocate column descriptions.
6646 current_desc = column_desc;
6647 while( (current_desc = g_list_last(current_desc)) )
6649 current_desc = g_list_remove(current_desc,current_desc->data);
6655 * @brief Displays Route information
6657 * @li The name of the active vehicle
6658 * @param wm The button that was pressed.
6662 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6666 struct widget * menu;
6667 struct widget * row;
6668 struct widget * box;
6671 if(! this->vehicle_cb)
6674 * Register the callback on vehicle updates.
6676 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
6677 attr_position_coord_geo,this);
6678 navit_add_callback(this->nav,this->vehicle_cb);
6681 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
6682 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
6684 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
6687 menu=gui_internal_menu(this,_("Route Description"));
6689 menu->free=gui_internal_route_screen_free;
6690 this->route_data.route_showing=1;
6691 this->route_data.route_table->spx = this->spacing;
6694 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
6696 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
6697 gui_internal_widget_append(box,this->route_data.route_table);
6699 box->spx = this->spacing;
6700 this->route_data.route_table->w=box->w;
6701 gui_internal_widget_append(menu,box);
6702 gui_internal_populate_route_table(this,this->nav);
6703 gui_internal_menu_render(this);
6708 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
6711 int adx=a2->x-a1->x;
6712 int ady=a2->y-a1->y;
6713 int bdx=b2->x-b1->x;
6714 int bdy=b2->y-b1->y;
6715 n = bdy * adx - bdx * ady;
6716 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
6717 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
6728 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
6729 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
6730 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
6733 res->x = a1->x + a * adx / n;
6734 res->y = a1->y + a * ady / n;
6739 struct heightline *next;
6741 struct coord_rect bbox;
6746 struct diagram_point {
6747 struct diagram_point *next;
6751 static struct heightline *
6752 item_get_heightline(struct item *item)
6754 struct heightline *ret=NULL;
6755 struct street_data *sd;
6759 if (item_attr_get(item, attr_label, &attr)) {
6760 height=atoi(attr.u.str);
6761 sd=street_get_data(item);
6762 if (sd && sd->count > 1) {
6763 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
6764 ret->bbox.lu=sd->c[0];
6765 ret->bbox.rl=sd->c[0];
6766 ret->count=sd->count;
6768 for (i = 0 ; i < sd->count ; i++) {
6770 coord_rect_extend(&ret->bbox, sd->c+i);
6773 street_data_free(sd);
6780 * @brief Displays Route Height Profile
6782 * @li The name of the active vehicle
6783 * @param wm The button that was pressed.
6787 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6791 struct widget * menu, *box;
6793 struct map * map=NULL;
6794 struct map_rect * mr=NULL;
6795 struct route * route;
6796 struct item * item =NULL;
6798 struct mapset_handle *msh;
6799 int x,i,first=1,dist=0;
6800 struct coord c,last,res;
6801 struct coord_rect rbbox,dbbox;
6802 struct map_selection sel;
6803 struct heightline *heightline,*heightlines=NULL;
6804 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
6807 sel.range.min=type_height_line_1;
6808 sel.range.max=type_height_line_3;
6811 menu=gui_internal_menu(this,_("Height Profile"));
6812 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
6813 gui_internal_widget_append(menu, box);
6814 route = navit_get_route(this->nav);
6816 map = route_get_map(route);
6818 mr = map_rect_new(map,NULL);
6820 while((item = map_rect_get_item(mr))) {
6821 while (item_coord_get(item, &c, 1)) {
6827 coord_rect_extend(&sel.u.c_rect, &c);
6830 map_rect_destroy(mr);
6831 ms=navit_get_mapset(this->nav);
6833 msh=mapset_open(ms);
6834 while ((map=mapset_next(msh, 1))) {
6835 mr=map_rect_new(map, &sel);
6837 while((item = map_rect_get_item(mr))) {
6838 if (item->type >= sel.range.min && item->type <= sel.range.max) {
6839 heightline=item_get_heightline(item);
6841 heightline->next=heightlines;
6842 heightlines=heightline;
6846 map_rect_destroy(mr);
6855 map = route_get_map(route);
6857 mr = map_rect_new(map,NULL);
6858 if(mr && heightlines) {
6859 while((item = map_rect_get_item(mr))) {
6861 while (item_coord_get(item, &c, 1)) {
6865 heightline=heightlines;
6868 coord_rect_extend(&rbbox, &c);
6869 while (heightline) {
6870 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
6871 for (i = 0 ; i < heightline->count - 1; i++) {
6872 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
6873 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
6874 diagram_point=g_new(struct diagram_point, 1);
6875 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
6876 diagram_point->c.y=heightline->height;
6877 diagram_point->next=diagram_points;
6878 diagram_points=diagram_point;
6879 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
6884 heightline=heightline->next;
6886 dist+=transform_distance(projection_mg, &last, &c);
6892 map_rect_destroy(mr);
6896 gui_internal_menu_render(this);
6898 diagram_point=diagram_points;
6899 while (diagram_point) {
6901 dbbox.lu=diagram_point->c;
6902 dbbox.rl=diagram_point->c;
6905 coord_rect_extend(&dbbox, &diagram_point->c);
6906 diagram_point=diagram_point->next;
6908 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
6909 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
6911 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
6913 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
6919 diagram_point=diagram_points;
6920 while (diagram_point) {
6921 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
6923 diagram_point=diagram_point->next;
6927 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
6928 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
6929 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
6930 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
6934 graphics_draw_lines(this->gra, this->foreground, p, 2);
6943 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6945 struct widget *menu,*wb,*w;
6948 graphics_draw_mode(this->gra, draw_mode_begin);
6949 menu=gui_internal_menu(this, _("Show Locale"));
6950 menu->spx=this->spacing*10;
6951 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
6952 gui_internal_widget_append(menu, wb);
6953 text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
6954 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6955 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
6957 #ifdef HAVE_API_WIN32_BASE
6959 char country[32],lang[32];
6960 #ifdef HAVE_API_WIN32_CE
6961 wchar_t wcountry[32],wlang[32];
6963 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
6964 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
6966 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
6968 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
6969 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6970 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
6972 #ifdef HAVE_API_WIN32_CE
6973 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
6974 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
6976 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
6978 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
6979 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
6980 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
6985 gui_internal_menu_render(this);
6986 graphics_draw_mode(this->gra, draw_mode_end);
6990 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6992 struct widget *menu,*wb,*w;
6995 graphics_draw_mode(this->gra, draw_mode_begin);
6996 menu=gui_internal_menu(this, _("About Navit"));
6997 menu->spx=this->spacing*10;
6998 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
6999 gui_internal_widget_append(menu, wb);
7002 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
7003 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
7006 text=g_strdup_printf("%s",PACKAGE_NAME);
7007 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7008 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7012 text=g_strdup_printf("%s",version);
7013 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7014 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7018 text=g_strdup_printf("http://www.navit-project.org/");
7019 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7020 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7024 text=g_strdup_printf("%s:",_("By"));
7025 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7026 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7028 text=g_strdup_printf("Martin Schaller");
7029 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7030 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7032 text=g_strdup_printf("Michael Farmbauer");
7033 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7034 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7036 text=g_strdup_printf("Alexander Atanasov");
7037 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7038 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7040 text=g_strdup_printf("Pierre Grandin");
7041 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7042 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7046 text=g_strdup_printf("%s",_("And all the Navit Team"));
7047 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7048 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7050 text=g_strdup_printf("%s",_("members and contributors."));
7051 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7052 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7055 gui_internal_menu_render(this);
7056 graphics_draw_mode(this->gra, draw_mode_end);
7060 * @brief handles the 'next page' table event.
7061 * A callback function that is invoked when the 'next page' button is pressed
7062 * to advance the contents of a table widget.
7064 * @param this The graphics context.
7065 * @param wm The button widget that was pressed.
7067 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
7069 struct widget * table_widget = (struct widget * ) wm->data;
7070 struct table_data * table_data = NULL;
7076 table_data = (struct table_data*) table_widget->data;
7082 * Before advancing to the next page we need to ensure
7083 * that the current top_row is in the list of previous top_rows
7084 * so previous page can work.
7087 for(iterator=table_data->page_headers; iterator != NULL;
7088 iterator = g_list_next(iterator) )
7090 if(iterator->data == table_data->top_row)
7099 table_data->page_headers=g_list_append(table_data->page_headers,
7100 table_data->top_row);
7103 * Invalidate row coordinates for all rows which were previously rendered
7105 for(iterator=table_data->top_row; iterator && table_data->rows_on_page; iterator = g_list_next(iterator))
7107 struct widget * cur_row_widget = (struct widget*)iterator->data;
7108 cur_row_widget->p.x=-1;
7109 cur_row_widget->p.y=-1;
7110 cur_row_widget->w=0;
7111 cur_row_widget->h=0;
7112 table_data->rows_on_page--;
7115 gui_internal_table_hide_rows(table_data);
7116 table_data->top_row=g_list_next(table_data->bottom_row);
7118 wm->state&= ~STATE_HIGHLIGHTED;
7119 gui_internal_menu_render(this);
7125 * @brief handles the 'previous page' table event.
7126 * A callback function that is invoked when the 'previous page' button is pressed
7127 * to go back in the contents of a table widget.
7129 * @param this The graphics context.
7130 * @param wm The button widget that was pressed.
7132 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
7134 struct widget * table_widget = (struct widget * ) wm->data;
7135 struct table_data * table_data = NULL;
7136 GList * current_page_top=NULL;
7141 table_data = (struct table_data*) table_widget->data;
7144 gui_internal_table_hide_rows(table_data);
7145 current_page_top = table_data->top_row;
7146 for(iterator = table_data->page_headers; iterator != NULL;
7147 iterator = g_list_next(iterator))
7149 if(current_page_top == iterator->data)
7153 table_data->top_row = (GList*) iterator->data;
7157 wm->state&= ~STATE_HIGHLIGHTED;
7158 gui_internal_menu_render(this);
7163 * @brief deallocates a table_data structure.
7166 void gui_internal_table_data_free(void * p)
7171 * @note button_box and its children (next_button,prev_button)
7172 * have their memory managed by the table itself.
7174 struct table_data * table_data = (struct table_data*) p;
7175 g_list_free(table_data->page_headers);
7183 * @brief Called when the route is updated.
7185 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
7188 if(this->route_data.route_showing) {
7189 gui_internal_populate_route_table(this,navit);
7190 graphics_draw_mode(this->gra, draw_mode_begin);
7191 gui_internal_menu_render(this);
7192 graphics_draw_mode(this->gra, draw_mode_end);
7200 * @brief Called when the route screen is closed (deallocated).
7202 * The main purpose of this function is to remove the widgets from
7203 * references route_data because those widgets are about to be freed.
7205 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
7208 this_->route_data.route_showing=0;
7209 this_->route_data.route_table=NULL;
7216 * @brief Populates the route table with route information
7218 * @param this The gui context
7219 * @param navit The navit object
7221 void gui_internal_populate_route_table(struct gui_priv * this,
7222 struct navit * navit)
7224 struct map * map=NULL;
7225 struct map_rect * mr=NULL;
7226 struct navigation * nav = NULL;
7227 struct item * item =NULL;
7229 struct widget * label = NULL;
7230 struct widget * row = NULL;
7231 nav = navit_get_navigation(navit);
7235 map = navigation_get_map(nav);
7237 mr = map_rect_new(map,NULL);
7239 gui_internal_widget_table_clear(this,this->route_data.route_table);
7240 while((item = map_rect_get_item(mr))) {
7241 if(item_attr_get(item,attr_navigation_long,&attr)) {
7242 label = gui_internal_label_new(this,attr.u.str);
7243 row = gui_internal_widget_table_row_new(this,
7246 | orientation_horizontal);
7247 row->children=g_list_append(row->children,label);
7248 gui_internal_widget_append(this->route_data.route_table,row);
7256 static struct command_table commands[] = {
7257 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
7258 {"back",command_cast(gui_internal_cmd2_back)},
7259 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
7260 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
7261 {"formerdests",command_cast(gui_internal_cmd_formerdests)},
7262 {"get_data",command_cast(gui_internal_get_data)},
7263 {"locale",command_cast(gui_internal_cmd2_locale)},
7264 {"log",command_cast(gui_internal_cmd_log)},
7265 {"menu",command_cast(gui_internal_cmd_menu2)},
7266 {"position",command_cast(gui_internal_cmd2_position)},
7267 {"route_description",command_cast(gui_internal_cmd2_route_description)},
7268 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
7269 {"set",command_cast(gui_internal_cmd2_set)},
7270 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
7271 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
7272 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
7273 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
7274 {"town",command_cast(gui_internal_cmd2_town)},
7275 {"quit",command_cast(gui_internal_cmd2_quit)},
7276 {"write",command_cast(gui_internal_cmd_write)},
7277 {"about",command_cast(gui_internal_cmd2_about)},
7282 //##############################################################################################################
7285 //# Authors: Martin Schaller (04/2008)
7286 //##############################################################################################################
7287 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
7289 struct color color_white={0xffff,0xffff,0xffff,0xffff};
7290 struct color color_black={0x0,0x0,0x0,0xffff};
7291 struct color back2_color={0x4141,0x4141,0x4141,0xffff};
7293 struct gui_priv *this;
7295 *meth=gui_internal_methods;
7296 this=g_new0(struct gui_priv, 1);
7299 this->self.type=attr_gui;
7300 this->self.u.gui=gui;
7302 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
7303 this->menu_on_map_click=attr->u.num;
7305 this->menu_on_map_click=1;
7306 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
7307 this->signal_on_map_click=attr->u.num;
7309 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
7310 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
7313 if( (attr=attr_search(attrs,NULL,attr_font_size)))
7315 this->config.font_size=attr->u.num;
7319 this->config.font_size=-1;
7321 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
7323 this->config.icon_xs=attr->u.num;
7327 this->config.icon_xs=-1;
7329 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
7331 this->config.icon_l=attr->u.num;
7335 this->config.icon_l=-1;
7337 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
7339 this->config.icon_s=attr->u.num;
7343 this->config.icon_s=-1;
7345 if( (attr=attr_search(attrs,NULL,attr_spacing)))
7347 this->config.spacing=attr->u.num;
7351 this->config.spacing=-1;
7353 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
7355 this->speech=attr->u.num;
7357 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
7358 this->keyboard=attr->u.num;
7362 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
7363 this->fullscreen=attr->u.num;
7365 if( (attr=attr_search(attrs,NULL,attr_flags)))
7366 this->flags=attr->u.num;
7367 if( (attr=attr_search(attrs,NULL,attr_background_color)))
7368 this->background_color=*attr->u.color;
7370 this->background_color=color_black;
7371 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
7372 this->background2_color=*attr->u.color;
7374 this->background2_color=back2_color;
7375 if( (attr=attr_search(attrs,NULL,attr_text_color)))
7376 this->text_foreground_color=*attr->u.color;
7378 this->text_foreground_color=color_white;
7379 this->text_background_color=color_black;
7380 if( (attr=attr_search(attrs,NULL,attr_columns)))
7381 this->cols=attr->u.num;
7382 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
7383 this->osd_configuration=*attr;
7385 if( (attr=attr_search(attrs,NULL,attr_pitch)))
7386 this->pitch=attr->u.num;
7389 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
7390 this->flags_town=attr->u.num;
7392 this->flags_town=-1;
7393 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
7394 this->flags_street=attr->u.num;
7396 this->flags_street=-1;
7397 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
7398 this->flags_house_number=attr->u.num;
7400 this->flags_house_number=-1;
7401 if( (attr=attr_search(attrs,NULL,attr_radius)))
7402 this->radius=attr->u.num;
7405 this->data.priv=this;
7406 this->data.gui=&gui_internal_methods_ext;
7407 this->data.widget=&gui_internal_widget_methods;
7408 this->cbl=callback_list_new();
7413 //##############################################################################################################
7416 //# Authors: Martin Schaller (04/2008)
7417 //##############################################################################################################
7418 void plugin_init(void)
7420 plugin_register_gui_type("internal", gui_internal_new);
7424 gui_internal_destroy(struct gui_priv *this)
7426 g_free(this->country_iso2);
7428 g_free(this->html_text);