View | Details | Raw Unified | Return to bug 193318 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse SWT PI/win32/library/os_structs.c (+43 lines)
Lines 7386-7391 Link Here
7386
}
7386
}
7387
#endif
7387
#endif
7388
7388
7389
#ifndef NO_TPMPARAMS
7390
typedef struct TPMPARAMS_FID_CACHE {
7391
	int cached;
7392
	jclass clazz;
7393
	jfieldID cbSize, left, top, right, bottom;
7394
} TPMPARAMS_FID_CACHE;
7395
7396
TPMPARAMS_FID_CACHE TPMPARAMSFc;
7397
7398
void cacheTPMPARAMSFields(JNIEnv *env, jobject lpObject)
7399
{
7400
	if (TPMPARAMSFc.cached) return;
7401
	TPMPARAMSFc.clazz = (*env)->GetObjectClass(env, lpObject);
7402
	TPMPARAMSFc.cbSize = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "cbSize", "I");
7403
	TPMPARAMSFc.left = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "left", "I");
7404
	TPMPARAMSFc.top = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "top", "I");
7405
	TPMPARAMSFc.right = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "right", "I");
7406
	TPMPARAMSFc.bottom = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "bottom", "I");
7407
	TPMPARAMSFc.cached = 1;
7408
}
7409
7410
TPMPARAMS *getTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct)
7411
{
7412
	if (!TPMPARAMSFc.cached) cacheTPMPARAMSFields(env, lpObject);
7413
	lpStruct->cbSize = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.cbSize);
7414
	lpStruct->rcExclude.left = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.left);
7415
	lpStruct->rcExclude.top = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.top);
7416
	lpStruct->rcExclude.right = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.right);
7417
	lpStruct->rcExclude.bottom = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.bottom);
7418
	return lpStruct;
7419
}
7420
7421
void setTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct)
7422
{
7423
	if (!TPMPARAMSFc.cached) cacheTPMPARAMSFields(env, lpObject);
7424
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.cbSize, (jint)lpStruct->cbSize);
7425
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.left, (jint)lpStruct->rcExclude.left);
7426
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.top, (jint)lpStruct->rcExclude.top);
7427
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.right, (jint)lpStruct->rcExclude.right);
7428
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.bottom, (jint)lpStruct->rcExclude.bottom);
7429
}
7430
#endif
7431
7389
#ifndef NO_TRACKMOUSEEVENT
7432
#ifndef NO_TRACKMOUSEEVENT
7390
typedef struct TRACKMOUSEEVENT_FID_CACHE {
7433
typedef struct TRACKMOUSEEVENT_FID_CACHE {
7391
	int cached;
7434
	int cached;
(-)Eclipse SWT PI/win32/library/os_stats.c (-2 / +4 lines)
Lines 14-21 Link Here
14
14
15
#ifdef NATIVE_STATS
15
#ifdef NATIVE_STATS
16
16
17
int OS_nativeFunctionCount = 930;
17
int OS_nativeFunctionCount = 932;
18
int OS_nativeFunctionCallCount[930];
18
int OS_nativeFunctionCallCount[932];
19
char * OS_nativeFunctionNames[] = {
19
char * OS_nativeFunctionNames[] = {
20
	"ACCEL_1sizeof",
20
	"ACCEL_1sizeof",
21
	"ACTCTX_1sizeof",
21
	"ACTCTX_1sizeof",
Lines 896-901 Link Here
896
	"TF_1DA_1COLOR_1sizeof",
896
	"TF_1DA_1COLOR_1sizeof",
897
	"TF_1DISPLAYATTRIBUTE_1sizeof",
897
	"TF_1DISPLAYATTRIBUTE_1sizeof",
898
	"TOOLINFO_1sizeof",
898
	"TOOLINFO_1sizeof",
899
	"TPMPARAMS_1sizeof",
899
	"TRACKMOUSEEVENT_1sizeof",
900
	"TRACKMOUSEEVENT_1sizeof",
900
	"TRIVERTEX_1sizeof",
901
	"TRIVERTEX_1sizeof",
901
	"TVHITTESTINFO_1sizeof",
902
	"TVHITTESTINFO_1sizeof",
Lines 907-912 Link Here
907
	"ToUnicode",
908
	"ToUnicode",
908
	"TrackMouseEvent",
909
	"TrackMouseEvent",
909
	"TrackPopupMenu",
910
	"TrackPopupMenu",
911
	"TrackPopupMenuEx",
910
	"TranslateAcceleratorA",
912
	"TranslateAcceleratorA",
911
	"TranslateAcceleratorW",
913
	"TranslateAcceleratorW",
912
	"TranslateCharsetInfo",
914
	"TranslateCharsetInfo",
(-)Eclipse SWT PI/win32/library/os_structs.h (+12 lines)
Lines 1559-1564 Link Here
1559
#define TOOLINFO_sizeof() 0
1559
#define TOOLINFO_sizeof() 0
1560
#endif
1560
#endif
1561
1561
1562
#ifndef NO_TPMPARAMS
1563
void cacheTPMPARAMSFields(JNIEnv *env, jobject lpObject);
1564
TPMPARAMS *getTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct);
1565
void setTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct);
1566
#define TPMPARAMS_sizeof() sizeof(TPMPARAMS)
1567
#else
1568
#define cacheTPMPARAMSFields(a,b)
1569
#define getTPMPARAMSFields(a,b,c) NULL
1570
#define setTPMPARAMSFields(a,b,c)
1571
#define TPMPARAMS_sizeof() 0
1572
#endif
1573
1562
#ifndef NO_TRACKMOUSEEVENT
1574
#ifndef NO_TRACKMOUSEEVENT
1563
void cacheTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject);
1575
void cacheTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject);
1564
TRACKMOUSEEVENT *getTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpStruct);
1576
TRACKMOUSEEVENT *getTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpStruct);
(-)Eclipse SWT PI/win32/library/os_stats.h (+2 lines)
Lines 904-909 Link Here
904
	TF_1DA_1COLOR_1sizeof_FUNC,
904
	TF_1DA_1COLOR_1sizeof_FUNC,
905
	TF_1DISPLAYATTRIBUTE_1sizeof_FUNC,
905
	TF_1DISPLAYATTRIBUTE_1sizeof_FUNC,
906
	TOOLINFO_1sizeof_FUNC,
906
	TOOLINFO_1sizeof_FUNC,
907
	TPMPARAMS_1sizeof_FUNC,
907
	TRACKMOUSEEVENT_1sizeof_FUNC,
908
	TRACKMOUSEEVENT_1sizeof_FUNC,
908
	TRIVERTEX_1sizeof_FUNC,
909
	TRIVERTEX_1sizeof_FUNC,
909
	TVHITTESTINFO_1sizeof_FUNC,
