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