Add:Core:Made selection more flexible
[navit-package] / navit / gui / internal / gui_internal.c
index 33f2024..19052eb 100644 (file)
 #include <math.h>
 #include <glib.h>
 #include <time.h>
+#ifdef HAVE_API_WIN32_BASE
+#include <windows.h>
+#endif
 #include "config.h"
 #include "item.h"
 #include "file.h"
 #include "navit.h"
+#include "navit_nls.h"
 #include "debug.h"
 #include "gui.h"
 #include "coord.h"
@@ -49,8 +53,9 @@
 #include "layout.h"
 #include "callback.h"
 #include "vehicle.h"
+#include "vehicleprofile.h"
 #include "window.h"
-#include "main.h"
+#include "config_.h"
 #include "keys.h"
 #include "mapset.h"
 #include "route.h"
 #include "navigation.h"
 #include "gui_internal.h"
 #include "command.h"
+#include "xmlconfig.h"
+#include "util.h"
 
 struct menu_data {
        struct widget *search_list;
        struct widget *keyboard;
        struct widget *button_bar;
+       struct widget *menu;
        int keyboard_mode;
        void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
        struct widget *redisplay_widget;
 };
 
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 struct widget {
@@ -101,7 +109,7 @@ struct widget {
 
        /**
         * @brief a function that will be called as the widget is being destroyed.
-        * This function can act as a destructor for the widget. It allows for 
+        * This function can act as a destructor for the widget. It allows for
         * on deallocation actions to be specified on a per widget basis.
         * This function will call g_free on the widget (if required).
         */
@@ -109,6 +117,7 @@ struct widget {
        char *prefix;
        char *name;
        char *speech;
+       char *command;
        struct pcoord c;
        struct item item;
        int selection_id;
@@ -117,8 +126,10 @@ struct widget {
        int wmin,hmin;
        int w,h;
        int textw,texth;
+       int font_idx;
        int bl,br,bt,bb,spx,spy;
        int border;
+       int packed;
        /**
         * The number of widgets to layout horizontally when doing
         * a orientation_horizontal_vertical layout
@@ -136,17 +147,17 @@ struct widget {
        int is_on;
        int redraw;
        struct menu_data *menu_data;
-       GList *children;  
+       GList *children;
 };
 
 /**
  * @brief A structure to store configuration values.
  *
  * This structure stores configuration values for how gui elements in the internal GUI
- * should be drawn.  
+ * should be drawn.
  */
 struct gui_config_settings {
-  
+
   /**
    * The base size (in fractions of a point) to use for text.
    */
@@ -167,7 +178,7 @@ struct gui_config_settings {
    * The default amount of spacing (in pixels) to place between GUI elements.
    */
   int spacing;
-  
+
 };
 
 /**
@@ -179,14 +190,14 @@ const int SMALL_PROFILE=2;
 
 /**
  * The default config profiles.
- * 
+ *
  * [0] =>  LARGE_PROFILE (screens 640 in one dimension)
  * [1] =>  MEDIUM PROFILE (screens larger than 320 in one dimension
  * [2] => Small profile (default)
  */
 static struct gui_config_settings config_profiles[]={
       {545,32,48,96,10}
-    , {545,32,48,96,5}
+    , {300,32,48,64,3}
       ,{200,16,32,48,2}
 };
 
@@ -197,12 +208,13 @@ struct route_data {
 };
 
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 struct gui_priv {
        struct navit *nav;
+       struct attr self;
        struct window *win;
        struct graphics *gra;
        struct graphics_gc *background;
@@ -215,7 +227,7 @@ struct gui_priv {
        int spacing;
        int font_size;
        int fullscreen;
-       struct graphics_font *font;
+       struct graphics_font *fonts[3];
        int icon_xs, icon_s, icon_l;
        int pressed;
        struct widget *widgets;
@@ -226,9 +238,11 @@ struct gui_priv {
        struct widget *highlighted_menu;
        int clickp_valid, vehicle_valid;
        struct pcoord clickp, vehiclep;
+       struct attr *click_coord_geo, *position_coord_geo;
        struct search_list *sl;
        int ignore_button;
        int menu_on_map_click;
+       int signal_on_map_click;
        char *country_iso2;
        int speech;
        int keyboard;
@@ -238,7 +252,7 @@ struct gui_priv {
         */
         struct gui_config_settings config;
        struct event_idle *idle;
-       struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*idle_cb, *motion_timeout_callback;
+       struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
        struct event_timeout *motion_timeout_event;
        struct point current;
 
@@ -254,6 +268,40 @@ struct gui_priv {
        int cols;
        struct attr osd_configuration;
        int pitch;
+       int flags_town,flags_street,flags_house_number;
+/* html */
+       char *html_text;
+       int html_depth; 
+       struct widget *html_container;
+       int html_skip;
+       char *html_anchor;
+       int html_anchor_found;
+       struct html {
+               int skip;
+               enum html_tag {
+                       html_tag_none,
+                       html_tag_a,
+                       html_tag_h1,
+                       html_tag_html,
+                       html_tag_img,
+                       html_tag_script,
+               } tag;
+               char *command;
+               char *name;
+               char *href;
+               struct widget *w;
+       } html[10];
+};
+
+struct html_tag_map {
+       char *tag_name;
+       enum html_tag tag;
+} html_tag_map[] = {
+       {"a",html_tag_a},
+       {"h1",html_tag_h1},
+       {"html",html_tag_html},
+       {"img",html_tag_img},
+       {"script",html_tag_script},
 };
 
 
@@ -264,7 +312,7 @@ struct gui_priv {
  * table widget.
  *
  * The table_data structure needs to be freed with data_free along with the widget.
- * 
+ *
  */
 struct table_data
 {
@@ -300,7 +348,7 @@ struct table_data
    * A button widget to handle 'previous page' requests.
    */
   struct widget * prev_button;
-    
+
 
   /**
    * a pointer to the gui context.
@@ -339,7 +387,6 @@ static void gui_internal_apply_config(struct gui_priv *this);
 static struct widget* gui_internal_widget_table_new(struct gui_priv * this, enum flags flags, int buttons);
 static struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum flags flags);
 static void gui_internal_table_render(struct gui_priv * this, struct widget * w);
-static void gui_internal_cmd_route(struct gui_priv * this, struct widget * w,void *);
 static void gui_internal_table_pack(struct gui_priv * this, struct widget * w);
 static void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, void *data);
 static void gui_internal_table_button_prev(struct gui_priv * this, struct widget * wm, void *data);
@@ -361,9 +408,14 @@ static void gui_internal_search_town(struct gui_priv *this, struct widget *wm, v
 static void gui_internal_search_town_in_country(struct gui_priv *this, struct widget *wm);
 static void gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *data);
 static void gui_internal_check_exit(struct gui_priv *this);
+static void gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void *data);
 
 static struct widget *gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode);
 static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
+
+static int gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle *vehicle);
+static void gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor);
+
 /*
  * * Display image scaled to specific size
  * * searches for scaleable and pre-scaled image
@@ -374,45 +426,51 @@ static struct menu_data * gui_internal_menu_data(struct gui_priv *this);
  * * @returns image_struct Ptr to scaled image struct or NULL if not scaled or found
  * */
 static struct graphics_image *
-image_new_scaled(struct gui_priv *this, char *name, int w, int h)
+image_new_scaled(struct gui_priv *this, const char *name, int w, int h)
 {
        struct graphics_image *ret=NULL;
        char *full_name=NULL;
+       char *full_path=NULL;
        int i;
 
        for (i = 1 ; i < 6 ; i++) {
                full_name=NULL;
                switch (i) {
                case 3:
-                       full_name=g_strdup_printf("%s/xpm/%s.svg", getenv("NAVIT_SHAREDIR"), name);
+                       full_name=g_strdup_printf("%s.svg", name);
                        break;
                case 2:
-                       full_name=g_strdup_printf("%s/xpm/%s.svgz", getenv("NAVIT_SHAREDIR"), name);
+                       full_name=g_strdup_printf("%s.svgz", name);
                        break;
                case 1:
                        if (w != -1 && h != -1) {
-                               full_name=g_strdup_printf("%s/xpm/%s_%d_%d.png", getenv("NAVIT_SHAREDIR"), name, w, h);
+                               full_name=g_strdup_printf("%s_%d_%d.png", name, w, h);
                        }
                        break;
                case 4:
-                       full_name=g_strdup_printf("%s/xpm/%s.png", getenv("NAVIT_SHAREDIR"), name);
+                       full_name=g_strdup_printf("%s.png", name);
                        break;
                case 5:
-                       full_name=g_strdup_printf("%s/xpm/%s.xpm", getenv("NAVIT_SHAREDIR"), name);
+                       full_name=g_strdup_printf("%s.xpm", name);
                        break;
                }
                dbg(1,"trying '%s'\n", full_name);
                if (! full_name)
                        continue;
+#if 0
+               /* needs to be checked in the driver */
                if (!file_exists(full_name)) {
                        g_free(full_name);
                        continue;
                }
-               ret=graphics_image_new_scaled(this->gra, full_name, w, h);
+#endif
+               full_path=graphics_icon_path(full_name);
+               ret=graphics_image_new_scaled(this->gra, full_path, w, h);
                dbg(1,"ret=%p\n", ret);
+               g_free(full_path);
                g_free(full_name);
-               if (ret) 
-                       return ret;     
+               if (ret)
+                       return ret;
        }
        dbg(0,"failed to load %s with %d,%d\n", name, w, h);
        return NULL;
@@ -427,35 +485,31 @@ image_new_o(struct gui_priv *this, char *name)
 #endif
 
 static struct graphics_image *
-image_new_xs(struct gui_priv *this, char *name)
+image_new_xs(struct gui_priv *this, const char *name)
 {
        return image_new_scaled(this, name, this->icon_xs, this->icon_xs);
 }
 
 
 static struct graphics_image *
-image_new_s(struct gui_priv *this, char *name)
+image_new_s(struct gui_priv *this, const char *name)
 {
        return image_new_scaled(this, name, this->icon_s, this->icon_s);
 }
 
 static struct graphics_image *
-image_new_l(struct gui_priv *this, char *name)
+image_new_l(struct gui_priv *this, const char *name)
 {
        return image_new_scaled(this, name, this->icon_l, this->icon_l);
 }
 
 static char *
-coordinates(struct pcoord *pc, char sep)
+coordinates_geo(const struct coord_geo *gc, char sep)
 {
        char latc='N',lngc='E';
        int lat_deg,lat_min,lat_sec;
        int lng_deg,lng_min,lng_sec;
-       struct coord_geo g;
-       struct coord c;
-       c.x=pc->x;
-       c.y=pc->y;
-       transform_to_geo(pc->pro, &c, &g);
+       struct coord_geo g=*gc;
 
        if (g.lat < 0) {
                g.lat=-g.lat;
@@ -474,29 +528,43 @@ coordinates(struct pcoord *pc, char sep)
        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);
 }
 
+static char *
+coordinates(struct pcoord *pc, char sep)
+{
+       struct coord_geo g;
+       struct coord c;
+       c.x=pc->x;
+       c.y=pc->y;
+       transform_to_geo(pc->pro, &c, &g);
+       return coordinates_geo(&g, sep);
+
+}
+
 static void
 gui_internal_background_render(struct gui_priv *this, struct widget *w)
 {
        struct point pnt=w->p;
-       if (w->state & STATE_HIGHLIGHTED) 
+       if (w->state & STATE_HIGHLIGHTED)
                graphics_draw_rectangle(this->gra, this->highlight_background, &pnt, w->w, w->h);
        else {
                if (w->background)
                        graphics_draw_rectangle(this->gra, w->background, &pnt, w->w, w->h);
        }
 }
+
 static struct widget *
-gui_internal_label_new(struct gui_priv *this, char *text)
+gui_internal_label_font_new(struct gui_priv *this, char *text, int font)
 {
        struct point p[4];
        int w=0;
        int h=0;
-       
+
        struct widget *widget=g_new0(struct widget, 1);
        widget->type=widget_label;
+       widget->font_idx=font;
        if (text) {
                widget->text=g_strdup(text);
-               graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p, 0);
+               graphics_get_text_bbox(this->gra, this->fonts[font], text, 0x10000, 0x0, p, 0);
                w=p[2].x-p[0].x;
                h=p[0].y-p[2].y;
        }
@@ -512,6 +580,12 @@ gui_internal_label_new(struct gui_priv *this, char *text)
 }
 
 static struct widget *
+gui_internal_label_new(struct gui_priv *this, char *text)
+{
+       return gui_internal_label_font_new(this, text, 0);
+}
+
+static struct widget *
 gui_internal_label_new_abbrev(struct gui_priv *this, char *text, int maxwidth)
 {
        struct widget *ret=NULL;
@@ -569,10 +643,10 @@ gui_internal_label_render(struct gui_priv *this, struct widget *w)
                if (w->flags & gravity_right) {
                        pnt.y+=w->h-this->spacing;
                        pnt.x+=w->w-w->textw-this->spacing;
-                       graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
+                       graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], w->text, &pnt, 0x10000, 0x0);
                } else {
                        pnt.y+=w->h-this->spacing;
-                       graphics_draw_text(this->gra, w->foreground, w->text_background, this->font, w->text, &pnt, 0x10000, 0x0);
+                       graphics_draw_text(this->gra, w->foreground, w->text_background, this->fonts[w->font_idx], w->text, &pnt, 0x10000, 0x0);
                }
        }
 }
@@ -583,22 +657,28 @@ gui_internal_label_render(struct gui_priv *this, struct widget *w)
  *
  */
 static struct widget *
-gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
+gui_internal_text_font_new(struct gui_priv *this, char *text, int font, enum flags flags)
 {
        char *s=g_strdup(text),*s2,*tok;
        struct widget *ret=gui_internal_box_new(this, flags);
        s2=s;
        while ((tok=strtok(s2,"\n"))) {
-               gui_internal_widget_append(ret, gui_internal_label_new(this, tok));
+               gui_internal_widget_append(ret, gui_internal_label_font_new(this, tok, font));
                s2=NULL;
        }
        gui_internal_widget_pack(this,ret);
        return ret;
 }
 
+static struct widget *
+gui_internal_text_new(struct gui_priv *this, char *text, enum flags flags)
+{
+       return gui_internal_text_font_new(this, text, 0, flags);
+}
+
 
 static struct widget *
-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)
+gui_internal_button_font_new_with_callback(struct gui_priv *this, char *text, int font, struct graphics_image *image, enum flags flags, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data)
 {
        struct widget *ret=NULL;
        ret=gui_internal_box_new(this, flags);
@@ -606,7 +686,7 @@ gui_internal_button_new_with_callback(struct gui_priv *this, char *text, struct
                if (image)
                        gui_internal_widget_append(ret, gui_internal_image_new(this, image));
                if (text)
-                       gui_internal_widget_append(ret, gui_internal_text_new(this, text, gravity_center|orientation_vertical));
+                       gui_internal_widget_append(ret, gui_internal_text_font_new(this, text, font, gravity_center|orientation_vertical));
                ret->func=func;
                ret->data=data;
                if (func) {
@@ -618,6 +698,12 @@ gui_internal_button_new_with_callback(struct gui_priv *this, char *text, struct
 
 }
 
+static struct widget *
+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)
+{
+       return gui_internal_button_font_new_with_callback(this, text, 0, image, flags, func, data);
+}
+
 static int
 gui_internal_button_attr_update(struct gui_priv *this, struct widget *w)
 {
@@ -659,12 +745,12 @@ gui_internal_button_attr_callback(struct gui_priv *this, struct widget *w)
 static void
 gui_internal_button_attr_pressed(struct gui_priv *this, struct widget *w, void *data)
 {
-       if (w->is_on) 
+       if (w->is_on)
                w->set_attr(w->instance, &w->off);
        else
                w->set_attr(w->instance, &w->on);
        gui_internal_button_attr_update(this, w);
-       
+
 }
 
 static struct widget *
@@ -723,8 +809,8 @@ gui_internal_button_new(struct gui_priv *this, char *text, struct graphics_image
 
 #if 0
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static void gui_internal_clear(struct gui_priv *this)
@@ -743,17 +829,17 @@ gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
        struct widget *ret,*child;
        GList *l=wi->children;
 
-       if (p) { 
+       if (p) {
                if (wi->p.x > p->x )
                        return NULL;
                if (wi->p.y > p->y )
                        return NULL;
-               if ( wi->p.x + wi->w < p->x) 
+               if ( wi->p.x + wi->w < p->x)
                        return NULL;
-               if ( wi->p.y + wi->h < p->y) 
+               if ( wi->p.y + wi->h < p->y)
                        return NULL;
        }
-       if (wi->state & flags) 
+       if (wi->state & flags)
                return wi;
        while (l) {
                child=l->data;
@@ -764,7 +850,7 @@ gui_internal_find_widget(struct widget *wi, struct point *p, int flags)
                l=g_list_next(l);
        }
        return NULL;
-       
+
 }
 
 static void
@@ -772,11 +858,11 @@ gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
 {
        if (found == this->highlighted)
                return;
-       
+
        graphics_draw_mode(this->gra, draw_mode_begin);
        if (this->highlighted) {
                this->highlighted->state &= ~STATE_HIGHLIGHTED;
-               if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data) 
+               if (this->root.children && this->highlighted_menu == g_list_last(this->root.children)->data)
                        gui_internal_widget_render(this, this->highlighted);
                this->highlighted=NULL;
                this->highlighted_menu=NULL;
@@ -787,12 +873,12 @@ gui_internal_highlight_do(struct gui_priv *this, struct widget *found)
                this->highlighted->state |= STATE_HIGHLIGHTED;
                gui_internal_widget_render(this, this->highlighted);
                dbg(1,"%d,%d %dx%d\n", found->p.x, found->p.y, found->w, found->h);
-       }       
+       }
        graphics_draw_mode(this->gra, draw_mode_end);
 }
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static void gui_internal_highlight(struct gui_priv *this)
@@ -807,11 +893,11 @@ static void gui_internal_highlight(struct gui_priv *this)
 }
 
 static struct widget *
-gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, char *label)
+gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label)
 {
        struct widget *widget=g_new0(struct widget, 1);
 
-       if (label) 
+       if (label)
                widget->text=g_strdup(label);
        widget->type=widget_box;
        widget->flags=flags;
@@ -831,6 +917,10 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
        GList *l;
 
        gui_internal_background_render(this, w);
+#if 0
+       w->border=1;
+       w->foreground=this->foreground;
+#endif
 #if 1
        if (w->foreground && w->border) {
        struct point pnt[5];
@@ -850,7 +940,7 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
 
        l=w->children;
        while (l) {
-               wc=l->data;     
+               wc=l->data;
                gui_internal_widget_render(this, wc);
                l=g_list_next(l);
        }
@@ -865,24 +955,22 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w)
 static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
 {
        struct widget *wc;
-       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;
+       int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0;
        GList *l;
        int orientation=w->flags & 0xffff0000;
 
        if (!cols)
                cols=this->cols;
        if (!cols) {
-                height=navit_get_height(this->nav);
-                width=navit_get_width(this->nav);
-                if ( (height/width) > 1.0 )
+                if ( this->root.w > this->root.h )
                         cols=3;
                 else
                         cols=2;
                 width=0;
                 height=0;
        }
-       
-       
+
+
        /**
         * count the number of children
         */
@@ -897,7 +985,7 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
        case orientation_horizontal:
                /**
                 * For horizontal orientation:
-                * pack each child and find the largest height and 
+                * pack each child and find the largest height and
                 * compute the total width. x spacing (spx) is considered
                 *
                 * If any children want to be expanded
@@ -918,10 +1006,10 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                }
                owidth=width;
                if (expand && w->w) {
-                       expand=100*(w->w-width+expand)/expand;
+                       expandd=w->w-width+expand;
                        owidth=w->w;
-               } else
-                       expand=100;
+               } else 
+                       expandd=expand=1;
                break;
        case orientation_vertical:
                /**
@@ -947,10 +1035,10 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                }
                oheight=height;
                if (expand && w->h) {
-                       expand=100*(w->h-height+expand)/expand;
+                       expandd=w->h-height+expand;
                        oheight=w->h;
-               } else
-                       expand=100;
+               } else 
+                       expandd=expand=1;
                break;
        case orientation_horizontal_vertical:
                /**
@@ -967,7 +1055,7 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                        gui_internal_widget_pack(this, wc);
                        if (height < wc->h)
                                height=wc->h;
-                       if (width < wc->w) 
+                       if (width < wc->w)
                                width=wc->w;
                        l=g_list_next(l);
                        count++;
@@ -981,7 +1069,7 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                height+=w->spy*(rows-1);
                owidth=width;
                oheight=height;
-               expand=100;
+               expandd=expand=1;
                break;
        default:
                /**
@@ -997,7 +1085,12 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
        if (! w->w && ! w->h) {
                w->w=w->bl+w->br+width;
                w->h=w->bt+w->bb+height;
+               w->packed=1;
        }
+#if 0
+       if (expand < 100)
+               expand=100;
+#endif
 
        /**
         * At this stage the width and height of this
@@ -1006,7 +1099,7 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
         * widths and coordinates to each child widget.
         */
 
-       if (w->flags & gravity_left) 
+       if (w->flags & gravity_left)
                x=w->p.x+w->bl;
        if (w->flags & gravity_xcenter)
                x=w->p.x+w->w/2-owidth/2;
@@ -1014,9 +1107,9 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                x=w->p.x+w->w-w->br-owidth;
        if (w->flags & gravity_top)
                y=w->p.y+w->bt;
-       if (w->flags & gravity_ycenter) 
+       if (w->flags & gravity_ycenter)
                y=w->p.y+w->h/2-oheight/2;
-       if (w->flags & gravity_bottom) 
+       if (w->flags & gravity_bottom)
                y=w->p.y+w->h-w->bb-oheight;
        l=w->children;
        switch (orientation) {
@@ -1030,13 +1123,13 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                        if (wc->flags & flags_expand) {
                                if (! wc->w)
                                        wc->w=1;
-                               wc->w=wc->w*expand/100;
+                               wc->w=wc->w*expandd/expand;
                        }
-                       if (w->flags & gravity_top) 
+                       if (w->flags & gravity_top)
                                wc->p.y=y;
-                       if (w->flags & gravity_ycenter) 
+                       if (w->flags & gravity_ycenter)
                                wc->p.y=y-wc->h/2;
-                       if (w->flags & gravity_bottom) 
+                       if (w->flags & gravity_bottom)
                                wc->p.y=y-wc->h;
                        x+=wc->w+w->spx;
                        l=g_list_next(l);
@@ -1047,18 +1140,18 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                while (l) {
                        wc=l->data;
                        wc->p.y=y;
-                       if (wc->flags & flags_fill)
+                       if (wc->flags & flags_fill) 
                                wc->w=w->w;
                        if (wc->flags & flags_expand) {
                                if (! wc->h)
                                        wc->h=1;
-                               wc->h=wc->h*expand/100;
+                               wc->h=wc->h*expandd/expand;
                        }
-                       if (w->flags & gravity_left) 
+                       if (w->flags & gravity_left)
                                wc->p.x=x;
-                       if (w->flags & gravity_xcenter) 
+                       if (w->flags & gravity_xcenter)
                                wc->p.x=x-wc->w/2;
-                       if (w->flags & gravity_right) 
+                       if (w->flags & gravity_right)
                                wc->p.x=x-wc->w;
                        y+=wc->h+w->spy;
                        l=g_list_next(l);
@@ -1078,17 +1171,17 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
                                wc->w=width;
                                wc->h=height;
                        }
-                       if (w->flags & gravity_left) 
+                       if (w->flags & gravity_left)
                                wc->p.x=x;
-                       if (w->flags & gravity_xcenter) 
+                       if (w->flags & gravity_xcenter)
                                wc->p.x=x+(width-wc->w)/2;
-                       if (w->flags & gravity_right) 
+                       if (w->flags & gravity_right)
                                wc->p.x=x+width-wc->w;
-                       if (w->flags & gravity_top) 
+                       if (w->flags & gravity_top)
                                wc->p.y=y;
-                       if (w->flags & gravity_ycenter) 
+                       if (w->flags & gravity_ycenter)
                                wc->p.y=y+(height-wc->h)/2;
-                       if (w->flags & gravity_bottom) 
+                       if (w->flags & gravity_bottom)
                                wc->p.y=y-height-wc->h;
                        x+=width;
                        if (++count == cols) {
@@ -1109,13 +1202,31 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w)
         */
        l=w->children;
        while (l) {
-               wc=l->data;             
+               wc=l->data;
                gui_internal_widget_pack(this, wc);
                l=g_list_next(l);
        }
 }
 
 static void
+gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w)
+{
+       struct widget *wc;
+       GList *l;
+
+       l=w->children;
+       while (l) {
+               wc=l->data;
+               gui_internal_widget_reset_pack(this, wc);
+               l=g_list_next(l);
+       }
+       if (w->packed) {
+               w->w=0;
+               w->h=0;
+       }
+}
+
+static void
 gui_internal_widget_append(struct widget *parent, struct widget *child)
 {
        if (! child)
@@ -1150,6 +1261,7 @@ static void gui_internal_widget_children_destroy(struct gui_priv *this, struct w
 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
 {
        gui_internal_widget_children_destroy(this, w);
+       g_free(w->command);
        g_free(w->speech);
        g_free(w->text);
        if (w->img)
@@ -1172,7 +1284,7 @@ static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w)
 static void
 gui_internal_widget_render(struct gui_priv *this, struct widget *w)
 {
-       if(w->p.x > navit_get_width(this->nav) || w->p.y > navit_get_height(this->nav))
+       if(w->p.x > this->root.w || w->p.y > this->root.h)
                return;
 
        switch (w->type) {
@@ -1208,8 +1320,8 @@ gui_internal_widget_pack(struct gui_priv *this, struct widget *w)
 }
 
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static void gui_internal_call_highlighted(struct gui_priv *this)
@@ -1291,6 +1403,21 @@ gui_internal_cmd_return(struct gui_priv *this, struct widget *wm, void *data)
 }
 
 static void
+gui_internal_cmd2_back(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+       graphics_draw_mode(this->gra, draw_mode_begin);
+       gui_internal_back(this, NULL, NULL);
+       graphics_draw_mode(this->gra, draw_mode_end);
+       gui_internal_check_exit(this);  
+}
+
+static void
+gui_internal_cmd2_back_to_map(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+       gui_internal_prune_menu(this, NULL);
+}
+
+static void
 gui_internal_cmd_main_menu(struct gui_priv *this, struct widget *wm, void *data)
 {
        gui_internal_prune_menu(this, this->root.children->data);
@@ -1315,6 +1442,8 @@ gui_internal_top_bar(struct gui_priv *this)
        128:Show help
        256:Use background for menu headline
        512:Set osd_configuration and zoom to route when setting position
+       1024:Don't show back button
+       2048:No highlighting of keyboard
 */
 
        w=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|(this->flags & 1 ? 0:flags_fill));
@@ -1362,7 +1491,7 @@ gui_internal_top_bar(struct gui_priv *this)
                        wc=l->data;
                        wcn=gui_internal_label_new(this, wc->text);
                        wcn->foreground=foreground;
-                       if (g_list_next(l)) 
+                       if (g_list_next(l))
                                use_sep=1;
                        else
                                use_sep=0;
@@ -1386,7 +1515,7 @@ gui_internal_top_bar(struct gui_priv *this)
                        }
                        res=g_list_prepend(res, wcn);
                        if (this->flags & 8)
-                               break;  
+                               break;
                }
                l=g_list_previous(l);
        }
@@ -1479,7 +1608,7 @@ static void gui_internal_apply_config(struct gui_priv *this)
 {
   struct gui_config_settings *  current_config=0;
 
-  dbg(0,"w=%d h=%d\n", this->root.w, this->root.h);
+  dbg(1,"w=%d h=%d\n", this->root.w, this->root.h);
   /**
    * Select default values from profile based on the screen.
    */
@@ -1498,7 +1627,7 @@ static void gui_internal_apply_config(struct gui_priv *this)
   {
     current_config = &config_profiles[SMALL_PROFILE];
   }
-  
+
   /**
    * Apply override values from config file
    */
@@ -1519,7 +1648,7 @@ static void gui_internal_apply_config(struct gui_priv *this)
   {
     this->icon_xs = this->config.icon_xs;
   }
-  
+
   if(this->config.icon_s == -1 )
   {
     this->icon_s = current_config->icon_s;
@@ -1544,7 +1673,7 @@ static void gui_internal_apply_config(struct gui_priv *this)
   {
     this->spacing = current_config->spacing;
   }
-               
+
 }
 
 static struct widget *
@@ -1571,7 +1700,7 @@ gui_internal_button_label(struct gui_priv *this, char *label, int mode)
 
 
 static struct widget *
-gui_internal_menu(struct gui_priv *this, char *label)
+gui_internal_menu(struct gui_priv *this, const char *label)
 {
        struct widget *menu,*w,*w1,*topbox;
 
@@ -1585,7 +1714,11 @@ gui_internal_menu(struct gui_priv *this, char *label)
        menu->h=this->root.h;
        menu->background=this->background;
        gui_internal_apply_config(this);
-       this->font=graphics_font_new(this->gra,this->font_size,1);
+       if (!this->fonts[0]) {
+               this->fonts[0]=graphics_font_new(this->gra,this->font_size,1);
+               this->fonts[1]=graphics_font_new(this->gra,this->font_size*66/100,1);
+               this->fonts[2]=graphics_font_new(this->gra,this->font_size*50/100,1);
+       }
        topbox->menu_data=g_new0(struct menu_data, 1);
        gui_internal_widget_append(topbox, menu);
        w=gui_internal_top_bar(this);
@@ -1594,7 +1727,7 @@ gui_internal_menu(struct gui_priv *this, char *label)
        w->spx=4*this->spacing;
        w->w=menu->w;
        gui_internal_widget_append(menu, w);
-       if (this->flags & 16) {
+       if (this->flags & 16 && (!this->flags & 1024)) {
                struct widget *wlb,*wb,*wm=w;
                wm->flags=gravity_center|orientation_vertical|flags_expand|flags_fill;
                w=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_expand|flags_fill);
@@ -1623,6 +1756,12 @@ gui_internal_menu(struct gui_priv *this, char *label)
                gui_internal_widget_append(topbox, menu);
                menu->background=NULL;
        }
+       gui_internal_widget_pack(this, topbox);
+       gui_internal_widget_reset_pack(this, topbox);
+        topbox->w=this->root.w;
+        topbox->h=this->root.h;
+       menu->w=this->root.w;
+       menu->h=this->root.h;
        return w;
 }
 
@@ -1638,6 +1777,17 @@ gui_internal_menu_data(struct gui_priv *this)
 }
 
 static void
+gui_internal_menu_reset_pack(struct gui_priv *this)
+{
+       GList *l;
+       struct widget *top_box;
+
+       l=g_list_last(this->root.children);
+       top_box=l->data;
+       gui_internal_widget_reset_pack(this, top_box);
+}
+
+static void
 gui_internal_menu_render(struct gui_priv *this)
 {
        GList *l;
@@ -1653,9 +1803,9 @@ gui_internal_menu_render(struct gui_priv *this)
 static void
 gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void *data)
 {
-       struct widget *w=wm->data;
-       dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
-       navit_set_destination(this->nav, &w->c, w->name, 1);
+       char *name=data;
+       dbg(0,"c=%d:0x%x,0x%x\n", wm->c.pro, wm->c.x, wm->c.y);
+       navit_set_destination(this->nav, &wm->c, name, 1);
        if (this->flags & 512) {
                struct attr follow;
                follow.type=attr_follow;
@@ -1663,15 +1813,14 @@ gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void
                navit_set_attr(this->nav, &this->osd_configuration);
                navit_set_attr(this->nav, &follow);
                navit_zoom_to_route(this->nav, 0);
-       }       
+       }
        gui_internal_prune_menu(this, NULL);
 }
 
 static void
 gui_internal_cmd_set_position(struct gui_priv *this, struct widget *wm, void *data)
 {
-       struct widget *w=wm->data;
-       navit_set_position(this->nav, &w->c);
+       navit_set_position(this->nav, &wm->c);
        gui_internal_prune_menu(this, NULL);
 }
 
@@ -1680,7 +1829,7 @@ gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget)
 {
        GList *l;
        dbg(0,"text='%s'\n", widget->text);
-       if (widget->text && strlen(widget->text)) 
+       if (widget->text && strlen(widget->text))
                navit_add_bookmark(this->nav, &widget->c, widget->text);
        g_free(widget->text);
        widget->text=NULL;
@@ -1713,15 +1862,16 @@ gui_internal_cmd_add_bookmark_changed(struct gui_priv *this, struct widget *wm,
 static struct widget * gui_internal_keyboard(struct gui_priv *this, int mode);
 
 static void
-gui_internal_cmd_add_bookmark(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd_add_bookmark2(struct gui_priv *this, struct widget *wm, void *data)
 {
-       struct widget *w,*wb,*wk,*wl,*we,*wnext,*wp=wm->data;
-       wb=gui_internal_menu(this, "Add Bookmark");     
+       struct widget *w,*wb,*wk,*wl,*we,*wnext;
+       char *name=data;
+       wb=gui_internal_menu(this,_("Add Bookmark"));
        w=gui_internal_box_new(this, gravity_left_top|orientation_vertical|flags_expand|flags_fill);
        gui_internal_widget_append(wb, w);
        we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
        gui_internal_widget_append(w, we);
-       gui_internal_widget_append(we, wk=gui_internal_label_new(this, wp->name ? wp->name : wp->text));
+       gui_internal_widget_append(we, wk=gui_internal_label_new(this, name));
        wk->state |= STATE_EDIT|STATE_CLEAR;
        wk->background=this->background;
        wk->flags |= flags_expand|flags_fill;
@@ -1796,7 +1946,6 @@ struct selector {
                type_poi_police,type_poi_autoservice,
                type_poi_information,type_poi_information,
                type_poi_personal_service,type_poi_repair_service,
-               type_poi_rest_room,type_poi_rest_room,
                type_poi_restroom,type_poi_restroom,
                type_none}},
        {"parking","Parking",(enum item_type []){type_poi_car_parking,type_poi_car_parking,type_none}},
@@ -1805,7 +1954,8 @@ struct selector {
                type_poi_dam,type_poi_dam,
                type_none}},
        {"unknown","Other",(enum item_type []){
-               type_point_unspecified,type_poi_land_feature-1,
+               type_point_unspecified,type_point_unkn-1,
+               type_point_unkn+1,type_poi_land_feature-1,
                type_poi_rock+1,type_poi_fuel-1,
                type_poi_marina+1,type_poi_car_parking-1,
                type_poi_car_parking+1,type_poi_bar-1,
@@ -1818,6 +1968,9 @@ struct selector {
                type_poi_shop_grocery+1,type_poi_motel-1,
                type_poi_hostel+1,type_selected_point,
                type_none}},
+       {"unknown","Unknown",(enum item_type []){
+               type_point_unkn,type_point_unkn,
+               type_none}},
 };
 
 static void gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data);
@@ -1845,7 +1998,7 @@ gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct i
        char dirbuf[32];
        char *type;
        struct attr attr;
-       struct widget *wl;
+       struct widget *wl,*wt;
        char *text;
 
        wl=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
@@ -1860,7 +2013,9 @@ gui_internal_cmd_pois_item(struct gui_priv *this, struct coord *center, struct i
                wl->name=g_strdup(type);
        }
         text=g_strdup_printf("%s %s %s %s", distbuf, dirbuf, type, attr.u.str);
-       gui_internal_widget_append(wl, gui_internal_label_new(this, text));
+       wt=gui_internal_label_new(this, text);
+       wt->datai=dist;
+       gui_internal_widget_append(wl, wt);
        g_free(text);
 
        return wl;
@@ -1873,11 +2028,15 @@ gui_internal_cmd_pois_sort_num(gconstpointer a, gconstpointer b, gpointer user_d
        const struct widget *wb=b;
        struct widget *wac=wa->children->data;
        struct widget *wbc=wb->children->data;
+#if 0
        int ia,ib;
        ia=atoi(wac->text);
        ib=atoi(wbc->text);
 
        return ia-ib;
+#else
+       return wac->datai-wbc->datai;
+#endif
 }
 
 static int
@@ -1893,8 +2052,8 @@ gui_internal_cmd_pois_item_selected(struct selector *sel, enum item_type type)
                if (type >= types[0] && type <= types[1]) {
                        return 1;
                }
-               types+=2;       
-       }       
+               types+=2;
+       }
        return 0;
 }
 
@@ -1932,9 +2091,9 @@ gui_internal_cmd_pois(struct gui_priv *this, struct widget *wm, void *data)
                dbg(2,"mr=%p\n", mr);
                if (mr) {
                        while ((item=map_rect_get_item(mr))) {
-                               if (gui_internal_cmd_pois_item_selected(isel, item->type) && 
-                                   item_coord_get_pro(item, &c, 1, pro) && 
-                                   coord_rect_contains(&sel->u.c_rect, &c) && 
+                               if (gui_internal_cmd_pois_item_selected(isel, item->type) &&
+                                   item_coord_get_pro(item, &c, 1, pro) &&
+                                   coord_rect_contains(&sel->u.c_rect, &c) &&
                                    (idist=transform_distance(pro, &center, &c)) < dist) {
                                        gui_internal_widget_append(w2, wi=gui_internal_cmd_pois_item(this, &center, item, &c, idist));
                                        wi->func=gui_internal_cmd_position;
@@ -1960,17 +2119,71 @@ static void
 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
 {
        struct widget *w=wm->data;
-       int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
+       int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)5);
        if (highlight) {
+               enum item_type type;
+               if (w->item.type < type_line)
+                       type=type_selected_point;
+               else if (w->item.type < type_area)
+                       type=type_selected_point;
+               else
+                       type=type_selected_area;
                graphics_clear_selection(this->gra, NULL);
-               graphics_add_selection(this->gra, &w->item, NULL);
+               graphics_add_selection(this->gra, &w->item, type, NULL);
        }
-       navit_set_center(this->nav, &w->c);
+       navit_set_center(this->nav, &w->c, 1);
        gui_internal_prune_menu(this, NULL);
 }
 
 
 static void
+gui_internal_cmd_view_attribute_details(struct gui_priv *this, struct widget *wm, void *data)
+{
+       struct widget *w,*wb;
+       struct map_rect *mr;
+       struct item *item;
+       struct attr attr;
+       char *text,*url;
+       int i;
+
+       text=g_strdup_printf("Attribute %s",wm->name);
+       wb=gui_internal_menu(this, text);
+       g_free(text);
+       w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+       gui_internal_widget_append(wb, w);
+       mr=map_rect_new(wm->item.map, NULL);
+       item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
+       for (i = 0 ; i < wm->datai ; i++) {
+               item_attr_get(item, attr_any, &attr);
+       }
+       if (item_attr_get(item, attr_any, &attr)) {
+               url=NULL;
+               switch (attr.type) {
+               case attr_osm_nodeid:
+                       url=g_strdup_printf("http://www.openstreetmap.org/browse/node/%Ld\n",*attr.u.num64);
+                       break;
+               case attr_osm_wayid:
+                       url=g_strdup_printf("http://www.openstreetmap.org/browse/way/%Ld\n",*attr.u.num64);
+                       break;
+               case attr_osm_relationid:
+                       url=g_strdup_printf("http://www.openstreetmap.org/browse/relation/%Ld\n",*attr.u.num64);
+                       break;
+               default:
+                       break;
+               }
+               if (url) {      
+                       gui_internal_widget_append(w,
+                                       wb=gui_internal_button_new_with_callback(this, _("View in Browser"),
+                                               image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+                                               gui_internal_cmd_view_in_browser, NULL));
+                       wb->name=url;
+               }
+       }
+       map_rect_destroy(mr);
+       gui_internal_menu_render(this);
+}
+
+static void
 gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void *data)
 {
        struct widget *w,*wb;
@@ -1978,6 +2191,7 @@ gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void
        struct item *item;
        struct attr attr;
        char *text;
+       int count=0;
 
        dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
        wb=gui_internal_menu(this, "Attributes");
@@ -1992,7 +2206,10 @@ gui_internal_cmd_view_attributes(struct gui_priv *this, struct widget *wm, void
                        gui_internal_widget_append(w,
                        wb=gui_internal_button_new_with_callback(this, text,
                                NULL, gravity_left_center|orientation_horizontal|flags_fill,
-                               gui_internal_cmd_view_attributes, NULL));
+                               gui_internal_cmd_view_attribute_details, NULL));
+                       wb->name=g_strdup(text);
+                       wb->item=wm->item;
+                       wb->datai=count++;
                        g_free(text);
                }
        }
@@ -2008,17 +2225,21 @@ gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void
        struct attr attr;
        char *cmd=NULL;
 
-       dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
-       mr=map_rect_new(wm->item.map, NULL);
-       item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
-       dbg(0,"item=%p\n", item);
-       if (item) {
-               while(item_attr_get(item, attr_url_local, &attr)) {
-                       if (! cmd)
-                               cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
+       if (!wm->name) {
+               dbg(0,"item=%p 0x%x 0x%x\n", wm->item.map,wm->item.id_hi, wm->item.id_lo);
+               mr=map_rect_new(wm->item.map, NULL);
+               item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
+               dbg(0,"item=%p\n", item);
+               if (item) {
+                       while(item_attr_get(item, attr_url_local, &attr)) {
+                               if (! cmd)
+                                       cmd=g_strdup_printf("navit-browser.sh '%s' &",attr.u.str);
+                       }
                }
+               map_rect_destroy(mr);
+       } else {
+               cmd=g_strdup_printf("navit-browser.sh '%s' &",wm->name);
        }
-       map_rect_destroy(mr);
        if (cmd) {
 #ifdef HAVE_SYSTEM
                system(cmd);
@@ -2029,55 +2250,40 @@ gui_internal_cmd_view_in_browser(struct gui_priv *this, struct widget *wm, void
        }
 }
 
-/* wm->data: 0 Nothing special
-            1 Map Point
-            2 Item
-            3 Town 
-*/
-
-
 static void
-gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd_position_do(struct gui_priv *this, struct pcoord *pc_in, struct coord_geo *g_in, struct widget *wm, char *name, int flags)
 {
        struct widget *wb,*w,*wc,*wbc;
        struct coord_geo g;
+       struct pcoord pc;
        struct coord c;
-       char *coord,*name;
-       int display_attributes=(wm->data == (void *)2);
-       int display_view_on_map=(wm->data != (void *)1);
-       int display_items=(wm->data == (void *)1);
-       int display_streets=(wm->data == (void *)3);
-       int display_house_numbers=1;
-       if (wm->data == (void *)4) {
-               gui_internal_search_town_in_country(this, wm);
+       char *coord;
+
+       if (pc_in) {
+               pc=*pc_in;
+               c.x=pc.x;
+               c.y=pc.y;
+               dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
+               transform_to_geo(pc.pro, &c, &g);
+       } else if (g_in) {
+               struct attr attr;
+               if (!navit_get_attr(this->nav, attr_projection, &attr, NULL))
+                       return;
+               g=*g_in;
+               pc.pro=attr.u.projection;
+               transform_from_geo(pc.pro, &g, &c);
+               pc.x=c.x;
+               pc.y=c.y;
+       } else
                return;
-       }
-#if 0
-       switch ((int)wm->data) {
-               case 0:
-#endif
-                       c.x=wm->c.x;
-                       c.y=wm->c.y;
-                       dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
-                       transform_to_geo(wm->c.pro, &c, &g);
-#if 0
-                       break;
-               case 1:
-                       g=this->click;
-                       break;
-               case 2:
-                       g=this->vehicle;
-                       break;
-       }
-#endif
-       name=wm->name ? wm->name : wm->text;
+
        wb=gui_internal_menu(this, name);
        w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
        gui_internal_widget_append(wb, w);
-       coord=coordinates(&wm->c, ' ');
+       coord=coordinates(&pc, ' ');
        gui_internal_widget_append(w, gui_internal_label_new(this, coord));
        g_free(coord);
-       if (display_streets) {
+       if ((flags & 1) && wm) {
                gui_internal_widget_append(w,
                        wc=gui_internal_button_new_with_callback(this, _("Streets"),
                                image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
@@ -2085,7 +2291,7 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
                wc->item=wm->item;
                wc->selection_id=wm->selection_id;
        }
-       if (display_house_numbers) {
+       if ((flags & 2) && wm) {
                gui_internal_widget_append(w,
                        wc=gui_internal_button_new_with_callback(this, _("House numbers"),
                                image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
@@ -2093,14 +2299,14 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
                wc->item=wm->item;
                wc->selection_id=wm->selection_id;
        }
-       if (display_attributes) {
+       if ((flags & 4) && wm) {
                struct map_rect *mr;
                struct item *item;
                struct attr attr;
                mr=map_rect_new(wm->item.map, NULL);
                item = map_rect_get_item_byid(mr, wm->item.id_hi, wm->item.id_lo);
                if (item) {
-                       if (item_attr_get(item, attr_description, &attr)) 
+                       if (item_attr_get(item, attr_description, &attr))
                                gui_internal_widget_append(w, gui_internal_label_new(this, attr.u.str));
                        if (item_attr_get(item, attr_url_local, &attr)) {
                                gui_internal_widget_append(w,
@@ -2117,39 +2323,48 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
                }
                map_rect_destroy(mr);
        }
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Set as destination"),
-                       image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
-                       gui_internal_cmd_set_destination, wm));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Set as position"),
+       if (flags & 8) {
+               gui_internal_widget_append(w,
+                       wbc=gui_internal_button_new_with_callback(this, _("Set as destination"),
+                               image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+                               gui_internal_cmd_set_destination, g_strdup(name)));
+               wbc->data_free=g_free;
+               wbc->c=pc;
+       }
+       if (flags & 16) {
+               gui_internal_widget_append(w,
+                       wbc=gui_internal_button_new_with_callback(this, _("Set as position"),
                        image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
                        gui_internal_cmd_set_position, wm));
-       gui_internal_widget_append(w,
-               wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
-                       image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
-                       gui_internal_cmd_add_bookmark, wm));
-       wbc->c=wm->c;
-       gui_internal_widget_append(w,
-               wbc=gui_internal_button_new_with_callback(this, _("POIs"),
+               wbc->c=pc;
+       }
+       if (flags & 32) {
+               gui_internal_widget_append(w,
+                       wbc=gui_internal_button_new_with_callback(this, _("Add as bookmark"),
                        image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
-                       gui_internal_cmd_pois, NULL));
-       wbc->c=wm->c;
+                       gui_internal_cmd_add_bookmark2, g_strdup(name)));
+               wbc->data_free=g_free;
+               wbc->c=pc;
+       }
+       if (flags & 64) {
+               gui_internal_widget_append(w,
+                       wbc=gui_internal_button_new_with_callback(this, _("POIs"),
+                               image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
+                               gui_internal_cmd_pois, NULL));
+               wbc->c=pc;
+       }
 #if 0
        gui_internal_widget_append(w,
                gui_internal_button_new(this, "Add to tour",
                        image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
-       gui_internal_widget_append(w,
-               gui_internal_button_new(this, "Add as bookmark",
-                       image_new_o(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill));
 #endif
-       if (display_view_on_map) {
+       if (flags & 128) {
                gui_internal_widget_append(w,
                        gui_internal_button_new_with_callback(this, _("View on map"),
                                image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
                                gui_internal_cmd_view_on_map, wm));
        }
-       if (display_items) {
+       if (flags & 256) {
                int dist=10;
                struct mapset *ms;
                struct mapset_handle *h;
@@ -2186,7 +2401,7 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
                                                label=map_convert_string(m, attr.u.str);
                                                text=g_strdup_printf("%s %s", item_to_name(item->type), label);
                                                map_convert_free(label);
-                                       } else 
+                                       } else
                                                text=g_strdup_printf("%s", item_to_name(item->type));
                                        gui_internal_widget_append(w,
                                                wc=gui_internal_button_new_with_callback(this, text,
@@ -2205,31 +2420,108 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
                }
                mapset_close(h);
        }
-       
        gui_internal_menu_render(this);
 }
 
+
+/* wm->data: 0 Nothing special
+            1 Map Point
+            2 Item
+            3 Town
+            4 County
+            5 Street
+            6 House number 
+*/
+
+static void
+gui_internal_cmd_position(struct gui_priv *this, struct widget *wm, void *data)
+{
+       int flags;
+       switch ((int) wm->data) {
+       case 0:
+               flags=8|16|32|64|128|256;
+               break;
+       case 1:
+               flags=8|16|32|64|256;
+               break;
+       case 2:
+               flags=4|8|16|32|64;
+               break;
+       case 3:
+               flags=1|8|16|32|64|128;
+               flags &= this->flags_town;
+               break;
+       case 4:
+               gui_internal_search_town_in_country(this, wm);
+               return;
+       case 5:
+               flags=2|8|16|32|64|128;
+               flags &= this->flags_street;
+               break;
+       case 6:
+               flags=8|16|32|64|128;
+               flags &= this->flags_house_number;
+               break;
+       default:
+               return;
+       }
+       switch (flags) {
+       case 2:
+               gui_internal_search_house_number_in_street(this, wm, NULL);
+               return;
+       case 8:
+               gui_internal_cmd_set_destination(this, wm, NULL);
+               return;
+       }
+       gui_internal_cmd_position_do(this, &wm->c, NULL, wm, wm->name ? wm->name : wm->text, flags);
+}
+
+static void
+gui_internal_cmd2_position(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+       char *name=_("Position");
+       int flags=-1;
+
+       dbg(1,"enter\n");
+       if (!in || !in[0])
+               return;
+       if (!ATTR_IS_COORD_GEO(in[0]->type))
+               return;
+       if (in[1] && ATTR_IS_STRING(in[1]->type)) {
+               name=in[1]->u.str;
+               if (in[2] && ATTR_IS_INT(in[2]->type)) 
+                       flags=in[2]->u.num;
+       }
+       dbg(1,"flags=0x%x\n",flags);
+       gui_internal_cmd_position_do(this, NULL, in[0]->u.coord_geo, NULL, name, flags);
+}
+
 static void
 gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
 {
        struct attr attr,mattr;
        struct map_rect *mr=NULL;
        struct item *item;
-       char *label_full,*l,*prefix,*pos;
-       int len,plen,hassub;
+       char *label_full,*l,*prefix="",*pos;
+       int len,plen,hassub,found=0;
        struct widget *wb,*w,*wbm;
        GHashTable *hash;
        struct coord c;
+       char *text=_("Bookmarks");
+       if (wm && wm->text)
+               text=wm->text;
 
-
-       wb=gui_internal_menu(this, wm->text ? wm->text : _("Bookmarks"));
+       wb=gui_internal_menu(this, text);
        w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
        w->spy=this->spacing*3;
        gui_internal_widget_append(wb, w);
 
-       prefix=wm->prefix;
-       if (! prefix)
-               prefix="";
+       if (data)
+               prefix=data;
+       else {
+               if (wm && wm->prefix)
+                       prefix=wm->prefix;
+       }
        plen=strlen(prefix);
 
        if(navit_get_attr(this->nav, attr_bookmark_map, &mattr, NULL) && mattr.u.map && (mr=map_rect_new(mattr.u.map, NULL))) {
@@ -2265,6 +2557,11 @@ gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
                                                wbm->prefix=g_malloc(len+2);
                                                strncpy(wbm->prefix, label_full, len+1);
                                                wbm->prefix[len+1]='\0';
+                                               if (!l[0]) {
+                                                       gui_internal_cmd_set_destination(this, wbm, wbm->name);
+                                                       found=1;
+                                                       break;
+                                               }
                                        } else {
                                                gui_internal_widget_destroy(this, wbm);
                                        }
@@ -2275,7 +2572,20 @@ gui_internal_cmd_bookmarks(struct gui_priv *this, struct widget *wm, void *data)
                }
                g_hash_table_destroy(hash);
        }
-       gui_internal_menu_render(this);
+       if (found)
+               gui_internal_check_exit(this);
+       else
+               gui_internal_menu_render(this);
+}
+
+static void
+gui_internal_cmd2_bookmarks(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+       char *str=NULL;
+       if (in && in[0] && ATTR_IS_STRING(in[0]->type)) {
+               str=in[0]->u.str;
+       }
+       gui_internal_cmd_bookmarks(this, NULL, str);
 }
 
 static void gui_internal_keypress_do(struct gui_priv *this, char *key)
@@ -2291,7 +2601,7 @@ static void gui_internal_keypress_do(struct gui_priv *this, char *key)
                        dbg(0,"backspace\n");
                        if (wi->text && wi->text[0]) {
                                len=g_utf8_prev_char(wi->text+strlen(wi->text))-wi->text;
-                               wi->text[len]=' ';      
+                               wi->text[len]=' ';
                                text=g_strdup_printf("%s ", wi->text);
                        }
                } else {
@@ -2324,9 +2634,9 @@ gui_internal_cmd_keypress(struct gui_priv *this, struct widget *wm, void *data)
 {
        struct menu_data *md=gui_internal_menu_data(this);
        gui_internal_keypress_do(this, (char *) wm->data);
-       if (md->keyboard_mode == 2) 
+       if (md->keyboard_mode == 2)
                gui_internal_keyboard_do(this, md->keyboard, 10);
-       if (md->keyboard_mode == 26) 
+       if (md->keyboard_mode == 26)
                gui_internal_keyboard_do(this, md->keyboard, 34);
 }
 
@@ -2343,16 +2653,71 @@ gui_internal_search_idle_end(struct gui_priv *this)
        }
 }
 
+static char *
+postal_str(struct search_list_result *res, int level)
+{
+       char *ret=NULL;
+       if (res->town->common.postal)
+               ret=res->town->common.postal;
+       if (res->town->common.postal_mask)
+               ret=res->town->common.postal_mask;
+       if (level == 1)
+               return ret;
+       if (res->street->common.postal)
+               ret=res->street->common.postal;
+       if (res->street->common.postal_mask)
+               ret=res->street->common.postal_mask;
+       if (level == 2)
+               return ret;
+       if (res->house_number->common.postal)
+               ret=res->house_number->common.postal;
+       if (res->house_number->common.postal_mask)
+               ret=res->house_number->common.postal_mask;
+       return ret;
+}
+
+static char *
+district_str(struct search_list_result *res, int level)
+{
+       char *ret=NULL;
+       if (res->town->common.district_name)
+               ret=res->town->common.district_name;
+       if (level == 1)
+               return ret;
+       if (res->street->common.district_name)
+               ret=res->street->common.district_name;
+       if (level == 2)
+               return ret;
+       if (res->house_number->common.district_name)
+               ret=res->house_number->common.district_name;
+       return ret;
+}
+
+static char *
+town_str(struct search_list_result *res, int level, int flags)
+{
+       char *town=res->town->common.town_name;
+       char *district=district_str(res, level);
+       char *postal=postal_str(res, level);
+       char *postal_sep=" ";
+       char *district_begin=" (";
+       char *district_end=")";
+       if (!postal) 
+               postal_sep=postal="";
+       if (!district || (flags & 1)) 
+               district_begin=district_end=district="";
+       
+       return g_strdup_printf("%s%s%s%s%s%s", postal, postal_sep, town, district_begin, district, district_end);
+}
+
 static void
 gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *search_list, void *param)
 {
-       char *text=NULL,*name=NULL;
+       char *text=NULL,*text2=NULL,*name=NULL;
        struct search_list_result *res;
        struct widget *wc;
        struct item *item=NULL;
        GList *l;
-       static int cpt_res = 0;
-       cpt_res ++;
        static char possible_keys[256]="";
 
        res=search_list_get_result(this->sl);
@@ -2362,9 +2727,9 @@ gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *se
                struct widget *menu=g_list_last(this->root.children)->data;
                struct widget *wi=gui_internal_find_widget(menu, NULL, STATE_EDIT);
 
-               if (! strcmp(wm_name,"Town")) 
-                       trunk_name = g_strrstr(res->town->name, wi->text);
-               if (! strcmp(wm_name,"Street")) 
+               if (! strcmp(wm_name,"Town"))
+                       trunk_name = g_strrstr(res->town->common.town_name, wi->text);
+               if (! strcmp(wm_name,"Street"))
                        trunk_name = g_strrstr(name=res->street->name, wi->text);
 
                if (trunk_name) {
@@ -2377,16 +2742,15 @@ gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *se
                                possible_keys[len+1]='\0';
 
                        }
-                       dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->name, possible_keys);
+                       dbg(1,"%s %s possible_keys:%s \n", wi->text, res->town->common.town_name, possible_keys);
                }
        }
 
        if (! res) {
                gui_internal_search_idle_end(this);
-               cpt_res = 0;
 
                struct menu_data *md=gui_internal_menu_data(this);
-               if (md && md->keyboard) {
+               if (md && md->keyboard && !(this->flags & 2048)) {
                        GList *lk=md->keyboard->children;
                        graphics_draw_mode(this->gra, draw_mode_begin);
                        while (lk) {
@@ -2409,10 +2773,10 @@ gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *se
                                lk=g_list_next(lk);
                        }
                        gui_internal_widget_render(this,md->keyboard);
-                       graphics_draw_mode(this->gra, draw_mode_end);           
+                       graphics_draw_mode(this->gra, draw_mode_end);
                }
 
-               possible_keys[0]='\0'; 
+               possible_keys[0]='\0';
                return;
        }
 
@@ -2422,25 +2786,42 @@ gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *se
                text=g_strdup_printf("%s", res->country->name);
        }
        if (! strcmp(wm_name,"Town")) {
-               name=res->town->name;
                item=&res->town->common.item;
-               if (res->town->name && res->town->district)
-                       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);
-               else
-                       text=g_strdup_printf("%s%s%s", res->town->common.postal ? res->town->common.postal_mask : "", res->town->common.postal_mask ? " ":"", res->town->name);
+               name=res->town->common.town_name;
+               text=town_str(res, 1, 0);
        }
        if (! strcmp(wm_name,"Street")) {
                name=res->street->name;
                item=&res->street->common.item;
-               text=g_strdup_printf("%s %s", res->town->name, res->street->name);
+               text=g_strdup(res->street->name);
+               text2=town_str(res, 2, 1);
+       }
+       if (! strcmp(wm_name,"House number")) {
+               name=res->house_number->house_number;
+               text=g_strdup_printf("%s %s", res->street->name, name);
+               text2=town_str(res, 3, 0);
        }
        dbg(1,"res->country->flag=%s\n", res->country->flag);
-       if (cpt_res <= 2) {
+               if (!text2) {
                gui_internal_widget_append(search_list,
                                wc=gui_internal_button_new_with_callback(this, text,
                                        image_new_xs(this, res->country->flag),
                                        gravity_left_center|orientation_horizontal|flags_fill,
                                        gui_internal_cmd_position, param));
+               } else {
+                       struct widget *wb;
+                       wc=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+                       gui_internal_widget_append(wc, gui_internal_image_new(this, image_new_xs(this, res->country->flag)));
+                       wb=gui_internal_box_new(this, gravity_left_center|orientation_vertical|flags_fill);
+                       gui_internal_widget_append(wb, gui_internal_label_new(this, text));
+                       gui_internal_widget_append(wb, gui_internal_label_font_new(this, text2, 1));
+                       gui_internal_widget_append(wc, wb);
+                       wc->func=gui_internal_cmd_position;
+                       wc->data=param;
+                       wc->state |= STATE_SENSITIVE;
+                       wc->speech=g_strdup(text);
+                       gui_internal_widget_append(search_list, wc);
+               }
                wc->name=g_strdup(name);
                if (res->c)
                        wc->c=*res->c;
@@ -2452,8 +2833,8 @@ gui_internal_search_idle(struct gui_priv *this, char *wm_name, struct widget *se
                graphics_draw_mode(this->gra, draw_mode_begin);
                gui_internal_widget_render(this, l->data);
                graphics_draw_mode(this->gra, draw_mode_end);
-       }
        g_free(text);
+       g_free(text2);
 }
 
 static void
@@ -2480,10 +2861,12 @@ gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data
 
        void *param=(void *)3;
        int minlen=1;
-       if (! strcmp(wm->name,"Country")) {
+       if (! strcmp(wm->name,"Country")) 
                param=(void *)4;
-               minlen=1;
-       }
+       if (! strcmp(wm->name,"Street")) 
+               param=(void *)5;
+       if (! strcmp(wm->name,"House number")) 
+               param=(void *)6;
        dbg(0,"%s now '%s'\n", wm->name, wm->text);
 
        gui_internal_search_idle_end(this);
@@ -2508,16 +2891,16 @@ gui_internal_search_changed(struct gui_priv *this, struct widget *wm, void *data
 }
 
 static struct widget *
-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)
+gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char *text, int font, void(*func)(struct gui_priv *priv, struct widget *widget, void *data), void *data, void (*data_free)(void *data), int w, int h)
 {
        struct widget *wk;
-       gui_internal_widget_append(wkbd, wk=gui_internal_button_new_with_callback(this, text,
+       gui_internal_widget_append(wkbd, wk=gui_internal_button_font_new_with_callback(this, text, font,
                NULL, gravity_center|orientation_vertical, func, data));
        wk->data_free=data_free;
        wk->background=this->background;
        wk->bl=w/2;
        wk->br=0;
-       wk->bt=h/2;
+       wk->bt=h/3;
        wk->bb=0;
        return wk;
 }
@@ -2525,24 +2908,45 @@ gui_internal_keyboard_key_data(struct gui_priv *this, struct widget *wkbd, char
 static struct widget *
 gui_internal_keyboard_key(struct gui_priv *this, struct widget *wkbd, char *text, char *key, int w, int h)
 {
-       return gui_internal_keyboard_key_data(this, wkbd, text, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
+       return gui_internal_keyboard_key_data(this, wkbd, text, 0, gui_internal_cmd_keypress, g_strdup(key), g_free,w,h);
 }
 
 static void gui_internal_keyboard_change(struct gui_priv *this, struct widget *key, void *data);
 
+// Some macros that make the keyboard layout easier to visualise in
+// the source code. The macros are #undef'd after this function.
+#define KEY(x) gui_internal_keyboard_key(this, wkbd, (x), (x), max_w, max_h)
+#define SPACER() gui_internal_keyboard_key_data(this, wkbd, "", 0, NULL, NULL, NULL,max_w,max_h)
 static struct widget *
 gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
 {
        struct widget *wkbd,*wk;
        struct menu_data *md=gui_internal_menu_data(this);
-       int i, max_w=navit_get_width(this->nav), max_h=navit_get_height(this->nav);
+       int i, max_w=this->root.w, max_h=this->root.h;
        int render=0;
+       char *space="_";
+       char *backspace="←";
+       char *ucase="ABC";
+       int ucase_font=2;
+       char *lcase="abc";
+       int lcase_font=2;
+       char *numeric="123";
+       int numeric_font=2;
+       char *umlauts_ucase="ÄÖÜ";
+       int umlauts_ucase_font=2;
+       char *umlauts_lcase="äöü";
+       int umlauts_lcase_font=2;
+       char *hide="▼";
+       char *unhide="▲";
 
        if (wkbdb) {
                this->current.x=-1;
                this->current.y=-1;
                gui_internal_highlight(this);
-               render=1;
+               if (md->keyboard_mode >= 1024)
+                       render=2;
+               else
+                       render=1;
                gui_internal_widget_children_destroy(this, wkbdb);
        } else
                wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
@@ -2559,115 +2963,153 @@ gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
        if (mode >= 0 && mode < 8) {
                for (i = 0 ; i < 26 ; i++) {
                        char text[]={'A'+i,'\0'};
-                       gui_internal_keyboard_key(this, wkbd, text, text,max_w,max_h);
+                       KEY(text);
                }
-               gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
+               gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
                if (mode == 0) {
-                       gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
-                       gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
+                       KEY("-");
+                       KEY("'");
+                       wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+                       wk->datai=mode+1024;
                } else {
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
-                       wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
+                       wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+                       wk->datai=mode+1024;
+                       wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
                        wk->datai=mode+8;
-                       wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
+                       wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
                        wk->datai=mode+16;
                }
-               wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
+               wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change, wkbdb,NULL,max_w,max_h);
                wk->datai=mode+24;
-               gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
+               gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
        }
        if (mode >= 8 && mode < 16) {
                for (i = 0 ; i < 26 ; i++) {
                        char text[]={'a'+i,'\0'};
-                       gui_internal_keyboard_key(this, wkbd, text, text,max_w,max_h);
+                       KEY(text);
                }
-               gui_internal_keyboard_key(this, wkbd, "_"," ",max_w,max_h);
+               gui_internal_keyboard_key(this, wkbd, space," ",max_w,max_h);
                if (mode == 8) {
-                       gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
-                       gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
+                       KEY("-");
+                       KEY("'");
+                       wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+                       wk->datai=mode+1024;
                } else {
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
-                       wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
+                       wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+                       wk->datai=mode+1024;
+                       wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
                        wk->datai=mode-8;
-                       wk=gui_internal_keyboard_key_data(this, wkbd, "1", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
+                       wk=gui_internal_keyboard_key_data(this, wkbd, numeric, numeric_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
                        wk->datai=mode+8;
                }
-               wk=gui_internal_keyboard_key_data(this, wkbd, "ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
+               wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_lcase, umlauts_lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
                wk->datai=mode+24;
-               gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
+               gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
        }
        if (mode >= 16 && mode < 24) {
                for (i = 0 ; i < 10 ; i++) {
                        char text[]={'0'+i,'\0'};
-                       gui_internal_keyboard_key(this, wkbd, text, text,max_w,max_h);
-               }
-               gui_internal_keyboard_key(this, wkbd, ".",".",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "°","°",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "\"","\"",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "+","+",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "*","*",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "/","/",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "(","(",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, ")",")",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "=","=",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "?","?",max_w,max_h);
-               for (i = 0 ; i < 5 ; i++) {
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
+                       KEY(text);
                }
+               KEY("."); KEY("°"); KEY("'"); KEY("\""); KEY("-"); KEY("+");
+               KEY("*"); KEY("/"); KEY("("); KEY(")"); KEY("="); KEY("?");
+
+               for (i = 0 ; i < 5 ; i++) SPACER();
+
                if (mode == 16) {
-                       gui_internal_keyboard_key(this, wkbd, "-","-",max_w,max_h);
-                       gui_internal_keyboard_key(this, wkbd, "'","'",max_w,max_h);
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
+                       KEY("-");
+                       KEY("'");
+                       wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+                       wk->datai=mode+1024;
                } else {
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
-                       wk=gui_internal_keyboard_key_data(this, wkbd, "A", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
+                       wk=gui_internal_keyboard_key_data(this, wkbd, hide, 0, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
+                       wk->datai=mode+1024;
+                       wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
                        wk->datai=mode-16;
-                       wk=gui_internal_keyboard_key_data(this, wkbd, "a", gui_internal_keyboard_change, wkbd, NULL,max_w,max_h);
+                       wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change, wkbdb, NULL,max_w,max_h);
                        wk->datai=mode-8;
                }
-               wk=gui_internal_keyboard_key_data(this, wkbd, "Ä",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
+               wk=gui_internal_keyboard_key_data(this, wkbd, umlauts_ucase, umlauts_ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
                wk->datai=mode+8;
-               gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
+               gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
        }
        if (mode >= 24 && mode < 32) {
-               gui_internal_keyboard_key(this, wkbd, "Ä","Ä",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "Ö","Ö",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "Ü","Ü",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "Æ","Æ",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "Ø","Ø",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "Å","Å",max_w,max_h);
-               for (i = 0 ; i < 24 ; i++) {
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
-               }
-               wk=gui_internal_keyboard_key_data(this, wkbd, "A",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
+               KEY("Ä"); KEY("Ë"); KEY("Ï"); KEY("Ö"); KEY("Ü"); KEY("Æ"); KEY("Ø"); KEY("Å");
+               KEY("Á"); KEY("É"); KEY("Í"); KEY("Ó"); KEY("Ú"); KEY("Š"); KEY("Č"); KEY("Ž");
+               KEY("À"); KEY("È"); KEY("Ì"); KEY("Ò"); KEY("Ù"); KEY("Ś"); KEY("Ć"); KEY("Ź");
+               KEY("Â"); KEY("Ê"); KEY("Î"); KEY("Ô"); KEY("Û"); SPACER();
+
+               wk=gui_internal_keyboard_key_data(this, wkbd, ucase, ucase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
                wk->datai=mode-24;
-               gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
+
+               gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
        }
        if (mode >= 32 && mode < 40) {
-               gui_internal_keyboard_key(this, wkbd, "ä","ä",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "ö","ö",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "ü","ü",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "æ","æ",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "ø","ø",max_w,max_h);
-               gui_internal_keyboard_key(this, wkbd, "å","å",max_w,max_h);
-               for (i = 0 ; i < 24 ; i++) {
-                       gui_internal_keyboard_key_data(this, wkbd, "", NULL, NULL, NULL,max_w,max_h);
-               }
-               wk=gui_internal_keyboard_key_data(this, wkbd, "a",gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
+               KEY("ä"); KEY("ë"); KEY("ï"); KEY("ö"); KEY("ü"); KEY("æ"); KEY("ø"); KEY("å");
+               KEY("á"); KEY("é"); KEY("í"); KEY("ó"); KEY("ú"); KEY("š"); KEY("č"); KEY("ž");
+               KEY("à"); KEY("è"); KEY("ì"); KEY("ò"); KEY("ù"); KEY("ś"); KEY("ć"); KEY("ź");
+               KEY("â"); KEY("ê"); KEY("î"); KEY("ô"); KEY("û"); KEY("ß");
+
+               wk=gui_internal_keyboard_key_data(this, wkbd, lcase, lcase_font, gui_internal_keyboard_change,wkbdb,NULL,max_w,max_h);
                wk->datai=mode-24;
-               gui_internal_keyboard_key(this, wkbd, "<-","\b",max_w,max_h);
+
+               gui_internal_keyboard_key(this, wkbd, backspace,"\b",max_w,max_h);
+       }
+       if (mode >= 1024) {
+               char *text;
+               int font;
+               struct widget *wkl;
+               mode -= 1024;
+               if (mode >= 0 && mode < 8) {
+                       text=ucase;
+                       font=ucase_font;
+               }
+               if (mode >= 8 && mode < 16) {
+                       text=lcase;
+                       font=lcase_font;
+               }
+               if (mode >= 16 && mode < 24) {
+                       text=numeric;
+                       font=numeric_font;
+               }
+               if (mode >= 24 && mode < 32) {
+                       text=umlauts_ucase;
+                       font=umlauts_ucase_font;
+               }
+               if (mode >= 32 && mode < 40) {
+                       text=umlauts_lcase;
+                       font=umlauts_lcase_font;
+               }
+               wk=gui_internal_box_new(this, gravity_center|orientation_horizontal|flags_fill);
+               wk->func=gui_internal_keyboard_change;
+               wk->data=wkbdb;
+               wk->background=this->background;
+               wk->bl=max_w/2;
+               wk->br=0;
+               wk->bt=max_h/3;
+               wk->bb=0;
+               wk->datai=mode;
+               wk->state |= STATE_SENSITIVE;
+               gui_internal_widget_append(wk, wkl=gui_internal_label_new(this, unhide));
+               wkl->background=NULL;
+               gui_internal_widget_append(wk, wkl=gui_internal_label_font_new(this, text,font));
+               wkl->background=NULL;
+               gui_internal_widget_append(wkbd, wk);
+               if (render)
+                       render=2;
        }
        gui_internal_widget_append(wkbdb, wkbd);
-       if (render) {
+       if (render == 1) {
                gui_internal_widget_pack(this, wkbdb);
                gui_internal_widget_render(this, wkbdb);
+       } else if (render == 2) {
+               gui_internal_menu_reset_pack(this);
+               gui_internal_menu_render(this);
        }
        return wkbdb;
 }
+#undef KEY
+#undef SPACER
 
 static struct widget *
 gui_internal_keyboard(struct gui_priv *this, int mode)
@@ -2706,7 +3148,7 @@ gui_internal_search_list_set_default_country(struct gui_priv *this)
                        search_list_search(this->sl, &search_attr, 0);
                        while((res=search_list_get_result(this->sl)));
                        g_free(this->country_iso2);
-                       if (item_attr_get(item, attr_country_iso2, &country_iso2)) 
+                       if (item_attr_get(item, attr_country_iso2, &country_iso2))
                                this->country_iso2=g_strdup(country_iso2.u.str);
                }
                country_search_destroy(cs);
@@ -2747,6 +3189,7 @@ gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
 {
        struct widget *wb,*wk,*w,*wr,*we,*wl,*wnext=NULL;
        char *country;
+       int keyboard_mode=2;
        gui_internal_search_list_new(this);
        wb=gui_internal_menu(this, what);
        w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
@@ -2760,9 +3203,15 @@ gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
                wnext=gui_internal_image_new(this, image_new_xs(this, "gui_select_town"));
                wnext->func=gui_internal_search_town;
        } else if (!strcmp(type,"Town")) {
-               if (this->country_iso2)
+               if (this->country_iso2) {
+#if HAVE_API_ANDROID
+                       char country_iso2[strlen(this->country_iso2)+1];
+                       strtolower(country_iso2, this->country_iso2);
+                       country=g_strdup_printf("country_%s", country_iso2);
+#else
                        country=g_strdup_printf("country_%s", this->country_iso2);
-               else
+#endif
+               } else
                        country=strdup("gui_select_country");
                gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, country)));
                wb->state |= STATE_SENSITIVE;
@@ -2783,6 +3232,7 @@ gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
                gui_internal_widget_append(we, wb=gui_internal_image_new(this, image_new_xs(this, "gui_select_street")));
                wb->state |= STATE_SENSITIVE;
                wb->func = gui_internal_back;
+               keyboard_mode=18;
        }
        gui_internal_widget_append(we, wk=gui_internal_label_new(this, NULL));
        if (wnext) {
@@ -2798,7 +3248,7 @@ gui_internal_search(struct gui_priv *this, char *what, char *type, int flags)
        wk->func = gui_internal_search_changed;
        wk->name=g_strdup(type);
        if (this->keyboard)
-               gui_internal_widget_append(w, gui_internal_keyboard(this,2));
+               gui_internal_widget_append(w, gui_internal_keyboard(this,keyboard_mode));
        gui_internal_menu_render(this);
 }
 
@@ -2866,7 +3316,7 @@ gui_internal_search_country(struct gui_priv *this, struct widget *widget, void *
 }
 
 static void
-gui_internal_cmd_town(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd2_town(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
        if (this->sl)
                search_list_select(this->sl, attr_country_all, 0, 0);
@@ -2874,7 +3324,7 @@ gui_internal_cmd_town(struct gui_priv *this, struct widget *wm, void *data)
 }
 
 static void
-gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
        struct attr attr;
        struct widget *w,*wb,*wl;
@@ -2896,134 +3346,31 @@ gui_internal_cmd_layout(struct gui_priv *this, struct widget *wm, void *data)
 }
 
 static void
-gui_internal_cmd_fullscreen(struct gui_priv *this, struct widget *wm, void *data)
-{
-       graphics_draw_mode(this->gra, draw_mode_end);
-       this->fullscreen=!this->fullscreen;
-       this->win->fullscreen(this->win, this->fullscreen);
-       graphics_draw_mode(this->gra, draw_mode_begin);
-}
-
-static void
-gui_internal_cmd_2d(struct gui_priv *this, struct widget *wm, void *data)
-{
-       struct transformation *trans=navit_get_trans(this->nav);
-       transform_set_pitch(trans, 0);
-       this->redraw=1;
-}
-
-static void
-gui_internal_cmd_3d(struct gui_priv *this, struct widget *wm, void *data)
-{
-       struct transformation *trans=navit_get_trans(this->nav);
-       transform_set_pitch(trans, this->pitch);
-       this->redraw=1;
-}
-
-static void
-gui_internal_cmd_display(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd2_quit(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
-       struct widget *w;
-       struct transformation *trans;
-
-       w=gui_internal_menu(this, _("Display"));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Layout"),
-                       image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_layout, NULL));
-       if (this->fullscreen) {
-               gui_internal_widget_append(w,
-                       gui_internal_button_new_with_callback(this, _("Window Mode"),
-                               image_new_l(this, "gui_leave_fullscreen"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_fullscreen, NULL));
-       } else {
-               gui_internal_widget_append(w,
-                       gui_internal_button_new_with_callback(this, _("Fullscreen"),
-                               image_new_l(this, "gui_fullscreen"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_fullscreen, NULL));
-       }
-       trans=navit_get_trans(this->nav);
-       if (transform_get_pitch(trans)) {
-               gui_internal_widget_append(w,
-                       gui_internal_button_new_with_callback(this, _("2D"),
-                               image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_2d, NULL));
-               
-       } else {
-               gui_internal_widget_append(w,
-                       gui_internal_button_new_with_callback(this, _("3D"),
-                               image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_3d, NULL));
-       }
-       gui_internal_menu_render(this);
+       struct attr navit;
+       navit.type=attr_navit;
+       navit.u.navit=this->nav;
+       navit_destroy(navit.u.navit);
+       config_remove_attr(config, &navit);
+       event_main_loop_quit();
 }
 
 static void
-gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_window_closed(struct gui_priv *this)
 {
-       struct navit *nav=this->nav;
-       navit_destroy(nav);
-       main_remove_navit(nav);
+       gui_internal_cmd2_quit(this, NULL, NULL, NULL, NULL);
 }
 
 static void
-gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd2_abort_navigation(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
        navit_set_destination(this->nav, NULL, NULL, 0);
 }
 
 
 static void
-gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm, void *data)
-{
-       struct widget *w,*wc;
-       char *coord;
-
-       w=gui_internal_menu(this, _("Actions"));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Bookmarks"),
-                       image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_bookmarks, NULL));
-       if (this->clickp_valid) {
-               coord=coordinates(&this->clickp, '\n');
-               gui_internal_widget_append(w,
-                       wc=gui_internal_button_new_with_callback(this, coord,
-                               image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_position, (void *)1));
-               wc->name=g_strdup(_("Map Point"));
-               wc->c=this->clickp;
-               g_free(coord);
-       }
-       if (this->vehicle_valid) {
-               coord=coordinates(&this->vehiclep, '\n');
-               gui_internal_widget_append(w,
-                       wc=gui_internal_button_new_with_callback(this, coord,
-                               image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_position, NULL));
-               wc->name=g_strdup(_("Vehicle Position"));
-               wc->c=this->vehiclep;
-               g_free(coord);
-       }
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Town"),
-                       image_new_l(this, "gui_town"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_town, NULL));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Quit"),
-                       image_new_l(this, "gui_quit"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_quit, NULL));
-       
-       if (navit_check_route(this->nav)) {
-               gui_internal_widget_append(w,
-                                                                  gui_internal_button_new_with_callback(this, _("Stop\nNavigation"),
-                                                                image_new_l(this, "gui_stop"), gravity_center|orientation_vertical,
-                                                                gui_internal_cmd_abort_navigation, NULL));
-       }
-       gui_internal_menu_render(this);
-}
-
-static void
-gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm, void *wdata)
+gui_internal_cmd2_setting_maps(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
        struct attr attr, on, off, description, type, data;
        struct widget *w,*wb,*wma;
@@ -3056,7 +3403,7 @@ gui_internal_cmd_maps(struct gui_priv *this, struct widget *wm, void *wdata)
        }
        navit_attr_iter_destroy(iter);
        gui_internal_menu_render(this);
-       
+
 }
 static void
 gui_internal_cmd_set_active_vehicle(struct gui_priv *this, struct widget *wm, void *data)
@@ -3082,15 +3429,15 @@ gui_internal_cmd_show_satellite_status(struct gui_priv *this, struct widget *wm,
        gui_internal_widget_append(wb, w);
        w = gui_internal_widget_table_new(this,gravity_center | orientation_vertical | flags_expand | flags_fill, 0);
        row = gui_internal_widget_table_row_new(this,gravity_left_top);
-       gui_internal_widget_append(row, gui_internal_label_new(this, " PRN "));
-       gui_internal_widget_append(row, gui_internal_label_new(this, " Elevation "));
-       gui_internal_widget_append(row, gui_internal_label_new(this, " Azimuth "));
-       gui_internal_widget_append(row, gui_internal_label_new(this, " SNR "));
+       gui_internal_widget_append(row, gui_internal_label_new(this, _(" PRN ")));
+       gui_internal_widget_append(row, gui_internal_label_new(this, _(" Elevation ")));
+       gui_internal_widget_append(row, gui_internal_label_new(this, _(" Azimuth ")));
+       gui_internal_widget_append(row, gui_internal_label_new(this, _(" SNR ")));
        gui_internal_widget_append(w,row);
        while (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
                row = gui_internal_widget_table_row_new(this,gravity_left_top);
                for (i = 0 ; i < sizeof(types)/sizeof(enum attr_type) ; i++) {
-                       if (item_attr_get(attr.u.item, types[i], &sat_attr)) 
+                       if (item_attr_get(attr.u.item, types[i], &sat_attr))
                                str=g_strdup_printf("%d", sat_attr.u.num);
                        else
                                str=g_strdup("");
@@ -3114,29 +3461,177 @@ gui_internal_cmd_show_nmea_data(struct gui_priv *this, struct widget *wm, void *
        gui_internal_menu_data(this)->redisplay_widget=wm;
        w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
        gui_internal_widget_append(wb, w);
-       if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL)) 
+       if (vehicle_get_attr(v, attr_position_nmea, &attr, NULL))
                gui_internal_widget_append(w, gui_internal_text_new(this, attr.u.str, gravity_left_center|orientation_vertical));
        gui_internal_menu_render(this);
 }
 
+/**
+ * A container to hold the selected vehicle and the desired profile in
+ * one data item.
+ */
+struct vehicle_and_profilename {
+       struct vehicle *vehicle;
+       char *profilename;
+};
+
+/**
+ * Figures out whether the given vehicle is the active vehicle.
+ *
+ * @return true if the vehicle is active, false otherwise.
+ */
+static int
+gui_internal_is_active_vehicle(struct gui_priv *this, struct vehicle
+        *vehicle)
+{
+       struct attr active_vehicle;
+
+       if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
+        active_vehicle.u.vehicle=NULL;
+
+       return active_vehicle.u.vehicle == vehicle;
+}
+
+static void
+save_vehicle_xml(struct vehicle *v)
+{
+       struct attr attr;
+       struct attr_iter *iter=vehicle_attr_iter_new();
+       int childs=0;
+       dbg(0,"enter\n");
+       printf("<vehicle");
+       while (vehicle_get_attr(v, attr_any_xml, &attr, iter)) {
+               if (ATTR_IS_OBJECT(attr.type))
+                       childs=1;
+               else
+                       printf(" %s=\"%s\"",attr_to_name(attr.type),attr_to_text(&attr, NULL, 1));
+       }
+       if (childs) {
+               printf(">\n");
+               printf("</vehicle>\n");
+       } else
+               printf(" />\n");
+       vehicle_attr_iter_destroy(iter);
+}
+
+
+/**
+ * Reacts to a button press that changes a vehicle's active profile.
+ *
+ * @see gui_internal_add_vehicle_profile
+ */
+static void
+gui_internal_cmd_set_active_profile(struct gui_priv *this, struct
+               widget *wm, void *data)
+{
+       struct vehicle_and_profilename *vapn = data;
+       struct vehicle *v = vapn->vehicle;
+       char *profilename = vapn->profilename;
+       struct attr vehicle_name_attr;
+       char *vehicle_name = NULL;
+
+       // Get the vehicle name
+       vehicle_get_attr(v, attr_name, &vehicle_name_attr, NULL);
+       vehicle_name = vehicle_name_attr.u.str;
+
+       dbg(0, "Changing vehicle %s to profile %s\n", vehicle_name,
+                       profilename);
+
+       // Change the profile name
+       struct attr profilename_attr = {attr_profilename, {profilename}};
+       if(!vehicle_set_attr(v, &profilename_attr)) {
+               dbg(0, "Unable to set the vehicle's profile name\n");
+       }
+
+    // Notify Navit that the routing should be re-done if this is the
+    // active vehicle.
+       if (gui_internal_is_active_vehicle(this, v)) {
+               struct attr vehicle;
+               vehicle.type=attr_vehicle;
+               vehicle.u.vehicle=v;
+               navit_set_attr(this->nav, &vehicle);
+       }
+       save_vehicle_xml(v);
+}
+
+/**
+ * Adds the vehicle profile to the GUI, allowing the user to pick a
+ * profile for the currently selected vehicle.
+ */
+static void
+gui_internal_add_vehicle_profile(struct gui_priv *this, struct widget
+               *parent, struct vehicle *v, struct vehicleprofile *profile)
+{
+       // Just here to show up in the translation file, nice and close to
+       // where the translations are actually used.
+       struct attr profile_attr;
+       struct attr *attr = NULL;
+       char *name = NULL;
+       char *active_profile = NULL;
+       char *label = NULL;
+       int active;
+       struct vehicle_and_profilename *context = NULL;
+
+#ifdef ONLY_FOR_TRANSLATION
+       char *translations[] = {_n("car"), _n("bike"), _n("pedestrian")};
+#endif
+
+       // Figure out the profile name
+       attr = attr_search(profile->attrs, NULL, attr_name);
+       name = attr->u.str;
+
+       // Determine whether the profile is the active one
+       vehicle_get_attr(v, attr_profilename, &profile_attr, NULL);
+       active_profile = profile_attr.u.str;
+       active = strcmp(name, active_profile) == 0;
+
+       dbg(0, "Adding vehicle profile %s, active=%s/%i\n", name,
+                       active_profile, active);
+
+       // Build a translatable label.
+       if(active) {
+               label = g_strdup_printf(_("Current profile: %s"), _(name));
+       } else {
+               label = g_strdup_printf(_("Change profile to: %s"), _(name));
+       }
+
+       // Create the context object (the vehicle and the desired profile)
+       context = g_new0(struct vehicle_and_profilename, 1);
+       context->vehicle = v;
+       context->profilename = name;
+
+       // Add the button
+       gui_internal_widget_append(parent,
+               gui_internal_button_new_with_callback(
+                       this, label,
+                       image_new_xs(this, active ? "gui_active" : "gui_inactive"),
+                       gravity_left_center|orientation_horizontal|flags_fill,
+                       gui_internal_cmd_set_active_profile, context));
+
+       free(label);
+}
 
 static void
 gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void *data)
 {
        struct widget *w,*wb;
-       struct attr attr,active_vehicle;
+       struct attr attr;
        struct vehicle *v=wm->data;
+    struct vehicleprofile *profile = NULL;
+
        wb=gui_internal_menu(this, wm->text);
        w=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
        gui_internal_widget_append(wb, w);
-       if (!navit_get_attr(this->nav, attr_vehicle, &active_vehicle, NULL))
-               active_vehicle.u.vehicle=NULL;
-       if (active_vehicle.u.vehicle != v) {
+
+    // Add the "Set as active" button if this isn't the active
+    // vehicle.
+       if (!gui_internal_is_active_vehicle(this, v)) {
                gui_internal_widget_append(w,
                        gui_internal_button_new_with_callback(this, _("Set as active"),
                                image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
                                gui_internal_cmd_set_active_vehicle, wm->data));
        }
+
        if (vehicle_get_attr(v, attr_position_sat_item, &attr, NULL)) {
                gui_internal_widget_append(w,
                        gui_internal_button_new_with_callback(this, _("Show Satellite status"),
@@ -3149,12 +3644,21 @@ gui_internal_cmd_vehicle_settings(struct gui_priv *this, struct widget *wm, void
                                image_new_xs(this, "gui_active"), gravity_left_center|orientation_horizontal|flags_fill,
                                gui_internal_cmd_show_nmea_data, wm->data));
        }
+
+    // Add all the possible vehicle profiles to the menu
+       GList *profiles = navit_get_vehicleprofiles(this->nav);
+    while(profiles) {
+        profile = (struct vehicleprofile *)profiles->data;
+        gui_internal_add_vehicle_profile(this, w, v, profile);
+               profiles = g_list_next(profiles);
+    }
+
        callback_list_call_attr_2(this->cbl, attr_vehicle, w, wm->data);
        gui_internal_menu_render(this);
 }
 
 static void
-gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd2_setting_vehicle(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
        struct attr attr,vattr;
        struct widget *w,*wb,*wl;
@@ -3183,7 +3687,7 @@ gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm, void *data)
 
 
 static void
-gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm, void *data)
+gui_internal_cmd2_setting_rules(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
        struct widget *wb,*w;
        struct attr on,off;
@@ -3205,41 +3709,16 @@ gui_internal_cmd_rules(struct gui_priv *this, struct widget *wm, void *data)
                        &on, &off));
        on.u.num=1;
        off.u.num=0;
-       on.type=off.type=attr_cursor;
+       on.type=off.type=attr_follow_cursor;
        gui_internal_widget_append(w,
                gui_internal_button_navit_attr_new(this, _("Map follows Vehicle"), gravity_left_center|orientation_horizontal|flags_fill,
                        &on, &off));
        gui_internal_menu_render(this);
 }
 
-static void
-gui_internal_cmd_settings(struct gui_priv *this, struct widget *wm, void *data)
-{
-       struct widget *w;
-
-       w=gui_internal_menu(this, _("Settings"));       
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Display"),
-                       image_new_l(this, "gui_display"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_display, NULL));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Maps"),
-                       image_new_l(this, "gui_maps"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_maps, NULL));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Vehicle"),
-                       image_new_l(this, "gui_vehicle"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_vehicle, NULL));
-       gui_internal_widget_append(w,
-               gui_internal_button_new_with_callback(this, _("Rules"),
-                       image_new_l(this, "gui_rules"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_rules, NULL));
-       gui_internal_menu_render(this);
-}
-
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static void gui_internal_motion(void *data, struct point *p)
@@ -3259,39 +3738,217 @@ static void gui_internal_motion(void *data, struct point *p)
                this->motion_timeout_event=event_add_timeout(100,0, this->motion_timeout_callback);
 }
 
+static const char *
+find_attr(const char **names, const char **values, const char *name)
+{
+       while (*names) {
+               if (!strcasecmp(*names, name))
+                       return *values;
+               names+=xml_attr_distance;
+               values+=xml_attr_distance;
+       }
+       return NULL;
+}
 
-static void gui_internal_menu_root(struct gui_priv *this)
+static char *
+find_attr_dup(const char **names, const char **values, const char *name)
+{
+       return g_strdup(find_attr(names, values, name));
+}
+
+static void
+gui_internal_evaluate(struct gui_priv *this, const char *command)
 {
+       if (command)
+               command_evaluate(&this->self, command);
+}
+
+
+static void
+gui_internal_html_command(struct gui_priv *this, struct widget *w, void *data)
+{
+       gui_internal_evaluate(this,w->command);
+}
+
+static void
+gui_internal_html_href(struct gui_priv *this, struct widget *w, void *data)
+{
+       if (w->command && w->command[0] == '#') {
+               dbg(1,"href=%s\n",w->command);
+               gui_internal_html_menu(this, this->html_text, w->command+1);
+       }
+}
+
+
+static void
+gui_internal_html_start(void *dummy, const char *tag_name, const char **names, const char **values, void *data, void *error)
+{
+       struct gui_priv *this=data;
+       int i;
+       enum html_tag tag=html_tag_none;
+       struct html *html=&this->html[this->html_depth];
+       const char *src, *cond;
+
+       if (!strcasecmp(tag_name,"text"))
+               return;
+       html->command=NULL;
+       html->name=NULL;
+       html->href=NULL;
+       html->skip=0;
+       cond=find_attr(names, values, "cond");
+       
+       if (cond && !this->html_skip) {
+               if (!command_evaluate_to_boolean(&this->self, cond, NULL)) 
+                       html->skip=1;
+       }
+
+       for (i=0 ; i < sizeof(html_tag_map)/sizeof(struct html_tag_map); i++) {
+               if (!strcasecmp(html_tag_map[i].tag_name, tag_name)) {
+                       tag=html_tag_map[i].tag;
+                       break;
+               }
+       }
+       html->tag=tag;
+       if (!this->html_skip && !html->skip) {
+               switch (tag) {
+               case html_tag_a:
+                       html->name=find_attr_dup(names, values, "name");
+                       if (html->name) {
+                               html->skip=this->html_anchor ? strcmp(html->name,this->html_anchor) : 0;
+                               if (!html->skip)
+                                       this->html_anchor_found=1;
+                       }
+                       html->href=find_attr_dup(names, values, "href");
+                       break;
+               case html_tag_img:
+                       html->command=find_attr_dup(names, values, "onclick");
+                       src=find_attr(names, values, "src");
+                       if (src)
+                               html->w=gui_internal_image_new(this, image_new_l(this, src));
+                       break;
+               default:
+                       break;
+               }
+       }
+       this->html_skip+=html->skip;
+       this->html_depth++;
+}
+
+static void
+gui_internal_html_end(void *dummy, const char *tag_name, void *data, void *error)
+{
+       struct gui_priv *this=data;
+       struct html *html;
+       struct html *parent=NULL;
+
+       if (!strcasecmp(tag_name,"text"))
+               return;
+       this->html_depth--;
+       html=&this->html[this->html_depth];
+       if (this->html_depth > 0)
+               parent=&this->html[this->html_depth-1];
+       
+
+       if (!this->html_skip) { 
+               if (html->command && html->w) {
+                       html->w->state |= STATE_SENSITIVE;
+                       html->w->command=html->command;
+                       html->w->func=gui_internal_html_command;
+                       html->command=NULL;
+               }
+               if (parent && parent->href && html->w) {
+                       html->w->state |= STATE_SENSITIVE;
+                       html->w->command=g_strdup(parent->href);
+                       html->w->func=gui_internal_html_href;
+               }
+               switch (html->tag) {
+               case html_tag_img:
+                       gui_internal_widget_append(this->html_container, html->w);
+                       break;
+               default:
+                       break;
+               }
+       }
+       this->html_skip-=html->skip;
+       g_free(html->command);
+       g_free(html->name);
+       g_free(html->href);
+}
+
+static void
+gui_internal_html_text(void *dummy, const char *text, int len, void *data, void *error)
+{
+       struct gui_priv *this=data;
        struct widget *w;
+       int depth=this->html_depth-1;
+       struct html *html=&this->html[depth];
+       char *text_stripped;
 
+       if (this->html_skip)
+               return;
+       while (isspace(text[0])) {
+               text++;
+               len--;
+       }
+       while (len > 0 && isspace(text[len-1]))
+               len--;
+       text_stripped=g_malloc(len+1);
+       strncpy(text_stripped, text, len);
+       text_stripped[len]='\0';
+       if (html->tag == html_tag_html && depth > 2) {
+               if (this->html[depth-1].tag == html_tag_script) {
+                       html=&this->html[depth-2];
+               }
+       }
+       switch (html->tag) {
+       case html_tag_a:
+               if (html->name && len) {
+                       this->html_container=gui_internal_menu(this, gettext(text_stripped));
+                       this->html_container->spx=this->spacing*10;
+               }
+               break;
+       case html_tag_h1:
+               if (!this->html_container) {
+                       this->html_container=gui_internal_menu(this, gettext(text_stripped));
+                       this->html_container->spx=this->spacing*10;
+               }
+               break;
+       case html_tag_img:
+               if (len) {
+                       w=gui_internal_box_new(this, gravity_center|orientation_vertical);
+                       gui_internal_widget_append(w, html->w);
+                       gui_internal_widget_append(w, gui_internal_text_new(this, gettext(text_stripped), gravity_center|orientation_vertical));
+                       html->w=w;
+               }
+               break;
+       case html_tag_script:
+               dbg(1,"execute %s\n",text_stripped);
+               gui_internal_evaluate(this,text_stripped);
+               break;
+       default:
+               break;
+       }
+}
+
+static void
+gui_internal_html_menu(struct gui_priv *this, const char *document, char *anchor)
+{
        graphics_draw_mode(this->gra, draw_mode_begin);
-       w=gui_internal_menu(this, _("Main menu"));
-       w->spx=this->spacing*10;
-       gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Actions"),
-                       image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_actions, NULL));
-       if (this->flags & 2) {
-               gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Show\nMap"),
-                               image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
-                               gui_internal_cmd_settings, NULL));
-       }
-       gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Settings"),
-                       image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_settings, NULL));
-       gui_internal_widget_append(w, gui_internal_button_new(this, _("Tools"),
-                       image_new_l(this, "gui_tools"), gravity_center|orientation_vertical));
-
-       gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, "Route",
-                       image_new_l(this, "gui_settings"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_route, NULL));
-
-
-       callback_list_call_attr_1(this->cbl, attr_gui, w);
-                                                             
+       this->html_container=NULL;
+       this->html_depth=0;
+       this->html_anchor=anchor;
+       this->html_anchor_found=0;
+       xml_parse_text(document, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
        gui_internal_menu_render(this);
        graphics_draw_mode(this->gra, draw_mode_end);
 }
 
