Exemplo n.º 1
0
static void
updateScrollerProportion(ScrollView *sPtr)
{
    float prop, value;
    float oldV, oldP;

    if (sPtr->flags.hasHScroller) {
        oldV = WMGetScrollerValue(sPtr->hScroller);
        oldP = WMGetScrollerKnobProportion(sPtr->hScroller);

        prop = (float)sPtr->viewport->size.width/(float)sPtr->contentView->size.width;

        if (oldP == 1.0)
            value = 0;
        else
            value = (prop * oldV) / oldP;
        WMSetScrollerParameters(sPtr->hScroller, value, prop);
    }
    if (sPtr->flags.hasVScroller) {
        oldV = WMGetScrollerValue(sPtr->vScroller);
        oldP = WMGetScrollerKnobProportion(sPtr->vScroller);

        prop = (float)sPtr->viewport->size.height/(float)sPtr->contentView->size.height;

        if (oldP == 1.0)
            value = 0;
        else
            value = (prop * oldV) / oldP;
        WMSetScrollerParameters(sPtr->vScroller, value, prop);
    }
    applyScrollerValues(sPtr);
}
Exemplo n.º 2
0
static void scrollToColumn(WMBrowser * bPtr, int column, Bool updateScroller)
{
	int i;
	int x;
	int notify = 0;

	if (column != bPtr->firstVisibleColumn) {
		notify = 1;
	}

	if (column < 0)
		column = 0;

	if (notify && bPtr->delegate && bPtr->delegate->willScroll) {
		(*bPtr->delegate->willScroll) (bPtr->delegate, bPtr);
	}

	x = 0;
	bPtr->firstVisibleColumn = column;
	for (i = 0; i < bPtr->columnCount; i++) {
		if (COLUMN_IS_VISIBLE(bPtr, i)) {
			WMMoveWidget(bPtr->columns[i], x, WMWidgetView(bPtr->columns[i])->pos.y);
			if (!WMWidgetView(bPtr->columns[i])->flags.realized)
				WMRealizeWidget(bPtr->columns[i]);
			WMMapWidget(bPtr->columns[i]);
			x += bPtr->columnSize.width + COLUMN_SPACING;
		} else {
			WMUnmapWidget(bPtr->columns[i]);
		}
	}

	/* update the scroller */
	if (updateScroller) {
		if (bPtr->columnCount > bPtr->maxVisibleColumns) {
			float value, proportion;

			value = bPtr->firstVisibleColumn / (float)(bPtr->columnCount - bPtr->maxVisibleColumns);
			proportion = bPtr->maxVisibleColumns / (float)bPtr->columnCount;
			WMSetScrollerParameters(bPtr->scroller, value, proportion);
		} else {
			WMSetScrollerParameters(bPtr->scroller, 0, 1);
		}
	}

	if (bPtr->view->flags.mapped)
		paintBrowser(bPtr);

	if (notify && bPtr->delegate && bPtr->delegate->didScroll) {
		(*bPtr->delegate->didScroll) (bPtr->delegate, bPtr);
	}
}
Exemplo n.º 3
0
void
WMScrollViewScrollPoint(WMScrollView *sPtr, WMPoint point)
{
    float xsize, ysize;
    float xpos, ypos;

    xsize = sPtr->contentView->size.width-sPtr->viewport->size.width;
    ysize = sPtr->contentView->size.height-sPtr->viewport->size.height;

    xpos = point.x / xsize;
    ypos = point.y / ysize;

    if (sPtr->hScroller)
        WMSetScrollerParameters(sPtr->hScroller, xpos,
                                WMGetScrollerKnobProportion(sPtr->hScroller));
    if (sPtr->vScroller)
        WMSetScrollerParameters(sPtr->vScroller, ypos,
                                WMGetScrollerKnobProportion(sPtr->vScroller));

    W_MoveView(sPtr->contentView, -point.x, -point.y);
}
Exemplo n.º 4
0
void
WMSetScrollViewContentView(WMScrollView *sPtr, WMView *view)
{
    assert(sPtr->contentView == NULL);

    sPtr->contentView = view;

    W_ReparentView(sPtr->contentView, sPtr->viewport, 0, 0);

    if (sPtr->flags.hasHScroller) {
        float prop;

        prop = (float)sPtr->viewport->size.width/sPtr->contentView->size.width;
        WMSetScrollerParameters(sPtr->hScroller, 0, prop);
    }
    if (sPtr->flags.hasVScroller) {
        float prop;

        prop = (float)sPtr->viewport->size.height/sPtr->contentView->size.height;

        WMSetScrollerParameters(sPtr->vScroller, 0, prop);
    }
}
Exemplo n.º 5
0
static void handleMotion(Scroller * sPtr, int mouseX, int mouseY)
{
	if (sPtr->flags.draggingKnob) {
		float newFloatValue;
		int point;

		if (sPtr->flags.horizontal) {
			point = mouseX;
		} else {
			point = mouseY;
		}

#ifndef STRICT_NEXT_BEHAVIOUR
		point -= sPtr->dragPoint;
#endif

		newFloatValue = floatValueForPoint(sPtr, point);
		WMSetScrollerParameters(sPtr, newFloatValue, sPtr->knobProportion);
		if (sPtr->action) {
			(*sPtr->action) (sPtr, sPtr->clientData);
			WMPostNotificationName(WMScrollerDidScrollNotification, sPtr, NULL);
		}
	} else {
		int part;

		part = locatePointInScroller(sPtr, mouseX, mouseY, False);

		sPtr->flags.hitPart = part;

		if (part == WSIncrementLine && sPtr->flags.decrDown) {
			sPtr->flags.decrDown = 0;
			sPtr->flags.incrDown = 1;
		} else if (part == WSDecrementLine && sPtr->flags.incrDown) {
			sPtr->flags.incrDown = 0;
			sPtr->flags.decrDown = 1;
		} else if (part != WSIncrementLine && part != WSDecrementLine) {
			sPtr->flags.incrDown = 0;
			sPtr->flags.decrDown = 0;
		}
	}
}
Exemplo n.º 6
0
int WMAddBrowserColumn(WMBrowser * bPtr)
{
	WMList *list;
	WMList **clist;
	char **tlist;
	int colY;
	int index;

	if (bPtr->usedColumnCount < bPtr->columnCount) {
		return bPtr->usedColumnCount++;
	}

	bPtr->usedColumnCount++;

	if (bPtr->flags.isTitled) {
		colY = TITLE_SPACING + bPtr->titleHeight;
	} else {
		colY = 0;
	}

	index = bPtr->columnCount;
	bPtr->columnCount++;
	clist = wmalloc(sizeof(WMList *) * bPtr->columnCount);
	tlist = wmalloc(sizeof(char *) * bPtr->columnCount);
	memcpy(clist, bPtr->columns, sizeof(WMList *) * (bPtr->columnCount - 1));
	memcpy(tlist, bPtr->titles, sizeof(char *) * (bPtr->columnCount - 1));
	if (bPtr->columns)
		wfree(bPtr->columns);
	if (bPtr->titles)
		wfree(bPtr->titles);
	bPtr->columns = clist;
	bPtr->titles = tlist;

	bPtr->titles[index] = NULL;

	list = WMCreateList(bPtr);
	WMSetListAllowMultipleSelection(list, bPtr->flags.allowMultipleSelection);
	WMSetListAllowEmptySelection(list, bPtr->flags.allowEmptySelection);
	WMSetListAction(list, listCallback, bPtr);
	WMSetListDoubleAction(list, listDoubleCallback, bPtr);
	WMSetListUserDrawProc(list, paintItem);
	WMAddNotificationObserver(listSelectionObserver, bPtr, WMListSelectionDidChangeNotification, list);

	bPtr->columns[index] = list;

	WMResizeWidget(list, bPtr->columnSize.width, bPtr->columnSize.height);
	WMMoveWidget(list, (bPtr->columnSize.width + COLUMN_SPACING) * index, colY);
	if (COLUMN_IS_VISIBLE(bPtr, index))
		WMMapWidget(list);

	/* update the scroller */
	if (bPtr->columnCount > bPtr->maxVisibleColumns) {
		float value, proportion;

		value = bPtr->firstVisibleColumn / (float)(bPtr->columnCount - bPtr->maxVisibleColumns);
		proportion = bPtr->maxVisibleColumns / (float)bPtr->columnCount;
		WMSetScrollerParameters(bPtr->scroller, value, proportion);
	}

	return index;
}
Exemplo n.º 7
0
static void
doScrolling(WMWidget *self, void *data)
{
    ScrollView *sPtr = (ScrollView*)data;
    float value;
    int pos;
    int vpsize;
    float size;

    if (sPtr->hScroller == (WMScroller *)self) {
        pos = -sPtr->contentView->pos.x;
        size = sPtr->contentView->size.width-sPtr->viewport->size.width;
        vpsize = sPtr->viewport->size.width - sPtr->pageScroll;
    } else {
        pos = -sPtr->contentView->pos.y;
        size = sPtr->contentView->size.height-sPtr->viewport->size.height;
        vpsize = sPtr->viewport->size.height - sPtr->pageScroll;
    }
    if (vpsize <= 0)
        vpsize = 1;

    switch (WMGetScrollerHitPart(self)) {
    case WSDecrementLine:
        if (pos > 0) {
            pos-=sPtr->lineScroll;
            if (pos < 0)
                pos = 0;
            value = (float)pos / size;
            WMSetScrollerParameters(self, value,
                                    WMGetScrollerKnobProportion(self));
        }
        break;
    case WSIncrementLine:
        if (pos < size) {
            pos+=sPtr->lineScroll;
            if (pos > size)
                pos = size;
            value = (float)pos / size;
            WMSetScrollerParameters(self, value,
                                    WMGetScrollerKnobProportion(self));
        }
        break;

    case WSKnob:
        value = WMGetScrollerValue(self);
        pos = value*size;
        break;

    case WSDecrementPage:
        if (pos > 0) {
            pos -= vpsize;
            if (pos < 0)
                pos = 0;
            value = (float)pos / size;
            WMSetScrollerParameters(self, value,
                                    WMGetScrollerKnobProportion(self));
        }
        break;

    case WSDecrementWheel:
        if (pos > 0) {
            pos -= vpsize/3;
            if (pos < 0)
                pos = 0;
            value = (float)pos / size;
            WMSetScrollerParameters(self, value,
                                    WMGetScrollerKnobProportion(self));
        }
        break;

    case WSIncrementPage:
        if (pos < size) {
            pos += vpsize;
            if (pos > size)
                pos = size;
            value = (float)pos / size;
            WMSetScrollerParameters(self, value,
                                    WMGetScrollerKnobProportion(self));
        }
        break;

    case WSIncrementWheel:
        if (pos < size) {
            pos += vpsize/3;
            if (pos > size)
                pos = size;
            value = (float)pos / size;
            WMSetScrollerParameters(self, value,
                                    WMGetScrollerKnobProportion(self));
        }
        break;

    case WSNoPart:
    case WSKnobSlot:
        break;
    }

    if (sPtr->hScroller == (WMScroller *)self) {
        W_MoveView(sPtr->contentView, -pos, sPtr->contentView->pos.y);
    } else {
        W_MoveView(sPtr->contentView, sPtr->contentView->pos.x, -pos);
    }
}