aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-12-18 01:05:09 +0100
committerThomas White <taw@bitwiz.org.uk>2011-12-18 01:05:09 +0100
commit0f0b800481ee358cbe2bd5eb068b4ab58b327ab7 (patch)
tree46931121410acdfd1ac0ea333524e83300c3ca96
parentb2811318f359d51cb892f53964dcb7ecbd71f0f5 (diff)
Auto-furniture: part 1
-rw-r--r--src/mainwindow.c2
-rw-r--r--src/presentation.c34
-rw-r--r--src/presentation.h4
-rw-r--r--src/stylesheet.c8
-rw-r--r--src/stylesheet.h16
-rw-r--r--src/tool_text.c68
6 files changed, 123 insertions, 9 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 1201667..eb68ba8 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -494,7 +494,7 @@ static gint add_furniture(GtkWidget *widget, struct presentation *p)
if ( sty == NULL ) return 0;
force_tool(p, TOOL_TEXT);
- p->text_tool->create_default(p, sty, p->text_tool);
+ p->text_tool->create_default(p, sty, p->cur_edit_slide, p->text_tool);
return 0;
}
diff --git a/src/presentation.c b/src/presentation.c
index cdb4a14..9261307 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -140,6 +140,40 @@ struct slide *add_slide(struct presentation *p, int pos)
free_slide(s);
return NULL;
}
+
+ if ( pos >= 0 ) {
+ struct slide *ex = p->slides[pos];
+
+ s->roles[S_ROLE_PTITLE_REF] = ex->roles[S_ROLE_PTITLE_REF];
+ s->roles[S_ROLE_PAUTHOR_REF] = ex->roles[S_ROLE_PAUTHOR_REF];
+ s->roles[S_ROLE_PDATE_REF] = ex->roles[S_ROLE_PDATE_REF];
+
+ if ( ex->roles[S_ROLE_PTITLE] != NULL ) {
+ p->text_tool->create_default(p,
+ ex->roles[S_ROLE_PTITLE]->style, s,
+ p->text_tool);
+ }
+
+ if ( ex->roles[S_ROLE_SLIDENUMBER] != NULL ) {
+ p->text_tool->create_default(p,
+ ex->roles[S_ROLE_SLIDENUMBER]->style, s,
+ p->text_tool);
+ }
+
+ if ( ex->roles[S_ROLE_PAUTHOR] != NULL ) {
+ p->text_tool->create_default(p,
+ ex->roles[S_ROLE_PAUTHOR]->style, s,
+ p->text_tool);
+ }
+
+ if ( ex->roles[S_ROLE_PDATE] != NULL ) {
+ p->text_tool->create_default(p,
+ ex->roles[S_ROLE_PDATE]->style, s,
+ p->text_tool);
+ }
+
+ }
+
return s;
}
diff --git a/src/presentation.h b/src/presentation.h
index efe9d5c..3a781d9 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -27,7 +27,6 @@
#include <config.h>
#endif
-
#include <gtk/gtk.h>
#include "stylesheet.h"
@@ -36,6 +35,7 @@
struct slide
{
struct presentation *parent;
+ struct object *roles[NUM_S_ROLES];
/* Any of these may be NULL */
cairo_surface_t *rendered_proj;
@@ -75,7 +75,7 @@ struct toolinfo
enum drag_status *drag_status,
enum drag_reason *drag_reason);
void (*create_default)(struct presentation *p, struct style *sty,
- struct toolinfo *tip);
+ struct slide *s, struct toolinfo *tip);
void (*select)(struct object *o, struct toolinfo *tip);
int (*deselect)(struct object *o, struct toolinfo *tip);
void (*drag)(struct toolinfo *tip, struct presentation *p,
diff --git a/src/stylesheet.c b/src/stylesheet.c
index a597abd..296d562 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -419,6 +419,7 @@ struct style *new_style(StyleSheet *ss, const char *name)
if ( sty == NULL ) return NULL;
sty->name = strdup(name);
+ sty->role = S_ROLE_NONE;
n = ss->n_styles;
styles_new = realloc(ss->styles, (n+1)*sizeof(sty));
@@ -505,6 +506,7 @@ void default_stylesheet(StyleSheet *ss)
sty->valign = V_BOTTOM;
sty->offset_x = 0.0;
sty->offset_y = 0.0;
+ sty->role = S_ROLE_PDATE;
sty = new_style(ss, "Slide number");
sty->font = strdup("Sans 12");
@@ -518,6 +520,7 @@ void default_stylesheet(StyleSheet *ss)
sty->valign = V_BOTTOM;
sty->offset_x = 0.0;
sty->offset_y = 0.0;
+ sty->role = S_ROLE_SLIDENUMBER;
sty = new_style(ss, "Presentation title on slide");
sty->font = strdup("Sans 12");
@@ -531,6 +534,7 @@ void default_stylesheet(StyleSheet *ss)
sty->valign = V_BOTTOM;
sty->offset_x = 0.0;
sty->offset_y = 0.0;
+ sty->role = S_ROLE_PTITLE;
sty = new_style(ss, "Presentation title");
sty->font = strdup("Sans 50");
@@ -544,6 +548,7 @@ void default_stylesheet(StyleSheet *ss)
sty->valign = V_CENTER;
sty->offset_x = -200.0;
sty->offset_y = +300.0;
+ sty->role = S_ROLE_PTITLE_REF;
sty = new_style(ss, "Presentation author");
sty->font = strdup("Sans 30");
@@ -557,6 +562,7 @@ void default_stylesheet(StyleSheet *ss)
sty->valign = V_CENTER;
sty->offset_x = +200.0;
sty->offset_y = -300.0;
+ sty->role = S_ROLE_PAUTHOR_REF;
sty = new_style(ss, "Presentation date");
sty->font = strdup("Sans 30");
@@ -570,6 +576,7 @@ void default_stylesheet(StyleSheet *ss)
sty->valign = V_CENTER;
sty->offset_x = +200.0;
sty->offset_y = -300.0;
+ sty->role = S_ROLE_PDATE_REF;
ss->bgblocks = malloc(sizeof(struct bgblock));
ss->n_bgblocks = 1;
@@ -580,7 +587,6 @@ void default_stylesheet(StyleSheet *ss)
ss->bgblocks[0].max_y = 768.0;
ss->bgblocks[0].colour1 = strdup("#ffffffffffff");
ss->bgblocks[0].alpha1 = 1.0;
-
}
diff --git a/src/stylesheet.h b/src/stylesheet.h
index e9134d1..b6663e4 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -27,10 +27,23 @@
#include <config.h>
#endif
-
#include "loadsave.h"
+enum object_role
+{
+ S_ROLE_NONE = 0,
+ S_ROLE_SLIDENUMBER = 1,
+ S_ROLE_PTITLE = 2, /* Presentation title on slide */
+ S_ROLE_PTITLE_REF = 3, /* Reference to actual title */
+ S_ROLE_PAUTHOR = 4,
+ S_ROLE_PAUTHOR_REF = 5,
+ S_ROLE_PDATE = 6,
+ S_ROLE_PDATE_REF = 7,
+ NUM_S_ROLES
+};
+
+
enum justify
{
J_LEFT = 0,
@@ -50,6 +63,7 @@ enum vert_pos
struct style
{
char *name;
+ enum object_role role;
double margin_left;
double margin_right;
diff --git a/src/tool_text.c b/src/tool_text.c
index 68e53c7..0dc122c 100644
--- a/src/tool_text.c
+++ b/src/tool_text.c
@@ -62,7 +62,7 @@ struct text_toolinfo
struct text_object
{
- struct object base;
+ struct object base;
char *text;
size_t text_len;
@@ -193,6 +193,33 @@ static void update_text(struct text_object *o)
double ebottom = 0.0;
double mw = 0.0;
double mh = 0.0;
+ struct object *ex;
+
+ switch ( o->base.style->role ) {
+
+ case S_ROLE_SLIDENUMBER:
+ if ( o->text_len < 32 ) {
+ free(o->text);
+ o->text = malloc(32);
+ o->text_len = 32;
+ }
+ snprintf(o->text, o->text_len-1, "Slide %i",
+ 1+slide_number(o->base.parent->parent, o->base.parent));
+ break;
+
+ case S_ROLE_PTITLE:
+ ex = o->base.parent->roles[S_ROLE_PTITLE_REF];
+ if ( ex != NULL ) {
+ free(o->text);
+ o->text = strdup(((struct text_object *)ex)->text);
+ o->text_len = strlen(o->text);
+ }
+ break;
+
+ default:
+ break;
+
+ }
if ( o->layout == NULL ) {
if ( *o->pc != NULL ) {
@@ -612,18 +639,51 @@ static void end_drag(struct toolinfo *tip, struct presentation *p,
static void create_default(struct presentation *p, struct style *sty,
- struct toolinfo *tip)
+ struct slide *s, struct toolinfo *tip)
{
struct object *n;
struct text_object *o;
struct text_toolinfo *ti = (struct text_toolinfo *)tip;
- n = add_text_object(p->cur_edit_slide, 0.0, 0.0, sty, ti);
+ n = add_text_object(s, 0.0, 0.0, sty, ti);
o = (struct text_object *)n;
o->furniture = 1;
+
+ if ( sty->role != S_ROLE_NONE ) {
+ s->roles[sty->role] = n;
+ }
+
+ switch ( sty->role )
+ {
+ case S_ROLE_NONE:
+ case S_ROLE_SLIDENUMBER:
+ case S_ROLE_PTITLE:
+ case S_ROLE_PAUTHOR:
+ case S_ROLE_PDATE:
+ break;
+
+ default:
+ p->editing_object = n;
+ break;
+ }
+
+ /* If we just created a new presentation title */
+ if ( sty->role == S_ROLE_PTITLE_REF ) {
+ int i;
+ for ( i=slide_number(p, s)+1;
+ i<p->num_slides; i++ )
+ {
+ struct slide *s = p->slides[i];
+ s->roles[S_ROLE_PTITLE_REF] = n;
+ if ( s->roles[S_ROLE_PTITLE] != NULL ) {
+ update_text((struct text_object *)
+ s->roles[S_ROLE_PTITLE]);
+ }
+ }
+ }
+
update_text(o);
redraw_slide(((struct object *)o)->parent);
- p->editing_object = n;
}