+
+static void gui_internal_menu_root(struct gui_priv *this)
+{
+       gui_internal_html_menu(this, this->html_text, "Main Menu");
+}
+
 static void
 gui_internal_enter(struct gui_priv *this, int ignore)
 {
@@ -3317,26 +3974,36 @@ gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
 {
        struct transformation *trans;
        struct coord c;
+       struct coord_geo g;
        struct attr attr,attrp;
 
+       dbg(1,"enter\n");
        gui_internal_enter(this, ignore);
        trans=navit_get_trans(this->nav);
+       attr_free(this->click_coord_geo);
+       this->click_coord_geo=NULL;
+       attr_free(this->position_coord_geo);
+       this->position_coord_geo=NULL;
        if (p) {
                transform_reverse(trans, p, &c);
-               dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
+               dbg(1,"x=0x%x y=0x%x\n", c.x, c.y);
                this->clickp.pro=transform_get_projection(trans);
                this->clickp.x=c.x;
                this->clickp.y=c.y;
-               this->clickp_valid=1;
+               transform_to_geo(this->clickp.pro, &c, &g);
+               attr.u.coord_geo=&g;
+               attr.type=attr_click_coord_geo;
+               this->click_coord_geo=attr_dup(&attr);
        }
        if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
                && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
+               this->position_coord_geo=attr_dup(&attrp);
                this->vehiclep.pro=transform_get_projection(trans);
                transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
                this->vehiclep.x=c.x;
                this->vehiclep.y=c.y;
                this->vehicle_valid=1;
-       }       
+       }
        // draw menu
        gui_internal_menu_root(this);
 }
