diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | src/mainwindow.c | 12 | ||||
-rw-r--r-- | src/notes.c | 151 | ||||
-rw-r--r-- | src/notes.h | 42 | ||||
-rw-r--r-- | src/presentation.c | 7 | ||||
-rw-r--r-- | src/presentation.h | 2 |
6 files changed, 209 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index a627142..a956a3c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,13 +14,13 @@ src_colloquium_SOURCES = src/colloquium.c src/render.c \ src/mainwindow.c src/presentation.c \ src/stylesheet.c src/loadsave.c src/frame.c \ src/slideshow.c src/wrap.c src/storycode.c \ - src/imagestore.c + src/imagestore.c src/notes.c INCLUDES = -Iharfatum/src EXTRA_DIST += src/presentation.h src/render.h src/wrap.h \ src/stylesheet.h src/loadsave.h src/slideshow.h src/storycode.h \ - src/imagestore.h + src/imagestore.h src/notes.h src/default_stylesheet.o: src/default_stylesheet.sty ld -r -b binary -o src/default_stylesheet.o src/default_stylesheet.sty diff --git a/src/mainwindow.c b/src/mainwindow.c index e84dd27..e3a5329 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -39,6 +39,7 @@ #include "frame.h" #include "slideshow.h" #include "wrap.h" +#include "notes.h" /* Update a slide, once it's been edited in some way. */ @@ -630,9 +631,9 @@ void change_edit_slide(struct presentation *p, struct slide *np) update_toolbar(p); redraw_editor(p); - //if ( p->notes != NULL ) { - // notify_notes_slide_changed(p, np); - //} + if ( p->notes != NULL ) { + notify_notes_slide_changed(p, np); + } if ( (p->slideshow != NULL) && p->slideshow_linked ) { change_proj_slide(p, np); @@ -708,8 +709,7 @@ static gint open_stylesheet_sig(GtkWidget *widget, struct presentation *p) static gint open_notes_sig(GtkWidget *widget, struct presentation *p) { - /* FIXME */ - //open_notes(p); + open_notes(p); return FALSE; } @@ -765,7 +765,7 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox) { "TSlideshowAction", GTK_STOCK_FULLSCREEN, "_Start slideshow", "F5", NULL, G_CALLBACK(start_slideshow_sig) }, { "NotesAction", NULL, "_Open slide notes", - "F5", NULL, G_CALLBACK(open_notes_sig) }, + "F8", NULL, G_CALLBACK(open_notes_sig) }, { "PrefsAction", GTK_STOCK_PREFERENCES, "_Preferences", NULL, NULL, NULL }, diff --git a/src/notes.c b/src/notes.c new file mode 100644 index 0000000..f5d9408 --- /dev/null +++ b/src/notes.c @@ -0,0 +1,151 @@ +/* + * notes.c + * + * Copyright © 2013 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 <gtk/gtk.h> + +#include "presentation.h" + + +struct notes +{ + GtkWidget *window; + GtkWidget *v; +}; + + +static void set_notes_title(struct presentation *p) +{ + gtk_window_set_title(GTK_WINDOW(p->notes->window), "Colloquium notes"); +} + + +static void update_notes(struct presentation *p) +{ + GtkTextBuffer *tb; + + if ( p->notes == NULL ) return; + + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(p->notes->v)); + gtk_text_buffer_set_text(tb, p->cur_edit_slide->notes, -1); +} + + +static void grab_notes(struct notes *n, struct slide *s) +{ + gchar *text; + GtkTextBuffer *tb; + GtkTextIter i1, i2; + + if ( n == NULL ) return; + + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(n->v)); + gtk_text_buffer_get_start_iter(tb, &i1); + gtk_text_buffer_get_end_iter(tb, &i2); + text = gtk_text_buffer_get_text(tb, &i1, &i2, TRUE); + + free(s->notes); + s->notes = text; +} + + +void grab_current_notes(struct presentation *p) +{ + grab_notes(p->notes, p->cur_notes_slide); +} + + +void notify_notes_slide_changed(struct presentation *p, struct slide *np) +{ + grab_notes(p->notes, p->cur_notes_slide); + p->cur_notes_slide = np; + update_notes(p); +} + + +static gint close_notes_sig(GtkWidget *w, struct presentation *p) +{ + grab_notes(p->notes, p->cur_notes_slide); + p->notes = NULL; + return FALSE; +} + + +void write_notes(struct slide *s, struct serializer *ser) +{ + serialize_s(ser, "notes", s->notes); +} + + +void load_notes(struct ds_node *node, struct slide *s) +{ + char *v; + + if ( get_field_s(node, "notes", &v) ) return; + + s->notes = v; +} + + +void open_notes(struct presentation *p) +{ + struct notes *n; + GtkWidget *sc; + PangoFontDescription *desc; + + if ( p->notes != NULL ) return; /* Already open */ + + n = malloc(sizeof(struct notes)); + if ( n == NULL ) return; + p->notes = n; + + p->cur_notes_slide = p->cur_edit_slide; + + n->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size(GTK_WINDOW(n->window), 800, 256); + sc = gtk_scrolled_window_new(NULL, NULL); + gtk_container_add(GTK_CONTAINER(n->window), sc); + + n->v = gtk_text_view_new(); + desc = pango_font_description_from_string("Sans 24"); + gtk_widget_modify_font(n->v, desc); + pango_font_description_free(desc); + gtk_text_view_set_left_margin(GTK_TEXT_VIEW(n->v), 30); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(n->v), 30); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(n->v), GTK_WRAP_WORD_CHAR); + gtk_container_add(GTK_CONTAINER(sc), n->v); + + g_signal_connect(G_OBJECT(n->v), "destroy", + G_CALLBACK(close_notes_sig), p); + + set_notes_title(p); + gtk_widget_show_all(n->window); + + update_notes(p); +} diff --git a/src/notes.h b/src/notes.h new file mode 100644 index 0000000..32b6bbe --- /dev/null +++ b/src/notes.h @@ -0,0 +1,42 @@ +/* + * notes.h + * + * Copyright © 2013 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 NOTES_H +#define NOTES_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +struct notes; + +extern void open_notes(struct presentation *p); + +extern void notify_notes_slide_changed(struct presentation *p, + struct slide *np); + +extern void write_notes(struct slide *s, struct serializer *ser); +extern void load_notes(struct ds_node *node, struct slide *s); + +extern void grab_current_notes(struct presentation *p); + +#endif /* NOTES_H */ diff --git a/src/presentation.c b/src/presentation.c index f9b4307..c406840 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -37,6 +37,7 @@ #include "frame.h" #include "imagestore.h" #include "wrap.h" +#include "notes.h" static int num_presentations = 0; @@ -361,7 +362,7 @@ int save_presentation(struct presentation *p, const char *filename) struct serializer ser; char *old_fn; - //grab_current_notes(p); + grab_current_notes(p); fh = fopen(filename, "w"); if ( fh == NULL ) return 1; @@ -399,6 +400,8 @@ int save_presentation(struct presentation *p, const char *filename) serialize_s(&ser, "sc", sc); free(sc); + write_notes(s, &ser); + serialize_end(&ser); } @@ -425,6 +428,8 @@ static struct slide *tree_to_slide(struct presentation *p, struct ds_node *root) s = new_slide(); s->parent = p; + load_notes(root, s); + get_field_s(root, "sc", &sc); s->top = sc_unpack(sc, p->ss); free(sc); diff --git a/src/presentation.h b/src/presentation.h index b15f732..aed2ddf 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -125,6 +125,8 @@ struct presentation PangoContext *pc; ImageStore *is; + struct notes *notes; + /* Pointers to the current "editing" and "projection" slides */ struct slide *cur_edit_slide; struct slide *cur_proj_slide; |