aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.c126
-rw-r--r--src/presentation.c38
-rw-r--r--src/presentation.h1
3 files changed, 150 insertions, 15 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 64d854e..c54e6f1 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -87,6 +87,120 @@ static gint about_sig(GtkWidget *widget, struct presentation *p)
}
+static void update_toolbar(struct presentation *p)
+{
+ GtkWidget *d;
+
+ 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);
+
+ if ( p->view_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 ( p->view_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 add_slide_sig(GtkWidget *widget, struct presentation *p)
+{
+ struct slide *new;
+
+ new = add_slide(p, p->view_slide_number);
+ p->view_slide = new;
+ p->view_slide_number++;
+ p->editing_object = NULL;
+
+ update_toolbar(p);
+
+ gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
+ return FALSE;
+}
+
+
+static gint first_slide_sig(GtkWidget *widget, struct presentation *p)
+{
+ p->view_slide_number = 0;
+ p->view_slide = p->slides[0];
+ p->editing_object = NULL;
+
+ update_toolbar(p);
+
+ gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
+ return FALSE;
+}
+
+
+static gint prev_slide_sig(GtkWidget *widget, struct presentation *p)
+{
+ if ( p->view_slide_number == 0 ) return FALSE;
+
+ p->view_slide_number--;
+ p->view_slide = p->slides[p->view_slide_number];
+ p->editing_object = NULL;
+
+ update_toolbar(p);
+
+ gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
+ return FALSE;
+}
+
+
+static gint next_slide_sig(GtkWidget *widget, struct presentation *p)
+{
+ if ( p->view_slide_number == p->num_slides-1 ) return FALSE;
+
+ p->view_slide_number++;
+ p->view_slide = p->slides[p->view_slide_number];
+ p->editing_object = NULL;
+
+ update_toolbar(p);
+
+ gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
+ return FALSE;
+}
+
+
+static gint last_slide_sig(GtkWidget *widget, struct presentation *p)
+{
+ p->view_slide_number = p->num_slides-1;
+ p->view_slide = p->slides[p->view_slide_number];
+ p->editing_object = NULL;
+
+ update_toolbar(p);
+
+ gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
+ return FALSE;
+}
+
+
static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
{
GError *error = NULL;
@@ -101,15 +215,15 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
NULL, NULL, G_CALLBACK(about_sig) },
{ "AddSlideAction", GTK_STOCK_ADD, "Add Slide",
- NULL, NULL, NULL },
+ NULL, NULL, G_CALLBACK(add_slide_sig) },
{ "ButtonFirstSlideAction", GTK_STOCK_GOTO_FIRST, "First Slide",
- NULL, NULL, NULL },
+ NULL, NULL, G_CALLBACK(first_slide_sig) },
{ "ButtonPrevSlideAction", GTK_STOCK_GO_BACK, "Previous Slide",
- NULL, NULL, NULL },
+ NULL, NULL, G_CALLBACK(prev_slide_sig) },
{ "ButtonNextSlideAction", GTK_STOCK_GO_FORWARD, "Next Slide",
- NULL, NULL, NULL },
+ NULL, NULL, G_CALLBACK(next_slide_sig) },
{ "ButtonLastSlideAction", GTK_STOCK_GOTO_LAST, "Last Slide",
- NULL, NULL, NULL },
+ NULL, NULL, G_CALLBACK(last_slide_sig) },
};
guint n_entries = G_N_ELEMENTS(entries);
@@ -130,6 +244,8 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
gtk_window_add_accel_group(GTK_WINDOW(p->window),
gtk_ui_manager_get_accel_group(p->ui));
gtk_ui_manager_ensure_update(p->ui);
+
+ update_toolbar(p);
}
diff --git a/src/presentation.c b/src/presentation.c
index dc4adbc..4dc9e59 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -34,19 +34,14 @@
#include "objects.h"
-struct slide *add_slide(struct presentation *p)
+struct slide *add_slide(struct presentation *p, int pos)
{
struct slide **try;
struct slide *new;
-
- try = realloc(p->slides, (1+p->num_slides)*sizeof(struct slide *));
- if ( try == NULL ) return NULL;
- p->slides = try;
+ int i;
new = malloc(sizeof(struct slide));
if ( new == NULL ) return NULL;
- /* Doesn't matter that p->slides now has some excess space -
- * it'll get corrected the next time a slide is added or deleted. */
/* No objects to start with */
new->num_objects = 0;
@@ -60,8 +55,31 @@ struct slide *add_slide(struct presentation *p)
new->render_cache = NULL;
render_slide(new); /* Render nothing, just to make the surface exist */
- p->slides[p->num_slides++] = new;
- printf("Now %i slides\n", p->num_slides);
+ try = realloc(p->slides, (1+p->num_slides)*sizeof(struct slide *));
+ if ( try == NULL ) {
+ free(new);
+ return NULL;
+ }
+ p->slides = try;
+
+ if ( (p->num_slides>1) && (pos<p->num_slides-1) ) {
+
+ 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;
+ }
+
+ p->num_slides++;
+
return new;
}
@@ -146,7 +164,7 @@ struct presentation *new_presentation()
/* Add one blank slide and view it */
new->num_slides = 0;
new->slides = NULL;
- new -> view_slide = add_slide(new);
+ new->view_slide = add_slide(new, 0);
new->view_slide_number = 0;
new->editing_object = NULL;
diff --git a/src/presentation.h b/src/presentation.h
index 28f324b..a96d215 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -72,6 +72,7 @@ struct presentation
extern struct presentation *new_presentation(void);
+extern struct slide *add_slide(struct presentation *p, int pos);
extern int add_object_to_slide(struct slide *s, struct object *o);
extern void remove_object_from_slide(struct slide *s, struct object *o);
extern struct object *find_object_at_position(struct slide *s,