]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/vlbox.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxVListBox is a virtual listbox with lines of variable height
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 #include "wx/vscroll.h" // base class
17 #define wxVListBoxNameStr _T("wxVListBox")
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
24 This class has two main differences from a regular listbox: it can have an
25 arbitrarily huge number of items because it doesn't store them itself but
26 uses OnDrawItem() callback to draw them and its items can have variable
27 height as determined by OnMeasureItem().
29 It emits the same events as wxListBox and the same event macros may be used
32 class WXDLLEXPORT wxVListBox
: public wxVScrolledWindow
35 // constructors and such
36 // ---------------------
38 // default constructor, you must call Create() later
39 wxVListBox() { Init(); }
41 // normal constructor which calls Create() internally
42 wxVListBox(wxWindow
*parent
,
43 wxWindowID id
= wxID_ANY
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
46 size_t countItems
= 0,
48 const wxString
& name
= wxVListBoxNameStr
)
52 (void)Create(parent
, id
, pos
, size
, countItems
, style
, name
);
55 // really creates the control and sets the initial number of items in it
56 // (which may be changed later with SetItemCount())
58 // there are no special styles defined for wxVListBox
60 // returns true on success or false if the control couldn't be created
61 bool Create(wxWindow
*parent
,
62 wxWindowID id
= wxID_ANY
,
63 const wxPoint
& pos
= wxDefaultPosition
,
64 const wxSize
& size
= wxDefaultSize
,
65 size_t countItems
= 0,
67 const wxString
& name
= wxVListBoxNameStr
);
73 // set the number of items to be shown in the control
75 // this is just a synonym for wxVScrolledWindow::SetLineCount()
76 void SetItemCount(size_t count
) { SetLineCount(count
); }
78 // delete all items from the control
79 void Clear() { SetItemCount(0); }
81 // set the selection to the specified item, if it is -1 the selection is
83 void SetSelection(int selection
) { DoSetSelection(selection
, false); }
85 // set the margins: horizontal margin is the distance between the window
86 // border and the item contents while vertical margin is half of the
87 // distance between items
89 // by default both margins are 0
90 void SetMargins(const wxPoint
& pt
);
91 void SetMargins(wxCoord x
, wxCoord y
) { SetMargins(wxPoint(x
, y
)); }
97 // get the number of items in the control
98 size_t GetItemCount() const { return GetLineCount(); }
100 // get the currently selected item or -1 if there is no selection
101 int GetSelection() const { return m_selection
; }
103 // is this item selected?
104 bool IsSelected(size_t line
) const { return (int)line
== m_selection
; }
106 // get the margins around each item
107 wxPoint
GetMargins() const { return m_ptMargins
; }
111 // the derived class must implement this function to actually draw the item
112 // with the given index on the provided DC
113 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const = 0;
115 // the derived class must implement this method to return the height of the
117 virtual wxCoord
OnMeasureItem(size_t n
) const = 0;
119 // this method may be used to draw separators between the lines; note that
120 // the rectangle may be modified, typically to deflate it a bit before
121 // passing to OnDrawItem()
123 // the base class version doesn't do anything
124 virtual void OnDrawSeparator(wxDC
& dc
, wxRect
& rect
, size_t n
) const;
127 // we implement OnGetLineHeight() in terms of OnMeasureItem() because this
128 // allows us to add borders to the items easily
130 // this function is not upposed to be overridden by the derived classes
131 virtual wxCoord
OnGetLineHeight(size_t line
) const;
135 void OnPaint(wxPaintEvent
& event
);
136 void OnKeyDown(wxKeyEvent
& event
);
137 void OnLeftDown(wxMouseEvent
& event
);
138 void OnLeftDClick(wxMouseEvent
& event
);
141 // common part of all ctors
144 // SetSelection() with additional parameter telling it whether to send a
145 // notification event or not
146 void DoSetSelection(int selection
, bool sendEvent
= true);
149 // the current selection or -1
156 DECLARE_EVENT_TABLE()
159 #endif // _WX_VLBOX_H_