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