1
///////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxPGOwnerDrawnComboBox and related classes interface
4
// Author: Jaakko Salli
6
// Created: Jan-25-2005
8
// Copyright: (c) 2005 Jaakko Salli
9
// Licence: wxWindows licence
10
///////////////////////////////////////////////////////////////////////////////
12
#ifndef _WX_ODCOMBO_H_
13
#define _WX_ODCOMBO_H_
15
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16
#pragma interface "odcombobox.h"
19
#include "wx/choice.h"
20
//#include "wx/popupwin.h"
22
// Item counts in GUI components were changed in 2.8.0
23
#if wxCHECK_VERSION(2,8,0)
24
#define wxODCCount unsigned int
25
#define wxODCIndex unsigned int
27
#define wxODCCount int
28
#define wxODCIndex int
31
class WXDLLEXPORT wxVListBox;
32
class WXDLLEXPORT wxTextCtrl;
33
class WXDLLEXPORT wxButton;
36
#ifdef WXMAKINGDLL_PROPGRID
37
#define WXDLLEXPORT_PGODC WXEXPORT
38
//#elif defined(WXUSINGDLL)
39
// #define WXDLLEXPORT_PGODC WXIMPORT
40
#else // not making nor using DLL
41
#define WXDLLEXPORT_PGODC
44
class WXDLLEXPORT_PGODC wxPGOwnerDrawnComboBox;
46
// ----------------------------------------------------------------------------
47
// wxComboPopupInterface is the interface class that lies between
48
// the wxPGOwnerDrawnComboBox and its popup window.
49
// ----------------------------------------------------------------------------
55
// when set, we are painting the selected item in control, not in the popup
56
#define wxODCB_CB_PAINTING_CONTROL 0x0001
59
typedef void (wxEvtHandler::* wxComboPaintCallback)(wxPGOwnerDrawnComboBox* pCb,
65
class WXDLLEXPORT_PGODC wxComboPopupInterface : public wxEvtHandler
67
friend class wxPGOwnerDrawnComboBox;
70
wxComboPopupInterface();
71
virtual ~wxComboPopupInterface();
73
// default implementation does nothing
76
// default implementation does nothing
77
virtual void Delete( int item );
79
// wxComboBox::FindString
80
// default implementation returns wxNOT_FOUND
81
virtual int FindString(const wxString& s) const;
83
// default implementation returns NULL
84
//virtual void* GetClientData( int item ) const;
86
// default implementation returns 0
87
virtual int GetCount() const;
89
// wxComboBox::GetString
90
// default implementation returns empty string
91
virtual wxString GetString( int item ) const;
93
// default implementation does nothing
94
virtual void Insert( const wxString& item, int pos );
96
// default implementation does nothing
97
//virtual void SetClientData( int item, void* clientData );
99
// wxComboBox::SetSelection
100
// default implementation does nothing
101
virtual void SetSelection( int item );
103
// wxComboBox::SetString
104
// default implementation does nothing
105
virtual void SetString( int item, const wxString& str );
107
// wxComboBox::SetValue
108
// default implementation does nothing
109
virtual void SetValueFromString ( const wxString& value );
111
// default implementation returns NULL
112
//virtual wxArrayString* GetArrayString();
114
// default implementation returns false
115
//virtual bool IsValueInt() const;
117
// returns TRUE if item is hilited
118
virtual bool IsHighlighted ( int item ) const;
120
// called by wxOwnerDrawComboBox after assigned to it
121
// If returns TRUE, then GeneratePopup is called immediately
122
// (instead of at the first time it is shown). Default returns
124
virtual bool Init( wxPGOwnerDrawnComboBox* combo );
126
// returns pointer to created popup control
127
// parent = wxPopupWindow where combo popup should be placed
128
// if NULL, then it is not necesary to create the popup
129
// minWidth = preferred minimum width for window
130
// maxHeight = absolute maximum height for window
131
// prefHeight = preferred height. Only applies if > 0,
132
// and should only be rounded down, if necessary.
133
// isVolatile = set to true if window should be destroyed
134
// when hidden. If not then this method is still called.
135
// In this case, the existing window, with adjusted
136
// dimensions should be returned.
137
virtual wxWindow* GeneratePopup( wxWindow* parent, int minWidth,
138
int maxHeight, int prefHeight ) = 0;
140
// Returns pointer to the current value (if integer).
141
// With the default popup, for example, this returns pointer
143
virtual const int* GetIntPtr () const;
145
// gets displayed string representation of the value
146
virtual wxString GetValueAsString() const = 0;
150
//wxPopupWindow* CreatePopupWindow () const;
152
// Event handler handles this.
153
//wxWindow* m_handledWnd;
155
//inline wxWindow* GetPopupControl() const { wxASSERT(m_popupAsWnd); return m_popupAsWnd; }
157
inline wxComboPaintCallback GetCallback() const { return m_callback; }
161
// TODO: Once popup transient window works Ok, remove these.
162
void OnMouseEvent( wxMouseEvent& event );
163
//void OnFocusChange ( wxFocusEvent& event );
165
wxPGOwnerDrawnComboBox* m_combo;
166
//wxWindow* m_popupAsWnd;
168
// Must be in all interfaces to paint the combobox too (in some cases)
169
wxComboPaintCallback m_callback;
172
DECLARE_EVENT_TABLE()
176
// ----------------------------------------------------------------------------
177
// wxPGCustomComboBox: a generic control that looks like a wxComboBox but allows
178
// completely custom popup.
181
// - It accepts wxCB_READONLY to disable the wxTextCtrl (actually the control
182
// is not created at all).
184
// ----------------------------------------------------------------------------
187
#define wxPGCustomComboBoxBase wxControl
190
class WXDLLEXPORT_PGODC wxPGCustomComboBox : public wxPGCustomComboBoxBase
194
wxPGCustomComboBox() : wxPGCustomComboBoxBase() { Init(); }
196
wxPGCustomComboBox(wxWindow *parent,
198
const wxString& value = wxEmptyString,
199
const wxPoint& pos = wxDefaultPosition,
200
const wxSize& size = wxDefaultSize,
202
const wxValidator& validator = wxDefaultValidator,
203
const wxString& name = wxComboBoxNameStr)
204
: wxPGCustomComboBoxBase()
208
(void)Create(parent, id, value, pos, size, style, validator, name);
211
bool Create(wxWindow *parent,
213
const wxString& value = wxEmptyString,
214
const wxPoint& pos = wxDefaultPosition,
215
const wxSize& size = wxDefaultSize,
217
const wxValidator& validator = wxDefaultValidator,
218
const wxString& name = wxComboBoxNameStr);
220
virtual ~wxPGCustomComboBox();
222
// get the popup window containing the popup control
223
wxWindow *GetPopupWindow() const { return m_winPopup; }
225
virtual void HidePopup( bool sendEvent );
226
void SendShowPopupSignal();
228
// common code to be called on popup hide
229
void OnPopupDismiss();
231
// return true if the popup is currently shown
232
bool IsPopupShown() const { return (m_isPopupShown > 0); }
234
// get the popup control/panel in window
235
wxWindow *GetPopupControl() const { return m_popup; }
237
// Get the text control which is part of the combobox.
238
wxTextCtrl *GetTextCtrl() const { return m_text; }
240
// get the dropdown button which is part of the combobox
241
// note: its not necessarily a wxButton or wxBitmapButton
242
wxWindow *GetButton() const { return m_btn; }
244
// forward these functions to all subcontrols
245
virtual bool Enable(bool enable = true);
246
virtual bool Show(bool show = true);
247
virtual bool SetFont(const wxFont& font);
248
//virtual void SetFocus();
249
//virtual void SetFocusFromKbd();
250
void SetId( wxWindowID winid );
252
// Return TRUE if item is hilited in the combo
253
bool IsHighlighted ( int item ) const;
256
virtual void DoSetToolTip( wxToolTip *tip );
257
#endif // wxUSE_TOOLTIPS
259
// wxTextCtrl methods
260
virtual wxString GetValue() const;
261
virtual void SetValue(const wxString& value);
264
virtual void Paste();
265
virtual void SetInsertionPoint(long pos);
266
virtual void SetInsertionPointEnd();
267
virtual long GetInsertionPoint() const;
268
virtual long GetLastPosition() const;
269
virtual void Replace(long from, long to, const wxString& value);
270
virtual void Remove(long from, long to);
271
virtual void SetSelection(long from, long to);
273
// wxPGCustomComboBox-only methods
275
// Adjust popup size.
276
// extLeft = how many pixels the popup extends to the left
277
// extRight = how many pixels the popup extends to the right
278
// prefHeight = preferred popup height
279
void SetPopupExtents( int extLeft, int extRight = 0, int prefHeight = -1 );
281
// set width of custom paint area in writable combo
282
// in read-only, used to indicate area that is not covered by the
284
void SetCustomPaintArea( int width );
286
// This is called to custom paint the control itself (ie. not the popup).
287
virtual void OnItemPaint( wxDC& dc, const wxRect& rect );
289
/*inline void PreventNextButtonPopup()
296
// override the base class virtuals involved into geometry calculations
297
virtual void DoMoveWindow(int x, int y, int width, int height);
298
virtual wxSize DoGetBestSize() const;
301
void OnMouseEvent( wxMouseEvent& event );
302
void OnPaint( wxPaintEvent& event );
303
void OnResize( wxSizeEvent& event );
304
void OnFocusEvent( wxFocusEvent& event );
306
// This is used when m_text is hidden (readonly).
307
wxString m_valueString;
309
// the text control and button we show all the time
313
// popup window containing the window managed by the interface .
314
wxWindow* m_winPopup;
316
// the popup control/panel
319
// this is for this control itself
320
wxEvtHandler* m_extraEvtHandler;
323
wxEvtHandler* m_textEvtHandler;
325
// this is for the top level window
326
wxEvtHandler* m_toplevEvtHandler;
328
wxLongLong m_timeLastMouseUp;
330
// how much popup should expand to the left/right of the control
334
// preferred popup height. default is -1.
335
wxCoord m_heightPopup;
337
// how much of writable combo is custom-paint by callback?
338
// also used to indicate area that is not covered by "blue"
339
// selection indicator.
340
wxCoord m_widthCustomPaint;
342
// FIXME: Only necessary for GTK and its kind
343
wxCoord m_widthCustomBorder;
345
// is the popup window currenty shown?
346
// < 0 is special value
349
// TODO: Remove after real popup works ok.
350
unsigned char m_fakePopupUsage;
352
unsigned char m_ignoreNextButtonClick;
354
// Set to 1 on mouse down, 0 on mouse up. Used to eliminate down-less mouse ups.
355
unsigned char m_downReceived;
360
DECLARE_EVENT_TABLE()
362
DECLARE_DYNAMIC_CLASS(wxPGCustomComboBox)
366
// ----------------------------------------------------------------------------
367
// wxPGOwnerDrawnComboBox: a generic wxComboBox that allows custom paint items
368
// and even a completely custom popup control.
369
// ----------------------------------------------------------------------------
373
// if used, control itself is not custom paint using callback
374
// even if this is not used, writable combo is never custom paint
375
// until SetCustomPaintArea is called
376
#define wxODCB_STD_CONTROL_PAINT 0x0100
378
// Causes double-clicking to cycle the item instead of showing
379
// the popup. Shift-pressed causes cycling direction to reverse.
380
#define wxODCB_DOUBLE_CLICK_CYCLES 0x0200
383
class WXDLLEXPORT_PGODC wxPGOwnerDrawnComboBox : public wxPGCustomComboBox, public wxItemContainer
385
friend class wxComboPopupWindow;
386
friend class wxPGCustomComboBox;
389
wxPGOwnerDrawnComboBox() : wxPGCustomComboBox() { Init(); }
391
wxPGOwnerDrawnComboBox(wxWindow *parent,
393
const wxString& value,
397
const wxString choices[],
398
wxComboPaintCallback callback,
400
const wxValidator& validator = wxDefaultValidator,
401
const wxString& name = wxComboBoxNameStr)
402
: wxPGCustomComboBox()
406
(void)Create(parent, id, value, pos, size, n, choices,
407
callback, style, validator, name);
410
wxPGOwnerDrawnComboBox(wxWindow *parent,
412
const wxString& value = wxEmptyString,
413
const wxPoint& pos = wxDefaultPosition,
414
const wxSize& size = wxDefaultSize,
415
wxComboPopupInterface* iface = (wxComboPopupInterface*) NULL,
417
const wxValidator& validator = wxDefaultValidator,
418
const wxString& name = wxComboBoxNameStr)
419
: wxPGCustomComboBox()
423
(void)Create(parent, id, value, pos, size, iface,
424
style, validator, name);
427
bool Create(wxWindow *parent,
429
const wxString& value = wxEmptyString,
430
const wxPoint& pos = wxDefaultPosition,
431
const wxSize& size = wxDefaultSize,
432
wxComboPopupInterface* iface = (wxComboPopupInterface*) NULL,
434
const wxValidator& validator = wxDefaultValidator,
435
const wxString& name = wxComboBoxNameStr);
437
wxPGOwnerDrawnComboBox(wxWindow *parent,
439
const wxString& value,
442
const wxArrayString& choices,
443
wxComboPaintCallback callback = (wxComboPaintCallback) NULL,
445
const wxValidator& validator = wxDefaultValidator,
446
const wxString& name = wxComboBoxNameStr);
448
bool Create(wxWindow *parent,
450
const wxString& value = wxEmptyString,
451
const wxPoint& pos = wxDefaultPosition,
452
const wxSize& size = wxDefaultSize,
454
const wxString choices[] = (const wxString *) NULL,
455
wxComboPaintCallback callback = (wxComboPaintCallback) NULL,
457
const wxValidator& validator = wxDefaultValidator,
458
const wxString& name = wxComboBoxNameStr);
460
bool Create(wxWindow *parent,
462
const wxString& value,
465
const wxArrayString& choices,
466
wxComboPaintCallback callback = (wxComboPaintCallback) NULL,
468
const wxValidator& validator = wxDefaultValidator,
469
const wxString& name = wxComboBoxNameStr);
471
virtual ~wxPGOwnerDrawnComboBox();
473
// a combo control needs a control for popup window it displays
474
//void SetPopupControl(wxComboPopup *popup);
475
wxComboPopupInterface* GetPopupInterface() const { return m_popupInterface; }
477
// show/hide popup window
479
void HidePopup( bool sendEvent = true );
481
// Return TRUE if item is hilited in the combo
482
bool IsHighlighted ( int item ) const;
484
// wxControlWithItems methods
485
virtual void Clear();
486
virtual void Delete(wxODCIndex n);
487
virtual wxODCCount GetCount() const;
488
virtual wxString GetString(wxODCIndex n) const;
489
virtual void SetString(wxODCIndex n, const wxString& s);
490
virtual int FindString(const wxString& s) const;
491
virtual void Select(int n);
492
virtual int GetSelection() const;
493
void SetSelection(int n) { Select(n); }
495
// wxPGOwnerDrawnComboBox-only methods
497
// Adjust popup size.
498
// extLeft = how many pixels the popup extends to the left
499
// extRight = how many pixels the popup extends to the right
500
// prefHeight = preferred popup height
501
//void SetPopupExtents( int extLeft, int extRight = 0, int prefHeight = -1 );
503
void SetPopupInterface( wxComboPopupInterface* iface );
505
virtual void OnItemPaint( wxDC& dc, const wxRect& rect );
507
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
509
//inline bool HasClientObjectData () const { return false; }
514
void OnButtonClick(wxCommandEvent& event);
516
// clears all allocated client datas
517
void ClearClientDatas();
519
virtual int DoAppend(const wxString& item);
520
virtual int DoInsert(const wxString& item, wxODCIndex pos);
521
virtual void DoSetItemClientData(wxODCIndex n, void* clientData);
522
virtual void* DoGetItemClientData(wxODCIndex n) const;
523
virtual void DoSetItemClientObject(wxODCIndex n, wxClientData* clientData);
524
virtual wxClientData* DoGetItemClientObject(wxODCIndex n) const;
527
wxComboPopupInterface* m_popupInterface;
529
// holder for client datas
530
wxArrayPtrVoid m_clientDatas;
532
// is the data type of interface 'int'?
538
DECLARE_EVENT_TABLE()
540
DECLARE_DYNAMIC_CLASS(wxPGOwnerDrawnComboBox)
543
#endif // _WX_ODCOMBO_H_