1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxOwnerDrawnComboBox and wxVListBoxPopup
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_ODCOMBO_H_
13 #define _WX_ODCOMBO_H_
17 #if wxUSE_OWNERDRAWNCOMBOBOX
20 #include "wx/ctrlsub.h"
25 // New window styles for wxOwnerDrawnComboBox
29 // Double-clicking cycles item if wxCB_READONLY is also used.
30 wxODCB_DCLICK_CYCLES
= wxCC_SPECIAL_DCLICK
,
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
44 // when set, we are painting the selected item in control,
46 wxCC_PAINTING_CONTROL
= 0x0001
50 // ----------------------------------------------------------------------------
51 // wxVListBoxComboPopup is a wxVListBox customized to act as a popup control.
54 // wxOwnerDrawnComboBox uses this as its popup. However, it always derives
55 // from native wxComboControl. If you need to use this popup with
56 // wxGenericComboControl, then remember that vast majority of item manipulation
57 // functionality is implemented in the wxVListBoxComboPopup class itself.
59 // ----------------------------------------------------------------------------
62 class WXDLLEXPORT wxVListBoxComboPopup
: public wxVListBox
, public wxComboPopup
64 friend class wxOwnerDrawnComboBox
;
68 wxVListBoxComboPopup(wxComboControlBase
* combo
);
69 virtual ~wxVListBoxComboPopup();
72 virtual bool Create(wxWindow
* parent
);
73 virtual wxWindow
*GetControl() { return this; }
74 virtual void SetStringValue( const wxString
& value
);
75 virtual wxString
GetStringValue() const;
78 virtual void OnPopup();
79 virtual wxSize
GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
);
80 virtual void PaintComboControl( wxDC
& dc
, const wxRect
& rect
);
81 virtual void OnComboKeyEvent( wxKeyEvent
& event
);
82 virtual void OnComboDoubleClick();
83 virtual bool LazyCreate();
86 void SetSelection( int item
);
87 void Insert( const wxString
& item
, int pos
);
88 int Append(const wxString
& item
);
90 void Delete( unsigned int item
);
91 void SetItemClientData(unsigned int n
, void* clientData
, wxClientDataType clientDataItemsType
);
92 void *GetItemClientData(unsigned int n
) const;
93 void SetString( int item
, const wxString
& str
);
94 wxString
GetString( int item
) const;
95 unsigned int GetCount() const;
96 int FindString(const wxString
& s
) const;
98 void Populate( int n
, const wxString choices
[] );
99 void ClearClientDatas();
102 int GetItemAtPosition( const wxPoint
& pos
) { return HitTest(pos
); }
103 wxCoord
GetTotalHeight() const { return EstimateTotalHeight(); }
104 wxCoord
GetLineHeight(int line
) const { return OnGetLineHeight(line
); }
108 // Called by OnComboDoubleClick and OnComboKeyEvent
109 bool HandleKey( int keycode
, bool saturate
);
111 // sends combobox select event from the parent combo control
112 void SendComboBoxEvent();
114 // Re-calculates width for given item
115 void CheckWidth( int pos
);
117 // wxVListBox implementation
118 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
119 virtual wxCoord
OnMeasureItem(size_t n
) const;
120 void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
122 // filter mouse move events happening outside the list box
123 // move selection with cursor
124 void OnMouseMove(wxMouseEvent
& event
);
125 void OnMouseWheel(wxMouseEvent
& event
);
126 void OnKey(wxKeyEvent
& event
);
127 void OnLeftClick(wxMouseEvent
& event
);
129 wxArrayString m_strings
;
130 wxArrayPtrVoid m_clientDatas
;
131 wxArrayInt m_widths
; // cached line widths
135 int m_value
; // selection
136 int m_itemHover
; // on which item the cursor is
137 int m_widestWidth
; // width of widest item thus far
139 int m_baseImageWidth
; // how much per item drawn in addition to text
140 int m_itemHeight
; // default item height (calculate from font size
141 // and used in the absence of callback)
142 wxClientDataType m_clientDataItemsType
;
146 // has the mouse been released on this control?
149 DECLARE_EVENT_TABLE()
153 // ----------------------------------------------------------------------------
154 // wxOwnerDrawnComboBox: a generic wxComboBox that allows custom paint items
155 // in addition to many other types of customization already allowed by
156 // the wxComboControl.
157 // ----------------------------------------------------------------------------
159 class WXDLLEXPORT wxOwnerDrawnComboBox
: public wxComboControl
, public wxItemContainer
161 friend class wxComboPopupWindow
;
162 friend class wxComboControlBase
;
166 wxOwnerDrawnComboBox() : wxComboControl() { Init(); }
168 wxOwnerDrawnComboBox(wxWindow
*parent
,
170 const wxString
& value
,
174 const wxString choices
[],
176 const wxValidator
& validator
= wxDefaultValidator
,
177 const wxString
& name
= wxComboBoxNameStr
)
182 (void)Create(parent
, id
, value
, pos
, size
, n
,
183 choices
, style
, validator
, name
);
186 bool Create(wxWindow
*parent
,
188 const wxString
& value
= wxEmptyString
,
189 const wxPoint
& pos
= wxDefaultPosition
,
190 const wxSize
& size
= wxDefaultSize
,
192 const wxValidator
& validator
= wxDefaultValidator
,
193 const wxString
& name
= wxComboBoxNameStr
);
195 wxOwnerDrawnComboBox(wxWindow
*parent
,
197 const wxString
& value
,
200 const wxArrayString
& choices
,
202 const wxValidator
& validator
= wxDefaultValidator
,
203 const wxString
& name
= wxComboBoxNameStr
);
205 bool Create(wxWindow
*parent
,
207 const wxString
& value
= wxEmptyString
,
208 const wxPoint
& pos
= wxDefaultPosition
,
209 const wxSize
& size
= wxDefaultSize
,
211 const wxString choices
[] = (const wxString
*) NULL
,
213 const wxValidator
& validator
= wxDefaultValidator
,
214 const wxString
& name
= wxComboBoxNameStr
);
216 bool Create(wxWindow
*parent
,
218 const wxString
& value
,
221 const wxArrayString
& choices
,
223 const wxValidator
& validator
= wxDefaultValidator
,
224 const wxString
& name
= wxComboBoxNameStr
);
226 virtual ~wxOwnerDrawnComboBox();
228 // wxControlWithItems methods
229 virtual void Clear();
230 virtual void Delete(unsigned int n
);
231 virtual unsigned int GetCount() const;
232 virtual wxString
GetString(unsigned int n
) const;
233 virtual void SetString(unsigned int n
, const wxString
& s
);
234 virtual int FindString(const wxString
& s
) const;
235 virtual void Select(int n
);
236 virtual int GetSelection() const;
237 void SetSelection(int n
) { Select(n
); }
239 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
243 // clears all allocated client datas
244 void ClearClientDatas();
246 virtual int DoAppend(const wxString
& item
);
247 virtual int DoInsert(const wxString
& item
, unsigned int pos
);
248 virtual void DoSetItemClientData(unsigned int n
, void* clientData
);
249 virtual void* DoGetItemClientData(unsigned int n
) const;
250 virtual void DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
);
251 virtual wxClientData
* DoGetItemClientObject(unsigned int n
) const;
253 // overload m_popupInterface member so we can access specific popup interface easier
254 wxVListBoxComboPopup
* m_popupInterface
;
259 DECLARE_EVENT_TABLE()
261 DECLARE_DYNAMIC_CLASS(wxOwnerDrawnComboBox
)
265 #endif // wxUSE_OWNERDRAWNCOMBOBOX