910
	TVHITTESTINFO_1sizeof_FUNC,
Lines 915-920 Link Here
915
	ToUnicode_FUNC,
916
	ToUnicode_FUNC,
916
	TrackMouseEvent_FUNC,
917
	TrackMouseEvent_FUNC,
917
	TrackPopupMenu_FUNC,
918
	TrackPopupMenu_FUNC,
919
	TrackPopupMenuEx_FUNC,
918
	TranslateAcceleratorA_FUNC,
920
	TranslateAcceleratorA_FUNC,
919
	TranslateAcceleratorW_FUNC,
921
	TranslateAcceleratorW_FUNC,
920
	TranslateCharsetInfo_FUNC,
922
	TranslateCharsetInfo_FUNC,
(-)Eclipse SWT PI/win32/library/os.c (+28 lines)
Lines 14133-14138 Link Here
14133
}
14133
}
14134
#endif
14134
#endif
14135
14135
14136
#ifndef NO_TPMPARAMS_1sizeof
14137
JNIEXPORT jint JNICALL OS_NATIVE(TPMPARAMS_1sizeof)
14138
	(JNIEnv *env, jclass that)
14139
{
14140
	jint rc = 0;
14141
	OS_NATIVE_ENTER(env, that, TPMPARAMS_1sizeof_FUNC);
14142
	rc = (jint)TPMPARAMS_sizeof();
14143
	OS_NATIVE_EXIT(env, that, TPMPARAMS_1sizeof_FUNC);
14144
	return rc;
14145
}
14146
#endif
14147
14136
#ifndef NO_TRACKMOUSEEVENT_1sizeof
14148
#ifndef NO_TRACKMOUSEEVENT_1sizeof
14137
JNIEXPORT jint JNICALL OS_NATIVE(TRACKMOUSEEVENT_1sizeof)
14149
JNIEXPORT jint JNICALL OS_NATIVE(TRACKMOUSEEVENT_1sizeof)
14138
	(JNIEnv *env, jclass that)
14150
	(JNIEnv *env, jclass that)
Lines 14287-14292 Link Here
14287
}
14299
}
14288
#endif
14300
#endif
14289
14301
14302
#ifndef NO_TrackPopupMenuEx
14303
JNIEXPORT jboolean JNICALL OS_NATIVE(TrackPopupMenuEx)
14304
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3, jint arg4, jobject arg5)
14305
{
14306
	TPMPARAMS _arg5, *lparg5=NULL;
14307
	jboolean rc = 0;
14308
	OS_NATIVE_ENTER(env, that, TrackPopupMenuEx_FUNC);
14309
	if (arg5) if ((lparg5 = getTPMPARAMSFields(env, arg5, &_arg5)) == NULL) goto fail;
14310
	rc = (jboolean)TrackPopupMenuEx((HMENU)arg0, arg1, arg2, arg3, (HWND)arg4, lparg5);
14311
fail:
14312
	if (arg5 && lparg5) setTPMPARAMSFields(env, arg5, lparg5);
14313
	OS_NATIVE_EXIT(env, that, TrackPopupMenuEx_FUNC);
14314
	return rc;
14315
}
14316
#endif
14317
14290
#ifndef NO_TranslateAcceleratorA
14318
#ifndef NO_TranslateAcceleratorA
14291
JNIEXPORT jint JNICALL OS_NATIVE(TranslateAcceleratorA)
14319
JNIEXPORT jint JNICALL OS_NATIVE(TranslateAcceleratorA)
14292
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2)
14320
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2)
(-)Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java (-6 / +130 lines)
Lines 44-49 Link Here
44
	ToolItem [] items;
44
	ToolItem [] items;
45
	boolean ignoreResize, ignoreMouse;
45
	boolean ignoreResize, ignoreMouse;
46
	ImageList imageList, disabledImageList, hotImageList;
46
	ImageList imageList, disabledImageList, hotImageList;
47
	boolean showingPushItemMenu;
47
	static final int /*long*/ ToolBarProc;
48
	static final int /*long*/ ToolBarProc;
48
	static final TCHAR ToolBarClass = new TCHAR (0, OS.TOOLBARCLASSNAME, true);
49
	static final TCHAR ToolBarClass = new TCHAR (0, OS.TOOLBARCLASSNAME, true);
49
	static {
50
	static {
Lines 1017-1023 Link Here
1017
	return ToolBarProc;
1018
	return ToolBarProc;
1018
}
1019
}
1019
1020
1020
LRESULT WM_CAPTURECHANGED (int /*long*/ wParam, int /*long*/ lParam) {
1021
LRESULT WM_CAPTURECHANGED (int wParam, int lParam) {
1022
	// Do not unpress the selected item while its menu is showing
1023
	// (if we call the super method, the ToolBar window procedure will unpress the item too).
1024
	if (showingPushItemMenu) return LRESULT.ZERO;
1021
	LRESULT result = super.WM_CAPTURECHANGED (wParam, lParam);
1025
	LRESULT result = super.WM_CAPTURECHANGED (wParam, lParam);
1022
	if (result != null) return result;
1026
	if (result != null) return result;
1023
	/*
1027
	/*
Lines 1119-1124 Link Here
1119
			* application the opportunity to cancel the operation.
1123
			* application the opportunity to cancel the operation.
1120
			*/
1124
			*/
1121
			return LRESULT.ZERO;
1125
			return LRESULT.ZERO;
1126
		case OS.VK_DOWN:
1127
		case OS.VK_UP:
1128
			/*
1129
			 * Menus of SWT.DROPDOWN items are automatically triggered by Windows on the
1130
			 * UP and DOWN keys. Here we mirror this behavior for PUSH items.
1131
			 */
1132
			int itemIndex = (int)/*64*/OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0);
1133
			ToolItem child = getEnabledPushItem (itemIndex);
1134
			if (child != null) {
1135
				RECT rect = new RECT ();
1136
				OS.SendMessage (handle, OS.TB_GETITEMRECT, itemIndex, rect);
1137
				if (sendItemMenuDetectEvent (child, rect, 0)) {
1138
					showPushItemMenu (child, rect);
1139
					return LRESULT.ZERO;
1140
				}
1141
			}
1122
	}
1142
	}
1123
	return result;
1143
	return result;
1124
}
1144
}
Lines 1131-1137 Link Here
1131
	return super.WM_KILLFOCUS (wParam, lParam);
1151
	return super.WM_KILLFOCUS (wParam, lParam);
1132
}
1152
}
1133
1153
1154
LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
1155
	// Handle menu display for push items
1156
	POINT point = new POINT ();
1157
	point.x = OS.GET_X_LPARAM (lParam);
1158
	point.y = OS.GET_Y_LPARAM (lParam);
1159
	int itemIndex = (int)/*64*/OS.SendMessage (handle, OS.TB_HITTEST, 0, point);
