From 716dc24570f542fd68df9edf5c54e178a7c58bdd Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Wed, 6 Oct 2004 20:09:34 +0000 Subject: [PATCH] Removed doubled events, corrected behaviour (patch #1037434) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29680 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/choicbkg.cpp | 51 ++++++++++++++++++---------------------- src/generic/listbkg.cpp | 51 ++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/src/generic/choicbkg.cpp b/src/generic/choicbkg.cpp index f390ca06e5..9c3062d742 100644 --- a/src/generic/choicbkg.cpp +++ b/src/generic/choicbkg.cpp @@ -309,6 +309,7 @@ int wxChoicebook::SetSelection(size_t n) page->SetSize(GetPageRect()); page->Show(); + // change m_selection now to ignore the selection change event m_selection = n; m_choice->Select(n); @@ -337,16 +338,28 @@ wxChoicebook::InsertPage(size_t n, m_choice->Insert(text, n); - // we should always have some selection if possible - if ( bSelect || (m_selection == wxNOT_FOUND) ) + // if the inserted page is before the selected one, we must update the + // index of the selected page + if ( int(n) <= m_selection ) { - SetSelection(n); + // one extra page added + m_selection++; + m_choice->Select(m_selection); } - else // don't select this page - { - // it will be shown only when selected + + // some page should be selected: either this one or the first one if there + // is still no selection + int selNew = -1; + if ( bSelect ) + selNew = n; + else if ( m_selection == -1 ) + selNew = 0; + + if ( selNew != m_selection ) page->Hide(); - } + + if ( selNew != -1 ) + SetSelection(selNew); InvalidateBestSize(); return true; @@ -395,7 +408,6 @@ bool wxChoicebook::DeleteAllPages() void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice) { const int selNew = eventChoice.GetSelection(); - const int selOld = m_selection; if ( selNew == m_selection ) { @@ -405,28 +417,11 @@ void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice) return; } - // first send "change in progress" event which may be vetoed by user - wxChoicebookEvent eventIng(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, GetId()); - - eventIng.SetEventObject(this); - eventIng.SetSelection(selNew); - eventIng.SetOldSelection(selOld); - if ( GetEventHandler()->ProcessEvent(eventIng) && !eventIng.IsAllowed() ) - { - m_choice->Select(m_selection); - return; - } - - // change allowed: do change the page and notify the user about it SetSelection(selNew); - wxChoicebookEvent eventEd(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, GetId()); - - eventEd.SetEventObject(this); - eventEd.SetSelection(selNew); - eventEd.SetOldSelection(selOld); - - (void)GetEventHandler()->ProcessEvent(eventEd); + // change wasn't allowed, return to previous state + if (m_selection != selNew) + m_choice->Select(m_selection); } #endif // wxUSE_CHOICEBOOK diff --git a/src/generic/listbkg.cpp b/src/generic/listbkg.cpp index e3a8391282..34d726efe7 100644 --- a/src/generic/listbkg.cpp +++ b/src/generic/listbkg.cpp @@ -367,6 +367,7 @@ int wxListbook::SetSelection(size_t n) page->SetSize(GetPageRect()); page->Show(); + // change m_selection now to ignore the selection change event m_selection = n; m_list->Select(n); m_list->Focus(n); @@ -396,16 +397,29 @@ wxListbook::InsertPage(size_t n, m_list->InsertItem(n, text, imageId); - // we should always have some selection if possible - if ( bSelect || (m_selection == wxNOT_FOUND) ) + // if the inserted page is before the selected one, we must update the + // index of the selected page + if ( int(n) <= m_selection ) { - SetSelection(n); + // one extra page added + m_selection++; + m_list->Select(m_selection); + m_list->Focus(m_selection); } - else // don't select this page - { - // it will be shown only when selected + + // some page should be selected: either this one or the first one if there + // is still no selection + int selNew = -1; + if ( bSelect ) + selNew = n; + else if ( m_selection == -1 ) + selNew = 0; + + if ( selNew != m_selection ) page->Hide(); - } + + if ( selNew != -1 ) + SetSelection(selNew); InvalidateBestSize(); return true; @@ -454,7 +468,6 @@ bool wxListbook::DeleteAllPages() void wxListbook::OnListSelected(wxListEvent& eventList) { const int selNew = eventList.GetIndex(); - const int selOld = m_selection; if ( selNew == m_selection ) { @@ -464,28 +477,14 @@ void wxListbook::OnListSelected(wxListEvent& eventList) return; } - // first send "change in progress" event which may be vetoed by user - wxListbookEvent eventIng(wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, GetId()); + SetSelection(selNew); - eventIng.SetEventObject(this); - eventIng.SetSelection(selNew); - eventIng.SetOldSelection(selOld); - if ( GetEventHandler()->ProcessEvent(eventIng) && !eventIng.IsAllowed() ) + // change wasn't allowed, return to previous state + if (m_selection != selNew) { m_list->Select(m_selection); - return; + m_list->Focus(m_selection); } - - // change allowed: do change the page and notify the user about it - SetSelection(selNew); - - wxListbookEvent eventEd(wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, GetId()); - - eventEd.SetEventObject(this); - eventEd.SetSelection(selNew); - eventEd.SetOldSelection(selOld); - - (void)GetEventHandler()->ProcessEvent(eventEd); } #endif // wxUSE_LISTBOOK -- 2.45.2