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

Collapse All | Expand All

(-)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/ToolBar.java (-5 / +129 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 ToolBarProc;
48
	static final int 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 1018-1023 Link Here
1018
}
1019
}
1019
1020
1020
LRESULT WM_CAPTURECHANGED (int wParam, int 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 
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 = 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 wParam, int 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 = 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 wParam, int lParam) {
1173
LRESULT WM_LBUTTONDOWN (int wParam, int 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 = 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 = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmtb.iItem, 0);
1357
				int index = 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 = 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 = 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 = 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 unpushed 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/Menu.java (-2 / +18 lines)
Lines 195-201 Link Here
195
	createWidget ();
195
	createWidget ();
196
}
196
}
197
197
198
void _setVisible (boolean visible) {
198
public void _setVisible (boolean visible) {
199
	_setVisible(visible, null, 0);
200
}
201
202
void _setVisible (boolean visible, RECT excludeRect, int extraFlags) {
199
	if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
203
	if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
200
	int hwndParent = parent.handle;
204
	int hwndParent = parent.handle;
201
	if (visible) {
205
	if (visible) {
Lines 206-211 Link Here
206
			flags &= ~OS.TPM_RIGHTALIGN;
210
			flags &= ~OS.TPM_RIGHTALIGN;
207
			if ((style & SWT.LEFT_TO_RIGHT) != 0) flags |= OS.TPM_RIGHTALIGN;
211
			if ((style & SWT.LEFT_TO_RIGHT) != 0) flags |= OS.TPM_RIGHTALIGN;
208
		}
212
		}
213
		flags |= extraFlags;
209
		int nX = x, nY = y;
214
		int nX = x, nY = y;
210
		if (!hasLocation) {
215
		if (!hasLocation) {
211
			int pos = OS.GetMessagePos ();
216
			int pos = OS.GetMessagePos ();
Lines 225-231 Link Here
225
		* the case when TrackPopupMenu() fails and the number of items in
230
		* the case when TrackPopupMenu() fails and the number of items in
226
		* the menu is zero and issue a fake WM_MENUSELECT.
231
		* the menu is zero and issue a fake WM_MENUSELECT.
227
		*/
232
		*/
228
		boolean success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null);
233
		boolean success;
234
		if (excludeRect == null) {
235
			success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null);
236
		} else {
237
			TPMPARAMS lptpm = new TPMPARAMS();
238
			lptpm.cbSize = TPMPARAMS.sizeof;
239
			lptpm.left = excludeRect.left;
240
			lptpm.top = excludeRect.top;
241
			lptpm.right = excludeRect.right;
242
			lptpm.bottom = excludeRect.bottom;
243
			success = OS.TrackPopupMenuEx (handle, flags, nX, nY, hwndParent, lptpm);
244
		}
229
		if (!success && GetMenuItemCount (handle) == 0) {
245
		if (!success && GetMenuItemCount (handle) == 0) {
230
			OS.SendMessage (hwndParent, OS.WM_MENUSELECT, OS.MAKEWPARAM (0, 0xFFFF), 0);
246
			OS.SendMessage (hwndParent, OS.WM_MENUSELECT, OS.MAKEWPARAM (0, 0xFFFF), 0);
231
		}
247
		}
(-)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 PI/win32/library/os_stats.c (-2 / +3 lines)
Lines 14-21 Link Here
14
14
15
#ifdef NATIVE_STATS
15
#ifdef NATIVE_STATS
16
16
17
int OS_nativeFunctionCount = 883;
17
int OS_nativeFunctionCount = 884;
18
int OS_nativeFunctionCallCount[883];
18
int OS_nativeFunctionCallCount[884];
19
char * OS_nativeFunctionNames[] = {
19
char * OS_nativeFunctionNames[] = {
20
	"ACCEL_1sizeof",
20
	"ACCEL_1sizeof",
21
	"ACTCTX_1sizeof",
21
	"ACTCTX_1sizeof",
Lines 867-872 Link Here
867
	"ToUnicode",
867
	"ToUnicode",
868
	"TrackMouseEvent",
868
	"TrackMouseEvent",
869
	"TrackPopupMenu",
869
	"TrackPopupMenu",
870
	"TrackPopupMenuEx",
870
	"TranslateAcceleratorA",
871
	"TranslateAcceleratorA",
871
	"TranslateAcceleratorW",
872
	"TranslateAcceleratorW",
872
	"TranslateCharsetInfo",
873
	"TranslateCharsetInfo",
(-)Eclipse SWT PI/win32/library/os_structs.h (+12 lines)
Lines 1427-1432 Link Here
1427
#define TOOLINFO_sizeof() 0
1427
#define TOOLINFO_sizeof() 0
1428
#endif
1428
#endif
1429
1429
1430
#ifndef NO_TPMPARAMS
1431
void cacheTPMPARAMSFields(JNIEnv *env, jobject lpObject);
1432
TPMPARAMS *getTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct);
1433
void setTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct);
1434
#define TPMPARAMS_sizeof() sizeof(TPMPARAMS)
1435
#else
1436
#define cacheTPMPARAMSFields(a,b)
1437
#define getTPMPARAMSFields(a,b,c) NULL
1438
#define setTPMPARAMSFields(a,b,c)
1439
#define TPMPARAMS_sizeof() 0
1440
#endif
1441
1430
#ifndef NO_TRACKMOUSEEVENT
1442
#ifndef NO_TRACKMOUSEEVENT
1431
void cacheTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject);
1443
void cacheTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject);
1432
TRACKMOUSEEVENT *getTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpStruct);
1444
TRACKMOUSEEVENT *getTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpStruct);
(-)Eclipse SWT PI/win32/library/os_stats.h (+1 lines)
Lines 875-880 Link Here
875
	ToUnicode_FUNC,
