store selected indices as unsigned int, not size_t, in wxSelectionStore, we don't need to waste twice the memory needed under Win64
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52936 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,14 +18,12 @@
|
|||||||
// wxSelectedIndices is just a sorted array of indices
|
// wxSelectedIndices is just a sorted array of indices
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
inline int CMPFUNC_CONV wxSizeTCmpFn(size_t n1, size_t n2)
|
inline int CMPFUNC_CONV wxUIntCmp(unsigned n1, unsigned n2)
|
||||||
{
|
{
|
||||||
return (int)(n1 - n2);
|
return (int)(n1 - n2);
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SIZE_T(size_t,
|
WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_INT(unsigned, wxUIntCmp, wxSelectedIndices);
|
||||||
wxSizeTCmpFn,
|
|
||||||
wxSelectedIndices);
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxSelectionStore is used to store the selected items in the virtual
|
// wxSelectionStore is used to store the selected items in the virtual
|
||||||
@@ -42,24 +40,24 @@ WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SIZE_T(size_t,
|
|||||||
class WXDLLIMPEXP_CORE wxSelectionStore
|
class WXDLLIMPEXP_CORE wxSelectionStore
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxSelectionStore() : m_itemsSel(wxSizeTCmpFn) { Init(); }
|
wxSelectionStore() : m_itemsSel(wxUIntCmp) { Init(); }
|
||||||
|
|
||||||
// set the total number of items we handle
|
// set the total number of items we handle
|
||||||
void SetItemCount(size_t count) { m_count = count; }
|
void SetItemCount(unsigned count) { m_count = count; }
|
||||||
|
|
||||||
// special case of SetItemCount(0)
|
// special case of SetItemCount(0)
|
||||||
void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = false; }
|
void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = false; }
|
||||||
|
|
||||||
// must be called when a new item is inserted/added
|
// must be called when a new item is inserted/added
|
||||||
void OnItemAdd(size_t WXUNUSED(item)) { wxFAIL_MSG( _T("TODO") ); }
|
void OnItemAdd(unsigned WXUNUSED(item)) { wxFAIL_MSG( _T("TODO") ); }
|
||||||
|
|
||||||
// must be called when an item is deleted
|
// must be called when an item is deleted
|
||||||
void OnItemDelete(size_t item);
|
void OnItemDelete(unsigned item);
|
||||||
|
|
||||||
// select one item, use SelectRange() insted if possible!
|
// select one item, use SelectRange() insted if possible!
|
||||||
//
|
//
|
||||||
// returns true if the items selection really changed
|
// returns true if the items selection really changed
|
||||||
bool SelectItem(size_t item, bool select = true);
|
bool SelectItem(unsigned item, bool select = true);
|
||||||
|
|
||||||
// select the range of items
|
// select the range of items
|
||||||
//
|
//
|
||||||
@@ -67,15 +65,15 @@ public:
|
|||||||
// which have changed state if "few" of them did, otherwise return false
|
// which have changed state if "few" of them did, otherwise return false
|
||||||
// (meaning that too many items changed state to bother counting them
|
// (meaning that too many items changed state to bother counting them
|
||||||
// individually)
|
// individually)
|
||||||
bool SelectRange(size_t itemFrom, size_t itemTo,
|
bool SelectRange(unsigned itemFrom, unsigned itemTo,
|
||||||
bool select = true,
|
bool select = true,
|
||||||
wxArrayInt *itemsChanged = NULL);
|
wxArrayInt *itemsChanged = NULL);
|
||||||
|
|
||||||
// return true if the given item is selected
|
// return true if the given item is selected
|
||||||
bool IsSelected(size_t item) const;
|
bool IsSelected(unsigned item) const;
|
||||||
|
|
||||||
// return the total number of selected items
|
// return the total number of selected items
|
||||||
size_t GetSelectedCount() const
|
unsigned GetSelectedCount() const
|
||||||
{
|
{
|
||||||
return m_defaultState ? m_count - m_itemsSel.GetCount()
|
return m_defaultState ? m_count - m_itemsSel.GetCount()
|
||||||
: m_itemsSel.GetCount();
|
: m_itemsSel.GetCount();
|
||||||
@@ -86,7 +84,7 @@ private:
|
|||||||
void Init() { m_defaultState = false; }
|
void Init() { m_defaultState = false; }
|
||||||
|
|
||||||
// the total number of items we handle
|
// the total number of items we handle
|
||||||
size_t m_count;
|
unsigned m_count;
|
||||||
|
|
||||||
// the default state: normally, false (i.e. off) but maybe set to true if
|
// the default state: normally, false (i.e. off) but maybe set to true if
|
||||||
// there are more selected items than non selected ones - this allows to
|
// there are more selected items than non selected ones - this allows to
|
||||||
@@ -99,6 +97,5 @@ private:
|
|||||||
DECLARE_NO_COPY_CLASS(wxSelectionStore)
|
DECLARE_NO_COPY_CLASS(wxSelectionStore)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // _WX_SELSTORE_H_
|
#endif // _WX_SELSTORE_H_
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
// tests
|
// tests
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxSelectionStore::IsSelected(size_t item) const
|
bool wxSelectionStore::IsSelected(unsigned item) const
|
||||||
{
|
{
|
||||||
bool isSel = m_itemsSel.Index(item) != wxNOT_FOUND;
|
bool isSel = m_itemsSel.Index(item) != wxNOT_FOUND;
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ bool wxSelectionStore::IsSelected(size_t item) const
|
|||||||
// Select*()
|
// 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
|
// 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
|
// insert it later if needed, so we do only one search in the array instead
|
||||||
@@ -75,14 +75,14 @@ bool wxSelectionStore::SelectItem(size_t item, bool select)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo,
|
bool wxSelectionStore::SelectRange(unsigned itemFrom, unsigned itemTo,
|
||||||
bool select,
|
bool select,
|
||||||
wxArrayInt *itemsChanged)
|
wxArrayInt *itemsChanged)
|
||||||
{
|
{
|
||||||
// 100 is hardcoded but it shouldn't matter much: the important thing is
|
// 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
|
// that we don't refresh everything when really few (e.g. 1 or 2) items
|
||||||
// change state
|
// 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, _T("should be in order") );
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo,
|
|||||||
// TODO: it should be possible to optimize the searches a bit
|
// TODO: it should be possible to optimize the searches a bit
|
||||||
// knowing the possible range
|
// knowing the possible range
|
||||||
|
|
||||||
size_t item;
|
unsigned item;
|
||||||
for ( item = 0; item < itemFrom; item++ )
|
for ( item = 0; item < itemFrom; item++ )
|
||||||
{
|
{
|
||||||
if ( selOld.Index(item) == wxNOT_FOUND )
|
if ( selOld.Index(item) == wxNOT_FOUND )
|
||||||
@@ -166,7 +166,7 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// just add the items to the selection
|
// 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 )
|
if ( SelectItem(item, select) && itemsChanged )
|
||||||
{
|
{
|
||||||
@@ -191,7 +191,7 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo,
|
|||||||
// callbacks
|
// callbacks
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxSelectionStore::OnItemDelete(size_t item)
|
void wxSelectionStore::OnItemDelete(unsigned item)
|
||||||
{
|
{
|
||||||
size_t count = m_itemsSel.GetCount(),
|
size_t count = m_itemsSel.GetCount(),
|
||||||
i = m_itemsSel.IndexForInsert(item);
|
i = m_itemsSel.IndexForInsert(item);
|
||||||
|
Reference in New Issue
Block a user