use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class CTable method onScrollHorizontal.
void onScrollHorizontal(Event event) {
ScrollBar hBar = getHorizontalBar();
if (hBar == null)
return;
int newSelection = hBar.getSelection();
update();
if (itemsCount > 0) {
GC gc = new GC(this);
gc.copyArea(0, 0, clientArea.width, clientArea.height, horizontalOffset - newSelection, 0);
gc.dispose();
} else {
redraw();
/* ensure that static focus rectangle updates properly */
}
if (drawCount <= 0 && header.isVisible()) {
header.update();
Rectangle headerClientArea = header.getClientArea();
GC gc = new GC(header);
gc.copyArea(0, 0, headerClientArea.width, headerClientArea.height, horizontalOffset - newSelection, 0);
gc.dispose();
}
horizontalOffset = newSelection;
}
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);
}
}
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();
}
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();
}
}
}
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);
}
Aggregations