]> git.saurik.com Git - wxWidgets.git/blame - include/wx/selstore.h
fix wxBitmapComboBox Gtk-CRITICAL assertion `GTK_IS_ENTRY (entry)' failed
[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
4cfcb00f 21inline int CMPFUNC_CONV wxUIntCmp(unsigned n1, unsigned n2)
975b6bcf
VZ
22{
23 return (int)(n1 - n2);
24}
c71d3313 25
4cfcb00f 26WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_INT(unsigned, wxUIntCmp, wxSelectedIndices);
c71d3313
VZ
27
28// ----------------------------------------------------------------------------
29// wxSelectionStore is used to store the selected items in the virtual
30// controls, i.e. it is well suited for storing even when the control contains
31// a huge (practically infinite) number of items.
32//
33// Of course, internally it still has to store the selected items somehow (as
34// an array currently) but the advantage is that it can handle the selection
35// of all items (common operation) efficiently and that it could be made even
36// smarter in the future (e.g. store the selections as an array of ranges +
37// individual items) without changing its API.
38// ----------------------------------------------------------------------------
39
53a2db12 40class WXDLLIMPEXP_CORE wxSelectionStore
c71d3313
VZ
41{
42public:
4cfcb00f 43 wxSelectionStore() : m_itemsSel(wxUIntCmp) { Init(); }
c71d3313
VZ
44
45 // set the total number of items we handle
c8f80d27 46 void SetItemCount(unsigned count);
c71d3313
VZ
47
48 // special case of SetItemCount(0)
d775fa82 49 void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = false; }
c71d3313
VZ
50
51 // must be called when a new item is inserted/added
9a83f860 52 void OnItemAdd(unsigned WXUNUSED(item)) { wxFAIL_MSG( wxT("TODO") ); }
c71d3313
VZ
53
54 // must be called when an item is deleted
4cfcb00f 55 void OnItemDelete(unsigned item);
c71d3313
VZ
56
57 // select one item, use SelectRange() insted if possible!
58 //
59 // returns true if the items selection really changed
4cfcb00f 60 bool SelectItem(unsigned item, bool select = true);
c71d3313 61
c8f80d27 62 // select the range of items (inclusive)
c71d3313
VZ
63 //
64 // return true and fill the itemsChanged array with the indices of items
65 // which have changed state if "few" of them did, otherwise return false
66 // (meaning that too many items changed state to bother counting them
67 // individually)
4cfcb00f 68 bool SelectRange(unsigned itemFrom, unsigned itemTo,
d775fa82 69 bool select = true,
c71d3313
VZ
70 wxArrayInt *itemsChanged = NULL);
71
72 // return true if the given item is selected
4cfcb00f 73 bool IsSelected(unsigned item) const;
c71d3313
VZ
74
75 // return the total number of selected items
4cfcb00f 76 unsigned GetSelectedCount() const
c71d3313
VZ
77 {
78 return m_defaultState ? m_count - m_itemsSel.GetCount()
79 : m_itemsSel.GetCount();
80 }
81
82private:
83 // (re)init
d775fa82 84 void Init() { m_defaultState = false; }
c71d3313
VZ
85
86 // the total number of items we handle
4cfcb00f 87 unsigned m_count;
c71d3313 88
d775fa82 89 // the default state: normally, false (i.e. off) but maybe set to true if
c71d3313
VZ
90 // there are more selected items than non selected ones - this allows to
91 // handle selection of all items efficiently
92 bool m_defaultState;
93
94 // the array of items whose selection state is different from default
95 wxSelectedIndices m_itemsSel;
96
c0c133e1 97 wxDECLARE_NO_COPY_CLASS(wxSelectionStore);
c71d3313
VZ
98};
99
c71d3313
VZ
100#endif // _WX_SELSTORE_H_
101