875
	ToUnicode_FUNC,
876
	TrackMouseEvent_FUNC,
876
	TrackMouseEvent_FUNC,
877
	TrackPopupMenu_FUNC,
877
	TrackPopupMenu_FUNC,
878
	TrackPopupMenuEx_FUNC,
878
	TranslateAcceleratorA_FUNC,
879
	TranslateAcceleratorA_FUNC,
879
	TranslateAcceleratorW_FUNC,
880
	TranslateAcceleratorW_FUNC,
880
	TranslateCharsetInfo_FUNC,
881
	TranslateCharsetInfo_FUNC,
(-)Eclipse SWT PI/win32/library/os_structs.c (+43 lines)
Lines 6523-6528 Link Here
6523
}
6523
}
6524
#endif
6524
#endif
6525
6525
6526
#ifndef NO_TPMPARAMS
6527
typedef struct TPMPARAMS_FID_CACHE {
6528
	int cached;
6529
	jclass clazz;
6530
	jfieldID cbSize, left, top, right, bottom;
6531
} TPMPARAMS_FID_CACHE;
6532
6533
TPMPARAMS_FID_CACHE TPMPARAMSFc;
6534
6535
void cacheTPMPARAMSFields(JNIEnv *env, jobject lpObject)
6536
{
6537
	if (TPMPARAMSFc.cached) return;
6538
	TPMPARAMSFc.clazz = (*env)->GetObjectClass(env, lpObject);
6539
	TPMPARAMSFc.cbSize = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "cbSize", "I");
6540
	TPMPARAMSFc.left = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "left", "I");
6541
	TPMPARAMSFc.top = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "top", "I");
6542
	TPMPARAMSFc.right = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "right", "I");
6543
	TPMPARAMSFc.bottom = (*env)->GetFieldID(env, TPMPARAMSFc.clazz, "bottom", "I");
6544
	TPMPARAMSFc.cached = 1;
6545
}
6546
6547
TPMPARAMS *getTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct)
6548
{
6549
	if (!TPMPARAMSFc.cached) cacheTPMPARAMSFields(env, lpObject);
6550
	lpStruct->cbSize = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.cbSize);
6551
	lpStruct->rcExclude.left = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.left);
6552
	lpStruct->rcExclude.top = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.top);
6553
	lpStruct->rcExclude.right = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.right);
6554
	lpStruct->rcExclude.bottom = (*env)->GetIntField(env, lpObject, TPMPARAMSFc.bottom);
6555
	return lpStruct;
