]> git.saurik.com Git - wxWidgets.git/commitdiff
don't use dynamic handlers for standard buttons as this prevents static event handler...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Aug 2006 14:02:51 +0000 (14:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Aug 2006 14:02:51 +0000 (14:02 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40708 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dialog.h
src/common/dlgcmn.cpp

index 74c6ecfcb6c9ec3c645788d82cf81c989856d7c1..1dd7535bc098429fdc03b7c09f86b279a42cb368 100644 (file)
@@ -41,7 +41,7 @@ public:
     wxDialogBase() { Init(); }
     virtual ~wxDialogBase() { }
 
-    // public wxDialog API, to be implemented by the derived classes
+    // define public wxDialog methods to be implemented by the derived classes
     virtual int ShowModal() = 0;
     virtual void EndModal(int retCode) = 0;
     virtual bool IsModal() const = 0;
@@ -121,9 +121,7 @@ private:
     void OnCloseWindow(wxCloseEvent& event);
 
     // handle the standard buttons
-    void OnAffirmativeButton(wxCommandEvent& event);
-    void OnApply(wxCommandEvent& event);
-    void OnCancelButton(wxCommandEvent& event);
+    void OnButton(wxCommandEvent& event);
 
     // update the background colour
     void OnSysColourChanged(wxSysColourChangedEvent& event);
index 730b2c300f551873554befb1ba439465e111632f..1355125f52431ac3738a80b86e23f6475ec2bac6 100644 (file)
@@ -99,9 +99,7 @@ private:
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
-    EVT_BUTTON(wxID_OK, wxDialogBase::OnAffirmativeButton)
-    EVT_BUTTON(wxID_APPLY, wxDialogBase::OnApply)
-    EVT_BUTTON(wxID_CANCEL, wxDialogBase::OnCancelButton)
+    EVT_BUTTON(wxID_ANY, wxDialogBase::OnButton)
 
     EVT_CLOSE(wxDialogBase::OnCloseWindow)
 
@@ -427,85 +425,35 @@ wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags )
 #endif // wxUSE_BUTTON
 
 // ----------------------------------------------------------------------------
-// escape/affirmatives button handling
+// standard buttons handling
 // ----------------------------------------------------------------------------
 
+void wxDialogBase::EndDialog(int rc)
+{
+    if ( IsModal() )
+        EndModal(rc);
+    else
+        Hide();
+}
+
 void wxDialogBase::AcceptAndClose()
 {
     if ( Validate() && TransferDataFromWindow() )
     {
-        EndDialog(wxID_OK);
+        EndDialog(m_affirmativeId);
     }
 }
 
 void wxDialogBase::SetAffirmativeId(int affirmativeId)
 {
-    if ( affirmativeId == m_affirmativeId )
-        return;
-
-    // disconnect the handler for the old affirmative button
-    if ( m_affirmativeId != wxID_NONE && m_affirmativeId != wxID_OK )
-    {
-        if ( !Disconnect
-              (
-                m_affirmativeId,
-                wxEVT_COMMAND_BUTTON_CLICKED,
-                wxCommandEventHandler(wxDialogBase::OnAffirmativeButton)
-              ) )
-        {
-            wxFAIL_MSG( _T("failed to disconnect old ok handler") );
-        }
-    }
-    //else: wxID_OK is always handled
-
     m_affirmativeId = affirmativeId;
-
-    // connect the handler to the new button
-    if ( m_affirmativeId != wxID_NONE )
-    {
-        Connect(m_affirmativeId,
-                wxEVT_COMMAND_BUTTON_CLICKED,
-                wxCommandEventHandler(wxDialogBase::OnAffirmativeButton));
-    }
-    //else: no affirmative button
 }
 
 void wxDialogBase::SetEscapeId(int escapeId)
 {
-    if ( escapeId == m_escapeId )
-        return;
-
-    if ( m_escapeId != wxID_ANY &&
-            m_escapeId != wxID_CANCEL &&
-                m_escapeId != wxID_ANY )
-    {
-        if ( !Disconnect
-              (
-                m_escapeId,
-                wxEVT_COMMAND_BUTTON_CLICKED,
-                wxCommandEventHandler(wxDialogBase::OnCancelButton)
-              ) )
-        {
-            wxFAIL_MSG( _T("failed to disconnect old cancel handler") );
-        }
-    }
-    //else: wxID_CANCEL is always handled
-
     m_escapeId = escapeId;
-
-    // connect the handler to the new button
-    if ( m_escapeId != wxID_NONE )
-    {
-        Connect(m_escapeId,
-                wxEVT_COMMAND_BUTTON_CLICKED,
-                wxCommandEventHandler(wxDialogBase::OnCancelButton));
-    }
 }
 
-// ----------------------------------------------------------------------------
-// event handling stuff
-// ----------------------------------------------------------------------------
-
 bool wxDialogBase::EmulateButtonClickIfPresent(int id)
 {
     wxButton *btn = wxDynamicCast(FindWindow(id), wxButton);
@@ -520,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
@@ -564,23 +504,34 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event)
     event.Skip();
 }
 
-void wxDialogBase::OnAffirmativeButton(wxCommandEvent& WXUNUSED(event))
+void wxDialogBase::OnButton(wxCommandEvent& event)
 {
-    AcceptAndClose();
-}
-
-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::OnCancelButton(wxCommandEvent& WXUNUSED(event))
-{
-    EndDialog(wxID_CANCEL);
-}
+// ----------------------------------------------------------------------------
+// other event handlers
+// ----------------------------------------------------------------------------
 
 void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 {