aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.c11
-rw-r--r--src/objects.c50
-rw-r--r--src/objects.h4
-rw-r--r--src/slide_render.c4
4 files changed, 65 insertions, 4 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 904c69f..362bd92 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -142,6 +142,14 @@ static gint close_sig(GtkWidget *window, struct presentation *p)
static gboolean im_commit_sig(GtkIMContext *im, gchar *str,
struct presentation *p)
{
+ if ( p->editing_object == NULL ) return FALSE;
+ if ( p->editing_object->type != TEXT ) return FALSE;
+
+ insert_text(p->editing_object, str);
+
+ /* FIXME: Invalidate only the necessary region */
+ gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
return FALSE;
}
@@ -156,9 +164,6 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
/* 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);
- /* 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 576eeb8..189241c 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "presentation.h"
#include "objects.h"
@@ -66,7 +67,10 @@ struct object *add_text_object(struct slide *s, double x, double y)
new->x = x; new->y = y;
new->bb_width = 10.0;
new->bb_height = 40.0;
- new->text = "Hello";
+ new->text = malloc(1);
+ new->text[0] = '\0';
+ new->text_len = 1;
+ new->insertion_point = 0;
s->object_seq++;
@@ -74,6 +78,50 @@ struct object *add_text_object(struct slide *s, double x, double y)
}
+void insert_text(struct object *o, char *t)
+{
+ char *tmp;
+ size_t tlen, olen;
+ int i;
+
+ assert(o->type == TEXT);
+ tlen = strlen(t);
+ olen = strlen(o->text);
+
+ if ( tlen + olen + 1 > o->text_len ) {
+
+ char *try;
+
+ try = realloc(o->text, o->text_len + tlen + 64);
+ if ( try == NULL ) return; /* Failed to insert */
+ o->text = try;
+ o->text_len += 64;
+ o->text_len += tlen;
+
+ }
+
+ tmp = malloc(o->text_len);
+ if ( tmp == NULL ) return;
+
+ for ( i=0; i<o->insertion_point; i++ ) {
+ tmp[i] = o->text[i];
+ }
+ for ( i=0; i<tlen; i++ ) {
+ tmp[i+o->insertion_point] = t[i];
+ }
+ for ( i=0; i<olen-o->insertion_point; i++ ) {
+ tmp[i+o->insertion_point+tlen] = o->text[i+o->insertion_point];
+ }
+ tmp[olen+tlen] = '\0';
+ memcpy(o->text, tmp, o->text_len);
+ free(tmp);
+
+ o->insertion_point += tlen;
+ o->parent->object_seq++;
+ o->empty = 0;
+}
+
+
void delete_object(struct object *o)
{
remove_object_from_slide(o->parent, o);
diff --git a/src/objects.h b/src/objects.h
index c220b00..e6e457e 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -52,10 +52,14 @@ struct object
/* For type TEXT */
char *text;
+ size_t text_len;
+ int insertion_point;
};
extern struct object *add_text_object(struct slide *s, double x, double y);
+extern void insert_text(struct object *o, char *t);
+
extern void delete_object(struct object *o);
diff --git a/src/slide_render.c b/src/slide_render.c
index 33eee36..ab656be 100644
--- a/src/slide_render.c
+++ b/src/slide_render.c
@@ -47,6 +47,10 @@ static void render_text_object(cairo_t *cr, struct object *o)
pango_cairo_update_layout(cr, l);
pango_layout_get_size(l, &width, &height);
+
+ o->bb_width = width/PANGO_SCALE;
+ o->bb_height = height/PANGO_SCALE;
+
cairo_move_to(cr, o->x - (width/PANGO_SCALE)/2.0,
o->y - (height/PANGO_SCALE)/2.0);