6556
}
6557
6558
void setTPMPARAMSFields(JNIEnv *env, jobject lpObject, TPMPARAMS *lpStruct)
6559
{
6560
	if (!TPMPARAMSFc.cached) cacheTPMPARAMSFields(env, lpObject);
6561
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.cbSize, (jint)lpStruct->cbSize);
6562
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.left, (jint)lpStruct->rcExclude.left);
6563
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.top, (jint)lpStruct->rcExclude.top);
6564
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.right, (jint)lpStruct->rcExclude.right);
6565
	(*env)->SetIntField(env, lpObject, TPMPARAMSFc.bottom, (jint)lpStruct->rcExclude.bottom);
6566
}
6567
#endif
6568
6526
#ifndef NO_TRACKMOUSEEVENT
6569
#ifndef NO_TRACKMOUSEEVENT
6527
typedef struct TRACKMOUSEEVENT_FID_CACHE {
6570
typedef struct TRACKMOUSEEVENT_FID_CACHE {
6528
	int cached;
6571
	int cached;
(-)Eclipse SWT PI/win32/library/os.c (+28 lines)
Lines 13506-13511 Link Here
13506
}
13506
}
13507
#endif
13507
#endif
13508
13508
13509
#ifndef NO_TPMPARAMS_1sizeof
13510
JNIEXPORT jint JNICALL OS_NATIVE(TPMPARAMS_1sizeof)
13511
	(JNIEnv *env, jclass that)
13512
{
13513
	jint rc = 0;
13514
	OS_NATIVE_ENTER(env, that, TPMPARAMS_1sizeof_FUNC);
13515
	rc = (jint)TPMPARAMS_sizeof();
13516
	OS_NATIVE_EXIT(env, that, TPMPARAMS_1sizeof_FUNC);
13517
	return rc;
13518
}
13519
#endif
13520
13509
#ifndef NO_TRACKMOUSEEVENT_1sizeof
13521
#ifndef NO_TRACKMOUSEEVENT_1sizeof
13510
JNIEXPORT jint JNICALL OS_NATIVE(TRACKMOUSEEVENT_1sizeof)
13522
JNIEXPORT jint JNICALL OS_NATIVE(TRACKMOUSEEVENT_1sizeof)
13511
	(JNIEnv *env, jclass that)
13523
	(JNIEnv *env, jclass that)
Lines 13660-13665 Link Here
13660
}
13672
}
13661
#endif
13673
#endif
13662
13674
13675
#ifndef NO_TrackPopupMenuEx
13676
JNIEXPORT jboolean JNICALL OS_NATIVE(TrackPopupMenuEx)
13677
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3, jint arg4, jobject arg5)
13678
{
13679
	TPMPARAMS _arg5, *lparg5=NULL;
13680
	jboolean rc = 0;
13681
	OS_NATIVE_ENTER(env, that, TrackPopupMenuEx_FUNC);
13682
	if (arg5) if ((lparg5 = getTPMPARAMSFields(env, arg5, &_arg5)) == NULL) goto fail;
13683
	rc = (jboolean)TrackPopupMenuEx(arg0, arg1, arg2, arg3, arg4, lparg5);
13684
fail:
13685
	if (arg5 && lparg5) setTPMPARAMSFields(env, arg5, lparg5);
13686
	OS_NATIVE_EXIT(env, that, TrackPopupMenuEx_FUNC);
13687
	return rc;
13688
}
13689
#endif
13690
13663
#ifndef NO_TranslateAcceleratorA
13691
#ifndef NO_TranslateAcceleratorA
13664
JNIEXPORT jint JNICALL OS_NATIVE(TranslateAcceleratorA)
13692
JNIEXPORT jint JNICALL OS_NATIVE(TranslateAcceleratorA)
13665
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2)
13693
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2)
(-)Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java (+5 lines)
Lines 1548-1553 Link Here
1548
	public static final int TB_GETROWS = 0x428;
1548
	public static final int TB_GETROWS = 0x428;
1549
	public static final int TB_GETSTATE = 0x412;
1549
	public static final int TB_GETSTATE = 0x412;
1550
	public static final int TB_GETTOOLTIPS = 0x423;