1160
	ToolItem child = getEnabledPushItem (itemIndex);
1161
	if (child != null) {
1162
		RECT rect = new RECT ();
1163
		OS.SendMessage (handle, OS.TB_GETITEMRECT, itemIndex, rect);
1164
		if (sendItemMenuDetectEvent (child, rect, 0)) {
1165
			super.WM_LBUTTONDBLCLK (wParam, lParam);
1166
			showPushItemMenu (child, rect);
1167
			return LRESULT.ZERO;
1168
		}
1169
	}
1170
	return super.WM_LBUTTONDBLCLK (wParam, lParam);
1171
}
1172
1134
LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
1173
LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
1174
	// Handle menu display for push items
1175
	POINT point = new POINT ();
1176
	point.x = OS.GET_X_LPARAM (lParam);
1177
	point.y = OS.GET_Y_LPARAM (lParam);
1178
	int itemIndex = (int)/*64*/OS.SendMessage (handle, OS.TB_HITTEST, 0, point);
1179
	ToolItem child = getEnabledPushItem (itemIndex);
1180
	if (child != null) {
1181
		RECT rect = new RECT ();
1182
		OS.SendMessage (handle, OS.TB_GETITEMRECT, itemIndex, rect);
1183
		if (sendItemMenuDetectEvent (child, rect, 0)) {
1184
			super.WM_LBUTTONDOWN (wParam, lParam);
1185
			showPushItemMenu (child, rect);
1186
			return LRESULT.ZERO;
1187
		}
1188
	}
1189
1135
	if (ignoreMouse) return null;
1190
	if (ignoreMouse) return null;
1136
	return super.WM_LBUTTONDOWN (wParam, lParam);
1191
	return super.WM_LBUTTONDOWN (wParam, lParam);
1137
}
1192
}
Lines 1299-1312 Link Here
1299
			OS.MoveMemory (lpnmtb, lParam, NMTOOLBAR.sizeof);
1354
			OS.MoveMemory (lpnmtb, lParam, NMTOOLBAR.sizeof);
1300
			ToolItem child = items [lpnmtb.iItem];
1355
			ToolItem child = items [lpnmtb.iItem];
1301
			if (child != null) {
1356
			if (child != null) {
1302
				Event event = new Event ();
1303
				event.detail = SWT.ARROW;
1304
				int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmtb.iItem, 0);
1357
				int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmtb.iItem, 0);
1305
				RECT rect = new RECT ();
1358
				RECT rect = new RECT ();
1306
				OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
1359
				OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
1307
				event.x = rect.left;
1360
				if (sendItemMenuDetectEvent (child, rect, SWT.ARROW)) {
1308
				event.y = rect.bottom;
1361
					showItemMenu (child, rect);
1309
				child.postEvent (SWT.Selection, event);
1362
				} else {
1363
					Event event = new Event ();
1364
					event.detail = SWT.ARROW;
1365
					event.x = rect.left;
1366
					event.y = rect.bottom;
1367
					child.postEvent (SWT.Selection, event);
1368
				}
1310
			}
1369
			}
1311
			break;
1370
			break;
1312
		case OS.NM_CUSTOMDRAW:
1371
		case OS.NM_CUSTOMDRAW:
Lines 1363-1366 Link Here
1363
	return super.wmNotifyChild (hdr, wParam, lParam);
1422
	return super.wmNotifyChild (hdr, wParam, lParam);
1364
}
1423
}
1365
1424
1425
private ToolItem getEnabledPushItem (int itemIndex) {
1426
	// Inspect non-separator item under the cursor
1427
	if (itemIndex >= 0) {
1428
		// Get item instance
1429
		TBBUTTON button = new TBBUTTON ();
1430
		OS.SendMessage (handle, OS.TB_GETBUTTON, itemIndex, button);
1431
		int buttonId = button.idCommand;
1432
		ToolItem child = items[buttonId];
1433
		// Only allow menu display for PUSH items
1434
		final int toolItemStyleMask = SWT.PUSH | SWT.CHECK | SWT.RADIO
1435
					| SWT.SEPARATOR | SWT.DROP_DOWN;
1436
		if ((child.style & toolItemStyleMask) == SWT.PUSH) {
1437
			// Get item state
1438
			int itemState = (int)/*64*/OS.SendMessage (handle, OS.TB_GETSTATE, buttonId, 0);
1439
			// Only attempt to show a menu if the item is enabled
1440
			if ((itemState & OS.TBSTATE_ENABLED) != 0) {
1441
				return child;
1442
			}
1443
		}
1444
	}
1445
	return null;
1446
}
1447
1448
private void showPushItemMenu (ToolItem child, RECT rect) {
1449
	// Press item
1450
	int itemState = (int)/*64*/OS.SendMessage (handle, OS.TB_GETSTATE, child.id, 0);
1451
	itemState |= OS.TBSTATE_PRESSED;
1452
	OS.SendMessage (handle, OS.TB_SETSTATE, child.id, itemState);
1453
	// Show menu
1454
	showingPushItemMenu = true;
1455
	showItemMenu (child, rect);
1456
	showingPushItemMenu = false;
1457
	// Unpress item - reload item state since it may have changed
1458
	itemState = (int)/*64*/OS.SendMessage (handle, OS.TB_GETSTATE, child.id, 0);
1459
	itemState &= ~OS.TBSTATE_PRESSED;
1460
	OS.SendMessage (handle, OS.TB_SETSTATE, child.id, itemState);
1461
	// If the menu was cancelled by an LBUTTONDOWN event on the control, discard that event.
1462
	// This allows the menu to be closed on a second click.
1463
	OS.PeekMessage (new MSG (), handle, OS.WM_LBUTTONDOWN, OS.WM_LBUTTONDOWN, OS.PM_REMOVE);
1464
	// Force a redraw of the item. Otherwise, if the user cancels the menu by clicking and holding
1465
	// the left mouse button over the (non-client) title bar of a window
1466
	// that belongs to this application, the item will only get unpressed after a short delay. 
1467
	OS.RedrawWindow (handle, rect, 0, OS.RDW_UPDATENOW);
1468
}
1469
1470
private boolean sendItemMenuDetectEvent (ToolItem child, RECT rect, int detail) {
1471
	Event event = new Event ();
1472
	event.detail = detail;
1473
	event.x = rect.left;
1474
	event.y = rect.bottom;
1475
	child.sendEvent (SWT.MenuDetect, event);
1476
	Menu menu = child.menu;
1477
	return event.doit && menu != null && !menu.isDisposed ();
1478
}
1479
1480
private void showItemMenu (ToolItem child, RECT rect) {
1481
	Menu menu = child.menu;
1482
	// Without this call, an lbuttondown event that triggers the menu
1483
	// will not be delivered to EventListeners until after the menu has been closed.
1484
	display.runDeferredEvents ();
1485
	OS.MapWindowPoints (handle, 0, rect, 2);
1486
	menu.setLocation (rect.left, rect.bottom);
1487
	menu._setVisible (true, rect, OS.TPM_VERTICAL);
1488
}
1489
1366
}
1490
}
(-)Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java (-1 / +46 lines)
Lines 1156-1162 Link Here
1156
					event.x = lpnm.left;
