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.
196 ==================== ============================================
197 wx.CB_READONLY Text will not be editable.
198 wx.CB_SORT Sorts the entries in the list alphabetically.
199 wx.TE_PROCESS_ENTER The control will generate the event
200 EVT_TEXT_ENTER (otherwise pressing Enter key
201 is either processed internally by the control
202 or used for navigation between dialog controls).
203 wx.CC_SPECIAL_DCLICK Double-clicking triggers a call to popup's
204 OnComboDoubleClick. Actual behaviour is defined
205 by a derived class. For instance,
206 OwnerDrawnComboBox will cycle an item. This
207 style only applies if wx.CB_READONLY is used
209 wx.CC_STD_BUTTON Drop button will behave more like a standard
211 ==================== ============================================
214 MustHaveApp(wxPyComboCtrl);
215 %rename(ComboCtrl) wxPyComboCtrl;
217 class wxPyComboCtrl : public wxControl
220 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
221 %pythonAppend wxPyComboCtrl() "";
224 wxPyComboCtrl(wxWindow *parent,
225 wxWindowID id = wxID_ANY,
226 const wxString& value = wxEmptyString,
227 const wxPoint& pos = wxDefaultPosition,
228 const wxSize& size = wxDefaultSize,
230 const wxValidator& validator = wxDefaultValidator,
231 const wxString& name = wxPyComboBoxNameStr),
240 void _setCallbackInfo(PyObject* self, PyObject* _class);
243 virtual void , ShowPopup(),
244 "Show the popup window.", "");
247 virtual void , HidePopup(),
248 "Dismisses the popup window.", "");
251 // Override for totally custom combo action
253 virtual void , OnButtonClick(),
254 "Implement in a derived class to define what happens on dropdown button
255 click. Default action is to show the popup. ", "");
258 // return true if the popup is currently shown
260 bool , IsPopupShown() const,
261 "Returns true if the popup is currently shown.", "");
264 %disownarg(wxPyComboPopup* popup);
266 void , SetPopupControl( wxPyComboPopup* popup ),
267 "Set popup interface class derived from `wx.combo.ComboPopup`. This
268 method should be called as soon as possible after the control has been
269 created, unless `OnButtonClick` has been overridden.", "");
270 %cleardisown(wxPyComboPopup* popup);
274 wxPyComboPopup* , GetPopupControl(),
275 "Returns the current popup interface that has been set with
276 `SetPopupControl`.", "");
280 wxWindow *, GetPopupWindow() const,
281 "Returns the popup window containing the popup control.", "");
285 wxTextCtrl *, GetTextCtrl() const,
286 "Get the text control which is part of the combo control.", "");
290 wxWindow *, GetButton() const,
291 "Get the dropdown button which is part of the combobox. Note: it's not
292 necessarily a wx.Button or wx.BitmapButton.", "");
295 // NOTE: These are virtuals defined in a base class, so there
296 // shouldn't be any reason to provide SWIG wrappers for them...
297 // // forward these methods to all subcontrols
298 // virtual bool Enable(bool enable = true);
299 // virtual bool Show(bool show = true);
300 // virtual bool SetFont(const wxFont& font);
301 // virtual void SetValidator(const wxValidator &validator);
302 // virtual wxValidator *GetValidator();
305 // wxTextCtrl methods - for readonly combo they should return
309 virtual wxString , GetValue() const,
310 "Returns text representation of the current value. For writable combo
311 control it always returns the value in the text field.", "");
314 virtual void , SetValue(const wxString& value),
315 "Sets the text for the combo control text field. For a combo control
316 with wx.CB_READONLY style the string must be accepted by the popup (for
317 instance, exist in the dropdown list), otherwise the call to
318 SetValue is ignored.", "");
322 virtual void Paste();
323 virtual void SetInsertionPoint(long pos);
324 virtual void SetInsertionPointEnd();
325 virtual long GetInsertionPoint() const;
326 virtual long GetLastPosition() const;
327 virtual void Replace(long from, long to, const wxString& value);
328 virtual void Remove(long from, long to);
331 %Rename(SetMark, void , SetSelection(long from, long to));
335 void , SetText(const wxString& value),
336 "Sets the text for the text field without affecting the popup. Thus,
337 unlike `SetValue`, it works equally well with combo control using
338 wx.CB_READONLY style.", "");
342 void , SetValueWithEvent(const wxString& value, bool withEvent = true),
343 "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
347 // Popup customization methods
351 void , SetPopupMinWidth( int width ),
352 "Sets minimum width of the popup. If wider than combo control, it will
353 extend to the left. A value of -1 indicates to use the default. The
354 popup implementation may choose to ignore this.", "");
358 void , SetPopupMaxHeight( int height ),
359 "Sets preferred maximum height of the popup. A value of -1 indicates to
360 use the default. The popup implementation may choose to ignore this.", "");
364 void , SetPopupExtents( int extLeft, int extRight ),
365 "Extends popup size horizontally, relative to the edges of the combo
366 control. Values are given in pixels, and the defaults are zero. It
367 is up to the popup to fully take these values into account.", "");
371 void , SetCustomPaintWidth( int width ),
372 "Set width, in pixels, of custom painted area in control without
373 wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
374 to indicate the area that is not covered by the focus rectangle.", "");
376 int GetCustomPaintWidth() const;
380 void , SetPopupAnchor( int anchorSide ),
381 "Set side of the control to which the popup will align itself. Valid
382 values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
383 most appropriate side is used (which, currently, is always wx.LEFT).", "");
387 void , SetButtonPosition( int width = -1,
391 "Set the position of the dropdown button.", "");
395 wxSize , GetButtonSize(),
396 "Returns current size of the dropdown button.", "");
400 void , SetButtonBitmaps( const wxBitmap& bmpNormal,
401 bool pushButtonBg = false,
402 const wxBitmap& bmpPressed = wxNullBitmap,
403 const wxBitmap& bmpHover = wxNullBitmap,
404 const wxBitmap& bmpDisabled = wxNullBitmap ),
405 "Sets custom dropdown button graphics.
407 :param bmpNormal: Default button image
408 :param pushButtonBg: If ``True``, blank push button background is painted below the image.
409 :param bmpPressed: Depressed butotn image.
410 :param bmpHover: Button imate to use when the mouse hovers over it.
411 :param bmpDisabled: Disabled button image.
416 void , SetTextIndent( int indent ),
417 "This will set the space in pixels between left edge of the control and
418 the text, regardless whether control is read-only or not. A value of -1 can
419 be given to indicate platform default.", "");
423 wxCoord , GetTextIndent() const,
424 "Returns actual indentation in pixels.", "");
428 const wxRect& , GetTextRect() const,
429 "Returns area covered by the text field (includes everything except
430 borders and the dropdown button).", "");
434 void , UseAltPopupWindow( bool enable = true ),
435 "Enable or disable usage of an alternative popup window, which
436 guarantees ability to focus the popup control, and allows common
437 native controls to function normally. This alternative popup window is
438 usually a wxDialog, and as such, when it is shown, its parent
439 top-level window will appear as if the focus has been lost from it.", "");
443 void , EnablePopupAnimation( bool enable = true ),
444 "Enables or disables popup animation, if any, depending on the value of
449 // Utilies needed by the popups or native implementations
453 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
454 "Returns true if given key combination should toggle the popup.", "");
458 virtual void , PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const,
459 "Prepare background of combo control or an item in a dropdown list in a
460 way typical on platform. This includes painting the focus/disabled
461 background and setting the clipping region. Unless you plan to paint
462 your own focus indicator, you should always call this in your
463 wxComboPopup::PaintComboControl implementation. In addition, it sets
464 pen and text colour to what looks good and proper against the
467 flags are the same as wx.RendererNative flags:
469 ====================== ============================================
470 wx.CONTROL_ISSUBMENU drawing a list item instead of combo control
471 wx.CONTROL_SELECTED list item is selected
472 wx.CONTROL_DISABLED control/item is disabled
473 ====================== ============================================
479 bool , ShouldDrawFocus() const,
480 "Returns true if focus indicator should be drawn in the control.", "");
483 const wxBitmap& GetBitmapNormal() const;
484 const wxBitmap& GetBitmapPressed() const;
485 const wxBitmap& GetBitmapHover() const;
486 const wxBitmap& GetBitmapDisabled() const;
488 wxUint32 GetInternalFlags() const;
491 bool , IsCreated() const,
492 "Return true if Create has finished", "");
496 void , OnPopupDismiss(),
497 "Common code to be called on popup hide/dismiss", "");
509 bool IsPopupWindowState( int state ) const;
511 int GetPopupWindowState() const;
513 // Set value returned by GetMainWindowOfCompositeControl
514 void SetCtrlMainWnd( wxWindow* wnd );
515 virtual wxWindow *GetMainWindowOfCompositeControl();
518 static int , GetFeatures(),
519 "Returns a bit-list of flags indicating which features of the ComboCtrl
520 functionality are implemented by this implemetation. See
521 `wx.combo.ComboCtrlFeatures`.", "");
525 // Flags for DoShowPopup and AnimateShow
528 ShowBelow = 0x0000, // Showing popup below the control
529 ShowAbove = 0x0001, // Showing popup above the control
530 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
533 // Shows and positions the popup.
535 virtual void , DoShowPopup( const wxRect& rect, int flags ),
536 "Shows and positions the popup.
539 ============ =====================================================
540 ShowBelow Showing popup below the control
541 ShowAbove Showing popup above the control
542 CanDeferShow Can only return true from AnimateShow if this is set
543 ============ =====================================================
549 virtual bool , AnimateShow( const wxRect& rect, int flags ),
550 "Implement in derived class to create a drop-down animation. Return
551 ``True`` if finished immediately. Otherwise the popup is only shown when the
552 derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
556 %property(PopupControl, GetPopupControl, SetPopupControl);
557 %property(PopupWindow, GetPopupWindow);
558 %property(TextCtrl, GetTextCtrl);
559 %property(Button, GetButton);
560 %property(Value, GetValue, SetValue);
561 %property(InsertionPoint, GetInsertionPoint);
562 %property(CustomPaintWidth, GetCustomPaintWidth, SetCustomPaintWidth);
563 %property(ButtonSize, GetButtonSize);
564 %property(TextIndent, GetTextIndent, SetTextIndent);
565 %property(TextRect, GetTextRect);
566 %property(BitmapNormal, GetBitmapNormal);
567 %property(BitmapPressed, GetBitmapPressed);
568 %property(BitmapHover, GetBitmapHover);
569 %property(BitmapDisabled, GetBitmapDisabled);
570 %property(PopupWindowState, GetPopupWindowState);
574 //---------------------------------------------------------------------------
578 // C++ implemetation of Python aware wxComboCtrl
580 class wxPyComboPopup : public wxComboPopup
583 wxPyComboPopup() : wxComboPopup() {}
587 DEC_PYCALLBACK_VOID_(Init);
588 DEC_PYCALLBACK_BOOL_WXWIN_pure(Create);
589 DEC_PYCALLBACK_VOID_(OnPopup);
590 DEC_PYCALLBACK_VOID_(OnDismiss);
591 DEC_PYCALLBACK__STRING(SetStringValue);
592 DEC_PYCALLBACK_STRING__constpure(GetStringValue);
593 DEC_PYCALLBACK_VOID_(OnComboDoubleClick);
594 DEC_PYCALLBACK_BOOL_(LazyCreate);
596 virtual wxWindow *GetControl()
598 wxWindow* rval = NULL;
599 const char* errmsg = "GetControl should return an object derived from wx.Window.";
600 wxPyBlock_t blocked = wxPyBeginBlockThreads();
601 if (wxPyCBH_findCallback(m_myInst, "GetControl")) {
603 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
605 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
606 PyErr_SetString(PyExc_TypeError, errmsg);
611 PyErr_SetString(PyExc_TypeError, errmsg);
612 wxPyEndBlockThreads(blocked);
617 virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
620 wxPyBlock_t blocked = wxPyBeginBlockThreads();
621 if ((found = wxPyCBH_findCallback(m_myInst, "PaintComboControl"))) {
622 PyObject* odc = wxPyMake_wxObject(&dc,false);
623 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
624 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
628 wxPyEndBlockThreads(blocked);
630 wxComboPopup::PaintComboControl(dc, rect);
634 virtual void OnComboKeyEvent( wxKeyEvent& event )
637 wxPyBlock_t blocked = wxPyBeginBlockThreads();
638 if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
639 PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
640 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
643 wxPyEndBlockThreads(blocked);
645 wxComboPopup::OnComboKeyEvent(event);
649 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
651 const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
654 wxSize* rptr = &rval;
655 wxPyBlock_t blocked = wxPyBeginBlockThreads();
656 if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
658 ro = wxPyCBH_callCallbackObj(
659 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
661 if (! wxSize_helper(ro, &rptr))
662 PyErr_SetString(PyExc_TypeError, errmsg);
668 wxPyEndBlockThreads(blocked);
670 rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
674 wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
680 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
681 IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
682 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
683 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
684 IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
685 IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
686 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
687 IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
693 // Now declare wxPyComboPopup for Python
694 DocStr(wxPyComboPopup,
695 "In order to use a custom popup with `wx.combo.ComboCtrl` an interface
696 class derived from wx.combo.ComboPopup is used to manage the interface
697 between the popup control and the popup. You can either derive a new
698 class from both the widget class and this ComboPopup class, or the
699 derived class can have a reference to the widget used for the popup.
700 In either case you simply need to return the widget from the
701 `GetControl` method to allow the ComboCtrl to interact with it.
703 Nearly all of the methods of this class are overridable in Python.", "");
706 MustHaveApp(wxPyComboPopup);
707 %rename(ComboPopup) wxPyComboPopup;
712 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
723 void _setCallbackInfo(PyObject* self, PyObject* _class);
726 virtual void , Init(),
727 "This method is called after the popup is contructed and has been
728 assigned to the ComboCtrl. Derived classes can override this to do
729 extra inialization or whatever.", "");
732 // Create the popup child control.
733 // Return true for success.
735 virtual bool , Create(wxWindow* parent),
736 "The derived class must implement this method to create the popup
737 control. It should be a child of the ``parent`` passed in, but other
738 than that there is much flexibility in what the widget can be, its
739 style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
740 this return value is not currently checked...)", "");
744 virtual wxWindow *, GetControl(),
745 "The derived class must implement this method and it should return a
746 reference to the widget created in the `Create` method. If the
747 derived class inherits from both the widget class and ComboPopup then
748 the return value is probably just ``self``.", "");
752 virtual void , OnPopup(),
753 "The derived class may implement this to do special processing when
754 popup is shown.", "");
758 virtual void , OnDismiss(),
759 "The derived class may implement this to do special processing when
760 popup is hidden.", "");
764 virtual void , SetStringValue( const wxString& value ),
765 "Called just prior to displaying the popup. The derived class can
766 implement this to \"select\" the item in the popup that coresponds to
767 the passed in string value, if appropriate. The default
768 implementation does nothing.", "");
772 virtual wxString , GetStringValue() const,
773 "Gets the string representation of the currently selected value to be
774 used to display in the combo widget.", "");
778 virtual void , PaintComboControl( wxDC& dc, const wxRect& rect ),
779 "This is called to custom paint in the combo control itself (ie. not
780 the popup). Default implementation draws the current value as string.", "");
784 virtual void , OnComboKeyEvent( wxKeyEvent& event ),
785 "Receives key events from the parent ComboCtrl. Events not handled
786 should be skipped, as usual.", "");
790 virtual void , OnComboDoubleClick(),
791 "Implement this method in the derived class if you need to support
792 special actions when the user double-clicks on the parent ComboCtrl.", "");
796 virtual wxSize , GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ),
797 "The derived class may implement this method to return adjusted size
798 for the popup control, according to the variables given. It is called
799 on every popup, just prior to `OnPopup`.
801 :param minWidth: Preferred minimum width.
802 :param prefHeight: Preferred height. May be -1 to indicate no preference.
803 :maxWidth: Max height for window, as limited by screen size, and
804 should only be rounded down, if necessary.
809 virtual bool , LazyCreate(),
810 "The derived class may implement this to return ``True`` if it wants to
811 delay the call to `Create` until the popup is shown for the first
812 time. It is more efficient, but on the other hand it is often more
813 convenient to have the control created immediately. The default
814 implementation returns ``False``.", "");
824 "Hides the popup", "");
828 bool , IsCreated() const,
829 "Returns true if `Create` has been called.", "");
833 static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
835 const wxRect& rect ),
836 "Default PaintComboControl behaviour", "");
840 wxPyComboCtrl* , GetCombo(),
841 "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
842 is associated with.", "");
848 //---------------------------------------------------------------------------
853 wxODCB_DCLICK_CYCLES,
854 wxODCB_STD_CONTROL_PAINT,
855 wxODCB_PAINTING_CONTROL,
856 wxODCB_PAINTING_SELECTED
861 // C++ implemetation of Python aware wxOwnerDrawnComboBox
863 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
866 wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
867 wxPyOwnerDrawnComboBox(wxWindow *parent,
869 const wxString& value,
872 const wxArrayString& choices,
874 const wxValidator& validator = wxDefaultValidator,
875 const wxString& name = wxPyComboBoxNameStr)
876 : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
880 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawItem);
881 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItem);
882 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItemWidth);
883 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawBackground);
889 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
890 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
891 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
892 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
898 // Now declare wxPyOwnerDrawnComboBox for Python
900 DocStr(wxPyOwnerDrawnComboBox,
901 "wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
902 items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
903 popup and a `wx.ControlWithItems` API.
905 Implementing item drawing and measuring is similar to wx.VListBox.
906 The application needs to subclass wx.combo.OwnerDrawnComboBox and
907 implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
910 MustHaveApp(wxPyOwnerDrawnComboBox);
911 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
913 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
914 public wxItemContainer
917 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
918 %pythonAppend wxPyOwnerDrawnComboBox() "";
921 wxPyOwnerDrawnComboBox(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 "Standard constructor.", "");
932 DocCtorStrName(wxPyOwnerDrawnComboBox(),
933 "2-phase create constructor.", "",
934 PreOwnerDrawnComboBox);
936 void _setCallbackInfo(PyObject* self, PyObject* _class);
940 bool , Create(wxWindow *parent,
942 const wxString& value = wxPyEmptyString,
943 const wxPoint& pos = wxDefaultPosition,
944 const wxSize& size = wxDefaultSize,
945 const wxArrayString& choices = wxPyEmptyStringArray,
947 const wxValidator& validator = wxDefaultValidator,
948 const wxString& name = wxPyComboBoxNameStr),
949 "Create the UI object, and other initialization.", "");
953 virtual int , GetWidestItemWidth(),
954 "Return the widest item width (recalculating it if necessary.)", "");
958 virtual int , GetWidestItem(),
959 "Return the index of the widest item (recalculating it if necessary.)", "");
962 void SetSelection(int n);
963 %Rename(SetMark, void , SetSelection(long from, long to));
966 // Callback for drawing. Font, background and text colour have been
967 // prepared according to selection, focus and such.
968 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
969 // and there is no valid selection
970 // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
972 virtual void , OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const,
973 "The derived class may implement this function to actually draw the
974 item with the given index on the provided DC. If this method is not
975 overridden, the item text is simply drawn as if the control was a
978 :param dc: The device context to use for drawing.
979 :param rect: The bounding rectangle for the item being drawn, the
980 DC's clipping region is set to this rectangle before
982 :param item: The index of the item to be drawn.
984 :param flags: ``wx.combo.ODCB_PAINTING_CONTROL`` (The Combo control itself
985 is being painted, instead of a list item. The ``item``
986 parameter may be ``wx.NOT_FOUND`` in this case.
987 ``wx.combo.ODCB_PAINTING_SELECTED`` (An item with
988 selection background is being painted. The DC's text colour
989 should already be correct.
994 virtual wxCoord , OnMeasureItem( size_t item ) const,
995 "The derived class may implement this method to return the height of
996 the specified item (in pixels). The default implementation returns
997 text height, as if this control was a normal combobox.", "");
1001 virtual wxCoord , OnMeasureItemWidth( size_t item ) const,
1002 "The derived class may implement this method to return the width of the
1003 specified item (in pixels). If -1 is returned, then the item text
1004 width is used. The default implementation returns -1.", "");
1008 virtual void , OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const,
1009 "This method is used to draw the items background and, maybe, a border
1012 The base class version implements a reasonable default behaviour which
1013 consists in drawing the selected item with the standard background
1014 colour and drawing a border around the item if it is either selected
1015 or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1020 //---------------------------------------------------------------------------
1023 #include <wx/bmpcbox.h>
1026 DocStr(wxBitmapComboBox,
1027 "A combobox that displays a bitmap in front of the list items. It
1028 currently only allows using bitmaps of one size, and resizes itself so
1029 that a bitmap can be shown next to the text field.",
1034 =================== ============================================
1035 wx.CB_READONLY Creates a combobox without a text editor. On
1036 some platforms the control may appear very
1037 different when this style is used.
1038 wx.CB_SORT Sorts the entries in the list alphabetically.
1039 wx.TE_PROCESS_ENTER The control will generate the event
1040 wx.EVT__TEXT_ENTER (otherwise pressing Enter
1041 key is either processed internally by the
1042 control or used for navigation between dialog
1044 =================== ============================================
1047 MustHaveApp(wxBitmapComboBox);
1049 class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1052 %pythonAppend wxBitmapComboBox "self._setOORInfo(self);";
1053 %pythonAppend wxBitmapComboBox() "";
1056 wxBitmapComboBox(wxWindow *parent,
1058 const wxString& value = wxPyEmptyString,
1059 const wxPoint& pos = wxDefaultPosition,
1060 const wxSize& size = wxDefaultSize,
1061 const wxArrayString& choices = wxPyEmptyStringArray,
1063 const wxValidator& validator = wxDefaultValidator,
1064 const wxString& name = wxBitmapComboBoxNameStr),
1065 "Standard constructor", "");
1067 DocCtorStrName(wxBitmapComboBox(),
1068 "2-phase create constructor.", "",
1072 bool , Create(wxWindow *parent,
1074 const wxString& value = wxPyEmptyString,
1075 const wxPoint& pos = wxDefaultPosition,
1076 const wxSize& size = wxDefaultSize,
1077 const wxArrayString& choices = wxPyEmptyStringArray,
1079 const wxValidator& validator = wxDefaultValidator,
1080 const wxString& name = wxBitmapComboBoxNameStr),
1081 "Create the UI object, and other initialization.", "");
1087 "Adds the item to the control, associating the given data with the item
1088 if not None. The return value is the index of the newly added item.", "");
1089 int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap, PyObject* clientData=NULL) {
1091 wxPyClientData* data = new wxPyClientData(clientData);
1092 return self->Append(item, bitmap, data);
1094 return self->Append(item, bitmap);
1100 virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
1101 "Returns the image of the item with the given index.", "");
1106 "Insert an item into the control before the item at the ``pos`` index,
1107 optionally associating some data object with the item.", "");
1108 int Insert(const wxString& item, const wxBitmap& bitmap,
1109 /*unsigned*/ int pos, PyObject* clientData=NULL) {
1111 wxPyClientData* data = new wxPyClientData(clientData);
1112 return self->Insert(item, bitmap, pos, data);
1114 return self->Insert(item, bitmap, pos);
1120 virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
1121 "Sets the image for the given item.", "");
1125 virtual wxSize , GetBitmapSize() const,
1126 "Returns size of the image used in list.", "");
1131 //---------------------------------------------------------------------------
1134 // Map renamed classes back to their common name for OOR
1135 wxPyPtrTypeMap_Add("wxComboCtrl", "wxPyComboCtrl");
1136 wxPyPtrTypeMap_Add("wxComboPopup", "wxPyComboPopup");
1137 wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
1139 //---------------------------------------------------------------------------