Add:gui_internal:Added key support
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 16 Jun 2008 20:39:09 +0000 (20:39 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 16 Jun 2008 20:39:09 +0000 (20:39 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1131 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/graphics.c
navit/navit/graphics.h
navit/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
navit/navit/gui/internal/gui_internal.c

index 5044b4a..38de405 100644 (file)
@@ -179,6 +179,16 @@ void graphics_register_motion_callback(struct graphics *this_, void (*callback)(
 //# Comment: 
 //# Authors: Martin Schaller (04/2008)
 //##############################################################################################################
+void graphics_register_keypress_callback(struct graphics *this_, void (*callback)(void *data, int key), void *data)
+{
+       this_->meth.register_keypress_callback(this_->priv, callback, data);
+}
+
+//##############################################################################################################
+//# Description: 
+//# Comment: 
+//# Authors: Martin Schaller (04/2008)
+//##############################################################################################################
 struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
 {
        struct graphics_font *this_;
index 191fc70..378b1c8 100644 (file)
@@ -68,7 +68,7 @@ struct graphics_methods {
        void (*image_free)(struct graphics_priv *gr, struct graphics_image_priv *priv);
        void (*get_text_bbox)(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret);
        void (*overlay_disable)(struct graphics_priv *gr, int disable);
-       void (*register_key_callback)(struct graphics_priv *gr, void (*callback)(void *data, struct point *p), void *data);
+       void (*register_keypress_callback)(struct graphics_priv *gr, void (*callback)(void *data, int key), void *data);
 };
 
 
@@ -131,6 +131,7 @@ void *graphics_get_data(struct graphics *this_, char *type);
 void graphics_register_resize_callback(struct graphics *this_, void (*callback)(void *data, int w, int h), void *data);
 void graphics_register_button_callback(struct graphics *this_, void (*callback)(void *data, int pressed, int button, struct point *p), void *data);
 void graphics_register_motion_callback(struct graphics *this_, void (*callback)(void *data, struct point *p), void *data);
+void graphics_register_keypress_callback(struct graphics *this_, void (*callback)(void *data, int key), void *data);
 struct graphics_font *graphics_font_new(struct graphics *gra, int size, int flags);
 struct graphics_gc *graphics_gc_new(struct graphics *gra);
 void graphics_gc_destroy(struct graphics_gc *gc);
index 74962f2..51b5a7f 100644 (file)
 #define GDK_ENABLE_BROKEN
 #include "config.h"
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#if !defined(GDK_Book) || !defined(GDK_Calendar)
+#include <X11/XF86keysym.h>
+#endif
 #include <fontconfig/fontconfig.h>
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include "color.h"
 #include "item.h"
 #include "window.h"
+#include "keys.h"
 #include "plugin.h"
 
+#ifndef GDK_Book
+#define GDK_Book XF86XK_Book
+#endif
+#ifndef GDK_Calendar
+#define GDK_Calendar XF86XK_Calendar
+#endif
+
+
 struct graphics_priv {
        GdkEventButton button_event;
        int button_timeout;
@@ -69,8 +82,8 @@ struct graphics_priv {
        void *motion_callback_data;
        void (*button_callback)(void *data, int press, int button, struct point *p);
        void *button_callback_data;
-       void (*key_callback)(void *data, int key);
-       void *key_callback_data;
+       void (*keypress_callback)(void *data, int key);
+       void *keypress_callback_data;
 };
 
 
@@ -836,6 +849,8 @@ button_release(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
        return FALSE;
 }
 
+
+
 static gint
 scroll(GtkWidget * widget, GdkEventScroll * event, gpointer user_data)
 {
@@ -878,6 +893,41 @@ motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
        return FALSE;
 }
 
+static gint
+keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
+{
+       struct graphics_priv *this=user_data;
+       if (! this->keypress_callback)
+               return FALSE;
+       if (event->keyval >= 32 && event->keyval < 127) {
+               (*this->keypress_callback)(this->motion_callback_data, event->keyval);
+               return FALSE;
+       }
+       switch (event->keyval) {
+       case GDK_Up:
+               (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_UP);
+               break;
+       case GDK_Down:
+               (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_DOWN);
+               break;
+       case GDK_Left:
+               (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_LEFT);
+               break;
+       case GDK_Right:
+               (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_RIGHT);
+               break;
+       case GDK_Book:
+               (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_ZOOM_IN);
+               break;
+       case GDK_Calendar:
+               (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_ZOOM_OUT);
+               break;
+       default:
+               break;
+       }
+       return FALSE;
+}
+
 static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth);
 
 static void
@@ -961,10 +1011,15 @@ register_button_callback(struct graphics_priv *this, void (*callback)(void *data
 }
 
 static void
-register_key_callback(struct graphics_priv *this, void (*callback)(void *data, int press, int button, struct point *p), void *data)
+register_keypress_callback(struct graphics_priv *this, void (*callback)(void *data, int key), void *data)
 {
-       this->key_callback=callback;
-       this->key_callback_data=data;
+       dbg(0,"enter\n");
+       GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
+        gtk_widget_set_sensitive(this->widget, TRUE);
+       gtk_widget_grab_focus(this->widget);
+       g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
+       this->keypress_callback=callback;
+       this->keypress_callback_data=data;
 }
 
 static struct graphics_methods graphics_methods = {
@@ -994,7 +1049,7 @@ static struct graphics_methods graphics_methods = {
        image_free,
        get_text_bbox,
        overlay_disable,
-       register_key_callback,
+       register_keypress_callback,
 };
 
 static struct graphics_priv *
index ccd35bc..65d9a5c 100644 (file)
@@ -50,6 +50,7 @@
 #include "vehicle.h"
 #include "window.h"
 #include "main.h"
+#include "keys.h"
 #include "config.h"
 
 #define STATE_VISIBLE 1
@@ -1391,6 +1392,49 @@ static void gui_internal_resize(void *data, int w, int h)
        gui_internal_menu_root(this);
 } 
 
+//##############################################################################################################
+//# Description: 
+//# Comment: 
+//# Authors: Martin Schaller (04/2008)
+//##############################################################################################################
+static void gui_internal_keypress(void *data, int key)
+{
+       struct gui_priv *this=data;
+       int w,h;
+       struct point p;
+       transform_get_size(navit_get_trans(this->nav), &w, &h);
+       switch (key) {
+       case NAVIT_KEY_UP:
+               p.x=w/2;
+                p.y=0;
+                navit_set_center_screen(this->nav, &p);
+                break;
+       case NAVIT_KEY_DOWN:
+                p.x=w/2;
+                p.y=h;
+                navit_set_center_screen(this->nav, &p);
+                break;
+        case NAVIT_KEY_LEFT:
+                p.x=0;
+                p.y=h/2;
+                navit_set_center_screen(this->nav, &p);
+                break;
+        case NAVIT_KEY_RIGHT:
+                p.x=w;
+                p.y=h/2;
+                navit_set_center_screen(this->nav, &p);
+                break;
+        case NAVIT_KEY_ZOOM_IN:
+                navit_zoom_in(this->nav, 2, NULL);
+                break;
+        case NAVIT_KEY_ZOOM_OUT:
+                navit_zoom_out(this->nav, 2, NULL);
+                break;
+       default:
+               dbg(0,"key=%d\n", key);
+       }
+} 
+
 
 //##############################################################################################################
 //# Description: 
@@ -1418,6 +1462,7 @@ static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra
        graphics_register_resize_callback(gra, gui_internal_resize, this);
        graphics_register_button_callback(gra, gui_internal_button, this);
        graphics_register_motion_callback(gra, gui_internal_motion, this);
+       graphics_register_keypress_callback(gra, gui_internal_keypress, this);
        this->background=graphics_gc_new(gra);
        graphics_gc_set_foreground(this->background, &cb);
        this->background2=graphics_gc_new(gra);