diff options
author | Thomas White <taw@bitwiz.org.uk> | 2016-05-17 23:44:50 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2016-05-17 23:44:50 +0200 |
commit | 0818526f58cbb1927733f16fe665552194fe9228 (patch) | |
tree | 9b177f486f1c4e1534227a762f2ea90fa7ba9b24 | |
parent | ff3e44a3e2b09b5eb1c7b2c199bb1321ce7d41dc (diff) |
GObjectify the slideshow
-rw-r--r-- | src/narrative_window.c | 142 | ||||
-rw-r--r-- | src/slide_window.c | 4 | ||||
-rw-r--r-- | src/slideshow.c | 168 | ||||
-rw-r--r-- | src/slideshow.h | 66 |
4 files changed, 141 insertions, 239 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c index e0d1293..abeb231 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -50,9 +50,8 @@ struct _narrative_window SCEditor *sceditor; GApplication *app; struct presentation *p; - SlideShow *show; + SCSlideshow *show; PRClock *pr_clock; - SCBlock *sel_slide; }; @@ -168,14 +167,6 @@ static void add_slide_sig(GSimpleAction *action, GVariant *parameter, } -static void ss_end_show(SlideShow *ss, void *vp) -{ - NarrativeWindow *nw = vp; - nw->show = NULL; - sc_editor_set_para_highlight(nw->sceditor, 0); -} - - static void first_para_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { @@ -187,7 +178,7 @@ static void first_para_sig(GSimpleAction *action, GVariant *parameter, } -static void ss_prev_para(SlideShow *ss, void *vp) +static void ss_prev_para(SCSlideshow *ss, void *vp) { NarrativeWindow *nw = vp; if ( sc_editor_get_cursor_para(nw->sceditor) == 0 ) return; @@ -207,7 +198,7 @@ static void prev_para_sig(GSimpleAction *action, GVariant *parameter, } -static void ss_next_para(SlideShow *ss, void *vp) +static void ss_next_para(SCSlideshow *ss, void *vp) { NarrativeWindow *nw = vp; SCBlock *ns; @@ -218,9 +209,7 @@ static void ss_next_para(SlideShow *ss, void *vp) sc_editor_get_num_paras(nw->sceditor)); ns = sc_editor_get_cursor_bvp(nw->sceditor); if ( ns != NULL ) { - nw->sel_slide = ns; - slideshow_rerender(nw->show); - redraw_slideshow(nw->show); + sc_slideshow_set_slide(nw->show, ns); } update_toolbar(nw); } @@ -245,43 +234,6 @@ static void last_para_sig(GSimpleAction *action, GVariant *parameter, } -static void ss_changed_link(SlideShow *ss, void *vp) -{ -} - - -static SCBlock *ss_cur_slide(void *vp) -{ - NarrativeWindow *nw = vp; - return nw->sel_slide; -} - - -static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter, - gpointer vp) -{ - NarrativeWindow *nw = vp; - struct sscontrolfuncs ssc; - - if ( num_slides(nw->p) == 0 ) return; - - ssc.next_slide = ss_next_para; - ssc.prev_slide = ss_prev_para; - ssc.current_slide = ss_cur_slide; - ssc.changed_link = ss_changed_link; - ssc.end_show = ss_end_show; - - nw->sel_slide = first_slide(nw->p); - nw->show = try_start_slideshow(nw->p, ssc, nw); - - if ( nw->show != NULL ) { - sc_editor_set_para_highlight(nw->sceditor, 1); - sc_editor_set_cursor_para(nw->sceditor, 0); - update_toolbar(nw); - } -} - - static void open_notes_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { } @@ -341,30 +293,6 @@ static void exportpdf_sig(GSimpleAction *action, GVariant *parameter, -GActionEntry nw_entries[] = { - - { "save", save_sig, NULL, NULL, NULL }, - { "saveas", saveas_sig, NULL, NULL, NULL }, - { "sorter", open_slidesorter_sig, NULL, NULL, NULL }, - { "deleteframe", delete_frame_sig, NULL, NULL, NULL }, - { "slide", add_slide_sig, NULL, NULL, NULL }, - { "startslideshow", start_slideshow_sig, NULL, NULL, NULL }, - { "notes", open_notes_sig, NULL, NULL, NULL }, - { "clock", open_clock_sig, NULL, NULL, NULL }, - { "testcard", testcard_sig, NULL, NULL, NULL }, - { "first", first_para_sig, NULL, NULL, NULL }, - { "prev", prev_para_sig, NULL, NULL, NULL }, - { "next", next_para_sig, NULL, NULL, NULL }, - { "last", last_para_sig, NULL, NULL, NULL }, -}; - - -GActionEntry nw_entries_p[] = { - { "print", print_sig, NULL, NULL, NULL }, - { "exportpdf", exportpdf_sig, NULL, NULL, NULL }, -}; - - static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, NarrativeWindow *nw) { @@ -418,12 +346,49 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, } break; + case GDK_KEY_Escape : + if ( nw->show != NULL ) { + gtk_widget_destroy(GTK_WIDGET(nw->show)); + return TRUE; + } + break; + } return FALSE; } +static gboolean ss_destroy_sig(GtkWidget *da, NarrativeWindow *nw) +{ + nw->show = NULL; + sc_editor_set_para_highlight(nw->sceditor, 0); + return FALSE; +} + + +static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + NarrativeWindow *nw = vp; + + if ( num_slides(nw->p) == 0 ) return; + + nw->show = sc_slideshow_new(nw->p); + + if ( nw->show == NULL ) return; + + g_signal_connect(G_OBJECT(nw->show), "key-press-event", + G_CALLBACK(key_press_sig), nw); + g_signal_connect(G_OBJECT(nw->show), "destroy", + G_CALLBACK(ss_destroy_sig), nw); + sc_slideshow_set_slide(nw->show, first_slide(nw->p)); + sc_editor_set_para_highlight(nw->sceditor, 1); + sc_editor_set_cursor_para(nw->sceditor, 0); + update_toolbar(nw); +} + + static void nw_update_titlebar(NarrativeWindow *nw) { get_titlebar_string(nw->p); @@ -496,6 +461,30 @@ static int click_thumbnail(double x, double y, void *bvp, void *vp) } +GActionEntry nw_entries[] = { + + { "save", save_sig, NULL, NULL, NULL }, + { "saveas", saveas_sig, NULL, NULL, NULL }, + { "sorter", open_slidesorter_sig, NULL, NULL, NULL }, + { "deleteframe", delete_frame_sig, NULL, NULL, NULL }, + { "slide", add_slide_sig, NULL, NULL, NULL }, + { "startslideshow", start_slideshow_sig, NULL, NULL, NULL }, + { "notes", open_notes_sig, NULL, NULL, NULL }, + { "clock", open_clock_sig, NULL, NULL, NULL }, + { "testcard", testcard_sig, NULL, NULL, NULL }, + { "first", first_para_sig, NULL, NULL, NULL }, + { "prev", prev_para_sig, NULL, NULL, NULL }, + { "next", next_para_sig, NULL, NULL, NULL }, + { "last", last_para_sig, NULL, NULL, NULL }, +}; + + +GActionEntry nw_entries_p[] = { + { "print", print_sig, NULL, NULL, NULL }, + { "exportpdf", exportpdf_sig, NULL, NULL, NULL }, +}; + + NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app) { NarrativeWindow *nw; @@ -605,7 +594,6 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app) gtk_actionable_set_action_name(GTK_ACTIONABLE(nw->blast), "win.last"); - nw->sel_slide = NULL; update_toolbar(nw); scroll = gtk_scrolled_window_new(NULL, NULL); diff --git a/src/slide_window.c b/src/slide_window.c index de543b6..24fee88 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -62,8 +62,6 @@ struct _slidewindow struct menu_pl *style_menu; int n_style_menu; - - SlideShow *show; }; @@ -313,8 +311,6 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks, g_action_map_add_action_entries(G_ACTION_MAP(window), sw_entries, G_N_ELEMENTS(sw_entries), sw); - sw->show = NULL; - update_titlebar(p); g_signal_connect(G_OBJECT(window), "destroy", diff --git a/src/slideshow.c b/src/slideshow.c index 9e334d4..b994f69 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -37,41 +37,26 @@ #include "inhibit_screensaver.h" #include "frame.h" -struct _slideshow -{ - struct presentation *p; - struct sscontrolfuncs ssc; - void *vp; /* Controller's private word */ - GtkWidget *window; - GtkWidget *drawingarea; - GdkCursor *blank_cursor; - int blank; - char geom[256]; - int slide_width; - int slide_height; - struct inhibit_sys *inhibit; - int linked; - cairo_surface_t *surface; - struct frame *top; -}; - - -/* Force a redraw of the slideshow */ -void redraw_slideshow(SlideShow *ss) +G_DEFINE_TYPE_WITH_CODE(SCSlideshow, sc_slideshow, GTK_TYPE_WINDOW, NULL) + + +static void sc_slideshow_init(SCSlideshow *ss) { - gint w, h; +} - w = gtk_widget_get_allocated_width(GTK_WIDGET(ss->drawingarea)); - h = gtk_widget_get_allocated_height(GTK_WIDGET(ss->drawingarea)); - gtk_widget_queue_draw_area(ss->drawingarea, 0, 0, w, h); +void sc_slideshow_class_init(SCSlideshowClass *klass) +{ } -void slideshow_rerender(SlideShow *ss) +static void slideshow_rerender(SCSlideshow *ss) { int n; SCBlock *stylesheets[2]; + gint w, h; + + if ( ss->cur_slide == NULL ) return; if ( ss->surface != NULL ) { cairo_surface_destroy(ss->surface); @@ -80,28 +65,31 @@ void slideshow_rerender(SlideShow *ss) stylesheets[0] = ss->p->stylesheet; stylesheets[1] = NULL; - n = slide_number(ss->p, ss->ssc.current_slide(ss->vp)); - ss->surface = render_sc(sc_block_child(ss->ssc.current_slide(ss->vp)), + n = slide_number(ss->p, ss->cur_slide); + ss->surface = render_sc(sc_block_child(ss->cur_slide), ss->slide_width, ss->slide_height, ss->p->slide_width, ss->p->slide_height, stylesheets, NULL, ss->p->is, ISZ_SLIDESHOW, n, &ss->top, ss->p->lang); + + w = gtk_widget_get_allocated_width(GTK_WIDGET(ss->drawingarea)); + h = gtk_widget_get_allocated_height(GTK_WIDGET(ss->drawingarea)); + + gtk_widget_queue_draw_area(ss->drawingarea, 0, 0, w, h); } -static gint ss_destroy_sig(GtkWidget *widget, SlideShow *ss) +static gint ss_destroy_sig(GtkWidget *widget, SCSlideshow *ss) { g_object_unref(ss->blank_cursor); - ss->ssc.end_show(ss, ss->vp); if ( ss->surface != NULL ) { cairo_surface_destroy(ss->surface); } - free(ss); return FALSE; } -static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, SlideShow *ss) +static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, SCSlideshow *ss) { double xoff, yoff; double width, height; @@ -137,90 +125,7 @@ static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, SlideShow *ss) } -void change_proj_slide(SlideShow *ss, SCBlock *np) -{ - slideshow_rerender(ss); - redraw_slideshow(ss); -} - - -static gint prev_slide_sig(GtkWidget *widget, SlideShow *ss) -{ - ss->ssc.prev_slide(ss, ss->vp); - return FALSE; -} - - -static gint next_slide_sig(GtkWidget *widget, SlideShow *ss) -{ - ss->ssc.next_slide(ss, ss->vp); - return FALSE; -} - - -void end_slideshow(SlideShow *ss) -{ - if ( ss->inhibit != NULL ) do_inhibit(ss->inhibit, 0); - gtk_widget_destroy(ss->drawingarea); - gtk_widget_destroy(ss->window); -} - - -void toggle_slideshow_link(SlideShow *ss) -{ - ss->linked = 1 - ss->linked; - if ( ss->linked ) { - change_proj_slide(ss, ss->ssc.current_slide(ss->vp)); - } - ss->ssc.changed_link(ss, ss->vp); -} - - -int slideshow_linked(SlideShow *ss) -{ - if ( ss == NULL ) return 0; - return ss->linked; -} - - -void check_toggle_blank(SlideShow *ss) -{ - toggle_slideshow_link(ss); -} - - -static gboolean ss_key_press_sig(GtkWidget *da, GdkEventKey *event, - SlideShow *ss) -{ - switch ( event->keyval ) - { - - case GDK_KEY_B : - case GDK_KEY_b : - check_toggle_blank(ss); - break; - - case GDK_KEY_Page_Up : - case GDK_KEY_Up : - prev_slide_sig(NULL, ss); - break; - - case GDK_KEY_Page_Down : - case GDK_KEY_Down : - next_slide_sig(NULL, ss); - break; - - case GDK_KEY_Escape : - end_slideshow(ss); - break; - - } - - return FALSE; -} - - -static gboolean ss_realize_sig(GtkWidget *w, SlideShow *ss) +static gboolean ss_realize_sig(GtkWidget *w, SCSlideshow *ss) { GdkWindow *win; @@ -237,42 +142,43 @@ static gboolean ss_realize_sig(GtkWidget *w, SlideShow *ss) } -SlideShow *try_start_slideshow(struct presentation *p, - struct sscontrolfuncs ssc, void *vp) +void sc_slideshow_set_slide(SCSlideshow *ss, SCBlock *ns) +{ + ss->cur_slide = ns; + slideshow_rerender(ss); +} + + +SCSlideshow *sc_slideshow_new(struct presentation *p) { GdkScreen *screen; int n_monitors; int i; - SlideShow *ss; + SCSlideshow *ss; double slide_width = 1024.0; /* Logical slide size */ double slide_height = 768.0; /* FIXME: Should come from slide */ - ss = calloc(1, sizeof(SlideShow)); + ss = g_object_new(SC_TYPE_SLIDESHOW, NULL); if ( ss == NULL ) return NULL; - ss->ssc = ssc; - ss->vp = vp; ss->blank = 0; ss->p = p; + ss->cur_slide = NULL; if ( ss->inhibit == NULL ) { ss->inhibit = inhibit_prepare(); } - ss->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - ss->drawingarea = gtk_drawing_area_new(); - gtk_container_add(GTK_CONTAINER(ss->window), ss->drawingarea); + gtk_container_add(GTK_CONTAINER(ss), ss->drawingarea); gtk_widget_set_can_focus(GTK_WIDGET(ss->drawingarea), TRUE); gtk_widget_add_events(GTK_WIDGET(ss->drawingarea), GDK_KEY_PRESS_MASK); - g_signal_connect(G_OBJECT(ss->drawingarea), "key-press-event", - G_CALLBACK(ss_key_press_sig), ss); - g_signal_connect(G_OBJECT(ss->window), "destroy", + g_signal_connect(G_OBJECT(ss), "destroy", G_CALLBACK(ss_destroy_sig), ss); - g_signal_connect(G_OBJECT(ss->window), "realize", + g_signal_connect(G_OBJECT(ss), "realize", G_CALLBACK(ss_realize_sig), ss); g_signal_connect(G_OBJECT(ss->drawingarea), "draw", @@ -299,8 +205,8 @@ SlideShow *try_start_slideshow(struct presentation *p, } /* FIXME: Sensible (configurable) choice of monitor */ ss->linked = 1; - gtk_window_fullscreen(GTK_WINDOW(ss->window)); - gtk_widget_show_all(GTK_WIDGET(ss->window)); + gtk_window_fullscreen(GTK_WINDOW(ss)); + gtk_widget_show_all(GTK_WIDGET(ss)); if ( ss->inhibit != NULL ) do_inhibit(ss->inhibit, 1); diff --git a/src/slideshow.h b/src/slideshow.h index 5c8b808..2ffc577 100644 --- a/src/slideshow.h +++ b/src/slideshow.h @@ -1,7 +1,7 @@ /* * slideshow.h * - * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2013-2016 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -27,40 +27,52 @@ #include <config.h> #endif -/* Opaque data structure representing a slideshow */ -typedef struct _slideshow SlideShow; +#define SC_TYPE_SLIDESHOW (sc_slideshow_get_type()) -struct sscontrolfuncs -{ - /* Controller should switch slide forwards or backwards */ - void (*next_slide)(SlideShow *ss, void *vp); - void (*prev_slide)(SlideShow *ss, void *vp); +#define SC_SLIDESHOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + SC_TYPE_SLIDESHOW, SCEditor)) + +#define SC_IS_SLIDESHOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + SC_TYPE_SLIDESHOW)) - /* 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) */ - SCBlock *(*current_slide)(void *vp); +#define SC_SLIDESHOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((obj), \ + SC_TYPE_SLIDESHOW, SCEditorClass)) - /* Controller should update whatever visual representation of - * whether or not the display is linked */ - void (*changed_link)(SlideShow *ss, void *vp); +#define SC_IS_SLIDESHOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), \ + SC_TYPE_SLIDESHOW)) - /* Slideshow ended (including if you called end_slideshow) */ - void (*end_show)(SlideShow *ss, void *vp); +#define SC_SLIDESHOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + SC_TYPE_SLIDESHOW, SCSlideShowClass)) + +struct _scslideshow +{ + GtkWindow parent_instance; + + /* <private> */ + struct presentation *p; + SCBlock *cur_slide; + GtkWidget *drawingarea; + GdkCursor *blank_cursor; + int blank; + char geom[256]; + int slide_width; + int slide_height; + struct inhibit_sys *inhibit; + int linked; + cairo_surface_t *surface; + struct frame *top; }; -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, SCBlock *np); -extern SCBlock *slideshow_slide(SlideShow *ss); +struct _scslideshowclass +{ + GtkWindowClass parent_class; +}; -extern void toggle_slideshow_link(SlideShow *ss); -extern int slideshow_linked(SlideShow *ss); -extern void check_toggle_blank(SlideShow *ss); +typedef struct _scslideshow SCSlideshow; +typedef struct _scslideshowclass SCSlideshowClass; -extern void redraw_slideshow(SlideShow *ss); -extern void slideshow_rerender(SlideShow *ss); +extern SCSlideshow *sc_slideshow_new(struct presentation *p); +extern void sc_slideshow_set_slide(SCSlideshow *ss, SCBlock *ns); #endif /* SLIDESHOW_H */ |