@@ -3351,7 +4018,7 @@ gui_internal_cmd_menu2(struct gui_priv *this)
 static void
 gui_internal_cmd_log_do(struct gui_priv *this, struct widget *widget)
 {
-       if (widget->text && strlen(widget->text)) 
+       if (widget->text && strlen(widget->text))
                navit_textfile_debug_log(this->nav, "type=log_entry label=\"%s\"",widget->text);
        g_free(widget->text);
        widget->text=NULL;
@@ -3423,29 +4090,131 @@ gui_internal_check_exit(struct gui_priv *this)
        }
 }
 
+static int
+gui_internal_get_attr(struct gui_priv *this, enum attr_type type, struct attr *attr)
+{
+       switch (type) {
+       case attr_active:
+               attr->u.num=this->root.children != NULL;
+               break;
+       case attr_click_coord_geo:
+               if (!this->click_coord_geo)
+                       return 0;
+               *attr=*this->click_coord_geo;
+               break;
+       case attr_position_coord_geo:
+               if (!this->position_coord_geo)
+                       return 0;
+               *attr=*this->position_coord_geo;
+               break;
+       case attr_pitch:
+               attr->u.num=this->pitch;
+               break;
+       default:
+               return 0;
+       }
+       attr->type=type;
+       return 1;
+}
+
+static int
+gui_internal_add_attr(struct gui_priv *this, struct attr *attr)
+{
+       switch (attr->type) {
+       case attr_xml_text:
+               g_free(this->html_text);
+               this->html_text=g_strdup(attr->u.str);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+static int
+gui_internal_set_attr(struct gui_priv *this, struct attr *attr)
+{
+       switch (attr->type) {
+       case attr_fullscreen:
+               if ((this->fullscreen > 0) != (attr->u.num > 0)) {
+                       graphics_draw_mode(this->gra, draw_mode_end);
+                       this->win->fullscreen(this->win, attr->u.num > 0);
+                       graphics_draw_mode(this->gra, draw_mode_begin);
+               }
+               this->fullscreen=attr->u.num;
+               return 1;
+       default:
+               dbg(0,"%s\n",attr_to_name(attr->type));
+               return 0;
+       }
+}
+
+static void gui_internal_dbus_signal(struct gui_priv *this, struct point *p)
+{
+       struct displaylist_handle *dlh;
+       struct displaylist *display;
+       struct displayitem *di;
+
+       display=navit_get_displaylist(this->nav);
+       dlh=graphics_displaylist_open(display);
+       while ((di=graphics_displaylist_next(dlh))) {
+               struct item *item=graphics_displayitem_get_item(di);
+               if (item_is_point(*item) && graphics_displayitem_get_displayed(di) &&
+                       graphics_displayitem_within_dist(display, di, p, 10)) {
+                       struct map_rect *mr=map_rect_new(item->map, NULL);
+                       struct item *itemo=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
+                       struct attr attr;
+                       if (item_attr_get(itemo, attr_data, &attr)) {
+                               struct attr cb,*attr_list[2];
+                               int valid=0;
+                               attr.type=attr_data;
+                               attr_list[0]=&attr;
+                               attr_list[1]=NULL;
+                                       if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL)) 
+                                               callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
+                       }
+                       map_rect_destroy(mr);
+               }
+       }
+               graphics_displaylist_close(dlh);
+}
+
+
 //##############################################################################################################
 //# Description: Function to handle mouse clicks and scroll wheel movement
