]> git.saurik.com Git - wxWidgets.git/blame - include/wx/odcombo.h
fix the tests to pass with both gcc and msvc (2nd part of patch 1462778)
[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//
40// Callback flags
41//
42enum
43{
44 // when set, we are painting the selected item in control,
45 // not in the popup
6d0ce565 46 wxCP_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
6d0ce565
VZ
87 // Callbacks for drawing and measuring items. Override in a derived class for
88 // owner-drawnness.
89 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
90 // and there is no valid selection
91 // flags: wxCP_PAINTING_CONTROL is set if painting to combo control instead of list
92 virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
93
6d0ce565
VZ
94 // Return item width, or -1 for calculating from text extent (default)
95 virtual wxCoord OnMeasureItemWidth( size_t item ) const;
96
97
a340b80d
VZ
98 // Item management
99 void SetSelection( int item );
100 void Insert( const wxString& item, int pos );
101 int Append(const wxString& item);
102 void Clear();
103 void Delete( unsigned int item );
104 void SetItemClientData(unsigned int n, void* clientData, wxClientDataType clientDataItemsType);
105 void *GetItemClientData(unsigned int n) const;
106 void SetString( int item, const wxString& str );
107 wxString GetString( int item ) const;
108 unsigned int GetCount() const;
9e6aca68 109 int FindString(const wxString& s, bool bCase = false) const;
6d0ce565 110 int GetSelection() const;
a340b80d 111
6d0ce565
VZ
112 //void Populate( int n, const wxString choices[] );
113 void Populate( const wxArrayString& choices );
a340b80d
VZ
114 void ClearClientDatas();
115
116 // helpers
117 int GetItemAtPosition( const wxPoint& pos ) { return HitTest(pos); }
118 wxCoord GetTotalHeight() const { return EstimateTotalHeight(); }
119 wxCoord GetLineHeight(int line) const { return OnGetLineHeight(line); }
120
121protected:
122
123 // Called by OnComboDoubleClick and OnComboKeyEvent
124 bool HandleKey( int keycode, bool saturate );
125
126 // sends combobox select event from the parent combo control
6d0ce565 127 void SendComboBoxEvent( int selection );
7ca4ac63 128
6d0ce565
VZ
129 // gets value, sends event and dismisses
130 void DismissWithEvent();
a340b80d
VZ
131
132 // Re-calculates width for given item
133 void CheckWidth( int pos );
134
135 // wxVListBox implementation
136 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
6d0ce565 137 //virtual wxCoord OnMeasureItem(size_t n) const;
a340b80d
VZ
138 void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
139
dcc8cf5a
PC
140 // Return item height
141 virtual wxCoord OnMeasureItem( size_t item ) const;
142
a340b80d
VZ
143 // filter mouse move events happening outside the list box
144 // move selection with cursor
145 void OnMouseMove(wxMouseEvent& event);
146 void OnMouseWheel(wxMouseEvent& event);
147 void OnKey(wxKeyEvent& event);
148 void OnLeftClick(wxMouseEvent& event);
149
150 wxArrayString m_strings;
151 wxArrayPtrVoid m_clientDatas;
152 wxArrayInt m_widths; // cached line widths
153
6d0ce565 154 wxFont m_useFont;
a340b80d 155
6d0ce565 156 //wxString m_stringValue; // displayed text (may be different than m_strings[m_value])
a340b80d
VZ
157 int m_value; // selection
158 int m_itemHover; // on which item the cursor is
159 int m_widestWidth; // width of widest item thus far
160 int m_avgCharWidth;
161 int m_baseImageWidth; // how much per item drawn in addition to text
162 int m_itemHeight; // default item height (calculate from font size
163 // and used in the absence of callback)
164 wxClientDataType m_clientDataItemsType;
165
166private:
167
168 // has the mouse been released on this control?
169 bool m_clicked;
170
171 DECLARE_EVENT_TABLE()
172};
173
174
175// ----------------------------------------------------------------------------
176// wxOwnerDrawnComboBox: a generic wxComboBox that allows custom paint items
177// in addition to many other types of customization already allowed by
a57d600f 178// the wxComboCtrl.
a340b80d
VZ
179// ----------------------------------------------------------------------------
180
a57d600f 181class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : public wxComboCtrl,
c98e80d9 182 public wxItemContainer
a340b80d
VZ
183{
184 friend class wxComboPopupWindow;
a57d600f 185 friend class wxComboCtrlBase;
a340b80d
VZ
186public:
187
188 // ctors and such
a57d600f 189 wxOwnerDrawnComboBox() : wxComboCtrl() { Init(); }
a340b80d
VZ
190
191 wxOwnerDrawnComboBox(wxWindow *parent,
192 wxWindowID id,
193 const wxString& value,
194 const wxPoint& pos,
195 const wxSize& size,
196 int n,
197 const wxString choices[],
198 long style = 0,
199 const wxValidator& validator = wxDefaultValidator,
200 const wxString& name = wxComboBoxNameStr)
a57d600f 201 : wxComboCtrl()
a340b80d
VZ
202 {
203 Init();
204
205 (void)Create(parent, id, value, pos, size, n,
206 choices, style, validator, name);
207 }
208
209 bool Create(wxWindow *parent,
210 wxWindowID id,
1c4743aa 211 const wxString& value = wxEmptyString,
a340b80d
VZ
212 const wxPoint& pos = wxDefaultPosition,
213 const wxSize& size = wxDefaultSize,
214 long style = 0,
215 const wxValidator& validator = wxDefaultValidator,
216 const wxString& name = wxComboBoxNameStr);
217
218 wxOwnerDrawnComboBox(wxWindow *parent,
219 wxWindowID id,
220 const wxString& value,
221 const wxPoint& pos,
222 const wxSize& size,
223 const wxArrayString& choices,
7ca4ac63 224 long style,
a340b80d
VZ
225 const wxValidator& validator = wxDefaultValidator,
226 const wxString& name = wxComboBoxNameStr);
227
228 bool Create(wxWindow *parent,
229 wxWindowID id,
1c4743aa
WS
230 const wxString& value,
231 const wxPoint& pos,
232 const wxSize& size,
233 int n,
234 const wxString choices[],
a340b80d
VZ
235 long style = 0,
236 const wxValidator& validator = wxDefaultValidator,
237 const wxString& name = wxComboBoxNameStr);
238
239 bool Create(wxWindow *parent,
240 wxWindowID id,
241 const wxString& value,
242 const wxPoint& pos,
243 const wxSize& size,
244 const wxArrayString& choices,
245 long style = 0,
246 const wxValidator& validator = wxDefaultValidator,
247 const wxString& name = wxComboBoxNameStr);
248
249 virtual ~wxOwnerDrawnComboBox();
250
6d0ce565
VZ
251 // NULL popup can be used to indicate default interface
252 virtual void SetPopupControl( wxComboPopup* popup );
253
a340b80d
VZ
254 // wxControlWithItems methods
255 virtual void Clear();
256 virtual void Delete(unsigned int n);
257 virtual unsigned int GetCount() const;
258 virtual wxString GetString(unsigned int n) const;
259 virtual void SetString(unsigned int n, const wxString& s);
9e6aca68 260 virtual int FindString(const wxString& s, bool bCase = false) const;
a340b80d
VZ
261 virtual void Select(int n);
262 virtual int GetSelection() const;
c0f48280 263 virtual void SetSelection(int n) { Select(n); }
a340b80d 264
7ca4ac63
WS
265
266 // Prevent a method from being hidden
267 virtual void SetSelection(long from, long to)
268 {
269 wxComboCtrl::SetSelection(from,to);
270 }
271
a340b80d
VZ
272 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
273
274protected:
275
276 // clears all allocated client datas
277 void ClearClientDatas();
278
279 virtual int DoAppend(const wxString& item);
280 virtual int DoInsert(const wxString& item, unsigned int pos);
281 virtual void DoSetItemClientData(unsigned int n, void* clientData);
282 virtual void* DoGetItemClientData(unsigned int n) const;
283 virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData);
284 virtual wxClientData* DoGetItemClientObject(unsigned int n) const;
285
286 // overload m_popupInterface member so we can access specific popup interface easier
287 wxVListBoxComboPopup* m_popupInterface;
288
6d0ce565
VZ
289 // temporary storage for the initial choices
290 //const wxString* m_baseChoices;
291 //int m_baseChoicesCount;
292 wxArrayString m_initChs;
293
a340b80d
VZ
294private:
295 void Init();
296
297 DECLARE_EVENT_TABLE()
298
299 DECLARE_DYNAMIC_CLASS(wxOwnerDrawnComboBox)
300};
301
302
a57d600f 303#endif // wxUSE_ODCOMBOBOX
7ca4ac63 304
a340b80d
VZ
305#endif
306 // _WX_ODCOMBO_H_