aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.c18
-rw-r--r--src/objects.c29
-rw-r--r--src/objects.h1
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);