-//# Comment: 
+//# Comment:
 //# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
 //##############################################################################################################
 static void gui_internal_button(void *data, int pressed, int button, struct point *p)
 {
        struct gui_priv *this=data;
        struct graphics *gra=this->gra;
-       
+
        dbg(1,"enter %d %d\n", pressed, button);
        // if still on the map (not in the menu, yet):
+       dbg(1,"children=%p ignore_button=%d\n",this->root.children,this->ignore_button);
        if (!this->root.children || this->ignore_button) {
+
                this->ignore_button=0;
-               // check whether the position of the mouse changed during press/release OR if it is the scrollwheel 
-               if (!navit_handle_button(this->nav, pressed, button, p, NULL) || button >=4) // Maybe there's a better way to do this
+               // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
+               if (!navit_handle_button(this->nav, pressed, button, p, NULL)) {
+                       dbg(1,"navit has handled button\n");
+                       return;
+               }
+               dbg(1,"menu_on_map_click=%d\n",this->menu_on_map_click);
+               if (button != 1)
+                       return;
+               if (this->menu_on_map_click) {
+                       gui_internal_cmd_menu(this, p, 0);
+                       return;
+               }
+               if (this->signal_on_map_click) {
+                       gui_internal_dbus_signal(this, p);
                        return;
-               if (this->menu_on_map_click)
-                       gui_internal_cmd_menu(this, p, 0);      
+               }
                return;
        }
-       
-       
+
+
        // if already in the menu:
        if (pressed) {
                this->pressed=1;
@@ -3463,27 +4232,53 @@ static void gui_internal_button(void *data, int pressed, int button, struct poin
        }
 }
 
+static void
+gui_internal_setup_gc(struct gui_priv *this)
+{
+       struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
+       struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
+       struct graphics *gra=this->gra;
+
+       if (this->background)
+               return;
+       this->background=graphics_gc_new(gra);
+       this->background2=graphics_gc_new(gra);
+       this->highlight_background=graphics_gc_new(gra);
+       graphics_gc_set_foreground(this->highlight_background, &cbh);
+       this->foreground=graphics_gc_new(gra);
+       graphics_gc_set_foreground(this->foreground, &cf);
+       this->text_background=graphics_gc_new(gra);
+       this->text_foreground=graphics_gc_new(gra);
+       graphics_gc_set_foreground(this->background, &this->background_color);
+       graphics_gc_set_foreground(this->background2, &this->background2_color);
+       graphics_gc_set_foreground(this->text_background, &this->text_background_color);
+       graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
+}
+
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static void gui_internal_resize(void *data, int w, int h)
 {
        struct gui_priv *this=data;
+       int changed=0;
 
-       if( this->root.w==w && this->root.h==h)
-                return;
+       gui_internal_setup_gc(this);
 
-       this->root.w=w;
-       this->root.h=h;
-       dbg(0,"w=%d h=%d children=%p\n", w, h, this->root.children);
+       if (this->root.w != w || this->root.h != h) {
+               this->root.w=w;
+               this->root.h=h;
+               changed=1;
+       }
+       dbg(1,"w=%d h=%d children=%p\n", w, h, this->root.children);
        navit_handle_resize(this->nav, w, h);
-       if (this->root.children) {
+       if (this->root.children && changed) {
                gui_internal_prune_menu(this, NULL);
                gui_internal_menu_root(this);
        }
-} 
+}
 
 static void
 gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
@@ -3494,7 +4289,7 @@ gui_internal_keynav_point(struct widget *w, int dx, int dy, struct point *p)
                p->x=w->p.x;
        if (dx > 0)
                p->x=w->p.x+w->w;
-       if (dy < 0) 
+       if (dy < 0)
                p->y=w->p.y;
        if (dy > 0)
                p->y=w->p.y+w->h;
@@ -3582,8 +4377,8 @@ gui_internal_keynav_highlight_next(struct gui_priv *this, int dx, int dy)
 }
 
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static void gui_internal_keypress(void *data, char *key)
@@ -3597,22 +4392,22 @@ static void gui_internal_keypress(void *data, char *key)
                case NAVIT_KEY_UP:
                        p.x=w/2;
                        p.y=0;
