]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: odcombo.h | |
e54c96f1 | 3 | // Purpose: interface of wxOwnerDrawnComboBox |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
3fedffdc FM |
9 | |
10 | enum wxOwnerDrawnComboBoxPaintingFlags | |
11 | { | |
12 | /** | |
13 | Combo control is being painted, instead of a list item. | |
14 | Argument item may be @c wxNOT_FOUND in this case. | |
15 | */ | |
16 | wxODCB_PAINTING_CONTROL = 0x0001, | |
17 | ||
18 | /** | |
19 | An item with selection background is being painted. | |
20 | DC text colour should already be correct. | |
21 | */ | |
22 | wxODCB_PAINTING_SELECTED = 0x0002 | |
23 | }; | |
24 | ||
23324ae1 FM |
25 | /** |
26 | @class wxOwnerDrawnComboBox | |
27 | @wxheader{odcombo.h} | |
7c913512 | 28 | |
23324ae1 | 29 | wxOwnerDrawnComboBox is a combobox with owner-drawn list items. |
74bf4e64 | 30 | In essence, it is a wxComboCtrl with wxVListBox popup and wxControlWithItems |
23324ae1 | 31 | interface. |
7c913512 | 32 | |
23324ae1 FM |
33 | Implementing item drawing and measuring is similar to wxVListBox. |
34 | Application needs to subclass wxOwnerDrawnComboBox and implement | |
74bf4e64 | 35 | OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth(). |
7c913512 | 36 | |
23324ae1 | 37 | @beginStyleTable |
8c6791e4 | 38 | @style{wxODCB_DCLICK_CYCLES} |
23324ae1 FM |
39 | Double-clicking cycles item if wxCB_READONLY is also used. |
40 | Synonymous with wxCC_SPECIAL_DCLICK. | |
8c6791e4 | 41 | @style{wxODCB_STD_CONTROL_PAINT} |
23324ae1 FM |
42 | Control itself is not custom painted using OnDrawItem. Even if this |
43 | style is not used, writable wxOwnerDrawnComboBox is never custom | |
74bf4e64 | 44 | painted unless SetCustomPaintWidth() is called. |
23324ae1 | 45 | @endStyleTable |
7c913512 | 46 | |
3fedffdc FM |
47 | @see wxComboCtrl window styles and @ref overview_windowstyles. |
48 | ||
1f1d2182 | 49 | @beginEventTable{wxCommandEvent} |
8c6791e4 | 50 | @event{EVT_COMBOBOX(id, func)} |
23324ae1 | 51 | Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on |
74bf4e64 | 52 | the list is selected. Note that calling GetValue() returns the new |
23324ae1 FM |
53 | value of selection. |
54 | @endEventTable | |
7c913512 | 55 | |
74bf4e64 FM |
56 | @see Events emitted by wxComboCtrl. |
57 | ||
23324ae1 FM |
58 | @library{wxadv} |
59 | @category{ctrl} | |
0c7fe6f2 | 60 | <!-- @appearance{ownerdrawncombobox.png} --> |
7c913512 | 61 | |
e54c96f1 | 62 | @see wxComboCtrl, wxComboBox, wxVListBox, wxCommandEvent |
23324ae1 FM |
63 | */ |
64 | class wxOwnerDrawnComboBox : public wxComboCtrl | |
65 | { | |
66 | public: | |
74bf4e64 FM |
67 | /** |
68 | Default constructor. | |
69 | */ | |
70 | wxOwnerDrawnComboBox(); | |
8c6791e4 | 71 | |
23324ae1 FM |
72 | //@{ |
73 | /** | |
74 | Constructor, creating and showing a owner-drawn combobox. | |
3c4f71cc | 75 | |
7c913512 | 76 | @param parent |
4cc4bfaf | 77 | Parent window. Must not be @NULL. |
7c913512 | 78 | @param id |
74bf4e64 | 79 | Window identifier. The value @c wxID_ANY indicates a default value. |
7c913512 | 80 | @param value |
4cc4bfaf | 81 | Initial selection string. An empty string indicates no selection. |
7c913512 | 82 | @param pos |
4cc4bfaf | 83 | Window position. |
7c913512 | 84 | @param size |
3fedffdc FM |
85 | Window size. |
86 | If ::wxDefaultSize is specified then the window is sized appropriately. | |
7c913512 | 87 | @param n |
4cc4bfaf | 88 | Number of strings with which to initialise the control. |
7c913512 | 89 | @param choices |
4cc4bfaf | 90 | An array of strings with which to initialise the control. |
7c913512 | 91 | @param style |
4cc4bfaf | 92 | Window style. See wxOwnerDrawnComboBox. |
7c913512 | 93 | @param validator |
4cc4bfaf | 94 | Window validator. |
7c913512 | 95 | @param name |
4cc4bfaf | 96 | Window name. |
3c4f71cc | 97 | |
4cc4bfaf | 98 | @see Create(), wxValidator |
23324ae1 | 99 | */ |
7c913512 FM |
100 | wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id, |
101 | const wxString& value = "", | |
102 | const wxPoint& pos = wxDefaultPosition, | |
103 | const wxSize& size = wxDefaultSize, | |
104 | int n = 0, | |
74bf4e64 | 105 | const wxString[] choices = NULL, |
7c913512 FM |
106 | long style = 0, |
107 | const wxValidator& validator = wxDefaultValidator, | |
108 | const wxString& name = "comboBox"); | |
109 | wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id, | |
110 | const wxString& value, | |
111 | const wxPoint& pos, | |
112 | const wxSize& size, | |
113 | const wxArrayString& choices, | |
114 | long style = 0, | |
115 | const wxValidator& validator = wxDefaultValidator, | |
116 | const wxString& name = "comboBox"); | |
23324ae1 FM |
117 | //@} |
118 | ||
119 | /** | |
120 | Destructor, destroying the owner-drawn combobox. | |
121 | */ | |
122 | ~wxOwnerDrawnComboBox(); | |
123 | ||
124 | //@{ | |
125 | /** | |
74bf4e64 FM |
126 | Creates the combobox for two-step construction. |
127 | See wxOwnerDrawnComboBox() for further details. | |
128 | ||
129 | @remarks Derived classes should call or replace this function. | |
23324ae1 FM |
130 | */ |
131 | bool Create(wxWindow* parent, wxWindowID id, | |
132 | const wxString& value = "", | |
133 | const wxPoint& pos = wxDefaultPosition, | |
134 | const wxSize& size = wxDefaultSize, | |
135 | int n, const wxString choices[], | |
136 | long style = 0, | |
137 | const wxValidator& validator = wxDefaultValidator, | |
138 | const wxString& name = "comboBox"); | |
7c913512 FM |
139 | bool Create(wxWindow* parent, wxWindowID id, |
140 | const wxString& value, | |
141 | const wxPoint& pos, | |
142 | const wxSize& size, | |
143 | const wxArrayString& choices, | |
144 | long style = 0, | |
145 | const wxValidator& validator = wxDefaultValidator, | |
146 | const wxString& name = "comboBox"); | |
23324ae1 FM |
147 | //@} |
148 | ||
149 | /** | |
150 | Returns index to the widest item in the list. | |
151 | */ | |
328f5751 | 152 | int GetWidestItem() const; |
23324ae1 FM |
153 | |
154 | /** | |
155 | Returns width of the widest item in the list. | |
156 | */ | |
328f5751 | 157 | int GetWidestItemWidth() const; |
23324ae1 FM |
158 | |
159 | /** | |
160 | This method is used to draw the items background and, maybe, a border around it. | |
74bf4e64 | 161 | |
23324ae1 FM |
162 | The base class version implements a reasonable default behaviour which consists |
163 | in drawing the selected item with the standard background colour and drawing a | |
164 | border around the item if it is either selected or current. | |
3c4f71cc | 165 | |
74bf4e64 | 166 | @remarks flags has the same meaning as with OnDrawItem(). |
23324ae1 FM |
167 | */ |
168 | void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, | |
328f5751 | 169 | int flags) const; |
23324ae1 FM |
170 | |
171 | /** | |
172 | The derived class may implement this function to actually draw the item | |
74bf4e64 FM |
173 | with the given index on the provided DC. |
174 | ||
175 | If function is not implemented, the item text is simply drawn, as if the control | |
176 | was a normal combobox. | |
3c4f71cc | 177 | |
7c913512 | 178 | @param dc |
4cc4bfaf | 179 | The device context to use for drawing |
7c913512 | 180 | @param rect |
4cc4bfaf FM |
181 | The bounding rectangle for the item being drawn (DC clipping |
182 | region is set to this rectangle before calling this function) | |
7c913512 | 183 | @param item |
4cc4bfaf | 184 | The index of the item to be drawn |
7c913512 | 185 | @param flags |
3fedffdc | 186 | A combination of the ::wxOwnerDrawnComboBoxPaintingFlags enumeration values. |
23324ae1 FM |
187 | */ |
188 | void OnDrawItem(wxDC& dc, const wxRect& rect, int item, | |
328f5751 | 189 | int flags) const; |
23324ae1 FM |
190 | |
191 | /** | |
192 | The derived class may implement this method to return the height of the | |
193 | specified item (in pixels). | |
74bf4e64 | 194 | |
23324ae1 FM |
195 | The default implementation returns text height, as if this control was |
196 | a normal combobox. | |
197 | */ | |
328f5751 | 198 | wxCoord OnMeasureItem(size_t item) const; |
23324ae1 FM |
199 | |
200 | /** | |
201 | The derived class may implement this method to return the width of the | |
202 | specified item (in pixels). If -1 is returned, then the item text width | |
203 | is used. | |
74bf4e64 | 204 | |
23324ae1 FM |
205 | The default implementation returns -1. |
206 | */ | |
328f5751 | 207 | wxCoord OnMeasureItemWidth(size_t item) const; |
23324ae1 | 208 | }; |
e54c96f1 | 209 |