1156
					event.x = lpnm.left;
1157
					event.y = lpnm.bottom;
1157
					event.y = lpnm.bottom;
1158
				}
1158
				}
1159
				item.postEvent (SWT.Selection, event);
1159
1160
				if (sendItemMenuDetectEvent (item, event.x, event.y, SWT.ARROW)) {
1161
					// Without this call, an lbuttondown event that triggers the menu
1162
					// will not be delivered to EventListeners until after the menu has been closed.
1163
					display.runDeferredEvents ();
1164
					RECT rect = new RECT ();
1165
					rect.top = lpnm.top;
1166
					rect.bottom = lpnm.bottom;
1167
					rect.left = lpnm.left;
1168
					rect.right = lpnm.right;
1169
					showItemMenu (item, rect);
1170
					// If the menu was cancelled by an LBUTTONDOWN event on the control, discard that event.
1171
					// This allows the menu to be closed on a second click.
1172
					OS.PeekMessage (new MSG (), handle, OS.WM_LBUTTONDOWN, OS.WM_LBUTTONDOWN, OS.PM_REMOVE);
1173
				} else {
1174
					item.postEvent (SWT.Selection, event);
1175
				}
1160
			}
1176
			}
1161
			break;
1177
			break;
1162
		}
1178
		}
Lines 1184-1187 Link Here
1184
	}
1200
	}
1185
	return super.wmNotifyChild (hdr, wParam, lParam);
1201
	return super.wmNotifyChild (hdr, wParam, lParam);
1186
}
1202
}
1203
1204
private void showItemMenu (CoolItem child, RECT rect) {
1205
	Menu menu = child.menu;
1206
	OS.MapWindowPoints (handle, 0, rect, 2);
1207
	int x, y;
1208
	int menuPosition;
1209
	if ((style & SWT.VERTICAL) != 0) {
1210
		x = rect.right;
1211
		y = rect.top;
1212
		menuPosition = OS.TPM_HORIZONTAL;
1213
	} else {
1214
		x = rect.left;
1215
		y = rect.bottom;
1216
		menuPosition = OS.TPM_VERTICAL;
1217
	}
1218
	menu.setLocation (x, y);
1219
	menu._setVisible (true, rect, menuPosition);
1220
}
1221
1222
private boolean sendItemMenuDetectEvent (CoolItem child, int x, int y, int detail) {
1223
	Event event = new Event ();
1224
	event.detail = detail;
1225
	event.x = x;
1226
	event.y = y;
1227
	child.sendEvent (SWT.MenuDetect, event);
1228
	Menu menu = child.menu;
1229
	return event.doit && menu != null && !menu.isDisposed ();
1230
}
1231
1187
}
1232
}
(-)Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java (+106 lines)
Lines 34-39 Link Here
34
public class CoolItem extends Item {
34
public class CoolItem extends Item {
35
	CoolBar parent;
35
	CoolBar parent;
36
	Control control;
36
	Control control;
37
	Menu menu;
37
	int id;
38
	int id;
38
	boolean ideal, minimum;
39
	boolean ideal, minimum;
39
40
Lines 112-117 Link Here
112
}
113
}
113
114
114
/**
115
/**
116
 * Adds the listener to the collection of listeners who will
117
 * be notified when the platform-specific chevron menu trigger
118
 * has occurred, by sending it one of the messages defined in
119
 * the <code>MenuDetectListener</code> interface.
120
 *
121
 * @param listener the listener which should be notified
122
 *
123
 * @exception IllegalArgumentException <ul>
124
 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
125
 * </ul>
126
 * @exception SWTException <ul>
127
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
128
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
129
 * </ul>
130
 *
131
 * @see MenuDetectListener
132
 * @see #removeMenuDetectListener
133
 *
134
 * @since 3.3
135
 */
136
public void addMenuDetectListener (MenuDetectListener listener) {
137
	checkWidget ();
138
	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
139
	TypedListener typedListener = new TypedListener (listener);
140
	addListener (SWT.MenuDetect, typedListener);
141
}
142
143
/**
115
 * Adds the listener to the collection of listeners that will
144
 * Adds the listener to the collection of listeners that will
116
 * be notified when the control is selected by the user, by sending it one
145
 * be notified when the control is selected by the user, by sending it one
117
 * of the messages defined in the <code>SelectionListener</code>
146
 * of the messages defined in the <code>SelectionListener</code>
Lines 279-284 Link Here
279
}
308
}
280
309
281
/**
310
/**
311
 * Returns the receiver's chevron menu if it has one, or null 
312
 * if it does not.
313
 * 
314
 * @return the receiver's drop-down menu
315
 * @exception SWTException <ul>
316
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
317
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
318
 * </ul>
319
 */
320
public Menu getMenu () {
321
	checkWidget();
322
	return menu;
323
}
324
325
/**
282
 * Returns the receiver's parent, which must be a <code>CoolBar</code>.
326
 * Returns the receiver's parent, which must be a <code>CoolBar</code>.
283
 *
327
 *
284
 * @return the receiver's parent
328
 * @return the receiver's parent
Lines 293-298 Link Here
293
	return parent;
337
	return parent;
294
}
338
}
295
339
340
void releaseWidget () {
341
	super.releaseWidget ();
342
	if (menu != null && !menu.isDisposed ()) {
343
		menu.dispose ();
344
	}
345
	menu = null;
346
}
347
296
void releaseHandle () {
348
void releaseHandle () {
297
	super.releaseHandle ();
349
	super.releaseHandle ();
298
	parent = null;
350
	parent = null;
Lines 357-362 Link Here
357
}
409
}
358
410
359
/**
411
/**
412
 * Sets the receiver's chevron menu to the argument, which may be 
413
 * null indicating that no drop-down menu should be displayed.
414
 * <p>
415
 * If this property is null a drop-down menu can still be displayed manually by adding a
416
 * {@link SelectionListener} to the receiver and handling{@link SWT#ARROW} events.
417
 * 
418
 * @param menu the drop-down menu to be displayed when the receiver's arrow is pressed
419
 * @exception SWTException <ul>
420
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
421
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
422
 * </ul>
423
 */
