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