moved Esc processing from wxWindow to wxDialog where it belongs; use the -- to be implemented in 2.7 -- GetEscapeId() to decide what to do when Esc is pressed

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2005-07-14 23:09:00 +00:00
parent 2b4f7fbc9f
commit f55fee08e9
3 changed files with 57 additions and 47 deletions

View File

@ -137,6 +137,14 @@ protected:
// end either modal or modeless dialog // end either modal or modeless dialog
void EndDialog(int rc); void EndDialog(int rc);
// emulate click of a button with the given id if it's present in the dialog
//
// return true if button was "clicked" or false if we don't have it
bool EmulateButtonClickIfPresent(int id);
// handle Escape here
virtual bool MSWProcessMessage(WXMSG* pMsg);
private: private:
wxWindow* m_oldFocus; wxWindow* m_oldFocus;
bool m_endModalCalled; // allow for closing within InitDialog bool m_endModalCalled; // allow for closing within InitDialog

View File

@ -383,6 +383,17 @@ void wxDialog::EndDialog(int rc)
// wxWin event handlers // wxWin event handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxDialog::EmulateButtonClickIfPresent(int id)
{
wxButton *btn = wxDynamicCast(FindWindow(id), wxButton);
if ( !btn || !btn->IsEnabled() )
return false;
btn->MSWCommand(BN_CLICKED, 0 /* unused */);
return true;
}
// Standard buttons // Standard buttons
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event)) void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{ {
@ -447,23 +458,16 @@ void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
// sending the event, by calling SetAffirmativeId. // sending the event, by calling SetAffirmativeId.
bool wxDialog::DoOK() bool wxDialog::DoOK()
{ {
wxButton *btn = wxDynamicCast(FindWindow(GetAffirmativeId()), wxButton); const int idOk = GetAffirmativeId();
if ( EmulateButtonClickIfPresent(idOk) )
if ( btn && btn->IsEnabled() )
{
// If we have this button, press it
btn->MSWCommand(BN_CLICKED, 0 /* unused */);
return true; return true;
}
else
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetAffirmativeId());
event.SetEventObject(this);
return GetEventHandler()->ProcessEvent(event); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetAffirmativeId());
} event.SetEventObject(this);
return GetEventHandler()->ProcessEvent(event);
} }
#endif #endif // __POCKETPC__
#if wxUSE_TOOLBAR && defined(__POCKETPC__) #if wxUSE_TOOLBAR && defined(__POCKETPC__)
// create main toolbar by calling OnCreateToolBar() // create main toolbar by calling OnCreateToolBar()
@ -486,9 +490,39 @@ wxToolBar *wxDialog::OnCreateToolBar(long style,
#endif #endif
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// dialog window proc // dialog Windows messages processing
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
bool wxDialog::MSWProcessMessage(WXMSG* pMsg)
{
const MSG * const msg = wx_reinterpret_cast(MSG *, pMsg);
if ( msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE )
{
int idCancel = GetEscapeId();
switch ( idCancel )
{
case wxID_NONE:
// don't handle Esc specially at all
break;
case wxID_ANY:
// this value is special: it means translate Esc to wxID_CANCEL
// but if there is no such button, then fall back to wxID_OK
if ( EmulateButtonClickIfPresent(wxID_CANCEL) )
return true;
idCancel = wxID_OK;
// fall through
default:
// translate Esc to button press for the button with given id
if ( EmulateButtonClickIfPresent(idCancel) )
return true;
}
}
return wxDialogBase::MSWProcessMessage(pMsg);
}
WXLRESULT wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) WXLRESULT wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{ {
WXLRESULT rc = 0; WXLRESULT rc = 0;

View File

@ -1940,38 +1940,6 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
bProcess = false; bProcess = false;
break; break;
case VK_ESCAPE:
{
#if wxUSE_BUTTON
wxButton *btn = wxDynamicCast(FindWindow(wxID_CANCEL),wxButton);
// our own wxLogDialog should react to Esc
// without Cancel button but this is a private class
// so let's try recognize it by content
#if wxUSE_LOG_DIALOG
if ( !btn &&
wxDynamicCast(this,wxDialog) &&
FindWindow(wxID_MORE) &&
FindWindow(wxID_OK) &&
!FindWindow(wxID_CANCEL) &&
GetTitle().MakeLower().StartsWith(wxTheApp->GetAppName().c_str())
)
btn = wxDynamicCast(FindWindow(wxID_OK),wxButton);
#endif // wxUSE_LOG_DIALOG
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: case VK_RETURN:
{ {
if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown ) if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )