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 #define snprintf sprintf_s
48 #include "navit_nls.h"
54 #include "transform.h"
60 #include "vehicleprofile.h"
66 #include "navit/search.h"
71 #include "navit_nls.h"
72 #include "navigation.h"
73 #include "gui_internal.h"
75 #include "xmlconfig.h"
77 #include "bookmarks.h"
91 struct widget *search_list;
92 struct widget *keyboard;
93 struct widget *button_bar;
96 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
97 struct widget *redisplay_widget;
99 struct attr refresh_callback_obj,refresh_callback;
102 //##############################################################################################################
105 //# Authors: Martin Schaller (04/2008)
106 //##############################################################################################################
108 enum widget_type type;
109 struct graphics_gc *background,*text_background;
110 struct graphics_gc *foreground_frame;
111 struct graphics_gc *foreground;
113 struct graphics_image *img;
115 * A function to be invoked on actions.
116 * @li widget The widget that is receiving the button press.
119 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
124 * @brief A function to deallocate data
126 void (*data_free)(void *data);
129 * @brief a function that will be called as the widget is being destroyed.
130 * This function can act as a destructor for the widget. It allows for
131 * on deallocation actions to be specified on a per widget basis.
132 * This function will call g_free on the widget (if required).
134 void (*wfree) (struct gui_priv *this_, struct widget * w);
148 int bl,br,bt,bb,spx,spy;
152 * The number of widgets to layout horizontally when doing
153 * a orientation_horizontal_vertical layout
159 int (*set_attr)(void *, struct attr *);
160 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
161 void (*remove_cb)(void *, struct callback *cb);
168 struct menu_data *menu_data;
171 struct widget *parent;
175 * @brief A structure to store configuration values.
177 * This structure stores configuration values for how gui elements in the internal GUI
180 struct gui_config_settings {
183 * The base size (in fractions of a point) to use for text.
187 * The size (in pixels) that xs style icons should be scaled to.
188 * This icon size is typically used in various lists and should be set to value which allows a list row to be easily cliked or dragged.
192 * The size (in pixels) that s style icons (small) should be scaled to, used for the menu top row icons
196 * The size (in pixels) that l style icons should be scaled to, used for icons defined in the menu html
200 * The default amount of spacing (in pixels) to place between GUI elements.
207 * Indexes into the config_profiles array.
209 const int LARGE_PROFILE=0;
210 const int MEDIUM_PROFILE=1;
211 const int SMALL_PROFILE=2;
214 * The default config profiles.
216 * [0] => LARGE_PROFILE (screens 640 in one dimension)
217 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
218 * [2] => Small profile (default)
220 static struct gui_config_settings config_profiles[]={
227 struct widget * route_table;
232 //##############################################################################################################
235 //# Authors: Martin Schaller (04/2008)
236 //##############################################################################################################
241 struct graphics *gra;
242 struct graphics_gc *background;
243 struct graphics_gc *background2;
244 struct graphics_gc *highlight_background;
245 struct graphics_gc *foreground;
246 struct graphics_gc *text_foreground;
247 struct graphics_gc *text_background;
248 struct color background_color, background2_color, text_foreground_color, text_background_color;
252 struct graphics_font *fonts[3];
254 * The size (in pixels) that xs style icons should be scaled to.
255 * This icon size can be too small to click it on some devices.
259 * The size (in pixels) that s style icons (small) should be scaled to
263 * The size (in pixels) that l style icons should be scaled to
267 struct widget *widgets;
271 struct widget *highlighted,*editable;
272 struct widget *highlighted_menu;
273 struct pcoord clickp, vehiclep;
274 struct attr *click_coord_geo, *position_coord_geo;
275 struct search_list *sl;
277 int menu_on_map_click;
279 int signal_on_map_click;
283 int keyboard_required;
285 * The setting information read from the configuration file.
286 * values of -1 indicate no value was specified in the config file.
288 struct gui_config_settings config;
289 struct event_idle *idle;
290 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
291 struct event_timeout *motion_timeout_event;
292 struct point current;
294 struct callback * vehicle_cb;
296 * Stores information about the route.
298 struct route_data route_data;
300 struct gui_internal_data data;
301 struct callback_list *cbl;
304 struct attr osd_configuration;
306 int flags_town,flags_street,flags_house_number;
308 int mouse_button_clicked_on_map;
312 struct widget *html_container;
316 int html_anchor_found;
336 struct widget *container;
341 struct gesture_elem {
344 } gesture_ring[GESTURE_RINGSIZE];
345 int gesture_ring_last, gesture_ring_first;
348 int results_map_population;
355 struct html_tag_map {
361 {"html",html_tag_html},
362 {"img",html_tag_img},
363 {"script",html_tag_script},
364 {"form",html_tag_form},
365 {"input",html_tag_input},
366 {"div",html_tag_div},
371 * @brief A structure to store information about a table.
373 * The table_data widget stores pointers to extra information needed by the
376 * The table_data structure needs to be freed with data_free along with the widget.
382 * A GList pointer into a widget->children list that indicates the row
383 * currently being rendered at the top of the table.
387 * A Glist pointer into a widget->children list that indicates the row
388 * currently being rendered at the bottom of the table.
393 * A container box that is the child of the table widget that contains+groups
394 * the next and previous button.
396 struct widget * button_box;
399 * Button box should not be displayed if button_box_hide is not zero.
404 * A button widget to handle 'next page' requests
406 struct widget * next_button;
408 * A button widget to handle 'previous page' requests.
410 struct widget * prev_button;
414 * a pointer to the gui context.
415 * This is needed by the free function to destory the buttons.
417 struct gui_priv * this;
421 * A data structure that holds information about a column that makes up a table.
425 struct table_column_desc
429 * The computed height of a cell in the table.
434 * The computed width of a cell in the table.
440 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
441 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
442 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
443 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
444 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child);
445 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child);
446 static void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func);
447 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
448 static void gui_internal_apply_config(struct gui_priv *this);
450 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
451 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
452 static void gui_internal_table_hide_rows(struct table_data * table_data);
453 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
454 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
455 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
456 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
457 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
458 static int gui_internal_widget_table_is_empty(struct gui_priv *this,struct widget * table);
459 static GList * gui_internal_widget_table_next_row(GList * row);
460 static GList * gui_internal_widget_table_prev_row(GList * row);
461 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
462 static void gui_internal_table_data_free(void * d);
463 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
465 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
466 static void gui_internal_populate_route_table(struct gui_priv * this,
467 struct navit * navit);
468 static void gui_internal_search_idle_end(struct gui_priv *this);
469 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
470 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
471 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
472 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
473 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
474 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
475 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
476 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
477 static void gui_internal_check_exit(struct gui_priv *this);
478 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
480 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
481 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
483 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
484 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
485 static void gui_internal_html_load_href(struct gui_priv *this, char *href, int replace);
486 static void gui_internal_destroy(struct gui_priv *this);
487 static void gui_internal_enter(struct gui_priv *this, int ignore);
488 static void gui_internal_enter_setup(struct gui_priv *this);
489 static void gui_internal_html_main_menu(struct gui_priv *this);
490 static void gui_internal_menu_vehicle_settings(struct gui_priv *this, struct vehicle *v, char *name);
494 * * Display image scaled to specific size
495 * * searches for scaleable and pre-scaled image
496 * * @param this Our gui context
497 * * @param name image name
498 * * @param w desired width of image
499 * * @param h desired height of image
500 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
502 static struct graphics_image *
503 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
505 struct graphics_image *ret=NULL;
506 char *full_path=NULL;
507 full_path=graphics_icon_path(name);
508 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
509 dbg(1,"Trying to load image '%s' (w=%d, h=%d): %s\n", name, w, h, ret ? "OK" : "NOT FOUND");
512 dbg(0,"Failed to load image for '%s' (w=%d, h=%d)\n", name, w, h);
517 static struct graphics_image *
518 image_new_o(struct gui_priv *this, char *name)
520 return image_new_scaled(this, name, -1, -1);
525 * * Display image scaled to xs (extra small) size
526 * * This image size can be too small to click it on some devices.
527 * * @param this Our gui context
528 * * @param name image name
529 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
531 static struct graphics_image *
532 image_new_xs(struct gui_priv *this, const char *name)
534 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
538 * * Display image scaled to s (small) size
539 * * @param this Our gui context
540 * * @param name image name
541 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
544 static struct graphics_image *
545 image_new_s(struct gui_priv *this, const char *name)
547 return image_new_scaled(this, name, this->icon_s, this->icon_s);
551 * * Display image scaled to l (large) size
552 * * @param this Our gui context
553 * * @param name image name
554 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
556 static struct graphics_image *
557 image_new_l(struct gui_priv *this, const char *name)
559 return image_new_scaled(this, name, this->icon_l, this->icon_l);
563 coordinates_geo(const struct coord_geo *gc, char sep)
565 char latc='N',lngc='E';
566 int lat_deg,lat_min,lat_sec;
567 int lng_deg,lng_min,lng_sec;
568 struct coord_geo g=*gc;
579 lat_min=fmod(g.lat*60,60);
580 lat_sec=fmod(g.lat*3600,60);
582 lng_min=fmod(g.lng*60,60);
583 lng_sec=fmod(g.lng*3600,60);
584 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);
588 coordinates(struct pcoord *pc, char sep)
594 transform_to_geo(pc->pro, &c, &g);
595 return coordinates_geo(&g, sep);
600 gui_internal_background_render(struct gui_priv *this, struct widget *w)
602 struct point pnt=w->p;
603 if (w->state & STATE_HIGHLIGHTED)
604 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
607 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
611 static struct widget *
612 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
618 struct widget *widget=g_new0(struct widget, 1);
619 widget->type=widget_label;
620 widget->font_idx=font;
622 widget->text=g_strdup(text);
623 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
627 widget->h=h+this->spacing;
629 widget->w=w+this->spacing;
631 widget->flags=gravity_center;
632 widget->foreground=this->text_foreground;
633 widget->text_background=this->text_background;
638 static struct widget *
639 gui_internal_label_new(struct gui_priv *this, char *text)
641 return gui_internal_label_font_new(this, text, 0);
644 static struct widget *
645 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
647 struct widget *ret=NULL;
648 char *tmp=g_malloc(strlen(text)+3), *p;
650 while ((p=g_utf8_find_prev_char(text, p)) >= text) {
654 ret=gui_internal_label_new(this, tmp);
655 if (ret->w < maxwidth)
657 gui_internal_widget_destroy(this, ret);
661 ret=gui_internal_label_new(this, "");
666 static struct widget *
667 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
669 struct widget *widget=g_new0(struct widget, 1);
670 widget->type=widget_image;
673 widget->w=image->width;
674 widget->h=image->height;
680 gui_internal_image_render(struct gui_priv *this, struct widget *w)
684 gui_internal_background_render(this, w);
687 pnt.x+=w->w/2-w->img->hot.x;
688 pnt.y+=w->h/2-w->img->hot.y;
689 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
694 gui_internal_label_render(struct gui_priv *this, struct widget *w)
696 struct point pnt=w->p;
697 gui_internal_background_render(this, w);
698 if (w->state & STATE_EDIT)
699 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
702 char *startext=(char*)g_alloca(strlen(w->text)+1);
706 for (i = 0 ; i < strlen(text); i++)
711 if (w->flags & gravity_right) {
712 pnt.y+=w->h-this->spacing;
713 pnt.x+=w->w-w->textw-this->spacing;
714 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
716 pnt.y+=w->h-this->spacing;
717 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
723 * @brief A text box is a widget that renders a text string containing newlines.
724 * The string will be broken up into label widgets at each newline with a vertical layout.
727 static struct widget *
728 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
730 char *s=g_strdup(text),*s2,*tok;
731 struct widget *ret=gui_internal_box_new(this, flags);
733 while ((tok=strtok(s2,"\n"))) {
734 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
737 gui_internal_widget_pack(this,ret);
742 static struct widget *
743 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
745 return gui_internal_text_font_new(this, text, 0, flags);
749 static struct widget *
750 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)
752 struct widget *ret=NULL;
753 ret=gui_internal_box_new(this, flags);
756 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
758 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
762 ret->state |= STATE_SENSITIVE;
763 ret->speech=g_strdup(text);
770 static struct widget *
771 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)
773 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
777 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
784 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
785 is_on=curr.u.data == w->on.u.data;
788 if (is_on != w->is_on) {
792 l=g_list_first(w->children);
796 graphics_image_free(this->gra, wi->img);
797 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
799 if (w->is_on && w->off.type == attr_none)
800 w->state &= ~STATE_SENSITIVE;
802 w->state |= STATE_SENSITIVE;
809 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
811 if (gui_internal_button_attr_update(this, w))
812 gui_internal_widget_render(this, w);
815 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
818 w->set_attr(w->instance, &w->off);
820 w->set_attr(w->instance, &w->on);
821 gui_internal_button_attr_update(this, w);
825 static struct widget *
826 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
828 struct graphics_image *image=NULL;
832 image=image_new_xs(this, "gui_inactive");
833 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
838 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
839 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
840 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
841 ret->instance=this->nav;
842 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
843 navit_add_callback(this->nav, ret->cb);
844 gui_internal_button_attr_update(this, ret);
848 static struct widget *
849 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)
851 struct graphics_image *image=NULL;
853 image=image_new_xs(this, "gui_inactive");
856 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
862 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
863 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
864 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
867 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
868 map_add_callback(map, ret->cb);
869 gui_internal_button_attr_update(this, ret);
873 static struct widget *
874 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
876 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
880 //##############################################################################################################
883 //# Authors: Martin Schaller (04/2008)
884 //##############################################################################################################
885 static void gui_internal_clear(struct gui_priv *this)
887 struct graphics *gra=this->gra;
891 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
895 static struct widget *
896 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
898 struct widget *ret,*child;
899 GList *l=wi->children;
906 if ( wi->p.x + wi->w < p->x)
908 if ( wi->p.y + wi->h < p->y)
911 if (wi->state & flags)
915 ret=gui_internal_find_widget(child, p, flags);
926 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
928 if (found == this->highlighted)
931 graphics_draw_mode(this->gra, draw_mode_begin);
932 if (this->highlighted) {
933 this->highlighted->state &= ~STATE_HIGHLIGHTED;
934 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
935 gui_internal_widget_render(this, this->highlighted);
936 this->highlighted=NULL;
937 this->highlighted_menu=NULL;
940 this->highlighted=found;
941 this->highlighted_menu=g_list_last(this->root.children)->data;
942 this->highlighted->state |= STATE_HIGHLIGHTED;
943 gui_internal_widget_render(this, this->highlighted);
944 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
946 graphics_draw_mode(this->gra, draw_mode_end);
948 //##############################################################################################################
951 //# Authors: Martin Schaller (04/2008)
952 //##############################################################################################################
953 static void gui_internal_highlight(struct gui_priv *this)
955 struct widget *menu,*found=NULL;
956 if (this->current.x > -1 && this->current.y > -1) {
957 menu=g_list_last(this->root.children)->data;
958 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
960 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
962 if (this->editable && this->editable != found) {
963 this->editable->state &= ~ STATE_EDIT;
964 gui_internal_widget_render(this, this->editable);
966 found->state |= STATE_EDIT;
967 gui_internal_widget_render(this, found);
968 this->editable=found;
973 gui_internal_highlight_do(this, found);
974 this->motion_timeout_event=NULL;
978 static void gui_internal_gesture_ring_clear(struct gui_priv *this)
980 this->gesture_ring_last=this->gesture_ring_first=0;
984 static struct gesture_elem * gui_internal_gesture_ring_get(struct gui_priv *this, int i)
986 int n=(this->gesture_ring_last-i)%GESTURE_RINGSIZE;
987 if(n==this->gesture_ring_first)
989 return this->gesture_ring+n;
992 static void gui_internal_gesture_ring_add(struct gui_priv *this, struct point *p)
995 #ifndef HAVE_API_WIN32_CE
997 gettimeofday(&tv,NULL);
998 msec=tv.tv_sec*1000+tv.tv_usec/1000;
1000 msec=GetTickCount();
1002 this->gesture_ring_last++;
1003 this->gesture_ring_last%=GESTURE_RINGSIZE;
1004 if(this->gesture_ring_last==this->gesture_ring_first) {
1005 this->gesture_ring_first++;
1006 this->gesture_ring_first%=GESTURE_RINGSIZE;
1008 this->gesture_ring[this->gesture_ring_last].p=*p;
1009 this->gesture_ring[this->gesture_ring_last].msec=msec;
1010 dbg(2,"msec=%d x=%d y=%d\n",msec,p->x,p->y);
1015 * @brief Calculate movement vector and timing of the gesture.
1016 * @param in this gui context
1017 * @param in msec time in milliseconds to find gesture within
1018 * @param out p0 pointer to the point object, where gesture starting point coordinates should be placed. Can be NULL.
1019 * @param out dx pointer to variable to store horizontal movement of the gesture.
1020 * @param out dy pointer to variable to store vertical movement of the gesture.
1021 * @returns amount of time the actual movement took.
1023 static int gui_internal_gesture_get_vector(struct gui_priv *this, int msec, struct point *p0, int *dx, int *dy)
1025 struct gesture_elem *g;
1038 g=gui_internal_gesture_ring_get(this,0);
1047 dbg(2,"%d %d %d\n",g->msec, g->p.x, g->p.y);
1048 for(i=1;(g=gui_internal_gesture_ring_get(this,i))!=NULL;i++) {
1049 if( msec-g->msec > 1000 )
1052 if(dx) *dx=x-g->p.x;
1053 if(dy) *dy=y-g->p.y;
1057 dbg(2,"%d %d %d\n",g->msec, g->p.x, g->p.y);
1062 static int gui_internal_gesture_do(struct gui_priv *this)
1067 dt=gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
1069 if( abs(dx) > this->icon_s*3 && abs(dy) < this->icon_s ) {
1071 dbg(1,"horizontal dx=%d dy=%d\n",dx,dy);
1073 /* Prevent swiping if widget was scrolled beforehand */
1074 if(this->pressed==2)
1077 for(wt=this->highlighted;wt && wt->type!=widget_table;wt=wt->parent);
1078 if(!wt || wt->type!=widget_table || !wt->data)
1080 if(this->highlighted) {
1081 this->highlighted->state &= ~STATE_HIGHLIGHTED;
1082 this->highlighted=NULL;
1085 gui_internal_table_button_next(this,NULL,wt);
1087 gui_internal_table_button_prev(this,NULL,wt);
1089 } else if( abs(dy) > this->icon_s*3 && abs(dx) < this->icon_s ) {
1090 dbg(1,"vertical dx=%d dy=%d\n",dx,dy);
1091 } else if (dt>300 && abs(dx) <this->icon_s && abs(dy) <this->icon_s ) {
1092 dbg(1,"longtap dx=%d dy=%d\n",dx,dy);
1094 dbg(1,"none dx=%d dy=%d\n",dx,dy);
1101 static void gui_internal_motion_cb(struct gui_priv *this)
1103 this->motion_timeout_event=NULL;
1104 gui_internal_gesture_ring_add(this, &(this->current));
1106 /* Check for scrollable table below the highligted item if there's a movement with the button pressed */
1107 if (this->pressed && this->highlighted) {
1108 struct widget *wt=NULL;
1109 struct widget *wr=NULL;
1112 /* Guard against accidental scrolling when user is likely going to swipe */
1113 gui_internal_gesture_get_vector(this, 1000, NULL, &dx, &dy);
1114 if(abs(dx)>abs(dy) || abs(dy)<this->icon_s)
1117 if(this->highlighted)
1118 for(wr=this->highlighted;wr && wr->type!=widget_table_row;wr=wr->parent);
1122 if(wt && wt->type==widget_table && (wt->state & STATE_SCROLLABLE)) {
1123 struct table_data *td=wt->data;
1133 if(this->current.y < wr->p.y && wr!=td->top_row->data ) {
1134 int n=(wr->p.y-this->current.y)/wr->h+1;
1139 while(n-->0 && (tbtm=gui_internal_widget_table_next_row(btm))!=NULL && (ttop=gui_internal_widget_table_next_row(top))!=NULL) {
1146 } else if (this->current.y > wr->p.y + wr->h ) {
1147 int y=wt->p.y+wt->h-wr->h;
1150 if(td->button_box && td->button_box->p.y!=0)
1151 y=td->button_box->p.y - td->button_box->h;
1153 if(y>this->current.y)
1156 n=(y - wr->p.y )/wr->h;
1161 while(n-->0 && (ttop=gui_internal_widget_table_prev_row(top))!=NULL && (tbtm=gui_internal_widget_table_prev_row(btm))!=NULL) {
1169 if( top && btm && (td->top_row!=top || td->bottom_row!=btm) ) {
1170 gui_internal_table_hide_rows(wt->data);
1173 graphics_draw_mode(this->gra, draw_mode_begin);
1174 gui_internal_widget_render(this,wt);
1175 graphics_draw_mode(this->gra, draw_mode_end);
1182 /* Else, just move highlight after pointer if there's nothing to scroll */
1183 gui_internal_highlight(this);
1186 static struct widget *
1187 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
1189 struct widget *widget=g_new0(struct widget, 1);
1192 widget->text=g_strdup(label);
1193 widget->type=widget_box;
1194 widget->flags=flags;
1198 static struct widget *
1199 gui_internal_box_new(struct gui_priv *this, enum flags flags)
1201 return gui_internal_box_new_with_label(this, flags, NULL);
1205 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
1210 gui_internal_background_render(this, w);
1213 w->foreground=this->foreground;
1216 if (w->foreground && w->border) {
1217 struct point pnt[5];
1219 pnt[1].x=pnt[0].x+w->w;
1221 pnt[2].x=pnt[0].x+w->w;
1222 pnt[2].y=pnt[0].y+w->h;
1224 pnt[3].y=pnt[0].y+w->h;
1226 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
1227 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
1228 graphics_gc_set_linewidth(w->foreground, 1);
1235 gui_internal_widget_render(this, wc);
1242 * @brief Compute the size and location for the widget.
1246 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
1249 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;
1251 int orientation=w->flags & 0xffff0000;
1256 if ( this->root.w > this->root.h )
1266 * count the number of children
1273 if (orientation == orientation_horizontal_vertical && count <= cols)
1274 orientation=orientation_horizontal;
1275 switch (orientation) {
1276 case orientation_horizontal:
1278 * For horizontal orientation:
1279 * pack each child and find the largest height and
1280 * compute the total width. x spacing (spx) is considered
1282 * If any children want to be expanded
1283 * we keep track of this
1288 gui_internal_widget_pack(this, wc);
1292 if (wc->flags & flags_expand)
1293 expand+=wc->w ? wc->w : 1;
1299 if (expand && w->w) {
1300 expandd=w->w-width+expand;
1305 case orientation_vertical:
1307 * For vertical layouts:
1308 * We pack each child and compute the largest width and
1309 * the total height. y spacing (spy) is considered
1311 * If the expand flag is set then teh expansion amount
1317 gui_internal_widget_pack(this, wc);
1321 if (wc->flags & flags_expand)
1322 expand+=wc->h ? wc->h : 1;
1328 if (expand && w->h) {
1329 expandd=w->h-height+expand;
1334 case orientation_horizontal_vertical:
1336 * For horizontal_vertical orientation
1337 * pack the children.
1338 * Compute the largest height and largest width.
1339 * Layout the widgets based on having the
1340 * number of columns specified by (cols)
1346 gui_internal_widget_pack(this, wc);
1356 rows=(count+cols-1)/cols;
1359 width+=w->spx*(cols-1);
1360 height+=w->spy*(rows-1);
1367 * No orientation was specified.
1368 * width and height are both 0.
1369 * The width & height of this widget
1373 dbg(0,"Warning width and height of a widget are 0");
1376 if (! w->w && ! w->h) {
1377 w->w=w->bl+w->br+width;
1378 w->h=w->bt+w->bb+height;
1387 * At this stage the width and height of this
1388 * widget has been computed.
1389 * We now make a second pass assigning heights,
1390 * widths and coordinates to each child widget.
1393 if (w->flags & gravity_left)
1395 if (w->flags & gravity_xcenter)
1396 x=w->p.x+w->w/2-owidth/2;
1397 if (w->flags & gravity_right)
1398 x=w->p.x+w->w-w->br-owidth;
1399 if (w->flags & gravity_top)
1401 if (w->flags & gravity_ycenter)
1402 y=w->p.y+w->h/2-oheight/2;
1403 if (w->flags & gravity_bottom)
1404 y=w->p.y+w->h-w->bb-oheight;
1406 switch (orientation) {
1407 case orientation_horizontal:
1412 if (wc->flags & flags_fill)
1414 if (wc->flags & flags_expand) {
1417 wc->w=wc->w*expandd/expand;
1419 if (w->flags & gravity_top)
1421 if (w->flags & gravity_ycenter)
1423 if (w->flags & gravity_bottom)
1429 case orientation_vertical:
1434 if (wc->flags & flags_fill)
1436 if (wc->flags & flags_expand) {
1439 wc->h=wc->h*expandd/expand;
1441 if (w->flags & gravity_left)
1443 if (w->flags & gravity_xcenter)
1445 if (w->flags & gravity_right)
1451 case orientation_horizontal_vertical:
1461 if (wc->flags & flags_fill) {
1465 if (w->flags & gravity_left)
1467 if (w->flags & gravity_xcenter)
1468 wc->p.x=x+(width-wc->w)/2;
1469 if (w->flags & gravity_right)
1470 wc->p.x=x+width-wc->w;
1471 if (w->flags & gravity_top)
1473 if (w->flags & gravity_ycenter)
1474 wc->p.y=y+(height-wc->h)/2;
1475 if (w->flags & gravity_bottom)
1476 wc->p.y=y-height-wc->h;
1478 if (++count == cols) {
1490 * Call pack again on each child,
1491 * the child has now had its size and coordinates
1492 * set so they can repack their children.
1497 gui_internal_widget_pack(this, wc);
1503 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1511 gui_internal_widget_reset_pack(this, wc);
1521 gui_internal_widget_append(struct widget *parent, struct widget *child)
1525 if (! child->background)
1526 child->background=parent->background;
1527 parent->children=g_list_append(parent->children, child);
1528 child->parent=parent;
1531 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1533 if (! child->background)
1534 child->background=parent->background;
1535 parent->children=g_list_prepend(parent->children, child);
1536 child->parent=parent;
1539 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child)
1542 if (! child->background)
1543 child->background=parent->background;
1546 sib=g_list_find(parent->children,sibling);
1547 parent->children=g_list_insert_before(parent->children, sib, child);
1548 child->parent=parent;
1551 static void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func)
1553 if (! child->background)
1554 child->background=parent->background;
1556 parent->children=g_list_insert_sorted(parent->children, child, func);
1557 child->parent=parent;
1561 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1569 gui_internal_widget_destroy(this, wc);
1572 g_list_free(w->children);
1577 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1579 gui_internal_widget_children_destroy(this, w);
1584 graphics_image_free(this->gra, w->img);
1590 w->data_free(w->data);
1591 if (w->cb && w->remove_cb)
1592 w->remove_cb(w->instance, w->cb);
1593 if (w==this->highlighted)
1594 this->highlighted=NULL;
1603 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1605 if(w->p.x > this->root.w || w->p.y > this->root.h)
1610 gui_internal_box_render(this, w);
1613 gui_internal_label_render(this, w);
1616 gui_internal_image_render(this, w);
1619 gui_internal_table_render(this,w);
1627 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1631 gui_internal_box_pack(this, w);
1634 gui_internal_table_pack(this,w);
1640 //##############################################################################################################
1643 //# Authors: Martin Schaller (04/2008)
1644 //##############################################################################################################
1645 static void gui_internal_call_highlighted(struct gui_priv *this)
1647 if (! this->highlighted || ! this->highlighted->func)
1649 this->highlighted->reason=1;
1650 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1654 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1656 char *text=w->speech;
1664 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1665 navit_say(this->nav, text);
1671 gui_internal_menu_destroy(struct gui_priv *this, struct widget *w)
1673 struct menu_data *menu_data=w->menu_data;
1675 if (menu_data->refresh_callback_obj.type) {
1676 struct object_func *func;
1677 func=object_func_lookup(menu_data->refresh_callback_obj.type);
1678 if (func && func->remove_attr)
1679 func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
1681 if (menu_data->refresh_callback.u.callback)
1682 callback_destroy(menu_data->refresh_callback.u.callback);
1684 g_free(menu_data->href);
1687 gui_internal_widget_destroy(this, w);
1688 this->root.children=g_list_remove(this->root.children, w);
1692 gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render)
1695 struct widget *wr,*wd;
1696 gui_internal_search_idle_end(this);
1697 while ((l = g_list_last(this->root.children))) {
1700 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1703 gui_internal_say(this, w, 0);
1704 redisplay=w->menu_data->redisplay;
1705 wr=w->menu_data->redisplay_widget;
1706 if (!w->menu_data->redisplay && !w->menu_data->href) {
1707 gui_internal_widget_render(this, w);
1711 gui_internal_menu_destroy(this, w);
1712 redisplay(this, wr, wr->data);
1714 char *href=g_strdup(w->menu_data->href);
1715 gui_internal_menu_destroy(this, w);
1716 gui_internal_html_load_href(this, href, 0);
1721 gui_internal_menu_destroy(this, wd);
1726 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1728 gui_internal_prune_menu_do(this, w, 1);
1732 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1734 GList *l=g_list_last(this->root.children);
1735 struct widget *w=NULL;
1736 while (l && count-- > 0)
1737 l=g_list_previous(l);
1740 gui_internal_prune_menu_do(this, w, render);
1745 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1747 gui_internal_prune_menu_count(this, 1, 1);
1751 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1753 gui_internal_prune_menu(this, wm->data);
1757 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1759 graphics_draw_mode(this->gra, draw_mode_begin);
1760 gui_internal_back(this, NULL, NULL);
1761 graphics_draw_mode(this->gra, draw_mode_end);
1762 gui_internal_check_exit(this);
1766 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1768 gui_internal_prune_menu(this, NULL);
1772 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1774 struct widget *w=this->root.children->data;
1775 if (w && w->menu_data && w->menu_data->href && !strcmp(w->menu_data->href,"#Main Menu"))
1776 gui_internal_prune_menu(this, w);
1778 gui_internal_html_main_menu(this);
1781 static struct widget *
1782 gui_internal_top_bar(struct gui_priv *this)
1784 struct widget *w,*wm,*wh,*wc,*wcn;
1785 int dots_len, sep_len;
1787 int width,width_used=0,use_sep=0,incomplete=0;
1788 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1790 1:Don't expand bar to screen width
1791 2:Don't show Map Icon
1792 4:Don't show Home Icon
1793 8:Show only current menu
1794 16:Don't use menu titles as button
1795 32:Show navit version
1798 256:Use background for menu headline
1799 512:Set osd_configuration and zoom to route when setting position
1800 1024:Don't show back button
1801 2048:No highlighting of keyboard
1804 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1805 w->bl=this->spacing;
1806 w->spx=this->spacing;
1807 w->background=this->background2;
1808 if ((this->flags & 6) == 6) {
1814 width=this->root.w-w->bl;
1815 if (! (this->flags & 2)) {
1816 wm=gui_internal_button_new_with_callback(this, NULL,
1817 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1818 gui_internal_cmd_return, NULL);
1819 wm->speech=g_strdup(_("Back to map"));
1820 gui_internal_widget_pack(this, wm);
1821 gui_internal_widget_append(w, wm);
1824 if (! (this->flags & 4)) {
1825 wh=gui_internal_button_new_with_callback(this, NULL,
1826 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1827 gui_internal_cmd_main_menu, NULL);
1828 wh->speech=g_strdup(_("Main Menu"));
1829 gui_internal_widget_pack(this, wh);
1830 gui_internal_widget_append(w, wh);
1833 if (!(this->flags & 6))
1835 l=g_list_last(this->root.children);
1836 wcn=gui_internal_label_new(this,".. »");
1837 wcn->foreground=foreground;
1839 gui_internal_widget_destroy(this, wcn);
1840 wcn=gui_internal_label_new(this,"»");
1841 wcn->foreground=foreground;
1843 gui_internal_widget_destroy(this, wcn);
1845 if (g_list_previous(l) || !g_list_next(l)) {
1847 wcn=gui_internal_label_new(this, wc->text);
1848 wcn->foreground=foreground;
1853 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1854 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1856 gui_internal_widget_destroy(this, wcn);
1860 struct widget *wct=gui_internal_label_new(this, "»");
1861 wct->foreground=foreground;
1862 res=g_list_prepend(res, wct);
1863 width_used+=sep_len+w->spx;
1866 if (!(this->flags & 16)) {
1867 wcn->func=gui_internal_cmd_return;
1869 wcn->state |= STATE_SENSITIVE;
1871 res=g_list_prepend(res, wcn);
1872 if (this->flags & 8)
1875 l=g_list_previous(l);
1879 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1880 wcn->foreground=foreground;
1881 wcn->func=gui_internal_cmd_return;
1883 wcn->state |= STATE_SENSITIVE;
1884 res=g_list_prepend(res, wcn);
1885 l=g_list_previous(l);
1889 wcn=gui_internal_label_new(this, ".. »");
1890 wcn->foreground=foreground;
1891 wcn->func=gui_internal_cmd_return;
1893 wcn->state |= STATE_SENSITIVE;
1894 res=g_list_prepend(res, wcn);
1899 gui_internal_widget_append(w, l->data);
1902 if (this->flags & 32) {
1903 char *version_text=g_strdup_printf("Navit %s",version);
1904 wcn=gui_internal_label_new(this, version_text);
1905 g_free(version_text);
1906 wcn->flags=gravity_right_center|flags_expand;
1907 gui_internal_widget_append(w, wcn);
1911 gui_internal_widget_destroy(this, dots);
1916 static struct widget *
1917 gui_internal_time_help(struct gui_priv *this)
1919 struct widget *w,*wc,*wcn;
1924 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1925 w->bl=this->spacing;
1926 w->spx=this->spacing;
1932 if (this->flags & 64) {
1933 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1939 tm=localtime(&timep);
1940 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1941 wcn=gui_internal_label_new(this, timestr);
1942 gui_internal_widget_append(wc, wcn);
1943 gui_internal_widget_append(w, wc);
1945 if (this->flags & 128) {
1946 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1947 gui_internal_widget_append(w, wcn);
1954 * Applys the configuration values to this based on the settings
1955 * specified in the configuration file (this->config) and
1956 * the most approriate default profile based on screen resolution.
1958 * This function should be run after this->root is setup and could
1959 * be rerun after the window is resized.
1961 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1963 static void gui_internal_apply_config(struct gui_priv *this)
1965 struct gui_config_settings * current_config=0;
1967 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1969 * Select default values from profile based on the screen.
1971 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1973 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1975 current_config = &config_profiles[LARGE_PROFILE];
1979 current_config = &config_profiles[MEDIUM_PROFILE];
1984 current_config = &config_profiles[SMALL_PROFILE];
1988 * Apply override values from config file
1990 if(this->config.font_size == -1 )
1992 this->font_size = current_config->font_size;
1996 this->font_size = this->config.font_size;
1999 if(this->config.icon_xs == -1 )
2001 this->icon_xs = current_config->icon_xs;
2005 this->icon_xs = this->config.icon_xs;
2008 if(this->config.icon_s == -1 )
2010 this->icon_s = current_config->icon_s;
2014 this->icon_s = this->config.icon_s;
2016 if(this->config.icon_l == -1 )
2018 this->icon_l = current_config->icon_l;
2022 this->icon_l = this->config.icon_l;
2024 if(this->config.spacing == -1 )
2026 this->spacing = current_config->spacing;
2030 this->spacing = current_config->spacing;
2035 static struct widget *
2036 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
2038 struct widget *wl,*wlb;
2039 struct widget *wb=gui_internal_menu_data(this)->button_bar;
2040 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
2041 wl=gui_internal_label_new(this, label);
2043 wlb->foreground=this->text_foreground;
2048 gui_internal_widget_append(wlb, wl);
2050 gui_internal_widget_prepend(wb, wlb);
2052 gui_internal_widget_append(wb, wlb);
2058 static struct widget *
2059 gui_internal_menu(struct gui_priv *this, const char *label)
2061 struct widget *menu,*w,*w1,*topbox;
2063 gui_internal_search_idle_end(this);
2064 topbox=gui_internal_box_new_with_label(this, 0, label);
2065 topbox->w=this->root.w;
2066 topbox->h=this->root.h;
2067 gui_internal_widget_append(&this->root, topbox);
2068 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
2069 menu->w=this->root.w;
2070 menu->h=this->root.h;
2071 menu->background=this->background;
2072 gui_internal_apply_config(this);
2073 if (!this->fonts[0]) {
2074 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
2075 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
2076 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
2078 topbox->menu_data=g_new0(struct menu_data, 1);
2079 gui_internal_widget_append(topbox, menu);
2080 w=gui_internal_top_bar(this);
2081 gui_internal_widget_append(menu, w);
2082 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
2083 w->spx=4*this->spacing;
2085 gui_internal_widget_append(menu, w);
2086 if (this->flags & 16 && !(this->flags & 1024)) {
2087 struct widget *wlb,*wb,*wm=w;
2088 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
2089 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
2090 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
2091 gui_internal_widget_append(wm, w);
2092 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
2098 topbox->menu_data->button_bar=wb;
2099 gui_internal_widget_append(wm, wb);
2100 wlb=gui_internal_button_label(this,_("Back"),1);
2101 wlb->func=gui_internal_back;
2102 wlb->state |= STATE_SENSITIVE;
2104 if (this->flags & 192) {
2105 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
2106 menu->w=this->root.w;
2107 menu->h=this->root.h;
2108 w1=gui_internal_time_help(this);
2109 gui_internal_widget_append(menu, w1);
2110 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
2111 gui_internal_widget_append(menu, w1);
2112 gui_internal_widget_append(topbox, menu);
2113 menu->background=NULL;
2115 gui_internal_widget_pack(this, topbox);
2116 gui_internal_widget_reset_pack(this, topbox);
2117 topbox->w=this->root.w;
2118 topbox->h=this->root.h;
2119 menu->w=this->root.w;
2120 menu->h=this->root.h;
2124 static struct menu_data *
2125 gui_internal_menu_data(struct gui_priv *this)
2128 struct widget *menu;
2130 l=g_list_last(this->root.children);
2132 return menu->menu_data;
2136 gui_internal_menu_reset_pack(struct gui_priv *this)
2139 struct widget *top_box;
2141 l=g_list_last(this->root.children);
2143 gui_internal_widget_reset_pack(this, top_box);
2147 gui_internal_menu_render(struct gui_priv *this)
2150 struct widget *menu;
2152 l=g_list_last(this->root.children);
2154 gui_internal_say(this, menu, 0);
2155 gui_internal_widget_pack(this, menu);
2156 gui_internal_widget_render(this, menu);
2160 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
2163 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
2164 navit_set_destination(this->nav, &wm->c, name, 1);
2165 if (this->flags & 512) {
2167 follow.type=attr_follow;
2169 navit_set_attr(this->nav, &this->osd_configuration);
2170 navit_set_attr(this->nav, &follow);
2171 navit_zoom_to_route(this->nav, 0);
2173 gui_internal_prune_menu(this, NULL);
2177 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
2181 v.type=attr_vehicle;
2183 navit_set_attr(this->nav, &v);
2185 navit_set_position(this->nav, &wm->c);
2186 gui_internal_prune_menu(this, NULL);
2190 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
2194 dbg(0,"text='%s'\n", widget->text);
2195 if (widget->text && strlen(widget->text)){
2196 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2197 bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
2199 g_free(widget->text);
2201 l=g_list_previous(g_list_last(this->root.children));
2202 gui_internal_prune_menu(this, l->data);
2206 gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
2210 dbg(0,"text='%s'\n", widget->text);
2211 if (widget->text && strlen(widget->text)){
2212 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2213 bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
2215 g_free(widget->text);
2217 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2218 gui_internal_prune_menu(this, l->data);
2222 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
2224 gui_internal_cmd_add_bookmark_do(this, widget->data);
2228 gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
2230 gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
2234 gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
2236 struct widget *w=(struct widget*)widget->data;
2239 dbg(0,"text='%s'\n", w->text);
2240 if (w->text && strlen(w->text)){
2241 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2242 bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
2248 l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
2249 gui_internal_prune_menu(this, l->data);
2253 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
2258 len=strlen(wm->text);
2259 dbg(1,"len=%d\n", len);
2260 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2261 wm->text[len-1]='\0';
2262 gui_internal_cmd_add_bookmark_do(this, wm);
2268 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
2271 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
2273 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2275 wb=gui_internal_menu(this,_("Add Bookmark"));
2276 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2277 gui_internal_widget_append(wb, w);
2278 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2279 gui_internal_widget_append(w, we);
2280 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2281 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2282 wk->background=this->background;
2283 wk->flags |= flags_expand|flags_fill;
2284 wk->func = gui_internal_cmd_add_bookmark_changed;
2286 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2287 wnext->state |= STATE_SENSITIVE;
2288 wnext->func = gui_internal_cmd_add_bookmark_clicked;
2290 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2291 gui_internal_widget_append(w, wl);
2293 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2294 gui_internal_menu_render(this);
2298 gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
2300 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2302 wb=gui_internal_menu(this,_("Add Bookmark folder"));
2303 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2304 gui_internal_widget_append(wb, w);
2305 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2306 gui_internal_widget_append(w, we);
2307 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2308 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2309 wk->background=this->background;
2310 wk->flags |= flags_expand|flags_fill;
2311 wk->func = gui_internal_cmd_add_bookmark_changed;
2313 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2314 wnext->state |= STATE_SENSITIVE;
2315 wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
2317 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2318 gui_internal_widget_append(w, wl);
2320 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2321 gui_internal_menu_render(this);
2325 gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2327 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2328 char *name=wm->text;
2329 wb=gui_internal_menu(this,_("Rename"));
2330 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2331 gui_internal_widget_append(wb, w);
2332 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2333 gui_internal_widget_append(w, we);
2334 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2335 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2336 wk->background=this->background;
2337 wk->flags |= flags_expand|flags_fill;
2338 wk->func = gui_internal_cmd_add_bookmark_changed;
2340 wk->name=g_strdup(name);
2341 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2342 wnext->state |= STATE_SENSITIVE;
2343 wnext->func = gui_internal_cmd_rename_bookmark_clicked;
2345 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2346 gui_internal_widget_append(w, wl);
2348 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2349 gui_internal_menu_render(this);
2353 gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2357 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2358 bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
2359 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2360 gui_internal_prune_menu(this, l->data);
2364 gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2368 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2369 bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
2370 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2371 gui_internal_prune_menu(this, l->data);
2375 gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2379 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2380 bookmarks_paste_bookmark(mattr.u.bookmarks);
2381 l=g_list_previous(g_list_last(this->root.children));
2382 gui_internal_prune_menu(this, l->data);
2386 gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2390 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2391 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
2392 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2393 gui_internal_prune_menu(this, l->data);
2397 gui_internal_cmd_delete_bookmark_folder(struct gui_priv *this, struct widget *wm, void *data)
2401 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2402 bookmarks_move_up(mattr.u.bookmarks);
2403 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->prefix);
2404 l=g_list_first(this->root.children);
2405 gui_internal_prune_menu(this, l->data);
2409 gui_internal_cmd_load_bookmarks_as_waypoints(struct gui_priv *this, struct widget *wm, void *data)
2413 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
2418 enum projection pro=bookmarks_get_projection(mattr.u.bookmarks);
2421 navit_set_destination(this->nav, NULL, NULL, 0);
2423 bm_count=bookmarks_get_bookmark_count(mattr.u.bookmarks);
2424 pc=g_alloca(bm_count*sizeof(struct pcoord));
2425 bookmarks_item_rewind(mattr.u.bookmarks);
2427 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
2428 if (!item_attr_get(item, attr_label, &attr))
2430 if (item->type == type_bookmark) {
2431 if (item_coord_get(item, &c, 1)) {
2442 navit_set_destinations(this->nav, pc, bm_count, wm->prefix, 1);
2443 if (this->flags & 512) {
2445 follow.type=attr_follow;
2447 navit_set_attr(this->nav, &this->osd_configuration);
2448 navit_set_attr(this->nav, &follow);
2449 navit_zoom_to_route(this->nav, 0);
2454 gui_internal_prune_menu(this, NULL);
2458 gui_internal_cmd_replace_bookmarks_from_waypoints(struct gui_priv *this, struct widget *wm, void *data)
2462 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
2468 if (bookmarks_get_bookmark_count(mattr.u.bookmarks)>0){
2470 bookmarks_item_rewind(mattr.u.bookmarks);
2472 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
2474 if (!item_attr_get(item, attr_label, &attr))
2477 if (item->type == type_bookmark)
2478 bookmarks_delete_bookmark(mattr.u.bookmarks, attr.u.str);
2480 bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
2483 bookmarks_item_rewind(mattr.u.bookmarks);
2485 bm_count=navit_get_destination_count(this->nav);
2486 pc=g_alloca(bm_count*sizeof(struct pcoord));
2487 navit_get_destinations(this->nav, pc, bm_count);
2489 for (i=0; i<bm_count; i++){
2490 desc=g_strdup_printf("%s WP%d", navit_get_destination_description(this->nav, i), i+1);
2491 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2492 bookmarks_add_bookmark(attr.u.bookmarks, &pc[i], desc);
2493 bookmarks_move_down(mattr.u.bookmarks,wm->prefix);
2498 gui_internal_prune_menu(this, NULL);
2502 get_direction(char *buffer, int angle, int mode)
2507 sprintf(buffer,"%d",angle);
2510 if (angle < 69 || angle > 291)
2512 if (angle > 111 && angle < 249)
2514 if (angle > 22 && angle < 158)
2516 if (angle > 202 && angle < 338)
2521 angle=(angle+15)/30;
2524 sprintf(buffer,"%d H", angle);
2529 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2534 enum item_type *types;
2536 static enum item_type selectors_BankTypes[]={type_poi_bank,type_poi_bank, type_poi_atm,type_poi_atm, type_none};
2537 static enum item_type selectors_FuelTypes[]={type_poi_fuel,type_poi_fuel,type_none};
2538 static enum item_type selectors_HotelTypes[]={type_poi_hotel,type_poi_camp_rv,type_poi_camping,type_poi_camping,
2539 type_poi_resort,type_poi_resort,type_poi_motel,type_poi_hostel,type_none};
2540 static enum item_type selectors_RestaurantTypes[]={type_poi_bar,type_poi_picnic,type_poi_burgerking,type_poi_fastfood,
2541 type_poi_restaurant,type_poi_restaurant,type_poi_cafe,type_poi_cafe,type_poi_pub,type_poi_pub,type_none};
2542 static enum item_type selectors_ShoppingTypes[]={type_poi_mall,type_poi_mall,type_poi_shop_grocery,type_poi_shop_grocery,
2543 type_poi_shopping,type_poi_shopping,type_poi_shop_butcher,type_poi_shop_baker,type_poi_shop_fruit,
2544 type_poi_shop_fruit,type_poi_shop_beverages,type_poi_shop_beverages,type_none};
2545 static enum item_type selectors_ServiceTypes[]={type_poi_marina,type_poi_marina,type_poi_hospital,type_poi_hospital,
2546 type_poi_public_utilities,type_poi_public_utilities,type_poi_police,type_poi_autoservice,type_poi_information,
2547 type_poi_information,type_poi_pharmacy,type_poi_pharmacy,type_poi_personal_service,type_poi_repair_service,
2548 type_poi_restroom,type_poi_restroom,type_none};
2549 static enum item_type selectors_ParkingTypes[]={type_poi_car_parking,type_poi_car_parking,type_none};
2550 static enum item_type selectors_LandFeaturesTypes[]={type_poi_land_feature,type_poi_rock,type_poi_dam,type_poi_dam,
2551 type_poi_peak,type_poi_peak,type_none};
2552 static enum item_type selectors_OtherTypes[]={type_point_unspecified,type_poi_land_feature-1,type_poi_rock+1,type_poi_fuel-1,
2553 type_poi_marina+1,type_poi_shopping-1,type_poi_shopping+1,type_poi_car_parking-1,type_poi_car_parking+1,
2554 type_poi_bar-1,type_poi_bank+1,type_poi_dam-1,type_poi_dam+1,type_poi_information-1,type_poi_information+1,
2555 type_poi_mall-1,type_poi_mall+1,type_poi_personal_service-1,type_poi_pharmacy+1,type_poi_repair_service-1,
2556 type_poi_repair_service+1,type_poi_restaurant-1,type_poi_restaurant+1,type_poi_restroom-1,type_poi_restroom+1,
2557 type_poi_shop_grocery-1,type_poi_shop_grocery+1,type_poi_peak-1,type_poi_peak+1,type_poi_motel-1,type_poi_hostel+1,
2558 type_poi_shop_butcher-1,type_poi_shop_baker+1,type_poi_shop_fruit-1,type_poi_shop_fruit+1,type_poi_shop_beverages-1,
2559 type_poi_shop_beverages+1,type_poi_pub-1,type_poi_atm+1,type_line-1,type_none};
2560 /*static enum item_type selectors_UnknownTypes[]={type_point_unkn,type_point_unkn,type_none};*/
2561 struct selector selectors[]={
2562 {"bank","Bank",selectors_BankTypes},
2563 {"fuel","Fuel",selectors_FuelTypes},
2564 {"hotel","Hotel",selectors_HotelTypes},
2565 {"restaurant","Restaurant",selectors_RestaurantTypes},
2566 {"shopping","Shopping",selectors_ShoppingTypes},
2567 {"hospital","Service",selectors_ServiceTypes},
2568 {"parking","Parking",selectors_ParkingTypes},
2569 {"peak","Land Features",selectors_LandFeaturesTypes},
2570 {"unknown","Other",selectors_OtherTypes},
2571 /* {"unknown","Unknown",selectors_UnknownTypes},*/
2576 * Get a utf-8 string, return the same prepared for case insensetive search. Result shoud be g_free()d after use.
2583 r=g_utf8_casefold(s,-1);
2588 * POI search/filtering parameters.
2595 * =1 if selnb is defined, 0 otherwize.
2600 * Index to struct selector selectors[], shows what type of POIs is defined.
2602 unsigned char selnb;
2604 * Page number to display.
2606 unsigned char pagenb;
2608 * Radius (number of 10-kilometer intervals) to search for POIs.
2612 * Should filter phrase be compared to postal address of the POI.
2613 * =1 - address filter, =0 - name filter
2615 unsigned char isAddressFilter;
2617 * Filter string, casefold()ed and divided into substrings at the spaces, which are replaced by ASCII 0*.
2621 * list of pointers to individual substrings of filterstr.
2625 * Number of POIs in this list
2632 * @brief Free poi_param structure.
2634 * @param p reference to the object to be freed.
2637 gui_internal_poi_param_free(void *p)
2639 if(((struct poi_param *)p)->filterstr)
2640 g_free(((struct poi_param *)p)->filterstr);
2641 if(((struct poi_param *)p)->filter)
2642 g_list_free(((struct poi_param *)p)->filter);
2647 * @brief Clone poi_param structure.
2649 * @param p reference to the object to be cloned.
2650 * @return Cloned object reference.
2652 static struct poi_param *
2653 gui_internal_poi_param_clone(struct poi_param *p)
2655 struct poi_param *r=g_new(struct poi_param,1);
2657 memcpy(r,p,sizeof(struct poi_param));
2661 char *last=g_list_last(l)->data;
2662 int len=(last - p->filterstr) + strlen(last)+1;
2663 r->filterstr=g_memdup(p->filterstr,len);
2666 r->filter=g_list_append(r->filter, r->filterstr + ((char*)(l->data) - p->filterstr) );
2673 * @brief Set POIs filter data in poi_param structure.
2674 * @param param poi_param structure with unset filter data.
2675 * @param text filter text.
2678 gui_internal_poi_param_set_filter(struct poi_param *param, char *text)
2682 param->filterstr=removecase(text);
2683 s1=param->filterstr;
2685 s2=g_utf8_strchr(s1,-1,' ');
2688 param->filter=g_list_append(param->filter,s1);
2698 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2699 static void gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data);
2702 static struct widget *
2703 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb)
2705 struct widget *wl,*wb;
2708 //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2709 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
2710 wl->background=this->background;
2712 wl->cols=this->root.w/this->icon_s;
2713 nitems=sizeof(selectors)/sizeof(struct selector);
2714 nrows=nitems/wl->cols + (nitems%wl->cols>0);
2715 wl->h=this->icon_l*nrows;
2716 for (i = 0 ; i < nitems ; i++) {
2717 struct poi_param *p=g_new0(struct poi_param,1);
2724 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2725 image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2726 gui_internal_cmd_pois, p));
2728 wb->data_free=gui_internal_poi_param_free;
2732 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2733 image_new_s(this, "gui_search"), gravity_left_center|orientation_vertical,
2734 gui_internal_cmd_pois_filter, NULL));
2738 gui_internal_widget_pack(this,wl);
2743 * @brief Get icon for given POI type.
2745 * @param this pointer to gui context
2746 * @param type POI type
2747 * @return Pointer to graphics_image object, or NULL if no picture available.
2749 static struct graphics_image * gui_internal_poi_icon(struct gui_priv *this, enum item_type type)
2753 navit_get_attr(this->nav, attr_layout, &layout, NULL);
2754 layer=layout.u.layout->layers;
2756 GList *itemgra=((struct layer *)layer->data)->itemgras;
2758 GList *types=((struct itemgra *)itemgra->data)->type;
2760 if((long)types->data==type) {
2761 GList *element=((struct itemgra *)itemgra->data)->elements;
2763 struct element * el=element->data;
2764 if(el->type==element_icon) {
2765 struct graphics_image *img;
2766 char *icon=g_strdup(el->u.icon.src);
2767 char *dot=g_strrstr(icon,".");
2768 dbg(0,"%s %s\n", item_to_name(type),icon);
2771 img=image_new_xs(this,icon);
2776 element=g_list_next(element);
2779 types=g_list_next(types);
2781 itemgra=g_list_next(itemgra);
2783 layer=g_list_next(layer);
2789 * @brief Widget to display POI item.
2791 * @param this pointer to gui context
2792 * @param center reference to the standing point where angle to be counted from
2793 * @param item POI item reference
2794 * @param c POI coordinates
2795 * @param dist precomputed distance to POI (or -1 if it's not to be displayed)
2796 * @param name POI name
2797 * @return Pointer to new widget.
2799 static struct widget *
2800 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist, char* name)
2802 char distbuf[32]="";
2807 struct graphics_image *icon;
2810 sprintf(distbuf,"%d ", dist/1000);
2812 sprintf(distbuf,"%d.%d ", dist/1000, (dist%1000)/100);
2815 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2821 type=item_to_name(item->type);
2823 icon=gui_internal_poi_icon(this,item->type);
2825 icon=image_new_xs(this,"gui_inactive");
2826 text=g_strdup_printf("%s%s%s %s", distbuf, dirbuf, type, name);
2827 } else if(strlen(name)>0)
2828 text=g_strdup_printf("%s%s%s", distbuf, dirbuf, name);
2830 text=g_strdup_printf("%s%s%s", distbuf, dirbuf, type);
2832 wl=gui_internal_button_new_with_callback(this, text, icon, gravity_left_center|orientation_horizontal|flags_fill, NULL, NULL);
2836 wl->name=g_strdup_printf("%s %s",type,name);
2838 wl->name=g_strdup(type);
2840 wl->func=gui_internal_cmd_position;
2843 wl->state|= STATE_SENSITIVE;
2848 * @brief Get string representation of item address suitable for doing search and for display in POI list.
2850 * @param item reference to item.
2851 * @return Pointer to string representation of address. To be g_free()d after use.
2854 gui_internal_compose_item_address_string(struct item *item)
2856 char *s=g_strdup("");
2858 if(item_attr_get(item, attr_house_number, &attr))
2859 s=g_strjoin(" ",s,attr.u.str,NULL);
2860 if(item_attr_get(item, attr_street_name, &attr))
2861 s=g_strjoin(" ",s,attr.u.str,NULL);
2862 if(item_attr_get(item, attr_street_name_systematic, &attr))
2863 s=g_strjoin(" ",s,attr.u.str,NULL);
2864 if(item_attr_get(item, attr_district_name, &attr))
2865 s=g_strjoin(" ",s,attr.u.str,NULL);
2866 if(item_attr_get(item, attr_town_name, &attr))
2867 s=g_strjoin(" ",s,attr.u.str,NULL);
2868 if(item_attr_get(item, attr_county_name, &attr))
2869 s=g_strjoin(" ",s,attr.u.str,NULL);
2870 if(item_attr_get(item, attr_country_name, &attr))
2871 s=g_strjoin(" ",s,attr.u.str,NULL);
2873 if(item_attr_get(item, attr_address, &attr))
2874 s=g_strjoin(" ",s,"|",attr.u.str,NULL);
2879 gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item)
2881 enum item_type *types;
2882 struct selector *sel = param->sel? &selectors[param->selnb]: NULL;
2883 enum item_type type=item->type;
2886 if (type >= type_line && param->filter==NULL)
2888 if (! sel || !sel->types) {
2892 while (*types != type_none) {
2893 if (item->type >= types[0] && item->type <= types[1]) {
2899 if (param->filter) {
2900 char *long_name, *s;
2902 if (param->isAddressFilter) {
2903 s=gui_internal_compose_item_address_string(item);
2904 } else if (item_attr_get(item, attr_label, &attr)) {
2905 s=g_strdup_printf("%s %s", item_to_name(item->type), attr.u.str);
2907 s=g_strdup(item_to_name(item->type));
2909 long_name=removecase(s);
2911 item_attr_rewind(item);
2913 for(s=long_name,f=param->filter;f && s;f=g_list_next(f)) {
2914 s=strstr(s,f->data);
2917 s=g_utf8_strchr(s,-1,' ');
2934 * @brief Event handler for POIs list "more" element.
2936 * @param this The graphics context.
2937 * @param wm called widget.
2938 * @param data event data.
2941 gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
2943 struct widget *w=g_new0(struct widget,1);
2948 gui_internal_back(this, NULL, NULL);
2949 gui_internal_cmd_pois(this, w, w->data);
2955 * @brief Event to apply POIs text filter.
2957 * @param this The graphics context.
2958 * @param wm called widget.
2959 * @param data event data (pointer to editor widget containg filter text).
2962 gui_internal_cmd_pois_filter_do(struct gui_priv *this, struct widget *wm, void *data)
2964 struct widget *w=data;
2965 struct poi_param *param;
2971 param=gui_internal_poi_param_clone(w->data);
2974 param=g_new0(struct poi_param,1);
2976 param->isAddressFilter=strcmp(wm->name,"AddressFilter")==0;
2978 gui_internal_poi_param_set_filter(param, w->text);
2980 gui_internal_cmd_pois(this,w,param);
2981 gui_internal_poi_param_free(param);
2985 * @brief POIs filter dialog.
2986 * Event to handle '\r' '\n' keys pressed.
2991 gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, void *data)
2995 len=strlen(wm->text);
2996 dbg(1,"len=%d\n", len);
2997 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2998 wm->text[len-1]='\0';
2999 //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?
3006 * @brief POIs filter dialog.
3008 * @param this The graphics context.
3009 * @param wm called widget.
3010 * @param data event data.
3013 gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data)
3015 struct widget *wb, *w, *wr, *wk, *we;
3016 int keyboard_mode=2;
3017 wb=gui_internal_menu(this,"Filter");
3018 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
3019 gui_internal_widget_append(wb, w);
3020 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3021 gui_internal_widget_append(w, wr);
3022 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3023 gui_internal_widget_append(wr, we);
3025 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
3026 wk->state |= STATE_EDIT|STATE_EDITABLE;
3027 wk->func=gui_internal_cmd_pois_filter_changed;
3028 wk->background=this->background;
3029 wk->flags |= flags_expand|flags_fill;
3030 wk->name=g_strdup("POIsFilter");
3032 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3033 wb->state |= STATE_SENSITIVE;
3034 wb->func = gui_internal_cmd_pois_filter_do;
3035 wb->name=g_strdup("NameFilter");
3037 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "post")));
3038 wb->state |= STATE_SENSITIVE;
3039 wb->name=g_strdup("AddressFilter");
3040 wb->func = gui_internal_cmd_pois_filter_do;
3044 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
3045 gui_internal_menu_render(this);
3051 * @brief Do POI search specified by poi_param and display POIs found
3053 * @param this The graphics context.
3054 * @param wm called widget.
3055 * @param data event data, reference to poi_param or NULL.
3058 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
3060 struct map_selection *sel,*selm;
3061 struct coord c,center;
3062 struct mapset_handle *h;
3064 struct map_rect *mr;
3066 struct widget *wi,*w,*w2,*wb, *wtable, *row;
3067 enum projection pro=wm->c.pro;
3068 struct poi_param *param;
3071 struct selector *isel;
3074 // Starting value and increment of count of items to be extracted
3075 const int pagesize = 50;
3076 int maxitem, it = 0, i;
3077 struct item_data *items;
3078 struct fibheap* fh = fh_makekeyheap();
3080 struct table_data *td;
3081 struct widget *wl,*wt;
3083 struct poi_param *paramnew;
3088 param = g_new0(struct poi_param,1);
3092 dist=10000*(param->dist+1);
3093 isel = param->sel? &selectors[param->selnb]: NULL;
3094 pagenb = param->pagenb;
3095 prevdist=param->dist*10000;
3096 maxitem = pagesize*(pagenb+1);
3097 items= g_new0( struct item_data, maxitem);
3100 dbg(0, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i, filterstr = %s, isAddressFilter= %d\n",
3101 param->sel, param->selnb, param->pagenb, param->dist, param->filterstr, param->isAddressFilter);
3103 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
3104 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3105 gui_internal_widget_append(wb, w);
3106 if (!isel && !param->filter)
3107 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
3108 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3109 gui_internal_widget_append(w, w2);
3111 sel=map_selection_rect_new(&wm->c,dist*transform_scale(abs(wm->c.y)+dist*1.5),18);
3114 h=mapset_open(navit_get_mapset(this->nav));
3115 while ((m=mapset_next(h, 1))) {
3116 selm=map_selection_dup_pro(sel, pro, map_projection(m));
3117 mr=map_rect_new(m, selm);
3118 dbg(2,"mr=%p\n", mr);
3120 while ((item=map_rect_get_item(mr))) {
3121 if (gui_internal_cmd_pois_item_selected(param, item) &&
3122 item_coord_get_pro(item, &c, 1, pro) &&
3123 coord_rect_contains(&sel->u.c_rect, &c) &&
3124 (idist=transform_distance(pro, ¢er, &c)) < dist) {
3125 struct item_data *data;
3129 if (item->type==type_house_number) {
3130 label=gui_internal_compose_item_address_string(item);
3131 } else if (item_attr_get(item, attr_label, &attr)) {
3132 label=g_strdup(attr.u.str);
3133 // Buildings which label is equal to addr:housenumber value
3134 // are duplicated by item_house_number. Don't include such
3135 // buildings into the list. This is true for OSM maps created with
3136 // maptool patched with #859 latest patch.
3137 // FIXME: For non-OSM maps, we probably would better don't skip these items.
3138 if(item->type==type_poly_building && item_attr_get(item, attr_house_number, &attr) ) {
3139 if(strcmp(label,attr.u.str)==0) {
3150 data = fh_extractmin(fh);
3151 g_free(data->label);
3154 data = &items[it++];
3160 // Key expression is a workaround to fight
3161 // probable heap collisions when two objects
3162 // are at the same distance. But it destroys
3163 // right order of POIs 2048 km away from cener
3164 // and if table grows more than 1024 rows.
3165 fh_insertkey(fh, -((idist<<10) + cnt++), data);
3167 dist = (-fh_minkey(fh))>>10;
3170 map_rect_destroy(mr);
3172 map_selection_destroy(selm);
3174 map_selection_destroy(sel);
3177 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3180 gui_internal_widget_append(w2,wtable);
3182 // Move items from heap to the table
3185 int key = fh_minkey(fh);
3186 struct item_data *data = fh_extractmin(fh);
3189 dbg(2, "Empty heap: maxitem = %i, it = %i, dist = %i\n", maxitem, it, dist);
3192 dbg(2, "dist1: %i, dist2: %i\n", data->dist, (-key)>>10);
3193 if(i==(it-pagesize*pagenb) && data->dist>prevdist)
3194 prevdist=data->dist;
3195 wi=gui_internal_cmd_pois_item(this, ¢er, &data->item, &data->c, data->dist, data->label);
3199 wi->background=this->background;
3200 row = gui_internal_widget_table_row_new(this,
3203 | orientation_horizontal);
3204 gui_internal_widget_append(row,wi);
3205 row->datai=data->dist;
3206 gui_internal_widget_prepend(wtable,row);
3213 // Add an entry for more POI
3214 row = gui_internal_widget_table_row_new(this,
3217 | orientation_horizontal);
3218 row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
3219 gui_internal_widget_append(wtable,row);
3220 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3221 gui_internal_widget_append(row,wl);
3222 if (it == maxitem) {
3223 paramnew=gui_internal_poi_param_clone(param);
3226 snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (paramnew->pagenb+1)*pagesize);
3227 wt=gui_internal_label_new(this, buffer);
3228 gui_internal_widget_append(wl, wt);
3229 wt->func=gui_internal_cmd_pois_more;
3231 wt->data_free=gui_internal_poi_param_free;
3232 wt->state |= STATE_SENSITIVE;
3235 static int dist[]={1,5,10,0};
3236 wt=gui_internal_label_new(this, "Set distance to");
3237 gui_internal_widget_append(wl, wt);
3238 for(i=0;dist[i];i++) {
3239 paramnew=gui_internal_poi_param_clone(param);
3240 paramnew->dist+=dist[i];
3242 snprintf(buffer, sizeof(buffer), " %i ", 10*(paramnew->dist+1));
3243 wt=gui_internal_label_new(this, buffer);
3244 gui_internal_widget_append(wl, wt);
3245 wt->func=gui_internal_cmd_pois_more;
3247 wt->data_free=gui_internal_poi_param_free;
3248 wt->state |= STATE_SENSITIVE;
3251 wt=gui_internal_label_new(this, "km.");
3252 gui_internal_widget_append(wl, wt);
3255 // Rendering now is needed to have table_data->bottomrow filled in.
3256 gui_internal_menu_render(this);
3258 if(td->bottom_row!=NULL)
3261 while(((struct widget*)td->bottom_row->data)->datai<=prevdist
3262 && (td->next_button->state & STATE_SENSITIVE))
3264 gui_internal_table_button_next(this, td->next_button, NULL);
3267 int firstrow=g_list_index(wtable->children, td->top_row->data);
3268 while(firstrow>=0) {
3269 int currow=g_list_index(wtable->children, td->bottom_row->data) - firstrow;
3271 dbg(0,"Can't find bottom row in children list. Stop paging.\n");
3274 if(currow>=param->count)
3276 if(!(td->next_button->state & STATE_SENSITIVE)) {
3277 dbg(0,"Reached last page but item %i not found. Stop paging.\n",param->count);
3280 gui_internal_table_button_next(this, td->next_button, NULL);
3284 gui_internal_menu_render(this);
3290 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
3292 if (wm->item.type != type_none) {
3293 enum item_type type;
3294 if (wm->item.type < type_line)
3295 type=type_selected_point;
3296 else if (wm->item.type < type_area)
3297 type=type_selected_point;
3299 type=type_selected_area;
3300 graphics_clear_selection(this->gra, NULL);
3301 graphics_add_selection(this->gra, &wm->item, type, NULL);
3303 navit_set_center(this->nav, &wm->c, 1);
3304 gui_internal_prune_menu(this, NULL);
3309 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
3311 struct widget *w,*wb;
3312 struct map_rect *mr;
3318 text=g_strdup_printf("Attribute %s",wm->name);
3319 wb=gui_internal_menu(this, text);
3321 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3322 gui_internal_widget_append(wb, w);
3323 mr=map_rect_new(wm->item.map, NULL);
3324 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3325 for (i = 0 ; i < wm->datai ; i++) {
3326 item_attr_get(item, attr_any, &attr);
3328 if (item_attr_get(item, attr_any, &attr)) {
3330 switch (attr.type) {
3331 case attr_osm_nodeid:
3332 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
3334 case attr_osm_wayid:
3335 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
3337 case attr_osm_relationid:
3338 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
3344 gui_internal_widget_append(w,
3345 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3346 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3347 gui_internal_cmd_view_in_browser, NULL));
3351 map_rect_destroy(mr);
3352 gui_internal_menu_render(this);
3356 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
3358 struct widget *w,*wb;
3359 struct map_rect *mr;
3365 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3366 wb=gui_internal_menu(this, "Attributes");
3367 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3368 gui_internal_widget_append(wb, w);
3369 mr=map_rect_new(wm->item.map, NULL);
3370 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3371 dbg(0,"item=%p\n", item);
3373 text=g_strdup_printf("%s:%s", _("Item type"), item_to_name(item->type));
3374 gui_internal_widget_append(w,
3375 wb=gui_internal_button_new(this, text,
3376 NULL, gravity_left_center|orientation_horizontal|flags_fill));
3377 wb->name=g_strdup(text);
3380 while(item_attr_get(item, attr_any, &attr)) {
3382 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attrtxt=attr_to_text(&attr, wm->item.map, 1));
3384 gui_internal_widget_append(w,
3385 wb=gui_internal_button_new_with_callback(this, text,
3386 NULL, gravity_left_center|orientation_horizontal|flags_fill,
3387 gui_internal_cmd_view_attribute_details, NULL));
3388 wb->name=g_strdup(text);
3394 map_rect_destroy(mr);
3395 gui_internal_menu_render(this);
3399 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
3401 struct map_rect *mr;
3407 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3408 mr=map_rect_new(wm->item.map, NULL);
3409 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3410 dbg(0,"item=%p\n", item);
3412 while(item_attr_get(item, attr_url_local, &attr)) {
3414 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
3417 map_rect_destroy(mr);
3419 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
3425 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
3433 * @brief Event to transfer search results to a map.
3435 * @param this The graphics context.
3436 * @param wm called widget.
3437 * @param data event data (pointer to the table widget containing results, or NULL if results map is only have to be cleaned).
3440 gui_internal_cmd_results_to_map(struct gui_priv *this, struct widget *wm, void *data)
3445 struct map_selection sel;
3446 struct map_rect *mr;
3449 struct coord_rect r;
3453 ms=navit_get_mapset(this->nav);
3458 map=mapset_get_map_by_name(ms, "search_results");
3460 struct attr *attrs[10], attrmap;
3461 enum attr_type types[]={attr_position_longitude,attr_position_latitude,attr_label,attr_none};
3464 attrs[0]=g_new0(struct attr,1);
3465 attrs[0]->type=attr_type;
3466 attrs[0]->u.str="csv";
3468 attrs[1]=g_new0(struct attr,1);
3469 attrs[1]->type=attr_name;
3470 attrs[1]->u.str="search_results";
3472 attrs[2]=g_new0(struct attr,1);
3473 attrs[2]->type=attr_charset;
3474 attrs[2]->u.str="utf-8";
3476 attrs[3]=g_new0(struct attr,1);
3477 attrs[3]->type=attr_item_type;
3478 attrs[3]->u.num=type_found_item;
3480 attrs[4]=g_new0(struct attr,1);
3481 attrs[4]->type=attr_attr_types;
3482 attrs[4]->u.attr_types=types;
3485 attrmap.type=attr_map;
3486 map=attrmap.u.map=map_new(NULL,attrs);
3488 mapset_add_attr(ms,&attrmap);
3490 for(i=0;attrs[i];i++)
3500 sel.range.min=type_none;
3501 sel.range.max=type_tec_common;
3504 mr = map_rect_new(map, NULL);
3510 while((item = map_rect_get_item(mr))!=NULL) {
3511 item_type_set(item,type_none);
3514 this->results_map_population=0;
3516 /* Find the table to pupulate the map */
3517 for(w=data; w && w->type!=widget_table;w=w->parent);
3520 map_rect_destroy(mr);
3521 dbg(1,"Can't find the results table - only map clean up is done.\n");
3525 /* Populate the map with search results*/
3526 for(l=w->children, count=0;l;l=g_list_next(l)) {
3527 struct widget *wr=l->data;
3528 if(wr->type==widget_table_row) {
3529 struct widget *wi=wr->children->data;
3533 dbg(0,"%s\n",wi->name);
3534 it=map_rect_create_item(mr,type_found_item);
3540 item_coord_set(it, &c, 1, change_mode_modify);
3543 item_attr_set(it, &a, change_mode_modify);
3547 coord_rect_extend(&r,&c);
3551 map_rect_destroy(mr);
3554 a.type=attr_orientation;
3556 navit_set_attr(this->nav,&a);
3557 navit_zoom_to_rect(this->nav,&r);
3558 gui_internal_prune_menu(this, NULL);
3559 this->results_map_population=count;
3563 * @brief Event to remove search results from the a map.
3565 * @param this The graphics context.
3566 * @param wm called widget.
3567 * @param data event data
3570 gui_internal_cmd_results_map_clean(struct gui_priv *this, struct widget *wm, void *data)
3572 gui_internal_cmd_results_to_map(this,wm,NULL);
3573 gui_internal_prune_menu(this, NULL);
3574 navit_draw(this->nav);
3578 /* meaning of the bits in "flags":
3580 * 2: "House numbers"
3581 * 4: "View in Browser", "View Attributes"
3584 * 32: "Add as bookm."
3586 * 128: "View on Map"
3587 * 256: POIs around this point, "Drop search results from the map"
3588 * 512: "Cut/Copy... bookmark"
3589 * 1024: "Jump to attributes of top item within this->radius pixels of this point (implies flags|=256)"
3590 * 2048: "Show search results on the map"
3591 * TODO define constants for these values
3594 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)
3596 struct widget *wb,*w,*wtable,*row,*wc,*wbc,*wclosest=NULL;
3606 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3607 transform_to_geo(pc.pro, &c, &g);
3610 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
3613 pc.pro=attr.u.projection;
3614 transform_from_geo(pc.pro, &g, &c);
3620 wb=gui_internal_menu(this, name);
3621 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3622 gui_internal_widget_append(wb, w);
3623 coord=coordinates(&pc, ' ');
3624 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
3626 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3627 gui_internal_widget_append(w,wtable);
3629 if ((flags & 1) && wm) {
3630 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3631 gui_internal_widget_append(row,
3632 wc=gui_internal_button_new_with_callback(this, _("Streets"),
3633 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3634 gui_internal_search_street_in_town, wm));
3636 wc->selection_id=wm->selection_id;
3638 if ((flags & 2) && wm) {
3639 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3640 gui_internal_widget_append(row,
3641 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
3642 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3643 gui_internal_search_house_number_in_street, wm));
3645 wc->selection_id=wm->selection_id;
3647 if ((flags & 4) && wm) {
3648 struct map_rect *mr;
3651 mr=map_rect_new(wm->item.map, NULL);
3652 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3654 if (item_attr_get(item, attr_description, &attr))
3655 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
3656 if (item_attr_get(item, attr_url_local, &attr)) {
3657 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3658 gui_internal_widget_append(row,
3659 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3660 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3661 gui_internal_cmd_view_in_browser, NULL));
3664 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3665 gui_internal_widget_append(row,
3666 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
3667 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3668 gui_internal_cmd_view_attributes, NULL));
3671 map_rect_destroy(mr);
3674 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3675 gui_internal_widget_append(row,
3676 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
3677 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3678 gui_internal_cmd_set_destination, g_strdup(name)));
3679 wbc->data_free=g_free_func;
3684 struct attr vehicle, source;
3686 if (navit_get_attr(this->nav, attr_vehicle, &vehicle, NULL) && vehicle.u.vehicle &&
3687 !(vehicle_get_attr(vehicle.u.vehicle, attr_source, &source, NULL) && source.u.str && !strcmp("demo://",source.u.str)))
3690 text=deactivate? _("Set as position (and deactivate vehicle)") : _("Set as position");
3692 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3693 gui_internal_widget_append(row,
3694 wbc=gui_internal_button_new_with_callback(this, text,
3695 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3696 gui_internal_cmd_set_position, (void*)deactivate));
3700 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3701 gui_internal_widget_append(row,
3702 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
3703 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3704 gui_internal_cmd_add_bookmark2, g_strdup(name)));
3705 wbc->data_free=g_free_func;
3709 //POIs are not operational under MSVC yet
3711 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3712 gui_internal_widget_append(row,
3713 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
3714 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3715 gui_internal_cmd_pois, NULL));
3718 #endif /* _MSC_VER */
3720 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3721 gui_internal_widget_append(row,
3722 gui_internal_button_new(this, "Add to tour",
3723 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
3726 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3727 gui_internal_widget_append(row,
3728 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
3729 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3730 gui_internal_cmd_view_on_map, NULL));
3732 if ((flags & 4) && wm)
3735 wbc->item.type=type_none;
3737 if(flags & 256 && this->results_map_population) {
3738 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3739 gui_internal_widget_append(row,
3740 wbc=gui_internal_button_new_with_callback(this, _("Remove search results from the map"),
3741 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3742 gui_internal_cmd_results_map_clean, NULL));
3746 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3747 gui_internal_widget_append(row,
3748 wbc=gui_internal_button_new_with_callback(this, _("Show results on the map"),
3749 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3750 gui_internal_cmd_results_to_map, NULL));
3753 if ((flags & 256) || (flags & 1024)) {
3754 struct displaylist_handle *dlh;
3755 struct displaylist *display;
3758 struct transformation *trans;
3761 struct map_selection *sel;
3767 trans=navit_get_trans(this->nav);
3768 transform(trans,pc.pro,&c,&p,1,0,0,0);
3769 display=navit_get_displaylist(this->nav);
3770 dlh=graphics_displaylist_open(display);
3771 sel=displaylist_get_selection(display);
3772 l=displaylist_get_clicked_list(display, &p, this->radius);
3773 for(ll=l;ll;ll=g_list_next(ll)) {
3774 struct displayitem *di;
3776 struct map_rect *mr;
3779 di=(struct displayitem*)ll->data;
3780 item=graphics_displayitem_get_item(di);
3782 mr=map_rect_new(item->map, sel);
3783 itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
3785 if (item_attr_get(itemo, attr_label, &attr)) {
3786 label=map_convert_string(itemo->map, attr.u.str);
3787 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
3788 map_convert_free(label);
3790 text=g_strdup_printf("%s", item_to_name(item->type));
3791 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3792 gui_internal_widget_append(row, wc=gui_internal_cmd_pois_item(this, NULL, itemo, NULL, -1, text));
3795 wc->name=g_strdup(text);
3798 map_rect_destroy(mr);
3804 map_selection_destroy(sel);
3805 graphics_displaylist_close(dlh);
3808 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3809 gui_internal_widget_append(row,
3810 wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
3811 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3812 gui_internal_cmd_cut_bookmark, NULL));
3813 wbc->text=g_strdup(wm->text);
3814 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3815 gui_internal_widget_append(row,
3816 wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
3817 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3818 gui_internal_cmd_copy_bookmark, NULL));
3819 wbc->text=g_strdup(wm->text);
3820 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3821 gui_internal_widget_append(row,
3822 wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
3823 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3824 gui_internal_cmd_rename_bookmark, NULL));
3825 wbc->text=g_strdup(wm->text);
3826 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3827 gui_internal_widget_append(row,
3828 wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
3829 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3830 gui_internal_cmd_paste_bookmark, NULL));
3831 gui_internal_widget_append(wtable,row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
3832 gui_internal_widget_append(row,
3833 wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
3834 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3835 gui_internal_cmd_delete_bookmark, NULL));
3836 wbc->text=g_strdup(wm->text);
3839 gui_internal_menu_render(this);
3841 if((flags & 1024) && wclosest)
3842 gui_internal_cmd_view_attributes(this,wclosest,wclosest->data);
3846 /* wm->data: 0 Nothing special
3854 8 Former destination
3855 9 Item from the POI list
3859 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
3862 switch ((long) wm->data) {
3864 flags=8|16|32|64|128|256;
3867 flags=8|16|32|64|256;
3870 flags=4|8|16|32|64|128;
3873 flags=1|8|16|32|64|128|2048;
3874 flags &= this->flags_town;
3877 gui_internal_search_town_in_country(this, wm);
3880 flags=2|8|16|32|64|128|2048;
3881 flags &= this->flags_street;
3884 flags=8|16|32|64|128|2048;
3885 flags &= this->flags_house_number;
3888 flags=8|16|64|128|512;
3891 flags=8|16|32|64|128;
3894 flags=4|8|16|32|64|128|2048;
3901 gui_internal_search_house_number_in_street(this, wm, NULL);
3904 gui_internal_cmd_set_destination(this, wm, NULL);
3907 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
3911 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3913 char *name=_("Position");
3919 if (!ATTR_IS_COORD_GEO(in[0]->type))
3921 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3923 if (in[2] && ATTR_IS_INT(in[2]->type))
3926 dbg(1,"flags=0x%x\n",flags);
3927 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
3931 gui_internal_cmd2_pois(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3934 struct poi_param *param;
3941 if (!ATTR_IS_COORD_GEO(in[0]->type))
3943 if (!navit_get_attr(this->nav, attr_projection, &pro, NULL))
3945 w=g_new0(struct widget,1);
3946 param=g_new0(struct poi_param,1);
3947 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3948 gui_internal_poi_param_set_filter(param, in[1]->u.str);
3949 if (in[2] && ATTR_IS_INT(in[2]->type))
3950 param->isAddressFilter=in[2]->u.num;
3953 transform_from_geo(pro.u.projection,in[0]->u.coord_geo,&c);
3956 w->c.pro=pro.u.projection;
3957 gui_internal_cmd_pois(this, w, param);
3959 gui_internal_poi_param_free(param);
3963 gui_internal_cmd2_refresh(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3965 char *href=g_strdup(this->href);
3966 gui_internal_html_load_href(this, href, 1);
3972 * The "Bookmarks" section of the OSD
3977 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
3979 struct attr attr,mattr;
3981 char *label_full,*prefix=0;
3982 int plen=0,hassub,found=0;
3983 struct widget *wb,*w,*wbm;
3985 struct widget *tbl, *row;
3988 prefix=g_strdup(data);
3990 if (wm && wm->prefix)
3991 prefix=g_strdup(wm->prefix);
3994 plen=strlen(prefix);
3996 gui_internal_prune_menu_count(this, 1, 0);
3997 wb=gui_internal_menu(this, _("Bookmarks"));
3998 wb->background=this->background;
3999 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4000 //w->spy=this->spacing*3;
4001 gui_internal_widget_append(wb, w);
4003 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
4005 bookmarks_move_root(mattr.u.bookmarks);
4007 if (!strcmp(prefix,"..")) {
4008 bookmarks_move_up(mattr.u.bookmarks);
4010 prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
4012 plen=strlen(prefix);
4017 bookmarks_move_down(mattr.u.bookmarks,prefix);
4020 // "Back" button, when inside a bookmark folder
4023 wbm=gui_internal_button_new_with_callback(this, "..",
4024 image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
4025 gui_internal_cmd_bookmarks, NULL);
4026 wbm->prefix=g_strdup("..");
4027 gui_internal_widget_append(w, wbm);
4029 // load bookmark folder as Waypoints, if any
4030 if (bookmarks_get_bookmark_count(mattr.u.bookmarks) > 0){
4031 wbm=gui_internal_button_new_with_callback(this, _("Bookmarks as Waypoints"),
4032 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4033 gui_internal_cmd_load_bookmarks_as_waypoints, NULL);
4034 wbm->prefix=g_strdup(prefix);
4035 gui_internal_widget_append(w, wbm);
4038 // save Waypoints in bookmark folder, if route exists
4039 if (navit_get_destination_count(this->nav) > 0){
4040 if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0){
4041 wbm=gui_internal_button_new_with_callback(this, _("Save Waypoints"),
4042 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4043 gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
4045 wbm=gui_internal_button_new_with_callback(this, _("Replace Waypoints"),
4046 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4047 gui_internal_cmd_replace_bookmarks_from_waypoints, NULL);
4049 wbm->prefix=g_strdup(prefix);
4050 gui_internal_widget_append(w, wbm);
4053 // delete empty folder
4054 if (bookmarks_get_bookmark_count(mattr.u.bookmarks)==0){
4055 gui_internal_widget_append(w,
4056 wbm=gui_internal_button_new_with_callback(this, _("Delete Folder"),
4057 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4058 gui_internal_cmd_delete_bookmark_folder, NULL));
4059 wbm->prefix=g_strdup(prefix);
4065 // Adds the Bookmark folders
4066 wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
4067 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4068 gui_internal_cmd_add_bookmark_folder2, NULL);
4069 gui_internal_widget_append(w, wbm);
4071 // Pastes the Bookmark
4072 wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
4073 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
4074 gui_internal_cmd_paste_bookmark, NULL);
4075 gui_internal_widget_append(w, wbm);
4077 bookmarks_item_rewind(mattr.u.bookmarks);
4079 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4080 gui_internal_widget_append(w,tbl);
4082 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
4083 if (!item_attr_get(item, attr_label, &attr)) continue;
4084 label_full=attr.u.str;
4085 dbg(0,"full_labled: %s\n",label_full);
4087 // hassub == 1 if the item type is a sub-folder
4088 if (item->type == type_bookmark_folder) {
4094 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
4095 gui_internal_widget_append(tbl, row);
4096 wbm=gui_internal_button_new_with_callback(this, label_full,
4097 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
4098 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
4100 gui_internal_widget_append(row,wbm);
4101 if (item_coord_get(item, &c, 1)) {
4104 wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
4105 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
4106 wbm->text=g_strdup(label_full);
4108 wbm->data=(void*)7;//Mark us as a bookmark
4110 wbm->prefix=g_strdup(label_full);
4112 gui_internal_widget_destroy(this, row);
4120 gui_internal_check_exit(this);
4122 gui_internal_menu_render(this);
4126 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4129 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
4132 gui_internal_cmd_bookmarks(this, NULL, str);
4137 gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4139 struct widget *wb,*w,*wbm,*tbl=NULL;
4140 struct map *formerdests;
4141 struct map_rect *mr_formerdests;
4145 enum projection projection;
4147 gui_internal_prune_menu_count(this, 1, 0);
4148 wb=gui_internal_menu(this, _("Former Destinations"));
4149 wb->background=this->background;
4151 w=gui_internal_box_new(this,
4152 gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4153 w->spy=this->spacing*2;
4154 gui_internal_widget_append(wb, w);
4156 formerdests=read_former_destinations_from_file();
4157 mr_formerdests=map_rect_new(formerdests, NULL);
4158 projection = map_projection(formerdests);
4159 while ((item=map_rect_get_item(mr_formerdests))) {
4162 if (!item_attr_get(item, attr_label, &attr)) continue;
4164 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand | orientation_vertical,1);
4165 gui_internal_widget_append(w,tbl);
4167 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_vertical);
4168 gui_internal_widget_prepend(tbl, row);
4169 label_full=attr.u.str;
4170 wbm=gui_internal_button_new_with_callback(this, label_full,
4171 image_new_xs(this, "gui_active"),
4172 gravity_left_center|orientation_horizontal|flags_fill,
4173 gui_internal_cmd_position, NULL);
4174 gui_internal_widget_append(row,wbm);
4175 if (item_coord_get(item, &c, 1)) {
4178 wbm->c.pro=projection;
4179 wbm->name=g_strdup(label_full);
4180 wbm->text=g_strdup(label_full);
4181 wbm->data=(void*)8; //Mark us as a former destination
4182 wbm->prefix=g_strdup(label_full);
4186 wbm=gui_internal_text_new(this, _("- No former destinations available -"),
4187 gravity_left_center|orientation_horizontal|flags_fill);
4188 gui_internal_widget_append(w, wbm);
4190 gui_internal_menu_render(this);
4191 map_rect_destroy(mr_formerdests);
4195 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy);
4197 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
4199 struct widget *wi,*menu,*search_list;
4203 menu=g_list_last(this->root.children)->data;
4204 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
4206 /* select first item of the searchlist */
4207 if (*key == NAVIT_KEY_RETURN && (search_list=gui_internal_menu_data(this)->search_list)) {
4208 GList *l=search_list->children;
4210 gui_internal_highlight_do(this, l->data);
4212 } else if (*key == NAVIT_KEY_BACKSPACE) {
4213 dbg(0,"backspace\n");
4214 if (wi->text && wi->text[0]) {
4215 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
4217 text=g_strdup_printf("%s ", wi->text);
4220 if (wi->state & STATE_CLEAR) {
4221 dbg(0,"wi->state=0x%x\n", wi->state);
4224 wi->state &= ~STATE_CLEAR;
4225 dbg(0,"wi->state=0x%x\n", wi->state);
4227 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
4231 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
4232 gui_internal_widget_render(this, wi);
4237 wi->func(this, wi, wi->data);
4239 gui_internal_widget_render(this, wi);
4245 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
4247 struct menu_data *md=gui_internal_menu_data(this);
4248 gui_internal_keypress_do(this, (char *) wm->data);
4249 // Switch to lowercase after the first key is pressed
4250 if (md->keyboard_mode == 2) // Latin
4251 gui_internal_keyboard_do(this, md->keyboard, 10);
4252 if (md->keyboard_mode == 26) // Umlaut
4253 gui_internal_keyboard_do(this, md->keyboard, 34);
4254 if ((md->keyboard_mode & ~7) == 40) // Russian/Ukrainian/Belorussian
4255 gui_internal_keyboard_do(this, md->keyboard, 48);
4259 gui_internal_search_idle_end(struct gui_priv *this)
4262 event_remove_idle(this->idle);
4265 if (this->idle_cb) {
4266 callback_destroy(this->idle_cb);
4272 postal_str(struct search_list_result *res, int level)
4275 if (res->town->common.postal)
4276 ret=res->town->common.postal;
4277 if (res->town->common.postal_mask)
4278 ret=res->town->common.postal_mask;
4281 if (res->street->common.postal)
4282 ret=res->street->common.postal;
4283 if (res->street->common.postal_mask)
4284 ret=res->street->common.postal_mask;
4287 if (res->house_number->common.postal)
4288 ret=res->house_number->common.postal;
4289 if (res->house_number->common.postal_mask)
4290 ret=res->house_number->common.postal_mask;
4295 district_str(struct search_list_result *res, int level)
4298 if (res->town->common.district_name)
4299 ret=res->town->common.district_name;
4302 if (res->street->common.district_name)
4303 ret=res->street->common.district_name;
4306 if (res->house_number->common.district_name)
4307 ret=res->house_number->common.district_name;
4312 town_str(struct search_list_result *res, int level, int flags)
4314 char *town=res->town->common.town_name;
4315 char *district=district_str(res, level);
4316 char *postal=postal_str(res, level);
4317 char *postal_sep=" ";
4318 char *district_begin=" (";
4319 char *district_end=")";
4320 char *county_sep = ", Co. ";
4321 char *county = res->town->common.county_name;
4323 postal_sep=postal="";
4324 if (!district || (flags & 1))
4325 district_begin=district_end=district="";
4327 county_sep=county="";
4329 return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
4332 static int gui_internal_search_cmp(gconstpointer _a, gconstpointer _b)
4334 struct widget *a=(struct widget *)_a, *b=(struct widget *)_b;
4338 if((!a || a->type!=widget_table_row || !a->text) && (!b || b->type!=widget_table_row || !b->text))
4340 if(!a || a->type!=widget_table_row || !a->text)
4342 if(!b || b->type!=widget_table_row || !b->text)
4344 r=a->datai-b->datai;
4349 sa=removecase(a->text);
4350 sb=removecase(b->text);
4358 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
4360 char *text=NULL,*text2=NULL,*name=NULL;
4361 struct search_list_result *res;
4363 struct item *item=NULL;
4365 static char possible_keys[256]="";
4366 struct widget *wi=NULL;
4369 res=search_list_get_result(this->sl);
4371 gchar* trunk_name = NULL;
4373 struct widget *menu=g_list_last(this->root.children)->data;
4374 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
4377 if (! strcmp(wm_name,"Town"))
4378 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
4379 if (! strcmp(wm_name,"Street"))
4381 name=res->street->name;
4383 trunk_name = g_strrstr(name, wi->text);
4389 char next_char = trunk_name[strlen(wi->text)];
4391 int len = strlen(possible_keys);
4392 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
4393 if (i==len || !len) {
4394 possible_keys[len]=trunk_name[strlen(wi->text)];
4395 possible_keys[len+1]='\0';
4397 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
4400 dbg(0, "Unable to find widget");
4405 struct menu_data *md;
4406 gui_internal_search_idle_end(this);
4408 md=gui_internal_menu_data(this);
4409 if (md && md->keyboard && !(this->flags & 2048)) {
4410 GList *lk=md->keyboard->children;
4411 graphics_draw_mode(this->gra, draw_mode_begin);
4413 struct widget *child=lk->data;
4414 GList *lk2=child->children;
4416 struct widget *child_=lk2->data;
4417 lk2=g_list_next(lk2);
4418 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
4419 if (strlen(possible_keys) == 0)
4420 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
4421 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
4422 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
4424 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
4426 gui_internal_widget_render(this,child_);
4431 gui_internal_widget_render(this,md->keyboard);
4432 graphics_draw_mode(this->gra, draw_mode_end);
4435 possible_keys[0]='\0';
4439 if (! strcmp(wm_name,"Country")) {
4440 name=res->country->name;
4441 item=&res->country->common.item;
4442 text=g_strdup_printf("%s", res->country->name);
4444 if (! strcmp(wm_name,"Town")) {
4445 item=&res->town->common.item;
4446 name=res->town->common.town_name;
4447 text=town_str(res, 1, 0);
4449 if (! strcmp(wm_name,"Street")) {
4450 name=res->street->name;
4451 item=&res->street->common.item;
4452 text=g_strdup(res->street->name);
4453 text2=town_str(res, 2, 1);
4455 if (! strcmp(wm_name,"House number")) {
4456 name=res->house_number->house_number;
4457 text=g_strdup_printf("%s %s", res->street->name, name);
4458 text2=town_str(res, 3, 0);
4460 dbg(1,"res->country->flag=%s\n", res->country->flag);
4461 wr=gui_internal_widget_table_row_new(this, gravity_left|orientation_horizontal|flags_fill);
4464 wr->text=g_strdup(text);
4465 gui_internal_widget_insert_sorted(search_list, wr, gui_internal_search_cmp);
4466 gui_internal_widget_append(wr,
4467 wc=gui_internal_button_new_with_callback(this, text,
4468 image_new_xs(this, res->country->flag),
4469 gravity_left_center|orientation_horizontal|flags_fill,
4470 gui_internal_cmd_position, param));
4473 wr->text=g_strdup_printf("%s %s",text,text2);
4475 if (! strcmp(wm_name,"House number") && !res->street->name) {
4479 dbg(0,"search text widget is NULL\n");
4480 if(wi && strlen(name)==strlen(wi->text)) {
4481 dbg(1,"xact %s %s\n",name, wi->text);
4484 dbg(1,"not xact %s %s\n",name, wi->text);
4488 gui_internal_widget_insert_sorted(search_list, wr, gui_internal_search_cmp);
4490 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4491 gui_internal_widget_append(wr, wc);
4492 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
4493 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
4494 gui_internal_widget_append(wc, wb);
4495 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
4496 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
4497 wc->func=gui_internal_cmd_position;
4499 wc->state |= STATE_SENSITIVE;
4500 wc->speech=g_strdup(text);
4502 wc->name=g_strdup(name);
4505 wc->selection_id=res->id;
4508 gui_internal_widget_pack(this, search_list);
4509 l=g_list_last(this->root.children);
4510 graphics_draw_mode(this->gra, draw_mode_begin);
4511 gui_internal_widget_render(this, l->data);
4512 graphics_draw_mode(this->gra, draw_mode_end);
4518 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
4520 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
4521 this->idle=event_add_idle(50,this->idle_cb);
4522 callback_call_0(this->idle_cb);
4528 * @param wm The widget that generated the event for the search changed,
4529 * if this was generated by a key on the virtual keyboard then
4530 * wm is the key button widget.
4533 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
4536 struct widget *search_list=gui_internal_menu_data(this)->search_list;
4537 void *param=(void *)3;
4540 gui_internal_widget_table_clear(this, search_list);
4542 if (! strcmp(wm->name,"Country"))
4544 if (! strcmp(wm->name,"Street"))
4546 if (! strcmp(wm->name,"House number"))
4548 dbg(0,"%s now '%s'\n", wm->name, wm->text);
4550 gui_internal_search_idle_end(this);
4551 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
4552 struct attr search_attr;
4555 if (! strcmp(wm->name,"Country"))
4556 search_attr.type=attr_country_all;
4557 if (! strcmp(wm->name,"Town"))
4558 search_attr.type=attr_town_or_district_name;
4559 if (! strcmp(wm->name,"Street"))
4560 search_attr.type=attr_street_name;
4561 if (! strcmp(wm->name,"House number"))
4562 search_attr.type=attr_house_number;
4563 search_attr.u.str=wm->text;
4564 search_list_search(this->sl, &search_attr, 1);
4565 gui_internal_search_idle_start(this, wm->name, search_list, param);
4567 l=g_list_last(this->root.children);
4568 gui_internal_widget_render(this, l->data);
4571 static struct widget *
4572 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)
4575 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
4576 NULL, gravity_center|orientation_vertical, func, data));
4577 wk->data_free=data_free;
4578 wk->background=this->background;
4588 static struct widget *
4589 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
4591 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
4594 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
4597 // A list of availiable keyboard modes.
4598 struct gui_internal_keyb_mode {
4599 char title[16]; // Label to be displayed on keys that switch to it
4600 int font; // Font size of label
4601 int case_mode; // Mode to switch to when case CHANGE() key is pressed.
4602 int umlaut_mode; // Mode to switch to when UMLAUT() key is pressed.
4603 } gui_internal_keyb_modes[]= {
4604 /* 0*/ {"ABC", 2, 8, 24},
4605 /* 8*/ {"abc", 2, 0, 32},
4606 /*16*/ {"123", 2, 0, 24},
4607 /*24*/ {"ÄÖÜ", 2, 40, 0},
4608 /*32*/ {"äöü", 2, 32, 8},
4609 /*40*/ {"АБВ", 2, 48, 0},
4610 /*48*/ {"абв", 2, 40, 8}
4614 // Some macros that make the keyboard layout easier to visualise in
4615 // the source code. The macros are #undef'd after this function.
4616 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
4617 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
4618 #define MODE(x) gui_internal_keyboard_key_data(this, wkbd, \
4619 gui_internal_keyb_modes[(x)/8].title, \
4620 gui_internal_keyb_modes[(x)/8].font, \
4621 gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h) \
4622 -> datai=(mode&7)+((x)&~7)
4623 #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode)
4624 #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode)
4625 static struct widget *
4626 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
4628 struct widget *wkbd,*wk;
4629 struct menu_data *md=gui_internal_menu_data(this);
4630 int i, max_w=this->root.w, max_h=this->root.h;
4633 char *backspace="←";
4640 gui_internal_highlight(this);
4641 if (md->keyboard_mode >= 1024)
4645 gui_internal_widget_children_destroy(this, wkbdb);
4647 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
4649 md->keyboard_mode=mode;
4650 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
4651 wkbd->background=this->background;
4656 max_h=max_h/8; // Allows 3 results in the list when searching for Towns
4658 if(mode>=40&&mode<56) { // Russian/Ukrainian/Belarussian layout needs more space...
4664 if (mode >= 0 && mode < 8) {
4665 for (i = 0 ; i < 26 ; i++) {
4666 char text[]={'A'+i,'\0'};
4669 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4673 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4674 wk->datai=mode+1024;
4676 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4677 wk->datai=mode+1024;
4683 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4685 if (mode >= 8 && mode < 16) {
4686 for (i = 0 ; i < 26 ; i++) {
4687 char text[]={'a'+i,'\0'};
4690 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4694 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4695 wk->datai=mode+1024;
4697 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4698 wk->datai=mode+1024;
4704 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4706 if (mode >= 16 && mode < 24) {
4707 for (i = 0 ; i < 10 ; i++) {
4708 char text[]={'0'+i,'\0'};
4711 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
4712 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
4717 for (i = 0 ; i < 5 ; i++) SPACER();
4720 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4721 wk->datai=mode+1024;
4723 for (i = 0 ; i < 3 ; i++) SPACER();
4726 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4727 wk->datai=mode+1024;
4732 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4734 if (mode >= 24 && mode < 32) {
4735 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
4736 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
4737 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
4738 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
4742 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4744 if (mode >= 32 && mode < 40) {
4745 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
4746 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
4747 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
4748 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
4752 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4754 if (mode >= 40 && mode < 48) {
4755 KEY("А"); KEY("Б"); KEY("В"); KEY("Г"); KEY("Д"); KEY("Е"); KEY("Ж"); KEY("З"); KEY("И");
4756 KEY("Й"); KEY("К"); KEY("Л"); KEY("М"); KEY("Н"); KEY("О"); KEY("П"); KEY("Р"); KEY("С");
4757 KEY("Т"); KEY("У"); KEY("Ф"); KEY("Х"); KEY("Ц"); KEY("Ч"); KEY("Ш"); KEY("Щ"); KEY("Ъ");
4758 KEY("Ы"); KEY("Ь"); KEY("Э"); KEY("Ю"); KEY("Я"); KEY("Ё"); KEY("І"); KEY("Ї"); KEY("Ў");
4759 SPACER(); SPACER(); SPACER();
4760 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4762 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4763 wk->datai=mode+1024;
4771 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4773 if (mode >= 48 && mode < 56) {
4774 KEY("а"); KEY("б"); KEY("в"); KEY("г"); KEY("д"); KEY("е"); KEY("ж"); KEY("з"); KEY("и");
4775 KEY("й"); KEY("к"); KEY("л"); KEY("м"); KEY("н"); KEY("о"); KEY("п"); KEY("р"); KEY("с");
4776 KEY("т"); KEY("у"); KEY("ф"); KEY("х"); KEY("ц"); KEY("ч"); KEY("ш"); KEY("щ"); KEY("ъ");
4777 KEY("ы"); KEY("ь"); KEY("э"); KEY("ю"); KEY("я"); KEY("ё"); KEY("і"); KEY("ї"); KEY("ў");
4778 SPACER(); SPACER(); SPACER();
4779 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4781 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4782 wk->datai=mode+1024;
4790 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4794 if(md->search_list && md->search_list->type==widget_table) {
4795 struct table_data *td=(struct table_data*)(md->search_list->data);
4796 td->button_box_hide=mode<1024;
4804 text=gui_internal_keyb_modes[mode/8].title;
4805 font=gui_internal_keyb_modes[mode/8].font;
4806 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
4807 wk->func=gui_internal_keyboard_change;
4809 wk->background=this->background;
4817 wk->state |= STATE_SENSITIVE;
4818 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
4819 wkl->background=NULL;
4820 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
4821 wkl->background=NULL;
4822 gui_internal_widget_append(wkbd, wk);
4826 gui_internal_widget_append(wkbdb, wkbd);
4828 gui_internal_widget_pack(this, wkbdb);
4829 gui_internal_widget_render(this, wkbdb);
4830 } else if (render == 2) {
4831 gui_internal_menu_reset_pack(this);
4832 gui_internal_menu_render(this);
4842 static struct widget *
4843 gui_internal_keyboard(struct gui_priv *this, int mode)
4845 if (! this->keyboard)
4847 return gui_internal_keyboard_do(this, NULL, mode);
4851 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
4853 gui_internal_keyboard_do(this, key->data, key->datai);
4857 gui_internal_search_list_set_default_country(struct gui_priv *this)
4859 struct attr search_attr, country_name, country_iso2, *country_attr;
4861 struct country_search *cs;
4862 struct tracking *tracking;
4863 struct search_list_result *res;
4865 country_attr=country_default();
4866 tracking=navit_get_tracking(this->nav);
4867 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
4868 country_attr=&search_attr;
4870 cs=country_search_new(country_attr, 0);
4871 item=country_search_get_item(cs);
4872 if (item && item_attr_get(item, attr_country_name, &country_name)) {
4873 search_attr.type=attr_country_all;
4874 dbg(0,"country %s\n", country_name.u.str);
4875 search_attr.u.str=country_name.u.str;
4876 search_list_search(this->sl, &search_attr, 0);
4877 while((res=search_list_get_result(this->sl)));
4878 if(this->country_iso2) {
4879 g_free(this->country_iso2);
4880 this->country_iso2=NULL;
4882 if (item_attr_get(item, attr_country_iso2, &country_iso2))
4883 this->country_iso2=g_strdup(country_iso2.u.str);
4885 country_search_destroy(cs);
4887 dbg(0,"warning: no default country found\n");
4888 if (this->country_iso2) {
4889 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
4890 search_attr.type=attr_country_iso2;
4891 search_attr.u.str=this->country_iso2;
4892 search_list_search(this->sl, &search_attr, 0);
4893 while((res=search_list_get_result(this->sl)));
4899 gui_internal_search_list_new(struct gui_priv *this)
4901 struct mapset *ms=navit_get_mapset(this->nav);
4903 this->sl=search_list_new(ms);
4904 gui_internal_search_list_set_default_country(this);
4909 gui_internal_search_list_destroy(struct gui_priv *this)
4912 search_list_destroy(this->sl);
4919 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
4921 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
4923 int keyboard_mode=2;
4924 gui_internal_search_list_new(this);
4925 wb=gui_internal_menu(this, what);
4926 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
4927 gui_internal_widget_append(wb, w);
4928 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4929 gui_internal_widget_append(w, wr);
4930 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4931 gui_internal_widget_append(wr, we);
4932 if (!strcmp(type,"Country")) {
4933 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
4934 wnext->func=gui_internal_search_town;
4935 } else if (!strcmp(type,"Town")) {
4936 if (this->country_iso2) {
4937 #if HAVE_API_ANDROID
4938 char country_iso2[strlen(this->country_iso2)+1];
4939 strtolower(country_iso2, this->country_iso2);
4940 country=g_strdup_printf("country_%s", country_iso2);
4942 country=g_strdup_printf("country_%s", this->country_iso2);
4945 country=g_strdup("gui_select_country");
4946 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
4947 wb->state |= STATE_SENSITIVE;
4949 wb->func = gui_internal_search_country;
4951 wb->func = gui_internal_back;
4952 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
4953 wnext->func=gui_internal_search_street;
4955 } else if (!strcmp(type,"Street")) {
4956 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
4957 wb->state |= STATE_SENSITIVE;
4958 wb->func = gui_internal_back;
4959 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
4960 wnext->func=gui_internal_search_house_number;
4961 } else if (!strcmp(type,"House number")) {
4962 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
4963 wb->state |= STATE_SENSITIVE;
4964 wb->func = gui_internal_back;
4967 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
4969 gui_internal_widget_append(we, wnext);
4970 wnext->state |= STATE_SENSITIVE;
4972 wl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);//gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
4973 gui_internal_widget_append(wr, wl);
4974 gui_internal_menu_data(this)->search_list=wl;
4975 wk->state |= STATE_EDIT|STATE_EDITABLE;
4976 wk->background=this->background;
4977 wk->flags |= flags_expand|flags_fill;
4978 wk->func = gui_internal_search_changed;
4979 wk->name=g_strdup(type);
4981 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
4982 gui_internal_menu_render(this);
4986 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
4988 search_list_select(this->sl, attr_street_name, 0, 0);
4989 gui_internal_search(this,_("House number"),"House number",0);
4993 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
4995 dbg(0,"id %d\n", widget->selection_id);
4996 search_list_select(this->sl, attr_street_name, 0, 0);
4997 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
4998 gui_internal_search(this,_("House number"),"House number",0);
5002 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
5004 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
5005 gui_internal_search(this,_("Street"),"Street",0);
5009 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
5011 dbg(0,"id %d\n", widget->selection_id);
5012 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
5013 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
5014 gui_internal_search(this,_("Street"),"Street",0);
5018 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
5021 search_list_select(this->sl, attr_country_all, 0, 0);
5022 g_free(this->country_iso2);
5023 this->country_iso2=NULL;
5024 gui_internal_search(this,_("Town"),"Town",0);
5028 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
5030 struct search_list_common *slc;
5031 dbg(0,"id %d\n", widget->selection_id);
5032 search_list_select(this->sl, attr_country_all, 0, 0);
5033 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
5035 g_free(this->country_iso2);
5036 this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
5038 gui_internal_search(this,widget->name,"Town",0);
5042 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
5044 gui_internal_prune_menu_count(this, 1, 0);
5045 gui_internal_search(this,_("Country"),"Country",0);
5049 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5052 search_list_select(this->sl, attr_country_all, 0, 0);
5053 gui_internal_search(this,_("Town"),"Town",1);
5057 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5060 struct widget *w,*wb,*wl,*row;
5061 struct attr_iter *iter;
5064 wb=gui_internal_menu(this, _("Layout"));
5065 w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
5066 gui_internal_widget_append(wb, w);
5067 iter=navit_attr_iter_new();
5068 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
5069 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5070 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
5072 gui_internal_widget_append(row, wl);
5074 navit_attr_iter_destroy(iter);
5075 gui_internal_menu_render(this);
5079 gui_internal_cmd_match_expand(char *pattern, struct attr **in)
5081 char p,*ret=g_strdup(pattern),*r=ret,*a;
5083 while ((p=*pattern++)) {
5087 a=attr_to_text(*in++,NULL,0);
5088 len=strlen(ret)+strlen(a)+strlen(pattern)+1;
5108 gui_internal_match(const char *pattern, const char *string)
5111 while ((p=*pattern++)) {
5114 while ((s=*string)) {
5115 if (gui_internal_match(pattern,string))
5131 gui_internal_set(char *remove, char *add)
5133 char *gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
5134 char *gui_file_new=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal_new.txt", NULL);
5135 FILE *fo=fopen(gui_file_new,"w");
5136 FILE *fi=fopen(gui_file,"r");
5141 while (getline(&line,&size,fi) > 0) {
5142 int len=strlen(line);
5143 if (len > 0 && line[len-1] == '\n')
5145 dbg(1,"line=%s\n",line);
5146 if (!gui_internal_match(remove, line))
5147 fprintf(fo,"%s\n",line);
5153 fprintf(fo,"%s;\n",add);
5155 ret=(rename(gui_file_new, gui_file)==0);
5156 g_free(gui_file_new);
5163 gui_internal_cmd2_set(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5165 char *pattern,*command=NULL;
5166 if (!in || !in[0] || !ATTR_IS_STRING(in[0]->type)) {
5167 dbg(0,"first parameter missing or wrong type\n");
5170 pattern=in[0]->u.str;
5171 dbg(0,"pattern %s\n",pattern);
5173 command=gui_internal_cmd_match_expand(pattern, in+1);
5174 dbg(0,"expand %s\n",command);
5175 gui_internal_set(pattern, command);
5176 command_evaluate(&this->self, command);
5183 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5186 gui_internal_prune_menu(this, NULL);
5187 navit.type=attr_navit;
5188 navit.u.navit=this->nav;
5189 config_remove_attr(config, &navit);
5190 gui_internal_destroy(this);
5191 event_main_loop_quit();
5195 gui_internal_window_closed(struct gui_priv *this)
5197 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
5201 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5203 navit_set_destination(this->nav, NULL, NULL, 0);
5207 gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data)
5209 char *text=g_strdup_printf(_("Download %s"),wm->name);
5210 struct widget *w, *wb;
5211 struct map *map=data;
5212 double bllon,bllat,trlon,trlat;
5214 wb=gui_internal_menu(this, text);
5216 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5217 w->spy=this->spacing*3;
5218 gui_internal_widget_append(wb, w);
5219 if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
5221 struct map_selection sel;
5222 struct map_rect *mr;
5229 transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
5232 transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
5233 sel.range.min=type_none;
5234 sel.range.max=type_last;
5235 mr=map_rect_new(map, &sel);
5236 while ((item=map_rect_get_item(mr))) {
5239 map_rect_destroy(mr);
5242 dbg(0,"bbox=%s\n",wm->prefix);
5243 gui_internal_menu_render(this);
5247 gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data)
5249 struct attr on, off, download_enabled, download_disabled;
5250 struct widget *w,*wb,*wma;
5251 struct map *map=data;
5253 char *search,buffer[256];
5254 int found,sp_match=0;
5256 dbg(1,"wm=%p prefix=%s\n",wm,wm->prefix);
5261 while(search[sp_match] == ' ')
5267 on.type=off.type=attr_active;
5270 wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
5271 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5272 w->spy=this->spacing*3;
5273 gui_internal_widget_append(wb, w);
5275 wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on, &off, 1);
5276 gui_internal_widget_append(w, wma);
5279 download_enabled.type=download_disabled.type=attr_update;
5280 download_enabled.u.num=1;
5281 download_disabled.u.num=0;
5282 wma=gui_internal_button_map_attr_new(this
5283 , _("Download Enabled")
5284 , gravity_left_center|orientation_horizontal|flags_fill
5287 , &download_disabled
5289 gui_internal_widget_append(w, wma);
5292 f=fopen("maps/areas.tsv","r");
5293 while (f && fgets(buffer, sizeof(buffer), f)) {
5294 char *nl,*description,*description_size,*bbox,*size=NULL;
5296 if ((nl=strchr(buffer,'\n')))
5298 if ((nl=strchr(buffer,'\r')))
5300 while(buffer[sp] == ' ')
5302 if ((bbox=strchr(buffer,'\t')))
5304 if (bbox && (size=strchr(bbox,'\t')))
5306 if (search && !strcmp(buffer, search)) {
5307 wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
5308 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
5309 wma->name=g_strdup(buffer+sp);
5310 wma->prefix=g_strdup(bbox);
5311 gui_internal_widget_append(w, wma);
5313 } else if (sp < sp_match)
5315 if (sp == sp_match && found && buffer[sp]) {
5316 description=g_strdup(buffer+sp);
5318 description_size=g_strdup_printf("%s (%s)",description,size);
5320 description_size=g_strdup(description);
5321 wma=gui_internal_button_new_with_callback(this, description_size, NULL,
5322 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
5323 g_free(description_size);
5324 wma->prefix=g_strdup(buffer);
5325 wma->name=description;
5326 gui_internal_widget_append(w, wma);
5330 gui_internal_menu_render(this);
5334 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5336 struct attr attr, on, off, description, type, data, url, active;
5337 struct widget *w,*wb,*row,*wma;
5339 struct attr_iter *iter;
5341 wb=gui_internal_menu(this, _("Maps"));
5342 //w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5343 //w->spy=this->spacing*3;
5344 w = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
5345 gui_internal_widget_append(wb, w);
5346 iter=navit_attr_iter_new();
5347 on.type=off.type=attr_active;
5350 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
5351 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
5352 label=g_strdup(description.u.str);
5354 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
5356 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
5358 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
5360 if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
5361 if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
5363 wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
5364 gravity_left_center|orientation_horizontal|flags_fill,
5365 gui_internal_cmd_map_download, attr.u.map);
5367 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
5368 attr.u.map, &on, &off, 1);
5370 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5371 gui_internal_widget_append(row, wma);
5374 navit_attr_iter_destroy(iter);
5375 gui_internal_menu_render(this);
5379 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
5381 struct attr vehicle = {attr_vehicle,{wm->data}};
5382 navit_set_attr(this->nav, &vehicle);
5386 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
5388 struct widget *w,*wb,*row;
5389 struct attr attr,sat_attr;
5390 struct vehicle *v=wm->data;
5393 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
5395 wb=gui_internal_menu(this, _("Show Satellite Status"));
5396 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
5397 gui_internal_menu_data(this)->redisplay_widget=wm;
5398 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5399 gui_internal_widget_append(wb, w);
5400 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
5401 row = gui_internal_widget_table_row_new(this,gravity_left_top);
5402 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
5403 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
5404 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
5405 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
5406 gui_internal_widget_append(w,row);
5407 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
5408 row = gui_internal_widget_table_row_new(this,gravity_left_top);
5409 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
5410 if (item_attr_get(attr.u.item, types[i], &sat_attr))
5411 str=g_strdup_printf("%ld", sat_attr.u.num);
5414 gui_internal_widget_append(row, gui_internal_label_new(this, str));
5417 gui_internal_widget_append(w,row);
5419 gui_internal_widget_append(wb, w);
5420 gui_internal_menu_render(this);
5424 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
5426 struct widget *w,*wb;
5428 struct vehicle *v=wm->data;
5429 wb=gui_internal_menu(this, _("Show NMEA Data"));
5430 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
5431 gui_internal_menu_data(this)->redisplay_widget=wm;
5432 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5433 gui_internal_widget_append(wb, w);
5434 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
5435 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
5436 gui_internal_menu_render(this);
5440 * A container to hold the selected vehicle and the desired profile in
5443 struct vehicle_and_profilename {
5444 struct vehicle *vehicle;
5449 * Figures out whether the given vehicle is the active vehicle.
5451 * @return true if the vehicle is active, false otherwise.
5454 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
5457 struct attr active_vehicle;
5459 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
5460 active_vehicle.u.vehicle=NULL;
5462 return active_vehicle.u.vehicle == vehicle;
5466 save_vehicle_xml(struct vehicle *v)
5469 struct attr_iter *iter=vehicle_attr_iter_new();
5473 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
5474 if (ATTR_IS_OBJECT(attr.type))
5478 printf(" %s=\"%s\"",attr_to_name(attr.type),attrtxt=attr_to_text(&attr, NULL, 1));
5484 printf("</vehicle>\n");
5487 vehicle_attr_iter_destroy(iter);
5492 * Reacts to a button press that changes a vehicle's active profile.
5494 * @see gui_internal_add_vehicle_profile
5497 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
5498 widget *wm, void *data)
5500 struct vehicle_and_profilename *vapn = data;
5501 struct vehicle *v = vapn->vehicle;
5502 char *profilename = vapn->profilename;
5503 struct attr vehicle_name_attr;
5504 char *vehicle_name = NULL;
5505 struct attr profilename_attr;
5507 // Get the vehicle name
5508 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
5509 vehicle_name = vehicle_name_attr.u.str;
5511 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
5514 // Change the profile name
5515 profilename_attr.type = attr_profilename;
5516 profilename_attr.u.str = profilename;
5517 if(!vehicle_set_attr(v, &profilename_attr)) {
5518 dbg(0, "Unable to set the vehicle's profile name\n");
5521 // Notify Navit that the routing should be re-done if this is the
5523 if (gui_internal_is_active_vehicle(this, v)) {
5524 struct attr vehicle;
5525 vehicle.type=attr_vehicle;
5526 vehicle.u.vehicle=v;
5527 navit_set_attr(this->nav, &vehicle);
5529 save_vehicle_xml(v);
5531 gui_internal_prune_menu_count(this, 1, 0);
5532 gui_internal_menu_vehicle_settings(this, v, vehicle_name);
5536 * Adds the vehicle profile to the GUI, allowing the user to pick a
5537 * profile for the currently selected vehicle.
5540 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
5541 *parent, struct vehicle *v, struct vehicleprofile *profile)
5543 // Just here to show up in the translation file, nice and close to
5544 // where the translations are actually used.
5545 struct attr profile_attr;
5546 struct attr *attr = NULL;
5548 char *active_profile = NULL;
5551 struct vehicle_and_profilename *context = NULL;
5553 #ifdef ONLY_FOR_TRANSLATION
5554 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
5557 // Figure out the profile name
5558 attr = attr_search(profile->attrs, NULL, attr_name);
5560 dbg(0, "Adding vehicle profile failed. attr==NULL");
5565 // Determine whether the profile is the active one
5566 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
5567 active_profile = profile_attr.u.str;
5568 active = active_profile != NULL && !strcmp(name, active_profile);
5570 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
5571 active_profile, active);
5573 // Build a translatable label.
5575 label = g_strdup_printf(_("Current profile: %s"), _(name));
5577 label = g_strdup_printf(_("Change profile to: %s"), _(name));
5580 // Create the context object (the vehicle and the desired profile)
5581 context = g_new0(struct vehicle_and_profilename, 1);
5582 context->vehicle = v;
5583 context->profilename = name;
5586 gui_internal_widget_append(parent,
5587 gui_internal_button_new_with_callback(
5589 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
5590 gravity_left_center|orientation_horizontal|flags_fill,
5591 gui_internal_cmd_set_active_profile, context));
5597 gui_internal_menu_vehicle_settings(struct gui_priv *this, struct vehicle *v, char *name)
5599 struct widget *w,*wb,*row;
5601 struct vehicleprofile *profile = NULL;
5604 wb=gui_internal_menu(this, name);
5605 w=gui_internal_widget_table_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill,1);
5606 gui_internal_widget_append(wb, w);
5608 // Add the "Set as active" button if this isn't the active
5610 if (!gui_internal_is_active_vehicle(this, v)) {
5611 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5612 gui_internal_widget_append(row,
5613 gui_internal_button_new_with_callback(this, _("Set as active"),
5614 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5615 gui_internal_cmd_set_active_vehicle, v));
5618 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
5619 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5620 gui_internal_widget_append(row,
5621 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
5622 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5623 gui_internal_cmd_show_satellite_status, v));
5625 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
5626 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5627 gui_internal_widget_append(row,
5628 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
5629 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5630 gui_internal_cmd_show_nmea_data, v));
5633 // Add all the possible vehicle profiles to the menu
5634 profiles = navit_get_vehicleprofiles(this->nav);
5636 profile = (struct vehicleprofile *)profiles->data;
5637 gui_internal_widget_append(w, row=gui_internal_widget_table_row_new(this,gravity_left|orientation_horizontal|flags_fill));
5638 gui_internal_add_vehicle_profile(this, row, v, profile);
5639 profiles = g_list_next(profiles);
5642 callback_list_call_attr_2(this->cbl, attr_vehicle, w, v);
5643 gui_internal_menu_render(this);
5647 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
5649 gui_internal_menu_vehicle_settings(this, wm->data, wm->text);
5653 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5655 struct attr attr,attr2,vattr;
5656 struct widget *w,*wb,*wl;
5657 struct attr_iter *iter;
5658 struct attr active_vehicle;
5660 iter=navit_attr_iter_new();
5661 if (navit_get_attr(this->nav, attr_vehicle, &attr, iter) && !navit_get_attr(this->nav, attr_vehicle, &attr2, iter)) {
5662 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
5663 navit_attr_iter_destroy(iter);
5664 gui_internal_menu_vehicle_settings(this, attr.u.vehicle, vattr.u.str);
5667 navit_attr_iter_destroy(iter);
5669 wb=gui_internal_menu(this, _("Vehicle"));
5670 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5671 w->spy=this->spacing*3;
5672 gui_internal_widget_append(wb, w);
5673 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
5674 active_vehicle.u.vehicle=NULL;
5675 iter=navit_attr_iter_new();
5676 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
5677 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
5678 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
5679 image_new_xs(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
5680 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
5681 wl->text=g_strdup(vattr.u.str);
5682 gui_internal_widget_append(w, wl);
5684 navit_attr_iter_destroy(iter);
5685 gui_internal_menu_render(this);
5690 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5692 struct widget *wb,*w;
5694 wb=gui_internal_menu(this, _("Rules"));
5695 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5696 w->spy=this->spacing*3;
5697 gui_internal_widget_append(wb, w);
5700 on.type=off.type=attr_tracking;
5701 gui_internal_widget_append(w,
5702 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
5706 on.type=off.type=attr_orientation;
5707 gui_internal_widget_append(w,
5708 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
5712 on.type=off.type=attr_follow_cursor;
5713 gui_internal_widget_append(w,
5714 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
5718 on.type=off.type=attr_waypoints_flag;
5719 gui_internal_widget_append(w,
5720 gui_internal_button_navit_attr_new(this, _("Plan with Waypoints"), gravity_left_center|orientation_horizontal|flags_fill,
5722 gui_internal_menu_render(this);
5725 //##############################################################################################################
5728 //# Authors: Martin Schaller (04/2008)
5729 //##############################################################################################################
5730 static void gui_internal_motion(void *data, struct point *p)
5733 struct gui_priv *this=data;
5734 if (!this->root.children) {
5735 navit_handle_motion(this->nav, p);
5741 if(!this->motion_timeout_callback)
5742 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_motion_cb), this);
5743 if(!this->motion_timeout_event)
5744 this->motion_timeout_event=event_add_timeout(30,0, this->motion_timeout_callback);
5748 find_attr(const char **names, const char **values, const char *name)
5751 if (!g_strcasecmp(*names, name))
5753 names+=xml_attr_distance;
5754 values+=xml_attr_distance;
5760 find_attr_dup(const char **names, const char **values, const char *name)
5762 return g_strdup(find_attr(names, values, name));
5766 gui_internal_evaluate(struct gui_priv *this, const char *command)
5769 command_evaluate(&this->self, command);
5774 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
5776 gui_internal_evaluate(this,w->command);
5780 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
5783 if (w->form == form && w->name) {
5784 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
5786 gui_set_attr(this->self.u.gui, attr);
5792 gui_internal_html_submit_set(this, w, form);
5799 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
5801 struct widget *menu;
5804 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
5805 l=g_list_last(this->root.children);
5807 graphics_draw_mode(this->gra, draw_mode_begin);
5808 gui_internal_highlight_do(this, NULL);
5809 gui_internal_menu_render(this);
5810 graphics_draw_mode(this->gra, draw_mode_end);
5811 gui_internal_html_submit_set(this, menu, w->form);
5812 gui_internal_evaluate(this,w->form->onsubmit);
5816 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
5819 gui_internal_prune_menu_count(this, 1, 0);
5820 if (href && href[0] == '#') {
5821 dbg(1,"href=%s\n",href);
5823 this->href=g_strdup(href);
5824 gui_internal_html_menu(this, this->html_text, href+1);
5829 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
5831 gui_internal_html_load_href(this, w->command, 0);
5834 struct div_flags_map {
5838 } div_flags_map[] = {
5839 {"gravity","none",gravity_none},
5840 {"gravity","left",gravity_left},
5841 {"gravity","xcenter",gravity_xcenter},
5842 {"gravity","right",gravity_right},
5843 {"gravity","top",gravity_top},
5844 {"gravity","ycenter",gravity_ycenter},
5845 {"gravity","bottom",gravity_bottom},
5846 {"gravity","left_top",gravity_left_top},
5847 {"gravity","top_center",gravity_top_center},
5848 {"gravity","right_top",gravity_right_top},
5849 {"gravity","left_center",gravity_left_center},
5850 {"gravity","center",gravity_center},
5851 {"gravity","right_center",gravity_right_center},
5852 {"gravity","left_bottom",gravity_left_bottom},
5853 {"gravity","bottom_center",gravity_bottom_center},
5854 {"gravity","right_bottom",gravity_right_bottom},
5855 {"expand","1",flags_expand},
5856 {"fill","1",flags_fill},
5857 {"orientation","horizontal",orientation_horizontal},
5858 {"orientation","vertical",orientation_vertical},
5859 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
5863 div_flag(const char **names, const char **values, char *name)
5867 const char *value=find_attr(names, values, name);
5870 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
5871 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
5872 ret|=div_flags_map[i].flags;
5878 div_flags(const char **names, const char **values)
5881 flags = div_flag(names, values, "gravity");
5882 flags |= div_flag(names, values, "orientation");
5883 flags |= div_flag(names, values, "expand");
5884 flags |= div_flag(names, values, "fill");
5888 static struct widget *
5889 html_image(struct gui_priv *this, const char **names, const char **values)
5891 const char *src, *size;
5892 struct graphics_image *img=NULL;
5894 src=find_attr(names, values, "src");
5897 size=find_attr(names, values, "size");
5900 if (!strcmp(size,"l"))
5901 img=image_new_l(this, src);
5902 else if (!strcmp(size,"s"))
5903 img=image_new_s(this, src);
5904 else if (!strcmp(size,"xs"))
5905 img=image_new_xs(this, src);
5908 return gui_internal_image_new(this, img);
5912 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
5914 struct gui_priv *this=data;
5916 enum html_tag tag=html_tag_none;
5917 struct html *html=&this->html[this->html_depth];
5918 const char *cond, *type;
5920 if (!g_strcasecmp(tag_name,"text"))
5926 html->refresh_cond=NULL;
5928 html->container=NULL;
5929 cond=find_attr(names, values, "cond");
5931 if (cond && !this->html_skip) {
5932 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
5936 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
5937 if (!g_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
5938 tag=html_tag_map[i].tag;
5943 if (!this->html_skip && !html->skip) {
5946 html->name=find_attr_dup(names, values, "name");
5948 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
5950 this->html_anchor_found=1;
5952 html->command=find_attr_dup(names, values, "onclick");
5953 html->href=find_attr_dup(names, values, "href");
5954 html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
5957 html->command=find_attr_dup(names, values, "onclick");
5958 html->w=html_image(this, names, values);
5961 this->form=g_new0(struct form, 1);
5962 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
5964 case html_tag_input:
5965 type=find_attr_dup(names, values, "type");
5968 if (!strcmp(type,"image")) {
5969 html->w=html_image(this, names, values);
5971 html->w->state|=STATE_SENSITIVE;
5972 html->w->func=gui_internal_html_submit;
5975 if (!strcmp(type,"text") || !strcmp(type,"password")) {
5976 html->w=gui_internal_label_new(this, NULL);
5977 html->w->background=this->background;
5978 html->w->flags |= div_flags(names, values);
5979 html->w->state|=STATE_EDITABLE;
5980 if (!this->editable) {
5981 this->editable=html->w;
5982 html->w->state|=STATE_EDIT;
5984 this->keyboard_required=1;
5985 if (!strcmp(type,"password"))
5986 html->w->flags2 |= 1;
5989 html->w->form=this->form;
5990 html->w->name=find_attr_dup(names, values, "name");
5994 html->w=gui_internal_box_new(this, div_flags(names, values));
5995 html->container=this->html_container;
5996 this->html_container=html->w;
6002 this->html_skip+=html->skip;
6007 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
6009 struct gui_priv *this=data;
6011 struct html *parent=NULL;
6013 if (!g_strcasecmp(tag_name,"text"))
6016 html=&this->html[this->html_depth];
6017 if (this->html_depth > 0)
6018 parent=&this->html[this->html_depth-1];
6021 if (!this->html_skip) {
6022 if (html->command && html->w) {
6023 html->w->state |= STATE_SENSITIVE;
6024 html->w->command=html->command;
6025 html->w->func=gui_internal_html_command;
6028 if (parent && (parent->href || parent->command) && html->w) {
6029 html->w->state |= STATE_SENSITIVE;
6030 if (parent->command) {
6031 html->w->command=g_strdup(parent->command);
6032 html->w->func=gui_internal_html_command;
6034 html->w->command=g_strdup(parent->href);
6035 html->w->func=gui_internal_html_href;
6038 switch (html->tag) {
6040 this->html_container=html->container;
6042 case html_tag_input:
6043 gui_internal_widget_append(this->html_container, html->w);
6052 this->html_skip-=html->skip;
6053 g_free(html->command);
6056 g_free(html->refresh_cond);
6060 gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data)
6062 if (gui_internal_menu_data(this) == menu_data) {
6063 char *href=g_strdup(menu_data->href);
6064 gui_internal_html_load_href(this, href, 1);
6070 gui_internal_set_refresh_callback(struct gui_priv *this, char *cond)
6072 dbg(0,"cond=%s\n",cond);
6074 enum attr_type type;
6075 struct object_func *func;
6076 struct menu_data *menu_data=gui_internal_menu_data(this);
6077 dbg(0,"navit=%p\n",this->nav);
6078 type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
6079 if (type == attr_none)
6081 func=object_func_lookup(menu_data->refresh_callback_obj.type);
6082 if (!func || !func->add_attr)
6084 menu_data->refresh_callback.type=attr_callback;
6085 menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,this,menu_data);
6086 func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
6091 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
6093 struct gui_priv *this=data;
6095 int depth=this->html_depth-1;
6096 struct html *html=&this->html[depth];
6097 gchar *text_stripped;
6099 if (this->html_skip)
6101 while (isspace(text[0])) {
6105 while (len > 0 && isspace(text[len-1]))
6108 text_stripped = g_strndup(text, len);
6109 if (html->tag == html_tag_html && depth > 2) {
6110 if (this->html[depth-1].tag == html_tag_script) {
6111 html=&this->html[depth-2];
6114 switch (html->tag) {
6116 if (html->name && len) {
6117 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
6118 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
6119 gui_internal_menu_data(this)->href=g_strdup(this->href);
6120 gui_internal_set_refresh_callback(this, html->refresh_cond);
6121 this->html_container->spx=this->spacing*10;
6125 if (!this->html_container) {
6126 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
6127 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
6128 this->html_container->spx=this->spacing*10;
6133 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
6134 gui_internal_widget_append(w, html->w);
6135 gui_internal_widget_append(w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
6141 gui_internal_widget_append(html->w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
6144 case html_tag_script:
6145 dbg(1,"execute %s\n",text_stripped);
6146 gui_internal_evaluate(this,text_stripped);
6151 g_free(text_stripped);
6155 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
6157 char *doc=g_strdup(document);
6158 graphics_draw_mode(this->gra, draw_mode_begin);
6159 this->html_container=NULL;
6161 this->html_anchor=anchor;
6162 this->html_anchor_found=0;
6164 this->keyboard_required=0;
6165 this->editable=NULL;
6166 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
6167 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
6169 if (this->keyboard_required && this->keyboard) {
6170 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
6171 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
6173 gui_internal_menu_render(this);
6174 graphics_draw_mode(this->gra, draw_mode_end);
6179 gui_internal_enter(struct gui_priv *this, int ignore)
6181 struct graphics *gra=this->gra;
6183 this->ignore_button=ignore;
6185 navit_block(this->nav, 1);
6186 graphics_overlay_disable(gra, 1);
6189 this->root.background=this->background;
6193 gui_internal_leave(struct gui_priv *this)
6195 graphics_draw_mode(this->gra, draw_mode_end);
6199 gui_internal_set_click_coord(struct gui_priv *this, struct point *p)
6204 struct transformation *trans;
6205 attr_free(this->click_coord_geo);
6206 this->click_coord_geo=NULL;
6208 trans=navit_get_trans(this->nav);
6209 transform_reverse(trans, p, &c);
6210 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
6211 this->clickp.pro=transform_get_projection(trans);
6214 transform_to_geo(this->clickp.pro, &c, &g);
6215 attr.u.coord_geo=&g;
6216 attr.type=attr_click_coord_geo;
6217 this->click_coord_geo=attr_dup(&attr);
6222 gui_internal_set_position_coord(struct gui_priv *this)
6224 struct transformation *trans;
6225 struct attr attr,attrp;
6228 attr_free(this->position_coord_geo);
6229 this->position_coord_geo=NULL;
6230 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
6231 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
6232 trans=navit_get_trans(this->nav);
6233 this->position_coord_geo=attr_dup(&attrp);
6234 this->vehiclep.pro=transform_get_projection(trans);
6235 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
6236 this->vehiclep.x=c.x;
6237 this->vehiclep.y=c.y;
6242 gui_internal_enter_setup(struct gui_priv *this)
6244 if (!this->mouse_button_clicked_on_map)
6245 gui_internal_set_position_coord(this);
6249 gui_internal_html_main_menu(struct gui_priv *this)
6251 gui_internal_prune_menu(this, NULL);
6252 gui_internal_html_load_href(this, "#Main Menu", 0);
6256 gui_internal_cmd_menu(struct gui_priv *this, int ignore, char *href)
6259 gui_internal_enter(this, ignore);
6260 gui_internal_enter_setup(this);
6263 gui_internal_html_load_href(this, href, 0);
6265 gui_internal_html_main_menu(this);
6269 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6272 int i=0, ignore=0, replace=0;
6274 if (in && in[i] && ATTR_IS_INT(in[i]->type))
6275 ignore=in[i++]->u.num;
6277 if (in && in[i] && ATTR_IS_STRING(in[i]->type)) {
6278 href=in[i++]->u.str;
6279 if (in[i] && ATTR_IS_INT(in[i]->type))
6280 replace=in[i++]->u.num;
6283 if (this->root.children) {
6286 gui_internal_html_load_href(this, href, replace);
6289 gui_internal_cmd_menu(this, ignore, href);
6294 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
6296 if (widget->text && strlen(widget->text)) {
6297 if (this->position_coord_geo)
6298 navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
6300 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
6302 g_free(widget->text);
6304 gui_internal_prune_menu(this, NULL);
6305 gui_internal_check_exit(this);
6309 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
6311 gui_internal_cmd_log_do(this, widget->data);
6315 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
6319 len=strlen(wm->text);
6320 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
6321 wm->text[len-1]='\0';
6322 gui_internal_cmd_log_do(this, wm);
6329 gui_internal_cmd_log(struct gui_priv *this)
6331 struct widget *w,*wb,*wk,*wl,*we,*wnext;
6332 gui_internal_enter(this, 1);
6333 gui_internal_set_click_coord(this, NULL);
6334 gui_internal_enter_setup(this);
6335 wb=gui_internal_menu(this, "Log Message");
6336 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
6337 gui_internal_widget_append(wb, w);
6338 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
6339 gui_internal_widget_append(w, we);
6340 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
6341 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
6342 wk->background=this->background;
6343 wk->flags |= flags_expand|flags_fill;
6344 wk->func = gui_internal_cmd_log_changed;
6345 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
6346 wnext->state |= STATE_SENSITIVE;
6347 wnext->func = gui_internal_cmd_log_clicked;
6349 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
6350 gui_internal_widget_append(w, wl);
6352 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
6353 gui_internal_menu_render(this);
6354 gui_internal_leave(this);
6358 gui_internal_check_exit(struct gui_priv *this)
6360 struct graphics *gra=this->gra;
6361 if (! this->root.children) {
6362 gui_internal_search_idle_end(this);
6363 gui_internal_search_list_destroy(this);
6364 graphics_overlay_disable(gra, 0);
6365 if (!navit_block(this->nav, 0)) {
6367 navit_draw(this->nav);
6369 navit_draw_displaylist(this->nav);
6375 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
6379 attr->u.num=this->root.children != NULL;
6381 case attr_click_coord_geo:
6382 if (!this->click_coord_geo)
6384 *attr=*this->click_coord_geo;
6386 case attr_position_coord_geo:
6387 if (!this->position_coord_geo)
6389 *attr=*this->position_coord_geo;
6392 attr->u.num=this->pitch;
6395 attr->u.num=this->mouse_button_clicked_on_map;
6405 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
6407 switch (attr->type) {
6409 g_free(this->html_text);
6410 this->html_text=g_strdup(attr->u.str);
6418 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
6420 switch (attr->type) {
6421 case attr_fullscreen:
6422 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
6423 graphics_draw_mode(this->gra, draw_mode_end);
6424 this->win->fullscreen(this->win, attr->u.num > 0);
6425 graphics_draw_mode(this->gra, draw_mode_begin);
6427 this->fullscreen=attr->u.num;
6429 case attr_menu_on_map_click:
6430 this->menu_on_map_click=attr->u.num;
6432 case attr_on_map_click:
6433 g_free(this->on_map_click);
6434 this->on_map_click=g_strdup(attr->u.str);
6437 dbg(0,"%s\n",attr_to_name(attr->type));
6442 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
6444 struct displaylist_handle *dlh;
6445 struct displaylist *display;
6446 struct displayitem *di;
6447 struct attr cb,**attr_list=NULL;
6450 display=navit_get_displaylist(this->nav);
6451 dlh=graphics_displaylist_open(display);
6452 while ((di=graphics_displaylist_next(dlh))) {
6453 struct item *item=graphics_displayitem_get_item(di);
6454 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
6455 graphics_displayitem_within_dist(display, di, p, this->radius)) {
6456 struct map_rect *mr=map_rect_new(item->map, NULL);
6457 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
6459 if (itemo && item_attr_get(itemo, attr_data, &attr))
6460 attr_list=attr_generic_add_attr(attr_list, &attr);
6461 map_rect_destroy(mr);
6464 graphics_displaylist_close(dlh);
6465 if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
6466 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
6467 attr_list_free(attr_list);
6472 //##############################################################################################################
6473 //# Description: Function to handle mouse clicks and scroll wheel movement
6475 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
6476 //##############################################################################################################
6477 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
6479 struct gui_priv *this=data;
6480 struct graphics *gra=this->gra;
6482 dbg(1,"enter %d %d\n", pressed, button);
6483 // if still on the map (not in the menu, yet):
6484 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
6485 if (!this->root.children || this->ignore_button) {
6487 this->ignore_button=0;
6488 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
6489 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
6490 dbg(1,"navit has handled button\n");
6493 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
6496 if (this->on_map_click || this->menu_on_map_click) {
6497 this->mouse_button_clicked_on_map=1;
6498 gui_internal_set_click_coord(this, p);
6499 gui_internal_set_position_coord(this);
6500 if (this->on_map_click)
6501 command_evaluate(&this->self, this->on_map_click);
6503 gui_internal_cmd_menu(this, 0, NULL);
6504 this->mouse_button_clicked_on_map=0;
6505 } else if (this->signal_on_map_click) {
6506 gui_internal_dbus_signal(this, p);
6514 * If already in the menu:
6520 gui_internal_gesture_ring_clear(this);
6521 gui_internal_gesture_ring_add(this, p);
6522 gui_internal_highlight(this);
6525 gui_internal_gesture_ring_add(this, p);
6526 gui_internal_gesture_get_vector(this, 300, NULL, &dx, &dy);
6529 graphics_draw_mode(gra, draw_mode_begin);
6530 if(!gui_internal_gesture_do(this) && this->pressed!=2 && abs(dx)<this->icon_s && abs(dy)<this->icon_s)
6531 gui_internal_call_highlighted(this);
6533 if (!event_main_loop_has_quit()) {
6534 gui_internal_highlight(this);
6535 graphics_draw_mode(gra, draw_mode_end);
6536 gui_internal_check_exit(this);
6542 gui_internal_setup(struct gui_priv *this)
6544 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
6545 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
6546 struct graphics *gra=this->gra;
6547 unsigned char *buffer;
6551 if (this->background)
6553 this->background=graphics_gc_new(gra);
6554 this->background2=graphics_gc_new(gra);
6555 this->highlight_background=graphics_gc_new(gra);
6556 graphics_gc_set_foreground(this->highlight_background, &cbh);
6557 this->foreground=graphics_gc_new(gra);
6558 graphics_gc_set_foreground(this->foreground, &cf);
6559 this->text_background=graphics_gc_new(gra);
6560 this->text_foreground=graphics_gc_new(gra);
6561 graphics_gc_set_foreground(this->background, &this->background_color);
6562 graphics_gc_set_foreground(this->background2, &this->background2_color);
6563 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
6564 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
6565 gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
6566 if (file_get_contents(gui_file,&buffer,&size)) {
6567 char *command=g_malloc(size+1);
6568 strncpy(command,(const char *)buffer,size);
6570 command_evaluate(&this->self, command);
6577 //##############################################################################################################
6580 //# Authors: Martin Schaller (04/2008)
6581 //##############################################################################################################
6582 static void gui_internal_resize(void *data, int w, int h)
6584 struct gui_priv *this=data;
6587 gui_internal_setup(this);
6589 if (this->root.w != w || this->root.h != h) {
6594 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
6595 navit_handle_resize(this->nav, w, h);
6596 if (this->root.children) {
6598 gui_internal_html_main_menu(this);
6600 gui_internal_menu_render(this);
6606 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
6621 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
6623 GList *l=wi->children;
6624 // Skip hidden elements
6625 if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
6627 if ((wi->state & STATE_SENSITIVE) ) {
6630 gui_internal_keynav_point(wi, -dx, -dy, &wp);
6632 dist1=(wp.x-p->x)*dx;
6635 dist1=(wp.y-p->y)*dy;
6643 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);
6649 if (dist1 < *distance) {
6656 struct widget *child=l->data;
6657 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
6663 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
6665 struct widget *result,*menu=g_list_last(this->root.children)->data;
6668 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6669 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
6675 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
6677 gui_internal_keynav_point(result, dx, dy, &p);
6678 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
6683 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
6684 dbg(1,"result=%p\n", result);
6696 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
6697 dbg(1,"wraparound result=%p\n", result);
6699 gui_internal_highlight_do(this, result);
6701 gui_internal_say(this, result, 1);
6704 //##############################################################################################################
6707 //# Authors: Martin Schaller (04/2008)
6708 //##############################################################################################################
6709 static void gui_internal_keypress(void *data, char *key)
6711 struct gui_priv *this=data;
6714 if (!this->root.children) {
6715 transform_get_size(navit_get_trans(this->nav), &w, &h);
6720 navit_set_center_screen(this->nav, &p, 1);
6722 case NAVIT_KEY_DOWN:
6725 navit_set_center_screen(this->nav, &p, 1);
6727 case NAVIT_KEY_LEFT:
6730 navit_set_center_screen(this->nav, &p, 1);
6732 case NAVIT_KEY_RIGHT:
6735 navit_set_center_screen(this->nav, &p, 1);
6737 case NAVIT_KEY_ZOOM_IN:
6738 navit_zoom_in(this->nav, 2, NULL);
6740 case NAVIT_KEY_ZOOM_OUT:
6741 navit_zoom_out(this->nav, 2, NULL);
6743 case NAVIT_KEY_RETURN:
6744 case NAVIT_KEY_MENU:
6745 gui_internal_set_click_coord(this, NULL);
6746 gui_internal_cmd_menu(this, 0, NULL);
6751 graphics_draw_mode(this->gra, draw_mode_begin);
6753 case NAVIT_KEY_LEFT:
6754 gui_internal_keynav_highlight_next(this,-1,0);
6756 case NAVIT_KEY_RIGHT:
6757 gui_internal_keynav_highlight_next(this,1,0);
6760 gui_internal_keynav_highlight_next(this,0,-1);
6762 case NAVIT_KEY_DOWN:
6763 gui_internal_keynav_highlight_next(this,0,1);
6765 case NAVIT_KEY_BACK:
6766 if (g_list_length(this->root.children) > 1)
6767 gui_internal_back(this, NULL, NULL);
6769 gui_internal_prune_menu(this, NULL);
6771 case NAVIT_KEY_RETURN:
6772 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6773 gui_internal_call_highlighted(this);
6775 gui_internal_keypress_do(this, key);
6778 gui_internal_keypress_do(this, key);
6780 if (!event_main_loop_has_quit()) {
6781 graphics_draw_mode(this->gra, draw_mode_end);
6782 gui_internal_check_exit(this);
6787 //##############################################################################################################
6790 //# Authors: Martin Schaller (04/2008)
6791 //##############################################################################################################
6792 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
6795 struct transformation *trans=navit_get_trans(this->nav);
6797 win=graphics_get_data(gra, "window");
6800 navit_ignore_graphics_events(this->nav, 1);
6803 navit_ignore_graphics_events(this->nav, 1);
6804 transform_get_size(trans, &this->root.w, &this->root.h);
6805 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
6806 graphics_add_callback(gra, this->resize_cb);
6807 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
6808 graphics_add_callback(gra, this->button_cb);
6809 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
6810 graphics_add_callback(gra, this->motion_cb);
6811 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
6812 graphics_add_callback(gra, this->keypress_cb);
6813 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
6814 graphics_add_callback(gra, this->window_closed_cb);
6816 // set fullscreen if needed
6817 if (this->fullscreen)
6818 this->win->fullscreen(this->win, this->fullscreen != 0);
6819 /* Was resize callback already issued? */
6820 if (navit_get_ready(this->nav) & 2)
6821 gui_internal_setup(this);
6825 static void gui_internal_disable_suspend(struct gui_priv *this)
6827 if (this->win->disable_suspend)
6828 this->win->disable_suspend(this->win);
6831 //##############################################################################################################
6834 //# Authors: Martin Schaller (04/2008)
6835 //##############################################################################################################
6836 struct gui_methods gui_internal_methods = {
6839 gui_internal_set_graphics,
6843 gui_internal_disable_suspend,
6844 gui_internal_get_attr,
6845 gui_internal_add_attr,
6846 gui_internal_set_attr,
6850 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
6852 struct attr private_data = { attr_private_data, {(void *)&priv->data}};
6854 *out=attr_generic_add_attr(*out, &private_data);
6858 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
6860 callback_list_add(priv->cbl, cb);
6864 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
6866 callback_list_remove(priv->cbl, cb);
6870 static struct gui_internal_methods gui_internal_methods_ext = {
6871 gui_internal_add_callback,
6872 gui_internal_remove_callback,
6873 gui_internal_menu_render,
6880 gui_internal_get_flags(struct widget *widget)
6882 return widget->flags;
6886 gui_internal_set_flags(struct widget *widget, enum flags flags)
6888 widget->flags=flags;
6892 gui_internal_get_state(struct widget *widget)
6894 return widget->state;
6898 gui_internal_set_state(struct widget *widget, int state)
6900 widget->state=state;
6904 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
6910 gui_internal_set_data(struct widget *widget, void *data)
6916 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
6918 widget->background=this->background;
6921 static struct gui_internal_widget_methods gui_internal_widget_methods = {
6922 gui_internal_widget_append,
6923 gui_internal_button_new,
6924 gui_internal_button_new_with_callback,
6925 gui_internal_box_new,
6926 gui_internal_label_new,
6927 gui_internal_image_new,
6928 gui_internal_keyboard,
6930 gui_internal_get_flags,
6931 gui_internal_set_flags,
6932 gui_internal_get_state,
6933 gui_internal_set_state,
6934 gui_internal_set_func,
6935 gui_internal_set_data,
6936 gui_internal_set_default_background,
6940 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
6942 char *str=NULL,*str2=NULL;
6943 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
6946 dbg(1,"%s\n",attr_to_name(in[0]->type));
6947 if (ATTR_IS_STRING(in[0]->type)) {
6950 if (ATTR_IS_COORD_GEO(in[0]->type)) {
6951 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
6954 str=g_strdup_printf("<html>%s</html>\n",str);
6955 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
6963 * @brief Creates a new table widget.
6965 * Creates and returns a new table widget. This function will
6966 * setup next/previous buttons as children.
6968 * @param this The graphics context.
6969 * @param flags widget sizing flags.
6970 * @returns The newly created widget
6972 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
6974 struct widget * widget = g_new0(struct widget,1);
6975 struct table_data * data = NULL;
6976 widget->type=widget_table;
6977 widget->flags=flags;
6978 widget->state=STATE_SCROLLABLE;
6979 widget->data=g_new0(struct table_data,1);
6980 widget->data_free=gui_internal_table_data_free;
6982 // We have to set background here explicitly
6983 // because it will be used by inner elements created later in this
6984 // function (navigation buttons). Else that elements won't have
6986 widget->background=this->background;
6987 data = (struct table_data*)widget->data;
6990 data->next_button=gui_internal_box_new(this, gravity_center|orientation_horizontal);
6991 gui_internal_widget_append(data->next_button, gui_internal_text_new(this,_("Next"),gravity_center|orientation_horizontal));
6992 gui_internal_widget_append(data->next_button, gui_internal_image_new(this, image_new_xs(this, "gui_arrow_right")));
6993 data->next_button->func=gui_internal_table_button_next;
6994 data->next_button->data=widget;
6997 data->prev_button = gui_internal_button_new_with_callback
6999 image_new_xs(this, "gui_arrow_left"),
7000 gravity_center |orientation_horizontal,
7001 gui_internal_table_button_prev,NULL);
7003 data->prev_button->data=widget;
7007 data->button_box=gui_internal_box_new(this,
7008 gravity_center|orientation_horizontal);
7009 gui_internal_widget_append(widget, data->button_box);
7010 gui_internal_widget_append(data->button_box, data->prev_button);
7011 gui_internal_widget_append(data->button_box, data->next_button);
7013 data->button_box->bl=this->spacing;
7014 gui_internal_widget_pack(this,data->button_box);
7022 * @brief Clears all the rows from the table.
7023 * This function removes all rows from a table.
7024 * New rows can later be added to the table.
7026 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
7029 struct table_data * table_data = (struct table_data* ) table->data;
7031 iter = table->children;
7033 if(iter->data != table_data->button_box) {
7034 struct widget * child = (struct widget*)iter->data;
7035 gui_internal_widget_destroy(this,child);
7036 if(table->children == iter) {
7037 table->children = g_list_remove(iter,iter->data);
7038 iter=table->children;
7041 iter = g_list_remove(iter,iter->data);
7044 iter = g_list_next(iter);
7048 table_data->top_row=NULL;
7049 table_data->bottom_row=NULL;
7053 * @brief Check if table has any data rows filled.
7054 * @param this The graphics context
7055 * @param table table widget
7056 * @returns 1 if the table is empty, 0 if there any data rows present.
7058 static int gui_internal_widget_table_is_empty(struct gui_priv *this, struct widget * table)
7061 struct table_data *td=(struct table_data*) table->data;
7063 for(l=table->children;l;l=g_list_next(l)) {
7064 if(l->data != td->button_box)
7072 * @brief Move GList pointer to the next table row, skipping other table children (button box, for example).
7073 * @param row GList pointer into the children list
7074 * @returns GList pointer to the next row in the children list, or NULL if there are no any rows left.
7076 static GList * gui_internal_widget_table_next_row(GList * row)
7078 while((row=g_list_next(row))!=NULL) {
7079 if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
7086 * @brief Move GList pointer to the previous table row, skipping other table children (button box, for example).
7087 * @param row GList pointer into the children list
7088 * @returns GList pointer to the previous row in the children list, or NULL if there are no any rows left.
7090 static GList * gui_internal_widget_table_prev_row(GList * row)
7092 while((row=g_list_previous(row))!=NULL) {
7093 if(row->data && ((struct widget *)(row->data))->type == widget_table_row)
7101 * Creates a new table_row widget.
7102 * @param this The graphics context
7103 * @param flags Sizing flags for the row
7104 * @returns The new table_row widget.
7106 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
7108 struct widget * widget = g_new0(struct widget,1);
7109 widget->type=widget_table_row;
7110 widget->flags=flags;
7117 * @brief Computes the column dimensions for the table.
7119 * @param w The table widget to compute dimensions for.
7121 * This function examines all of the rows and columns for the table w
7122 * and returns a list (GList) of table_column_desc elements that
7123 * describe each column of the table.
7125 * The caller is responsible for freeing the returned list.
7127 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
7130 GList * column_desc = NULL;
7131 GList * current_desc=NULL;
7132 GList * cur_row = w->children;
7133 struct widget * cur_row_widget=NULL;
7134 GList * cur_column=NULL;
7135 struct widget * cell_w=NULL;
7136 struct table_column_desc * current_cell=NULL;
7137 struct table_data * table_data=NULL;
7144 * Scroll through the the table and
7145 * 1. Compute the maximum width + height of each column across all rows.
7147 table_data = (struct table_data*) w->data;
7148 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
7150 cur_row_widget = (struct widget*) cur_row->data;
7151 current_desc = column_desc;
7152 if(cur_row_widget == table_data->button_box)
7157 for(cur_column = cur_row_widget->children; cur_column;
7158 cur_column=g_list_next(cur_column))
7160 cell_w = (struct widget*) cur_column->data;
7161 gui_internal_widget_pack(this,cell_w);
7162 if(current_desc == 0)
7164 current_cell = g_new0(struct table_column_desc,1);
7165 column_desc = g_list_append(column_desc,current_cell);
7166 current_desc = g_list_last(column_desc);
7167 current_cell->height=cell_w->h;
7168 current_cell->width=cell_w->w;
7169 total_width+=cell_w->w;
7174 current_cell = current_desc->data;
7177 if(current_cell->height < height )
7179 current_cell->height = height;
7181 if(current_cell->width < width)
7183 total_width += (width-current_cell->width);
7184 current_cell->width = width;
7189 current_desc = g_list_next(current_desc);
7199 * If the width of all columns is less than the width off
7200 * the table expand each cell proportionally.
7203 if(total_width+(this->spacing*column_count) < w->w ) {
7204 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
7205 current_cell = (struct table_column_desc*) current_desc->data;
7206 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
7215 * @brief Computes the height and width for the table.
7217 * The height and widht are computed to display all cells in the table
7218 * at the requested height/width.
7220 * @param this The graphics context
7221 * @param w The widget to pack.
7224 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
7230 GList * column_data = gui_internal_compute_table_dimensions(this,w);
7232 struct table_column_desc * cell_desc=0;
7233 struct table_data * table_data = (struct table_data*)w->data;
7235 for(current = column_data; current; current=g_list_next(current))
7237 if(table_data->button_box == current->data )
7241 cell_desc = (struct table_column_desc *) current->data;
7242 width = width + cell_desc->width + this->spacing;
7243 if(height < cell_desc->height)
7245 height = cell_desc->height ;
7251 for(current=w->children; current; current=g_list_next(current))
7253 if(current->data!= table_data->button_box)
7260 if(w->w + w->c.x > this->root.w)
7262 w->w = this->root.w - w->c.x;
7266 if(w->h + w->c.y > this->root.h )
7269 * Do not allow the widget to exceed the screen.
7272 w->h = this->root.h- w->c.y - height;
7275 if (table_data->button_box)
7277 gui_internal_widget_pack(this,table_data->button_box);
7282 * Deallocate column descriptions.
7284 g_list_foreach(column_data,(GFunc)g_free,NULL);
7285 g_list_free(column_data);
7292 * @brief Invalidates coordinates for previosly rendered table widget rows.
7294 * @param table_data Data from the table object.
7296 static void gui_internal_table_hide_rows(struct table_data * table_data)
7299 for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row))
7301 struct widget * cur_row_widget = (struct widget*)cur_row->data;
7302 if (cur_row_widget->type!=widget_table_row)
7304 cur_row_widget->p.x=0;
7305 cur_row_widget->p.y=0;
7306 cur_row_widget->w=0;
7307 cur_row_widget->h=0;
7308 if(cur_row==table_data->bottom_row)
7315 * @brief Renders a table widget.
7317 * @param this The graphics context
7318 * @param w The table widget to render.
7320 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
7325 GList * column_desc=NULL;
7326 GList * cur_row = NULL;
7327 GList * current_desc=NULL;
7328 struct table_data * table_data = (struct table_data*)w->data;
7330 int is_first_page=1;
7331 struct table_column_desc * dim=NULL;
7333 dbg_assert(table_data);
7334 column_desc = gui_internal_compute_table_dimensions(this,w);
7338 gui_internal_table_hide_rows(table_data);
7340 * Skip rows that are on previous pages.
7342 cur_row = w->children;
7343 if(table_data->top_row && table_data->top_row != w->children && !table_data->button_box_hide)
7345 cur_row = table_data->top_row;
7348 table_data->top_row=NULL;
7351 * Loop through each row. Drawing each cell with the proper sizes,
7352 * at the proper positions.
7354 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
7356 int max_height=0, bbox_height=0;
7357 struct widget * cur_row_widget;
7358 GList * cur_column=NULL;
7359 current_desc = column_desc;
7360 cur_row_widget = (struct widget*)cur_row->data;
7361 x =w->p.x+this->spacing;
7362 if(cur_row_widget == table_data->button_box )
7366 dim = (struct table_column_desc*)current_desc->data;
7368 if (table_data->button_box && !table_data->button_box_hide)
7369 bbox_height=table_data->button_box->h;
7371 if( y + dim->height + bbox_height + this->spacing >= w->p.y + w->h )
7374 * No more drawing space left.
7379 for(cur_column = cur_row_widget->children; cur_column;
7380 cur_column=g_list_next(cur_column))
7382 struct widget * cur_widget = (struct widget*) cur_column->data;
7383 dim = (struct table_column_desc*)current_desc->data;
7386 cur_widget->w=dim->width;
7388 cur_widget->h=dim->height;
7390 max_height = dim->height;
7391 /* We pack the widget before rendering to ensure that the x and y
7392 * coordinates get pushed down.
7394 gui_internal_widget_pack(this,cur_widget);
7395 gui_internal_widget_render(this,cur_widget);
7397 if(dim->height > max_height)
7399 max_height = dim->height;
7403 /* Row object should have its coordinates in actual
7404 * state to be able to pass mouse clicks to Column objects
7406 cur_row_widget->p.x=w->p.x;
7407 cur_row_widget->w=w->w;
7408 cur_row_widget->p.y=y;
7409 cur_row_widget->h=max_height;
7411 table_data->bottom_row=cur_row;
7412 current_desc = g_list_next(current_desc);
7414 if(table_data->button_box && (is_skipped || !is_first_page) && !table_data->button_box_hide )
7416 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
7418 if(table_data->button_box->p.y < y )
7420 table_data->button_box->p.y=y;
7422 table_data->button_box->p.x = w->p.x;
7423 table_data->button_box->w = w->w;
7424 // table_data->button_box->h = w->h - y;
7425 // table_data->next_button->h=table_data->button_box->h;
7426 // table_data->prev_button->h=table_data->button_box->h;
7427 // table_data->next_button->c.y=table_data->button_box->c.y;
7428 // table_data->prev_button->c.y=table_data->button_box->c.y;
7429 gui_internal_widget_pack(this,table_data->button_box);
7430 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
7432 table_data->button_box->p.y = w->p.y + w->h -
7433 table_data->button_box->h;
7437 table_data->next_button->state|= STATE_SENSITIVE;
7441 table_data->next_button->state&= ~STATE_SENSITIVE;
7444 if(table_data->top_row != w->children)
7446 table_data->prev_button->state|= STATE_SENSITIVE;
7450 table_data->prev_button->state&= ~STATE_SENSITIVE;
7452 gui_internal_widget_render(this,table_data->button_box);
7456 * Deallocate column descriptions.
7458 g_list_foreach(column_desc,(GFunc)g_free,NULL);
7459 g_list_free(column_desc);
7464 * @brief Displays Route information
7466 * @li The name of the active vehicle
7467 * @param wm The button that was pressed.
7471 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7475 struct widget * menu;
7476 struct widget * row;
7477 struct widget * box;
7480 if(! this->vehicle_cb)
7483 * Register the callback on vehicle updates.
7485 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
7486 attr_position_coord_geo,this);
7487 navit_add_callback(this->nav,this->vehicle_cb);
7490 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
7492 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
7495 menu=gui_internal_menu(this,_("Route Description"));
7497 menu->wfree=gui_internal_route_screen_free;
7498 this->route_data.route_showing=1;
7499 this->route_data.route_table->spx = this->spacing;
7502 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
7504 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
7505 gui_internal_widget_append(box,this->route_data.route_table);
7507 box->spx = this->spacing;
7508 this->route_data.route_table->w=box->w;
7509 gui_internal_widget_append(menu,box);
7510 gui_internal_populate_route_table(this,this->nav);
7511 gui_internal_menu_render(this);
7516 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
7519 int adx=a2->x-a1->x;
7520 int ady=a2->y-a1->y;
7521 int bdx=b2->x-b1->x;
7522 int bdy=b2->y-b1->y;
7523 n = bdy * adx - bdx * ady;
7524 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
7525 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
7536 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
7537 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
7538 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
7541 res->x = a1->x + a * adx / n;
7542 res->y = a1->y + a * ady / n;
7547 struct heightline *next;
7549 struct coord_rect bbox;
7554 struct diagram_point {
7555 struct diagram_point *next;
7559 static struct heightline *
7560 item_get_heightline(struct item *item)
7562 struct heightline *ret=NULL;
7563 struct street_data *sd;
7567 if (item_attr_get(item, attr_label, &attr)) {
7568 height=atoi(attr.u.str);
7569 sd=street_get_data(item);
7570 if (sd && sd->count > 1) {
7571 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
7572 ret->bbox.lu=sd->c[0];
7573 ret->bbox.rl=sd->c[0];
7574 ret->count=sd->count;
7576 for (i = 0 ; i < sd->count ; i++) {
7578 coord_rect_extend(&ret->bbox, sd->c+i);
7581 street_data_free(sd);
7588 * @brief Displays Route Height Profile
7590 * @li The name of the active vehicle
7591 * @param wm The button that was pressed.
7595 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7599 struct widget * menu, *box;
7601 struct map * map=NULL;
7602 struct map_rect * mr=NULL;
7603 struct route * route;
7604 struct item * item =NULL;
7606 struct mapset_handle *msh;
7607 int x,i,first=1,dist=0;
7608 struct coord c,last,res;
7609 struct coord_rect rbbox,dbbox;
7610 struct map_selection sel;
7611 struct heightline *heightline,*heightlines=NULL;
7612 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
7615 sel.range.min=type_height_line_1;
7616 sel.range.max=type_height_line_3;
7619 menu=gui_internal_menu(this,_("Height Profile"));
7620 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
7621 gui_internal_widget_append(menu, box);
7622 route = navit_get_route(this->nav);
7624 map = route_get_map(route);
7626 mr = map_rect_new(map,NULL);
7628 while((item = map_rect_get_item(mr))) {
7629 while (item_coord_get(item, &c, 1)) {
7635 coord_rect_extend(&sel.u.c_rect, &c);
7638 map_rect_destroy(mr);
7639 ms=navit_get_mapset(this->nav);
7641 msh=mapset_open(ms);
7642 while ((map=mapset_next(msh, 1))) {
7643 mr=map_rect_new(map, &sel);
7645 while((item = map_rect_get_item(mr))) {
7646 if (item->type >= sel.range.min && item->type <= sel.range.max) {
7647 heightline=item_get_heightline(item);
7649 heightline->next=heightlines;
7650 heightlines=heightline;
7654 map_rect_destroy(mr);
7663 map = route_get_map(route);
7665 mr = map_rect_new(map,NULL);
7666 if(mr && heightlines) {
7667 while((item = map_rect_get_item(mr))) {
7669 while (item_coord_get(item, &c, 1)) {
7673 heightline=heightlines;
7676 coord_rect_extend(&rbbox, &c);
7677 while (heightline) {
7678 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
7679 for (i = 0 ; i < heightline->count - 1; i++) {
7680 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
7681 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
7682 diagram_point=g_new(struct diagram_point, 1);
7683 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
7684 diagram_point->c.y=heightline->height;
7685 diagram_point->next=diagram_points;
7686 diagram_points=diagram_point;
7687 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
7692 heightline=heightline->next;
7694 dist+=transform_distance(projection_mg, &last, &c);
7700 map_rect_destroy(mr);
7704 gui_internal_menu_render(this);
7706 diagram_point=diagram_points;
7707 while (diagram_point) {
7709 dbbox.lu=diagram_point->c;
7710 dbbox.rl=diagram_point->c;
7713 coord_rect_extend(&dbbox, &diagram_point->c);
7714 diagram_point=diagram_point->next;
7716 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
7717 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
7719 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
7721 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
7727 diagram_point=diagram_points;
7728 while (diagram_point) {
7729 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
7731 diagram_point=diagram_point->next;
7735 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
7736 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
7737 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
7738 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
7742 graphics_draw_lines(this->gra, this->foreground, p, 2);
7752 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7754 struct widget *menu,*wb,*w;
7757 graphics_draw_mode(this->gra, draw_mode_begin);
7758 menu=gui_internal_menu(this, _("Show Locale"));
7759 menu->spx=this->spacing*10;
7760 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
7761 gui_internal_widget_append(menu, wb);
7762 text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
7763 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7764 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7766 #ifdef HAVE_API_WIN32_BASE
7768 char country[32],lang[32];
7769 #ifdef HAVE_API_WIN32_CE
7770 wchar_t wcountry[32],wlang[32];
7772 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
7773 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
7775 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
7777 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
7778 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7779 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7781 #ifdef HAVE_API_WIN32_CE
7782 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
7783 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
7785 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
7787 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
7788 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7789 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7794 gui_internal_menu_render(this);
7795 graphics_draw_mode(this->gra, draw_mode_end);
7799 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7801 struct widget *menu,*wb,*w;
7804 graphics_draw_mode(this->gra, draw_mode_begin);
7805 menu=gui_internal_menu(this, _("About Navit"));
7806 menu->spx=this->spacing*10;
7807 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
7808 gui_internal_widget_append(menu, wb);
7811 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
7812 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
7815 text=g_strdup_printf("%s",PACKAGE_NAME);
7816 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7817 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7821 text=g_strdup_printf("%s",version);
7822 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7823 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7827 text=g_strdup_printf("http://www.navit-project.org/");
7828 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7829 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7833 text=g_strdup_printf("%s:",_("By"));
7834 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7835 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7837 text=g_strdup_printf("Martin Schaller");
7838 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7839 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7841 text=g_strdup_printf("Michael Farmbauer");
7842 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7843 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7845 text=g_strdup_printf("Alexander Atanasov");
7846 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7847 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7849 text=g_strdup_printf("Pierre Grandin");
7850 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7851 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7855 text=g_strdup_printf("%s",_("And all the Navit Team"));
7856 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7857 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7859 text=g_strdup_printf("%s",_("members and contributors."));
7860 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7861 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7864 gui_internal_menu_render(this);
7865 graphics_draw_mode(this->gra, draw_mode_end);
7869 * @brief handles the 'next page' table event.
7870 * A callback function that is invoked when the 'next page' button is pressed
7871 * to advance the contents of a table widget.
7873 * @param this The graphics context.
7874 * @param wm The button widget that was pressed.
7876 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
7878 struct widget * table_widget=NULL;
7879 struct table_data * table_data = NULL;
7882 table_widget = (struct widget * ) wm->data;
7884 table_widget = data;
7886 if(table_widget && table_widget->type==widget_table)
7887 table_data = (struct table_data*) table_widget->data;
7891 GList *l=g_list_next(table_data->bottom_row);
7893 gui_internal_table_hide_rows(table_data);
7894 table_data->top_row=l;
7899 wm->state&= ~STATE_HIGHLIGHTED;
7901 gui_internal_menu_render(this);
7907 * @brief handles the 'previous page' table event.
7908 * A callback function that is invoked when the 'previous page' button is pressed
7909 * to go back in the contents of a table widget.
7911 * @param this The graphics context.
7912 * @param wm The button widget that was pressed.
7914 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
7916 struct widget * table_widget = NULL;
7917 struct table_data * table_data = NULL;
7920 table_widget=(struct widget * ) wm->data;
7922 table_widget=(struct widget * ) data;
7924 if(table_widget && table_widget->type==widget_table)
7925 table_data = (struct table_data*) table_widget->data;
7928 int bottomy=table_widget->p.y+table_widget->h;
7930 GList *top=table_data->top_row;
7931 struct widget *w=(struct widget*)top->data;
7932 if(table_data->button_box->p.y!=0) {
7933 bottomy=table_data->button_box->p.y;
7935 n=(bottomy-w->p.y)/w->h;
7936 while(n-- > 0 && (top=g_list_previous(top))!=NULL);
7937 gui_internal_table_hide_rows(table_data);
7938 table_data->top_row=top;
7941 wm->state&= ~STATE_HIGHLIGHTED;
7942 gui_internal_menu_render(this);
7947 * @brief deallocates a table_data structure.
7950 void gui_internal_table_data_free(void * p)
7955 * @note button_box and its children (next_button,prev_button)
7956 * have their memory managed by the table itself.
7965 * @brief Called when the route is updated.
7967 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
7970 if(this->route_data.route_showing) {
7971 gui_internal_populate_route_table(this,navit);
7972 graphics_draw_mode(this->gra, draw_mode_begin);
7973 gui_internal_menu_render(this);
7974 graphics_draw_mode(this->gra, draw_mode_end);
7982 * @brief Called when the route screen is closed (deallocated).
7984 * The main purpose of this function is to remove the widgets from
7985 * references route_data because those widgets are about to be freed.
7987 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
7990 this_->route_data.route_showing=0;
7991 this_->route_data.route_table=NULL;
7998 * @brief Populates the route table with route information
8000 * @param this The gui context
8001 * @param navit The navit object
8003 void gui_internal_populate_route_table(struct gui_priv * this,
8004 struct navit * navit)
8006 struct map * map=NULL;
8007 struct map_rect * mr=NULL;
8008 struct navigation * nav = NULL;
8009 struct item * item =NULL;
8011 struct widget * label = NULL;
8012 struct widget * row = NULL;
8014 nav = navit_get_navigation(navit);
8018 map = navigation_get_map(nav);
8020 mr = map_rect_new(map,NULL);
8022 gui_internal_widget_table_clear(this,this->route_data.route_table);
8023 while((item = map_rect_get_item(mr))) {
8024 if(item_attr_get(item,attr_navigation_long,&attr)) {
8025 row = gui_internal_widget_table_row_new(this,
8028 | orientation_horizontal);
8029 gui_internal_widget_append(this->route_data.route_table,row);
8031 label = gui_internal_label_new(this,attr.u.str);
8032 gui_internal_widget_append(row,label);
8035 item_coord_get(item, &c, 1);
8038 label->c.pro=map_projection(map);
8039 label->func=gui_internal_cmd_position;
8040 label->state|=STATE_SENSITIVE;
8041 label->data=(void*)2;
8049 static struct command_table commands[] = {
8050 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
8051 {"back",command_cast(gui_internal_cmd2_back)},
8052 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
8053 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
8054 {"formerdests",command_cast(gui_internal_cmd_formerdests)},
8055 {"get_data",command_cast(gui_internal_get_data)},
8056 {"locale",command_cast(gui_internal_cmd2_locale)},
8057 {"log",command_cast(gui_internal_cmd_log)},
8058 {"menu",command_cast(gui_internal_cmd_menu2)},
8059 {"position",command_cast(gui_internal_cmd2_position)},
8060 {"pois",command_cast(gui_internal_cmd2_pois)},
8061 {"refresh",command_cast(gui_internal_cmd2_refresh)},
8062 {"route_description",command_cast(gui_internal_cmd2_route_description)},
8063 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
8064 {"set",command_cast(gui_internal_cmd2_set)},
8065 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
8066 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
8067 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
8068 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
8069 {"town",command_cast(gui_internal_cmd2_town)},
8070 {"quit",command_cast(gui_internal_cmd2_quit)},
8071 {"write",command_cast(gui_internal_cmd_write)},
8072 {"about",command_cast(gui_internal_cmd2_about)},
8077 //##############################################################################################################
8080 //# Authors: Martin Schaller (04/2008)
8081 //##############################################################################################################
8082 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
8084 struct color color_white={0xffff,0xffff,0xffff,0xffff};
8085 struct color color_black={0x0,0x0,0x0,0xffff};
8086 struct color back2_color={0x4141,0x4141,0x4141,0xffff};
8088 struct gui_priv *this;
8090 *meth=gui_internal_methods;
8091 this=g_new0(struct gui_priv, 1);
8094 this->self.type=attr_gui;
8095 this->self.u.gui=gui;
8097 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
8098 this->menu_on_map_click=attr->u.num;
8100 this->menu_on_map_click=1;
8102 if ((attr=attr_search(attrs, NULL, attr_on_map_click)))
8103 this->on_map_click=g_strdup(attr->u.str);
8105 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
8106 this->signal_on_map_click=attr->u.num;
8108 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
8109 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
8112 if( (attr=attr_search(attrs,NULL,attr_font_size)))
8114 this->config.font_size=attr->u.num;
8118 this->config.font_size=-1;
8120 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
8122 this->config.icon_xs=attr->u.num;
8126 this->config.icon_xs=-1;
8128 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
8130 this->config.icon_l=attr->u.num;
8134 this->config.icon_l=-1;
8136 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
8138 this->config.icon_s=attr->u.num;
8142 this->config.icon_s=-1;
8144 if( (attr=attr_search(attrs,NULL,attr_spacing)))
8146 this->config.spacing=attr->u.num;
8150 this->config.spacing=-1;
8152 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
8154 this->speech=attr->u.num;
8156 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
8157 this->keyboard=attr->u.num;
8161 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
8162 this->fullscreen=attr->u.num;
8164 if( (attr=attr_search(attrs,NULL,attr_flags)))
8165 this->flags=attr->u.num;
8166 if( (attr=attr_search(attrs,NULL,attr_background_color)))
8167 this->background_color=*attr->u.color;
8169 this->background_color=color_black;
8170 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
8171 this->background2_color=*attr->u.color;
8173 this->background2_color=back2_color;
8174 if( (attr=attr_search(attrs,NULL,attr_text_color)))
8175 this->text_foreground_color=*attr->u.color;
8177 this->text_foreground_color=color_white;
8178 this->text_background_color=color_black;
8179 if( (attr=attr_search(attrs,NULL,attr_columns)))
8180 this->cols=attr->u.num;
8181 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
8182 this->osd_configuration=*attr;
8184 if( (attr=attr_search(attrs,NULL,attr_pitch)))
8185 this->pitch=attr->u.num;
8188 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
8189 this->flags_town=attr->u.num;
8191 this->flags_town=-1;
8192 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
8193 this->flags_street=attr->u.num;
8195 this->flags_street=-1;
8196 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
8197 this->flags_house_number=attr->u.num;
8199 this->flags_house_number=-1;
8200 if( (attr=attr_search(attrs,NULL,attr_radius)))
8201 this->radius=attr->u.num;
8204 this->data.priv=this;
8205 this->data.gui=&gui_internal_methods_ext;
8206 this->data.widget=&gui_internal_widget_methods;
8207 this->cbl=callback_list_new();
8212 //##############################################################################################################
8215 //# Authors: Martin Schaller (04/2008)
8216 //##############################################################################################################
8217 void plugin_init(void)
8219 plugin_register_gui_type("internal", gui_internal_new);
8223 gui_internal_destroy(struct gui_priv *this)
8226 graphics_font_destroy(this->fonts[0]);
8227 graphics_font_destroy(this->fonts[1]);
8228 graphics_font_destroy(this->fonts[2]);
8229 attr_free(this->click_coord_geo);
8230 attr_free(this->position_coord_geo);
8231 g_free(this->country_iso2);
8233 g_free(this->html_text);
8234 g_free(this->on_map_click);