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);
}
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;
}
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);
}
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();
}
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();
}
}
}
Aggregations