-                       navit_set_center_screen(this->nav, &p);
+                       navit_set_center_screen(this->nav, &p, 1);
                        break;
                case NAVIT_KEY_DOWN:
                        p.x=w/2;
                        p.y=h;
-                       navit_set_center_screen(this->nav, &p);
+                       navit_set_center_screen(this->nav, &p, 1);
                        break;
                case NAVIT_KEY_LEFT:
                        p.x=0;
                        p.y=h/2;
-                       navit_set_center_screen(this->nav, &p);
+                       navit_set_center_screen(this->nav, &p, 1);
                        break;
                case NAVIT_KEY_RIGHT:
                        p.x=w;
                        p.y=h/2;
-                       navit_set_center_screen(this->nav, &p);
+                       navit_set_center_screen(this->nav, &p, 1);
                        break;
                case NAVIT_KEY_ZOOM_IN:
                        navit_zoom_in(this->nav, 2, NULL);
@@ -3621,6 +4416,7 @@ static void gui_internal_keypress(void *data, char *key)
                        navit_zoom_out(this->nav, 2, NULL);
                        break;
                case NAVIT_KEY_RETURN:
+               case NAVIT_KEY_MENU:
                        gui_internal_cmd_menu(this, NULL, 0);
                        break;
                }
@@ -3640,6 +4436,8 @@ static void gui_internal_keypress(void *data, char *key)
        case NAVIT_KEY_DOWN:
                gui_internal_keynav_highlight_next(this,0,1);
                break;
+       case NAVIT_KEY_BACK:
+               break;
        case NAVIT_KEY_RETURN:
                if (this->highlighted && this->highlighted_menu == g_list_last(this->root.children)->data)
                        gui_internal_call_highlighted(this);
@@ -3651,21 +4449,19 @@ static void gui_internal_keypress(void *data, char *key)
        }
        graphics_draw_mode(this->gra, draw_mode_end);
        gui_internal_check_exit(this);
-} 
+}
 
 
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
 {
        struct window *win;
-       struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
-       struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
        struct transformation *trans=navit_get_trans(this->nav);
-       
+
        win=graphics_get_data(gra, "window");
         if (! win)
                 return 1;
@@ -3682,22 +4478,15 @@ static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra
        graphics_add_callback(gra, this->motion_cb);
        this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
        graphics_add_callback(gra, this->keypress_cb);
-       this->background=graphics_gc_new(gra);
-       this->background2=graphics_gc_new(gra);
-       this->highlight_background=graphics_gc_new(gra);
-       graphics_gc_set_foreground(this->highlight_background, &cbh);
-       this->foreground=graphics_gc_new(gra);
-       graphics_gc_set_foreground(this->foreground, &cf);
-       this->text_background=graphics_gc_new(gra);
-       this->text_foreground=graphics_gc_new(gra);
-       graphics_gc_set_foreground(this->background, &this->background_color);
-       graphics_gc_set_foreground(this->background2, &this->background2_color);
-       graphics_gc_set_foreground(this->text_background, &this->text_background_color);
-       graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
-       
+       this->window_closed_cb=callback_new_attr_1(callback_cast(gui_internal_window_closed), attr_window_closed, this);
+       graphics_add_callback(gra, this->window_closed_cb);
+
        // set fullscreen if needed
        if (this->fullscreen)
-               this->win->fullscreen(this->win, this->fullscreen);
+               this->win->fullscreen(this->win, this->fullscreen != 0);
+       /* Was resize callback already issued? */
+       if (navit_get_ready(this->nav) & 2)
+               gui_internal_setup_gc(this);
        return 0;
 }
 
