X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..010d821b3138ae39c43403da64eb0bcde9af82ae:/src/generic/selstore.cpp?ds=sidebyside diff --git a/src/generic/selstore.cpp b/src/generic/selstore.cpp index e99cc2df42..6f606c335a 100644 --- a/src/generic/selstore.cpp +++ b/src/generic/selstore.cpp @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: generic/selstore.cpp +// Name: src/generic/selstore.cpp // Purpose: wxSelectionStore implementation // Author: Vadim Zeitlin // Modified by: // Created: 08.06.03 (extracted from src/generic/listctrl.cpp) -// RCS-ID: $Id$ // Copyright: (c) 2000-2003 Vadim Zeitlin -// Licence: wxWidgets licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -33,7 +32,7 @@ // tests // ---------------------------------------------------------------------------- -bool wxSelectionStore::IsSelected(size_t item) const +bool wxSelectionStore::IsSelected(unsigned item) const { bool isSel = m_itemsSel.Index(item) != wxNOT_FOUND; @@ -46,7 +45,7 @@ bool wxSelectionStore::IsSelected(size_t item) const // Select*() // ---------------------------------------------------------------------------- -bool wxSelectionStore::SelectItem(size_t item, bool select) +bool wxSelectionStore::SelectItem(unsigned item, bool select) { // search for the item ourselves as like this we get the index where to // insert it later if needed, so we do only one search in the array instead @@ -60,7 +59,7 @@ bool wxSelectionStore::SelectItem(size_t item, bool select) { m_itemsSel.AddAt(item, index); - return TRUE; + return true; } } else // reset to default state @@ -68,23 +67,23 @@ bool wxSelectionStore::SelectItem(size_t item, bool select) if ( isSel ) { m_itemsSel.RemoveAt(index); - return TRUE; + return true; } } - return FALSE; + return false; } -bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, +bool wxSelectionStore::SelectRange(unsigned itemFrom, unsigned itemTo, bool select, wxArrayInt *itemsChanged) { // 100 is hardcoded but it shouldn't matter much: the important thing is // that we don't refresh everything when really few (e.g. 1 or 2) items // change state - static const size_t MANY_ITEMS = 100; + static const unsigned MANY_ITEMS = 100; - wxASSERT_MSG( itemFrom <= itemTo, _T("should be in order") ); + wxASSERT_MSG( itemFrom <= itemTo, wxT("should be in order") ); // are we going to have more [un]selected items than the other ones? if ( itemTo - itemFrom > m_count/2 ) @@ -102,7 +101,7 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, // TODO: it should be possible to optimize the searches a bit // knowing the possible range - size_t item; + unsigned item; for ( item = 0; item < itemFrom; item++ ) { if ( selOld.Index(item) == wxNOT_FOUND ) @@ -166,7 +165,7 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, } // just add the items to the selection - for ( size_t item = itemFrom; item <= itemTo; item++ ) + for ( unsigned item = itemFrom; item <= itemTo; item++ ) { if ( SelectItem(item, select) && itemsChanged ) { @@ -191,7 +190,7 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, // callbacks // ---------------------------------------------------------------------------- -void wxSelectionStore::OnItemDelete(size_t item) +void wxSelectionStore::OnItemDelete(unsigned item) { size_t count = m_itemsSel.GetCount(), i = m_itemsSel.IndexForInsert(item); @@ -208,9 +207,25 @@ void wxSelectionStore::OnItemDelete(size_t item) while ( i < count ) { // all following elements must be greater than the one we deleted - wxASSERT_MSG( m_itemsSel[i] > item, _T("logic error") ); + wxASSERT_MSG( m_itemsSel[i] > item, wxT("logic error") ); m_itemsSel[i++]--; } } +void wxSelectionStore::SetItemCount(unsigned count) +{ + // forget about all items whose indices are now invalid if the size + // decreased + if ( count < m_count ) + { + for ( size_t i = m_itemsSel.GetCount(); i > 0; i-- ) + { + if ( m_itemsSel[i - 1] >= count ) + m_itemsSel.RemoveAt(i - 1); + } + } + + // remember the new number of items + m_count = count; +}