]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/combo.i
added wxDialog::GetParentForModalDialog() and use it to try to always create modal...
[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 // 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,
58
59 };
60
61
62 // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
63 enum
64 {
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.
68 };
69
70
71 DocStr( wxComboCtrlFeatures,
72 "Namespace for `wx.combo.ComboCtrl` feature flags. See
73 `wx.combo.ComboCtrl.GetFeatures`.", "");
74 struct wxComboCtrlFeatures
75 {
76 enum
77 {
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
81 // of the control
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
86 // painted
87 Borderless = 0x0040, // wxNO_BORDER window style works
88
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.
92
93 All = MovableButton|BitmapButton|
94 ButtonSpacing|TextIndent|
95 PaintControl|PaintWritable|
96 Borderless
97 };
98 };
99
100 //---------------------------------------------------------------------------
101
102 // C++ implemetation of Python aware wxComboCtrl
103 %{
104 class wxPyComboCtrl : public wxComboCtrl
105 {
106 DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
107 public:
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,
114 long style = 0,
115 const wxValidator& validator = wxDefaultValidator,
116 const wxString& name = wxPyComboBoxNameStr)
117 : wxComboCtrl(parent, id, value, pos, size, style, validator, name)
118 {}
119
120 void DoSetPopupControl(wxComboPopup* popup)
121 {
122 bool found;
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));
127 Py_DECREF(obj);
128 }
129 wxPyEndBlockThreads(blocked);
130 if (! found)
131 wxComboCtrl::DoSetPopupControl(popup);
132 }
133
134 virtual bool IsKeyPopupToggle( const wxKeyEvent& event ) const
135 {
136 bool found;
137 bool rval = false;
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));
142 Py_DECREF(oevt);
143 }
144 wxPyEndBlockThreads(blocked);
145 if (! found)
146 rval = wxComboCtrl::IsKeyPopupToggle(event);
147 return rval;
148 }
149
150
151 virtual wxWindow *GetMainWindowOfCompositeControl()
152 {
153 return wxComboCtrl::GetMainWindowOfCompositeControl();
154 }
155
156
157 enum
158 {
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
162 };
163
164
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);
170
171 PYPRIVATE;
172 };
173
174 IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
175
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);
181
182 %}
183
184
185
186 // Now declare wxPyComboCtrl for Python
187
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.
192
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.
199 ", "
200
201 Window Styles
202 -------------
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
215 as well.
216 wx.CC_STD_BUTTON Drop button will behave more like a standard
217 push button.
218 ==================== ============================================
219 ");
220
221 MustHaveApp(wxPyComboCtrl);
222 %rename(ComboCtrl) wxPyComboCtrl;
223
224 class wxPyComboCtrl : public wxControl
225 {
226 public:
227 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
228 %pythonAppend wxPyComboCtrl() "";
229
230 DocCtorStr(
231 wxPyComboCtrl(wxWindow *parent,
232 wxWindowID id = wxID_ANY,
233 const wxString& value = wxEmptyString,
234 const wxPoint& pos = wxDefaultPosition,
235 const wxSize& size = wxDefaultSize,
236 long style = 0,
237 const wxValidator& validator = wxDefaultValidator,
238 const wxString& name = wxPyComboBoxNameStr),
239 "", "");
240
241 DocCtorStrName(
242 wxPyComboCtrl(),
243 "", "",
244 PreComboCtrl);
245
246
247 void _setCallbackInfo(PyObject* self, PyObject* _class);
248
249 DocDeclStr(
250 virtual void , ShowPopup(),
251 "Show the popup window.", "");
252
253 DocDeclStr(
254 virtual void , HidePopup(),
255 "Dismisses the popup window.", "");
256
257
258 // Override for totally custom combo action
259 DocDeclStr(
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. ", "");
263
264
265 // return true if the popup is currently shown
266 DocDeclStr(
267 bool , IsPopupShown() const,
268 "Returns true if the popup is currently shown.", "");
269
270
271 %disownarg(wxPyComboPopup* popup);
272 DocDeclStr(
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);
278
279
280 DocDeclStr(
281 wxPyComboPopup* , GetPopupControl(),
282 "Returns the current popup interface that has been set with
283 `SetPopupControl`.", "");
284
285
286 DocDeclStr(
287 wxWindow *, GetPopupWindow() const,
288 "Returns the popup window containing the popup control.", "");
289
290
291 DocDeclStr(
292 wxTextCtrl *, GetTextCtrl() const,
293 "Get the text control which is part of the combo control.", "");
294
295
296 DocDeclStr(
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.", "");
300
301
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();
310
311
312 // wxTextCtrl methods - for readonly combo they should return
313 // without errors.
314
315 DocDeclStr(
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.", "");
319
320 DocDeclStr(
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.", "");
326
327 virtual void Copy();
328 virtual void Cut();
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);
336 virtual void Undo();
337
338 %Rename(SetMark, void , SetSelection(long from, long to));
339
340
341 DocDeclStr(
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.", "");
346
347
348 DocDeclStr(
349 void , SetValueWithEvent(const wxString& value, bool withEvent = true),
350 "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
351
352
353 //
354 // Popup customization methods
355 //
356
357 DocDeclStr(
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.", "");
362
363
364 DocDeclStr(
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.", "");
368
369
370 DocDeclStr(
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.", "");
375
376
377 DocDeclStr(
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.", "");
382
383 int GetCustomPaintWidth() const;
384
385
386 DocDeclStr(
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).", "");
391
392
393 DocDeclStr(
394 void , SetButtonPosition( int width = -1,
395 int height = -1,
396 int side = wxRIGHT,
397 int spacingX = 0 ),
398 "Set the position of the dropdown button.", "");
399
400
401 DocDeclStr(
402 wxSize , GetButtonSize(),
403 "Returns current size of the dropdown button.", "");
404
405
406 DocDeclStr(
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.
413
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.
419 ", "");
420
421
422 DocDeclStr(
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.", "");
427
428
429 DocDeclStr(
430 wxCoord , GetTextIndent() const,
431 "Returns actual indentation in pixels.", "");
432
433
434 DocDeclStr(
435 const wxRect& , GetTextRect() const,
436 "Returns area covered by the text field (includes everything except
437 borders and the dropdown button).", "");
438
439
440 DocDeclStr(
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.", "");
447
448
449 DocDeclStr(
450 void , EnablePopupAnimation( bool enable = true ),
451 "Enables or disables popup animation, if any, depending on the value of
452 the argument.", "");
453
454
455 //
456 // Utilies needed by the popups or native implementations
457 //
458
459 DocDeclStr(
460 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
461 "Returns true if given key combination should toggle the popup.", "");
462
463
464 DocDeclStr(
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
472 background.
473
474 flags are the same as wx.RendererNative flags:
475
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 ====================== ============================================
481 ", "");
482
483
484
485 DocDeclStr(
486 bool , ShouldDrawFocus() const,
487 "Returns true if focus indicator should be drawn in the control.", "");
488
489
490 const wxBitmap& GetBitmapNormal() const;
491 const wxBitmap& GetBitmapPressed() const;
492 const wxBitmap& GetBitmapHover() const;
493 const wxBitmap& GetBitmapDisabled() const;
494
495 wxUint32 GetInternalFlags() const;
496
497 DocDeclStr(
498 bool , IsCreated() const,
499 "Return true if Create has finished", "");
500
501
502 DocDeclStr(
503 void , OnPopupDismiss(),
504 "Common code to be called on popup hide/dismiss", "");
505
506
507 // PopupShown states
508 enum
509 {
510 Hidden = 0,
511 //Closing = 1,
512 Animating = 2,
513 Visible = 3
514 };
515
516 bool IsPopupWindowState( int state ) const;
517
518 int GetPopupWindowState() const;
519
520 // Set value returned by GetMainWindowOfCompositeControl
521 void SetCtrlMainWnd( wxWindow* wnd );
522 virtual wxWindow *GetMainWindowOfCompositeControl();
523
524 DocDeclStr(
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`.", "");
529
530
531
532 // Flags for DoShowPopup and AnimateShow
533 enum
534 {
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
538 };
539
540 // Shows and positions the popup.
541 DocDeclStr(
542 virtual void , DoShowPopup( const wxRect& rect, int flags ),
543 "Shows and positions the popup.
544
545 Flags:
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 ============ =====================================================
551 ", "");
552
553
554
555 DocDeclStr(
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`.
560 ", "");
561
562
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);
578
579 };
580
581 //---------------------------------------------------------------------------
582 %newgroup
583
584
585 // C++ implemetation of Python aware wxComboCtrl
586 %{
587 class wxPyComboPopup : public wxComboPopup
588 {
589 public:
590 wxPyComboPopup() : wxComboPopup() {}
591 ~wxPyComboPopup() {}
592
593
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);
602
603 virtual wxWindow *GetControl()
604 {
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")) {
609 PyObject* ro;
610 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
611 if (ro) {
612 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
613 PyErr_SetString(PyExc_TypeError, errmsg);
614 Py_DECREF(ro);
615 }
616 }
617 else
618 PyErr_SetString(PyExc_TypeError, errmsg);
619 wxPyEndBlockThreads(blocked);
620 return rval;
621 }
622
623
624 virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
625 {
626 bool found;
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));
632 Py_DECREF(odc);
633 Py_DECREF(orect);
634 }
635 wxPyEndBlockThreads(blocked);
636 if (! found)
637 wxComboPopup::PaintComboControl(dc, rect);
638 }
639
640
641 virtual void OnComboKeyEvent( wxKeyEvent& event )
642 {
643 bool found;
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));
648 Py_DECREF(oevt);
649 }
650 wxPyEndBlockThreads(blocked);
651 if (! found)
652 wxComboPopup::OnComboKeyEvent(event);
653 }
654
655
656 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
657 {
658 const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
659 bool found;
660 wxSize rval(0,0);
661 wxSize* rptr = &rval;
662 wxPyBlock_t blocked = wxPyBeginBlockThreads();
663 if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
664 PyObject* ro;
665 ro = wxPyCBH_callCallbackObj(
666 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
667 if (ro) {
668 if (! wxSize_helper(ro, &rptr))
669 PyErr_SetString(PyExc_TypeError, errmsg);
670 else
671 rval = *rptr;
672 Py_DECREF(ro);
673 }
674 }
675 wxPyEndBlockThreads(blocked);
676 if (! found)
677 rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
678 return rval;
679 }
680
681 wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
682
683 PYPRIVATE;
684 };
685
686
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);
695
696 %}
697
698
699
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.
709
710 Nearly all of the methods of this class are overridable in Python.", "");
711
712
713 MustHaveApp(wxPyComboPopup);
714 %rename(ComboPopup) wxPyComboPopup;
715
716 class wxPyComboPopup
717 {
718 public:
719 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
720
721 DocCtorStr(
722 wxPyComboPopup(),
723 "Constructor", "");
724
725 DocCtorStr(
726 ~wxPyComboPopup(),
727 "Destructor", "");
728
729
730 void _setCallbackInfo(PyObject* self, PyObject* _class);
731
732 DocDeclStr(
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.", "");
737
738
739 // Create the popup child control.
740 // Return true for success.
741 DocDeclStr(
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...)", "");
748
749
750 DocDeclStr(
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``.", "");
756
757
758 DocDeclStr(
759 virtual void , OnPopup(),
760 "The derived class may implement this to do special processing when
761 popup is shown.", "");
762
763
764 DocDeclStr(
765 virtual void , OnDismiss(),
766 "The derived class may implement this to do special processing when
767 popup is hidden.", "");
768
769
770 DocDeclStr(
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.", "");
776
777
778 DocDeclStr(
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.", "");
782
783
784 DocDeclStr(
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.", "");
788
789
790 DocDeclStr(
791 virtual void , OnComboKeyEvent( wxKeyEvent& event ),
792 "Receives key events from the parent ComboCtrl. Events not handled
793 should be skipped, as usual.", "");
794
795
796 DocDeclStr(
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.", "");
800
801
802 DocDeclStr(
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`.
807
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.
812 ", "");
813
814
815 DocDeclStr(
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``.", "");
822
823
824 //
825 // Utilies
826 //
827
828
829 DocDeclStr(
830 void , Dismiss(),
831 "Hides the popup", "");
832
833
834 DocDeclStr(
835 bool , IsCreated() const,
836 "Returns true if `Create` has been called.", "");
837
838
839 DocDeclStr(
840 static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
841 wxDC& dc,
842 const wxRect& rect ),
843 "Default PaintComboControl behaviour", "");
844
845
846 DocDeclStr(
847 wxPyComboCtrl* , GetCombo(),
848 "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
849 is associated with.", "");
850
851 };
852
853
854
855 //---------------------------------------------------------------------------
856 %newgroup
857
858
859 enum {
860 wxODCB_DCLICK_CYCLES,
861 wxODCB_STD_CONTROL_PAINT,
862 wxODCB_PAINTING_CONTROL,
863 wxODCB_PAINTING_SELECTED
864 };
865
866
867
868 // C++ implemetation of Python aware wxOwnerDrawnComboBox
869 %{
870 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
871 {
872 public:
873 wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
874 wxPyOwnerDrawnComboBox(wxWindow *parent,
875 wxWindowID id,
876 const wxString& value,
877 const wxPoint& pos,
878 const wxSize& size,
879 const wxArrayString& choices,
880 long style,
881 const wxValidator& validator = wxDefaultValidator,
882 const wxString& name = wxPyComboBoxNameStr)
883 : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
884 validator, name)
885 {}
886
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);
891
892
893 PYPRIVATE;
894 };
895
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);
900
901 %}
902
903
904
905 // Now declare wxPyOwnerDrawnComboBox for Python
906
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.
911
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`
915 methods.", "");
916
917 MustHaveApp(wxPyOwnerDrawnComboBox);
918 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
919
920 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
921 public wxItemContainer
922 {
923 public:
924 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
925 %pythonAppend wxPyOwnerDrawnComboBox() "";
926
927 DocCtorStr(
928 wxPyOwnerDrawnComboBox(wxWindow *parent,
929 wxWindowID id = -1,
930 const wxString& value = wxPyEmptyString,
931 const wxPoint& pos = wxDefaultPosition,
932 const wxSize& size = wxDefaultSize,
933 const wxArrayString& choices = wxPyEmptyStringArray,
934 long style = 0,
935 const wxValidator& validator = wxDefaultValidator,
936 const wxString& name = wxPyComboBoxNameStr),
937 "Standard constructor.", "");
938
939 DocCtorStrName(wxPyOwnerDrawnComboBox(),
940 "2-phase create constructor.", "",
941 PreOwnerDrawnComboBox);
942
943 void _setCallbackInfo(PyObject* self, PyObject* _class);
944
945
946 DocDeclStr(
947 bool , Create(wxWindow *parent,
948 wxWindowID id = -1,
949 const wxString& value = wxPyEmptyString,
950 const wxPoint& pos = wxDefaultPosition,
951 const wxSize& size = wxDefaultSize,
952 const wxArrayString& choices = wxPyEmptyStringArray,
953 long style = 0,
954 const wxValidator& validator = wxDefaultValidator,
955 const wxString& name = wxPyComboBoxNameStr),
956 "Create the UI object, and other initialization.", "");
957
958
959 DocDeclStr(
960 virtual int , GetWidestItemWidth(),
961 "Return the widest item width (recalculating it if necessary.)", "");
962
963
964 DocDeclStr(
965 virtual int , GetWidestItem(),
966 "Return the index of the widest item (recalculating it if necessary.)", "");
967
968
969 void SetSelection(int n);
970 %Rename(SetMark, void , SetSelection(long from, long to));
971
972
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
978 DocDeclStr(
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
983 normal combobox.
984
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
988 calling this method.
989 :param item: The index of the item to be drawn.
990
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.
997 ", "");
998
999
1000 DocDeclStr(
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.", "");
1005
1006
1007 DocDeclStr(
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.", "");
1012
1013
1014 DocDeclStr(
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
1017 around it.
1018
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`.", "");
1023
1024
1025 };
1026
1027 //---------------------------------------------------------------------------
1028
1029 %{
1030 #include <wx/bmpcbox.h>
1031 %}
1032
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.",
1037 "
1038
1039 Window Styles
1040 -------------
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
1050 controls).
1051 =================== ============================================
1052 ");
1053
1054 MustHaveApp(wxBitmapComboBox);
1055
1056 class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1057 {
1058 public:
1059 %pythonAppend wxBitmapComboBox "self._setOORInfo(self);";
1060 %pythonAppend wxBitmapComboBox() "";
1061
1062 DocCtorStr(
1063 wxBitmapComboBox(wxWindow *parent,
1064 wxWindowID id = -1,
1065 const wxString& value = wxPyEmptyString,
1066 const wxPoint& pos = wxDefaultPosition,
1067 const wxSize& size = wxDefaultSize,
1068 const wxArrayString& choices = wxPyEmptyStringArray,
1069 long style = 0,
1070 const wxValidator& validator = wxDefaultValidator,
1071 const wxString& name = wxBitmapComboBoxNameStr),
1072 "Standard constructor", "");
1073
1074 DocCtorStrName(wxBitmapComboBox(),
1075 "2-phase create constructor.", "",
1076 PreBitmapComboBox);
1077
1078 DocDeclStr(
1079 bool , Create(wxWindow *parent,
1080 wxWindowID id = -1,
1081 const wxString& value = wxPyEmptyString,
1082 const wxPoint& pos = wxDefaultPosition,
1083 const wxSize& size = wxDefaultSize,
1084 const wxArrayString& choices = wxPyEmptyStringArray,
1085 long style = 0,
1086 const wxValidator& validator = wxDefaultValidator,
1087 const wxString& name = wxBitmapComboBoxNameStr),
1088 "Create the UI object, and other initialization.", "");
1089
1090
1091
1092 %extend {
1093 DocStr(Append,
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) {
1097 if (clientData) {
1098 wxPyClientData* data = new wxPyClientData(clientData);
1099 return self->Append(item, bitmap, data);
1100 } else
1101 return self->Append(item, bitmap);
1102 }
1103 }
1104
1105
1106 DocDeclStr(
1107 virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
1108 "Returns the image of the item with the given index.", "");
1109
1110
1111 %extend {
1112 DocStr(Insert,
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) {
1117 if (clientData) {
1118 wxPyClientData* data = new wxPyClientData(clientData);
1119 return self->Insert(item, bitmap, pos, data);
1120 } else
1121 return self->Insert(item, bitmap, pos);
1122 }
1123 }
1124
1125
1126 DocDeclStr(
1127 virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
1128 "Sets the image for the given item.", "");
1129
1130
1131 DocDeclStr(
1132 virtual wxSize , GetBitmapSize() const,
1133 "Returns size of the image used in list.", "");
1134
1135
1136 };
1137
1138 //---------------------------------------------------------------------------
1139
1140 %init %{
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");
1145 %}
1146 //---------------------------------------------------------------------------
1147