1550
	public static final int TB_GETTOOLTIPS = 0x423;
1551
	public static final int TB_HITTEST = 0x445;
1551
	public static final int TB_INSERTBUTTON = IsUnicode ? 0x443 : 0x415;
1552
	public static final int TB_INSERTBUTTON = IsUnicode ? 0x443 : 0x415;
1552
	public static final int TB_LOADIMAGES = 0x432;
1553
	public static final int TB_LOADIMAGES = 0x432;
1553
	public static final int TB_MAPACCELERATOR = 0x0400 + (IsUnicode ? 90 : 78);
1554
	public static final int TB_MAPACCELERATOR = 0x0400 + (IsUnicode ? 90 : 78);
Lines 1618-1623 Link Here
1618
	public static final int TPM_LEFTBUTTON = 0x0;
1619
	public static final int TPM_LEFTBUTTON = 0x0;
1619
	public static final int TPM_RIGHTBUTTON = 0x2;
1620
	public static final int TPM_RIGHTBUTTON = 0x2;
1620
	public static final int TPM_RIGHTALIGN = 0x8;
1621
	public static final int TPM_RIGHTALIGN = 0x8;
1622
	public static final int TPM_HORIZONTAL = 0x00;
1623
	public static final int TPM_VERTICAL = 0x40;
1621
	public static final String TRACKBAR_CLASS = "msctls_trackbar32"; //$NON-NLS-1$
1624
	public static final String TRACKBAR_CLASS = "msctls_trackbar32"; //$NON-NLS-1$
1622
	public static final int TRANSPARENT = 0x1;
1625
	public static final int TRANSPARENT = 0x1;
1623
	public static final int TREIS_DISABLED = 4;
1626
	public static final int TREIS_DISABLED = 4;
Lines 2138-2143 Link Here
2138
public static final native int TEXTMETRICA_sizeof ();
2141
public static final native int TEXTMETRICA_sizeof ();
2139
public static final native int TEXTMETRICW_sizeof ();
2142
public static final native int TEXTMETRICW_sizeof ();
2140
public static final native int TOOLINFO_sizeof ();
2143
public static final native int TOOLINFO_sizeof ();
2144
public static final native int TPMPARAMS_sizeof ();
2141
public static final native int TRACKMOUSEEVENT_sizeof ();
2145
public static final native int TRACKMOUSEEVENT_sizeof ();
2142
public static final native int TRIVERTEX_sizeof ();
2146
public static final native int TRIVERTEX_sizeof ();
2143
public static final native int TVHITTESTINFO_sizeof ();
2147
public static final native int TVHITTESTINFO_sizeof ();
Lines 3858-3863 Link Here
3858
public static final native boolean TreeView_GetItemRect (int /*long*/ hwndTV, int /*long*/ hitem, RECT prc, boolean fItemRect);
3862
public static final native boolean TreeView_GetItemRect (int /*long*/ hwndTV, int /*long*/ hitem, RECT prc, boolean fItemRect);
3859
public static final native boolean TrackMouseEvent (TRACKMOUSEEVENT lpEventTrack);
3863
public static final native boolean TrackMouseEvent (TRACKMOUSEEVENT lpEventTrack);
3860
public static final native boolean TrackPopupMenu (int /*long*/ hMenu, int uFlags, int x, int y, int nReserved, int /*long*/ hWnd, RECT prcRect);
3864
public static final native boolean TrackPopupMenu (int /*long*/ hMenu, int uFlags, int x, int y, int nReserved, int /*long*/ hWnd, RECT prcRect);
3865
public static final native boolean TrackPopupMenuEx (int /*long*/ hMenu, int uFlags, int x, int y, int /*long*/ hWnd, TPMPARAMS lptpm);
3861
public static final native int TranslateAcceleratorW (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3866
public static final native int TranslateAcceleratorW (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3862
public static final native int TranslateAcceleratorA (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3867
public static final native int TranslateAcceleratorA (int /*long*/ hWnd, int /*long*/ hAccTable, MSG lpMsg);
3863
public static final native boolean TranslateCharsetInfo (int /*long*/ lpSrc, int [] lpCs, int dwFlags);
3868
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
}

Return to bug 193318