424
public void setMenu (Menu menu) {
425
	checkWidget();
426
	if (menu != null) {
427
		if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
428
		if ((menu.style & SWT.POP_UP) == 0) {
429
			error (SWT.ERROR_MENU_NOT_POP_UP);
430
		}
431
		if (menu.parent != parent.menuShell ()) {
432
			error (SWT.ERROR_INVALID_PARENT);
433
		}
434
	}
435
	this.menu = menu;
436
}
437
438
/**
360
 * Returns a point describing the receiver's ideal size.
439
 * Returns a point describing the receiver's ideal size.
361
 * The x coordinate of the result is the ideal width of the receiver.
440
 * The x coordinate of the result is the ideal width of the receiver.
362
 * The y coordinate of the result is the ideal height of the receiver.
441
 * The y coordinate of the result is the ideal height of the receiver.
Lines 685-690 Link Here
685
}
764
}
686
765
687
/**
766
/**
767
 * Removes the listener from the collection of listeners who will
768
 * be notified when the platform-specific chevron menu trigger has
769
 * occurred.
770
 *
771
 * @param listener the listener which should no longer be notified
772
 *
773
 * @exception IllegalArgumentException <ul>
774
 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
775
 * </ul>
776
 * @exception SWTException <ul>
777
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
778
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
779
 * </ul>
780
 *
781
 * @see MenuDetectListener
782
 * @see #addMenuDetectListener
783
 *
784
 * @since 3.3
785
 */
786
public void removeMenuDetectListener (MenuDetectListener listener) {
787
	checkWidget ();
788
	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
789
	if (eventTable == null) return;
790
	eventTable.unhook (SWT.MenuDetect, listener);
791
}
792
793
/**
688
 * Removes the listener from the collection of listeners that
794
 * Removes the listener from the collection of listeners that
689
 * will be notified when the control is selected by the user.
795
 * will be notified when the control is selected by the user.
690
 *
796
 *
(-)Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java (+109 lines)
Lines 39-44 Link Here
39
	String toolTipText;
39
	String toolTipText;
40
	Image disabledImage, hotImage;
40
	Image disabledImage, hotImage;
41
	Image disabledImage2;
41
	Image disabledImage2;
42
	Menu menu;
42
	int id;
43
	int id;
43
44
44
/**
45
/**
Lines 125-130 Link Here
125
126
126
/**
127
/**
127
 * Adds the listener to the collection of listeners who will
128
 * Adds the listener to the collection of listeners who will
129
 * be notified when the platform-specific drop-down menu trigger
130
 * has occurred, by sending it one of the messages defined in
131
 * the <code>MenuDetectListener</code> interface.
132
 *
133
 * @param listener the listener which should be notified
134
 *
135
 * @exception IllegalArgumentException <ul>
136
 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
137
 * </ul>
138
 * @exception SWTException <ul>
139
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
140
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
141
 * </ul>
142
 *
143
 * @see MenuDetectListener
144
 * @see #removeMenuDetectListener
145
 *
146
 * @since 3.3
147
 */
148
public void addMenuDetectListener (MenuDetectListener listener) {
149
	checkWidget ();
150
	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
151
	TypedListener typedListener = new TypedListener (listener);
152
	addListener (SWT.MenuDetect, typedListener);
153
}
154
155
/**
156
 * Adds the listener to the collection of listeners who will
128
 * be notified when the control is selected by the user, by sending
157
 * be notified when the control is selected by the user, by sending
129
 * it one of the messages defined in the <code>SelectionListener</code>
158
 * it one of the messages defined in the <code>SelectionListener</code>
130
 * interface.
159
 * interface.
Lines 298-303 Link Here
298
}
327
}
299
328
300
/**
329
/**
330
 * Returns the receiver's drop-down menu if it has one, or null 
331
 * if it does not.
332
 * <p>
333
 * The drop-down menu is activated when the arrow of an {@link SWT#DROP_DOWN}-styled receiver is pressed.
334
 * </p>
335
 * 
336
 * @return the receiver's drop-down menu
337
 * @exception SWTException <ul>
338
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
339
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
340
 * </ul>
341
 */
342
public Menu getMenu () {
343
	checkWidget();
344
	return menu;
345
}
346
347
/**
301
 * Returns the receiver's parent, which must be a <code>ToolBar</code>.
348
 * Returns the receiver's parent, which must be a <code>ToolBar</code>.
302
 *
349
 *
303
 * @return the receiver's parent
350
 * @return the receiver's parent
Lines 394-399 Link Here
394
void releaseWidget () {
441
void releaseWidget () {
395
	super.releaseWidget ();
442
	super.releaseWidget ();
396
	releaseImages ();
443
	releaseImages ();
444
	if (menu != null && !menu.isDisposed ()) {
445
		menu.dispose ();
446
	}
447
	menu = null;
397
	control = null;
448
	control = null;
398
	toolTipText = null;
449
	toolTipText = null;
399
	disabledImage = hotImage = null;
450
	disabledImage = hotImage = null;
Lines 435-440 Link Here
435
486
436
/**
487
/**
437
 * Removes the listener from the collection of listeners who will
488
 * Removes the listener from the collection of listeners who will
489
 * be notified when the platform-specific drop-down menu trigger has
490
 * occurred.
491
 *
492
 * @param listener the listener which should no longer be notified
493
 *
494
 * @exception IllegalArgumentException <ul>
495
 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
496
 * </ul>
497
 * @exception SWTException <ul>
498
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
499
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
500
 * </ul>
501
 *
502
 * @see MenuDetectListener
503
 * @see #addMenuDetectListener
504
 *
505
 * @since 3.3
506
 */
507
public void removeMenuDetectListener (MenuDetectListener listener) {
508
	checkWidget ();
509
	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
510
	if (eventTable == null) return;
511
	eventTable.unhook (SWT.MenuDetect, listener);
512
}
513
514
/**
515
 * Removes the listener from the collection of listeners who will
438
 * be notified when the control is selected by the user.
516
 * be notified when the control is selected by the user.
439
 *
517
 *
440
 * @param listener the listener which should no longer be notified
518
 * @param listener the listener which should no longer be notified
Lines 670-675 Link Here
670
	updateImages (getEnabled () && parent.getEnabled ());
748
	updateImages (getEnabled () && parent.getEnabled ());
671
}
749
}
672
750
751
/**
752
 * Sets the receiver's drop-down menu to the argument, which may be 
753
 * null indicating that no drop-down menu should be displayed.
754
 * <p>
755
 * If this property is null a drop-down menu can still be displayed manually by adding a
756
 * {@link SelectionListener} to the receiver and handling{@link SWT#ARROW} events.
757
 * <p>
758
 * The drop-down menu is activated when the arrow of an {@link SWT#DROP_DOWN}-styled
759
 * receiver or any portion of an {@link SWT#PUSH}-styled receiver is pressed.
760
 * </p>
761
 * 
762
 * @param menu the drop-down menu to be displayed when the receiver's arrow is pressed
763
 * @exception SWTException <ul>
764
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
765
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
766
 * </ul>
767
 */
