2003-06-11 10:49:53 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/selstore.h
|
|
|
|
// Purpose: wxSelectionStore stores selected items in a control
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 08.06.03 (extracted from src/generic/listctrl.cpp)
|
2004-05-23 14:56:36 +00:00
|
|
|
// Copyright: (c) 2000-2003 Vadim Zeitlin <vadim@wxwidgets.org>
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
2003-06-11 10:49:53 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_SELSTORE_H_
|
|
|
|
#define _WX_SELSTORE_H_
|
|
|
|
|
|
|
|
#include "wx/dynarray.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxSelectedIndices is just a sorted array of indices
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-31 14:42:07 +00:00
|
|
|
inline int CMPFUNC_CONV wxUIntCmp(unsigned n1, unsigned n2)
|
2004-02-10 13:02:51 +00:00
|
|
|
{
|
|
|
|
return (int)(n1 - n2);
|
|
|
|
}
|
2003-06-11 10:49:53 +00:00
|
|
|
|
2008-03-31 14:42:07 +00:00
|
|
|
WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_INT(unsigned, wxUIntCmp, wxSelectedIndices);
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxSelectionStore is used to store the selected items in the virtual
|
|
|
|
// controls, i.e. it is well suited for storing even when the control contains
|
|
|
|
// a huge (practically infinite) number of items.
|
|
|
|
//
|
|
|
|
// Of course, internally it still has to store the selected items somehow (as
|
|
|
|
// an array currently) but the advantage is that it can handle the selection
|
|
|
|
// of all items (common operation) efficiently and that it could be made even
|
|
|
|
// smarter in the future (e.g. store the selections as an array of ranges +
|
|
|
|
// individual items) without changing its API.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxSelectionStore
|
2003-06-11 10:49:53 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-03-31 14:42:07 +00:00
|
|
|
wxSelectionStore() : m_itemsSel(wxUIntCmp) { Init(); }
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// set the total number of items we handle
|
2008-03-31 15:22:10 +00:00
|
|
|
void SetItemCount(unsigned count);
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// special case of SetItemCount(0)
|
2004-09-22 14:38:52 +00:00
|
|
|
void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = false; }
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// must be called when a new item is inserted/added
|
2009-07-23 20:30:22 +00:00
|
|
|
void OnItemAdd(unsigned WXUNUSED(item)) { wxFAIL_MSG( wxT("TODO") ); }
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// must be called when an item is deleted
|
2008-03-31 14:42:07 +00:00
|
|
|
void OnItemDelete(unsigned item);
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// select one item, use SelectRange() insted if possible!
|
|
|
|
//
|
|
|
|
// returns true if the items selection really changed
|
2008-03-31 14:42:07 +00:00
|
|
|
bool SelectItem(unsigned item, bool select = true);
|
2003-06-11 10:49:53 +00:00
|
|
|
|
2008-03-31 15:22:10 +00:00
|
|
|
// select the range of items (inclusive)
|
2003-06-11 10:49:53 +00:00
|
|
|
//
|
|
|
|
// return true and fill the itemsChanged array with the indices of items
|
|
|
|
// which have changed state if "few" of them did, otherwise return false
|
|
|
|
// (meaning that too many items changed state to bother counting them
|
|
|
|
// individually)
|
2008-03-31 14:42:07 +00:00
|
|
|
bool SelectRange(unsigned itemFrom, unsigned itemTo,
|
2004-09-22 14:38:52 +00:00
|
|
|
bool select = true,
|
2003-06-11 10:49:53 +00:00
|
|
|
wxArrayInt *itemsChanged = NULL);
|
|
|
|
|
|
|
|
// return true if the given item is selected
|
2008-03-31 14:42:07 +00:00
|
|
|
bool IsSelected(unsigned item) const;
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// return the total number of selected items
|
2008-03-31 14:42:07 +00:00
|
|
|
unsigned GetSelectedCount() const
|
2003-06-11 10:49:53 +00:00
|
|
|
{
|
|
|
|
return m_defaultState ? m_count - m_itemsSel.GetCount()
|
|
|
|
: m_itemsSel.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// (re)init
|
2013-11-12 18:06:37 +00:00
|
|
|
void Init() { m_count = 0; m_defaultState = false; }
|
2003-06-11 10:49:53 +00:00
|
|
|
|
|
|
|
// the total number of items we handle
|
2008-03-31 14:42:07 +00:00
|
|
|
unsigned m_count;
|
2003-06-11 10:49:53 +00:00
|
|
|
|
2004-09-22 14:38:52 +00:00
|
|
|
// the default state: normally, false (i.e. off) but maybe set to true if
|
2003-06-11 10:49:53 +00:00
|
|
|
// there are more selected items than non selected ones - this allows to
|
|
|
|
// handle selection of all items efficiently
|
|
|
|
bool m_defaultState;
|
|
|
|
|
|
|
|
// the array of items whose selection state is different from default
|
|
|
|
wxSelectedIndices m_itemsSel;
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxSelectionStore);
|
2003-06-11 10:49:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_SELSTORE_H_
|
|
|
|
|