// 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))
{
// 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()
#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;
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 )