768
public void setMenu (Menu menu) {
769
	checkWidget();
770
	if (menu != null) {
771
		if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
772
		if ((menu.style & SWT.POP_UP) == 0) {
773
			error (SWT.ERROR_MENU_NOT_POP_UP);
774
		}
775
		if (menu.parent != parent.menuShell ()) {
776
			error (SWT.ERROR_INVALID_PARENT);
777
		}
778
	}
779
	this.menu = menu;
780
}
781
673
boolean setRadioSelection (boolean value) {
782
boolean setRadioSelection (boolean value) {
674
	if ((style & SWT.RADIO) == 0) return false;
783
	if ((style & SWT.RADIO) == 0) return false;
675
	if (getSelection () != value) {
784
	if (getSelection () != value) {
(-)Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java (-2 / +18 lines)
Lines 213-219 Link Here
213
	createWidget ();
213
	createWidget ();
214
}
214
}
215
215
216
void _setVisible (boolean visible) {
216
public void _setVisible (boolean visible) {
217
	_setVisible(visible, null, 0);
218
}
219
220
void _setVisible (boolean visible, RECT excludeRect, int extraFlags) {
217
	if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
221
	if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
218
	int /*long*/ hwndParent = parent.handle;
222
	int /*long*/ hwndParent = parent.handle;
219
	if (visible) {
223
	if (visible) {
Lines 224-229 Link Here
224
			flags &= ~OS.TPM_RIGHTALIGN;
228
			flags &= ~OS.TPM_RIGHTALIGN;
225
			if ((style & SWT.LEFT_TO_RIGHT) != 0) flags |= OS.TPM_RIGHTALIGN;
229
			if ((style & SWT.LEFT_TO_RIGHT) != 0) flags |= OS.TPM_RIGHTALIGN;
226
		}
230
		}
231
		flags |= extraFlags;
227
		int nX = x, nY = y;
232
		int nX = x, nY = y;
228
		if (!hasLocation) {
233
		if (!hasLocation) {
229
			int pos = OS.GetMessagePos ();
234
			int pos = OS.GetMessagePos ();
Lines 243-249 Link Here
243
		* the case when TrackPopupMenu() fails and the number of items in
248
		* the case when TrackPopupMenu() fails and the number of items in
244
		* the menu is zero and issue a fake WM_MENUSELECT.
249
		* the menu is zero and issue a fake WM_MENUSELECT.
245
		*/
250
		*/
246
		boolean success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null);
251
		boolean success;
252
		if (excludeRect == null) {
253
			success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null);
254
		} else {
255
			TPMPARAMS lptpm = new TPMPARAMS();
256
			lptpm.cbSize = TPMPARAMS.sizeof;
257
			lptpm.left = excludeRect.left;
258
			lptpm.top = excludeRect.top;
259
			lptpm.right = excludeRect.right;
260
			lptpm.bottom = excludeRect.bottom;
261
			success = OS.TrackPopupMenuEx (handle, flags, nX, nY, hwndParent, lptpm);
262
		}
247
		if (!success && GetMenuItemCount (handle) == 0) {
263
		if (!success && GetMenuItemCount (handle) == 0) {
248
			OS.SendMessage (hwndParent, OS.WM_MENUSELECT, OS.MAKEWPARAM (0, 0xFFFF), 0);
264
			OS.SendMessage (hwndParent, OS.WM_MENUSELECT, OS.MAKEWPARAM (0, 0xFFFF), 0);
249
		}
265
		}
(-)Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java (+5 lines)
Lines 1580-1585 Link Here
1580
	public static final int TB_GETROWS = 0x428;
1580
	public static final int TB_GETROWS = 0x428;
1581
	public static final int TB_GETSTATE = 0x412;
1581
	public static final int TB_GETSTATE = 0x412;
1582
	public static final int TB_GETTOOLTIPS = 0x423;
1582
	public static final int TB_GETTOOLTIPS = 0x423;
1583
	public static final int TB_HITTEST = 0x445;
1583
	public static final int TB_INSERTBUTTON = IsUnicode ? 0x443 : 0x415;
1584
	public static final int TB_INSERTBUTTON = IsUnicode ? 0x443 : 0x415;
1584
	public static final int TB_LOADIMAGES = 0x432;
1585
	public static final int TB_LOADIMAGES = 0x432;
1585
	public static final int TB_MAPACCELERATOR = 0x0400 + (IsUnicode ? 90 : 78);
1586
	public static final int TB_MAPACCELERATOR = 0x0400 + (IsUnicode ? 90 : 78);
Lines 1665-1670 Link Here
1665
	public static final int TPM_LEFTBUTTON = 0x0;
1666
	public static final int TPM_LEFTBUTTON = 0x0;
1666
	public static final int TPM_RIGHTBUTTON = 0x2;
1667
	public static final int TPM_RIGHTBUTTON = 0x2;
1667
	public static final int TPM_RIGHTALIGN = 0x8;
1668
	public static final int TPM_RIGHTALIGN = 0x8;
1669
	public static final int TPM_HORIZONTAL = 0x00;
1670
	public static final int TPM_VERTICAL = 0x40;
1668
	public static final String TRACKBAR_CLASS = "msctls_trackbar32"; //$NON-NLS-1$
1671
	public static final String TRACKBAR_CLASS = "msctls_trackbar32"; //$NON-NLS-1$
1669
	public static final int TRANSPARENT = 0x1;
1672
	public static final int TRANSPARENT = 0x1;
1670
	public static final int TREIS_DISABLED = 4;
1673
	public static final int TREIS_DISABLED = 4;
Lines 2207-2212 Link Here
2207
public static final native int TF_DA_COLOR_sizeof ();
2210
public static final native int TF_DA_COLOR_sizeof ();
2208
public static final native int TF_DISPLAYATTRIBUTE_sizeof ();
2211
public static final native int TF_DISPLAYATTRIBUTE_sizeof ();
2209
public static final native int TOOLINFO_sizeof ();
2212
public static final native int TOOLINFO_sizeof ();
2213
public static final native int TPMPARAMS_sizeof ();
2210
public static final native int TRACKMOUSEEVENT_sizeof ();
2214
public static final native int TRACKMOUSEEVENT_sizeof ();
2211
public static final native int TRIVERTEX_sizeof ();
2215
public static final native int TRIVERTEX_sizeof ();
2212
public static final native int TVHITTESTINFO_sizeof ();
2216
public static final native int TVHITTESTINFO_sizeof ();
Lines 3962-3967 Link Here
3962
public static final native boolean TreeView_GetItemRect (int /*long*/ hwndTV, int /*long*/ hitem, RECT prc, boolean fItemRect);
3966
public static final native boolean TreeView_GetItemRect (int /*long*/ hwndTV, int /*long*/ hitem, RECT prc, boolean fItemRect);
3963
public static final native boolean TrackMouseEvent (TRACKMOUSEEVENT lpEventTrack);
3967
public static final native boolean TrackMouseEvent (TRACKMOUSEEVENT lpEventTrack);
3964
public static final native boolean TrackPopupMenu (int /*long*/ hMenu, int uFlags, int x, int y, int nReserved, int /*long*/ hWnd, RECT prcRect);
3968
public static final native boolean TrackPopupMenu (int /*long*/ hMenu, int uFlags, int x, int y, int nReserved, int /*long*/ hWnd, RECT prcRect);
3969
public static final native boolean TrackPopupMenuEx (int /*long*/ hMenu, int uFlags, int x, int y, int /*long*/ hWnd, TPMPARAMS lptpm);
3965
public static final native int TranslateAcceleratorW (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3970
public static final native int TranslateAcceleratorW (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3966
public static final native int TranslateAcceleratorA (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3971
public static final native int TranslateAcceleratorA (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3967
public static final native boolean TranslateCharsetInfo (int /*long*/ lpSrc, int [] lpCs, int dwFlags);
3972
public static final native boolean TranslateCharsetInfo (int /*long*/ lpSrc, int [] lpCs, int dwFlags);
(-)Eclipse (+8 lines)
Added Link Here
1
package org.eclipse.swt.internal.win32;
2
3
public class TPMPARAMS {
4
	public int cbSize;
5
//	public RECT rcExclude;
6
	public int left, top, right, bottom;
7
	public static int sizeof =  OS.TPMPARAMS_sizeof ();
8
}
(-)JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.win32.OS.properties (+17 lines)
Lines 4757-4762 Link Here
4757
4757
4758
OS_TOOLINFO_sizeof=
4758
OS_TOOLINFO_sizeof=
4759
4759
4760
OS_TPMPARAMS_sizeof=
4761
4760
OS_TRACKMOUSEEVENT_sizeof=
4762
OS_TRACKMOUSEEVENT_sizeof=
4761
4763
4762
OS_TRIVERTEX_sizeof=
4764
OS_TRIVERTEX_sizeof=
Lines 4798-4803 Link Here
4798
OS_TrackPopupMenu_5=cast=(HWND)
4800
OS_TrackPopupMenu_5=cast=(HWND)
4799
OS_TrackPopupMenu_6=
4801
OS_TrackPopupMenu_6=
4800
4802
4803
OS_TrackPopupMenuEx=
4804
OS_TrackPopupMenuEx_0=cast=(HMENU)
4805
OS_TrackPopupMenuEx_1=
4806
OS_TrackPopupMenuEx_2=
4807
OS_TrackPopupMenuEx_3=
4808
OS_TrackPopupMenuEx_4=cast=(HWND)
4809
OS_TrackPopupMenuEx_5=
4810
4801
OS_TranslateAcceleratorA=
4811
OS_TranslateAcceleratorA=
4802
OS_TranslateAcceleratorA_0=cast=(HWND)
4812
OS_TranslateAcceleratorA_0=cast=(HWND)
4803
OS_TranslateAcceleratorA_1=cast=(HACCEL)
4813
OS_TranslateAcceleratorA_1=cast=(HACCEL)
Lines 5450-5455 Link Here
5450
TOOLINFO_lParam=
5460
TOOLINFO_lParam=
5451
TOOLINFO_lpReserved=cast=(void *)
5461
TOOLINFO_lpReserved=cast=(void *)
5452
5462
5463
org_eclipse_swt_internal_win32_TPMPARAMS=
5464
TPMPARAMS_cbSize=
5465
TPMPARAMS_left=accessor=rcExclude.left
5466
TPMPARAMS_top=accessor=rcExclude.top
5467
TPMPARAMS_right=accessor=rcExclude.right
5468
TPMPARAMS_bottom=accessor=rcExclude.bottom
5469
5453
org_eclipse_swt_internal_win32_TRACKMOUSEEVENT=
5470
org_eclipse_swt_internal_win32_TRACKMOUSEEVENT=
5454
TRACKMOUSEEVENT_cbSize=
5471
TRACKMOUSEEVENT_cbSize=
5455
TRACKMOUSEEVENT_dwFlags=
5472
TRACKMOUSEEVENT_dwFlags=
(-)src/org/eclipse/swt/snippets/Snippet140.java (-38 / +35 lines)
Lines 51-97 Link Here
51
	coolItem.setMinimumSize(minWidth, coolSize.y);
51
	coolItem.setMinimumSize(minWidth, coolSize.y);
52
	coolItem.setPreferredSize(coolSize);
52
	coolItem.setPreferredSize(coolSize);
53
	coolItem.setSize(coolSize);
53
	coolItem.setSize(coolSize);
54
	coolItem.addSelectionListener(new SelectionAdapter() {
54
	coolItem.addMenuDetectListener(new MenuDetectListener() {
55
		public void widgetSelected(SelectionEvent event) {
55
		public void menuDetected(MenuDetectEvent event) {
56
			if (event.detail == SWT.ARROW) {
56
			CoolItem item = (CoolItem) event.widget;
57
				CoolItem item = (CoolItem) event.widget;
57
			Rectangle itemBounds = item.getBounds ();
58
				Rectangle itemBounds = item.getBounds ();
58
			Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y));
59
				Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y));
59
			itemBounds.x = pt.x;
60
				itemBounds.x = pt.x;
60
			itemBounds.y = pt.y;
61
				itemBounds.y = pt.y;
61
			ToolBar bar = (ToolBar) item.getControl ();
62
				ToolBar bar = (ToolBar) item.getControl ();
62
			ToolItem[] tools = bar.getItems ();
63
				ToolItem[] tools = bar.getItems ();
63
			
64
			int i = 0;
65
			while (i < tools.length) {
66
				Rectangle toolBounds = tools[i].getBounds ();
67
				pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y));
68
				toolBounds.x = pt.x;
69
				toolBounds.y = pt.y;
64
				
70
				
65
				int i = 0;
71
				/* Figure out the visible portion of the tool by looking at the
66
				while (i < tools.length) {
72
				 * intersection of the tool bounds with the cool item bounds. */
67
					Rectangle toolBounds = tools[i].getBounds ();
73
				Rectangle intersection = itemBounds.intersection (toolBounds);
68
					pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y));
69
					toolBounds.x = pt.x;
70
					toolBounds.y = pt.y;
71
					
72
					/* Figure out the visible portion of the tool by looking at the
73
					 * intersection of the tool bounds with the cool item bounds. */
74
			  		Rectangle intersection = itemBounds.intersection (toolBounds);
75
			  		
76
					/* If the tool is not completely within the cool item bounds, then it
77
					 * is partially hidden, and all remaining tools are completely hidden. */
78
			  		if (!intersection.equals (toolBounds)) break;
79
			  		i++;
80
				}
81
				
74
				
82
				/* Create a menu with items for each of the completely hidden buttons. */
75
				/* If the tool is not completely within the cool item bounds, then it
83
				if (chevronMenu != null) chevronMenu.dispose();
76
				 * is partially hidden, and all remaining tools are completely hidden. */
84
				chevronMenu = new Menu (coolBar);
77
				if (!intersection.equals (toolBounds)) break;
85
				for (int j = i; j < tools.length; j++) {
78
				i++;
86
					MenuItem menuItem = new MenuItem (chevronMenu, SWT.PUSH);
79
			}
87
					menuItem.setText (tools[j].getText());
80
			
88
				}
81
			/* Create a menu with items for each of the completely hidden buttons. */
89
				
82
			if (chevronMenu != null) chevronMenu.dispose();
90
				/* Drop down the menu below the chevron, with the left edges aligned. */
83
			chevronMenu = new Menu (coolBar);
91
				pt = coolBar.toDisplay(new Point(event.x, event.y));
84
			for (int j = i; j < tools.length; j++) {
92
				chevronMenu.setLocation (pt.x, pt.y);
85
				MenuItem menuItem = new MenuItem (chevronMenu, SWT.PUSH);
93
				chevronMenu.setVisible (true);
86
				menuItem.setText (tools[j].getText());
94
			}
87
			}
88
			
89
			/* Drop down the menu below the chevron, with the left edges aligned. */
90
			pt = coolBar.toDisplay(new Point(event.x, event.y));
91
			item.setMenu(chevronMenu);
95
		}
92
		}
96
	});
93
	});
