]> git.saurik.com Git - wxWidgets.git/commitdiff
handle accel keys for owner drawn menu items (based on the patch 657105)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 21 Dec 2002 15:01:21 +0000 (15:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 21 Dec 2002 15:01:21 +0000 (15:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18389 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/window.h
src/msw/window.cpp

index 8d8f82a50d5d32be56d46e78d5b1c48e66c965d0..af9579572a76c8fa28eab5e58a3dea35d1fecde2 100644 (file)
@@ -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:
 
index ff29093534c97526cec9d79cf30e17f841eccb5b..bd2d747fbd092b38d5459400d98a9aafca45e515 100644 (file)
@@ -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);
 
index 890bd089c33ddd80c7bfb7b70f7494565038000c..7cf2d2292afc366fb7e6119f6f2c87f46c4135ab 100644 (file)
@@ -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
 // ---------------------------------------------------------------------------