]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/vlbox.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxVListBox
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
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).
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).
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
34 @see wxSimpleHtmlListBox, wxHtmlListBox
36 class wxVListBox
: public wxVScrolledWindow
40 Default constructor, you must call Create() later.
44 Normal constructor which calls Create() internally.
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
);
54 virtual ~wxVListBox();
57 Deletes all items from the control.
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.
65 The only special style which may be used with wxVListBox is
66 @c wxLB_MULTIPLE which indicates that the listbox should support
69 @return @true on success or @false if the control couldn't be created.
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
);
77 Deselects all the items in the listbox. This method is only valid for
78 multi selection listboxes.
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
84 @see SelectAll(), Select()
89 Returns the index of the first selected item in the listbox or
90 @c wxNOT_FOUND if no items are currently selected.
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.
96 Here is a typical example of using these functions:
100 int item = hlbox->GetFirstSelected(cookie);
101 while ( item != wxNOT_FOUND )
103 // ... process item ...
104 item = hlbox->GetNextSelected(cookie);
108 This method is only valid for multi selection listboxes.
110 int GetFirstSelected(unsigned long& cookie
) const;
113 Get the number of items in the control.
117 size_t GetItemCount() const;
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.
125 wxPoint
GetMargins() const;
128 Returns the rectangle occupied by this item in physical coordinates.
130 If the item is not currently visible, returns an empty rectangle.
134 wxRect
GetItemRect(size_t item
) const;
137 Returns the index of the next selected item or @c wxNOT_FOUND if there
140 This method is only valid for multi selection listboxes.
142 @see GetFirstSelected()
144 int GetNextSelected(unsigned long& cookie
) const;
147 Returns the number of the items currently selected.
149 It is valid for both single and multi selection controls. In the former
150 case it may only return 0 or 1 however.
152 @see IsSelected(), GetFirstSelected(), GetNextSelected()
154 size_t GetSelectedCount() const;
157 Get the currently selected item or @c wxNOT_FOUND if there is no
160 int GetSelection() const;
163 Returns the background colour used for the selected cells. By default
164 the standard system colour is used.
166 @see wxSystemSettings::GetColour(), SetSelectionBackground()
168 const wxColour
& GetSelectionBackground() const;
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
175 bool HasMultipleSelection() const;
178 Returns @true if this item is the current one, @false otherwise.
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.
185 bool IsCurrent(size_t item
) const;
188 Returns @true if this item is selected, @false otherwise.
190 bool IsSelected(size_t item
) const;
193 Selects or deselects the specified item which must be valid (i.e.\ not
194 equal to @c wxNOT_FOUND).
196 @return @true if the items selection status has changed or @false
199 This function is only valid for the multiple selection listboxes, use
200 SetSelection() for the single selection ones.
202 bool Select(size_t item
, bool select
= true);
205 Selects all the items in the listbox.
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
211 This method is only valid for multi selection listboxes.
213 @see DeselectAll(), Select()
218 Selects all items in the specified range which may be given in any
221 @return @true if the items selection status has changed or @false
224 This method is only valid for multi selection listboxes.
226 @see SelectAll(), Select()
228 bool SelectRange(size_t from
, size_t to
);
231 Set the number of items to be shown in the control.
233 This is just a synonym for wxVScrolledWindow::SetRowCount().
235 virtual void SetItemCount(size_t count
);
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.
243 By default both margins are 0.
245 void SetMargins(const wxPoint
& pt
);
246 void SetMargins(wxCoord x
, wxCoord y
);
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.
254 This method may be used both with single and multiple selection
257 void SetSelection(int selection
);
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().
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.
268 @see GetSelectionBackground()
270 void SetSelectionBackground(const wxColour
& col
);
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.
276 This method is only valid for multi selection listboxes.
280 void Toggle(size_t item
);
285 The derived class must implement this function to actually draw the
286 item with the given index on the provided DC.
289 The device context to use for drawing.
291 The bounding rectangle for the item being drawn (DC clipping
292 region is set to this rectangle before calling this function).
294 The index of the item to be drawn.
296 @todo Change this function signature to non-const.
298 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const = 0;
301 This method is used to draw the item's background and, maybe, a border
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
309 @todo Change this function signature to non-const.
311 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
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().
318 The base class version of this method doesn't do anything.
321 The device context to use for drawing.
323 The bounding rectangle for the item.
325 The index of the item.
327 @todo Change this function signature to non-const.
329 virtual void OnDrawSeparator(wxDC
& dc
, wxRect
& rect
, size_t n
) const;
332 The derived class must implement this method to return the height of
333 the specified item (in pixels).
335 virtual wxCoord
OnMeasureItem(size_t n
) const = 0;