aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-12-26 18:41:41 +0100
committerThomas White <taw@bitwiz.org.uk>2015-12-26 18:41:41 +0100
commit7bc3dc12dd7eb45a8bd28fdf020bcfd802ad91f0 (patch)
tree7895c4f3a06a55dfcac883ec7bcf4090e08c1645 /src
parent79f3fdbb0b6e379c90eb3783d200e6d4249f4a3b (diff)
Open slide window on right slide
Diffstat (limited to 'src')
-rw-r--r--src/narrative_window.c17
-rw-r--r--src/sc_editor.c47
-rw-r--r--src/sc_interp.c19
-rw-r--r--src/sc_interp.h2
-rw-r--r--src/shape.c6
-rw-r--r--src/shape.h4
-rw-r--r--src/slide_window.c18
-rw-r--r--src/slide_window.h2
-rw-r--r--src/wrap.h1
9 files changed, 88 insertions, 28 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index ac4da22..db9adb7 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -321,10 +321,6 @@ GActionEntry nw_entries[] = {
static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
NarrativeWindow *nw)
{
- if ( event->type == GDK_2BUTTON_PRESS ) {
- nw->p->slidewindow = slide_window_open(nw->p, nw->app);
- }
-
return 0;
}
@@ -433,6 +429,17 @@ static cairo_surface_t *render_thumbnail(int w, int h, void *bvp, void *vp)
}
+static int click_thumbnail(double x, double y, void *bvp, void *vp)
+{
+ struct presentation *p = vp;
+ SCBlock *scblocks = bvp;
+
+ slide_window_open(p, scblocks);
+
+ return 0;
+}
+
+
NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
{
NarrativeWindow *nw;
@@ -472,7 +479,7 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
nw->sceditor = sc_editor_new(nw->p->scblocks, stylesheets, p->lang);
cbl = sc_callback_list_new();
sc_callback_list_add_callback(cbl, "sthumb", create_thumbnail,
- render_thumbnail, p);
+ render_thumbnail, click_thumbnail, p);
sc_editor_set_callbacks(nw->sceditor, cbl);
toolbar = gtk_toolbar_new();
diff --git a/src/sc_editor.c b/src/sc_editor.c
index ef48e8d..1e273f5 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -1161,6 +1161,26 @@ static void calculate_box_size(struct frame *fr, SCEditor *e,
}
+static struct wrap_box *cbox(struct frame *fr, int ln, int bn)
+{
+ return &fr->lines[ln].boxes[bn];
+}
+
+
+static int callback_click(SCEditor *e, struct frame *fr, double x, double y)
+{
+ int ln, bn, pn;
+ struct wrap_box *bx;
+
+ find_cursor(fr, x, y, &ln, &bn, &pn);
+ bx = cbox(fr, ln, bn);
+ if ( bx->type == WRAP_BOX_CALLBACK ) {
+ return bx->click_func(x, y, bx->bvp, bx->vp);
+ }
+ return 0;
+}
+
+
static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
SCEditor *e)
{
@@ -1205,17 +1225,26 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
} else {
- e->cursor_frame = clicked;
- find_cursor(clicked, x-fr->x, y-fr->y,
- &e->cursor_line, &e->cursor_box,
- &e->cursor_pos);
+ /* If this is a callback box, check to see if the owner
+ * is interested */
+ if ( !callback_click(e, clicked, x, y) ) {
+
+ /* else position cursor and prepare for possible
+ * drag */
- e->start_corner_x = event->x - e->border_offs_x;
- e->start_corner_y = event->y - e->border_offs_y;
+ e->cursor_frame = clicked;
+ find_cursor(clicked, x-fr->x, y-fr->y,
+ &e->cursor_line, &e->cursor_box,
+ &e->cursor_pos);
+
+ e->start_corner_x = event->x - e->border_offs_x;
+ e->start_corner_y = event->y - e->border_offs_y;
+
+ if ( fr->resizable ) {
+ e->drag_status = DRAG_STATUS_COULD_DRAG;
+ e->drag_reason = DRAG_REASON_MOVE;
+ }
- if ( fr->resizable ) {
- e->drag_status = DRAG_STATUS_COULD_DRAG;
- e->drag_reason = DRAG_REASON_MOVE;
}
}
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 566e8e4..50a582b 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -86,6 +86,7 @@ struct _sccallbacklist
char **names;
SCCallbackBoxFunc *box_funcs;
SCCallbackDrawFunc *draw_funcs;
+ SCCallbackClickFunc *click_funcs;
void **vps;
};
@@ -106,6 +107,9 @@ SCCallbackList *sc_callback_list_new()
cbl->draw_funcs = calloc(8, sizeof(cbl->draw_funcs[0]));
if ( cbl->draw_funcs == NULL ) return NULL;
+ cbl->click_funcs = calloc(8, sizeof(cbl->click_funcs[0]));
+ if ( cbl->click_funcs == NULL ) return NULL;
+
cbl->vps = calloc(8, sizeof(cbl->vps[0]));
if ( cbl->vps == NULL ) return NULL;
@@ -137,12 +141,15 @@ void sc_callback_list_free(SCCallbackList *cbl)
void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
SCCallbackBoxFunc box_func,
- SCCallbackDrawFunc draw_func, void *vp)
+ SCCallbackDrawFunc draw_func,
+ SCCallbackClickFunc click_func,
+ void *vp)
{
if ( cbl->n_callbacks == cbl->max_callbacks ) {
SCCallbackBoxFunc *box_funcs_new;
SCCallbackDrawFunc *draw_funcs_new;
+ SCCallbackClickFunc *click_funcs_new;
char **names_new;
void **vps_new;
int mcn = cbl->max_callbacks + 8;
@@ -152,10 +159,13 @@ void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
mcn*sizeof(SCCallbackBoxFunc));
draw_funcs_new = realloc(cbl->draw_funcs,
mcn*sizeof(SCCallbackDrawFunc));
+ click_funcs_new = realloc(cbl->click_funcs,
+ mcn*sizeof(SCCallbackClickFunc));
vps_new = realloc(cbl->vps, mcn*sizeof(void *));
if ( (names_new == NULL) || (box_funcs_new == NULL)
- || (vps_new == NULL) || (draw_funcs_new == NULL) ) {
+ || (vps_new == NULL) || (draw_funcs_new == NULL)
+ || (click_funcs_new == NULL) ) {
fprintf(stderr, "Failed to grow callback list\n");
return;
}
@@ -163,6 +173,7 @@ void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
cbl->names = names_new;
cbl->box_funcs = box_funcs_new;
cbl->draw_funcs = draw_funcs_new;
+ cbl->click_funcs = click_funcs_new;
cbl->vps = vps_new;
cbl->max_callbacks = mcn;
@@ -171,6 +182,7 @@ void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
cbl->names[cbl->n_callbacks] = strdup(name);
cbl->box_funcs[cbl->n_callbacks] = box_func;
cbl->draw_funcs[cbl->n_callbacks] = draw_func;
+ cbl->click_funcs[cbl->n_callbacks] = click_func;
cbl->vps[cbl->n_callbacks] = vp;
cbl->n_callbacks++;
}
@@ -206,7 +218,8 @@ static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name)
r = cbl->box_funcs[i](scin, bl, &w, &h, &bvp, cbl->vps[i]);
if ( !r ) return;
add_callback_box(sc_interp_get_frame(scin)->boxes, w, h,
- cbl->draw_funcs[i], bvp, cbl->vps[i]);
+ cbl->draw_funcs[i], cbl->click_funcs[i],
+ bvp, cbl->vps[i]);
return;
}
diff --git a/src/sc_interp.h b/src/sc_interp.h
index ec8fe06..e5f4d0a 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -37,6 +37,7 @@ typedef struct _sccallbacklist SCCallbackList;
typedef int (*SCCallbackBoxFunc)(SCInterpreter *scin, SCBlock *bl,
double *w, double *h, void **, void *);
typedef cairo_surface_t *(*SCCallbackDrawFunc)(int w, int h, void *, void *);
+typedef int (*SCCallbackClickFunc)(double x, double y, void *, void *);
extern SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang,
struct frame *top);
@@ -59,6 +60,7 @@ extern void sc_callback_list_free(SCCallbackList *cbl);
extern void sc_callback_list_add_callback(SCCallbackList *cbl, const char *name,
SCCallbackBoxFunc box_func,
SCCallbackDrawFunc draw_func,
+ SCCallbackClickFunc click_func,
void *vp);
extern void sc_interp_set_callbacks(SCInterpreter *scin, SCCallbackList *cbl);
diff --git a/src/shape.c b/src/shape.c
index 3fddaa6..84f8f03 100644
--- a/src/shape.c
+++ b/src/shape.c
@@ -251,7 +251,8 @@ static int add_text_box(struct wrap_line *line,
void add_callback_box(struct wrap_line *line, double w, double h,
- SCCallbackDrawFunc func, void *bvp, void *vp)
+ SCCallbackDrawFunc draw_func,
+ SCCallbackClickFunc click_func, void *bvp, void *vp)
{
struct wrap_box *box;
@@ -269,7 +270,8 @@ void add_callback_box(struct wrap_line *line, double w, double h,
box->width = pango_units_from_double(w);
box->ascent = pango_units_from_double(h);
box->height = pango_units_from_double(h);
- box->draw_func = func;
+ box->draw_func = draw_func;
+ box->click_func = click_func;
box->bvp = bvp;
box->vp = vp;
box->editable = 0;
diff --git a/src/shape.h b/src/shape.h
index 4f3a0ce..b9a5191 100644
--- a/src/shape.h
+++ b/src/shape.h
@@ -41,6 +41,8 @@ extern void add_image_box(struct wrap_line *line, const char *filename,
int w, int h, int editable);
extern void add_callback_box(struct wrap_line *line, double w, double h,
- SCCallbackDrawFunc func, void *bvp, void *vp);
+ SCCallbackDrawFunc draw_func,
+ SCCallbackClickFunc click_func,
+ void *bvp, void *vp);
#endif /* SHAPE_H */
diff --git a/src/slide_window.c b/src/slide_window.c
index 3e167d7..f44a699 100644
--- a/src/slide_window.c
+++ b/src/slide_window.c
@@ -538,7 +538,7 @@ GActionEntry sw_entries[] = {
};
-SlideWindow *slide_window_open(struct presentation *p, GApplication *app)
+SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks)
{
GtkWidget *window;
GtkWidget *vbox;
@@ -549,20 +549,24 @@ SlideWindow *slide_window_open(struct presentation *p, GApplication *app)
SCBlock *stylesheets[2];
GtkWidget *image;
- if ( p->slidewindow != NULL ) {
- fprintf(stderr, "Slide window is already open!\n");
- return p->slidewindow;
- }
-
sw = calloc(1, sizeof(SlideWindow));
if ( sw == NULL ) return NULL;
- window = gtk_application_window_new(GTK_APPLICATION(app));
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_action_map_add_action_entries(G_ACTION_MAP(window), sw_entries,
G_N_ELEMENTS(sw_entries), sw);
sw->window = window;
sw->p = p;
+
+ /* FIXME: Horrible bodge. */
+ int i;
sw->cur_slide = p->slides[0];
+ for ( i=0; i<p->num_slides; i++ ) {
+ if ( p->slides[i]->scblocks == sc_block_child(scblocks) ) {
+ sw->cur_slide = p->slides[i];
+ }
+ }
+
sw->show = NULL;
update_titlebar(p);
diff --git a/src/slide_window.h b/src/slide_window.h
index d0006b3..cd18378 100644
--- a/src/slide_window.h
+++ b/src/slide_window.h
@@ -29,7 +29,7 @@
typedef struct _slidewindow SlideWindow;
-extern SlideWindow *slide_window_open(struct presentation *p, GApplication *app);
+extern SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks);
extern void change_edit_slide(SlideWindow *sw, struct slide *np);
extern void update_titlebar(struct presentation *p);
diff --git a/src/wrap.h b/src/wrap.h
index c293ea9..97dea37 100644
--- a/src/wrap.h
+++ b/src/wrap.h
@@ -103,6 +103,7 @@ struct wrap_box
/* For type == WRAP_BOX_CALLBACK */
SCCallbackDrawFunc draw_func;
+ SCCallbackClickFunc click_func;
void *bvp;
void *vp;
};