diff options
Diffstat (limited to 'libstorycode')
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.c | 99 | ||||
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.h | 5 | ||||
-rw-r--r-- | libstorycode/gtk/gtkslideview.c | 22 | ||||
-rw-r--r-- | libstorycode/gtk/gtkslideview.h | 5 | ||||
-rw-r--r-- | libstorycode/narrative.c | 133 | ||||
-rw-r--r-- | libstorycode/narrative.h | 20 | ||||
-rw-r--r-- | libstorycode/narrative_priv.h | 7 | ||||
-rw-r--r-- | libstorycode/narrative_render_cairo.h | 2 | ||||
-rw-r--r-- | libstorycode/presentation.c | 220 | ||||
-rw-r--r-- | libstorycode/presentation.h | 59 | ||||
-rw-r--r-- | libstorycode/scparse_priv.h | 2 | ||||
-rw-r--r-- | libstorycode/slide.h | 2 | ||||
-rw-r--r-- | libstorycode/slide_render_cairo.c | 1 | ||||
-rw-r--r-- | libstorycode/slide_render_cairo.h | 2 | ||||
-rw-r--r-- | libstorycode/storycode.c | 5 | ||||
-rw-r--r-- | libstorycode/storycode.h | 4 | ||||
-rw-r--r-- | libstorycode/storycode.l | 1 | ||||
-rw-r--r-- | libstorycode/storycode.y | 18 |
18 files changed, 219 insertions, 388 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 66ed570..2e50065 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -33,7 +33,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <math.h> -#include <presentation.h> +#include <narrative.h> #include <narrative_render_cairo.h> //#include "slide_window.h" @@ -131,14 +131,14 @@ static void rewrap_range(GtkNarrativeView *e, int min, int max) pc = gtk_widget_get_pango_context(GTK_WIDGET(e)); - langname = presentation_get_language(e->p); + langname = narrative_get_language(e->n); lang = pango_language_from_string(langname); /* Wrap everything with the current width, to get the total height */ - narrative_wrap_range(presentation_get_narrative(e->p), - presentation_get_stylesheet(e->p), + narrative_wrap_range(e->n, + narrative_get_stylesheet(e->n), lang, pc, e->w, - presentation_get_imagestore(e->p), + narrative_get_imagestore(e->n), min, max, e->sel_start, e->sel_end); } @@ -146,7 +146,7 @@ static void rewrap_range(GtkNarrativeView *e, int min, int max) static void update_size(GtkNarrativeView *e) { e->w = e->visible_width; - e->h = narrative_get_height(presentation_get_narrative(e->p)); + e->h = narrative_get_height(e->n); set_vertical_params(e); set_horizontal_params(e); @@ -156,15 +156,11 @@ static void update_size(GtkNarrativeView *e) static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event, GtkNarrativeView *e) { - Narrative *n; - - n = presentation_get_narrative(e->p); - e->visible_height = event->height; e->visible_width = event->width; e->w = e->visible_width; - rewrap_range(e, 0, n->n_items-1); + rewrap_range(e, 0, e->n->n_items-1); update_size(e); @@ -604,8 +600,7 @@ static void draw_caret(cairo_t *cr, Narrative *n, struct edit_pos cpos, static void draw_overlay(cairo_t *cr, GtkNarrativeView *e) { - draw_caret(cr, presentation_get_narrative(e->p), - e->cpos, e->para_highlight, e->w); + draw_caret(cr, e->n, e->cpos, e->para_highlight, e->w); } @@ -623,8 +618,7 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, GtkNarrativeView *e) cairo_fill(cr); /* Contents */ - narrative_render_cairo(presentation_get_narrative(e->p), cr, - presentation_get_stylesheet(e->p)); + narrative_render_cairo(e->n, cr, narrative_get_stylesheet(e->n)); /* Editing overlay */ draw_overlay(cr, e); @@ -635,34 +629,23 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, GtkNarrativeView *e) static void check_cursor_visible(GtkNarrativeView *e) { - Narrative *n; double x, y, h; - n = presentation_get_narrative(e->p); - get_cursor_pos(n, e->cpos, &x, &y, &h); + get_cursor_pos(e->n, e->cpos, &x, &y, &h); /* Off the bottom? */ if ( y - e->scroll_pos + h > e->visible_height ) { e->scroll_pos = y + h - e->visible_height; - e->scroll_pos += n->space_b; + e->scroll_pos += e->n->space_b; } /* Off the top? */ if ( y < e->scroll_pos ) { - e->scroll_pos = y - n->space_t; + e->scroll_pos = y - e->n->space_t; } } -static struct narrative_item *get_current_item(GtkNarrativeView *e, - Narrative **pn) -{ - Narrative *n = presentation_get_narrative(e->p); - if ( pn != NULL ) *pn = n; - return &n->items[e->cpos.para]; -} - - static size_t end_offset_of_para(Narrative *n, int pnum) { assert(pnum >= 0); @@ -780,12 +763,9 @@ static int positions_equal(struct edit_pos a, struct edit_pos b) static void do_backspace(GtkNarrativeView *e, signed int dir) { - Narrative *n; struct edit_pos p1, p2; size_t o1, o2; - n = presentation_get_narrative(e->p); - if ( !positions_equal(e->sel_start, e->sel_end) ) { /* Block delete */ @@ -797,13 +777,13 @@ static void do_backspace(GtkNarrativeView *e, signed int dir) /* Delete one character, as represented visually */ p2 = e->cpos; p1 = p2; - cursor_moveh(n, &p1, dir); + cursor_moveh(e->n, &p1, dir); } sort_positions(&p1, &p2); - o1 = pos_trail_to_offset(&n->items[p1.para], p1.pos, p1.trail); - o2 = pos_trail_to_offset(&n->items[p2.para], p2.pos, p2.trail); - narrative_delete_block(n, p1.para, o1, p2.para, o2); + o1 = pos_trail_to_offset(&e->n->items[p1.para], p1.pos, p1.trail); + o2 = pos_trail_to_offset(&e->n->items[p2.para], p2.pos, p2.trail); + narrative_delete_block(e->n, p1.para, o1, p2.para, o2); e->cpos = p1; unset_selection(e); @@ -848,20 +828,19 @@ static void split_paragraph_at_cursor(Narrative *n, struct edit_pos pos) static void insert_text(char *t, GtkNarrativeView *e) { - Narrative *n; struct narrative_item *item; if ( !positions_equal(e->sel_start, e->sel_end) ) { do_backspace(e, 0); } - item = get_current_item(e, &n); + item = &e->n->items[e->cpos.para]; if ( strcmp(t, "\n") == 0 ) { - split_paragraph_at_cursor(n, e->cpos); + split_paragraph_at_cursor(e->n, e->cpos); rewrap_range(e, e->cpos.para, e->cpos.para+1); update_size(e); - cursor_moveh(n, &e->cpos, +1); + cursor_moveh(e->n, &e->cpos, +1); check_cursor_visible(e); emit_change_sig(e); redraw(e); @@ -876,7 +855,7 @@ static void insert_text(char *t, GtkNarrativeView *e) insert_text_in_paragraph(item, off, t); rewrap_range(e, e->cpos.para, e->cpos.para); update_size(e); - cursor_moveh(n, &e->cpos, +1); + cursor_moveh(e->n, &e->cpos, +1); } /* else do nothing: pressing enter is OK, though */ @@ -926,21 +905,19 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, GtkNarrativeView *e) { gdouble x, y; - Narrative *n; - n = presentation_get_narrative(e->p); x = event->x; y = event->y + e->scroll_pos; /* Clicked an existing frame, no immediate dragging */ e->drag_status = DRAG_STATUS_COULD_DRAG; unset_selection(e); - find_cursor(n, x, y, &e->sel_start); + find_cursor(e->n, x, y, &e->sel_start); e->sel_end = e->sel_start; e->cpos = e->sel_start; if ( event->type == GDK_2BUTTON_PRESS ) { - struct narrative_item *item = &n->items[e->cpos.para]; + struct narrative_item *item = &e->n->items[e->cpos.para]; if ( item->type == NARRATIVE_ITEM_SLIDE ) { g_signal_emit_by_name(e, "slide-double-clicked", item->slide); @@ -966,7 +943,6 @@ static void sorti(int *a, int *b) static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, GtkNarrativeView *e) { - Narrative *n; gdouble x, y; struct edit_pos old_sel_end; int minp, maxp; @@ -981,8 +957,7 @@ static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, } old_sel_end = e->sel_end; - n = presentation_get_narrative(e->p); - find_cursor(n, x, y, &e->sel_end); + find_cursor(e->n, x, y, &e->sel_end); minp = e->sel_start.para; maxp = e->sel_end.para; @@ -993,7 +968,7 @@ static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, } rewrap_range(e, minp, maxp); - find_cursor(n, x, y, &e->cpos); + find_cursor(e->n, x, y, &e->cpos); redraw(e); gdk_event_request_motions(event); @@ -1005,7 +980,6 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, GtkNarrativeView *e) { gboolean r; - Narrative *n; int claim = 0; /* Throw the event to the IM context and let it sort things out */ @@ -1013,30 +987,28 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, event); if ( r ) return FALSE; /* IM ate it */ - n = presentation_get_narrative(e->p); - switch ( event->keyval ) { case GDK_KEY_Left : - cursor_moveh(n, &e->cpos, -1); + cursor_moveh(e->n, &e->cpos, -1); redraw(e); claim = 1; break; case GDK_KEY_Right : - cursor_moveh(n, &e->cpos, +1); + cursor_moveh(e->n, &e->cpos, +1); redraw(e); claim = 1; break; case GDK_KEY_Up : - cursor_moveh(n, &e->cpos, -1); + cursor_moveh(e->n, &e->cpos, -1); redraw(e); claim = 1; break; case GDK_KEY_Down : - cursor_moveh(n, &e->cpos, +1); + cursor_moveh(e->n, &e->cpos, +1); redraw(e); claim = 1; break; @@ -1132,7 +1104,7 @@ static gint realise_sig(GtkWidget *da, GtkNarrativeView *e) } -GtkWidget *gtk_narrative_view_new(Presentation *p) +GtkWidget *gtk_narrative_view_new(Narrative *n) { GtkNarrativeView *nview; GtkTargetEntry targets[1]; @@ -1142,7 +1114,7 @@ GtkWidget *gtk_narrative_view_new(Presentation *p) nview->w = 100; nview->h = 100; nview->scroll_pos = 0; - nview->p = p; + nview->n = n; nview->para_highlight = 0; @@ -1215,21 +1187,16 @@ void gtk_narrative_view_set_cursor_para(GtkNarrativeView *e, signed int pos) redraw(e); } + void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e) { - Narrative *n; Slide *s; - int pos; - - n = presentation_get_narrative(e->p); s = slide_new(); if ( s == NULL ) return; - split_paragraph_at_cursor(n, e->cpos); - pos = narrative_get_slide_number(n, e->cpos.para); - presentation_insert_slide(e->p, s, pos); - narrative_insert_slide(n, s, e->cpos.para+1); + split_paragraph_at_cursor(e->n, e->cpos); + narrative_insert_slide(e->n, s, e->cpos.para+1); rewrap_range(e, e->cpos.para, e->cpos.para+2); e->cpos.para++; diff --git a/libstorycode/gtk/gtknarrativeview.h b/libstorycode/gtk/gtknarrativeview.h index c85ca1f..82fd215 100644 --- a/libstorycode/gtk/gtknarrativeview.h +++ b/libstorycode/gtk/gtknarrativeview.h @@ -32,7 +32,6 @@ #include <stylesheet.h> #include <narrative.h> -#include <presentation.h> #include <imagestore.h> #include <narrative_render_cairo.h> @@ -66,7 +65,7 @@ struct _gtknarrativeview GtkDrawingArea parent_instance; /*< private >*/ - Presentation *p; + Narrative *n; GtkIMContext *im_context; int w; /* Surface size in pixels */ @@ -101,7 +100,7 @@ typedef struct _gtknarrativeview GtkNarrativeView; typedef struct _gtknarrativeviewclass GtkNarrativeViewClass; extern GType gtk_narrative_view_get_type(void); -extern GtkWidget *gtk_narrative_view_new(Presentation *p); +extern GtkWidget *gtk_narrative_view_new(Narrative *n); extern void gtk_narrative_view_set_logical_size(GtkNarrativeView *e, double w, double h); diff --git a/libstorycode/gtk/gtkslideview.c b/libstorycode/gtk/gtkslideview.c index 91bc1c7..c98fe5b 100644 --- a/libstorycode/gtk/gtkslideview.c +++ b/libstorycode/gtk/gtkslideview.c @@ -35,7 +35,7 @@ #include <libintl.h> #define _(x) gettext(x) -#include <presentation.h> +#include <narrative.h> #include <slide_render_cairo.h> #include <stylesheet.h> @@ -57,7 +57,7 @@ static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event, double log_w, log_h; Stylesheet *ss; - ss = presentation_get_stylesheet(e->p); + ss = narrative_get_stylesheet(e->n); if ( slide_get_logical_size(e->slide, ss, &log_w, &log_h) ) { fprintf(stderr, "Failed to get logical size\n"); return FALSE; @@ -250,7 +250,7 @@ static void draw_overlay(cairo_t *cr, GtkSlideView *e) double slide_w, slide_h; Stylesheet *stylesheet; - stylesheet = presentation_get_stylesheet(e->p); + stylesheet = narrative_get_stylesheet(e->n); slide_get_logical_size(e->slide, stylesheet, &slide_w, &slide_h); slide_item_get_geom(e->cursor_frame, stylesheet, &x, &y, &w, &h, slide_w, slide_h); @@ -322,9 +322,9 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, GtkSlideView *e) /* Contents */ pc = pango_cairo_create_context(cr); - slide_render_cairo(e->slide, cr, presentation_get_imagestore(e->p), - presentation_get_stylesheet(e->p), - presentation_get_slide_number(e->p, e->slide), + slide_render_cairo(e->slide, cr, narrative_get_imagestore(e->n), + narrative_get_stylesheet(e->n), + narrative_get_slide_number_for_slide(e->n, e->slide), pango_language_get_default(), pc, e->cursor_frame, e->sel_start, e->sel_end); g_object_unref(pc); @@ -581,7 +581,7 @@ static void do_resize(GtkSlideView *e, double x, double y, double w, double h) assert(e->cursor_frame != NULL); - stylesheet = presentation_get_stylesheet(e->p); + stylesheet = narrative_get_stylesheet(e->n); slide_get_logical_size(e->slide, stylesheet, &slide_w, &slide_h); if ( w < 0.0 ) { @@ -635,7 +635,7 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, double slide_w, slide_h; double frx, fry, frw, frh; - stylesheet = presentation_get_stylesheet(e->p); + stylesheet = narrative_get_stylesheet(e->n); slide_get_logical_size(e->slide, stylesheet, &slide_w, &slide_h); x = event->x - e->border_offs_x + e->h_scroll_pos; @@ -750,7 +750,7 @@ static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, GtkSlideView *e x /= e->view_scale; y /= e->view_scale; - stylesheet = presentation_get_stylesheet(e->p); + stylesheet = narrative_get_stylesheet(e->n); slide_get_logical_size(e->slide, stylesheet, &slide_w, &slide_h); if ( e->drag_status == DRAG_STATUS_COULD_DRAG ) { @@ -1397,7 +1397,7 @@ void gtk_slide_view_set_slide(GtkWidget *widget, Slide *slide) } -GtkWidget *gtk_slide_view_new(Presentation *p, Slide *slide) +GtkWidget *gtk_slide_view_new(Narrative *n, Slide *slide) { GtkSlideView *sv; GtkTargetEntry targets[1]; @@ -1405,7 +1405,7 @@ GtkWidget *gtk_slide_view_new(Presentation *p, Slide *slide) sv = g_object_new(GTK_TYPE_SLIDE_VIEW, NULL); - sv->p = p; + sv->n = n; sv->slide = slide; sv->w = 100; sv->h = 100; diff --git a/libstorycode/gtk/gtkslideview.h b/libstorycode/gtk/gtkslideview.h index 0221fca..59b9ad4 100644 --- a/libstorycode/gtk/gtkslideview.h +++ b/libstorycode/gtk/gtkslideview.h @@ -33,7 +33,6 @@ #include <stylesheet.h> #include <narrative.h> -#include <presentation.h> #include <imagestore.h> #include <slide_render_cairo.h> @@ -90,7 +89,7 @@ struct _gtkslideview GtkDrawingArea parent_instance; /*< private >*/ - Presentation *p; + Narrative *n; Slide *slide; GtkIMContext *im_context; @@ -148,7 +147,7 @@ struct _gtkslideviewclass typedef struct _gtkslideview GtkSlideView; typedef struct _gtkslideviewclass GtkSlideViewClass; -extern GtkWidget *gtk_slide_view_new(Presentation *p, Slide *slide); +extern GtkWidget *gtk_slide_view_new(Narrative *n, Slide *slide); extern void gtk_slide_view_set_slide(GtkWidget *sv, Slide *slide); #endif /* GTK_SLIDE_VIEW_H */ diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index 5dfe117..19797e3 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -28,9 +28,23 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <stdio.h> +#include <gio/gio.h> +#ifdef HAVE_PANGO +#include <pango/pango.h> +#endif + +#ifdef HAVE_CAIRO +#include <cairo.h> +#endif + +#include "stylesheet.h" +#include "slide.h" #include "narrative.h" #include "narrative_priv.h" +#include "imagestore.h" +#include "storycode.h" Narrative *narrative_new() { @@ -39,6 +53,14 @@ Narrative *narrative_new() if ( n == NULL ) return NULL; n->n_items = 0; n->items = NULL; + n->stylesheet = NULL; + n->imagestore = NULL; + n->saved = 1; +#ifdef HAVE_PANGO + n->language = pango_language_to_string(pango_language_get_default()); +#else + n->language = NULL; +#endif return n; } @@ -70,6 +92,74 @@ void narrative_free(Narrative *n) } +Narrative *narrative_load(GFile *file) +{ + GBytes *bytes; + const char *text; + size_t len; + Narrative *n; + + bytes = g_file_load_bytes(file, NULL, NULL, NULL); + if ( bytes == NULL ) return NULL; + + text = g_bytes_get_data(bytes, &len); + n = storycode_parse_presentation(text); + g_bytes_unref(bytes); + if ( n == NULL ) return NULL; + + n->imagestore = imagestore_new("."); /* FIXME: From app config */ + imagestore_set_parent(n->imagestore, g_file_get_parent(file)); + return n; +} + + +int narrative_save(Narrative *n, GFile *file) +{ + /* FIXME: Implementation */ + return 1; +} + + +void narrative_set_unsaved(Narrative *n) +{ + n->saved = 0; +} + + +int narrative_get_unsaved(Narrative *n) +{ + return !n->saved; +} + + +void narrative_add_stylesheet(Narrative *n, Stylesheet *ss) +{ + assert(n->stylesheet == NULL); + n->stylesheet = ss; +} + + +Stylesheet *narrative_get_stylesheet(Narrative *n) +{ + if ( n == NULL ) return NULL; + return n->stylesheet; +} + + +const char *narrative_get_language(Narrative *n) +{ + if ( n == NULL ) return NULL; + return n->language; +} + + +ImageStore *narrative_get_imagestore(Narrative *n) +{ + if ( n == NULL ) return NULL; + return n->imagestore; +} + + static void init_item(struct narrative_item *item) { item->layout = NULL; @@ -265,6 +355,17 @@ int narrative_get_num_items(Narrative *n) } +int narrative_get_num_slides(Narrative *n) +{ + int i; + int ns = 0; + for ( i=0; i<n->n_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) ns++; + } + return ns; +} + + Slide *narrative_get_slide(Narrative *n, int para) { if ( para >= n->n_items ) return NULL; @@ -273,12 +374,40 @@ Slide *narrative_get_slide(Narrative *n, int para) } -int narrative_get_slide_number(Narrative *n, int para) +int narrative_get_slide_number_for_para(Narrative *n, int para) { int i; int ns = 0; - for ( i=0; i<n->n_items; i++ ) { + for ( i=0; i<para; i++ ) { if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) ns++; } return ns; } + + +int narrative_get_slide_number_for_slide(Narrative *n, Slide *s) +{ + int i; + int ns = 0; + for ( i=0; i<n->n_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) { + if ( n->items[i].slide == s ) return ns; + ns++; + } + } + return n->n_items; +} + + +Slide *narrative_get_slide_by_number(Narrative *n, int pos) +{ + int i; + int ns = 0; + for ( i=0; i<n->n_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) { + if ( ns == pos ) return n->items[i].slide; + ns++; + } + } + return NULL; +} diff --git a/libstorycode/narrative.h b/libstorycode/narrative.h index 193339d..22918e1 100644 --- a/libstorycode/narrative.h +++ b/libstorycode/narrative.h @@ -27,13 +27,28 @@ #include <config.h> #endif +#include <gio/gio.h> + typedef struct _narrative Narrative; #include "slide.h" +#include "imagestore.h" extern Narrative *narrative_new(void); extern void narrative_free(Narrative *n); +extern void narrative_add_stylesheet(Narrative *n, Stylesheet *ss); +extern Stylesheet *narrative_get_stylesheet(Narrative *n); + +extern const char *narrative_get_language(Narrative *n); +extern ImageStore *narrative_get_imagestore(Narrative *n); + +extern Narrative *narrative_load(GFile *file); +extern int narrative_save(Narrative *n, GFile *file); + +extern void narrative_set_unsaved(Narrative *n); +extern int narrative_get_unsaved(Narrative *n); + extern void narrative_add_prestitle(Narrative *n, char *text); extern void narrative_add_bp(Narrative *n, char *text); extern void narrative_add_text(Narrative *n, char *text); @@ -43,8 +58,11 @@ extern void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2); extern void narrative_split_item(Narrative *n, int i1, size_t o1); extern int narrative_get_num_items(Narrative *n); +extern int narrative_get_num_slides(Narrative *n); extern Slide *narrative_get_slide(Narrative *n, int para); -extern int narrative_get_slide_number(Narrative *n, int para); +extern Slide *narrative_get_slide_by_number(Narrative *n, int pos); +extern int narrative_get_slide_number_for_para(Narrative *n, int para); +extern int narrative_get_slide_number_for_slide(Narrative *n, Slide *s); #endif /* NARRATIVE_H */ diff --git a/libstorycode/narrative_priv.h b/libstorycode/narrative_priv.h index 1a461c4..065b416 100644 --- a/libstorycode/narrative_priv.h +++ b/libstorycode/narrative_priv.h @@ -27,6 +27,7 @@ #include <pango/pangocairo.h> #endif +#include "imagestore.h" #include "storycode.h" #include "slide.h" @@ -72,8 +73,14 @@ struct narrative_item struct _narrative { + Stylesheet *stylesheet; + ImageStore *imagestore; + int saved; + const char *language; + int n_items; struct narrative_item *items; + double w; double space_l; double space_r; diff --git a/libstorycode/narrative_render_cairo.h b/libstorycode/narrative_render_cairo.h index 690517d..fe3680a 100644 --- a/libstorycode/narrative_render_cairo.h +++ b/libstorycode/narrative_render_cairo.h @@ -27,7 +27,7 @@ #include <config.h> #endif -#include "presentation.h" +#include "narrative.h" #include "imagestore.h" struct edit_pos diff --git a/libstorycode/presentation.c b/libstorycode/presentation.c deleted file mode 100644 index 925f011..0000000 --- a/libstorycode/presentation.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * presentation.c - * - * Copyright © 2019 Thomas White <taw@bitwiz.org.uk> - * - * This file is part of Colloquium. - * - * Colloquium is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <stdio.h> -#include <gio/gio.h> - -#ifdef HAVE_PANGO -#include <pango/pango.h> -#endif - -#include "presentation.h" -#include "stylesheet.h" -#include "slide.h" -#include "narrative.h" -#include "imagestore.h" -#include "storycode.h" - -struct _presentation -{ - Stylesheet *stylesheet; - Narrative *narrative; - ImageStore *imagestore; - int n_slides; - Slide **slides; - int max_slides; - int saved; - const char *language; -}; - - -Presentation *presentation_new() -{ - Presentation *p; - p = malloc(sizeof(*p)); - if ( p == NULL ) return NULL; - p->stylesheet = NULL; - p->narrative = NULL; - p->slides = NULL; - p->n_slides = 0; - p->max_slides = 0; - p->imagestore = NULL; - p->saved = 1; -#ifdef HAVE_PANGO - p->language = pango_language_to_string(pango_language_get_default()); -#else - p->language = NULL; -#endif - return p; -} - - -Presentation *presentation_load(GFile *file) -{ - GBytes *bytes; - const char *text; - size_t len; - Presentation *p; - - bytes = g_file_load_bytes(file, NULL, NULL, NULL); - if ( bytes == NULL ) return NULL; - - text = g_bytes_get_data(bytes, &len); - p = storycode_parse_presentation(text); - g_bytes_unref(bytes); - if ( p == NULL ) return NULL; - - p->imagestore = imagestore_new("."); /* FIXME: From app config */ - imagestore_set_parent(p->imagestore, g_file_get_parent(file)); - return p; -} - - -int presentation_save(Presentation *p, GFile *file) -{ - /* FIXME: Implementation */ - return 1; -} - - -void presentation_set_unsaved(Presentation *p) -{ - p->saved = 0; -} - - -int presentation_get_unsaved(Presentation *p) -{ - return !p->saved; -} - - -void presentation_free(Presentation *p) -{ - /* FIXME: Free narrative, slides, imagestore */ - free(p); -} - - -void presentation_add_stylesheet(Presentation *p, Stylesheet *ss) -{ - assert(p->stylesheet == NULL); - p->stylesheet = ss; -} - - -void presentation_add_narrative(Presentation *p, Narrative *n) -{ - assert(p->narrative == NULL); - p->narrative = n; -} - - -void presentation_add_slide(Presentation *p, Slide *s) -{ - assert(p->n_slides <= p->max_slides); - if ( p->n_slides == p->max_slides ) { - Slide **nslides = realloc(p->slides, - (p->max_slides+8)*sizeof(Slide *)); - if ( nslides == NULL ) { - fprintf(stderr, "Failed to allocate memory for slide\n"); - return; - } - p->slides = nslides; - p->max_slides += 8; - } - - p->slides[p->n_slides++] = s; -} - - -void presentation_insert_slide(Presentation *p, Slide *s, int pos) -{ - int i; - presentation_add_slide(p, NULL); - assert(pos < p->n_slides); - for ( i=p->n_slides-1; i>pos+1; i-- ) { - p->slides[i] = p->slides[i-1]; - } - p->slides[pos] = s; -} - - -int presentation_get_num_slides(Presentation *p) -{ - return p->n_slides; -} - - -Slide *presentation_get_slide_by_number(Presentation *p, int i) -{ - if ( i >= p->n_slides ) return NULL; - if ( i < 0 ) return NULL; - return p->slides[i]; -} - - -signed int presentation_get_slide_number(Presentation *p, Slide *s) -{ - int i; - if ( p == NULL ) return -1; - for ( i=0; i<p->n_slides; i++ ) { - if ( s == p->slides[i] ) return i; - } - return -1; -} - - -Stylesheet *presentation_get_stylesheet(Presentation *p) -{ - if ( p == NULL ) return NULL; - return p->stylesheet; -} - - -Narrative *presentation_get_narrative(Presentation *p) -{ - if ( p == NULL ) return NULL; - return p->narrative; -} - - -const char *presentation_get_language(Presentation *p) -{ - if ( p == NULL ) return NULL; - return p->language; -} - - -ImageStore *presentation_get_imagestore(Presentation *p) -{ - if ( p == NULL ) return NULL; - return p->imagestore; -} diff --git a/libstorycode/presentation.h b/libstorycode/presentation.h deleted file mode 100644 index f2f22f4..0000000 --- a/libstorycode/presentation.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * presentation.h - * - * Copyright © 2019 Thomas White <taw@bitwiz.org.uk> - * - * This file is part of Colloquium. - * - * Colloquium is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef PRESENTATION_H -#define PRESENTATION_H - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gio/gio.h> - -typedef struct _presentation Presentation; - -#include "stylesheet.h" -#include "narrative.h" -#include "imagestore.h" - -extern Presentation *presentation_new(void); -extern Presentation *presentation_load(GFile *file); -extern int presentation_save(Presentation *p, GFile *file); -extern void presentation_free(Presentation *p); -extern void presentation_set_unsaved(Presentation *p); -extern int presentation_get_unsaved(Presentation *p); - -extern void presentation_add_stylesheet(Presentation *p, Stylesheet *ss); -extern void presentation_add_narrative(Presentation *p, Narrative *n); -extern void presentation_add_slide(Presentation *p, Slide *s); -extern void presentation_insert_slide(Presentation *p, Slide *s, int pos); - -extern int presentation_get_num_slides(Presentation *p); -extern Slide *presentation_get_slide_by_number(Presentation *p, int i); -extern signed int presentation_get_slide_number(Presentation *p, Slide *s); -extern Stylesheet *presentation_get_stylesheet(Presentation *p); -extern Narrative *presentation_get_narrative(Presentation *p); -extern const char *presentation_get_language(Presentation *p); -extern ImageStore *presentation_get_imagestore(Presentation *p); - - -#endif /* PRESENTATION_H */ diff --git a/libstorycode/scparse_priv.h b/libstorycode/scparse_priv.h index 47edbf8..c327b1a 100644 --- a/libstorycode/scparse_priv.h +++ b/libstorycode/scparse_priv.h @@ -23,7 +23,6 @@ #ifndef SCPARSE_PRIV_H #define SCPARSE_PRIV_H -#include "presentation.h" #include "narrative.h" #include "slide.h" @@ -40,7 +39,6 @@ enum style_mask struct scpctx { - Presentation *p; Narrative *n; Stylesheet *ss; Slide *s; diff --git a/libstorycode/slide.h b/libstorycode/slide.h index b4510ec..3957f9e 100644 --- a/libstorycode/slide.h +++ b/libstorycode/slide.h @@ -27,6 +27,8 @@ #include <config.h> #endif +#include <stddef.h> + typedef struct _slide Slide; typedef struct _slideitem SlideItem; diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c index c428fad..03df9c6 100644 --- a/libstorycode/slide_render_cairo.c +++ b/libstorycode/slide_render_cairo.c @@ -33,7 +33,6 @@ #include <stdlib.h> #include <math.h> -#include "presentation.h" #include "slide.h" #include "narrative.h" #include "stylesheet.h" diff --git a/libstorycode/slide_render_cairo.h b/libstorycode/slide_render_cairo.h index cd6e03b..bb7ad84 100644 --- a/libstorycode/slide_render_cairo.h +++ b/libstorycode/slide_render_cairo.h @@ -27,7 +27,7 @@ #include <config.h> #endif -#include "presentation.h" +#include "slide.h" #include "imagestore.h" struct slide_pos diff --git a/libstorycode/storycode.c b/libstorycode/storycode.c index edfe580..b34785d 100644 --- a/libstorycode/storycode.c +++ b/libstorycode/storycode.c @@ -28,7 +28,6 @@ #include <stdlib.h> #include <string.h> -#include "presentation.h" #include "narrative.h" #include "slide.h" #include "stylesheet.h" @@ -38,7 +37,7 @@ #include "scparse_priv.h" -Presentation *storycode_parse_presentation(const char *sc) +Narrative *storycode_parse_presentation(const char *sc) { YY_BUFFER_STATE b; struct scpctx parse_ctx; @@ -47,5 +46,5 @@ Presentation *storycode_parse_presentation(const char *sc) scparse(&parse_ctx); sc_delete_buffer(b); - return parse_ctx.p; + return parse_ctx.n; } diff --git a/libstorycode/storycode.h b/libstorycode/storycode.h index 476941e..f941493 100644 --- a/libstorycode/storycode.h +++ b/libstorycode/storycode.h @@ -27,9 +27,9 @@ #include <config.h> #endif -#include "presentation.h" +#include "narrative.h" -extern Presentation *storycode_parse_presentation(const char *sc); +extern Narrative *storycode_parse_presentation(const char *sc); #endif /* STORYCODE_H */ diff --git a/libstorycode/storycode.l b/libstorycode/storycode.l index d64b8c0..e7f3961 100644 --- a/libstorycode/storycode.l +++ b/libstorycode/storycode.l @@ -23,7 +23,6 @@ %{ #define YYDEBUG 1 - #include "presentation.h" #include "narrative.h" #include "slide.h" #include "stylesheet.h" diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index f549525..d2508e2 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -26,7 +26,6 @@ %code requires { - #include "presentation.h" #include "narrative.h" #include "slide.h" #include "stylesheet.h" @@ -35,7 +34,6 @@ } %union { - Presentation *p; Stylesheet *ss; Narrative *n; Slide *s; @@ -77,7 +75,6 @@ %token SQOPEN SQCLOSE %token UNIT VALUE SIZE HEXCOL -%type <p> presentation %type <n> narrative %type <s> slide %type <ss> stylesheet @@ -102,11 +99,10 @@ %parse-param { struct scpctx *ctx }; %initial-action { - ctx->p = presentation_new(); + ctx->n = narrative_new(); /* These are the objects currently being created. They will be - * added to the presentation when they're complete */ - ctx->n = narrative_new(); + * added to the narrative when they're complete */ ctx->ss = stylesheet_new(); ctx->s = slide_new(); @@ -179,9 +175,8 @@ void set_style(struct scpctx *ctx, enum style_element element) /* The only thing a "presentation" really needs is narrative */ presentation: - stylesheet narrative { presentation_add_stylesheet(ctx->p, ctx->ss); - presentation_add_narrative(ctx->p, ctx->n); } -| narrative { presentation_add_narrative(ctx->p, ctx->n); } + stylesheet narrative +| narrative ; @@ -211,8 +206,7 @@ narrative_bulletpoint: /* -------- Slide -------- */ slide: - SLIDE '{' slide_parts '}' { presentation_add_slide(ctx->p, ctx->s); - narrative_add_slide(ctx->n, ctx->s); + SLIDE '{' slide_parts '}' { narrative_add_slide(ctx->n, ctx->s); /* New work in progress object */ ctx->s = slide_new(); } ; @@ -326,7 +320,7 @@ stylesheet: STYLES '{' style_narrative style_slide - '}' { } + '}' { narrative_add_stylesheet(ctx->n, ctx->ss); } ; style_narrative: |