2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 //##############################################################################################################
22 //# File: gui_internal.c
23 //# Description: New "internal" GUI for use with any graphics library
24 //# Comment: Trying to make a touchscreen friendly GUI
25 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
27 //##############################################################################################################
40 #include "navit_nls.h"
47 #include "transform.h"
53 #include "vehicleprofile.h"
64 #include "navit_nls.h"
65 #include "navigation.h"
66 #include "gui_internal.h"
71 struct widget *search_list;
72 struct widget *keyboard;
73 struct widget *button_bar;
75 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
76 struct widget *redisplay_widget;
79 //##############################################################################################################
82 //# Authors: Martin Schaller (04/2008)
83 //##############################################################################################################
85 enum widget_type type;
86 struct graphics_gc *background,*text_background;
87 struct graphics_gc *foreground_frame;
88 struct graphics_gc *foreground;
90 struct graphics_image *img;
92 * A function to be invoked on actions.
93 * @li widget The widget that is receiving the button press.
96 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
101 * @brief A function to deallocate data
103 void (*data_free)(void *data);
106 * @brief a function that will be called as the widget is being destroyed.
107 * This function can act as a destructor for the widget. It allows for
108 * on deallocation actions to be specified on a per widget basis.
109 * This function will call g_free on the widget (if required).
111 void (*free) (struct gui_priv *this_, struct widget * w);
123 int bl,br,bt,bb,spx,spy;
126 * The number of widgets to layout horizontally when doing
127 * a orientation_horizontal_vertical layout
132 int (*set_attr)(void *, struct attr *);
133 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
134 void (*remove_cb)(void *, struct callback *cb);
141 struct menu_data *menu_data;
146 * @brief A structure to store configuration values.
148 * This structure stores configuration values for how gui elements in the internal GUI
151 struct gui_config_settings {
154 * The base size (in fractions of a point) to use for text.
158 * The size (in pixels) that xs style icons should be scaled to.
162 * The size (in pixels) that s style icons (small) should be scaled to
166 * The size (in pixels) that l style icons should be scaled to
170 * The default amount of spacing (in pixels) to place between GUI elements.
177 * Indexes into the config_profiles array.
179 const int LARGE_PROFILE=0;
180 const int MEDIUM_PROFILE=1;
181 const int SMALL_PROFILE=2;
184 * The default config profiles.
186 * [0] => LARGE_PROFILE (screens 640 in one dimension)
187 * [1] => MEDIUM PROFILE (screens larger than 320 in one dimension
188 * [2] => Small profile (default)
190 static struct gui_config_settings config_profiles[]={
197 struct widget * route_table;
202 //##############################################################################################################
205 //# Authors: Martin Schaller (04/2008)
206 //##############################################################################################################
210 struct graphics *gra;
211 struct graphics_gc *background;
212 struct graphics_gc *background2;
213 struct graphics_gc *highlight_background;
214 struct graphics_gc *foreground;
215 struct graphics_gc *text_foreground;
216 struct graphics_gc *text_background;
217 struct color background_color, background2_color, text_foreground_color, text_background_color;
221 struct graphics_font *font;
222 int icon_xs, icon_s, icon_l;
224 struct widget *widgets;
228 struct widget *highlighted;
229 struct widget *highlighted_menu;
230 int clickp_valid, vehicle_valid;
231 struct pcoord clickp, vehiclep;
232 struct search_list *sl;
234 int menu_on_map_click;
239 * The setting information read from the configuration file.
240 * values of -1 indicate no value was specified in the config file.
242 struct gui_config_settings config;
243 struct event_idle *idle;
244 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*idle_cb, *motion_timeout_callback;
245 struct event_timeout *motion_timeout_event;
246 struct point current;
248 struct callback * vehicle_cb;
250 * Stores information about the route.
252 struct route_data route_data;
254 struct gui_internal_data data;
255 struct callback_list *cbl;
258 struct attr osd_configuration;
264 * @brief A structure to store information about a table.
266 * The table_data widget stores pointers to extra information needed by the
269 * The table_data structure needs to be freed with data_free along with the widget.
275 * A GList pointer into a widget->children list that indicates the row
276 * currently being rendered at the top of the table.
280 * A Glist pointer into a widget->children list that indicates the row
281 * currently being rendered at the bottom of the table.
286 * A list of table_row widgets that mark the
287 * top rows for each page of the table.
288 * This is needed for the 'previous page' function of the table.
290 GList * page_headers;
293 * A container box that is the child of the table widget that contains+groups
294 * the next and previous button.
296 struct widget * button_box;
299 * A button widget to handle 'next page' requests
301 struct widget * next_button;
303 * A button widget to handle 'previous page' requests.
305 struct widget * prev_button;
309 * a pointer to the gui context.
310 * This is needed by the free function to destory the buttons.
312 struct gui_priv * this;
316 * A data structure that holds information about a column that makes up a table.
320 struct table_column_desc
324 * The computed height of a cell in the table.
329 * The computed width of a cell in the table.
335 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
336 static void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
337 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
338 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
339 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
340 static void gui_internal_apply_config(struct gui_priv *this);
342 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
343 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
344 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
345 static void gui_internal_cmd_route(struct gui_priv * this, struct widget * w,void *);
346 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
347 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
348 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
349 static void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table);
350 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
351 static void gui_internal_table_data_free(void * d);
352 static void gui_internal_route_update(struct gui_priv * this, struct navit * navit,
354 static void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w);
355 static void gui_internal_populate_route_table(struct gui_priv * this,
356 struct navit * navit);
357 static void gui_internal_search_idle_end(struct gui_priv *this);
358 static void gui_internal_search(struct gui_priv *this, char *what, char *type, int flags);
359 static void gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data);
360 static void gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data);
361 static void gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data);
362 static void gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data);
363 static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data);
364 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
365 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
366 static void gui_internal_check_exit(struct gui_priv *this);
368 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
369 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
371 static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
374 * * Display image scaled to specific size
375 * * searches for scaleable and pre-scaled image
376 * * @param this Our gui context
377 * * @param name image name
378 * * @param w desired width of image
379 * * @param h desired height of image
380 * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
382 static struct graphics_image *
383 image_new_scaled(struct gui_priv *this, char *name, int w, int h)
385 struct graphics_image *ret=NULL;
386 char *full_name=NULL;
387 char *full_path=NULL;
390 for (i = 1 ; i < 6 ; i++) {
394 full_name=g_strdup_printf("%s.svg", name);
397 full_name=g_strdup_printf("%s.svgz", name);
400 if (w != -1 && h != -1) {
401 full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
405 full_name=g_strdup_printf("%s.png", name);
408 full_name=g_strdup_printf("%s.xpm", name);
411 dbg(1,"trying '%s'\n", full_name);
415 /* needs to be checked in the driver */
416 if (!file_exists(full_name)) {
421 full_path=graphics_icon_path(full_name);
422 ret=graphics_image_new_scaled(this->gra, full_path, w, h);
423 dbg(1,"ret=%p\n", ret);
429 dbg(0,"failed to load %s with %d,%d\n", name, w, h);
434 static struct graphics_image *
435 image_new_o(struct gui_priv *this, char *name)
437 return image_new_scaled(this, name, -1, -1);
441 static struct graphics_image *
442 image_new_xs(struct gui_priv *this, char *name)
444 return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
448 static struct graphics_image *
449 image_new_s(struct gui_priv *this, char *name)
451 return image_new_scaled(this, name, this->icon_s, this->icon_s);
454 static struct graphics_image *
455 image_new_l(struct gui_priv *this, char *name)
457 return image_new_scaled(this, name, this->icon_l, this->icon_l);
461 coordinates(struct pcoord *pc, char sep)
463 char latc='N',lngc='E';
464 int lat_deg,lat_min,lat_sec;
465 int lng_deg,lng_min,lng_sec;
470 transform_to_geo(pc->pro, &c, &g);
481 lat_min=fmod(g.lat*60,60);
482 lat_sec=fmod(g.lat*3600,60);
484 lng_min=fmod(g.lng*60,60);
485 lng_sec=fmod(g.lng*3600,60);
486 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);
490 gui_internal_background_render(struct gui_priv *this, struct widget *w)
492 struct point pnt=w->p;
493 if (w->state & STATE_HIGHLIGHTED)
494 graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
497 graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
500 static struct widget *
501 gui_internal_label_new(struct gui_priv *this, char *text)
507 struct widget *widget=g_new0(struct widget, 1);
508 widget->type=widget_label;
510 widget->text=g_strdup(text);
511 graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
515 widget->h=h+this->spacing;
517 widget->w=w+this->spacing;
519 widget->flags=gravity_center;
520 widget->foreground=this->text_foreground;
521 widget->text_background=this->text_background;
526 static struct widget *
527 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
529 struct widget *ret=NULL;
530 char *tmp=g_malloc(strlen(text)+3);
537 ret=gui_internal_label_new(this, tmp);
538 if (ret->w < maxwidth)
540 gui_internal_widget_destroy(this, ret);
548 static struct widget *
549 gui_internal_image_new(struct gui_priv *this, struct graphics_image *image)
551 struct widget *widget=g_new0(struct widget, 1);
552 widget->type=widget_image;
555 widget->w=image->width;
556 widget->h=image->height;
562 gui_internal_image_render(struct gui_priv *this, struct widget *w)
566 gui_internal_background_render(this, w);
569 pnt.x+=w->w/2-w->img->hot.x;
570 pnt.y+=w->h/2-w->img->hot.y;
571 graphics_draw_image(this->gra, this->foreground, &pnt, w->img);
576 gui_internal_label_render(struct gui_priv *this, struct widget *w)
578 struct point pnt=w->p;
579 gui_internal_background_render(this, w);
581 if (w->flags & gravity_right) {
582 pnt.y+=w->h-this->spacing;
583 pnt.x+=w->w-w->textw-this->spacing;
584 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
586 pnt.y+=w->h-this->spacing;
587 graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
593 * @brief A text box is a widget that renders a text string containing newlines.
594 * The string will be broken up into label widgets at each newline with a vertical layout.
597 static struct widget *
598 gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
600 char *s=g_strdup(text),*s2,*tok;
601 struct widget *ret=gui_internal_box_new(this, flags);
603 while ((tok=strtok(s2,"\n"))) {
604 gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
607 gui_internal_widget_pack(this,ret);
612 static struct widget *
613 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)
615 struct widget *ret=NULL;
616 ret=gui_internal_box_new(this, flags);
619 gui_internal_widget_append(ret, gui_internal_image_new(this, image));
621 gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
625 ret->state |= STATE_SENSITIVE;
626 ret->speech=g_strdup(text);
634 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
641 if (w->get_attr(w->instance, w->on.type, &curr, NULL))
642 is_on=curr.u.data == w->on.u.data;
645 if (is_on != w->is_on) {
649 l=g_list_first(w->children);
653 graphics_image_free(this->gra, wi->img);
654 wi->img=image_new_xs(this, is_on ? "gui_active" : "gui_inactive");
656 if (w->is_on && w->off.type == attr_none)
657 w->state &= ~STATE_SENSITIVE;
659 w->state |= STATE_SENSITIVE;
666 gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
668 if (gui_internal_button_attr_update(this, w))
669 gui_internal_widget_render(this, w);
672 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
675 w->set_attr(w->instance, &w->off);
677 w->set_attr(w->instance, &w->on);
678 gui_internal_button_attr_update(this, w);
682 static struct widget *
683 gui_internal_button_navit_attr_new(struct gui_priv *this, char *text, enum flags flags, struct attr *on, struct attr *off)
685 struct graphics_image *image=NULL;
689 image=image_new_xs(this, "gui_inactive");
690 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
695 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))navit_get_attr;
696 ret->set_attr=(int (*)(void *, struct attr *))navit_set_attr;
697 ret->remove_cb=(void (*)(void *, struct callback *))navit_remove_callback;
698 ret->instance=this->nav;
699 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
700 navit_add_callback(this->nav, ret->cb);
701 gui_internal_button_attr_update(this, ret);
705 static struct widget *
706 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)
708 struct graphics_image *image=NULL;
710 image=image_new_xs(this, "gui_inactive");
713 ret=gui_internal_button_new_with_callback(this, text, image, flags, gui_internal_button_attr_pressed, NULL);
719 ret->get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr;
720 ret->set_attr=(int (*)(void *, struct attr *))map_set_attr;
721 ret->remove_cb=(void (*)(void *, struct callback *))map_remove_callback;
724 ret->cb=callback_new_attr_2(callback_cast(gui_internal_button_attr_callback), on?on->type:off->type, this, ret);
725 map_add_callback(map, ret->cb);
726 gui_internal_button_attr_update(this, ret);
730 static struct widget *
731 gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image *image, enum flags flags)
733 return gui_internal_button_new_with_callback(this, text, image, flags, NULL, NULL);
737 //##############################################################################################################
740 //# Authors: Martin Schaller (04/2008)
741 //##############################################################################################################
742 static void gui_internal_clear(struct gui_priv *this)
744 struct graphics *gra=this->gra;
748 graphics_draw_rectangle(gra, this->background, &pnt, this->root.w, this->root.h);
752 static struct widget *
753 gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
755 struct widget *ret,*child;
756 GList *l=wi->children;
763 if ( wi->p.x + wi->w < p->x)
765 if ( wi->p.y + wi->h < p->y)
768 if (wi->state & flags)
772 ret=gui_internal_find_widget(child, p, flags);
783 gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
785 if (found == this->highlighted)
788 graphics_draw_mode(this->gra, draw_mode_begin);
789 if (this->highlighted) {
790 this->highlighted->state &= ~STATE_HIGHLIGHTED;
791 if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
792 gui_internal_widget_render(this, this->highlighted);
793 this->highlighted=NULL;
794 this->highlighted_menu=NULL;
797 this->highlighted=found;
798 this->highlighted_menu=g_list_last(this->root.children)->data;
799 this->highlighted->state |= STATE_HIGHLIGHTED;
800 gui_internal_widget_render(this, this->highlighted);
801 dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
803 graphics_draw_mode(this->gra, draw_mode_end);
805 //##############################################################################################################
808 //# Authors: Martin Schaller (04/2008)
809 //##############################################################################################################
810 static void gui_internal_highlight(struct gui_priv *this)
812 struct widget *menu,*found=NULL;
813 if (this->current.x > -1 && this->current.y > -1) {
814 menu=g_list_last(this->root.children)->data;
815 found=gui_internal_find_widget(menu, &this->current, STATE_SENSITIVE);
817 gui_internal_highlight_do(this, found);
818 this->motion_timeout_event=NULL;
821 static struct widget *
822 gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, char *label)
824 struct widget *widget=g_new0(struct widget, 1);
827 widget->text=g_strdup(label);
828 widget->type=widget_box;
833 static struct widget *
834 gui_internal_box_new(struct gui_priv *this, enum flags flags)
836 return gui_internal_box_new_with_label(this, flags, NULL);
840 static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
845 gui_internal_background_render(this, w);
847 if (w->foreground && w->border) {
850 pnt[1].x=pnt[0].x+w->w;
852 pnt[2].x=pnt[0].x+w->w;
853 pnt[2].y=pnt[0].y+w->h;
855 pnt[3].y=pnt[0].y+w->h;
857 graphics_gc_set_linewidth(w->foreground, w->border ? w->border : 1);
858 graphics_draw_lines(this->gra, w->foreground, pnt, 5);
859 graphics_gc_set_linewidth(w->foreground, 1);
866 gui_internal_widget_render(this, wc);
873 * @brief Compute the size and location for the widget.
877 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
880 int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,count=0,rows=0,cols=w->cols ? w->cols : 0;
882 int orientation=w->flags & 0xffff0000;
887 if ( this->root.w > this->root.h )
897 * count the number of children
904 if (orientation == orientation_horizontal_vertical && count <= cols)
905 orientation=orientation_horizontal;
906 switch (orientation) {
907 case orientation_horizontal:
909 * For horizontal orientation:
910 * pack each child and find the largest height and
911 * compute the total width. x spacing (spx) is considered
913 * If any children want to be expanded
914 * we keep track of this
919 gui_internal_widget_pack(this, wc);
923 if (wc->flags & flags_expand)
924 expand+=wc->w ? wc->w : 1;
930 if (expand && w->w) {
931 expand=100*(w->w-width+expand)/expand;
936 case orientation_vertical:
938 * For vertical layouts:
939 * We pack each child and compute the largest width and
940 * the total height. y spacing (spy) is considered
942 * If the expand flag is set then teh expansion amount
948 gui_internal_widget_pack(this, wc);
952 if (wc->flags & flags_expand)
953 expand+=wc->h ? wc->h : 1;
959 if (expand && w->h) {
960 expand=100*(w->h-height+expand)/expand;
965 case orientation_horizontal_vertical:
967 * For horizontal_vertical orientation
969 * Compute the largest height and largest width.
970 * Layout the widgets based on having the
971 * number of columns specified by (cols)
977 gui_internal_widget_pack(this, wc);
987 rows=(count+cols-1)/cols;
990 width+=w->spx*(cols-1);
991 height+=w->spy*(rows-1);
998 * No orientation was specified.
999 * width and height are both 0.
1000 * The width & height of this widget
1004 dbg(0,"Warning width and height of a widget are 0");
1007 if (! w->w && ! w->h) {
1008 w->w=w->bl+w->br+width;
1009 w->h=w->bt+w->bb+height;
1013 * At this stage the width and height of this
1014 * widget has been computed.
1015 * We now make a second pass assigning heights,
1016 * widths and coordinates to each child widget.
1019 if (w->flags & gravity_left)
1021 if (w->flags & gravity_xcenter)
1022 x=w->p.x+w->w/2-owidth/2;
1023 if (w->flags & gravity_right)
1024 x=w->p.x+w->w-w->br-owidth;
1025 if (w->flags & gravity_top)
1027 if (w->flags & gravity_ycenter)
1028 y=w->p.y+w->h/2-oheight/2;
1029 if (w->flags & gravity_bottom)
1030 y=w->p.y+w->h-w->bb-oheight;
1032 switch (orientation) {
1033 case orientation_horizontal:
1038 if (wc->flags & flags_fill)
1040 if (wc->flags & flags_expand) {
1043 wc->w=wc->w*expand/100;
1045 if (w->flags & gravity_top)
1047 if (w->flags & gravity_ycenter)
1049 if (w->flags & gravity_bottom)
1055 case orientation_vertical:
1060 if (wc->flags & flags_fill)
1062 if (wc->flags & flags_expand) {
1065 wc->h=wc->h*expand/100;
1067 if (w->flags & gravity_left)
1069 if (w->flags & gravity_xcenter)
1071 if (w->flags & gravity_right)
1077 case orientation_horizontal_vertical:
1087 if (wc->flags & flags_fill) {
1091 if (w->flags & gravity_left)
1093 if (w->flags & gravity_xcenter)
1094 wc->p.x=x+(width-wc->w)/2;
1095 if (w->flags & gravity_right)
1096 wc->p.x=x+width-wc->w;
1097 if (w->flags & gravity_top)
1099 if (w->flags & gravity_ycenter)
1100 wc->p.y=y+(height-wc->h)/2;
1101 if (w->flags & gravity_bottom)
1102 wc->p.y=y-height-wc->h;
1104 if (++count == cols) {
1116 * Call pack again on each child,
1117 * the child has now had its size and coordinates
1118 * set so they can repack their children.
1123 gui_internal_widget_pack(this, wc);
1129 gui_internal_widget_append(struct widget *parent, struct widget *child)
1133 if (! child->background)
1134 child->background=parent->background;
1135 parent->children=g_list_append(parent->children, child);
1138 static void gui_internal_widget_prepend(struct widget *parent, struct widget *child)
1140 if (! child->background)
1141 child->background=parent->background;
1142 parent->children=g_list_prepend(parent->children, child);
1145 static void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w)
1153 gui_internal_widget_destroy(this, wc);
1156 g_list_free(w->children);
1160 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
1162 gui_internal_widget_children_destroy(this, w);
1166 graphics_image_free(this->gra, w->img);
1172 w->data_free(w->data);
1173 if (w->cb && w->remove_cb)
1174 w->remove_cb(w->instance, w->cb);
1183 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
1185 if(w->p.x > this->root.w || w->p.y > this->root.h)
1190 gui_internal_box_render(this, w);
1193 gui_internal_label_render(this, w);
1196 gui_internal_image_render(this, w);
1199 gui_internal_table_render(this,w);
1207 gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
1211 gui_internal_box_pack(this, w);
1214 gui_internal_table_pack(this,w);
1220 //##############################################################################################################
1223 //# Authors: Martin Schaller (04/2008)
1224 //##############################################################################################################
1225 static void gui_internal_call_highlighted(struct gui_priv *this)
1227 if (! this->highlighted || ! this->highlighted->func)
1229 this->highlighted->reason=1;
1230 this->highlighted->func(this, this->highlighted, this->highlighted->data);
1234 gui_internal_say(struct gui_priv *this, struct widget *w, int questionmark)
1236 char *text=w->speech;
1244 text=g_strdup_printf("%s%c", text, questionmark ? '?':'\0');
1245 navit_say(this->nav, text);
1251 gui_internal_prune_menu(struct gui_priv *this, struct widget *w)
1255 gui_internal_search_idle_end(this);
1256 while ((l = g_list_last(this->root.children))) {
1258 void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
1259 gui_internal_say(this, w, 0);
1260 redisplay=w->menu_data->redisplay;
1261 wr=w->menu_data->redisplay_widget;
1262 if (!w->menu_data->redisplay) {
1263 gui_internal_widget_render(this, w);
1266 gui_internal_widget_destroy(this, l->data);
1267 this->root.children=g_list_remove(this->root.children, l->data);
1268 redisplay(this, wr, wr->data);
1271 gui_internal_widget_destroy(this, l->data);
1272 this->root.children=g_list_remove(this->root.children, l->data);
1277 gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
1280 gui_internal_search_idle_end(this);
1281 while ((l = g_list_last(this->root.children)) && count-- > 0) {
1282 gui_internal_widget_destroy(this, l->data);
1283 this->root.children=g_list_remove(this->root.children, l->data);
1286 gui_internal_say(this, l->data, 0);
1287 gui_internal_widget_render(this, l->data);
1292 gui_internal_back(struct gui_priv *this, struct widget *w, void *data)
1294 gui_internal_prune_menu_count(this, 1, 1);
1298 gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
1300 gui_internal_prune_menu(this, wm->data);
1304 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
1306 gui_internal_prune_menu(this, this->root.children->data);
1309 static struct widget *
1310 gui_internal_top_bar(struct gui_priv *this)
1312 struct widget *w,*wm,*wh,*wc,*wcn;
1313 int dots_len, sep_len;
1315 int width,width_used=0,use_sep=0,incomplete=0;
1316 struct graphics_gc *foreground=(this->flags & 256 ? this->background : this->text_foreground);
1318 1:Don't expand bar to screen width
1319 2:Don't show Map Icon
1320 4:Don't show Home Icon
1321 8:Show only current menu
1322 16:Don't use menu titles as button
1323 32:Show navit version
1326 256:Use background for menu headline
1327 512:Set osd_configuration and zoom to route when setting position
1330 w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
1331 w->bl=this->spacing;
1332 w->spx=this->spacing;
1333 w->background=this->background2;
1334 if ((this->flags & 6) == 6) {
1340 width=this->root.w-w->bl;
1341 if (! (this->flags & 2)) {
1342 wm=gui_internal_button_new_with_callback(this, NULL,
1343 image_new_s(this, "gui_map"), gravity_center|orientation_vertical,
1344 gui_internal_cmd_return, NULL);
1345 wm->speech=g_strdup(_("Back to map"));
1346 gui_internal_widget_pack(this, wm);
1347 gui_internal_widget_append(w, wm);
1350 if (! (this->flags & 4)) {
1351 wh=gui_internal_button_new_with_callback(this, NULL,
1352 image_new_s(this, "gui_home"), gravity_center|orientation_vertical,
1353 gui_internal_cmd_main_menu, NULL);
1354 wh->speech=g_strdup(_("Main Menu"));
1355 gui_internal_widget_pack(this, wh);
1356 gui_internal_widget_append(w, wh);
1359 if (!(this->flags & 6))
1361 l=g_list_last(this->root.children);
1362 wcn=gui_internal_label_new(this,".. »");
1363 wcn->foreground=foreground;
1365 gui_internal_widget_destroy(this, wcn);
1366 wcn=gui_internal_label_new(this,"»");
1367 wcn->foreground=foreground;
1369 gui_internal_widget_destroy(this, wcn);
1371 if (g_list_previous(l) || !g_list_next(l)) {
1373 wcn=gui_internal_label_new(this, wc->text);
1374 wcn->foreground=foreground;
1379 dbg(1,"%d (%s) + %d + %d + %d > %d\n", wcn->w, wc->text, width_used, w->spx, use_sep ? sep_len : 0, width);
1380 if (wcn->w + width_used + w->spx + (use_sep ? sep_len : 0) + (g_list_previous(l) ? dots_len : 0) > width) {
1382 gui_internal_widget_destroy(this, wcn);
1386 struct widget *wct=gui_internal_label_new(this, "»");
1387 wct->foreground=foreground;
1388 res=g_list_prepend(res, wct);
1389 width_used+=sep_len+w->spx;
1392 if (!(this->flags & 16)) {
1393 wcn->func=gui_internal_cmd_return;
1395 wcn->state |= STATE_SENSITIVE;
1397 res=g_list_prepend(res, wcn);
1398 if (this->flags & 8)
1401 l=g_list_previous(l);
1405 wcn=gui_internal_label_new_abbrev(this, wc->text, width-width_used-w->spx-dots_len);
1406 wcn->foreground=foreground;
1407 wcn->func=gui_internal_cmd_return;
1409 wcn->state |= STATE_SENSITIVE;
1410 res=g_list_prepend(res, wcn);
1411 l=g_list_previous(l);
1414 wcn=gui_internal_label_new(this, ".. »");
1415 wcn->foreground=foreground;
1416 wcn->func=gui_internal_cmd_return;
1418 wcn->state |= STATE_SENSITIVE;
1419 res=g_list_prepend(res, wcn);
1423 gui_internal_widget_append(w, l->data);
1426 if (this->flags & 32) {
1427 extern char *version;
1428 char *version_text=g_strdup_printf("Navit %s",version);
1429 wcn=gui_internal_label_new(this, version_text);
1430 g_free(version_text);
1431 wcn->flags=gravity_right_center|flags_expand;
1432 gui_internal_widget_append(w, wcn);
1436 gui_internal_widget_destroy(this, dots);
1441 static struct widget *
1442 gui_internal_time_help(struct gui_priv *this)
1444 struct widget *w,*wc,*wcn;
1449 w=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1450 w->bl=this->spacing;
1451 w->spx=this->spacing;
1457 if (this->flags & 64) {
1458 wc=gui_internal_box_new(this, gravity_right_top|orientation_vertical|flags_fill);
1464 tm=localtime(&timep);
1465 strftime(timestr, 64, "%H:%M %d.%m.%Y", tm);
1466 wcn=gui_internal_label_new(this, timestr);
1467 gui_internal_widget_append(wc, wcn);
1468 gui_internal_widget_append(w, wc);
1470 if (this->flags & 128) {
1471 wcn=gui_internal_button_new_with_callback(this, _("Help"), image_new_l(this, "gui_help"), gravity_center|orientation_vertical|flags_fill, NULL, NULL);
1472 gui_internal_widget_append(w, wcn);
1479 * Applys the configuration values to this based on the settings
1480 * specified in the configuration file (this->config) and
1481 * the most approriate default profile based on screen resolution.
1483 * This function should be run after this->root is setup and could
1484 * be rerun after the window is resized.
1486 * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
1488 static void gui_internal_apply_config(struct gui_priv *this)
1490 struct gui_config_settings * current_config=0;
1492 dbg(0,"w=%d h=%d\n", this->root.w, this->root.h);
1494 * Select default values from profile based on the screen.
1496 if((this->root.w > 320 || this->root.h > 320) && this->root.w > 240 && this->root.h > 240)
1498 if((this->root.w > 640 || this->root.h > 640) && this->root.w > 480 && this->root.h > 480 )
1500 current_config = &config_profiles[LARGE_PROFILE];
1504 current_config = &config_profiles[MEDIUM_PROFILE];
1509 current_config = &config_profiles[SMALL_PROFILE];
1513 * Apply override values from config file
1515 if(this->config.font_size == -1 )
1517 this->font_size = current_config->font_size;
1521 this->font_size = this->config.font_size;
1524 if(this->config.icon_xs == -1 )
1526 this->icon_xs = current_config->icon_xs;
1530 this->icon_xs = this->config.icon_xs;
1533 if(this->config.icon_s == -1 )
1535 this->icon_s = current_config->icon_s;
1539 this->icon_s = this->config.icon_s;
1541 if(this->config.icon_l == -1 )
1543 this->icon_l = current_config->icon_l;
1547 this->icon_l = this->config.icon_l;
1549 if(this->config.spacing == -1 )
1551 this->spacing = current_config->spacing;
1555 this->spacing = current_config->spacing;
1560 static struct widget *
1561 gui_internal_button_label(struct gui_priv *this, char *label, int mode)
1563 struct widget *wl,*wlb;
1564 struct widget *wb=gui_internal_menu_data(this)->button_bar;
1565 wlb=gui_internal_box_new(this, gravity_right_center|orientation_vertical);
1566 wl=gui_internal_label_new(this, label);
1568 wlb->foreground=this->text_foreground;
1573 gui_internal_widget_append(wlb, wl);
1575 gui_internal_widget_prepend(wb, wlb);
1577 gui_internal_widget_append(wb, wlb);
1583 static struct widget *
1584 gui_internal_menu(struct gui_priv *this, char *label)
1586 struct widget *menu,*w,*w1,*topbox;
1588 gui_internal_search_idle_end(this);
1589 topbox=gui_internal_box_new_with_label(this, 0, label);
1590 topbox->w=this->root.w;
1591 topbox->h=this->root.h;
1592 gui_internal_widget_append(&this->root, topbox);
1593 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1594 menu->w=this->root.w;
1595 menu->h=this->root.h;
1596 menu->background=this->background;
1597 gui_internal_apply_config(this);
1598 this->font=graphics_font_new(this->gra,this->font_size,1);
1599 topbox->menu_data=g_new0(struct menu_data, 1);
1600 gui_internal_widget_append(topbox, menu);
1601 w=gui_internal_top_bar(this);
1602 gui_internal_widget_append(menu, w);
1603 w=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1604 w->spx=4*this->spacing;
1606 gui_internal_widget_append(menu, w);
1607 if (this->flags & 16) {
1608 struct widget *wlb,*wb,*wm=w;
1609 wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
1610 w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
1611 dbg(0,"topbox->menu_data=%p\n", topbox->menu_data);
1612 gui_internal_widget_append(wm, w);
1613 wb=gui_internal_box_new(this, gravity_right_center|orientation_horizontal|flags_fill);
1619 topbox->menu_data->button_bar=wb;
1620 gui_internal_widget_append(wm, wb);
1621 wlb=gui_internal_button_label(this,_("Back"),1);
1622 wlb->func=gui_internal_back;
1623 wlb->state |= STATE_SENSITIVE;
1625 if (this->flags & 192) {
1626 menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
1627 menu->w=this->root.w;
1628 menu->h=this->root.h;
1629 w1=gui_internal_time_help(this);
1630 gui_internal_widget_append(menu, w1);
1631 w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
1632 gui_internal_widget_append(menu, w1);
1633 gui_internal_widget_append(topbox, menu);
1634 menu->background=NULL;
1639 static struct menu_data *
1640 gui_internal_menu_data(struct gui_priv *this)
1643 struct widget *menu;
1645 l=g_list_last(this->root.children);
1647 return menu->menu_data;
1651 gui_internal_menu_render(struct gui_priv *this)
1654 struct widget *menu;
1656 l=g_list_last(this->root.children);
1658 gui_internal_say(this, menu, 0);
1659 gui_internal_widget_pack(this, menu);
1660 gui_internal_widget_render(this, menu);
1664 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
1666 struct widget *w=wm->data;
1667 dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
1668 navit_set_destination(this->nav, &w->c, w->name, 1);
1669 if (this->flags & 512) {
1671 follow.type=attr_follow;
1673 navit_set_attr(this->nav, &this->osd_configuration);
1674 navit_set_attr(this->nav, &follow);
1675 navit_zoom_to_route(this->nav, 0);
1677 gui_internal_prune_menu(this, NULL);
1681 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
1683 struct widget *w=wm->data;
1684 navit_set_position(this->nav, &w->c);
1685 gui_internal_prune_menu(this, NULL);
1689 gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
1692 dbg(0,"text='%s'\n", widget->text);
1693 if (widget->text && strlen(widget->text))
1694 navit_add_bookmark(this->nav, &widget->c, widget->text);
1695 g_free(widget->text);
1697 l=g_list_previous(g_list_last(this->root.children));
1698 gui_internal_prune_menu(this, l->data);
1702 gui_internal_cmd_add_bookmark_clicked(struct gui_priv *this, struct widget *widget, void *data)
1704 gui_internal_cmd_add_bookmark_do(this, widget->data);
1708 gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm, void *data)
1713 len=strlen(wm->text);
1714 dbg(1,"len=%d\n", len);
1715 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
1716 wm->text[len-1]='\0';
1717 gui_internal_cmd_add_bookmark_do(this, wm);
1723 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
1726 gui_internal_cmd_add_bookmark(struct gui_priv *this, struct widget *wm, void *data)
1728 struct widget *w,*wb,*wk,*wl,*we,*wnext,*wp=wm->data;
1729 wb=gui_internal_menu(this, "Add Bookmark");
1730 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1731 gui_internal_widget_append(wb, w);
1732 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1733 gui_internal_widget_append(w, we);
1734 gui_internal_widget_append(we, wk=gui_internal_label_new(this, wp->name ? wp->name : wp->text));
1735 wk->state |= STATE_EDIT|STATE_CLEAR;
1736 wk->background=this->background;
1737 wk->flags |= flags_expand|flags_fill;
1738 wk->func = gui_internal_cmd_add_bookmark_changed;
1740 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
1741 wnext->state |= STATE_SENSITIVE;
1742 wnext->func = gui_internal_cmd_add_bookmark_clicked;
1744 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
1745 gui_internal_widget_append(w, wl);
1747 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
1748 gui_internal_menu_render(this);
1753 get_direction(char *buffer, int angle, int mode)
1758 sprintf(buffer,"%d",angle);
1761 if (angle < 69 || angle > 291)
1763 if (angle > 111 && angle < 249)
1765 if (angle > 22 && angle < 158)
1767 if (angle > 202 && angle < 338)
1772 angle=(angle+15)/30;
1775 sprintf(buffer,"%d H", angle);
1783 enum item_type *types;
1785 {"bank","Bank",(enum item_type []){type_poi_bank,type_poi_bank,type_none}},
1786 {"fuel","Fuel",(enum item_type []){type_poi_fuel,type_poi_fuel,type_none}},
1787 {"hotel","Hotel",(enum item_type []) {
1788 type_poi_hotel,type_poi_camp_rv,
1789 type_poi_camping,type_poi_camping,
1790 type_poi_resort,type_poi_resort,
1791 type_poi_motel,type_poi_hostel,
1793 {"restaurant","Restaurant",(enum item_type []) {
1794 type_poi_bar,type_poi_picnic,
1795 type_poi_burgerking,type_poi_fastfood,
1796 type_poi_restaurant,type_poi_restaurant,
1798 {"shopping","Shopping",(enum item_type []) {
1799 type_poi_mall,type_poi_mall,
1800 type_poi_shop_grocery,type_poi_shop_grocery,
1802 {"hospital","Service",(enum item_type []) {
1803 type_poi_marina,type_poi_marina,
1804 type_poi_hospital,type_poi_hospital,
1805 type_poi_public_utilities,type_poi_public_utilities,
1806 type_poi_police,type_poi_autoservice,
1807 type_poi_information,type_poi_information,
1808 type_poi_personal_service,type_poi_repair_service,
1809 type_poi_rest_room,type_poi_rest_room,
1810 type_poi_restroom,type_poi_restroom,
1812 {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
1813 {"peak","Land Features",(enum item_type []){
1814 type_poi_land_feature,type_poi_rock,
1815 type_poi_dam,type_poi_dam,
1817 {"unknown","Other",(enum item_type []){
1818 type_point_unspecified,type_poi_land_feature-1,
1819 type_poi_rock+1,type_poi_fuel-1,
1820 type_poi_marina+1,type_poi_car_parking-1,
1821 type_poi_car_parking+1,type_poi_bar-1,
1822 type_poi_bank+1,type_poi_dam-1,
1823 type_poi_dam+1,type_poi_information-1,
1824 type_poi_information+1,type_poi_mall-1,
1825 type_poi_mall+1,type_poi_personal_service-1,
1826 type_poi_restaurant+1,type_poi_restroom-1,
1827 type_poi_restroom+1,type_poi_shop_grocery-1,
1828 type_poi_shop_grocery+1,type_poi_motel-1,
1829 type_poi_hostel+1,type_selected_point,
1833 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
1835 static struct widget *
1836 gui_internal_cmd_pois_selector(struct gui_priv *this, struct pcoord *c)
1838 struct widget *wl,*wb;
1840 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1841 for (i = 0 ; i < sizeof(selectors)/sizeof(struct selector) ; i++) {
1842 gui_internal_widget_append(wl, wb=gui_internal_button_new_with_callback(this, NULL,
1843 image_new_xs(this, selectors[i].icon), gravity_left_center|orientation_vertical,
1844 gui_internal_cmd_pois, &selectors[i]));
1851 static struct widget *
1852 gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct item *item, struct coord *c, int dist)
1861 wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
1863 sprintf(distbuf,"%d", dist/1000);
1864 get_direction(dirbuf, transform_get_angle_delta(center, c, 0), 1);
1865 type=item_to_name(item->type);
1866 if (item_attr_get(item, attr_label, &attr)) {
1867 wl->name=g_strdup_printf("%s %s",type,attr.u.str);
1870 wl->name=g_strdup(type);
1872 text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
1873 gui_internal_widget_append(wl, gui_internal_label_new(this, text));
1880 gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_data)
1882 const struct widget *wa=a;
1883 const struct widget *wb=b;
1884 struct widget *wac=wa->children->data;
1885 struct widget *wbc=wb->children->data;
1894 gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
1896 enum item_type *types;
1897 if (type >= type_line)
1899 if (! sel || !sel->types)
1902 while (*types != type_none) {
1903 if (type >= types[0] && type <= types[1]) {
1911 static void gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data);
1914 gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
1916 struct map_selection *sel,*selm;
1917 struct coord c,center;
1918 struct mapset_handle *h;
1920 struct map_rect *mr;
1922 int idist,dist=20000;
1923 struct widget *wi,*w,*w2,*wb;
1924 enum projection pro=wm->c.pro;
1925 struct selector *isel=wm->data;
1927 wb=gui_internal_menu(this, isel ? isel->name : _("POIs"));
1928 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1929 gui_internal_widget_append(wb, w);
1931 gui_internal_widget_append(w, gui_internal_cmd_pois_selector(this,&wm->c));
1932 w2=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1933 gui_internal_widget_append(w, w2);
1935 sel=map_selection_rect_new(&wm->c, dist, 18);
1938 h=mapset_open(navit_get_mapset(this->nav));
1939 while ((m=mapset_next(h, 1))) {
1940 selm=map_selection_dup_pro(sel, pro, map_projection(m));
1941 mr=map_rect_new(m, selm);
1942 dbg(2,"mr=%p\n", mr);
1944 while ((item=map_rect_get_item(mr))) {
1945 if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
1946 item_coord_get_pro(item, &c, 1, pro) &&
1947 coord_rect_contains(&sel->u.c_rect, &c) &&
1948 (idist=transform_distance(pro, ¢er, &c)) < dist) {
1949 gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, ¢er, item, &c, idist));
1950 wi->func=gui_internal_cmd_position;
1953 wi->state |= STATE_SENSITIVE;
1959 map_rect_destroy(mr);
1961 map_selection_destroy(selm);
1963 map_selection_destroy(sel);
1965 w2->children=g_list_sort_with_data(w2->children, gui_internal_cmd_pois_sort_num, (void *)1);
1966 gui_internal_menu_render(this);
1970 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
1972 struct widget *w=wm->data;
1973 int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
1975 graphics_clear_selection(this->gra, NULL);
1976 graphics_add_selection(this->gra, &w->item, NULL);
1978 navit_set_center(this->nav, &w->c, 1);
1979 gui_internal_prune_menu(this, NULL);
1984 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
1986 struct widget *w,*wb;
1987 struct map_rect *mr;
1992 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
1993 wb=gui_internal_menu(this, "Attributes");
1994 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
1995 gui_internal_widget_append(wb, w);
1996 mr=map_rect_new(wm->item.map, NULL);
1997 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
1998 dbg(0,"item=%p\n", item);
2000 while(item_attr_get(item, attr_any, &attr)) {
2001 text=g_strdup_printf("%s:%s", attr_to_name(attr.type), attr_to_text(&attr, wm->item.map, 1));
2002 gui_internal_widget_append(w,
2003 wb=gui_internal_button_new_with_callback(this, text,
2004 NULL, gravity_left_center|orientation_horizontal|flags_fill,
2005 gui_internal_cmd_view_attributes, NULL));
2009 map_rect_destroy(mr);
2010 gui_internal_menu_render(this);
2014 gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data)
2016 struct map_rect *mr;
2021 dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
2022 mr=map_rect_new(wm->item.map, NULL);
2023 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2024 dbg(0,"item=%p\n", item);
2026 while(item_attr_get(item, attr_url_local, &attr)) {
2028 cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
2031 map_rect_destroy(mr);
2036 dbg(0,"calling external cmd '%s' is not supported\n",cmd);
2042 /* wm->data: 0 Nothing special
2050 gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
2052 struct widget *wb,*w,*wc,*wbc;
2056 int display_attributes=(wm->data == (void *)2);
2057 int display_view_on_map=(wm->data != (void *)1);
2058 int display_items=(wm->data == (void *)1);
2059 int display_streets=(wm->data == (void *)3);
2060 int display_house_numbers=1;
2061 if (wm->data == (void *)4) {
2062 gui_internal_search_town_in_country(this, wm);
2066 switch ((int)wm->data) {
2071 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
2072 transform_to_geo(wm->c.pro, &c, &g);
2083 name=wm->name ? wm->name : wm->text;
2084 wb=gui_internal_menu(this, name);
2085 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2086 gui_internal_widget_append(wb, w);
2087 coord=coordinates(&wm->c, ' ');
2088 gui_internal_widget_append(w, gui_internal_label_new(this, coord));
2090 if (display_streets) {
2091 gui_internal_widget_append(w,
2092 wc=gui_internal_button_new_with_callback(this, _("Streets"),
2093 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2094 gui_internal_search_street_in_town, wm));
2096 wc->selection_id=wm->selection_id;
2098 if (display_house_numbers) {
2099 gui_internal_widget_append(w,
2100 wc=gui_internal_button_new_with_callback(this, _("House numbers"),
2101 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2102 gui_internal_search_house_number_in_street, wm));
2104 wc->selection_id=wm->selection_id;
2106 if (display_attributes) {
2107 struct map_rect *mr;
2110 mr=map_rect_new(wm->item.map, NULL);
2111 item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
2113 if (item_attr_get(item, attr_description, &attr))
2114 gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
2115 if (item_attr_get(item, attr_url_local, &attr)) {
2116 gui_internal_widget_append(w,
2117 wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
2118 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2119 gui_internal_cmd_view_in_browser, NULL));
2122 gui_internal_widget_append(w,
2123 wb=gui_internal_button_new_with_callback(this, _("View Attributes"),
2124 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2125 gui_internal_cmd_view_attributes, NULL));
2128 map_rect_destroy(mr);
2130 gui_internal_widget_append(w,
2131 gui_internal_button_new_with_callback(this, _("Set as destination"),
2132 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2133 gui_internal_cmd_set_destination, wm));
2134 gui_internal_widget_append(w,
2135 gui_internal_button_new_with_callback(this, _("Set as position"),
2136 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2137 gui_internal_cmd_set_position, wm));
2138 gui_internal_widget_append(w,
2139 wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
2140 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2141 gui_internal_cmd_add_bookmark, wm));
2143 gui_internal_widget_append(w,
2144 wbc=gui_internal_button_new_with_callback(this, _("POIs"),
2145 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2146 gui_internal_cmd_pois, NULL));
2149 gui_internal_widget_append(w,
2150 gui_internal_button_new(this, "Add to tour",
2151 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2152 gui_internal_widget_append(w,
2153 gui_internal_button_new(this, "Add as bookmark",
2154 image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
2156 if (display_view_on_map) {
2157 gui_internal_widget_append(w,
2158 gui_internal_button_new_with_callback(this, _("View on map"),
2159 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2160 gui_internal_cmd_view_on_map, wm));
2162 if (display_items) {
2165 struct mapset_handle *h;
2166 struct map_rect *mr;
2169 struct street_data *data;
2170 struct map_selection sel;
2171 struct transformation *trans;
2172 enum projection pro;
2176 trans=navit_get_trans(this->nav);
2177 pro=transform_get_projection(trans);
2178 transform_from_geo(pro, &g, &c);
2179 ms=navit_get_mapset(this->nav);
2181 sel.u.c_rect.lu.x=c.x-dist;
2182 sel.u.c_rect.lu.y=c.y+dist;
2183 sel.u.c_rect.rl.x=c.x+dist;
2184 sel.u.c_rect.rl.y=c.y-dist;
2186 sel.range=item_range_all;
2188 while ((m=mapset_next(h,1))) {
2189 mr=map_rect_new(m, &sel);
2192 while ((item=map_rect_get_item(mr))) {
2193 data=street_get_data(item);
2194 if (transform_within_dist_item(&c, item->type, data->c, data->count, dist)) {
2195 if (item_attr_get(item, attr_label, &attr)) {
2196 label=map_convert_string(m, attr.u.str);
2197 text=g_strdup_printf("%s %s", item_to_name(item->type), label);
2198 map_convert_free(label);
2200 text=g_strdup_printf("%s", item_to_name(item->type));
2201 gui_internal_widget_append(w,
2202 wc=gui_internal_button_new_with_callback(this, text,
2203 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
2204 gui_internal_cmd_position, (void *)2));
2205 wc->c.x=data->c[0].x;
2206 wc->c.y=data->c[0].y;
2208 wc->name=g_strdup(text);
2212 street_data_free(data);
2214 map_rect_destroy(mr);
2219 gui_internal_menu_render(this);
2223 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
2225 struct attr attr,mattr;
2226 struct map_rect *mr=NULL;
2228 char *label_full,*l,*prefix,*pos;
2229 int len,plen,hassub;
2230 struct widget *wb,*w,*wbm;
2235 wb=gui_internal_menu(this, wm->text ? wm->text : _("Bookmarks"));
2236 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2237 w->spy=this->spacing*3;
2238 gui_internal_widget_append(wb, w);
2243 plen=strlen(prefix);
2245 if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
2246 hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
2247 while ((item=map_rect_get_item(mr))) {
2248 if (item->type != type_bookmark) continue;
2249 if (!item_attr_get(item, attr_label, &attr)) continue;
2250 label_full=attr.u.str;
2251 if (!strncmp(label_full, prefix, plen)) {
2252 pos=strchr(label_full+plen, '/');
2258 len=strlen(label_full);
2260 l=g_malloc(len-plen+1);
2261 strncpy(l, label_full+plen, len-plen);
2263 if (!g_hash_table_lookup(hash, l)) {
2264 wbm=gui_internal_button_new_with_callback(this, l,
2265 image_new_xs(this, hassub ? "gui_inactive" : "gui_active" ), gravity_left_center|orientation_horizontal|flags_fill,
2266 hassub ? gui_internal_cmd_bookmarks : gui_internal_cmd_position, NULL);
2267 if (item_coord_get(item, &c, 1)) {
2270 wbm->c.pro=map_projection(mattr.u.map);
2271 wbm->name=g_strdup_printf(_("Bookmark %s"),label_full);
2272 wbm->text=g_strdup(l);
2273 gui_internal_widget_append(w, wbm);
2274 g_hash_table_insert(hash, g_strdup(l), (void *)1);
2275 wbm->prefix=g_malloc(len+2);
2276 strncpy(wbm->prefix, label_full, len+1);
2277 wbm->prefix[len+1]='\0';
2279 gui_internal_widget_destroy(this, wbm);
2286 g_hash_table_destroy(hash);
2288 gui_internal_menu_render(this);
2291 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
2293 struct widget *wi,*menu;
2297 menu=g_list_last(this->root.children)->data;
2298 wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2300 if (*key == NAVIT_KEY_BACKSPACE) {
2301 dbg(0,"backspace\n");
2302 if (wi->text && wi->text[0]) {
2303 len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
2305 text=g_strdup_printf("%s ", wi->text);
2308 if (wi->state & STATE_CLEAR) {
2309 dbg(0,"wi->state=0x%x\n", wi->state);
2312 wi->state &= ~STATE_CLEAR;
2313 dbg(0,"wi->state=0x%x\n", wi->state);
2315 text=g_strdup_printf("%s%s", wi->text ? wi->text : "", key);
2319 if (*key == NAVIT_KEY_BACKSPACE && wi->text) {
2320 gui_internal_widget_render(this, wi);
2325 wi->func(this, wi, wi->data);
2327 gui_internal_widget_render(this, wi);
2333 gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
2335 struct menu_data *md=gui_internal_menu_data(this);
2336 gui_internal_keypress_do(this, (char *) wm->data);
2337 if (md->keyboard_mode == 2)
2338 gui_internal_keyboard_do(this, md->keyboard, 10);
2339 if (md->keyboard_mode == 26)
2340 gui_internal_keyboard_do(this, md->keyboard, 34);
2344 gui_internal_search_idle_end(struct gui_priv *this)
2347 event_remove_idle(this->idle);
2350 if (this->idle_cb) {
2351 callback_destroy(this->idle_cb);
2357 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2359 char *text=NULL,*name=NULL;
2360 struct search_list_result *res;
2362 struct item *item=NULL;
2364 static char possible_keys[256]="";
2366 res=search_list_get_result(this->sl);
2368 gchar* trunk_name = NULL;
2370 struct widget *menu=g_list_last(this->root.children)->data;
2371 struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
2373 if (! strcmp(wm_name,"Town"))
2374 trunk_name = g_strrstr(res->town->name, wi->text);
2375 if (! strcmp(wm_name,"Street"))
2376 trunk_name = g_strrstr(name=res->street->name, wi->text);
2379 char next_char = trunk_name[strlen(wi->text)];
2381 int len = strlen(possible_keys);
2382 for(i = 0; (i<len) && (possible_keys[i] != next_char) ;i++) ;
2383 if (i==len || !len) {
2384 possible_keys[len]=trunk_name[strlen(wi->text)];
2385 possible_keys[len+1]='\0';
2388 dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->name, possible_keys);
2393 gui_internal_search_idle_end(this);
2395 struct menu_data *md=gui_internal_menu_data(this);
2396 if (md && md->keyboard) {
2397 GList *lk=md->keyboard->children;
2398 graphics_draw_mode(this->gra, draw_mode_begin);
2400 struct widget *child=lk->data;
2401 GList *lk2=child->children;
2403 struct widget *child_=lk2->data;
2404 lk2=g_list_next(lk2);
2405 if (child_->data && strcmp("\b", child_->data)) { // FIXME don't disable special keys
2406 if (strlen(possible_keys) == 0)
2407 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2408 else if (g_strrstr(possible_keys, child_->data)!=NULL ) {
2409 child_->state|= STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SENSITIVE|STATE_CLEAR ;
2411 child_->state&= ~(STATE_HIGHLIGHTED|STATE_VISIBLE|STATE_SELECTED) ;
2413 gui_internal_widget_render(this,child_);
2418 gui_internal_widget_render(this,md->keyboard);
2419 graphics_draw_mode(this->gra, draw_mode_end);
2422 possible_keys[0]='\0';
2426 if (! strcmp(wm_name,"Country")) {
2427 name=res->country->name;
2428 item=&res->country->common.item;
2429 text=g_strdup_printf("%s", res->country->name);
2431 if (! strcmp(wm_name,"Town")) {
2432 name=res->town->name;
2433 item=&res->town->common.item;
2434 if (res->town->name && res->town->district)
2435 text=g_strdup_printf("%s%s%s (%s)", res->town->common.postal_mask ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name, res->town->district);
2437 text=g_strdup_printf("%s%s%s", res->town->common.postal ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name);
2439 if (! strcmp(wm_name,"Street")) {
2440 name=res->street->name;
2441 item=&res->street->common.item;
2442 text=g_strdup_printf("%s %s", res->town->name, res->street->name);
2444 dbg(1,"res->country->flag=%s\n", res->country->flag);
2445 gui_internal_widget_append(search_list,
2446 wc=gui_internal_button_new_with_callback(this, text,
2447 image_new_xs(this, res->country->flag),
2448 gravity_left_center|orientation_horizontal|flags_fill,
2449 gui_internal_cmd_position, param));
2450 wc->name=g_strdup(name);
2453 wc->selection_id=res->id;
2456 gui_internal_widget_pack(this, search_list);
2457 l=g_list_last(this->root.children);
2458 graphics_draw_mode(this->gra, draw_mode_begin);
2459 gui_internal_widget_render(this, l->data);
2460 graphics_draw_mode(this->gra, draw_mode_end);
2465 gui_internal_search_idle_start(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
2467 this->idle_cb=callback_new_4(callback_cast(gui_internal_search_idle), this, wm_name, search_list, param);
2468 this->idle=event_add_idle(50,this->idle_cb);
2469 callback_call_0(this->idle_cb);
2475 * @param wm The widget that generated the event for the search changed,
2476 * if this was generated by a key on the virtual keyboard then
2477 * wm is the key button widget.
2480 gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data)
2483 struct widget *search_list=gui_internal_menu_data(this)->search_list;
2484 gui_internal_widget_children_destroy(this, search_list);
2486 void *param=(void *)3;
2488 if (! strcmp(wm->name,"Country")) {
2492 dbg(0,"%s now '%s'\n", wm->name, wm->text);
2494 gui_internal_search_idle_end(this);
2495 if (wm->text && g_utf8_strlen(wm->text, -1) >= minlen) {
2496 struct attr search_attr;
2499 if (! strcmp(wm->name,"Country"))
2500 search_attr.type=attr_country_all;
2501 if (! strcmp(wm->name,"Town"))
2502 search_attr.type=attr_town_or_district_name;
2503 if (! strcmp(wm->name,"Street"))
2504 search_attr.type=attr_street_name;
2505 if (! strcmp(wm->name,"House number"))
2506 search_attr.type=attr_house_number;
2507 search_attr.u.str=wm->text;
2508 search_list_search(this->sl, &search_attr, 1);
2509 gui_internal_search_idle_start(this, wm->name, search_list, param);
2511 l=g_list_last(this->root.children);
2512 gui_internal_widget_render(this, l->data);
2515 static struct widget *
2516 gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w, int h)
2519 gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
2520 NULL, gravity_center|orientation_vertical, func, data));
2521 wk->data_free=data_free;
2522 wk->background=this->background;
2530 static struct widget *
2531 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
2533 return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
2536 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
2538 // Some macros that make the keyboard layout easier to visualise in
2539 // the source code. The macros are #undef'd after this function.
2540 #define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
2541 #define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h)
2542 static struct widget *
2543 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
2545 struct widget *wkbd,*wk;
2546 struct menu_data *md=gui_internal_menu_data(this);
2547 int i, max_w=this->root.w, max_h=this->root.h;
2553 gui_internal_highlight(this);
2555 gui_internal_widget_children_destroy(this, wkbdb);
2557 wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2559 md->keyboard_mode=mode;
2560 wkbd=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
2561 wkbd->background=this->background;
2568 if (mode >= 0 && mode < 8) {
2569 for (i = 0 ; i < 26 ; i++) {
2570 char text[]={'A'+i,'\0'};
2573 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2580 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2582 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2585 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
2587 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2589 if (mode >= 8 && mode < 16) {
2590 for (i = 0 ; i < 26 ; i++) {
2591 char text[]={'a'+i,'\0'};
2594 gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
2601 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2603 wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2606 wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2608 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2610 if (mode >= 16 && mode < 24) {
2611 for (i = 0 ; i < 10 ; i++) {
2612 char text[]={'0'+i,'\0'};
2615 KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
2616 KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
2618 for (i = 0 ; i < 5 ; i++) SPACER();
2626 wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2628 wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
2631 wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2633 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2635 if (mode >= 24 && mode < 32) {
2636 KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
2637 KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
2638 KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
2639 KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
2641 wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2644 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2646 if (mode >= 32 && mode < 40) {
2647 KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
2648 KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
2649 KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
2650 KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
2652 wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
2655 gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
2657 gui_internal_widget_append(wkbdb, wkbd);
2659 gui_internal_widget_pack(this, wkbdb);
2660 gui_internal_widget_render(this, wkbdb);
2667 static struct widget *
2668 gui_internal_keyboard(struct gui_priv *this, int mode)
2670 if (! this->keyboard)
2672 return gui_internal_keyboard_do(this, NULL, mode);
2676 gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data)
2678 gui_internal_keyboard_do(this, key->data, key->datai);
2682 gui_internal_search_list_set_default_country(struct gui_priv *this)
2684 struct attr search_attr, country_name, country_iso2, *country_attr;
2686 struct country_search *cs;
2687 struct tracking *tracking;
2688 struct search_list_result *res;
2690 country_attr=country_default();
2691 tracking=navit_get_tracking(this->nav);
2692 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
2693 country_attr=&search_attr;
2695 cs=country_search_new(country_attr, 0);
2696 item=country_search_get_item(cs);
2697 if (item && item_attr_get(item, attr_country_name, &country_name)) {
2698 search_attr.type=attr_country_all;
2699 dbg(0,"country %s\n", country_name.u.str);
2700 search_attr.u.str=country_name.u.str;
2701 search_list_search(this->sl, &search_attr, 0);
2702 while((res=search_list_get_result(this->sl)));
2703 g_free(this->country_iso2);
2704 if (item_attr_get(item, attr_country_iso2, &country_iso2))
2705 this->country_iso2=g_strdup(country_iso2.u.str);
2707 country_search_destroy(cs);
2709 dbg(0,"warning: no default country found\n");
2710 if (this->country_iso2) {
2711 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
2712 search_attr.type=attr_country_iso2;
2713 search_attr.u.str=this->country_iso2;
2714 search_list_search(this->sl, &search_attr, 0);
2715 while((res=search_list_get_result(this->sl)));
2721 gui_internal_search_list_new(struct gui_priv *this)
2723 struct mapset *ms=navit_get_mapset(this->nav);
2725 this->sl=search_list_new(ms);
2726 gui_internal_search_list_set_default_country(this);
2731 gui_internal_search_list_destroy(struct gui_priv *this)
2734 search_list_destroy(this->sl);
2741 gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
2743 struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
2745 gui_internal_search_list_new(this);
2746 wb=gui_internal_menu(this, what);
2747 w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
2748 gui_internal_widget_append(wb, w);
2749 wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2750 gui_internal_widget_append(w, wr);
2751 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
2752 gui_internal_widget_append(wr, we);
2754 if (!strcmp(type,"Country")) {
2755 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
2756 wnext->func=gui_internal_search_town;
2757 } else if (!strcmp(type,"Town")) {
2758 if (this->country_iso2) {
2759 #if HAVE_API_ANDROID
2760 char country_iso2[strlen(this->country_iso2)+1];
2761 strtolower(country_iso2, this->country_iso2);
2762 country=g_strdup_printf("country_%s", country_iso2);
2764 country=g_strdup_printf("country_%s", this->country_iso2);
2767 country=strdup("gui_select_country");
2768 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
2769 wb->state |= STATE_SENSITIVE;
2771 wb->func = gui_internal_search_country;
2773 wb->func = gui_internal_back;
2774 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_street"));
2775 wnext->func=gui_internal_search_street;
2777 } else if (!strcmp(type,"Street")) {
2778 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_town")));
2779 wb->state |= STATE_SENSITIVE;
2780 wb->func = gui_internal_back;
2781 wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_house_number"));
2782 wnext->func=gui_internal_search_house_number;
2783 } else if (!strcmp(type,"House number")) {
2784 gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
2785 wb->state |= STATE_SENSITIVE;
2786 wb->func = gui_internal_back;
2788 gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
2790 gui_internal_widget_append(we, wnext);
2791 wnext->state |= STATE_SENSITIVE;
2793 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
2794 gui_internal_widget_append(wr, wl);
2795 gui_internal_menu_data(this)->search_list=wl;
2796 wk->state |= STATE_EDIT;
2797 wk->background=this->background;
2798 wk->flags |= flags_expand|flags_fill;
2799 wk->func = gui_internal_search_changed;
2800 wk->name=g_strdup(type);
2802 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
2803 gui_internal_menu_render(this);
2807 gui_internal_search_house_number(struct gui_priv *this, struct widget *widget, void *data)
2809 search_list_select(this->sl, attr_street_name, 0, 0);
2810 gui_internal_search(this,_("House number"),"House number",0);
2814 gui_internal_search_house_number_in_street(struct gui_priv *this, struct widget *widget, void *data)
2816 dbg(0,"id %d\n", widget->selection_id);
2817 search_list_select(this->sl, attr_street_name, 0, 0);
2818 search_list_select(this->sl, attr_street_name, widget->selection_id, 1);
2819 gui_internal_search(this,_("House number"),"House number",0);
2823 gui_internal_search_street(struct gui_priv *this, struct widget *widget, void *data)
2825 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
2826 gui_internal_search(this,_("Street"),"Street",0);
2830 gui_internal_search_street_in_town(struct gui_priv *this, struct widget *widget, void *data)
2832 dbg(0,"id %d\n", widget->selection_id);
2833 search_list_select(this->sl, attr_town_or_district_name, 0, 0);
2834 search_list_select(this->sl, attr_town_or_district_name, widget->selection_id, 1);
2835 gui_internal_search(this,_("Street"),"Street",0);
2839 gui_internal_search_town(struct gui_priv *this, struct widget *wm, void *data)
2842 search_list_select(this->sl, attr_country_all, 0, 0);
2843 g_free(this->country_iso2);
2844 this->country_iso2=NULL;
2845 gui_internal_search(this,_("Town"),"Town",0);
2849 gui_internal_search_town_in_country(struct gui_priv *this, struct widget *widget)
2851 struct search_list_common *slc;
2852 dbg(0,"id %d\n", widget->selection_id);
2853 search_list_select(this->sl, attr_country_all, 0, 0);
2854 slc=search_list_select(this->sl, attr_country_all, widget->selection_id, 1);
2856 g_free(this->country_iso2);
2857 this->country_iso2=((struct search_list_country *)slc)->iso2;
2859 gui_internal_search(this,widget->name,"Town",0);
2863 gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data)
2865 gui_internal_prune_menu_count(this, 1, 0);
2866 gui_internal_search(this,_("Country"),"Country",0);
2870 gui_internal_cmd_town(struct gui_priv *this, struct widget *wm, void *data)
2873 search_list_select(this->sl, attr_country_all, 0, 0);
2874 gui_internal_search(this,_("Town"),"Town",1);
2878 gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm, void *data)
2881 struct widget *w,*wb,*wl;
2882 struct attr_iter *iter;
2885 wb=gui_internal_menu(this, _("Layout"));
2886 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
2887 w->spy=this->spacing*3;
2888 gui_internal_widget_append(wb, w);
2889 iter=navit_attr_iter_new();
2890 while(navit_get_attr(this->nav, attr_layout, &attr, iter)) {
2891 wl=gui_internal_button_navit_attr_new(this, attr.u.layout->name, gravity_left_center|orientation_horizontal|flags_fill,
2893 gui_internal_widget_append(w, wl);
2895 navit_attr_iter_destroy(iter);
2896 gui_internal_menu_render(this);
2900 gui_internal_cmd_fullscreen(struct gui_priv *this, struct widget *wm, void *data)
2902 graphics_draw_mode(this->gra, draw_mode_end);
2903 if (this->fullscreen != 2)
2904 this->fullscreen=!this->fullscreen;
2905 this->win->fullscreen(this->win, this->fullscreen != 0);
2906 graphics_draw_mode(this->gra, draw_mode_begin);
2910 gui_internal_cmd_2d(struct gui_priv *this, struct widget *wm, void *data)
2912 struct transformation *trans=navit_get_trans(this->nav);
2913 transform_set_pitch(trans, 0);
2915 gui_internal_prune_menu(this, NULL);
2919 gui_internal_cmd_3d(struct gui_priv *this, struct widget *wm, void *data)
2921 struct transformation *trans=navit_get_trans(this->nav);
2922 transform_set_pitch(trans, this->pitch);
2924 gui_internal_prune_menu(this, NULL);
2928 gui_internal_cmd_display(struct gui_priv *this, struct widget *wm, void *data)
2931 struct transformation *trans;
2933 w=gui_internal_menu(this, _("Display"));
2934 gui_internal_widget_append(w,
2935 gui_internal_button_new_with_callback(this, _("Layout"),
2936 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
2937 gui_internal_cmd_layout, NULL));
2939 if(this->fullscreen != 2) {
2940 if (this->fullscreen) {
2941 gui_internal_widget_append(w,
2942 gui_internal_button_new_with_callback(this, _("Window Mode"),
2943 image_new_l(this, "gui_leave_fullscreen"), gravity_center|orientation_vertical,
2944 gui_internal_cmd_fullscreen, NULL));
2946 gui_internal_widget_append(w,
2947 gui_internal_button_new_with_callback(this, _("Fullscreen"),
2948 image_new_l(this, "gui_fullscreen"), gravity_center|orientation_vertical,
2949 gui_internal_cmd_fullscreen, NULL));
2952 trans=navit_get_trans(this->nav);
2953 if (transform_get_pitch(trans)) {
2954 gui_internal_widget_append(w,
2955 gui_internal_button_new_with_callback(this, _("2D"),
2956 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2957 gui_internal_cmd_2d, NULL));
2960 gui_internal_widget_append(w,
2961 gui_internal_button_new_with_callback(this, _("3D"),
2962 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2963 gui_internal_cmd_3d, NULL));
2965 gui_internal_menu_render(this);
2969 gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm, void *data)
2971 struct navit *nav=this->nav;
2973 main_remove_navit(nav);
2977 gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm, void *data)
2979 navit_set_destination(this->nav, NULL, NULL, 0);
2984 gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm, void *data)
2986 struct widget *w,*wc;
2989 w=gui_internal_menu(this, _("Actions"));
2990 gui_internal_widget_append(w,
2991 gui_internal_button_new_with_callback(this, _("Bookmarks"),
2992 image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
2993 gui_internal_cmd_bookmarks, NULL));
2994 if (this->clickp_valid) {
2995 coord=coordinates(&this->clickp, '\n');
2996 gui_internal_widget_append(w,
2997 wc=gui_internal_button_new_with_callback(this, coord,
2998 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
2999 gui_internal_cmd_position, (void *)1));
3000 wc->name=g_strdup(_("Map Point"));
3004 if (this->vehicle_valid) {
3005 coord=coordinates(&this->vehiclep, '\n');
3006 gui_internal_widget_append(w,
3007 wc=gui_internal_button_new_with_callback(this, coord,
3008 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3009 gui_internal_cmd_position, NULL));
3010 wc->name=g_strdup(_("Vehicle Position"));
3011 wc->c=this->vehiclep;
3014 gui_internal_widget_append(w,
3015 gui_internal_button_new_with_callback(this, _("Town"),
3016 image_new_l(this, "gui_town"), gravity_center|orientation_vertical,
3017 gui_internal_cmd_town, NULL));
3018 gui_internal_widget_append(w,
3019 gui_internal_button_new_with_callback(this, _("Quit"),
3020 image_new_l(this, "gui_quit"), gravity_center|orientation_vertical,
3021 gui_internal_cmd_quit, NULL));
3023 if (navit_check_route(this->nav)) {
3024 gui_internal_widget_append(w,
3025 gui_internal_button_new_with_callback(this, _("Stop\nNavigation"),
3026 image_new_l(this, "gui_stop"), gravity_center|orientation_vertical,
3027 gui_internal_cmd_abort_navigation, NULL));
3029 gui_internal_menu_render(this);
3033 gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm, void *wdata)
3035 struct attr attr, on, off, description, type, data;
3036 struct widget *w,*wb,*wma;
3038 struct attr_iter *iter;
3041 wb=gui_internal_menu(this, _("Maps"));
3042 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3043 w->spy=this->spacing*3;
3044 gui_internal_widget_append(wb, w);
3045 iter=navit_attr_iter_new();
3046 on.type=off.type=attr_active;
3049 while(navit_get_attr(this->nav, attr_map, &attr, iter)) {
3050 if (map_get_attr(attr.u.map, attr_description, &description, NULL)) {
3051 label=g_strdup(description.u.str);
3053 if (!map_get_attr(attr.u.map, attr_type, &type, NULL))
3055 if (!map_get_attr(attr.u.map, attr_data, &data, NULL))
3057 label=g_strdup_printf("%s:%s", type.u.str, data.u.str);
3059 wma=gui_internal_button_map_attr_new(this, label, gravity_left_center|orientation_horizontal|flags_fill,
3060 attr.u.map, &on, &off, 1);
3061 gui_internal_widget_append(w, wma);
3064 navit_attr_iter_destroy(iter);
3065 gui_internal_menu_render(this);
3069 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3071 struct attr vehicle = {attr_vehicle,{wm->data}};
3072 navit_set_attr(this->nav, &vehicle);
3076 gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm, void *data)
3078 struct widget *w,*wb,*row;
3079 struct attr attr,sat_attr;
3080 struct vehicle *v=wm->data;
3083 enum attr_type types[]={attr_sat_prn, attr_sat_elevation, attr_sat_azimuth, attr_sat_snr};
3085 wb=gui_internal_menu(this, _("Show Satellite Status"));
3086 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_satellite_status;
3087 gui_internal_menu_data(this)->redisplay_widget=wm;
3088 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3089 gui_internal_widget_append(wb, w);
3090 w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
3091 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3092 gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
3093 gui_internal_widget_append(row, gui_internal_label_new(this, " Elevation "));
3094 gui_internal_widget_append(row, gui_internal_label_new(this, " Azimuth "));
3095 gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
3096 gui_internal_widget_append(w,row);
3097 while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3098 row = gui_internal_widget_table_row_new(this,gravity_left_top);
3099 for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
3100 if (item_attr_get(attr.u.item, types[i], &sat_attr))
3101 str=g_strdup_printf("%d", sat_attr.u.num);
3104 gui_internal_widget_append(row, gui_internal_label_new(this, str));
3107 gui_internal_widget_append(w,row);
3109 gui_internal_widget_append(wb, w);
3110 gui_internal_menu_render(this);
3114 gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *data)
3116 struct widget *w,*wb;
3118 struct vehicle *v=wm->data;
3119 wb=gui_internal_menu(this, _("Show NMEA Data"));
3120 gui_internal_menu_data(this)->redisplay=gui_internal_cmd_show_nmea_data;
3121 gui_internal_menu_data(this)->redisplay_widget=wm;
3122 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3123 gui_internal_widget_append(wb, w);
3124 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
3125 gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
3126 gui_internal_menu_render(this);
3130 * A container to hold the selected vehicle and the desired profile in
3133 struct vehicle_and_profilename {
3134 struct vehicle *vehicle;
3139 * Figures out whether the given vehicle is the active vehicle.
3141 * @return true if the vehicle is active, false otherwise.
3144 gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
3147 struct attr active_vehicle;
3149 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3150 active_vehicle.u.vehicle=NULL;
3152 return active_vehicle.u.vehicle == vehicle;
3156 save_vehicle_xml(struct vehicle *v)
3159 struct attr_iter *iter=vehicle_attr_iter_new();
3163 while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
3164 if (attr_type_begin(attr.type) == attr_type_object_begin)
3167 printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
3171 printf("</vehicle>\n");
3174 vehicle_attr_iter_destroy(iter);
3179 * Reacts to a button press that changes a vehicle's active profile.
3181 * @see gui_internal_add_vehicle_profile
3184 gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
3185 widget *wm, void *data)
3187 struct vehicle_and_profilename *vapn = data;
3188 struct vehicle *v = vapn->vehicle;
3189 char *profilename = vapn->profilename;
3190 struct attr vehicle_name_attr;
3191 char *vehicle_name = NULL;
3193 // Get the vehicle name
3194 vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
3195 vehicle_name = vehicle_name_attr.u.str;
3197 dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
3200 // Change the profile name
3201 struct attr profilename_attr = {attr_profilename, {profilename}};
3202 if(!vehicle_set_attr(v, &profilename_attr, NULL)) {
3203 dbg(0, "Unable to set the vehicle's profile name\n");
3206 // Notify Navit that the routing should be re-done if this is the
3208 if(gui_internal_is_active_vehicle(this, v)) {
3209 struct attr vehicle = {attr_vehicle, {v}};
3210 navit_set_attr(this->nav, &vehicle);
3212 save_vehicle_xml(v);
3218 * Adds the vehicle profile to the GUI, allowing the user to pick a
3219 * profile for the currently selected vehicle.
3222 gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
3223 *parent, struct vehicle *v, struct vehicleprofile *profile)
3225 // Just here to show up in the translation file, nice and close to
3226 // where the translations are actually used.
3227 struct attr profile_attr;
3228 struct attr *attr = NULL;
3230 char *active_profile = NULL;
3233 struct vehicle_and_profilename *context = NULL;
3235 static char *__profile_translations[] = {
3236 _n("car"), _n("bike"), _n("pedestrian")
3239 // Figure out the profile name
3240 attr = attr_search(profile->attrs, NULL, attr_name);
3243 // Determine whether the profile is the active one
3244 vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
3245 active_profile = profile_attr.u.str;
3246 active = strcmp(name, active_profile) == 0;
3248 dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
3249 active_profile, active);
3251 // Build a translatable label.
3253 label = g_strdup_printf(_("Current profile: %s"), _(name));
3255 label = g_strdup_printf(_("Change profile to: %s"), _(name));
3258 // Create the context object (the vehicle and the desired profile)
3259 context = g_new0(struct vehicle_and_profilename, 1);
3260 context->vehicle = v;
3261 context->profilename = name;
3264 gui_internal_widget_append(parent,
3265 gui_internal_button_new_with_callback(
3267 image_new_xs(this, active ? "gui_active" : "gui_inactive"),
3268 gravity_left_center|orientation_horizontal|flags_fill,
3269 gui_internal_cmd_set_active_profile, context));
3275 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
3277 struct widget *w,*wb;
3279 struct vehicle *v=wm->data;
3280 struct vehicleprofile *profile = NULL;
3282 wb=gui_internal_menu(this, wm->text);
3283 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3284 gui_internal_widget_append(wb, w);
3286 // Add the "Set as active" button if this isn't the active
3288 if (!gui_internal_is_active_vehicle(this, v)) {
3289 gui_internal_widget_append(w,
3290 gui_internal_button_new_with_callback(this, _("Set as active"),
3291 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3292 gui_internal_cmd_set_active_vehicle, wm->data));
3295 if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
3296 gui_internal_widget_append(w,
3297 gui_internal_button_new_with_callback(this, _("Show Satellite status"),
3298 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3299 gui_internal_cmd_show_satellite_status, wm->data));
3301 if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) {
3302 gui_internal_widget_append(w,
3303 gui_internal_button_new_with_callback(this, _("Show NMEA data"),
3304 image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
3305 gui_internal_cmd_show_nmea_data, wm->data));
3308 // Add all the possible vehicle profiles to the menu
3309 GList *profiles = navit_get_vehicleprofiles(this->nav);
3311 profile = (struct vehicleprofile *)profiles->data;
3312 gui_internal_add_vehicle_profile(this, w, v, profile);
3313 profiles = g_list_next(profiles);
3316 callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
3317 gui_internal_menu_render(this);
3321 gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm, void *data)
3323 struct attr attr,vattr;
3324 struct widget *w,*wb,*wl;
3325 struct attr_iter *iter;
3326 struct attr active_vehicle;
3329 wb=gui_internal_menu(this, _("Vehicle"));
3330 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3331 w->spy=this->spacing*3;
3332 gui_internal_widget_append(wb, w);
3333 if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
3334 active_vehicle.u.vehicle=NULL;
3335 iter=navit_attr_iter_new();
3336 while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
3337 vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
3338 wl=gui_internal_button_new_with_callback(this, vattr.u.str,
3339 image_new_l(this, attr.u.vehicle == active_vehicle.u.vehicle ? "gui_active" : "gui_inactive"), gravity_left_center|orientation_horizontal|flags_fill,
3340 gui_internal_cmd_vehicle_settings, attr.u.vehicle);
3341 wl->text=g_strdup(vattr.u.str);
3342 gui_internal_widget_append(w, wl);
3344 navit_attr_iter_destroy(iter);
3345 gui_internal_menu_render(this);
3350 gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm, void *data)
3352 struct widget *wb,*w;
3354 wb=gui_internal_menu(this, _("Rules"));
3355 w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
3356 w->spy=this->spacing*3;
3357 gui_internal_widget_append(wb, w);
3360 on.type=off.type=attr_tracking;
3361 gui_internal_widget_append(w,
3362 gui_internal_button_navit_attr_new(this, _("Lock on road"), gravity_left_center|orientation_horizontal|flags_fill,
3366 on.type=off.type=attr_orientation;
3367 gui_internal_widget_append(w,
3368 gui_internal_button_navit_attr_new(this, _("Northing"), gravity_left_center|orientation_horizontal|flags_fill,
3372 on.type=off.type=attr_follow_cursor;
3373 gui_internal_widget_append(w,
3374 gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
3376 gui_internal_menu_render(this);
3380 gui_internal_cmd_settings(struct gui_priv *this, struct widget *wm, void *data)
3384 w=gui_internal_menu(this, _("Settings"));
3385 gui_internal_widget_append(w,
3386 gui_internal_button_new_with_callback(this, _("Display"),
3387 image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
3388 gui_internal_cmd_display, NULL));
3389 gui_internal_widget_append(w,
3390 gui_internal_button_new_with_callback(this, _("Maps"),
3391 image_new_l(this, "gui_maps"), gravity_center|orientation_vertical,
3392 gui_internal_cmd_maps, NULL));
3393 gui_internal_widget_append(w,
3394 gui_internal_button_new_with_callback(this, _("Vehicle"),
3395 image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
3396 gui_internal_cmd_vehicle, NULL));
3397 gui_internal_widget_append(w,
3398 gui_internal_button_new_with_callback(this, _("Rules"),
3399 image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
3400 gui_internal_cmd_rules, NULL));
3401 gui_internal_menu_render(this);
3404 //##############################################################################################################
3407 //# Authors: Martin Schaller (04/2008)
3408 //##############################################################################################################
3409 static void gui_internal_motion(void *data, struct point *p)
3412 struct gui_priv *this=data;
3413 if (!this->root.children) {
3414 navit_handle_motion(this->nav, p);
3420 if(!this->motion_timeout_callback)
3421 this->motion_timeout_callback=callback_new_1(callback_cast(gui_internal_highlight), this);
3422 if(!this->motion_timeout_event)
3423 this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
3427 static void gui_internal_menu_root(struct gui_priv *this)
3431 graphics_draw_mode(this->gra, draw_mode_begin);
3432 w=gui_internal_menu(this, _("Main menu"));
3433 w->spx=this->spacing*10;
3434 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Actions"),
3435 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
3436 gui_internal_cmd_actions, NULL));
3437 if (this->flags & 2) {
3438 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Show\nMap"),
3439 image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
3440 gui_internal_cmd_settings, NULL));
3442 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Settings"),
3443 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
3444 gui_internal_cmd_settings, NULL));
3445 gui_internal_widget_append(w, gui_internal_button_new(this, _("Tools"),
3446 image_new_l(this, "gui_tools"), gravity_center|orientation_vertical));
3448 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, "Route",
3449 image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
3450 gui_internal_cmd_route, NULL));
3453 callback_list_call_attr_1(this->cbl, attr_gui, w);
3455 gui_internal_menu_render(this);
3456 graphics_draw_mode(this->gra, draw_mode_end);
3460 gui_internal_enter(struct gui_priv *this, int ignore)
3462 struct graphics *gra=this->gra;
3463 this->ignore_button=ignore;
3464 this->clickp_valid=this->vehicle_valid=0;
3466 navit_block(this->nav, 1);
3467 graphics_overlay_disable(gra, 1);
3470 this->root.background=this->background;
3474 gui_internal_leave(struct gui_priv *this)
3476 graphics_draw_mode(this->gra, draw_mode_end);
3480 gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
3482 struct transformation *trans;
3484 struct attr attr,attrp;
3487 gui_internal_enter(this, ignore);
3488 trans=navit_get_trans(this->nav);
3490 transform_reverse(trans, p, &c);
3491 dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
3492 this->clickp.pro=transform_get_projection(trans);
3495 this->clickp_valid=1;
3497 if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
3498 && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
3499 this->vehiclep.pro=transform_get_projection(trans);
3500 transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
3501 this->vehiclep.x=c.x;
3502 this->vehiclep.y=c.y;
3503 this->vehicle_valid=1;
3506 gui_internal_menu_root(this);
3510 gui_internal_cmd_menu2(struct gui_priv *this)
3512 gui_internal_cmd_menu(this, NULL, 1);
3517 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
3519 if (widget->text && strlen(widget->text))
3520 navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
3521 g_free(widget->text);
3523 gui_internal_prune_menu(this, NULL);
3524 gui_internal_check_exit(this);
3528 gui_internal_cmd_log_clicked(struct gui_priv *this, struct widget *widget, void *data)
3530 gui_internal_cmd_log_do(this, widget->data);
3534 gui_internal_cmd_log_changed(struct gui_priv *this, struct widget *wm, void *data)
3538 len=strlen(wm->text);
3539 if (len && (wm->text[len-1] == '\n' || wm->text[len-1] == '\r')) {
3540 wm->text[len-1]='\0';
3541 gui_internal_cmd_log_do(this, wm);
3548 gui_internal_cmd_log(struct gui_priv *this)
3550 struct widget *w,*wb,*wk,*wl,*we,*wnext;
3551 gui_internal_enter(this, 1);
3552 wb=gui_internal_menu(this, "Log Message");
3553 w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3554 gui_internal_widget_append(wb, w);
3555 we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
3556 gui_internal_widget_append(w, we);
3557 gui_internal_widget_append(we, wk=gui_internal_label_new(this, _("Message")));
3558 wk->state |= STATE_EDIT|STATE_CLEAR;
3559 wk->background=this->background;
3560 wk->flags |= flags_expand|flags_fill;
3561 wk->func = gui_internal_cmd_log_changed;
3562 gui_internal_widget_append(we, wnext=gui_internal_image_new(this, image_new_xs(this, "gui_active")));
3563 wnext->state |= STATE_SENSITIVE;
3564 wnext->func = gui_internal_cmd_log_clicked;
3566 wl=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
3567 gui_internal_widget_append(w, wl);
3569 gui_internal_widget_append(w, gui_internal_keyboard(this,2));
3570 gui_internal_menu_render(this);
3571 gui_internal_leave(this);
3575 gui_internal_check_exit(struct gui_priv *this)
3577 struct graphics *gra=this->gra;
3578 if (! this->root.children) {
3579 gui_internal_search_idle_end(this);
3580 gui_internal_search_list_destroy(this);
3581 graphics_overlay_disable(gra, 0);
3582 if (!navit_block(this->nav, 0)) {
3584 navit_draw(this->nav);
3586 navit_draw_displaylist(this->nav);
3591 //##############################################################################################################
3592 //# Description: Function to handle mouse clicks and scroll wheel movement
3594 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
3595 //##############################################################################################################
3596 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
3598 struct gui_priv *this=data;
3599 struct graphics *gra=this->gra;
3601 dbg(1,"enter %d %d\n", pressed, button);
3602 // if still on the map (not in the menu, yet):
3603 dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
3604 if (!this->root.children || this->ignore_button) {
3605 this->ignore_button=0;
3606 // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
3607 if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
3608 dbg(1,"navit has handled button\n");
3611 dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
3612 if (this->menu_on_map_click && button == 1)
3613 gui_internal_cmd_menu(this, p, 0);
3618 // if already in the menu:
3622 gui_internal_highlight(this);
3627 graphics_draw_mode(gra, draw_mode_begin);
3628 gui_internal_call_highlighted(this);
3629 gui_internal_highlight(this);
3630 graphics_draw_mode(gra, draw_mode_end);
3631 gui_internal_check_exit(this);
3635 //##############################################################################################################
3638 //# Authors: Martin Schaller (04/2008)
3639 //##############################################################################################################
3640 static void gui_internal_resize(void *data, int w, int h)
3642 struct gui_priv *this=data;
3644 if( this->root.w==w && this->root.h==h)
3649 dbg(0,"w=%d h=%d children=%p\n", w, h, this->root.children);
3650 navit_handle_resize(this->nav, w, h);
3651 if (this->root.children) {
3652 gui_internal_prune_menu(this, NULL);
3653 gui_internal_menu_root(this);
3658 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
3673 gui_internal_keynav_find_closest(struct widget *wi, struct point *p, int dx, int dy, int *distance, struct widget **result)
3675 GList *l=wi->children;
3676 if (wi->state & STATE_SENSITIVE) {
3679 gui_internal_keynav_point(wi, -dx, -dy, &wp);
3681 dist1=(wp.x-p->x)*dx;
3684 dist1=(wp.y-p->y)*dy;
3692 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);
3698 if (dist1 < *distance) {
3705 struct widget *child=l->data;
3706 gui_internal_keynav_find_closest(child, p, dx, dy, distance, result);
3712 gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
3714 struct widget *result,*menu=g_list_last(this->root.children)->data;
3717 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3718 gui_internal_keynav_point(this->highlighted, dx, dy, &p);
3724 gui_internal_keynav_find_closest(menu, &p, 0, 0, &distance, &result);
3726 gui_internal_keynav_point(result, dx, dy, &p);
3727 dbg(1,"result origin=%p p=%d,%d\n", result, p.x, p.y);
3732 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3733 dbg(1,"result=%p\n", result);
3745 gui_internal_keynav_find_closest(menu, &p, dx, dy, &distance, &result);
3746 dbg(1,"wraparound result=%p\n", result);
3748 gui_internal_highlight_do(this, result);
3750 gui_internal_say(this, result, 1);
3753 //##############################################################################################################
3756 //# Authors: Martin Schaller (04/2008)
3757 //##############################################################################################################
3758 static void gui_internal_keypress(void *data, char *key)
3760 struct gui_priv *this=data;
3763 if (!this->root.children) {
3764 transform_get_size(navit_get_trans(this->nav), &w, &h);
3769 navit_set_center_screen(this->nav, &p, 1);
3771 case NAVIT_KEY_DOWN:
3774 navit_set_center_screen(this->nav, &p, 1);
3776 case NAVIT_KEY_LEFT:
3779 navit_set_center_screen(this->nav, &p, 1);
3781 case NAVIT_KEY_RIGHT:
3784 navit_set_center_screen(this->nav, &p, 1);
3786 case NAVIT_KEY_ZOOM_IN:
3787 navit_zoom_in(this->nav, 2, NULL);
3789 case NAVIT_KEY_ZOOM_OUT:
3790 navit_zoom_out(this->nav, 2, NULL);
3792 case NAVIT_KEY_RETURN:
3793 case NAVIT_KEY_MENU:
3794 gui_internal_cmd_menu(this, NULL, 0);
3799 graphics_draw_mode(this->gra, draw_mode_begin);
3801 case NAVIT_KEY_LEFT:
3802 gui_internal_keynav_highlight_next(this,-1,0);
3804 case NAVIT_KEY_RIGHT:
3805 gui_internal_keynav_highlight_next(this,1,0);
3808 gui_internal_keynav_highlight_next(this,0,-1);
3810 case NAVIT_KEY_DOWN:
3811 gui_internal_keynav_highlight_next(this,0,1);
3813 case NAVIT_KEY_BACK:
3815 case NAVIT_KEY_RETURN:
3816 if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
3817 gui_internal_call_highlighted(this);
3819 gui_internal_keypress_do(this, key);
3822 gui_internal_keypress_do(this, key);
3824 graphics_draw_mode(this->gra, draw_mode_end);
3825 gui_internal_check_exit(this);
3829 //##############################################################################################################
3832 //# Authors: Martin Schaller (04/2008)
3833 //##############################################################################################################
3834 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
3837 struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
3838 struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
3839 struct transformation *trans=navit_get_trans(this->nav);
3841 win=graphics_get_data(gra, "window");
3844 navit_ignore_graphics_events(this->nav, 1);
3847 navit_ignore_graphics_events(this->nav, 1);
3848 transform_get_size(trans, &this->root.w, &this->root.h);
3849 this->resize_cb=callback_new_attr_1(callback_cast(gui_internal_resize), attr_resize, this);
3850 graphics_add_callback(gra, this->resize_cb);
3851 this->button_cb=callback_new_attr_1(callback_cast(gui_internal_button), attr_button, this);
3852 graphics_add_callback(gra, this->button_cb);
3853 this->motion_cb=callback_new_attr_1(callback_cast(gui_internal_motion), attr_motion, this);
3854 graphics_add_callback(gra, this->motion_cb);
3855 this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
3856 graphics_add_callback(gra, this->keypress_cb);
3857 this->background=graphics_gc_new(gra);
3858 this->background2=graphics_gc_new(gra);
3859 this->highlight_background=graphics_gc_new(gra);
3860 graphics_gc_set_foreground(this->highlight_background, &cbh);
3861 this->foreground=graphics_gc_new(gra);
3862 graphics_gc_set_foreground(this->foreground, &cf);
3863 this->text_background=graphics_gc_new(gra);
3864 this->text_foreground=graphics_gc_new(gra);
3865 graphics_gc_set_foreground(this->background, &this->background_color);
3866 graphics_gc_set_foreground(this->background2, &this->background2_color);
3867 graphics_gc_set_foreground(this->text_background, &this->text_background_color);
3868 graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
3870 // set fullscreen if needed
3871 if (this->fullscreen)
3872 this->win->fullscreen(this->win, this->fullscreen != 0);
3876 static void gui_internal_disable_suspend(struct gui_priv *this)
3878 if (this->win->disable_suspend)
3879 this->win->disable_suspend(this->win);
3882 //##############################################################################################################
3885 //# Authors: Martin Schaller (04/2008)
3886 //##############################################################################################################
3887 struct gui_methods gui_internal_methods = {
3890 gui_internal_set_graphics,
3894 gui_internal_disable_suspend,
3898 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
3900 struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
3902 *out=attr_generic_add_attr(*out, &private_data);
3906 gui_internal_add_callback(struct gui_priv *priv, struct callback *cb)
3908 callback_list_add(priv->cbl, cb);
3912 gui_internal_remove_callback(struct gui_priv *priv, struct callback *cb)
3914 callback_list_remove(priv->cbl, cb);
3918 static struct gui_internal_methods gui_internal_methods_ext = {
3919 gui_internal_add_callback,
3920 gui_internal_remove_callback,
3921 gui_internal_menu_render,
3928 gui_internal_get_flags(struct widget *widget)
3930 return widget->flags;
3934 gui_internal_set_flags(struct widget *widget, enum flags flags)
3936 widget->flags=flags;
3940 gui_internal_get_state(struct widget *widget)
3942 return widget->state;
3946 gui_internal_set_state(struct widget *widget, int state)
3948 widget->state=state;
3952 gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv, struct widget *widget, void *data))
3958 gui_internal_set_data(struct widget *widget, void *data)
3964 gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
3966 widget->background=this->background;
3969 static struct gui_internal_widget_methods gui_internal_widget_methods = {
3970 gui_internal_widget_append,
3971 gui_internal_button_new,
3972 gui_internal_button_new_with_callback,
3973 gui_internal_box_new,
3974 gui_internal_label_new,
3975 gui_internal_image_new,
3976 gui_internal_keyboard,
3978 gui_internal_get_flags,
3979 gui_internal_set_flags,
3980 gui_internal_get_state,
3981 gui_internal_set_state,
3982 gui_internal_set_func,
3983 gui_internal_set_data,
3984 gui_internal_set_default_background,
3987 static struct command_table commands[] = {
3988 {"menu",command_cast(gui_internal_cmd_menu2)},
3989 {"fullscreen",command_cast(gui_internal_cmd_fullscreen)},
3990 {"get_data",command_cast(gui_internal_get_data)},
3991 {"log",command_cast(gui_internal_cmd_log)},
3995 //##############################################################################################################
3998 //# Authors: Martin Schaller (04/2008)
3999 //##############################################################################################################
4000 static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
4002 struct gui_priv *this;
4004 *meth=gui_internal_methods;
4005 this=g_new0(struct gui_priv, 1);
4007 if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
4008 this->menu_on_map_click=attr->u.num;
4010 this->menu_on_map_click=1;
4011 if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
4012 dbg(0,"register\n");
4013 command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
4016 if( (attr=attr_search(attrs,NULL,attr_font_size)))
4018 this->config.font_size=attr->u.num;
4022 this->config.font_size=-1;
4024 if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
4026 this->config.icon_xs=attr->u.num;
4030 this->config.icon_xs=-1;
4032 if( (attr=attr_search(attrs,NULL,attr_icon_l)))
4034 this->config.icon_l=attr->u.num;
4038 this->config.icon_l=-1;
4040 if( (attr=attr_search(attrs,NULL,attr_icon_s)))
4042 this->config.icon_s=attr->u.num;
4046 this->config.icon_s=-1;
4048 if( (attr=attr_search(attrs,NULL,attr_spacing)))
4050 this->config.spacing=attr->u.num;
4054 this->config.spacing=-1;
4056 if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
4058 this->speech=attr->u.num;
4060 if( (attr=attr_search(attrs,NULL,attr_keyboard)))
4061 this->keyboard=attr->u.num;
4065 if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
4066 this->fullscreen=attr->u.num;
4068 if( (attr=attr_search(attrs,NULL,attr_flags)))
4069 this->flags=attr->u.num;
4070 if( (attr=attr_search(attrs,NULL,attr_background_color)))
4071 this->background_color=*attr->u.color;
4073 this->background_color=(struct color){0x0,0x0,0x0,0xffff};
4074 if( (attr=attr_search(attrs,NULL,attr_background_color2)))
4075 this->background2_color=*attr->u.color;
4077 this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
4078 if( (attr=attr_search(attrs,NULL,attr_text_color)))
4079 this->text_foreground_color=*attr->u.color;
4081 this->text_foreground_color=(struct color){0xffff,0xffff,0xffff,0xffff};
4082 if( (attr=attr_search(attrs,NULL,attr_columns)))
4083 this->cols=attr->u.num;
4084 if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
4085 this->osd_configuration=*attr;
4087 if( (attr=attr_search(attrs,NULL,attr_pitch)))
4088 this->pitch=attr->u.num;
4091 this->data.priv=this;
4092 this->data.gui=&gui_internal_methods_ext;
4093 this->data.widget=&gui_internal_widget_methods;
4094 this->cbl=callback_list_new();
4099 //##############################################################################################################
4102 //# Authors: Martin Schaller (04/2008)
4103 //##############################################################################################################
4104 void plugin_init(void)
4106 plugin_register_gui_type("internal", gui_internal_new);
4110 * @brief Creates a new table widget.
4112 * Creates and returns a new table widget. This function will
4113 * setup next/previous buttons as children.
4115 * @param this The graphics context.
4116 * @param flags widget sizing flags.
4117 * @returns The newly created widget
4119 struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons)
4121 struct widget * widget = g_new0(struct widget,1);
4122 struct table_data * data = NULL;
4123 widget->type=widget_table;
4124 widget->flags=flags;
4125 widget->data = g_new0(struct table_data,1);
4126 widget->data_free=gui_internal_table_data_free;
4127 data = (struct table_data*)widget->data;
4131 data->next_button = gui_internal_button_new_with_callback
4132 (this,"Next",image_new_xs(this, "gui_active") ,
4133 gravity_left_center |orientation_vertical,
4134 gui_internal_table_button_next,NULL);
4135 data->next_button->data=widget;
4138 data->prev_button = gui_internal_button_new_with_callback
4140 image_new_xs(this, "gui_active")
4141 ,gravity_right_center |orientation_vertical,
4142 gui_internal_table_button_prev,NULL);
4144 data->prev_button->data=widget;
4148 data->button_box=gui_internal_box_new(this,
4149 gravity_center|orientation_horizontal);
4150 data->button_box->children=g_list_append(data->button_box->children,
4152 data->button_box->children=g_list_append(data->button_box->children,
4154 //data->button_box->background=this->background2;
4155 data->button_box->bl=this->spacing;
4156 widget->children=g_list_append(widget->children,data->button_box);
4157 gui_internal_widget_pack(this,data->button_box);
4165 * @brief Clears all the rows from the table.
4166 * This function removes all rows from a table.
4167 * New rows can later be added to the table.
4169 void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * table)
4172 struct table_data * table_data = (struct table_data* ) table->data;
4174 iter = table->children;
4176 if(iter->data != table_data->button_box) {
4177 struct widget * child = (struct widget*)iter->data;
4178 gui_internal_widget_destroy(this,child);
4179 if(table->children == iter) {
4180 table->children = g_list_remove(iter,iter->data);
4181 iter=table->children;
4184 iter = g_list_remove(iter,iter->data);
4187 iter = g_list_next(iter);
4191 table_data->top_row=NULL;
4192 table_data->bottom_row=NULL;
4193 if(table_data->page_headers)
4194 g_list_free(table_data->page_headers);
4195 table_data->page_headers=NULL;
4200 * Creates a new table_row widget.
4201 * @param this The graphics context
4202 * @param flags Sizing flags for the row
4203 * @returns The new table_row widget.
4205 struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags)
4207 struct widget * widget = g_new0(struct widget,1);
4208 widget->type=widget_table_row;
4209 widget->flags=flags;
4216 * @brief Computes the column dimensions for the table.
4218 * @param w The table widget to compute dimensions for.
4220 * This function examines all of the rows and columns for the table w
4221 * and returns a list (GList) of table_column_desc elements that
4222 * describe each column of the table.
4224 * The caller is responsible for freeing the returned list.
4226 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
4229 GList * column_desc = NULL;
4230 GList * current_desc=NULL;
4231 GList * cur_row = w->children;
4232 struct widget * cur_row_widget=NULL;
4233 GList * cur_column=NULL;
4234 struct widget * cell_w=NULL;
4235 struct table_column_desc * current_cell=NULL;
4236 struct table_data * table_data=NULL;
4243 * Scroll through the the table and
4244 * 1. Compute the maximum width + height of each column across all rows.
4246 table_data = (struct table_data*) w->data;
4247 for(cur_row=w->children; cur_row ; cur_row = g_list_next(cur_row) )
4249 cur_row_widget = (struct widget*) cur_row->data;
4250 current_desc = column_desc;
4251 if(cur_row_widget == table_data->button_box)
4256 for(cur_column = cur_row_widget->children; cur_column;
4257 cur_column=g_list_next(cur_column))
4259 cell_w = (struct widget*) cur_column->data;
4260 gui_internal_widget_pack(this,cell_w);
4261 if(current_desc == 0)
4263 current_cell = g_new0(struct table_column_desc,1);
4264 column_desc = g_list_append(column_desc,current_cell);
4265 current_desc = g_list_last(column_desc);
4266 current_cell->height=cell_w->h;
4267 current_cell->width=cell_w->w;
4268 total_width+=cell_w->w;
4273 current_cell = current_desc->data;
4276 if(current_cell->height < height )
4278 current_cell->height = height;
4280 if(current_cell->width < width)
4282 total_width += (width-current_cell->width);
4283 current_cell->width = width;
4288 current_desc = g_list_next(current_desc);
4298 * If the width of all columns is less than the width off
4299 * the table expand each cell proportionally.
4302 if(total_width+(this->spacing*column_count) < w->w ) {
4303 for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
4304 current_cell = (struct table_column_desc*) current_desc->data;
4305 current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
4314 * @brief Computes the height and width for the table.
4316 * The height and widht are computed to display all cells in the table
4317 * at the requested height/width.
4319 * @param this The graphics context
4320 * @param w The widget to pack.
4323 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
4329 GList * column_data = gui_internal_compute_table_dimensions(this,w);
4331 struct table_column_desc * cell_desc=0;
4332 struct table_data * table_data = (struct table_data*)w->data;
4334 for(current = column_data; current; current=g_list_next(current))
4336 if(table_data->button_box == current->data )
4340 cell_desc = (struct table_column_desc *) current->data;
4341 width = width + cell_desc->width + this->spacing;
4342 if(height < cell_desc->height)
4344 height = cell_desc->height ;
4350 for(current=w->children; current; current=g_list_next(current))
4352 if(current->data!= table_data->button_box)
4357 if (table_data->button_box)
4358 gui_internal_widget_pack(this,table_data->button_box);
4362 if(w->h + w->c.y > this->root.h )
4365 * Do not allow the widget to exceed the screen.
4368 w->h = this->root.h- w->c.y - height;
4373 * Deallocate column descriptions.
4375 current = column_data;
4376 while( (current = g_list_last(current)) )
4378 current = g_list_remove(current,current->data);
4386 * @brief Renders a table widget.
4388 * @param this The graphics context
4389 * @param w The table widget to render.
4391 void gui_internal_table_render(struct gui_priv * this, struct widget * w)
4396 GList * column_desc=NULL;
4397 GList * cur_row = NULL;
4398 GList * current_desc=NULL;
4399 struct table_data * table_data = (struct table_data*)w->data;
4401 int is_first_page=1;
4402 struct table_column_desc * dim=NULL;
4404 dbg_assert(table_data);
4405 column_desc = gui_internal_compute_table_dimensions(this,w);
4409 * Skip rows that are on previous pages.
4411 cur_row = w->children;
4412 if(table_data->top_row && table_data->top_row != w->children )
4414 cur_row = table_data->top_row;
4420 * Loop through each row. Drawing each cell with the proper sizes,
4421 * at the proper positions.
4423 for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
4425 GList * cur_column=NULL;
4426 current_desc = column_desc;
4427 struct widget * cur_row_widget = (struct widget*)cur_row->data;
4429 x =w->p.x+this->spacing;
4430 if(cur_row_widget == table_data->button_box )
4434 dim = (struct table_column_desc*)current_desc->data;
4436 if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
4439 * No more drawing space left.
4445 for(cur_column = cur_row_widget->children; cur_column;
4446 cur_column=g_list_next(cur_column))
4448 struct widget * cur_widget = (struct widget*) cur_column->data;
4449 dim = (struct table_column_desc*)current_desc->data;
4452 cur_widget->w=dim->width;
4454 cur_widget->h=dim->height;
4456 max_height = dim->height;
4457 /* We pack the widget before rendering to ensure that the x and y
4458 * coordinates get pushed down.
4460 gui_internal_widget_pack(this,cur_widget);
4461 gui_internal_widget_render(this,cur_widget);
4463 if(dim->height > max_height)
4465 max_height = dim->height;
4469 table_data->bottom_row=cur_row;
4470 current_desc = g_list_next(current_desc);
4472 if(table_data->button_box && (is_skipped || !is_first_page) )
4474 table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
4476 if(table_data->button_box->p.y < y )
4478 table_data->button_box->p.y=y;
4480 table_data->button_box->p.x = w->p.x;
4481 table_data->button_box->w = w->w;
4482 // table_data->button_box->h = w->h - y;
4483 // table_data->next_button->h=table_data->button_box->h;
4484 // table_data->prev_button->h=table_data->button_box->h;
4485 // table_data->next_button->c.y=table_data->button_box->c.y;
4486 // table_data->prev_button->c.y=table_data->button_box->c.y;
4488 gui_internal_widget_pack(this,table_data->button_box);
4489 if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
4492 table_data->button_box->p.y = w->p.y + w->h -
4493 table_data->button_box->h;
4497 table_data->next_button->state|= STATE_SENSITIVE;
4501 table_data->next_button->state&= ~STATE_SENSITIVE;
4504 if(table_data->top_row != w->children)
4506 table_data->prev_button->state|= STATE_SENSITIVE;
4510 table_data->prev_button->state&= ~STATE_SENSITIVE;
4512 gui_internal_widget_render(this,table_data->button_box);
4518 * Deallocate column descriptions.
4520 current_desc = column_desc;
4521 while( (current_desc = g_list_last(current_desc)) )
4523 current_desc = g_list_remove(current_desc,current_desc->data);
4529 * @brief Displays Route information
4531 * @li The name of the active vehicle
4532 * @param wm The button that was pressed.
4536 gui_internal_cmd_route_description(struct gui_priv * this, struct widget * wm,void *v)
4540 struct widget * menu;
4541 struct widget * row;
4544 if(! this->vehicle_cb)
4547 * Register the callback on vehicle updates.
4549 this->vehicle_cb = callback_new_attr_1(callback_cast(gui_internal_route_update),
4550 attr_position_coord_geo,this);
4551 navit_add_callback(this->nav,this->vehicle_cb);
4554 this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
4555 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4557 row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
4560 menu=gui_internal_menu(this,"Route Description");
4562 menu->free=gui_internal_route_screen_free;
4563 this->route_data.route_showing=1;
4564 this->route_data.route_table->spx = this->spacing;
4567 struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4569 // gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
4570 gui_internal_widget_append(box,this->route_data.route_table);
4572 box->spx = this->spacing;
4573 this->route_data.route_table->w=box->w;
4574 gui_internal_widget_append(menu,box);
4575 gui_internal_populate_route_table(this,this->nav);
4576 gui_internal_menu_render(this);
4581 line_intersection(struct coord* a1, struct coord *a2, struct coord * b1, struct coord *b2, struct coord *res)
4584 int adx=a2->x-a1->x;
4585 int ady=a2->y-a1->y;
4586 int bdx=b2->x-b1->x;
4587 int bdy=b2->y-b1->y;
4588 n = bdy * adx - bdx * ady;
4589 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
4590 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
4601 dbg(0,"a=%d b=%d n=%d\n", a, b, n);
4602 dbg(0,"a1=0x%x,0x%x ad %d,%d\n", a1->x, a1->y, adx, ady);
4603 dbg(0,"b1=0x%x,0x%x bd %d,%d\n", b1->x, b1->y, bdx, bdy);
4606 res->x = a1->x + a * adx / n;
4607 res->y = a1->y + a * ady / n;
4612 struct heightline *next;
4614 struct coord_rect bbox;
4619 struct diagram_point {
4620 struct diagram_point *next;
4624 static struct heightline *
4625 item_get_heightline(struct item *item)
4627 struct heightline *ret=NULL;
4628 struct street_data *sd;
4632 if (item_attr_get(item, attr_label, &attr)) {
4633 height=atoi(attr.u.str);
4634 sd=street_get_data(item);
4635 if (sd && sd->count > 1) {
4636 ret=g_malloc(sizeof(struct heightline)+sd->count*sizeof(struct coord));
4637 ret->bbox.lu=sd->c[0];
4638 ret->bbox.rl=sd->c[0];
4639 ret->count=sd->count;
4641 for (i = 0 ; i < sd->count ; i++) {
4643 coord_rect_extend(&ret->bbox, sd->c+i);
4646 street_data_free(sd);
4653 * @brief Displays Route Height Profile
4655 * @li The name of the active vehicle
4656 * @param wm The button that was pressed.
4659 static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct widget * wm,void *v)
4663 struct widget * menu, *box;
4665 struct map * map=NULL;
4666 struct map_rect * mr=NULL;
4667 struct route * route;
4668 struct item * item =NULL;
4670 struct mapset_handle *msh;
4671 int x,i,first=1,dist=0;
4672 struct coord c,last,res;
4673 struct coord_rect rbbox,dbbox;
4674 struct map_selection sel;
4675 struct heightline *heightline,*heightlines=NULL;
4676 struct diagram_point *min,*diagram_point,*diagram_points=NULL;
4679 sel.range.min=type_height_line_1;
4680 sel.range.max=type_height_line_3;
4683 menu=gui_internal_menu(this,_("Height Profile"));
4684 box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
4685 gui_internal_widget_append(menu, box);
4686 route = navit_get_route(this->nav);
4688 map = route_get_map(route);
4690 mr = map_rect_new(map,NULL);
4692 while((item = map_rect_get_item(mr))) {
4693 while (item_coord_get(item, &c, 1)) {
4699 coord_rect_extend(&sel.u.c_rect, &c);
4702 map_rect_destroy(mr);
4703 ms=navit_get_mapset(this->nav);
4705 msh=mapset_open(ms);
4706 while ((map=mapset_next(msh, 1))) {
4707 mr=map_rect_new(map, &sel);
4709 while((item = map_rect_get_item(mr))) {
4710 if (item->type >= sel.range.min && item->type <= sel.range.max) {
4711 heightline=item_get_heightline(item);
4713 heightline->next=heightlines;
4714 heightlines=heightline;
4718 map_rect_destroy(mr);
4727 map = route_get_map(route);
4729 mr = map_rect_new(map,NULL);
4730 if(mr && heightlines) {
4731 while((item = map_rect_get_item(mr))) {
4733 while (item_coord_get(item, &c, 1)) {
4737 heightline=heightlines;
4740 coord_rect_extend(&rbbox, &c);
4741 while (heightline) {
4742 if (coord_rect_overlap(&rbbox, &heightline->bbox)) {
4743 for (i = 0 ; i < heightline->count - 1; i++) {
4744 if (heightline->c[i].x != heightline->c[i+1].x || heightline->c[i].y != heightline->c[i+1].y) {
4745 if (line_intersection(heightline->c+i, heightline->c+i+1, &last, &c, &res)) {
4746 diagram_point=g_new(struct diagram_point, 1);
4747 diagram_point->c.x=dist+transform_distance(projection_mg, &last, &res);
4748 diagram_point->c.y=heightline->height;
4749 diagram_point->next=diagram_points;
4750 diagram_points=diagram_point;
4751 dbg(0,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
4756 heightline=heightline->next;
4758 dist+=transform_distance(projection_mg, &last, &c);
4764 map_rect_destroy(mr);
4768 gui_internal_menu_render(this);
4770 diagram_point=diagram_points;
4771 while (diagram_point) {
4773 dbbox.lu=diagram_point->c;
4774 dbbox.rl=diagram_point->c;
4777 coord_rect_extend(&dbbox, &diagram_point->c);
4778 diagram_point=diagram_point->next;
4780 dbg(0,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
4781 if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
4783 if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
4785 dbg(0,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
4791 diagram_point=diagram_points;
4792 while (diagram_point) {
4793 if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
4795 diagram_point=diagram_point->next;
4799 p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
4800 p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
4801 dbg(0,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
4802 graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
4806 graphics_draw_lines(this->gra, this->foreground, p, 2);
4815 * @brief Displays Route information
4817 * @li The name of the active vehicle
4818 * @param wm The button that was pressed.
4821 void gui_internal_cmd_route(struct gui_priv * this, struct widget * wm,void *v)
4825 graphics_draw_mode(this->gra, draw_mode_begin);
4826 w=gui_internal_menu(this, _("Route"));
4827 w->spx=this->spacing*10;
4828 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Description"),
4829 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4830 gui_internal_cmd_route_description, NULL));
4831 gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Height Profile"),
4832 image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
4833 gui_internal_cmd_route_height_profile, NULL));
4834 gui_internal_menu_render(this);
4835 gui_internal_menu_render(this);
4836 graphics_draw_mode(this->gra, draw_mode_end);
4843 * @brief handles the 'next page' table event.
4844 * A callback function that is invoked when the 'next page' button is pressed
4845 * to advance the contents of a table widget.
4847 * @param this The graphics context.
4848 * @param wm The button widget that was pressed.
4850 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data)
4852 struct widget * table_widget = (struct widget * ) wm->data;
4853 struct table_data * table_data = NULL;
4859 table_data = (struct table_data*) table_widget->data;
4865 * Before advancing to the next page we need to ensure
4866 * that the current top_row is in the list of previous top_rows
4867 * so previous page can work.
4870 for(iterator=table_data->page_headers; iterator != NULL;
4871 iterator = g_list_next(iterator) )
4873 if(iterator->data == table_data->top_row)
4882 table_data->page_headers=g_list_append(table_data->page_headers,
4883 table_data->top_row);
4886 table_data->top_row = g_list_next(table_data->bottom_row);
4888 wm->state&= ~STATE_HIGHLIGHTED;
4889 gui_internal_menu_render(this);
4895 * @brief handles the 'previous page' table event.
4896 * A callback function that is invoked when the 'previous page' button is pressed
4897 * to go back in the contents of a table widget.
4899 * @param this The graphics context.
4900 * @param wm The button widget that was pressed.
4902 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data)
4904 struct widget * table_widget = (struct widget * ) wm->data;
4905 struct table_data * table_data = NULL;
4906 GList * current_page_top=NULL;
4911 table_data = (struct table_data*) table_widget->data;
4914 current_page_top = table_data->top_row;
4915 for(iterator = table_data->page_headers; iterator != NULL;
4916 iterator = g_list_next(iterator))
4918 if(current_page_top == iterator->data)
4922 table_data->top_row = (GList*) iterator->data;
4926 wm->state&= ~STATE_HIGHLIGHTED;
4927 gui_internal_menu_render(this);
4932 * @brief deallocates a table_data structure.
4935 void gui_internal_table_data_free(void * p)
4940 * @note button_box and its children (next_button,prev_button)
4941 * have their memory managed by the table itself.
4943 struct table_data * table_data = (struct table_data*) p;
4944 g_list_free(table_data->page_headers);
4952 * @brief Called when the route is updated.
4954 void gui_internal_route_update(struct gui_priv * this, struct navit * navit, struct vehicle *v)
4957 if(this->route_data.route_showing) {
4958 gui_internal_populate_route_table(this,navit);
4959 graphics_draw_mode(this->gra, draw_mode_begin);
4960 gui_internal_menu_render(this);
4961 graphics_draw_mode(this->gra, draw_mode_end);
4969 * @brief Called when the route screen is closed (deallocated).
4971 * The main purpose of this function is to remove the widgets from
4972 * references route_data because those widgets are about to be freed.
4974 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
4977 this_->route_data.route_showing=0;
4978 this_->route_data.route_table=NULL;
4985 * @brief Populates the route table with route information
4987 * @param this The gui context
4988 * @param navit The navit object
4990 void gui_internal_populate_route_table(struct gui_priv * this,
4991 struct navit * navit)
4993 struct map * map=NULL;
4994 struct map_rect * mr=NULL;
4995 struct navigation * nav = NULL;
4996 struct item * item =NULL;
4998 struct widget * label = NULL;
4999 struct widget * row = NULL;
5000 nav = navit_get_navigation(navit);
5004 map = navigation_get_map(nav);
5006 mr = map_rect_new(map,NULL);
5008 gui_internal_widget_table_clear(this,this->route_data.route_table);
5009 while((item = map_rect_get_item(mr))) {
5010 if(item_attr_get(item,attr_navigation_long,&attr)) {
5011 label = gui_internal_label_new(this,attr.u.str);
5012 row = gui_internal_widget_table_row_new(this,
5015 | orientation_horizontal);
5016 row->children=g_list_append(row->children,label);
5017 gui_internal_widget_append(this->route_data.route_table,row);