aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-09-10 01:17:12 +0200
committerThomas White <taw@bitwiz.org.uk>2012-09-10 01:17:12 +0200
commitb254880cc2f1ebad293c9396e71e1158a5d86ee2 (patch)
tree2ecf17eee73625a376eb3479e7101d9d3aef99fa /src
parent750e7e89dd7b7fdf8a4b8543d6dd7b66fdc70942 (diff)
Slide template stuff
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.c42
-rw-r--r--src/stylesheet.c106
-rw-r--r--src/stylesheet.h24
3 files changed, 143 insertions, 29 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 65a94df..8419e1e 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -513,13 +513,31 @@ static gint open_notes_sig(GtkWidget *widget, struct presentation *p)
}
+static gint add_furniture(GtkWidget *widget, struct presentation *p)
+{
+ gchar *name;
+ struct style *sty;
+
+ g_object_get(G_OBJECT(widget), "label", &name, NULL);
+ sty = find_style(p->ss, name);
+ g_free(name);
+ if ( sty == NULL ) return 0;
+
+ /* FIXME: Create it */
+
+ return 0;
+}
+
+
static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
{
GError *error = NULL;
GtkWidget *toolbar;
GtkWidget *menu;
GtkWidget *item;
- //int i;
+ struct style *s;
+ StyleIterator *iter;
+
GtkActionEntry entries[] = {
{ "FileAction", NULL, "_File", NULL, NULL, NULL },
@@ -613,17 +631,15 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
item = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
- /* FIXME */
- //for ( i=1; i<p->ss->n_styles; i++ )
- //{
- // char *name;
- // name = p->ss->styles[i]->name;
- // item = gtk_menu_item_new_with_label(name);
- // gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
- // g_signal_connect(G_OBJECT(item), "activate",
- // G_CALLBACK(add_furniture), p);
- //
- //}
+ for ( s = style_first(p->ss, &iter);
+ s != NULL;
+ s = style_next(p->ss, iter) )
+ {
+ item = gtk_menu_item_new_with_label(s->name);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+ g_signal_connect(G_OBJECT(item), "activate",
+ G_CALLBACK(add_furniture), p);
+ }
update_toolbar(p);
}
@@ -658,7 +674,7 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr,
xoff = (width - p->slide_width)/2.0;
yoff = (height - p->slide_height)/2.0;
p->border_offs_x = xoff; p->border_offs_y = yoff;
-
+
/* Draw the slide from the cache */
cairo_rectangle(cr, xoff, yoff, p->slide_width, p->slide_height);
cairo_set_source_surface(cr, p->cur_edit_slide->rendered_edit,
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 8cf519f..8852b3e 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -35,6 +35,16 @@
#include "loadsave.h"
+struct _stylesheet
+{
+ struct style **styles;
+ int n_styles;
+
+ struct slide_template **templates;
+ int n_templates;
+};
+
+
struct style *new_style(StyleSheet *ss, const char *name)
{
struct style *sty;
@@ -78,19 +88,34 @@ void free_stylesheet(StyleSheet *ss)
void default_stylesheet(StyleSheet *ss)
{
struct style *sty;
+ struct slide_template *titlepage;
+ struct slide_template *slide;
+ struct slide_template *acknowledgements;
+
+ titlepage = new_template(ss, "Title page");
+ slide = new_template(ss, "Slide");
+ acknowledgements = new_template(ss, "Acknowledgements");
+
+ sty = new_style(ss, "Presentation title");
+ sty->lop.margin_l = 20.0;
+ sty->lop.margin_r = 20.0;
+ sty->lop.margin_t = 20.0;
+ sty->lop.margin_b = 20.0;
+ add_to_template(titlepage, sty);
- /* Default style must be first */
- sty = new_style(ss, "Default");
+ sty = new_style(ss, "Content");
sty->lop.margin_l = 20.0;
sty->lop.margin_r = 20.0;
sty->lop.margin_t = 20.0;
sty->lop.margin_b = 20.0;
+ add_to_template(slide, sty);
sty = new_style(ss, "Slide title");
sty->lop.margin_l = 20.0;
sty->lop.margin_r = 20.0;
sty->lop.margin_t = 20.0;
sty->lop.margin_b = 20.0;
+ add_to_template(slide, sty);
}
@@ -245,3 +270,80 @@ struct style *find_style(StyleSheet *ss, const char *name)
return NULL;
}
+
+
+struct slide_template *new_template(StyleSheet *ss, const char *name)
+{
+ struct slide_template *t;
+ int n;
+ struct slide_template **templates_new;
+
+ t = calloc(1, sizeof(*t));
+ if ( t == NULL ) return NULL;
+
+ t->name = strdup(name);
+
+ n = ss->n_templates;
+ templates_new = realloc(ss->templates, (n+1)*sizeof(t));
+ if ( templates_new == NULL ) {
+ free(t->name);
+ free(t);
+ return NULL;
+ }
+ ss->templates = templates_new;
+ ss->templates[n] = t;
+ ss->n_templates = n+1;
+
+ return t;
+}
+
+
+void add_to_template(struct slide_template *t, struct style *sty)
+{
+ int n;
+ struct style **styles_new;
+
+ n = t->n_styles;
+ styles_new = realloc(t->styles, (n+1)*sizeof(sty));
+ if ( styles_new == NULL ) {
+ fprintf(stderr, "Failed to add style '%s' to template '%s'.\n",
+ sty->name, t->name);
+ return;
+ }
+ t->styles = styles_new;
+ t->styles[n] = sty;
+ t->n_styles = n+1;
+}
+
+
+struct _styleiterator
+{
+ int n;
+};
+
+struct style *style_first(StyleSheet *ss, StyleIterator **piter)
+{
+ StyleIterator *iter;
+
+ if ( ss->n_styles == 0 ) return NULL;
+
+ iter = calloc(1, sizeof(StyleIterator));
+ if ( iter == NULL ) return NULL;
+
+ iter->n = 0;
+ *piter = iter;
+
+ return ss->styles[0];
+}
+
+
+struct style *style_next(StyleSheet *ss, StyleIterator *iter)
+{
+ iter->n++;
+ if ( iter->n == ss->n_styles ) {
+ free(iter);
+ return NULL;
+ }
+
+ return ss->styles[iter->n];
+}
diff --git a/src/stylesheet.h b/src/stylesheet.h
index 58f4c13..49e3b77 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -49,15 +49,9 @@ struct slide_template
{
char *name;
- struct frame_class **frame_classes;
- int n_frame_classes;
-};
-
-
-struct _stylesheet
-{
- struct style **styles;
- int n_styles;
+ /* References to the styles in the main list */
+ struct style **styles;
+ int n_styles;
};
@@ -70,16 +64,18 @@ extern void free_stylesheet(StyleSheet *ss);
extern void default_stylesheet(StyleSheet *ss);
extern struct style *new_style(StyleSheet *ss, const char *name);
-
-extern int save_stylesheet(StyleSheet *ss, const char *filename);
-
extern struct style *find_style(StyleSheet *ss, const char *name);
-extern enum justify str_to_halign(char *halign);
-extern enum vert_pos str_to_valign(char *valign);
+extern struct slide_template *new_template(StyleSheet *ss, const char *name);
+extern void add_to_template(struct slide_template *t, struct style *sty);
+extern int save_stylesheet(StyleSheet *ss, const char *filename);
extern StyleSheet *tree_to_stylesheet(struct ds_node *root);
extern void write_stylesheet(StyleSheet *ss, struct serializer *ser);
+typedef struct _styleiterator StyleIterator;
+
+extern struct style *style_first(StyleSheet *ss, StyleIterator **piter);
+extern struct style *style_next(StyleSheet *ss, StyleIterator *iter);
#endif /* STYLESHEET_H */