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:
parent
2b4f7fbc9f
commit
f55fee08e9
@ -137,6 +137,14 @@ protected:
|
||||
// end either modal or modeless dialog
|
||||
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:
|
||||
wxWindow* m_oldFocus;
|
||||
bool m_endModalCalled; // allow for closing within InitDialog
|
||||
|
@ -383,6 +383,17 @@ void wxDialog::EndDialog(int rc)
|
||||
// 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
|
||||
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
@ -447,23 +458,16 @@ void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
|
||||
// sending the event, by calling SetAffirmativeId.
|
||||
bool wxDialog::DoOK()
|
||||
{
|
||||
wxButton *btn = wxDynamicCast(FindWindow(GetAffirmativeId()), wxButton);
|
||||
|
||||
if ( btn && btn->IsEnabled() )
|
||||
{
|
||||
// If we have this button, press it
|
||||
btn->MSWCommand(BN_CLICKED, 0 /* unused */);
|
||||
const int idOk = GetAffirmativeId();
|
||||
if ( EmulateButtonClickIfPresent(idOk) )
|
||||
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__)
|
||||
// create main toolbar by calling OnCreateToolBar()
|
||||
@ -486,9 +490,39 @@ wxToolBar *wxDialog::OnCreateToolBar(long style,
|
||||
#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 rc = 0;
|
||||
|
@ -1940,38 +1940,6 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
|
||||
bProcess = false;
|
||||
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:
|
||||
{
|
||||
if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
|
||||
|
Loading…
Reference in New Issue
Block a user