@@ -3708,8 +4497,8 @@ static void gui_internal_disable_suspend(struct gui_priv *this)
 }
 
 //##############################################################################################################
-//# Description: 
-//# Comment: 
+//# Description:
+//# Comment:
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
 struct gui_methods gui_internal_methods = {
@@ -3720,13 +4509,16 @@ struct gui_methods gui_internal_methods = {
        NULL,
        NULL,
        gui_internal_disable_suspend,
+       gui_internal_get_attr,
+       gui_internal_add_attr,
+       gui_internal_set_attr,
 };
 
 static void
 gui_internal_get_data(struct gui_priv *priv, char *command, struct attr **in, struct attr ***out)
 {
        struct attr private_data = (struct attr) { attr_private_data, {(void *)&priv->data}};
-       if (out)  
+       if (out)
                *out=attr_generic_add_attr(*out, &private_data);
 }
 
@@ -3752,7 +4544,7 @@ static struct gui_internal_methods gui_internal_methods_ext = {
 };
 
 
-static enum flags 
+static enum flags
 gui_internal_get_flags(struct widget *widget)
 {
        return widget->flags;
@@ -3782,164 +4574,65 @@ gui_internal_set_func(struct widget *widget, void (*func)(struct gui_priv *priv,
        widget->func=func;
 }
 
-static void
-gui_internal_set_data(struct widget *widget, void *data)
-{
-       widget->data=data;
-}
-
-static void
-gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
-{
-       widget->background=this->background;
-}
-
-static struct gui_internal_widget_methods gui_internal_widget_methods = {
-       gui_internal_widget_append,
-        gui_internal_button_new,
-        gui_internal_button_new_with_callback,
-        gui_internal_box_new,
-        gui_internal_label_new,
-        gui_internal_image_new,
-        gui_internal_keyboard,
-       gui_internal_menu,
-       gui_internal_get_flags,
-       gui_internal_set_flags,
-       gui_internal_get_state,
-       gui_internal_set_state,
-       gui_internal_set_func,
-       gui_internal_set_data,
-       gui_internal_set_default_background,
-};
-
-static struct command_table commands[] = {
-       {"menu",command_cast(gui_internal_cmd_menu2)},
-       {"fullscreen",command_cast(gui_internal_cmd_fullscreen)},
-       {"get_data",command_cast(gui_internal_get_data)},
-       {"log",command_cast(gui_internal_cmd_log)},
-};
-
-
-//##############################################################################################################
-//# Description: 
-//# Comment: 
-//# Authors: Martin Schaller (04/2008)
-//##############################################################################################################
-static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs) 
-{
-       struct gui_priv *this;
-       struct attr *attr;
-       *meth=gui_internal_methods;
-       this=g_new0(struct gui_priv, 1);
-       this->nav=nav;
-       if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
-               this->menu_on_map_click=attr->u.num;
-       else
-               this->menu_on_map_click=1;
-       if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
-               dbg(0,"register\n");
-               command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
-       }
-
-       if( (attr=attr_search(attrs,NULL,attr_font_size)))
-        {
-         this->config.font_size=attr->u.num;
-       }
-       else
-       {
-         this->config.font_size=-1;
-       }
-       if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
-       {
-         this->config.icon_xs=attr->u.num;
-       }
-       else
-       {
-         this->config.icon_xs=-1;
-       }
-       if( (attr=attr_search(attrs,NULL,attr_icon_l)))
-       {
-         this->config.icon_l=attr->u.num;
-       }
-       else
-        {
-         this->config.icon_l=-1;
-       }
-       if( (attr=attr_search(attrs,NULL,attr_icon_s)))
-       {
-         this->config.icon_s=attr->u.num;
-       }
-       else
-        {
-         this->config.icon_s=-1;
-       }
-       if( (attr=attr_search(attrs,NULL,attr_spacing)))
-       {
-         this->config.spacing=attr->u.num;
-       }
-       else
-       {
-         this->config.spacing=-1;        
-       }
-       if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
-       {
-         this->speech=attr->u.num;
-       }
-       if( (attr=attr_search(attrs,NULL,attr_keyboard)))
-         this->keyboard=attr->u.num;
-        else
-         this->keyboard=1;
-       
-    if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
-      this->fullscreen=attr->u.num;
-
-       if( (attr=attr_search(attrs,NULL,attr_flags)))
-             this->flags=attr->u.num;
-       if( (attr=attr_search(attrs,NULL,attr_background_color)))
-             this->background_color=*attr->u.color;
-       else
-             this->background_color=(struct color){0x0,0x0,0x0,0xffff};
-       if( (attr=attr_search(attrs,NULL,attr_background_color2))) 
-               this->background2_color=*attr->u.color;
-       else
-               this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
-       if( (attr=attr_search(attrs,NULL,attr_text_color)))
-             this->text_foreground_color=*attr->u.color;
-       else
-             this->text_foreground_color=(struct color){0xffff,0xffff,0xffff,0xffff};
-       if( (attr=attr_search(attrs,NULL,attr_columns)))
-             this->cols=attr->u.num;
-       if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
-             this->osd_configuration=*attr;
-
-       if( (attr=attr_search(attrs,NULL,attr_pitch)))
-             this->pitch=attr->u.num;
-       else
-               this->pitch=20;
-       this->data.priv=this;
-       this->data.gui=&gui_internal_methods_ext;
-       this->data.widget=&gui_internal_widget_methods;
-       this->cbl=callback_list_new();
-
-       return this;
+static void
+gui_internal_set_data(struct widget *widget, void *data)
+{
+       widget->data=data;
 }
 
-//##############################################################################################################
-//# Description: 
-//# Comment: 
-//# Authors: Martin Schaller (04/2008)
-//##############################################################################################################
-void plugin_init(void)
+static void
+gui_internal_set_default_background(struct gui_priv *this, struct widget *widget)
 {
-       plugin_register_gui_type("internal", gui_internal_new);
+       widget->background=this->background;
+}
+
+static struct gui_internal_widget_methods gui_internal_widget_methods = {
+       gui_internal_widget_append,
+        gui_internal_button_new,
+        gui_internal_button_new_with_callback,
+        gui_internal_box_new,
+        gui_internal_label_new,
+        gui_internal_image_new,
+        gui_internal_keyboard,
+       gui_internal_menu,
+       gui_internal_get_flags,
+       gui_internal_set_flags,
+       gui_internal_get_state,
+       gui_internal_set_state,
+       gui_internal_set_func,
+       gui_internal_set_data,
+       gui_internal_set_default_background,
+};
+
+static void
+gui_internal_cmd_write(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+       char *str=NULL,*str2=NULL;
+       dbg(1,"enter %s %p %p %p\n",function,in,out,valid);
+       if (!in || !in[0])
+               return;
+       dbg(1,"%s\n",attr_to_name(in[0]->type));        
+       if (ATTR_IS_STRING(in[0]->type)) {
+               str=in[0]->u.str;
+       }
+       if (ATTR_IS_COORD_GEO(in[0]->type)) {
+               str=str2=coordinates_geo(in[0]->u.coord_geo, '\n');
+       }
+       if (str) {
+               str=g_strdup_printf("<html>%s</html>\n",str);
+               xml_parse_text(str, this, gui_internal_html_start, gui_internal_html_end, gui_internal_html_text);
+       }
+       g_free(str);
+       g_free(str2);
 }
 
+
 /**
  * @brief Creates a new table widget.
- * 
+ *
  * Creates and returns a new table widget.  This function will
  * setup next/previous buttons as children.
- * 
+ *
  * @param this The graphics context.
  * @param flags widget sizing flags.
  * @returns The newly created widget
@@ -3953,7 +4646,7 @@ struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags
        widget->data = g_new0(struct table_data,1);
        widget->data_free=gui_internal_table_data_free;
        data = (struct table_data*)widget->data;
-       
+
 
        if (buttons) {
        data->next_button = gui_internal_button_new_with_callback
@@ -3961,18 +4654,18 @@ struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags
                 gravity_left_center  |orientation_vertical,
                 gui_internal_table_button_next,NULL);
        data->next_button->data=widget;
-       
-  
+
+
        data->prev_button =  gui_internal_button_new_with_callback
                (this,"Prev",
                 image_new_xs(this, "gui_active")
                 ,gravity_right_center |orientation_vertical,
                 gui_internal_table_button_prev,NULL);
-       
+
        data->prev_button->data=widget;
-       
+
        data->this=this;
-       
+
        data->button_box=gui_internal_box_new(this,
                                              gravity_center|orientation_horizontal);
        data->button_box->children=g_list_append(data->button_box->children,
@@ -3984,7 +4677,7 @@ struct widget * gui_internal_widget_table_new(struct gui_priv * this, enum flags
        widget->children=g_list_append(widget->children,data->button_box);
        gui_internal_widget_pack(this,data->button_box);
        }
-       
+
        return widget;
 
 }
@@ -3998,23 +4691,23 @@ void gui_internal_widget_table_clear(struct gui_priv * this,struct widget * tabl
 {
   GList * iter;
   struct table_data * table_data = (struct table_data* ) table->data;
-  
-  iter = table->children; 
+
+  iter = table->children;
   while(iter ) {
-         if(iter->data != table_data->button_box) {              
+         if(iter->data != table_data->button_box) {
                  struct widget * child = (struct widget*)iter->data;
                  gui_internal_widget_destroy(this,child);
-                 if(table->children == iter) {                   
+                 if(table->children == iter) {
                          table->children = g_list_remove(iter,iter->data);
                          iter=table->children;
                  }
-                 else 
+                 else
                          iter = g_list_remove(iter,iter->data);
          }
          else {
                  iter = g_list_next(iter);
          }
-    
+
   }
   table_data->top_row=NULL;
   table_data->bottom_row=NULL;
@@ -4053,7 +4746,7 @@ struct widget * gui_internal_widget_table_row_new(struct gui_priv * this, enum f
  */
 static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,struct widget * w)
 {
-  
+
        GList * column_desc = NULL;
        GList * current_desc=NULL;
        GList * cur_row = w->children;
@@ -4066,7 +4759,7 @@ static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,stru
        int width=0;
        int total_width=0;
        int column_count=0;
-  
+
        /**
         * Scroll through the the table and
         * 1. Compute the maximum width + height of each column across all rows.
@@ -4081,20 +4774,20 @@ static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,stru
                        continue;
                }
                column_count=0;
-               for(cur_column = cur_row_widget->children; cur_column; 
+               for(cur_column = cur_row_widget->children; cur_column;
                    cur_column=g_list_next(cur_column))
                {
                        cell_w = (struct widget*) cur_column->data;
                        gui_internal_widget_pack(this,cell_w);
-                       if(current_desc == 0) 
+                       if(current_desc == 0)
                        {
-                               current_cell = g_new0(struct table_column_desc,1);      
+                               current_cell = g_new0(struct table_column_desc,1);
                                column_desc = g_list_append(column_desc,current_cell);
                                current_desc = g_list_last(column_desc);
-                               current_cell->height=cell_w->h; 
-                               current_cell->width=cell_w->w; 
+                               current_cell->height=cell_w->h;
+                               current_cell->width=cell_w->w;
                                total_width+=cell_w->w;
-                               
+
                        }
                        else
                        {
@@ -4111,14 +4804,14 @@ static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,stru
                                        current_cell->width = width;
 
 
-                                       
+
                                }
                                current_desc = g_list_next(current_desc);
                        }
                        column_count++;
-                       
+
                }/* column loop */
-               
+
        } /*row loop */
 
 
@@ -4128,7 +4821,7 @@ static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,stru
         *
         */
        if(total_width+(this->spacing*column_count) < w->w ) {
-               for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) { 
+               for(current_desc=column_desc; current_desc; current_desc=g_list_next(current_desc)) {
                        current_cell = (struct table_column_desc*) current_desc->data;
                        current_cell->width= ( (current_cell->width+this->spacing)/(float)total_width) * w->w ;
                }
@@ -4150,7 +4843,7 @@ static GList * gui_internal_compute_table_dimensions(struct gui_priv * this,stru
  */
 void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
 {
-  
+
        int height=0;
        int width=0;
        int count=0;
@@ -4158,7 +4851,7 @@ void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
        GList * current=0;
        struct table_column_desc * cell_desc=0;
        struct table_data * table_data = (struct table_data*)w->data;
-       
+
        for(current = column_data; current; current=g_list_next(current))
        {
                if(table_data->button_box == current->data )
@@ -4167,7 +4860,7 @@ void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
                }
                cell_desc = (struct table_column_desc *) current->data;
                width = width + cell_desc->width + this->spacing;
-               if(height < cell_desc->height) 
+               if(height < cell_desc->height)
                {
                        height = cell_desc->height ;
                }
@@ -4183,7 +4876,7 @@ void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
                }
        }
        if (table_data->button_box)
-               gui_internal_widget_pack(this,table_data->button_box);  
+               gui_internal_widget_pack(this,table_data->button_box);
 
 
 
@@ -4191,12 +4884,12 @@ void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
        {
                /**
                 * Do not allow the widget to exceed the screen.
-                * 
+                *
                 */
                w->h = this->root.h- w->c.y  - height;
        }
        w->w = width;
-       
+
        /**
         * Deallocate column descriptions.
         */
@@ -4205,14 +4898,14 @@ void gui_internal_table_pack(struct gui_priv * this, struct widget * w)
        {
                current = g_list_remove(current,current->data);
        }
-       
+
 }
 
 
 
 /**
  * @brief Renders a table widget.
- * 
+ *
  * @param this The graphics context
  * @param w The table widget to render.
  */
@@ -4228,11 +4921,11 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
        int is_skipped=0;
        int is_first_page=1;
        struct table_column_desc * dim=NULL;
-       
+
        dbg_assert(table_data);
        column_desc = gui_internal_compute_table_dimensions(this,w);
        y=w->p.y;
-       
+
        /**
         * Skip rows that are on previous pages.
         */
@@ -4242,10 +4935,10 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
                cur_row = table_data->top_row;
                is_first_page=0;
        }
