void ZLWin32ApplicationWindow::processChevron(const NMREBARCHEVRON &chevron) { RECT toolbarRect; GetClientRect(myWindowToolbar.hwnd, &toolbarRect); HIMAGELIST imageList = (HIMAGELIST)SendMessage(myWindowToolbar.hwnd, TB_GETIMAGELIST, 0, 0); int imageIndex = 0; const int len = SendMessage(myWindowToolbar.hwnd, TB_BUTTONCOUNT, 0, 0); int index = 0; for (; index < len; ++index) { TBBUTTON info; SendMessage(myWindowToolbar.hwnd, TB_GETBUTTON, index, (LPARAM)&info); if ((info.fsState & TBSTATE_HIDDEN) == 0) { RECT rect; SendMessage(myWindowToolbar.hwnd, TB_GETITEMRECT, index, (LPARAM)&rect); if (rect.right > toolbarRect.right) { break; } } if (info.idCommand > -100) { ++imageIndex; } } myPopupMenu = new ZLWin32PopupMenu(myMainWindow); for (; index < len; ++index) { TBBUTTON info; SendMessage(myWindowToolbar.hwnd, TB_GETBUTTON, index, (LPARAM)&info); if ((info.fsState & TBSTATE_HIDDEN) == 0) { ZLToolbar::ItemPtr item = myWindowToolbar.TBItemByActionCode[info.idCommand]; if (!item.isNull()) { const ZLToolbar::AbstractButtonItem &button = (const ZLToolbar::AbstractButtonItem&)*item; myPopupMenu->addItem( " " + button.tooltip(), ImageList_GetIcon(imageList, imageIndex, ILD_NORMAL), info.fsState & TBSTATE_ENABLED, info.idCommand ); } else if (info.idCommand >= -200) /* is a separator */ { myPopupMenu->addSeparator(); } } if (info.idCommand > -100) { ++imageIndex; } } POINT p; p.x = chevron.rc.right - 2; p.y = chevron.rc.bottom; ClientToScreen(myMainWindow, &p); onToolbarButtonRelease(myPopupMenu->run(p, true)); myPopupMenu.reset(); }
LRESULT ZLWin32ApplicationWindow::mainLoopCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case MY_WM_FULLSCREEN: setFullscreen(true); return 0; case WM_MEASUREITEM: if (!myPopupMenu.isNull()) { myPopupMenu->measureItem(*(MEASUREITEMSTRUCT*)lParam); } return 1; case WM_DRAWITEM: if (!myPopupMenu.isNull()) { myPopupMenu->drawItem(*(DRAWITEMSTRUCT*)lParam); } return 1; case WM_MOUSEWHEEL: if (!mouseEventsAreBlocked()) { application().doActionByKey( ((short)HIWORD(wParam) > 0) ? ZLApplication::MouseScrollUpKey : ZLApplication::MouseScrollDownKey ); } return 0; case WM_PAINT: { LRESULT code = DefWindowProc(hWnd, uMsg, wParam, lParam); updateWindowToolbarInfo(); updateFullscreenToolbarSize(); return code; } case WM_TIMER: ((ZLWin32TimeManager&)ZLTimeManager::instance()).execute(wParam); return 0; case WM_CREATE: myMainWindow = hWnd; ZLApplicationWindow::init(); return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_KEYDOWN: case WM_SYSKEYDOWN: if (wParam == 0x10) { myKeyboardModifierMask |= 0x1; } else if (wParam == 0x11) { myKeyboardModifierMask |= 0x2; } else if (wParam == 0x12) { myKeyboardModifierMask |= 0x4; } else { application().doActionByKey(ZLKeyUtil::keyName(wParam, wParam, myKeyboardModifierMask)); myKeyboardModifierMask = 0; } return 0; case WM_KEYUP: case WM_SYSKEYUP: if (wParam == 0x10) { myKeyboardModifierMask &= ~0x1; } else if (wParam == 0x11) { myKeyboardModifierMask &= ~0x2; } else if (wParam == 0x12) { myKeyboardModifierMask &= ~0x4; } return 0; case WM_SIZE: { RECT rebarRect; GetWindowRect(myRebar, &rebarRect); int offset = rebarRect.bottom - rebarRect.top - 1; MoveWindow(myRebar, 0, 0, LOWORD(lParam), rebarRect.bottom - rebarRect.top, true); if (myFullScreen) { offset = 0; } MoveWindow(myWin32ViewWidget->handle(), 0, offset, LOWORD(lParam), HIWORD(lParam) - offset, true); return DefWindowProc(hWnd, uMsg, wParam, lParam); } case WM_CLOSE: if (myFullScreen) { myWindowStateOption.setValue(FULLSCREEN); } else if (IsMaximized(myMainWindow)) { myWindowStateOption.setValue(MAXIMIZED); } else { myWindowStateOption.setValue(NORMAL); RECT rectangle; GetWindowRect(myMainWindow, &rectangle); myXOption.setValue(rectangle.left); myYOption.setValue(rectangle.top); myWidthOption.setValue(rectangle.right - rectangle.left + 1); myHeightOption.setValue(rectangle.bottom - rectangle.top + 1); } application().closeView(); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_COMMAND: onToolbarButtonRelease(LOWORD(wParam)); return 0; case WM_NOTIFY: { const NMHDR *notificationHeader = (const NMHDR*)lParam; switch (notificationHeader->code) { case TTN_NEEDTEXT: setTooltip(*(TOOLTIPTEXT*)lParam); break; case NM_CUSTOMDRAW: updateParameters(); break; case TBN_DROPDOWN: runPopup(*(const NMTOOLBAR*)lParam); break; case RBN_CHEVRONPUSHED: processChevron(*(const NMREBARCHEVRON*)lParam); break; } return 0; } default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } }