From 68e95ce3e7d4489c68ca3d610991a198acc71a19 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 18 Dec 2011 22:24:23 +0100 Subject: Auto-furniture mostly working --- src/mainwindow.c | 1 + src/objects.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/presentation.c | 10 ++++++++++ src/stylesheet.c | 2 +- src/tool_text.c | 38 ++++++++++++++++++++++++++++++-------- 5 files changed, 88 insertions(+), 9 deletions(-) diff --git a/src/mainwindow.c b/src/mainwindow.c index eb68ba8..3895c73 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -332,6 +332,7 @@ static gint start_slideshow_sig(GtkWidget *widget, struct presentation *p) void notify_slide_changed(struct presentation *p) { + p->cur_tool->deselect(p->editing_object, p->cur_tool); p->editing_object = NULL; update_toolbar(p); redraw_slide(p->cur_edit_slide); diff --git a/src/objects.c b/src/objects.c index 93349ea..f50502b 100644 --- a/src/objects.c +++ b/src/objects.c @@ -183,10 +183,56 @@ void notify_style_update(struct presentation *p, struct style *sty) } +static void check_references(struct slide *s, struct object *om) +{ + if ( s->roles[S_ROLE_PDATE_REF] == om ) { + struct object *o; + s->roles[S_ROLE_PDATE_REF] = NULL; + o = s->roles[S_ROLE_PDATE]; + if ( o != NULL ) o->update_object(o); + } + + if ( s->roles[S_ROLE_PAUTHOR_REF] == om ) { + struct object *o; + s->roles[S_ROLE_PAUTHOR_REF] = NULL; + o = s->roles[S_ROLE_PAUTHOR]; + if ( o != NULL ) o->update_object(o); + } + + if ( s->roles[S_ROLE_PTITLE_REF] == om ) { + struct object *o; + s->roles[S_ROLE_PTITLE_REF] = NULL; + o = s->roles[S_ROLE_PTITLE]; + if ( o != NULL ) o->update_object(o); + } + +} + + void delete_object(struct object *o) { + int i; + if ( o->parent != NULL ) remove_object_from_slide(o->parent, o); o->delete_object(o); + + /* If this object was any kind of special (for this slide), + * check all the other slides for references */ + if ( (o->parent->roles[S_ROLE_PTITLE_REF] == o) + || (o->parent->roles[S_ROLE_PAUTHOR_REF] == o) + || (o->parent->roles[S_ROLE_PDATE_REF] == o) ) + { + for ( i=0; iparent->parent->num_slides; i++ ) { + check_references(o->parent->parent->slides[i], o); + } + } + + for ( i=0; iparent->roles[i] == o ) { + o->parent->roles[i] = NULL; + } + } + free(o); } diff --git a/src/presentation.c b/src/presentation.c index 9261307..cf0d971 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -67,6 +67,7 @@ void free_presentation(struct presentation *p) int insert_slide(struct presentation *p, struct slide *new, int pos) { struct slide **try; + int i; try = realloc(p->slides, (1+p->num_slides)*sizeof(struct slide *)); if ( try == NULL ) { @@ -98,6 +99,13 @@ int insert_slide(struct presentation *p, struct slide *new, int pos) new->parent = p; p->num_slides++; + for ( i=pos+1; inum_slides; i++ ) { + struct object *o = p->slides[i]->roles[S_ROLE_SLIDENUMBER]; + if ( o != NULL ) { + o->update_object(o); + } + } + return 0; } @@ -141,7 +149,9 @@ struct slide *add_slide(struct presentation *p, int pos) return NULL; } + /* Copy roles and references to this slide as applicable */ if ( pos >= 0 ) { + struct slide *ex = p->slides[pos]; s->roles[S_ROLE_PTITLE_REF] = ex->roles[S_ROLE_PTITLE_REF]; diff --git a/src/stylesheet.c b/src/stylesheet.c index 296d562..2e97d66 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -547,7 +547,7 @@ void default_stylesheet(StyleSheet *ss) sty->halign = J_CENTER; sty->valign = V_CENTER; sty->offset_x = -200.0; - sty->offset_y = +300.0; + sty->offset_y = -200.0; sty->role = S_ROLE_PTITLE_REF; sty = new_style(ss, "Presentation author"); diff --git a/src/tool_text.c b/src/tool_text.c index 0dc122c..e16f37c 100644 --- a/src/tool_text.c +++ b/src/tool_text.c @@ -194,6 +194,7 @@ static void update_text(struct text_object *o) double mw = 0.0; double mh = 0.0; struct object *ex; + struct text_object *ext; switch ( o->base.style->role ) { @@ -209,9 +210,10 @@ static void update_text(struct text_object *o) case S_ROLE_PTITLE: ex = o->base.parent->roles[S_ROLE_PTITLE_REF]; - if ( ex != NULL ) { + ext = (struct text_object *)ex; + if ( (ext != NULL) && (ext->text != NULL) ) { free(o->text); - o->text = strdup(((struct text_object *)ex)->text); + o->text = strdup(ext->text); o->text_len = strlen(o->text); } break; @@ -667,7 +669,8 @@ static void create_default(struct presentation *p, struct style *sty, break; } - /* If we just created a new presentation title */ + /* If we just created a new presentation title, set this object as the + * presentation title reference for all subsequent slides */ if ( sty->role == S_ROLE_PTITLE_REF ) { int i; for ( i=slide_number(p, s)+1; @@ -675,10 +678,6 @@ static void create_default(struct presentation *p, struct style *sty, { 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]); - } } } @@ -717,11 +716,34 @@ static void select_object(struct object *o, struct toolinfo *tip) static int deselect_object(struct object *o, struct toolinfo *tip) { - if ( (o != NULL) && o->empty ) { + struct slide *s; + struct presentation *p; + + if ( o == NULL ) return 0; + + s = o->parent; + p = s->parent; + + if ( o->empty ) { delete_object(o); return 1; } + if ( o->style->role == S_ROLE_PTITLE_REF ) { + + int i; + + for ( i=slide_number(p, s)+1; inum_slides; i++ ) { + + struct slide *s = p->slides[i]; + if ( s->roles[S_ROLE_PTITLE] != NULL ) { + update_text((struct text_object *) + s->roles[S_ROLE_PTITLE]); + } + } + + } + return 0; } -- cgit v1.2.3