aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-10-04 23:57:01 +0200
committerThomas White <taw@bitwiz.org.uk>2011-10-04 23:57:01 +0200
commit48cbffa2da42612a242f96fa0fd09683e9d1442b (patch)
tree42e16e5a9021c3e6f850f1b2c512f203e933d506 /src
parent064482aaaf0857cc0ad01b845558d84e1f684d58 (diff)
Move key press stuff into tool callbacks
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.c26
-rw-r--r--src/presentation.h3
-rw-r--r--src/tool_select.c14
-rw-r--r--src/tool_text.c35
-rw-r--r--src/tool_text.h4
5 files changed, 52 insertions, 30 deletions
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 <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <gdk/gdkkeysyms.h>
#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 <gtk/gtk.h>
-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);