aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-03-18 17:03:57 +0100
committerThomas White <taw@physics.org>2018-03-18 21:32:59 +0100
commit61394e51a92e28963d82ded391ccf402a0157b5d (patch)
tree489ef30600867a40b4601528809db28e580b9c93
parent0cf5b0a52dfc1134806c56fdd9940d9e2a564cc8 (diff)
Remove \callback
Make the callback mechanism into one of general interception of any Storycode command. This way, the narrative rendering (the only thing using this functionality) doesn't have to do its horrible stylesheet thing. That's necessary so that the rendering function gets the actual SCBlock, not the definition of the macro.
-rw-r--r--src/narrative_window.c21
-rw-r--r--src/print.c16
-rw-r--r--src/sc_interp.c31
3 files changed, 24 insertions, 44 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index e5faffa..8da1c62 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -225,14 +225,6 @@ static SCBlock *get_slide_template(SCBlock *ss)
}
-static SCBlock *narrative_stylesheet()
-{
- return sc_parse("\\stylesheet{"
- "\\ss[slide]{\\callback[sthumb]}"
- "}");
-}
-
-
static SCBlock **get_ss_list(struct presentation *p)
{
SCBlock **stylesheets;
@@ -242,11 +234,9 @@ static SCBlock **get_ss_list(struct presentation *p)
if ( p->stylesheet != NULL ) {
stylesheets[0] = p->stylesheet;
- stylesheets[1] = narrative_stylesheet();
- stylesheets[2] = NULL;
- } else {
- stylesheets[0] = narrative_stylesheet();
stylesheets[1] = NULL;
+ } else {
+ stylesheets[0] = NULL;
}
return stylesheets;
@@ -672,13 +662,10 @@ static int create_thumbnail(SCInterpreter *scin, SCBlock *bl,
double *w, double *h, void **bvp, void *vp)
{
struct presentation *p = vp;
- SCBlock *b;
*w = 270.0*(p->slide_width / p->slide_height);
*h = 270.0;
- b = sc_interp_get_macro_real_block(scin);
-
- *bvp = b;
+ *bvp = bl;
return 1;
}
@@ -817,7 +804,7 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *papp
colloquium_get_imagestore(app));
free(stylesheets);
cbl = sc_callback_list_new();
- sc_callback_list_add_callback(cbl, "sthumb", create_thumbnail,
+ sc_callback_list_add_callback(cbl, "slide", create_thumbnail,
render_thumbnail, click_thumbnail, p);
sc_editor_set_callbacks(nw->sceditor, cbl);
sc_editor_set_imagestore(nw->sceditor, p->is);
diff --git a/src/print.c b/src/print.c
index 18402fc..8275f23 100644
--- a/src/print.c
+++ b/src/print.c
@@ -186,14 +186,6 @@ static cairo_surface_t *print_render_thumbnail(int w, int h, void *bvp, void *vp
}
-static SCBlock *print_narrative_stylesheet()
-{
- return sc_parse("\\stylesheet{"
- "\\ss[slide]{\\callback[sthumb]}"
- "}");
-}
-
-
static void begin_narrative_print(GtkPrintOperation *op, GtkPrintContext *ctx,
struct print_stuff *ps)
{
@@ -205,18 +197,16 @@ static void begin_narrative_print(GtkPrintOperation *op, GtkPrintContext *ctx,
cbl = sc_callback_list_new();
ps->slide_number = 1;
- sc_callback_list_add_callback(cbl, "sthumb", print_create_thumbnail,
+ sc_callback_list_add_callback(cbl, "slide", print_create_thumbnail,
print_render_thumbnail, NULL, ps);
ps->is = imagestore_new(ps->storename);
if ( ps->p->stylesheet != NULL ) {
stylesheets[0] = ps->p->stylesheet;
- stylesheets[1] = print_narrative_stylesheet();
- stylesheets[2] = NULL;
- } else {
- stylesheets[0] = print_narrative_stylesheet();
stylesheets[1] = NULL;
+ } else {
+ stylesheets[0] = NULL;
}
pc = gtk_print_context_create_pango_context(ctx);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 0301aad..6914b13 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -216,15 +216,17 @@ void sc_interp_set_callbacks(SCInterpreter *scin, SCCallbackList *cbl)
}
-static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name)
+static int check_callback(SCInterpreter *scin, SCBlock *bl)
{
int i;
+ const char *name = sc_block_name(bl);
SCCallbackList *cbl = scin->cbl;
- if ( cbl == NULL ) {
- fprintf(stderr, "No callback list.\n");
- return;
- }
+ /* No callback list -> easy */
+ if ( cbl == NULL ) return 0;
+
+ /* No name -> definitely not a callback */
+ if ( name == NULL ) return 0;
for ( i=0; i<cbl->n_callbacks; i++ ) {
@@ -240,15 +242,16 @@ static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name)
if ( strcmp(cbl->names[i], name) != 0 ) continue;
r = cbl->box_funcs[i](scin, bl, &w, &h, &bvp, cbl->vps[i]);
- if ( !r ) return;
- add_callback_para(sc_interp_get_frame(scin), bl, rbl, w, h,
- cbl->draw_funcs[i], cbl->click_funcs[i],
- bvp, cbl->vps[i]);
+ if ( r ) {
+ add_callback_para(sc_interp_get_frame(scin), bl, w, h,
+ cbl->draw_funcs[i], cbl->click_funcs[i],
+ bvp, cbl->vps[i]);
+ }
+ return 1;
- return;
}
- fprintf(stderr, "Unknown callback '%s'\n", name);
+ return 0;
}
@@ -1143,6 +1146,9 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
exec_macro(bl, scin, child);
sc_interp_restore(scin);
+ } else if ( check_callback(scin, bl) ) {
+ /* Handled in check_callback, don't do anything else */
+
} else if ((sc_interp_get_frame(scin) != NULL)
&& check_outputs(bl, scin) ) {
/* Block handled as output thing */
@@ -1209,9 +1215,6 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
set_paraspace(scin, options);
maybe_recurse_after(scin, child);
- } else if ( strcmp(name, "callback") == 0 ) {
- do_callback(scin, bl, options);
-
} else {
//fprintf(stderr, "Don't know what to do with this:\n");