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 1119-1124
Link Here
|
1119 |
* application the opportunity to cancel the operation. |
1120 |
* application the opportunity to cancel the operation. |
1120 |
*/ |
1121 |
*/ |
1121 |
return LRESULT.ZERO; |
1122 |
return LRESULT.ZERO; |
|
|
1123 |
case OS.VK_DOWN: |
1124 |
case OS.VK_UP: |
1125 |
/* |
1126 |
* SWT.DROPDOWN menus are automatically triggered by Windows on the |
1127 |
* UP and DOWN keys. Here we mirror this behavior for PUSH items. |
1128 |
*/ |
1129 |
int itemIndex = OS.SendMessage(handle, OS.TB_GETHOTITEM, 0, 0); |
1130 |
if (handlePushItemMenu(itemIndex)) { |
1131 |
return LRESULT.ZERO; |
1132 |
} |
1122 |
} |
1133 |
} |
1123 |
return result; |
1134 |
return result; |
1124 |
} |
1135 |
} |
Lines 1131-1138
Link Here
|
1131 |
return super.WM_KILLFOCUS (wParam, lParam); |
1142 |
return super.WM_KILLFOCUS (wParam, lParam); |
1132 |
} |
1143 |
} |
1133 |
|
1144 |
|
|
|
1145 |
LRESULT WM_LBUTTONDBLCLK(int wParam, int lParam) { |
1146 |
POINT point = new POINT (); |
1147 |
point.x = OS.GET_X_LPARAM (lParam); |
1148 |
point.y = OS.GET_Y_LPARAM (lParam); |
1149 |
int itemIndex = OS.SendMessage (handle, OS.TB_HITTEST, 0, point); |
1150 |
if (handlePushItemMenu (itemIndex)) { |
1151 |
return LRESULT.ZERO; |
1152 |
} |
1153 |
return super.WM_LBUTTONDBLCLK(wParam, lParam); |
1154 |
} |
1155 |
|
1134 |
LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { |
1156 |
LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { |
|
|
1157 |
if (!showingPushItemMenu) { |
1158 |
POINT point = new POINT (); |
1159 |
point.x = OS.GET_X_LPARAM (lParam); |
1160 |
point.y = OS.GET_Y_LPARAM (lParam); |
1161 |
int itemIndex = OS.SendMessage (handle, OS.TB_HITTEST, 0, point); |
1162 |
if (handlePushItemMenu (itemIndex)) { |
1163 |
return LRESULT.ZERO; |
1164 |
} |
1165 |
} else { |
1166 |
showingPushItemMenu = false; |
1167 |
return LRESULT.ZERO; |
1168 |
} |
1169 |
|
1135 |
if (ignoreMouse) return null; |
1170 |
if (ignoreMouse) return null; |
|
|
1171 |
|
1136 |
return super.WM_LBUTTONDOWN (wParam, lParam); |
1172 |
return super.WM_LBUTTONDOWN (wParam, lParam); |
1137 |
} |
1173 |
} |
1138 |
|
1174 |
|
Lines 1306-1312
Link Here
|
1306 |
OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect); |
1342 |
OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect); |
1307 |
event.x = rect.left; |
1343 |
event.x = rect.left; |
1308 |
event.y = rect.bottom; |
1344 |
event.y = rect.bottom; |
1309 |
child.postEvent (SWT.Selection, event); |
1345 |
|
|
|
1346 |
if (sendItemMenuDetectEvent (child, rect, SWT.ARROW)) { |
1347 |
// Without this call, an lbuttondown event that triggers the menu |
1348 |
// will not be delivered to EventListeners until after the menu has been closed. |
1349 |
display.runDeferredEvents(); |
1350 |
showItemMenu (child, rect); |
1351 |
} else { |
1352 |
child.postEvent (SWT.Selection, event); |
1353 |
} |
1310 |
} |
1354 |
} |
1311 |
break; |
1355 |
break; |
1312 |
case OS.NM_CUSTOMDRAW: |
1356 |
case OS.NM_CUSTOMDRAW: |
Lines 1363-1366
Link Here
|
1363 |
return super.wmNotifyChild (hdr, wParam, lParam); |
1407 |
return super.wmNotifyChild (hdr, wParam, lParam); |
1364 |
} |
1408 |
} |
1365 |
|
1409 |
|
|
|
1410 |
private boolean handlePushItemMenu(int itemIndex) { |
1411 |
// Inspect non-separator item under the cursor |
1412 |
if (itemIndex >= 0) { |
1413 |
// Get item instance |
1414 |
TBBUTTON button = new TBBUTTON (); |
1415 |
OS.SendMessage (handle, OS.TB_GETBUTTON, itemIndex, button); |
1416 |
ToolItem child = items[button.idCommand]; |
1417 |
// Only allow menu display for PUSH items |
1418 |
final int toolItemStyleMask = SWT.PUSH | SWT.CHECK | SWT.RADIO |
1419 |
| SWT.SEPARATOR | SWT.DROP_DOWN; |
1420 |
if ((child.style & toolItemStyleMask) == SWT.PUSH) { |
1421 |
// Get item state |
1422 |
int itemState = OS.SendMessage (handle, OS.TB_GETSTATE, button.idCommand, 0); |
1423 |
// Only attempt to show a menu if the item is enabled |
1424 |
if ((itemState & OS.TBSTATE_ENABLED) != 0) { |
1425 |
RECT rect = new RECT (); |
1426 |
OS.SendMessage (handle, OS.TB_GETITEMRECT, itemIndex, rect); |
1427 |
if (sendItemMenuDetectEvent (child, rect, 0)) { |
1428 |
// Press item |
1429 |
itemState |= OS.TBSTATE_PRESSED; |
1430 |
OS.SendMessage (handle, OS.TB_SETSTATE, button.idCommand, itemState); |
1431 |
// Show menu |
1432 |
showingPushItemMenu = true; |
1433 |
showItemMenu (child, rect); |
1434 |
// Unpress item - reload item state since it may have changed |
1435 |
itemState = OS.SendMessage (handle, OS.TB_GETSTATE, button.idCommand, 0); |
1436 |
itemState &= ~OS.TBSTATE_PRESSED; |
1437 |
OS.SendMessage (handle, OS.TB_SETSTATE, button.idCommand, itemState); |
1438 |
// Allow the mouse event that cancelled the menu to be eaten away |
1439 |
// since on reentrance to the method showingPushItemMenu will still be true. |
1440 |
// This allows the menu to be closed on a second click. |
1441 |
if (display != null && !display.isDisposed ()) { |
1442 |
display.readAndDispatch (); |
1443 |
} |
1444 |
showingPushItemMenu = false; |
1445 |
return true; |
1446 |
} |
1447 |
} |
1448 |
} |
1449 |
} |
1450 |
return false; |
1451 |
} |
1452 |
|
1453 |
private void showItemMenu (ToolItem child, RECT rect) { |
1454 |
Menu menu = child.menu; |
1455 |
OS.MapWindowPoints (handle, 0, rect, 2); |
1456 |
menu.setLocation (rect.left, rect.bottom); |
1457 |
menu._setVisible (true, rect, OS.TPM_VERTICAL); |
1458 |
} |
1459 |
|
1460 |
private boolean sendItemMenuDetectEvent (ToolItem child, RECT rect, int detail) { |
1461 |
Event event = new Event (); |
1462 |
event.detail = detail; |
1463 |
event.x = rect.left; |
1464 |
event.y = rect.bottom; |
1465 |
child.sendEvent (SWT.MenuDetect, event); |
1466 |
Menu menu = child.menu; |
1467 |
return event.doit && menu != null && !menu.isDisposed(); |
1468 |
} |
1469 |
|
1366 |
} |
1470 |
} |