2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2010 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 //##############################################################################################################
22 //# File: gui_internal.c
23 //# Description: New "internal" GUI for use with any graphics library
24 //# Comment: Trying to make a touchscreen friendly GUI
25 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
27 //##############################################################################################################
37 #ifdef HAVE_API_WIN32_BASE
43 #include "navit_nls.h"
49 #include "transform.h"
55 #include "vehicleprofile.h"
61 #include "navit/search.h"
66 #include "navit_nls.h"
67 #include "navigation.h"
68 #include "gui_internal.h"
70 #include "xmlconfig.h"
72 #include "bookmarks.h"
86 struct widget *search_list;
87 struct widget *keyboard;
88 struct widget *button_bar;
91 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
92 struct widget *redisplay_widget;
94 struct attr refresh_callback_obj,refresh_callback;
97 //##############################################################################################################
100 //# Authors: Martin Schaller (04/2008)
101 //##############################################################################################################
103 enum widget_type type;
104 struct graphics_gc *background,*text_background;
105 struct graphics_gc *foreground_frame;
106 struct graphics_gc *foreground;
108 struct graphics_image *img;
110 * A function to be invoked on actions.
111 * @li widget The widget that is receiving the button press.
114 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
119 * @brief A function to deallocate data
121 void (*data_free)(void *data);
124 * @brief a function that will be called as the widget is being destroyed.
125 * This function can act as a destructor for the widget. It allows for
126 * on deallocation actions to be specified on a per widget basis.
127 * This function will call g_free on the widget (if required).
129 void (*free) (struct gui_priv *this_, struct widget * w);
143 int bl,br,bt,bb,spx,spy;
147 * The number of widgets to layout horizontally when doing
148 * a orientation_horizontal_vertical layout
154 int (*set_attr)(void *, struct attr *);
155 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
156 void (*remove_cb)(void *, struct callback *cb);
163 struct menu_data *menu_data;
169 * @brief A structure to store configuration values.
171 * This structure stores configuration values for how gui elements in the internal GUI
174 struct gui_config_settings {
177 * The base size (in fractions of a point) to use for text.
181 * The size (in pixels) that xs style icons should be scaled to.
182 * This icon size can be too small to click it on some devices.
186 * The size (in pixels) that s style icons (small) should be scaled to
190 * The size (in pixels) that l style icons should be scaled to
194 * The default amount of spacing (in pixels) to place between GUI elements.
201 * Indexes into the config_profiles array.
203 const int LARGE_PROFILE=0;
204 const int MEDIUM_PROFILE=1;
205 const int SMALL_PROFILE=2;
208 * The default config profiles.
210 * [0] => LARGE_PROFILE (screens 640 in one dimension)
211 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
212 * [2] => Small profile (default)
214 static struct gui_config_settings config_profiles[]={
221 struct widget * route_table;
226 //##############################################################################################################
229 //# Authors: Martin Schaller (04/2008)
230 //##############################################################################################################
235 struct graphics *gra;
236 struct graphics_gc *background;
237 struct graphics_gc *background2;
238 struct graphics_gc *highlight_background;
239 struct graphics_gc *foreground;
240 struct graphics_gc *text_foreground;
241 struct graphics_gc *text_background;
242 struct color background_color, background2_color, text_foreground_color, text_background_color;
246 struct graphics_font *fonts[3];
248 * The size (in pixels) that xs style icons should be scaled to.
249 * This icon size can be too small to click it on some devices.
253 * The size (in pixels) that s style icons (small) should be scaled to
257 * The size (in pixels) that l style icons should be scaled to
261 struct widget *widgets;
265 struct widget *highlighted,*editable;
266 struct widget *highlighted_menu;
267 int clickp_valid, vehicle_valid;
268 struct pcoord clickp, vehiclep;
269 struct attr *click_coord_geo, *position_coord_geo;
270 struct search_list *sl;
272 int menu_on_map_click;
273 int signal_on_map_click;
277 int keyboard_required;
279 * The setting information read from the configuration file.
280 * values of -1 indicate no value was specified in the config file.
282 struct gui_config_settings config;
283 struct event_idle *idle;
284 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
285 struct event_timeout *motion_timeout_event;
286 struct point current;
288 struct callback * vehicle_cb;
290 * Stores information about the route.
292 struct route_data route_data;
294 struct gui_internal_data data;
295 struct callback_list *cbl;
298 struct attr osd_configuration;
300 int flags_town,flags_street,flags_house_number;
302 int mouse_button_clicked_on_map;
306 struct widget *html_container;
310 int html_anchor_found;
330 struct widget *container;
334 struct html_tag_map {
340 {"html",html_tag_html},
341 {"img",html_tag_img},
342 {"script",html_tag_script},
343 {"form",html_tag_form},
344 {"input",html_tag_input},
345 {"div",html_tag_div},
350 * @brief A structure to store information about a table.
352 * The table_data widget stores pointers to extra information needed by the
355 * The table_data structure needs to be freed with data_free along with the widget.
361 * A GList pointer into a widget->children list that indicates the row
362 * currently being rendered at the top of the table.
366 * A Glist pointer into a widget->children list that indicates the row
367 * currently being rendered at the bottom of the table.
372 * A list of table_row widgets that mark the
373 * top rows for each page of the table.
374 * This is needed for the 'previous page' function of the table.
376 GList * page_headers;
379 * A container box that is the child of the table widget that contains+groups
380 * the next and previous button.
382 struct widget * button_box;
385 * Button box should not be displayed if button_box_hide is not zero.
390 * A button widget to handle 'next page' requests
392 struct widget * next_button;
394 * A button widget to handle 'previous page' requests.
396 struct widget * prev_button;
400 * a pointer to the gui context.
401 * This is needed by the free function to destory the buttons.
403 struct gui_priv * this;
407 * A data structure that holds information about a column that makes up a table.
411 struct table_column_desc
415 * The computed height of a cell in the table.
420 * The computed width of a cell in the table.
426 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
427 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
428 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
429 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
430 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child);
431 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child);
432 static void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func);
433 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
434 static void gui_internal_apply_config(struct gui_priv *this);
436 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
437 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
438 static void gui_internal_table_hide_rows(struct table_data * table_data);
439 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
440 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
441 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
442 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
443 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
444 static int gui_internal_widget_table_is_empty(struct gui_priv *this,struct widget * table);
445 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
446 static void gui_internal_table_data_free(void * d);
447 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
449 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
450 static void gui_internal_populate_route_table(struct gui_priv * this,
451 struct navit * navit);
452 static void gui_internal_search_idle_end(struct gui_priv *this);
453 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
454 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
455 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
456 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
457 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
458 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
459 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
460 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
461 static void gui_internal_check_exit(struct gui_priv *this);
462 static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
464 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
465 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
467 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
468 static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
469 static void gui_internal_html_load_href(struct gui_priv *this, char *href, int replace);
470 static void gui_internal_destroy(struct gui_priv *this);
474 * * Display image scaled to specific size
475 * * searches for scaleable and pre-scaled image
476 * * @param this Our gui context
477 * * @param name image name
478 * * @param w desired width of image
479 * * @param h desired height of image
480 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
482 static struct graphics_image *
483 image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
485 struct graphics_image *ret=NULL;
486 char *full_name=NULL;
487 char *full_path=NULL;
490 for (i = 1 ; i < 6 ; i++) {
494 full_name=g_strdup_printf("%s.svg", name);
497 full_name=g_strdup_printf("%s.svgz", name);
500 if (w != -1 && h != -1) {
501 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
505 full_name=g_strdup_printf("%s.png", name);
508 full_name=g_strdup_printf("%s.xpm", name);
511 dbg(1,"trying '%s'\n", full_name);
515 /* needs to be checked in the driver */
516 if (!file_exists(full_name)) {
521 full_path=graphics_icon_path(full_name);
522 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
523 dbg(1,"ret=%p\n", ret);
529 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
534 static struct graphics_image *
535 image_new_o(struct gui_priv *this, char *name)
537 return image_new_scaled(this, name, -1, -1);
542 * * Display image scaled to xs (extra small) size
543 * * This image size can be too small to click it on some devices.
544 * * @param this Our gui context
545 * * @param name image name
546 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
548 static struct graphics_image *
549 image_new_xs(struct gui_priv *this, const char *name)
551 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
555 * * Display image scaled to s (small) size
556 * * @param this Our gui context
557 * * @param name image name
558 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
561 static struct graphics_image *
562 image_new_s(struct gui_priv *this, const char *name)
564 return image_new_scaled(this, name, this->icon_s, this->icon_s);
568 * * Display image scaled to l (large) size
569 * * @param this Our gui context
570 * * @param name image name
571 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
573 static struct graphics_image *
574 image_new_l(struct gui_priv *this, const char *name)
576 return image_new_scaled(this, name, this->icon_l, this->icon_l);
580 coordinates_geo(const struct coord_geo *gc, char sep)
582 char latc='N',lngc='E';
583 int lat_deg,lat_min,lat_sec;
584 int lng_deg,lng_min,lng_sec;
585 struct coord_geo g=*gc;
596 lat_min=fmod(g.lat*60,60);
597 lat_sec=fmod(g.lat*3600,60);
599 lng_min=fmod(g.lng*60,60);
600 lng_sec=fmod(g.lng*3600,60);
601 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);
605 coordinates(struct pcoord *pc, char sep)
611 transform_to_geo(pc->pro, &c, &g);
612 return coordinates_geo(&g, sep);
617 gui_internal_background_render(struct gui_priv *this, struct widget *w)
619 struct point pnt=w->p;
620 if (w->state & STATE_HIGHLIGHTED)
621 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
624 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
628 static struct widget *
629 gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
635 struct widget *widget=g_new0(struct widget, 1);
636 widget->type=widget_label;
637 widget->font_idx=font;
639 widget->text=g_strdup(text);
640 graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
644 widget->h=h+this->spacing;
646 widget->w=w+this->spacing;
648 widget->flags=gravity_center;
649 widget->foreground=this->text_foreground;
650 widget->text_background=this->text_background;
655 static struct widget *
656 gui_internal_label_new(struct gui_priv *this, char *text)
658 return gui_internal_label_font_new(this, text, 0);
661 static struct widget *
662 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
664 struct widget *ret=NULL;
665 char *tmp=g_malloc(strlen(text)+3), *p;
667 while ((p=g_utf8_find_prev_char(text, p)) >= text) {
671 ret=gui_internal_label_new(this, tmp);
672 if (ret->w < maxwidth)
674 gui_internal_widget_destroy(this, ret);
678 ret=gui_internal_label_new(this, "");
683 static struct widget *
684 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
686 struct widget *widget=g_new0(struct widget, 1);
687 widget->type=widget_image;
690 widget->w=image->width;
691 widget->h=image->height;
697 gui_internal_image_render(struct gui_priv *this, struct widget *w)
701 gui_internal_background_render(this, w);
704 pnt.x+=w->w/2-w->img->hot.x;
705 pnt.y+=w->h/2-w->img->hot.y;
706 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
711 gui_internal_label_render(struct gui_priv *this, struct widget *w)
713 struct point pnt=w->p;
714 gui_internal_background_render(this, w);
715 if (w->state & STATE_EDIT)
716 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
719 char *startext=(char*)g_alloca(strlen(w->text)+1);
723 for (i = 0 ; i < strlen(text); i++)
728 if (w->flags & gravity_right) {
729 pnt.y+=w->h-this->spacing;
730 pnt.x+=w->w-w->textw-this->spacing;
731 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
733 pnt.y+=w->h-this->spacing;
734 graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], text, &pnt, 0x10000, 0x0);
740 * @brief A text box is a widget that renders a text string containing newlines.
741 * The string will be broken up into label widgets at each newline with a vertical layout.
744 static struct widget *
745 gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
747 char *s=g_strdup(text),*s2,*tok;
748 struct widget *ret=gui_internal_box_new(this, flags);
750 while ((tok=strtok(s2,"\n"))) {
751 gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
754 gui_internal_widget_pack(this,ret);
759 static struct widget *
760 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
762 return gui_internal_text_font_new(this, text, 0, flags);
766 static struct widget *
767 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)
769 struct widget *ret=NULL;
770 ret=gui_internal_box_new(this, flags);
773 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
775 gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
779 ret->state |= STATE_SENSITIVE;
780 ret->speech=g_strdup(text);
787 static struct widget *
788 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)
790 return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
794 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
801 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
802 is_on=curr.u.data == w->on.u.data;
805 if (is_on != w->is_on) {
809 l=g_list_first(w->children);
813 graphics_image_free(this->gra, wi->img);
814 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
816 if (w->is_on && w->off.type == attr_none)
817 w->state &= ~STATE_SENSITIVE;
819 w->state |= STATE_SENSITIVE;
826 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
828 if (gui_internal_button_attr_update(this, w))
829 gui_internal_widget_render(this, w);
832 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
835 w->set_attr(w->instance, &w->off);
837 w->set_attr(w->instance, &w->on);
838 gui_internal_button_attr_update(this, w);
842 static struct widget *
843 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
845 struct graphics_image *image=NULL;
849 image=image_new_xs(this, "gui_inactive");
850 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
855 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
856 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
857 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
858 ret->instance=this->nav;
859 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
860 navit_add_callback(this->nav, ret->cb);
861 gui_internal_button_attr_update(this, ret);
865 static struct widget *
866 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)
868 struct graphics_image *image=NULL;
870 image=image_new_xs(this, "gui_inactive");
873 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
879 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
880 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
881 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
884 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
885 map_add_callback(map, ret->cb);
886 gui_internal_button_attr_update(this, ret);
890 static struct widget *
891 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
893 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
897 //##############################################################################################################
900 //# Authors: Martin Schaller (04/2008)
901 //##############################################################################################################
902 static void gui_internal_clear(struct gui_priv *this)
904 struct graphics *gra=this->gra;
908 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
912 static struct widget *
913 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
915 struct widget *ret,*child;
916 GList *l=wi->children;
923 if ( wi->p.x + wi->w < p->x)
925 if ( wi->p.y + wi->h < p->y)
928 if (wi->state & flags)
932 ret=gui_internal_find_widget(child, p, flags);
943 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
945 if (found == this->highlighted)
948 graphics_draw_mode(this->gra, draw_mode_begin);
949 if (this->highlighted) {
950 this->highlighted->state &= ~STATE_HIGHLIGHTED;
951 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
952 gui_internal_widget_render(this, this->highlighted);
953 this->highlighted=NULL;
954 this->highlighted_menu=NULL;
957 this->highlighted=found;
958 this->highlighted_menu=g_list_last(this->root.children)->data;
959 this->highlighted->state |= STATE_HIGHLIGHTED;
960 gui_internal_widget_render(this, this->highlighted);
961 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
963 graphics_draw_mode(this->gra, draw_mode_end);
965 //##############################################################################################################
968 //# Authors: Martin Schaller (04/2008)
969 //##############################################################################################################
970 static void gui_internal_highlight(struct gui_priv *this)
972 struct widget *menu,*found=NULL;
973 if (this->current.x > -1 && this->current.y > -1) {
974 menu=g_list_last(this->root.children)->data;
975 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
977 found=gui_internal_find_widget(menu, &this->current, STATE_EDITABLE);
979 if (this->editable && this->editable != found) {
980 this->editable->state &= ~ STATE_EDIT;
981 gui_internal_widget_render(this, this->editable);
983 found->state |= STATE_EDIT;
984 gui_internal_widget_render(this, found);
985 this->editable=found;
990 gui_internal_highlight_do(this, found);
991 this->motion_timeout_event=NULL;
994 static struct widget *
995 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
997 struct widget *widget=g_new0(struct widget, 1);
1000 widget->text=g_strdup(label);
1001 widget->type=widget_box;
1002 widget->flags=flags;
1006 static struct widget *
1007 gui_internal_box_new(struct gui_priv *this, enum flags flags)
1009 return gui_internal_box_new_with_label(this, flags, NULL);
1013 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
1018 gui_internal_background_render(this, w);
1021 w->foreground=this->foreground;
1024 if (w->foreground && w->border) {
1025 struct point pnt[5];
1027 pnt[1].x=pnt[0].x+w->w;
1029 pnt[2].x=pnt[0].x+w->w;
1030 pnt[2].y=pnt[0].y+w->h;
1032 pnt[3].y=pnt[0].y+w->h;
1034 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
1035 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
1036 graphics_gc_set_linewidth(w->foreground, 1);
1043 gui_internal_widget_render(this, wc);
1050 * @brief Compute the size and location for the widget.
1054 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
1057 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;
1059 int orientation=w->flags & 0xffff0000;
1064 if ( this->root.w > this->root.h )
1074 * count the number of children
1081 if (orientation == orientation_horizontal_vertical && count <= cols)
1082 orientation=orientation_horizontal;
1083 switch (orientation) {
1084 case orientation_horizontal:
1086 * For horizontal orientation:
1087 * pack each child and find the largest height and
1088 * compute the total width. x spacing (spx) is considered
1090 * If any children want to be expanded
1091 * we keep track of this
1096 gui_internal_widget_pack(this, wc);
1100 if (wc->flags & flags_expand)
1101 expand+=wc->w ? wc->w : 1;
1107 if (expand && w->w) {
1108 expandd=w->w-width+expand;
1113 case orientation_vertical:
1115 * For vertical layouts:
1116 * We pack each child and compute the largest width and
1117 * the total height. y spacing (spy) is considered
1119 * If the expand flag is set then teh expansion amount
1125 gui_internal_widget_pack(this, wc);
1129 if (wc->flags & flags_expand)
1130 expand+=wc->h ? wc->h : 1;
1136 if (expand && w->h) {
1137 expandd=w->h-height+expand;
1142 case orientation_horizontal_vertical:
1144 * For horizontal_vertical orientation
1145 * pack the children.
1146 * Compute the largest height and largest width.
1147 * Layout the widgets based on having the
1148 * number of columns specified by (cols)
1154 gui_internal_widget_pack(this, wc);
1164 rows=(count+cols-1)/cols;
1167 width+=w->spx*(cols-1);
1168 height+=w->spy*(rows-1);
1175 * No orientation was specified.
1176 * width and height are both 0.
1177 * The width & height of this widget
1181 dbg(0,"Warning width and height of a widget are 0");
1184 if (! w->w && ! w->h) {
1185 w->w=w->bl+w->br+width;
1186 w->h=w->bt+w->bb+height;
1195 * At this stage the width and height of this
1196 * widget has been computed.
1197 * We now make a second pass assigning heights,
1198 * widths and coordinates to each child widget.
1201 if (w->flags & gravity_left)
1203 if (w->flags & gravity_xcenter)
1204 x=w->p.x+w->w/2-owidth/2;
1205 if (w->flags & gravity_right)
1206 x=w->p.x+w->w-w->br-owidth;
1207 if (w->flags & gravity_top)
1209 if (w->flags & gravity_ycenter)
1210 y=w->p.y+w->h/2-oheight/2;
1211 if (w->flags & gravity_bottom)
1212 y=w->p.y+w->h-w->bb-oheight;
1214 switch (orientation) {
1215 case orientation_horizontal:
1220 if (wc->flags & flags_fill)
1222 if (wc->flags & flags_expand) {
1225 wc->w=wc->w*expandd/expand;
1227 if (w->flags & gravity_top)
1229 if (w->flags & gravity_ycenter)
1231 if (w->flags & gravity_bottom)
1237 case orientation_vertical:
1242 if (wc->flags & flags_fill)
1244 if (wc->flags & flags_expand) {
1247 wc->h=wc->h*expandd/expand;
1249 if (w->flags & gravity_left)
1251 if (w->flags & gravity_xcenter)
1253 if (w->flags & gravity_right)
1259 case orientation_horizontal_vertical:
1269 if (wc->flags & flags_fill) {
1273 if (w->flags & gravity_left)
1275 if (w->flags & gravity_xcenter)
1276 wc->p.x=x+(width-wc->w)/2;
1277 if (w->flags & gravity_right)
1278 wc->p.x=x+width-wc->w;
1279 if (w->flags & gravity_top)
1281 if (w->flags & gravity_ycenter)
1282 wc->p.y=y+(height-wc->h)/2;
1283 if (w->flags & gravity_bottom)
1284 wc->p.y=y-height-wc->h;
1286 if (++count == cols) {
1298 * Call pack again on each child,
1299 * the child has now had its size and coordinates
1300 * set so they can repack their children.
1305 gui_internal_widget_pack(this, wc);
1311 gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
1319 gui_internal_widget_reset_pack(this, wc);
1329 gui_internal_widget_append(struct widget *parent, struct widget *child)
1333 if (! child->background)
1334 child->background=parent->background;
1335 parent->children=g_list_append(parent->children, child);
1338 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1340 if (! child->background)
1341 child->background=parent->background;
1342 parent->children=g_list_prepend(parent->children, child);
1345 static void gui_internal_widget_insert_before(struct widget *parent, struct widget *sibling, struct widget *child)
1348 if (! child->background)
1349 child->background=parent->background;
1352 sib=g_list_find(parent->children,sibling);
1353 parent->children=g_list_insert_before(parent->children, sib, child);
1356 static void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *child, GCompareFunc func)
1358 if (! child->background)
1359 child->background=parent->background;
1361 parent->children=g_list_insert_sorted(parent->children, child, func);
1365 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1373 gui_internal_widget_destroy(this, wc);
1376 g_list_free(w->children);
1381 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1383 gui_internal_widget_children_destroy(this, w);
1388 graphics_image_free(this->gra, w->img);
1394 w->data_free(w->data);
1395 if (w->cb && w->remove_cb)
1396 w->remove_cb(w->instance, w->cb);
1397 if (w==this->highlighted)
1398 this->highlighted=NULL;
1407 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1409 if(w->p.x > this->root.w || w->p.y > this->root.h)
1414 gui_internal_box_render(this, w);
1417 gui_internal_label_render(this, w);
1420 gui_internal_image_render(this, w);
1423 gui_internal_table_render(this,w);
1431 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1435 gui_internal_box_pack(this, w);
1438 gui_internal_table_pack(this,w);
1444 //##############################################################################################################
1447 //# Authors: Martin Schaller (04/2008)
1448 //##############################################################################################################
1449 static void gui_internal_call_highlighted(struct gui_priv *this)
1451 if (! this->highlighted || ! this->highlighted->func)
1453 this->highlighted->reason=1;
1454 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1458 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1460 char *text=w->speech;
1468 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1469 navit_say(this->nav, text);
1475 gui_internal_menu_destroy(struct gui_priv *this, struct widget *w)
1477 struct menu_data *menu_data=w->menu_data;
1479 if (menu_data->refresh_callback_obj.type) {
1480 struct object_func *func;
1481 func=object_func_lookup(menu_data->refresh_callback_obj.type);
1482 if (func && func->remove_attr)
1483 func->remove_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
1485 if (menu_data->refresh_callback.u.callback)
1486 callback_destroy(menu_data->refresh_callback.u.callback);
1488 g_free(menu_data->href);
1491 gui_internal_widget_destroy(this, w);
1492 this->root.children=g_list_remove(this->root.children, w);
1496 gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render)
1499 struct widget *wr,*wd;
1500 gui_internal_search_idle_end(this);
1501 while ((l = g_list_last(this->root.children))) {
1504 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1507 gui_internal_say(this, w, 0);
1508 redisplay=w->menu_data->redisplay;
1509 wr=w->menu_data->redisplay_widget;
1510 if (!w->menu_data->redisplay && !w->menu_data->href) {
1511 gui_internal_widget_render(this, w);
1515 gui_internal_menu_destroy(this, w);
1516 redisplay(this, wr, wr->data);
1518 char *href=g_strdup(w->menu_data->href);
1519 gui_internal_menu_destroy(this, w);
1520 gui_internal_html_load_href(this, href, 0);
1525 gui_internal_menu_destroy(this, wd);
1530 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1532 gui_internal_prune_menu_do(this, w, 1);
1536 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1538 GList *l=g_list_last(this->root.children);
1539 struct widget *w=NULL;
1540 while (l && count-- > 0)
1541 l=g_list_previous(l);
1544 gui_internal_prune_menu_do(this, w, render);
1549 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1551 gui_internal_prune_menu_count(this, 1, 1);
1555 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1557 gui_internal_prune_menu(this, wm->data);
1561 gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1563 graphics_draw_mode(this->gra, draw_mode_begin);
1564 gui_internal_back(this, NULL, NULL);
1565 graphics_draw_mode(this->gra, draw_mode_end);
1566 gui_internal_check_exit(this);
1570 gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
1572 gui_internal_prune_menu(this, NULL);
1576 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1578 gui_internal_prune_menu(this, this->root.children->data);
1581 static struct widget *
1582 gui_internal_top_bar(struct gui_priv *this)
1584 struct widget *w,*wm,*wh,*wc,*wcn;
1585 int dots_len, sep_len;
1587 int width,width_used=0,use_sep=0,incomplete=0;
1588 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1590 1:Don't expand bar to screen width
1591 2:Don't show Map Icon
1592 4:Don't show Home Icon
1593 8:Show only current menu
1594 16:Don't use menu titles as button
1595 32:Show navit version
1598 256:Use background for menu headline
1599 512:Set osd_configuration and zoom to route when setting position
1600 1024:Don't show back button
1601 2048:No highlighting of keyboard
1604 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1605 w->bl=this->spacing;
1606 w->spx=this->spacing;
1607 w->background=this->background2;
1608 if ((this->flags & 6) == 6) {
1614 width=this->root.w-w->bl;
1615 if (! (this->flags & 2)) {
1616 wm=gui_internal_button_new_with_callback(this, NULL,
1617 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1618 gui_internal_cmd_return, NULL);
1619 wm->speech=g_strdup(_("Back to map"));
1620 gui_internal_widget_pack(this, wm);
1621 gui_internal_widget_append(w, wm);
1624 if (! (this->flags & 4)) {
1625 wh=gui_internal_button_new_with_callback(this, NULL,
1626 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1627 gui_internal_cmd_main_menu, NULL);
1628 wh->speech=g_strdup(_("Main Menu"));
1629 gui_internal_widget_pack(this, wh);
1630 gui_internal_widget_append(w, wh);
1633 if (!(this->flags & 6))
1635 l=g_list_last(this->root.children);
1636 wcn=gui_internal_label_new(this,".. »");
1637 wcn->foreground=foreground;
1639 gui_internal_widget_destroy(this, wcn);
1640 wcn=gui_internal_label_new(this,"»");
1641 wcn->foreground=foreground;
1643 gui_internal_widget_destroy(this, wcn);
1645 if (g_list_previous(l) || !g_list_next(l)) {
1647 wcn=gui_internal_label_new(this, wc->text);
1648 wcn->foreground=foreground;
1653 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1654 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1656 gui_internal_widget_destroy(this, wcn);
1660 struct widget *wct=gui_internal_label_new(this, "»");
1661 wct->foreground=foreground;
1662 res=g_list_prepend(res, wct);
1663 width_used+=sep_len+w->spx;
1666 if (!(this->flags & 16)) {
1667 wcn->func=gui_internal_cmd_return;
1669 wcn->state |= STATE_SENSITIVE;
1671 res=g_list_prepend(res, wcn);
1672 if (this->flags & 8)
1675 l=g_list_previous(l);
1679 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1680 wcn->foreground=foreground;
1681 wcn->func=gui_internal_cmd_return;
1683 wcn->state |= STATE_SENSITIVE;
1684 res=g_list_prepend(res, wcn);
1685 l=g_list_previous(l);
1689 wcn=gui_internal_label_new(this, ".. »");
1690 wcn->foreground=foreground;
1691 wcn->func=gui_internal_cmd_return;
1693 wcn->state |= STATE_SENSITIVE;
1694 res=g_list_prepend(res, wcn);
1699 gui_internal_widget_append(w, l->data);
1702 if (this->flags & 32) {
1703 char *version_text=g_strdup_printf("Navit %s",version);
1704 wcn=gui_internal_label_new(this, version_text);
1705 g_free(version_text);
1706 wcn->flags=gravity_right_center|flags_expand;
1707 gui_internal_widget_append(w, wcn);
1711 gui_internal_widget_destroy(this, dots);
1716 static struct widget *
1717 gui_internal_time_help(struct gui_priv *this)
1719 struct widget *w,*wc,*wcn;
1724 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1725 w->bl=this->spacing;
1726 w->spx=this->spacing;
1732 if (this->flags & 64) {
1733 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1739 tm=localtime(&timep);
1740 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1741 wcn=gui_internal_label_new(this, timestr);
1742 gui_internal_widget_append(wc, wcn);
1743 gui_internal_widget_append(w, wc);
1745 if (this->flags & 128) {
1746 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1747 gui_internal_widget_append(w, wcn);
1754 * Applys the configuration values to this based on the settings
1755 * specified in the configuration file (this->config) and
1756 * the most approriate default profile based on screen resolution.
1758 * This function should be run after this->root is setup and could
1759 * be rerun after the window is resized.
1761 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1763 static void gui_internal_apply_config(struct gui_priv *this)
1765 struct gui_config_settings * current_config=0;
1767 dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
1769 * Select default values from profile based on the screen.
1771 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1773 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1775 current_config = &config_profiles[LARGE_PROFILE];
1779 current_config = &config_profiles[MEDIUM_PROFILE];
1784 current_config = &config_profiles[SMALL_PROFILE];
1788 * Apply override values from config file
1790 if(this->config.font_size == -1 )
1792 this->font_size = current_config->font_size;
1796 this->font_size = this->config.font_size;
1799 if(this->config.icon_xs == -1 )
1801 this->icon_xs = current_config->icon_xs;
1805 this->icon_xs = this->config.icon_xs;
1808 if(this->config.icon_s == -1 )
1810 this->icon_s = current_config->icon_s;
1814 this->icon_s = this->config.icon_s;
1816 if(this->config.icon_l == -1 )
1818 this->icon_l = current_config->icon_l;
1822 this->icon_l = this->config.icon_l;
1824 if(this->config.spacing == -1 )
1826 this->spacing = current_config->spacing;
1830 this->spacing = current_config->spacing;
1835 static struct widget *
1836 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1838 struct widget *wl,*wlb;
1839 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1840 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1841 wl=gui_internal_label_new(this, label);
1843 wlb->foreground=this->text_foreground;
1848 gui_internal_widget_append(wlb, wl);
1850 gui_internal_widget_prepend(wb, wlb);
1852 gui_internal_widget_append(wb, wlb);
1858 static struct widget *
1859 gui_internal_menu(struct gui_priv *this, const char *label)
1861 struct widget *menu,*w,*w1,*topbox;
1863 gui_internal_search_idle_end(this);
1864 topbox=gui_internal_box_new_with_label(this, 0, label);
1865 topbox->w=this->root.w;
1866 topbox->h=this->root.h;
1867 gui_internal_widget_append(&this->root, topbox);
1868 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1869 menu->w=this->root.w;
1870 menu->h=this->root.h;
1871 menu->background=this->background;
1872 gui_internal_apply_config(this);
1873 if (!this->fonts[0]) {
1874 this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
1875 this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
1876 this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
1878 topbox->menu_data=g_new0(struct menu_data, 1);
1879 gui_internal_widget_append(topbox, menu);
1880 w=gui_internal_top_bar(this);
1881 gui_internal_widget_append(menu, w);
1882 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1883 w->spx=4*this->spacing;
1885 gui_internal_widget_append(menu, w);
1886 if (this->flags & 16 && !(this->flags & 1024)) {
1887 struct widget *wlb,*wb,*wm=w;
1888 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1889 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1890 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1891 gui_internal_widget_append(wm, w);
1892 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1898 topbox->menu_data->button_bar=wb;
1899 gui_internal_widget_append(wm, wb);
1900 wlb=gui_internal_button_label(this,_("Back"),1);
1901 wlb->func=gui_internal_back;
1902 wlb->state |= STATE_SENSITIVE;
1904 if (this->flags & 192) {
1905 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1906 menu->w=this->root.w;
1907 menu->h=this->root.h;
1908 w1=gui_internal_time_help(this);
1909 gui_internal_widget_append(menu, w1);
1910 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1911 gui_internal_widget_append(menu, w1);
1912 gui_internal_widget_append(topbox, menu);
1913 menu->background=NULL;
1915 gui_internal_widget_pack(this, topbox);
1916 gui_internal_widget_reset_pack(this, topbox);
1917 topbox->w=this->root.w;
1918 topbox->h=this->root.h;
1919 menu->w=this->root.w;
1920 menu->h=this->root.h;
1924 static struct menu_data *
1925 gui_internal_menu_data(struct gui_priv *this)
1928 struct widget *menu;
1930 l=g_list_last(this->root.children);
1932 return menu->menu_data;
1936 gui_internal_menu_reset_pack(struct gui_priv *this)
1939 struct widget *top_box;
1941 l=g_list_last(this->root.children);
1943 gui_internal_widget_reset_pack(this, top_box);
1947 gui_internal_menu_render(struct gui_priv *this)
1950 struct widget *menu;
1952 l=g_list_last(this->root.children);
1954 gui_internal_say(this, menu, 0);
1955 gui_internal_widget_pack(this, menu);
1956 gui_internal_widget_render(this, menu);
1960 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1963 dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
1964 navit_set_destination(this->nav, &wm->c, name, 1);
1965 if (this->flags & 512) {
1967 follow.type=attr_follow;
1969 navit_set_attr(this->nav, &this->osd_configuration);
1970 navit_set_attr(this->nav, &follow);
1971 navit_zoom_to_route(this->nav, 0);
1973 gui_internal_prune_menu(this, NULL);
1977 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1979 navit_set_position(this->nav, &wm->c);
1980 gui_internal_prune_menu(this, NULL);
1984 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1988 dbg(0,"text='%s'\n", widget->text);
1989 if (widget->text && strlen(widget->text)){
1990 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
1991 bookmarks_add_bookmark(attr.u.bookmarks, &widget->c, widget->text);
1993 g_free(widget->text);
1995 l=g_list_previous(g_list_last(this->root.children));
1996 gui_internal_prune_menu(this, l->data);
2000 gui_internal_cmd_add_bookmark_folder_do(struct gui_priv *this, struct widget *widget)
2004 dbg(0,"text='%s'\n", widget->text);
2005 if (widget->text && strlen(widget->text)){
2006 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2007 bookmarks_add_bookmark(attr.u.bookmarks, NULL, widget->text);
2009 g_free(widget->text);
2011 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2012 gui_internal_prune_menu(this, l->data);
2016 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
2018 gui_internal_cmd_add_bookmark_do(this, widget->data);
2022 gui_internal_cmd_add_bookmark_folder_clicked(struct gui_priv *this, struct widget *widget, void *data)
2024 gui_internal_cmd_add_bookmark_folder_do(this, widget->data);
2028 gui_internal_cmd_rename_bookmark_clicked(struct gui_priv *this, struct widget *widget,void *data)
2030 struct widget *w=(struct widget*)widget->data;
2033 dbg(0,"text='%s'\n", w->text);
2034 if (w->text && strlen(w->text)){
2035 navit_get_attr(this->nav, attr_bookmarks, &attr, NULL);
2036 bookmarks_rename_bookmark(attr.u.bookmarks, w->name, w->text);
2042 l=g_list_previous(g_list_previous(g_list_previous(g_list_last(this->root.children))));
2043 gui_internal_prune_menu(this, l->data);
2047 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
2052 len=strlen(wm->text);
2053 dbg(1,"len=%d\n", len);
2054 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2055 wm->text[len-1]='\0';
2056 gui_internal_cmd_add_bookmark_do(this, wm);
2062 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
2065 gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
2067 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2069 wb=gui_internal_menu(this,_("Add Bookmark"));
2070 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2071 gui_internal_widget_append(wb, w);
2072 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2073 gui_internal_widget_append(w, we);
2074 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2075 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2076 wk->background=this->background;
2077 wk->flags |= flags_expand|flags_fill;
2078 wk->func = gui_internal_cmd_add_bookmark_changed;
2080 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2081 wnext->state |= STATE_SENSITIVE;
2082 wnext->func = gui_internal_cmd_add_bookmark_clicked;
2084 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2085 gui_internal_widget_append(w, wl);
2087 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2088 gui_internal_menu_render(this);
2092 gui_internal_cmd_add_bookmark_folder2(struct gui_priv *this, struct widget *wm, void *data)
2094 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2096 wb=gui_internal_menu(this,_("Add Bookmark folder"));
2097 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2098 gui_internal_widget_append(wb, w);
2099 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2100 gui_internal_widget_append(w, we);
2101 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2102 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2103 wk->background=this->background;
2104 wk->flags |= flags_expand|flags_fill;
2105 wk->func = gui_internal_cmd_add_bookmark_changed;
2107 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2108 wnext->state |= STATE_SENSITIVE;
2109 wnext->func = gui_internal_cmd_add_bookmark_folder_clicked;
2111 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2112 gui_internal_widget_append(w, wl);
2114 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2115 gui_internal_menu_render(this);
2119 gui_internal_cmd_rename_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2121 struct widget *w,*wb,*wk,*wl,*we,*wnext;
2122 char *name=wm->text;
2123 wb=gui_internal_menu(this,_("Rename"));
2124 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2125 gui_internal_widget_append(wb, w);
2126 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2127 gui_internal_widget_append(w, we);
2128 gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
2129 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
2130 wk->background=this->background;
2131 wk->flags |= flags_expand|flags_fill;
2132 wk->func = gui_internal_cmd_add_bookmark_changed;
2134 wk->name=g_strdup(name);
2135 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2136 wnext->state |= STATE_SENSITIVE;
2137 wnext->func = gui_internal_cmd_rename_bookmark_clicked;
2139 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2140 gui_internal_widget_append(w, wl);
2142 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2143 gui_internal_menu_render(this);
2147 gui_internal_cmd_cut_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2151 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2152 bookmarks_cut_bookmark(mattr.u.bookmarks,wm->text);
2153 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2154 gui_internal_prune_menu(this, l->data);
2158 gui_internal_cmd_copy_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2162 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2163 bookmarks_copy_bookmark(mattr.u.bookmarks,wm->text);
2164 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2165 gui_internal_prune_menu(this, l->data);
2169 gui_internal_cmd_paste_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2173 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2174 bookmarks_paste_bookmark(mattr.u.bookmarks);
2175 l=g_list_previous(g_list_last(this->root.children));
2176 gui_internal_prune_menu(this, l->data);
2180 gui_internal_cmd_delete_bookmark(struct gui_priv *this, struct widget *wm, void *data)
2184 navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL);
2185 bookmarks_delete_bookmark(mattr.u.bookmarks,wm->text);
2186 l=g_list_previous(g_list_previous(g_list_last(this->root.children)));
2187 gui_internal_prune_menu(this, l->data);
2191 get_direction(char *buffer, int angle, int mode)
2196 sprintf(buffer,"%d",angle);
2199 if (angle < 69 || angle > 291)
2201 if (angle > 111 && angle < 249)
2203 if (angle > 22 && angle < 158)
2205 if (angle > 202 && angle < 338)
2210 angle=(angle+15)/30;
2213 sprintf(buffer,"%d H", angle);
2218 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
2221 //MSVC doesn't supports this style of initialization and i'm not sure
2226 enum item_type *types;
2228 struct selector selectors[]={
2229 {"bank","Bank",(enum item_type []){
2230 type_poi_bank,type_poi_bank,
2231 type_poi_atm,type_poi_atm,
2233 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
2234 {"hotel","Hotel",(enum item_type []) {
2235 type_poi_hotel,type_poi_camp_rv,
2236 type_poi_camping,type_poi_camping,
2237 type_poi_resort,type_poi_resort,
2238 type_poi_motel,type_poi_hostel,
2240 {"restaurant","Restaurant",(enum item_type []) {
2241 type_poi_bar,type_poi_picnic,
2242 type_poi_burgerking,type_poi_fastfood,
2243 type_poi_restaurant,type_poi_restaurant,
2244 type_poi_cafe,type_poi_cafe,
2245 type_poi_pub,type_poi_pub,
2247 {"shopping","Shopping",(enum item_type []) {
2248 type_poi_mall,type_poi_mall,
2249 type_poi_shop_grocery,type_poi_shop_grocery,
2250 type_poi_shopping,type_poi_shopping,
2251 type_poi_shop_butcher,type_poi_shop_baker,
2252 type_poi_shop_fruit,type_poi_shop_fruit,
2253 type_poi_shop_beverages,type_poi_shop_beverages,
2255 {"hospital","Service",(enum item_type []) {
2256 type_poi_marina,type_poi_marina,
2257 type_poi_hospital,type_poi_hospital,
2258 type_poi_public_utilities,type_poi_public_utilities,
2259 type_poi_police,type_poi_autoservice,
2260 type_poi_information,type_poi_information,
2261 type_poi_pharmacy,type_poi_pharmacy,
2262 type_poi_personal_service,type_poi_repair_service,
2263 type_poi_restroom,type_poi_restroom,
2265 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
2266 {"peak","Land Features",(enum item_type []){
2267 type_poi_land_feature,type_poi_rock,
2268 type_poi_dam,type_poi_dam,
2269 type_poi_peak,type_poi_peak,
2271 {"unknown","Other",(enum item_type []){
2272 type_point_unspecified,type_poi_land_feature-1,
2273 type_poi_rock+1,type_poi_fuel-1,
2274 type_poi_marina+1,type_poi_shopping-1,
2275 type_poi_shopping+1,type_poi_car_parking-1,
2276 type_poi_car_parking+1,type_poi_bar-1,
2277 type_poi_bank+1,type_poi_dam-1,
2278 type_poi_dam+1,type_poi_information-1,
2279 type_poi_information+1,type_poi_mall-1,
2280 type_poi_mall+1,type_poi_personal_service-1,
2281 type_poi_pharmacy+1,type_poi_repair_service-1,
2282 type_poi_repair_service+1,type_poi_restaurant-1,
2283 type_poi_restaurant+1,type_poi_restroom-1,
2284 type_poi_restroom+1,type_poi_shop_grocery-1,
2285 type_poi_shop_grocery+1,type_poi_peak-1,
2286 type_poi_peak+1, type_poi_motel-1,
2287 type_poi_hostel+1,type_poi_shop_butcher-1,
2288 type_poi_shop_baker+1,type_poi_shop_fruit-1,
2289 type_poi_shop_fruit+1,type_poi_shop_beverages-1,
2290 type_poi_shop_beverages+1,type_poi_pub-1,
2291 type_poi_atm+1,type_line-1,
2293 /* {"unknown","Unknown",(enum item_type []){
2294 type_point_unkn,type_point_unkn,
2300 * Get a utf-8 string, return the same prepared for case insensetive search. Result shoud be g_free()d after use.
2307 r=g_utf8_casefold(s,-1);
2312 * POI search/filtering parameters.
2319 * =1 if selnb is defined, 0 otherwize.
2324 * Index to struct selector selectors[], shows what type of POIs is defined.
2326 unsigned char selnb;
2328 * Page number to display.
2330 unsigned char pagenb;
2332 * Radius (number of 10-kilometer intervals) to search for POIs.
2336 * Should filter phrase be compared to postal address of the POI.
2337 * =1 - address filter, =0 - name filter
2339 unsigned char isAddressFilter;
2341 * Filter string, casefold()ed and divided into substrings at the spaces, which are replaced by ASCII 0*.
2345 * list of pointers to individual substrings of filterstr.
2349 * Number of POIs in this list
2356 * @brief Free poi_param structure.
2358 * @param p reference to the object to be freed.
2361 gui_internal_poi_param_free(void *p)
2363 if(((struct poi_param *)p)->filterstr)
2364 g_free(((struct poi_param *)p)->filterstr);
2365 if(((struct poi_param *)p)->filter)
2366 g_list_free(((struct poi_param *)p)->filter);
2371 * @brief Clone poi_param structure.
2373 * @param p reference to the object to be cloned.
2374 * @return Cloned object reference.
2376 static struct poi_param *
2377 gui_internal_poi_param_clone(struct poi_param *p)
2379 struct poi_param *r=g_new(struct poi_param,1);
2381 memcpy(r,p,sizeof(struct poi_param));
2385 char *last=g_list_last(l)->data;
2386 int len=(last - p->filterstr) + strlen(last)+1;
2387 r->filterstr=g_memdup(p->filterstr,len);
2390 r->filter=g_list_append(r->filter, r->filterstr + ((char*)(l->data) - p->filterstr) );
2397 * @brief Set POIs filter data in poi_param structure.
2398 * @param param poi_param structure with unset filter data.
2399 * @param text filter text.
2402 gui_internal_poi_param_set_filter(struct poi_param *param, char *text)
2406 param->filterstr=removecase(text);
2407 s1=param->filterstr;
2409 s2=g_utf8_strchr(s1,-1,' ');
2412 param->filter=g_list_append(param->filter,s1);
2422 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
2423 static void gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data);
2426 static struct widget *
2427 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c, int pagenb)
2429 struct widget *wl,*wb;
2432 //wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2433 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal_vertical|flags_fill);
2434 wl->background=this->background;
2436 wl->cols=this->root.w/this->icon_s;
2437 nitems=sizeof(selectors)/sizeof(struct selector);
2438 nrows=nitems/wl->cols + (nitems%wl->cols>0);
2439 wl->h=this->icon_l*nrows;
2440 for (i = 0 ; i < nitems ; i++) {
2441 struct poi_param *p=g_new0(struct poi_param,1);
2448 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2449 image_new_s(this, selectors[i].icon), gravity_left_center|orientation_vertical,
2450 gui_internal_cmd_pois, p));
2452 wb->data_free=gui_internal_poi_param_free;
2456 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
2457 image_new_s(this, "gui_search"), gravity_left_center|orientation_vertical,
2458 gui_internal_cmd_pois_filter, NULL));
2462 gui_internal_widget_pack(this,wl);
2466 static struct widget *
2467 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist, char* name)
2472 struct widget *wl,*wt;
2475 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2478 sprintf(distbuf,"%d", dist/1000);
2480 sprintf(distbuf,"%d.%d", dist/1000, (dist%1000)/100);
2481 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
2482 type=item_to_name(item->type);
2484 wl->name=g_strdup_printf("%s %s",type,name);
2486 wl->name=g_strdup(type);
2488 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, name);
2489 wt=gui_internal_label_new(this, text);
2491 gui_internal_widget_append(wl, wt);
2498 * @brief Get string representation of item address suitable for doing search and for display in POI list.
2500 * @param item reference to item.
2501 * @return Pointer to string representation of address. To be g_free()d after use.
2504 gui_internal_compose_item_address_string(struct item *item)
2506 char *s=g_strdup("");
2508 if(item_attr_get(item, attr_house_number, &attr))
2509 s=g_strjoin(" ",s,attr.u.str,NULL);
2510 if(item_attr_get(item, attr_street_name, &attr))
2511 s=g_strjoin(" ",s,attr.u.str,NULL);
2512 if(item_attr_get(item, attr_street_name_systematic, &attr))
2513 s=g_strjoin(" ",s,attr.u.str,NULL);
2514 if(item_attr_get(item, attr_district_name, &attr))
2515 s=g_strjoin(" ",s,attr.u.str,NULL);
2516 if(item_attr_get(item, attr_town_name, &attr))
2517 s=g_strjoin(" ",s,attr.u.str,NULL);
2518 if(item_attr_get(item, attr_county_name, &attr))
2519 s=g_strjoin(" ",s,attr.u.str,NULL);
2520 if(item_attr_get(item, attr_country_name, &attr))
2521 s=g_strjoin(" ",s,attr.u.str,NULL);
2523 if(item_attr_get(item, attr_address, &attr))
2524 s=g_strjoin(" ",s,"|",attr.u.str,NULL);
2529 gui_internal_cmd_pois_item_selected(struct poi_param *param, struct item *item)
2531 enum item_type *types;
2532 struct selector *sel = param->sel? &selectors[param->selnb]: NULL;
2533 enum item_type type=item->type;
2536 if (type >= type_line && param->filter==NULL)
2538 if (! sel || !sel->types) {
2542 while (*types != type_none) {
2543 if (item->type >= types[0] && item->type <= types[1]) {
2549 if (param->filter) {
2550 char *long_name, *s;
2552 if (param->isAddressFilter) {
2553 s=gui_internal_compose_item_address_string(item);
2554 } else if (item_attr_get(item, attr_label, &attr)) {
2555 s=g_strdup_printf("%s %s", item_to_name(item->type), attr.u.str);
2557 s=g_strdup(item_to_name(item->type));
2559 long_name=removecase(s);
2561 item_attr_rewind(item);
2563 for(s=long_name,f=param->filter;f && s;f=g_list_next(f)) {
2564 s=strstr(s,f->data);
2567 s=g_utf8_strchr(s,-1,' ');
2584 * @brief Event handler for POIs list "more" element.
2586 * @param this The graphics context.
2587 * @param wm called widget.
2588 * @param data event data.
2591 gui_internal_cmd_pois_more(struct gui_priv *this, struct widget *wm, void *data)
2593 struct widget *w=g_new0(struct widget,1);
2598 gui_internal_back(this, NULL, NULL);
2599 gui_internal_cmd_pois(this, w, w->data);
2605 * @brief Event to apply POIs text filter.
2607 * @param this The graphics context.
2608 * @param wm called widget.
2609 * @param data event data (pointer to editor widget containg filter text).
2612 gui_internal_cmd_pois_filter_do(struct gui_priv *this, struct widget *wm, void *data)
2614 struct widget *w=data;
2615 struct poi_param *param;
2621 param=gui_internal_poi_param_clone(w->data);
2624 param=g_new0(struct poi_param,1);
2626 param->isAddressFilter=strcmp(wm->name,"AddressFilter")==0;
2628 gui_internal_poi_param_set_filter(param, w->text);
2630 gui_internal_cmd_pois(this,w,param);
2631 gui_internal_poi_param_free(param);
2635 * @brief POIs filter dialog.
2636 * Event to handle '\r' '\n' keys pressed.
2641 gui_internal_cmd_pois_filter_changed(struct gui_priv *this, struct widget *wm, void *data)
2645 len=strlen(wm->text);
2646 dbg(1,"len=%d\n", len);
2647 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
2648 wm->text[len-1]='\0';
2649 //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?
2656 * @brief POIs filter dialog.
2658 * @param this The graphics context.
2659 * @param wm called widget.
2660 * @param data event data.
2663 gui_internal_cmd_pois_filter(struct gui_priv *this, struct widget *wm, void *data)
2665 struct widget *wb, *w, *wr, *wk, *we;
2666 int keyboard_mode=2;
2667 wb=gui_internal_menu(this,"Filter");
2668 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2669 gui_internal_widget_append(wb, w);
2670 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2671 gui_internal_widget_append(w, wr);
2672 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2673 gui_internal_widget_append(wr, we);
2675 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2676 wk->state |= STATE_EDIT|STATE_EDITABLE;
2677 wk->func=gui_internal_cmd_pois_filter_changed;
2678 wk->background=this->background;
2679 wk->flags |= flags_expand|flags_fill;
2680 wk->name=g_strdup("POIsFilter");
2682 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
2683 wb->state |= STATE_SENSITIVE;
2684 wb->func = gui_internal_cmd_pois_filter_do;
2685 wb->name=g_strdup("NameFilter");
2687 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "post")));
2688 wb->state |= STATE_SENSITIVE;
2689 wb->name=g_strdup("AddressFilter");
2690 wb->func = gui_internal_cmd_pois_filter_do;
2694 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
2695 gui_internal_menu_render(this);
2701 * @brief Do POI search specified by poi_param and display POIs found
2703 * @param this The graphics context.
2704 * @param wm called widget.
2705 * @param data event data, reference to poi_param or NULL.
2708 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
2710 struct map_selection *sel,*selm;
2711 struct coord c,center;
2712 struct mapset_handle *h;
2714 struct map_rect *mr;
2716 struct widget *wi,*w,*w2,*wb, *wtable, *row;
2717 enum projection pro=wm->c.pro;
2718 struct poi_param *param;
2721 struct selector *isel;
2724 // Starting value and increment of count of items to be extracted
2725 const int pagesize = 50;
2726 int maxitem, it = 0, i;
2727 struct item_data *items;
2728 struct fibheap* fh = fh_makekeyheap();
2730 struct table_data *td;
2737 param = g_new0(struct poi_param,1);
2741 dist=10000*(param->dist+1);
2742 isel = param->sel? &selectors[param->selnb]: NULL;
2743 pagenb = param->pagenb;
2744 prevdist=param->dist*10000;
2745 maxitem = pagesize*(pagenb+1);
2746 items= g_new0( struct item_data, maxitem);
2749 dbg(0, "Params: sel = %i, selnb = %i, pagenb = %i, dist = %i, filterstr = %s, isAddressFilter= %d\n",
2750 param->sel, param->selnb, param->pagenb, param->dist, param->filterstr, param->isAddressFilter);
2752 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
2753 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2754 gui_internal_widget_append(wb, w);
2755 if (!isel && !param->filter)
2756 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c,pagenb));
2757 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2758 gui_internal_widget_append(w, w2);
2760 sel=map_selection_rect_new(&wm->c,dist*transform_scale(abs(wm->c.y)+dist*1.5),18);
2763 h=mapset_open(navit_get_mapset(this->nav));
2764 while ((m=mapset_next(h, 1))) {
2765 selm=map_selection_dup_pro(sel, pro, map_projection(m));
2766 mr=map_rect_new(m, selm);
2767 dbg(2,"mr=%p\n", mr);
2769 while ((item=map_rect_get_item(mr))) {
2770 if (gui_internal_cmd_pois_item_selected(param, item) &&
2771 item_coord_get_pro(item, &c, 1, pro) &&
2772 coord_rect_contains(&sel->u.c_rect, &c) &&
2773 (idist=transform_distance(pro, ¢er, &c)) < dist) {
2774 struct item_data *data;
2778 if (item->type==type_house_number) {
2779 label=gui_internal_compose_item_address_string(item);
2780 } else if (item_attr_get(item, attr_label, &attr)) {
2781 label=g_strdup(attr.u.str);
2782 // Buildings which label is equal to addr:housenumber value
2783 // are duplicated by item_house_number. Don't include such
2784 // buildings into the list. This is true for OSM maps created with
2785 // maptool patched with #859 latest patch.
2786 // FIXME: For non-OSM maps, we probably would better don't skip these items.
2787 if(item->type==type_poly_building && item_attr_get(item, attr_house_number, &attr) ) {
2788 if(strcmp(label,attr.u.str)==0) {
2799 data = fh_extractmin(fh);
2800 g_free(data->label);
2803 data = &items[it++];
2809 // Key expression is a workaround to fight
2810 // probable heap collisions when two objects
2811 // are at the same distance. But it destroys
2812 // right order of POIs 2048 km away from cener
2813 // and if table grows more than 1024 rows.
2814 fh_insertkey(fh, -((idist<<10) + cnt++), data);
2816 dist = (-fh_minkey(fh))>>10;
2819 map_rect_destroy(mr);
2821 map_selection_destroy(selm);
2823 map_selection_destroy(sel);
2826 wtable = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
2829 gui_internal_widget_append(w2,wtable);
2831 // Move items from heap to the table
2834 int key = fh_minkey(fh);
2835 struct item_data *data = fh_extractmin(fh);
2838 dbg(2, "Empty heap: maxitem = %i, it = %i, dist = %i\n", maxitem, it, dist);
2841 dbg(2, "dist1: %i, dist2: %i\n", data->dist, (-key)>>10);
2842 if(i==(it-pagesize*pagenb) && data->dist>prevdist)
2843 prevdist=data->dist;
2844 wi=gui_internal_cmd_pois_item(this, ¢er, &data->item, &data->c, data->dist, data->label);
2845 wi->func=gui_internal_cmd_position;
2847 wi->item=data->item;
2848 wi->state |= STATE_SENSITIVE;
2853 wi->background=this->background;
2854 row = gui_internal_widget_table_row_new(this,
2857 | orientation_horizontal);
2858 gui_internal_widget_append(row,wi);
2859 row->datai=data->dist;
2860 gui_internal_widget_prepend(wtable,row);
2867 // Add an entry for more POI
2868 struct widget *wl,*wt;
2870 struct poi_param *paramnew;
2871 row = gui_internal_widget_table_row_new(this,
2874 | orientation_horizontal);
2875 row->datai=100000000; // Really far away for Earth, but won't work for bigger planets.
2876 gui_internal_widget_append(wtable,row);
2877 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2878 gui_internal_widget_append(row,wl);
2879 if (it == maxitem) {
2880 paramnew=gui_internal_poi_param_clone(param);
2883 snprintf(buffer, sizeof(buffer), "Get more (up to %d items)...", (paramnew->pagenb+1)*pagesize);
2884 wt=gui_internal_label_new(this, buffer);
2885 gui_internal_widget_append(wl, wt);
2886 wt->func=gui_internal_cmd_pois_more;
2888 wt->data_free=gui_internal_poi_param_free;
2889 wt->state |= STATE_SENSITIVE;
2892 static int dist[]={1,5,10,0};
2893 wt=gui_internal_label_new(this, "Set distance to");
2894 gui_internal_widget_append(wl, wt);
2895 for(i=0;dist[i];i++) {
2896 paramnew=gui_internal_poi_param_clone(param);
2897 paramnew->dist+=dist[i];
2899 snprintf(buffer, sizeof(buffer), " %i ", 10*(paramnew->dist+1));
2900 wt=gui_internal_label_new(this, buffer);
2901 gui_internal_widget_append(wl, wt);
2902 wt->func=gui_internal_cmd_pois_more;
2904 wt->data_free=gui_internal_poi_param_free;
2905 wt->state |= STATE_SENSITIVE;
2908 wt=gui_internal_label_new(this, "km.");
2909 gui_internal_widget_append(wl, wt);
2912 // Rendering now is needed to have table_data->bottomrow filled in.
2913 gui_internal_menu_render(this);
2915 if(td->bottom_row!=NULL)
2918 while(((struct widget*)td->bottom_row->data)->datai<=prevdist
2919 && (td->next_button->state & STATE_SENSITIVE))
2921 gui_internal_table_button_next(this, td->next_button, NULL);
2924 int firstrow=g_list_index(wtable->children, td->top_row->data);
2925 while(firstrow>=0) {
2926 int currow=g_list_index(wtable->children, td->bottom_row->data) - firstrow;
2928 dbg(0,"Can't find bottom row in children list. Stop paging.\n");
2931 if(currow>=param->count)
2933 if(!(td->next_button->state & STATE_SENSITIVE)) {
2934 dbg(0,"Reached last page but item %i not found. Stop paging.\n",param->count);
2937 gui_internal_table_button_next(this, td->next_button, NULL);
2941 gui_internal_menu_render(this);
2945 #endif /* _MSC_VER */
2948 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
2950 if (wm->item.type != type_none) {
2951 enum item_type type;
2952 if (wm->item.type < type_line)
2953 type=type_selected_point;
2954 else if (wm->item.type < type_area)
2955 type=type_selected_point;
2957 type=type_selected_area;
2958 graphics_clear_selection(this->gra, NULL);
2959 graphics_add_selection(this->gra, &wm->item, type, NULL);
2961 navit_set_center(this->nav, &wm->c, 1);
2962 gui_internal_prune_menu(this, NULL);
2967 gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
2969 struct widget *w,*wb;
2970 struct map_rect *mr;
2976 text=g_strdup_printf("Attribute %s",wm->name);
2977 wb=gui_internal_menu(this, text);
2979 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2980 gui_internal_widget_append(wb, w);
2981 mr=map_rect_new(wm->item.map, NULL);
2982 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2983 for (i = 0 ; i < wm->datai ; i++) {
2984 item_attr_get(item, attr_any, &attr);
2986 if (item_attr_get(item, attr_any, &attr)) {
2988 switch (attr.type) {
2989 case attr_osm_nodeid:
2990 url=g_strdup_printf("http://www.openstreetmap.org/browse/node/"LONGLONG_FMT"\n",*attr.u.num64);
2992 case attr_osm_wayid:
2993 url=g_strdup_printf("http://www.openstreetmap.org/browse/way/"LONGLONG_FMT"\n",*attr.u.num64);
2995 case attr_osm_relationid:
2996 url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/"LONGLONG_FMT"\n",*attr.u.num64);
3002 gui_internal_widget_append(w,
3003 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3004 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3005 gui_internal_cmd_view_in_browser, NULL));
3009 map_rect_destroy(mr);
3010 gui_internal_menu_render(this);
3014 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
3016 struct widget *w,*wb;
3017 struct map_rect *mr;
3023 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3024 wb=gui_internal_menu(this, "Attributes");
3025 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3026 gui_internal_widget_append(wb, w);
3027 mr=map_rect_new(wm->item.map, NULL);
3028 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3029 dbg(0,"item=%p\n", item);
3031 text=g_strdup_printf("%s:%s", _("Item type"), item_to_name(item->type));
3032 gui_internal_widget_append(w,
3033 wb=gui_internal_button_new(this, text,
3034 NULL, gravity_left_center|orientation_horizontal|flags_fill));
3035 wb->name=g_strdup(text);
3038 while(item_attr_get(item, attr_any, &attr)) {
3039 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
3040 gui_internal_widget_append(w,
3041 wb=gui_internal_button_new_with_callback(this, text,
3042 NULL, gravity_left_center|orientation_horizontal|flags_fill,
3043 gui_internal_cmd_view_attribute_details, NULL));
3044 wb->name=g_strdup(text);
3050 map_rect_destroy(mr);
3051 gui_internal_menu_render(this);
3055 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
3057 struct map_rect *mr;
3063 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
3064 mr=map_rect_new(wm->item.map, NULL);
3065 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3066 dbg(0,"item=%p\n", item);
3068 while(item_attr_get(item, attr_url_local, &attr)) {
3070 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
3073 map_rect_destroy(mr);
3075 cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
3081 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
3087 /* meaning of the bits in "flags":
3089 * 2: "House numbers"
3090 * 4: "View in Browser", "View Attributes"
3093 * 32: "Add as bookm."
3095 * 128: "View on Map"
3096 * 256: POIs around this point
3097 * 512: "Cut/Copy... bookmark"
3098 * 1024: "Jump to attributes of top item within this->radius pixels of this point (implies flags|=256)"
3099 * TODO define constants for these values
3102 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)
3104 struct widget *wb,*w,*wc,*wbc,*wclosest=NULL;
3114 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3115 transform_to_geo(pc.pro, &c, &g);
3118 if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
3121 pc.pro=attr.u.projection;
3122 transform_from_geo(pc.pro, &g, &c);
3128 wb=gui_internal_menu(this, name);
3129 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3130 gui_internal_widget_append(wb, w);
3131 coord=coordinates(&pc, ' ');
3132 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
3134 if ((flags & 1) && wm) {
3135 gui_internal_widget_append(w,
3136 wc=gui_internal_button_new_with_callback(this, _("Streets"),
3137 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3138 gui_internal_search_street_in_town, wm));
3140 wc->selection_id=wm->selection_id;
3142 if ((flags & 2) && wm) {
3143 gui_internal_widget_append(w,
3144 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
3145 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3146 gui_internal_search_house_number_in_street, wm));
3148 wc->selection_id=wm->selection_id;
3150 if ((flags & 4) && wm) {
3151 struct map_rect *mr;
3154 mr=map_rect_new(wm->item.map, NULL);
3155 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
3157 if (item_attr_get(item, attr_description, &attr))
3158 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
3159 if (item_attr_get(item, attr_url_local, &attr)) {
3160 gui_internal_widget_append(w,
3161 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
3162 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3163 gui_internal_cmd_view_in_browser, NULL));
3166 gui_internal_widget_append(w,
3167 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
3168 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3169 gui_internal_cmd_view_attributes, NULL));
3172 map_rect_destroy(mr);
3175 gui_internal_widget_append(w,
3176 wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
3177 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3178 gui_internal_cmd_set_destination, g_strdup(name)));
3179 wbc->data_free=g_free_func;
3183 gui_internal_widget_append(w,
3184 wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
3185 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3186 gui_internal_cmd_set_position, wm));
3190 gui_internal_widget_append(w,
3191 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
3192 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3193 gui_internal_cmd_add_bookmark2, g_strdup(name)));
3194 wbc->data_free=g_free_func;
3198 //POIs are not operational under MSVC yet
3200 gui_internal_widget_append(w,
3201 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
3202 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3203 gui_internal_cmd_pois, NULL));
3206 #endif /* _MSC_VER */
3208 gui_internal_widget_append(w,
3209 gui_internal_button_new(this, "Add to tour",
3210 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
3213 gui_internal_widget_append(w,
3214 wbc=gui_internal_button_new_with_callback(this, _("View on map"),
3215 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3216 gui_internal_cmd_view_on_map, NULL));
3218 if ((flags & 4) && wm)
3221 wbc->item.type=type_none;
3223 if ((flags & 256) || (flags & 1024)) {
3224 struct displaylist_handle *dlh;
3225 struct displaylist *display;
3228 struct transformation *trans;
3231 struct map_selection *sel;
3237 trans=navit_get_trans(this->nav);
3238 transform(trans,pc.pro,&c,&p,1,0,0,0);
3239 display=navit_get_displaylist(this->nav);
3240 dlh=graphics_displaylist_open(display);
3241 sel=displaylist_get_selection(display);
3242 l=displaylist_get_clicked_list(display, &p, this->radius);
3243 for(ll=l;ll;ll=g_list_next(ll)) {
3244 struct displayitem *di;
3246 struct map_rect *mr;
3249 di=(struct displayitem*)ll->data;
3250 item=graphics_displayitem_get_item(di);
3252 mr=map_rect_new(item->map, sel);
3253 itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
3255 if (item_attr_get(itemo, attr_label, &attr)) {
3256 label=map_convert_string(itemo->map, attr.u.str);
3257 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
3258 map_convert_free(label);
3260 text=g_strdup_printf("%s", item_to_name(item->type));
3261 gui_internal_widget_append(w,
3262 wc=gui_internal_button_new_with_callback(this, text,
3263 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3264 gui_internal_cmd_position, (void *)2));
3266 wc->name=g_strdup(text);
3269 map_rect_destroy(mr);
3275 map_selection_destroy(sel);
3276 graphics_displaylist_close(dlh);
3279 gui_internal_widget_append(w,
3280 wbc=gui_internal_button_new_with_callback(this, _("Cut Bookmark"),
3281 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3282 gui_internal_cmd_cut_bookmark, NULL));
3283 wbc->text=g_strdup(wm->text);
3284 gui_internal_widget_append(w,
3285 wbc=gui_internal_button_new_with_callback(this, _("Copy Bookmark"),
3286 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3287 gui_internal_cmd_copy_bookmark, NULL));
3288 wbc->text=g_strdup(wm->text);
3289 gui_internal_widget_append(w,
3290 wbc=gui_internal_button_new_with_callback(this, _("Rename Bookmark"),
3291 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3292 gui_internal_cmd_rename_bookmark, NULL));
3293 wbc->text=g_strdup(wm->text);
3294 gui_internal_widget_append(w,
3295 wbc=gui_internal_button_new_with_callback(this, _("Paste Bookmark"),
3296 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3297 gui_internal_cmd_paste_bookmark, NULL));
3298 gui_internal_widget_append(w,
3299 wbc=gui_internal_button_new_with_callback(this, _("Delete Bookmark"),
3300 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3301 gui_internal_cmd_delete_bookmark, NULL));
3302 wbc->text=g_strdup(wm->text);
3304 gui_internal_menu_render(this);
3306 if((flags & 1024) && wclosest)
3307 gui_internal_cmd_view_attributes(this,wclosest,wclosest->data);
3311 /* wm->data: 0 Nothing special
3319 8 Former destination
3323 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
3326 switch ((long) wm->data) {
3328 flags=8|16|32|64|128|256;
3331 flags=8|16|32|64|256;
3334 flags=4|8|16|32|64|128;
3337 flags=1|8|16|32|64|128;
3338 flags &= this->flags_town;
3341 gui_internal_search_town_in_country(this, wm);
3344 flags=2|8|16|32|64|128;
3345 flags &= this->flags_street;
3348 flags=8|16|32|64|128;
3349 flags &= this->flags_house_number;
3352 flags=8|16|64|128|512;
3355 flags=8|16|32|64|128;
3362 gui_internal_search_house_number_in_street(this, wm, NULL);
3365 gui_internal_cmd_set_destination(this, wm, NULL);
3368 gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
3372 gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3374 char *name=_("Position");
3380 if (!ATTR_IS_COORD_GEO(in[0]->type))
3382 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3384 if (in[2] && ATTR_IS_INT(in[2]->type))
3387 dbg(1,"flags=0x%x\n",flags);
3388 gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
3392 gui_internal_cmd2_pois(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3395 struct poi_param *param;
3402 if (!ATTR_IS_COORD_GEO(in[0]->type))
3404 if (!navit_get_attr(this->nav, attr_projection, &pro, NULL))
3406 w=g_new0(struct widget,1);
3407 param=g_new0(struct poi_param,1);
3408 if (in[1] && ATTR_IS_STRING(in[1]->type)) {
3409 gui_internal_poi_param_set_filter(param, in[1]->u.str);
3410 if (in[2] && ATTR_IS_INT(in[2]->type))
3411 param->isAddressFilter=in[2]->u.num;
3414 transform_from_geo(pro.u.projection,in[0]->u.coord_geo,&c);
3417 w->c.pro=pro.u.projection;
3418 gui_internal_cmd_pois(this, w, param);
3420 gui_internal_poi_param_free(param);
3425 * The "Bookmarks" section of the OSD
3430 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
3432 struct attr attr,mattr;
3434 char *label_full,*prefix=0;
3435 int plen=0,hassub,found=0;
3436 struct widget *wb,*w,*wbm;
3438 struct widget *tbl, *row;
3441 prefix=g_strdup(data);
3443 if (wm && wm->prefix)
3444 prefix=g_strdup(wm->prefix);
3447 plen=strlen(prefix);
3449 gui_internal_prune_menu_count(this, 1, 0);
3450 wb=gui_internal_menu(this, _("Bookmarks"));
3451 wb->background=this->background;
3452 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3453 w->spy=this->spacing*3;
3454 gui_internal_widget_append(wb, w);
3456 if(navit_get_attr(this->nav, attr_bookmarks, &mattr, NULL) ) {
3458 bookmarks_move_root(mattr.u.bookmarks);
3460 if (!strcmp(prefix,"..")) {
3461 bookmarks_move_up(mattr.u.bookmarks);
3463 prefix=g_strdup(bookmarks_item_cwd(mattr.u.bookmarks));
3465 plen=strlen(prefix);
3470 bookmarks_move_down(mattr.u.bookmarks,prefix);
3473 // "Back" button, when inside a bookmark folder
3476 wbm=gui_internal_button_new_with_callback(this, "..",
3477 image_new_xs(this, "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3478 gui_internal_cmd_bookmarks, NULL);
3479 wbm->prefix=g_strdup("..");
3480 gui_internal_widget_append(w, wbm);
3484 // Adds the Bookmark folders
3485 wbm=gui_internal_button_new_with_callback(this, _("Add Bookmark folder"),
3486 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3487 gui_internal_cmd_add_bookmark_folder2, NULL);
3488 gui_internal_widget_append(w, wbm);
3490 // Pastes the Bookmark
3491 wbm=gui_internal_button_new_with_callback(this, _("Paste bookmark"),
3492 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3493 gui_internal_cmd_paste_bookmark, NULL);
3494 gui_internal_widget_append(w, wbm);
3496 bookmarks_item_rewind(mattr.u.bookmarks);
3498 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
3499 gui_internal_widget_append(w,tbl);
3501 while ((item=bookmarks_get_item(mattr.u.bookmarks))) {
3502 if (!item_attr_get(item, attr_label, &attr)) continue;
3503 label_full=attr.u.str;
3504 dbg(0,"full_labled: %s\n",label_full);
3506 // hassub == 1 if the item type is a sub-folder
3507 if (item->type == type_bookmark_folder) {
3513 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_horizontal);
3514 gui_internal_widget_append(tbl, row);
3515 wbm=gui_internal_button_new_with_callback(this, label_full,
3516 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
3517 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
3519 gui_internal_widget_append(row,wbm);
3520 if (item_coord_get(item, &c, 1)) {
3523 wbm->c.pro=bookmarks_get_projection(mattr.u.bookmarks);
3524 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
3525 wbm->text=g_strdup(label_full);
3527 wbm->data=(void*)7;//Mark us as a bookmark
3529 wbm->prefix=g_strdup(label_full);
3531 gui_internal_widget_destroy(this, row);
3539 gui_internal_check_exit(this);
3541 gui_internal_menu_render(this);
3545 gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3548 if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
3551 gui_internal_cmd_bookmarks(this, NULL, str);
3556 gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
3558 struct widget *wb,*w,*wbm,*tbl=NULL;
3559 struct map *formerdests;
3560 struct map_rect *mr_formerdests;
3564 enum projection projection;
3566 gui_internal_prune_menu_count(this, 1, 0);
3567 wb=gui_internal_menu(this, _("Former Destinations"));
3568 wb->background=this->background;
3570 w=gui_internal_box_new(this,
3571 gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3572 w->spy=this->spacing*2;
3573 gui_internal_widget_append(wb, w);
3575 formerdests=read_former_destinations_from_file();
3576 mr_formerdests=map_rect_new(formerdests, NULL);
3577 projection = map_projection(formerdests);
3578 while ((item=map_rect_get_item(mr_formerdests))) {
3581 if (!item_attr_get(item, attr_label, &attr)) continue;
3583 tbl=gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand | orientation_vertical,1);
3584 gui_internal_widget_append(w,tbl);
3586 row=gui_internal_widget_table_row_new(this,gravity_left| flags_fill| orientation_vertical);
3587 gui_internal_widget_prepend(tbl, row);
3588 label_full=attr.u.str;
3589 wbm=gui_internal_button_new_with_callback(this, label_full,
3590 image_new_xs(this, "gui_active"),
3591 gravity_left_center|orientation_horizontal|flags_fill,
3592 gui_internal_cmd_position, NULL);
3593 gui_internal_widget_append(row,wbm);
3594 if (item_coord_get(item, &c, 1)) {
3597 wbm->c.pro=projection;
3598 wbm->name=g_strdup(label_full);
3599 wbm->text=g_strdup(label_full);
3600 wbm->data=(void*)8; //Mark us as a former destination
3601 wbm->prefix=g_strdup(label_full);
3605 wbm=gui_internal_text_new(this, _("- No former destinations available -"),
3606 gravity_left_center|orientation_horizontal|flags_fill);
3607 gui_internal_widget_append(w, wbm);
3609 gui_internal_menu_render(this);
3610 map_rect_destroy(mr_formerdests);
3614 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy);
3616 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
3618 struct widget *wi,*menu,*search_list;
3622 menu=g_list_last(this->root.children)->data;
3623 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
3625 /* select first item of the searchlist */
3626 if (*key == NAVIT_KEY_RETURN && (search_list=gui_internal_menu_data(this)->search_list)) {
3627 GList *l=search_list->children;
3629 gui_internal_highlight_do(this, l->data);
3631 } else if (*key == NAVIT_KEY_BACKSPACE) {
3632 dbg(0,"backspace\n");
3633 if (wi->text && wi->text[0]) {
3634 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
3636 text=g_strdup_printf("%s ", wi->text);
3639 if (wi->state & STATE_CLEAR) {
3640 dbg(0,"wi->state=0x%x\n", wi->state);
3643 wi->state &= ~STATE_CLEAR;
3644 dbg(0,"wi->state=0x%x\n", wi->state);
3646 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
3650 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
3651 gui_internal_widget_render(this, wi);
3656 wi->func(this, wi, wi->data);
3658 gui_internal_widget_render(this, wi);
3664 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
3666 struct menu_data *md=gui_internal_menu_data(this);
3667 gui_internal_keypress_do(this, (char *) wm->data);
3668 // Switch to lowercase after the first key is pressed
3669 if (md->keyboard_mode == 2) // Latin
3670 gui_internal_keyboard_do(this, md->keyboard, 10);
3671 if (md->keyboard_mode == 26) // Umlaut
3672 gui_internal_keyboard_do(this, md->keyboard, 34);
3673 if ((md->keyboard_mode & ~7) == 40) // Russian/Ukrainian/Belorussian
3674 gui_internal_keyboard_do(this, md->keyboard, 48);
3678 gui_internal_search_idle_end(struct gui_priv *this)
3681 event_remove_idle(this->idle);
3684 if (this->idle_cb) {
3685 callback_destroy(this->idle_cb);
3691 postal_str(struct search_list_result *res, int level)
3694 if (res->town->common.postal)
3695 ret=res->town->common.postal;
3696 if (res->town->common.postal_mask)
3697 ret=res->town->common.postal_mask;
3700 if (res->street->common.postal)
3701 ret=res->street->common.postal;
3702 if (res->street->common.postal_mask)
3703 ret=res->street->common.postal_mask;
3706 if (res->house_number->common.postal)
3707 ret=res->house_number->common.postal;
3708 if (res->house_number->common.postal_mask)
3709 ret=res->house_number->common.postal_mask;
3714 district_str(struct search_list_result *res, int level)
3717 if (res->town->common.district_name)
3718 ret=res->town->common.district_name;
3721 if (res->street->common.district_name)
3722 ret=res->street->common.district_name;
3725 if (res->house_number->common.district_name)
3726 ret=res->house_number->common.district_name;
3731 town_str(struct search_list_result *res, int level, int flags)
3733 char *town=res->town->common.town_name;
3734 char *district=district_str(res, level);
3735 char *postal=postal_str(res, level);
3736 char *postal_sep=" ";
3737 char *district_begin=" (";
3738 char *district_end=")";
3739 char *county_sep = ", Co. ";
3740 char *county = res->town->common.county_name;
3742 postal_sep=postal="";
3743 if (!district || (flags & 1))
3744 district_begin=district_end=district="";
3746 county_sep=county="";
3748 return g_strdup_printf("%s%s%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end, county_sep, county);
3751 static int gui_internal_search_cmp(gconstpointer _a, gconstpointer _b)
3753 struct widget *a=(struct widget *)_a, *b=(struct widget *)_b;
3757 if((!a || a->type!=widget_table_row || !a->text) && (!b || b->type!=widget_table_row || !b->text))
3759 if(!a || a->type!=widget_table_row || !a->text)
3761 if(!b || b->type!=widget_table_row || !b->text)
3763 r=a->datai-b->datai;
3768 sa=removecase(a->text);
3769 sb=removecase(b->text);
3777 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3779 char *text=NULL,*text2=NULL,*name=NULL;
3780 struct search_list_result *res;
3782 struct item *item=NULL;
3784 static char possible_keys[256]="";
3785 struct widget *wi=NULL;
3787 res=search_list_get_result(this->sl);
3789 gchar* trunk_name = NULL;
3791 struct widget *menu=g_list_last(this->root.children)->data;
3792 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
3795 if (! strcmp(wm_name,"Town"))
3796 trunk_name = g_strrstr(res->town->common.town_name, wi->text);
3797 if (! strcmp(wm_name,"Street"))
3799 name=res->street->name;
3801 trunk_name = g_strrstr(name, wi->text);
3807 char next_char = trunk_name[strlen(wi->text)];
3809 int len = strlen(possible_keys);
3810 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
3811 if (i==len || !len) {
3812 possible_keys[len]=trunk_name[strlen(wi->text)];
3813 possible_keys[len+1]='\0';
3815 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
3818 dbg(0, "Unable to find widget");
3823 struct menu_data *md;
3824 gui_internal_search_idle_end(this);
3826 md=gui_internal_menu_data(this);
3827 if (md && md->keyboard && !(this->flags & 2048)) {
3828 GList *lk=md->keyboard->children;
3829 graphics_draw_mode(this->gra, draw_mode_begin);
3831 struct widget *child=lk->data;
3832 GList *lk2=child->children;
3834 struct widget *child_=lk2->data;
3835 lk2=g_list_next(lk2);
3836 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
3837 if (strlen(possible_keys) == 0)
3838 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3839 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
3840 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
3842 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
3844 gui_internal_widget_render(this,child_);
3849 gui_internal_widget_render(this,md->keyboard);
3850 graphics_draw_mode(this->gra, draw_mode_end);
3853 possible_keys[0]='\0';
3857 if (! strcmp(wm_name,"Country")) {
3858 name=res->country->name;
3859 item=&res->country->common.item;
3860 text=g_strdup_printf("%s", res->country->name);
3862 if (! strcmp(wm_name,"Town")) {
3863 item=&res->town->common.item;
3864 name=res->town->common.town_name;
3865 text=town_str(res, 1, 0);
3867 if (! strcmp(wm_name,"Street")) {
3868 name=res->street->name;
3869 item=&res->street->common.item;
3870 text=g_strdup(res->street->name);
3871 text2=town_str(res, 2, 1);
3873 if (! strcmp(wm_name,"House number")) {
3874 name=res->house_number->house_number;
3875 text=g_strdup_printf("%s %s", res->street->name, name);
3876 text2=town_str(res, 3, 0);
3878 dbg(1,"res->country->flag=%s\n", res->country->flag);
3880 wr=gui_internal_widget_table_row_new(this, gravity_left|orientation_horizontal|flags_fill);
3883 wr->text=g_strdup(text);
3884 gui_internal_widget_insert_sorted(search_list, wr, gui_internal_search_cmp);
3885 gui_internal_widget_append(wr,
3886 wc=gui_internal_button_new_with_callback(this, text,
3887 image_new_xs(this, res->country->flag),
3888 gravity_left_center|orientation_horizontal|flags_fill,
3889 gui_internal_cmd_position, param));
3892 wr->text=g_strdup_printf("%s %s",text,text2);
3894 if (! strcmp(wm_name,"House number") && !res->street->name) {
3898 dbg(0,"search text widget is NULL\n");
3899 if(wi && strlen(name)==strlen(wi->text)) {
3900 dbg(1,"xact %s %s\n",name, wi->text);
3903 dbg(1,"not xact %s %s\n",name, wi->text);
3907 gui_internal_widget_insert_sorted(search_list, wr, gui_internal_search_cmp);
3909 wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3910 gui_internal_widget_append(wr, wc);
3911 gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
3912 wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
3913 gui_internal_widget_append(wc, wb);
3914 gui_internal_widget_append(wb, gui_internal_label_new(this, text));
3915 gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
3916 wc->func=gui_internal_cmd_position;
3918 wc->state |= STATE_SENSITIVE;
3919 wc->speech=g_strdup(text);
3921 wc->name=g_strdup(name);
3924 wc->selection_id=res->id;
3927 gui_internal_widget_pack(this, search_list);
3928 l=g_list_last(this->root.children);
3929 graphics_draw_mode(this->gra, draw_mode_begin);
3930 gui_internal_widget_render(this, l->data);
3931 graphics_draw_mode(this->gra, draw_mode_end);
3937 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
3939 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
3940 this->idle=event_add_idle(50,this->idle_cb);
3941 callback_call_0(this->idle_cb);
3947 * @param wm The widget that generated the event for the search changed,
3948 * if this was generated by a key on the virtual keyboard then
3949 * wm is the key button widget.
3952 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
3955 struct widget *search_list=gui_internal_menu_data(this)->search_list;
3956 void *param=(void *)3;
3959 gui_internal_widget_table_clear(this, search_list);
3961 if (! strcmp(wm->name,"Country"))
3963 if (! strcmp(wm->name,"Street"))
3965 if (! strcmp(wm->name,"House number"))
3967 dbg(0,"%s now '%s'\n", wm->name, wm->text);
3969 gui_internal_search_idle_end(this);
3970 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
3971 struct attr search_attr;
3974 if (! strcmp(wm->name,"Country"))
3975 search_attr.type=attr_country_all;
3976 if (! strcmp(wm->name,"Town"))
3977 search_attr.type=attr_town_or_district_name;
3978 if (! strcmp(wm->name,"Street"))
3979 search_attr.type=attr_street_name;
3980 if (! strcmp(wm->name,"House number"))
3981 search_attr.type=attr_house_number;
3982 search_attr.u.str=wm->text;
3983 search_list_search(this->sl, &search_attr, 1);
3984 gui_internal_search_idle_start(this, wm->name, search_list, param);
3986 l=g_list_last(this->root.children);
3987 gui_internal_widget_render(this, l->data);
3990 static struct widget *
3991 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)
3994 gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
3995 NULL, gravity_center|orientation_vertical, func, data));
3996 wk->data_free=data_free;
3997 wk->background=this->background;
4007 static struct widget *
4008 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
4010 return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free_func,w,h);
4013 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
4016 // A list of availiable keyboard modes.
4017 struct gui_internal_keyb_mode {
4018 char title[16]; // Label to be displayed on keys that switch to it
4019 int font; // Font size of label
4020 int case_mode; // Mode to switch to when case CHANGE() key is pressed.
4021 int umlaut_mode; // Mode to switch to when UMLAUT() key is pressed.
4022 } gui_internal_keyb_modes[]= {
4023 /* 0*/ {"ABC", 2, 8, 24},
4024 /* 8*/ {"abc", 2, 0, 32},
4025 /*16*/ {"123", 2, 0, 24},
4026 /*24*/ {"ÄÖÜ", 2, 40, 0},
4027 /*32*/ {"äöü", 2, 32, 8},
4028 /*40*/ {"АБВ", 2, 48, 0},
4029 /*48*/ {"абв", 2, 40, 8}
4033 // Some macros that make the keyboard layout easier to visualise in
4034 // the source code. The macros are #undef'd after this function.
4035 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
4036 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
4037 #define MODE(x) gui_internal_keyboard_key_data(this, wkbd, \
4038 gui_internal_keyb_modes[(x)/8].title, \
4039 gui_internal_keyb_modes[(x)/8].font, \
4040 gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h) \
4041 -> datai=(mode&7)+((x)&~7)
4042 #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode)
4043 #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode)
4044 static struct widget *
4045 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
4047 struct widget *wkbd,*wk;
4048 struct menu_data *md=gui_internal_menu_data(this);
4049 int i, max_w=this->root.w, max_h=this->root.h;
4052 char *backspace="←";
4059 gui_internal_highlight(this);
4060 if (md->keyboard_mode >= 1024)
4064 gui_internal_widget_children_destroy(this, wkbdb);
4066 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
4068 md->keyboard_mode=mode;
4069 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
4070 wkbd->background=this->background;
4075 max_h=max_h/8; // Allows 3 results in the list when searching for Towns
4077 if(mode>=40&&mode<56) { // Russian/Ukrainian/Belarussian layout needs more space...
4083 if (mode >= 0 && mode < 8) {
4084 for (i = 0 ; i < 26 ; i++) {
4085 char text[]={'A'+i,'\0'};
4088 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4092 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4093 wk->datai=mode+1024;
4095 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4096 wk->datai=mode+1024;
4102 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4104 if (mode >= 8 && mode < 16) {
4105 for (i = 0 ; i < 26 ; i++) {
4106 char text[]={'a'+i,'\0'};
4109 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4113 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4114 wk->datai=mode+1024;
4116 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4117 wk->datai=mode+1024;
4123 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4125 if (mode >= 16 && mode < 24) {
4126 for (i = 0 ; i < 10 ; i++) {
4127 char text[]={'0'+i,'\0'};
4130 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
4131 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
4136 for (i = 0 ; i < 5 ; i++) SPACER();
4139 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4140 wk->datai=mode+1024;
4142 for (i = 0 ; i < 3 ; i++) SPACER();
4145 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4146 wk->datai=mode+1024;
4151 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4153 if (mode >= 24 && mode < 32) {
4154 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
4155 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
4156 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
4157 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
4161 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4163 if (mode >= 32 && mode < 40) {
4164 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
4165 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
4166 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
4167 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
4171 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4173 if (mode >= 40 && mode < 48) {
4174 KEY("А"); KEY("Б"); KEY("В"); KEY("Г"); KEY("Д"); KEY("Е"); KEY("Ж"); KEY("З"); KEY("И");
4175 KEY("Й"); KEY("К"); KEY("Л"); KEY("М"); KEY("Н"); KEY("О"); KEY("П"); KEY("Р"); KEY("С");
4176 KEY("Т"); KEY("У"); KEY("Ф"); KEY("Х"); KEY("Ц"); KEY("Ч"); KEY("Ш"); KEY("Щ"); KEY("Ъ");
4177 KEY("Ы"); KEY("Ь"); KEY("Э"); KEY("Ю"); KEY("Я"); KEY("Ё"); KEY("І"); KEY("Ї"); KEY("Ў");
4178 SPACER(); SPACER(); SPACER();
4179 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4181 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4182 wk->datai=mode+1024;
4190 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4192 if (mode >= 48 && mode < 56) {
4193 KEY("а"); KEY("б"); KEY("в"); KEY("г"); KEY("д"); KEY("е"); KEY("ж"); KEY("з"); KEY("и");
4194 KEY("й"); KEY("к"); KEY("л"); KEY("м"); KEY("н"); KEY("о"); KEY("п"); KEY("р"); KEY("с");
4195 KEY("т"); KEY("у"); KEY("ф"); KEY("х"); KEY("ц"); KEY("ч"); KEY("ш"); KEY("щ"); KEY("ъ");
4196 KEY("ы"); KEY("ь"); KEY("э"); KEY("ю"); KEY("я"); KEY("ё"); KEY("і"); KEY("ї"); KEY("ў");
4197 SPACER(); SPACER(); SPACER();
4198 gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
4200 wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
4201 wk->datai=mode+1024;
4209 gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
4213 if(md->search_list && md->search_list->type==widget_table) {
4214 struct table_data *td=(struct table_data*)(md->search_list->data);
4215 td->button_box_hide=mode<1024;
4223 text=gui_internal_keyb_modes[mode/8].title;
4224 font=gui_internal_keyb_modes[mode/8].font;
4225 wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
4226 wk->func=gui_internal_keyboard_change;
4228 wk->background=this->background;
4236 wk->state |= STATE_SENSITIVE;
4237 gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
4238 wkl->background=NULL;
4239 gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text, font));
4240 wkl->background=NULL;
4241 gui_internal_widget_append(wkbd, wk);
4245 gui_internal_widget_append(wkbdb, wkbd);
4247 gui_internal_widget_pack(this, wkbdb);
4248 gui_internal_widget_render(this, wkbdb);
4249 } else if (render == 2) {
4250 gui_internal_menu_reset_pack(this);
4251 gui_internal_menu_render(this);
4261 static struct widget *
4262 gui_internal_keyboard(struct gui_priv *this, int mode)
4264 if (! this->keyboard)
4266 return gui_internal_keyboard_do(this, NULL, mode);
4270 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
4272 gui_internal_keyboard_do(this, key->data, key->datai);
4276 gui_internal_search_list_set_default_country(struct gui_priv *this)
4278 struct attr search_attr, country_name, country_iso2, *country_attr;
4280 struct country_search *cs;
4281 struct tracking *tracking;
4282 struct search_list_result *res;
4284 country_attr=country_default();
4285 tracking=navit_get_tracking(this->nav);
4286 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
4287 country_attr=&search_attr;
4289 cs=country_search_new(country_attr, 0);
4290 item=country_search_get_item(cs);
4291 if (item && item_attr_get(item, attr_country_name, &country_name)) {
4292 search_attr.type=attr_country_all;
4293 dbg(0,"country %s\n", country_name.u.str);
4294 search_attr.u.str=country_name.u.str;
4295 search_list_search(this->sl, &search_attr, 0);
4296 while((res=search_list_get_result(this->sl)));
4297 if(this->country_iso2) {
4298 g_free(this->country_iso2);
4299 this->country_iso2=NULL;
4301 if (item_attr_get(item, attr_country_iso2, &country_iso2))
4302 this->country_iso2=g_strdup(country_iso2.u.str);
4304 country_search_destroy(cs);
4306 dbg(0,"warning: no default country found\n");
4307 if (this->country_iso2) {
4308 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
4309 search_attr.type=attr_country_iso2;
4310 search_attr.u.str=this->country_iso2;
4311 search_list_search(this->sl, &search_attr, 0);
4312 while((res=search_list_get_result(this->sl)));
4318 gui_internal_search_list_new(struct gui_priv *this)
4320 struct mapset *ms=navit_get_mapset(this->nav);
4322 this->sl=search_list_new(ms);
4323 gui_internal_search_list_set_default_country(this);
4328 gui_internal_search_list_destroy(struct gui_priv *this)
4331 search_list_destroy(this->sl);
4338 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
4340 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
4342 int keyboard_mode=2;
4343 gui_internal_search_list_new(this);
4344 wb=gui_internal_menu(this, what);
4345 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
4346 gui_internal_widget_append(wb, w);
4347 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4348 gui_internal_widget_append(w, wr);
4349 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
4350 gui_internal_widget_append(wr, we);
4351 if (!strcmp(type,"Country")) {
4352 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
4353 wnext->func=gui_internal_search_town;
4354 } else if (!strcmp(type,"Town")) {
4355 if (this->country_iso2) {
4356 #if HAVE_API_ANDROID
4357 char country_iso2[strlen(this->country_iso2)+1];
4358 strtolower(country_iso2, this->country_iso2);
4359 country=g_strdup_printf("country_%s", country_iso2);
4361 country=g_strdup_printf("country_%s", this->country_iso2);
4364 country=g_strdup("gui_select_country");
4365 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
4366 wb->state |= STATE_SENSITIVE;
4368 wb->func = gui_internal_search_country;
4370 wb->func = gui_internal_back;
4371 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
4372 wnext->func=gui_internal_search_street;
4374 } else if (!strcmp(type,"Street")) {
4375 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
4376 wb->state |= STATE_SENSITIVE;
4377 wb->func = gui_internal_back;
4378 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
4379 wnext->func=gui_internal_search_house_number;
4380 } else if (!strcmp(type,"House number")) {
4381 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
4382 wb->state |= STATE_SENSITIVE;
4383 wb->func = gui_internal_back;
4386 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
4388 gui_internal_widget_append(we, wnext);
4389 wnext->state |= STATE_SENSITIVE;
4391 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);
4392 gui_internal_widget_append(wr, wl);
4393 gui_internal_menu_data(this)->search_list=wl;
4394 wk->state |= STATE_EDIT|STATE_EDITABLE;
4395 wk->background=this->background;
4396 wk->flags |= flags_expand|flags_fill;
4397 wk->func = gui_internal_search_changed;
4398 wk->name=g_strdup(type);
4400 gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
4401 gui_internal_menu_render(this);
4405 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
4407 search_list_select(this->sl, attr_street_name, 0, 0);
4408 gui_internal_search(this,_("House number"),"House number",0);
4412 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
4414 dbg(0,"id %d\n", widget->selection_id);
4415 search_list_select(this->sl, attr_street_name, 0, 0);
4416 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
4417 gui_internal_search(this,_("House number"),"House number",0);
4421 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
4423 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
4424 gui_internal_search(this,_("Street"),"Street",0);
4428 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
4430 dbg(0,"id %d\n", widget->selection_id);
4431 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
4432 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
4433 gui_internal_search(this,_("Street"),"Street",0);
4437 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
4440 search_list_select(this->sl, attr_country_all, 0, 0);
4441 g_free(this->country_iso2);
4442 this->country_iso2=NULL;
4443 gui_internal_search(this,_("Town"),"Town",0);
4447 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
4449 struct search_list_common *slc;
4450 dbg(0,"id %d\n", widget->selection_id);
4451 search_list_select(this->sl, attr_country_all, 0, 0);
4452 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
4454 g_free(this->country_iso2);
4455 this->country_iso2=g_strdup(((struct search_list_country *)slc)->iso2);
4457 gui_internal_search(this,widget->name,"Town",0);
4461 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
4463 gui_internal_prune_menu_count(this, 1, 0);
4464 gui_internal_search(this,_("Country"),"Country",0);
4468 gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4471 search_list_select(this->sl, attr_country_all, 0, 0);
4472 gui_internal_search(this,_("Town"),"Town",1);
4476 gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4479 struct widget *w,*wb,*wl;
4480 struct attr_iter *iter;
4483 wb=gui_internal_menu(this, _("Layout"));
4484 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4485 w->spy=this->spacing*3;
4486 gui_internal_widget_append(wb, w);
4487 iter=navit_attr_iter_new();
4488 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
4489 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
4491 gui_internal_widget_append(w, wl);
4493 navit_attr_iter_destroy(iter);
4494 gui_internal_menu_render(this);
4498 gui_internal_cmd_match_expand(char *pattern, struct attr **in)
4500 char p,*ret=g_strdup(pattern),*r=ret,*a;
4502 while ((p=*pattern++)) {
4506 a=attr_to_text(*in++,NULL,0);
4507 len=strlen(ret)+strlen(a)+strlen(pattern)+1;
4527 gui_internal_match(const char *pattern, const char *string)
4530 while ((p=*pattern++)) {
4533 while ((s=*string)) {
4534 if (gui_internal_match(pattern,string))
4550 gui_internal_set(char *remove, char *add)
4552 char *gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
4553 char *gui_file_new=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal_new.txt", NULL);
4554 FILE *fo=fopen(gui_file_new,"w");
4555 FILE *fi=fopen(gui_file,"r");
4560 while (getline(&line,&size,fi) > 0) {
4561 int len=strlen(line);
4562 if (len > 0 && line[len-1] == '\n')
4564 dbg(1,"line=%s\n",line);
4565 if (!gui_internal_match(remove, line))
4566 fprintf(fo,"%s\n",line);
4572 fprintf(fo,"%s;\n",add);
4574 ret=(rename(gui_file_new, gui_file)==0);
4575 g_free(gui_file_new);
4582 gui_internal_cmd2_set(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4584 char *pattern,*command=NULL;
4585 if (!in || !in[0] || !ATTR_IS_STRING(in[0]->type)) {
4586 dbg(0,"first parameter missing or wrong type\n");
4589 pattern=in[0]->u.str;
4590 dbg(0,"pattern %s\n",pattern);
4592 command=gui_internal_cmd_match_expand(pattern, in+1);
4593 dbg(0,"expand %s\n",command);
4594 gui_internal_set(pattern, command);
4595 command_evaluate(&this->self, command);
4602 gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4605 gui_internal_prune_menu(this, NULL);
4606 navit.type=attr_navit;
4607 navit.u.navit=this->nav;
4608 config_remove_attr(config, &navit);
4609 gui_internal_destroy(this);
4610 event_main_loop_quit();
4614 gui_internal_window_closed(struct gui_priv *this)
4616 gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
4620 gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4622 navit_set_destination(this->nav, NULL, NULL, 0);
4626 gui_internal_cmd_map_download_do(struct gui_priv *this, struct widget *wm, void *data)
4628 char *text=g_strdup_printf(_("Download %s"),wm->name);
4629 struct widget *w, *wb;
4630 struct map *map=data;
4631 double bllon,bllat,trlon,trlat;
4633 wb=gui_internal_menu(this, text);
4635 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4636 w->spy=this->spacing*3;
4637 gui_internal_widget_append(wb, w);
4638 if (sscanf(wm->prefix,"%lf,%lf,%lf,%lf",&bllon,&bllat,&trlon,&trlat) == 4) {
4640 struct map_selection sel;
4641 struct map_rect *mr;
4648 transform_from_geo(projection_mg, &g, &sel.u.c_rect.lu);
4651 transform_from_geo(projection_mg, &g, &sel.u.c_rect.rl);
4652 sel.range.min=type_none;
4653 sel.range.max=type_last;
4654 mr=map_rect_new(map, &sel);
4655 while ((item=map_rect_get_item(mr))) {
4658 map_rect_destroy(mr);
4661 dbg(0,"bbox=%s\n",wm->prefix);
4662 gui_internal_menu_render(this);
4666 gui_internal_cmd_map_download(struct gui_priv *this, struct widget *wm, void *data)
4668 struct attr on, off, download_enabled, download_disabled;
4669 struct widget *w,*wb,*wma;
4670 struct map *map=data;
4672 char *search,buffer[256];
4673 int found,sp_match=0;
4675 dbg(1,"wm=%p prefix=%s\n",wm,wm->prefix);
4680 while(search[sp_match] == ' ')
4686 on.type=off.type=attr_active;
4689 wb=gui_internal_menu(this, wm->name?wm->name:_("Map Download"));
4690 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4691 w->spy=this->spacing*3;
4692 gui_internal_widget_append(wb, w);
4694 wma=gui_internal_button_map_attr_new(this, _("Active"), gravity_left_center|orientation_horizontal|flags_fill, map, &on, &off, 1);
4695 gui_internal_widget_append(w, wma);
4698 download_enabled.type=download_disabled.type=attr_update;
4699 download_enabled.u.num=1;
4700 download_disabled.u.num=0;
4701 wma=gui_internal_button_map_attr_new(this
4702 , _("Download Enabled")
4703 , gravity_left_center|orientation_horizontal|flags_fill
4706 , &download_disabled
4708 gui_internal_widget_append(w, wma);
4711 f=fopen("maps/areas.tsv","r");
4712 while (f && fgets(buffer, sizeof(buffer), f)) {
4713 char *nl,*description,*description_size,*bbox,*size=NULL;
4715 if ((nl=strchr(buffer,'\n')))
4717 if ((nl=strchr(buffer,'\r')))
4719 while(buffer[sp] == ' ')
4721 if ((bbox=strchr(buffer,'\t')))
4723 if (bbox && (size=strchr(bbox,'\t')))
4725 if (search && !strcmp(buffer, search)) {
4726 wma=gui_internal_button_new_with_callback(this, _("Download completely"), NULL,
4727 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download_do, map);
4728 wma->name=g_strdup(buffer+sp);
4729 wma->prefix=g_strdup(bbox);
4730 gui_internal_widget_append(w, wma);
4732 } else if (sp < sp_match)
4734 if (sp == sp_match && found && buffer[sp]) {
4735 description=g_strdup(buffer+sp);
4737 description_size=g_strdup_printf("%s (%s)",description,size);
4739 description_size=g_strdup(description);
4740 wma=gui_internal_button_new_with_callback(this, description_size, NULL,
4741 gravity_left_center|orientation_horizontal|flags_fill, gui_internal_cmd_map_download, map);
4742 g_free(description_size);
4743 wma->prefix=g_strdup(buffer);
4744 wma->name=description;
4745 gui_internal_widget_append(w, wma);
4749 gui_internal_menu_render(this);
4753 gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
4755 struct attr attr, on, off, description, type, data, url, active;
4756 struct widget *w,*wb,*wma;
4758 struct attr_iter *iter;
4760 wb=gui_internal_menu(this, _("Maps"));
4761 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4762 w->spy=this->spacing*3;
4763 gui_internal_widget_append(wb, w);
4764 iter=navit_attr_iter_new();
4765 on.type=off.type=attr_active;
4768 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
4769 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
4770 label=g_strdup(description.u.str);
4772 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
4774 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
4776 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
4778 if (map_get_attr(attr.u.map, attr_url, &url, NULL)) {
4779 if (!map_get_attr(attr.u.map, attr_active, &active, NULL))
4781 wma=gui_internal_button_new_with_callback(this, label, image_new_xs(this, active.u.num ? "gui_active" : "gui_inactive"),
4782 gravity_left_center|orientation_horizontal|flags_fill,
4783 gui_internal_cmd_map_download, attr.u.map);
4785 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
4786 attr.u.map, &on, &off, 1);
4788 gui_internal_widget_append(w, wma);
4791 navit_attr_iter_destroy(iter);
4792 gui_internal_menu_render(this);
4796 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
4798 struct attr vehicle = {attr_vehicle,{wm->data}};
4799 navit_set_attr(this->nav, &vehicle);
4803 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
4805 struct widget *w,*wb,*row;
4806 struct attr attr,sat_attr;
4807 struct vehicle *v=wm->data;
4810 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
4812 wb=gui_internal_menu(this, _("Show Satellite Status"));
4813 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
4814 gui_internal_menu_data(this)->redisplay_widget=wm;
4815 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4816 gui_internal_widget_append(wb, w);
4817 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
4818 row = gui_internal_widget_table_row_new(this,gravity_left_top);
4819 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
4820 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
4821 gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
4822 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
4823 gui_internal_widget_append(w,row);
4824 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
4825 row = gui_internal_widget_table_row_new(this,gravity_left_top);
4826 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
4827 if (item_attr_get(attr.u.item, types[i], &sat_attr))
4828 str=g_strdup_printf("%ld", sat_attr.u.num);
4831 gui_internal_widget_append(row, gui_internal_label_new(this, str));
4834 gui_internal_widget_append(w,row);
4836 gui_internal_widget_append(wb, w);
4837 gui_internal_menu_render(this);
4841 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
4843 struct widget *w,*wb;
4845 struct vehicle *v=wm->data;
4846 wb=gui_internal_menu(this, _("Show NMEA Data"));
4847 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
4848 gui_internal_menu_data(this)->redisplay_widget=wm;
4849 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
4850 gui_internal_widget_append(wb, w);
4851 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
4852 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
4853 gui_internal_menu_render(this);
4857 * A container to hold the selected vehicle and the desired profile in
4860 struct vehicle_and_profilename {
4861 struct vehicle *vehicle;
4866 * Figures out whether the given vehicle is the active vehicle.
4868 * @return true if the vehicle is active, false otherwise.
4871 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
4874 struct attr active_vehicle;
4876 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
4877 active_vehicle.u.vehicle=NULL;
4879 return active_vehicle.u.vehicle == vehicle;
4883 save_vehicle_xml(struct vehicle *v)
4886 struct attr_iter *iter=vehicle_attr_iter_new();
4890 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
4891 if (ATTR_IS_OBJECT(attr.type))
4894 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
4898 printf("</vehicle>\n");
4901 vehicle_attr_iter_destroy(iter);
4906 * Reacts to a button press that changes a vehicle's active profile.
4908 * @see gui_internal_add_vehicle_profile
4911 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
4912 widget *wm, void *data)
4914 struct vehicle_and_profilename *vapn = data;
4915 struct vehicle *v = vapn->vehicle;
4916 char *profilename = vapn->profilename;
4917 struct attr vehicle_name_attr;
4918 char *vehicle_name = NULL;
4919 struct attr profilename_attr;
4921 // Get the vehicle name
4922 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
4923 vehicle_name = vehicle_name_attr.u.str;
4925 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
4928 // Change the profile name
4929 profilename_attr.type = attr_profilename;
4930 profilename_attr.u.str = profilename;
4931 if(!vehicle_set_attr(v, &profilename_attr)) {
4932 dbg(0, "Unable to set the vehicle's profile name\n");
4935 // Notify Navit that the routing should be re-done if this is the
4937 if (gui_internal_is_active_vehicle(this, v)) {
4938 struct attr vehicle;
4939 vehicle.type=attr_vehicle;
4940 vehicle.u.vehicle=v;
4941 navit_set_attr(this->nav, &vehicle);
4943 save_vehicle_xml(v);
4947 * Adds the vehicle profile to the GUI, allowing the user to pick a
4948 * profile for the currently selected vehicle.
4951 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
4952 *parent, struct vehicle *v, struct vehicleprofile *profile)
4954 // Just here to show up in the translation file, nice and close to
4955 // where the translations are actually used.
4956 struct attr profile_attr;
4957 struct attr *attr = NULL;
4959 char *active_profile = NULL;
4962 struct vehicle_and_profilename *context = NULL;
4964 #ifdef ONLY_FOR_TRANSLATION
4965 char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
4968 // Figure out the profile name
4969 attr = attr_search(profile->attrs, NULL, attr_name);
4971 dbg(0, "Adding vehicle profile failed. attr==NULL");
4976 // Determine whether the profile is the active one
4977 if (vehicle_get_attr(v, attr_profilename, &profile_attr, NULL))
4978 active_profile = profile_attr.u.str;
4979 active = active_profile != NULL && !strcmp(name, active_profile);
4981 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
4982 active_profile, active);
4984 // Build a translatable label.
4986 label = g_strdup_printf(_("Current profile: %s"), _(name));
4988 label = g_strdup_printf(_("Change profile to: %s"), _(name));
4991 // Create the context object (the vehicle and the desired profile)
4992 context = g_new0(struct vehicle_and_profilename, 1);
4993 context->vehicle = v;
4994 context->profilename = name;
4997 gui_internal_widget_append(parent,
4998 gui_internal_button_new_with_callback(
5000 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
5001 gravity_left_center|orientation_horizontal|flags_fill,
5002 gui_internal_cmd_set_active_profile, context));
5008 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
5010 struct widget *w,*wb;
5012 struct vehicle *v=wm->data;
5013 struct vehicleprofile *profile = NULL;
5016 wb=gui_internal_menu(this, wm->text);
5017 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5018 gui_internal_widget_append(wb, w);
5020 // Add the "Set as active" button if this isn't the active
5022 if (!gui_internal_is_active_vehicle(this, v)) {
5023 gui_internal_widget_append(w,
5024 gui_internal_button_new_with_callback(this, _("Set as active"),
5025 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5026 gui_internal_cmd_set_active_vehicle, wm->data));
5029 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
5030 gui_internal_widget_append(w,
5031 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
5032 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5033 gui_internal_cmd_show_satellite_status, wm->data));
5035 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
5036 gui_internal_widget_append(w,
5037 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
5038 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
5039 gui_internal_cmd_show_nmea_data, wm->data));
5042 // Add all the possible vehicle profiles to the menu
5043 profiles = navit_get_vehicleprofiles(this->nav);
5045 profile = (struct vehicleprofile *)profiles->data;
5046 gui_internal_add_vehicle_profile(this, w, v, profile);
5047 profiles = g_list_next(profiles);
5050 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
5051 gui_internal_menu_render(this);
5055 gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5057 struct attr attr,vattr;
5058 struct widget *w,*wb,*wl;
5059 struct attr_iter *iter;
5060 struct attr active_vehicle;
5063 wb=gui_internal_menu(this, _("Vehicle"));
5064 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5065 w->spy=this->spacing*3;
5066 gui_internal_widget_append(wb, w);
5067 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
5068 active_vehicle.u.vehicle=NULL;
5069 iter=navit_attr_iter_new();
5070 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
5071 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
5072 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
5073 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
5074 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
5075 wl->text=g_strdup(vattr.u.str);
5076 gui_internal_widget_append(w, wl);
5078 navit_attr_iter_destroy(iter);
5079 gui_internal_menu_render(this);
5084 gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5086 struct widget *wb,*w;
5088 wb=gui_internal_menu(this, _("Rules"));
5089 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
5090 w->spy=this->spacing*3;
5091 gui_internal_widget_append(wb, w);
5094 on.type=off.type=attr_tracking;
5095 gui_internal_widget_append(w,
5096 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
5100 on.type=off.type=attr_orientation;
5101 gui_internal_widget_append(w,
5102 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
5106 on.type=off.type=attr_follow_cursor;
5107 gui_internal_widget_append(w,
5108 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
5110 gui_internal_menu_render(this);
5113 //##############################################################################################################
5116 //# Authors: Martin Schaller (04/2008)
5117 //##############################################################################################################
5118 static void gui_internal_motion(void *data, struct point *p)
5121 struct gui_priv *this=data;
5122 if (!this->root.children) {
5123 navit_handle_motion(this->nav, p);
5129 if(!this->motion_timeout_callback)
5130 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
5131 if(!this->motion_timeout_event)
5132 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
5136 find_attr(const char **names, const char **values, const char *name)
5139 if (!g_strcasecmp(*names, name))
5141 names+=xml_attr_distance;
5142 values+=xml_attr_distance;
5148 find_attr_dup(const char **names, const char **values, const char *name)
5150 return g_strdup(find_attr(names, values, name));
5154 gui_internal_evaluate(struct gui_priv *this, const char *command)
5157 command_evaluate(&this->self, command);
5162 gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
5164 gui_internal_evaluate(this,w->command);
5168 gui_internal_html_submit_set(struct gui_priv *this, struct widget *w, struct form *form)
5171 if (w->form == form && w->name) {
5172 struct attr *attr=attr_new_from_text(w->name, w->text?w->text:"");
5174 gui_set_attr(this->self.u.gui, attr);
5180 gui_internal_html_submit_set(this, w, form);
5187 gui_internal_html_submit(struct gui_priv *this, struct widget *w, void *data)
5189 struct widget *menu;
5192 dbg(1,"enter form %p %s\n",w->form,w->form->onsubmit);
5193 l=g_list_last(this->root.children);
5195 graphics_draw_mode(this->gra, draw_mode_begin);
5196 gui_internal_highlight_do(this, NULL);
5197 gui_internal_menu_render(this);
5198 graphics_draw_mode(this->gra, draw_mode_end);
5199 gui_internal_html_submit_set(this, menu, w->form);
5200 gui_internal_evaluate(this,w->form->onsubmit);
5204 gui_internal_html_load_href(struct gui_priv *this, char *href, int replace)
5207 gui_internal_prune_menu_count(this, 1, 0);
5208 if (href && href[0] == '#') {
5209 dbg(1,"href=%s\n",href);
5211 this->href=g_strdup(href);
5212 gui_internal_html_menu(this, this->html_text, href+1);
5217 gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
5219 gui_internal_html_load_href(this, w->command, 0);
5222 struct div_flags_map {
5226 } div_flags_map[] = {
5227 {"gravity","none",gravity_none},
5228 {"gravity","left",gravity_left},
5229 {"gravity","xcenter",gravity_xcenter},
5230 {"gravity","right",gravity_right},
5231 {"gravity","top",gravity_top},
5232 {"gravity","ycenter",gravity_ycenter},
5233 {"gravity","bottom",gravity_bottom},
5234 {"gravity","left_top",gravity_left_top},
5235 {"gravity","top_center",gravity_top_center},
5236 {"gravity","right_top",gravity_right_top},
5237 {"gravity","left_center",gravity_left_center},
5238 {"gravity","center",gravity_center},
5239 {"gravity","right_center",gravity_right_center},
5240 {"gravity","left_bottom",gravity_left_bottom},
5241 {"gravity","bottom_center",gravity_bottom_center},
5242 {"gravity","right_bottom",gravity_right_bottom},
5243 {"expand","1",flags_expand},
5244 {"fill","1",flags_fill},
5245 {"orientation","horizontal",orientation_horizontal},
5246 {"orientation","vertical",orientation_vertical},
5247 {"orientation","horizontal_vertical",orientation_horizontal_vertical},
5251 div_flag(const char **names, const char **values, char *name)
5255 const char *value=find_attr(names, values, name);
5258 for (i = 0 ; i < sizeof(div_flags_map)/sizeof(struct div_flags_map); i++) {
5259 if (!strcmp(div_flags_map[i].attr,name) && !strcmp(div_flags_map[i].val,value))
5260 ret|=div_flags_map[i].flags;
5266 div_flags(const char **names, const char **values)
5269 flags = div_flag(names, values, "gravity");
5270 flags |= div_flag(names, values, "orientation");
5271 flags |= div_flag(names, values, "expand");
5272 flags |= div_flag(names, values, "fill");
5276 static struct widget *
5277 html_image(struct gui_priv *this, const char **names, const char **values)
5279 const char *src, *size;
5280 struct graphics_image *img=NULL;
5282 src=find_attr(names, values, "src");
5285 size=find_attr(names, values, "size");
5288 if (!strcmp(size,"l"))
5289 img=image_new_l(this, src);
5290 else if (!strcmp(size,"s"))
5291 img=image_new_s(this, src);
5292 else if (!strcmp(size,"xs"))
5293 img=image_new_xs(this, src);
5296 return gui_internal_image_new(this, img);
5300 gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
5302 struct gui_priv *this=data;
5304 enum html_tag tag=html_tag_none;
5305 struct html *html=&this->html[this->html_depth];
5306 const char *cond, *type;
5308 if (!g_strcasecmp(tag_name,"text"))
5314 cond=find_attr(names, values, "cond");
5316 if (cond && !this->html_skip) {
5317 if (!command_evaluate_to_boolean(&this->self, cond, NULL))
5321 for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
5322 if (!g_strcasecmp(html_tag_map[i].tag_name, tag_name)) {
5323 tag=html_tag_map[i].tag;
5328 if (!this->html_skip && !html->skip) {
5331 html->name=find_attr_dup(names, values, "name");
5333 html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
5335 this->html_anchor_found=1;
5337 html->command=find_attr_dup(names, values, "onclick");
5338 html->href=find_attr_dup(names, values, "href");
5339 html->refresh_cond=find_attr_dup(names, values, "refresh_cond");
5342 html->command=find_attr_dup(names, values, "onclick");
5343 html->w=html_image(this, names, values);
5346 this->form=g_new0(struct form, 1);
5347 this->form->onsubmit=find_attr_dup(names, values, "onsubmit");
5349 case html_tag_input:
5350 type=find_attr_dup(names, values, "type");
5353 if (!strcmp(type,"image")) {
5354 html->w=html_image(this, names, values);
5356 html->w->state|=STATE_SENSITIVE;
5357 html->w->func=gui_internal_html_submit;
5360 if (!strcmp(type,"text") || !strcmp(type,"password")) {
5361 html->w=gui_internal_label_new(this, NULL);
5362 html->w->background=this->background;
5363 html->w->flags |= div_flags(names, values);
5364 html->w->state|=STATE_EDITABLE;
5365 if (!this->editable) {
5366 this->editable=html->w;
5367 html->w->state|=STATE_EDIT;
5369 this->keyboard_required=1;
5370 if (!strcmp(type,"password"))
5371 html->w->flags2 |= 1;
5374 html->w->form=this->form;
5375 html->w->name=find_attr_dup(names, values, "name");
5379 html->w=gui_internal_box_new(this, div_flags(names, values));
5380 html->container=this->html_container;
5381 this->html_container=html->w;
5387 this->html_skip+=html->skip;
5392 gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
5394 struct gui_priv *this=data;
5396 struct html *parent=NULL;
5398 if (!g_strcasecmp(tag_name,"text"))
5401 html=&this->html[this->html_depth];
5402 if (this->html_depth > 0)
5403 parent=&this->html[this->html_depth-1];
5406 if (!this->html_skip) {
5407 if (html->command && html->w) {
5408 html->w->state |= STATE_SENSITIVE;
5409 html->w->command=html->command;
5410 html->w->func=gui_internal_html_command;
5413 if (parent && (parent->href || parent->command) && html->w) {
5414 html->w->state |= STATE_SENSITIVE;
5415 if (parent->command) {
5416 html->w->command=g_strdup(parent->command);
5417 html->w->func=gui_internal_html_command;
5419 html->w->command=g_strdup(parent->href);
5420 html->w->func=gui_internal_html_href;
5423 switch (html->tag) {
5425 this->html_container=html->container;
5427 case html_tag_input:
5428 gui_internal_widget_append(this->html_container, html->w);
5437 this->html_skip-=html->skip;
5438 g_free(html->command);
5441 g_free(html->refresh_cond);
5445 gui_internal_refresh_callback_called(struct gui_priv *this, struct menu_data *menu_data)
5447 if (gui_internal_menu_data(this) == menu_data) {
5448 char *href=g_strdup(menu_data->href);
5449 gui_internal_html_load_href(this, href, 1);
5455 gui_internal_set_refresh_callback(struct gui_priv *this, char *cond)
5457 dbg(0,"cond=%s\n",cond);
5459 enum attr_type type;
5460 struct object_func *func;
5461 struct menu_data *menu_data=gui_internal_menu_data(this);
5462 dbg(0,"navit=%p\n",this->nav);
5463 type=command_evaluate_to_attr(&this->self, cond, NULL, &menu_data->refresh_callback_obj);
5464 if (type == attr_none)
5466 func=object_func_lookup(menu_data->refresh_callback_obj.type);
5467 if (!func || !func->add_attr)
5469 menu_data->refresh_callback.type=attr_callback;
5470 menu_data->refresh_callback.u.callback=callback_new_attr_2(callback_cast(gui_internal_refresh_callback_called),type,this,menu_data);
5471 func->add_attr(menu_data->refresh_callback_obj.u.data, &menu_data->refresh_callback);
5476 gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
5478 struct gui_priv *this=data;
5480 int depth=this->html_depth-1;
5481 struct html *html=&this->html[depth];
5482 gchar *text_stripped;
5484 if (this->html_skip)
5486 while (isspace(text[0])) {
5490 while (len > 0 && isspace(text[len-1]))
5493 text_stripped = g_strndup(text, len);
5494 if (html->tag == html_tag_html && depth > 2) {
5495 if (this->html[depth-1].tag == html_tag_script) {
5496 html=&this->html[depth-2];
5499 switch (html->tag) {
5501 if (html->name && len) {
5502 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
5503 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
5504 gui_internal_menu_data(this)->href=g_strdup(this->href);
5505 gui_internal_set_refresh_callback(this, html->refresh_cond);
5506 this->html_container->spx=this->spacing*10;
5510 if (!this->html_container) {
5511 this->html_container=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
5512 gui_internal_widget_append(gui_internal_menu(this, _(text_stripped)), this->html_container);
5513 this->html_container->spx=this->spacing*10;
5518 w=gui_internal_box_new(this, gravity_center|orientation_vertical);
5519 gui_internal_widget_append(w, html->w);
5520 gui_internal_widget_append(w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
5526 gui_internal_widget_append(html->w, gui_internal_text_new(this, _(text_stripped), gravity_center|orientation_vertical));
5529 case html_tag_script:
5530 dbg(1,"execute %s\n",text_stripped);
5531 gui_internal_evaluate(this,text_stripped);
5536 g_free(text_stripped);
5540 gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
5542 char *doc=g_strdup(document);
5543 graphics_draw_mode(this->gra, draw_mode_begin);
5544 this->html_container=NULL;
5546 this->html_anchor=anchor;
5547 this->html_anchor_found=0;
5549 this->keyboard_required=0;
5550 this->editable=NULL;
5551 callback_list_call_attr_2(this->cbl,attr_gui,anchor,&doc);
5552 xml_parse_text(doc, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
5554 if (this->keyboard_required && this->keyboard) {
5555 this->html_container->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
5556 gui_internal_widget_append(this->html_container, gui_internal_keyboard(this,2));
5558 gui_internal_menu_render(this);
5559 graphics_draw_mode(this->gra, draw_mode_end);
5564 gui_internal_enter(struct gui_priv *this, int ignore)
5566 struct graphics *gra=this->gra;
5567 this->ignore_button=ignore;
5568 this->clickp_valid=this->vehicle_valid=0;
5570 navit_block(this->nav, 1);
5571 graphics_overlay_disable(gra, 1);
5574 this->root.background=this->background;
5578 gui_internal_leave(struct gui_priv *this)
5580 graphics_draw_mode(this->gra, draw_mode_end);
5584 gui_internal_enter_setup(struct gui_priv *this, struct point *p)
5586 struct transformation *trans;
5589 struct attr attr,attrp;
5591 trans=navit_get_trans(this->nav);
5592 attr_free(this->click_coord_geo);
5593 this->click_coord_geo=NULL;
5594 attr_free(this->position_coord_geo);
5595 this->position_coord_geo=NULL;
5597 transform_reverse(trans, p, &c);
5598 dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
5599 this->clickp.pro=transform_get_projection(trans);
5602 transform_to_geo(this->clickp.pro, &c, &g);
5603 attr.u.coord_geo=&g;
5604 attr.type=attr_click_coord_geo;
5605 this->click_coord_geo=attr_dup(&attr);
5607 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
5608 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
5609 this->position_coord_geo=attr_dup(&attrp);
5610 this->vehiclep.pro=transform_get_projection(trans);
5611 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
5612 this->vehiclep.x=c.x;
5613 this->vehiclep.y=c.y;
5614 this->vehicle_valid=1;
5619 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore, char *href)
5622 gui_internal_enter(this, ignore);
5623 gui_internal_enter_setup(this, p);
5625 gui_internal_html_load_href(this, href?href:"#Main Menu", 0);
5629 gui_internal_cmd_menu2(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
5632 int i=0, ignore=0, replace=0;
5634 if (in && in[i] && ATTR_IS_INT(in[i]->type))
5635 ignore=in[i++]->u.num;
5637 if (in && in[i] && ATTR_IS_STRING(in[i]->type)) {
5638 href=in[i++]->u.str;
5639 if (in[i] && ATTR_IS_INT(in[i]->type))
5640 replace=in[i++]->u.num;
5643 if (this->root.children) {
5646 gui_internal_html_load_href(this, href, replace);
5650 gui_internal_cmd_menu(this, NULL, ignore, href);
5655 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
5657 if (widget->text && strlen(widget->text)) {
5658 if (this->vehicle_valid)
5659 navit_textfile_debug_log_at(this->nav, &this->vehiclep, "type=log_entry label=\"%s\"",widget->text);
5661 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
5663 g_free(widget->text);
5665 gui_internal_prune_menu(this, NULL);
5666 gui_internal_check_exit(this);
5670 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
5672 gui_internal_cmd_log_do(this, widget->data);
5676 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
5680 len=strlen(wm->text);
5681 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
5682 wm->text[len-1]='\0';
5683 gui_internal_cmd_log_do(this, wm);
5690 gui_internal_cmd_log(struct gui_priv *this)
5692 struct widget *w,*wb,*wk,*wl,*we,*wnext;
5693 gui_internal_enter(this, 1);
5694 gui_internal_enter_setup(this, NULL);
5695 wb=gui_internal_menu(this, "Log Message");
5696 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5697 gui_internal_widget_append(wb, w);
5698 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
5699 gui_internal_widget_append(w, we);
5700 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
5701 wk->state |= STATE_EDIT|STATE_EDITABLE|STATE_CLEAR;
5702 wk->background=this->background;
5703 wk->flags |= flags_expand|flags_fill;
5704 wk->func = gui_internal_cmd_log_changed;
5705 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
5706 wnext->state |= STATE_SENSITIVE;
5707 wnext->func = gui_internal_cmd_log_clicked;
5709 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
5710 gui_internal_widget_append(w, wl);
5712 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
5713 gui_internal_menu_render(this);
5714 gui_internal_leave(this);
5718 gui_internal_check_exit(struct gui_priv *this)
5720 struct graphics *gra=this->gra;
5721 if (! this->root.children) {
5722 gui_internal_search_idle_end(this);
5723 gui_internal_search_list_destroy(this);
5724 graphics_overlay_disable(gra, 0);
5725 if (!navit_block(this->nav, 0)) {
5727 navit_draw(this->nav);
5729 navit_draw_displaylist(this->nav);
5735 gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
5739 attr->u.num=this->root.children != NULL;
5741 case attr_click_coord_geo:
5742 if (!this->click_coord_geo)
5744 *attr=*this->click_coord_geo;
5746 case attr_position_coord_geo:
5747 if (!this->position_coord_geo)
5749 *attr=*this->position_coord_geo;
5752 attr->u.num=this->pitch;
5755 attr->u.num=this->mouse_button_clicked_on_map;
5765 gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
5767 switch (attr->type) {
5769 g_free(this->html_text);
5770 this->html_text=g_strdup(attr->u.str);
5778 gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
5780 switch (attr->type) {
5781 case attr_fullscreen:
5782 if ((this->fullscreen > 0) != (attr->u.num > 0)) {
5783 graphics_draw_mode(this->gra, draw_mode_end);
5784 this->win->fullscreen(this->win, attr->u.num > 0);
5785 graphics_draw_mode(this->gra, draw_mode_begin);
5787 this->fullscreen=attr->u.num;
5789 case attr_menu_on_map_click:
5790 this->menu_on_map_click=attr->u.num;
5793 dbg(0,"%s\n",attr_to_name(attr->type));
5798 static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
5800 struct displaylist_handle *dlh;
5801 struct displaylist *display;
5802 struct displayitem *di;
5803 struct attr cb,**attr_list=NULL;
5806 display=navit_get_displaylist(this->nav);
5807 dlh=graphics_displaylist_open(display);
5808 while ((di=graphics_displaylist_next(dlh))) {
5809 struct item *item=graphics_displayitem_get_item(di);
5810 if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
5811 graphics_displayitem_within_dist(display, di, p, this->radius)) {
5812 struct map_rect *mr=map_rect_new(item->map, NULL);
5813 struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
5815 if (itemo && item_attr_get(itemo, attr_data, &attr))
5816 attr_list=attr_generic_add_attr(attr_list, &attr);
5817 map_rect_destroy(mr);
5820 graphics_displaylist_close(dlh);
5821 if (attr_list && navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
5822 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
5823 attr_list_free(attr_list);
5828 //##############################################################################################################
5829 //# Description: Function to handle mouse clicks and scroll wheel movement
5831 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
5832 //##############################################################################################################
5833 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
5835 struct gui_priv *this=data;
5836 struct graphics *gra=this->gra;
5838 dbg(1,"enter %d %d\n", pressed, button);
5839 // if still on the map (not in the menu, yet):
5840 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
5841 if (!this->root.children || this->ignore_button) {
5843 this->ignore_button=0;
5844 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
5845 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
5846 dbg(1,"navit has handled button\n");
5849 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
5852 if (this->menu_on_map_click) {
5853 this->mouse_button_clicked_on_map=1;
5854 gui_internal_cmd_menu(this, p, 0, NULL);
5855 this->mouse_button_clicked_on_map=0;
5858 if (this->signal_on_map_click) {
5859 gui_internal_dbus_signal(this, p);
5866 // if already in the menu:
5870 gui_internal_highlight(this);
5875 graphics_draw_mode(gra, draw_mode_begin);
5876 gui_internal_call_highlighted(this);
5877 if (!event_main_loop_has_quit()) {
5878 gui_internal_highlight(this);
5879 graphics_draw_mode(gra, draw_mode_end);
5880 gui_internal_check_exit(this);
5886 gui_internal_setup(struct gui_priv *this)
5888 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
5889 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
5890 struct graphics *gra=this->gra;
5891 unsigned char *buffer;
5895 if (this->background)
5897 this->background=graphics_gc_new(gra);
5898 this->background2=graphics_gc_new(gra);
5899 this->highlight_background=graphics_gc_new(gra);
5900 graphics_gc_set_foreground(this->highlight_background, &cbh);
5901 this->foreground=graphics_gc_new(gra);
5902 graphics_gc_set_foreground(this->foreground, &cf);
5903 this->text_background=graphics_gc_new(gra);
5904 this->text_foreground=graphics_gc_new(gra);
5905 graphics_gc_set_foreground(this->background, &this->background_color);
5906 graphics_gc_set_foreground(this->background2, &this->background2_color);
5907 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
5908 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
5909 gui_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/gui_internal.txt", NULL);
5910 if (file_get_contents(gui_file,&buffer,&size)) {
5911 char *command=g_malloc(size+1);
5912 strncpy(command,(const char *)buffer,size);
5914 command_evaluate(&this->self, command);
5921 //##############################################################################################################
5924 //# Authors: Martin Schaller (04/2008)
5925 //##############################################################################################################
5926 static void gui_internal_resize(void *data, int w, int h)
5928 struct gui_priv *this=data;
5931 gui_internal_setup(this);
5933 if (this->root.w != w || this->root.h != h) {
5938 dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
5939 navit_handle_resize(this->nav, w, h);
5940 if (this->root.children) {
5942 gui_internal_prune_menu(this, NULL);
5943 gui_internal_html_load_href(this, "#Main Menu", 0);
5945 gui_internal_menu_render(this);
5951 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
5966 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
5968 GList *l=wi->children;
5969 // Skip hidden elements
5970 if (wi->p.x==0 && wi->p.y==0 && wi->w==0 && wi->h==0)
5972 if ((wi->state & STATE_SENSITIVE) ) {
5975 gui_internal_keynav_point(wi, -dx, -dy, &wp);
5977 dist1=(wp.x-p->x)*dx;
5980 dist1=(wp.y-p->y)*dy;
5988 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);
5994 if (dist1 < *distance) {
6001 struct widget *child=l->data;
6002 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
6008 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
6010 struct widget *result,*menu=g_list_last(this->root.children)->data;
6013 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6014 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
6020 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
6022 gui_internal_keynav_point(result, dx, dy, &p);
6023 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
6028 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
6029 dbg(1,"result=%p\n", result);
6041 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
6042 dbg(1,"wraparound result=%p\n", result);
6044 gui_internal_highlight_do(this, result);
6046 gui_internal_say(this, result, 1);
6049 //##############################################################################################################
6052 //# Authors: Martin Schaller (04/2008)
6053 //##############################################################################################################
6054 static void gui_internal_keypress(void *data, char *key)
6056 struct gui_priv *this=data;
6059 if (!this->root.children) {
6060 transform_get_size(navit_get_trans(this->nav), &w, &h);
6065 navit_set_center_screen(this->nav, &p, 1);
6067 case NAVIT_KEY_DOWN:
6070 navit_set_center_screen(this->nav, &p, 1);
6072 case NAVIT_KEY_LEFT:
6075 navit_set_center_screen(this->nav, &p, 1);
6077 case NAVIT_KEY_RIGHT:
6080 navit_set_center_screen(this->nav, &p, 1);
6082 case NAVIT_KEY_ZOOM_IN:
6083 navit_zoom_in(this->nav, 2, NULL);
6085 case NAVIT_KEY_ZOOM_OUT:
6086 navit_zoom_out(this->nav, 2, NULL);
6088 case NAVIT_KEY_RETURN:
6089 case NAVIT_KEY_MENU:
6090 gui_internal_cmd_menu(this, NULL, 0, NULL);
6095 graphics_draw_mode(this->gra, draw_mode_begin);
6097 case NAVIT_KEY_LEFT:
6098 gui_internal_keynav_highlight_next(this,-1,0);
6100 case NAVIT_KEY_RIGHT:
6101 gui_internal_keynav_highlight_next(this,1,0);
6104 gui_internal_keynav_highlight_next(this,0,-1);
6106 case NAVIT_KEY_DOWN:
6107 gui_internal_keynav_highlight_next(this,0,1);
6109 case NAVIT_KEY_BACK:
6110 if (g_list_length(this->root.children) > 1)
6111 gui_internal_back(this, NULL, NULL);
6113 gui_internal_prune_menu(this, NULL);
6115 case NAVIT_KEY_RETURN:
6116 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
6117 gui_internal_call_highlighted(this);
6119 gui_internal_keypress_do(this, key);
6122 gui_internal_keypress_do(this, key);
6124 if (!event_main_loop_has_quit()) {
6125 graphics_draw_mode(this->gra, draw_mode_end);
6126 gui_internal_check_exit(this);
6131 //##############################################################################################################
6134 //# Authors: Martin Schaller (04/2008)
6135 //##############################################################################################################
6136 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
6139 struct transformation *trans=navit_get_trans(this->nav);
6141 win=graphics_get_data(gra, "window");
6144 navit_ignore_graphics_events(this->nav, 1);
6147 navit_ignore_graphics_events(this->nav, 1);
6148 transform_get_size(trans, &this->root.w, &this->root.h);
6149 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
6150 graphics_add_callback(gra, this->resize_cb);
6151 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
6152 graphics_add_callback(gra, this->button_cb);
6153 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
6154 graphics_add_callback(gra, this->motion_cb);
6155 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
6156 graphics_add_callback(gra, this->keypress_cb);
6157 this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
6158 graphics_add_callback(gra, this->window_closed_cb);
6160 // set fullscreen if needed
6161 if (this->fullscreen)
6162 this->win->fullscreen(this->win, this->fullscreen != 0);
6163 /* Was resize callback already issued? */
6164 if (navit_get_ready(this->nav) & 2)
6165 gui_internal_setup(this);
6169 static void gui_internal_disable_suspend(struct gui_priv *this)
6171 if (this->win->disable_suspend)
6172 this->win->disable_suspend(this->win);
6175 //##############################################################################################################
6178 //# Authors: Martin Schaller (04/2008)
6179 //##############################################################################################################
6180 struct gui_methods gui_internal_methods = {
6183 gui_internal_set_graphics,
6187 gui_internal_disable_suspend,
6188 gui_internal_get_attr,
6189 gui_internal_add_attr,
6190 gui_internal_set_attr,
6194 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
6196 struct attr private_data = { attr_private_data, {(void *)&priv->data}};
6198 *out=attr_generic_add_attr(*out, &private_data);
6202 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
6204 callback_list_add(priv->cbl, cb);
6208 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
6210 callback_list_remove(priv->cbl, cb);
6214 static struct gui_internal_methods gui_internal_methods_ext = {
6215 gui_internal_add_callback,
6216 gui_internal_remove_callback,
6217 gui_internal_menu_render,
6224 gui_internal_get_flags(struct widget *widget)
6226 return widget->flags;
6230 gui_internal_set_flags(struct widget *widget, enum flags flags)
6232 widget->flags=flags;
6236 gui_internal_get_state(struct widget *widget)
6238 return widget->state;
6242 gui_internal_set_state(struct widget *widget, int state)
6244 widget->state=state;
6248 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
6254 gui_internal_set_data(struct widget *widget, void *data)
6260 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
6262 widget->background=this->background;
6265 static struct gui_internal_widget_methods gui_internal_widget_methods = {
6266 gui_internal_widget_append,
6267 gui_internal_button_new,
6268 gui_internal_button_new_with_callback,
6269 gui_internal_box_new,
6270 gui_internal_label_new,
6271 gui_internal_image_new,
6272 gui_internal_keyboard,
6274 gui_internal_get_flags,
6275 gui_internal_set_flags,
6276 gui_internal_get_state,
6277 gui_internal_set_state,
6278 gui_internal_set_func,
6279 gui_internal_set_data,
6280 gui_internal_set_default_background,
6284 gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
6286 char *str=NULL,*str2=NULL;
6287 dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
6290 dbg(1,"%s\n",attr_to_name(in[0]->type));
6291 if (ATTR_IS_STRING(in[0]->type)) {
6294 if (ATTR_IS_COORD_GEO(in[0]->type)) {
6295 str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
6298 str=g_strdup_printf("<html>%s</html>\n",str);
6299 xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
6307 * @brief Creates a new table widget.
6309 * Creates and returns a new table widget. This function will
6310 * setup next/previous buttons as children.
6312 * @param this The graphics context.
6313 * @param flags widget sizing flags.
6314 * @returns The newly created widget
6316 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
6318 struct widget * widget = g_new0(struct widget,1);
6319 struct table_data * data = NULL;
6320 widget->type=widget_table;
6321 widget->flags=flags;
6322 widget->data = g_new0(struct table_data,1);
6323 widget->data_free=gui_internal_table_data_free;
6325 // We have to set background here explicitly
6326 // because it will be used by inner elements created later in this
6327 // function (navigation buttons). Else that elements won't have
6329 widget->background=this->background;
6330 data = (struct table_data*)widget->data;
6333 data->next_button=gui_internal_box_new(this, gravity_center|orientation_horizontal);
6334 gui_internal_widget_append(data->next_button, gui_internal_text_new(this,_("Next"),gravity_center|orientation_horizontal));
6335 gui_internal_widget_append(data->next_button, gui_internal_image_new(this, image_new_xs(this, "gui_arrow_right")));
6336 data->next_button->func=gui_internal_table_button_next;
6337 data->next_button->data=widget;
6340 data->prev_button = gui_internal_button_new_with_callback
6342 image_new_xs(this, "gui_arrow_left"),
6343 gravity_center |orientation_horizontal,
6344 gui_internal_table_button_prev,NULL);
6346 data->prev_button->data=widget;
6350 data->button_box=gui_internal_box_new(this,
6351 gravity_center|orientation_horizontal);
6352 gui_internal_widget_append(widget, data->button_box);
6353 gui_internal_widget_append(data->button_box, data->prev_button);
6354 gui_internal_widget_append(data->button_box, data->next_button);
6356 data->button_box->bl=this->spacing;
6357 gui_internal_widget_pack(this,data->button_box);
6365 * @brief Clears all the rows from the table.
6366 * This function removes all rows from a table.
6367 * New rows can later be added to the table.
6369 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
6372 struct table_data * table_data = (struct table_data* ) table->data;
6374 iter = table->children;
6376 if(iter->data != table_data->button_box) {
6377 struct widget * child = (struct widget*)iter->data;
6378 gui_internal_widget_destroy(this,child);
6379 if(table->children == iter) {
6380 table->children = g_list_remove(iter,iter->data);
6381 iter=table->children;
6384 iter = g_list_remove(iter,iter->data);
6387 iter = g_list_next(iter);
6391 table_data->top_row=NULL;
6392 table_data->bottom_row=NULL;
6393 if(table_data->page_headers)
6394 g_list_free(table_data->page_headers);
6395 table_data->page_headers=NULL;
6399 * @brief Check if table has any data rows filled.
6400 * @param this The graphics context
6401 * @param table table widget
6402 * @returns 1 if the table is empty, 0 if there any data rows present.
6404 static int gui_internal_widget_table_is_empty(struct gui_priv *this, struct widget * table)
6407 struct table_data *td=(struct table_data*) table->data;
6409 for(l=table->children;l;l=g_list_next(l)) {
6410 if(l->data != td->button_box)
6418 * Creates a new table_row widget.
6419 * @param this The graphics context
6420 * @param flags Sizing flags for the row
6421 * @returns The new table_row widget.
6423 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
6425 struct widget * widget = g_new0(struct widget,1);
6426 widget->type=widget_table_row;
6427 widget->flags=flags;
6434 * @brief Computes the column dimensions for the table.
6436 * @param w The table widget to compute dimensions for.
6438 * This function examines all of the rows and columns for the table w
6439 * and returns a list (GList) of table_column_desc elements that
6440 * describe each column of the table.
6442 * The caller is responsible for freeing the returned list.
6444 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
6447 GList * column_desc = NULL;
6448 GList * current_desc=NULL;
6449 GList * cur_row = w->children;
6450 struct widget * cur_row_widget=NULL;
6451 GList * cur_column=NULL;
6452 struct widget * cell_w=NULL;
6453 struct table_column_desc * current_cell=NULL;
6454 struct table_data * table_data=NULL;
6461 * Scroll through the the table and
6462 * 1. Compute the maximum width + height of each column across all rows.
6464 table_data = (struct table_data*) w->data;
6465 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
6467 cur_row_widget = (struct widget*) cur_row->data;
6468 current_desc = column_desc;
6469 if(cur_row_widget == table_data->button_box)
6474 for(cur_column = cur_row_widget->children; cur_column;
6475 cur_column=g_list_next(cur_column))
6477 cell_w = (struct widget*) cur_column->data;
6478 gui_internal_widget_pack(this,cell_w);
6479 if(current_desc == 0)
6481 current_cell = g_new0(struct table_column_desc,1);
6482 column_desc = g_list_append(column_desc,current_cell);
6483 current_desc = g_list_last(column_desc);
6484 current_cell->height=cell_w->h;
6485 current_cell->width=cell_w->w;
6486 total_width+=cell_w->w;
6491 current_cell = current_desc->data;
6494 if(current_cell->height < height )
6496 current_cell->height = height;
6498 if(current_cell->width < width)
6500 total_width += (width-current_cell->width);
6501 current_cell->width = width;
6506 current_desc = g_list_next(current_desc);
6516 * If the width of all columns is less than the width off
6517 * the table expand each cell proportionally.
6520 if(total_width+(this->spacing*column_count) < w->w ) {
6521 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
6522 current_cell = (struct table_column_desc*) current_desc->data;
6523 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
6532 * @brief Computes the height and width for the table.
6534 * The height and widht are computed to display all cells in the table
6535 * at the requested height/width.
6537 * @param this The graphics context
6538 * @param w The widget to pack.
6541 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
6547 GList * column_data = gui_internal_compute_table_dimensions(this,w);
6549 struct table_column_desc * cell_desc=0;
6550 struct table_data * table_data = (struct table_data*)w->data;
6552 for(current = column_data; current; current=g_list_next(current))
6554 if(table_data->button_box == current->data )
6558 cell_desc = (struct table_column_desc *) current->data;
6559 width = width + cell_desc->width + this->spacing;
6560 if(height < cell_desc->height)
6562 height = cell_desc->height ;
6568 for(current=w->children; current; current=g_list_next(current))
6570 if(current->data!= table_data->button_box)
6577 if(w->w + w->c.x > this->root.w)
6579 w->w = this->root.w - w->c.x;
6583 if(w->h + w->c.y > this->root.h )
6586 * Do not allow the widget to exceed the screen.
6589 w->h = this->root.h- w->c.y - height;
6592 if (table_data->button_box)
6594 gui_internal_widget_pack(this,table_data->button_box);
6599 * Deallocate column descriptions.
6601 current = column_data;
6602 while( (current = g_list_last(current)) )
6604 current = g_list_remove(current,current->data);
6610 * @brief Invalidates coordinates for previosly rendered table widget rows.
6612 * @param table_data Data from the table object.
6614 void gui_internal_table_hide_rows(struct table_data * table_data)
6617 for(cur_row=table_data->top_row; cur_row ; cur_row = g_list_next(cur_row))
6619 struct widget * cur_row_widget = (struct widget*)cur_row->data;
6620 if (cur_row_widget->type!=widget_table_row)
6622 cur_row_widget->p.x=0;
6623 cur_row_widget->p.y=0;
6624 cur_row_widget->w=0;
6625 cur_row_widget->h=0;
6626 if(cur_row==table_data->bottom_row)
6632 * @brief Renders a table widget.
6634 * @param this The graphics context
6635 * @param w The table widget to render.
6637 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
6642 GList * column_desc=NULL;
6643 GList * cur_row = NULL;
6644 GList * current_desc=NULL;
6645 struct table_data * table_data = (struct table_data*)w->data;
6647 int is_first_page=1;
6648 struct table_column_desc * dim=NULL;
6650 dbg_assert(table_data);
6651 column_desc = gui_internal_compute_table_dimensions(this,w);
6655 gui_internal_table_hide_rows(table_data);
6657 * Skip rows that are on previous pages.
6659 cur_row = w->children;
6660 if(table_data->top_row && table_data->top_row != w->children && !table_data->button_box_hide)
6662 cur_row = table_data->top_row;
6665 table_data->top_row=NULL;
6668 * Loop through each row. Drawing each cell with the proper sizes,
6669 * at the proper positions.
6671 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
6673 int max_height=0, bbox_height=0;
6674 struct widget * cur_row_widget;
6675 GList * cur_column=NULL;
6676 current_desc = column_desc;
6677 cur_row_widget = (struct widget*)cur_row->data;
6678 x =w->p.x+this->spacing;
6679 if(cur_row_widget == table_data->button_box )
6683 dim = (struct table_column_desc*)current_desc->data;
6685 if (table_data->button_box && !table_data->button_box_hide)
6686 bbox_height=table_data->button_box->h;
6688 if( y + dim->height + bbox_height + this->spacing >= w->p.y + w->h )
6691 * No more drawing space left.
6696 for(cur_column = cur_row_widget->children; cur_column;
6697 cur_column=g_list_next(cur_column))
6699 struct widget * cur_widget = (struct widget*) cur_column->data;
6700 dim = (struct table_column_desc*)current_desc->data;
6703 cur_widget->w=dim->width;
6705 cur_widget->h=dim->height;
6707 max_height = dim->height;
6708 /* We pack the widget before rendering to ensure that the x and y
6709 * coordinates get pushed down.
6711 gui_internal_widget_pack(this,cur_widget);
6712 gui_internal_widget_render(this,cur_widget);
6714 if(dim->height > max_height)
6716 max_height = dim->height;
6720 /* Row object should have its coordinates in actual
6721 * state to be able to pass mouse clicks to Column objects
6723 cur_row_widget->p.x=w->p.x;
6724 cur_row_widget->w=w->w;
6725 cur_row_widget->p.y=y;
6726 cur_row_widget->h=max_height;
6728 table_data->bottom_row=cur_row;
6729 current_desc = g_list_next(current_desc);
6731 if(table_data->button_box && (is_skipped || !is_first_page) && !table_data->button_box_hide )
6733 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
6735 if(table_data->button_box->p.y < y )
6737 table_data->button_box->p.y=y;
6739 table_data->button_box->p.x = w->p.x;
6740 table_data->button_box->w = w->w;
6741 // table_data->button_box->h = w->h - y;
6742 // table_data->next_button->h=table_data->button_box->h;
6743 // table_data->prev_button->h=table_data->button_box->h;
6744 // table_data->next_button->c.y=table_data->button_box->c.y;
6745 // table_data->prev_button->c.y=table_data->button_box->c.y;
6746 gui_internal_widget_pack(this,table_data->button_box);
6747 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
6749 table_data->button_box->p.y = w->p.y + w->h -
6750 table_data->button_box->h;
6754 table_data->next_button->state|= STATE_SENSITIVE;
6758 table_data->next_button->state&= ~STATE_SENSITIVE;
6761 if(table_data->top_row != w->children)
6763 table_data->prev_button->state|= STATE_SENSITIVE;
6767 table_data->prev_button->state&= ~STATE_SENSITIVE;
6769 gui_internal_widget_render(this,table_data->button_box);
6773 * Deallocate column descriptions.
6775 current_desc = column_desc;
6776 while( (current_desc = g_list_last(current_desc)) )
6778 current_desc = g_list_remove(current_desc,current_desc->data);
6784 * @brief Displays Route information
6786 * @li The name of the active vehicle
6787 * @param wm The button that was pressed.
6791 gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6795 struct widget * menu;
6796 struct widget * row;
6797 struct widget * box;
6800 if(! this->vehicle_cb)
6803 * Register the callback on vehicle updates.
6805 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
6806 attr_position_coord_geo,this);
6807 navit_add_callback(this->nav,this->vehicle_cb);
6810 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
6812 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
6815 menu=gui_internal_menu(this,_("Route Description"));
6817 menu->free=gui_internal_route_screen_free;
6818 this->route_data.route_showing=1;
6819 this->route_data.route_table->spx = this->spacing;
6822 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
6824 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
6825 gui_internal_widget_append(box,this->route_data.route_table);
6827 box->spx = this->spacing;
6828 this->route_data.route_table->w=box->w;
6829 gui_internal_widget_append(menu,box);
6830 gui_internal_populate_route_table(this,this->nav);
6831 gui_internal_menu_render(this);
6836 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
6839 int adx=a2->x-a1->x;
6840 int ady=a2->y-a1->y;
6841 int bdx=b2->x-b1->x;
6842 int bdy=b2->y-b1->y;
6843 n = bdy * adx - bdx * ady;
6844 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
6845 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
6856 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
6857 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
6858 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
6861 res->x = a1->x + a * adx / n;
6862 res->y = a1->y + a * ady / n;
6867 struct heightline *next;
6869 struct coord_rect bbox;
6874 struct diagram_point {
6875 struct diagram_point *next;
6879 static struct heightline *
6880 item_get_heightline(struct item *item)
6882 struct heightline *ret=NULL;
6883 struct street_data *sd;
6887 if (item_attr_get(item, attr_label, &attr)) {
6888 height=atoi(attr.u.str);
6889 sd=street_get_data(item);
6890 if (sd && sd->count > 1) {
6891 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
6892 ret->bbox.lu=sd->c[0];
6893 ret->bbox.rl=sd->c[0];
6894 ret->count=sd->count;
6896 for (i = 0 ; i < sd->count ; i++) {
6898 coord_rect_extend(&ret->bbox, sd->c+i);
6901 street_data_free(sd);
6908 * @brief Displays Route Height Profile
6910 * @li The name of the active vehicle
6911 * @param wm The button that was pressed.
6915 gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
6919 struct widget * menu, *box;
6921 struct map * map=NULL;
6922 struct map_rect * mr=NULL;
6923 struct route * route;
6924 struct item * item =NULL;
6926 struct mapset_handle *msh;
6927 int x,i,first=1,dist=0;
6928 struct coord c,last,res;
6929 struct coord_rect rbbox,dbbox;
6930 struct map_selection sel;
6931 struct heightline *heightline,*heightlines=NULL;
6932 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
6935 sel.range.min=type_height_line_1;
6936 sel.range.max=type_height_line_3;
6939 menu=gui_internal_menu(this,_("Height Profile"));
6940 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
6941 gui_internal_widget_append(menu, box);
6942 route = navit_get_route(this->nav);
6944 map = route_get_map(route);
6946 mr = map_rect_new(map,NULL);
6948 while((item = map_rect_get_item(mr))) {
6949 while (item_coord_get(item, &c, 1)) {
6955 coord_rect_extend(&sel.u.c_rect, &c);
6958 map_rect_destroy(mr);
6959 ms=navit_get_mapset(this->nav);
6961 msh=mapset_open(ms);
6962 while ((map=mapset_next(msh, 1))) {
6963 mr=map_rect_new(map, &sel);
6965 while((item = map_rect_get_item(mr))) {
6966 if (item->type >= sel.range.min && item->type <= sel.range.max) {
6967 heightline=item_get_heightline(item);
6969 heightline->next=heightlines;
6970 heightlines=heightline;
6974 map_rect_destroy(mr);
6983 map = route_get_map(route);
6985 mr = map_rect_new(map,NULL);
6986 if(mr && heightlines) {
6987 while((item = map_rect_get_item(mr))) {
6989 while (item_coord_get(item, &c, 1)) {
6993 heightline=heightlines;
6996 coord_rect_extend(&rbbox, &c);
6997 while (heightline) {
6998 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
6999 for (i = 0 ; i < heightline->count - 1; i++) {
7000 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
7001 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
7002 diagram_point=g_new(struct diagram_point, 1);
7003 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
7004 diagram_point->c.y=heightline->height;
7005 diagram_point->next=diagram_points;
7006 diagram_points=diagram_point;
7007 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
7012 heightline=heightline->next;
7014 dist+=transform_distance(projection_mg, &last, &c);
7020 map_rect_destroy(mr);
7024 gui_internal_menu_render(this);
7026 diagram_point=diagram_points;
7027 while (diagram_point) {
7029 dbbox.lu=diagram_point->c;
7030 dbbox.rl=diagram_point->c;
7033 coord_rect_extend(&dbbox, &diagram_point->c);
7034 diagram_point=diagram_point->next;
7036 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
7037 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
7039 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
7041 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
7047 diagram_point=diagram_points;
7048 while (diagram_point) {
7049 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
7051 diagram_point=diagram_point->next;
7055 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
7056 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
7057 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
7058 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
7062 graphics_draw_lines(this->gra, this->foreground, p, 2);
7071 gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7073 struct widget *menu,*wb,*w;
7076 graphics_draw_mode(this->gra, draw_mode_begin);
7077 menu=gui_internal_menu(this, _("Show Locale"));
7078 menu->spx=this->spacing*10;
7079 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
7080 gui_internal_widget_append(menu, wb);
7081 text=g_strdup_printf("LANG=%1$s (1=%3$s 2=%2$s)",getenv("LANG"),"2","1");
7082 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7083 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7085 #ifdef HAVE_API_WIN32_BASE
7087 char country[32],lang[32];
7088 #ifdef HAVE_API_WIN32_CE
7089 wchar_t wcountry[32],wlang[32];
7091 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
7092 WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
7094 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, lang, sizeof(lang));
7096 text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
7097 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7098 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7100 #ifdef HAVE_API_WIN32_CE
7101 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
7102 WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
7104 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, country, sizeof(country));
7106 text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
7107 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7108 w->flags=gravity_left_center|orientation_horizontal|flags_fill;
7113 gui_internal_menu_render(this);
7114 graphics_draw_mode(this->gra, draw_mode_end);
7118 gui_internal_cmd2_about(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
7120 struct widget *menu,*wb,*w;
7123 graphics_draw_mode(this->gra, draw_mode_begin);
7124 menu=gui_internal_menu(this, _("About Navit"));
7125 menu->spx=this->spacing*10;
7126 wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand);
7127 gui_internal_widget_append(menu, wb);
7130 gui_internal_widget_append(wb, w=gui_internal_image_new(this, image_new_xs(this, "navit")));
7131 w->flags=gravity_top_center|orientation_horizontal|flags_fill;
7134 text=g_strdup_printf("%s",PACKAGE_NAME);
7135 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7136 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7140 text=g_strdup_printf("%s",version);
7141 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7142 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7146 text=g_strdup_printf("http://www.navit-project.org/");
7147 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7148 w->flags=gravity_top_center|orientation_horizontal|flags_expand;
7152 text=g_strdup_printf("%s:",_("By"));
7153 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7154 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7156 text=g_strdup_printf("Martin Schaller");
7157 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7158 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7160 text=g_strdup_printf("Michael Farmbauer");
7161 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7162 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7164 text=g_strdup_printf("Alexander Atanasov");
7165 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7166 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7168 text=g_strdup_printf("Pierre Grandin");
7169 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7170 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7174 text=g_strdup_printf("%s",_("And all the Navit Team"));
7175 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7176 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7178 text=g_strdup_printf("%s",_("members and contributors."));
7179 gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
7180 w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
7183 gui_internal_menu_render(this);
7184 graphics_draw_mode(this->gra, draw_mode_end);
7188 * @brief handles the 'next page' table event.
7189 * A callback function that is invoked when the 'next page' button is pressed
7190 * to advance the contents of a table widget.
7192 * @param this The graphics context.
7193 * @param wm The button widget that was pressed.
7195 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
7197 struct widget * table_widget = (struct widget * ) wm->data;
7198 struct table_data * table_data = NULL;
7204 table_data = (struct table_data*) table_widget->data;
7210 * Before advancing to the next page we need to ensure
7211 * that the current top_row is in the list of previous top_rows
7212 * so previous page can work.
7215 for(iterator=table_data->page_headers; iterator != NULL;
7216 iterator = g_list_next(iterator) )
7218 if(iterator->data == table_data->top_row)
7227 table_data->page_headers=g_list_append(table_data->page_headers,
7228 table_data->top_row);
7231 * Invalidate row coordinates for all rows which were previously rendered
7233 for(iterator=table_data->top_row; iterator && table_data->rows_on_page; iterator = g_list_next(iterator))
7235 struct widget * cur_row_widget = (struct widget*)iterator->data;
7236 cur_row_widget->p.x=-1;
7237 cur_row_widget->p.y=-1;
7238 cur_row_widget->w=0;
7239 cur_row_widget->h=0;
7240 table_data->rows_on_page--;
7243 gui_internal_table_hide_rows(table_data);
7244 table_data->top_row=g_list_next(table_data->bottom_row);
7246 wm->state&= ~STATE_HIGHLIGHTED;
7247 gui_internal_menu_render(this);
7253 * @brief handles the 'previous page' table event.
7254 * A callback function that is invoked when the 'previous page' button is pressed
7255 * to go back in the contents of a table widget.
7257 * @param this The graphics context.
7258 * @param wm The button widget that was pressed.
7260 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
7262 struct widget * table_widget = (struct widget * ) wm->data;
7263 struct table_data * table_data = NULL;
7264 GList * current_page_top=NULL;
7269 table_data = (struct table_data*) table_widget->data;
7272 gui_internal_table_hide_rows(table_data);
7273 current_page_top = table_data->top_row;
7274 for(iterator = table_data->page_headers; iterator != NULL;
7275 iterator = g_list_next(iterator))
7277 if(current_page_top == iterator->data)
7281 table_data->top_row = (GList*) iterator->data;
7285 wm->state&= ~STATE_HIGHLIGHTED;
7286 gui_internal_menu_render(this);
7291 * @brief deallocates a table_data structure.
7294 void gui_internal_table_data_free(void * p)
7299 * @note button_box and its children (next_button,prev_button)
7300 * have their memory managed by the table itself.
7302 struct table_data * table_data = (struct table_data*) p;
7303 g_list_free(table_data->page_headers);
7311 * @brief Called when the route is updated.
7313 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
7316 if(this->route_data.route_showing) {
7317 gui_internal_populate_route_table(this,navit);
7318 graphics_draw_mode(this->gra, draw_mode_begin);
7319 gui_internal_menu_render(this);
7320 graphics_draw_mode(this->gra, draw_mode_end);
7328 * @brief Called when the route screen is closed (deallocated).
7330 * The main purpose of this function is to remove the widgets from
7331 * references route_data because those widgets are about to be freed.
7333 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
7336 this_->route_data.route_showing=0;
7337 this_->route_data.route_table=NULL;
7344 * @brief Populates the route table with route information
7346 * @param this The gui context
7347 * @param navit The navit object
7349 void gui_internal_populate_route_table(struct gui_priv * this,
7350 struct navit * navit)
7352 struct map * map=NULL;
7353 struct map_rect * mr=NULL;
7354 struct navigation * nav = NULL;
7355 struct item * item =NULL;
7357 struct widget * label = NULL;
7358 struct widget * row = NULL;
7360 nav = navit_get_navigation(navit);
7364 map = navigation_get_map(nav);
7366 mr = map_rect_new(map,NULL);
7368 gui_internal_widget_table_clear(this,this->route_data.route_table);
7369 while((item = map_rect_get_item(mr))) {
7370 if(item_attr_get(item,attr_navigation_long,&attr)) {
7371 row = gui_internal_widget_table_row_new(this,
7374 | orientation_horizontal);
7375 gui_internal_widget_append(this->route_data.route_table,row);
7377 label = gui_internal_label_new(this,attr.u.str);
7378 gui_internal_widget_append(row,label);
7381 item_coord_get(item, &c, 1);
7384 label->c.pro=map_projection(map);
7385 label->func=gui_internal_cmd_position;
7386 label->state|=STATE_SENSITIVE;
7387 label->data=(void*)2;
7395 static struct command_table commands[] = {
7396 {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
7397 {"back",command_cast(gui_internal_cmd2_back)},
7398 {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
7399 {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
7400 {"formerdests",command_cast(gui_internal_cmd_formerdests)},
7401 {"get_data",command_cast(gui_internal_get_data)},
7402 {"locale",command_cast(gui_internal_cmd2_locale)},
7403 {"log",command_cast(gui_internal_cmd_log)},
7404 {"menu",command_cast(gui_internal_cmd_menu2)},
7405 {"position",command_cast(gui_internal_cmd2_position)},
7406 {"pois",command_cast(gui_internal_cmd2_pois)},
7407 {"route_description",command_cast(gui_internal_cmd2_route_description)},
7408 {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
7409 {"set",command_cast(gui_internal_cmd2_set)},
7410 {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
7411 {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
7412 {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
7413 {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
7414 {"town",command_cast(gui_internal_cmd2_town)},
7415 {"quit",command_cast(gui_internal_cmd2_quit)},
7416 {"write",command_cast(gui_internal_cmd_write)},
7417 {"about",command_cast(gui_internal_cmd2_about)},
7422 //##############################################################################################################
7425 //# Authors: Martin Schaller (04/2008)
7426 //##############################################################################################################
7427 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
7429 struct color color_white={0xffff,0xffff,0xffff,0xffff};
7430 struct color color_black={0x0,0x0,0x0,0xffff};
7431 struct color back2_color={0x4141,0x4141,0x4141,0xffff};
7433 struct gui_priv *this;
7435 *meth=gui_internal_methods;
7436 this=g_new0(struct gui_priv, 1);
7439 this->self.type=attr_gui;
7440 this->self.u.gui=gui;
7442 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
7443 this->menu_on_map_click=attr->u.num;
7445 this->menu_on_map_click=1;
7446 if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
7447 this->signal_on_map_click=attr->u.num;
7449 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
7450 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
7453 if( (attr=attr_search(attrs,NULL,attr_font_size)))
7455 this->config.font_size=attr->u.num;
7459 this->config.font_size=-1;
7461 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
7463 this->config.icon_xs=attr->u.num;
7467 this->config.icon_xs=-1;
7469 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
7471 this->config.icon_l=attr->u.num;
7475 this->config.icon_l=-1;
7477 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
7479 this->config.icon_s=attr->u.num;
7483 this->config.icon_s=-1;
7485 if( (attr=attr_search(attrs,NULL,attr_spacing)))
7487 this->config.spacing=attr->u.num;
7491 this->config.spacing=-1;
7493 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
7495 this->speech=attr->u.num;
7497 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
7498 this->keyboard=attr->u.num;
7502 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
7503 this->fullscreen=attr->u.num;
7505 if( (attr=attr_search(attrs,NULL,attr_flags)))
7506 this->flags=attr->u.num;
7507 if( (attr=attr_search(attrs,NULL,attr_background_color)))
7508 this->background_color=*attr->u.color;
7510 this->background_color=color_black;
7511 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
7512 this->background2_color=*attr->u.color;
7514 this->background2_color=back2_color;
7515 if( (attr=attr_search(attrs,NULL,attr_text_color)))
7516 this->text_foreground_color=*attr->u.color;
7518 this->text_foreground_color=color_white;
7519 this->text_background_color=color_black;
7520 if( (attr=attr_search(attrs,NULL,attr_columns)))
7521 this->cols=attr->u.num;
7522 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
7523 this->osd_configuration=*attr;
7525 if( (attr=attr_search(attrs,NULL,attr_pitch)))
7526 this->pitch=attr->u.num;
7529 if( (attr=attr_search(attrs,NULL,attr_flags_town)))
7530 this->flags_town=attr->u.num;
7532 this->flags_town=-1;
7533 if( (attr=attr_search(attrs,NULL,attr_flags_street)))
7534 this->flags_street=attr->u.num;
7536 this->flags_street=-1;
7537 if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
7538 this->flags_house_number=attr->u.num;
7540 this->flags_house_number=-1;
7541 if( (attr=attr_search(attrs,NULL,attr_radius)))
7542 this->radius=attr->u.num;
7545 this->data.priv=this;
7546 this->data.gui=&gui_internal_methods_ext;
7547 this->data.widget=&gui_internal_widget_methods;
7548 this->cbl=callback_list_new();
7553 //##############################################################################################################
7556 //# Authors: Martin Schaller (04/2008)
7557 //##############################################################################################################
7558 void plugin_init(void)
7560 plugin_register_gui_type("internal", gui_internal_new);
7564 gui_internal_destroy(struct gui_priv *this)
7566 g_free(this->country_iso2);
7568 g_free(this->html_text);