-       
-       
+
+
        /**
-        * Loop through each row.  Drawing each cell with the proper sizes, 
+        * Loop through each row.  Drawing each cell with the proper sizes,
         * at the proper positions.
         */
        for(table_data->top_row=cur_row; cur_row; cur_row = g_list_next(cur_row))
@@ -4254,13 +4947,13 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
                current_desc = column_desc;
                struct widget * cur_row_widget = (struct widget*)cur_row->data;
                int max_height=0;
-               x =w->p.x+this->spacing;        
+               x =w->p.x+this->spacing;
                if(cur_row_widget == table_data->button_box )
                {
                        continue;
                }
                dim = (struct table_column_desc*)current_desc->data;
-               
+
                if( y + dim->height + (table_data->button_box ? table_data->button_box->h : 0) + this->spacing >= w->p.y + w->h )
                {
                        /*
@@ -4268,26 +4961,26 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
                         */
                        is_skipped=1;
                        break;
-                       
-               }      
-               for(cur_column = cur_row_widget->children; cur_column; 
+
+               }
+               for(cur_column = cur_row_widget->children; cur_column;
                    cur_column=g_list_next(cur_column))
                {
                        struct  widget * cur_widget = (struct widget*) cur_column->data;
                        dim = (struct table_column_desc*)current_desc->data;
-                       
+
                        cur_widget->p.x=x;
                        cur_widget->w=dim->width;
                        cur_widget->p.y=y;
                        cur_widget->h=dim->height;
                        x=x+cur_widget->w;
                        max_height = dim->height;
-                       /* We pack the widget before rendering to ensure that the x and y 
+                       /* We pack the widget before rendering to ensure that the x and y
                         * coordinates get pushed down.
                         */
                        gui_internal_widget_pack(this,cur_widget);
                        gui_internal_widget_render(this,cur_widget);
-      
+
                        if(dim->height > max_height)
                        {
                                max_height = dim->height;
@@ -4299,28 +4992,28 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
        }
        if(table_data->button_box && (is_skipped || !is_first_page)  )
        {
-               table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h - 
+               table_data->button_box->p.y =w->p.y+w->h-table_data->button_box->h -
                        this->spacing;
                if(table_data->button_box->p.y < y )
                {
                        table_data->button_box->p.y=y;
-               }       
+               }
                table_data->button_box->p.x = w->p.x;
                table_data->button_box->w = w->w;
                //    table_data->button_box->h = w->h - y;
-               //    table_data->next_button->h=table_data->button_box->h;    
+               //    table_data->next_button->h=table_data->button_box->h;
                //    table_data->prev_button->h=table_data->button_box->h;
-               //    table_data->next_button->c.y=table_data->button_box->c.y;    
-               //    table_data->prev_button->c.y=table_data->button_box->c.y;    
+               //    table_data->next_button->c.y=table_data->button_box->c.y;
+               //    table_data->prev_button->c.y=table_data->button_box->c.y;
 
                gui_internal_widget_pack(this,table_data->button_box);
                if(table_data->next_button->p.y > w->p.y + w->h + table_data->next_button->h)
                {
-               
-                       table_data->button_box->p.y = w->p.y + w->h - 
+
+                       table_data->button_box->p.y = w->p.y + w->h -
                                table_data->button_box->h;
                }
-               if(is_skipped) 
+               if(is_skipped)
                {
                        table_data->next_button->state|= STATE_SENSITIVE;
                }
@@ -4328,7 +5021,7 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
                {
                        table_data->next_button->state&= ~STATE_SENSITIVE;
                }
-               
+
                if(table_data->top_row != w->children)
                {
                        table_data->prev_button->state|= STATE_SENSITIVE;
@@ -4338,10 +5031,10 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
                        table_data->prev_button->state&= ~STATE_SENSITIVE;
                }
                gui_internal_widget_render(this,table_data->button_box);
-               
+
 
        }
-       
+
        /**
         * Deallocate column descriptions.
         */
@@ -4361,7 +5054,7 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w)
  * @param v Unused
  */
 static void
-gui_internal_cmd_route_description(struct gui_priv * this, struct widget * wm,void *v)
+gui_internal_cmd2_route_description(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
 
 
@@ -4378,20 +5071,20 @@ gui_internal_cmd_route_description(struct gui_priv * this, struct widget * wm,vo
                                                       attr_position_coord_geo,this);
          navit_add_callback(this->nav,this->vehicle_cb);
        }
-       
+
        this->route_data.route_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
        row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
 
        row = gui_internal_widget_table_row_new(this,gravity_left | orientation_horizontal | flags_fill);
 
 
-       menu=gui_internal_menu(this,"Route Description");
-       
+       menu=gui_internal_menu(this,_("Route Description"));
+
        menu->free=gui_internal_route_screen_free;
        this->route_data.route_showing=1;
        this->route_data.route_table->spx = this->spacing;
 
-       
+
        struct widget * box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
 
        //      gui_internal_widget_append(box,gui_internal_box_new_with_label(this,"Test"));
@@ -4484,7 +5177,8 @@ item_get_heightline(struct item *item)
  * @param wm The button that was pressed.
  * @param v Unused
  */
-static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct widget * wm,void *v)
+static void
+gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
 
 
@@ -4506,7 +5200,7 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
        sel.order=18;
        sel.range.min=type_height_line_1;
        sel.range.max=type_height_line_3;
-       
+
 
        menu=gui_internal_menu(this,_("Height Profile"));
        box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
@@ -4523,7 +5217,7 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
                                        first=0;
                                        sel.u.c_rect.lu=c;
                                        sel.u.c_rect.rl=c;
-                               } else 
+                               } else
                                        coord_rect_extend(&sel.u.c_rect, &c);
                        }
                }
@@ -4546,7 +5240,7 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
                                        map_rect_destroy(mr);
                                }
                        }
-                       mapset_close(msh);      
+                       mapset_close(msh);
                }
        }
        map=NULL;
@@ -4559,7 +5253,7 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
                while((item = map_rect_get_item(mr))) {
                        first=1;
                        while (item_coord_get(item, &c, 1)) {
-                               if (first) 
+                               if (first)
                                        first=0;
                                else {
                                        heightline=heightlines;
@@ -4587,12 +5281,12 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
                                }
                                last=c;
                        }
-                       
+
                }
                map_rect_destroy(mr);
        }
-       
-       
+
+
        gui_internal_menu_render(this);
        first=1;
        diagram_point=diagram_points;
@@ -4618,7 +5312,7 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
                min=NULL;
                diagram_point=diagram_points;
                while (diagram_point) {
-                       if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x)) 
+                       if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
                                min=diagram_point;
                        diagram_point=diagram_point->next;
                }
@@ -4635,38 +5329,50 @@ static void gui_internal_cmd_route_height_profile(struct gui_priv * this, struct
                p[0]=p[1];
                x=min->c.x+1;
        }
-       
+
 
 }
 
-/**
- * @brief Displays Route information
- *
- * @li The name of the active vehicle
- * @param wm The button that was pressed.
- * @param v Unused
-               */
-void gui_internal_cmd_route(struct gui_priv * this, struct widget * wm,void *v)
+static void
+gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
-       struct widget *w;
+       struct widget *menu,*wb,*w;
+       char *text;
 
        graphics_draw_mode(this->gra, draw_mode_begin);
-       w=gui_internal_menu(this, _("Route"));
-       w->spx=this->spacing*10;
-       gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Description"),
-                       image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_route_description, NULL));
-       gui_internal_widget_append(w, gui_internal_button_new_with_callback(this, _("Height Profile"),
-                       image_new_l(this, "gui_actions"), gravity_center|orientation_vertical,
-                       gui_internal_cmd_route_height_profile, NULL));
-       gui_internal_menu_render(this);
+       menu=gui_internal_menu(this, _("Show Locale"));
+       menu->spx=this->spacing*10;
+       wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+       gui_internal_widget_append(menu, wb);
+       text=g_strdup_printf("LANG=%s",getenv("LANG"));
+       gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+       w->flags=gravity_left_center|orientation_horizontal|flags_fill;
+       g_free(text);
+#ifdef HAVE_API_WIN32_BASE
+       {
+               wchar_t wcountry[32],wlang[32];
+               char country[32],lang[32];
+
+               GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wlang, sizeof(wlang));
+               WideCharToMultiByte(CP_ACP,0,wlang,-1,lang,sizeof(lang),NULL,NULL);
+               text=g_strdup_printf("LOCALE_SABBREVLANGNAME=%s",lang);
+               gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+               w->flags=gravity_left_center|orientation_horizontal|flags_fill;
+               g_free(text);
+               GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wcountry, sizeof(wcountry));
+               WideCharToMultiByte(CP_ACP,0,wcountry,-1,country,sizeof(country),NULL,NULL);
+               text=g_strdup_printf("LOCALE_SABBREVCTRYNAME=%s",country);
+               gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+               w->flags=gravity_left_center|orientation_horizontal|flags_fill;
+               g_free(text);
+       }
+#endif
+
        gui_internal_menu_render(this);
        graphics_draw_mode(this->gra, draw_mode_end);
-
 }
 
 
-
 /**
  * @brief handles the 'next page' table event.
  * A callback function that is invoked when the 'next page' button is pressed
@@ -4681,17 +5387,17 @@ static void gui_internal_table_button_next(struct gui_priv * this, struct widget
        struct table_data * table_data = NULL;
        int found=0;
        GList * iterator;
-       
+
        if(table_widget)
        {
                table_data = (struct table_data*) table_widget->data;
-               
+
        }
        if(table_data)
        {
                /**
                 * Before advancing to the next page we need to ensure
-                * that the current top_row is in the list of previous top_rows 
+                * that the current top_row is in the list of previous top_rows
                 * so previous page can work.
                 *
                 */
@@ -4703,14 +5409,14 @@ static void gui_internal_table_button_next(struct gui_priv * this, struct widget
                                found=1;
                                break;
                        }
-                       
+
                }
                if( ! found)
                {
                        table_data->page_headers=g_list_append(table_data->page_headers,
                                                               table_data->top_row);
                }
-               
+
                table_data->top_row = g_list_next(table_data->bottom_row);
        }
        wm->state&= ~STATE_HIGHLIGHTED;
@@ -4737,7 +5443,7 @@ static void gui_internal_table_button_prev(struct gui_priv * this, struct widget
        if(table_widget)
        {
                table_data = (struct table_data*) table_widget->data;
-               if(table_data) 
+               if(table_data)
                {
                        current_page_top = table_data->top_row;
                        for(iterator = table_data->page_headers; iterator != NULL;
@@ -4783,20 +5489,20 @@ void gui_internal_route_update(struct gui_priv * this, struct navit * navit, str
 {
 
        if(this->route_data.route_showing) {
-               gui_internal_populate_route_table(this,navit);    
+               gui_internal_populate_route_table(this,navit);
                graphics_draw_mode(this->gra, draw_mode_begin);
                gui_internal_menu_render(this);
                graphics_draw_mode(this->gra, draw_mode_end);
        }
 
-       
+
 }
 
 
 /**
  * @brief Called when the route screen is closed (deallocated).
  *
- * The main purpose of this function is to remove the widgets from 
+ * The main purpose of this function is to remove the widgets from
  * references route_data because those widgets are about to be freed.
  */
 void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
@@ -4806,7 +5512,7 @@ void gui_internal_route_screen_free(struct gui_priv * this_,struct widget * w)
                this_->route_data.route_table=NULL;
                g_free(w);
        }
-  
+
 }
 
 /**
@@ -4838,14 +5544,170 @@ void gui_internal_populate_route_table(struct gui_priv * this,
                        if(item_attr_get(item,attr_navigation_long,&attr)) {
                          label = gui_internal_label_new(this,attr.u.str);
                          row = gui_internal_widget_table_row_new(this,
-                                                                 gravity_left 
-                                                                 | flags_fill 
+                                                                 gravity_left
+                                                                 | flags_fill
                                                                  | orientation_horizontal);
                          row->children=g_list_append(row->children,label);
                          gui_internal_widget_append(this->route_data.route_table,row);
                        }
-                       
+
                }
-               
-       }                            
+
+       }
+}
+
+static struct command_table commands[] = {
+       {"abort_navigation",command_cast(gui_internal_cmd2_abort_navigation)},
+       {"back",command_cast(gui_internal_cmd2_back)},
+       {"back_to_map",command_cast(gui_internal_cmd2_back_to_map)},
+       {"bookmarks",command_cast(gui_internal_cmd2_bookmarks)},
+       {"get_data",command_cast(gui_internal_get_data)},
+       {"locale",command_cast(gui_internal_cmd2_locale)},
+       {"log",command_cast(gui_internal_cmd_log)},
+       {"menu",command_cast(gui_internal_cmd_menu2)},
+       {"position",command_cast(gui_internal_cmd2_position)},
+       {"route_description",command_cast(gui_internal_cmd2_route_description)},
+       {"route_height_profile",command_cast(gui_internal_cmd2_route_height_profile)},
+       {"setting_layout",command_cast(gui_internal_cmd2_setting_layout)},
+       {"setting_maps",command_cast(gui_internal_cmd2_setting_maps)},
+       {"setting_rules",command_cast(gui_internal_cmd2_setting_rules)},
+       {"setting_vehicle",command_cast(gui_internal_cmd2_setting_vehicle)},
+       {"town",command_cast(gui_internal_cmd2_town)},
+       {"quit",command_cast(gui_internal_cmd2_quit)},
+       {"write",command_cast(gui_internal_cmd_write)},
+};
+
+
+//##############################################################################################################
+//# Description:
+//# Comment:
+//# Authors: Martin Schaller (04/2008)
+//##############################################################################################################
+static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
+{
+       struct gui_priv *this;
+       struct attr *attr;
+       *meth=gui_internal_methods;
+       this=g_new0(struct gui_priv, 1);
+       this->nav=nav;
+
+       this->self.type=attr_gui;
+       this->self.u.gui=gui;   
+
+       if ((attr=attr_search(attrs, NULL, attr_menu_on_map_click)))
+               this->menu_on_map_click=attr->u.num;
+       else
+               this->menu_on_map_click=1;
+       if ((attr=attr_search(attrs, NULL, attr_signal_on_map_click)))
+               this->signal_on_map_click=attr->u.num;
+
+       if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
+               command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this);
+       }
+
+       if( (attr=attr_search(attrs,NULL,attr_font_size)))
+        {
+         this->config.font_size=attr->u.num;
+       }
+       else
+       {
+         this->config.font_size=-1;
+       }
+       if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
+       {
+         this->config.icon_xs=attr->u.num;
+       }
+       else
+       {
+         this->config.icon_xs=-1;
+       }
+       if( (attr=attr_search(attrs,NULL,attr_icon_l)))
+       {
+         this->config.icon_l=attr->u.num;
+       }
+       else
+        {
+         this->config.icon_l=-1;
+       }
+       if( (attr=attr_search(attrs,NULL,attr_icon_s)))
+       {
+         this->config.icon_s=attr->u.num;
+       }
+       else
+        {
+         this->config.icon_s=-1;
+       }
+       if( (attr=attr_search(attrs,NULL,attr_spacing)))
+       {
+         this->config.spacing=attr->u.num;
+       }
+       else
+       {
+         this->config.spacing=-1;
+       }
+       if( (attr=attr_search(attrs,NULL,attr_gui_speech)))
+       {
+         this->speech=attr->u.num;
+       }
+       if( (attr=attr_search(attrs,NULL,attr_keyboard)))
+         this->keyboard=attr->u.num;
+        else
+         this->keyboard=1;
+
+    if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
+      this->fullscreen=attr->u.num;
+
+       if( (attr=attr_search(attrs,NULL,attr_flags)))
+             this->flags=attr->u.num;
+       if( (attr=attr_search(attrs,NULL,attr_background_color)))
+             this->background_color=*attr->u.color;
+       else
+             this->background_color=COLOR_BLACK;
+       if( (attr=attr_search(attrs,NULL,attr_background_color2)))
+               this->background2_color=*attr->u.color;
+       else
+               this->background2_color=(struct color){0x4141,0x4141,0x4141,0xffff};
+       if( (attr=attr_search(attrs,NULL,attr_text_color)))
+             this->text_foreground_color=*attr->u.color;
+       else
+             this->text_foreground_color=COLOR_WHITE;
+       this->text_background_color=COLOR_BLACK;
+       if( (attr=attr_search(attrs,NULL,attr_columns)))
+             this->cols=attr->u.num;
+       if( (attr=attr_search(attrs,NULL,attr_osd_configuration)))
+             this->osd_configuration=*attr;
+
+       if( (attr=attr_search(attrs,NULL,attr_pitch)))
+             this->pitch=attr->u.num;
+       else
+               this->pitch=20;
+       if( (attr=attr_search(attrs,NULL,attr_flags_town)))
+               this->flags_town=attr->u.num;
+       else
+               this->flags_town=-1;
+       if( (attr=attr_search(attrs,NULL,attr_flags_street)))
+               this->flags_street=attr->u.num;
+       else
+               this->flags_street=-1;
+       if( (attr=attr_search(attrs,NULL,attr_flags_house_number)))
+               this->flags_house_number=attr->u.num;
+       else
+               this->flags_house_number=-1;
+       this->data.priv=this;
+       this->data.gui=&gui_internal_methods_ext;
+       this->data.widget=&gui_internal_widget_methods;
+       this->cbl=callback_list_new();
+
+       return this;
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
+//# Authors: Martin Schaller (04/2008)
+//##############################################################################################################
+void plugin_init(void)
+{
+       plugin_register_gui_type("internal", gui_internal_new);
 }
+