diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2008-06-16 20:39:09 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2008-06-16 20:39:09 +0000 |
commit | d9f16207a1c246a377a0357cbeddb24db1921259 (patch) | |
tree | 7499505114e02a7ff7e9dce9a37634aa982be52d | |
parent | 11f2f1fbb70283db69b15b86014e128d13ce88d5 (diff) | |
download | navit-d9f16207a1c246a377a0357cbeddb24db1921259.tar.gz |
Add:gui_internal:Added key support
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1131 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | navit/graphics.c | 10 | ||||
-rw-r--r-- | navit/graphics.h | 3 | ||||
-rw-r--r-- | navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c | 67 | ||||
-rw-r--r-- | navit/gui/internal/gui_internal.c | 45 |
4 files changed, 118 insertions, 7 deletions
diff --git a/navit/graphics.c b/navit/graphics.c index 5044b4ad2..38de40579 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -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_; diff --git a/navit/graphics.h b/navit/graphics.h index 191fc702e..378b1c8cf 100644 --- a/navit/graphics.h +++ b/navit/graphics.h @@ -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); diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c index 74962f2b5..51b5a7fe6 100644 --- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c +++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c @@ -20,6 +20,10 @@ #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 @@ -37,8 +41,17 @@ #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 * diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index ccd35bc19..65d9a5c1f 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -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); |