X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/153a0b7831e1eab3e8823f157b3337b66a6e9473..0d91b2342a1f83b3b9db145c7210efd5d9547cc8:/src/common/dlgcmn.cpp diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index ec34631b67..dd09b3a322 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -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,87 +425,38 @@ 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 - - // connect the handler to the new button - if ( affirmativeId != wxID_NONE ) - { - Connect(m_affirmativeId, - wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxDialogBase::OnAffirmativeButton)); - } - //else: no affirmative button - m_affirmativeId = affirmativeId; } 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 - - // connect the handler to the new button - if ( escapeId != wxID_NONE ) - { - Connect(m_escapeId, - wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxDialogBase::OnCancelButton)); - } - m_escapeId = escapeId; } -// ---------------------------------------------------------------------------- -// event handling stuff -// ---------------------------------------------------------------------------- - bool wxDialogBase::EmulateButtonClickIfPresent(int id) { +#if wxUSE_BUTTON wxButton *btn = wxDynamicCast(FindWindow(id), wxButton); if ( !btn || !btn->IsEnabled() || !btn->IsShown() ) @@ -518,14 +467,10 @@ bool wxDialogBase::EmulateButtonClickIfPresent(int id) btn->GetEventHandler()->ProcessEvent(event); return true; -} - -void wxDialogBase::EndDialog(int rc) -{ - if ( IsModal() ) - EndModal(rc); - else - Hide(); +#else // !wxUSE_BUTTON + wxUnusedVar(id); + return false; +#endif // wxUSE_BUTTON/!wxUSE_BUTTON } bool wxDialogBase::IsEscapeKey(const wxKeyEvent& event) @@ -564,23 +509,34 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event) event.Skip(); } -void wxDialogBase::OnAffirmativeButton(wxCommandEvent& WXUNUSED(event)) -{ - AcceptAndClose(); -} - -void wxDialogBase::OnApply(wxCommandEvent& WXUNUSED(event)) +void wxDialogBase::OnButton(wxCommandEvent& 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)) {