aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/narrative_window.c104
-rw-r--r--src/pr_clock.c51
-rw-r--r--src/pr_clock.h9
-rw-r--r--src/sc_editor.c41
-rw-r--r--src/sc_editor.h3
-rw-r--r--src/slideshow.c4
6 files changed, 108 insertions, 104 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index d1aa5f0..dd62cd6 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -51,16 +51,17 @@ struct _narrative_window
GApplication *app;
struct presentation *p;
SlideShow *show;
+ PRClock *pr_clock;
SCBlock *sel_slide;
};
static void update_toolbar(NarrativeWindow *nw)
{
- int cur_slide_number;
+ int cur_para;
- cur_slide_number = slide_number(nw->p, nw->sel_slide);
- if ( cur_slide_number == 0 ) {
+ cur_para = sc_editor_get_cursor_para(nw->sceditor);
+ if ( cur_para == 0 ) {
gtk_widget_set_sensitive(GTK_WIDGET(nw->bfirst), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(nw->bprev), FALSE);
} else {
@@ -68,7 +69,7 @@ static void update_toolbar(NarrativeWindow *nw)
gtk_widget_set_sensitive(GTK_WIDGET(nw->bprev), TRUE);
}
- if ( cur_slide_number == num_slides(nw->p)-1 ) {
+ if ( cur_para == sc_editor_get_num_paras(nw->sceditor) ) {
gtk_widget_set_sensitive(GTK_WIDGET(nw->bnext), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(nw->blast), FALSE);
} else {
@@ -175,79 +176,57 @@ static void ss_end_show(SlideShow *ss, void *vp)
}
-static void ss_next_slide(SlideShow *ss, void *vp)
+static void first_para_sig(GSimpleAction *action, GVariant *parameter,
+ gpointer vp)
{
NarrativeWindow *nw = vp;
- SCBlock *tt;
-
- tt = next_slide(nw->p, nw->sel_slide);
- if ( tt == NULL ) return; /* Already on last slide */
- nw->sel_slide = tt;
- if ( slideshow_linked(nw->show) ) {
- change_proj_slide(nw->show, nw->sel_slide);
- } /* else leave the slideshow alone */
+ sc_editor_set_cursor_para(nw->sceditor, 0);
update_toolbar(nw);
}
-static void ss_prev_slide(SlideShow *ss, void *vp)
+static void ss_prev_para(SlideShow *ss, void *vp)
{
NarrativeWindow *nw = vp;
- SCBlock *tt;
-
- tt = prev_slide(nw->p, nw->sel_slide);
- if ( tt == NULL ) return; /* Already on first slide */
- nw->sel_slide = tt;
- if ( slideshow_linked(nw->show) ) {
- change_proj_slide(nw->show, nw->sel_slide);
- } /* else leave the slideshow alone */
- update_toolbar(nw);
+ if ( sc_editor_get_cursor_para(nw->sceditor) == 0 ) return;
+ sc_editor_set_cursor_para(nw->sceditor,
+ sc_editor_get_cursor_para(nw->sceditor)-1);
+ pr_clock_set_pos(nw->pr_clock, sc_editor_get_cursor_para(nw->sceditor),
+ sc_editor_get_num_paras(nw->sceditor));
}
-static void first_slide_sig(GSimpleAction *action, GVariant *parameter,
- gpointer vp)
+static void prev_para_sig(GSimpleAction *action, GVariant *parameter,
+ gpointer vp)
{
NarrativeWindow *nw = vp;
- SCBlock *tt;
-
- tt = first_slide(nw->p);
- if ( tt == NULL ) return; /* Fail */
- nw->sel_slide = tt;
- if ( slideshow_linked(nw->show) ) {
- change_proj_slide(nw->show, nw->sel_slide);
- } /* else leave the slideshow alone */
- update_toolbar(nw);
+ ss_prev_para(nw->show, nw);
}
-static void prev_slide_sig(GSimpleAction *action, GVariant *parameter,
- gpointer vp)
+static void ss_next_para(SlideShow *ss, void *vp)
{
- ss_prev_slide(NULL, vp);
+ NarrativeWindow *nw = vp;
+ sc_editor_set_cursor_para(nw->sceditor,
+ sc_editor_get_cursor_para(nw->sceditor)+1);
+ pr_clock_set_pos(nw->pr_clock, sc_editor_get_cursor_para(nw->sceditor),
+ sc_editor_get_num_paras(nw->sceditor));
}
-static void next_slide_sig(GSimpleAction *action, GVariant *parameter,
- gpointer vp)
+static void next_para_sig(GSimpleAction *action, GVariant *parameter,
+ gpointer vp)
{
- ss_next_slide(NULL, vp);
+ NarrativeWindow *nw = vp;
+ ss_next_para(nw->show, nw);
}
-static void last_slide_sig(GSimpleAction *action, GVariant *parameter,
- gpointer vp)
+static void last_para_sig(GSimpleAction *action, GVariant *parameter,
+ gpointer vp)
{
NarrativeWindow *nw = vp;
- SCBlock *tt;
-
- tt = last_slide(nw->p);
- if ( tt == NULL ) return; /* Fail */
- nw->sel_slide = tt;
- if ( slideshow_linked(nw->show) ) {
- change_proj_slide(nw->show, nw->sel_slide);
- } /* else leave the slideshow alone */
- update_toolbar(nw);
+ sc_editor_set_cursor_para(nw->sceditor, -1);
}
@@ -271,17 +250,18 @@ static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter,
if ( num_slides(nw->p) == 0 ) return;
- ssc.next_slide = ss_next_slide;
- ssc.prev_slide = ss_prev_slide;
+ ssc.next_slide = ss_next_para;
+ ssc.prev_slide = ss_prev_para;
ssc.current_slide = ss_cur_slide;
ssc.changed_link = ss_changed_link;
ssc.end_show = ss_end_show;
nw->sel_slide = first_slide(nw->p);
-
nw->show = try_start_slideshow(nw->p, ssc, nw);
+
if ( nw->show != NULL ) {
sc_editor_set_para_highlight(nw->sceditor, 1);
+ sc_editor_set_cursor_para(nw->sceditor, 0);
}
}
@@ -294,7 +274,7 @@ static void open_notes_sig(GSimpleAction *action, GVariant *parameter, gpointer
static void open_clock_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
{
NarrativeWindow *nw = vp;
- open_clock(nw->p);
+ nw->pr_clock = pr_clock_new();
}
@@ -356,10 +336,10 @@ GActionEntry nw_entries[] = {
{ "notes", open_notes_sig, NULL, NULL, NULL },
{ "clock", open_clock_sig, NULL, NULL, NULL },
{ "testcard", testcard_sig, NULL, NULL, NULL },
- { "first", first_slide_sig, NULL, NULL, NULL },
- { "prev", prev_slide_sig, NULL, NULL, NULL },
- { "next", next_slide_sig, NULL, NULL, NULL },
- { "last", last_slide_sig, NULL, NULL, NULL },
+ { "first", first_para_sig, NULL, NULL, NULL },
+ { "prev", prev_para_sig, NULL, NULL, NULL },
+ { "next", next_para_sig, NULL, NULL, NULL },
+ { "last", last_para_sig, NULL, NULL, NULL },
};
@@ -410,14 +390,14 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
case GDK_KEY_Page_Up :
if ( nw->show != NULL ) {
- ss_prev_slide(nw->show, nw);
+ ss_prev_para(nw->show, nw);
return TRUE;
}
break;
case GDK_KEY_Page_Down :
if ( nw->show != NULL) {
- ss_next_slide(nw->show, nw);
+ ss_next_para(nw->show, nw);
return TRUE;
}
break;
@@ -631,6 +611,8 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
gtk_window_set_default_size(GTK_WINDOW(nw->window), 768, 768);
gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
+ gtk_container_set_focus_child(GTK_CONTAINER(nw->window),
+ GTK_WIDGET(nw->sceditor));
gtk_widget_show_all(nw->window);
nw->app = app;
diff --git a/src/pr_clock.c b/src/pr_clock.c
index f48478d..db661d7 100644
--- a/src/pr_clock.c
+++ b/src/pr_clock.c
@@ -31,6 +31,7 @@
#include <gtk/gtk.h>
#include "presentation.h"
+#include "pr_clock.h"
struct pr_clock
@@ -53,9 +54,9 @@ struct pr_clock
int running;
double time_allowed;
double time_elapsed;
- int slide_reached;
- int last_slide;
- int cur_slide;
+ int pos;
+ int end;
+ int pos_reached;
double t;
double tf;
@@ -181,8 +182,8 @@ static gboolean update_clock(gpointer data)
if ( n->time_allowed == 0.0 ) n->t = 0.0;
if ( n->time_elapsed > n->time_allowed ) n->t = 1.0;
- if ( n->last_slide > 0 ) {
- n->tf = (double)n->slide_reached / (n->last_slide-1);
+ if ( n->end > 0 ) {
+ n->tf = (double)n->pos_reached / (n->end-1);
} else {
n->tf = 0.0;
}
@@ -200,19 +201,14 @@ static gboolean update_clock(gpointer data)
}
-void notify_clock_slide_changed(struct presentation *p, SCBlock *np)
+void pr_clock_set_pos(PRClock *n, int pos, int end)
{
- struct pr_clock *n = p->clock;
- int sr;
-
if ( n == NULL ) return;
-
- sr = slide_number(p, np);
- n->cur_slide = sr;
- n->last_slide = num_slides(p);
-
- if ( sr > n->slide_reached ) n->slide_reached = sr;
-
+ n->pos = pos;
+ if ( n->pos > n->pos_reached ) {
+ n->pos_reached = pos;
+ }
+ n->end = end;
update_clock(n);
}
@@ -254,8 +250,8 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct pr_clock *n)
cairo_fill(cr);
}
- ff = (double)n->cur_slide / (n->last_slide-1);
- if ( n->last_slide == 1 ) ff = 0.0;
+ ff = (double)n->pos / (n->end-1);
+ if ( n->end == 1 ) ff = 0.0;
cairo_move_to(cr, 10.0+ff*s, 0.0);
cairo_line_to(cr, 10.0+ff*s, height);
cairo_set_line_width(cr, 2.0);
@@ -298,7 +294,6 @@ static gboolean reset_sig(GtkWidget *w, gpointer data)
n->time_elapsed = 0;
n->time_elapsed_at_start = 0;
- n->slide_reached = n->cur_slide;
if ( n->start != NULL ) {
g_date_time_unref(n->start);
@@ -315,11 +310,7 @@ static gboolean reset_sig(GtkWidget *w, gpointer data)
static gboolean setpos_sig(GtkWidget *w, gpointer data)
{
struct pr_clock *n = data;
-
- n->slide_reached = n->cur_slide;
-
update_clock(n);
-
return FALSE;
}
@@ -350,7 +341,7 @@ static gboolean start_sig(GtkWidget *w, gpointer data)
}
-void open_clock(struct presentation *p)
+PRClock *pr_clock_new()
{
struct pr_clock *n;
GtkWidget *vbox;
@@ -360,11 +351,8 @@ void open_clock(struct presentation *p)
GtkWidget *grid;
GtkWidget *label;
- if ( p->clock != NULL ) return; /* Already open */
-
n = malloc(sizeof(struct pr_clock));
- if ( n == NULL ) return;
- p->clock = n;
+ if ( n == NULL ) return NULL;
n->open = 1;
n->tz = g_time_zone_new_local();
@@ -399,7 +387,7 @@ void open_clock(struct presentation *p)
gtk_box_pack_start(GTK_BOX(vbox), n->da, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(n->da), "draw", G_CALLBACK(draw_sig), n);
g_signal_connect(G_OBJECT(n->window), "destroy",
- G_CALLBACK(close_clock_sig), p);
+ G_CALLBACK(close_clock_sig), n); /* FIXME: Uniqueness */
grid = gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
@@ -433,8 +421,8 @@ void open_clock(struct presentation *p)
n->time_allowed = 0;
n->time_elapsed = 0;
n->time_elapsed_at_start = 0;
- n->slide_reached = 0;
- n->last_slide = 0;
+ n->pos = 0;
+ n->end = 0;
n->start = NULL;
update_clock(n);
g_timeout_add_seconds(1, update_clock, n);
@@ -442,4 +430,5 @@ void open_clock(struct presentation *p)
gtk_window_set_title(GTK_WINDOW(n->window), "Presentation clock");
gtk_widget_show_all(n->window);
+ return n;
}
diff --git a/src/pr_clock.h b/src/pr_clock.h
index 919d61b..eb6033f 100644
--- a/src/pr_clock.h
+++ b/src/pr_clock.h
@@ -1,6 +1,6 @@
/*
* pr_clock.h
- *
+ *
* Copyright © 2013-2016 Thomas White <taw@bitwiz.org.uk>
*
* This file is part of Colloquium.
@@ -27,12 +27,11 @@
#include <config.h>
#endif
-struct pr_clock;
+typedef struct pr_clock PRClock;
-extern void open_clock(struct presentation *p);
+extern PRClock *pr_clock_new(void);
-extern void notify_clock_slide_changed(struct presentation *p,
- SCBlock *np);
+extern void pr_clock_set_pos(PRClock *n, int pos, int end);
#endif /* CLOCK_H */
diff --git a/src/sc_editor.c b/src/sc_editor.c
index beb1d5a..9980866 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -422,6 +422,7 @@ static void draw_caret(cairo_t *cr, struct frame *fr, int cursor_para,
cairo_set_source_rgba(cr, 0.7, 0.7, 1.0, 0.5);
cairo_set_line_width(cr, 5.0);
cairo_stroke(cr);
+ return;
}
if ( get_cursor_pos(fr, cursor_para, cursor_pos+cursor_trail,
@@ -1170,9 +1171,11 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
switch ( event->keyval ) {
case GDK_KEY_Escape :
- sc_editor_remove_cursor(e);
- sc_editor_redraw(e);
- claim = 1;
+ if ( !e->para_highlight ) {
+ sc_editor_remove_cursor(e);
+ sc_editor_redraw(e);
+ claim = 1;
+ }
break;
case GDK_KEY_Left :
@@ -1598,6 +1601,38 @@ void sc_editor_set_para_highlight(SCEditor *e, int para_highlight)
sc_editor_redraw(e);
}
+int sc_editor_get_cursor_para(SCEditor *e)
+{
+ if ( e->cursor_frame == NULL ) return 0;
+ return e->cursor_para;
+}
+
+
+void sc_editor_set_cursor_para(SCEditor *e, signed int pos)
+{
+ if ( e->cursor_frame == NULL ) {
+ e->cursor_frame = e->top;
+ e->selection = e->top;
+ }
+
+ if ( pos < 0 ) {
+ e->cursor_para = e->cursor_frame->n_paras;
+ } else if ( pos >= e->cursor_frame->n_paras ) {
+ e->cursor_para = e->cursor_frame->n_paras - 1;
+ } else {
+ e->cursor_para = pos;
+ }
+ e->cursor_pos = 0;
+ sc_editor_redraw(e);
+}
+
+
+int sc_editor_get_num_paras(SCEditor *e)
+{
+ if ( e->cursor_frame == NULL ) return 1;
+ return e->cursor_frame->n_paras;
+}
+
SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets,
PangoLanguage *lang)
diff --git a/src/sc_editor.h b/src/sc_editor.h
index a2a9b38..cef3423 100644
--- a/src/sc_editor.h
+++ b/src/sc_editor.h
@@ -183,5 +183,8 @@ extern void sc_editor_remove_cursor(SCEditor *e);
extern SCBlock *split_paragraph_at_cursor(SCEditor *e);
extern void sc_editor_set_para_highlight(SCEditor *e, int para_highlight);
+extern int sc_editor_get_cursor_para(SCEditor *e);
+extern void sc_editor_set_cursor_para(SCEditor *e, signed int pos);
+extern int sc_editor_get_num_paras(SCEditor *e);
#endif /* SC_EDITOR_H */
diff --git a/src/slideshow.c b/src/slideshow.c
index 8bcb2f7..2f84cc7 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -142,8 +142,6 @@ void change_proj_slide(SlideShow *ss, SCBlock *np)
{
ss->cur_slide = np;
- notify_clock_slide_changed(ss->p, np);
-
slideshow_rerender(ss);
redraw_slideshow(ss);
}
@@ -317,8 +315,6 @@ SlideShow *try_start_slideshow(struct presentation *p,
if ( ss->inhibit != NULL ) do_inhibit(ss->inhibit, 1);
- //notify_clock_slide_changed(p, ss->cur_slide); FIXME
-
return ss;
}