From 5d1938781158148842a2b66565abf70858c11930 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 9 Oct 2015 10:09:55 -0400 Subject: [PATCH] Did scrolling for the uiArea test and uiArea itself on GTK+. --- test/page6.c | 30 ++++++++++++++++++++++++------ unix/area.c | 17 +++++++++++++---- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/test/page6.c b/test/page6.c index bc1137bb..8a1ed164 100644 --- a/test/page6.c +++ b/test/page6.c @@ -3,6 +3,8 @@ static uiArea *area; static uiCombobox *which; +static uiSpinbox *hamount; +static uiSpinbox *vamount; struct handler { uiAreaHandler ah; @@ -226,20 +228,18 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area) { - // TODO - return 0; + return uiSpinboxValue(hamount); } static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area) { - // TODO - return 0; + return uiSpinboxValue(vamount); } static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area) { - // TODO - return 1; + // TODO make a checkbox + return uiSpinboxValue(hamount) == 0 && uiSpinboxValue(vamount) == 0; } static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) @@ -282,6 +282,11 @@ static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) return 0; } +static void onAmountChanged(uiSpinbox *s, void *data) +{ + uiAreaUpdateScroll(area); +} + uiBox *makePage6(void) { uiBox *page6; @@ -303,8 +308,21 @@ uiBox *makePage6(void) which = uiNewCombobox(); uiBoxAppend(hbox, uiControl(which), 0); + // make these first in case the area handler calls the information as part of the constructor + hamount = uiNewSpinbox(0, 100000); + uiSpinboxOnChanged(hamount, onAmountChanged, NULL); + vamount = uiNewSpinbox(0, 100000); + uiSpinboxOnChanged(vamount, onAmountChanged, NULL); + area = uiNewArea((uiAreaHandler *) (&handler)); uiBoxAppend(page6, uiControl(area), 1); + hbox = newHorizontalBox(); + uiBoxAppend(hbox, uiControl(uiNewLabel("H ")), 0); + uiBoxAppend(hbox, uiControl(hamount), 0); + uiBoxAppend(hbox, uiControl(uiNewLabel(" V ")), 0); + uiBoxAppend(hbox, uiControl(vamount), 0); + uiBoxAppend(page6, uiControl(hbox), 0); + return page6; } diff --git a/unix/area.c b/unix/area.c index 399b2312..a05c2a40 100644 --- a/unix/area.c +++ b/unix/area.c @@ -23,6 +23,9 @@ struct areaWidgetClass { struct uiArea { uiUnixControl c; GtkWidget *widget; + GtkContainer *scontainer; + GtkScrolledWindow *sw; + GtkWidget *areaWidget; GtkDrawingArea *drawingArea; areaWidget *area; }; @@ -571,13 +574,19 @@ uiArea *uiNewArea(uiAreaHandler *ah) a = (uiArea *) uiNewControl(uiAreaType()); - a->widget = GTK_WIDGET(g_object_new(areaWidgetType, + a->widget = gtk_scrolled_window_new(NULL, NULL); + a->scontainer = GTK_CONTAINER(a->widget); + a->sw = GTK_SCROLLED_WINDOW(a->widget); + + a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, "area-handler", ah, NULL)); - a->drawingArea = GTK_DRAWING_AREA(a->widget); - a->area = areaWidget(a->widget); + a->drawingArea = GTK_DRAWING_AREA(a->areaWidget); + a->area = areaWidget(a->areaWidget); - // TODO wrap in scrolled window + gtk_container_add(a->scontainer, a->areaWidget); + // and make the area visible; only the scrolled window's visibility is controlled by libui + gtk_widget_show(a->areaWidget); uiUnixFinishNewControl(a, uiArea);