]> git.saurik.com Git - wxWidgets.git/blame - include/wx/univ/listbox.h
Add missing wxUSE_OLE checks to safearray.cpp.
[wxWidgets.git] / include / wx / univ / listbox.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/univ/listbox.h
3// Purpose: the universal listbox
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 30.08.00
7// RCS-ID: $Id$
a3870b2f 8// Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UNIV_LISTBOX_H_
13#define _WX_UNIV_LISTBOX_H_
14
1e6feb95 15#include "wx/scrolwin.h" // for wxScrollHelper
ed39ff57 16#include "wx/dynarray.h"
18dbdd3c 17#include "wx/arrstr.h"
1e6feb95
VZ
18
19// ----------------------------------------------------------------------------
20// the actions supported by this control
21// ----------------------------------------------------------------------------
22
23// change the current item
9a83f860
VZ
24#define wxACTION_LISTBOX_SETFOCUS wxT("setfocus") // select the item
25#define wxACTION_LISTBOX_MOVEDOWN wxT("down") // select item below
26#define wxACTION_LISTBOX_MOVEUP wxT("up") // select item above
27#define wxACTION_LISTBOX_PAGEDOWN wxT("pagedown") // go page down
28#define wxACTION_LISTBOX_PAGEUP wxT("pageup") // go page up
29#define wxACTION_LISTBOX_START wxT("start") // go to first item
30#define wxACTION_LISTBOX_END wxT("end") // go to last item
31#define wxACTION_LISTBOX_FIND wxT("find") // find item by 1st letter
1e6feb95
VZ
32
33// do something with the current item
9a83f860
VZ
34#define wxACTION_LISTBOX_ACTIVATE wxT("activate") // activate (choose)
35#define wxACTION_LISTBOX_TOGGLE wxT("toggle") // togglee selected state
36#define wxACTION_LISTBOX_SELECT wxT("select") // sel this, unsel others
37#define wxACTION_LISTBOX_SELECTADD wxT("selectadd") // add to selection
38#define wxACTION_LISTBOX_UNSELECT wxT("unselect") // unselect
39#define wxACTION_LISTBOX_ANCHOR wxT("selanchor") // anchor selection
1e6feb95
VZ
40
41// do something with the selection globally (not for single selection ones)
9a83f860
VZ
42#define wxACTION_LISTBOX_SELECTALL wxT("selectall") // select all items
43#define wxACTION_LISTBOX_UNSELECTALL wxT("unselectall") // unselect all items
44#define wxACTION_LISTBOX_SELTOGGLE wxT("togglesel") // invert the selection
45#define wxACTION_LISTBOX_EXTENDSEL wxT("extend") // extend to item
1e6feb95
VZ
46
47// ----------------------------------------------------------------------------
48// wxListBox: a list of selectable items
49// ----------------------------------------------------------------------------
50
53a2db12 51class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase, public wxScrollHelper
1e6feb95
VZ
52{
53public:
54 // ctors and such
afe13769 55 wxListBox() : wxScrollHelper(this) { Init(); }
1e6feb95
VZ
56 wxListBox(wxWindow *parent,
57 wxWindowID id,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 int n = 0, const wxString choices[] = (const wxString *) NULL,
61 long style = 0,
62 const wxValidator& validator = wxDefaultValidator,
6463b9f5 63 const wxString& name = wxListBoxNameStr )
afe13769 64 : wxScrollHelper(this)
6463b9f5
JS
65 {
66 Init();
67
68 Create(parent, id, pos, size, n, choices, style, validator, name);
69 }
584ad2a3
MB
70 wxListBox(wxWindow *parent,
71 wxWindowID id,
72 const wxPoint& pos,
73 const wxSize& size,
74 const wxArrayString& choices,
75 long style = 0,
76 const wxValidator& validator = wxDefaultValidator,
77 const wxString& name = wxListBoxNameStr );
1e6feb95
VZ
78
79 virtual ~wxListBox();
80
81 bool Create(wxWindow *parent,
82 wxWindowID id,
83 const wxPoint& pos = wxDefaultPosition,
84 const wxSize& size = wxDefaultSize,
85 int n = 0, const wxString choices[] = (const wxString *) NULL,
86 long style = 0,
87 const wxValidator& validator = wxDefaultValidator,
88 const wxString& name = wxListBoxNameStr);
584ad2a3
MB
89 bool Create(wxWindow *parent,
90 wxWindowID id,
91 const wxPoint& pos,
92 const wxSize& size,
93 const wxArrayString& choices,
94 long style = 0,
95 const wxValidator& validator = wxDefaultValidator,
96 const wxString& name = wxListBoxNameStr);
1e6feb95
VZ
97
98 // implement the listbox interface defined by wxListBoxBase
a236aa20
VZ
99 virtual void DoClear();
100 virtual void DoDeleteOneItem(unsigned int n);
1e6feb95 101
6f34862c
VZ
102 virtual unsigned int GetCount() const;
103 virtual wxString GetString(unsigned int n) const;
aa61d352 104 virtual void SetString(unsigned int n, const wxString& s);
6f34862c 105 virtual int FindString(const wxString& s, bool bCase = false) const;
1e6feb95
VZ
106
107 virtual bool IsSelected(int n) const
108 { return m_selections.Index(n) != wxNOT_FOUND; }
1e6feb95
VZ
109 virtual int GetSelection() const;
110 virtual int GetSelections(wxArrayInt& aSelections) const;
111
112protected:
6f02a879 113 virtual void DoSetSelection(int n, bool select);
a236aa20
VZ
114
115 virtual int DoInsertItems(const wxArrayStringsAdapter& items,
116 unsigned int pos,
117 void **clientData,
118 wxClientDataType type);
119
120 // universal wxComboBox implementation internally uses wxListBox
5bcc2e54 121 friend class WXDLLIMPEXP_FWD_CORE wxComboBox;
1e6feb95
VZ
122
123 virtual void DoSetFirstItem(int n);
124
aa61d352
VZ
125 virtual void DoSetItemClientData(unsigned int n, void* clientData);
126 virtual void* DoGetItemClientData(unsigned int n) const;
1e6feb95
VZ
127
128public:
129 // override some more base class methods
130 virtual bool SetFont(const wxFont& font);
131
132 // the wxUniversal-specific methods
133 // --------------------------------
134
135 // the current item is the same as the selected one for wxLB_SINGLE
136 // listboxes but for the other ones it is just the focused item which may
137 // be selected or not
138 int GetCurrentItem() const { return m_current; }
139 void SetCurrentItem(int n);
140
141 // select the item which is diff items below the current one
142 void ChangeCurrent(int diff);
143
144 // activate (i.e. send a LISTBOX_DOUBLECLICKED message) the specified or
145 // current (if -1) item
146 void Activate(int item = -1);
147
148 // select or unselect the specified or current (if -1) item
a290fa5a 149 void DoSelect(int item = -1, bool sel = true);
1e6feb95
VZ
150
151 // more readable wrapper
a290fa5a 152 void DoUnselect(int item) { DoSelect(item, false); }
1e6feb95
VZ
153
154 // select an item and send a notification about it
155 void SelectAndNotify(int item);
156
157 // ensure that the given item is visible by scrolling it into view
158 virtual void EnsureVisible(int n);
159
160 // find the first item [strictly] after the current one which starts with
a290fa5a 161 // the given string and make it the current one, return true if the current
1e6feb95 162 // item changed
a290fa5a
WS
163 bool FindItem(const wxString& prefix, bool strictlyAfter = false);
164 bool FindNextItem(const wxString& prefix) { return FindItem(prefix, true); }
1e6feb95
VZ
165
166 // extend the selection to span the range from the anchor (see below) to
167 // the specified or current item
168 void ExtendSelection(int itemTo = -1);
169
170 // make this item the new selection anchor: extending selection with
171 // ExtendSelection() will work with it
172 void AnchorSelection(int itemFrom) { m_selAnchor = itemFrom; }
173
174 // get, calculating it if necessary, the number of items per page, the
175 // height of each line and the max width of an item
176 int GetItemsPerPage() const;
177 wxCoord GetLineHeight() const;
178 wxCoord GetMaxWidth() const;
179
180 // override the wxControl virtual methods
181 virtual bool PerformAction(const wxControlAction& action,
182 long numArg = 0l,
183 const wxString& strArg = wxEmptyString);
184
9467bdb7
VZ
185 static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
186 virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
187 {
188 return GetStdInputHandler(handlerDef);
189 }
190
e39af974
JS
191 // idle processing
192 virtual void OnInternalIdle();
81b344a5 193
1e6feb95
VZ
194protected:
195 // geometry
196 virtual wxSize DoGetBestClientSize() const;
197 virtual void DoSetSize(int x, int y,
198 int width, int height,
199 int sizeFlags = wxSIZE_AUTO);
200
201 virtual void DoDraw(wxControlRenderer *renderer);
202 virtual wxBorder GetDefaultBorder() const;
203
a236aa20
VZ
204 // special hook for wxCheckListBox which allows it to update its internal
205 // data when a new item is inserted into the listbox
206 virtual void OnItemInserted(unsigned int WXUNUSED(pos)) { }
207
208
1e6feb95
VZ
209 // common part of all ctors
210 void Init();
211
212 // event handlers
1e6feb95
VZ
213 void OnSize(wxSizeEvent& event);
214
1e6feb95
VZ
215 // refresh the given item(s) or everything
216 void RefreshItems(int from, int count);
217 void RefreshItem(int n);
218 void RefreshFromItemToEnd(int n);
219 void RefreshAll();
220
221 // send an event of the given type (using m_current by default)
222 bool SendEvent(wxEventType type, int item = -1);
223
224 // calculate the number of items per page using our current size
225 void CalcItemsPerPage();
226
227 // can/should we have a horz scrollbar?
228 bool HasHorzScrollbar() const
229 { return (m_windowStyle & wxLB_HSCROLL) != 0; }
230
231 // redraw the items in the given range only: called from DoDraw()
232 virtual void DoDrawRange(wxControlRenderer *renderer,
233 int itemFirst, int itemLast);
234
235 // update the scrollbars and then ensure that the item is visible
236 void DoEnsureVisible(int n);
237
238 // mark horz scrollbar for updating
239 void RefreshHorzScrollbar();
240
241 // update (show/hide/adjust) the scrollbars
242 void UpdateScrollbars();
243
244 // refresh the items specified by m_updateCount and m_updateFrom
245 void UpdateItems();
246
247 // the array containing all items (it is sorted if the listbox has
e1d6e01c 248 // wxLB_SORT style)
6f34862c
VZ
249 union
250 {
251 wxArrayString *unsorted;
252 wxSortedArrayString *sorted;
253 } m_strings;
1e6feb95
VZ
254
255 // this array contains the indices of the selected items (for the single
256 // selection listboxes only the first element of it is used and contains
257 // the current selection)
258 wxArrayInt m_selections;
259
260 // and this one the client data (either void or wxClientData)
261 wxArrayPtrVoid m_itemsClientData;
262
263 // the current item
264 int m_current;
265
266private:
267 // the range of elements which must be updated: if m_updateCount is 0 no
268 // update is needed, if it is -1 everything must be updated, otherwise
269 // m_updateCount items starting from m_updateFrom have to be redrawn
270 int m_updateFrom,
271 m_updateCount;
272
273 // the height of one line in the listbox (all lines have the same height)
274 wxCoord m_lineHeight;
275
276 // the maximal width of a listbox item and the item which has it
277 wxCoord m_maxWidth;
278 int m_maxWidthItem;
279
280 // the extents of horz and vert scrollbars
281 int m_scrollRangeX,
282 m_scrollRangeY;
283
284 // the number of items per page
285 size_t m_itemsPerPage;
286
287 // if the number of items has changed we may need to show/hide the
288 // scrollbar
289 bool m_updateScrollbarX, m_updateScrollbarY,
290 m_showScrollbarX, m_showScrollbarY;
291
292 // if the current item has changed, we might need to scroll if it went out
293 // of the window
294 bool m_currentChanged;
295
296 // the anchor from which the selection is extended for the listboxes with
297 // wxLB_EXTENDED style - this is set to the last item which was selected
298 // by not extending the selection but by choosing it directly
299 int m_selAnchor;
300
301 DECLARE_EVENT_TABLE()
302 DECLARE_DYNAMIC_CLASS(wxListBox)
303};
304
1e6feb95 305#endif // _WX_UNIV_LISTBOX_H_