Search in sources :

Example 41 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)

Example 42 with ScrollBar

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

the class CTable method onScrollVertical.

void onScrollVertical(Event event) {
    ScrollBar vBar = getVerticalBar();
    if (vBar == null)
        return;
    int newSelection = vBar.getSelection();
    update();
    GC gc = new GC(this);
    gc.copyArea(0, 0, clientArea.width, clientArea.height, 0, (topIndex - newSelection) * itemHeight);
    gc.dispose();
    topIndex = newSelection;
}
Also used : GC(org.eclipse.swt.graphics.GC) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Example 43 with ScrollBar

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

the class CTable method onArrowDown.

void onArrowDown(int stateMask) {
    if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
        /* Down Arrow with no modifiers */
        int newFocusIndex = focusItem.index + 1;
        if (newFocusIndex == itemsCount)
            return;
        /* at bottom */
        selectItem(items[newFocusIndex], false);
        setFocusItem(items[newFocusIndex], true);
        redrawItem(newFocusIndex, true);
        showItem(items[newFocusIndex]);
        Event newEvent = new Event();
        newEvent.item = items[newFocusIndex];
        notifyListeners(SWT.Selection, newEvent);
        return;
    }
    if ((getStyle() & SWT.SINGLE) != 0) {
        if ((stateMask & SWT.CTRL) != 0) {
            /* CTRL+Down Arrow, CTRL+Shift+Down Arrow */
            int visibleItemCount = (clientArea.height - getHeaderHeight()) / itemHeight;
            if (itemsCount <= topIndex + visibleItemCount)
                return;
            /* at bottom */
            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+Down Arrow */
        int newFocusIndex = focusItem.index + 1;
        if (newFocusIndex == itemsCount)
            return;
        /* at bottom */
        selectItem(items[newFocusIndex], false);
        setFocusItem(items[newFocusIndex], true);
        redrawItem(newFocusIndex, true);
        showItem(items[newFocusIndex]);
        Event newEvent = new Event();
        newEvent.item = items[newFocusIndex];
        notifyListeners(SWT.Selection, newEvent);
        return;
    }
    /* SWT.MULTI */
    if ((stateMask & SWT.CTRL) != 0) {
        if ((stateMask & SWT.SHIFT) != 0) {
            /* CTRL+Shift+Down Arrow */
            int visibleItemCount = (clientArea.height - getHeaderHeight()) / itemHeight;
            if (itemsCount <= topIndex + visibleItemCount)
                return;
            /* at bottom */
            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+Down Arrow */
        int focusIndex = focusItem.index;
        if (focusIndex == itemsCount - 1)
            return;
        /* at bottom */
        CTableItem newFocusItem = items[focusIndex + 1];
        setFocusItem(newFocusItem, true);
        redrawItem(newFocusItem.index, true);
        showItem(newFocusItem);
        return;
    }
    /* Shift+Down Arrow */
    int newFocusIndex = focusItem.index + 1;
    if (newFocusIndex == itemsCount)
        return;
    /* at bottom */
    if (anchorItem == null)
        anchorItem = focusItem;
    if (focusItem.index < anchorItem.index) {
        deselectItem(focusItem);
        redrawItem(focusItem.index, true);
    }
    selectItem(items[newFocusIndex], true);
    setFocusItem(items[newFocusIndex], true);
    redrawItem(newFocusIndex, true);
    showItem(items[newFocusIndex]);
    Event newEvent = new Event();
    newEvent.item = items[newFocusIndex];
    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 44 with ScrollBar

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

the class CTable method setFont.

@Override
public void setFont(Font value) {
    checkWidget();
    Font oldFont = getFont();
    super.setFont(value);
    Font font = getFont();
    if (font.equals(oldFont))
        return;
    GC gc = new GC(this);
    /* recompute the receiver's cached font height and item height values */
    fontHeight = gc.getFontMetrics().getHeight();
    setItemHeight(Math.max(fontHeight, imageHeight) + 2 * getCellPadding());
    Point headerSize = header.getSize();
    int newHeaderHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding();
    if (headerSize.y != newHeaderHeight) {
        header.setSize(headerSize.x, newHeaderHeight);
    }
    header.setFont(font);
    /*
	 * Notify all columns and items of the font change so that elements that
	 * use the receiver's font can recompute their cached string widths.
	 */
    for (CTableColumn column : columns) {
        column.updateFont(gc);
    }
    for (int i = 0; i < itemsCount; i++) {
        items[i].updateFont(gc);
    }
    gc.dispose();
    if (drawCount <= 0 && header.isVisible())
        header.redraw();
    /* update scrollbars */
    if (columns.length == 0)
        updateHorizontalBar();
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        int thumb = (clientArea.height - getHeaderHeight()) / itemHeight;
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
        topIndex = vBar.getSelection();
        vBar.setVisible(thumb < vBar.getMaximum());
    }
    redraw();
}
Also used : Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 45 with ScrollBar

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

the class CTable method updateHorizontalBar.

/*
 * This is a naive implementation that computes the value from scratch.
 */
void updateHorizontalBar() {
    if (drawCount > 0)
        return;
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;
    int maxX = 0;
    if (columns.length > 0) {
        for (CTableColumn column : columns) {
            maxX += column.width;
        }
    } else {
        for (int i = 0; i < itemsCount; i++) {
            Rectangle itemBounds = items[i].getCellBounds(0);
            maxX = Math.max(maxX, itemBounds.x + itemBounds.width + horizontalOffset);
        }
    }
    int clientWidth = clientArea.width;
    if (maxX != hBar.getMaximum()) {
        hBar.setMaximum(Math.max(1, maxX));
    /* setting a value of 0 here is ignored */
    }
    int thumb = Math.min(clientWidth, maxX);
    if (thumb != hBar.getThumb()) {
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
    }
    hBar.setVisible(clientWidth < maxX);
    /* reclaim any space now left on the right */
    if (maxX < horizontalOffset + thumb) {
        horizontalOffset = maxX - thumb;
        hBar.setSelection(horizontalOffset);
        redraw();
    } else {
        int selection = hBar.getSelection();
        if (selection != horizontalOffset) {
            horizontalOffset = selection;
            redraw();
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Aggregations

ScrollBar (org.eclipse.swt.widgets.ScrollBar)50 Point (org.eclipse.swt.graphics.Point)32 Rectangle (org.eclipse.swt.graphics.Rectangle)20 GC (org.eclipse.swt.graphics.GC)14 Event (org.eclipse.swt.widgets.Event)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 GridData (org.eclipse.swt.layout.GridData)7 Listener (org.eclipse.swt.widgets.Listener)7 Composite (org.eclipse.swt.widgets.Composite)6 SWT (org.eclipse.swt.SWT)5 Font (org.eclipse.swt.graphics.Font)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 AccessibleControlEvent (org.eclipse.swt.accessibility.AccessibleControlEvent)4 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)4 AccessibleTableEvent (org.eclipse.swt.accessibility.AccessibleTableEvent)4 ControlListener (org.eclipse.swt.events.ControlListener)4 Color (org.eclipse.swt.graphics.Color)4 ClientAreaResizeCommand (net.sourceforge.nattable.grid.command.ClientAreaResizeCommand)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3