From 48cbffa2da42612a242f96fa0fd09683e9d1442b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 4 Oct 2011 23:57:01 +0200 Subject: Move key press stuff into tool callbacks --- src/mainwindow.c | 26 ++------------------------ src/presentation.h | 3 +++ src/tool_select.c | 14 ++++++++++++++ src/tool_text.c | 35 +++++++++++++++++++++++++++++++++-- src/tool_text.h | 4 ---- 5 files changed, 52 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/mainwindow.c b/src/mainwindow.c index d115ec3..b98ed00 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -557,7 +557,7 @@ static gboolean im_commit_sig(GtkIMContext *im, gchar *str, if ( p->editing_object == NULL ) return FALSE; if ( p->editing_object->type != TEXT ) return FALSE; - insert_text(p->editing_object, str); + p->cur_tool->im_commit(p->editing_object, str, p->cur_tool); redraw_object(p->editing_object); @@ -573,31 +573,9 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, /* Throw the event to the IM context and let it sort things out */ r = gtk_im_context_filter_keypress(GTK_IM_CONTEXT(p->im_context), event); - if ( r ) return FALSE; /* IM ate it */ - if ( (p->editing_object != NULL) - && (p->editing_object->type == TEXT) ) - { - switch ( event->keyval ) { - - case GDK_KEY_BackSpace : - handle_text_backspace(p->editing_object); - redraw_object(p->editing_object); - break; - - case GDK_KEY_Left : - move_cursor_left(p->editing_object); - redraw_object(p->editing_object); - break; - - case GDK_KEY_Right : - move_cursor_right(p->editing_object); - redraw_object(p->editing_object); - break; - - } - } + p->cur_tool->key_pressed(p->editing_object, event->keyval, p->cur_tool); switch ( event->keyval ) { diff --git a/src/presentation.h b/src/presentation.h index 1c24f5d..3588eb6 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -59,6 +59,9 @@ struct toolinfo void (*drag_object)(struct toolinfo *tip, struct presentation *p, struct object *o, double x, double y); void (*draw_editing_overlay)(cairo_t *cr, struct object *o); + void (*key_pressed)(struct object *o, guint keyval, + struct toolinfo *tip); + void (*im_commit)(struct object *o, gchar *str, struct toolinfo *tip); }; diff --git a/src/tool_select.c b/src/tool_select.c index 269dfc7..2e9aa37 100644 --- a/src/tool_select.c +++ b/src/tool_select.c @@ -94,6 +94,18 @@ static void draw_overlay(cairo_t *cr, struct object *o) } +static void key_pressed(struct object *o, guint keyval, struct toolinfo *tip) +{ + /* Do nothing */ +} + + +static void im_commit(struct object *o, gchar *str, struct toolinfo *tip) +{ + /* Do nothing */ +} + + struct toolinfo *initialise_select_tool() { struct select_toolinfo *ti; @@ -107,6 +119,8 @@ struct toolinfo *initialise_select_tool() ti->base.deselect = deselect_object; ti->base.drag_object = drag_object; ti->base.draw_editing_overlay = draw_overlay; + ti->base.key_pressed = key_pressed; + ti->base.im_commit = im_commit; return (struct toolinfo *)ti; } diff --git a/src/tool_text.c b/src/tool_text.c index f4df9a3..c5555b6 100644 --- a/src/tool_text.c +++ b/src/tool_text.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "presentation.h" #include "objects.h" @@ -452,13 +453,13 @@ static void create_default(struct presentation *p, struct style *sty, } -static void select_object(struct object *o,struct toolinfo *tip) +static void select_object(struct object *o, struct toolinfo *tip) { /* Do nothing */ } -static int deselect_object(struct object *o,struct toolinfo *tip) +static int deselect_object(struct object *o, struct toolinfo *tip) { if ( (o != NULL) && o->empty ) { delete_object(o); @@ -477,6 +478,34 @@ static void draw_overlay(cairo_t *cr, struct object *o) } +static void key_pressed(struct object *o, guint keyval, struct toolinfo *tip) +{ + if ( o == NULL ) return; + + switch ( keyval ) { + + case GDK_KEY_BackSpace : + handle_text_backspace(o); + break; + + case GDK_KEY_Left : + move_cursor_left(o); + break; + + case GDK_KEY_Right : + move_cursor_right(o); + break; + + } +} + + +static void im_commit(struct object *o, gchar *str, struct toolinfo *tip) +{ + insert_text(o, str); +} + + struct toolinfo *initialise_text_tool(GtkWidget *w) { struct text_toolinfo *ti; @@ -492,6 +521,8 @@ struct toolinfo *initialise_text_tool(GtkWidget *w) ti->base.deselect = deselect_object; ti->base.drag_object = drag_object; ti->base.draw_editing_overlay = draw_overlay; + ti->base.key_pressed = key_pressed; + ti->base.im_commit = im_commit; return (struct toolinfo *)ti; } diff --git a/src/tool_text.h b/src/tool_text.h index b2f333b..2e865d7 100644 --- a/src/tool_text.h +++ b/src/tool_text.h @@ -29,10 +29,6 @@ #include -extern void insert_text(struct object *o, char *t); -extern void handle_text_backspace(struct object *o); -extern void move_cursor_left(struct object *o); -extern void move_cursor_right(struct object *o); extern struct toolinfo *initialise_text_tool(GtkWidget *w); -- cgit v1.2.3