diff options
author | Thomas White <taw@bitwiz.me.uk> | 2018-10-28 00:03:51 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.me.uk> | 2018-10-28 00:03:51 +0200 |
commit | 8e05062ad3b94068825a1f80eb362aa3d3e9098f (patch) | |
tree | 77944d65437fa57755a7bc8bc16fd3e2c5b43f17 /src/stylesheet_editor.c | |
parent | 791ee4e65f3ec7ef470302e4381baefb431fb56d (diff) | |
parent | 21418cfb52b87a32cfdc9bb14be83b85a8e70281 (diff) |
Merge branch 'json-stylesheets'
Diffstat (limited to 'src/stylesheet_editor.c')
-rw-r--r-- | src/stylesheet_editor.c | 594 |
1 files changed, 284 insertions, 310 deletions
diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 66e8afa..8100472 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -33,12 +33,13 @@ #include "stylesheet_editor.h" #include "presentation.h" #include "sc_interp.h" +#include "stylesheet.h" +#include "utils.h" G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor, GTK_TYPE_DIALOG, NULL) -static void set_values_from_presentation(StylesheetEditor *se); struct _sspriv { @@ -46,175 +47,247 @@ struct _sspriv }; -static SCBlock *find_block(SCBlock *bl, const char *find) +static void set_font_from_ss(Stylesheet *ss, const char *path, GtkWidget *w) { - while ( bl != NULL ) { - - const char *name = sc_block_name(bl); - if ( (name != NULL) && (strcmp(name, find)==0) ) { - return bl; - } - - bl = sc_block_next(bl); - + char *result = stylesheet_lookup(ss, path, "font"); + if ( result != NULL ) { + gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), result); } - - return NULL; } -static void find_replace(SCBlock *parent, const char *find, const char *seti) +static void set_col_from_ss(Stylesheet *ss, const char *path, GtkWidget *w) { - SCBlock *bl = find_block(sc_block_child(parent), find); - - if ( bl != NULL ) { + char *result = stylesheet_lookup(ss, path, "fgcol"); + if ( result != NULL ) { + GdkRGBA rgba; + if ( gdk_rgba_parse(&rgba, result) == TRUE ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(w), &rgba); + } + } +} - printf("replacing '%s' with '%s'\n", sc_block_options(bl), seti); - sc_block_set_options(bl, strdup(seti)); +static void set_vals_from_ss(Stylesheet *ss, const char *path, const char *key, + GtkWidget *wl, GtkWidget *wr, + GtkWidget *wt, GtkWidget *wb) +{ + char *result = stylesheet_lookup(ss, path, key); + if ( result != NULL ) { + float v[4]; + if ( parse_tuple(result, v) == 0 ) { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wl), v[0]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wr), v[1]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wt), v[2]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wb), v[3]); + } else { + fprintf(stderr, _("Failed to parse quad: %s\n"), result); + } } else { - - /* Block not found -> create it */ - sc_block_append_inside(parent, strdup(find), strdup(seti), NULL); - + printf("Not found %s\n", path); } } -static SCBlock *find_or_create_style(struct presentation *p, const char *style_name) +static void set_size_from_ss(Stylesheet *ss, const char *path, + GtkWidget *ww, GtkWidget *wh) { - SCBlock *bl; - const char *name; - - /* If no stylesheet yet, create one now */ - if ( p->stylesheet == NULL ) { - p->stylesheet = sc_parse("\\stylesheet"); - if ( p->stylesheet == NULL ) { - fprintf(stderr, "WARNING: Couldn't create stylesheet\n"); - return NULL; + char *result = stylesheet_lookup(ss, path, "size"); + if ( result != NULL ) { + float v[2]; + if ( parse_double(result, v) == 0 ) { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ww), v[0]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wh), v[1]); + } else { + fprintf(stderr, _("Failed to parse double: %s\n"), result); } - sc_block_append_p(p->stylesheet, p->scblocks); - p->scblocks = p->stylesheet; + } else { + printf("Not found %s\n", path); } - bl = p->stylesheet; +} - name = sc_block_name(bl); - if ( (name != NULL) && (strcmp(name, "stylesheet")==0) ) { - bl = sc_block_child(bl); +static void set_bg_from_ss(Stylesheet *ss, const char *path, GtkWidget *wcol, + GtkWidget *wcol2, GtkWidget *wgrad) +{ + char *result; + int found = 0; + + result = stylesheet_lookup(ss, path, "bgcol"); + if ( result != NULL ) { + GdkRGBA rgba; + found = 1; + if ( gdk_rgba_parse(&rgba, result) == TRUE ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "flat"); + gtk_widget_set_sensitive(wcol, TRUE); + gtk_widget_set_sensitive(wcol2, FALSE); + } else { + fprintf(stderr, _("Failed to parse colour: %s\n"), result); + } } - while ( bl != NULL ) { - - const char *name = sc_block_name(bl); - const char *options = sc_block_options(bl); - if ( (name != NULL) && (strcmp(name, "style")==0) - && (strcmp(options, style_name)==0) ) - { - return bl; + result = stylesheet_lookup(ss, path, "bggradv"); + if ( result != NULL ) { + GdkRGBA rgba1, rgba2; + found = 1; + if ( parse_colour_duo(result, &rgba1, &rgba2) == 0 ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba1); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol2), &rgba2); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "vert"); + gtk_widget_set_sensitive(wcol, TRUE); + gtk_widget_set_sensitive(wcol2, TRUE); } + } - bl = sc_block_next(bl); + result = stylesheet_lookup(ss, path, "bggradh"); + if ( result != NULL ) { + GdkRGBA rgba1, rgba2; + found = 1; + if ( parse_colour_duo(result, &rgba1, &rgba2) == 0 ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba1); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol2), &rgba2); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "horiz"); + gtk_widget_set_sensitive(wcol, TRUE); + gtk_widget_set_sensitive(wcol2, TRUE); + } + } + if ( !found ) { + GdkRGBA rgba; + rgba.red = 1.0; + rgba.green = 1.0; + rgba.blue = 1.0; + rgba.alpha = 0.0; + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "flat"); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba); + gtk_widget_set_sensitive(wcol, TRUE); + gtk_widget_set_sensitive(wcol2, FALSE); } +} - /* Not found -> add style */ - return sc_block_append_inside(p->stylesheet, strdup("style"), - strdup(style_name), NULL); + +static void set_values_from_presentation(StylesheetEditor *se) +{ + Stylesheet *ss = se->priv->p->stylesheet; + + /* Narrative */ + set_font_from_ss(ss, "$.narrative", se->narrative_style_font); + set_col_from_ss(ss, "$.narrative", se->narrative_style_fgcol); + set_bg_from_ss(ss, "$.narrative", se->narrative_style_bgcol, + se->narrative_style_bgcol2, + se->narrative_style_bggrad); + set_vals_from_ss(ss, "$.narrative", "pad", se->narrative_style_padding_l, + se->narrative_style_padding_r, + se->narrative_style_padding_t, + se->narrative_style_padding_b); + set_vals_from_ss(ss, "$.narrative", "paraspace", se->narrative_style_paraspace_l, + se->narrative_style_paraspace_r, + se->narrative_style_paraspace_t, + se->narrative_style_paraspace_b); + + /* Slides */ + set_size_from_ss(ss, "$.slide", se->slide_size_w, se->slide_size_h); + set_bg_from_ss(ss, "$.slide", se->slide_style_bgcol, + se->slide_style_bgcol2, + se->slide_style_bggrad); + + + /* Frames */ + set_font_from_ss(ss, "$.slide.frame", se->frame_style_font); + set_col_from_ss(ss, "$.slide.frame", se->frame_style_fgcol); + set_bg_from_ss(ss, "$.slide.frame", se->frame_style_bgcol, + se->frame_style_bgcol2, + se->frame_style_bggrad); + set_vals_from_ss(ss, "$.slide.frame", "pad", se->frame_style_padding_l, + se->frame_style_padding_r, + se->frame_style_padding_t, + se->frame_style_padding_b); + set_vals_from_ss(ss, "$.slide.frame", "paraspace", se->frame_style_paraspace_l, + se->frame_style_paraspace_r, + se->frame_style_paraspace_t, + se->frame_style_paraspace_b); } -static void set_ss(struct presentation *p, const char *style_name, - const char *find, const char *seti) +static GradientType id_to_gradtype(const gchar *id) { - SCBlock *bl = find_or_create_style(p, style_name); - if ( bl == NULL ) { - fprintf(stderr, "WARNING: Couldn't find style\n"); - return; - } - find_replace(bl, find, seti); + assert(id != NULL); + if ( strcmp(id, "flat") == 0 ) return GRAD_NONE; + if ( strcmp(id, "horiz") == 0 ) return GRAD_HORIZ; + if ( strcmp(id, "vert") == 0 ) return GRAD_VERT; + return GRAD_NONE; } -static void set_ss_bg_block(SCBlock *bl, GradientType bggrad, - GdkRGBA col1, GdkRGBA col2) +static void update_bg(struct presentation *p, const char *style_name, + GtkWidget *bggradw, GtkWidget *col1w, GtkWidget*col2w) { - char tmp[64]; + GradientType g; + const gchar *id; + GdkRGBA rgba; + gchar *col1; + gchar *col2; + gchar *gradient; - switch ( bggrad ) { + id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(bggradw)); + g = id_to_gradtype(id); - case GRAD_NONE : - sc_block_set_name(bl, strdup("bgcol")); - snprintf(tmp, 63, "#%.2x%.2x%.2x", - (int)(col1.red*255), (int)(col1.green*255), (int)(col1.blue*255)); - sc_block_set_options(bl, strdup(tmp)); - break; + gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(col1w), &rgba); + if ( rgba.alpha < 0.000001 ) rgba.alpha = 0.0; + col1 = gdk_rgba_to_string(&rgba); - case GRAD_VERT : - sc_block_set_name(bl, strdup("bggradv")); - snprintf(tmp, 63, "#%.2x%.2x%.2x,#%.2x%.2x%.2x", - (int)(col1.red*255), (int)(col1.green*255), (int)(col1.blue*255), - (int)(col2.red*255), (int)(col2.green*255), (int)(col2.blue*255)); - sc_block_set_options(bl, strdup(tmp)); + gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(col2w), &rgba); + col2 = gdk_rgba_to_string(&rgba); + + gradient = g_strconcat(col1, ",", col2, NULL); + + switch ( g ) { + + case GRAD_NONE : + stylesheet_set(p->stylesheet, style_name, "bgcol", + col1); + stylesheet_delete(p->stylesheet, style_name, "bggradv"); + stylesheet_delete(p->stylesheet, style_name, "bggradh"); break; case GRAD_HORIZ : - sc_block_set_name(bl, strdup("bggradh")); - snprintf(tmp, 63, "#%.2x%.2x%.2x,#%.2x%.2x%.2x", - (int)(col1.red*255), (int)(col1.green*255), (int)(col1.blue*255), - (int)(col2.red*255), (int)(col2.green*255), (int)(col2.blue*255)); - sc_block_set_options(bl, strdup(tmp)); + stylesheet_set(p->stylesheet, style_name, "bggradh", + gradient); + stylesheet_delete(p->stylesheet, style_name, "bggradv"); + stylesheet_delete(p->stylesheet, style_name, "bgcol"); break; - case GRAD_NOBG : - printf("no bg\n"); - sc_block_set_name(bl, NULL); - sc_block_set_options(bl, NULL); - sc_block_set_contents(bl, NULL); + case GRAD_VERT : + stylesheet_set(p->stylesheet, style_name, "bggradv", + gradient); + stylesheet_delete(p->stylesheet, style_name, "bggradh"); + stylesheet_delete(p->stylesheet, style_name, "bgcol"); break; } -} - - -static int try_set_block(SCBlock **parent, const char *name, - GradientType bggrad, GdkRGBA col1, GdkRGBA col2) -{ - SCBlock *ibl; - - ibl = find_block(sc_block_child(*parent), name); - if ( ibl != NULL ) { - if ( bggrad != GRAD_NOBG ) { - set_ss_bg_block(ibl, bggrad, col1, col2); - return 1; - } else { - sc_block_delete(parent, ibl); - return 1; - } - } - return 0; + g_free(gradient); + g_free(col1); + g_free(col2); } -static void update_bg(struct presentation *p, const char *style_name, - GradientType bggrad, GdkRGBA col1, GdkRGBA col2) +static void update_spacing(struct presentation *p, const char *style_name, + const char *key, GtkWidget *wl, GtkWidget *wr, + GtkWidget *wt, GtkWidget *wb) { - int done; - SCBlock *bl; + int v[4]; + char tmp[256]; - bl = find_or_create_style(p, style_name); - if ( bl == NULL ) { - fprintf(stderr, "WARNING: Couldn't find style\n"); - return; - } + v[0] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(wl)); + v[1] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(wr)); + v[2] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(wt)); + v[3] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(wb)); - /* FIXME: What if there are two of these? */ - done = try_set_block(&bl, "bgcol", bggrad, col1, col2); - if ( !done ) done = try_set_block(&bl, "bggradv", bggrad, col1, col2); - if ( !done ) done = try_set_block(&bl, "bggradh", bggrad, col1, col2); - if ( !done && bggrad != GRAD_NOBG ) { - SCBlock *ibl = sc_block_append_inside(bl, NULL, NULL, NULL); - set_ss_bg_block(ibl, bggrad, col1, col2); + if ( snprintf(tmp, 256, "%i,%i,%i,%i", v[0], v[1], v[2], v[3]) >= 256 ) { + fprintf(stderr, _("Spacing too long\n")); + } else { + stylesheet_set(p->stylesheet, style_name, key, tmp); } } @@ -225,23 +298,13 @@ static void revert_sig(GtkButton *button, StylesheetEditor *widget) } -static GradientType id_to_gradtype(const gchar *id) -{ - assert(id != NULL); - if ( strcmp(id, "flat") == 0 ) return GRAD_NONE; - if ( strcmp(id, "horiz") == 0 ) return GRAD_HORIZ; - if ( strcmp(id, "vert") == 0 ) return GRAD_VERT; - if ( strcmp(id, "none") == 0 ) return GRAD_NOBG; - return GRAD_NONE; -} - - static void set_font(GtkFontButton *widget, StylesheetEditor *se, const char *style_name) { const gchar *font; font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget)); - set_ss(se->priv->p, style_name, "font", font); + + stylesheet_set(se->priv->p->stylesheet, style_name, "font", font); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } @@ -254,7 +317,7 @@ static void set_col(GtkColorButton *widget, StylesheetEditor *se, gchar *col; gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), &rgba); col = gdk_rgba_to_string(&rgba); - set_ss(se->priv->p, style_name, col_name, col); + stylesheet_set(se->priv->p->stylesheet, style_name, "fgcol", col); g_free(col); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); @@ -263,135 +326,125 @@ static void set_col(GtkColorButton *widget, StylesheetEditor *se, static void narrative_font_sig(GtkFontButton *widget, StylesheetEditor *se) { - set_font(widget, se, "narrative"); + set_font(widget, se, "$.narrative"); } static void narrative_fgcol_sig(GtkColorButton *widget, StylesheetEditor *se) { - set_col(widget, se, "narrative", "fgcol"); + set_col(widget, se, "$.narrative", "fgcol"); } -static void narrative_bgcol_sig(GtkColorButton *widget, StylesheetEditor *se) +static void narrative_bg_sig(GtkColorButton *widget, StylesheetEditor *se) { - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), - &se->narrative_bgcol); - update_bg(se->priv->p, "narrative", se->narrative_bggrad, - se->narrative_bgcol, se->narrative_bgcol2); - + update_bg(se->priv->p, "$.narrative", + se->narrative_style_bggrad, + se->narrative_style_bgcol, + se->narrative_style_bgcol2); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } -static void narrative_bgcol2_sig(GtkColorButton *widget, StylesheetEditor *se) +static void slide_size_sig(GtkSpinButton *widget, StylesheetEditor *se) { - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), - &se->narrative_bgcol2); - update_bg(se->priv->p, "narrative", se->narrative_bggrad, - se->narrative_bgcol, se->narrative_bgcol2); - - set_values_from_presentation(se); - g_signal_emit_by_name(se, "changed"); -} + int w, h; + char tmp[256]; + w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(se->slide_size_w)); + h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(se->slide_size_h)); -static void narrative_bggrad_sig(GtkComboBox *widget, StylesheetEditor *se) -{ - const gchar *id; - id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); - se->narrative_bggrad = id_to_gradtype(id); - update_bg(se->priv->p, "narrative", se->narrative_bggrad, - se->narrative_bgcol, se->narrative_bgcol2); + if ( snprintf(tmp, 256, "%ix%i", w, h) >= 256 ) { + fprintf(stderr, _("Slide size too long\n")); + } else { + stylesheet_set(se->priv->p->stylesheet, "$.slide", "size", tmp); + se->priv->p->slide_width = w; + se->priv->p->slide_height = h; + } set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } -static void slide_bgcol_sig(GtkColorButton *widget, StylesheetEditor *se) +static void slide_bg_sig(GtkColorButton *widget, StylesheetEditor *se) { - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), - &se->slide_bgcol); - update_bg(se->priv->p, "slide", se->slide_bggrad, - se->slide_bgcol, se->slide_bgcol2); - + update_bg(se->priv->p, "$.slide", + se->slide_style_bggrad, + se->slide_style_bgcol, + se->slide_style_bgcol2); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } -static void slide_bgcol2_sig(GtkColorButton *widget, StylesheetEditor *se) +static void frame_font_sig(GtkFontButton *widget, StylesheetEditor *se) { - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), - &se->slide_bgcol2); - update_bg(se->priv->p, "slide", se->slide_bggrad, - se->slide_bgcol, se->slide_bgcol2); - - set_values_from_presentation(se); - g_signal_emit_by_name(se, "changed"); + set_font(widget, se, "$.slide.frame"); } -static void slide_bggrad_sig(GtkComboBox *widget, StylesheetEditor *se) +static void frame_fgcol_sig(GtkColorButton *widget, StylesheetEditor *se) { - const gchar *id; - - id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); - se->slide_bggrad = id_to_gradtype(id); - update_bg(se->priv->p, "slide", se->slide_bggrad, - se->slide_bgcol, se->slide_bgcol2); - - set_values_from_presentation(se); - g_signal_emit_by_name(se, "changed"); + set_col(widget, se, "$.slide.frame", "fgcol"); } -static void frame_font_sig(GtkFontButton *widget, StylesheetEditor *se) +static void frame_bg_sig(GtkColorButton *widget, StylesheetEditor *se) { - set_font(widget, se, "frame"); + update_bg(se->priv->p, "$.slide.frame", + se->frame_style_bggrad, + se->frame_style_bgcol, + se->frame_style_bgcol2); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } -static void frame_fgcol_sig(GtkColorButton *widget, StylesheetEditor *se) +static void frame_padding_sig(GtkSpinButton *widget, StylesheetEditor *se) { - set_col(widget, se, "frame", "fgcol"); + update_spacing(se->priv->p, "$.slide.frame", "pad", + se->frame_style_padding_l, + se->frame_style_padding_r, + se->frame_style_padding_t, + se->frame_style_padding_b); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } -static void frame_bgcol_sig(GtkColorButton *widget, StylesheetEditor *se) +static void frame_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) { - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), - &se->frame_bgcol); - update_bg(se->priv->p, "frame", se->frame_bggrad, - se->frame_bgcol, se->frame_bgcol2); - + update_spacing(se->priv->p, "$.slide.frame", "paraspace", + se->frame_style_paraspace_l, + se->frame_style_paraspace_r, + se->frame_style_paraspace_t, + se->frame_style_paraspace_b); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } -static void frame_bgcol2_sig(GtkColorButton *widget, StylesheetEditor *se) +static void narrative_padding_sig(GtkSpinButton *widget, StylesheetEditor *se) { - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), - &se->frame_bgcol); - update_bg(se->priv->p, "frame", se->frame_bggrad, - se->frame_bgcol, se->frame_bgcol2); - + update_spacing(se->priv->p, "$.narrative", "pad", + se->narrative_style_padding_l, + se->narrative_style_padding_r, + se->narrative_style_padding_t, + se->narrative_style_padding_b); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } -static void frame_bggrad_sig(GtkComboBox *widget, StylesheetEditor *se) +static void narrative_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) { - const gchar *id; - id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); - se->frame_bggrad = id_to_gradtype(id); - update_bg(se->priv->p, "frame", se->frame_bggrad, - se->frame_bgcol, se->frame_bgcol2); - + update_spacing(se->priv->p, "$.narrative", "paraspace", + se->narrative_style_paraspace_l, + se->narrative_style_paraspace_r, + se->narrative_style_paraspace_t, + se->narrative_style_paraspace_b); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } @@ -423,21 +476,39 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) /* Narrative style */ SE_BIND_CHILD(narrative_style_font, narrative_font_sig); SE_BIND_CHILD(narrative_style_fgcol, narrative_fgcol_sig); - SE_BIND_CHILD(narrative_style_bgcol, narrative_bgcol_sig); - SE_BIND_CHILD(narrative_style_bgcol2, narrative_bgcol2_sig); - SE_BIND_CHILD(narrative_style_bggrad, narrative_bggrad_sig); + SE_BIND_CHILD(narrative_style_bgcol, narrative_bg_sig); + SE_BIND_CHILD(narrative_style_bgcol2, narrative_bg_sig); + SE_BIND_CHILD(narrative_style_bggrad, narrative_bg_sig); + SE_BIND_CHILD(narrative_style_paraspace_l, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_paraspace_r, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_paraspace_t, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_paraspace_b, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_padding_l, narrative_padding_sig); + SE_BIND_CHILD(narrative_style_padding_r, narrative_padding_sig); + SE_BIND_CHILD(narrative_style_padding_t, narrative_padding_sig); + SE_BIND_CHILD(narrative_style_padding_b, narrative_padding_sig); /* Slide style */ - SE_BIND_CHILD(slide_style_bgcol, slide_bgcol_sig); - SE_BIND_CHILD(slide_style_bgcol2, slide_bgcol2_sig); - SE_BIND_CHILD(slide_style_bggrad, slide_bggrad_sig); + SE_BIND_CHILD(slide_size_w, slide_size_sig); + SE_BIND_CHILD(slide_size_h, slide_size_sig); + SE_BIND_CHILD(slide_style_bgcol, slide_bg_sig); + SE_BIND_CHILD(slide_style_bgcol2, slide_bg_sig); + SE_BIND_CHILD(slide_style_bggrad, slide_bg_sig); /* Slide->frame style */ SE_BIND_CHILD(frame_style_font, frame_font_sig); SE_BIND_CHILD(frame_style_fgcol, frame_fgcol_sig); - SE_BIND_CHILD(frame_style_bgcol, frame_bgcol_sig); - SE_BIND_CHILD(frame_style_bgcol2, frame_bgcol2_sig); - SE_BIND_CHILD(frame_style_bggrad, frame_bggrad_sig); + SE_BIND_CHILD(frame_style_bgcol, frame_bg_sig); + SE_BIND_CHILD(frame_style_bgcol2, frame_bg_sig); + SE_BIND_CHILD(frame_style_bggrad, frame_bg_sig); + SE_BIND_CHILD(frame_style_paraspace_l, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_paraspace_r, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_paraspace_t, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_paraspace_b, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_padding_l, frame_padding_sig); + SE_BIND_CHILD(frame_style_padding_r, frame_padding_sig); + SE_BIND_CHILD(frame_style_padding_t, frame_padding_sig); + SE_BIND_CHILD(frame_style_padding_b, frame_padding_sig); gtk_widget_class_bind_template_callback(widget_class, revert_sig); @@ -446,103 +517,6 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) } -static void set_from_interp_col(double *col, GtkWidget *w) -{ - GdkRGBA rgba; - - rgba.red = col[0]; - rgba.green = col[1]; - rgba.blue = col[2]; - rgba.alpha = col[3]; - gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(w), &rgba); -} - - -static void set_from_interp_bggrad(SCInterpreter *scin, GtkWidget *w) -{ - GradientType grad; - const gchar *id; - - grad = sc_interp_get_bggrad(scin); - - switch ( grad ) { - case GRAD_NONE : id = "flat"; break; - case GRAD_HORIZ : id = "horiz"; break; - case GRAD_VERT : id = "vert"; break; - case GRAD_NOBG : id = "none"; break; - default : id = NULL; break; - } - - gtk_combo_box_set_active_id(GTK_COMBO_BOX(w), id); -} - - -static void set_from_interp_font(SCInterpreter *scin, GtkWidget *w) -{ - char *fontname; - PangoFontDescription *fontdesc; - - fontdesc = sc_interp_get_fontdesc(scin); - fontname = pango_font_description_to_string(fontdesc); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontname); - g_free(fontname); -} - - -static void set_values_from_presentation(StylesheetEditor *se) -{ - SCInterpreter *scin; - PangoContext *pc; - - pc = gdk_pango_context_get(); - - scin = sc_interp_new(pc, NULL, NULL, NULL); - sc_interp_run_stylesheet(scin, se->priv->p->stylesheet); /* NULL stylesheet is OK */ - - /* Narrative style */ - sc_interp_save(scin); - sc_interp_run_style(scin, "narrative"); - set_from_interp_font(scin, se->narrative_style_font); - set_from_interp_col(sc_interp_get_fgcol(scin), se->narrative_style_fgcol); - set_from_interp_col(sc_interp_get_bgcol(scin), se->narrative_style_bgcol); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->narrative_style_bgcol), - &se->narrative_bgcol); - set_from_interp_col(sc_interp_get_bgcol2(scin), se->narrative_style_bgcol2); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->narrative_style_bgcol2), - &se->narrative_bgcol2); - set_from_interp_bggrad(scin, se->narrative_style_bggrad); - sc_interp_restore(scin); - - /* Slide style */ - sc_interp_save(scin); - sc_interp_run_style(scin, "slide"); - set_from_interp_col(sc_interp_get_bgcol(scin), se->slide_style_bgcol); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->slide_style_bgcol), - &se->slide_bgcol); - set_from_interp_col(sc_interp_get_bgcol2(scin), se->slide_style_bgcol2); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->slide_style_bgcol2), - &se->slide_bgcol2); - set_from_interp_bggrad(scin, se->slide_style_bggrad); - sc_interp_restore(scin); - - /* Slide->Frame style */ - sc_interp_save(scin); - sc_interp_run_style(scin, "frame"); - set_from_interp_font(scin, se->frame_style_font); - set_from_interp_col(sc_interp_get_fgcol(scin), se->frame_style_fgcol); - set_from_interp_col(sc_interp_get_bgcol(scin), se->frame_style_bgcol); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->frame_style_bgcol), - &se->frame_bgcol); - set_from_interp_col(sc_interp_get_bgcol2(scin), se->frame_style_bgcol2); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->frame_style_bgcol2), - &se->frame_bgcol2); - set_from_interp_bggrad(scin, se->frame_style_bggrad); - sc_interp_restore(scin); - - sc_interp_destroy(scin); -} - - StylesheetEditor *stylesheet_editor_new(struct presentation *p) { StylesheetEditor *se; |