aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2013-09-17 21:31:23 +0200
committerThomas White <taw@bitwiz.org.uk>2013-09-17 21:31:23 +0200
commit4e90a9c416a66e3ab6170e2a557d8966d93fbbd2 (patch)
treeb12c2eebbe9385f857b5d29929004756c26018f5 /src
parent057871cbe90d434f9462213f929054302f8da3ab (diff)
Delete completely empty frames
Diffstat (limited to 'src')
-rw-r--r--src/frame.c2
-rw-r--r--src/mainwindow.c3
-rw-r--r--src/presentation.c64
3 files changed, 69 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c
index bf0672a..62d8ada 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -228,6 +228,7 @@ static int recursive_unpack(struct frame *fr, const char *sc, StyleSheet *ss)
struct frame *sfr;
sfr = add_subframe(fr);
+ sfr->empty = 0;
parse_options(sfr, b->options, ss);
if ( sfr->lop.w < 0.0 ) {
@@ -261,6 +262,7 @@ struct frame *sc_unpack(const char *sc, StyleSheet *ss)
fr = frame_new();
if ( fr == NULL ) return NULL;
+ fr->empty = 0;
fr->sc = remove_blocks(sc, "f");
if ( recursive_unpack(fr, sc, ss) ) {
return NULL;
diff --git a/src/mainwindow.c b/src/mainwindow.c
index c3468dd..0bfc7e1 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -192,6 +192,7 @@ static void add_furniture_real(struct presentation *p, struct style *sty)
fr->sc = malloc(1);
fr->sc[0] = '\0';
fr->sc_len = 1;
+ fr->empty = 0;
set_selection(p, fr);
fr->pos = 0;
p->cursor_pos = 0;
@@ -1456,6 +1457,7 @@ static struct frame *create_frame(struct presentation *p, double x, double y,
fr->lop.w = w;
fr->lop.h = h;
fr->is_image = 0;
+ fr->empty = 1;
return fr;
}
@@ -1842,6 +1844,7 @@ static void dnd_receive(GtkWidget *widget, GdkDragContext *drag_context,
fr->sc = sc;
fr->sc_len = len;
fr->is_image = 1;
+ fr->empty = 0;
show_hierarchy(p->cur_edit_slide->top, "");
rerender_slide(p);
set_selection(p, fr);
diff --git a/src/presentation.c b/src/presentation.c
index c406840..3c4e593 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -553,6 +553,60 @@ int load_presentation(struct presentation *p, const char *filename)
}
+static struct frame *find_parent(struct frame *fr, struct frame *search)
+{
+ int i;
+
+ for ( i=0; i<fr->num_children; i++ ) {
+ if ( fr->children[i] == search ) {
+ return fr;
+ }
+ }
+
+ for ( i=0; i<fr->num_children; i++ ) {
+ struct frame *tt;
+ tt = find_parent(fr->children[i], search);
+ if ( tt != NULL ) return tt;
+ }
+
+ return NULL;
+}
+
+
+static void delete_subframe(struct slide *s, struct frame *fr)
+{
+ struct frame *parent;
+ int i, idx, found;
+
+ parent = find_parent(s->top, fr);
+ if ( parent == NULL ) {
+ fprintf(stderr, "Couldn't find parent when deleting frame.\n");
+ return;
+ }
+
+
+ found = 0;
+ for ( i=0; i<parent->num_children; i++ ) {
+ if ( parent->children[i] == fr ) {
+ idx = i;
+ found = 1;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ fprintf(stderr, "Couldn't find child when deleting frame.\n");
+ return;
+ }
+
+ for ( i=idx; i<parent->num_children-1; i++ ) {
+ parent->children[i] = parent->children[i+1];
+ }
+
+ parent->num_children--;
+}
+
+
void set_edit(struct presentation *p, struct slide *s)
{
p->cur_edit_slide = s;
@@ -561,6 +615,16 @@ void set_edit(struct presentation *p, struct slide *s)
void set_selection(struct presentation *p, struct frame *fr)
{
+ if ( p->n_selection != 0 ) {
+ int i;
+ for ( i=0; i<p->n_selection; i++ ) {
+ if ( p->selection[i]->empty ) {
+ delete_subframe(p->cur_edit_slide,
+ p->selection[i]);
+ }
+ }
+ }
+
p->selection[0] = fr;
p->n_selection = 1;