diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-05-24 23:48:02 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-05-24 23:48:02 +0200 |
commit | bcbdceef6e1be59a6ca1d653b6a54bf9009b4143 (patch) | |
tree | 8fc7b7ab999ffdcff0418132bc1d87fd9d7c88bc /src | |
parent | b0770e263f6b94386aa0818b0c0f79ca486cf1b2 (diff) |
Make backspace work
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.c | 18 | ||||
-rw-r--r-- | src/objects.c | 29 | ||||
-rw-r--r-- | src/objects.h | 1 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c index 48740cd..44fed9e 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -29,6 +29,7 @@ #include <string.h> #include <gtk/gtk.h> #include <assert.h> +#include <gdk/gdkkeysyms.h> #include "presentation.h" #include "mainwindow.h" @@ -157,10 +158,25 @@ static gboolean im_commit_sig(GtkIMContext *im, gchar *str, static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct presentation *p) { + gboolean r; + if ( p->editing_object == NULL ) return FALSE; /* Throw the event to the IM context and let it sort things out */ - gtk_im_context_filter_keypress(GTK_IM_CONTEXT(p->im_context), event); + r = gtk_im_context_filter_keypress(GTK_IM_CONTEXT(p->im_context), + event); + + if ( r ) return FALSE; /* IM ate it */ + + if ( event->keyval == GDK_KEY_BackSpace ) { + if ( (p->editing_object != NULL) + && (p->editing_object->type == TEXT) ) { + handle_text_backspace(p->editing_object); + } + } + + /* FIXME: Invalidate only the necessary region */ + gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE); return FALSE; } diff --git a/src/objects.c b/src/objects.c index 189241c..a91b737 100644 --- a/src/objects.c +++ b/src/objects.c @@ -122,6 +122,35 @@ void insert_text(struct object *o, char *t) } +void handle_text_backspace(struct object *o) +{ + size_t ndel; + int i; + + assert(o->type == TEXT); + + if ( o->insertion_point == 0 ) return; /* Nothing to delete */ + + if ( !(o->text[o->insertion_point-1] & 0x80) ) { + /* Simple (ASCII-style) backspace */ + ndel = 1; + } else { + ndel = 0; + for ( i=1; i<=6; i++ ) { + if ( !(o->text[o->insertion_point-i] & 0xC0) ) ndel++; + } + } + + memmove(o->text+o->insertion_point-ndel, + o->text+o->insertion_point, + o->text_len-o->insertion_point); + + o->insertion_point -= ndel; + + o->parent->object_seq++; +} + + void delete_object(struct object *o) { remove_object_from_slide(o->parent, o); diff --git a/src/objects.h b/src/objects.h index e6e457e..15f2618 100644 --- a/src/objects.h +++ b/src/objects.h @@ -59,6 +59,7 @@ struct object extern struct object *add_text_object(struct slide *s, double x, double y); extern void insert_text(struct object *o, char *t); +extern void handle_text_backspace(struct object *o); extern void delete_object(struct object *o); |