]> git.saurik.com Git - wxWidgets.git/commitdiff
moved Esc processing from wxWindow to wxDialog where it belongs; use the -- to be...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 14 Jul 2005 23:09:00 +0000 (23:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 14 Jul 2005 23:09:00 +0000 (23:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/dialog.h
src/msw/dialog.cpp
src/msw/window.cpp

index 319cd2bcc4626529c0d2a7eabdfd1dcde459a50e..3d8cfa3cc29c6a51ee24447a114caead856fed66 100644 (file)
@@ -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
index cda785f0b35dcbac0ad8a848832a426ba6393f20..d5a9b749305b2991b181019d049aa3c48d17b3c1 100644 (file)
@@ -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;
index 046ea54f71b05dd3ef955ed883c2dae1c2a25485..1699bfeda023c898806c3cc94673f5f9af82a339 100644 (file)
@@ -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 )