aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2018-02-16 21:13:37 +0100
committerThomas White <taw@bitwiz.org.uk>2018-02-16 21:13:37 +0100
commit1a0b0833c7eb6ceef377c69f32e2325b3fab8f00 (patch)
treea9dcbbcd43f73fef772dfbcc64bbb16062213744 /src
parentc05574d014e87df5bf3ac52ed7173375f70d7175 (diff)
Record whether or not macro is editable
Diffstat (limited to 'src')
-rw-r--r--src/frame.c22
-rw-r--r--src/frame.h3
-rw-r--r--src/sc_editor.c4
-rw-r--r--src/sc_interp.c9
4 files changed, 24 insertions, 14 deletions
diff --git a/src/frame.c b/src/frame.c
index ff741a0..cdd84f7 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -41,6 +41,7 @@ struct text_run
SCBlock *scblock;
SCBlock *macro_real_block;
SCBlock *macro_contents;
+ int macro_editable;
size_t scblock_offs_bytes; /* Offset from start of SCBlock */
size_t para_offs_bytes; /* Offset from start of paragraph */
size_t len_bytes;
@@ -380,7 +381,7 @@ void set_newline_at_end(Paragraph *para, SCBlock *bl)
void add_run(Paragraph *para, SCBlock *scblock,
SCBlock *macro_real, SCBlock *contents_top,
size_t offs_bytes, size_t len_bytes, PangoFontDescription *fdesc,
- double col[4])
+ double col[4], int macro_editable)
{
struct text_run *runs_new;
@@ -400,6 +401,7 @@ void add_run(Paragraph *para, SCBlock *scblock,
para->runs[para->n_runs].scblock = scblock;
para->runs[para->n_runs].macro_real_block = macro_real;
para->runs[para->n_runs].macro_contents = contents_top;
+ para->runs[para->n_runs].macro_editable = macro_editable;
para->runs[para->n_runs].scblock_offs_bytes = offs_bytes;
para->runs[para->n_runs].para_offs_bytes = para->offset_last;
para->offset_last += len_bytes;
@@ -988,8 +990,10 @@ void insert_text_in_paragraph(Paragraph *para, size_t offs, const char *t)
run = &para->runs[nrun];
if ( run->macro_real_block != NULL ) {
- printf("Not inserting text into a macro block.\n");
- return;
+ if ( !run->macro_editable ) {
+ printf("Not inserting text into a macro block.\n");
+ return;
+ }
}
if ( (sc_block_name(run->scblock) != NULL)
@@ -1207,11 +1211,6 @@ size_t delete_text_in_paragraph(struct frame *fr, int npara, size_t offs1, ssize
run = &para->runs[nrun];
- if ( run->macro_real_block != NULL ) {
- printf("Not deleting text from macro block\n");
- continue;
- }
-
ds = offs1 - run->para_offs_bytes;
if ( offs2 < 0 ) {
de = run->len_bytes;
@@ -1226,6 +1225,13 @@ size_t delete_text_in_paragraph(struct frame *fr, int npara, size_t offs1, ssize
assert(de >= 0); /* Otherwise nrun2 was too big */
if ( ds == de ) continue;
+ if ( run->macro_real_block != NULL ) {
+ if ( !run->macro_editable ) {
+ printf("Not deleting inside macro block!\n");
+ continue;
+ }
+ }
+
/* Delete from the corresponding SC block */
scblock_offs1 = ds + run->scblock_offs_bytes;
scblock_offs2 = de + run->scblock_offs_bytes;
diff --git a/src/frame.h b/src/frame.h
index 746038e..b60afa1 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -138,7 +138,8 @@ extern void show_edit_pos(struct edit_pos a);
extern void add_run(Paragraph *para, SCBlock *scblock,
SCBlock *macro_real, SCBlock *contents_top,
size_t offs_bytes, size_t len_bytes,
- PangoFontDescription *fdesc, double col[4]);
+ PangoFontDescription *fdesc, double col[4],
+ int macro_editable);
extern Paragraph *insert_paragraph(struct frame *fr, int pos);
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 08ddb46..5cb1b00 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -854,7 +854,7 @@ static void insert_text(char *t, SCEditor *e)
return;
}
add_run(pnew, ad, NULL, NULL, 0, strlen(t),
- e->cursor_frame->fontdesc, e->cursor_frame->col);
+ e->cursor_frame->fontdesc, e->cursor_frame->col, 0);
wrap_frame(e->cursor_frame, e->pc);
@@ -1076,7 +1076,7 @@ static void check_paragraph(struct frame *fr, PangoContext *pc,
}
scblocks = sc_block_append(scblocks, NULL, NULL, strdup(""), NULL);
- add_run(para, scblocks, NULL, NULL, 0, 0, fr->fontdesc, fr->col);
+ add_run(para, scblocks, NULL, NULL, 0, 0, fr->fontdesc, fr->col, 0);
wrap_paragraph(para, pc, fr->w - fr->pad_l - fr->pad_r, 0, 0);
}
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 993253c..efdffa6 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -77,6 +77,7 @@ struct sc_state
SCBlock *macro_contents; /* If running a macro, the child block of the caller */
SCBlock *macro_real_block; /* If running a macro, the block which called the macro */
+ int macro_editable; /* If running a macro, whether this bit can be edited or not */
};
@@ -599,6 +600,7 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang,
}
st->macro_contents = NULL;
st->macro_real_block = NULL;
+ st->macro_editable = 0;
st->fr = NULL;
st->paraspace[0] = 0.0;
st->paraspace[1] = 0.0;
@@ -966,7 +968,7 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
Paragraph *para = last_open_para(fr);
add_run(para, bl, mrb, st->macro_contents, start, len,
- fontdesc, col);
+ fontdesc, col, st->macro_editable);
set_para_spacing(para, st->paraspace);
start += len;
@@ -1031,7 +1033,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
struct sc_state *st = &scin->state[scin->j];
/* Add a dummy run which we can type into */
add_run(para, bl, st->macro_real_block, st->macro_contents, 0, 0,
- sc_interp_get_fontdesc(scin), fr->col);
+ sc_interp_get_fontdesc(scin), fr->col, st->macro_editable);
set_newline_at_end(para, bl);
close_last_paragraph(fr);
@@ -1097,7 +1099,8 @@ static void run_editable(SCInterpreter *scin, SCBlock *contents)
//struct sc_state *st = &scin->state[scin->j];
sc_interp_save(scin);
- scin->state[scin->j].macro_real_block = NULL;
+ //scin->state[scin->j].macro_real_block = NULL;
+ scin->state[scin->j].macro_editable = 1;
sc_interp_add_blocks(scin, contents);
sc_interp_restore(scin);
}