]> git.saurik.com Git - wxWidgets.git/commitdiff
don't use char hook to handle Esc in the dialogs, it is too blunt and prevents us...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Feb 2004 16:20:02 +0000 (16:20 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Feb 2004 16:20:02 +0000 (16:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25649 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/msw/dialog.cpp
src/msw/window.cpp

index 1c04fd1f1706fe1c2de45e256425f6d75202dd21..df860b7234b4a2b90e8c84f1999c5ffe3e8051c2 100644 (file)
@@ -156,6 +156,7 @@ wxMSW:
 - accelerators are now initially hidden if appropriate (Peter Nielsen)
 - background colour of a wxComboBox may now be set
 - fixed wxListCtrl::GetItemText/BackgroundColour()
+- Esc can now be used to close menus in the dialogs (Hartmut Honisch)
 
 wxGTK:
 
index 20b10cd112758af665cb9db7addbe4d0ba3e7fae..d1f46b4b371d142d6ff86b7c112527a1d3a4bb0b 100644 (file)
@@ -113,8 +113,6 @@ BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
     EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
     EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
 
-    EVT_CHAR_HOOK(wxDialog::OnCharHook)
-
     EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
 
     EVT_CLOSE(wxDialog::OnCloseWindow)
@@ -214,35 +212,6 @@ wxDialog::~wxDialog()
     Show(FALSE);
 }
 
-// ----------------------------------------------------------------------------
-// kbd handling
-// ----------------------------------------------------------------------------
-
-// By default, pressing escape cancels the dialog
-void wxDialog::OnCharHook(wxKeyEvent& event)
-{
-    if (GetHWND())
-    {
-        // "Esc" works as an accelerator for the "Cancel" button, but it
-        // shouldn't close the dialog which doesn't have any cancel button
-        if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) )
-        {
-            wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
-            cancelEvent.SetEventObject( this );
-            GetEventHandler()->ProcessEvent(cancelEvent);
-
-            // ensure that there is another message for this window so the
-            // ShowModal loop will exit and won't get stuck in GetMessage().
-            ::PostMessage(GetHwnd(), WM_NULL, 0, 0);
-
-            return;
-        }
-    }
-
-    // We didn't process this event.
-    event.Skip();
-}
-
 // ----------------------------------------------------------------------------
 // showing the dialogs
 // ----------------------------------------------------------------------------
index eb062f01029bd1dcaa3c4fcc8d95f62dfcee0de0..5762e1de98547a37ba8c13aaed6f4d9e37635ae0 100644 (file)
@@ -1837,6 +1837,25 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                         bProcess = FALSE;
                     break;
 
+                case VK_ESCAPE:
+                    {
+#if wxUSE_BUTTON
+                        wxButton *btn = wxDynamicCast(FindWindow(wxID_CANCEL),
+                                                      wxButton);
+                        if ( btn && btn->IsEnabled() )
+                        {
+                            // if we do have a cancel button, do press it
+                            btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+
+                            // we consumed the message
+                            return TRUE;
+                        }
+#endif // wxUSE_BUTTON
+
+                        bProcess = FALSE;
+                    }
+                    break;
+
                 case VK_RETURN:
                     {
                         if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
@@ -1950,8 +1969,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
         }
 #endif // 1/0
 
-        // we handle VK_ESCAPE ourselves in wxDialog::OnCharHook() and we
-        // shouldn't let IsDialogMessage() get it as it _always_ eats the
+        // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
         // message even when there is no cancel button and when the message is
         // needed by the control itself: in particular, it prevents the tree in
         // place edit control from being closed with Escape in a dialog