diff options
author | Thomas White <taw@bitwiz.org.uk> | 2016-04-16 19:04:33 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2016-04-19 22:53:40 +0200 |
commit | 1f305d199195d5e27e0731917399dca7de3e75cd (patch) | |
tree | a8f1c5401367134ee9877327f63e9153c1416e4d /src | |
parent | 890e5ac7b89f5cccf120d966dc488f9ddd516a3d (diff) |
WIP on slide adding
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.c | 30 | ||||
-rw-r--r-- | src/frame.h | 3 | ||||
-rw-r--r-- | src/narrative_window.c | 36 | ||||
-rw-r--r-- | src/sc_editor.c | 39 | ||||
-rw-r--r-- | src/sc_editor.h | 2 |
5 files changed, 60 insertions, 50 deletions
diff --git a/src/frame.c b/src/frame.c index 3699b74..9440ec1 100644 --- a/src/frame.c +++ b/src/frame.c @@ -388,6 +388,36 @@ static Paragraph *create_paragraph(struct frame *fr) } +/* Create a new paragraph in 'fr' just after paragraph 'pos' */ +static Paragraph *insert_paragraph(struct frame *fr, int pos) +{ + Paragraph **paras_new; + Paragraph *pnew; + int i; + + if ( pos >= fr->n_paras ) { + fprintf(stderr, "insert_paragraph(): pos too high!\n"); + return NULL; + } + + paras_new = realloc(fr->paras, (fr->n_paras+1)*sizeof(Paragraph *)); + if ( paras_new == NULL ) return NULL; + + pnew = calloc(1, sizeof(struct _paragraph)); + if ( pnew == NULL ) return NULL; + + fr->paras = paras_new; + fr->n_paras ++; + + for ( i=fr->n_paras-1; i>pos; i-- ) { + fr->paras[i] = fr->paras[i-1]; + } + fr->paras[pos+1] = pnew; + + return pnew; +} + + void add_callback_para(struct frame *fr, double w, double h, SCCallbackDrawFunc draw_func, SCCallbackClickFunc click_func, void *bvp, diff --git a/src/frame.h b/src/frame.h index d6d171c..5c7abc2 100644 --- a/src/frame.h +++ b/src/frame.h @@ -150,4 +150,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, int pos, + PangoContext *pc); + #endif /* FRAME_H */ diff --git a/src/narrative_window.c b/src/narrative_window.c index 6e09d71..bfad8b2 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -139,41 +139,37 @@ static void exportpdf_sig(GSimpleAction *action, GVariant *parameter, } -static void open_slidesorter_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) +static void open_slidesorter_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) { } -static void delete_frame_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) +static void delete_frame_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) { } -static void add_slide_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) +static void add_slide_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) { int n_slides; SCBlock *block; SCBlock *nsblock; NarrativeWindow *nw = vp; - /* Link it into the SC structure */ + /* Create the SCBlock for the new slide */ nsblock = sc_parse("\\slide{}"); - insert_scblock(nsblock, nw->sceditor); - - /* Iterate over blocks of presentation, counting \slides, until - * we reach the block we just added */ - block = nw->p->scblocks; - n_slides = 0; - while ( block != NULL ) { - const char *n = sc_block_name(block); - if ( n == NULL ) goto next; - if ( strcmp(n, "slide") == 0 ) { - if ( block == nsblock ) break; - n_slides++; - } -next: - block = sc_block_next(block); - } + + /* Split the current paragraph */ + split_paragraph_at_cursor(nw->sceditor); + + /* Link the new SCBlock in */ + + /* Create a new paragraph for the slide */ + + sc_editor_redraw(nw->sceditor); } diff --git a/src/sc_editor.c b/src/sc_editor.c index 5549c54..0db20a8 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -555,34 +555,9 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, SCEditor *e) } -void insert_scblock(SCBlock *scblock, SCEditor *e) +void split_paragraph_at_cursor(SCEditor *e) { -#if 0 - /* FIXME: Insert "scblock" at the cursor */ - int sln, sbx, sps; - struct wrap_box *sbox; - struct frame *fr = e->cursor_frame; - - if ( fr == NULL ) return; - - /* If this is, say, the top level frame, do nothing */ - if ( fr->boxes == NULL ) return; - - sln = e->cursor_line; - sbx = e->cursor_box; - sps = e->cursor_pos; - sbox = bv_box(e->cursor_frame->lines[sln].boxes, sbx); - - sc_insert_block(sbox->scblock, sps+sbox->offs_char, scblock); - - fr->empty = 0; - - full_rerender(e); /* FIXME: No need for full */ - - //fixup_cursor(e); - //advance_cursor(e); - //sc_editor_redraw(e); -#endif + split_paragraph(e->cursor_frame, e->cursor_para, e->cursor_pos, e->pc); } @@ -923,12 +898,18 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, } else { - /* Selected top new frame, no immediate dragging */ + /* Clicked an existing frame, no immediate dragging */ e->drag_status = DRAG_STATUS_NONE; e->drag_reason = DRAG_REASON_NONE; e->selection = clicked; e->cursor_frame = clicked; - check_paragraph(e->cursor_frame, e->pc, e->scblocks); + if ( clicked == e->top ) { + show_sc_block(clicked->scblocks, ")>"); + check_paragraph(e->cursor_frame, e->pc, clicked->scblocks); + } else { + check_paragraph(e->cursor_frame, e->pc, + sc_block_child(clicked->scblocks)); + } find_cursor(clicked, x-clicked->x, y-clicked->y, &e->cursor_para, &e->cursor_pos, &e->cursor_trail); diff --git a/src/sc_editor.h b/src/sc_editor.h index 594f344..0a04f20 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -177,8 +177,8 @@ extern void sc_editor_set_min_border(SCEditor *e, double min_border); extern void sc_editor_set_top_frame_editable(SCEditor *e, int top_frame_editable); extern void sc_editor_set_callbacks(SCEditor *e, SCCallbackList *cbl); -extern void insert_scblock(SCBlock *scblock, SCEditor *e); 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); #endif /* SC_EDITOR_H */ |