]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/combo.i
389afca86e0b571785d2b21d233eb7060600e803
[wxWidgets.git] / wxPython / src / combo.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: combo.i
3 // Purpose: SWIG interface for the owner-drawn combobox classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 11-Nov-2006
8 // RCS-ID: $Id$
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
14 "ComboCtrl class that can have any type of popup widget, and also an
15 owner-drawn combobox control."
16 %enddef
17
18 %module(package="wx", docstring=DOCSTRING) combo
19
20 %{
21 #include "wx/wxPython/wxPython.h"
22 #include "wx/wxPython/pyclasses.h"
23
24 #include <wx/combo.h>
25 #include <wx/odcombo.h>
26 %}
27
28 //---------------------------------------------------------------------------
29
30 %import windows.i
31 %pythoncode { wx = _core }
32 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
33
34 //---------------------------------------------------------------------------
35 %newgroup
36
37 MAKE_CONST_WXSTRING_NOSWIG(ComboBoxNameStr);
38 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
39
40 %{
41 const wxArrayString wxPyEmptyStringArray;
42 %}
43
44
45 enum {
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 };
53
54
55 // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
56 enum
57 {
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.
61 };
62
63
64 DocStr( wxComboCtrlFeatures,
65 "Namespace for `wx.combo.ComboCtrl` feature flags. See
66 `wx.combo.ComboCtrl.GetFeatures`.", "");
67 struct wxComboCtrlFeatures
68 {
69 enum
70 {
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
74 // of the control
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
79 // painted
80 Borderless = 0x0040, // wxNO_BORDER window style works
81
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.
85
86 All = MovableButton|BitmapButton|
87 ButtonSpacing|TextIndent|
88 PaintControl|PaintWritable|
89 Borderless
90 };
91 };
92
93 //---------------------------------------------------------------------------
94
95 // C++ implemetation of Python aware wxComboCtrl
96 %{
97 class wxPyComboCtrl : public wxComboCtrl
98 {
99 DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
100 public:
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,
107 long style = 0,
108 const wxValidator& validator = wxDefaultValidator,
109 const wxString& name = wxPyComboBoxNameStr)
110 : wxComboCtrl(parent, id, value, pos, size, style, validator, name)
111 {}
112
113 void DoSetPopupControl(wxComboPopup* popup)
114 {
115 bool found;
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));
120 Py_DECREF(obj);
121 }
122 wxPyEndBlockThreads(blocked);
123 if (! found)
124 wxComboCtrl::DoSetPopupControl(popup);
125 }
126
127 virtual bool IsKeyPopupToggle( const wxKeyEvent& event ) const
128 {
129 bool found;
130 bool rval = false;
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));
135 Py_DECREF(oevt);
136 }
137 wxPyEndBlockThreads(blocked);
138 if (! found)
139 rval = wxComboCtrl::IsKeyPopupToggle(event);
140 return rval;
141 }
142
143
144 enum
145 {
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
149 };
150
151
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);
157
158 PYPRIVATE;
159 };
160
161 IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
162
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);
168
169 %}
170
171
172
173 // Now declare wxPyComboCtrl for Python
174
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.
179
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.
186 ", "
187 Window Styles
188 -------------
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
201 as well.
202 wx.CC_STD_BUTTON Drop button will behave more like a standard
203 push button.
204 ==================== ============================================
205 ");
206
207 MustHaveApp(wxPyComboCtrl);
208 %rename(ComboCtrl) wxPyComboCtrl;
209
210 class wxPyComboCtrl : public wxControl
211 {
212 public:
213 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
214 %pythonAppend wxPyComboCtrl() "";
215
216 DocCtorStr(
217 wxPyComboCtrl(wxWindow *parent,
218 wxWindowID id = wxID_ANY,
219 const wxString& value = wxEmptyString,
220 const wxPoint& pos = wxDefaultPosition,
221 const wxSize& size = wxDefaultSize,
222 long style = 0,
223 const wxValidator& validator = wxDefaultValidator,
224 const wxString& name = wxPyComboBoxNameStr),
225 "", "");
226
227 DocCtorStrName(
228 wxPyComboCtrl(),
229 "", "",
230 PreComboCtrl);
231
232
233 void _setCallbackInfo(PyObject* self, PyObject* _class);
234
235 DocDeclStr(
236 virtual void , ShowPopup(),
237 "Show the popup window.", "");
238
239 DocDeclStr(
240 virtual void , HidePopup(),
241 "Dismisses the popup window.", "");
242
243
244 // Override for totally custom combo action
245 DocDeclStr(
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. ", "");
249
250
251 // return true if the popup is currently shown
252 DocDeclStr(
253 bool , IsPopupShown() const,
254 "Returns true if the popup is currently shown.", "");
255
256
257 %disownarg(wxPyComboPopup* popup);
258 DocDeclStr(
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);
264
265
266 DocDeclStr(
267 wxPyComboPopup* , GetPopupControl(),
268 "Returns the current popup interface that has been set with
269 `SetPopupControl`.", "");
270
271
272 DocDeclStr(
273 wxWindow *, GetPopupWindow() const,
274 "Returns the popup window containing the popup control.", "");
275
276
277 DocDeclStr(
278 wxTextCtrl *, GetTextCtrl() const,
279 "Get the text control which is part of the combo control.", "");
280
281
282 DocDeclStr(
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.", "");
286
287
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);
292
293 // wxTextCtrl methods - for readonly combo they should return
294 // without errors.
295
296 DocDeclStr(
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.", "");
300
301 DocDeclStr(
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.", "");
307
308 virtual void Copy();
309 virtual void Cut();
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);
317 virtual void Undo();
318
319 %Rename(SetMark, void , SetSelection(long from, long to));
320
321
322 DocDeclStr(
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.", "");
327
328
329 DocDeclStr(
330 void , SetValueWithEvent(const wxString& value, bool withEvent = true),
331 "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
332
333
334 //
335 // Popup customization methods
336 //
337
338 DocDeclStr(
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.", "");
343
344
345 DocDeclStr(
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.", "");
349
350
351 DocDeclStr(
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.", "");
356
357
358 DocDeclStr(
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.", "");
363
364 int GetCustomPaintWidth() const;
365
366
367 DocDeclStr(
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).", "");
372
373
374 DocDeclStr(
375 void , SetButtonPosition( int width = -1,
376 int height = -1,
377 int side = wxRIGHT,
378 int spacingX = 0 ),
379 "Set the position of the dropdown button.", "");
380
381
382 DocDeclStr(
383 wxSize , GetButtonSize(),
384 "Returns current size of the dropdown button.", "");
385
386
387 DocDeclStr(
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.
394
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.
400 ", "");
401
402
403 DocDeclStr(
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.", "");
408
409
410 DocDeclStr(
411 wxCoord , GetTextIndent() const,
412 "Returns actual indentation in pixels.", "");
413
414
415 DocDeclStr(
416 const wxRect& , GetTextRect() const,
417 "Returns area covered by the text field (includes everything except
418 borders and the dropdown button).", "");
419
420
421 DocDeclStr(
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.", "");
428
429
430 DocDeclStr(
431 void , EnablePopupAnimation( bool enable = true ),
432 "Enables or disables popup animation, if any, depending on the value of
433 the argument.", "");
434
435
436 //
437 // Utilies needed by the popups or native implementations
438 //
439
440 DocDeclStr(
441 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
442 "Returns true if given key combination should toggle the popup.", "");
443
444
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
455 DocDeclStr(
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
463 background.
464
465 flags are the same as wx.RendererNative flags:
466
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 ====================== ============================================
472 ", "");
473
474
475
476 DocDeclStr(
477 bool , ShouldDrawFocus() const,
478 "Returns true if focus indicator should be drawn in the control.", "");
479
480
481 const wxBitmap& GetBitmapNormal() const;
482 const wxBitmap& GetBitmapPressed() const;
483 const wxBitmap& GetBitmapHover() const;
484 const wxBitmap& GetBitmapDisabled() const;
485
486 wxUint32 GetInternalFlags() const;
487
488 DocDeclStr(
489 bool , IsCreated() const,
490 "Return true if Create has finished", "");
491
492
493 DocDeclStr(
494 void , OnPopupDismiss(),
495 "Common code to be called on popup hide/dismiss", "");
496
497
498 // PopupShown states
499 enum
500 {
501 Hidden = 0,
502 //Closing = 1,
503 Animating = 2,
504 Visible = 3
505 };
506
507 bool IsPopupWindowState( int state ) const;
508
509 int GetPopupWindowState() const;
510
511 // Set value returned by GetMainWindowOfCompositeControl
512 void SetCtrlMainWnd( wxWindow* wnd );
513
514 DocDeclStr(
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`.", "");
519
520
521
522 // Flags for DoShowPopup and AnimateShow
523 enum
524 {
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
528 };
529
530 // Shows and positions the popup.
531 DocDeclStr(
532 virtual void , DoShowPopup( const wxRect& rect, int flags ),
533 "Shows and positions the popup.
534
535 Flags:
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 ============ =====================================================
541 ", "");
542
543
544
545 DocDeclStr(
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`.
550 ", "");
551
552
553 };
554
555 //---------------------------------------------------------------------------
556 %newgroup
557
558
559 // C++ implemetation of Python aware wxComboCtrl
560 %{
561 class wxPyComboPopup : public wxComboPopup
562 {
563 public:
564 wxPyComboPopup() : wxComboPopup() {}
565 ~wxPyComboPopup() {}
566
567
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);
576
577 virtual wxWindow *GetControl()
578 {
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")) {
583 PyObject* ro;
584 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
585 if (ro) {
586 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
587 PyErr_SetString(PyExc_TypeError, errmsg);
588 Py_DECREF(ro);
589 }
590 }
591 else
592 PyErr_SetString(PyExc_TypeError, errmsg);
593 wxPyEndBlockThreads(blocked);
594 return rval;
595 }
596
597
598 virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
599 {
600 bool found;
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));
606 Py_DECREF(odc);
607 Py_DECREF(orect);
608 }
609 wxPyEndBlockThreads(blocked);
610 if (! found)
611 wxComboPopup::PaintComboControl(dc, rect);
612 }
613
614
615 virtual void OnComboKeyEvent( wxKeyEvent& event )
616 {
617 bool found;
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));
622 Py_DECREF(oevt);
623 }
624 wxPyEndBlockThreads(blocked);
625 if (! found)
626 wxComboPopup::OnComboKeyEvent(event);
627 }
628
629
630 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
631 {
632 const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
633 bool found;
634 wxSize rval(0,0);
635 wxSize* rptr = &rval;
636 wxPyBlock_t blocked = wxPyBeginBlockThreads();
637 if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
638 PyObject* ro;
639 ro = wxPyCBH_callCallbackObj(
640 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
641 if (ro) {
642 if (! wxSize_helper(ro, &rptr))
643 PyErr_SetString(PyExc_TypeError, errmsg);
644 else
645 rval = *rptr;
646 Py_DECREF(ro);
647 }
648 }
649 wxPyEndBlockThreads(blocked);
650 if (! found)
651 rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
652 return rval;
653 }
654
655 wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
656
657 PYPRIVATE;
658 };
659
660
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);
669
670 %}
671
672
673
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.
683
684 Nearly all of the methods of this class are overridable in Python.", "");
685
686
687 MustHaveApp(wxPyComboPopup);
688 %rename(ComboPopup) wxPyComboPopup;
689
690 class wxPyComboPopup
691 {
692 public:
693 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
694
695 DocCtorStr(
696 wxPyComboPopup(),
697 "Constructor", "");
698
699 DocCtorStr(
700 ~wxPyComboPopup(),
701 "Destructor", "");
702
703
704 void _setCallbackInfo(PyObject* self, PyObject* _class);
705
706 DocDeclStr(
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.", "");
711
712
713 // Create the popup child control.
714 // Return true for success.
715 DocDeclStr(
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...)", "");
722
723
724 DocDeclStr(
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``.", "");
730
731
732 DocDeclStr(
733 virtual void , OnPopup(),
734 "The derived class may implement this to do special processing when
735 popup is shown.", "");
736
737
738 DocDeclStr(
739 virtual void , OnDismiss(),
740 "The derived class may implement this to do special processing when
741 popup is hidden.", "");
742
743
744 DocDeclStr(
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.", "");
750
751
752 DocDeclStr(
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.", "");
756
757
758 DocDeclStr(
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.", "");
762
763
764 DocDeclStr(
765 virtual void , OnComboKeyEvent( wxKeyEvent& event ),
766 "Receives key events from the parent ComboCtrl. Events not handled
767 should be skipped, as usual.", "");
768
769
770 DocDeclStr(
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.", "");
774
775
776 DocDeclStr(
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`.
781
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.
786 ", "");
787
788
789 DocDeclStr(
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``.", "");
796
797
798 //
799 // Utilies
800 //
801
802
803 DocDeclStr(
804 void , Dismiss(),
805 "Hides the popup", "");
806
807
808 DocDeclStr(
809 bool , IsCreated() const,
810 "Returns true if `Create` has been called.", "");
811
812
813 DocDeclStr(
814 static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
815 wxDC& dc,
816 const wxRect& rect ),
817 "Default PaintComboControl behaviour", "");
818
819
820 DocDeclStr(
821 wxPyComboCtrl* , GetCombo(),
822 "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
823 is associated with.", "");
824
825 };
826
827
828
829 //---------------------------------------------------------------------------
830 %newgroup
831
832
833 enum {
834 wxODCB_DCLICK_CYCLES,
835 wxODCB_STD_CONTROL_PAINT,
836 wxODCB_PAINTING_CONTROL,
837 wxODCB_PAINTING_SELECTED
838 };
839
840
841
842 // C++ implemetation of Python aware wxOwnerDrawnComboBox
843 %{
844 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
845 {
846 public:
847 wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
848 wxPyOwnerDrawnComboBox(wxWindow *parent,
849 wxWindowID id,
850 const wxString& value,
851 const wxPoint& pos,
852 const wxSize& size,
853 const wxArrayString& choices,
854 long style,
855 const wxValidator& validator = wxDefaultValidator,
856 const wxString& name = wxPyComboBoxNameStr)
857 : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
858 validator, name)
859 {}
860
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);
865
866
867 PYPRIVATE;
868 };
869
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);
874
875 %}
876
877
878
879 // Now declare wxPyOwnerDrawnComboBox for Python
880
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.
885
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`
889 methods.", "");
890
891 MustHaveApp(wxPyOwnerDrawnComboBox);
892 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
893
894 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
895 public wxItemContainer
896 {
897 public:
898 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
899 %pythonAppend wxPyOwnerDrawnComboBox() "";
900
901 DocCtorStr(
902 wxPyOwnerDrawnComboBox(wxWindow *parent,
903 wxWindowID id = -1,
904 const wxString& value = wxPyEmptyString,
905 const wxPoint& pos = wxDefaultPosition,
906 const wxSize& size = wxDefaultSize,
907 const wxArrayString& choices = wxPyEmptyStringArray,
908 long style = 0,
909 const wxValidator& validator = wxDefaultValidator,
910 const wxString& name = wxPyComboBoxNameStr),
911 "Standard constructor.", "");
912
913 DocCtorStrName(wxPyOwnerDrawnComboBox(),
914 "2-phase create constructor.", "",
915 PreOwnerDrawnComboBox);
916
917 void _setCallbackInfo(PyObject* self, PyObject* _class);
918
919
920 DocDeclStr(
921 bool , Create(wxWindow *parent,
922 wxWindowID id = -1,
923 const wxString& value = wxPyEmptyString,
924 const wxPoint& pos = wxDefaultPosition,
925 const wxSize& size = wxDefaultSize,
926 const wxArrayString& choices = wxPyEmptyStringArray,
927 long style = 0,
928 const wxValidator& validator = wxDefaultValidator,
929 const wxString& name = wxPyComboBoxNameStr),
930 "Create the UI object, and other initialization.", "");
931
932
933 DocDeclStr(
934 virtual int , GetWidestItemWidth(),
935 "Return the widest item width (recalculating it if necessary.)", "");
936
937
938 DocDeclStr(
939 virtual int , GetWidestItem(),
940 "Return the index of the widest item (recalculating it if necessary.)", "");
941
942
943 void SetSelection(int n);
944 %Rename(SetMark, void , SetSelection(long from, long to));
945
946
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
952 DocDeclStr(
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
957 normal combobox.
958
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
962 calling this method.
963 :param item: The index of the item to be drawn.
964
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.
971 ", "");
972
973
974 DocDeclStr(
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.", "");
979
980
981 DocDeclStr(
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.", "");
986
987
988 DocDeclStr(
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
991 around it.
992
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`.", "");
997
998
999 };
1000
1001
1002 //---------------------------------------------------------------------------
1003
1004 %init %{
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");
1009 %}
1010 //---------------------------------------------------------------------------
1011