From 34db1cd5f43ccd48cf672266413f608173eb838f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 14 Jun 2012 16:02:15 +0100 Subject: Simplify... --- src/colloquium.c | 17 +- src/loadsave.c | 855 ----------------------------------------- src/loadsave.h | 75 ---- src/mainwindow.c | 851 ----------------------------------------- src/mainwindow.h | 38 -- src/notes.c | 151 -------- src/notes.h | 41 -- src/objects.c | 289 -------------- src/objects.h | 103 ----- src/presentation.c | 371 ------------------ src/presentation.h | 135 +------ src/slideshow.c | 290 -------------- src/slideshow.h | 41 -- src/storycode.c | 241 ------------ src/storycode.h | 14 - src/stylesheet-editor.c | 328 ---------------- src/stylesheet-editor.h | 35 -- src/stylesheet.c | 580 ---------------------------- src/stylesheet.h | 19 - src/tool_image.c | 514 ------------------------- src/tool_image.h | 41 -- src/tool_select.c | 234 ------------ src/tool_select.h | 34 -- src/tool_text.c | 984 ------------------------------------------------ src/tool_text.h | 36 -- 25 files changed, 11 insertions(+), 6306 deletions(-) delete mode 100644 src/loadsave.c delete mode 100644 src/loadsave.h delete mode 100644 src/mainwindow.c delete mode 100644 src/mainwindow.h delete mode 100644 src/notes.c delete mode 100644 src/notes.h delete mode 100644 src/objects.c delete mode 100644 src/objects.h delete mode 100644 src/presentation.c delete mode 100644 src/slideshow.c delete mode 100644 src/slideshow.h delete mode 100644 src/stylesheet-editor.c delete mode 100644 src/stylesheet-editor.h delete mode 100644 src/stylesheet.c delete mode 100644 src/tool_image.c delete mode 100644 src/tool_image.h delete mode 100644 src/tool_select.c delete mode 100644 src/tool_select.h delete mode 100644 src/tool_text.c delete mode 100644 src/tool_text.h (limited to 'src') diff --git a/src/colloquium.c b/src/colloquium.c index b389e32..15836be 100644 --- a/src/colloquium.c +++ b/src/colloquium.c @@ -28,9 +28,6 @@ #include #include -#include "presentation.h" -#include "mainwindow.h" - static void show_help(const char *s) { @@ -74,13 +71,13 @@ int main(int argc, char *argv[]) } - p = new_presentation(); - p->cur_edit_slide = add_slide(p, 0); - p->completely_empty = 1; - if ( open_mainwindow(p) ) { - fprintf(stderr, "Couldn't open main window.\n"); - return 1; - } +// p = new_presentation(); +// p->cur_edit_slide = add_slide(p, 0); +// p->completely_empty = 1; +// if ( open_mainwindow(p) ) { +// fprintf(stderr, "Couldn't open main window.\n"); +// return 1; +// } gtk_main(); diff --git a/src/loadsave.c b/src/loadsave.c deleted file mode 100644 index 4388953..0000000 --- a/src/loadsave.c +++ /dev/null @@ -1,855 +0,0 @@ -/* - * loadsave.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "presentation.h" -#include "objects.h" -#include "stylesheet.h" -#include "mainwindow.h" -#include "notes.h" - - -static int alloc_children(struct ds_node *node) -{ - struct ds_node **new; - - new = realloc(node->children, - node->max_children*sizeof(*node->children)); - if ( new == NULL ) return 1; - - node->children = new; - return 0; -} - - -static struct ds_node *new_ds_node(const char *key) -{ - struct ds_node *new; - - new = malloc(sizeof(*new)); - if ( new == NULL ) return NULL; - - new->key = strdup(key); - if ( new->key == NULL ) { - free(new); - return NULL; - } - - new->value = NULL; - new->n_children = 0; - new->max_children = 32; - new->children = NULL; - - if ( alloc_children(new) ) { - free(new); - return NULL; - } - - return new; -} - - -static struct ds_node *add_child(struct ds_node *node, const char *key) -{ - struct ds_node *new; - - new = new_ds_node(key); - if ( new == NULL ) return NULL; - - if ( node->n_children >= new->max_children ) { - new->max_children += 32; - if ( alloc_children(node) ) { - free(new); - return NULL; - } - } - - node->children[node->n_children++] = new; - - return new; -} - - -void show_tree(struct ds_node *root, const char *path) -{ - char newpath[1024]; - int i; - - snprintf(newpath, 1023, "%s%s/", path, root->key); - - printf("%s\n", newpath); - for ( i=0; in_children; i++ ) { - printf(" %s => %s\n", root->children[i]->key, - root->children[i]->value); - } - - for ( i=0; in_children; i++ ) { - if ( root->children[i]->n_children > 0 ) { - printf("\n"); - show_tree(root->children[i], newpath); - } - } -} - - -struct ds_node *find_node(struct ds_node *root, const char *path, int cr) -{ - size_t start, len; - char element[1024]; - struct ds_node *cur = root; - - len = strlen(path); - - start = 0; - while ( start < len ) { - - size_t pos, i; - int child; - int found = 0; - - pos = 0; - for ( i=start; in_children; child++ ) { - - const char *this_key = cur->children[child]->key; - - if ( strcmp(this_key, element) == 0 ) { - cur = cur->children[child]; - found = 1; - break; - } - - } - - if ( !found ) { - - if ( cr ) { - cur = add_child(cur, element); - if ( cur == NULL ) { - return NULL; /* Error */ - } - } else { - return NULL; - } - - } - - } - -out: - return cur; -} - - -static void parse_line(struct ds_node *root, struct ds_node **cn, - const char *line) -{ - size_t i; - size_t len, s_start; - size_t s_equals = 0; - size_t s_val = 0; - size_t s_openbracket = 0; - size_t s_closebracket = 0; - int h_start = 0; - int h_equals = 0; - int h_val = 0; - int h_openbracket = 0; - int h_closebracket = 0; - struct ds_node *cur_node = *cn; - - len = strlen(line); - - s_start = len; - - for ( i=0; ivalue = strdup(value); - - free(key); - free(value); - - } else { - - size_t pos = 0; - char *path; - - path = malloc(len); - - for ( i=s_openbracket+1; in_children; i++ ) { - if ( root->children[i]->n_children > 0 ) { - free_ds_tree(root->children[i]); - } - } - - free(root->key); - free(root->value); /* Might free(NULL), but that's fine */ - free(root); -} - - -char *escape_text(const char *a) -{ - char *b; - size_t l1, l, i; - - l1 = strlen(a); - - b = malloc(2*l1 + 1); - l = 0; - - for ( i=0; ivalue, &check); - if ( check == node->value ) { - fprintf(stderr, "Invalid value for '%s'\n", key); - return 1; - } - - *val = v; - - return 0; -} - - -int get_field_i(struct ds_node *root, const char *key, int *val) -{ - struct ds_node *node; - int v; - char *check; - - node = find_node(root, key, 0); - if ( node == NULL ) { - fprintf(stderr, "Couldn't find field '%s'\n", key); - return 1; - } - - v = strtol(node->value, &check, 0); - if ( check == node->value ) { - fprintf(stderr, "Invalid value for '%s'\n", key); - return 1; - } - - *val = v; - - return 0; -} - - -int get_field_s(struct ds_node *root, const char *key, char **val) -{ - struct ds_node *node; - char *v; - size_t i, len, s1, s2; - int hq; - - node = find_node(root, key, 0); - if ( node == NULL ) { - *val = NULL; - return 1; - } - - len = strlen(node->value); - hq = 0; - for ( i=0; ivalue[i] == '"' ) { - s1 = i; - hq = 1; - break; - } - } - if ( !hq ) { - fprintf(stderr, "No quotes in '%s'\n", node->value); - return 1; - } - - for ( i=len-1; i>=0; i-- ) { - if ( node->value[i] == '"' ) { - s2 = i; - break; - } - } - - if ( s1 == s2 ) { - fprintf(stderr, "Mismatched quotes in '%s'\n", node->value); - return 1; - } - - v = malloc(s2-s1+1); - if ( v == NULL ) { - fprintf(stderr, "Failed to allocate space for '%s'\n", key); - return 1; - } - - strncpy(v, node->value+s1+1, s2-s1-1); - v[s2-s1-1] = '\0'; - - *val = unescape_text(v); - free(v); - - return 0; -} - - -static struct frame *tree_to_frame(struct ds_node *root) -{ - return NULL; -} - - -static struct slide *tree_to_slide(struct presentation *p, struct ds_node *root) -{ - struct slide *s; - int i; - - s = new_slide(); - s->parent = p; - - load_notes(root, s); - - /* Loop over objects */ - for ( i=0; in_children; i++ ) { - - struct frame *fr; - - fr = tree_to_frame(root->children[i]); - if ( fr != NULL ) { - add_frame_to_slide(s, fr); - } - - } - - return s; -} - - -static int tree_to_slides(struct ds_node *root, struct presentation *p) -{ - int i; - - for ( i=0; in_children; i++ ) { - - struct slide *s; - - s = tree_to_slide(p, root->children[i]); - if ( s != NULL ) { - insert_slide(p, s, p->num_slides-1); - } - - } - - return 0; -} - - -int tree_to_presentation(struct ds_node *root, struct presentation *p) -{ - struct ds_node *node; - char *check; - int i; - - p->cur_edit_slide = NULL; - p->cur_proj_slide = NULL; - - node = find_node(root, "slide-properties/width", 0); - if ( node == NULL ) return 1; - p->slide_width = strtod(node->value, &check); - if ( check == node->value ) { - fprintf(stderr, "Invalid slide width\n"); - return 1; - } - - node = find_node(root, "slide-properties/height", 0); - if ( node == NULL ) return 1; - p->slide_height = strtod(node->value, &check); - if ( check == node->value ) { - fprintf(stderr, "Invalid slide height\n"); - return 1; - } - - node = find_node(root, "stylesheet", 0); - if ( node != NULL ) { - free_stylesheet(p->ss); - p->ss = tree_to_stylesheet(node); - if ( p->ss == NULL ) { - fprintf(stderr, "Invalid style sheet\n"); - return 1; - } - } - - for ( i=0; inum_slides; i++ ) { - free_slide(p->slides[i]); - p->num_slides = 0; - } - - node = find_node(root, "slides", 0); - if ( node != NULL ) { - tree_to_slides(node, p); - if ( p->num_slides == 0 ) { - fprintf(stderr, "Failed to load any slides\n"); - p->cur_edit_slide = add_slide(p, 0); - return 1; - } - } - - p->cur_edit_slide = p->slides[0]; -// redraw_slide(p->cur_edit_slide); - - return 0; -} - - -int load_presentation(struct presentation *p, const char *filename) -{ - FILE *fh; - struct ds_node *root; - int r; - - assert(p->completely_empty); - - fh = fopen(filename, "r"); - if ( fh == NULL ) return 1; - - root = new_ds_node("root"); - if ( root == NULL ) return 1; - - if ( deserialize_file(fh, root) ) { - fclose(fh); - return 1; - } - - r = tree_to_presentation(root, p); - free_ds_tree(root); - - fclose(fh); - - if ( r ) { - p->cur_edit_slide = new_slide(); - insert_slide(p, p->cur_edit_slide, 0); - p->completely_empty = 1; - return r; /* Error */ - } - - assert(p->filename == NULL); - p->filename = strdup(filename); - update_titlebar(p); - - p->cur_edit_slide = p->slides[0]; - - return 0; -} - - -static void rebuild_prefix(struct serializer *ser) -{ - int i; - size_t sz = 1; /* Space for terminator */ - - for ( i=0; istack_depth; i++ ) { - sz += strlen(ser->stack[i]) + 1; - } - - free(ser->prefix); - ser->prefix = malloc(sz); - if ( ser->prefix == NULL ) return; /* Probably bad! */ - - ser->prefix[0] = '\0'; - for ( i=0; istack_depth; i++ ) { - if ( i != 0 ) strcat(ser->prefix, "/"); - strcat(ser->prefix, ser->stack[i]); - } -} - - -void serialize_start(struct serializer *ser, const char *id) -{ - ser->stack[ser->stack_depth++] = strdup(id); - rebuild_prefix(ser); - ser->empty_set = 1; -} - - -static void check_prefix_output(struct serializer *ser) -{ - if ( ser->empty_set ) { - ser->empty_set = 0; - if ( ser->prefix != NULL ) { - fprintf(ser->fh, "\n"); - fprintf(ser->fh, "[%s]\n", ser->prefix); - } - } -} - - -void serialize_s(struct serializer *ser, const char *key, const char *val) -{ - char *n; - - n = escape_text(val); - if ( n == NULL ) { - fprintf(stderr, "Failed to escape '%s'\n", val); - return; - } - - check_prefix_output(ser); - fprintf(ser->fh, "%s = \"%s\"\n", key, n); - - free(n); -} - - -void serialize_f(struct serializer *ser, const char *key, double val) -{ - check_prefix_output(ser); - fprintf(ser->fh, "%s = %.2f\n", key, val); -} - - -void serialize_b(struct serializer *ser, const char *key, int val) -{ - check_prefix_output(ser); - fprintf(ser->fh, "%s = %i\n", key, val); -} - - -void serialize_end(struct serializer *ser) -{ - free(ser->stack[--ser->stack_depth]); - rebuild_prefix(ser); - ser->empty_set = 1; -} - - -int save_presentation(struct presentation *p, const char *filename) -{ - FILE *fh; - int i; - struct serializer ser; - char *old_fn; - - grab_current_notes(p); - - fh = fopen(filename, "w"); - if ( fh == NULL ) return 1; - - /* Set up the serializer */ - ser.fh = fh; - ser.stack_depth = 0; - ser.prefix = NULL; - - fprintf(fh, "# Colloquium presentation file\n"); - serialize_f(&ser, "version", 0.1); - - serialize_start(&ser, "slide-properties"); - serialize_f(&ser, "width", p->slide_width); - serialize_f(&ser, "height", p->slide_height); - serialize_end(&ser); - - serialize_start(&ser, "stylesheet"); - write_stylesheet(p->ss, &ser); - serialize_end(&ser); - - serialize_start(&ser, "slides"); - for ( i=0; inum_slides; i++ ) { - - int j; - struct slide *s; - char s_id[32]; - - s = p->slides[i]; - - snprintf(s_id, 31, "%i", i); - serialize_start(&ser, s_id); - for ( j=0; jnum_frames; j++ ) { - - struct frame *fr = s->frames[j]; - char fr_id[32]; - - if ( fr->empty ) continue; - snprintf(fr_id, 31, "%i", j); - - serialize_start(&ser, fr_id); - fr->serialize(fr, &ser); - serialize_end(&ser); - - } - - write_notes(s, &ser); - - serialize_end(&ser); - - } - serialize_end(&ser); - - /* Slightly fiddly because someone might - * do save_presentation(p, p->filename) */ - old_fn = p->filename; - p->filename = strdup(filename); - if ( old_fn != NULL ) free(old_fn); - update_titlebar(p); - - fclose(fh); - return 0; -} diff --git a/src/loadsave.h b/src/loadsave.h deleted file mode 100644 index 14fb6ff..0000000 --- a/src/loadsave.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * loadsave.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef LOADSAVE_H -#define LOADSAVE_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -/* Forward declaration */ -struct presentation; - -struct ds_node -{ - char *key; - char *value; - struct ds_node **children; - int n_children; - int max_children; -}; - -/* Would be opaque if I could be bothered to write the constructor */ -struct serializer -{ - FILE *fh; - - char *stack[32]; - int stack_depth; - char *prefix; - int empty_set; - int blank_written; -}; - -extern void show_tree(struct ds_node *root, const char *path); - -extern char *escape_text(const char *a); -extern char *unescape_text(const char *a); - -extern void serialize_start(struct serializer *s, const char *id); -extern void serialize_s(struct serializer *s, const char *key, const char *val); -extern void serialize_f(struct serializer *s, const char *key, double val); -extern void serialize_b(struct serializer *s, const char *key, int val); -extern void serialize_end(struct serializer *s); - -extern int get_field_f(struct ds_node *root, const char *key, double *val); -extern int get_field_i(struct ds_node *root, const char *key, int *val); -extern int get_field_s(struct ds_node *root, const char *key, char **val); - -extern struct ds_node *find_node(struct ds_node *root, const char *path, - int cr); - -extern int load_presentation(struct presentation *p, const char *filename); -extern int save_presentation(struct presentation *p, const char *filename); - -#endif /* LOADSAVE_H */ diff --git a/src/mainwindow.c b/src/mainwindow.c deleted file mode 100644 index 67d3374..0000000 --- a/src/mainwindow.c +++ /dev/null @@ -1,851 +0,0 @@ -/* - * mainwindow.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include - -#include "presentation.h" -#include "mainwindow.h" -#include "storycode.h" -#include "objects.h" -#include "slideshow.h" -#include "stylesheet.h" -#include "loadsave.h" -#include "tool_select.h" -#include "tool_text.h" -#include "tool_image.h" -#include "notes.h" - - -static void add_ui_sig(GtkUIManager *ui, GtkWidget *widget, - GtkContainer *container) -{ - gtk_box_pack_start(GTK_BOX(container), widget, FALSE, FALSE, 0); - if ( GTK_IS_TOOLBAR(widget) ) { - gtk_toolbar_set_show_arrow(GTK_TOOLBAR(widget), TRUE); - } -} - - -static gint quit_sig(GtkWidget *widget, struct presentation *p) -{ - return 0; -} - - -static void show_error(struct presentation *p, const char *message) -{ - GtkWidget *window; - - window = gtk_message_dialog_new(GTK_WINDOW(p->window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, message); - gtk_window_set_title(GTK_WINDOW(window), "Error"); - - g_signal_connect_swapped(window, "response", - G_CALLBACK(gtk_widget_destroy), window); - gtk_widget_show(window); -} - - -static void update_toolbar(struct presentation *p) -{ - GtkWidget *d; - int cur_slide_number; - - d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/first"); - gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE); - d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/prev"); - gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE); - d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/next"); - gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE); - d = gtk_ui_manager_get_widget(p->ui, "/ui/displaywindowtoolbar/last"); - gtk_widget_set_sensitive(GTK_WIDGET(d), TRUE); - - cur_slide_number = slide_number(p, p->cur_edit_slide); - if ( cur_slide_number == 0 ) { - - d = gtk_ui_manager_get_widget(p->ui, - "/ui/displaywindowtoolbar/first"); - gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE); - d = gtk_ui_manager_get_widget(p->ui, - "/ui/displaywindowtoolbar/prev"); - gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE); - - } - - if ( cur_slide_number == p->num_slides-1 ) { - - d = gtk_ui_manager_get_widget(p->ui, - "/ui/displaywindowtoolbar/next"); - gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE); - d = gtk_ui_manager_get_widget(p->ui, - "/ui/displaywindowtoolbar/last"); - gtk_widget_set_sensitive(GTK_WIDGET(d), FALSE); - - } - - -} - - -static gint open_response_sig(GtkWidget *d, gint response, - struct presentation *p) -{ - if ( response == GTK_RESPONSE_ACCEPT ) { - - char *filename; - - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); - - if ( p->completely_empty ) { - - if ( load_presentation(p, filename) ) { - show_error(p, "Failed to open presentation"); - } - redraw_slide(p->cur_edit_slide); - update_toolbar(p); - - } else { - - struct presentation *p; - - p = new_presentation(); - if ( load_presentation(p, filename) ) { - show_error(p, "Failed to open presentation"); - } else { - open_mainwindow(p); - } - - } - - g_free(filename); - - } - - gtk_widget_destroy(d); - - return 0; -} - - -static gint open_sig(GtkWidget *widget, struct presentation *p) -{ - GtkWidget *d; - - d = gtk_file_chooser_dialog_new("Open Presentation", - GTK_WINDOW(p->window), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - g_signal_connect(G_OBJECT(d), "response", - G_CALLBACK(open_response_sig), p); - - gtk_widget_show_all(d); - - return 0; -} - - -static gint new_sig(GtkWidget *widget, struct presentation *pnn) -{ - struct presentation *p; - - p = new_presentation(); - if ( p != NULL ) { - p->cur_edit_slide = add_slide(p, 0); - p->completely_empty = 1; - open_mainwindow(p); - } - - return 0; -} - - -static gint saveas_response_sig(GtkWidget *d, gint response, - struct presentation *p) -{ - if ( response == GTK_RESPONSE_ACCEPT ) { - - char *filename; - - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); - - if ( save_presentation(p, filename) ) { - show_error(p, "Failed to save presentation"); - } - - g_free(filename); - - } - - gtk_widget_destroy(d); - - return 0; -} - - -static gint saveas_sig(GtkWidget *widget, struct presentation *p) -{ - GtkWidget *d; - - d = gtk_file_chooser_dialog_new("Save Presentation", - GTK_WINDOW(p->window), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d), - TRUE); - - g_signal_connect(G_OBJECT(d), "response", - G_CALLBACK(saveas_response_sig), p); - - gtk_widget_show_all(d); - - return 0; -} - - -static gint save_sig(GtkWidget *widget, struct presentation *p) -{ - if ( p->filename == NULL ) { - return saveas_sig(widget, p); - } - - save_presentation(p, p->filename); - - return 0; -} - - -static gint save_ss_response_sig(GtkWidget *d, gint response, - struct presentation *p) -{ - if ( response == GTK_RESPONSE_ACCEPT ) { - - char *filename; - - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); - - if ( save_stylesheet(p->ss, filename) ) { - show_error(p, "Failed to save style sheet"); - } - - g_free(filename); - - } - - gtk_widget_destroy(d); - - return 0; -} - - -static gint save_ss_sig(GtkWidget *widget, struct presentation *p) -{ - GtkWidget *d; - - d = gtk_file_chooser_dialog_new("Save Style sheet", - GTK_WINDOW(p->window), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d), - TRUE); - - g_signal_connect(G_OBJECT(d), "response", - G_CALLBACK(save_ss_response_sig), p); - - gtk_widget_show_all(d); - - return 0; -} - - -static gint export_pdf_response_sig(GtkWidget *d, gint response, - struct presentation *p) -{ - if ( response == GTK_RESPONSE_ACCEPT ) { - - char *filename; - - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); - - if ( export_pdf(p, filename) ) { - show_error(p, "Failed to export as PDF"); - } - - g_free(filename); - - } - - gtk_widget_destroy(d); - - return 0; -} - - -static gint export_pdf_sig(GtkWidget *widget, struct presentation *p) -{ - GtkWidget *d; - - d = gtk_file_chooser_dialog_new("Export PDF", - GTK_WINDOW(p->window), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d), - TRUE); - - g_signal_connect(G_OBJECT(d), "response", - G_CALLBACK(export_pdf_response_sig), p); - - gtk_widget_show_all(d); - - return 0; -} - - -static gint about_sig(GtkWidget *widget, struct presentation *p) -{ - GtkWidget *window; - - const gchar *authors[] = { - "Thomas White ", - NULL - }; - - window = gtk_about_dialog_new(); - gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(p->window)); - - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(window), "Colloquium"); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window), PACKAGE_VERSION); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window), - "(c) 2011 Thomas White "); - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window), - "A tiny presentation program"); - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(window), - "(c) 2011 Thomas White \n"); - gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(window), - "http://www.bitwiz.org.uk/"); - gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(window), authors); - - g_signal_connect(window, "response", G_CALLBACK(gtk_widget_destroy), - NULL); - - gtk_widget_show_all(window); - - return 0; -} - - -static gint start_slideshow_sig(GtkWidget *widget, struct presentation *p) -{ - try_start_slideshow(p); - return FALSE; -} - - -void notify_slide_changed(struct presentation *p, struct slide *np) -{ - if ( p->cur_edit_slide->rendered_edit != NULL ) { - cairo_surface_destroy(p->cur_edit_slide->rendered_edit); - p->cur_edit_slide->rendered_edit = NULL; - } - p->cur_edit_slide = np; - - p->cur_frame = NULL; - - redraw_slide(p->cur_edit_slide); - - if ( p->notes != NULL ) { - notify_notes_slide_changed(p, np); - } - - if ( (p->slideshow != NULL) && p->slideshow_linked ) { - notify_slideshow_slide_changed(p, np); - } -} - - -static gint add_slide_sig(GtkWidget *widget, struct presentation *p) -{ - struct slide *new; - int cur_slide_number; - - cur_slide_number = slide_number(p, p->cur_edit_slide); - - new = add_slide(p, cur_slide_number); - notify_slide_changed(p, new); - - return FALSE; -} - - -static gint first_slide_sig(GtkWidget *widget, struct presentation *p) -{ - notify_slide_changed(p, p->slides[0]); - update_toolbar(p); - return FALSE; -} - - -static gint prev_slide_sig(GtkWidget *widget, struct presentation *p) -{ - int cur_slide_number; - - cur_slide_number = slide_number(p, p->cur_edit_slide); - if ( cur_slide_number == 0 ) return FALSE; - - notify_slide_changed(p, p->slides[cur_slide_number-1]); - update_toolbar(p); - - return FALSE; -} - - -static gint next_slide_sig(GtkWidget *widget, struct presentation *p) -{ - int cur_slide_number; - - cur_slide_number = slide_number(p, p->cur_edit_slide); - if ( cur_slide_number == p->num_slides-1 ) return FALSE; - - notify_slide_changed(p, p->slides[cur_slide_number+1]); - update_toolbar(p); - - return FALSE; -} - - -static gint last_slide_sig(GtkWidget *widget, struct presentation *p) -{ - notify_slide_changed(p, p->slides[p->num_slides-1]); - update_toolbar(p); - - return FALSE; -} - - -static gint open_stylesheet_sig(GtkWidget *widget, struct presentation *p) -{ - if ( p->stylesheetwindow == NULL ) { - p->stylesheetwindow = open_stylesheet(p); - } /* else already open */ - - return FALSE; -} - - -static gint open_notes_sig(GtkWidget *widget, struct presentation *p) -{ - open_notes(p); - return FALSE; -} - - -static void add_menu_bar(struct presentation *p, GtkWidget *vbox) -{ - GError *error = NULL; - GtkWidget *toolbar; - GtkWidget *menu; - GtkWidget *item; -// int i; - GtkActionEntry entries[] = { - - { "FileAction", NULL, "_File", NULL, NULL, NULL }, - { "NewAction", GTK_STOCK_NEW, "_New", - NULL, NULL, G_CALLBACK(new_sig) }, - { "OpenAction", GTK_STOCK_OPEN, "_Open...", - NULL, NULL, G_CALLBACK(open_sig) }, - { "SaveAction", GTK_STOCK_SAVE, "_Save", - NULL, NULL, G_CALLBACK(save_sig) }, - { "SaveAsAction", GTK_STOCK_SAVE_AS, "Save _As...", - NULL, NULL, G_CALLBACK(saveas_sig) }, - { "SaveStyleAction", GTK_STOCK_SAVE_AS, "Save St_ylesheet", - NULL, NULL, G_CALLBACK(save_ss_sig) }, - { "ExportPDFAction", GTK_STOCK_SAVE_AS, "Export PDF", - NULL, NULL, G_CALLBACK(export_pdf_sig) }, - { "QuitAction", GTK_STOCK_QUIT, "_Quit", - NULL, NULL, G_CALLBACK(quit_sig) }, - - { "EditAction", NULL, "_Edit", NULL, NULL, NULL }, - { "UndoAction", GTK_STOCK_UNDO, "_Undo", - NULL, NULL, NULL }, - { "RedoAction", GTK_STOCK_REDO, "_Redo", - NULL, NULL, NULL }, - { "CutAction", GTK_STOCK_CUT, "Cut", - NULL, NULL, NULL }, - { "CopyAction", GTK_STOCK_COPY, "Copy", - NULL, NULL, NULL }, - { "PasteAction", GTK_STOCK_PASTE, "Paste", - NULL, NULL, NULL }, - { "DeleteAction", GTK_STOCK_DELETE, "Delete", - NULL, NULL, NULL }, - { "EditStyleAction", NULL, "Stylesheet...", - NULL, NULL, G_CALLBACK(open_stylesheet_sig) }, - - { "InsertAction", NULL, "_Insert", NULL, NULL, NULL }, - { "NewSlideAction", GTK_STOCK_ADD, "_New Slide", - NULL, NULL, G_CALLBACK(add_slide_sig) }, - - { "ToolsAction", NULL, "_Tools", NULL, NULL, NULL }, - { "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) }, - { "PrefsAction", GTK_STOCK_PREFERENCES, "_Preferences", - NULL, NULL, NULL }, - - { "HelpAction", NULL, "_Help", NULL, NULL, NULL }, - { "AboutAction", GTK_STOCK_ABOUT, "_About...", - NULL, NULL, G_CALLBACK(about_sig) }, - - { "SlideshowAction", GTK_STOCK_FULLSCREEN, "Start Presentation", - NULL, NULL, G_CALLBACK(start_slideshow_sig) }, - { "AddSlideAction", GTK_STOCK_ADD, "Add Slide", - NULL, NULL, G_CALLBACK(add_slide_sig) }, - { "ButtonFirstSlideAction", GTK_STOCK_GOTO_FIRST, "First Slide", - NULL, NULL, G_CALLBACK(first_slide_sig) }, - { "ButtonPrevSlideAction", GTK_STOCK_GO_BACK, "Previous Slide", - NULL, NULL, G_CALLBACK(prev_slide_sig) }, - { "ButtonNextSlideAction", GTK_STOCK_GO_FORWARD, "Next Slide", - NULL, NULL, G_CALLBACK(next_slide_sig) }, - { "ButtonLastSlideAction", GTK_STOCK_GOTO_LAST, "Last Slide", - NULL, NULL, G_CALLBACK(last_slide_sig) }, - - }; - guint n_entries = G_N_ELEMENTS(entries); - - p->action_group = gtk_action_group_new("mainwindow"); - gtk_action_group_add_actions(p->action_group, entries, n_entries, p); - - p->ui = gtk_ui_manager_new(); - gtk_ui_manager_insert_action_group(p->ui, p->action_group, 0); - g_signal_connect(p->ui, "add_widget", G_CALLBACK(add_ui_sig), vbox); - if ( gtk_ui_manager_add_ui_from_file(p->ui, - DATADIR"/colloquium/colloquium.ui", &error) == 0 ) { - fprintf(stderr, "Error loading main window menu bar: %s\n", - error->message); - return; - } - - gtk_window_add_accel_group(GTK_WINDOW(p->window), - gtk_ui_manager_get_accel_group(p->ui)); - gtk_ui_manager_ensure_update(p->ui); - - toolbar = gtk_ui_manager_get_widget(p->ui, "/displaywindowtoolbar"); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), - gtk_separator_tool_item_new(), -1); - - /* Add the styles to the "Insert" menu */ - menu = gtk_ui_manager_get_widget(p->ui, "/displaywindow/insert"); - menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu)); - item = gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); -// for ( i=1; iss->n_frame_classes; i++ ) -// { -// char *name; -// name = p->ss->frame_classes[i]->name; -// item = gtk_menu_item_new_with_label(name); -// gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); -// g_signal_connect(G_OBJECT(item), "activate", -// G_CALLBACK(add_furniture), p); -// -// } - update_toolbar(p); -} - - -static gint close_sig(GtkWidget *window, struct presentation *p) -{ - free_presentation(p); - return 0; -} - - -static void redraw_frame(struct frame *o) -{ - if ( o == NULL ) return; -// gdk_window_invalidate_rect(o->parent->parent->drawingarea->window, -// NULL, FALSE); -} - - -void redraw_overlay(struct presentation *p) -{ - gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE); -} - - -static gboolean im_commit_sig(GtkIMContext *im, gchar *str, - struct presentation *p) -{ - if ( p->cur_frame == NULL ) { - if ( str[0] == 'b' ) { - check_toggle_blank(p); - } else { - printf("IM keypress: %s\n", str); - } - return FALSE; - } - - return FALSE; -} - - -static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, - struct presentation *p) -{ - gboolean r; - - /* Throw the event to the IM context and let it sort things out */ - r = gtk_im_context_filter_keypress(GTK_IM_CONTEXT(p->im_context), - event); - if ( r ) return FALSE; /* IM ate it */ - -// p->cur_tool->key_pressed(p->editing_object, event->keyval, p->cur_tool); - - switch ( event->keyval ) { - - case GDK_KEY_Page_Up : - prev_slide_sig(NULL, p); - break; - - case GDK_KEY_Page_Down : - next_slide_sig(NULL, p); - break; - - case GDK_KEY_Escape : - if ( p->slideshow != NULL ) end_slideshow(p); - redraw_frame(p->cur_frame); - p->cur_frame = NULL; - break; - - case GDK_KEY_Return : - //p->cur_tool->im_commit(p->cur_frame, "\n", p->cur_tool); - break; - - case GDK_KEY_B : - case GDK_KEY_b : - if ( p->slideshow != NULL ) { - if ( p->prefs->b_splits ) { - toggle_slideshow_link(p); - } else { - p->ss_blank = 1-p->ss_blank; - gdk_window_invalidate_rect( - p->ss_drawingarea->window, - NULL, FALSE); - } - } - break; - - } - - return FALSE; -} - - -static void draw_overlay(cairo_t *cr, struct presentation *p) -{ - struct frame *fr = p->cur_frame; - - if ( fr != NULL ) { - /* Draw margins */ - cairo_move_to(cr, fr->cl->margin_left, -p->border_offs_y); - cairo_line_to(cr, fr->cl->margin_left, - p->slide_height+p->border_offs_y); - - cairo_move_to(cr, p->slide_width-fr->cl->margin_right, - -p->border_offs_y); - cairo_line_to(cr, p->slide_width-fr->cl->margin_right, - p->slide_height+p->border_offs_y); - - cairo_move_to(cr, -p->border_offs_x, fr->cl->margin_top); - cairo_line_to(cr, p->slide_width+p->border_offs_x, - fr->cl->margin_top); - - cairo_move_to(cr, -p->border_offs_x, - p->slide_height-fr->cl->margin_bottom); - cairo_line_to(cr, p->slide_width+p->border_offs_x, - p->slide_height-fr->cl->margin_bottom); - - cairo_set_source_rgb(cr, 0.2, 0.2, 0.2); - cairo_set_line_width(cr, 1.0); - cairo_stroke(cr); - } -} - - -static gboolean expose_sig(GtkWidget *da, GdkEventExpose *event, - struct presentation *p) -{ - cairo_t *cr; - GtkAllocation allocation; - double xoff, yoff; - - cr = gdk_cairo_create(da->window); - - /* Overall background */ - cairo_rectangle(cr, event->area.x, event->area.y, - event->area.width, event->area.height); - if ( (p->slideshow != NULL) && !p->slideshow_linked ) { - cairo_set_source_rgb(cr, 1.0, 0.3, 0.2); - } else { - cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); - } - cairo_fill(cr); - - /* Get the overall size */ - gtk_widget_get_allocation(da, &allocation); - xoff = (allocation.width - p->slide_width)/2.0; - yoff = (allocation.height - p->slide_height)/2.0; - p->border_offs_x = xoff; p->border_offs_y = yoff; - - /* Draw the slide from the cache */ - cairo_rectangle(cr, event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_set_source_surface(cr, p->cur_edit_slide->rendered_edit, - xoff, yoff); - cairo_fill(cr); - - cairo_translate(cr, xoff, yoff); - - draw_overlay(cr, p); - - cairo_destroy(cr); - - return FALSE; -} - - -void update_titlebar(struct presentation *p) -{ - get_titlebar_string(p); - - if ( p->window != NULL ) { - - char *title; - - title = malloc(strlen(p->titlebar)+14); - sprintf(title, "%s - Colloquium", p->titlebar); - gtk_window_set_title(GTK_WINDOW(p->window), title); - free(title); - - } -} - - -int open_mainwindow(struct presentation *p) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *sw; -// GtkTargetEntry targets[1]; - - if ( p->window != NULL ) { - fprintf(stderr, "Presentation window is already open!\n"); - return 1; - } - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - p->window = window; - - update_titlebar(p); - - g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(close_sig), p); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(window), vbox); - - p->drawingarea = gtk_drawing_area_new(); - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), - p->drawingarea); - gtk_widget_set_size_request(GTK_WIDGET(p->drawingarea), - p->slide_width + 20, - p->slide_height + 20); - - realise_everything(p); - add_menu_bar(p, vbox); - gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); - - gtk_widget_set_can_focus(GTK_WIDGET(p->drawingarea), TRUE); - gtk_widget_add_events(GTK_WIDGET(p->drawingarea), - GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON1_MOTION_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); - -// g_signal_connect(G_OBJECT(p->drawingarea), "button-press-event", -// G_CALLBACK(button_press_sig), p); -// g_signal_connect(G_OBJECT(p->drawingarea), "button-release-event", -// G_CALLBACK(button_release_sig), p); - g_signal_connect(G_OBJECT(p->drawingarea), "key-press-event", - G_CALLBACK(key_press_sig), p); - g_signal_connect(G_OBJECT(p->drawingarea), "expose-event", - G_CALLBACK(expose_sig), p); -// g_signal_connect(G_OBJECT(p->drawingarea), "motion-notify-event", -// G_CALLBACK(motion_sig), p); - - /* Input method */ - p->im_context = gtk_im_multicontext_new(); - gtk_im_context_set_client_window(GTK_IM_CONTEXT(p->im_context), - p->drawingarea->window); - g_signal_connect(G_OBJECT(p->im_context), "commit", - G_CALLBACK(im_commit_sig), p); - - /* Default size */ - gtk_window_set_default_size(GTK_WINDOW(p->window), 1024+100, 768+100); - gtk_window_set_resizable(GTK_WINDOW(p->window), TRUE); - - assert(p->num_slides > 0); - - gtk_widget_grab_focus(GTK_WIDGET(p->drawingarea)); - - gtk_widget_show_all(window); - - p->edit_slide_width = 1024; - p->proj_slide_width = 2048; - p->thumb_slide_width = 320; /* FIXME: Completely made up */ - redraw_slide(p->cur_edit_slide); - - return 0; -} diff --git a/src/mainwindow.h b/src/mainwindow.h deleted file mode 100644 index 3bfff44..0000000 --- a/src/mainwindow.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * presentation.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -extern int open_mainwindow(struct presentation *p); -extern void notify_slide_changed(struct presentation *p, struct slide *np); -extern void update_titlebar(struct presentation *p); - -extern void redraw_overlay(struct presentation *p); - - -#endif /* MAINWINDOW_H */ diff --git a/src/notes.c b/src/notes.c deleted file mode 100644 index 270f753..0000000 --- a/src/notes.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * notes.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#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 deleted file mode 100644 index 82d1355..0000000 --- a/src/notes.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * notes.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef NOTES_H -#define NOTES_H - -#ifdef HAVE_CONFIG_H -#include -#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/objects.c b/src/objects.c deleted file mode 100644 index d2383c3..0000000 --- a/src/objects.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * objects.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "presentation.h" -#include "objects.h" -#include "mainwindow.h" - - -struct image_store -{ - int n_images; - struct image **images; -}; - - -static struct image *add_image_to_store(struct image_store *is, char *filename) -{ - struct image **images_new; - struct image *i_new; - int idx; - GError *error = NULL; - int w, h; - - i_new = calloc(1, sizeof(struct image)); - if ( i_new == NULL ) return NULL; - - images_new = realloc(is->images, - (is->n_images+1)*sizeof(struct image *)); - if ( images_new == NULL ) { - fprintf(stderr, "Couldn't allocate memory for image.\n"); - return NULL; - } - is->images = images_new; - idx = is->n_images++; - - gdk_pixbuf_get_file_info(filename, &w, &h); - - /* FIXME: If image is huge, load a smaller version */ - i_new->pb = gdk_pixbuf_new_from_file(filename, &error); - if ( i_new->pb == NULL ) { - fprintf(stderr, "Failed to load image '%s'\n", filename); - is->n_images--; - return NULL; - } - i_new->filename = strdup(filename); - i_new->refcount = 1; - i_new->width = w; - i_new->height = h; - i_new->parent = is; - - is->images[idx] = i_new; - - return i_new; -} - - -static struct image *find_filename(struct image_store *is, const char *filename) -{ - int i; - - for ( i=0; in_images; i++ ) { - if ( strcmp(is->images[i]->filename, filename) == 0 ) { - return is->images[i]; - } - } - - return NULL; -} - - -struct image *get_image(struct image_store *is, char *filename) -{ - struct image *image; - - image = find_filename(is, filename); - if ( image == NULL ) { - image = add_image_to_store(is, filename); - } else { - image->refcount++; - } - - return image; -} - - -void unref_image(struct image *i) -{ - i->refcount--; - - if ( i->refcount == 0 ) { - - struct image_store *is; - int j; - - g_object_unref(G_OBJECT(i->pb)); - free(i->filename); - is = i->parent; - free(i); - - for ( j=0; jn_images; j++ ) { - if ( is->images[j] == i ) { - int k; - for ( k=j+1; kn_images; k++ ) { - is->images[k-1] = is->images[k]; - } - break; - } - } - is->n_images--; - - } -} - - -struct image_store *image_store_new() -{ - struct image_store *is; - - is = calloc(1, sizeof(*is)); - if ( is == NULL ) return NULL; - - is->images = NULL; - is->n_images = 0; - - return is; -} - - -void notify_style_update(struct presentation *p, struct style *sty) -{ - int i; - int changed = 0; - - for ( i=0; inum_slides; i++ ) { - - int j; - struct slide *s; - - s = p->slides[i]; - - for ( j=0; jslides[i]->num_objects; j++ ) { - - if ( s->objects[j]->style != sty ) continue; - - s->objects[j]->update_object(s->objects[j]); - if ( p->cur_edit_slide == s ) changed = 1; - - } - - } - - /* Trigger redraw etc */ - p->completely_empty = 0; - if ( changed ) notify_slide_changed(p, p->cur_edit_slide); -} - - -static void check_references(struct slide *s, struct object *om) -{ - /* FIXME: Should replace with previous useful one, not NULL */ - if ( s->roles[S_ROLE_PDATE_REF] == om ) { - struct object *o; - s->roles[S_ROLE_PDATE_REF] = NULL; - o = s->roles[S_ROLE_PDATE]; - if ( o != NULL ) o->update_object(o); - } - - if ( s->roles[S_ROLE_PAUTHOR_REF] == om ) { - struct object *o; - s->roles[S_ROLE_PAUTHOR_REF] = NULL; - o = s->roles[S_ROLE_PAUTHOR]; - if ( o != NULL ) o->update_object(o); - } - - if ( s->roles[S_ROLE_PTITLE_REF] == om ) { - struct object *o; - s->roles[S_ROLE_PTITLE_REF] = NULL; - o = s->roles[S_ROLE_PTITLE]; - if ( o != NULL ) o->update_object(o); - } - -} - - -void delete_object(struct object *o) -{ - int i; - - if ( o->parent != NULL ) remove_object_from_slide(o->parent, o); - o->delete_object(o); - - /* If this object was any kind of special (for this slide), - * check all the other slides for references */ - if ( (o->parent->roles[S_ROLE_PTITLE_REF] == o) - || (o->parent->roles[S_ROLE_PAUTHOR_REF] == o) - || (o->parent->roles[S_ROLE_PDATE_REF] == o) ) - { - for ( i=0; iparent->parent->num_slides; i++ ) { - check_references(o->parent->parent->slides[i], o); - } - } - - for ( i=0; iparent->roles[i] == o ) { - o->parent->roles[i] = NULL; - } - } - - free(o); -} - - -void realise_everything(struct presentation *p) -{ - int i; - - /* Realise all the tools */ - p->select_tool->realise(p->select_tool, p->drawingarea, p); - p->text_tool->realise(p->text_tool, p->drawingarea, p); - p->image_tool->realise(p->image_tool, p->drawingarea, p); - - for ( i=0; inum_slides; i++ ) { - - int j; - struct slide *s; - - s = p->slides[i]; - - for ( j=0; jslides[i]->num_objects; j++ ) { - s->objects[j]->update_object(s->objects[j]); - } - - } -} - - -enum corner which_corner(double xp, double yp, struct object *o) -{ - double x, y; /* Relative to object position */ - - x = xp - o->x; - y = yp - o->y; - - if ( x < 0.0 ) return CORNER_NONE; - if ( y < 0.0 ) return CORNER_NONE; - if ( x > o->bb_width ) return CORNER_NONE; - if ( y > o->bb_height ) return CORNER_NONE; - - /* Top left? */ - if ( (x<20.0) && (y<20.0) ) return CORNER_TL; - if ( (x>o->bb_width-20.0) && (y<20.0) ) return CORNER_TR; - if ( (x<20.0) && (y>o->bb_height-20.0) ) { - return CORNER_BL; - } - if ( (x>o->bb_width-20.0) && (y>o->bb_height-20.0) ) { - return CORNER_BR; - } - - return CORNER_NONE; -} diff --git a/src/objects.h b/src/objects.h deleted file mode 100644 index dba19da..0000000 --- a/src/objects.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * objects.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef OBJECTS_H -#define OBJECTS_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -#include "loadsave.h" - - -enum objtype -{ - OBJ_UNKNOWN, - OBJ_TEXT, - OBJ_IMAGE, -}; - - -struct object -{ - enum objtype type; - struct slide *parent; - struct style *style; - - /* Position of corner of object */ - double x; - double y; - - /* Side of rectangular bounding box of object */ - double bb_width; - double bb_height; - - int empty; - - void (*render_object)(cairo_t *cr, struct object *o); - void (*update_object)(struct object *o); - void (*delete_object)(struct object *o); - void (*serialize)(struct object *o, struct serializer *ser); -}; - - -struct image_store; - -struct image -{ - char *filename; - GdkPixbuf *pb; - int width; - int height; - - int refcount; - - struct image_store *parent; -}; - - -enum corner -{ - CORNER_NONE, - CORNER_TL, - CORNER_TR, - CORNER_BL, - CORNER_BR -}; - - -extern struct image *get_image(struct image_store *is, char *filename); -extern struct image_store *image_store_new(void); -extern void unref_image(struct image *i); - -extern void notify_style_update(struct presentation *p, - struct style *sty); - -extern void delete_object(struct object *o); - -extern void realise_everything(struct presentation *p); - -extern enum corner which_corner(double xp, double yp, struct object *o); - -#endif /* OBJECTS_H */ diff --git a/src/presentation.c b/src/presentation.c deleted file mode 100644 index 36e2abe..0000000 --- a/src/presentation.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * presentation.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "presentation.h" -#include "objects.h" -#include "stylesheet.h" -#include "tool_select.h" -#include "tool_text.h" -#include "tool_image.h" - - -static int num_presentations = 0; - - -void free_presentation(struct presentation *p) -{ - int i; - int final = 0; - - for ( i=0; inum_slides; i++ ) { - free_slide(p->slides[i]); - } - - (*p->num_presentations)--; - if ( *p->num_presentations == 0 ) final = 1; - - /* FIXME: Loads of stuff leaks here */ - free(p->filename); - free(p); - - if ( final ) { - gtk_main_quit(); - } -} - - -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 ) { - free(new); - return 1; - } - p->slides = try; - p->completely_empty = 0; - - /* Insert into list. Yuk yuk yuk etc. */ - if ( (p->num_slides>1) && (posnum_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; - } - - new->parent = p; - p->num_slides++; - - /* Update slide numbers for all subsequent slides */ -// for ( i=pos+1; inum_slides; i++ ) { -// struct object *o = p->slides[i]->roles[S_ROLE_SLIDENUMBER]; -// if ( o != NULL ) { -// o->update_object(o); -// } -// } - - return 0; -} - - -struct slide *new_slide() -{ - struct slide *new; - - new = calloc(1, sizeof(struct slide)); - if ( new == NULL ) return NULL; - - /* No frames to start with */ - new->num_frames = 0; - new->frames = NULL; - - new->rendered_edit = NULL; - new->rendered_proj = NULL; - new->rendered_thumb = NULL; - - new->notes = strdup(""); - - return new; -} - - -static void free_frame(struct frame *fr) -{ - int i; - - for ( i=0; inum_children; i++ ) { - free_frame(fr->children[i]); - } - - free(fr->sc); - - free(fr); -} - - -void free_slide(struct slide *s) -{ - int i; - - for ( i=0; inum_frames; i++ ) { - free_frame(s->frames[i]); - } - - free(s); -} - - -struct slide *add_slide(struct presentation *p, int pos) -{ - struct slide *s = new_slide(); - if ( insert_slide(p, s, pos) ) { - free_slide(s); - return NULL; - } - -#if 0 - /* Copy roles and references to this slide as applicable */ - if ( pos >= 0 ) { - - struct slide *ex = p->slides[pos]; - - s->roles[S_ROLE_PTITLE_REF] = ex->roles[S_ROLE_PTITLE_REF]; - s->roles[S_ROLE_PAUTHOR_REF] = ex->roles[S_ROLE_PAUTHOR_REF]; - s->roles[S_ROLE_PDATE_REF] = ex->roles[S_ROLE_PDATE_REF]; - - if ( ex->roles[S_ROLE_PTITLE] != NULL ) { - p->text_tool->create_default(p, - ex->roles[S_ROLE_PTITLE]->style, s, - p->text_tool); - } - - if ( ex->roles[S_ROLE_SLIDENUMBER] != NULL ) { - p->text_tool->create_default(p, - ex->roles[S_ROLE_SLIDENUMBER]->style, s, - p->text_tool); - } - - if ( ex->roles[S_ROLE_PAUTHOR] != NULL ) { - p->text_tool->create_default(p, - ex->roles[S_ROLE_PAUTHOR]->style, s, - p->text_tool); - } - - if ( ex->roles[S_ROLE_PDATE] != NULL ) { - p->text_tool->create_default(p, - ex->roles[S_ROLE_PDATE]->style, s, - p->text_tool); - } - - } -#endif - - return s; -} - - -int add_frame_to_slide(struct slide *s, struct frame *fr) -{ - struct frame **try; - - try = realloc(s->frames, (1+s->num_frames)*sizeof(struct frame *)); - if ( try == NULL ) return 1; - s->frames = try; - - s->frames[s->num_frames++] = fr; - - s->parent->completely_empty = 0; - - return 0; -} - - -void remove_frame_from_slide(struct slide *s, struct frame *fr) -{ - int i; - int found = 0; - - for ( i=0; inum_frames; i++ ) { - - if ( s->frames[i] == fr ) { - assert(!found); - found = 1; - } - - if ( found ) { - if ( i == s->num_frames-1 ) { - s->frames[i] = NULL; - } else { - s->frames[i] = s->frames[i+1]; - } - } - - } - - s->num_frames--; -} - - -struct frame *find_frame_at_position(struct slide *s, double x, double y) -{ - int i; - struct frame *fr = NULL; - - for ( i=0; inum_frames; i++ ) { - - if ( /* FIXME: implement */ 1 ) - { - fr = s->frames[i]; - } - - } - - /* FIXME: Recurse */ - - return fr; -} - - -static char *safe_basename(const char *in) -{ - int i; - char *cpy; - char *res; - - cpy = strdup(in); - - /* Get rid of any trailing slashes */ - for ( i=strlen(cpy)-1; i>0; i-- ) { - if ( cpy[i] == '/' ) { - cpy[i] = '\0'; - } else { - break; - } - } - - /* Find the base name */ - for ( i=strlen(cpy)-1; i>0; i-- ) { - if ( cpy[i] == '/' ) { - i++; - break; - } - } - - res = strdup(cpy+i); - /* If we didn't find a previous slash, i==0 so res==cpy */ - - free(cpy); - - return res; -} - - -void get_titlebar_string(struct presentation *p) -{ - free(p->titlebar); - - if ( p->filename == NULL ) { - p->titlebar = strdup("(untitled)"); - } else { - p->titlebar = safe_basename(p->filename); - } -} - - -int slide_number(struct presentation *p, struct slide *s) -{ - int i; - - for ( i=0; inum_slides; i++ ) { - if ( p->slides[i] == s ) return i; - } - - return p->num_slides; -} - - -struct presentation *new_presentation() -{ - struct presentation *new; - - new = calloc(1, sizeof(struct presentation)); - - num_presentations++; - new->num_presentations = &num_presentations; - - new->filename = NULL; - new->titlebar = NULL; - get_titlebar_string(new); - - /* FIXME: Should be just one of these */ - new->prefs = calloc(1, sizeof(struct prefs)); - new->prefs->b_splits = 1; - new->prefs->open_notes = 0; - - new->window = NULL; - new->ui = NULL; - new->action_group = NULL; - new->slideshow = NULL; - new->notes = NULL; - - new->slide_width = 1024.0; - new->slide_height = 768.0; - - /* Add one blank slide and view it */ - new->num_slides = 0; - new->slides = NULL; - new->cur_edit_slide = NULL; - new->cur_proj_slide = NULL; - - new->cur_frame = NULL; - new->completely_empty = 1; - new->drag_status = DRAG_STATUS_NONE; - - new->ss = new_stylesheet(); - default_stylesheet(new->ss); - new->image_store = image_store_new(); - - return new; -} diff --git a/src/presentation.h b/src/presentation.h index 1e0e787..423ea42 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -27,10 +27,7 @@ #include #endif -#include - -#include "stylesheet.h" -#include "stylesheet-editor.h" +#include struct slide { @@ -44,123 +41,18 @@ struct slide /* This should always be present (and up to date). */ cairo_surface_t *rendered_thumb; - int num_frames; - struct frame **frames; + struct frame *top; char *notes; }; -enum drag_reason -{ - DRAG_REASON_NONE, - DRAG_REASON_CREATE, - DRAG_REASON_IMPORT, - DRAG_REASON_TOOL, -}; - - -enum drag_status -{ - DRAG_STATUS_NONE, - DRAG_STATUS_COULD_DRAG, - DRAG_STATUS_DRAGGING, -}; - - -struct prefs -{ - int b_splits; - int open_notes; -}; - - -struct presentation -{ - char *titlebar; - char *filename; - int completely_empty; - int *num_presentations; - - struct prefs *prefs; - - GtkWidget *window; - GtkWidget *drawingarea; - GtkUIManager *ui; - GtkActionGroup *action_group; - GtkIMContext *im_context; - struct notes *notes; - - /* Pointers to the current "editing" and "projection" slides */ - struct slide *cur_edit_slide; - struct slide *cur_proj_slide; - struct slide *cur_notes_slide; - int slideshow_linked; - - /* This is the "native" size of the slide. It only exists to give - * font size some meaning in the context of a somewhat arbitrary DPI */ - double slide_width; - double slide_height; - - /* Width of a slide in the editor, projector or thumbnail (pixels) */ - int edit_slide_width; - int proj_slide_width; - int thumb_slide_width; - - /* This is just to help with rendering the slides within the - * editing window. */ - double border_offs_x; - double border_offs_y; - - struct frame *cur_frame; - - /* Stylesheet */ - StyleSheet *ss; - - /* Dialogue boxes */ - StylesheetWindow *stylesheetwindow; - - /* Slideshow stuff */ - GtkWidget *slideshow; - GtkWidget *ss_drawingarea; - GdkCursor *blank_cursor; - int ss_blank; - char ss_geom[256]; - - /* Rubber band boxes and related stuff */ - double start_corner_x; - double start_corner_y; - double drag_corner_x; - double drag_corner_y; - enum drag_reason drag_reason; - enum drag_status drag_status; - - /* Stuff to do with drag and drop import of "content" */ - int drag_preview_pending; - int have_drag_data; - int drag_highlight; - double import_width; - double import_height; - int import_acceptable; - - /* All the images used in the presentation */ - struct image_store *image_store; - - unsigned int num_slides; - struct slide **slides; -}; - - struct frame { struct frame_class *cl; - struct frame **children; - int num_children; - - int (*render_frame)(struct frame *this, cairo_t *cr); - int (*serialize)(struct frame *this, - struct serializer *ser); + struct frame **rendering_order; + int num_ro; char *sc; /* Storycode */ @@ -168,23 +60,4 @@ struct frame }; -extern struct presentation *new_presentation(void); -extern void free_presentation(struct presentation *p); - -extern struct slide *new_slide(void); -extern struct slide *add_slide(struct presentation *p, int pos); -extern int insert_slide(struct presentation *p, struct slide *s, int pos); -extern void free_slide(struct slide *s); - -extern int add_frame_to_slide(struct slide *s, struct frame *fr); - -extern void get_titlebar_string(struct presentation *p); - -extern struct frame *find_frame_at_position(struct slide *s, - double x, double y); - -extern int slide_number(struct presentation *p, struct slide *s); - -#define UNUSED __attribute__((unused)) - #endif /* PRESENTATION_H */ diff --git a/src/slideshow.c b/src/slideshow.c deleted file mode 100644 index bcbf528..0000000 --- a/src/slideshow.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - * slideshow.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "presentation.h" -#include "storycode.h" -#include "mainwindow.h" -#include "notes.h" - - -static gint ss_destroy_sig(GtkWidget *widget, struct presentation *p) -{ - p->slideshow = NULL; - gdk_cursor_unref(p->blank_cursor); - return FALSE; -} - - -static gboolean ss_expose_sig(GtkWidget *da, GdkEventExpose *event, - struct presentation *p) -{ - cairo_t *cr; - GtkAllocation allocation; - double xoff, yoff; - - cr = gdk_cairo_create(da->window); - - /* Overall background */ - cairo_rectangle(cr, event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); - cairo_fill(cr); - - if ( !p->ss_blank ) { - - int h; - - h = p->proj_slide_width * p->slide_height / p->slide_width; - - /* Get the overall size */ - gtk_widget_get_allocation(da, &allocation); - xoff = (allocation.width - p->proj_slide_width)/2.0; - yoff = (allocation.height - h)/2.0; - - /* Draw the slide from the cache */ - cairo_rectangle(cr, event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_set_source_surface(cr, p->cur_proj_slide->rendered_proj, - xoff, yoff); - cairo_fill(cr); - - } - - cairo_destroy(cr); - - return FALSE; -} - - -void notify_slideshow_slide_changed(struct presentation *p, struct slide *np) -{ - if ( (p->cur_proj_slide != NULL) - && (p->cur_proj_slide->rendered_edit != NULL) ) - { - cairo_surface_destroy(p->cur_proj_slide->rendered_proj); - p->cur_proj_slide->rendered_proj = NULL; - } - p->cur_proj_slide = np; - redraw_slide(p->cur_proj_slide); -} - - -static void change_slide(struct presentation *p, signed int n) -{ - - int cur_slide_number; - - /* If linked, it doesn't matter whether we work from the editor or - * slideshow position because they're showing the same thing. If not, - * then we must use the editor's slide. */ - cur_slide_number = slide_number(p, p->cur_edit_slide); - - if ( cur_slide_number+n < 0 ) return; - if ( cur_slide_number+n >= p->num_slides ) return; - - p->ss_blank = 0; - - if ( p->slideshow_linked ) { - - /* If we are currently "linked", update both. */ - notify_slideshow_slide_changed(p, p->slides[cur_slide_number+n]); - notify_slide_changed(p, p->slides[cur_slide_number+n]); - - } else { - - /* If we are not linked, a slide change on the "slideshow" - * actually affects the editor. */ - notify_slide_changed(p, p->slides[cur_slide_number+n]); - /* p->cur_proj_slide not changed */ - - } -} - - -static gint prev_slide_sig(GtkWidget *widget, struct presentation *p) -{ - change_slide(p, -1); - return FALSE; -} - - -static gint next_slide_sig(GtkWidget *widget, struct presentation *p) -{ - change_slide(p, +1); - return FALSE; -} - - -void end_slideshow(struct presentation *p) -{ - gtk_widget_destroy(p->ss_drawingarea); - gtk_widget_destroy(p->slideshow); - p->slideshow = NULL; - - if ( (p->cur_proj_slide != NULL) - && (p->cur_proj_slide->rendered_edit != NULL) ) - { - cairo_surface_destroy(p->cur_proj_slide->rendered_proj); - p->cur_proj_slide->rendered_proj = NULL; - } - - p->cur_proj_slide = NULL; - redraw_overlay(p); -} - - -void toggle_slideshow_link(struct presentation *p) -{ - p->slideshow_linked = 1 - p->slideshow_linked; - if ( p->slideshow_linked ) { - p->cur_proj_slide = p->cur_edit_slide; - notify_slideshow_slide_changed(p, p->cur_proj_slide); - } else { - redraw_overlay(p); - } -} - - -void check_toggle_blank(struct presentation *p) -{ - if ( p->slideshow != NULL ) { - if ( p->prefs->b_splits ) { - toggle_slideshow_link(p); - } else { - p->ss_blank = 1-p->ss_blank; - gdk_window_invalidate_rect(p->ss_drawingarea->window, - NULL, FALSE); - } - } -} - - -static gboolean ss_key_press_sig(GtkWidget *da, GdkEventKey *event, - struct presentation *p) -{ - switch ( event->keyval ) { - - case GDK_KEY_B : - case GDK_KEY_b : - check_toggle_blank(p); - break; - - case GDK_KEY_Page_Up : - case GDK_KEY_Up : - prev_slide_sig(NULL, p); - break; - - case GDK_KEY_Page_Down : - case GDK_KEY_Down : - next_slide_sig(NULL, p); - break; - - case GDK_KEY_Escape : - end_slideshow(p); - break; - - } - - return FALSE; -} - - -static gboolean ss_realize_sig(GtkWidget *w, struct presentation *p) -{ - p->blank_cursor = gdk_cursor_new(GDK_BLANK_CURSOR); - gdk_window_set_cursor(GDK_WINDOW(p->slideshow->window), - p->blank_cursor); - - gtk_window_parse_geometry(GTK_WINDOW(w), p->ss_geom); - - return FALSE; -} - - -void try_start_slideshow(struct presentation *p) -{ - GtkWidget *n; - GdkScreen *screen; - int n_monitors; - int i; - - /* Presentation already running? */ - if ( p->slideshow != NULL ) return; - - p->ss_blank = 0; - - n = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - p->ss_drawingarea = gtk_drawing_area_new(); - gtk_container_add(GTK_CONTAINER(n), p->ss_drawingarea); - - gtk_widget_set_can_focus(GTK_WIDGET(p->ss_drawingarea), TRUE); - gtk_widget_add_events(GTK_WIDGET(p->ss_drawingarea), - GDK_KEY_PRESS_MASK); - - g_signal_connect(G_OBJECT(p->ss_drawingarea), "key-press-event", - G_CALLBACK(ss_key_press_sig), p); - g_signal_connect(G_OBJECT(p->ss_drawingarea), "expose-event", - G_CALLBACK(ss_expose_sig), p); - g_signal_connect(G_OBJECT(n), "destroy", G_CALLBACK(ss_destroy_sig), p); - g_signal_connect(G_OBJECT(n), "realize", G_CALLBACK(ss_realize_sig), p); - - gtk_widget_grab_focus(GTK_WIDGET(p->ss_drawingarea)); - - screen = gdk_screen_get_default(); - n_monitors = gdk_screen_get_n_monitors(screen); - for ( i=0; iss_geom, 255, "%ix%i+%i+%i", - rect.width, rect.height, rect.x, rect.y); - - w = rect.height * p->slide_width/p->slide_height; - if ( w > rect.width ) w = rect.width; - p->proj_slide_width = w; - - } /* FIXME: Sensible (configurable) choice of monitor */ - - p->slideshow = n; - p->slideshow_linked = 1; - gtk_window_fullscreen(GTK_WINDOW(n)); - gtk_widget_show_all(GTK_WIDGET(n)); - - if ( p->prefs->open_notes ) open_notes(p); - - p->cur_proj_slide = p->cur_edit_slide; - redraw_slide(p->cur_proj_slide); -} diff --git a/src/slideshow.h b/src/slideshow.h deleted file mode 100644 index fc0ab1b..0000000 --- a/src/slideshow.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * slideshow.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef SLIDESHOW_H -#define SLIDESHOW_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -extern void try_start_slideshow(struct presentation *p); - -extern void notify_slideshow_slide_changed(struct presentation *p, - struct slide *np); - -extern void toggle_slideshow_link(struct presentation *p); -extern void check_toggle_blank(struct presentation *p); - -extern void end_slideshow(struct presentation *p); - -#endif /* SLIDESHOW_H */ diff --git a/src/storycode.c b/src/storycode.c index d394f02..f3c2e27 100644 --- a/src/storycode.c +++ b/src/storycode.c @@ -25,247 +25,6 @@ #include #endif -#include -#include -#include #include #include "storycode.h" -#include "presentation.h" -#include "objects.h" -#include "stylesheet.h" - - -static void render_bgblock(cairo_t *cr, struct bgblock *b) -{ - GdkColor col1; - GdkColor col2; - cairo_pattern_t *patt = NULL; - double cx, cy, r, r1, r2; - - cairo_rectangle(cr, b->min_x, b->min_y, - b->max_x - b->min_x, - b->max_y - b->min_y); - - switch ( b->type ) { - - case BGBLOCK_SOLID : - gdk_color_parse(b->colour1, &col1); - gdk_cairo_set_source_color(cr, &col1); - /* FIXME: Honour alpha as well */ - cairo_fill(cr); - break; - - case BGBLOCK_GRADIENT_CIRCULAR : - cx = b->min_x + (b->max_x-b->min_x)/2.0; - cy = b->min_y + (b->max_y-b->min_y)/2.0; - r1 = (b->max_x-b->min_x)/2.0; - r2 = (b->max_y-b->min_y)/2.0; - r = r1 > r2 ? r1 : r2; - patt = cairo_pattern_create_radial(cx, cy, r, cx, cy, 0.0); - /* Fall-through */ - - case BGBLOCK_GRADIENT_X : - if ( patt == NULL ) { - patt = cairo_pattern_create_linear(b->min_x, 0.0, - b->max_y, 0.0); - } - /* Fall-through */ - - case BGBLOCK_GRADIENT_Y : - if ( patt == NULL ) { - patt = cairo_pattern_create_linear(0.0, b->min_y, - 0.0, b->max_y); - } - - gdk_color_parse(b->colour1, &col1); - gdk_color_parse(b->colour2, &col2); - cairo_pattern_add_color_stop_rgba(patt, 0.0, col1.red/65535.0, - col1.green/65535.0, - col1.blue/65535.0, - b->alpha1); - cairo_pattern_add_color_stop_rgba(patt, 1.0, col2.red/65535.0, - col2.green/65535.0, - col2.blue/65535.0, - b->alpha2); - cairo_set_source(cr, patt); - cairo_fill(cr); - cairo_pattern_destroy(patt); - break; - - case BGBLOCK_IMAGE : - cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); - cairo_fill(cr); - - } -} - - -static void render_slide_bits(struct slide *s, cairo_t *cr) -{ - int i; - cairo_font_options_t *fopts; - - fopts = cairo_font_options_create(); - cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_OFF); - cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_SUBPIXEL); - cairo_set_font_options(cr, fopts); - - for ( i=0; ist->n_bgblocks; i++ ) { - render_bgblock(cr, s->st->bgblocks[i]); - } - - for ( i=0; inum_frames; i++ ) { - - struct frame *fr = s->frames[i]; - - fr->render_frame(fr, cr); - - } - - cairo_font_options_destroy(fopts); -} - - -static cairo_surface_t *render_slide(struct slide *s, int w, int h) -{ - cairo_surface_t *surf; - cairo_t *cr; - - surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); - - cr = cairo_create(surf); - cairo_scale(cr, w/s->parent->slide_width, h/s->parent->slide_height); - - render_slide_bits(s, cr); - - cairo_destroy(cr); - - return surf; -} - - -void redraw_slide(struct slide *s) -{ - int w, h; - - if ( s->rendered_thumb != NULL ) { - cairo_surface_destroy(s->rendered_thumb); - } - - w = s->parent->thumb_slide_width; - h = (s->parent->slide_height/s->parent->slide_width) * w; - s->rendered_thumb = render_slide(s, w, h); - /* FIXME: Request redraw for slide sorter if open */ - - /* Is this slide currently open in the editor? */ - if ( s == s->parent->cur_edit_slide ) { - - GtkWidget *da; - - if ( s->rendered_edit != NULL ) { - cairo_surface_destroy(s->rendered_edit); - } - - w = s->parent->edit_slide_width; - h = (s->parent->slide_height/s->parent->slide_width) * w; - s->rendered_edit = render_slide(s, w, h); - - da = s->parent->drawingarea; - if ( da != NULL ) { - gdk_window_invalidate_rect(da->window, NULL, FALSE); - } - - } - - /* Is this slide currently being displayed on the projector? */ - if ( s == s->parent->cur_proj_slide ) { - - GtkWidget *da; - - if ( s->rendered_proj != NULL ) { - cairo_surface_destroy(s->rendered_proj); - } - - w = s->parent->proj_slide_width; - h = (s->parent->slide_height/s->parent->slide_width) * w; - s->rendered_proj = render_slide(s, w, h); - - da = s->parent->ss_drawingarea; - if ( da != NULL ) { - gdk_window_invalidate_rect(da->window, NULL, FALSE); - } - - } -} - - -void draw_rubberband_box(cairo_t *cr, double x, double y, - double width, double height) -{ - cairo_new_path(cr); - cairo_rectangle(cr, x, y, width, height); - cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); - cairo_set_line_width(cr, 0.5); - cairo_stroke(cr); -} - - -void draw_resize_handle(cairo_t *cr, double x, double y) -{ - cairo_new_path(cr); - cairo_rectangle(cr, x, y, 20.0, 20.0); - cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.5); - cairo_fill(cr); -} - - -void draw_editing_box(cairo_t *cr, double xmin, double ymin, - double width, double height) -{ - const double dash[] = {2.0, 2.0}; - - cairo_new_path(cr); - cairo_rectangle(cr, xmin-5.0, ymin-5.0, width+10.0, height+10.0); - cairo_set_source_rgb(cr, 0.0, 0.69, 1.0); - cairo_set_line_width(cr, 0.5); - cairo_stroke(cr); - - cairo_new_path(cr); - cairo_rectangle(cr, xmin, ymin, width, height); - cairo_set_dash(cr, dash, 2, 0.0); - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); - cairo_set_line_width(cr, 0.1); - cairo_stroke(cr); - - cairo_set_dash(cr, NULL, 0, 0.0); -} - - -int export_pdf(struct presentation *p, const char *filename) -{ - int i; - cairo_surface_t *surf; - cairo_t *cr; - - surf = cairo_pdf_surface_create(filename, p->slide_width, - p->slide_height); - - if ( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) { - fprintf(stderr, "Couldn't create Cairo surface\n"); - return 1; - } - - cr = cairo_create(surf); - - for ( i=0; inum_slides; i++ ) { - render_slide_bits(p->slides[i], cr); - cairo_surface_show_page(surf); - } - - cairo_surface_finish(surf); - cairo_destroy(cr); - - return 0; -} diff --git a/src/storycode.h b/src/storycode.h index bd33638..6e106e3 100644 --- a/src/storycode.h +++ b/src/storycode.h @@ -28,20 +28,6 @@ #endif -#include "presentation.h" - -extern void redraw_slide(struct slide *s); - -extern void draw_rubberband_box(cairo_t *cr, double xmin, double ymin, - double width, double height); - -extern void draw_resize_handle(cairo_t *cr, double x, double y); - -extern void draw_editing_box(cairo_t *cr, double xmin, double ymin, - double width, double height); - -extern int export_pdf(struct presentation *p, const char *filename); - extern char *sc_get_final_font(const char *sc); extern char *sc_get_final_text_colour(const char *sc); diff --git a/src/stylesheet-editor.c b/src/stylesheet-editor.c deleted file mode 100644 index c08271c..0000000 --- a/src/stylesheet-editor.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * stylesheet-editor.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "presentation.h" -#include "stylesheet.h" -#include "objects.h" -#include "loadsave.h" -#include "storycode.h" - - -struct _stylesheetwindow -{ - struct presentation *p; /* Presentation to update when user alters - * something in this window */ - GtkWidget *window; - StyleSheet *ss; /* Style sheet this window corresponds to */ - - GtkWidget *margin_left; - GtkWidget *margin_right; - GtkWidget *margin_top; - GtkWidget *margin_bottom; - - GtkWidget *text_font; - GtkWidget *text_colour; - - char *font; - char *colour; - double alpha; - - struct slide_template *cur_slide_template; - struct frame_class *cur_frame_class; -}; - - -static void text_font_set_sig(GtkFontButton *widget, - struct _stylesheetwindow *s) -{ - const gchar *font; - - font = gtk_font_button_get_font_name(widget); - free(s->font); - s->font = strdup(font); - -// notify_style_update(s->p, s->cur_frame_class); -} - - -static void text_colour_set_sig(GtkColorButton *widget, - struct _stylesheetwindow *s) -{ - GdkColor col; - guint16 al; - - gtk_color_button_get_color(widget, &col); - free(s->colour); - s->colour = gdk_color_to_string(&col); - al = gtk_color_button_get_alpha(widget); - s->alpha = (double)al / 65535.0; - -// notify_style_update(s->p, s->cur_frame_class); -} - - -static void margin_left_changed_sig(GtkSpinButton *spin, - struct _stylesheetwindow *s) -{ - s->cur_frame_class->margin_left = gtk_spin_button_get_value(spin); -// notify_style_update(s->p, s->cur_frame_class); -} - - -static void margin_right_changed_sig(GtkSpinButton *spin, - struct _stylesheetwindow *s) -{ - s->cur_frame_class->margin_right = gtk_spin_button_get_value(spin); -// notify_style_update(s->p, s->cur_frame_class); -} - - -static void margin_top_changed_sig(GtkSpinButton *spin, - struct _stylesheetwindow *s) -{ - s->cur_frame_class->margin_top = gtk_spin_button_get_value(spin); -// notify_style_update(s->p, s->cur_frame_class); -} - - -static void margin_bottom_changed_sig(GtkSpinButton *spin, - struct _stylesheetwindow *s) -{ - s->cur_frame_class->margin_bottom = gtk_spin_button_get_value(spin); -// notify_style_update(s->p, s->cur_frame_class); -} - - -static void frame_class_changed_sig(GtkComboBox *combo, - struct _stylesheetwindow *s) -{ - int n; - GdkColor col; - char *font; - - n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); - s->cur_frame_class = s->cur_slide_template->frame_classes[n]; - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_left), - s->cur_frame_class->margin_left); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_right), - s->cur_frame_class->margin_right); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_bottom), - s->cur_frame_class->margin_bottom); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_top), - s->cur_frame_class->margin_top); - - font = sc_get_final_font(s->cur_frame_class->sc_prologue); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(s->text_font), font); - - s->colour = sc_get_final_text_colour(s->cur_frame_class->sc_prologue); - gdk_color_parse(s->colour, &col); - gtk_color_button_set_color(GTK_COLOR_BUTTON(s->text_colour), &col); -} - - -static void slide_template_changed_sig(GtkComboBox *combo, - struct _stylesheetwindow *s) -{ - for ( i=0; iss->n_styles; i++ ) { - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), - s->ss->styles[i]->name); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); -} - - -static void do_layout(struct _stylesheetwindow *s, GtkWidget *b) -{ - GtkWidget *table; - GtkWidget *line; - GtkWidget *label; - GtkWidget *combo; - GtkWidget *box; - GtkWidget *vbox; - int i; - - box = gtk_hbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(b), box, FALSE, FALSE, 5); - label = gtk_label_new("Top-level frame:"); - gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); - gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); - combo = gtk_combo_box_new_text(); - g_signal_connect(G_OBJECT(combo), "changed", - G_CALLBACK(style_changed_sig), s); - gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0); - - line = gtk_hseparator_new(); - gtk_box_pack_start(GTK_BOX(b), line, FALSE, FALSE, 5); - - box = gtk_hbox_new(TRUE, 30); - gtk_box_pack_start(GTK_BOX(b), box, FALSE, FALSE, 5); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, FALSE, 0); - label = gtk_label_new("Margins:"); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5); - table = gtk_table_new(3, 3, TRUE); - gtk_table_set_row_spacings(GTK_TABLE(table), 5.0); - gtk_table_set_col_spacings(GTK_TABLE(table), 5.0); - gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); - - /* Left */ - s->margin_left = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0); - gtk_table_attach_defaults(GTK_TABLE(table), s->margin_left, - 0, 1, 1, 2); - g_signal_connect(G_OBJECT(s->margin_left), "value-changed", - G_CALLBACK(margin_left_changed_sig), s); - - /* Up */ - s->margin_top = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0); - gtk_table_attach_defaults(GTK_TABLE(table), s->margin_top, - 1, 2, 0, 1); - g_signal_connect(G_OBJECT(s->margin_top), "value-changed", - G_CALLBACK(margin_top_changed_sig), s); - - /* Right */ - s->margin_right = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0); - gtk_table_attach_defaults(GTK_TABLE(table), s->margin_right, - 2, 3, 1, 2); - g_signal_connect(G_OBJECT(s->margin_right), "value-changed", - G_CALLBACK(margin_right_changed_sig), s); - - /* Down */ - s->margin_bottom = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0); - gtk_table_attach_defaults(GTK_TABLE(table), s->margin_bottom, - 1, 2, 2, 3); - g_signal_connect(G_OBJECT(s->margin_bottom), "value-changed", - G_CALLBACK(margin_bottom_changed_sig), s); - - /* Font/colour stuff */ - label = gtk_label_new("Font:"); - gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); - s->text_font = gtk_font_button_new_with_font("Sans 12"); - box = gtk_hbox_new(FALSE, 0); - gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 3, 4); - gtk_box_pack_start(GTK_BOX(box), s->text_font, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(s->text_font), "font-set", - G_CALLBACK(text_font_set_sig), s); - - label = gtk_label_new("Colour:"); - gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5); - s->text_colour = gtk_color_button_new(); - box = gtk_hbox_new(FALSE, 0); - gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 4, 5); - gtk_box_pack_start(GTK_BOX(box), s->text_colour, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(s->text_colour), "color-set", - G_CALLBACK(text_colour_set_sig), s); - - /* Force first update */ - frame_class_changed_sig(GTK_COMBO_BOX(combo), s); -} - - - -static gint destroy_stylesheet_sig(GtkWidget *w, struct _stylesheetwindow *s) -{ - s->p->stylesheetwindow = NULL; - free(s); - return FALSE; -} - - -StylesheetWindow *open_stylesheet(struct presentation *p) -{ - struct _stylesheetwindow *s; - GtkWidget *nb; - GtkWidget *text_box; - GtkWidget *background_box; - GtkWidget *box; - GtkWidget *label; - GtkWidget *combo; - - s = malloc(sizeof(*s)); - if ( s == NULL ) return NULL; - - s->p = p; - s->ss = p->ss; - s->cur_slide_template = NULL; - s->cur_frame_class = NULL; - - s->window = gtk_dialog_new_with_buttons("Stylesheet", - GTK_WINDOW(p->window), 0, - GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_dialog_set_has_separator(GTK_DIALOG(s->window), TRUE); - - box = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(s->window)->vbox), box, - TRUE, TRUE, 0); - - label = gtk_label_new("Slide template:"); - gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); - gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); - combo = gtk_combo_box_new_text(); -// for ( i=0; iss->n_styles; i++ ) { -// gtk_combo_box_append_text(GTK_COMBO_BOX(combo), -// s->ss->styles[i]->name); -// } - gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); -// g_signal_connect(G_OBJECT(combo), "changed", -// G_CALLBACK(template_changed_sig), s); - gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0); - - nb = gtk_notebook_new(); - gtk_notebook_set_tab_pos(GTK_NOTEBOOK(nb), GTK_POS_TOP); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(s->window)->vbox), nb, - TRUE, TRUE, 0); - - text_box = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(text_box), 12); - gtk_notebook_append_page(GTK_NOTEBOOK(nb), text_box, - gtk_label_new("Top Level Frames")); - do_layout(s, text_box); - - background_box = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(background_box), 12); - gtk_notebook_append_page(GTK_NOTEBOOK(nb), background_box, - gtk_label_new("Background")); - - g_signal_connect(G_OBJECT(s->window), "destroy", - G_CALLBACK(destroy_stylesheet_sig), s); - g_signal_connect(G_OBJECT(s->window), "response", - G_CALLBACK(gtk_widget_destroy), NULL); - - gtk_widget_show_all(s->window); - - return s; -} diff --git a/src/stylesheet-editor.h b/src/stylesheet-editor.h deleted file mode 100644 index a20dfb8..0000000 --- a/src/stylesheet-editor.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * stylesheet-editor.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef STYLESHEET_EDITOR_H -#define STYLESHEET_EDITOR_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -typedef struct _stylesheetwindow StylesheetWindow; - -extern StylesheetWindow *open_stylesheet(struct presentation *p); - -#endif /* STYLESHEET_EDITOR_H */ diff --git a/src/stylesheet.c b/src/stylesheet.c deleted file mode 100644 index eb959c1..0000000 --- a/src/stylesheet.c +++ /dev/null @@ -1,580 +0,0 @@ -/* - * stylesheet.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "presentation.h" -#include "stylesheet.h" -#include "objects.h" -#include "loadsave.h" - - -struct _stylesheet -{ - struct slide_template **slide_templates; - int n_slide_templates; -}; - - -struct slide_template *new_slide_template(StyleSheet *ss, const char *name) -{ - struct slide_template *st; - int n; - struct slide_template **slide_templates_new; - - st = calloc(1, sizeof(*st)); - if ( st == NULL ) return NULL; - - st->name = strdup(name); - st->frame_classes = NULL; - st->n_frame_classes = 0; - st->bgblocks = NULL; - st->n_bgblocks = 0; - - n = ss->n_slide_templates; - - /* Resize to n_slide_templates * size of pointer */ - slide_templates_new = realloc(ss->slide_templates, (n+1)*sizeof(st)); - if ( slide_templates_new == NULL ) { - free(st->name); - free(st); - return NULL; - } - ss->slide_templates = slide_templates_new; - ss->slide_templates[n] = st; - ss->n_slide_templates = n+1; - - return st; -} - - -struct frame_class *new_frame_class(struct slide_template *st, const char *name) -{ - struct frame_class *fc; - int n; - struct frame_class **frame_classes_new; - - fc = calloc(1, sizeof(*fc)); - if ( fc == NULL ) return NULL; - - fc->name = strdup(name); - fc->sc_prologue = NULL; - - n = st->n_frame_classes; - frame_classes_new = realloc(st->frame_classes, (n+1)*sizeof(fc)); - if ( frame_classes_new == NULL ) { - free(fc->name); - free(fc); - return NULL; - } - st->frame_classes = frame_classes_new; - st->frame_classes[n] = fc; - st->n_frame_classes = n+1; - - return fc; -} - - -static void free_frame_class(struct frame_class *fc) -{ - free(fc->name); - free(fc->sc_prologue); -} - - -static void free_bgblock(struct bgblock *bg) -{ - free(bg->colour1); - free(bg->colour2); -} - - -static void free_slide_template(struct slide_template *st) -{ - int i; - - for ( i=0; in_frame_classes; i++ ) { - free_frame_class(st->frame_classes[i]); - } - free(st->frame_classes); - - for ( i=0; in_bgblocks; i++ ) { - free_bgblock(st->bgblocks[i]); - } - free(st->bgblocks); - - free(st->name); -} - - -void free_stylesheet(StyleSheet *ss) -{ - int i; - - for ( i=0; in_slide_templates; i++ ) { - free_slide_template(ss->slide_templates[i]); - } - - free(ss->slide_templates); - free(ss); -} - - -void default_stylesheet(StyleSheet *ss) -{ - struct slide_template *st; - struct frame_class *fc; - - st = new_slide_template(ss, "Title page"); - - fc = new_frame_class(st, "Presentation title"); - fc->margin_left = 20.0; - fc->margin_right = 20.0; - fc->margin_top = 20.0; - fc->margin_bottom = 20.0; - fc->sc_prologue = strdup("\\FF'Sans 50';\\FC'#000000000000';"); - - fc = new_frame_class(st, "Author(s)"); - fc->margin_left = 20.0; - fc->margin_right = 20.0; - fc->margin_top = 20.0; - fc->margin_bottom = 20.0; - fc->sc_prologue = strdup("\\FF'Sans 30';\\FC'#000000000000';"); - - fc = new_frame_class(st, "Date"); - fc->margin_left = 20.0; - fc->margin_right = 20.0; - fc->margin_top = 20.0; - fc->margin_bottom = 20.0; - fc->sc_prologue = strdup("\\FF'Sans 30';\\FC'#000000000000';"); - - st->bgblocks = malloc(sizeof(struct bgblock)); - st->n_bgblocks = 1; - st->bgblocks[0]->type = BGBLOCK_SOLID; - st->bgblocks[0]->min_x = 0.0; - st->bgblocks[0]->max_x = 1024.0; - st->bgblocks[0]->min_y = 0.0; - st->bgblocks[0]->max_y = 768.0; - st->bgblocks[0]->colour1 = strdup("#eeeeeeeeeeee"); - st->bgblocks[0]->alpha1 = 1.0; - - st = new_slide_template(ss, "Slide"); - - fc = new_frame_class(st, "Content"); - fc->margin_left = 20.0; - fc->margin_right = 20.0; - fc->margin_top = 20.0; - fc->margin_bottom = 20.0; - fc->sc_prologue = strdup("\\FF'Sans 18';\\FC'#000000000000';"); - - fc = new_frame_class(st, "Title"); - fc->margin_left = 20.0; - fc->margin_right = 20.0; - fc->margin_top = 20.0; - fc->margin_bottom = 20.0; - fc->sc_prologue = strdup("\\FF'Sans 40';\\FC'#000000000000';"); - - fc = new_frame_class(st, "Credit"); - fc->margin_left = 20.0; - fc->margin_right = 20.0; - fc->margin_top = 20.0; - fc->margin_bottom = 35.0; - fc->sc_prologue = strdup("\\FF'Sans 14';\\FC'#000000000000';"); - - fc = new_frame_class(st, "Date"); - fc->margin_left = 600.0; - fc->margin_right = 100.0; - fc->margin_top = 745.0; - fc->margin_bottom = 5.0; - fc->sc_prologue = strdup("\\FF'Sans 12';\\FC'#999999999999';"); - - fc = new_frame_class(st, "Slide number"); - fc->margin_left = 600.0; - fc->margin_right = 5.0; - fc->margin_top = 745.0; - fc->margin_bottom = 5.0; - fc->sc_prologue = strdup("\\FF'Sans 12';\\FC'#999999999999';\\JR"); - - fc = new_frame_class(st, "Presentation title"); - fc->margin_left = 5.0; - fc->margin_right = 600.0; - fc->margin_top = 745.0; - fc->margin_bottom = 5.0; - fc->sc_prologue = strdup("\\FF'Sans 12';\\FC'#999999999999';\\JC\\VC"); - - st->bgblocks = malloc(sizeof(struct bgblock)); - st->n_bgblocks = 1; - st->bgblocks[0]->type = BGBLOCK_SOLID; - st->bgblocks[0]->min_x = 0.0; - st->bgblocks[0]->max_x = 1024.0; - st->bgblocks[0]->min_y = 0.0; - st->bgblocks[0]->max_y = 768.0; - st->bgblocks[0]->colour1 = strdup("#ffffffffffff"); - st->bgblocks[0]->alpha1 = 1.0; -} - - -static const char *str_bgtype(enum bgblocktype t) -{ - switch ( t ) { - case BGBLOCK_SOLID : return "solid"; - case BGBLOCK_GRADIENT_X : return "gradient_x"; - case BGBLOCK_GRADIENT_Y : return "gradient_y"; - case BGBLOCK_GRADIENT_CIRCULAR : return "gradient_circular"; - case BGBLOCK_IMAGE : return "image"; - default : return "???"; - } -} - - -static enum bgblocktype str_to_bgtype(char *t) -{ - if ( strcmp(t, "solid") == 0 ) return BGBLOCK_SOLID; - if ( strcmp(t, "gradient_x") == 0 ) return BGBLOCK_GRADIENT_X; - if ( strcmp(t, "gradient_y") == 0 ) return BGBLOCK_GRADIENT_Y; - if ( strcmp(t, "gradient_ciruclar") == 0 ) { - return BGBLOCK_GRADIENT_CIRCULAR; - } - if ( strcmp(t, "image") == 0 ) return BGBLOCK_IMAGE; - - return BGBLOCK_SOLID; -} - - -static int read_frame_class(struct frame_class *fc, struct ds_node *root) -{ - get_field_f(root, "margin_left", &fc->margin_left); - get_field_f(root, "margin_right", &fc->margin_right); - get_field_f(root, "margin_top", &fc->margin_top); - get_field_f(root, "margin_bottom", &fc->margin_bottom); - get_field_s(root, "sc_prologue", &fc->sc_prologue); - - return 0; -} - - -static int read_bgblock(struct bgblock *b, struct ds_node *root) -{ - char *type; - - get_field_s(root, "type", &type); - b->type = str_to_bgtype(type); - - get_field_f(root, "min_x", &b->min_x); - get_field_f(root, "max_x", &b->max_x); - get_field_f(root, "min_y", &b->min_y); - get_field_f(root, "max_y", &b->max_y); - - switch ( b->type ) { - - case BGBLOCK_SOLID : - get_field_s(root, "colour1", &b->colour1); - get_field_f(root, "alpha1", &b->alpha1); - break; - - case BGBLOCK_GRADIENT_X : - case BGBLOCK_GRADIENT_Y : - case BGBLOCK_GRADIENT_CIRCULAR : - get_field_s(root, "colour1", &b->colour1); - get_field_f(root, "alpha1", &b->alpha1); - get_field_s(root, "colour2", &b->colour2); - get_field_f(root, "alpha2", &b->alpha2); - break; - - default: - break; - - } - - return 0; -} - - -struct slide_template *tree_to_slide_template(StyleSheet *ss, - struct ds_node *root) -{ - struct slide_template *st; - int i; - char *v; - struct ds_node *node; - - get_field_s(root, "name", &v); - if ( v == NULL ) { - fprintf(stderr, "No name for slide template '%s'\n", - root->key); - return NULL; - } - - st = new_slide_template(ss, v); - if ( st == NULL ) return NULL; - - node = find_node(root, "frame_classes", 0); - if ( node == NULL ) { - fprintf(stderr, "Couldn't find frame classes\n"); - free_slide_template(st); - return NULL; - } - - st->frame_classes = malloc(node->n_children - * sizeof(struct frame_class)); - if ( st->frame_classes == NULL ) { - fprintf(stderr, "Couldn't allocate frame classes\n"); - free_slide_template(st); - return NULL; - } - st->n_frame_classes = node->n_children; - - for ( i=0; in_children; i++ ) { - - struct frame_class *fc; - - fc = st->frame_classes[i]; - - if ( read_frame_class(fc, node->children[i]) ) { - fprintf(stderr, "Couldn't read frame class %i\n", i); - continue; - } - - } - - node = find_node(root, "bgblocks", 0); - if ( node == NULL ) { - fprintf(stderr, "Couldn't find bgblocks\n"); - free_stylesheet(ss); - return NULL; - } - - st->bgblocks = malloc(node->n_children * sizeof(struct bgblock)); - if ( st->bgblocks == NULL ) { - fprintf(stderr, "Couldn't allocate bgblocks\n"); - free_slide_template(st); - return NULL; - } - st->n_bgblocks = node->n_children; - - for ( i=0; in_children; i++ ) { - - struct bgblock *b; - - b = st->bgblocks[i]; - - if ( read_bgblock(b, node->children[i]) ) { - fprintf(stderr, "Couldn't read bgblock %i\n", i); - continue; - } - - } - - return st; -} - - -StyleSheet *tree_to_stylesheet(struct ds_node *root) -{ - StyleSheet *ss; - struct ds_node *node; - int i; - - ss = new_stylesheet(); - if ( ss == NULL ) return NULL; - - node = find_node(root, "templates", 0); - if ( node == NULL ) { - fprintf(stderr, "Couldn't find slide templates\n"); - free_stylesheet(ss); - return NULL; - } - - for ( i=0; in_children; i++ ) { - - struct slide_template *st; - - st = tree_to_slide_template(ss, node->children[i]); - - } - - return ss; -} - - -StyleSheet *new_stylesheet() -{ - StyleSheet *ss; - - ss = calloc(1, sizeof(struct _stylesheet)); - if ( ss == NULL ) return NULL; - - ss->n_slide_templates = 0; - ss->slide_templates = NULL; - - return ss; -} - - -int save_stylesheet(StyleSheet *ss, const char *filename) -{ - FILE *fh; - struct serializer ser; - - fh = fopen(filename, "w"); - if ( fh == NULL ) return 1; - - /* Set up the serializer */ - ser.fh = fh; - ser.stack_depth = 0; - ser.prefix = NULL; - - fprintf(fh, "# Colloquium style sheet file\n"); - serialize_f(&ser, "version", 0.1); - - serialize_start(&ser, "stylesheet"); - write_stylesheet(ss, &ser); - serialize_end(&ser); - - return 0; -} - - -StyleSheet *load_stylesheet(const char *filename) -{ - StyleSheet *ss; - - ss = new_stylesheet(); - if ( ss == NULL ) return NULL; - - /* FIXME: Implement this */ - - return ss; -} - - -void write_stylesheet(StyleSheet *ss, struct serializer *ser) -{ - int i; - - serialize_start(ser, "templates"); - for ( i=0; in_slide_templates; i++ ) { - - int j; - struct slide_template *st; - - st = ss->slide_templates[i]; - - serialize_start(ser, "bgblocks"); - for ( j=0; jn_bgblocks; j++ ) { - - struct bgblock *b = st->bgblocks[j]; - char id[32]; - - snprintf(id, 31, "%i", j); - - serialize_start(ser, id); - serialize_s(ser, "type", str_bgtype(b->type)); - serialize_f(ser, "min_x", b->min_x); - serialize_f(ser, "min_y", b->min_y); - serialize_f(ser, "max_x", b->max_x); - serialize_f(ser, "max_y", b->max_y); - - switch ( b->type ) { - - case BGBLOCK_SOLID : - serialize_s(ser, "colour1", b->colour1); - serialize_f(ser, "alpha1", b->alpha1); - break; - - case BGBLOCK_GRADIENT_X : - case BGBLOCK_GRADIENT_Y : - case BGBLOCK_GRADIENT_CIRCULAR : - serialize_s(ser, "colour1", b->colour1); - serialize_f(ser, "alpha1", b->alpha1); - serialize_s(ser, "colour2", b->colour2); - serialize_f(ser, "alpha2", b->alpha2); - break; - - default: - break; - - } - - serialize_end(ser); - - } - serialize_end(ser); - - serialize_start(ser, "frame_classes"); - for ( j=0; jn_frame_classes; j++ ) { - - struct frame_class *fc = st->frame_classes[j]; - char id[32]; - - snprintf(id, 31, "%i", j); - - serialize_start(ser, id); - serialize_s(ser, "name", fc->name); - serialize_f(ser, "margin_left", fc->margin_left); - serialize_f(ser, "margin_right", fc->margin_right); - serialize_f(ser, "margin_top", fc->margin_top); - serialize_f(ser, "margin_bottom", fc->margin_bottom); - serialize_s(ser, "sc_prologue", fc->sc_prologue); - serialize_end(ser); - - } - serialize_end(ser); - - } - - serialize_end(ser); -} - - -struct frame_class *find_frame_class(struct slide_template *st, - const char *name) -{ - int i; - for ( i=0; in_frame_classes; i++ ) { - if ( strcmp(st->frame_classes[i]->name, name) == 0 ) { - return st->frame_classes[i]; - } - } - - return NULL; -} - - -struct slide_template *find_slide_template(StyleSheet *ss, const char *name) -{ - int i; - for ( i=0; in_slide_templates; i++ ) { - if ( strcmp(ss->slide_templates[i]->name, name) == 0 ) { - return ss->slide_templates[i]; - } - } - - return NULL; -} diff --git a/src/stylesheet.h b/src/stylesheet.h index 558c7c5..44230fb 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -27,8 +27,6 @@ #include #endif -#include "loadsave.h" - struct frame_class { @@ -91,21 +89,4 @@ struct slide_template typedef struct _stylesheet StyleSheet; struct presentation; -extern StyleSheet *new_stylesheet(); -extern StyleSheet *load_stylesheet(const char *filename); -extern void free_stylesheet(StyleSheet *ss); -extern void default_stylesheet(StyleSheet *ss); - -extern int save_stylesheet(StyleSheet *ss, const char *filename); - -/* Used during deserialization */ -extern struct slide_template *find_slide_template(StyleSheet *ss, - const char *name); - -extern struct frame_class *find_frame_class(struct slide_template *st, - const char *name); - -extern StyleSheet *tree_to_stylesheet(struct ds_node *root); -extern void write_stylesheet(StyleSheet *ss, struct serializer *ser); - #endif /* STYLESHEET_H */ diff --git a/src/tool_image.c b/src/tool_image.c deleted file mode 100644 index 2495b95..0000000 --- a/src/tool_image.c +++ /dev/null @@ -1,514 +0,0 @@ -/* - * tool_image.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "presentation.h" -#include "objects.h" -#include "mainwindow.h" -#include "slide_render.h" - - -enum image_drag_reason -{ - IMAGE_DRAG_REASON_NONE, - IMAGE_DRAG_REASON_RESIZE, -}; - - -struct image_toolinfo -{ - struct toolinfo base; - enum image_drag_reason drag_reason; - enum corner drag_corner; - double box_x; - double box_y; - double box_width; - double box_height; - double drag_initial_x; - double drag_initial_y; -}; - - -struct image_object -{ - struct object base; - - struct image *image; - GdkPixbuf *scaled_pb; - int scaled_w; - int scaled_h; - double diagonal_length; -}; - - -static void update_image(struct image_object *o) -{ - struct image *i = o->image; - int w, h; - - /* Fit the width and calculate the height */ - w = o->base.bb_width; - h = ((double)i->height / i->width) * o->base.bb_width; - if ( h > o->base.bb_height ) { - h = o->base.bb_height; - w = ((double)i->width / i->height) * o->base.bb_height; - } - - if ( (o->scaled_w != w) || (o->scaled_h != h) ) { - if ( o->scaled_pb != NULL ) gdk_pixbuf_unref(o->scaled_pb); - o->scaled_pb = gdk_pixbuf_scale_simple(i->pb, w, h, - GDK_INTERP_BILINEAR); - } /* else the size didn't change */ -} - - -static void render_image_object(cairo_t *cr, struct object *op) -{ - struct image_object *o = (struct image_object *)op; - - cairo_new_path(cr); - cairo_rectangle(cr, op->x, op->y, op->bb_width, op->bb_height); - gdk_cairo_set_source_pixbuf(cr, o->scaled_pb, op->x, op->y); - cairo_fill(cr); -} - - - -static void update_image_object(struct object *op) -{ - struct image_object *o = (struct image_object *)op; - update_image(o); -} - - -static void delete_image_object(struct object *op) -{ - struct image_object *o = (struct image_object *)op; - if ( o->scaled_pb != NULL ) gdk_pixbuf_unref(o->scaled_pb); - unref_image(o->image); -} - - -static void serialize(struct object *op, struct serializer *ser) -{ - struct image_object *o = (struct image_object *)op; - - serialize_f(ser, "x", op->x); - serialize_f(ser, "y", op->y); - serialize_f(ser, "w", op->bb_width); - serialize_f(ser, "h", op->bb_height); - serialize_s(ser, "filename", o->image->filename); -} - - -static struct image_object *new_image_object(double x, double y, - double bb_width, double bb_height, - char *filename, struct style *sty, - struct image_store *is, - struct image_toolinfo *ti) -{ - struct image_object *new; - - new = calloc(1, sizeof(*new)); - if ( new == NULL ) return NULL; - - /* Base properties */ - new->base.x = x; new->base.y = y; - new->base.bb_width = bb_width; - new->base.bb_height = bb_height; - new->base.type = OBJ_IMAGE; - new->base.empty = 0; - new->base.parent = NULL; - new->base.style = sty; - - new->scaled_pb = NULL; - new->image = get_image(is, filename); - if ( new->image == NULL ) { - free(new); - printf("Failed to load or get image.\n"); - return NULL; - } - - /* Methods for this object */ - new->base.render_object = render_image_object; - new->base.delete_object = delete_image_object; - new->base.update_object = update_image_object; - new->base.serialize = serialize; - - return new; -} - - -struct object *add_image_object(struct slide *s, double x, double y, - double bb_width, double bb_height, - char *filename, struct style *sty, - struct image_store *is, - struct image_toolinfo *ti) -{ - struct image_object *new; - - new = new_image_object(x, y, bb_width, bb_height, - filename, sty, is, ti); - if ( new == NULL ) return NULL; - - new->base.parent = s; - if ( add_object_to_slide(s, (struct object *)new) ) { - free(new); - return NULL; - } - - update_image(new); - redraw_slide(s); - - return (struct object *)new; -} - - -static void calculate_box_size(struct object *o, double x, double y, - struct image_toolinfo *ti) -{ - double ddx, ddy, dlen, mult; - double vx, vy, dbx, dby; - struct image_object *to = (struct image_object *)o; - - ddx = x - ti->drag_initial_x; - ddy = y - ti->drag_initial_y; - - switch ( ti->drag_corner ) { - - case CORNER_BR : - vx = o->bb_width; - vy = o->bb_height; - break; - - case CORNER_BL : - vx = -o->bb_width; - vy = o->bb_height; - break; - - case CORNER_TL : - vx = -o->bb_width; - vy = -o->bb_height; - break; - - case CORNER_TR : - vx = o->bb_width; - vy = -o->bb_height; - break; - - case CORNER_NONE : - default: - vx = 0.0; - vy = 0.0; - break; - - } - - dlen = (ddx*vx + ddy*vy) / to->diagonal_length; - mult = (dlen+to->diagonal_length) / to->diagonal_length; - - ti->box_width = o->bb_width * mult; - ti->box_height = o->bb_height * mult; - dbx = ti->box_width - o->bb_width; - dby = ti->box_height - o->bb_height; - - if ( ti->box_width < 40.0 ) { - mult = 40.0 / o->bb_width; - } - if ( ti->box_height < 40.0 ) { - mult = 40.0 / o->bb_height; - } - ti->box_width = o->bb_width * mult; - ti->box_height = o->bb_height * mult; - dbx = ti->box_width - o->bb_width; - dby = ti->box_height - o->bb_height; - - switch ( ti->drag_corner ) { - - case CORNER_BR : - ti->box_x = o->x; - ti->box_y = o->y; - break; - - case CORNER_BL : - ti->box_x = o->x - dbx; - ti->box_y = o->y; - break; - - case CORNER_TL : - ti->box_x = o->x - dbx; - ti->box_y = o->y - dby; - break; - - case CORNER_TR : - ti->box_x = o->x; - ti->box_y = o->y - dby; - break; - - case CORNER_NONE : - break; - - } - -} - - -static void click_select(struct presentation *p, struct toolinfo *tip, - double x, double y, GdkEventButton *event, - enum drag_status *drag_status, - enum drag_reason *drag_reason) -{ - enum corner c; - struct image_toolinfo *ti = (struct image_toolinfo *)tip; - struct image_object *o = (struct image_object *)p->editing_object; - - assert(o->base.type == OBJ_IMAGE); - - /* Within the resizing region? */ - c = which_corner(x, y, &o->base); - if ( c != CORNER_NONE ) - { - ti->drag_reason = IMAGE_DRAG_REASON_RESIZE; - ti->drag_corner = c; - - ti->drag_initial_x = x; - ti->drag_initial_y = y; - o->diagonal_length = pow(o->base.bb_width, 2.0); - o->diagonal_length += pow(o->base.bb_height, 2.0); - o->diagonal_length = sqrt(o->diagonal_length); - - calculate_box_size((struct object *)o, x, y, ti); - - /* Tell the MCP what we did, and return */ - *drag_status = DRAG_STATUS_DRAGGING; - *drag_reason = DRAG_REASON_TOOL; - return; - } -} - - -static void drag(struct toolinfo *tip, struct presentation *p, - struct object *o, double x, double y) -{ - struct image_toolinfo *ti = (struct image_toolinfo *)tip; - - if ( ti->drag_reason == IMAGE_DRAG_REASON_RESIZE ) { - - calculate_box_size(o, x, y, ti); - redraw_overlay(p); - - } -} - - -static void end_drag(struct toolinfo *tip, struct presentation *p, - struct object *o, double x, double y) -{ - struct image_toolinfo *ti = (struct image_toolinfo *)tip; - - calculate_box_size((struct object *)o, x, y, ti); - - o->x = ti->box_x; - o->y = ti->box_y; - o->bb_width = ti->box_width; - o->bb_height = ti->box_height; - update_image((struct image_object *)o); - redraw_slide(o->parent); - - ti->drag_reason = IMAGE_DRAG_REASON_NONE; -} - - -static void create_region(struct toolinfo *tip, struct presentation *p, - double x1, double y1, double x2, double y2) -{ - //struct object *n; - //struct image_toolinfo *ti = (struct image_toolinfo *)tip; - //struct image_object *o; - - /* FIXME: Open an "Open file" dialogue box and use the result */ -} - - -static void select_object(struct object *o, struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static int deselect_object(struct object *o, struct toolinfo *tip) -{ - if ( (o != NULL) && o->empty ) { - delete_object(o); - return 1; - } - - return 0; -} - - -static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *n) -{ - struct image_toolinfo *ti = (struct image_toolinfo *)tip; - //struct image_object *o = (struct image_object *)n; - - if ( n != NULL ) { - - draw_editing_box(cr, n->x, n->y, n->bb_width, n->bb_height); - - /* Draw resize handles */ - draw_resize_handle(cr, n->x, n->y+n->bb_height-20.0); - draw_resize_handle(cr, n->x+n->bb_width-20.0, n->y); - draw_resize_handle(cr, n->x, n->y); - draw_resize_handle(cr, n->x+n->bb_width-20.0, - n->y+n->bb_height-20.0); - - } - - if ( ti->drag_reason == IMAGE_DRAG_REASON_RESIZE ) { - draw_rubberband_box(cr, ti->box_x, ti->box_y, - ti->box_width, ti->box_height); - } - -} - - -static void key_pressed(struct object *o, guint keyval, struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static void im_commit(struct object *o, gchar *str, struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static int valid_object(struct object *o) -{ - if ( o->type == OBJ_IMAGE ) return 1; - return 0; -} - - -static struct object *deserialize(struct presentation *p, struct ds_node *root, - struct toolinfo *tip) -{ - struct image_object *o; - double x, y, w, h; - char *filename; - struct image_toolinfo *ti = (struct image_toolinfo *)tip; - - if ( get_field_f(root, "x", &x) ) { - fprintf(stderr, - "Couldn't find x position for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_f(root, "y", &y) ) { - fprintf(stderr, - "Couldn't find y position for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_f(root, "w", &w) ) { - fprintf(stderr, - "Couldn't find width for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_f(root, "h", &h) ) { - fprintf(stderr, - "Couldn't find height for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_s(root, "filename", &filename) ) { - fprintf(stderr, "Couldn't find filename for object '%s'\n", - root->key); - return NULL; - } - - o = new_image_object(x, y, w, h, filename, - p->ss->styles[0], p->image_store, ti); - free(filename); - - return (struct object *)o; -} - - -static gint prop_sig(GtkWidget *widget, struct presentation *p) -{ - if ( p->editing_object == NULL ) return FALSE; - - - return FALSE; -} - - -static void realise(struct toolinfo *ti, GtkWidget *w, struct presentation *p) -{ - GtkWidget *prop; - - ti->tbox = gtk_hbox_new(FALSE, 0.0); - prop = gtk_button_new_from_stock(GTK_STOCK_PROPERTIES); - g_signal_connect(G_OBJECT(prop), "clicked", G_CALLBACK(prop_sig), p); - gtk_box_pack_start(GTK_BOX(ti->tbox), prop, FALSE, FALSE, 0); - - g_object_ref(ti->tbox); - gtk_widget_show_all(ti->tbox); -} - - -struct toolinfo *initialise_image_tool() -{ - struct image_toolinfo *ti; - - ti = malloc(sizeof(*ti)); - - ti->base.click_select = click_select; - ti->base.create_default = NULL; - ti->base.select = select_object; - ti->base.deselect = deselect_object; - ti->base.drag = drag; - ti->base.end_drag = end_drag; - ti->base.create_region = create_region; - ti->base.draw_editing_overlay = draw_overlay; - ti->base.key_pressed = key_pressed; - ti->base.im_commit = im_commit; - ti->base.valid_object = valid_object; - ti->base.deserialize = deserialize; - ti->base.realise = realise; - - return (struct toolinfo *)ti; -} diff --git a/src/tool_image.h b/src/tool_image.h deleted file mode 100644 index d4d613b..0000000 --- a/src/tool_image.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * tool_image.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef TOOL_IMAGE_H -#define TOOL_IMAGE_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - - -extern struct toolinfo *initialise_image_tool(void); - -extern struct object *add_image_object(struct slide *s, double x, double y, - double bb_width, double bb_height, - char *filename, struct style *sty, - struct image_store *is, - struct toolinfo *ti); - -#endif /* TOOL_IMAGE_H */ diff --git a/src/tool_select.c b/src/tool_select.c deleted file mode 100644 index 1b9debb..0000000 --- a/src/tool_select.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * tool_sekect.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "presentation.h" -#include "objects.h" -#include "mainwindow.h" -#include "slide_render.h" - - -enum select_drag_reason -{ - SELECT_DRAG_REASON_NONE, - SELECT_DRAG_REASON_POTENTIAL_MOVE, - SELECT_DRAG_REASON_MOVE, -}; - - -struct select_toolinfo -{ - struct toolinfo base; - double drag_offs_x; - double drag_offs_y; - double box_x; - double box_y; - double box_width; - double box_height; - enum select_drag_reason drag_reason; -}; - - -static void click_select(struct presentation *p, struct toolinfo *tip, - double x, double y, GdkEventButton *event, - enum drag_status *drag_status, - enum drag_reason *drag_reason) -{ - struct select_toolinfo *ti = (struct select_toolinfo *)tip; - struct object *clicked = p->editing_object; - - ti->drag_offs_x = clicked->x - x; - ti->drag_offs_y = clicked->y - y; - - *drag_status = DRAG_STATUS_COULD_DRAG; - *drag_reason = DRAG_REASON_TOOL; - ti->drag_reason = SELECT_DRAG_REASON_POTENTIAL_MOVE; -} - - -static void update_box(struct select_toolinfo *ti, double x, double y, - struct object *o) -{ - double nx, ny; - double eright, ebottom; - - nx = x + ti->drag_offs_x; - ny = y + ti->drag_offs_y; - - /* Enforce margins */ - eright = o->parent->parent->slide_width - o->style->margin_right; - ebottom = o->parent->parent->slide_height - o->style->margin_bottom; - if ( nx < o->style->margin_left ) nx = o->style->margin_left; - if ( ny < o->style->margin_top ) ny = o->style->margin_top; - if ( nx+o->bb_width > eright ) nx = eright - o->bb_width; - if ( ny+o->bb_height > ebottom ) ny = ebottom - o->bb_height; - - ti->box_x = nx; - ti->box_y = ny; - ti->box_width = o->bb_width; - ti->box_height = o->bb_height; -} - - -static void drag(struct toolinfo *tip, struct presentation *p, - struct object *o, double x, double y) -{ - struct select_toolinfo *ti = (struct select_toolinfo *)tip; - - if ( ti->drag_reason == SELECT_DRAG_REASON_POTENTIAL_MOVE ) { - ti->drag_reason = SELECT_DRAG_REASON_MOVE; - } - - if ( ti->drag_reason != SELECT_DRAG_REASON_MOVE ) return; - - update_box(ti, x, y, o); - - redraw_overlay(p); -} - - -static void end_drag(struct toolinfo *tip, struct presentation *p, - struct object *o, double x, double y) -{ - struct select_toolinfo *ti = (struct select_toolinfo *)tip; - - update_box(ti, x, y, o); - o->x = ti->box_x; - o->y = ti->box_y; - ti->drag_reason = SELECT_DRAG_REASON_NONE; - redraw_slide(o->parent); -} - - -static void create_region(struct toolinfo *tip, struct presentation *p, - double x1, double y1, double x2, double y2) -{ - /* FIXME: Select multiple objects */ -} - - -static void select_object(struct object *o,struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static int deselect_object(struct object *o,struct toolinfo *tip) -{ - /* Do nothing */ - return 0; -} - - -static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *o) -{ - struct select_toolinfo *ti = (struct select_toolinfo *)tip; - - if ( o != NULL ) { - draw_editing_box(cr, o->x, o->y, o->bb_width, o->bb_height); - } - - if ( ti->drag_reason == SELECT_DRAG_REASON_MOVE ) { - draw_rubberband_box(cr, ti->box_x, ti->box_y, - ti->box_width, ti->box_height); - } -} - - -static void key_pressed(struct object *o, guint keyval, struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static void im_commit(struct object *o, gchar *str, struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static int valid_object(struct object *o) -{ - return 1; -} - - -static gint delete_sig(GtkWidget *widget, struct presentation *p) -{ - if ( p->editing_object == NULL ) return FALSE; - - delete_object(p->editing_object); - p->editing_object = NULL; - redraw_slide(p->cur_edit_slide); - - return FALSE; -} - - -static void realise(struct toolinfo *ti, GtkWidget *w, struct presentation *p) -{ - GtkWidget *hbox; - GtkWidget *del; - - hbox = gtk_hbox_new(FALSE, 0.0); - ti->tbox = hbox; - - del = gtk_button_new_from_stock(GTK_STOCK_DELETE); - g_signal_connect(G_OBJECT(del), "clicked", G_CALLBACK(delete_sig), p); - gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0); - - g_object_ref(ti->tbox); - gtk_widget_show_all(ti->tbox); -} - - -struct toolinfo *initialise_select_tool() -{ - struct select_toolinfo *ti; - - ti = malloc(sizeof(*ti)); - - ti->drag_reason = SELECT_DRAG_REASON_NONE; - - ti->base.click_select = click_select; - ti->base.create_default = NULL; - ti->base.select = select_object; - ti->base.deselect = deselect_object; - ti->base.drag = drag; - ti->base.end_drag = end_drag; - ti->base.create_region = create_region; - ti->base.draw_editing_overlay = draw_overlay; - ti->base.key_pressed = key_pressed; - ti->base.im_commit = im_commit; - ti->base.valid_object = valid_object; - ti->base.realise = realise; - - return (struct toolinfo *)ti; -} diff --git a/src/tool_select.h b/src/tool_select.h deleted file mode 100644 index 93aeb15..0000000 --- a/src/tool_select.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * tool_select.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef TOOL_SELECT_H -#define TOOL_SELECT_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -extern struct toolinfo *initialise_select_tool(void); - - -#endif /* TOOL_SELECT_H */ diff --git a/src/tool_text.c b/src/tool_text.c deleted file mode 100644 index 1b62f91..0000000 --- a/src/tool_text.c +++ /dev/null @@ -1,984 +0,0 @@ -/* - * tool_text.c - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "presentation.h" -#include "objects.h" -#include "mainwindow.h" -#include "slide_render.h" -#include "loadsave.h" - - -enum text_drag_reason -{ - TEXT_DRAG_REASON_NONE, - TEXT_DRAG_REASON_RESIZE, -}; - - -struct text_toolinfo -{ - struct toolinfo base; - PangoContext *pc; - enum text_drag_reason drag_reason; - enum corner drag_corner; - double box_x; - double box_y; - double box_width; - double box_height; - double drag_initial_x; - double drag_initial_y; -}; - - -struct text_object -{ - struct object base; - - char *text; - size_t text_len; - int insertion_point; - int insertion_trail; - PangoLayout *layout; - PangoFontDescription *fontdesc; - double offs_x; - double offs_y; - int furniture; - - PangoContext **pc; -}; - - -static void calculate_size_from_style(struct text_object *o, - double *peright, double *pebottom, - double *pmw, double *pmh) -{ - double max_width, max_height; - double ebottom, eright, mw, mh; - - eright = o->base.parent->parent->slide_width - - o->base.style->margin_right; - ebottom = o->base.parent->parent->slide_height - - o->base.style->margin_bottom; - mw = o->base.parent->parent->slide_width; - mh = o->base.parent->parent->slide_height; - - *peright = eright; *pebottom = ebottom; - *pmw = mw; *pmh = mh; - - max_width = mw - o->base.style->margin_left - - o->base.style->margin_right; - - - /* Use the provided maximum width if it exists and is smaller */ - if ( o->base.style->use_max_width - && (o->base.style->max_width < max_width) ) - { - max_width = o->base.style->max_width; - } - - max_height = mh - o->base.style->margin_top - - o->base.style->margin_bottom; - - pango_layout_set_width(o->layout, max_width*PANGO_SCALE); - pango_layout_set_height(o->layout, max_height*PANGO_SCALE); - pango_layout_set_wrap(o->layout, PANGO_WRAP_WORD_CHAR); - pango_layout_set_ellipsize(o->layout, PANGO_ELLIPSIZE_MIDDLE); - - switch ( o->base.style->halign ) { - case J_LEFT : - pango_layout_set_alignment(o->layout, PANGO_ALIGN_LEFT); - break; - case J_RIGHT : - pango_layout_set_alignment(o->layout, PANGO_ALIGN_RIGHT); - break; - case J_CENTER : - pango_layout_set_alignment(o->layout, PANGO_ALIGN_CENTER); - break; - } -} - - -static void calculate_position_from_style(struct text_object *o, - double eright, double ebottom, - double mw, double mh) -{ - double xo, yo; - - xo = o->base.bb_width; yo = o->base.bb_height; - - switch ( o->base.style->halign ) { - case J_LEFT : - o->base.x = o->base.style->margin_left; - break; - case J_RIGHT : - o->base.x = eright - xo; - break; - case J_CENTER : - o->base.x = mw/2.0 - xo/2.0 + o->base.style->offset_x; - break; - } - - /* Correct if centering crashes into opposite margin */ - if ( o->base.style->halign == J_CENTER ) - { - if ( o->base.x < o->base.style->margin_left ) { - o->base.x = o->base.style->margin_left; - } - - if ( o->base.x + xo > eright ) { - o->base.x = eright - xo; - } - } - - switch ( o->base.style->valign ) { - case V_TOP : - o->base.y = o->base.style->margin_top; - break; - case V_BOTTOM : - o->base.y = ebottom - yo; - break; - case V_CENTER : - o->base.y = mh/2.0 - yo/2.0 + o->base.style->offset_y; - break; - } - - if ( o->base.style->valign == V_CENTER ) { - - if ( o->base.y < o->base.style->margin_top ) { - o->base.y = o->base.style->margin_top; - } - - if ( o->base.y+yo + yo > ebottom ) - { - o->base.y = ebottom - yo; - } - } -} - - -static void update_text(struct text_object *o, cairo_t *cr) -{ - PangoRectangle logical; - double eright = 0.0; - double ebottom = 0.0; - double mw = 0.0; - double mh = 0.0; - struct object *ex; - struct text_object *ext; - - switch ( o->base.style->role ) { - - case S_ROLE_SLIDENUMBER: - if ( o->text_len < 32 ) { - free(o->text); - o->text = malloc(32); - o->text_len = 32; - } - snprintf(o->text, o->text_len-1, "Slide %i", - 1+slide_number(o->base.parent->parent, o->base.parent)); - break; - - case S_ROLE_PTITLE: - ex = o->base.parent->roles[S_ROLE_PTITLE_REF]; - ext = (struct text_object *)ex; - if ( (ext != NULL) && (ext->text != NULL) ) { - free(o->text); - o->text = strdup(ext->text); - o->text_len = strlen(o->text); - } - if ( ext == NULL ) { - free(o->text); - o->text = strdup(""); - o->text_len = strlen(o->text); - } - break; - - case S_ROLE_PDATE: - ex = o->base.parent->roles[S_ROLE_PDATE_REF]; - ext = (struct text_object *)ex; - if ( (ext != NULL) && (ext->text != NULL) ) { - free(o->text); - o->text = strdup(ext->text); - o->text_len = strlen(o->text); - } - if ( ext == NULL ) { - free(o->text); - o->text = strdup(""); - o->text_len = strlen(o->text); - } - break; - - default: - break; - - } - - if ( o->layout == NULL ) { - if ( *o->pc != NULL ) { - o->layout = pango_layout_new(*o->pc); - } else { - /* Can't render yet */ - return; - } - } - - if ( cr != NULL ) pango_cairo_update_layout(cr, o->layout); - - o->furniture = o->base.style != o->base.parent->parent->ss->styles[0]; - - pango_layout_set_text(o->layout, o->text, -1); - o->fontdesc = pango_font_description_from_string(o->base.style->font); - pango_layout_set_font_description(o->layout, o->fontdesc); - - if ( o->furniture ) { - - calculate_size_from_style(o, &eright, &ebottom, &mw, &mh); - - pango_layout_get_extents(o->layout, NULL, &logical); - - o->base.bb_width = logical.width / PANGO_SCALE; - o->base.bb_height = logical.height / PANGO_SCALE; - o->offs_x = logical.x / PANGO_SCALE; - o->offs_y = logical.y / PANGO_SCALE; - - } else { - - pango_layout_set_width(o->layout, - o->base.bb_width*PANGO_SCALE); - pango_layout_set_height(o->layout, - o->base.bb_height*PANGO_SCALE); - pango_layout_set_wrap(o->layout, PANGO_WRAP_WORD_CHAR); - pango_layout_set_ellipsize(o->layout, PANGO_ELLIPSIZE_MIDDLE); - - } - - if ( o->furniture ) { - calculate_position_from_style(o, eright, ebottom, mw, mh); - } -} - - -void insert_text(struct object *op, char *t) -{ - struct text_object *o = (struct text_object *)op; - char *tmp; - size_t tlen, olen, offs; - int i; - - assert(o->base.type == OBJ_TEXT); - tlen = strlen(t); - olen = strlen(o->text); - - if ( tlen + olen + 1 > o->text_len ) { - - char *try; - - try = realloc(o->text, o->text_len + tlen + 64); - if ( try == NULL ) return; /* Failed to insert */ - o->text = try; - o->text_len += 64; - o->text_len += tlen; - - } - - tmp = malloc(o->text_len); - if ( tmp == NULL ) return; - - offs = o->insertion_point + o->insertion_trail; - - for ( i=0; itext[i]; - } - for ( i=0; iinsertion_point; i++ ) { - tmp[i+offs+tlen] = o->text[i+offs]; - } - tmp[olen+tlen] = '\0'; - memcpy(o->text, tmp, o->text_len); - free(tmp); - - redraw_slide(op->parent); - o->insertion_point += tlen; - o->base.empty = 0; -} - - -void move_cursor(struct object *op, int dir) -{ - struct text_object *o = (struct text_object *)op; - int new_idx, new_trail; - - pango_layout_move_cursor_visually(o->layout, TRUE, o->insertion_point, - o->insertion_trail, - dir, &new_idx, &new_trail); - - if ( (new_idx >= 0) && (new_idx < G_MAXINT) ) { - o->insertion_point = new_idx; - o->insertion_trail = new_trail; - } -} - - -void move_cursor_left(struct object *op) -{ - move_cursor(op, -1); - redraw_overlay(op->parent->parent); -} - - -void move_cursor_right(struct object *op) -{ - move_cursor(op, +1); - redraw_overlay(op->parent->parent); -} - - -void handle_text_backspace(struct object *op) -{ - int old_idx, new_idx; - struct text_object *o = (struct text_object *)op; - - assert(o->base.type == OBJ_TEXT); - - if ( o->insertion_point == 0 ) return; /* Nothing to delete */ - - old_idx = o->insertion_point + o->insertion_trail; - move_cursor_left(op); - new_idx = o->insertion_point + o->insertion_trail; - - memmove(o->text+new_idx, o->text+old_idx, - o->text_len-new_idx); - - if ( strlen(o->text) == 0 ) o->base.empty = 1; - - redraw_slide(op->parent); -} - - -static void render_text_object(cairo_t *cr, struct object *op) -{ - struct text_object *o = (struct text_object *)op; - GdkColor col; - - if ( o->layout == NULL ) { - return; - } - - update_text(o, cr); - - cairo_move_to(cr, o->base.x - o->offs_x, o->base.y - o->offs_y); - gdk_color_parse(o->base.style->colour, &col); - gdk_cairo_set_source_color(cr, &col); /* FIXME: Honour alpha as well */ - pango_cairo_show_layout(cr, o->layout); -} - - -static void draw_caret(cairo_t *cr, struct text_object *o) -{ - double xposd, yposd, cx; - double clow, chigh; - PangoRectangle pos; - const double t = 1.8; - - assert(o->base.type == OBJ_TEXT); - - pango_layout_get_cursor_pos(o->layout, - o->insertion_point+o->insertion_trail, - &pos, NULL); - - xposd = pos.x/PANGO_SCALE; - cx = o->base.x - o->offs_x + xposd; - yposd = pos.y/PANGO_SCALE; - clow = o->base.y - o->offs_y + yposd; - chigh = clow + (pos.height/PANGO_SCALE); - - cairo_move_to(cr, cx, clow); - cairo_line_to(cr, cx, chigh); - - cairo_move_to(cr, cx-t, clow-t); - cairo_line_to(cr, cx, clow); - cairo_move_to(cr, cx+t, clow-t); - cairo_line_to(cr, cx, clow); - - cairo_move_to(cr, cx-t, chigh+t); - cairo_line_to(cr, cx, chigh); - cairo_move_to(cr, cx+t, chigh+t); - cairo_line_to(cr, cx, chigh); - - cairo_set_source_rgb(cr, 0.86, 0.0, 0.0); - cairo_set_line_width(cr, 1.0); - cairo_stroke(cr); -} - - -static void update_text_object(struct object *op) -{ - struct text_object *o = (struct text_object *)op; - update_text(o, NULL); -} - - -static void delete_text_object(struct object *op) -{ - struct text_object *o = (struct text_object *)op; - - if ( o->layout != NULL ) g_object_unref(o->layout); - if ( o->fontdesc != NULL ) pango_font_description_free(o->fontdesc); -} - - -static void serialize(struct object *op, struct serializer *ser) -{ - struct text_object *o = (struct text_object *)op; - - serialize_s(ser, "style", op->style->name); - if ( op->style == op->parent->parent->ss->styles[0] ) { - serialize_f(ser, "x", op->x); - serialize_f(ser, "y", op->y); - serialize_f(ser, "w", op->bb_width); - serialize_f(ser, "h", op->bb_height); - } - - serialize_s(ser, "text", o->text); -} - - -static struct object *new_text_object(double x, double y, struct style *sty, - struct text_toolinfo *ti) -{ - struct text_object *new; - - new = calloc(1, sizeof(*new)); - if ( new == NULL ) return NULL; - - /* Base properties */ - new->base.x = x; new->base.y = y; - new->base.bb_width = 10.0; - new->base.bb_height = 40.0; - new->base.type = OBJ_TEXT; - new->base.empty = 1; - new->base.parent = NULL; - new->base.style = sty; - - /* Text-specific stuff */ - new->text = malloc(1); - new->text[0] = '\0'; - new->text_len = 1; - new->insertion_point = 0; - new->insertion_trail = 0; - if ( ti->pc != NULL ) { - new->layout = pango_layout_new(ti->pc); - new->pc = NULL; - } else { - new->layout = NULL; - new->pc = &ti->pc; - } - new->fontdesc = NULL; - - /* Methods for this object */ - new->base.render_object = render_text_object; - new->base.delete_object = delete_text_object; - new->base.update_object = update_text_object; - new->base.serialize = serialize; - - return (struct object *)new; -} - - -static struct object *add_text_object(struct slide *s, double x, double y, - struct style *sty, - struct text_toolinfo *ti) -{ - struct object *o; - - o = new_text_object(x, y, sty, ti); - - if ( add_object_to_slide(s, o) ) { - delete_object(o); - return NULL; - } - - redraw_slide(o->parent); - - return o; -} - - -static void calculate_box_size(struct object *o, double x, double y, - struct text_toolinfo *ti) -{ - double ddx, ddy; - - ddx = x - ti->drag_initial_x; - ddy = y - ti->drag_initial_y; - - switch ( ti->drag_corner ) { - - case CORNER_BR : - ti->box_x = o->x; - ti->box_y = o->y; - ti->box_width = o->bb_width + ddx; - ti->box_height = o->bb_height + ddy; - break; - - case CORNER_BL : - ti->box_x = o->x + ddx; - ti->box_y = o->y; - ti->box_width = o->bb_width - ddx; - ti->box_height = o->bb_height + ddy; - break; - - case CORNER_TL : - ti->box_x = o->x + ddx; - ti->box_y = o->y + ddy; - ti->box_width = o->bb_width - ddx; - ti->box_height = o->bb_height - ddy; - break; - - case CORNER_TR : - ti->box_x = o->x; - ti->box_y = o->y + ddy; - ti->box_width = o->bb_width + ddx; - ti->box_height = o->bb_height - ddy; - break; - - case CORNER_NONE : - break; - - } - - if ( ti->box_width < 20.0 ) ti->box_width = 20.0; - if ( ti->box_height < 20.0 ) ti->box_height = 20.0; -} - - -static void click_select(struct presentation *p, struct toolinfo *tip, - double x, double y, GdkEventButton *event, - enum drag_status *drag_status, - enum drag_reason *drag_reason) -{ - int xp, yp; - double xo, yo; - gboolean v; - enum corner c; - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - struct text_object *o = (struct text_object *)p->editing_object; - int idx, trail; - - assert(o->base.type == OBJ_TEXT); - - xo = x - o->base.x; yo = y - o->base.y; - - /* Within the resizing region? */ - c = which_corner(x, y, &o->base); - if ( (c != CORNER_NONE) && !o->furniture ) - { - ti->drag_reason = TEXT_DRAG_REASON_RESIZE; - ti->drag_corner = c; - - ti->drag_initial_x = x; - ti->drag_initial_y = y; - - calculate_box_size((struct object *)o, x, y, ti); - - /* Tell the MCP what we did, and return */ - *drag_status = DRAG_STATUS_DRAGGING; - *drag_reason = DRAG_REASON_TOOL; - return; - } - - xp = (xo + o->offs_x)*PANGO_SCALE; - yp = (yo + o->offs_y)*PANGO_SCALE; - - v = pango_layout_xy_to_index(o->layout, xp, yp, &idx, &trail); - - o->insertion_point = idx; - o->insertion_trail = trail; -} - - -static void drag(struct toolinfo *tip, struct presentation *p, - struct object *o, double x, double y) -{ - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - - if ( ti->drag_reason == TEXT_DRAG_REASON_RESIZE ) { - - calculate_box_size(o, x, y, ti); - redraw_overlay(p); - - } -} - - -static void end_drag(struct toolinfo *tip, struct presentation *p, - struct object *o, double x, double y) -{ - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - - calculate_box_size((struct object *)o, x, y, ti); - - o->x = ti->box_x; - o->y = ti->box_y; - o->bb_width = ti->box_width; - o->bb_height = ti->box_height; - update_text((struct text_object *)o, NULL); - redraw_slide(o->parent); - - ti->drag_reason = TEXT_DRAG_REASON_NONE; -} - - -static void update_subsequent_refs(struct presentation *p, int start, - enum object_role role, struct object *o) -{ - int i; - - for ( i=start; inum_slides; i++ ) - { - struct slide *s = p->slides[i]; - s->roles[role] = o; - } -} - - -static void create_default(struct presentation *p, struct style *sty, - struct slide *s, struct toolinfo *tip) -{ - struct object *n; - struct text_object *o; - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - - n = add_text_object(s, 0.0, 0.0, sty, ti); - o = (struct text_object *)n; - o->furniture = 1; - n->empty = 0; - - if ( sty->role != S_ROLE_NONE ) { - s->roles[sty->role] = n; - } - - switch ( sty->role ) - { - case S_ROLE_SLIDENUMBER: - case S_ROLE_PTITLE: - case S_ROLE_PAUTHOR: - case S_ROLE_PDATE: - break; - - default: - p->editing_object = n; - break; - } - - /* If we just created a new presentation title (etc), set this object as - * the presentation title reference for all subsequent slides. - * Any relevant objects will get updated when the current object gets - * deselected. */ - if ( sty->role == S_ROLE_PTITLE_REF ) { - update_subsequent_refs(p, slide_number(p, s)+1, - S_ROLE_PTITLE_REF, n); - } - if ( sty->role == S_ROLE_PAUTHOR_REF ) { - update_subsequent_refs(p, slide_number(p, s)+1, - S_ROLE_PAUTHOR_REF, n); - } - if ( sty->role == S_ROLE_PDATE_REF ) { - update_subsequent_refs(p, slide_number(p, s)+1, - S_ROLE_PDATE_REF, n); - } - - redraw_slide(((struct object *)o)->parent); -} - - -static void create_region(struct toolinfo *tip, struct presentation *p, - double x1, double y1, double x2, double y2) -{ - struct object *n; - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - struct text_object *o; - - n = add_text_object(p->cur_edit_slide, 0.0, 0.0, p->ss->styles[0], ti); - n->x = x1y = y1bb_width = fabs(x1-x2); - n->bb_height = fabs(y1-y2); - - o = (struct text_object *)n; - o->furniture = 0; - - redraw_slide(((struct object *)o)->parent); - p->editing_object = n; -} - - -static void select_object(struct object *o, struct toolinfo *tip) -{ - /* Do nothing */ -} - - -static void update_subsequent(struct presentation *p, int start, - enum object_role role, struct object *o) -{ - int i; - - for ( i=start; inum_slides; i++ ) { - - struct slide *s = p->slides[i]; - - if ( s->roles[role] != NULL ) { - s->roles[role]->update_object(s->roles[role]); - } - } -} - - -static int deselect_object(struct object *o, struct toolinfo *tip) -{ - struct slide *s; - struct presentation *p; - - if ( o == NULL ) return 0; - - s = o->parent; - p = s->parent; - - if ( o->empty ) { - delete_object(o); - return 1; - } - - if ( o->style->role == S_ROLE_PTITLE_REF ) { - update_subsequent(p, slide_number(p, s)+1, S_ROLE_PTITLE, o); - } - if ( o->style->role == S_ROLE_PAUTHOR_REF ) { - update_subsequent(p, slide_number(p, s)+1, S_ROLE_PAUTHOR, o); - } - if ( o->style->role == S_ROLE_PDATE_REF ) { - update_subsequent(p, slide_number(p, s)+1, S_ROLE_PDATE, o); - } - - return 0; -} - - -static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *n) -{ - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - struct text_object *o = (struct text_object *)n; - - if ( n != NULL ) { - - draw_editing_box(cr, n->x, n->y, n->bb_width, n->bb_height); - - if ( !o->furniture ) { - - /* Draw resize handles */ - draw_resize_handle(cr, n->x, n->y+n->bb_height-20.0); - draw_resize_handle(cr, n->x+n->bb_width-20.0, n->y); - draw_resize_handle(cr, n->x, n->y); - draw_resize_handle(cr, n->x+n->bb_width-20.0, - n->y+n->bb_height-20.0); - - } - - draw_caret(cr, o); - } - - if ( ti->drag_reason == TEXT_DRAG_REASON_RESIZE ) { - draw_rubberband_box(cr, ti->box_x, ti->box_y, - ti->box_width, ti->box_height); - } - -} - - -static void key_pressed(struct object *o, guint keyval, struct toolinfo *tip) -{ - if ( o == NULL ) return; - - switch ( keyval ) { - - case GDK_KEY_BackSpace : - handle_text_backspace(o); - break; - - case GDK_KEY_Left : - move_cursor_left(o); - break; - - case GDK_KEY_Right : - move_cursor_right(o); - break; - - } -} - - -static void im_commit(struct object *o, gchar *str, struct toolinfo *tip) -{ - insert_text(o, str); -} - - -static int valid_object(struct object *o) -{ - if ( o->type == OBJ_TEXT ) return 1; - return 0; -} - - -static void realise(struct toolinfo *ti, GtkWidget *w, struct presentation *p) -{ - struct text_toolinfo *tip = (struct text_toolinfo *)ti; - tip->pc = gtk_widget_get_pango_context(w); - - ti->tbox = gtk_label_new("Text tool"); - g_object_ref(ti->tbox); - gtk_widget_show(ti->tbox); -} - - -static struct object *deserialize(struct presentation *p, struct ds_node *root, - struct toolinfo *tip) -{ - struct object *o; - struct text_object *to; - char *style; - char *text; - struct style *sty; - double x, y, w, h; - struct text_toolinfo *ti = (struct text_toolinfo *)tip; - - if ( get_field_s(root, "style", &style) ) { - fprintf(stderr, "Couldn't find style for object '%s'\n", - root->key); - return NULL; - } - - sty = find_style(p->ss, style); - if ( sty == NULL ) { - fprintf(stderr, "Style '%s' not found in style sheet.\n", - style); - free(style); - return NULL; - } - free(style); - - if ( sty == p->ss->styles[0] ) { - - if ( get_field_f(root, "x", &x) ) { - fprintf(stderr, - "Couldn't find x position for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_f(root, "y", &y) ) { - fprintf(stderr, - "Couldn't find y position for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_f(root, "w", &w) ) { - fprintf(stderr, - "Couldn't find width for object '%s'\n", - root->key); - return NULL; - } - if ( get_field_f(root, "h", &h) ) { - fprintf(stderr, - "Couldn't find height for object '%s'\n", - root->key); - return NULL; - } - - } else { - - /* Furniture */ - x = 0.0; - y = 0.0; - w = 0.0; - h = 0.0; - - } - - o = new_text_object(x, y, sty, ti); - o->bb_width = w; - o->bb_height = h; - - /* Apply the correct text */ - if ( get_field_s(root, "text", &text) ) { - fprintf(stderr, "Couldn't find text for object '%s'\n", - root->key); - return NULL; - } - to = (struct text_object *)o; - free(to->text); - to->text = text; - to->text_len = strlen(text); - o->empty = 0; - - return o; -} - - -struct toolinfo *initialise_text_tool(GtkWidget *w) -{ - struct text_toolinfo *ti; - - ti = malloc(sizeof(*ti)); - - ti->base.click_select = click_select; - ti->base.create_default = create_default; - ti->base.select = select_object; - ti->base.deselect = deselect_object; - ti->base.drag = drag; - ti->base.end_drag = end_drag; - ti->base.create_region = create_region; - ti->base.draw_editing_overlay = draw_overlay; - ti->base.key_pressed = key_pressed; - ti->base.im_commit = im_commit; - ti->base.valid_object = valid_object; - ti->base.realise = realise; - ti->base.deserialize = deserialize; - - ti->pc = NULL; - - ti->drag_reason = DRAG_REASON_NONE; - - return (struct toolinfo *)ti; -} diff --git a/src/tool_text.h b/src/tool_text.h deleted file mode 100644 index aaca10a..0000000 --- a/src/tool_text.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * tool_text.h - * - * Colloquium - A tiny presentation program - * - * Copyright (c) 2011 Thomas White - * - * This program 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 . - * - */ - -#ifndef TOOL_TEXT_H -#define TOOL_TEXT_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - - -extern struct toolinfo *initialise_text_tool(); - - -#endif /* TOOL_TEXT_H */ -- cgit v1.2.3