]> git.saurik.com Git - wxWidgets.git/blame - include/wx/selstore.h
removed __throws_bad_alloc import, this apparently breaks CW8.3 compilation and...
[wxWidgets.git] / include / wx / selstore.h
CommitLineData
c71d3313
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/selstore.h
3// Purpose: wxSelectionStore stores selected items in a control
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 08.06.03 (extracted from src/generic/listctrl.cpp)
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) 2000-2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 9// Licence: wxWindows licence
c71d3313
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_SELSTORE_H_
13#define _WX_SELSTORE_H_
14
15#include "wx/dynarray.h"
16
17// ----------------------------------------------------------------------------
18// wxSelectedIndices is just a sorted array of indices
19// ----------------------------------------------------------------------------
20
975b6bcf
VZ
21inline int CMPFUNC_CONV wxSizeTCmpFn(size_t n1, size_t n2)
22{
23 return (int)(n1 - n2);
24}
c71d3313 25
975b6bcf
VZ
26WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SIZE_T(size_t,
27 wxSizeTCmpFn,
28 wxSelectedIndices);
c71d3313
VZ
29
30// ----------------------------------------------------------------------------
31// wxSelectionStore is used to store the selected items in the virtual
32// controls, i.e. it is well suited for storing even when the control contains
33// a huge (practically infinite) number of items.
34//
35// Of course, internally it still has to store the selected items somehow (as
36// an array currently) but the advantage is that it can handle the selection
37// of all items (common operation) efficiently and that it could be made even
38// smarter in the future (e.g. store the selections as an array of ranges +
39// individual items) without changing its API.
40// ----------------------------------------------------------------------------
41
42class WXDLLEXPORT wxSelectionStore
43{
44public:
45 wxSelectionStore() : m_itemsSel(wxSizeTCmpFn) { Init(); }
46
47 // set the total number of items we handle
48 void SetItemCount(size_t count) { m_count = count; }
49
50 // special case of SetItemCount(0)
d775fa82 51 void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = false; }
c71d3313
VZ
52
53 // must be called when a new item is inserted/added
2eb10e2a 54 void OnItemAdd(size_t WXUNUSED(item)) { wxFAIL_MSG( _T("TODO") ); }
c71d3313
VZ
55
56 // must be called when an item is deleted
57 void OnItemDelete(size_t item);
58
59 // select one item, use SelectRange() insted if possible!
60 //
61 // returns true if the items selection really changed
d775fa82 62 bool SelectItem(size_t item, bool select = true);
c71d3313
VZ
63
64 // select the range of items
65 //
66 // return true and fill the itemsChanged array with the indices of items
67 // which have changed state if "few" of them did, otherwise return false
68 // (meaning that too many items changed state to bother counting them
69 // individually)
70 bool SelectRange(size_t itemFrom, size_t itemTo,
d775fa82 71 bool select = true,
c71d3313
VZ
72 wxArrayInt *itemsChanged = NULL);
73
74 // return true if the given item is selected
75 bool IsSelected(size_t item) const;
76
77 // return the total number of selected items
78 size_t GetSelectedCount() const
79 {
80 return m_defaultState ? m_count - m_itemsSel.GetCount()
81 : m_itemsSel.GetCount();
82 }
83
84private:
85 // (re)init
d775fa82 86 void Init() { m_defaultState = false; }
c71d3313
VZ
87
88 // the total number of items we handle
89 size_t m_count;
90
d775fa82 91 // the default state: normally, false (i.e. off) but maybe set to true if
c71d3313
VZ
92 // there are more selected items than non selected ones - this allows to
93 // handle selection of all items efficiently
94 bool m_defaultState;
95
96 // the array of items whose selection state is different from default
97 wxSelectedIndices m_itemsSel;
98
99 DECLARE_NO_COPY_CLASS(wxSelectionStore)
100};
101
102
103#endif // _WX_SELSTORE_H_
104