1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: SWIG interface for the owner-drawn combobox classes
7
// Created: 11-Nov-2006
8
// RCS-ID: $Id: combo.i 68064 2011-06-27 21:31:30Z RD $
9
// Copyright: (c) 2006 by Total Control Software
10
// Licence: wxWindows license
11
/////////////////////////////////////////////////////////////////////////////
14
"ComboCtrl class that can have any type of popup widget, and also an
15
owner-drawn combobox control."
18
%module(package="wx", docstring=DOCSTRING) combo
21
#include "wx/wxPython/wxPython.h"
22
#include "wx/wxPython/pyclasses.h"
24
#include "wx/wxPython/pytree.h"
25
typedef wxTreeCtrl wxPyTreeCtrl;
28
#include <wx/odcombo.h>
31
//---------------------------------------------------------------------------
35
%pythoncode { wx = _core }
36
%pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
38
//---------------------------------------------------------------------------
41
MAKE_CONST_WXSTRING_NOSWIG(ComboBoxNameStr);
42
MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
45
const wxArrayString wxPyEmptyStringArray;
50
// Button is preferred outside the border (GTK style)
51
wxCC_BUTTON_OUTSIDE_BORDER = 0x0001,
52
// Show popup on mouse up instead of mouse down (which is the Windows style)
53
wxCC_POPUP_ON_MOUSE_UP = 0x0002,
54
// All text is not automatically selected on click
55
wxCC_NO_TEXT_AUTO_SELECT = 0x0004,
56
// Drop-button stays down as long as popup is displayed.
57
wxCC_BUTTON_STAYS_DOWN = 0x0008,
58
// Drop-button covers the entire control.
59
wxCC_FULL_BUTTON = 0x0010,
60
// Drop-button goes over the custom-border (used under WinVista).
61
wxCC_BUTTON_COVERS_BORDER = 0x0020,
66
// Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
69
wxCC_MF_ON_BUTTON = 0x0001, // cursor is on dropbutton area
70
wxCC_MF_ON_CLICK_AREA = 0x0002 // cursor is on dropbutton or other area
71
// that can be clicked to show the popup.
75
DocStr( wxComboCtrlFeatures,
76
"Namespace for `wx.combo.ComboCtrl` feature flags. See
77
`wx.combo.ComboCtrl.GetFeatures`.", "");
78
struct wxComboCtrlFeatures
82
MovableButton = 0x0001, // Button can be on either side of control
83
BitmapButton = 0x0002, // Button may be replaced with bitmap
84
ButtonSpacing = 0x0004, // Button can have spacing from the edge
86
TextIndent = 0x0008, // SetTextIndent can be used
87
PaintControl = 0x0010, // Combo control itself can be custom painted
88
PaintWritable = 0x0020, // A variable-width area in front of writable
89
// combo control's textctrl can be custom
91
Borderless = 0x0040, // wxNO_BORDER window style works
93
// There are no feature flags for...
94
// PushButtonBitmapBackground - if its in wxRendererNative, then it should be
95
// not an issue to have it automatically under the bitmap.
97
All = MovableButton|BitmapButton|
98
ButtonSpacing|TextIndent|
99
PaintControl|PaintWritable|
104
//---------------------------------------------------------------------------
106
// C++ implemetation of Python aware wxComboCtrl
108
class wxPyComboCtrl : public wxComboCtrl
110
DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
112
wxPyComboCtrl() : wxComboCtrl() {}
113
wxPyComboCtrl(wxWindow *parent,
114
wxWindowID id = wxID_ANY,
115
const wxString& value = wxEmptyString,
116
const wxPoint& pos = wxDefaultPosition,
117
const wxSize& size = wxDefaultSize,
119
const wxValidator& validator = wxDefaultValidator,
120
const wxString& name = wxPyComboBoxNameStr)
121
: wxComboCtrl(parent, id, value, pos, size, style, validator, name)
124
void DoSetPopupControl(wxComboPopup* popup)
127
wxPyBlock_t blocked = wxPyBeginBlockThreads();
128
if ((found = wxPyCBH_findCallback(m_myInst, "DoSetPopupControl"))) {
129
PyObject* obj = wxPyConstructObject(popup, wxT("wxComboPopup"), false);
130
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)",obj));
133
wxPyEndBlockThreads(blocked);
135
wxComboCtrl::DoSetPopupControl(popup);
138
virtual bool IsKeyPopupToggle( const wxKeyEvent& event ) const
142
wxPyBlock_t blocked = wxPyBeginBlockThreads();
143
if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
144
PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
145
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
148
wxPyEndBlockThreads(blocked);
150
rval = wxComboCtrl::IsKeyPopupToggle(event);
155
virtual wxWindow *GetMainWindowOfCompositeControl()
157
return wxComboCtrl::GetMainWindowOfCompositeControl();
162
wxComboCtrlBase::DestroyPopup();
168
ShowBelow = 0x0000, // Showing popup below the control
169
ShowAbove = 0x0001, // Showing popup above the control
170
CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
174
DEC_PYCALLBACK_VOID_(ShowPopup);
175
DEC_PYCALLBACK_VOID_(HidePopup);
176
DEC_PYCALLBACK_VOID_(OnButtonClick);
177
DEC_PYCALLBACK__RECTINT(DoShowPopup);
178
DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
183
IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
185
IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
186
IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
187
IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
188
IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
189
IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
195
// Now declare wxPyComboCtrl for Python
197
DocStr(wxPyComboCtrl,
198
"A combo control is a generic combobox that allows for a totally custom
199
popup. In addition it has other customization features. For instance,
200
position and size of the dropdown button can be changed.
202
To specify what to use for the popup control you need to derive a
203
class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
204
`SetPopupControl`. It doesn't derive from any widget class so it can
205
be used either as a mixin class combined with some standard or custom
206
widget, or you can use the derived ComboPopup to create and hold an
207
independent reference to the widget to be used for the popup.
212
==================== ============================================
213
wx.CB_READONLY Text will not be editable.
214
wx.CB_SORT Sorts the entries in the list alphabetically.
215
wx.TE_PROCESS_ENTER The control will generate the event
216
EVT_TEXT_ENTER (otherwise pressing Enter key
217
is either processed internally by the control
218
or used for navigation between dialog controls).
219
wx.CC_SPECIAL_DCLICK Double-clicking triggers a call to popup's
220
OnComboDoubleClick. Actual behaviour is defined
221
by a derived class. For instance,
222
OwnerDrawnComboBox will cycle an item. This
223
style only applies if wx.CB_READONLY is used
225
wx.CC_STD_BUTTON Drop button will behave more like a standard
227
==================== ============================================
230
MustHaveApp(wxPyComboCtrl);
231
%rename(ComboCtrl) wxPyComboCtrl;
233
class wxPyComboCtrl : public wxControl, public wxTextEntry
236
%pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
237
%pythonAppend wxPyComboCtrl() "";
240
wxPyComboCtrl(wxWindow *parent,
241
wxWindowID id = wxID_ANY,
242
const wxString& value = wxEmptyString,
243
const wxPoint& pos = wxDefaultPosition,
244
const wxSize& size = wxDefaultSize,
246
const wxValidator& validator = wxDefaultValidator,
247
const wxString& name = wxPyComboBoxNameStr),
256
void _setCallbackInfo(PyObject* self, PyObject* _class);
259
virtual void Popup();
260
virtual void Dismiss();
263
virtual void , ShowPopup(),
264
"Show the popup window.", "");
267
virtual void , HidePopup(),
268
"Dismisses the popup window.", "");
271
// Override for totally custom combo action
273
virtual void , OnButtonClick(),
274
"Implement in a derived class to define what happens on dropdown button
275
click. Default action is to show the popup. ", "");
278
// return true if the popup is currently shown
280
bool , IsPopupShown() const,
281
"Returns true if the popup is currently shown.", "");
284
%disownarg(wxPyComboPopup* popup);
286
void , SetPopupControl( wxPyComboPopup* popup ),
287
"Set popup interface class derived from `wx.combo.ComboPopup`. This
288
method should be called as soon as possible after the control has been
289
created, unless `OnButtonClick` has been overridden.", "");
290
%cleardisown(wxPyComboPopup* popup);
294
wxPyComboPopup* , GetPopupControl(),
295
"Returns the current popup interface that has been set with
296
`SetPopupControl`.", "");
300
wxWindow *, GetPopupWindow() const,
301
"Returns the popup window containing the popup control.", "");
305
wxTextCtrl *, GetTextCtrl() const,
306
"Get the text control which is part of the combo control.", "");
310
wxWindow *, GetButton() const,
311
"Get the dropdown button which is part of the combobox. Note: it's not
312
necessarily a wx.Button or wx.BitmapButton.", "");
315
// NOTE: These are virtuals defined in a base class, so there
316
// shouldn't be any reason to provide SWIG wrappers for them...
317
// // forward these methods to all subcontrols
318
// virtual bool Enable(bool enable = true);
319
// virtual bool Show(bool show = true);
320
// virtual bool SetFont(const wxFont& font);
321
// virtual void SetValidator(const wxValidator &validator);
322
// virtual wxValidator *GetValidator();
325
// wxTextCtrl methods - for readonly combo they should return
328
// Hint functions mirrored from TextEntryBase
329
virtual bool SetHint(const wxString& hint);
330
virtual wxString GetHint() const;
332
// Margins functions mirrored from TextEntryBase
333
// (wxComboCtrl does not inherit from wxTextEntry, but may embed a
334
// wxTextCtrl, so we need these). Also note that these functions
335
// have replaced SetTextIndent() in wxWidgets 2.9.1 and later.
336
bool SetMargins(const wxPoint& pt);
337
bool SetMargins(wxCoord left, wxCoord top = -1);
338
wxPoint GetMargins() const;
341
void , SetTextCtrlStyle( int style ),
342
"Set a custom window style for the embedded wxTextCtrl. Usually you
343
will need to use this during two-step creation, just before Create().
346
class MyComboCtrl(wx.combo.ComboCtrl):
347
def __init__(self, *args, **kwargs):
348
pre = wx.combo.PreComboCtrl()
349
# Let's make the text right-aligned
350
pre.SetTextCtrlStyle(wx.TE_RIGHT)
351
pre.Create(*args, **kwargs);
356
virtual wxString , GetValue() const,
357
"Returns text representation of the current value. For writable combo
358
control it always returns the value in the text field.", "");
361
virtual void , SetValue(const wxString& value),
362
"Sets the text for the combo control text field. For a combo control
363
with wx.CB_READONLY style the string must be accepted by the popup (for
364
instance, exist in the dropdown list), otherwise the call to
365
SetValue is ignored.", "");
367
virtual void ChangeValue(const wxString& value);
368
virtual void WriteText(const wxString& text);
369
virtual void AppendText(const wxString& text);
370
virtual wxString GetRange(long from, long to) const;
374
virtual void Paste();
375
virtual void SetInsertionPoint(long pos);
376
virtual void SetInsertionPointEnd();
377
virtual long GetInsertionPoint() const;
378
virtual long GetLastPosition() const;
379
virtual void Replace(long from, long to, const wxString& value);
380
virtual void Remove(long from, long to);
383
virtual bool CanUndo() const;
384
virtual bool CanRedo() const;
386
virtual void GetSelection(long *OUTPUT, long *OUTPUT) const;
388
virtual bool IsEditable() const;
389
virtual void SetEditable(bool editable);
391
virtual bool SetHint(const wxString& hint);
392
virtual wxString GetHint() const;
394
%Rename(SetMark, void , SetSelection(long from, long to));
398
void , SetText(const wxString& value),
399
"Sets the text for the text field without affecting the popup. Thus,
400
unlike `SetValue`, it works equally well with combo control using
401
wx.CB_READONLY style.", "");
405
void , SetValueWithEvent(const wxString& value, bool withEvent = true),
406
"Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
408
void SetValueByUser(const wxString& value);
411
// Popup customization methods
415
void , SetPopupMinWidth( int width ),
416
"Sets minimum width of the popup. If wider than combo control, it will
417
extend to the left. A value of -1 indicates to use the default. The
418
popup implementation may choose to ignore this.", "");
422
void , SetPopupMaxHeight( int height ),
423
"Sets preferred maximum height of the popup. A value of -1 indicates to
424
use the default. The popup implementation may choose to ignore this.", "");
428
void , SetPopupExtents( int extLeft, int extRight ),
429
"Extends popup size horizontally, relative to the edges of the combo
430
control. Values are given in pixels, and the defaults are zero. It
431
is up to the popup to fully take these values into account.", "");
435
void , SetCustomPaintWidth( int width ),
436
"Set width, in pixels, of custom painted area in control without
437
wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
438
to indicate the area that is not covered by the focus rectangle.", "");
440
int GetCustomPaintWidth() const;
444
void , SetPopupAnchor( int anchorSide ),
445
"Set side of the control to which the popup will align itself. Valid
446
values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
447
most appropriate side is used (which, currently, is always wx.LEFT).", "");
451
void , SetButtonPosition( int width = -1,
455
"Set the position of the dropdown button.", "");
459
wxSize , GetButtonSize(),
460
"Returns current size of the dropdown button.", "");
464
void , SetButtonBitmaps( const wxBitmap& bmpNormal,
465
bool pushButtonBg = false,
466
const wxBitmap& bmpPressed = wxNullBitmap,
467
const wxBitmap& bmpHover = wxNullBitmap,
468
const wxBitmap& bmpDisabled = wxNullBitmap ),
469
"Sets custom dropdown button graphics.
471
:param bmpNormal: Default button image
472
:param pushButtonBg: If ``True``, blank push button background is painted below the image.
473
:param bmpPressed: Depressed button image.
474
:param bmpHover: Button image to use when the mouse hovers over it.
475
:param bmpDisabled: Disabled button image.
480
void , SetTextIndent( int indent ),
481
"This will set the space in pixels between left edge of the control and
482
the text, regardless whether control is read-only or not. A value of -1 can
483
be given to indicate platform default.", "");
487
wxCoord , GetTextIndent() const,
488
"Returns actual indentation in pixels.", "");
492
const wxRect& , GetTextRect() const,
493
"Returns area covered by the text field (includes everything except
494
borders and the dropdown button).", "");
498
void , UseAltPopupWindow( bool enable = true ),
499
"Enable or disable usage of an alternative popup window, which
500
guarantees ability to focus the popup control, and allows common
501
native controls to function normally. This alternative popup window is
502
usually a wxDialog, and as such, when it is shown, its parent
503
top-level window will appear as if the focus has been lost from it.", "");
507
void , EnablePopupAnimation( bool enable = true ),
508
"Enables or disables popup animation, if any, depending on the value of
513
// Utilies needed by the popups or native implementations
517
virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
518
"Returns true if given key combination should toggle the popup.", "");
522
virtual void , PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const,
523
"Prepare background of combo control or an item in a dropdown list in a
524
way typical on platform. This includes painting the focus/disabled
525
background and setting the clipping region. Unless you plan to paint
526
your own focus indicator, you should always call this in your
527
wxComboPopup::PaintComboControl implementation. In addition, it sets
528
pen and text colour to what looks good and proper against the
531
flags are the same as wx.RendererNative flags:
533
====================== ============================================
534
wx.CONTROL_ISSUBMENU drawing a list item instead of combo control
535
wx.CONTROL_SELECTED list item is selected
536
wx.CONTROL_DISABLED control/item is disabled
537
====================== ============================================
543
bool , ShouldDrawFocus() const,
544
"Returns true if focus indicator should be drawn in the control.", "");
547
const wxBitmap& GetBitmapNormal() const;
548
const wxBitmap& GetBitmapPressed() const;
549
const wxBitmap& GetBitmapHover() const;
550
const wxBitmap& GetBitmapDisabled() const;
552
wxUint32 GetInternalFlags() const;
555
bool , IsCreated() const,
556
"Return true if Create has finished", "");
560
void , OnPopupDismiss(bool generateEvent),
561
"Common code to be called on popup hide/dismiss", "");
573
bool IsPopupWindowState( int state ) const;
575
int GetPopupWindowState() const;
577
// Set value returned by GetMainWindowOfCompositeControl
578
void SetCtrlMainWnd( wxWindow* wnd );
579
virtual wxWindow *GetMainWindowOfCompositeControl();
583
static int , GetFeatures(),
584
"Returns a bit-list of flags indicating which features of the ComboCtrl
585
functionality are implemented by this implemetation. See
586
`wx.combo.ComboCtrlFeatures`.", "");
590
// Flags for DoShowPopup and AnimateShow
593
ShowBelow = 0x0000, // Showing popup below the control
594
ShowAbove = 0x0001, // Showing popup above the control
595
CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
598
// Shows and positions the popup.
600
virtual void , DoShowPopup( const wxRect& rect, int flags ),
601
"Shows and positions the popup.
604
============ =====================================================
605
ShowBelow Showing popup below the control
606
ShowAbove Showing popup above the control
607
CanDeferShow Can only return true from AnimateShow if this is set
608
============ =====================================================
614
virtual bool , AnimateShow( const wxRect& rect, int flags ),
615
"Implement in derived class to create a drop-down animation. Return
616
``True`` if finished immediately. Otherwise the popup is only shown when the
617
derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
621
%property(PopupControl, GetPopupControl, SetPopupControl);
622
%property(PopupWindow, GetPopupWindow);
623
%property(TextCtrl, GetTextCtrl);
624
%property(Button, GetButton);
625
// %property(InsertionPoint, GetInsertionPoint);
626
%property(CustomPaintWidth, GetCustomPaintWidth, SetCustomPaintWidth);
627
%property(ButtonSize, GetButtonSize);
628
%property(TextIndent, GetTextIndent, SetTextIndent);
629
%property(TextRect, GetTextRect);
630
%property(BitmapNormal, GetBitmapNormal);
631
%property(BitmapPressed, GetBitmapPressed);
632
%property(BitmapHover, GetBitmapHover);
633
%property(BitmapDisabled, GetBitmapDisabled);
634
%property(PopupWindowState, GetPopupWindowState);
638
//---------------------------------------------------------------------------
642
// C++ implemetation of Python aware wxComboPopup
644
class wxPyComboPopup : public wxComboPopup
647
wxPyComboPopup() : wxComboPopup() {}
651
DEC_PYCALLBACK_VOID_(Init);
652
DEC_PYCALLBACK_BOOL_WXWIN_pure(Create);
653
DEC_PYCALLBACK_VOID_(OnPopup);
654
DEC_PYCALLBACK_VOID_(OnDismiss);
655
DEC_PYCALLBACK__STRING(SetStringValue);
656
DEC_PYCALLBACK_STRING__constpure(GetStringValue);
657
DEC_PYCALLBACK_VOID_(OnComboDoubleClick);
658
DEC_PYCALLBACK_BOOL_(LazyCreate);
660
virtual wxWindow *GetControl()
662
wxWindow* rval = NULL;
663
const char* errmsg = "GetControl should return an object derived from wx.Window.";
664
wxPyBlock_t blocked = wxPyBeginBlockThreads();
665
if (wxPyCBH_findCallback(m_myInst, "GetControl")) {
667
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
669
if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
670
PyErr_SetString(PyExc_TypeError, errmsg);
675
PyErr_SetString(PyExc_TypeError, errmsg);
676
wxPyEndBlockThreads(blocked);
681
virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
684
wxPyBlock_t blocked = wxPyBeginBlockThreads();
685
if ((found = wxPyCBH_findCallback(m_myInst, "PaintComboControl"))) {
686
PyObject* odc = wxPyMake_wxObject(&dc,false);
687
PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
688
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
692
wxPyEndBlockThreads(blocked);
694
wxComboPopup::PaintComboControl(dc, rect);
698
virtual void OnComboKeyEvent( wxKeyEvent& event )
701
wxPyBlock_t blocked = wxPyBeginBlockThreads();
702
if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
703
PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
704
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
707
wxPyEndBlockThreads(blocked);
709
wxComboPopup::OnComboKeyEvent(event);
713
virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
715
const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
718
wxSize* rptr = &rval;
719
wxPyBlock_t blocked = wxPyBeginBlockThreads();
720
if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
722
ro = wxPyCBH_callCallbackObj(
723
m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
725
if (! wxSize_helper(ro, &rptr))
726
PyErr_SetString(PyExc_TypeError, errmsg);
732
wxPyEndBlockThreads(blocked);
734
rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
738
wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
744
IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
745
IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
746
IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
747
IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
748
IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
749
IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
750
IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
751
IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
757
// Now declare wxPyComboPopup for Python
758
DocStr(wxPyComboPopup,
759
"In order to use a custom popup with `wx.combo.ComboCtrl` an interface
760
class derived from wx.combo.ComboPopup is used to manage the interface
761
between the popup control and the popup. You can either derive a new
762
class from both the widget class and this ComboPopup class, or the
763
derived class can have a reference to the widget used for the popup.
764
In either case you simply need to return the widget from the
765
`GetControl` method to allow the ComboCtrl to interact with it.
767
Nearly all of the methods of this class are overridable in Python.", "");
770
MustHaveApp(wxPyComboPopup);
771
%rename(ComboPopup) wxPyComboPopup;
772
%typemap(out) wxPyComboCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); }
777
%pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
788
void _setCallbackInfo(PyObject* self, PyObject* _class);
791
virtual void , Init(),
792
"This method is called after the popup is contructed and has been
793
assigned to the ComboCtrl. Derived classes can override this to do
794
extra inialization or whatever.", "");
797
// Create the popup child control.
798
// Return true for success.
800
virtual bool , Create(wxWindow* parent),
801
"The derived class must implement this method to create the popup
802
control. It should be a child of the ``parent`` passed in, but other
803
than that there is much flexibility in what the widget can be, its
804
style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
805
this return value is not currently checked...)", "");
808
// Calls Destroy() for the popup control (i.e. one returned by
809
// GetControl()) and makes sure that 'this' is deleted at the end.
810
// Default implementation works for both cases where popup control
811
// class is multiple inherited or created on heap as a separate
813
virtual void DestroyPopup();
816
virtual wxWindow *, GetControl(),
817
"The derived class must implement this method and it should return a
818
reference to the widget created in the `Create` method. If the
819
derived class inherits from both the widget class and ComboPopup then
820
the return value is probably just ``self``.", "");
824
virtual void , OnPopup(),
825
"The derived class may implement this to do special processing when
826
popup is shown.", "");
830
virtual void , OnDismiss(),
831
"The derived class may implement this to do special processing when
832
popup is hidden.", "");
836
virtual void , SetStringValue( const wxString& value ),
837
"Called just prior to displaying the popup. The derived class can
838
implement this to \"select\" the item in the popup that coresponds to
839
the passed in string value, if appropriate. The default
840
implementation does nothing.", "");
844
virtual wxString , GetStringValue() const,
845
"Gets the string representation of the currently selected value to be
846
used to display in the combo widget.", "");
850
virtual void , PaintComboControl( wxDC& dc, const wxRect& rect ),
851
"This is called to custom paint in the combo control itself (ie. not
852
the popup). Default implementation draws the current value as string.", "");
856
virtual void , OnComboKeyEvent( wxKeyEvent& event ),
857
"Receives key events from the parent ComboCtrl. Events not handled
858
should be skipped, as usual.", "");
862
virtual void , OnComboDoubleClick(),
863
"Implement this method in the derived class if you need to support
864
special actions when the user double-clicks on the parent ComboCtrl.", "");
868
virtual wxSize , GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ),
869
"The derived class may implement this method to return adjusted size
870
for the popup control, according to the variables given. It is called
871
on every popup, just prior to `OnPopup`.
873
:param minWidth: Preferred minimum width.
874
:param prefHeight: Preferred height. May be -1 to indicate no preference.
875
:maxWidth: Max height for window, as limited by screen size, and
876
should only be rounded down, if necessary.
881
virtual bool , LazyCreate(),
882
"The derived class may implement this to return ``True`` if it wants to
883
delay the call to `Create` until the popup is shown for the first
884
time. It is more efficient, but on the other hand it is often more
885
convenient to have the control created immediately. The default
886
implementation returns ``False``.", "");
896
"Hides the popup", "");
900
bool , IsCreated() const,
901
"Returns true if `Create` has been called.", "");
905
wxComboCtrl* , GetComboCtrl() const,
906
"Returns the associated parent ComboCtrl.", "");
910
static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
912
const wxRect& rect ),
913
"Default PaintComboControl behaviour", "");
917
wxPyComboCtrl* , GetCombo(),
918
"Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
919
is associated with.", "");
924
//---------------------------------------------------------------------------
929
wxODCB_DCLICK_CYCLES,
930
wxODCB_STD_CONTROL_PAINT,
931
wxODCB_PAINTING_CONTROL,
932
wxODCB_PAINTING_SELECTED
937
// C++ implemetation of Python aware wxOwnerDrawnComboBox
939
class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
942
wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
943
wxPyOwnerDrawnComboBox(wxWindow *parent,
945
const wxString& value,
948
const wxArrayString& choices,
950
const wxValidator& validator = wxDefaultValidator,
951
const wxString& name = wxPyComboBoxNameStr)
952
: wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
956
DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawItem);
957
DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItem);
958
DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItemWidth);
959
DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawBackground);
965
IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
966
IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
967
IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
968
IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
974
// Now declare wxPyOwnerDrawnComboBox for Python
976
DocStr(wxPyOwnerDrawnComboBox,
977
"wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
978
items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
979
popup and a `wx.ControlWithItems` API.
981
Implementing item drawing and measuring is similar to wx.VListBox.
982
The application needs to subclass wx.combo.OwnerDrawnComboBox and
983
implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
986
MustHaveApp(wxPyOwnerDrawnComboBox);
987
%rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
989
class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
990
public wxItemContainer
993
%pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
994
%pythonAppend wxPyOwnerDrawnComboBox() "";
997
wxPyOwnerDrawnComboBox(wxWindow *parent,
999
const wxString& value = wxPyEmptyString,
1000
const wxPoint& pos = wxDefaultPosition,
1001
const wxSize& size = wxDefaultSize,
1002
const wxArrayString& choices = wxPyEmptyStringArray,
1004
const wxValidator& validator = wxDefaultValidator,
1005
const wxString& name = wxPyComboBoxNameStr),
1006
"Standard constructor.", "");
1008
DocCtorStrName(wxPyOwnerDrawnComboBox(),
1009
"2-phase create constructor.", "",
1010
PreOwnerDrawnComboBox);
1012
void _setCallbackInfo(PyObject* self, PyObject* _class);
1016
bool , Create(wxWindow *parent,
1018
const wxString& value = wxPyEmptyString,
1019
const wxPoint& pos = wxDefaultPosition,
1020
const wxSize& size = wxDefaultSize,
1021
const wxArrayString& choices = wxPyEmptyStringArray,
1023
const wxValidator& validator = wxDefaultValidator,
1024
const wxString& name = wxPyComboBoxNameStr),
1025
"Create the UI object, and other initialization.", "");
1029
virtual int , GetWidestItemWidth(),
1030
"Return the widest item width (recalculating it if necessary.)", "");
1034
virtual int , GetWidestItem(),
1035
"Return the index of the widest item (recalculating it if necessary.)", "");
1038
void SetSelection(int n);
1039
%Rename(SetMark, void , SetSelection(long from, long to));
1041
// Implemented in wxItemContainer, but hidden in wxPyComboCtrl, so list
1042
// it explicitly here.
1043
%pythoncode { GetString = wx.ItemContainer.GetString }
1046
// Callback for drawing. Font, background and text colour have been
1047
// prepared according to selection, focus and such.
1048
// item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
1049
// and there is no valid selection
1050
// flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
1052
virtual void , OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const,
1053
"The derived class may implement this function to actually draw the
1054
item with the given index on the provided DC. If this method is not
1055
overridden, the item text is simply drawn as if the control was a
1058
:param dc: The device context to use for drawing.
1059
:param rect: The bounding rectangle for the item being drawn, the
1060
DC's clipping region is set to this rectangle before
1061
calling this method.
1062
:param item: The index of the item to be drawn.
1064
:param flags: ``wx.combo.ODCB_PAINTING_CONTROL`` (The Combo control itself
1065
is being painted, instead of a list item. The ``item``
1066
parameter may be ``wx.NOT_FOUND`` in this case.
1067
``wx.combo.ODCB_PAINTING_SELECTED`` (An item with
1068
selection background is being painted. The DC's text colour
1069
should already be correct.
1074
virtual wxCoord , OnMeasureItem( size_t item ) const,
1075
"The derived class may implement this method to return the height of
1076
the specified item (in pixels). The default implementation returns
1077
text height, as if this control was a normal combobox.", "");
1081
virtual wxCoord , OnMeasureItemWidth( size_t item ) const,
1082
"The derived class may implement this method to return the width of the
1083
specified item (in pixels). If -1 is returned, then the item text
1084
width is used. The default implementation returns -1.", "");
1088
virtual void , OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const,
1089
"This method is used to draw the items background and, maybe, a border
1092
The base class version implements a reasonable default behaviour which
1093
consists in drawing the selected item with the standard background
1094
colour and drawing a border around the item if it is either selected
1095
or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1100
//---------------------------------------------------------------------------
1103
#include <wx/bmpcbox.h>
1106
DocStr(wxBitmapComboBox,
1107
"A combobox that displays a bitmap in front of the list items. It
1108
currently only allows using bitmaps of one size, and resizes itself so
1109
that a bitmap can be shown next to the text field.",
1114
=================== ============================================
1115
wx.CB_READONLY Creates a combobox without a text editor. On
1116
some platforms the control may appear very
1117
different when this style is used.
1118
wx.CB_SORT Sorts the entries in the list alphabetically.
1119
wx.TE_PROCESS_ENTER The control will generate the event
1120
wx.EVT__TEXT_ENTER (otherwise pressing Enter
1121
key is either processed internally by the
1122
control or used for navigation between dialog
1124
=================== ============================================
1127
MustHaveApp(wxBitmapComboBox);
1129
#if defined(__WXMSW__) || defined(__WXGTK__)
1130
class wxBitmapComboBox : public wxComboBox
1132
class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1136
%pythonAppend wxBitmapComboBox "self._setOORInfo(self);";
1137
%pythonAppend wxBitmapComboBox() "";
1140
wxBitmapComboBox(wxWindow *parent,
1142
const wxString& value = wxPyEmptyString,
1143
const wxPoint& pos = wxDefaultPosition,
1144
const wxSize& size = wxDefaultSize,
1145
const wxArrayString& choices = wxPyEmptyStringArray,
1147
const wxValidator& validator = wxDefaultValidator,
1148
const wxString& name = wxBitmapComboBoxNameStr),
1149
"Standard constructor", "");
1151
DocCtorStrName(wxBitmapComboBox(),
1152
"2-phase create constructor.", "",
1156
bool , Create(wxWindow *parent,
1158
const wxString& value = wxPyEmptyString,
1159
const wxPoint& pos = wxDefaultPosition,
1160
const wxSize& size = wxDefaultSize,
1161
const wxArrayString& choices = wxPyEmptyStringArray,
1163
const wxValidator& validator = wxDefaultValidator,
1164
const wxString& name = wxBitmapComboBoxNameStr),
1165
"Create the UI object, and other initialization.", "");
1171
"Adds the item to the control, associating the given data with the item
1172
if not None. The return value is the index of the newly added item.", "");
1173
int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap, PyObject* clientData=NULL) {
1175
wxPyClientData* data = new wxPyClientData(clientData);
1176
return self->Append(item, bitmap, data);
1178
return self->Append(item, bitmap);
1184
virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
1185
"Returns the image of the item with the given index.", "");
1190
"Insert an item into the control before the item at the ``pos`` index,
1191
optionally associating some data object with the item.", "");
1192
int Insert(const wxString& item, const wxBitmap& bitmap,
1193
/*unsigned*/ int pos, PyObject* clientData=NULL) {
1195
wxPyClientData* data = new wxPyClientData(clientData);
1196
return self->Insert(item, bitmap, pos, data);
1198
return self->Insert(item, bitmap, pos);
1204
virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
1205
"Sets the image for the given item.", "");
1209
virtual wxSize , GetBitmapSize() const,
1210
"Returns size of the image used in list.", "");
1215
//---------------------------------------------------------------------------
1218
// Map renamed classes back to their common name for OOR
1219
wxPyPtrTypeMap_Add("wxComboCtrl", "wxPyComboCtrl");
1220
wxPyPtrTypeMap_Add("wxComboPopup", "wxPyComboPopup");
1221
wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
1223
//---------------------------------------------------------------------------