diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-09-22 17:58:28 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-09-22 17:58:28 +0200 |
commit | 197f5b68e85343b2c0229c28b7661a8bbaeb8b04 (patch) | |
tree | fa76b34f308552965c55ddbc84667b27f8979c72 /src | |
parent | ccc1f0fb422b149f51b335f45fcde2b493e4358f (diff) |
Do the actual slide transfer
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.c | 2 | ||||
-rw-r--r-- | src/presentation.c | 32 | ||||
-rw-r--r-- | src/slide_sorter.c | 79 |
3 files changed, 80 insertions, 33 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c index 94f2f6b..00667a3 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -652,7 +652,7 @@ static gint add_slide_sig(GtkWidget *widget, struct presentation *p) cur_slide_number = slide_number(p, p->cur_edit_slide); - new = add_slide(p, cur_slide_number); + new = add_slide(p, cur_slide_number+1); change_edit_slide(p, new); return FALSE; diff --git a/src/presentation.c b/src/presentation.c index f4e5bb6..786627c 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -74,14 +74,20 @@ static void renumber_slides(struct presentation *p) { int i; for ( i=0; i<p->num_slides; i++ ) { - p->slides[i]->constants->slide_number = i+1; + if ( p->slides[i]->constants != NULL ) { + p->slides[i]->constants->slide_number = i+1; + } else { + fprintf(stderr, "Slide %i has no constants.\n", i); + } } } +/* "pos" is the index that the caller would like this slide to have */ 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 ) { @@ -90,28 +96,14 @@ int insert_slide(struct presentation *p, struct slide *new, int pos) } p->slides = try; p->completely_empty = 0; + p->num_slides++; - /* Insert into list. Yuk yuk yuk etc. */ - if ( (p->num_slides>1) && (pos<p->num_slides-1) ) { - - int i; - - for ( i=p->num_slides; i>pos+1; i-- ) { - p->slides[i] = p->slides[i-1]; - } - p->slides[pos+1] = new; - - } else if ( pos == p->num_slides-1 ) { - - p->slides[pos+1] = new; - - } else { - assert(pos == 0); - p->slides[pos] = new; + for ( i=p->num_slides-1; i>=pos; i-- ) { + p->slides[i] = p->slides[i-1]; } + p->slides[pos] = new; new->parent = p; - p->num_slides++; renumber_slides(p); @@ -456,7 +448,7 @@ static int tree_to_slides(struct ds_node *root, struct presentation *p) s = tree_to_slide(p, root->children[i]); if ( s != NULL ) { - insert_slide(p, s, p->num_slides-1); + insert_slide(p, s, p->num_slides); } } diff --git a/src/slide_sorter.c b/src/slide_sorter.c index 7fcb773..11412ed 100644 --- a/src/slide_sorter.c +++ b/src/slide_sorter.c @@ -47,6 +47,8 @@ struct slide_sorter int bw; int selection; + + int drop_here; int dragging; int drag_preview_pending; int have_drag_data; @@ -121,6 +123,12 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct slide_sorter *n) cairo_set_line_width(cr, 1.0); cairo_stroke(cr); + if ( n->dragging && (i == n->drop_here) ) { + cairo_rectangle(cr, -1.5*n->bw, 0.0, n->bw, n->th); + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_fill(cr); + } + cairo_restore(cr); } @@ -156,15 +164,16 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, x = (event->x - n->bw) / (n->tw + 2*n->bw); y = (event->y - n->bw) / (n->th + 2*n->bw); - if ( x >= n->width ) x = n->width-1; - if ( y >= n->height ) y = n->height-1; + if ( (x < n->width) && (y < n->height) ) { - n->selection = y*n->width + x; - if ( n->selection >= n->p->num_slides ) { - n->selection = n->p->num_slides - 1; - } + n->selection = y*n->width + x; + + if ( n->selection >= n->p->num_slides ) { + n->selection = n->p->num_slides - 1; + } - redraw_slidesorter(n); + redraw_slidesorter(n); + } return FALSE; } @@ -205,7 +214,7 @@ static gboolean button_release_sig(GtkWidget *da, GdkEventButton *event, static gboolean dnd_motion(GtkWidget *widget, GdkDragContext *drag_context, - gint x, gint y, guint time, struct slide_sorter *n) + gint xc, gint yc, guint time, struct slide_sorter *n) { GdkAtom target; @@ -232,10 +241,31 @@ static gboolean dnd_motion(GtkWidget *widget, GdkDragContext *drag_context, if ( n->have_drag_data ) { + int x, y; + int sw, sh; + gdk_drag_status(drag_context, GDK_ACTION_MOVE, time); /* Draw drag box */ n->have_drag_data = 1; + sw = n->tw + 2*n->bw; + sh = n->th + 2*n->bw; + + x = (xc - n->bw + sw/2) / sw; + y = (yc - n->bw) / sh;; + + if ( x >= n->width ) x = n->width-1; + if ( y >= n->height ) y = n->height-1; + + n->drop_here = y*n->width + x; + if ( n->drop_here > n->p->num_slides ) { + n->drop_here = n->p->num_slides; + } + + n->dragging = 1; /* Because this might be the first signal */ + + redraw_slidesorter(n); + } return TRUE; @@ -275,14 +305,39 @@ static void dnd_receive(GtkWidget *widget, GdkDragContext *drag_context, } else { - const guchar *sc; + const char *sc; + struct slide *s; - sc = gtk_selection_data_get_data(seldata); + sc = (const char *)gtk_selection_data_get_data(seldata); n->dragging = 0; gtk_drag_finish(drag_context, TRUE, TRUE, time); - printf("Got SC: '%s'\n", sc); + //printf("Got SC: '%s'\n", sc); + printf("Inserting at %i\n", n->drop_here); + s = add_slide(n->p, n->drop_here); + + if ( s != NULL ) { + + s->top = sc_unpack(sc, n->p->ss); + + s->rendered_thumb = render_slide(s, + n->p->thumb_slide_width, + n->p->slide_width, + n->p->slide_height, + n->p->is, + ISZ_THUMBNAIL); + + /* FIXME: Transfer the notes as well */ + + redraw_slidesorter(n); + + } else { + + fprintf(stderr, "Failed to add slide\n"); + + } + } @@ -301,7 +356,7 @@ static void dnd_get(GtkWidget *widget, GdkDragContext *drag_context, char *sc; sc = packed_sc(n->p->slides[n->selection]->top, n->p->ss); - printf("Sending SC: '%s'\n", sc); + //printf("Sending SC: '%s'\n", sc); gtk_selection_data_set(seldata, target, 8, (guchar *)sc, strlen(sc)); |