From b74cce40fd1ddd4d1432ff668deee5ea89cd406c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 Dec 2002 15:01:21 +0000 Subject: [PATCH] handle accel keys for owner drawn menu items (based on the patch 657105) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18389 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/window.h | 3 ++ src/msw/window.cpp | 77 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 8d8f82a50d..af9579572a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -22,6 +22,7 @@ wxGTK: wxMSW: - wxStaticBitmap doesn't stretch its bitmap any longer (like other ports) +- support for accelerator keys in the owner drawn menus (Derry Bryson) All: diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index ff29093534..bd2d747fbd 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -367,6 +367,9 @@ public: bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = FALSE); bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam); bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam); +#ifdef __WIN32__ + int HandleMenuChar(int chAccel, WXLPARAM lParam); +#endif bool HandleQueryDragIcon(WXHICON *hIcon); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 890bd089c3..7cf2d2292a 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -2887,6 +2887,20 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam processed = GetEventHandler()->ProcessEvent(evtCtx); } break; + + case WM_MENUCHAR: + // we're only interested in our own menus, not MF_SYSMENU + if ( HIWORD(wParam) == MF_POPUP ) + { + // handle menu chars for ownerdrawn menu items + int i = HandleMenuChar(toupper(LOWORD(wParam)), lParam); + if ( i != wxNOT_FOUND ) + { + rc.result = MAKELRESULT(i, MNC_EXECUTE); + processed = TRUE; + } + } + break; #endif // __WIN32__ } @@ -4478,6 +4492,69 @@ bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam) return FALSE; } +#ifdef __WIN32__ + +int wxWindowMSW::HandleMenuChar(int chAccel, WXLPARAM lParam) +{ + const HMENU hmenu = (HMENU)lParam; + + MENUITEMINFO mii; + wxZeroMemory(mii); + mii.cbSize = sizeof(MENUITEMINFO); + mii.fMask = MIIM_TYPE | MIIM_DATA; + + // find if we have this letter in any owner drawn item + const int count = ::GetMenuItemCount(hmenu); + for ( int i = 0; i < count; i++ ) + { + if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) ) + { + if ( mii.fType == MFT_OWNERDRAW ) + { + // dwItemData member of the MENUITEMINFO is a + // pointer to the associated wxMenuItem -- see the + // menu creation code + wxMenuItem *item = (wxMenuItem*)mii.dwItemData; + + const wxChar *p = wxStrchr(item->GetText(), _T('&')); + while ( p++ ) + { + if ( *p == _T('&') ) + { + // this is not the accel char, find the real one + p = wxStrchr(p + 1, _T('&')); + } + else // got the accel char + { + // FIXME-UNICODE: this comparison doesn't risk to work + // for non ASCII accelerator characters I'm afraid, but + // what can we do? + if ( wxToupper(*p) == chAccel ) + { + return i; + } + else + { + // this one doesn't match + break; + } + } + } + } + } + else // failed ot get the menu text? + { + // it's not fatal, so don't show error, but still log + // it + wxLogLastError(_T("GetMenuItemInfo")); + } + } + + return wxNOT_FOUND; +} + +#endif // __WIN32__ + // --------------------------------------------------------------------------- // joystick // --------------------------------------------------------------------------- -- 2.45.2