]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dialog.cpp
Added #pragma implementation for gcc.
[wxWidgets.git] / src / msw / dialog.cpp
index bbd4c9f3342355ed1f9871fe15af76a6d199e0e0..4a0102db14048d3b4e69359da5661b18770bf9e6 100644 (file)
@@ -235,24 +235,26 @@ wxDialog::~wxDialog()
 // By default, pressing escape cancels the dialog
 void wxDialog::OnCharHook(wxKeyEvent& event)
 {
-  if (GetHWND())
-  {
-    if (event.m_keyCode == WXK_ESCAPE)
+    if (GetHWND())
     {
-        // Behaviour changed in 2.0: we'll send a Cancel message
-        // to the dialog instead of Close.
-        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;
+        // "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();
+
+    // We didn't process this event.
+    event.Skip();
 }
 
 // ----------------------------------------------------------------------------