diff options
author | Thomas White <taw@bitwiz.org.uk> | 2016-04-22 22:43:54 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2016-04-22 22:45:03 +0200 |
commit | bf21da066c16bd945f56230f726bc95e70f41bc2 (patch) | |
tree | d5f36ffa6c9d1175a6dbe4aeab6b22fd0db405b5 /src | |
parent | 044b25bb359c4b3254b947ca34a1491f5eb9f901 (diff) |
Slide adding works
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.c | 15 | ||||
-rw-r--r-- | src/frame.h | 4 | ||||
-rw-r--r-- | src/narrative_window.c | 17 | ||||
-rw-r--r-- | src/sc_editor.c | 6 | ||||
-rw-r--r-- | src/sc_editor.h | 2 | ||||
-rw-r--r-- | src/slide_window.c | 9 |
6 files changed, 31 insertions, 22 deletions
diff --git a/src/frame.c b/src/frame.c index 744f85d..3713277 100644 --- a/src/frame.c +++ b/src/frame.c @@ -857,8 +857,8 @@ static char *s_strdup(const char *a) } -static void split_text_paragraph(struct frame *fr, int pn, size_t pos, - PangoContext *pc) +static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, + PangoContext *pc) { Paragraph *pnew; int i; @@ -870,7 +870,7 @@ static void split_text_paragraph(struct frame *fr, int pn, size_t pos, pnew = insert_paragraph(fr, pn); if ( pnew == NULL ) { fprintf(stderr, "Failed to insert paragraph\n"); - return; + return NULL; } /* Determine which run the cursor is in */ @@ -882,7 +882,7 @@ static void split_text_paragraph(struct frame *fr, int pn, size_t pos, pnew->runs = malloc(pnew->n_runs * sizeof(struct text_run)); if ( pnew->runs == NULL ) { fprintf(stderr, "Failed to allocate runs.\n"); - return; /* Badness is coming */ + return NULL; /* Badness is coming */ } /* First run of the new paragraph contains the leftover text */ @@ -930,16 +930,19 @@ static void split_text_paragraph(struct frame *fr, int pn, size_t pos, wrap_paragraph(para, pc, fr->w); wrap_paragraph(pnew, pc, fr->w); + + return sc_block_next(rr->scblock); } -void split_paragraph(struct frame *fr, int pn, size_t pos, PangoContext *pc) +SCBlock *split_paragraph(struct frame *fr, int pn, size_t pos, PangoContext *pc) { Paragraph *para = fr->paras[pn]; if ( para->type == PARA_TYPE_TEXT ) { - split_text_paragraph(fr, pn, pos, pc); + return split_text_paragraph(fr, pn, pos, pc); } else { /* Other types can't be split */ + return NULL; } } diff --git a/src/frame.h b/src/frame.h index 1edd440..2941411 100644 --- a/src/frame.h +++ b/src/frame.h @@ -152,7 +152,7 @@ extern void insert_text_in_paragraph(Paragraph *para, size_t offs, extern void delete_text_in_paragraph(Paragraph *para, size_t offs1, size_t offs2); -extern void split_paragraph(struct frame *fr, int pn, size_t pos, - PangoContext *pc); +extern SCBlock *split_paragraph(struct frame *fr, int pn, size_t pos, + PangoContext *pc); #endif /* FRAME_H */ diff --git a/src/narrative_window.c b/src/narrative_window.c index bfad8b2..5a352f7 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -154,22 +154,21 @@ static void delete_frame_sig(GSimpleAction *action, GVariant *parameter, static void add_slide_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { - int n_slides; - SCBlock *block; SCBlock *nsblock; NarrativeWindow *nw = vp; - /* Create the SCBlock for the new slide */ - nsblock = sc_parse("\\slide{}"); - /* Split the current paragraph */ - split_paragraph_at_cursor(nw->sceditor); + nsblock = split_paragraph_at_cursor(nw->sceditor); /* Link the new SCBlock in */ + if ( nsblock != NULL ) { + sc_block_append(nsblock, "slide", NULL, NULL, NULL); + } else { + fprintf(stderr, "Failed to split paragraph\n"); + } - /* Create a new paragraph for the slide */ - - sc_editor_redraw(nw->sceditor); + sc_editor_set_scblock(nw->sceditor, + sc_editor_get_scblock(nw->sceditor)); } diff --git a/src/sc_editor.c b/src/sc_editor.c index fac8210..dcfd9fd 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -555,10 +555,10 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, SCEditor *e) } -void split_paragraph_at_cursor(SCEditor *e) +SCBlock *split_paragraph_at_cursor(SCEditor *e) { - split_paragraph(e->cursor_frame, e->cursor_para, - e->cursor_pos+e->cursor_trail, e->pc); + return split_paragraph(e->cursor_frame, e->cursor_para, + e->cursor_pos+e->cursor_trail, e->pc); } diff --git a/src/sc_editor.h b/src/sc_editor.h index 0a04f20..5e54cde 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -179,6 +179,6 @@ extern void sc_editor_set_top_frame_editable(SCEditor *e, extern void sc_editor_set_callbacks(SCEditor *e, SCCallbackList *cbl); extern void sc_editor_delete_selected_frame(SCEditor *e); extern void sc_editor_remove_cursor(SCEditor *e); -extern void split_paragraph_at_cursor(SCEditor *e); +extern SCBlock *split_paragraph_at_cursor(SCEditor *e); #endif /* SC_EDITOR_H */ diff --git a/src/slide_window.c b/src/slide_window.c index b232e58..659c0bd 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -533,6 +533,7 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks) SlideWindow *sw; SCBlock *stylesheets[2]; GtkWidget *image; + SCBlock *ch; sw = calloc(1, sizeof(SlideWindow)); if ( sw == NULL ) return NULL; @@ -610,7 +611,13 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks) "win.last"); stylesheets[0] = p->stylesheet; stylesheets[1] = NULL; - sw->sceditor = sc_editor_new(sc_block_child(scblocks), stylesheets, p->lang); + + ch = sc_block_child(scblocks); + if ( ch == NULL ) { + ch = sc_block_append_inside(scblocks, NULL, NULL, ""); + } + + sw->sceditor = sc_editor_new(ch, stylesheets, p->lang); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, |