Search in sources :

Example 56 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method createItem.

void createItem(CTableItem item) {
    int index = item.index;
    if (itemsCount == items.length) {
        int grow = drawCount <= 0 ? 4 : Math.max(4, items.length * 3 / 2);
        CTableItem[] newItems = new CTableItem[items.length + grow];
        System.arraycopy(items, 0, newItems, 0, items.length);
        items = newItems;
    }
    if (index != itemsCount) {
        /* new item is not at end of list, so shift other items right to create space for it */
        System.arraycopy(items, index, items, index + 1, itemsCount - index);
    }
    items[index] = item;
    itemsCount++;
    /* update the index for items bumped down by this new item */
    for (int i = index + 1; i < itemsCount; i++) {
        items[i].index = i;
    }
    /* Rows were added, so notify the accessible. */
    int[] eventData = new int[5];
    eventData[0] = ACC.INSERT;
    eventData[1] = index;
    eventData[2] = 1;
    eventData[3] = 0;
    eventData[4] = 0;
    getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
    /* update scrollbars */
    updateVerticalBar();
    Rectangle bounds = item.getBounds(false);
    int rightX = bounds.x + bounds.width;
    updateHorizontalBar(rightX, rightX);
    /*
	 * If new item is above viewport then adjust topIndex and the vertical
	 * scrollbar so that the current viewport items will not change.
	 */
    if (item.index < topIndex) {
        topIndex++;
        ScrollBar vBar = getVerticalBar();
        if (vBar != null)
            vBar.setSelection(topIndex);
        return;
    }
    /*
	 * If this is the first item and the receiver has focus then its boundary
	 * focus ring must be removed.
	 */
    if (itemsCount == 1 && isFocusControl()) {
        focusItem = item;
        redraw();
        return;
    }
    if (item.isInViewport()) {
        redrawFromItemDownwards(index);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 57 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method onResize.

void onResize(Event event) {
    clientArea = getClientArea();
    /* vertical scrollbar */
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        int clientHeight = (clientArea.height - getHeaderHeight()) / itemHeight;
        int thumb = Math.min(clientHeight, itemsCount);
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
        int index = vBar.getSelection();
        if (index != topIndex) {
            topIndex = index;
            redraw();
        }
        boolean visible = clientHeight < itemsCount;
        if (visible != vBar.getVisible()) {
            vBar.setVisible(visible);
            clientArea = getClientArea();
        }
    }
    /* horizontal scrollbar */
    ScrollBar hBar = getHorizontalBar();
    if (hBar != null) {
        int hBarMaximum = hBar.getMaximum();
        int thumb = Math.min(clientArea.width, hBarMaximum);
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
        horizontalOffset = hBar.getSelection();
        boolean visible = clientArea.width < hBarMaximum;
        if (visible != hBar.getVisible()) {
            hBar.setVisible(visible);
            clientArea = getClientArea();
        }
    }
    /* header */
    int headerHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding();
    header.setSize(clientArea.width, headerHeight);
    /* if this is the focus control but there are no items then the boundary focus ring must be repainted */
    if (itemsCount == 0 && isFocusControl())
        redraw();
}
Also used : ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Example 58 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method updateVerticalBar.

void updateVerticalBar() {
    if (drawCount > 0)
        return;
    ScrollBar vBar = getVerticalBar();
    if (vBar == null)
        return;
    int pageSize = (clientArea.height - getHeaderHeight()) / itemHeight;
    int maximum = Math.max(1, itemsCount);
    /* setting a value of 0 here is ignored */
    if (maximum != vBar.getMaximum()) {
        vBar.setMaximum(maximum);
    }
    int thumb = Math.min(pageSize, maximum);
    if (thumb != vBar.getThumb()) {
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
    }
    vBar.setVisible(pageSize < maximum);
    /* reclaim any space now left on the bottom */
    if (maximum < topIndex + thumb) {
        topIndex = maximum - thumb;
        vBar.setSelection(topIndex);
        redraw();
    } else {
        int selection = vBar.getSelection();
        if (selection != topIndex) {
            topIndex = selection;
            redraw();
        }
    }
}
Also used : ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Example 59 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method onArrowUp.

void onArrowUp(int stateMask) {
    if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
        /* Up Arrow with no modifiers */
        int newFocusIndex = focusItem.index - 1;
        if (newFocusIndex < 0)
            return;
        /* at top */
        CTableItem item = items[newFocusIndex];
        selectItem(item, false);
        setFocusItem(item, true);
        redrawItem(newFocusIndex, true);
        showItem(item);
        Event newEvent = new Event();
        newEvent.item = item;
        notifyListeners(SWT.Selection, newEvent);
        return;
    }
    if ((getStyle() & SWT.SINGLE) != 0) {
        if ((stateMask & SWT.CTRL) != 0) {
            /* CTRL+Up Arrow, CTRL+Shift+Up Arrow */
            if (topIndex == 0)
                return;
            /* at top */
            update();
            topIndex--;
            ScrollBar vBar = getVerticalBar();
            if (vBar != null)
                vBar.setSelection(topIndex);
            GC gc = new GC(this);
            gc.copyArea(0, 0, clientArea.width, clientArea.height, 0, itemHeight);
            gc.dispose();
            return;
        }
        /* Shift+Up Arrow */
        int newFocusIndex = focusItem.index - 1;
        if (newFocusIndex < 0)
            return;
        /* at top */
        CTableItem item = items[newFocusIndex];
        selectItem(item, false);
        setFocusItem(item, true);
        redrawItem(newFocusIndex, true);
        showItem(item);
        Event newEvent = new Event();
        newEvent.item = item;
        notifyListeners(SWT.Selection, newEvent);
        return;
    }
    /* SWT.MULTI */
    if ((stateMask & SWT.CTRL) != 0) {
        if ((stateMask & SWT.SHIFT) != 0) {
            /* CTRL+Shift+Up Arrow */
            if (topIndex == 0)
                return;
            /* at top */
            update();
            topIndex--;
            ScrollBar vBar = getVerticalBar();
            if (vBar != null)
                vBar.setSelection(topIndex);
            GC gc = new GC(this);
            gc.copyArea(0, 0, clientArea.width, clientArea.height, 0, itemHeight);
            gc.dispose();
            return;
        }
        /* CTRL+Up Arrow */
        int focusIndex = focusItem.index;
        if (focusIndex == 0)
            return;
        /* at top */
        CTableItem newFocusItem = items[focusIndex - 1];
        setFocusItem(newFocusItem, true);
        showItem(newFocusItem);
        redrawItem(newFocusItem.index, true);
        return;
    }
    /* Shift+Up Arrow */
    int newFocusIndex = focusItem.index - 1;
    if (newFocusIndex < 0)
        return;
    /* at top */
    if (anchorItem == null)
        anchorItem = focusItem;
    if (anchorItem.index < focusItem.index) {
        deselectItem(focusItem);
        redrawItem(focusItem.index, true);
    }
    CTableItem item = items[newFocusIndex];
    selectItem(item, true);
    setFocusItem(item, true);
    redrawItem(newFocusIndex, true);
    showItem(item);
    Event newEvent = new Event();
    newEvent.item = item;
    notifyListeners(SWT.Selection, newEvent);
}
Also used : Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleTableEvent(org.eclipse.swt.accessibility.AccessibleTableEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 60 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method onArrowRight.

void onArrowRight(int stateMask) {
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;
    int maximum = hBar.getMaximum();
    int clientWidth = clientArea.width;
    if ((horizontalOffset + clientArea.width) == maximum)
        return;
    if (maximum <= clientWidth)
        return;
    int newSelection = Math.min(horizontalOffset + SIZE_HORIZONTALSCROLL, maximum - clientWidth);
    update();
    GC gc = new GC(this);
    gc.copyArea(0, 0, clientArea.width, clientArea.height, horizontalOffset - newSelection, 0);
    gc.dispose();
    if (header.getVisible()) {
        Rectangle headerClientArea = header.getClientArea();
        header.update();
        gc = new GC(header);
        gc.copyArea(0, 0, headerClientArea.width, headerClientArea.height, horizontalOffset - newSelection, 0);
        gc.dispose();
    }
    horizontalOffset = newSelection;
    hBar.setSelection(horizontalOffset);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Aggregations

ScrollBar (org.eclipse.swt.widgets.ScrollBar)84 Point (org.eclipse.swt.graphics.Point)39 Rectangle (org.eclipse.swt.graphics.Rectangle)25 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 GC (org.eclipse.swt.graphics.GC)14 GridData (org.eclipse.swt.layout.GridData)12 Event (org.eclipse.swt.widgets.Event)12 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)11 Composite (org.eclipse.swt.widgets.Composite)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 Listener (org.eclipse.swt.widgets.Listener)7 StyledText (org.eclipse.swt.custom.StyledText)6 Button (org.eclipse.swt.widgets.Button)6 Label (org.eclipse.swt.widgets.Label)6 SWT (org.eclipse.swt.SWT)5 ControlListener (org.eclipse.swt.events.ControlListener)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 Font (org.eclipse.swt.graphics.Font)5 Text (org.eclipse.swt.widgets.Text)5 AffineTransform (java.awt.geom.AffineTransform)4