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 1018-1023
Link Here
|
1018 |
} |
1019 |
} |
1019 |
|
1020 |
|
1020 |
LRESULT WM_CAPTURECHANGED (int /*long*/ wParam, int /*long*/ lParam) { |
1021 |
LRESULT WM_CAPTURECHANGED (int /*long*/ wParam, int /*long*/ 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 |
} |