]>
git.saurik.com Git - wxWidgets.git/blob - interface/vlbox.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxVListBox
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
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).
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).
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
34 <!-- @appearance{vlistbox.png} -->
36 @see wxSimpleHtmlListBox, wxHtmlListBox
38 class wxVListBox
: public wxVScrolledWindow
42 Default constructor, you must call Create() later.
46 Normal constructor which calls Create() internally.
48 wxVListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
49 const wxPoint
& pos
= wxDefaultPosition
,
50 const wxSize
& size
= wxDefaultSize
,
51 long style
= 0, const wxString
& name
= wxVListBoxNameStr
);
56 virtual ~wxVListBox();
59 Deletes all items from the control.
64 Creates the control. To finish creating it you also should call
65 SetItemCount() to let it know about the number of items it contains.
67 The only special style which may be used with wxVListBox is
68 @c wxLB_MULTIPLE which indicates that the listbox should support
71 @returns @true on success or @false if the control couldn't be created.
73 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
, long style
= 0,
76 const wxString
& name
= wxVListBoxNameStr
);
79 Deselects all the items in the listbox. This method is only valid for
80 multi selection listboxes.
82 @returns @true if any items were changed, i.e. if there had been any
83 selected items before, or @false if all the items were already
86 @see SelectAll(), Select()
91 Returns the index of the first selected item in the listbox or
92 @c wxNOT_FOUND if no items are currently selected.
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.
98 Here is a typical example of using these functions:
101 unsigned long cookie;
102 int item = hlbox->GetFirstSelected(cookie);
103 while ( item != wxNOT_FOUND )
105 // ... process item ...
106 item = hlbox->GetNextSelected(cookie);
110 This method is only valid for multi selection listboxes.
112 int GetFirstSelected(unsigned long& cookie
) const;
115 Get the number of items in the control.
119 size_t GetItemCount() const;
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.
127 wxPoint
GetMargins() const;
130 Returns the index of the next selected item or @c wxNOT_FOUND if there
133 This method is only valid for multi selection listboxes.
135 @see GetFirstSelected()
137 int GetNextSelected(unsigned long& cookie
) const;
140 Returns the number of the items currently selected.
142 It is valid for both single and multi selection controls. In the former
143 case it may only return 0 or 1 however.
145 @see IsSelected(), GetFirstSelected(), GetNextSelected()
147 size_t GetSelectedCount() const;
150 Get the currently selected item or @c wxNOT_FOUND if there is no
153 int GetSelection() const;
156 Returns the background colour used for the selected cells. By default
157 the standard system colour is used.
159 @see wxSystemSettings::GetColour(), SetSelectionBackground()
161 const wxColour
& GetSelectionBackground() const;
164 Returns @true if the listbox was created with @c wxLB_MULTIPLE style
165 and so supports multiple selection or @false if it is a single
168 bool HasMultipleSelection() const;
171 Returns @true if this item is the current one, @false otherwise.
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.
178 bool IsCurrent(size_t item
) const;
181 Returns @true if this item is selected, @false otherwise.
183 bool IsSelected(size_t item
) const;
186 This method is used to draw the items background and, maybe, a border
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
194 void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
197 The derived class must implement this function to actually draw the
198 item with the given index on the provided DC.
201 The device context to use for drawing.
203 The bounding rectangle for the item being drawn (DC clipping
204 region is set to this rectangle before calling this function).
206 The index of the item to be drawn.
208 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
211 This method may be used to draw separators between the lines. The
212 rectangle passed to it may be modified, typically to deflate it a bit
213 before passing to OnDrawItem().
215 The base class version of this method doesn't do anything.
218 The device context to use for drawing.
220 The bounding rectangle for the item.
222 The index of the item.
224 virtual void OnDrawSeparator(wxDC
& dc
, wxRect
& rect
, size_t n
) const;
227 The derived class must implement this method to return the height of
228 the specified item (in pixels).
230 virtual wxCoord
OnMeasureItem(size_t n
) const;
233 Selects or deselects the specified item which must be valid (i.e. not
234 equal to @c wxNOT_FOUND).
236 @returns @true if the items selection status has changed or @false
239 This function is only valid for the multiple selection listboxes, use
240 SetSelection() for the single selection ones.
242 bool Select(size_t item
, bool select
= true);
245 Selects all the items in the listbox.
247 @returns @true if any items were changed, i.e. if there had been any
248 unselected items before, or @false if all the items were
251 This method is only valid for multi selection listboxes.
253 @see DeselectAll(), Select()
258 Selects all items in the specified range which may be given in any
261 @returns @true if the items selection status has changed or @false
264 This method is only valid for multi selection listboxes.
266 @see SelectAll(), Select()
268 bool SelectRange(size_t from
, size_t to
);
271 Set the number of items to be shown in the control.
273 This is just a synonym for wxVScrolledWindow::SetRowCount().
275 void SetItemCount(size_t count
);
279 Set the margins: horizontal margin is the distance between the window
280 border and the item contents while vertical margin is half of the
281 distance between items.
283 By default both margins are 0.
285 void SetMargins(const wxPoint
& pt
);
286 void SetMargins(wxCoord x
, wxCoord y
);
290 Set the selection to the specified item, if it is -1 the selection is
291 unset. The selected item will be automatically scrolled into view if it
292 isn't currently visible.
294 This method may be used both with single and multiple selection
297 void SetSelection(int selection
);
300 Sets the colour to be used for the selected cells background. The
301 background of the standard cells may be changed by simply calling
302 wxWindow::SetBackgroundColour().
304 @note Using a non-default background colour may result in control
305 having an appearance different from the similar native controls
306 and should be avoided in general.
308 @see GetSelectionBackground()
310 void SetSelectionBackground(const wxColour
& col
);
313 Toggles the state of the specified @a item, i.e. selects it if it was
314 unselected and deselects it if it was selected.
316 This method is only valid for multi selection listboxes.
320 void Toggle(size_t item
);