]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/vlbox.h
Move SetDefaultTimeout to wxProtocol and set it to 60 seconds for both wxHTTP and...
[wxWidgets.git] / interface / wx / vlbox.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: vlbox.h
3 // Purpose: interface of wxVListBox
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxVListBox
11
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.
30
31 @library{wxcore}
32 @category{ctrl}
33
34 @see wxSimpleHtmlListBox, wxHtmlListBox
35 */
36 class wxVListBox : public wxVScrolledWindow
37 {
38 public:
39 /**
40 Default constructor, you must call Create() later.
41 */
42 wxVListBox();
43 /**
44 Normal constructor which calls Create() internally.
45 */
46 wxVListBox(wxWindow* parent, wxWindowID id = wxID_ANY,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize,
49 long style = 0, const wxString& name = wxVListBoxNameStr);
50
51 /**
52 Destructor.
53 */
54 virtual ~wxVListBox();
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
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
69 @return @true on success or @false if the control couldn't be created.
70 */
71 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
72 const wxPoint& pos = wxDefaultPosition,
73 const wxSize& size = wxDefaultSize, long style = 0,
74 const wxString& name = wxVListBoxNameStr);
75
76 /**
77 Deselects all the items in the listbox. This method is only valid for
78 multi selection listboxes.
79
80 @return @true if any items were changed, i.e. if there had been any
81 selected items before, or @false if all the items were already
82 deselected.
83
84 @see SelectAll(), Select()
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.
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
96 Here is a typical example of using these functions:
97
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
108 This method is only valid for multi selection listboxes.
109 */
110 int GetFirstSelected(unsigned long& cookie) const;
111
112 /**
113 Get the number of items in the control.
114
115 @see SetItemCount()
116 */
117 size_t GetItemCount() const;
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.
122
123 @see SetMargins()
124 */
125 wxPoint GetMargins() const;
126
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.
131
132 @since 2.9.0
133 */
134 wxRect GetItemRect(size_t item) const;
135
136 /**
137 Returns the index of the next selected item or @c wxNOT_FOUND if there
138 are no more.
139
140 This method is only valid for multi selection listboxes.
141
142 @see GetFirstSelected()
143 */
144 int GetNextSelected(unsigned long& cookie) const;
145
146 /**
147 Returns the number of the items currently selected.
148
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()
153 */
154 size_t GetSelectedCount() const;
155
156 /**
157 Get the currently selected item or @c wxNOT_FOUND if there is no
158 selection.
159 */
160 int GetSelection() const;
161
162 /**
163 Returns the background colour used for the selected cells. By default
164 the standard system colour is used.
165
166 @see wxSystemSettings::GetColour(), SetSelectionBackground()
167 */
168 const wxColour& GetSelectionBackground() const;
169
170 /**
171 Returns @true if the listbox was created with @c wxLB_MULTIPLE style
172 and so supports multiple selection or @false if it is a single
173 selection listbox.
174 */
175 bool HasMultipleSelection() const;
176
177 /**
178 Returns @true if this item is the current one, @false otherwise.
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.
184 */
185 bool IsCurrent(size_t item) const;
186
187 /**
188 Returns @true if this item is selected, @false otherwise.
189 */
190 bool IsSelected(size_t item) const;
191
192 /**
193 Selects or deselects the specified item which must be valid (i.e. not
194 equal to @c wxNOT_FOUND).
195
196 @return @true if the items selection status has changed or @false
197 otherwise.
198
199 This function is only valid for the multiple selection listboxes, use
200 SetSelection() for the single selection ones.
201 */
202 bool Select(size_t item, bool select = true);
203
204 /**
205 Selects all the items in the listbox.
206
207 @return @true if any items were changed, i.e. if there had been any
208 unselected items before, or @false if all the items were
209 already selected.
210
211 This method is only valid for multi selection listboxes.
212
213 @see DeselectAll(), Select()
214 */
215 bool SelectAll();
216
217 /**
218 Selects all items in the specified range which may be given in any
219 order.
220
221 @return @true if the items selection status has changed or @false
222 otherwise.
223
224 This method is only valid for multi selection listboxes.
225
226 @see SelectAll(), Select()
227 */
228 bool SelectRange(size_t from, size_t to);
229
230 /**
231 Set the number of items to be shown in the control.
232
233 This is just a synonym for wxVScrolledWindow::SetRowCount().
234 */
235 virtual void SetItemCount(size_t count);
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.
242
243 By default both margins are 0.
244 */
245 void SetMargins(const wxPoint& pt);
246 void SetMargins(wxCoord x, wxCoord y);
247 //@}
248
249 /**
250 Set the selection to the specified item, if it is -1 the selection is
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.
256 */
257 void SetSelection(int selection);
258
259 /**
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.
267
268 @see GetSelectionBackground()
269 */
270 void SetSelectionBackground(const wxColour& col);
271
272 /**
273 Toggles the state of the specified @a item, i.e. selects it if it was
274 unselected and deselects it if it was selected.
275
276 This method is only valid for multi selection listboxes.
277
278 @see Select()
279 */
280 void Toggle(size_t item);
281
282 protected:
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 */
298 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
299
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
331 /**
332 The derived class must implement this method to return the height of
333 the specified item (in pixels).
334 */
335 virtual wxCoord OnMeasureItem(size_t n) const = 0;
336 };
337