aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2013-05-24 22:26:18 +0200
committerThomas White <taw@bitwiz.org.uk>2013-05-24 22:26:18 +0200
commitf520d3f84ca8181e6e4925b83c94fab6c4a6d661 (patch)
tree5d05527c0782ef9b8b6c654cac8e11a8a1d231b8 /src
parent25568bffc829c7e373a9049c713464df456ff6aa (diff)
Load/save stylesshet and menu stuff
Diffstat (limited to 'src')
-rw-r--r--src/default_stylesheet.sty14
-rw-r--r--src/loadsave.c10
-rw-r--r--src/mainwindow.c26
-rw-r--r--src/presentation.c1
-rw-r--r--src/presentation.h9
-rw-r--r--src/stylesheet.c104
6 files changed, 146 insertions, 18 deletions
diff --git a/src/default_stylesheet.sty b/src/default_stylesheet.sty
index d9099d7..575f190 100644
--- a/src/default_stylesheet.sty
+++ b/src/default_stylesheet.sty
@@ -12,6 +12,8 @@ pad_t = 0.00
pad_b = 0.00
w = "1.00 fr"
h = "100.00 u"
+x = 0.0
+y = 300.0
prologue = "\font[Sorts Mill Goudy 64]"
[stylesheet/styles/1]
@@ -26,6 +28,8 @@ pad_t = 20.00
pad_b = 20.00
w = "1.00 fr"
h = "100.00 u"
+x = 0.0
+y = 0.0
prologue = "\bgcol{#00a6eb}\fgcol{#ffffff}\font[Sans 40]"
[stylesheet/styles/2]
@@ -40,6 +44,8 @@ pad_t = 20.00
pad_b = 20.00
w = "1.00 fr"
h = "100.00 u"
+x = 0.0
+y = 0.0
prologue = "\bgcol{#00a6eb}\fgcol{#ffffff}\font[Sans 40]Acknowledgements"
[stylesheet/styles/3]
@@ -54,6 +60,8 @@ pad_t = 20.00
pad_b = 20.00
w = "1.00 fr"
h = "1.00 fr"
+x = 0.0
+y = 100.0
prologue = "\bgcol{#dddddd}\fgcol{#ffffff}\font[Sans 24]"
[stylesheet/templates/0]
@@ -62,10 +70,10 @@ sty0 = 0
[stylesheet/templates/1]
name = "Slide"
-sty1 = 1
+sty0 = 1
[stylesheet/templates/2]
name = "Acknowledgements"
-sty2 = 2
-sty2 = 3
+sty0 = 2
+sty1 = 3
diff --git a/src/loadsave.c b/src/loadsave.c
index 0112f45..32782ff 100644
--- a/src/loadsave.c
+++ b/src/loadsave.c
@@ -454,9 +454,13 @@ char *unescape_text(const char *a)
if ( escape ) {
if ( c == 'r' ) b[l++] = '\r';
- if ( c == 'n' ) b[l++] = '\n';
- if ( c == '\"' ) b[l++] = '\"';
- if ( c == 't' ) b[l++] = '\t';
+ else if ( c == 'n' ) b[l++] = '\n';
+ else if ( c == '\"' ) b[l++] = '\"';
+ else if ( c == 't' ) b[l++] = '\t';
+ else {
+ b[l++] = '\\';
+ b[l++] = c;
+ }
escape = 0;
continue;
}
diff --git a/src/mainwindow.c b/src/mainwindow.c
index d159e7c..8305a47 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -547,16 +547,11 @@ static void do_slide_update(struct presentation *p, PangoContext *pc)
-static gint add_furniture(GtkWidget *widget, struct presentation *p)
+static gint add_furniture(GtkWidget *widget, struct menu_pl *pl)
{
- gchar *name;
- struct style *sty;
struct frame *fr;
-
- g_object_get(G_OBJECT(widget), "label", &name, NULL);
- sty = find_style(p->ss, name);
- g_free(name);
- if ( sty == NULL ) return 0;
+ struct style *sty = pl->sty;
+ struct presentation *p = pl->p;
fr = add_subframe(p->cur_edit_slide->top);
fr->style = sty;
@@ -586,6 +581,7 @@ static void update_style_menus(struct presentation *p)
gtk_widget_destroy(p->menu_rebuild_list[i]);
}
free(p->menu_rebuild_list);
+ free(p->menu_path_list);
/* Add the styles to the "Insert" menu */
menu = gtk_ui_manager_get_widget(p->ui, "/displaywindow/insert");
@@ -605,6 +601,9 @@ static void update_style_menus(struct presentation *p)
p->menu_rebuild_list = calloc(n, sizeof(GtkWidget *));
if ( p->menu_rebuild_list == NULL ) return;
+ p->menu_path_list = calloc(n, sizeof(struct menu_pl));
+ if ( p->menu_path_list == NULL ) return;
+
j = 0;
for ( t = template_first(p->ss, &iter);
t != NULL;
@@ -622,14 +621,21 @@ static void update_style_menus(struct presentation *p)
struct style *s = t->styles[i];
+ p->menu_path_list[j].p = p;
+ p->menu_path_list[j].sty = s;
+
item = gtk_menu_item_new_with_label(s->name);
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
- p->menu_rebuild_list[j++] = item;
+ p->menu_rebuild_list[j] = item;
g_signal_connect(G_OBJECT(item), "activate",
- G_CALLBACK(add_furniture), p);
+ G_CALLBACK(add_furniture),
+ &p->menu_path_list[j]);
+ j++;
}
}
+
+ p->n_menu_rebuild = j;
}
diff --git a/src/presentation.c b/src/presentation.c
index db1a398..6dd3a99 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -242,6 +242,7 @@ struct presentation *new_presentation()
new->n_menu_rebuild = 0;
new->menu_rebuild_list = NULL;
+ new->menu_path_list = NULL;
new->selection = NULL;
new->n_selection = 0;
diff --git a/src/presentation.h b/src/presentation.h
index 84b5490..533ee10 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -67,6 +67,14 @@ enum drag_status
};
+/* Inelegance to make furniture selection menus work */
+struct menu_pl
+{
+ struct presentation *p;
+ struct style *sty;
+};
+
+
struct presentation
{
char *titlebar;
@@ -80,6 +88,7 @@ struct presentation
GtkActionGroup *action_group;
GtkIMContext *im_context;
GtkWidget **menu_rebuild_list;
+ struct menu_pl *menu_path_list;
int n_menu_rebuild;
PangoContext *pc;
ImageStore *is;
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 3e30ea3..35d8211 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -92,8 +92,8 @@ void free_stylesheet(StyleSheet *ss)
}
-extern const char *_binary_src_default_stylesheet_sty_start;
-extern const char *_binary_src_default_stylesheet_sty_size;
+extern void *_binary_src_default_stylesheet_sty_start;
+extern void *_binary_src_default_stylesheet_sty_size;
StyleSheet *default_stylesheet()
{
@@ -125,12 +125,84 @@ StyleSheet *default_stylesheet()
}
+static void get_field_f_units(struct ds_node *root, const char *key,
+ double *val, LengthUnits *units)
+{
+ char *s;
+ char *u;
+ double v;
+ char *check;
+
+ get_field_s(root, key, &s);
+ u = index(s, ' ');
+ if ( u == NULL ) {
+ fprintf(stderr, "Invalid value '%s'\n", s);
+ return;
+ }
+
+ u[0] = '\0';
+ u++;
+ v = strtod(s, &check);
+ if ( check == s ) {
+ fprintf(stderr, "Invalid value '%s'\n", s);
+ return;
+ }
+
+ if ( strcmp(u, "fr") == 0 ) *units = UNITS_FRAC;
+ else if ( strcmp(u, "u") == 0 ) *units = UNITS_SLIDE;
+ else {
+ fprintf(stderr, "Invalid unit '%s'\n", u);
+ return;
+ }
+
+ *val = v;
+}
+
+
+static int read_template(struct slide_template *t, StyleSheet *ss,
+ struct ds_node *node)
+{
+ int i;
+
+ for ( i=0; i<node->n_children; i++ ) {
+
+ long v;
+ char *check;
+ struct style *sty;
+
+ if ( strncmp(node->children[i]->key, "sty", 3) != 0 ) {
+ continue;
+ }
+
+ v = strtol(node->children[i]->value, &check, 10);
+ if ( check == node->children[i]->value ) {
+ fprintf(stderr, "Invalid number '%s'\n",
+ node->children[i]->value);
+ }
+ sty = ss->styles[v];
+
+ add_to_template(t, sty);
+ }
+
+ return 0;
+}
+
+
static int read_style(struct style *sty, struct ds_node *root)
{
get_field_f(root, "margin_l", &sty->lop.margin_l);
get_field_f(root, "margin_r", &sty->lop.margin_r);
get_field_f(root, "margin_t", &sty->lop.margin_t);
get_field_f(root, "margin_b", &sty->lop.margin_b);
+ get_field_f(root, "pad_l", &sty->lop.pad_l);
+ get_field_f(root, "pad_r", &sty->lop.pad_r);
+ get_field_f(root, "pad_t", &sty->lop.pad_t);
+ get_field_f(root, "pad_b", &sty->lop.pad_b);
+ get_field_f(root, "x", &sty->lop.x);
+ get_field_f(root, "y", &sty->lop.y);
+ get_field_f_units(root, "w", &sty->lop.w, &sty->lop.w_units);
+ get_field_f_units(root, "h", &sty->lop.h, &sty->lop.h_units);
+ get_field_s(root, "prologue", &sty->sc_prologue);
return 0;
}
@@ -185,6 +257,32 @@ StyleSheet *tree_to_stylesheet(struct ds_node *root)
return NULL;
}
+ for ( i=0; i<node->n_children; i++ ) {
+
+ struct slide_template *nt;
+ char *v;
+
+ get_field_s(node->children[i], "name", &v);
+ if ( v == NULL ) {
+ fprintf(stderr, "No name for template '%s'\n",
+ node->children[i]->key);
+ continue;
+ }
+
+ nt = new_template(ss, v);
+ if ( nt == NULL ) {
+ fprintf(stderr, "Couldn't create template for '%s'\n",
+ node->children[i]->key);
+ continue;
+ }
+
+ if ( read_template(nt, ss, node->children[i]) ) {
+ fprintf(stderr, "Couldn't read template '%s'\n", v);
+ continue;
+ }
+
+ }
+
return ss;
}
@@ -296,6 +394,8 @@ void write_stylesheet(StyleSheet *ss, struct serializer *ser)
serialize_f(ser, "pad_b", s->lop.pad_b);
serialize_f_units(ser, "w", s->lop.w, s->lop.w_units);
serialize_f_units(ser, "h", s->lop.h, s->lop.h_units);
+ serialize_f(ser, "x", s->lop.x);
+ serialize_f(ser, "y", s->lop.y);
serialize_s(ser, "prologue", s->sc_prologue);
serialize_end(ser);