1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for the owner-drawn combobox classes
7 // Created: 11-Nov-2006
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"
25 #include <wx/odcombo.h>
28 //---------------------------------------------------------------------------
31 %pythoncode { wx = _core }
32 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
34 //---------------------------------------------------------------------------
37 MAKE_CONST_WXSTRING_NOSWIG(ComboBoxNameStr);
38 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
41 const wxArrayString wxPyEmptyStringArray;
46 // Button is preferred outside the border (GTK style)
47 wxCC_BUTTON_OUTSIDE_BORDER = 0x0001,
48 // Show popup on mouse up instead of mouse down (which is the Windows style)
49 wxCC_POPUP_ON_MOUSE_UP = 0x0002,
50 // All text is not automatically selected on click
51 wxCC_NO_TEXT_AUTO_SELECT = 0x0004,
55 // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
58 wxCC_MF_ON_BUTTON = 0x0001, // cursor is on dropbutton area
59 wxCC_MF_ON_CLICK_AREA = 0x0002 // cursor is on dropbutton or other area
60 // that can be clicked to show the popup.
64 DocStr( wxComboCtrlFeatures,
65 "Namespace for `wx.combo.ComboCtrl` feature flags. See
66 `wx.combo.ComboCtrl.GetFeatures`.", "");
67 struct wxComboCtrlFeatures
71 MovableButton = 0x0001, // Button can be on either side of control
72 BitmapButton = 0x0002, // Button may be replaced with bitmap
73 ButtonSpacing = 0x0004, // Button can have spacing from the edge
75 TextIndent = 0x0008, // SetTextIndent can be used
76 PaintControl = 0x0010, // Combo control itself can be custom painted
77 PaintWritable = 0x0020, // A variable-width area in front of writable
78 // combo control's textctrl can be custom
80 Borderless = 0x0040, // wxNO_BORDER window style works
82 // There are no feature flags for...
83 // PushButtonBitmapBackground - if its in wxRendererNative, then it should be
84 // not an issue to have it automatically under the bitmap.
86 All = MovableButton|BitmapButton|
87 ButtonSpacing|TextIndent|
88 PaintControl|PaintWritable|
93 //---------------------------------------------------------------------------
95 // C++ implemetation of Python aware wxComboCtrl
97 class wxPyComboCtrl : public wxComboCtrl
99 DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
101 wxPyComboCtrl() : wxComboCtrl() {}
102 wxPyComboCtrl(wxWindow *parent,
103 wxWindowID id = wxID_ANY,
104 const wxString& value = wxEmptyString,
105 const wxPoint& pos = wxDefaultPosition,
106 const wxSize& size = wxDefaultSize,
108 const wxValidator& validator = wxDefaultValidator,
109 const wxString& name = wxPyComboBoxNameStr)
110 : wxComboCtrl(parent, id, value, pos, size, style, validator, name)
113 void DoSetPopupControl(wxComboPopup* popup)
116 wxPyBlock_t blocked = wxPyBeginBlockThreads();
117 if ((found = wxPyCBH_findCallback(m_myInst, "DoSetPopupControl"))) {
118 PyObject* obj = wxPyConstructObject(popup, wxT("wxComboPopup"), false);
119 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)",obj));
122 wxPyEndBlockThreads(blocked);
124 wxComboCtrl::DoSetPopupControl(popup);
127 virtual bool IsKeyPopupToggle( const wxKeyEvent& event ) const
131 wxPyBlock_t blocked = wxPyBeginBlockThreads();
132 if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
133 PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
134 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
137 wxPyEndBlockThreads(blocked);
139 rval = wxComboCtrl::IsKeyPopupToggle(event);
144 virtual wxWindow *GetMainWindowOfCompositeControl()
146 return wxComboCtrl::GetMainWindowOfCompositeControl();
152 ShowBelow = 0x0000, // Showing popup below the control
153 ShowAbove = 0x0001, // Showing popup above the control
154 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
158 DEC_PYCALLBACK_VOID_(ShowPopup);
159 DEC_PYCALLBACK_VOID_(HidePopup);
160 DEC_PYCALLBACK_VOID_(OnButtonClick);
161 DEC_PYCALLBACK__RECTINT(DoShowPopup);
162 DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
167 IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
169 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
170 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
171 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
172 IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
173 IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
179 // Now declare wxPyComboCtrl for Python
181 DocStr(wxPyComboCtrl,
182 "A combo control is a generic combobox that allows for a totally custom
183 popup. In addition it has other customization features. For instance,
184 position and size of the dropdown button can be changed.
186 To specify what to use for the popup control you need to derive a
187 class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
188 `SetPopupControl`. It doesn't derive from any widget class so it can
189 be used either as a mixin class combined with some standard or custom
190 widget, or you can use the derived ComboPopup to create and hold an
191 independent reference to the widget to be used for the popup.
195 ==================== ============================================
196 wx.CB_READONLY Text will not be editable.
197 wx.CB_SORT Sorts the entries in the list alphabetically.
198 wx.TE_PROCESS_ENTER The control will generate the event
199 EVT_TEXT_ENTER (otherwise pressing Enter key
200 is either processed internally by the control
201 or used for navigation between dialog controls).
202 wx.CC_SPECIAL_DCLICK Double-clicking triggers a call to popup's
203 OnComboDoubleClick. Actual behaviour is defined
204 by a derived class. For instance,
205 OwnerDrawnComboBox will cycle an item. This
206 style only applies if wx.CB_READONLY is used
208 wx.CC_STD_BUTTON Drop button will behave more like a standard
210 ==================== ============================================
213 MustHaveApp(wxPyComboCtrl);
214 %rename(ComboCtrl) wxPyComboCtrl;
216 class wxPyComboCtrl : public wxControl
219 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
220 %pythonAppend wxPyComboCtrl() "";
223 wxPyComboCtrl(wxWindow *parent,
224 wxWindowID id = wxID_ANY,
225 const wxString& value = wxEmptyString,
226 const wxPoint& pos = wxDefaultPosition,
227 const wxSize& size = wxDefaultSize,
229 const wxValidator& validator = wxDefaultValidator,
230 const wxString& name = wxPyComboBoxNameStr),
239 void _setCallbackInfo(PyObject* self, PyObject* _class);
242 virtual void , ShowPopup(),
243 "Show the popup window.", "");
246 virtual void , HidePopup(),
247 "Dismisses the popup window.", "");
250 // Override for totally custom combo action
252 virtual void , OnButtonClick(),
253 "Implement in a derived class to define what happens on dropdown button
254 click. Default action is to show the popup. ", "");
257 // return true if the popup is currently shown
259 bool , IsPopupShown() const,
260 "Returns true if the popup is currently shown.", "");
263 %disownarg(wxPyComboPopup* popup);
265 void , SetPopupControl( wxPyComboPopup* popup ),
266 "Set popup interface class derived from `wx.combo.ComboPopup`. This
267 method should be called as soon as possible after the control has been
268 created, unless `OnButtonClick` has been overridden.", "");
269 %cleardisown(wxPyComboPopup* popup);
273 wxPyComboPopup* , GetPopupControl(),
274 "Returns the current popup interface that has been set with
275 `SetPopupControl`.", "");
279 wxWindow *, GetPopupWindow() const,
280 "Returns the popup window containing the popup control.", "");
284 wxTextCtrl *, GetTextCtrl() const,
285 "Get the text control which is part of the combo control.", "");
289 wxWindow *, GetButton() const,
290 "Get the dropdown button which is part of the combobox. Note: it's not
291 necessarily a wx.Button or wx.BitmapButton.", "");
294 // // forward these methods to all subcontrols
295 // virtual bool Enable(bool enable = true);
296 // virtual bool Show(bool show = true);
297 // virtual bool SetFont(const wxFont& font);
299 // wxTextCtrl methods - for readonly combo they should return
303 virtual wxString , GetValue() const,
304 "Returns text representation of the current value. For writable combo
305 control it always returns the value in the text field.", "");
308 virtual void , SetValue(const wxString& value),
309 "Sets the text for the combo control text field. For a combo control
310 with wx.CB_READONLY style the string must be accepted by the popup (for
311 instance, exist in the dropdown list), otherwise the call to
312 SetValue is ignored.", "");
316 virtual void Paste();
317 virtual void SetInsertionPoint(long pos);
318 virtual void SetInsertionPointEnd();
319 virtual long GetInsertionPoint() const;
320 virtual long GetLastPosition() const;
321 virtual void Replace(long from, long to, const wxString& value);
322 virtual void Remove(long from, long to);
325 %Rename(SetMark, void , SetSelection(long from, long to));
329 void , SetText(const wxString& value),
330 "Sets the text for the text field without affecting the popup. Thus,
331 unlike `SetValue`, it works equally well with combo control using
332 wx.CB_READONLY style.", "");
336 void , SetValueWithEvent(const wxString& value, bool withEvent = true),
337 "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
341 // Popup customization methods
345 void , SetPopupMinWidth( int width ),
346 "Sets minimum width of the popup. If wider than combo control, it will
347 extend to the left. A value of -1 indicates to use the default. The
348 popup implementation may choose to ignore this.", "");
352 void , SetPopupMaxHeight( int height ),
353 "Sets preferred maximum height of the popup. A value of -1 indicates to
354 use the default. The popup implementation may choose to ignore this.", "");
358 void , SetPopupExtents( int extLeft, int extRight ),
359 "Extends popup size horizontally, relative to the edges of the combo
360 control. Values are given in pixels, and the defaults are zero. It
361 is up to the popup to fully take these values into account.", "");
365 void , SetCustomPaintWidth( int width ),
366 "Set width, in pixels, of custom painted area in control without
367 wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
368 to indicate the area that is not covered by the focus rectangle.", "");
370 int GetCustomPaintWidth() const;
374 void , SetPopupAnchor( int anchorSide ),
375 "Set side of the control to which the popup will align itself. Valid
376 values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
377 most appropriate side is used (which, currently, is always wx.LEFT).", "");
381 void , SetButtonPosition( int width = -1,
385 "Set the position of the dropdown button.", "");
389 wxSize , GetButtonSize(),
390 "Returns current size of the dropdown button.", "");
394 void , SetButtonBitmaps( const wxBitmap& bmpNormal,
395 bool pushButtonBg = false,
396 const wxBitmap& bmpPressed = wxNullBitmap,
397 const wxBitmap& bmpHover = wxNullBitmap,
398 const wxBitmap& bmpDisabled = wxNullBitmap ),
399 "Sets custom dropdown button graphics.
401 :param bmpNormal: Default button image
402 :param pushButtonBg: If ``True``, blank push button background is painted below the image.
403 :param bmpPressed: Depressed butotn image.
404 :param bmpHover: Button imate to use when the mouse hovers over it.
405 :param bmpDisabled: Disabled button image.
410 void , SetTextIndent( int indent ),
411 "This will set the space in pixels between left edge of the control and
412 the text, regardless whether control is read-only or not. A value of -1 can
413 be given to indicate platform default.", "");
417 wxCoord , GetTextIndent() const,
418 "Returns actual indentation in pixels.", "");
422 const wxRect& , GetTextRect() const,
423 "Returns area covered by the text field (includes everything except
424 borders and the dropdown button).", "");
428 void , UseAltPopupWindow( bool enable = true ),
429 "Enable or disable usage of an alternative popup window, which
430 guarantees ability to focus the popup control, and allows common
431 native controls to function normally. This alternative popup window is
432 usually a wxDialog, and as such, when it is shown, its parent
433 top-level window will appear as if the focus has been lost from it.", "");
437 void , EnablePopupAnimation( bool enable = true ),
438 "Enables or disables popup animation, if any, depending on the value of
443 // Utilies needed by the popups or native implementations
447 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
448 "Returns true if given key combination should toggle the popup.", "");
451 // Prepare background of combo control or an item in a dropdown list
452 // in a way typical on platform. This includes painting the focus/disabled
453 // background and setting the clipping region.
454 // Unless you plan to paint your own focus indicator, you should always call this
455 // in your wxComboPopup::PaintComboControl implementation.
456 // In addition, it sets pen and text colour to what looks good and proper
457 // against the background.
458 // flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control
459 // wxCONTROL_SELECTED: list item is selected
460 // wxCONTROL_DISABLED: control/item is disabled
462 virtual void , PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const,
463 "Prepare background of combo control or an item in a dropdown list in a
464 way typical on platform. This includes painting the focus/disabled
465 background and setting the clipping region. Unless you plan to paint
466 your own focus indicator, you should always call this in your
467 wxComboPopup::PaintComboControl implementation. In addition, it sets
468 pen and text colour to what looks good and proper against the
471 flags are the same as wx.RendererNative flags:
473 ====================== ============================================
474 wx.CONTROL_ISSUBMENU drawing a list item instead of combo control
475 wx.CONTROL_SELECTED list item is selected
476 wx.CONTROL_DISABLED control/item is disabled
477 ====================== ============================================
483 bool , ShouldDrawFocus() const,
484 "Returns true if focus indicator should be drawn in the control.", "");
487 const wxBitmap& GetBitmapNormal() const;
488 const wxBitmap& GetBitmapPressed() const;
489 const wxBitmap& GetBitmapHover() const;
490 const wxBitmap& GetBitmapDisabled() const;
492 wxUint32 GetInternalFlags() const;
495 bool , IsCreated() const,
496 "Return true if Create has finished", "");
500 void , OnPopupDismiss(),
501 "Common code to be called on popup hide/dismiss", "");
513 bool IsPopupWindowState( int state ) const;
515 int GetPopupWindowState() const;
517 // Set value returned by GetMainWindowOfCompositeControl
518 void SetCtrlMainWnd( wxWindow* wnd );
519 virtual wxWindow *GetMainWindowOfCompositeControl();
522 static int , GetFeatures(),
523 "Returns a bit-list of flags indicating which features of the ComboCtrl
524 functionality are implemented by this implemetation. See
525 `wx.combo.ComboCtrlFeatures`.", "");
529 // Flags for DoShowPopup and AnimateShow
532 ShowBelow = 0x0000, // Showing popup below the control
533 ShowAbove = 0x0001, // Showing popup above the control
534 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
537 // Shows and positions the popup.
539 virtual void , DoShowPopup( const wxRect& rect, int flags ),
540 "Shows and positions the popup.
543 ============ =====================================================
544 ShowBelow Showing popup below the control
545 ShowAbove Showing popup above the control
546 CanDeferShow Can only return true from AnimateShow if this is set
547 ============ =====================================================
553 virtual bool , AnimateShow( const wxRect& rect, int flags ),
554 "Implement in derived class to create a drop-down animation. Return
555 ``True`` if finished immediately. Otherwise the popup is only shown when the
556 derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
560 %property(PopupControl, GetPopupControl, SetPopupControl);
561 %property(PopupWindow, GetPopupWindow);
562 %property(TextCtrl, GetTextCtrl);
563 %property(Button, GetButton);
564 %property(Value, GetValue, SetValue);
565 %property(InsertionPoint, GetInsertionPoint);
566 %property(CustomPaintWidth, GetCustomPaintWidth, SetCustomPaintWidth);
567 %property(ButtonSize, GetButtonSize);
568 %property(TextIndent, GetTextIndent, SetTextIndent);
569 %property(TextRect, GetTextRect);
570 %property(BitmapNormal, GetBitmapNormal);
571 %property(BitmapPressed, GetBitmapPressed);
572 %property(BitmapHover, GetBitmapHover);
573 %property(BitmapDisabled, GetBitmapDisabled);
574 %property(PopupWindowState, GetPopupWindowState);
578 //---------------------------------------------------------------------------
582 // C++ implemetation of Python aware wxComboCtrl
584 class wxPyComboPopup : public wxComboPopup
587 wxPyComboPopup() : wxComboPopup() {}
591 DEC_PYCALLBACK_VOID_(Init);
592 DEC_PYCALLBACK_BOOL_WXWIN_pure(Create);
593 DEC_PYCALLBACK_VOID_(OnPopup);
594 DEC_PYCALLBACK_VOID_(OnDismiss);
595 DEC_PYCALLBACK__STRING(SetStringValue);
596 DEC_PYCALLBACK_STRING__constpure(GetStringValue);
597 DEC_PYCALLBACK_VOID_(OnComboDoubleClick);
598 DEC_PYCALLBACK_BOOL_(LazyCreate);
600 virtual wxWindow *GetControl()
602 wxWindow* rval = NULL;
603 const char* errmsg = "GetControl should return an object derived from wx.Window.";
604 wxPyBlock_t blocked = wxPyBeginBlockThreads();
605 if (wxPyCBH_findCallback(m_myInst, "GetControl")) {
607 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
609 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
610 PyErr_SetString(PyExc_TypeError, errmsg);
615 PyErr_SetString(PyExc_TypeError, errmsg);
616 wxPyEndBlockThreads(blocked);
621 virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
624 wxPyBlock_t blocked = wxPyBeginBlockThreads();
625 if ((found = wxPyCBH_findCallback(m_myInst, "PaintComboControl"))) {
626 PyObject* odc = wxPyMake_wxObject(&dc,false);
627 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
628 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
632 wxPyEndBlockThreads(blocked);
634 wxComboPopup::PaintComboControl(dc, rect);
638 virtual void OnComboKeyEvent( wxKeyEvent& event )
641 wxPyBlock_t blocked = wxPyBeginBlockThreads();
642 if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
643 PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
644 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
647 wxPyEndBlockThreads(blocked);
649 wxComboPopup::OnComboKeyEvent(event);
653 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
655 const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
658 wxSize* rptr = &rval;
659 wxPyBlock_t blocked = wxPyBeginBlockThreads();
660 if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
662 ro = wxPyCBH_callCallbackObj(
663 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
665 if (! wxSize_helper(ro, &rptr))
666 PyErr_SetString(PyExc_TypeError, errmsg);
672 wxPyEndBlockThreads(blocked);
674 rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
678 wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
684 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
685 IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
686 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
687 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
688 IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
689 IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
690 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
691 IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
697 // Now declare wxPyComboPopup for Python
698 DocStr(wxPyComboPopup,
699 "In order to use a custom popup with `wx.combo.ComboCtrl` an interface
700 class derived from wx.combo.ComboPopup is used to manage the interface
701 between the popup control and the popup. You can either derive a new
702 class from both the widget class and this ComboPopup class, or the
703 derived class can have a reference to the widget used for the popup.
704 In either case you simply need to return the widget from the
705 `GetControl` method to allow the ComboCtrl to interact with it.
707 Nearly all of the methods of this class are overridable in Python.", "");
710 MustHaveApp(wxPyComboPopup);
711 %rename(ComboPopup) wxPyComboPopup;
716 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
727 void _setCallbackInfo(PyObject* self, PyObject* _class);
730 virtual void , Init(),
731 "This method is called after the popup is contructed and has been
732 assigned to the ComboCtrl. Derived classes can override this to do
733 extra inialization or whatever.", "");
736 // Create the popup child control.
737 // Return true for success.
739 virtual bool , Create(wxWindow* parent),
740 "The derived class must implement this method to create the popup
741 control. It should be a child of the ``parent`` passed in, but other
742 than that there is much flexibility in what the widget can be, its
743 style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
744 this return value is not currently checked...)", "");
748 virtual wxWindow *, GetControl(),
749 "The derived class must implement this method and it should return a
750 reference to the widget created in the `Create` method. If the
751 derived class inherits from both the widget class and ComboPopup then
752 the return value is probably just ``self``.", "");
756 virtual void , OnPopup(),
757 "The derived class may implement this to do special processing when
758 popup is shown.", "");
762 virtual void , OnDismiss(),
763 "The derived class may implement this to do special processing when
764 popup is hidden.", "");
768 virtual void , SetStringValue( const wxString& value ),
769 "Called just prior to displaying the popup. The derived class can
770 implement this to \"select\" the item in the popup that coresponds to
771 the passed in string value, if appropriate. The default
772 implementation does nothing.", "");
776 virtual wxString , GetStringValue() const,
777 "Gets the string representation of the currently selected value to be
778 used to display in the combo widget.", "");
782 virtual void , PaintComboControl( wxDC& dc, const wxRect& rect ),
783 "This is called to custom paint in the combo control itself (ie. not
784 the popup). Default implementation draws the current value as string.", "");
788 virtual void , OnComboKeyEvent( wxKeyEvent& event ),
789 "Receives key events from the parent ComboCtrl. Events not handled
790 should be skipped, as usual.", "");
794 virtual void , OnComboDoubleClick(),
795 "Implement this method in the derived class if you need to support
796 special actions when the user double-clicks on the parent ComboCtrl.", "");
800 virtual wxSize , GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ),
801 "The derived class may implement this method to return adjusted size
802 for the popup control, according to the variables given. It is called
803 on every popup, just prior to `OnPopup`.
805 :param minWidth: Preferred minimum width.
806 :param prefHeight: Preferred height. May be -1 to indicate no preference.
807 :maxWidth: Max height for window, as limited by screen size, and
808 should only be rounded down, if necessary.
813 virtual bool , LazyCreate(),
814 "The derived class may implement this to return ``True`` if it wants to
815 delay the call to `Create` until the popup is shown for the first
816 time. It is more efficient, but on the other hand it is often more
817 convenient to have the control created immediately. The default
818 implementation returns ``False``.", "");
828 "Hides the popup", "");
832 bool , IsCreated() const,
833 "Returns true if `Create` has been called.", "");
837 static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
839 const wxRect& rect ),
840 "Default PaintComboControl behaviour", "");
844 wxPyComboCtrl* , GetCombo(),
845 "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
846 is associated with.", "");
852 //---------------------------------------------------------------------------
857 wxODCB_DCLICK_CYCLES,
858 wxODCB_STD_CONTROL_PAINT,
859 wxODCB_PAINTING_CONTROL,
860 wxODCB_PAINTING_SELECTED
865 // C++ implemetation of Python aware wxOwnerDrawnComboBox
867 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
870 wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
871 wxPyOwnerDrawnComboBox(wxWindow *parent,
873 const wxString& value,
876 const wxArrayString& choices,
878 const wxValidator& validator = wxDefaultValidator,
879 const wxString& name = wxPyComboBoxNameStr)
880 : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
884 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawItem);
885 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItem);
886 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItemWidth);
887 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawBackground);
893 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
894 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
895 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
896 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
902 // Now declare wxPyOwnerDrawnComboBox for Python
904 DocStr(wxPyOwnerDrawnComboBox,
905 "wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
906 items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
907 popup and a `wx.ControlWithItems` API.
909 Implementing item drawing and measuring is similar to wx.VListBox.
910 The application needs to subclass wx.combo.OwnerDrawnComboBox and
911 implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
914 MustHaveApp(wxPyOwnerDrawnComboBox);
915 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
917 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
918 public wxItemContainer
921 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
922 %pythonAppend wxPyOwnerDrawnComboBox() "";
925 wxPyOwnerDrawnComboBox(wxWindow *parent,
927 const wxString& value = wxPyEmptyString,
928 const wxPoint& pos = wxDefaultPosition,
929 const wxSize& size = wxDefaultSize,
930 const wxArrayString& choices = wxPyEmptyStringArray,
932 const wxValidator& validator = wxDefaultValidator,
933 const wxString& name = wxPyComboBoxNameStr),
934 "Standard constructor.", "");
936 DocCtorStrName(wxPyOwnerDrawnComboBox(),
937 "2-phase create constructor.", "",
938 PreOwnerDrawnComboBox);
940 void _setCallbackInfo(PyObject* self, PyObject* _class);
944 bool , Create(wxWindow *parent,
946 const wxString& value = wxPyEmptyString,
947 const wxPoint& pos = wxDefaultPosition,
948 const wxSize& size = wxDefaultSize,
949 const wxArrayString& choices = wxPyEmptyStringArray,
951 const wxValidator& validator = wxDefaultValidator,
952 const wxString& name = wxPyComboBoxNameStr),
953 "Create the UI object, and other initialization.", "");
957 virtual int , GetWidestItemWidth(),
958 "Return the widest item width (recalculating it if necessary.)", "");
962 virtual int , GetWidestItem(),
963 "Return the index of the widest item (recalculating it if necessary.)", "");
966 void SetSelection(int n);
967 %Rename(SetMark, void , SetSelection(long from, long to));
970 // Callback for drawing. Font, background and text colour have been
971 // prepared according to selection, focus and such.
972 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
973 // and there is no valid selection
974 // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
976 virtual void , OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const,
977 "The derived class may implement this function to actually draw the
978 item with the given index on the provided DC. If this method is not
979 overridden, the item text is simply drawn as if the control was a
982 :param dc: The device context to use for drawing.
983 :param rect: The bounding rectangle for the item being drawn, the
984 DC's clipping region is set to this rectangle before
986 :param item: The index of the item to be drawn.
988 :param flags: ``wx.combo.ODCB_PAINTING_CONTROL`` (The Combo control itself
989 is being painted, instead of a list item. The ``item``
990 parameter may be ``wx.NOT_FOUND`` in this case.
991 ``wx.combo.ODCB_PAINTING_SELECTED`` (An item with
992 selection background is being painted. The DC's text colour
993 should already be correct.
998 virtual wxCoord , OnMeasureItem( size_t item ) const,
999 "The derived class may implement this method to return the height of
1000 the specified item (in pixels). The default implementation returns
1001 text height, as if this control was a normal combobox.", "");
1005 virtual wxCoord , OnMeasureItemWidth( size_t item ) const,
1006 "The derived class may implement this method to return the width of the
1007 specified item (in pixels). If -1 is returned, then the item text
1008 width is used. The default implementation returns -1.", "");
1012 virtual void , OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const,
1013 "This method is used to draw the items background and, maybe, a border
1016 The base class version implements a reasonable default behaviour which
1017 consists in drawing the selected item with the standard background
1018 colour and drawing a border around the item if it is either selected
1019 or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1024 //---------------------------------------------------------------------------
1027 #include <wx/bmpcbox.h>
1030 DocStr(wxBitmapComboBox,
1031 "A combobox that displays a bitmap in front of the list items. It
1032 currently only allows using bitmaps of one size, and resizes itself so
1033 that a bitmap can be shown next to the text field.",
1037 =================== ============================================
1038 wx.CB_READONLY Creates a combobox without a text editor. On
1039 some platforms the control may appear very
1040 different when this style is used.
1041 wx.CB_SORT Sorts the entries in the list alphabetically.
1042 wx.TE_PROCESS_ENTER The control will generate the event
1043 wx.EVT__TEXT_ENTER (otherwise pressing Enter
1044 key is either processed internally by the
1045 control or used for navigation between dialog
1047 =================== ============================================
1050 MustHaveApp(wxBitmapComboBox);
1052 class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1055 %pythonAppend wxBitmapComboBox "self._setOORInfo(self);";
1056 %pythonAppend wxBitmapComboBox() "";
1059 wxBitmapComboBox(wxWindow *parent,
1061 const wxString& value = wxPyEmptyString,
1062 const wxPoint& pos = wxDefaultPosition,
1063 const wxSize& size = wxDefaultSize,
1064 const wxArrayString& choices = wxPyEmptyStringArray,
1066 const wxValidator& validator = wxDefaultValidator,
1067 const wxString& name = wxBitmapComboBoxNameStr),
1068 "Standard constructor", "");
1070 DocCtorStrName(wxBitmapComboBox(),
1071 "2-phase create constructor.", "",
1075 bool , Create(wxWindow *parent,
1077 const wxString& value = wxPyEmptyString,
1078 const wxPoint& pos = wxDefaultPosition,
1079 const wxSize& size = wxDefaultSize,
1080 const wxArrayString& choices = wxPyEmptyStringArray,
1082 const wxValidator& validator = wxDefaultValidator,
1083 const wxString& name = wxBitmapComboBoxNameStr),
1084 "Create the UI object, and other initialization.", "");
1090 "Adds the item to the control, associating the given data with the item
1091 if not None. The return value is the index of the newly added item.", "");
1092 int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap, PyObject* clientData=NULL) {
1094 wxPyClientData* data = new wxPyClientData(clientData);
1095 return self->Append(item, bitmap, data);
1097 return self->Append(item, bitmap);
1103 virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
1104 "Returns the image of the item with the given index.", "");
1109 "Insert an item into the control before the item at the ``pos`` index,
1110 optionally associating some data object with the item.", "");
1111 int Insert(const wxString& item, const wxBitmap& bitmap,
1112 /*unsigned*/ int pos, PyObject* clientData=NULL) {
1114 wxPyClientData* data = new wxPyClientData(clientData);
1115 return self->Insert(item, bitmap, pos, data);
1117 return self->Insert(item, bitmap, pos);
1123 virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
1124 "Sets the image for the given item.", "");
1128 virtual wxSize , GetBitmapSize() const,
1129 "Returns size of the image used in list.", "");
1134 //---------------------------------------------------------------------------
1137 // Map renamed classes back to their common name for OOR
1138 wxPyPtrTypeMap_Add("wxComboCtrl", "wxPyComboCtrl");
1139 wxPyPtrTypeMap_Add("wxComboPopup", "wxPyComboPopup");
1140 wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
1142 //---------------------------------------------------------------------------