aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-05-20 23:48:19 +0200
committerThomas White <taw@bitwiz.org.uk>2011-05-21 22:47:26 +0200
commit06836da21128e7ce72d06e208b19078e69c70f9c (patch)
treec607345cdd1f6942fa9572819cf44a6c31f5bbe6 /src
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/colloquium.c86
-rw-r--r--src/mainwindow.c216
-rw-r--r--src/mainwindow.h34
-rw-r--r--src/presentation.c51
-rw-r--r--src/presentation.h52
5 files changed, 439 insertions, 0 deletions
diff --git a/src/colloquium.c b/src/colloquium.c
new file mode 100644
index 0000000..d9dc4d9
--- /dev/null
+++ b/src/colloquium.c
@@ -0,0 +1,86 @@
+/*
+ * colloquium.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <getopt.h>
+
+#include "presentation.h"
+#include "mainwindow.h"
+
+
+static void show_help(const char *s)
+{
+ printf("Syntax: %s [options]\n\n", s);
+ printf(
+"A tiny presentation program.\n"
+"\n"
+" -h, --help Display this help message.\n"
+"\n");
+}
+
+
+int main(int argc, char *argv[])
+{
+ int c;
+ struct presentation *p;
+
+ /* Long options */
+ const struct option longopts[] = {
+ {"help", 0, NULL, 'h'},
+ {0, 0, NULL, 0}
+ };
+
+ gtk_init(&argc, &argv);
+
+ /* Short options */
+ while ((c = getopt_long(argc, argv, "h",
+ longopts, NULL)) != -1) {
+
+ switch (c) {
+ case 'h' :
+ show_help(argv[0]);
+ return 0;
+
+ case 0 :
+ break;
+
+ default :
+ return 1;
+ }
+
+ }
+
+ p = new_presentation();
+ if ( open_mainwindow(p) ) {
+ fprintf(stderr, "Couldn't open main window.\n");
+ return 1;
+ }
+
+ gtk_main();
+
+ return 0;
+}
diff --git a/src/mainwindow.c b/src/mainwindow.c
new file mode 100644
index 0000000..b118328
--- /dev/null
+++ b/src/mainwindow.c
@@ -0,0 +1,216 @@
+/*
+ * mainwindow.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <gtk/gtk.h>
+
+#include "presentation.h"
+#include "mainwindow.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)
+{
+ gtk_main_quit();
+ return 0;
+}
+
+
+static gint about_sig(GtkWidget *widget, struct presentation *p)
+{
+ GtkWidget *window;
+
+ const gchar *authors[] = {
+ "Thomas White <taw@bitwiz.org.uk>",
+ 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 <taw@bitwiz.org.uk>");
+ 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 <taw@bitwiz.org.uk>\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 void add_menu_bar(struct presentation *p, GtkWidget *vbox)
+{
+ GError *error = NULL;
+ GtkActionEntry entries[] = {
+
+ { "FileAction", NULL, "_File", NULL, NULL, NULL },
+ { "QuitAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL,
+ G_CALLBACK(quit_sig) },
+
+ { "HelpAction", NULL, "_Help", NULL, NULL, NULL },
+ { "AboutAction", GTK_STOCK_ABOUT, "_About...",
+ NULL, NULL, G_CALLBACK(about_sig) },
+
+ { "AddSlideAction", GTK_STOCK_ADD, "Add Slide",
+ NULL, NULL, NULL },
+ { "ButtonFirstSlideAction", GTK_STOCK_GOTO_FIRST, "First Slide",
+ NULL, NULL, NULL },
+ { "ButtonPrevSlideAction", GTK_STOCK_GO_BACK, "Previous Slide",
+ NULL, NULL, NULL },
+ { "ButtonNextSlideAction", GTK_STOCK_GO_FORWARD, "Next Slide",
+ NULL, NULL, NULL },
+ { "ButtonLastSlideAction", GTK_STOCK_GOTO_LAST, "Last Slide",
+ NULL, NULL, NULL },
+
+ };
+ 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);
+}
+
+
+static gint close_sig(GtkWidget *window, struct presentation *p)
+{
+ gtk_main_quit();
+ return 0;
+}
+
+
+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);
+ cairo_set_source_rgb(cr, 0.8, 0.8, 1.0);
+ 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;
+
+ cairo_translate(cr, xoff, yoff);
+ cairo_rectangle(cr, 0.0, 0.0, p->slide_width, p->slide_height);
+ cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ cairo_fill(cr);
+
+ cairo_destroy(cr);
+
+ return FALSE;
+}
+
+
+int open_mainwindow(struct presentation *p)
+{
+ GtkWidget *window;
+ GtkWidget *vbox;
+ char *title;
+ GtkWidget *sw;
+
+ if ( p->window != NULL ) {
+ fprintf(stderr, "Presentation window is already open!\n");
+ return 1;
+ }
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ p->window = window;
+
+ title = malloc(strlen(p->titlebar)+14);
+ sprintf(title, "%s - Colloquium", p->titlebar);
+ gtk_window_set_title(GTK_WINDOW(window), title);
+ free(title);
+
+ 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);
+ add_menu_bar(p, 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_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
+ gtk_widget_set_size_request(GTK_WIDGET(p->drawingarea),
+ p->slide_width + 20,
+ p->slide_height + 20);
+
+ g_signal_connect(GTK_OBJECT(p->drawingarea), "expose-event",
+ G_CALLBACK(expose_sig), p);
+
+ gtk_window_set_default_size(GTK_WINDOW(p->window), 1024+100, 768+100);
+ gtk_window_set_resizable(GTK_WINDOW(p->window), TRUE);
+
+ gtk_widget_show_all(window);
+ return 0;
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
new file mode 100644
index 0000000..9b653f9
--- /dev/null
+++ b/src/mainwindow.h
@@ -0,0 +1,34 @@
+/*
+ * presentation.h
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+extern int open_mainwindow(struct presentation *p);
+
+
+#endif /* MAINWINDOW_H */
diff --git a/src/presentation.c b/src/presentation.c
new file mode 100644
index 0000000..8a5dca7
--- /dev/null
+++ b/src/presentation.c
@@ -0,0 +1,51 @@
+/*
+ * presentation.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "presentation.h"
+
+
+struct presentation *new_presentation()
+{
+ struct presentation *new;
+
+ new = malloc(sizeof(struct presentation));
+
+ new->titlebar = strdup("(untitled)");
+ new->filename = NULL;
+
+ new->window = NULL;
+ new->ui = NULL;
+ new->action_group = NULL;
+
+ new->slide_width = 1024.0;
+ new->slide_height = 768.0;
+
+ return new;
+}
diff --git a/src/presentation.h b/src/presentation.h
new file mode 100644
index 0000000..14829c7
--- /dev/null
+++ b/src/presentation.h
@@ -0,0 +1,52 @@
+/*
+ * presentation.h
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef PRESENTATION_H
+#define PRESENTATION_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <gtk/gtk.h>
+
+
+struct presentation
+{
+ char *titlebar;
+ char *filename;
+
+ GtkWidget *window;
+ GtkWidget *drawingarea;
+ GtkUIManager *ui;
+ GtkActionGroup *action_group;
+
+ double slide_width;
+ double slide_height;
+};
+
+
+extern struct presentation *new_presentation(void);
+
+
+#endif /* PRESENTATION_H */