]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/vlbox.h
fixing non-precomp builds
[wxWidgets.git] / interface / wx / vlbox.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: vlbox.h
e54c96f1 3// Purpose: interface of wxVListBox
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxVListBox
7c913512 11
30a7cc7b
BP
12 wxVListBox is a wxListBox-like control with the following two main
13 differences from a regular wxListBox: it can have an arbitrarily huge
14 number of items because it doesn't store them itself but uses the
15 OnDrawItem() callback to draw them (so it is a virtual listbox) and its
16 items can have variable height as determined by OnMeasureItem() (so it is
17 also a listbox with the lines of variable height).
18
19 Also, as a consequence of its virtual nature, it doesn't have any methods
20 to append or insert items in it as it isn't necessary to do it: you just
21 have to call SetItemCount() to tell the control how many items it should
22 display. Of course, this also means that you will never use this class
23 directly because it has pure virtual functions, but will need to derive
24 your own class from it (for example, wxHtmlListBox).
25
26 However it emits the same events as wxListBox and the same event macros may
27 be used with it. Since wxVListBox does not store its items itself, the
28 events will only contain the index, not any contents such as the string of
29 an item.
7c913512 30
23324ae1
FM
31 @library{wxcore}
32 @category{ctrl}
7c913512 33
e54c96f1 34 @see wxSimpleHtmlListBox, wxHtmlListBox
23324ae1
FM
35*/
36class wxVListBox : public wxVScrolledWindow
37{
38public:
23324ae1
FM
39 /**
40 Default constructor, you must call Create() later.
41 */
30a7cc7b
BP
42 wxVListBox();
43 /**
44 Normal constructor which calls Create() internally.
45 */
23324ae1
FM
46 wxVListBox(wxWindow* parent, wxWindowID id = wxID_ANY,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize,
1a1b0c8a 49 long style = 0, const wxString& name = wxVListBoxNameStr);
30a7cc7b
BP
50
51 /**
52 Destructor.
53 */
54 virtual ~wxVListBox();
23324ae1
FM
55
56 /**
57 Deletes all items from the control.
58 */
59 void Clear();
60
61 /**
62 Creates the control. To finish creating it you also should call
30a7cc7b
BP
63 SetItemCount() to let it know about the number of items it contains.
64
65 The only special style which may be used with wxVListBox is
66 @c wxLB_MULTIPLE which indicates that the listbox should support
67 multiple selection.
68
d29a9a8a 69 @return @true on success or @false if the control couldn't be created.
23324ae1
FM
70 */
71 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
72 const wxPoint& pos = wxDefaultPosition,
30a7cc7b 73 const wxSize& size = wxDefaultSize, long style = 0,
23324ae1
FM
74 const wxString& name = wxVListBoxNameStr);
75
76 /**
30a7cc7b
BP
77 Deselects all the items in the listbox. This method is only valid for
78 multi selection listboxes.
79
d29a9a8a 80 @return @true if any items were changed, i.e. if there had been any
30a7cc7b
BP
81 selected items before, or @false if all the items were already
82 deselected.
3c4f71cc 83
4cc4bfaf 84 @see SelectAll(), Select()
23324ae1
FM
85 */
86 bool DeselectAll();
87
88 /**
89 Returns the index of the first selected item in the listbox or
90 @c wxNOT_FOUND if no items are currently selected.
30a7cc7b
BP
91
92 @a cookie is an opaque parameter which should be passed to the
93 subsequent calls to GetNextSelected(). It is needed in order to allow
94 parallel iterations over the selected items.
95
23324ae1 96 Here is a typical example of using these functions:
3c4f71cc 97
30a7cc7b
BP
98 @code
99 unsigned long cookie;
100 int item = hlbox->GetFirstSelected(cookie);
101 while ( item != wxNOT_FOUND )
102 {
103 // ... process item ...
104 item = hlbox->GetNextSelected(cookie);
105 }
106 @endcode
107
23324ae1
FM
108 This method is only valid for multi selection listboxes.
109 */
328f5751 110 int GetFirstSelected(unsigned long& cookie) const;
23324ae1
FM
111
112 /**
113 Get the number of items in the control.
3c4f71cc 114
4cc4bfaf 115 @see SetItemCount()
23324ae1 116 */
328f5751 117 size_t GetItemCount() const;
23324ae1
FM
118
119 /**
120 Returns the margins used by the control. The @c x field of the returned
121 point is the horizontal margin and the @c y field is the vertical one.
3c4f71cc 122
4cc4bfaf 123 @see SetMargins()
23324ae1 124 */
328f5751 125 wxPoint GetMargins() const;
23324ae1 126
293b15f7
VZ
127 /**
128 Returns the rectangle occupied by this item in physical coordinates.
129
130 If the item is not currently visible, returns an empty rectangle.
9379b3f6
VZ
131
132 @since 2.9.0
293b15f7
VZ
133 */
134 wxRect GetItemRect(size_t item) const;
135
23324ae1 136 /**
30a7cc7b
BP
137 Returns the index of the next selected item or @c wxNOT_FOUND if there
138 are no more.
139
23324ae1 140 This method is only valid for multi selection listboxes.
3c4f71cc 141
4cc4bfaf 142 @see GetFirstSelected()
23324ae1 143 */
328f5751 144 int GetNextSelected(unsigned long& cookie) const;
23324ae1
FM
145
146 /**
147 Returns the number of the items currently selected.
3c4f71cc 148
30a7cc7b
BP
149 It is valid for both single and multi selection controls. In the former
150 case it may only return 0 or 1 however.
151
152 @see IsSelected(), GetFirstSelected(), GetNextSelected()
23324ae1 153 */
328f5751 154 size_t GetSelectedCount() const;
23324ae1
FM
155
156 /**
30a7cc7b
BP
157 Get the currently selected item or @c wxNOT_FOUND if there is no
158 selection.
23324ae1 159 */
328f5751 160 int GetSelection() const;
23324ae1
FM
161
162 /**
30a7cc7b
BP
163 Returns the background colour used for the selected cells. By default
164 the standard system colour is used.
3c4f71cc 165
30a7cc7b 166 @see wxSystemSettings::GetColour(), SetSelectionBackground()
23324ae1 167 */
30a7cc7b 168 const wxColour& GetSelectionBackground() const;
23324ae1
FM
169
170 /**
171 Returns @true if the listbox was created with @c wxLB_MULTIPLE style
30a7cc7b
BP
172 and so supports multiple selection or @false if it is a single
173 selection listbox.
23324ae1 174 */
328f5751 175 bool HasMultipleSelection() const;
23324ae1
FM
176
177 /**
178 Returns @true if this item is the current one, @false otherwise.
30a7cc7b
BP
179
180 The current item is always the same as selected one for the single
181 selection listbox and in this case this method is equivalent to
182 IsSelected() but they are different for multi selection listboxes where
183 many items may be selected but only one (at most) is current.
23324ae1 184 */
328f5751 185 bool IsCurrent(size_t item) const;
23324ae1
FM
186
187 /**
188 Returns @true if this item is selected, @false otherwise.
189 */
328f5751 190 bool IsSelected(size_t item) const;
23324ae1 191
23324ae1
FM
192 /**
193 Selects or deselects the specified item which must be valid (i.e. not
194 equal to @c wxNOT_FOUND).
30a7cc7b 195
d29a9a8a 196 @return @true if the items selection status has changed or @false
30a7cc7b
BP
197 otherwise.
198
23324ae1
FM
199 This function is only valid for the multiple selection listboxes, use
200 SetSelection() for the single selection ones.
201 */
4cc4bfaf 202 bool Select(size_t item, bool select = true);
23324ae1
FM
203
204 /**
205 Selects all the items in the listbox.
30a7cc7b 206
d29a9a8a 207 @return @true if any items were changed, i.e. if there had been any
30a7cc7b
BP
208 unselected items before, or @false if all the items were
209 already selected.
210
23324ae1 211 This method is only valid for multi selection listboxes.
3c4f71cc 212
4cc4bfaf 213 @see DeselectAll(), Select()
23324ae1
FM
214 */
215 bool SelectAll();
216
217 /**
30a7cc7b
BP
218 Selects all items in the specified range which may be given in any
219 order.
220
d29a9a8a 221 @return @true if the items selection status has changed or @false
30a7cc7b
BP
222 otherwise.
223
23324ae1 224 This method is only valid for multi selection listboxes.
3c4f71cc 225
4cc4bfaf 226 @see SelectAll(), Select()
23324ae1
FM
227 */
228 bool SelectRange(size_t from, size_t to);
229
230 /**
231 Set the number of items to be shown in the control.
30a7cc7b
BP
232
233 This is just a synonym for wxVScrolledWindow::SetRowCount().
23324ae1 234 */
adaaa686 235 virtual void SetItemCount(size_t count);
23324ae1
FM
236
237 //@{
238 /**
239 Set the margins: horizontal margin is the distance between the window
240 border and the item contents while vertical margin is half of the
241 distance between items.
30a7cc7b 242
23324ae1
FM
243 By default both margins are 0.
244 */
245 void SetMargins(const wxPoint& pt);
7c913512 246 void SetMargins(wxCoord x, wxCoord y);
23324ae1
FM
247 //@}
248
249 /**
250 Set the selection to the specified item, if it is -1 the selection is
30a7cc7b
BP
251 unset. The selected item will be automatically scrolled into view if it
252 isn't currently visible.
253
254 This method may be used both with single and multiple selection
255 listboxes.
23324ae1
FM
256 */
257 void SetSelection(int selection);
258
259 /**
30a7cc7b
BP
260 Sets the colour to be used for the selected cells background. The
261 background of the standard cells may be changed by simply calling
262 wxWindow::SetBackgroundColour().
263
264 @note Using a non-default background colour may result in control
265 having an appearance different from the similar native controls
266 and should be avoided in general.
3c4f71cc 267
4cc4bfaf 268 @see GetSelectionBackground()
23324ae1
FM
269 */
270 void SetSelectionBackground(const wxColour& col);
271
272 /**
30a7cc7b 273 Toggles the state of the specified @a item, i.e. selects it if it was
23324ae1 274 unselected and deselects it if it was selected.
30a7cc7b 275
23324ae1 276 This method is only valid for multi selection listboxes.
30a7cc7b
BP
277
278 @see Select()
23324ae1
FM
279 */
280 void Toggle(size_t item);
551266a9
FM
281
282protected:
283
284 /**
285 The derived class must implement this function to actually draw the
286 item with the given index on the provided DC.
287
288 @param dc
289 The device context to use for drawing.
290 @param rect
291 The bounding rectangle for the item being drawn (DC clipping
292 region is set to this rectangle before calling this function).
293 @param n
294 The index of the item to be drawn.
295
296 @todo Change this function signature to non-const.
297 */
da1ed74c 298 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
551266a9 299
5e6e278d
FM
300 /**
301 This method is used to draw the items background and, maybe, a border
302 around it.
303
304 The base class version implements a reasonable default behaviour which
305 consists in drawing the selected item with the standard background
306 colour and drawing a border around the item if it is either selected or
307 current.
308
309 @todo Change this function signature to non-const.
310 */
311 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
312
313 /**
314 This method may be used to draw separators between the lines. The
315 rectangle passed to it may be modified, typically to deflate it a bit
316 before passing to OnDrawItem().
317
318 The base class version of this method doesn't do anything.
319
320 @param dc
321 The device context to use for drawing.
322 @param rect
323 The bounding rectangle for the item.
324 @param n
325 The index of the item.
326
327 @todo Change this function signature to non-const.
328 */
329 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
330
551266a9
FM
331 /**
332 The derived class must implement this method to return the height of
333 the specified item (in pixels).
334 */
da1ed74c 335 virtual wxCoord OnMeasureItem(size_t n) const = 0;
23324ae1 336};
e54c96f1 337