diff options
author | Thomas White <taw@bitwiz.org.uk> | 2015-08-17 21:44:08 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2015-08-17 21:44:08 +0200 |
commit | 8d8eccb93da07559c675f053d5dce3781423b253 (patch) | |
tree | 64ede67247367cf36281d4b023b7160e04197e7e /src | |
parent | 91eb4f02e4a539bc8b9fb3b475b6644717846d2b (diff) |
Dispatch table for slideshow controller
Diffstat (limited to 'src')
-rw-r--r-- | src/slide_window.c | 78 | ||||
-rw-r--r-- | src/slide_window.h | 10 | ||||
-rw-r--r-- | src/slideshow.c | 24 | ||||
-rw-r--r-- | src/slideshow.h | 26 |
4 files changed, 91 insertions, 47 deletions
diff --git a/src/slide_window.c b/src/slide_window.c index 8db26bc..d2aa95c 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -253,13 +253,6 @@ static void add_slide_sig(GSimpleAction *action, GVariant *parameter, gpointer v } -static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) -{ - SlideWindow *sw = vp; - sw->show = try_start_slideshow(sw, sw->p); -} - - static gint export_pdf_response_sig(GtkWidget *d, gint response, SlideWindow *sw) { @@ -305,12 +298,6 @@ static void exportpdf_sig(GSimpleAction *action, GVariant *parameter, } -void slidewindow_slideshow_ended(SlideWindow *sw) -{ - sw->show = NULL; -} - - void slidewindow_notes_closed(SlideWindow *sw) { sw->notes = NULL; @@ -335,13 +322,13 @@ void change_edit_slide(SlideWindow *sw, struct slide *np) } -void change_slide_first(SlideWindow *sw) +static void change_slide_first(SlideWindow *sw) { change_edit_slide(sw, sw->p->slides[0]); } -void change_slide_backwards(SlideWindow *sw) +static void change_slide_backwards(SlideWindow *sw) { int cur_slide_number; @@ -352,7 +339,7 @@ void change_slide_backwards(SlideWindow *sw) } -void change_slide_forwards(SlideWindow *sw) +static void change_slide_forwards(SlideWindow *sw) { int cur_slide_number; @@ -363,7 +350,7 @@ void change_slide_forwards(SlideWindow *sw) } -void change_slide_last(SlideWindow *sw) +static void change_slide_last(SlideWindow *sw) { change_edit_slide(sw, sw->p->slides[sw->p->num_slides-1]); } @@ -434,12 +421,6 @@ void slidewindow_redraw(SlideWindow *sw) } -struct slide *slidewindow_get_slide(SlideWindow *sw) -{ - return sw->cur_slide; -} - - void update_titlebar(struct presentation *p) { get_titlebar_string(p); @@ -465,6 +446,57 @@ static gboolean close_sig(GtkWidget *w, SlideWindow *sw) } +static void ss_end_show(SlideShow *ss, void *vp) +{ + SlideWindow *sw = vp; + sw->show = NULL; +} + + +static void ss_next_slide(SlideShow *ss, void *vp) +{ + SlideWindow *sw = vp; + change_slide_forwards(sw); +} + + +static void ss_prev_slide(SlideShow *ss, void *vp) +{ + SlideWindow *sw = vp; + change_slide_backwards(sw); +} + + +static void ss_changed_link(SlideShow *ss, void *vp) +{ + SlideWindow *sw = vp; + slidewindow_redraw(sw); +} + + +static struct slide *ss_cur_slide(SlideShow *ss, void *vp) +{ + SlideWindow *sw = vp; + return sw->cur_slide; +} + + +static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + SlideWindow *sw = vp; + struct sscontrolfuncs ssc; + + ssc.next_slide = ss_next_slide; + ssc.prev_slide = ss_prev_slide; + ssc.current_slide = ss_cur_slide; + ssc.changed_link = ss_changed_link; + ssc.end_show = ss_end_show; + + sw->show = try_start_slideshow(sw->p, ssc, sw); +} + + static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, SlideWindow *sw) { diff --git a/src/slide_window.h b/src/slide_window.h index 72a2f24..d0006b3 100644 --- a/src/slide_window.h +++ b/src/slide_window.h @@ -1,7 +1,7 @@ /* * slide_window.h * - * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -33,14 +33,6 @@ extern SlideWindow *slide_window_open(struct presentation *p, GApplication *app) extern void change_edit_slide(SlideWindow *sw, struct slide *np); extern void update_titlebar(struct presentation *p); -extern void change_slide_first(SlideWindow *sw); -extern void change_slide_backwards(SlideWindow *sw); -extern void change_slide_forwards(SlideWindow *sw); -extern void change_slide_last(SlideWindow *sw); - -extern struct slide *slidewindow_get_slide(SlideWindow *sw); -extern void slidewindow_redraw(SlideWindow *sw); -extern void slidewindow_slideshow_ended(SlideWindow *sw); extern void slidewindow_notes_closed(SlideWindow *sw); #endif /* SLIDEWINDOW_H */ diff --git a/src/slideshow.c b/src/slideshow.c index 8124268..b33a41b 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -32,7 +32,6 @@ #include <gdk/gdkkeysyms.h> #include "presentation.h" -#include "slide_window.h" #include "render.h" #include "pr_clock.h" #include "inhibit_screensaver.h" @@ -41,7 +40,8 @@ struct _slideshow { struct presentation *p; - SlideWindow *slide_window; /* Slide window controlling us */ + struct sscontrolfuncs ssc; + void *vp; /* Controller's private word */ struct slide *cur_slide; GtkWidget *window; GtkWidget *drawingarea; @@ -93,8 +93,7 @@ void slideshow_rerender(SlideShow *ss) static gint ss_destroy_sig(GtkWidget *widget, SlideShow *ss) { g_object_unref(ss->blank_cursor); - slidewindow_slideshow_ended(ss->slide_window); - slidewindow_redraw(ss->slide_window); + ss->ssc.end_show(ss, ss->vp); if ( ss->surface != NULL ) { cairo_surface_destroy(ss->surface); } @@ -152,14 +151,14 @@ void change_proj_slide(SlideShow *ss, struct slide *np) static gint prev_slide_sig(GtkWidget *widget, SlideShow *ss) { - change_slide_backwards(ss->slide_window); + ss->ssc.prev_slide(ss, ss->vp); return FALSE; } static gint next_slide_sig(GtkWidget *widget, SlideShow *ss) { - change_slide_forwards(ss->slide_window); + ss->ssc.next_slide(ss, ss->vp); return FALSE; } @@ -176,9 +175,9 @@ void toggle_slideshow_link(SlideShow *ss) { ss->linked = 1 - ss->linked; if ( ss->linked ) { - change_proj_slide(ss, slidewindow_get_slide(ss->slide_window)); + change_proj_slide(ss, ss->ssc.current_slide(ss, ss->vp)); } - slidewindow_redraw(ss->slide_window); + ss->ssc.changed_link(ss, ss->vp); } @@ -249,7 +248,8 @@ struct slide *slideshow_slide(SlideShow *ss) } -SlideShow *try_start_slideshow(SlideWindow *sw, struct presentation *p) +SlideShow *try_start_slideshow(struct presentation *p, + struct sscontrolfuncs ssc, void *vp) { GdkScreen *screen; int n_monitors; @@ -257,13 +257,15 @@ SlideShow *try_start_slideshow(SlideWindow *sw, struct presentation *p) SlideShow *ss; double slide_width = 1024.0; /* Logical slide size */ double slide_height = 768.0; /* FIXME: Should come from slide */ + ss = calloc(1, sizeof(SlideShow)); if ( ss == NULL ) return NULL; - ss->slide_window = sw; + ss->ssc = ssc; + ss->vp = vp; ss->blank = 0; ss->p = p; - ss->cur_slide = slidewindow_get_slide(sw); + ss->cur_slide = ss->ssc.current_slide(ss, vp); if ( ss->inhibit == NULL ) { ss->inhibit = inhibit_prepare(); diff --git a/src/slideshow.h b/src/slideshow.h index 16bd6e0..99d5549 100644 --- a/src/slideshow.h +++ b/src/slideshow.h @@ -1,7 +1,7 @@ /* * slideshow.h * - * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -27,12 +27,30 @@ #include <config.h> #endif -#include "slide_window.h" - /* Opaque data structure representing a slideshow */ typedef struct _slideshow SlideShow; -extern SlideShow *try_start_slideshow(SlideWindow *sw, struct presentation *p); +struct sscontrolfuncs +{ + /* Controller should switch slide forwards or backwards */ + void (*next_slide)(SlideShow *ss, void *vp); + void (*prev_slide)(SlideShow *ss, void *vp); + + /* Controller should return what it thinks is the current slide + * (this might not be what is on the screen, e.g. if the display + * is unlinked) */ + struct slide *(*current_slide)(SlideShow *ss, void *vp); + + /* Controller should update whatever visual representation of + * whether or not the display is linked */ + void (*changed_link)(SlideShow *ss, void *vp); + + /* Slideshow ended (including if you called end_slideshow) */ + void (*end_show)(SlideShow *ss, void *vp); +}; + +extern SlideShow *try_start_slideshow(struct presentation *p, + struct sscontrolfuncs ssc, void *vp); extern void end_slideshow(SlideShow *ss); extern void change_proj_slide(SlideShow *ss, struct slide *np); |