]> git.saurik.com Git - wxWidgets.git/blame - include/wx/odcombo.h
we don't need to override MSWTranslateMessage(), it was a wrong workaround for the...
[wxWidgets.git] / include / wx / odcombo.h
CommitLineData
a340b80d
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/odcombo.h
3// Purpose: wxOwnerDrawnComboBox and wxVListBoxPopup
4// Author: Jaakko Salli
5// Modified by:
6// Created: Apr-30-2006
7// RCS-ID: $Id$
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_ODCOMBO_H_
13#define _WX_ODCOMBO_H_
14
15#include "wx/defs.h"
16
a57d600f 17#if wxUSE_ODCOMBOBOX
a340b80d
VZ
18
19#include "wx/combo.h"
20#include "wx/ctrlsub.h"
21#include "wx/vlbox.h"
22
23
24//
25// New window styles for wxOwnerDrawnComboBox
26//
27enum
28{
29 // Double-clicking cycles item if wxCB_READONLY is also used.
30 wxODCB_DCLICK_CYCLES = wxCC_SPECIAL_DCLICK,
31
32 // If used, control itself is not custom paint using callback.
33 // Even if this is not used, writable combo is never custom paint
34 // until SetCustomPaintWidth is called
35 wxODCB_STD_CONTROL_PAINT = 0x1000
36};
37
38
39//
40b26d75 40// Callback flags (see wxOwnerDrawnComboBox::OnDrawItem)
a340b80d
VZ
41//
42enum
43{
44 // when set, we are painting the selected item in control,
45 // not in the popup
40b26d75 46 wxODCB_PAINTING_CONTROL = 0x0001
a340b80d
VZ
47};
48
49
50// ----------------------------------------------------------------------------
51// wxVListBoxComboPopup is a wxVListBox customized to act as a popup control.
52//
53// Notes:
54// wxOwnerDrawnComboBox uses this as its popup. However, it always derives
a57d600f 55// from native wxComboCtrl. If you need to use this popup with
a340b80d
VZ
56// wxGenericComboControl, then remember that vast majority of item manipulation
57// functionality is implemented in the wxVListBoxComboPopup class itself.
58//
59// ----------------------------------------------------------------------------
60
61
c98e80d9
VZ
62class WXDLLIMPEXP_ADV wxVListBoxComboPopup : public wxVListBox,
63 public wxComboPopup
a340b80d
VZ
64{
65 friend class wxOwnerDrawnComboBox;
66public:
67
6d0ce565
VZ
68 // init and dtor
69 wxVListBoxComboPopup() : wxVListBox(), wxComboPopup() { }
a340b80d
VZ
70 virtual ~wxVListBoxComboPopup();
71
72 // required virtuals
6d0ce565 73 virtual void Init();
a340b80d
VZ
74 virtual bool Create(wxWindow* parent);
75 virtual wxWindow *GetControl() { return this; }
76 virtual void SetStringValue( const wxString& value );
77 virtual wxString GetStringValue() const;
78
79 // more customization
80 virtual void OnPopup();
81 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight );
82 virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
83 virtual void OnComboKeyEvent( wxKeyEvent& event );
84 virtual void OnComboDoubleClick();
85 virtual bool LazyCreate();
86
87 // Item management
88 void SetSelection( int item );
89 void Insert( const wxString& item, int pos );
90 int Append(const wxString& item);
91 void Clear();
92 void Delete( unsigned int item );
93 void SetItemClientData(unsigned int n, void* clientData, wxClientDataType clientDataItemsType);
94 void *GetItemClientData(unsigned int n) const;
95 void SetString( int item, const wxString& str );
96 wxString GetString( int item ) const;
97 unsigned int GetCount() const;
9e6aca68 98 int FindString(const wxString& s, bool bCase = false) const;
6d0ce565 99 int GetSelection() const;
a340b80d 100
6d0ce565
VZ
101 //void Populate( int n, const wxString choices[] );
102 void Populate( const wxArrayString& choices );
a340b80d
VZ
103 void ClearClientDatas();
104
105 // helpers
106 int GetItemAtPosition( const wxPoint& pos ) { return HitTest(pos); }
107 wxCoord GetTotalHeight() const { return EstimateTotalHeight(); }
108 wxCoord GetLineHeight(int line) const { return OnGetLineHeight(line); }
109
110protected:
111
112 // Called by OnComboDoubleClick and OnComboKeyEvent
113 bool HandleKey( int keycode, bool saturate );
114
115 // sends combobox select event from the parent combo control
6d0ce565 116 void SendComboBoxEvent( int selection );
7ca4ac63 117
6d0ce565
VZ
118 // gets value, sends event and dismisses
119 void DismissWithEvent();
a340b80d 120
e5d63342
WS
121 // OnMeasureItemWidth will be called on next GetAdjustedSize.
122 void ItemWidthChanged(unsigned int item)
123 {
124 m_widths[item] = -1;
125 m_widthsDirty = true;
126 }
a340b80d 127
40b26d75
WS
128 // Callbacks for drawing and measuring items. Override in a derived class for
129 // owner-drawnness. Font, background and text colour have been prepared according
130 // to selection, focus and such.
131 //
132 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
133 // and there is no valid selection
134 // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
135 // NOTE: If wxVListBoxComboPopup is used with wxComboCtrl class not derived from
136 // wxOwnerDrawnComboBox, this method must be overridden.
137 virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
a340b80d 138
40b26d75 139 // This is same as in wxVListBox
dcc8cf5a
PC
140 virtual wxCoord OnMeasureItem( size_t item ) const;
141
40b26d75
WS
142 // Return item width, or -1 for calculating from text extent (default)
143 virtual wxCoord OnMeasureItemWidth( size_t item ) const;
144
145 // Draw item and combo control background. Flags are same as with OnDrawItem.
146 // NB: Can't use name OnDrawBackground because of virtual function hiding warnings.
147 virtual void OnDrawBg(wxDC& dc, const wxRect& rect, int item, int flags) const;
148
149 // Additional wxVListBox implementation (no need to override in derived classes)
150 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
151 void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
152
a340b80d
VZ
153 // filter mouse move events happening outside the list box
154 // move selection with cursor
155 void OnMouseMove(wxMouseEvent& event);
156 void OnMouseWheel(wxMouseEvent& event);
157 void OnKey(wxKeyEvent& event);
158 void OnLeftClick(wxMouseEvent& event);
159
160 wxArrayString m_strings;
161 wxArrayPtrVoid m_clientDatas;
a340b80d 162
6d0ce565 163 wxFont m_useFont;
a340b80d 164
6d0ce565 165 //wxString m_stringValue; // displayed text (may be different than m_strings[m_value])
a340b80d
VZ
166 int m_value; // selection
167 int m_itemHover; // on which item the cursor is
a340b80d
VZ
168 int m_itemHeight; // default item height (calculate from font size
169 // and used in the absence of callback)
170 wxClientDataType m_clientDataItemsType;
171
172private:
173
e5d63342
WS
174 // Cached item widths (in pixels).
175 wxArrayInt m_widths;
176
177 // Width of currently widest item.
178 int m_widestWidth;
179
180 // Index of currently widest item.
181 int m_widestItem;
182
183 // Measure some items in next GetAdjustedSize?
184 bool m_widthsDirty;
185
186 // Find widest item in next GetAdjustedSize?
187 bool m_findWidest;
188
a340b80d 189 // has the mouse been released on this control?
e5d63342 190 bool m_clicked;
a340b80d
VZ
191
192 DECLARE_EVENT_TABLE()
193};
194
195
196// ----------------------------------------------------------------------------
197// wxOwnerDrawnComboBox: a generic wxComboBox that allows custom paint items
198// in addition to many other types of customization already allowed by
a57d600f 199// the wxComboCtrl.
a340b80d
VZ
200// ----------------------------------------------------------------------------
201
a57d600f 202class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : public wxComboCtrl,
c98e80d9 203 public wxItemContainer
a340b80d 204{
40b26d75
WS
205 //friend class wxComboPopupWindow;
206 friend class wxVListBoxComboPopup;
a340b80d
VZ
207public:
208
209 // ctors and such
a57d600f 210 wxOwnerDrawnComboBox() : wxComboCtrl() { Init(); }
a340b80d
VZ
211
212 wxOwnerDrawnComboBox(wxWindow *parent,
213 wxWindowID id,
214 const wxString& value,
215 const wxPoint& pos,
216 const wxSize& size,
217 int n,
218 const wxString choices[],
219 long style = 0,
220 const wxValidator& validator = wxDefaultValidator,
221 const wxString& name = wxComboBoxNameStr)
a57d600f 222 : wxComboCtrl()
a340b80d
VZ
223 {
224 Init();
225
226 (void)Create(parent, id, value, pos, size, n,
227 choices, style, validator, name);
228 }
229
230 bool Create(wxWindow *parent,
231 wxWindowID id,
1c4743aa 232 const wxString& value = wxEmptyString,
a340b80d
VZ
233 const wxPoint& pos = wxDefaultPosition,
234 const wxSize& size = wxDefaultSize,
235 long style = 0,
236 const wxValidator& validator = wxDefaultValidator,
237 const wxString& name = wxComboBoxNameStr);
238
239 wxOwnerDrawnComboBox(wxWindow *parent,
240 wxWindowID id,
241 const wxString& value,
242 const wxPoint& pos,
243 const wxSize& size,
244 const wxArrayString& choices,
7ca4ac63 245 long style,
a340b80d
VZ
246 const wxValidator& validator = wxDefaultValidator,
247 const wxString& name = wxComboBoxNameStr);
248
249 bool Create(wxWindow *parent,
250 wxWindowID id,
1c4743aa
WS
251 const wxString& value,
252 const wxPoint& pos,
253 const wxSize& size,
254 int n,
255 const wxString choices[],
a340b80d
VZ
256 long style = 0,
257 const wxValidator& validator = wxDefaultValidator,
258 const wxString& name = wxComboBoxNameStr);
259
260 bool Create(wxWindow *parent,
261 wxWindowID id,
262 const wxString& value,
263 const wxPoint& pos,
264 const wxSize& size,
265 const wxArrayString& choices,
266 long style = 0,
267 const wxValidator& validator = wxDefaultValidator,
268 const wxString& name = wxComboBoxNameStr);
269
270 virtual ~wxOwnerDrawnComboBox();
271
db53c6ea
WS
272 // Prevent app from using wxComboPopup
273 void SetPopupControl(wxVListBoxComboPopup* popup)
274 {
275 DoSetPopupControl(popup);
276 }
6d0ce565 277
a340b80d
VZ
278 // wxControlWithItems methods
279 virtual void Clear();
280 virtual void Delete(unsigned int n);
281 virtual unsigned int GetCount() const;
282 virtual wxString GetString(unsigned int n) const;
283 virtual void SetString(unsigned int n, const wxString& s);
9e6aca68 284 virtual int FindString(const wxString& s, bool bCase = false) const;
a340b80d
VZ
285 virtual void Select(int n);
286 virtual int GetSelection() const;
c0f48280 287 virtual void SetSelection(int n) { Select(n); }
a340b80d 288
7ca4ac63
WS
289
290 // Prevent a method from being hidden
291 virtual void SetSelection(long from, long to)
292 {
293 wxComboCtrl::SetSelection(from,to);
294 }
295
a340b80d
VZ
296 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
297
298protected:
299
40b26d75
WS
300 // Callback for drawing. Font, background and text colour have been
301 // prepared according to selection, focus and such.
302 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
303 // and there is no valid selection
304 // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
305 virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
306
307 // Callback for item height, or -1 for default
308 virtual wxCoord OnMeasureItem( size_t item ) const;
309
310 // Callback for item width, or -1 for default/undetermined
311 virtual wxCoord OnMeasureItemWidth( size_t item ) const;
312
313 // Callback for background drawing. Flags are same as with
314 // OnDrawItem.
315 virtual void OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const;
316
db53c6ea
WS
317 // NULL popup can be used to indicate default interface
318 virtual void DoSetPopupControl(wxComboPopup* popup);
319
a340b80d
VZ
320 // clears all allocated client datas
321 void ClearClientDatas();
322
57693473
VZ
323 wxVListBoxComboPopup* GetVListBoxComboPopup() const
324 {
325 return (wxVListBoxComboPopup*) m_popupInterface;
326 }
327
a340b80d
VZ
328 virtual int DoAppend(const wxString& item);
329 virtual int DoInsert(const wxString& item, unsigned int pos);
330 virtual void DoSetItemClientData(unsigned int n, void* clientData);
331 virtual void* DoGetItemClientData(unsigned int n) const;
332 virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData);
333 virtual wxClientData* DoGetItemClientObject(unsigned int n) const;
334
6d0ce565
VZ
335 // temporary storage for the initial choices
336 //const wxString* m_baseChoices;
337 //int m_baseChoicesCount;
338 wxArrayString m_initChs;
339
a340b80d
VZ
340private:
341 void Init();
342
343 DECLARE_EVENT_TABLE()
344
345 DECLARE_DYNAMIC_CLASS(wxOwnerDrawnComboBox)
346};
347
348
a57d600f 349#endif // wxUSE_ODCOMBOBOX
7ca4ac63 350
a340b80d
VZ
351#endif
352 // _WX_ODCOMBO_H_