aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/narrative_window.c7
-rw-r--r--src/sc_interp.c20
-rw-r--r--src/sc_interp.h5
3 files changed, 23 insertions, 9 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 55d1961..428187c 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -194,9 +194,12 @@ static SCBlock *narrative_stylesheet()
}
-static cairo_surface_t *render_thumbnail(SCBlock *scblocks, void *vp)
+static cairo_surface_t *render_thumbnail(SCInterpreter *scin, SCBlock *bl,
+ void *vp)
{
struct presentation *p = vp;
+ printf("thumbnail callback\n");
+ show_sc_block(sc_interp_get_macro_real_block(scin), "");
return NULL;
}
@@ -238,7 +241,7 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
stylesheets[2] = NULL;
nw->sceditor = sc_editor_new(nw->p->scblocks, stylesheets);
cbl = sc_callback_list_new();
- sc_callback_list_add_callback(cbl, "sthumb", render_thumbnail);
+ sc_callback_list_add_callback(cbl, "sthumb", render_thumbnail, NULL);
sc_editor_set_callbacks(nw->sceditor, cbl);
toolbar = gtk_toolbar_new();
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 7799971..f628754 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -85,6 +85,7 @@ struct _sccallbacklist
int max_callbacks;
char **names;
SCCallbackFunc *funcs;
+ void **vps;
};
@@ -101,6 +102,9 @@ SCCallbackList *sc_callback_list_new()
cbl->funcs = calloc(8, sizeof(cbl->funcs[0]));
if ( cbl->funcs == NULL ) return NULL;
+ cbl->vps = calloc(8, sizeof(cbl->vps[0]));
+ if ( cbl->vps == NULL ) return NULL;
+
cbl->max_callbacks = 8;
cbl->n_callbacks = 0;
@@ -120,35 +124,41 @@ void sc_callback_list_free(SCCallbackList *cbl)
free(cbl->names);
free(cbl->funcs);
+ free(cbl->vps);
free(cbl);
}
void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
- SCCallbackFunc func)
+ SCCallbackFunc func, void *vp)
{
if ( cbl->n_callbacks == cbl->max_callbacks ) {
SCCallbackFunc *funcs_new;
char **names_new;
+ void **vps_new;
int mcn = cbl->max_callbacks + 8;
names_new = realloc(cbl->names, mcn*sizeof(char *));
funcs_new = realloc(cbl->funcs, mcn*sizeof(SCCallbackFunc));
+ vps_new = realloc(cbl->vps, mcn*sizeof(void *));
- if ( (names_new == NULL) || (funcs_new == NULL) ) {
+ if ( (names_new == NULL) || (funcs_new == NULL)
+ || (vps_new == NULL) ) {
fprintf(stderr, "Failed to grow callback list\n");
return;
}
cbl->names = names_new;
cbl->funcs = funcs_new;
+ cbl->vps = vps_new;
cbl->max_callbacks = mcn;
}
cbl->names[cbl->n_callbacks] = strdup(name);
cbl->funcs[cbl->n_callbacks] = func;
+ cbl->vps[cbl->n_callbacks] = vp;
cbl->n_callbacks++;
}
@@ -163,7 +173,7 @@ void sc_interp_set_callbacks(SCInterpreter *scin, SCCallbackList *cbl)
}
-static void do_callback(SCInterpreter *scin, const char *name)
+static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name)
{
int i;
SCCallbackList *cbl = scin->cbl;
@@ -175,7 +185,7 @@ static void do_callback(SCInterpreter *scin, const char *name)
for ( i=0; i<cbl->n_callbacks; i++ ) {
if ( strcmp(cbl->names[i], name) != 0 ) continue;
- cbl->funcs[i](NULL, NULL);
+ cbl->funcs[i](scin, bl, cbl->vps[i]);
return;
}
@@ -917,7 +927,7 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
set_frame_bggrad(sc_interp_get_frame(scin), options,
GRAD_VERT);
} else if ( strcmp(name, "callback") == 0 ) {
- do_callback(scin, options);
+ do_callback(scin, bl, options);
} else {
diff --git a/src/sc_interp.h b/src/sc_interp.h
index c84942f..0963091 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -32,7 +32,8 @@
struct presentation;
typedef struct _scinterp SCInterpreter;
typedef struct _sccallbacklist SCCallbackList;
-typedef cairo_surface_t *(*SCCallbackFunc)(SCBlock *bl, void *);
+typedef cairo_surface_t *(*SCCallbackFunc)(SCInterpreter *scin, SCBlock *bl,
+ void *);
extern SCInterpreter *sc_interp_new(PangoContext *pc, struct frame *top);
extern void sc_interp_destroy(SCInterpreter *scin);
@@ -52,7 +53,7 @@ extern void add_macro(SCInterpreter *scin, const char *mname,
extern SCCallbackList *sc_callback_list_new();
extern void sc_callback_list_free(SCCallbackList *cbl);
extern void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
- SCCallbackFunc func);
+ SCCallbackFunc func, void *vp);
extern void sc_interp_set_callbacks(SCInterpreter *scin, SCCallbackList *cbl);
/* Get the current state of the interpreter */