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