]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dlgcmn.cpp
fixed a crash and a leak in GetShortcutTarget() (closes bug 1541321)
[wxWidgets.git] / src / common / dlgcmn.cpp
index ed592fb8cf54015481490f5341ed5a86937f843e..1355125f52431ac3738a80b86e23f6475ec2bac6 100644 (file)
@@ -99,9 +99,7 @@ private:
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
-    EVT_BUTTON(wxID_OK, wxDialogBase::OnOK)
-    EVT_BUTTON(wxID_APPLY, wxDialogBase::OnApply)
-    EVT_BUTTON(wxID_CANCEL, wxDialogBase::OnCancel)
+    EVT_BUTTON(wxID_ANY, wxDialogBase::OnButton)
 
     EVT_CLOSE(wxDialogBase::OnCloseWindow)
 
@@ -427,9 +425,35 @@ wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags )
 #endif // wxUSE_BUTTON
 
 // ----------------------------------------------------------------------------
-// event handling stuff
+// standard buttons handling
 // ----------------------------------------------------------------------------
 
+void wxDialogBase::EndDialog(int rc)
+{
+    if ( IsModal() )
+        EndModal(rc);
+    else
+        Hide();
+}
+
+void wxDialogBase::AcceptAndClose()
+{
+    if ( Validate() && TransferDataFromWindow() )
+    {
+        EndDialog(m_affirmativeId);
+    }
+}
+
+void wxDialogBase::SetAffirmativeId(int affirmativeId)
+{
+    m_affirmativeId = affirmativeId;
+}
+
+void wxDialogBase::SetEscapeId(int escapeId)
+{
+    m_escapeId = escapeId;
+}
+
 bool wxDialogBase::EmulateButtonClickIfPresent(int id)
 {
     wxButton *btn = wxDynamicCast(FindWindow(id), wxButton);
@@ -444,14 +468,6 @@ bool wxDialogBase::EmulateButtonClickIfPresent(int id)
     return true;
 }
 
-void wxDialogBase::EndDialog(int rc)
-{
-    if ( IsModal() )
-        EndModal(rc);
-    else
-        Hide();
-}
-
 bool wxDialogBase::IsEscapeKey(const wxKeyEvent& event)
 {
     // for most platforms, Esc key is used to close the dialogs
@@ -475,7 +491,7 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event)
                 // but if there is no such button, then fall back to wxID_OK
                 if ( EmulateButtonClickIfPresent(wxID_CANCEL) )
                     return;
-                idCancel = wxID_OK;
+                idCancel = GetAffirmativeId();
                 // fall through
 
             default:
@@ -488,26 +504,34 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event)
     event.Skip();
 }
 
-void wxDialogBase::OnOK(wxCommandEvent& WXUNUSED(event))
+void wxDialogBase::OnButton(wxCommandEvent& event)
 {
-  if ( Validate() && TransferDataFromWindow() )
-  {
-      EndDialog(wxID_OK);
-  }
-}
-
-void wxDialogBase::OnApply(wxCommandEvent& WXUNUSED(event))
-{
-    if ( Validate() )
-        TransferDataFromWindow();
+    const int id = event.GetId();
+    if ( id == GetAffirmativeId() )
+    {
+        AcceptAndClose();
+    }
+    else if ( id == wxID_APPLY )
+    {
+        if ( Validate() )
+            TransferDataFromWindow();
 
-    // TODO probably need to disable the Apply button until things change again
+        // TODO: disable the Apply button until things change again
+    }
+    else if ( id == GetEscapeId() ||
+                (id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
+    {
+        EndDialog(wxID_CANCEL);
+    }
+    else // not a standard button
+    {
+        event.Skip();
+    }
 }
 
-void wxDialogBase::OnCancel(wxCommandEvent& WXUNUSED(event))
-{
-    EndDialog(wxID_CANCEL);
-}
+// ----------------------------------------------------------------------------
+// other event handlers
+// ----------------------------------------------------------------------------
 
 void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 {