diff --git a/docs/changes.txt b/docs/changes.txt index 1c04fd1f17..df860b7234 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index 20b10cd112..d1f46b4b37 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -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 // ---------------------------------------------------------------------------- diff --git a/src/msw/window.cpp b/src/msw/window.cpp index eb062f0102..5762e1de98 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -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