return; // We have a maximized control, so we don't need to worry about the sash.
// Let's get the list of all sashes the sash form now has. If there is more than one then just disable the sashinfo.
// If there is no current sash, and there is only one sash, then create the sashinfo for it.
Control[] children = getChildren();
Sash newSash = null;
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Sash)
if (newSash == null)
newSash = (Sash) children[i];
else {
// We have more than one sash, so need to disable current sash, if we have one.
if (currentSashInfo != null)
currentSashInfo.enabled = false;
return; // Don't go on.
}
}
if (newSash == null)
return; // We have no sashes at all.
// Now we need to see if this is a new sash.
if (currentSashInfo == null || currentSashInfo.sash == null) {
if (currentSashInfo == null)
currentSashInfo = new SashInfo(newSash);
else
currentSashInfo.sash = newSash;
newSash.addPaintListener(new PaintListener() {
/**
* @see org.eclipse.swt.events.PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent e) {
// Need to find the index of the sash we're interested in.
GC gc = e.gc;
Color oldFg = gc.getForeground();
Color oldBg = gc.getBackground();
drawArrow(gc, currentSashInfo.sashLocs[0], currentSashInfo.cursorOver == 0); // Draw first arrow
if (currentSashInfo.sashLocs.length > 1)
drawArrow(gc, currentSashInfo.sashLocs[1], currentSashInfo.cursorOver == 1); // Draw second arrow
if (currentSashInfo.sashBorderLeft)
drawSashBorder(gc, currentSashInfo.sash, true);
if (currentSashInfo.sashBorderRight)
drawSashBorder(gc, currentSashInfo.sash, false);
gc.setForeground(oldFg);
gc.setBackground(oldBg);
}
});
newSash.addControlListener(new ControlListener() {
/**
* @see org.eclipse.swt.events.ControlAdapter#controlMoved(ControlEvent)
*/
public void controlMoved(ControlEvent e) {
recomputeSashInfo();
}
/**
* @see org.eclipse.swt.events.ControlAdapter#controlResized(ControlEvent)
*/
public void controlResized(ControlEvent e) {
recomputeSashInfo();
}
});
newSash.addDisposeListener(new DisposeListener() {
/**
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(DisposeEvent)
*/
public void widgetDisposed(DisposeEvent e) {
// Need to clear out the widget from current.
currentSashInfo= null;
}
});
// This is a kludge because we can't override the set cursor hit test.
newSash.addMouseMoveListener(new MouseMoveListener() {
/**
* @see org.eclipse.swt.events.MouseMoveListener#mouseMove(MouseEvent)
*/
public void mouseMove(MouseEvent e) {
// See if within one of the arrows.
int x = e.x;
int y = e.y;
for (int i=0; i<currentSashInfo.sashLocs.length; i++) {
int[] locs = currentSashInfo.sashLocs[i];
boolean vertical = getOrientation() == SWT.VERTICAL;
int loc = vertical ? x : y;
int locIndex = vertical ? X_INDEX : Y_INDEX;
int sizeIndex = vertical ? WIDTH_INDEX : HEIGHT_INDEX;
if (locs[locIndex] <= loc && loc <= locs[locIndex]+locs[sizeIndex]) {
// if (currentSashInfo.cursorOver == NO_ARROW) {
// currentSashInfo.sash.setCursor(Cursors.ARROW);
// }
if (currentSashInfo.cursorOver != i) {
currentSashInfo.cursorOver = i;
currentSashInfo.sash.redraw();
switch (locs[ARROW_TYPE_INDEX]) {
case UP_ARROW:
case DOWN_ARROW:
currentSashInfo.sash.setToolTipText("Restore"); //$NON-NLS-1$
break;
case UP_MAX_ARROW:
case DOWN_MAX_ARROW:
currentSashInfo.sash.setToolTipText("Maximize"); //$NON-NLS-1$
break;
}
}
return;
}
}
if (currentSashInfo.cursorOver != NO_ARROW) {
currentSashInfo.sash.setCursor(null);
currentSashInfo.cursorOver = NO_ARROW;
currentSashInfo.sash.redraw();
currentSashInfo.sash.setToolTipText(null);
}
}
});
// Need to know when we leave so that we can clear the cursor feedback if set.
newSash.addMouseTrackListener(new MouseTrackAdapter() {
/**
* @see org.eclipse.swt.events.MouseTrackAdapter#mouseExit(MouseEvent)
*/
public void mouseExit(MouseEvent e) {
if (currentSashInfo.cursorOver != NO_ARROW) {
// Undo the cursor.
currentSashInfo.sash.setCursor(null);
currentSashInfo.cursorOver = NO_ARROW;
currentSashInfo.sash.redraw();
currentSashInfo.sash.setToolTipText(null);
}
}
});
// Want to handle mouse down as a selection.
newSash.addMouseListener(new MouseAdapter() {
/**
* @see org.eclipse.swt.events.MouseAdapter#mouseDown(MouseEvent)
*/
public void mouseDown(MouseEvent e) {
inMouseClick = true;