Add:Core:Configurable keybindings for OSDs
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 18 Dec 2010 21:11:01 +0000 (21:11 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 18 Dec 2010 21:11:01 +0000 (21:11 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3798 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/attr_def.h
navit/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
navit/navit/osd.c
navit/navit/osd.h

index f696983..3d02d68 100644 (file)
@@ -328,6 +328,7 @@ ATTR(house_number_right)
 ATTR(house_number_right_odd)
 ATTR(house_number_right_even)
 ATTR(map_release)
+ATTR(accesskey)
 ATTR2(0x0003ffff,type_string_end)
 ATTR2(0x00040000,type_special_begin)
 ATTR(order)
index ddb5da8..095da21 100644 (file)
@@ -838,6 +838,10 @@ keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
                key[0]=NAVIT_KEY_BACKSPACE;
                key[1]='\0';
                break;
+       case GDK_Tab:
+               key[0]='\t';
+               key[1]='\0';
+               break;
        case GDK_Return:
        case GDK_KP_Enter:
                key[0]=NAVIT_KEY_RETURN;
index 0b79df4..051b4e4 100644 (file)
@@ -62,6 +62,16 @@ osd_wrap_point(struct point *p, struct navit *nav)
 
 }
 
+static void
+osd_evaluate_command(struct osd_item *this, struct navit *nav)
+{
+       struct attr navit;
+       navit.type=attr_navit;
+       navit.u.navit=nav;
+       dbg(0, "calling command '%s'\n", this->command);
+       command_evaluate(&navit, this->command);
+}
+
 void
 osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p)
 {
@@ -76,13 +86,8 @@ osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button,
        if (navit_ignore_button(nav))
                return;
        this->pressed = pressed;
-       if (pressed && this->command) {
-               struct attr navit;
-               navit.type=attr_navit;
-               navit.u.navit=nav;
-               dbg(0, "calling command '%s'\n", this->command);
-               command_evaluate(&navit, this->command);
-       }
+       if (pressed && this->command) 
+               osd_evaluate_command(this, nav);
 }
 
 void
@@ -121,6 +126,23 @@ osd_std_calculate_sizes(struct osd_item *item, struct osd_priv *priv, int w, int
 }
 
 static void
+osd_std_keypress(struct osd_item *item, struct navit *nav, char *key) 
+{
+#if 0
+       int i;
+       dbg(0,"key=%s\n",key);
+       for (i = 0 ; i < strlen(key) ; i++) {
+               dbg(0,"key:0x%02x\n",key[i]);
+       }
+       for (i = 0 ; i < strlen(item->accesskey) ; i++) {
+               dbg(0,"accesskey:0x%02x\n",item->accesskey[i]);
+       }
+#endif
+       if (item->accesskey && key && !strcmp(key, item->accesskey)) 
+               osd_evaluate_command(item, nav);
+}
+
+static void
 osd_std_reconfigure(struct osd_item *item, struct command_saved *cs)
 {
        if (!command_saved_error(cs)) {
@@ -222,6 +244,9 @@ osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags)
        attr=attr_search(attrs, NULL, attr_flags);
        if (attr)
                item->attr_flags=attr->u.num;
+       attr=attr_search(attrs, NULL, attr_accesskey);
+       if (attr)
+               item->accesskey = g_strdup(attr->u.str);
 }
 
 void
@@ -280,6 +305,11 @@ osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *p
 
        item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes), attr_resize, item, priv);
        graphics_add_callback(navit_gr, item->resize_cb);
+       dbg(0,"accesskey %s\n",item->accesskey);
+       if (item->accesskey) {
+               item->keypress_cb=callback_new_attr_2(callback_cast(osd_std_keypress), attr_keypress, item, nav);
+               graphics_add_callback(navit_gr, item->keypress_cb);
+       }
 
 }
 
index 6aa1da8..e5b4799 100644 (file)
@@ -45,9 +45,11 @@ struct osd_item {
        struct callback *cb;
        struct callback *resize_cb;
        struct callback *reconfig_cb;
+       struct callback *keypress_cb;
        int pressed;
        char *command;
        struct command_saved *enable_cs;
+       char *accesskey;
 };
 
 /* prototypes */