diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-05-20 23:48:19 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-05-21 22:47:26 +0200 |
commit | 06836da21128e7ce72d06e208b19078e69c70f9c (patch) | |
tree | c607345cdd1f6942fa9572819cf44a6c31f5bbe6 /src/mainwindow.c |
Initial commit
Diffstat (limited to 'src/mainwindow.c')
-rw-r--r-- | src/mainwindow.c | 216 |
1 files changed, 216 insertions, 0 deletions
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; +} |