From 0a605ec565f3ccdbaa4c72b20a1b3586cc53ceb8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 10 Oct 2019 22:34:10 +0200 Subject: Restore slide text insertion --- libstorycode/gtk/gtkslideview.c | 45 ++++++++++++++++++--------------------- libstorycode/slide_priv.h | 3 +++ libstorycode/slide_render_cairo.c | 4 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libstorycode/gtk/gtkslideview.c b/libstorycode/gtk/gtkslideview.c index 2697d5f..11cf05a 100644 --- a/libstorycode/gtk/gtkslideview.c +++ b/libstorycode/gtk/gtkslideview.c @@ -1104,27 +1104,31 @@ static void gtksv_do_backspace(GtkSlideView *e, signed int dir) } -static void gtksv_insert_text_in_paragraph(SlideItem *item, int para, +static void gtksv_insert_text_in_paragraph(SlideItem *item, int para_num, size_t offs, char *t) { - /* FIXME! */ -#if 0 - char *n = malloc(strlen(t) + strlen(item->paras[para].text) + 1); + struct slide_text_paragraph *para; + int run; + size_t run_offs; + char *n; + + para = &item->paras[para_num]; + run = slide_which_run(para, offs, &run_offs); + + n = malloc(strlen(t) + strlen(para->runs[run].text) + 1); if ( n == NULL ) return; - strncpy(n, item->paras[para].text, offs); - n[offs] = '\0'; + + strncpy(n, para->runs[run].text, run_offs); + n[run_offs] = '\0'; strcat(n, t); - strcat(n, item->paras[para].text+offs); - free(item->paras[para].text); - item->paras[para].text = n; -#endif + strcat(n, para->runs[run].text+run_offs); + free(para->runs[run].text); + para->runs[run].text = n; } static void gtksv_insert_text(char *t, GtkSlideView *e) { - /* FIXME! */ -#if 0 size_t off; if ( e->cursor_frame == NULL ) return; @@ -1135,27 +1139,20 @@ static void gtksv_insert_text(char *t, GtkSlideView *e) } gtksv_unset_selection(e); + off = slide_pos_trail_to_offset(e->cursor_frame, e->cpos.para, + e->cpos.pos, e->cpos.trail); if ( strcmp(t, "\n") == 0 ) { - off = pos_trail_to_offset(e->cursor_frame, e->cpos.para, - e->cpos.pos, e->cpos.trail); slide_item_split_text_paragraph(e->cursor_frame, e->cpos.para, off); e->cpos.para++; e->cpos.pos = 0; e->cpos.trail = 0; - gtksv_emit_change_sig(e); - gtksv_redraw(e); - return; + } else { + gtksv_insert_text_in_paragraph(e->cursor_frame, e->cpos.para, off, t); + e->cpos.pos += strlen(t); } - off = pos_trail_to_offset(e->cursor_frame, e->cpos.para, - e->cpos.pos, e->cpos.trail); - gtksv_insert_text_in_paragraph(e->cursor_frame, e->cpos.para, off, t); - pango_layout_set_text(e->cursor_frame->paras[e->cpos.para].layout, - e->cursor_frame->paras[e->cpos.para].text, -1); - gtksv_cursor_moveh(e, &e->cpos, +1); gtksv_emit_change_sig(e); gtksv_redraw(e); -#endif } diff --git a/libstorycode/slide_priv.h b/libstorycode/slide_priv.h index 64e6d75..d415d33 100644 --- a/libstorycode/slide_priv.h +++ b/libstorycode/slide_priv.h @@ -76,4 +76,7 @@ struct _slide SlideItem *items; }; +extern int slide_which_run(struct slide_text_paragraph *para, size_t item_offs, + size_t *run_offs); + #endif /* SLIDE_PRIV_H */ diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c index 32bd236..a1da5da 100644 --- a/libstorycode/slide_render_cairo.c +++ b/libstorycode/slide_render_cairo.c @@ -55,8 +55,8 @@ static int slide_positions_equal(struct slide_pos a, struct slide_pos b) } -static int slide_which_run(struct slide_text_paragraph *para, size_t item_offs, - size_t *run_offs) +int slide_which_run(struct slide_text_paragraph *para, size_t item_offs, + size_t *run_offs) { int run; size_t pos = 0; -- cgit v1.2.3