]>
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$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
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 | ||
5eeccdd5 RD |
25 | |
26 | /** | |
27 | New window styles for wxOwnerDrawnComboBox | |
28 | */ | |
29 | enum | |
30 | { | |
31 | /** | |
32 | Double-clicking cycles item if wxCB_READONLY is also used. | |
33 | */ | |
34 | wxODCB_DCLICK_CYCLES = wxCC_SPECIAL_DCLICK, | |
35 | ||
36 | /** | |
37 | If used, control itself is not custom paint using callback. | |
38 | Even if this is not used, writable combo is never custom paint | |
39 | until SetCustomPaintWidth is called | |
40 | */ | |
41 | wxODCB_STD_CONTROL_PAINT = 0x1000 | |
42 | }; | |
43 | ||
44 | ||
45 | ||
23324ae1 FM |
46 | /** |
47 | @class wxOwnerDrawnComboBox | |
7c913512 | 48 | |
23324ae1 | 49 | wxOwnerDrawnComboBox is a combobox with owner-drawn list items. |
74bf4e64 | 50 | In essence, it is a wxComboCtrl with wxVListBox popup and wxControlWithItems |
23324ae1 | 51 | interface. |
7c913512 | 52 | |
23324ae1 FM |
53 | Implementing item drawing and measuring is similar to wxVListBox. |
54 | Application needs to subclass wxOwnerDrawnComboBox and implement | |
74bf4e64 | 55 | OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth(). |
7c913512 | 56 | |
23324ae1 | 57 | @beginStyleTable |
8c6791e4 | 58 | @style{wxODCB_DCLICK_CYCLES} |
23324ae1 FM |
59 | Double-clicking cycles item if wxCB_READONLY is also used. |
60 | Synonymous with wxCC_SPECIAL_DCLICK. | |
8c6791e4 | 61 | @style{wxODCB_STD_CONTROL_PAINT} |
23324ae1 FM |
62 | Control itself is not custom painted using OnDrawItem. Even if this |
63 | style is not used, writable wxOwnerDrawnComboBox is never custom | |
74bf4e64 | 64 | painted unless SetCustomPaintWidth() is called. |
23324ae1 | 65 | @endStyleTable |
7c913512 | 66 | |
3fedffdc FM |
67 | @see wxComboCtrl window styles and @ref overview_windowstyles. |
68 | ||
3051a44a | 69 | @beginEventEmissionTable{wxCommandEvent} |
8c6791e4 | 70 | @event{EVT_COMBOBOX(id, func)} |
23324ae1 | 71 | Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on |
74bf4e64 | 72 | the list is selected. Note that calling GetValue() returns the new |
23324ae1 FM |
73 | value of selection. |
74 | @endEventTable | |
7c913512 | 75 | |
74bf4e64 FM |
76 | @see Events emitted by wxComboCtrl. |
77 | ||
23324ae1 FM |
78 | @library{wxadv} |
79 | @category{ctrl} | |
7e59b885 | 80 | @appearance{ownerdrawncombobox.png} |
7c913512 | 81 | |
e54c96f1 | 82 | @see wxComboCtrl, wxComboBox, wxVListBox, wxCommandEvent |
23324ae1 | 83 | */ |
7af4648f | 84 | class wxOwnerDrawnComboBox : public wxComboCtrl, public wxItemContainer |
23324ae1 FM |
85 | { |
86 | public: | |
74bf4e64 FM |
87 | /** |
88 | Default constructor. | |
89 | */ | |
90 | wxOwnerDrawnComboBox(); | |
8c6791e4 | 91 | |
23324ae1 FM |
92 | /** |
93 | Constructor, creating and showing a owner-drawn combobox. | |
3c4f71cc | 94 | |
7c913512 | 95 | @param parent |
4cc4bfaf | 96 | Parent window. Must not be @NULL. |
7c913512 | 97 | @param id |
74bf4e64 | 98 | Window identifier. The value @c wxID_ANY indicates a default value. |
7c913512 | 99 | @param value |
4cc4bfaf | 100 | Initial selection string. An empty string indicates no selection. |
7c913512 | 101 | @param pos |
4cc4bfaf | 102 | Window position. |
7c913512 | 103 | @param size |
3fedffdc FM |
104 | Window size. |
105 | If ::wxDefaultSize is specified then the window is sized appropriately. | |
7c913512 | 106 | @param n |
4cc4bfaf | 107 | Number of strings with which to initialise the control. |
7c913512 | 108 | @param choices |
4cc4bfaf | 109 | An array of strings with which to initialise the control. |
7c913512 | 110 | @param style |
4cc4bfaf | 111 | Window style. See wxOwnerDrawnComboBox. |
7c913512 | 112 | @param validator |
4cc4bfaf | 113 | Window validator. |
7c913512 | 114 | @param name |
4cc4bfaf | 115 | Window name. |
3c4f71cc | 116 | |
4cc4bfaf | 117 | @see Create(), wxValidator |
23324ae1 | 118 | */ |
7c913512 | 119 | wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id, |
e9c3992c | 120 | const wxString& value = wxEmptyString, |
7c913512 FM |
121 | const wxPoint& pos = wxDefaultPosition, |
122 | const wxSize& size = wxDefaultSize, | |
123 | int n = 0, | |
6dea8384 | 124 | const wxString choices[] = NULL, |
7c913512 FM |
125 | long style = 0, |
126 | const wxValidator& validator = wxDefaultValidator, | |
127 | const wxString& name = "comboBox"); | |
792255cc VZ |
128 | /** |
129 | Constructor, creating and showing a owner-drawn combobox. | |
130 | ||
131 | @param parent | |
132 | Parent window. Must not be @NULL. | |
133 | @param id | |
134 | Window identifier. The value @c wxID_ANY indicates a default value. | |
135 | @param value | |
136 | Initial selection string. An empty string indicates no selection. | |
137 | @param pos | |
138 | Window position. | |
139 | @param size | |
140 | Window size. | |
141 | If ::wxDefaultSize is specified then the window is sized appropriately. | |
142 | @param choices | |
143 | An array of strings with which to initialise the control. | |
144 | @param style | |
145 | Window style. See wxOwnerDrawnComboBox. | |
146 | @param validator | |
147 | Window validator. | |
148 | @param name | |
149 | Window name. | |
150 | ||
151 | @see Create(), wxValidator | |
152 | */ | |
7c913512 FM |
153 | wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id, |
154 | const wxString& value, | |
155 | const wxPoint& pos, | |
156 | const wxSize& size, | |
157 | const wxArrayString& choices, | |
158 | long style = 0, | |
159 | const wxValidator& validator = wxDefaultValidator, | |
160 | const wxString& name = "comboBox"); | |
23324ae1 FM |
161 | |
162 | /** | |
163 | Destructor, destroying the owner-drawn combobox. | |
164 | */ | |
adaaa686 | 165 | virtual ~wxOwnerDrawnComboBox(); |
23324ae1 FM |
166 | |
167 | //@{ | |
168 | /** | |
74bf4e64 FM |
169 | Creates the combobox for two-step construction. |
170 | See wxOwnerDrawnComboBox() for further details. | |
171 | ||
172 | @remarks Derived classes should call or replace this function. | |
23324ae1 | 173 | */ |
57bf907d FM |
174 | bool Create(wxWindow *parent, |
175 | wxWindowID id, | |
e9c3992c | 176 | const wxString& value = wxEmptyString, |
23324ae1 FM |
177 | const wxPoint& pos = wxDefaultPosition, |
178 | const wxSize& size = wxDefaultSize, | |
23324ae1 FM |
179 | long style = 0, |
180 | const wxValidator& validator = wxDefaultValidator, | |
57bf907d FM |
181 | const wxString& name = wxComboBoxNameStr); |
182 | bool Create(wxWindow *parent, | |
183 | wxWindowID id, | |
184 | const wxString& value, | |
185 | const wxPoint& pos, | |
186 | const wxSize& size, | |
187 | int n, | |
188 | const wxString choices[], | |
189 | long style = 0, | |
190 | const wxValidator& validator = wxDefaultValidator, | |
191 | const wxString& name = wxComboBoxNameStr); | |
192 | bool Create(wxWindow *parent, | |
193 | wxWindowID id, | |
7c913512 FM |
194 | const wxString& value, |
195 | const wxPoint& pos, | |
196 | const wxSize& size, | |
197 | const wxArrayString& choices, | |
198 | long style = 0, | |
199 | const wxValidator& validator = wxDefaultValidator, | |
57bf907d | 200 | const wxString& name = wxComboBoxNameStr); |
23324ae1 FM |
201 | //@} |
202 | ||
203 | /** | |
204 | Returns index to the widest item in the list. | |
205 | */ | |
adaaa686 | 206 | virtual int GetWidestItem(); |
23324ae1 FM |
207 | |
208 | /** | |
209 | Returns width of the widest item in the list. | |
210 | */ | |
adaaa686 | 211 | virtual int GetWidestItemWidth(); |
23324ae1 | 212 | |
5e6e278d FM |
213 | protected: |
214 | ||
23324ae1 FM |
215 | /** |
216 | This method is used to draw the items background and, maybe, a border around it. | |
74bf4e64 | 217 | |
23324ae1 FM |
218 | The base class version implements a reasonable default behaviour which consists |
219 | in drawing the selected item with the standard background colour and drawing a | |
220 | border around the item if it is either selected or current. | |
3c4f71cc | 221 | |
74bf4e64 | 222 | @remarks flags has the same meaning as with OnDrawItem(). |
23324ae1 | 223 | */ |
fadc2df6 FM |
224 | virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, |
225 | int flags) const; | |
23324ae1 FM |
226 | |
227 | /** | |
228 | The derived class may implement this function to actually draw the item | |
74bf4e64 FM |
229 | with the given index on the provided DC. |
230 | ||
231 | If function is not implemented, the item text is simply drawn, as if the control | |
232 | was a normal combobox. | |
3c4f71cc | 233 | |
7c913512 | 234 | @param dc |
4cc4bfaf | 235 | The device context to use for drawing |
7c913512 | 236 | @param rect |
4cc4bfaf FM |
237 | The bounding rectangle for the item being drawn (DC clipping |
238 | region is set to this rectangle before calling this function) | |
7c913512 | 239 | @param item |
4cc4bfaf | 240 | The index of the item to be drawn |
7c913512 | 241 | @param flags |
3fedffdc | 242 | A combination of the ::wxOwnerDrawnComboBoxPaintingFlags enumeration values. |
23324ae1 | 243 | */ |
fadc2df6 FM |
244 | virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item, |
245 | int flags) const; | |
23324ae1 FM |
246 | |
247 | /** | |
248 | The derived class may implement this method to return the height of the | |
249 | specified item (in pixels). | |
74bf4e64 | 250 | |
23324ae1 FM |
251 | The default implementation returns text height, as if this control was |
252 | a normal combobox. | |
253 | */ | |
0004982c | 254 | virtual wxCoord OnMeasureItem(size_t item) const; |
23324ae1 FM |
255 | |
256 | /** | |
257 | The derived class may implement this method to return the width of the | |
258 | specified item (in pixels). If -1 is returned, then the item text width | |
259 | is used. | |
74bf4e64 | 260 | |
23324ae1 FM |
261 | The default implementation returns -1. |
262 | */ | |
0004982c | 263 | virtual wxCoord OnMeasureItemWidth(size_t item) const; |
23324ae1 | 264 | }; |
e54c96f1 | 265 |