String platform = SWT.getPlatform(); if (!"gtk".equals(platform)) setToolTipText(null);
void onMouse(Event event) {	int x = event.x, y = event.y;	switch (event.type) {		case SWT.MouseExit: {			// TEMPORARY CODE			// On GTK, clearing tooltip on mouse exit prevents close button from drawing			String platform = SWT.getPlatform();			if (!"gtk".equals(platform)) setToolTipText(null); //$NON-NLS-1$			if (minImageState != NORMAL) {				minImageState = NORMAL;				redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);			}			if (maxImageState != NORMAL) {				maxImageState = NORMAL;				redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);			}			if (chevronImageState != NORMAL) {				chevronImageState = NORMAL;				redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);			}			for (int i=0; i<items.length; i++) {				CTabItem item = items[i];				if (i != selectedIndex && item.closeImageState != NONE) {					item.closeImageState = NONE;					redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);				}				if (i == selectedIndex && item.closeImageState != NORMAL) {					item.closeImageState = NORMAL;					redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);				}			}			break;		}		case SWT.MouseDown: {			if (minRect.contains(x, y)) {				if (event.button != 1) return;				minImageState = SELECTED;				redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);				update();				return;			}			if (maxRect.contains(x, y)) {				if (event.button != 1) return;				maxImageState = SELECTED;				redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);				update();				return;			}			if (chevronRect.contains(x, y)) {				if (event.button != 1) return;				if (chevronImageState != HOT) {					chevronImageState = HOT;				} else {					chevronImageState = SELECTED;				}				redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);				update();				return;			}			CTabItem item = null;			if (single) {				if (selectedIndex != -1) {					Rectangle bounds = items[selectedIndex].getBounds();					if (bounds.contains(x, y)){						item = items[selectedIndex];					}				}			} else {				for (int i=0; i<items.length; i++) {					Rectangle bounds = items[i].getBounds();					if (bounds.contains(x, y)){						item = items[i];					}				}			}			if (item != null) {				if (item.closeRect.contains(x,y)){					if (event.button != 1) return;					item.closeImageState = SELECTED;					redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);					update();					return;				}				int index = indexOf(item);				if (item.showing){					setSelection(index, true);				}				return;			}			break;		}		case SWT.MouseMove: {			_setToolTipText(event.x, event.y);			boolean close = false, minimize = false, maximize = false, chevron = false;			if (minRect.contains(x, y)) {				minimize = true;				if (minImageState != SELECTED && minImageState != HOT) {					minImageState = HOT;					redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);				}			}			if (maxRect.contains(x, y)) {				maximize = true;				if (maxImageState != SELECTED && maxImageState != HOT) {					maxImageState = HOT;					redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);				}			}			if (chevronRect.contains(x, y)) {				chevron = true;				if (chevronImageState != SELECTED && chevronImageState != HOT) {					chevronImageState = HOT;					redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);				}			}			if (minImageState != NORMAL && !minimize) {				minImageState = NORMAL;				redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);			}			if (maxImageState != NORMAL && !maximize) {				maxImageState = NORMAL;				redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);			}			if (chevronImageState != NORMAL && !chevron) {				chevronImageState = NORMAL;				redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);			}			for (int i=0; i<items.length; i++) {				CTabItem item = items[i];				close = false;				if (item.getBounds().contains(x, y)) {					close = true;					if (item.closeRect.contains(x, y)) {						if (item.closeImageState != SELECTED && item.closeImageState != HOT) {							item.closeImageState = HOT;							redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);						}					} else {						if (item.closeImageState != NORMAL) {							item.closeImageState = NORMAL;							redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);						}					}				} 				if (i != selectedIndex && item.closeImageState != NONE && !close) {					item.closeImageState = NONE;					redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);				}				if (i == selectedIndex && item.closeImageState != NORMAL && !close) {					item.closeImageState = NORMAL;					redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);				}			}			break;		}		case SWT.MouseUp: {			if (event.button != 1) return;			if (chevronRect.contains(x, y)) {				boolean selected = chevronImageState == SELECTED;				if (!selected) return;				CTabFolderEvent e = new CTabFolderEvent(this);				e.widget = this;				e.time = event.time;				e.x = chevronRect.x;				e.y = chevronRect.y;				e.width = chevronRect.width;				e.height = chevronRect.height;				e.doit = true;				for (int i = 0; i < folderListeners.length; i++) {					folderListeners[i].showList(e);				}				if (e.doit && !isDisposed()) {					showList(chevronRect);				}				return;			}			if (minRect.contains(x, y)) {				boolean selected = minImageState == SELECTED;				minImageState = HOT;				redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);				if (!selected) return;				CTabFolderEvent e = new CTabFolderEvent(this);				e.widget = this;				e.time = event.time;				for (int i = 0; i < folderListeners.length; i++) {					if (minimized) {						folderListeners[i].restore(e);					} else {						folderListeners[i].minimize(e);					}				}				return;			}			if (maxRect.contains(x, y)) {				boolean selected = maxImageState == SELECTED;				maxImageState = HOT;				redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);				if (!selected) return;				CTabFolderEvent e = new CTabFolderEvent(this);				e.widget = this;				e.time = event.time;				for (int i = 0; i < folderListeners.length; i++) {					if (maximized) {						folderListeners[i].restore(e);					} else {						folderListeners[i].maximize(e);					}				}				return;			}			CTabItem item = null;			if (single) {				if (selectedIndex != -1) {					Rectangle bounds = items[selectedIndex].getBounds();					if (bounds.contains(x, y)){						item = items[selectedIndex];					}				}			} else {				for (int i=0; i<items.length; i++) {					Rectangle bounds = items[i].getBounds();					if (bounds.contains(x, y)){						item = items[i];					}				}			}			if (item != null) {				if (item.closeRect.contains(x,y)) {					boolean selected = item.closeImageState == SELECTED;					item.closeImageState = HOT;					redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false);					if (!selected) return;					CTabFolderEvent e = new CTabFolderEvent(this);					e.widget = this;					e.time = event.time;					e.item = item;					e.doit = true;					for (int j = 0; j < folderListeners.length; j++) {						CTabFolder2Listener listener = folderListeners[j];						listener.close(e);					}					for (int j = 0; j < tabListeners.length; j++) {						CTabFolderListener listener = tabListeners[j];						listener.itemClosed(e);					}					if (e.doit) {						item.dispose();						Display display = getDisplay();						Point pt = display.getCursorLocation();						pt = display.map(null, this, pt.x, pt.y);						CTabItem nextItem = getItem(pt);						if (nextItem != null) {							if (nextItem.closeRect.contains(pt)) {								if (nextItem.closeImageState != SELECTED && nextItem.closeImageState != HOT) {									nextItem.closeImageState = HOT;									redraw(nextItem.closeRect.x, nextItem.closeRect.y, nextItem.closeRect.width, nextItem.closeRect.height, false);								}							} else {								if (nextItem.closeImageState != NORMAL) {									nextItem.closeImageState = NORMAL;									redraw(nextItem.closeRect.x, nextItem.closeRect.y, nextItem.closeRect.width, nextItem.closeRect.height, false);								}							} 						}					}					return;				}			}		}	}}