aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-10-22 22:00:47 +0100
committerThomas White <taw@bitwiz.org.uk>2015-10-22 22:00:47 +0100
commit0bb6c559e2e10b54caf943097e097372b79a982a (patch)
tree1c60f52d8307416f34a71b4d71b045099dfefdc1
parent4fc3fe9e769b6e88c9323fae0eadd097f5800619 (diff)
Height for width stuff
-rw-r--r--src/narrative_window.c28
-rw-r--r--src/sc_editor.c222
-rw-r--r--src/sc_editor.h11
3 files changed, 212 insertions, 49 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index fd473b6..fd3112c 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -42,7 +42,7 @@
struct _narrative_window
{
GtkWidget *window;
- GtkWidget *sb;
+ GtkAdjustment *vadj;
GtkToolItem *bfirst;
GtkToolItem *bprev;
GtkToolItem *bnext;
@@ -332,12 +332,13 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
static void scroll_down(NarrativeWindow *nw)
{
- GtkAdjustment *adj;
+/* FIXME: Implement via SCEditor */
+#if 0
gdouble inc, val;
- adj = gtk_range_get_adjustment(GTK_RANGE(nw->sb));
- inc = gtk_adjustment_get_step_increment(GTK_ADJUSTMENT(adj));
- val = gtk_adjustment_get_value(GTK_ADJUSTMENT(adj));
- gtk_adjustment_set_value(GTK_ADJUSTMENT(adj), inc+val);
+ inc = gtk_adjustment_get_step_increment(GTK_ADJUSTMENT(nw->vadj));
+ val = gtk_adjustment_get_value(GTK_ADJUSTMENT(nw->vadj));
+ gtk_adjustment_set_value(GTK_ADJUSTMENT(nw->vadj), inc+val);
+#endif
}
@@ -432,15 +433,6 @@ static cairo_surface_t *render_thumbnail(int w, int h, void *bvp, void *vp)
}
-static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event,
- NarrativeWindow *nw)
-{
- sc_editor_set_size(nw->sceditor, event->width, 12000);
- sc_editor_set_logical_size(nw->sceditor, event->width, 12000);
- return FALSE;
-}
-
-
NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
{
NarrativeWindow *nw;
@@ -545,10 +537,8 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(nw->sceditor));
- nw->sb = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(scroll));
- sc_editor_set_size(nw->sceditor, 640, 12000);
- sc_editor_set_logical_size(nw->sceditor, 640.0, 12000);
+ sc_editor_set_flow(nw->sceditor, 1);
sc_editor_set_background(nw->sceditor, 0.9, 0.9, 0.9);
sc_editor_set_min_border(nw->sceditor, 0.0);
sc_editor_set_top_frame_editable(nw->sceditor, 1);
@@ -558,8 +548,6 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
g_signal_connect(G_OBJECT(nw->sceditor), "key-press-event",
G_CALLBACK(key_press_sig), nw);
- g_signal_connect(G_OBJECT(nw->sceditor), "configure-event",
- G_CALLBACK(resize_sig), nw);
gtk_window_set_default_size(GTK_WINDOW(nw->window), 768, 768);
gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 45c8faf..f5c9627 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -46,16 +46,194 @@
#include "shape.h"
-G_DEFINE_TYPE(SCEditor, sc_editor, GTK_TYPE_DRAWING_AREA);
+static void scroll_interface_init(GtkScrollable *iface)
+{
+}
+
+
+enum
+{
+ SCEDITOR_0,
+ SCEDITOR_VADJ,
+ SCEDITOR_HADJ,
+ SCEDITOR_VPOL,
+ SCEDITOR_HPOL,
+};
+
+
+G_DEFINE_TYPE_WITH_CODE(SCEditor, sc_editor, GTK_TYPE_DRAWING_AREA,
+ G_IMPLEMENT_INTERFACE(GTK_TYPE_SCROLLABLE,
+ scroll_interface_init))
+
+
+static void vertical_adjust(GtkAdjustment *adj, SCEditor *e)
+{
+ e->scroll_pos = gtk_adjustment_get_value(adj);
+ sc_editor_redraw(e);
+}
+
+
+static void set_vertical_params(SCEditor *e)
+{
+ if ( e->vadj == NULL ) return;
+ gtk_adjustment_configure(e->vadj, e->scroll_pos, 0, e->h, 100,
+ e->visible_height, e->visible_height);
+ printf("set scrollbar for height %i, ac %i\n", e->visible_height, e->h);
+}
+
+
+static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event,
+ SCEditor *e)
+{
+ e->visible_height = event->height;
+
+ /* Interpret and shape, if not already done */
+ if ( e->top == NULL ) {
+ cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
+ e->top = interp_and_shape(e->scblocks, e->stylesheets, NULL,
+ e->is, ISZ_EDITOR, 0, cr);
+ cairo_destroy(cr);
+ }
+
+ /* Wrap using current width */
+ e->top->w = event->width;
+ wrap_contents(e->top); /* Only the top level needs to be wrapped */
+ e->need_draw = 1;
+
+ e->w = e->top->w;
+ e->h = total_height(e->top);
+ e->log_w = e->w;
+ e->log_h = e->h;
+ printf("set %i %i %f %f\n", e->w, e->h, e->log_w, e->log_h);
+ set_vertical_params(e);
+ return FALSE;
+}
+
+
+void sc_editor_set_flow(SCEditor *e, int flow)
+{
+ e->flow = flow;
+}
+
+
+static void sc_editor_set_property(GObject *obj, guint id, const GValue *val,
+ GParamSpec *spec)
+{
+ SCEditor *e = SC_EDITOR(obj);
+
+ switch ( id ) {
+
+ case SCEDITOR_VPOL :
+ e->vpol = g_value_get_enum(val);
+ break;
+
+ case SCEDITOR_HPOL :
+ e->hpol = g_value_get_enum(val);
+ break;
+
+ case SCEDITOR_VADJ :
+ e->vadj = g_value_get_object(val);
+ set_vertical_params(e);
+ if ( e->vadj != NULL ) {
+ g_signal_connect(G_OBJECT(e->vadj), "value-changed",
+ G_CALLBACK(vertical_adjust), e);
+ }
+ break;
+
+ case SCEDITOR_HADJ :
+ e->hadj = g_value_get_object(val);
+ break;
+
+ default :
+ printf("setting %i\n", id);
+ break;
+
+ }
+}
+
+
+static void sc_editor_get_property(GObject *obj, guint id, GValue *val,
+ GParamSpec *spec)
+{
+ SCEditor *e = SC_EDITOR(obj);
+
+ switch ( id ) {
+
+ case SCEDITOR_VADJ :
+ g_value_set_object(val, e->vadj);
+ break;
+
+ case SCEDITOR_HADJ :
+ g_value_set_object(val, e->hadj);
+ break;
+
+ case SCEDITOR_VPOL :
+ g_value_set_enum(val, e->vpol);
+ break;
+
+ case SCEDITOR_HPOL :
+ g_value_set_enum(val, e->hpol);
+ break;
+
+ default :
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+ break;
+
+ }
+}
+
+
+static GtkSizeRequestMode get_request_mode(GtkWidget *widget)
+{
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
+
+static void get_preferred_width(GtkWidget *widget, gint *min, gint *natural)
+{
+ *min = 100;
+ *natural = 640;
+}
+
+
+static void get_preferred_height(GtkWidget *widget, gint *min, gint *natural)
+{
+ *min = 1000;
+ *natural = 1000;
+}
+
+
+static void hforw(GtkWidget *widget, gint width, gint *min, gint *natural)
+{
+ printf("height for width = %i\n", width);
+ *min = 10000;
+ *natural = 10000;
+}
static void sc_editor_class_init(SCEditorClass *klass)
{
+ GObjectClass *goc = G_OBJECT_CLASS(klass);
+ goc->set_property = sc_editor_set_property;
+ goc->get_property = sc_editor_get_property;
+ g_object_class_override_property(goc, SCEDITOR_VADJ, "vadjustment");
+ g_object_class_override_property(goc, SCEDITOR_HADJ, "hadjustment");
+ g_object_class_override_property(goc, SCEDITOR_VPOL, "vscroll-policy");
+ g_object_class_override_property(goc, SCEDITOR_HPOL, "hscroll-policy");
+
+ GTK_WIDGET_CLASS(klass)->get_request_mode = get_request_mode;
+ GTK_WIDGET_CLASS(klass)->get_preferred_width = get_preferred_width;
+ GTK_WIDGET_CLASS(klass)->get_preferred_height = get_preferred_height;
+ GTK_WIDGET_CLASS(klass)->get_preferred_height_for_width = hforw;
}
-static void sc_editor_init(SCEditor *self)
+static void sc_editor_init(SCEditor *e)
{
+ e->vpol = GTK_SCROLL_NATURAL;
+ e->hpol = GTK_SCROLL_NATURAL;
+ e->vadj = gtk_adjustment_new(0, 0, 100, 1, 10, 10);
+ e->hadj = gtk_adjustment_new(0, 0, 100, 1, 10, 10);
}
@@ -439,41 +617,23 @@ static void tile_pixbuf(cairo_t *cr, GdkPixbuf *pb, int width, int height)
}
-static gboolean draw_sig(GtkWidget *da, cairo_t *cr,
- SCEditor *e)
+static gboolean draw_sig(GtkWidget *da, cairo_t *cr, SCEditor *e)
{
int width, height;
+ /* Overall background */
width = gtk_widget_get_allocated_width(GTK_WIDGET(da));
height = gtk_widget_get_allocated_height(GTK_WIDGET(da));
-
- /* Overall background */
- tile_pixbuf(cr, e->bg_pixbuf, width, height);
- cairo_set_source_rgba(cr, e->bgcol[0], e->bgcol[1], e->bgcol[2], 0.5);
+ cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
cairo_rectangle(cr, 0.0, 0.0, width, height);
cairo_fill(cr);
- /* Get the overall size */
- e->border_offs_x = rint((width - e->w)/2.0);
- e->border_offs_y = rint((height - e->h)/2.0);
- if ( e->border_offs_x < e->min_border ) {
- e->border_offs_x = e->min_border;
- }
- if ( e->border_offs_y < e->min_border ) {
- e->border_offs_y = e->min_border;
- }
-
- /* Draw the slide from the cache */
- if ( e->surface != NULL ) {
- cairo_set_source_surface(cr, e->surface,
- rint(e->border_offs_x),
- rint(e->border_offs_y));
- cairo_paint(cr);
- } else {
- fprintf(stderr, "Current slide not rendered yet!\n");
- }
-
+ /* Contents */
+ cairo_translate(cr, 0.0, -e->scroll_pos);
cairo_translate(cr, e->border_offs_x, e->border_offs_y);
+ recursive_draw(e->top, cr, e->is, ISZ_EDITOR);
+
+ /* Editing overlay */
draw_overlay(cr, e);
return FALSE;
@@ -1471,7 +1631,6 @@ static gint realise_sig(GtkWidget *da, SCEditor *e)
/* FIXME: Can do this "properly" by setting up a separate font map */
e->pc = gtk_widget_get_pango_context(GTK_WIDGET(e));
- full_rerender(e);
return FALSE;
}
@@ -1578,6 +1737,9 @@ SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets)
sceditor->min_border = 0.0;
sceditor->top_editable = 0;
sceditor->cbl = NULL;
+ sceditor->scroll_pos = 0;
+ sceditor->flow = 0;
+ sceditor->need_draw = 1;
sceditor->stylesheets = copy_ss_list(stylesheets);
@@ -1601,6 +1763,8 @@ SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets)
G_CALLBACK(button_release_sig), sceditor);
g_signal_connect(G_OBJECT(sceditor), "motion-notify-event",
G_CALLBACK(motion_sig), sceditor);
+ g_signal_connect(G_OBJECT(sceditor), "configure-event",
+ G_CALLBACK(resize_sig), sceditor);
/* Drag and drop */
targets[0].target = "text/uri-list";
diff --git a/src/sc_editor.h b/src/sc_editor.h
index 6e6011e..d37fb66 100644
--- a/src/sc_editor.h
+++ b/src/sc_editor.h
@@ -98,6 +98,16 @@ struct _sceditor
SCCallbackList *cbl;
struct frame *top;
+ /* Redraw/scroll stuff */
+ GtkScrollablePolicy hpol;
+ GtkScrollablePolicy vpol;
+ GtkAdjustment *hadj;
+ GtkAdjustment *vadj;
+ double scroll_pos;
+ int visible_height;
+ int flow;
+ int need_draw;
+
/* Pointers to the frame currently being edited */
struct frame *selection;
int top_editable;
@@ -156,6 +166,7 @@ extern GtkWidget *sc_editor_get_widget(SCEditor *e);
extern SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets);
extern void sc_editor_set_size(SCEditor *e, int w, int h);
extern void sc_editor_set_logical_size(SCEditor *e, double w, double h);
+extern void sc_editor_set_flow(SCEditor *e, int flow);
extern void sc_editor_redraw(SCEditor *e);
extern void sc_editor_set_background(SCEditor *e, double r, double g, double b);
extern void sc_editor_set_slidenum(SCEditor *e, int slidenum);