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);
146 ShowBelow = 0x0000, // Showing popup below the control
147 ShowAbove = 0x0001, // Showing popup above the control
148 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
152 DEC_PYCALLBACK_VOID_(ShowPopup);
153 DEC_PYCALLBACK_VOID_(HidePopup);
154 DEC_PYCALLBACK_VOID_(OnButtonClick);
155 DEC_PYCALLBACK__RECTINT(DoShowPopup);
156 DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
161 IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
163 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
164 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
165 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
166 IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
167 IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
173 // Now declare wxPyComboCtrl for Python
175 DocStr(wxPyComboCtrl,
176 "A combo control is a generic combobox that allows for a totally custom
177 popup. In addition it has other customization features. For instance,
178 position and size of the dropdown button can be changed.
180 To specify what to use for the popup control you need to derive a
181 class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
182 `SetPopupControl`. It doesn't derive from any widget class so it can
183 be used either as a mixin class combined with some standard or custom
184 widget, or you can use the derived ComboPopup to create and hold an
185 independent reference to the widget to be used for the popup.
189 ==================== ============================================
190 wx.CB_READONLY Text will not be editable.
191 wx.CB_SORT Sorts the entries in the list alphabetically.
192 wx.TE_PROCESS_ENTER The control will generate the event
193 EVT_TEXT_ENTER (otherwise pressing Enter key
194 is either processed internally by the control
195 or used for navigation between dialog controls).
196 wx.CC_SPECIAL_DCLICK Double-clicking triggers a call to popup's
197 OnComboDoubleClick. Actual behaviour is defined
198 by a derived class. For instance,
199 OwnerDrawnComboBox will cycle an item. This
200 style only applies if wx.CB_READONLY is used
202 wx.CC_STD_BUTTON Drop button will behave more like a standard
204 ==================== ============================================
207 MustHaveApp(wxPyComboCtrl);
208 %rename(ComboCtrl) wxPyComboCtrl;
210 class wxPyComboCtrl : public wxControl
213 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
214 %pythonAppend wxPyComboCtrl() "";
217 wxPyComboCtrl(wxWindow *parent,
218 wxWindowID id = wxID_ANY,
219 const wxString& value = wxEmptyString,
220 const wxPoint& pos = wxDefaultPosition,
221 const wxSize& size = wxDefaultSize,
223 const wxValidator& validator = wxDefaultValidator,
224 const wxString& name = wxPyComboBoxNameStr),
233 void _setCallbackInfo(PyObject* self, PyObject* _class);
236 virtual void , ShowPopup(),
237 "Show the popup window.", "");
240 virtual void , HidePopup(),
241 "Dismisses the popup window.", "");
244 // Override for totally custom combo action
246 virtual void , OnButtonClick(),
247 "Implement in a derived class to define what happens on dropdown button
248 click. Default action is to show the popup. ", "");
251 // return true if the popup is currently shown
253 bool , IsPopupShown() const,
254 "Returns true if the popup is currently shown.", "");
257 %disownarg(wxPyComboPopup* popup);
259 void , SetPopupControl( wxPyComboPopup* popup ),
260 "Set popup interface class derived from `wx.combo.ComboPopup`. This
261 method should be called as soon as possible after the control has been
262 created, unless `OnButtonClick` has been overridden.", "");
263 %cleardisown(wxPyComboPopup* popup);
267 wxPyComboPopup* , GetPopupControl(),
268 "Returns the current popup interface that has been set with
269 `SetPopupControl`.", "");
273 wxWindow *, GetPopupWindow() const,
274 "Returns the popup window containing the popup control.", "");
278 wxTextCtrl *, GetTextCtrl() const,
279 "Get the text control which is part of the combo control.", "");
283 wxWindow *, GetButton() const,
284 "Get the dropdown button which is part of the combobox. Note: it's not
285 necessarily a wx.Button or wx.BitmapButton.", "");
288 // // forward these methods to all subcontrols
289 // virtual bool Enable(bool enable = true);
290 // virtual bool Show(bool show = true);
291 // virtual bool SetFont(const wxFont& font);
293 // wxTextCtrl methods - for readonly combo they should return
297 virtual wxString , GetValue() const,
298 "Returns text representation of the current value. For writable combo
299 control it always returns the value in the text field.", "");
302 virtual void , SetValue(const wxString& value),
303 "Sets the text for the combo control text field. For a combo control
304 with wx.CB_READONLY style the string must be accepted by the popup (for
305 instance, exist in the dropdown list), otherwise the call to
306 SetValue is ignored.", "");
310 virtual void Paste();
311 virtual void SetInsertionPoint(long pos);
312 virtual void SetInsertionPointEnd();
313 virtual long GetInsertionPoint() const;
314 virtual long GetLastPosition() const;
315 virtual void Replace(long from, long to, const wxString& value);
316 virtual void Remove(long from, long to);
319 %Rename(SetMark, void , SetSelection(long from, long to));
323 void , SetText(const wxString& value),
324 "Sets the text for the text field without affecting the popup. Thus,
325 unlike `SetValue`, it works equally well with combo control using
326 wx.CB_READONLY style.", "");
330 void , SetValueWithEvent(const wxString& value, bool withEvent = true),
331 "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
335 // Popup customization methods
339 void , SetPopupMinWidth( int width ),
340 "Sets minimum width of the popup. If wider than combo control, it will
341 extend to the left. A value of -1 indicates to use the default. The
342 popup implementation may choose to ignore this.", "");
346 void , SetPopupMaxHeight( int height ),
347 "Sets preferred maximum height of the popup. A value of -1 indicates to
348 use the default. The popup implementation may choose to ignore this.", "");
352 void , SetPopupExtents( int extLeft, int extRight ),
353 "Extends popup size horizontally, relative to the edges of the combo
354 control. Values are given in pixels, and the defaults are zero. It
355 is up to th epopup to fully take these values into account.", "");
359 void , SetCustomPaintWidth( int width ),
360 "Set width, in pixels, of custom painted area in control without
361 wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
362 to indicate the area that is not covered by the focus rectangle.", "");
364 int GetCustomPaintWidth() const;
368 void , SetPopupAnchor( int anchorSide ),
369 "Set side of the control to which the popup will align itself. Valid
370 values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
371 most appropriate side is used (which, currently, is always wx.LEFT).", "");
375 void , SetButtonPosition( int width = -1,
379 "Set the position of the dropdown button.", "");
383 wxSize , GetButtonSize(),
384 "Returns current size of the dropdown button.", "");
388 void , SetButtonBitmaps( const wxBitmap& bmpNormal,
389 bool pushButtonBg = false,
390 const wxBitmap& bmpPressed = wxNullBitmap,
391 const wxBitmap& bmpHover = wxNullBitmap,
392 const wxBitmap& bmpDisabled = wxNullBitmap ),
393 "Sets custom dropdown button graphics.
395 :param bmpNormal: Default button image
396 :param pushButtonBg: If ``True``, blank push button background is painted below the image.
397 :param bmpPressed: Depressed butotn image.
398 :param bmpHover: Button imate to use when the mouse hovers over it.
399 :param bmpDisabled: Disabled button image.
404 void , SetTextIndent( int indent ),
405 "This will set the space in pixels between left edge of the control and
406 the text, regardless whether control is read-only or not. A value of -1 can
407 be given to indicate platform default.", "");
411 wxCoord , GetTextIndent() const,
412 "Returns actual indentation in pixels.", "");
416 const wxRect& , GetTextRect() const,
417 "Returns area covered by the text field (includes everything except
418 borders and the dropdown button).", "");
422 void , UseAltPopupWindow( bool enable = true ),
423 "Enable or disable usage of an alternative popup window, which
424 guarantees ability to focus the popup control, and allows common
425 native controls to function normally. This alternative popup window is
426 usually a wxDialog, and as such, when it is shown, its parent
427 top-level window will appear as if the focus has been lost from it.", "");
431 void , EnablePopupAnimation( bool enable = true ),
432 "Enables or disables popup animation, if any, depending on the value of
437 // Utilies needed by the popups or native implementations
441 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
442 "Returns true if given key combination should toggle the popup.", "");
445 // Prepare background of combo control or an item in a dropdown list
446 // in a way typical on platform. This includes painting the focus/disabled
447 // background and setting the clipping region.
448 // Unless you plan to paint your own focus indicator, you should always call this
449 // in your wxComboPopup::PaintComboControl implementation.
450 // In addition, it sets pen and text colour to what looks good and proper
451 // against the background.
452 // flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control
453 // wxCONTROL_SELECTED: list item is selected
454 // wxCONTROL_DISABLED: control/item is disabled
456 virtual void , PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const,
457 "Prepare background of combo control or an item in a dropdown list in a
458 way typical on platform. This includes painting the focus/disabled
459 background and setting the clipping region. Unless you plan to paint
460 your own focus indicator, you should always call this in your
461 wxComboPopup::PaintComboControl implementation. In addition, it sets
462 pen and text colour to what looks good and proper against the
465 flags are the same as wx.RendererNative flags:
467 ====================== ============================================
468 wx.CONTROL_ISSUBMENU drawing a list item instead of combo control
469 wx.CONTROL_SELECTED list item is selected
470 wx.CONTROL_DISABLED control/item is disabled
471 ====================== ============================================
477 bool , ShouldDrawFocus() const,
478 "Returns true if focus indicator should be drawn in the control.", "");
481 const wxBitmap& GetBitmapNormal() const;
482 const wxBitmap& GetBitmapPressed() const;
483 const wxBitmap& GetBitmapHover() const;
484 const wxBitmap& GetBitmapDisabled() const;
486 wxUint32 GetInternalFlags() const;
489 bool , IsCreated() const,
490 "Return true if Create has finished", "");
494 void , OnPopupDismiss(),
495 "Common code to be called on popup hide/dismiss", "");
507 bool IsPopupWindowState( int state ) const;
509 int GetPopupWindowState() const;
511 // Set value returned by GetMainWindowOfCompositeControl
512 void SetCtrlMainWnd( wxWindow* wnd );
515 static int , GetFeatures(),
516 "Returns a bit-list of flags indicating which features of the ComboCtrl
517 functionality are implemented by this implemetation. See
518 `wx.combo.ComboCtrlFeatures`.", "");
522 // Flags for DoShowPopup and AnimateShow
525 ShowBelow = 0x0000, // Showing popup below the control
526 ShowAbove = 0x0001, // Showing popup above the control
527 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
530 // Shows and positions the popup.
532 virtual void , DoShowPopup( const wxRect& rect, int flags ),
533 "Shows and positions the popup.
536 ============ =====================================================
537 ShowBelow Showing popup below the control
538 ShowAbove Showing popup above the control
539 CanDeferShow Can only return true from AnimateShow if this is set
540 ============ =====================================================
546 virtual bool , AnimateShow( const wxRect& rect, int flags ),
547 "Implement in derived class to create a drop-down animation. Return
548 ``True`` if finished immediately. Otherwise the popup is only shown when the
549 derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
555 //---------------------------------------------------------------------------
559 // C++ implemetation of Python aware wxComboCtrl
561 class wxPyComboPopup : public wxComboPopup
564 wxPyComboPopup() : wxComboPopup() {}
568 DEC_PYCALLBACK_VOID_(Init);
569 DEC_PYCALLBACK_BOOL_WXWIN_pure(Create);
570 DEC_PYCALLBACK_VOID_(OnPopup);
571 DEC_PYCALLBACK_VOID_(OnDismiss);
572 DEC_PYCALLBACK__STRING(SetStringValue);
573 DEC_PYCALLBACK_STRING__constpure(GetStringValue);
574 DEC_PYCALLBACK_VOID_(OnComboDoubleClick);
575 DEC_PYCALLBACK_BOOL_(LazyCreate);
577 virtual wxWindow *GetControl()
579 wxWindow* rval = NULL;
580 const char* errmsg = "GetControl should return an object derived from wx.Window.";
581 wxPyBlock_t blocked = wxPyBeginBlockThreads();
582 if (wxPyCBH_findCallback(m_myInst, "GetControl")) {
584 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
586 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
587 PyErr_SetString(PyExc_TypeError, errmsg);
592 PyErr_SetString(PyExc_TypeError, errmsg);
593 wxPyEndBlockThreads(blocked);
598 virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
601 wxPyBlock_t blocked = wxPyBeginBlockThreads();
602 if ((found = wxPyCBH_findCallback(m_myInst, "PaintComboControl"))) {
603 PyObject* odc = wxPyMake_wxObject(&dc,false);
604 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
605 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
609 wxPyEndBlockThreads(blocked);
611 wxComboPopup::PaintComboControl(dc, rect);
615 virtual void OnComboKeyEvent( wxKeyEvent& event )
618 wxPyBlock_t blocked = wxPyBeginBlockThreads();
619 if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
620 PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
621 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
624 wxPyEndBlockThreads(blocked);
626 wxComboPopup::OnComboKeyEvent(event);
630 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
632 const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
635 wxSize* rptr = &rval;
636 wxPyBlock_t blocked = wxPyBeginBlockThreads();
637 if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
639 ro = wxPyCBH_callCallbackObj(
640 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
642 if (! wxSize_helper(ro, &rptr))
643 PyErr_SetString(PyExc_TypeError, errmsg);
649 wxPyEndBlockThreads(blocked);
651 rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
655 wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
661 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
662 IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
663 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
664 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
665 IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
666 IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
667 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
668 IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
674 // Now declare wxPyComboPopup for Python
675 DocStr(wxPyComboPopup,
676 "In order to use a custom popup with `wx.combo.ComboCtrl` an interface
677 class derived from wx.combo.ComboPopup is used to manage the interface
678 between the popup control and the popup. You can either derive a new
679 class from both the widget class and this ComboPopup class, or the
680 derived class can have a reference to the widget used for the popup.
681 In either case you simply need to return the widget from the
682 `GetControl` method to allow the ComboCtrl to interact with it.
684 Nearly all of the methods of this class are overridable in Python.", "");
687 MustHaveApp(wxPyComboPopup);
688 %rename(ComboPopup) wxPyComboPopup;
693 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
704 void _setCallbackInfo(PyObject* self, PyObject* _class);
707 virtual void , Init(),
708 "This method is called after the popup is contructed and has been
709 assigned to the ComboCtrl. Derived classes can override this to do
710 extra inialization or whatever.", "");
713 // Create the popup child control.
714 // Return true for success.
716 virtual bool , Create(wxWindow* parent),
717 "The derived class must implement this method to create the popup
718 control. It should be a child of the ``parent`` passed in, but other
719 than that there is much flexibility in what the widget can be, its
720 style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
721 this return value is not currently checked...)", "");
725 virtual wxWindow *, GetControl(),
726 "The derived class must implement this method and it should return a
727 reference to the widget created in the `Create` method. If the
728 derived class inherits from both the widget class and ComboPopup then
729 the return value is probably just ``self``.", "");
733 virtual void , OnPopup(),
734 "The derived class may implement this to do special processing when
735 popup is shown.", "");
739 virtual void , OnDismiss(),
740 "The derived class may implement this to do special processing when
741 popup is hidden.", "");
745 virtual void , SetStringValue( const wxString& value ),
746 "Called just prior to displaying the popup. The derived class can
747 implement this to \"select\" the item in the popup that coresponds to
748 the passed in string value, if appropriate. The default
749 implementation does nothing.", "");
753 virtual wxString , GetStringValue() const,
754 "Gets the string representation of the currently selected value to be
755 used to display in the combo widget.", "");
759 virtual void , PaintComboControl( wxDC& dc, const wxRect& rect ),
760 "This is called to custom paint in the combo control itself (ie. not
761 the popup). Default implementation draws the current value as string.", "");
765 virtual void , OnComboKeyEvent( wxKeyEvent& event ),
766 "Receives key events from the parent ComboCtrl. Events not handled
767 should be skipped, as usual.", "");
771 virtual void , OnComboDoubleClick(),
772 "Implement this method in the derived class if you need to support
773 special actions when the user double-clicks on the parent ComboCtrl.", "");
777 virtual wxSize , GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ),
778 "The derived class may implement this method to return adjusted size
779 for the popup control, according to the variables given. It is called
780 on every popup, just prior to `OnPopup`.
782 :param minWidth: Preferred minimum width.
783 :param prefHeight: Preferred height. May be -1 to indicate no preference.
784 :maxWidth: Max height for window, as limited by screen size, and
785 should only be rounded down, if necessary.
790 virtual bool , LazyCreate(),
791 "The derived class may implement this to return ``True`` if it wants to
792 delay the call to `Create` until the popup is shown for the first
793 time. It is more efficient, but on the other hand it is often more
794 convenient to have the control created immediately. The default
795 implementation returns ``False``.", "");
805 "Hides the popup", "");
809 bool , IsCreated() const,
810 "Returns true if `Create` has been called.", "");
814 static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
816 const wxRect& rect ),
817 "Default PaintComboControl behaviour", "");
821 wxPyComboCtrl* , GetCombo(),
822 "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
823 is associated with.", "");
829 //---------------------------------------------------------------------------
834 wxODCB_DCLICK_CYCLES,
835 wxODCB_STD_CONTROL_PAINT,
836 wxODCB_PAINTING_CONTROL,
837 wxODCB_PAINTING_SELECTED
842 // C++ implemetation of Python aware wxOwnerDrawnComboBox
844 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
847 wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
848 wxPyOwnerDrawnComboBox(wxWindow *parent,
850 const wxString& value,
853 const wxArrayString& choices,
855 const wxValidator& validator = wxDefaultValidator,
856 const wxString& name = wxPyComboBoxNameStr)
857 : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
861 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawItem);
862 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItem);
863 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItemWidth);
864 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawBackground);
870 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
871 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
872 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
873 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
879 // Now declare wxPyOwnerDrawnComboBox for Python
881 DocStr(wxPyOwnerDrawnComboBox,
882 "wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
883 items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
884 popup and a `wx.ControlWithItems` API.
886 Implementing item drawing and measuring is similar to wx.VListBox.
887 The application needs to subclass wx.combo.OwnerDrawnComboBox and
888 implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
891 MustHaveApp(wxPyOwnerDrawnComboBox);
892 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
894 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
895 public wxItemContainer
898 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
899 %pythonAppend wxPyOwnerDrawnComboBox() "";
902 wxPyOwnerDrawnComboBox(wxWindow *parent,
904 const wxString& value = wxPyEmptyString,
905 const wxPoint& pos = wxDefaultPosition,
906 const wxSize& size = wxDefaultSize,
907 const wxArrayString& choices = wxPyEmptyStringArray,
909 const wxValidator& validator = wxDefaultValidator,
910 const wxString& name = wxPyComboBoxNameStr),
911 "Standard constructor.", "");
913 DocCtorStrName(wxPyOwnerDrawnComboBox(),
914 "2-phase create constructor.", "",
915 PreOwnerDrawnComboBox);
917 void _setCallbackInfo(PyObject* self, PyObject* _class);
921 bool , Create(wxWindow *parent,
923 const wxString& value = wxPyEmptyString,
924 const wxPoint& pos = wxDefaultPosition,
925 const wxSize& size = wxDefaultSize,
926 const wxArrayString& choices = wxPyEmptyStringArray,
928 const wxValidator& validator = wxDefaultValidator,
929 const wxString& name = wxPyComboBoxNameStr),
930 "Create the UI object, and other initialization.", "");
934 virtual int , GetWidestItemWidth(),
935 "Return the widest item width (recalculating it if necessary.)", "");
939 virtual int , GetWidestItem(),
940 "Return the index of the widest item (recalculating it if necessary.)", "");
943 void SetSelection(int n);
944 %Rename(SetMark, void , SetSelection(long from, long to));
947 // Callback for drawing. Font, background and text colour have been
948 // prepared according to selection, focus and such.
949 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
950 // and there is no valid selection
951 // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
953 virtual void , OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const,
954 "The derived class may implement this function to actually draw the
955 item with the given index on the provided DC. If this method is not
956 overridden, the item text is simply drawn as if the control was a
959 :param dc: The device context to use for drawing.
960 :param rect: The bounding rectangle for the item being drawn, the
961 DC's clipping region is set to this rectangle before
963 :param item: The index of the item to be drawn.
965 :param flags: ``wx.combo.ODCB_PAINTING_CONTROL`` (The Combo control itself
966 is being painted, instead of a list item. The ``item``
967 parameter may be ``wx.NOT_FOUND`` in this case.
968 ``wx.combo.ODCB_PAINTING_SELECTED`` (An item with
969 selection background is being painted. The DC's text colour
970 should already be correct.
975 virtual wxCoord , OnMeasureItem( size_t item ) const,
976 "The derived class may implement this method to return the height of
977 the specified item (in pixels). The default implementation returns
978 text height, as if this control was a normal combobox.", "");
982 virtual wxCoord , OnMeasureItemWidth( size_t item ) const,
983 "The derived class may implement this method to return the width of the
984 specified item (in pixels). If -1 is returned, then the item text
985 width is used. The default implementation returns -1.", "");
989 virtual void , OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const,
990 "This method is used to draw the items background and, maybe, a border
993 The base class version implements a reasonable default behaviour which
994 consists in drawing the selected item with the standard background
995 colour and drawing a border around the item if it is either selected
996 or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1002 //---------------------------------------------------------------------------
1005 // Map renamed classes back to their common name for OOR
1006 wxPyPtrTypeMap_Add("wxComboCtrl", "wxPyComboCtrl");
1007 wxPyPtrTypeMap_Add("wxComboPopup", "wxPyComboPopup");
1008 wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
1010 //---------------------------------------------------------------------------