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