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,
 
  52     // Drop-button stays down as long as popup is displayed.    
 
  53     wxCC_BUTTON_STAYS_DOWN          = 0x0008,
 
  54     // Drop-button covers the entire control.
 
  55     wxCC_FULL_BUTTON                = 0x0010,
 
  56     // Drop-button goes over the custom-border (used under WinVista).
 
  57     wxCC_BUTTON_COVERS_BORDER       = 0x0020,
 
  62 // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
 
  65     wxCC_MF_ON_BUTTON               =   0x0001, // cursor is on dropbutton area
 
  66     wxCC_MF_ON_CLICK_AREA           =   0x0002  // cursor is on dropbutton or other area
 
  67                                                 // that can be clicked to show the popup.
 
  71 DocStr( wxComboCtrlFeatures,
 
  72         "Namespace for `wx.combo.ComboCtrl` feature flags.  See
 
  73 `wx.combo.ComboCtrl.GetFeatures`.", "");
 
  74 struct wxComboCtrlFeatures
 
  78         MovableButton       = 0x0001, // Button can be on either side of control
 
  79         BitmapButton        = 0x0002, // Button may be replaced with bitmap
 
  80         ButtonSpacing       = 0x0004, // Button can have spacing from the edge
 
  82         TextIndent          = 0x0008, // SetTextIndent can be used
 
  83         PaintControl        = 0x0010, // Combo control itself can be custom painted
 
  84         PaintWritable       = 0x0020, // A variable-width area in front of writable
 
  85                                       // combo control's textctrl can be custom
 
  87         Borderless          = 0x0040, // wxNO_BORDER window style works
 
  89         // There are no feature flags for...
 
  90         // PushButtonBitmapBackground - if its in wxRendererNative, then it should be
 
  91         //   not an issue to have it automatically under the bitmap.
 
  93         All                 = MovableButton|BitmapButton|
 
  94                               ButtonSpacing|TextIndent|
 
  95                               PaintControl|PaintWritable|
 
 100 //---------------------------------------------------------------------------
 
 102 // C++ implemetation of Python aware wxComboCtrl
 
 104 class wxPyComboCtrl : public wxComboCtrl
 
 106     DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
 
 108     wxPyComboCtrl() : wxComboCtrl() {}
 
 109     wxPyComboCtrl(wxWindow *parent,
 
 110                   wxWindowID id = wxID_ANY,
 
 111                   const wxString& value = wxEmptyString,
 
 112                   const wxPoint& pos = wxDefaultPosition,
 
 113                   const wxSize& size = wxDefaultSize,
 
 115                   const wxValidator& validator = wxDefaultValidator,
 
 116                   const wxString& name = wxPyComboBoxNameStr)
 
 117         : wxComboCtrl(parent, id, value, pos, size, style, validator, name)
 
 120     void DoSetPopupControl(wxComboPopup* popup)
 
 123         wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 124         if ((found = wxPyCBH_findCallback(m_myInst, "DoSetPopupControl"))) {
 
 125             PyObject* obj = wxPyConstructObject(popup, wxT("wxComboPopup"), false);
 
 126             wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)",obj));
 
 129         wxPyEndBlockThreads(blocked);
 
 131             wxComboCtrl::DoSetPopupControl(popup);
 
 134     virtual bool IsKeyPopupToggle( const wxKeyEvent& event ) const
 
 138         wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 139         if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
 
 140             PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
 
 141             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
 
 144         wxPyEndBlockThreads(blocked);
 
 146             rval = wxComboCtrl::IsKeyPopupToggle(event);
 
 151     virtual wxWindow *GetMainWindowOfCompositeControl()
 
 153         return wxComboCtrl::GetMainWindowOfCompositeControl();
 
 159         ShowBelow       = 0x0000,  // Showing popup below the control
 
 160         ShowAbove       = 0x0001,  // Showing popup above the control
 
 161         CanDeferShow    = 0x0002  // Can only return true from AnimateShow if this is set
 
 165     DEC_PYCALLBACK_VOID_(ShowPopup);
 
 166     DEC_PYCALLBACK_VOID_(HidePopup);
 
 167     DEC_PYCALLBACK_VOID_(OnButtonClick);
 
 168     DEC_PYCALLBACK__RECTINT(DoShowPopup);
 
 169     DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
 
 174 IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
 
 176 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
 
 177 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
 
 178 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
 
 179 IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
 
 180 IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
 
 186 // Now declare wxPyComboCtrl for Python
 
 188 DocStr(wxPyComboCtrl,
 
 189 "A combo control is a generic combobox that allows for a totally custom
 
 190 popup. In addition it has other customization features. For instance,
 
 191 position and size of the dropdown button can be changed.
 
 193 To specify what to use for the popup control you need to derive a
 
 194 class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
 
 195 `SetPopupControl`.  It doesn't derive from any widget class so it can
 
 196 be used either as a mixin class combined with some standard or custom
 
 197 widget, or you can use the derived ComboPopup to create and hold an
 
 198 independent reference to the widget to be used for the popup.
 
 203     ====================   ============================================
 
 204     wx.CB_READONLY         Text will not be editable.
 
 205     wx.CB_SORT             Sorts the entries in the list alphabetically.
 
 206     wx.TE_PROCESS_ENTER    The control will generate the event
 
 207                            EVT_TEXT_ENTER (otherwise pressing Enter key
 
 208                            is either processed internally by the control
 
 209                            or used for navigation between dialog controls).
 
 210     wx.CC_SPECIAL_DCLICK   Double-clicking triggers a call to popup's
 
 211                            OnComboDoubleClick. Actual behaviour is defined
 
 212                            by a derived class. For instance,
 
 213                            OwnerDrawnComboBox will cycle an item. This
 
 214                            style only applies if wx.CB_READONLY is used
 
 216     wx.CC_STD_BUTTON       Drop button will behave more like a standard
 
 218     ====================   ============================================
 
 221 MustHaveApp(wxPyComboCtrl);
 
 222 %rename(ComboCtrl) wxPyComboCtrl;
 
 224 class wxPyComboCtrl : public wxControl
 
 227     %pythonAppend wxPyComboCtrl      "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
 
 228     %pythonAppend wxPyComboCtrl()    "";
 
 231         wxPyComboCtrl(wxWindow *parent,
 
 232                       wxWindowID id = wxID_ANY,
 
 233                       const wxString& value = wxEmptyString,
 
 234                       const wxPoint& pos = wxDefaultPosition,
 
 235                       const wxSize& size = wxDefaultSize,
 
 237                       const wxValidator& validator = wxDefaultValidator,
 
 238                       const wxString& name = wxPyComboBoxNameStr),
 
 247     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 250         virtual void , ShowPopup(),
 
 251         "Show the popup window.", "");
 
 254         virtual void , HidePopup(),
 
 255         "Dismisses the popup window.", "");
 
 258     // Override for totally custom combo action
 
 260         virtual void , OnButtonClick(),
 
 261         "Implement in a derived class to define what happens on dropdown button
 
 262 click.  Default action is to show the popup. ", "");
 
 265     // return true if the popup is currently shown
 
 267         bool , IsPopupShown() const,
 
 268         "Returns true if the popup is currently shown.", "");
 
 271     %disownarg(wxPyComboPopup* popup);
 
 273         void , SetPopupControl( wxPyComboPopup* popup ),
 
 274         "Set popup interface class derived from `wx.combo.ComboPopup`. This
 
 275 method should be called as soon as possible after the control has been
 
 276 created, unless `OnButtonClick` has been overridden.", "");
 
 277     %cleardisown(wxPyComboPopup* popup);
 
 281         wxPyComboPopup* , GetPopupControl(),
 
 282         "Returns the current popup interface that has been set with
 
 283 `SetPopupControl`.", "");
 
 287         wxWindow *, GetPopupWindow() const,
 
 288         "Returns the popup window containing the popup control.", "");
 
 292         wxTextCtrl *, GetTextCtrl() const,
 
 293         "Get the text control which is part of the combo control.", "");
 
 297         wxWindow *, GetButton() const,
 
 298         "Get the dropdown button which is part of the combobox.  Note: it's not
 
 299 necessarily a wx.Button or wx.BitmapButton.", "");
 
 302 // NOTE: These are virtuals defined in a base class, so there
 
 303 // shouldn't be any reason to provide SWIG wrappers for them...    
 
 304 //     // forward these methods to all subcontrols
 
 305 //     virtual bool Enable(bool enable = true);
 
 306 //     virtual bool Show(bool show = true);
 
 307 //     virtual bool SetFont(const wxFont& font);
 
 308 //     virtual void SetValidator(const wxValidator &validator);
 
 309 //     virtual wxValidator *GetValidator();
 
 312     // wxTextCtrl methods - for readonly combo they should return
 
 316         virtual wxString , GetValue() const,
 
 317         "Returns text representation of the current value. For writable combo
 
 318 control it always returns the value in the text field.", "");
 
 321         virtual void , SetValue(const wxString& value),
 
 322         "Sets the text for the combo control text field.  For a combo control
 
 323 with wx.CB_READONLY style the string must be accepted by the popup (for
 
 324 instance, exist in the dropdown list), otherwise the call to
 
 325 SetValue is ignored.", "");
 
 329     virtual void Paste();
 
 330     virtual void SetInsertionPoint(long pos);
 
 331     virtual void SetInsertionPointEnd();
 
 332     virtual long GetInsertionPoint() const;
 
 333     virtual long GetLastPosition() const;
 
 334     virtual void Replace(long from, long to, const wxString& value);
 
 335     virtual void Remove(long from, long to);
 
 338     %Rename(SetMark, void , SetSelection(long from, long to));
 
 342         void , SetText(const wxString& value),
 
 343         "Sets the text for the text field without affecting the popup. Thus,
 
 344 unlike `SetValue`, it works equally well with combo control using
 
 345 wx.CB_READONLY style.", "");
 
 349         void , SetValueWithEvent(const wxString& value, bool withEvent = true),
 
 350         "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
 
 354     // Popup customization methods
 
 358         void , SetPopupMinWidth( int width ),
 
 359         "Sets minimum width of the popup. If wider than combo control, it will
 
 360 extend to the left.  A value of -1 indicates to use the default.  The
 
 361 popup implementation may choose to ignore this.", "");
 
 365         void , SetPopupMaxHeight( int height ),
 
 366         "Sets preferred maximum height of the popup. A value of -1 indicates to
 
 367 use the default.  The popup implementation may choose to ignore this.", "");
 
 371         void , SetPopupExtents( int extLeft, int extRight ),
 
 372         "Extends popup size horizontally, relative to the edges of the combo
 
 373 control.  Values are given in pixels, and the defaults are zero.  It
 
 374 is up to the popup to fully take these values into account.", "");
 
 378         void , SetCustomPaintWidth( int width ),
 
 379         "Set width, in pixels, of custom painted area in control without
 
 380 wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
 
 381 to indicate the area that is not covered by the focus rectangle.", "");
 
 383     int GetCustomPaintWidth() const;
 
 387         void , SetPopupAnchor( int anchorSide ),
 
 388         "Set side of the control to which the popup will align itself. Valid
 
 389 values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
 
 390 most appropriate side is used (which, currently, is always wx.LEFT).", "");
 
 394         void , SetButtonPosition( int width = -1,
 
 398         "Set the position of the dropdown button.", "");
 
 402         wxSize , GetButtonSize(),
 
 403         "Returns current size of the dropdown button.", "");
 
 407         void , SetButtonBitmaps( const wxBitmap& bmpNormal,
 
 408                                  bool pushButtonBg = false,
 
 409                                  const wxBitmap& bmpPressed = wxNullBitmap,
 
 410                                  const wxBitmap& bmpHover = wxNullBitmap,
 
 411                                  const wxBitmap& bmpDisabled = wxNullBitmap ),
 
 412         "Sets custom dropdown button graphics.
 
 414     :param bmpNormal:  Default button image
 
 415     :param pushButtonBg: If ``True``, blank push button background is painted below the image.
 
 416     :param bmpPressed:  Depressed butotn image.
 
 417     :param bmpHover:  Button imate to use when the mouse hovers over it.
 
 418     :param bmpDisabled: Disabled button image.
 
 423         void , SetTextIndent( int indent ),
 
 424         "This will set the space in pixels between left edge of the control and
 
 425 the text, regardless whether control is read-only or not. A value of -1 can
 
 426 be given to indicate platform default.", "");
 
 430         wxCoord , GetTextIndent() const,
 
 431         "Returns actual indentation in pixels.", "");
 
 435         const wxRect& , GetTextRect() const,
 
 436         "Returns area covered by the text field (includes everything except
 
 437 borders and the dropdown button).", "");
 
 441         void , UseAltPopupWindow( bool enable = true ),
 
 442         "Enable or disable usage of an alternative popup window, which
 
 443 guarantees ability to focus the popup control, and allows common
 
 444 native controls to function normally. This alternative popup window is
 
 445 usually a wxDialog, and as such, when it is shown, its parent
 
 446 top-level window will appear as if the focus has been lost from it.", "");
 
 450         void , EnablePopupAnimation( bool enable = true ),
 
 451         "Enables or disables popup animation, if any, depending on the value of
 
 456     // Utilies needed by the popups or native implementations
 
 460         virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
 
 461         "Returns true if given key combination should toggle the popup.", "");
 
 465         virtual void , PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const,
 
 466         "Prepare background of combo control or an item in a dropdown list in a
 
 467 way typical on platform. This includes painting the focus/disabled
 
 468 background and setting the clipping region.  Unless you plan to paint
 
 469 your own focus indicator, you should always call this in your
 
 470 wxComboPopup::PaintComboControl implementation.  In addition, it sets
 
 471 pen and text colour to what looks good and proper against the
 
 474 flags are the same as wx.RendererNative flags:
 
 476     ======================   ============================================
 
 477     wx.CONTROL_ISSUBMENU     drawing a list item instead of combo control
 
 478     wx.CONTROL_SELECTED      list item is selected
 
 479     wx.CONTROL_DISABLED       control/item is disabled
 
 480     ======================   ============================================
 
 486         bool , ShouldDrawFocus() const,
 
 487         "Returns true if focus indicator should be drawn in the control.", "");
 
 490     const wxBitmap& GetBitmapNormal() const;
 
 491     const wxBitmap& GetBitmapPressed() const;
 
 492     const wxBitmap& GetBitmapHover() const;
 
 493     const wxBitmap& GetBitmapDisabled() const;
 
 495     wxUint32 GetInternalFlags() const;
 
 498         bool , IsCreated() const,
 
 499         "Return true if Create has finished", "");
 
 503         void , OnPopupDismiss(),
 
 504         "Common code to be called on popup hide/dismiss", "");
 
 516     bool IsPopupWindowState( int state ) const;
 
 518     int GetPopupWindowState() const;
 
 520     // Set value returned by GetMainWindowOfCompositeControl
 
 521     void SetCtrlMainWnd( wxWindow* wnd );
 
 522     virtual wxWindow *GetMainWindowOfCompositeControl();
 
 525         static int , GetFeatures(),
 
 526         "Returns a bit-list of flags indicating which features of the ComboCtrl
 
 527 functionality are implemented by this implemetation.  See
 
 528 `wx.combo.ComboCtrlFeatures`.", "");
 
 532     // Flags for DoShowPopup and AnimateShow
 
 535         ShowBelow       = 0x0000,  // Showing popup below the control
 
 536         ShowAbove       = 0x0001,  // Showing popup above the control
 
 537         CanDeferShow    = 0x0002  // Can only return true from AnimateShow if this is set
 
 540     // Shows and positions the popup.
 
 542         virtual void , DoShowPopup( const wxRect& rect, int flags ),
 
 543         "Shows and positions the popup.
 
 546     ============  =====================================================
 
 547     ShowBelow     Showing popup below the control
 
 548     ShowAbove     Showing popup above the control
 
 549     CanDeferShow  Can only return true from AnimateShow if this is set
 
 550     ============  =====================================================
 
 556         virtual bool , AnimateShow( const wxRect& rect, int flags ),
 
 557         "Implement in derived class to create a drop-down animation.  Return
 
 558 ``True`` if finished immediately. Otherwise the popup is only shown when the
 
 559 derived class calls `DoShowPopup`.  Flags are same as for `DoShowPopup`.
 
 563     %property(PopupControl, GetPopupControl, SetPopupControl);
 
 564     %property(PopupWindow, GetPopupWindow);
 
 565     %property(TextCtrl, GetTextCtrl);
 
 566     %property(Button, GetButton);
 
 567     %property(Value, GetValue, SetValue);
 
 568     %property(InsertionPoint, GetInsertionPoint);
 
 569     %property(CustomPaintWidth, GetCustomPaintWidth, SetCustomPaintWidth);
 
 570     %property(ButtonSize, GetButtonSize);
 
 571     %property(TextIndent, GetTextIndent, SetTextIndent);
 
 572     %property(TextRect, GetTextRect);
 
 573     %property(BitmapNormal, GetBitmapNormal);
 
 574     %property(BitmapPressed, GetBitmapPressed);
 
 575     %property(BitmapHover, GetBitmapHover);
 
 576     %property(BitmapDisabled, GetBitmapDisabled);
 
 577     %property(PopupWindowState, GetPopupWindowState);
 
 581 //---------------------------------------------------------------------------
 
 585 // C++ implemetation of Python aware wxComboCtrl
 
 587 class wxPyComboPopup : public wxComboPopup
 
 590     wxPyComboPopup() : wxComboPopup() {}
 
 594     DEC_PYCALLBACK_VOID_(Init);
 
 595     DEC_PYCALLBACK_BOOL_WXWIN_pure(Create);
 
 596     DEC_PYCALLBACK_VOID_(OnPopup);
 
 597     DEC_PYCALLBACK_VOID_(OnDismiss);
 
 598     DEC_PYCALLBACK__STRING(SetStringValue);
 
 599     DEC_PYCALLBACK_STRING__constpure(GetStringValue);
 
 600     DEC_PYCALLBACK_VOID_(OnComboDoubleClick);
 
 601     DEC_PYCALLBACK_BOOL_(LazyCreate);
 
 603     virtual wxWindow *GetControl()
 
 605         wxWindow* rval = NULL;
 
 606         const char* errmsg = "GetControl should return an object derived from wx.Window.";
 
 607         wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 608         if (wxPyCBH_findCallback(m_myInst, "GetControl")) {
 
 610             ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
 
 612                 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
 
 613                     PyErr_SetString(PyExc_TypeError, errmsg);
 
 618             PyErr_SetString(PyExc_TypeError, errmsg);
 
 619         wxPyEndBlockThreads(blocked);
 
 624     virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
 
 627         wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 628         if ((found = wxPyCBH_findCallback(m_myInst, "PaintComboControl"))) {
 
 629             PyObject* odc = wxPyMake_wxObject(&dc,false);
 
 630             PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
 
 631             wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
 
 635         wxPyEndBlockThreads(blocked);
 
 637             wxComboPopup::PaintComboControl(dc, rect);
 
 641     virtual void OnComboKeyEvent( wxKeyEvent& event )
 
 644         wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 645         if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
 
 646             PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
 
 647             wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
 
 650         wxPyEndBlockThreads(blocked);
 
 652             wxComboPopup::OnComboKeyEvent(event);
 
 656     virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
 
 658         const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
 
 661         wxSize* rptr = &rval;
 
 662         wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 663         if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
 
 665             ro = wxPyCBH_callCallbackObj(
 
 666                 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
 
 668                 if (! wxSize_helper(ro, &rptr))
 
 669                     PyErr_SetString(PyExc_TypeError, errmsg);
 
 675         wxPyEndBlockThreads(blocked);
 
 677             rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
 
 681     wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
 
 687 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
 
 688 IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
 
 689 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
 
 690 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
 
 691 IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
 
 692 IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
 
 693 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
 
 694 IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
 
 700 // Now declare wxPyComboPopup for Python
 
 701 DocStr(wxPyComboPopup,
 
 702 "In order to use a custom popup with `wx.combo.ComboCtrl` an interface
 
 703 class derived from wx.combo.ComboPopup is used to manage the interface
 
 704 between the popup control and the popup.  You can either derive a new
 
 705 class from both the widget class and this ComboPopup class, or the
 
 706 derived class can have a reference to the widget used for the popup.
 
 707 In either case you simply need to return the widget from the
 
 708 `GetControl` method to allow the ComboCtrl to interact with it.
 
 710 Nearly all of the methods of this class are overridable in Python.", "");
 
 713 MustHaveApp(wxPyComboPopup);
 
 714 %rename(ComboPopup) wxPyComboPopup;
 
 719     %pythonAppend wxPyComboPopup  setCallbackInfo(ComboPopup);
 
 730     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 733         virtual void , Init(),
 
 734         "This method is called after the popup is contructed and has been
 
 735 assigned to the ComboCtrl.  Derived classes can override this to do
 
 736 extra inialization or whatever.", "");
 
 739     // Create the popup child control.
 
 740     // Return true for success.
 
 742         virtual bool , Create(wxWindow* parent),
 
 743         "The derived class must implement this method to create the popup
 
 744 control.  It should be a child of the ``parent`` passed in, but other
 
 745 than that there is much flexibility in what the widget can be, its
 
 746 style, etc.  Return ``True`` for success, ``False`` otherwise.  (NOTE:
 
 747 this return value is not currently checked...)", "");
 
 751         virtual wxWindow *, GetControl(),
 
 752         "The derived class must implement this method and it should return a
 
 753 reference to the widget created in the `Create` method.  If the
 
 754 derived class inherits from both the widget class and ComboPopup then
 
 755 the return value is probably just ``self``.", "");
 
 759         virtual void , OnPopup(),
 
 760         "The derived class may implement this to do special processing when
 
 761 popup is shown.", "");
 
 765         virtual void , OnDismiss(),
 
 766         "The derived class may implement this to do special processing when
 
 767 popup is hidden.", "");
 
 771         virtual void , SetStringValue( const wxString& value ),
 
 772         "Called just prior to displaying the popup.  The derived class can
 
 773 implement this to \"select\" the item in the popup that coresponds to
 
 774 the passed in string value, if appropriate.  The default
 
 775 implementation does nothing.", "");
 
 779         virtual wxString , GetStringValue() const,
 
 780         "Gets the string representation of the currently selected value to be
 
 781 used to display in the combo widget.", "");
 
 785         virtual void , PaintComboControl( wxDC& dc, const wxRect& rect ),
 
 786         "This is called to custom paint in the combo control itself (ie. not
 
 787 the popup).  Default implementation draws the current value as string.", "");
 
 791         virtual void , OnComboKeyEvent( wxKeyEvent& event ),
 
 792         "Receives key events from the parent ComboCtrl.  Events not handled
 
 793 should be skipped, as usual.", "");
 
 797         virtual void , OnComboDoubleClick(),
 
 798         "Implement this method in the derived class if you need to support
 
 799 special actions when the user double-clicks on the parent ComboCtrl.", "");
 
 803         virtual wxSize , GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ),
 
 804         "The derived class may implement this method to return adjusted size
 
 805 for the popup control, according to the variables given.  It is called
 
 806 on every popup, just prior to `OnPopup`.
 
 808     :param minWidth:    Preferred minimum width.
 
 809     :param prefHeight:  Preferred height. May be -1 to indicate no preference.
 
 810     :maxWidth:          Max height for window, as limited by screen size, and
 
 811                         should only be rounded down, if necessary.
 
 816         virtual bool , LazyCreate(),
 
 817         "The derived class may implement this to return ``True`` if it wants to
 
 818 delay the call to `Create` until the popup is shown for the first
 
 819 time. It is more efficient, but on the other hand it is often more
 
 820 convenient to have the control created immediately.  The default
 
 821 implementation returns ``False``.", "");
 
 831         "Hides the popup", "");
 
 835         bool , IsCreated() const,
 
 836         "Returns true if `Create` has been called.", "");
 
 840         static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
 
 842                                                 const wxRect& rect ),
 
 843         "Default PaintComboControl behaviour", "");
 
 847         wxPyComboCtrl* , GetCombo(),
 
 848         "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
 
 849 is associated with.", "");
 
 855 //---------------------------------------------------------------------------
 
 860     wxODCB_DCLICK_CYCLES,
 
 861     wxODCB_STD_CONTROL_PAINT,
 
 862     wxODCB_PAINTING_CONTROL,
 
 863     wxODCB_PAINTING_SELECTED
 
 868 // C++ implemetation of Python aware wxOwnerDrawnComboBox
 
 870 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
 
 873     wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
 
 874     wxPyOwnerDrawnComboBox(wxWindow *parent,
 
 876                            const wxString& value,
 
 879                            const wxArrayString& choices,
 
 881                            const wxValidator& validator = wxDefaultValidator,
 
 882                            const wxString& name = wxPyComboBoxNameStr)
 
 883         : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
 
 887     DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawItem);
 
 888     DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItem);
 
 889     DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItemWidth);
 
 890     DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawBackground);
 
 896 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
 
 897 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
 
 898 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
 
 899 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
 
 905 // Now declare wxPyOwnerDrawnComboBox for Python
 
 907 DocStr(wxPyOwnerDrawnComboBox,
 
 908 "wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
 
 909 items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
 
 910 popup and a `wx.ControlWithItems` API.
 
 912 Implementing item drawing and measuring is similar to wx.VListBox.
 
 913 The application needs to subclass wx.combo.OwnerDrawnComboBox and
 
 914 implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
 
 917 MustHaveApp(wxPyOwnerDrawnComboBox);
 
 918 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
 
 920 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
 
 921                                public wxItemContainer
 
 924     %pythonAppend wxPyOwnerDrawnComboBox      "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
 
 925     %pythonAppend wxPyOwnerDrawnComboBox()    "";
 
 928         wxPyOwnerDrawnComboBox(wxWindow *parent,
 
 930                                const wxString& value = wxPyEmptyString,
 
 931                                const wxPoint& pos = wxDefaultPosition,
 
 932                                const wxSize& size = wxDefaultSize,
 
 933                                const wxArrayString& choices = wxPyEmptyStringArray,
 
 935                                const wxValidator& validator = wxDefaultValidator,
 
 936                                const wxString& name = wxPyComboBoxNameStr),
 
 937         "Standard constructor.", "");
 
 939     DocCtorStrName(wxPyOwnerDrawnComboBox(),
 
 940                    "2-phase create constructor.", "",
 
 941                    PreOwnerDrawnComboBox);
 
 943     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 947         bool , Create(wxWindow *parent,
 
 949                       const wxString& value = wxPyEmptyString,
 
 950                       const wxPoint& pos = wxDefaultPosition,
 
 951                       const wxSize& size = wxDefaultSize,
 
 952                       const wxArrayString& choices = wxPyEmptyStringArray,
 
 954                       const wxValidator& validator = wxDefaultValidator,
 
 955                       const wxString& name = wxPyComboBoxNameStr),
 
 956         "Create the UI object, and other initialization.", "");
 
 960         virtual int , GetWidestItemWidth(),
 
 961         "Return the widest item width (recalculating it if necessary.)", "");
 
 965         virtual int , GetWidestItem(),
 
 966         "Return the index of the widest item (recalculating it if necessary.)", "");
 
 969     void SetSelection(int n);
 
 970     %Rename(SetMark, void , SetSelection(long from, long to));
 
 973     // Callback for drawing. Font, background and text colour have been
 
 974     // prepared according to selection, focus and such.
 
 975     // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
 
 976     //       and there is no valid selection
 
 977     // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
 
 979         virtual void , OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const,
 
 980         "The derived class may implement this function to actually draw the
 
 981 item with the given index on the provided DC. If this method is not
 
 982 overridden, the item text is simply drawn as if the control was a
 
 985    :param dc:    The device context to use for drawing.
 
 986    :param rect:  The bounding rectangle for the item being drawn, the
 
 987                  DC's clipping region is set to this rectangle before
 
 989    :param item:  The index of the item to be drawn.
 
 991    :param flags: ``wx.combo.ODCB_PAINTING_CONTROL`` (The Combo control itself
 
 992                   is being painted, instead of a list item.  The ``item``
 
 993                   parameter may be ``wx.NOT_FOUND`` in this case.
 
 994                   ``wx.combo.ODCB_PAINTING_SELECTED``  (An item with
 
 995                   selection background is being painted. The DC's text colour
 
 996                   should already be correct.
 
1001         virtual wxCoord , OnMeasureItem( size_t item ) const,
 
1002         "The derived class may implement this method to return the height of
 
1003 the specified item (in pixels).  The default implementation returns
 
1004 text height, as if this control was a normal combobox.", "");
 
1008         virtual wxCoord , OnMeasureItemWidth( size_t item ) const,
 
1009         "The derived class may implement this method to return the width of the
 
1010 specified item (in pixels). If -1 is returned, then the item text
 
1011 width is used.  The default implementation returns -1.", "");
 
1015         virtual void , OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const,
 
1016         "This method is used to draw the items background and, maybe, a border
 
1019 The base class version implements a reasonable default behaviour which
 
1020 consists in drawing the selected item with the standard background
 
1021 colour and drawing a border around the item if it is either selected
 
1022 or current.  ``flags`` has the sam meaning as with `OnDrawItem`.", "");
 
1027 //---------------------------------------------------------------------------
 
1030 #include <wx/bmpcbox.h>
 
1033 DocStr(wxBitmapComboBox,
 
1034        "A combobox that displays a bitmap in front of the list items. It
 
1035 currently only allows using bitmaps of one size, and resizes itself so
 
1036 that a bitmap can be shown next to the text field.",
 
1041     ===================    ============================================
 
1042     wx.CB_READONLY         Creates a combobox without a text editor. On
 
1043                            some platforms the control may appear very
 
1044                            different when this style is used. 
 
1045     wx.CB_SORT             Sorts the entries in the list alphabetically. 
 
1046     wx.TE_PROCESS_ENTER    The control will generate the event
 
1047                            wx.EVT__TEXT_ENTER (otherwise pressing Enter
 
1048                            key is either processed internally by the
 
1049                            control or used for navigation between dialog
 
1051     ===================    ============================================
 
1054 MustHaveApp(wxBitmapComboBox);
 
1056 class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
 
1059     %pythonAppend wxBitmapComboBox      "self._setOORInfo(self);";
 
1060     %pythonAppend wxBitmapComboBox()    "";
 
1063         wxBitmapComboBox(wxWindow *parent,
 
1065                          const wxString& value = wxPyEmptyString,
 
1066                          const wxPoint& pos = wxDefaultPosition,
 
1067                          const wxSize& size = wxDefaultSize,
 
1068                          const wxArrayString& choices = wxPyEmptyStringArray,
 
1070                          const wxValidator& validator = wxDefaultValidator,
 
1071                          const wxString& name = wxBitmapComboBoxNameStr),
 
1072         "Standard constructor", "");
 
1074     DocCtorStrName(wxBitmapComboBox(),
 
1075                    "2-phase create constructor.", "",
 
1079         bool , Create(wxWindow *parent,
 
1081                       const wxString& value = wxPyEmptyString,
 
1082                       const wxPoint& pos = wxDefaultPosition,
 
1083                       const wxSize& size = wxDefaultSize,
 
1084                       const wxArrayString& choices = wxPyEmptyStringArray,
 
1086                       const wxValidator& validator = wxDefaultValidator,
 
1087                       const wxString& name = wxBitmapComboBoxNameStr),
 
1088         "Create the UI object, and other initialization.", "");
 
1094                "Adds the item to the control, associating the given data with the item
 
1095 if not None.  The return value is the index of the newly added item.", "");
 
1096         int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap, PyObject* clientData=NULL) {
 
1098                 wxPyClientData* data = new wxPyClientData(clientData);
 
1099                 return self->Append(item, bitmap, data);
 
1101                 return self->Append(item, bitmap);
 
1107         virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
 
1108         "Returns the image of the item with the given index.", "");
 
1113                "Insert an item into the control before the item at the ``pos`` index,
 
1114 optionally associating some data object with the item.", "");
 
1115         int Insert(const wxString& item, const wxBitmap& bitmap,
 
1116                    /*unsigned*/ int pos, PyObject* clientData=NULL) {
 
1118                 wxPyClientData* data = new wxPyClientData(clientData);
 
1119                 return self->Insert(item, bitmap, pos, data);
 
1121                 return self->Insert(item, bitmap, pos);
 
1127         virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
 
1128         "Sets the image for the given item.", "");
 
1132         virtual wxSize , GetBitmapSize() const,
 
1133         "Returns size of the image used in list.", "");
 
1138 //---------------------------------------------------------------------------
 
1141     // Map renamed classes back to their common name for OOR
 
1142     wxPyPtrTypeMap_Add("wxComboCtrl", "wxPyComboCtrl");
 
1143     wxPyPtrTypeMap_Add("wxComboPopup", "wxPyComboPopup");
 
1144     wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
 
1146 //---------------------------------------------------------------------------