From 072516c65a7335cc168e6ecc9b5a0737c9842913 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 1 May 2018 22:12:22 +0200 Subject: Get rid of stylesheet lists and add stylesheet change signal We no longer have a need for more than one (since the callback stuff changed, see 61394e51), and removing it makes it much easier to hook up the stylesheet update code for the stylesheet editor. --- src/narrative_window.c | 54 +++++++++++++++++-------------------------------- src/print.c | 24 +++++----------------- src/render.c | 25 ++++++++--------------- src/render.h | 4 ++-- src/sc_editor.c | 39 ++++++----------------------------- src/sc_editor.h | 6 +++--- src/slide_window.c | 6 +----- src/slideshow.c | 6 +----- src/stylesheet_editor.c | 7 +++++++ 9 files changed, 52 insertions(+), 119 deletions(-) diff --git a/src/narrative_window.c b/src/narrative_window.c index 027281c..0f6145d 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -244,24 +244,6 @@ static SCBlock *get_slide_template(SCBlock *ss) } -static SCBlock **get_ss_list(struct presentation *p) -{ - SCBlock **stylesheets; - - stylesheets = malloc(3 * sizeof(SCBlock *)); - if ( stylesheets == NULL ) return NULL; - - if ( p->stylesheet != NULL ) { - stylesheets[0] = p->stylesheet; - stylesheets[1] = NULL; - } else { - stylesheets[0] = NULL; - } - - return stylesheets; -} - - static gint load_ss_response_sig(GtkWidget *d, gint response, NarrativeWindow *nw) { @@ -275,22 +257,20 @@ static gint load_ss_response_sig(GtkWidget *d, gint response, stext = load_everything(filename); if ( stext != NULL ) { + SCBlock *bl; SCBlock *ss; bl = sc_parse(stext); free(stext); ss = find_stylesheet(bl); - if ( ss != NULL ) { - SCBlock **stylesheets; + if ( ss != NULL ) { - /* Substitute the style sheet */ + /* Substitute the style sheet in + * presentation Storycode */ replace_stylesheet(nw->p, ss); - stylesheets = get_ss_list(nw->p); - sc_editor_set_stylesheets(nw->sceditor, - stylesheets); - free(stylesheets); + sc_editor_set_stylesheet(nw->sceditor, ss); /* Full rerender, first block may have * changed */ @@ -314,6 +294,16 @@ static gint load_ss_response_sig(GtkWidget *d, gint response, } +static void stylesheet_changed_sig(GtkWidget *da, NarrativeWindow *nw) +{ + /* It might have changed (been created) since last time */ + sc_editor_set_stylesheet(nw->sceditor, nw->p->stylesheet); + + /* Full rerender, first block may have changed */ + sc_editor_set_scblock(nw->sceditor, nw->dummy_top); +} + + static void edit_ss_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { @@ -322,6 +312,8 @@ static void edit_ss_sig(GSimpleAction *action, GVariant *parameter, se = stylesheet_editor_new(nw->p); gtk_window_set_transient_for(GTK_WINDOW(se), GTK_WINDOW(nw->window)); + g_signal_connect(G_OBJECT(se), "changed", + G_CALLBACK(stylesheet_changed_sig), nw); gtk_widget_show_all(GTK_WIDGET(se)); } @@ -715,16 +707,12 @@ static cairo_surface_t *render_thumbnail(int w, int h, void *bvp, void *vp) struct presentation *p = vp; SCBlock *scblocks = bvp; cairo_surface_t *surf; - SCBlock *stylesheets[2]; struct frame *top; int sn = slide_number(p, scblocks); - stylesheets[0] = p->stylesheet; - stylesheets[1] = NULL; - /* FIXME: Cache like crazy here */ surf = render_sc(scblocks, w, h, p->slide_width, p->slide_height, - stylesheets, NULL, p->is, sn, &top, p->lang); + p->stylesheet, NULL, p->is, sn, &top, p->lang); frame_free(top); return surf; @@ -793,7 +781,6 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *papp GtkWidget *scroll; GtkWidget *toolbar; GtkToolItem *button; - SCBlock **stylesheets; SCCallbackList *cbl; GtkWidget *image; Colloquium *app = COLLOQUIUM(papp); @@ -821,8 +808,6 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *papp vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(nw->window), vbox); - stylesheets = get_ss_list(p); - /* If the presentation is completely empty, give ourselves at least * something to work with */ if ( nw->p->scblocks == NULL ) { @@ -833,9 +818,8 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *papp * SCEditor will start processing one level down */ nw->dummy_top = sc_block_new_parent(nw->p->scblocks, "presentation"); - nw->sceditor = sc_editor_new(nw->dummy_top, stylesheets, p->lang, + nw->sceditor = sc_editor_new(nw->dummy_top, p->stylesheet, p->lang, colloquium_get_imagestore(app)); - free(stylesheets); cbl = sc_callback_list_new(); sc_callback_list_add_callback(cbl, "slide", create_thumbnail, render_thumbnail, click_thumbnail, p); diff --git a/src/print.c b/src/print.c index ce52ba8..c50a3c5 100644 --- a/src/print.c +++ b/src/print.c @@ -106,7 +106,6 @@ static void print_slide_only(GtkPrintOperation *op, GtkPrintContext *ctx, cairo_t *cr; PangoContext *pc; double w, h; - SCBlock *stylesheets[2]; struct frame *top; const double sw = ps->p->slide_width; const double sh = ps->p->slide_height; @@ -117,9 +116,6 @@ static void print_slide_only(GtkPrintOperation *op, GtkPrintContext *ctx, w = gtk_print_context_get_width(ctx); h = gtk_print_context_get_height(ctx); - stylesheets[0] = ps->p->stylesheet; - stylesheets[1] = NULL; - cairo_rectangle(cr, 0.0, 0.0, w, h); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_fill(cr); @@ -136,7 +132,7 @@ static void print_slide_only(GtkPrintOperation *op, GtkPrintContext *ctx, printf("%f x %f ---> %f x %f\n", w, h, slide_width, slide_height); - top = interp_and_shape(ps->slide, stylesheets, NULL, + top = interp_and_shape(ps->slide, ps->p->stylesheet, NULL, ps->p->is, page+1, pc, sw, sh, ps->p->lang); recursive_wrap(top, pc); @@ -173,13 +169,11 @@ static cairo_surface_t *print_render_thumbnail(int w, int h, void *bvp, void *vp struct presentation *p = ps->p; SCBlock *scblocks = bvp; cairo_surface_t *surf; - SCBlock *stylesheets[2]; struct frame *top; - stylesheets[0] = p->stylesheet; - stylesheets[1] = NULL; - surf = render_sc(scblocks, w, h, p->slide_width, p->slide_height, stylesheets, NULL, - p->is, ps->slide_number++, &top, p->lang); + surf = render_sc(scblocks, w, h, p->slide_width, p->slide_height, + p->stylesheet, NULL, p->is, ps->slide_number++, + &top, p->lang); frame_free(top); return surf; @@ -189,7 +183,6 @@ static cairo_surface_t *print_render_thumbnail(int w, int h, void *bvp, void *vp static void begin_narrative_print(GtkPrintOperation *op, GtkPrintContext *ctx, struct print_stuff *ps) { - SCBlock *stylesheets[3]; SCCallbackList *cbl; PangoContext *pc; int i, n_pages; @@ -203,17 +196,10 @@ static void begin_narrative_print(GtkPrintOperation *op, GtkPrintContext *ctx, ps->is = imagestore_new(ps->storename); - if ( ps->p->stylesheet != NULL ) { - stylesheets[0] = ps->p->stylesheet; - stylesheets[1] = NULL; - } else { - stylesheets[0] = NULL; - } - pc = gtk_print_context_create_pango_context(ctx); dummy_top = sc_block_new_parent(ps->p->scblocks, "presentation"); - ps->top = interp_and_shape(dummy_top, stylesheets, cbl, + ps->top = interp_and_shape(dummy_top, ps->p->stylesheet, cbl, ps->is, 0, pc, gtk_print_context_get_width(ctx), gtk_print_context_get_height(ctx), diff --git a/src/render.c b/src/render.c index fd8151c..7adbcbc 100644 --- a/src/render.c +++ b/src/render.c @@ -171,7 +171,7 @@ int recursive_wrap(struct frame *fr, PangoContext *pc) } -struct frame *interp_and_shape(SCBlock *scblocks, SCBlock **stylesheets, +struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, PangoContext *pc, double w, double h, @@ -201,12 +201,8 @@ struct frame *interp_and_shape(SCBlock *scblocks, SCBlock **stylesheets, snprintf(snum, 63, "%i", slide_number); add_macro(scin, "slidenumber", snum); - if ( stylesheets != NULL ) { - int i = 0; - while ( stylesheets[i] != NULL ) { - sc_interp_run_stylesheet(scin, stylesheets[i]); - i++; - } + if ( stylesheet != NULL ) { + sc_interp_run_stylesheet(scin, stylesheet); } top->fontdesc = pango_font_description_copy(sc_interp_get_fontdesc(scin)); @@ -225,7 +221,7 @@ struct frame *interp_and_shape(SCBlock *scblocks, SCBlock **stylesheets, static struct frame *render_sc_with_context(SCBlock *scblocks, cairo_t *cr, double log_w, double log_h, - SCBlock **stylesheets, SCCallbackList *cbl, + SCBlock *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, PangoLanguage *lang, PangoContext *pc) @@ -236,7 +232,7 @@ static struct frame *render_sc_with_context(SCBlock *scblocks, cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_fill(cr); - top = interp_and_shape(scblocks, stylesheets, cbl, is, + top = interp_and_shape(scblocks, stylesheet, cbl, is, slide_number, pc, log_w, log_h, lang); recursive_wrap(top, pc); @@ -249,7 +245,7 @@ static struct frame *render_sc_with_context(SCBlock *scblocks, cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, double log_w, double log_h, - SCBlock **stylesheets, SCCallbackList *cbl, + SCBlock *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, struct frame **ptop, PangoLanguage *lang) @@ -264,7 +260,7 @@ cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, pc = pango_cairo_create_context(cr); cairo_scale(cr, w/log_w, h/log_h); top = render_sc_with_context(scblocks, cr, log_w, log_h, - stylesheets, cbl, is, slide_number, + stylesheet, cbl, is, slide_number, lang, pc); g_object_unref(pc); cairo_destroy(cr); @@ -307,11 +303,6 @@ int export_pdf(struct presentation *p, const char *filename) continue; } - SCBlock *stylesheets[2]; - - stylesheets[0] = p->stylesheet; - stylesheets[1] = NULL; - cairo_save(cr); cairo_scale(cr, scale, scale); @@ -321,7 +312,7 @@ int export_pdf(struct presentation *p, const char *filename) cairo_fill(cr); render_sc_with_context(bl, cr, p->slide_width, - p->slide_height, stylesheets, NULL, + p->slide_height, p->stylesheet, NULL, p->is, i, p->lang, pc); cairo_restore(cr); diff --git a/src/render.h b/src/render.h index b3404f0..aadb033 100644 --- a/src/render.h +++ b/src/render.h @@ -35,7 +35,7 @@ /* Convienience function to run the entire pipeline */ extern cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, double log_w, double log_h, - SCBlock **stylesheets, SCCallbackList *cbl, + SCBlock *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, struct frame **ptop, PangoLanguage *lang); @@ -44,7 +44,7 @@ extern cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, * Needs to be followed by: wrap_contents() (recursively) * recursive_draw() */ -extern struct frame *interp_and_shape(SCBlock *scblocks, SCBlock **stylesheets, +extern struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, PangoContext *pc, diff --git a/src/sc_editor.c b/src/sc_editor.c index 3183fb3..999f919 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -195,8 +195,7 @@ static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event, w = e->log_w; h = e->log_h; } - e->top = interp_and_shape(e->scblocks, - e->stylesheets, e->cbl, + e->top = interp_and_shape(e->scblocks, e->stylesheet, e->cbl, e->is, e->slidenum, pc, w, h, e->lang); e->top->scblocks = e->scblocks; @@ -407,8 +406,7 @@ static void full_rerender(SCEditor *e) pc = gdk_pango_context_get(); - e->top = interp_and_shape(e->scblocks, - e->stylesheets, e->cbl, + e->top = interp_and_shape(e->scblocks, e->stylesheet, e->cbl, e->is, e->slidenum, pc, e->log_w, 0.0, e->lang); @@ -2035,34 +2033,9 @@ void sc_editor_set_top_frame_editable(SCEditor *e, int top_frame_editable) } -static SCBlock **copy_ss_list(SCBlock **stylesheets) +void sc_editor_set_stylesheet(SCEditor *e, SCBlock *stylesheet) { - int n_ss = 0; - int i = 0; - SCBlock **ssc; - - if ( stylesheets == NULL ) return NULL; - - while ( stylesheets[n_ss] != NULL ) n_ss++; - n_ss++; /* One more for sentinel */ - - ssc = malloc(n_ss*sizeof(SCBlock *)); - if ( ssc == NULL ) return NULL; - - for ( i=0; istylesheets[i] != NULL ) { - sc_block_free(e->stylesheets[i++]); - } - free(e->stylesheets); - e->stylesheets = copy_ss_list(stylesheets); + e->stylesheet = stylesheet; } @@ -2152,7 +2125,7 @@ void sc_editor_set_imagestore(SCEditor *e, ImageStore *is) } -SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets, +SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock *stylesheet, PangoLanguage *lang, const char *storename) { SCEditor *sceditor; @@ -2182,7 +2155,7 @@ SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets, sceditor->para_highlight = 0; sc_editor_remove_cursor(sceditor); - sceditor->stylesheets = copy_ss_list(stylesheets); + sceditor->stylesheet = stylesheet; sceditor->bg_pixbuf = NULL; diff --git a/src/sc_editor.h b/src/sc_editor.h index 5fea0e1..adbbaf2 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -94,7 +94,7 @@ struct _sceditor double log_w; /* Size of surface in "SC units" */ double log_h; SCBlock *scblocks; - SCBlock **stylesheets; + SCBlock *stylesheet; ImageStore *is; SCCallbackList *cbl; struct frame *top; @@ -168,10 +168,10 @@ typedef struct _sceditor SCEditor; typedef struct _sceditorclass SCEditorClass; extern void sc_editor_set_scblock(SCEditor *e, SCBlock *scblocks); -extern void sc_editor_set_stylesheets(SCEditor *e, SCBlock **stylesheets); +extern void sc_editor_set_stylesheet(SCEditor *e, SCBlock *stylesheet); extern SCBlock *sc_editor_get_scblock(SCEditor *e); extern GtkWidget *sc_editor_get_widget(SCEditor *e); -extern SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets, +extern SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock *stylesheet, PangoLanguage *lang, const char *storename); extern void sc_editor_set_size(SCEditor *e, int w, int h); extern void sc_editor_set_logical_size(SCEditor *e, double w, double h); diff --git a/src/slide_window.c b/src/slide_window.c index a9f8459..b010d1b 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -238,7 +238,6 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks, { GtkWidget *window; SlideWindow *sw; - SCBlock *stylesheets[2]; Colloquium *app = COLLOQUIUM(papp); sw = calloc(1, sizeof(SlideWindow)); @@ -255,11 +254,8 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks, g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(sw_close_sig), sw); - stylesheets[0] = p->stylesheet; - stylesheets[1] = NULL; - sw->scblocks = scblocks; - sw->sceditor = sc_editor_new(scblocks, stylesheets, p->lang, + sw->sceditor = sc_editor_new(scblocks, p->stylesheet, p->lang, colloquium_get_imagestore(app)); sc_editor_set_slidenum(sw->sceditor, slide_number(sw->p, scblocks)); sc_editor_set_scale(sw->sceditor, 1); diff --git a/src/slideshow.c b/src/slideshow.c index 754a453..6e1c49d 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -54,7 +54,6 @@ void sc_slideshow_class_init(SCSlideshowClass *klass) static void slideshow_rerender(SCSlideshow *ss) { int n; - SCBlock *stylesheets[2]; gint w, h; if ( ss->cur_slide == NULL ) return; @@ -63,14 +62,11 @@ static void slideshow_rerender(SCSlideshow *ss) cairo_surface_destroy(ss->surface); } - stylesheets[0] = ss->p->stylesheet; - stylesheets[1] = NULL; - n = slide_number(ss->p, ss->cur_slide); ss->surface = render_sc(ss->cur_slide, ss->slide_width, ss->slide_height, ss->p->slide_width, ss->p->slide_height, - stylesheets, NULL, ss->p->is, n, + ss->p->stylesheet, NULL, ss->p->is, n, &ss->top, ss->p->lang); w = gtk_widget_get_allocated_width(GTK_WIDGET(ss->drawingarea)); diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 66644f6..6dee835 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -58,6 +58,8 @@ static void set_ss(struct presentation *p, const char *find, const char *seti) fprintf(stderr, "WARNING: Couldn't create stylesheet\n"); return; } + sc_block_append_p(p->stylesheet, p->scblocks); + p->scblocks = p->stylesheet; } bl = p->stylesheet; @@ -97,6 +99,7 @@ static void default_font_sig(GtkFontButton *widget, StylesheetEditor *se) font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget)); set_ss(se->priv->p, "font", font); set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } @@ -109,6 +112,7 @@ static void default_colour_sig(GtkColorButton *widget, StylesheetEditor *se) set_ss(se->priv->p, "fgcol", col); g_free(col); set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } @@ -140,6 +144,9 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) gtk_widget_class_bind_template_callback(widget_class, revert_sig); gtk_widget_class_bind_template_callback(widget_class, default_font_sig); gtk_widget_class_bind_template_callback(widget_class, default_colour_sig); + + g_signal_new("changed", COLLOQUIUM_TYPE_STYLESHEET_EDITOR, + G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } -- cgit v1.2.3