X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c3627a004d0333ec7bfc88e2a397d7d7f9752ea9..7b25d8e7bd0eca9f0f6efe62b3721d14c394dac9:/src/generic/listbkg.cpp?ds=sidebyside diff --git a/src/generic/listbkg.cpp b/src/generic/listbkg.cpp index e3a8391282..3b10666dcb 100644 --- a/src/generic/listbkg.cpp +++ b/src/generic/listbkg.cpp @@ -172,7 +172,8 @@ wxRect wxListbook::GetPageRect() const { const wxSize sizeList = m_list->GetSize(); - wxRect rectPage(wxPoint(0, 0), GetClientSize()); + wxPoint pt(0, 0); + wxRect rectPage(pt, GetClientSize()); switch ( GetWindowStyle() & wxLB_ALIGN_MASK ) { default: @@ -367,6 +368,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 +398,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 +469,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 +478,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