97
94
(-)src/org/eclipse/swt/snippets/Snippet67.java (-11 / +1 lines)
Lines 32-48 Link Here
32
		item.setText ("Item " + i);
32
		item.setText ("Item " + i);
33
	}
33
	}
34
	final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
34
	final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
35
	item.addListener (SWT.Selection, new Listener () {
35
	item.setMenu(menu);
36
		public void handleEvent (Event event) {
37
			if (event.detail == SWT.ARROW) {
38
				Rectangle rect = item.getBounds ();
39
				Point pt = new Point (rect.x, rect.y + rect.height);
40
				pt = toolBar.toDisplay (pt);
41
				menu.setLocation (pt.x, pt.y);
42
				menu.setVisible (true);
43
			}
44
		}
45
	});
46
	toolBar.pack ();
36
	toolBar.pack ();
47
	shell.pack ();
37
	shell.pack ();
48
	shell.open ();
38
	shell.open ();
(-)src/org/eclipse/swt/snippets/Snippet67x.java (+132 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.swt.snippets;
12
13
/*
14
 * ToolBar example snippet: place a drop down menu in a tool bar
15
 *
16
 * For a list of all SWT example snippets see
17
 * http://www.eclipse.org/swt/snippets/
18
 */
19
import java.util.Date;
20
import java.util.Random;
21
22
import org.eclipse.swt.*;
23
import org.eclipse.swt.events.KeyAdapter;
24
import org.eclipse.swt.events.KeyEvent;
25
import org.eclipse.swt.events.MenuDetectEvent;
26
import org.eclipse.swt.events.MenuDetectListener;
27
import org.eclipse.swt.events.MouseAdapter;
28
import org.eclipse.swt.events.MouseEvent;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.events.SelectionListener;
31
import org.eclipse.swt.graphics.*;
32
import org.eclipse.swt.widgets.*;
33
34
public class Snippet67x {
35
36
public static void main (String [] args) {
37
	final Display display = new Display ();
38
	final Shell shell = new Shell (display);
39
	final ToolBar toolBar = new ToolBar (shell, SWT.FLAT);
40
	toolBar.addMouseListener(new MouseAdapter() {
41
	
42
		public void mouseDown(MouseEvent e) {
43
			long time = e.time & 0xFFFFFFFFL;
44
			System.out.println("mousedown " + new Date(time));
45
		}
46
47
		public void mouseDoubleClick(MouseEvent e) {
48
			long time = e.time & 0xFFFFFFFFL;
49
			System.out.println("mousedblclick");
50
		}
51
52
		public void mouseUp(MouseEvent e) {
53
			long time = e.time & 0xFFFFFFFFL;
54
			System.out.println("mouseup " + new Date(time));
55
		}
56
	
57
	});
58
	toolBar.addKeyListener(new KeyAdapter() {
59
	
60
		public void keyPressed(KeyEvent e) {
61
			System.out.println("keypressed");
62
		}
63
64
		public void keyReleased(KeyEvent e) {
65
			System.out.println("keyreleased");
66
		}
67
68
	});
69
	final Menu menu = new Menu (shell, SWT.POP_UP);
70
	for (int i=0; i<8; i++) {
71
		MenuItem item = new MenuItem (menu, SWT.PUSH);
72
		item.setText ("Item " + i);
73
	}
74
	final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
75
	item.addMenuDetectListener(new MenuDetectListener() {
76
	
77
		public void menuDetected(MenuDetectEvent e) {
78
			System.out.println("menudetectdropdown");
79
		}
80
	
81
	});
82
	item.setText("My Item");
83
	item.setMenu(menu);
84
	final ToolItem item2 = new ToolItem (toolBar, SWT.PUSH, 0);
85
	item2.setText("theone");
86
	item2.addSelectionListener(new SelectionListener() {
87
	
88
		public void widgetSelected(SelectionEvent e) {
89
			System.out.println("sel");
90
		}
91
	
92
		public void widgetDefaultSelected(SelectionEvent e) {
93
			System.out.println("default sel");
94
		}
95
	
96
	});
97
	item2.addMenuDetectListener(new MenuDetectListener(){
98
99
		public void menuDetected(MenuDetectEvent event) {
100
			System.out.println("menudetect");
101
			if (false) {
102
				event.doit = false;
103
			} else {
104
				if (item2.getMenu() != null) {
105
					item2.getMenu().dispose();
106
				}
107
				final Menu menu = new Menu (shell, SWT.POP_UP);
108
				for (int i=0; i<8; i++) {
109
					MenuItem item = new MenuItem (menu, SWT.PUSH);
110
					item.setText ("Item " + new Random().nextInt(10));
111
				}
112
				item2.setMenu(menu);
113
			}
114
		}
115
116
	});
117
	toolBar.pack ();
118
	
119
	Button btn = new Button(shell, SWT.PUSH);
120
	btn.setLocation(120, 00);
121
	btn.setText("Hello");
122
	btn.pack();
123
124
	shell.pack ();
125
	shell.open ();
126
	while (!shell.isDisposed ()) {
127
		if (!display.readAndDispatch ()) display.sleep ();
128
	}
129
	menu.dispose ();
130
	display.dispose ();
131
}
132
} 

Return to bug 193318