]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/combo.i
Compilation fixes
[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 virtual wxWindow *GetMainWindowOfCompositeControl()
145 {
146 return wxComboCtrl::GetMainWindowOfCompositeControl();
147 }
148
149
150 enum
151 {
152 ShowBelow = 0x0000, // Showing popup below the control
153 ShowAbove = 0x0001, // Showing popup above the control
154 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
155 };
156
157
158 DEC_PYCALLBACK_VOID_(ShowPopup);
159 DEC_PYCALLBACK_VOID_(HidePopup);
160 DEC_PYCALLBACK_VOID_(OnButtonClick);
161 DEC_PYCALLBACK__RECTINT(DoShowPopup);
162 DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
163
164 PYPRIVATE;
165 };
166
167 IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
168
169 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
170 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
171 IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
172 IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
173 IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
174
175 %}
176
177
178
179 // Now declare wxPyComboCtrl for Python
180
181 DocStr(wxPyComboCtrl,
182 "A combo control is a generic combobox that allows for a totally custom
183 popup. In addition it has other customization features. For instance,
184 position and size of the dropdown button can be changed.
185
186 To specify what to use for the popup control you need to derive a
187 class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
188 `SetPopupControl`. It doesn't derive from any widget class so it can
189 be used either as a mixin class combined with some standard or custom
190 widget, or you can use the derived ComboPopup to create and hold an
191 independent reference to the widget to be used for the popup.
192 ", "
193
194 Window Styles
195 -------------
196 ==================== ============================================
197 wx.CB_READONLY Text will not be editable.
198 wx.CB_SORT Sorts the entries in the list alphabetically.
199 wx.TE_PROCESS_ENTER The control will generate the event
200 EVT_TEXT_ENTER (otherwise pressing Enter key
201 is either processed internally by the control
202 or used for navigation between dialog controls).
203 wx.CC_SPECIAL_DCLICK Double-clicking triggers a call to popup's
204 OnComboDoubleClick. Actual behaviour is defined
205 by a derived class. For instance,
206 OwnerDrawnComboBox will cycle an item. This
207 style only applies if wx.CB_READONLY is used
208 as well.
209 wx.CC_STD_BUTTON Drop button will behave more like a standard
210 push button.
211 ==================== ============================================
212 ");
213
214 MustHaveApp(wxPyComboCtrl);
215 %rename(ComboCtrl) wxPyComboCtrl;
216
217 class wxPyComboCtrl : public wxControl
218 {
219 public:
220 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
221 %pythonAppend wxPyComboCtrl() "";
222
223 DocCtorStr(
224 wxPyComboCtrl(wxWindow *parent,
225 wxWindowID id = wxID_ANY,
226 const wxString& value = wxEmptyString,
227 const wxPoint& pos = wxDefaultPosition,
228 const wxSize& size = wxDefaultSize,
229 long style = 0,
230 const wxValidator& validator = wxDefaultValidator,
231 const wxString& name = wxPyComboBoxNameStr),
232 "", "");
233
234 DocCtorStrName(
235 wxPyComboCtrl(),
236 "", "",
237 PreComboCtrl);
238
239
240 void _setCallbackInfo(PyObject* self, PyObject* _class);
241
242 DocDeclStr(
243 virtual void , ShowPopup(),
244 "Show the popup window.", "");
245
246 DocDeclStr(
247 virtual void , HidePopup(),
248 "Dismisses the popup window.", "");
249
250
251 // Override for totally custom combo action
252 DocDeclStr(
253 virtual void , OnButtonClick(),
254 "Implement in a derived class to define what happens on dropdown button
255 click. Default action is to show the popup. ", "");
256
257
258 // return true if the popup is currently shown
259 DocDeclStr(
260 bool , IsPopupShown() const,
261 "Returns true if the popup is currently shown.", "");
262
263
264 %disownarg(wxPyComboPopup* popup);
265 DocDeclStr(
266 void , SetPopupControl( wxPyComboPopup* popup ),
267 "Set popup interface class derived from `wx.combo.ComboPopup`. This
268 method should be called as soon as possible after the control has been
269 created, unless `OnButtonClick` has been overridden.", "");
270 %cleardisown(wxPyComboPopup* popup);
271
272
273 DocDeclStr(
274 wxPyComboPopup* , GetPopupControl(),
275 "Returns the current popup interface that has been set with
276 `SetPopupControl`.", "");
277
278
279 DocDeclStr(
280 wxWindow *, GetPopupWindow() const,
281 "Returns the popup window containing the popup control.", "");
282
283
284 DocDeclStr(
285 wxTextCtrl *, GetTextCtrl() const,
286 "Get the text control which is part of the combo control.", "");
287
288
289 DocDeclStr(
290 wxWindow *, GetButton() const,
291 "Get the dropdown button which is part of the combobox. Note: it's not
292 necessarily a wx.Button or wx.BitmapButton.", "");
293
294
295 // NOTE: These are virtuals defined in a base class, so there
296 // shouldn't be any reason to provide SWIG wrappers for them...
297 // // forward these methods to all subcontrols
298 // virtual bool Enable(bool enable = true);
299 // virtual bool Show(bool show = true);
300 // virtual bool SetFont(const wxFont& font);
301 // virtual void SetValidator(const wxValidator &validator);
302 // virtual wxValidator *GetValidator();
303
304
305 // wxTextCtrl methods - for readonly combo they should return
306 // without errors.
307
308 DocDeclStr(
309 virtual wxString , GetValue() const,
310 "Returns text representation of the current value. For writable combo
311 control it always returns the value in the text field.", "");
312
313 DocDeclStr(
314 virtual void , SetValue(const wxString& value),
315 "Sets the text for the combo control text field. For a combo control
316 with wx.CB_READONLY style the string must be accepted by the popup (for
317 instance, exist in the dropdown list), otherwise the call to
318 SetValue is ignored.", "");
319
320 virtual void Copy();
321 virtual void Cut();
322 virtual void Paste();
323 virtual void SetInsertionPoint(long pos);
324 virtual void SetInsertionPointEnd();
325 virtual long GetInsertionPoint() const;
326 virtual long GetLastPosition() const;
327 virtual void Replace(long from, long to, const wxString& value);
328 virtual void Remove(long from, long to);
329 virtual void Undo();
330
331 %Rename(SetMark, void , SetSelection(long from, long to));
332
333
334 DocDeclStr(
335 void , SetText(const wxString& value),
336 "Sets the text for the text field without affecting the popup. Thus,
337 unlike `SetValue`, it works equally well with combo control using
338 wx.CB_READONLY style.", "");
339
340
341 DocDeclStr(
342 void , SetValueWithEvent(const wxString& value, bool withEvent = true),
343 "Same as `SetValue`, but also sends a EVT_TEXT event if withEvent is true.", "");
344
345
346 //
347 // Popup customization methods
348 //
349
350 DocDeclStr(
351 void , SetPopupMinWidth( int width ),
352 "Sets minimum width of the popup. If wider than combo control, it will
353 extend to the left. A value of -1 indicates to use the default. The
354 popup implementation may choose to ignore this.", "");
355
356
357 DocDeclStr(
358 void , SetPopupMaxHeight( int height ),
359 "Sets preferred maximum height of the popup. A value of -1 indicates to
360 use the default. The popup implementation may choose to ignore this.", "");
361
362
363 DocDeclStr(
364 void , SetPopupExtents( int extLeft, int extRight ),
365 "Extends popup size horizontally, relative to the edges of the combo
366 control. Values are given in pixels, and the defaults are zero. It
367 is up to the popup to fully take these values into account.", "");
368
369
370 DocDeclStr(
371 void , SetCustomPaintWidth( int width ),
372 "Set width, in pixels, of custom painted area in control without
373 wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
374 to indicate the area that is not covered by the focus rectangle.", "");
375
376 int GetCustomPaintWidth() const;
377
378
379 DocDeclStr(
380 void , SetPopupAnchor( int anchorSide ),
381 "Set side of the control to which the popup will align itself. Valid
382 values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
383 most appropriate side is used (which, currently, is always wx.LEFT).", "");
384
385
386 DocDeclStr(
387 void , SetButtonPosition( int width = -1,
388 int height = -1,
389 int side = wxRIGHT,
390 int spacingX = 0 ),
391 "Set the position of the dropdown button.", "");
392
393
394 DocDeclStr(
395 wxSize , GetButtonSize(),
396 "Returns current size of the dropdown button.", "");
397
398
399 DocDeclStr(
400 void , SetButtonBitmaps( const wxBitmap& bmpNormal,
401 bool pushButtonBg = false,
402 const wxBitmap& bmpPressed = wxNullBitmap,
403 const wxBitmap& bmpHover = wxNullBitmap,
404 const wxBitmap& bmpDisabled = wxNullBitmap ),
405 "Sets custom dropdown button graphics.
406
407 :param bmpNormal: Default button image
408 :param pushButtonBg: If ``True``, blank push button background is painted below the image.
409 :param bmpPressed: Depressed butotn image.
410 :param bmpHover: Button imate to use when the mouse hovers over it.
411 :param bmpDisabled: Disabled button image.
412 ", "");
413
414
415 DocDeclStr(
416 void , SetTextIndent( int indent ),
417 "This will set the space in pixels between left edge of the control and
418 the text, regardless whether control is read-only or not. A value of -1 can
419 be given to indicate platform default.", "");
420
421
422 DocDeclStr(
423 wxCoord , GetTextIndent() const,
424 "Returns actual indentation in pixels.", "");
425
426
427 DocDeclStr(
428 const wxRect& , GetTextRect() const,
429 "Returns area covered by the text field (includes everything except
430 borders and the dropdown button).", "");
431
432
433 DocDeclStr(
434 void , UseAltPopupWindow( bool enable = true ),
435 "Enable or disable usage of an alternative popup window, which
436 guarantees ability to focus the popup control, and allows common
437 native controls to function normally. This alternative popup window is
438 usually a wxDialog, and as such, when it is shown, its parent
439 top-level window will appear as if the focus has been lost from it.", "");
440
441
442 DocDeclStr(
443 void , EnablePopupAnimation( bool enable = true ),
444 "Enables or disables popup animation, if any, depending on the value of
445 the argument.", "");
446
447
448 //
449 // Utilies needed by the popups or native implementations
450 //
451
452 DocDeclStr(
453 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
454 "Returns true if given key combination should toggle the popup.", "");
455
456
457 DocDeclStr(
458 virtual void , PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const,
459 "Prepare background of combo control or an item in a dropdown list in a
460 way typical on platform. This includes painting the focus/disabled
461 background and setting the clipping region. Unless you plan to paint
462 your own focus indicator, you should always call this in your
463 wxComboPopup::PaintComboControl implementation. In addition, it sets
464 pen and text colour to what looks good and proper against the
465 background.
466
467 flags are the same as wx.RendererNative flags:
468
469 ====================== ============================================
470 wx.CONTROL_ISSUBMENU drawing a list item instead of combo control
471 wx.CONTROL_SELECTED list item is selected
472 wx.CONTROL_DISABLED control/item is disabled
473 ====================== ============================================
474 ", "");
475
476
477
478 DocDeclStr(
479 bool , ShouldDrawFocus() const,
480 "Returns true if focus indicator should be drawn in the control.", "");
481
482
483 const wxBitmap& GetBitmapNormal() const;
484 const wxBitmap& GetBitmapPressed() const;
485 const wxBitmap& GetBitmapHover() const;
486 const wxBitmap& GetBitmapDisabled() const;
487
488 wxUint32 GetInternalFlags() const;
489
490 DocDeclStr(
491 bool , IsCreated() const,
492 "Return true if Create has finished", "");
493
494
495 DocDeclStr(
496 void , OnPopupDismiss(),
497 "Common code to be called on popup hide/dismiss", "");
498
499
500 // PopupShown states
501 enum
502 {
503 Hidden = 0,
504 //Closing = 1,
505 Animating = 2,
506 Visible = 3
507 };
508
509 bool IsPopupWindowState( int state ) const;
510
511 int GetPopupWindowState() const;
512
513 // Set value returned by GetMainWindowOfCompositeControl
514 void SetCtrlMainWnd( wxWindow* wnd );
515 virtual wxWindow *GetMainWindowOfCompositeControl();
516
517 DocDeclStr(
518 static int , GetFeatures(),
519 "Returns a bit-list of flags indicating which features of the ComboCtrl
520 functionality are implemented by this implemetation. See
521 `wx.combo.ComboCtrlFeatures`.", "");
522
523
524
525 // Flags for DoShowPopup and AnimateShow
526 enum
527 {
528 ShowBelow = 0x0000, // Showing popup below the control
529 ShowAbove = 0x0001, // Showing popup above the control
530 CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set
531 };
532
533 // Shows and positions the popup.
534 DocDeclStr(
535 virtual void , DoShowPopup( const wxRect& rect, int flags ),
536 "Shows and positions the popup.
537
538 Flags:
539 ============ =====================================================
540 ShowBelow Showing popup below the control
541 ShowAbove Showing popup above the control
542 CanDeferShow Can only return true from AnimateShow if this is set
543 ============ =====================================================
544 ", "");
545
546
547
548 DocDeclStr(
549 virtual bool , AnimateShow( const wxRect& rect, int flags ),
550 "Implement in derived class to create a drop-down animation. Return
551 ``True`` if finished immediately. Otherwise the popup is only shown when the
552 derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
553 ", "");
554
555
556 %property(PopupControl, GetPopupControl, SetPopupControl);
557 %property(PopupWindow, GetPopupWindow);
558 %property(TextCtrl, GetTextCtrl);
559 %property(Button, GetButton);
560 %property(Value, GetValue, SetValue);
561 %property(InsertionPoint, GetInsertionPoint);
562 %property(CustomPaintWidth, GetCustomPaintWidth, SetCustomPaintWidth);
563 %property(ButtonSize, GetButtonSize);
564 %property(TextIndent, GetTextIndent, SetTextIndent);
565 %property(TextRect, GetTextRect);
566 %property(BitmapNormal, GetBitmapNormal);
567 %property(BitmapPressed, GetBitmapPressed);
568 %property(BitmapHover, GetBitmapHover);
569 %property(BitmapDisabled, GetBitmapDisabled);
570 %property(PopupWindowState, GetPopupWindowState);
571
572 };
573
574 //---------------------------------------------------------------------------
575 %newgroup
576
577
578 // C++ implemetation of Python aware wxComboCtrl
579 %{
580 class wxPyComboPopup : public wxComboPopup
581 {
582 public:
583 wxPyComboPopup() : wxComboPopup() {}
584 ~wxPyComboPopup() {}
585
586
587 DEC_PYCALLBACK_VOID_(Init);
588 DEC_PYCALLBACK_BOOL_WXWIN_pure(Create);
589 DEC_PYCALLBACK_VOID_(OnPopup);
590 DEC_PYCALLBACK_VOID_(OnDismiss);
591 DEC_PYCALLBACK__STRING(SetStringValue);
592 DEC_PYCALLBACK_STRING__constpure(GetStringValue);
593 DEC_PYCALLBACK_VOID_(OnComboDoubleClick);
594 DEC_PYCALLBACK_BOOL_(LazyCreate);
595
596 virtual wxWindow *GetControl()
597 {
598 wxWindow* rval = NULL;
599 const char* errmsg = "GetControl should return an object derived from wx.Window.";
600 wxPyBlock_t blocked = wxPyBeginBlockThreads();
601 if (wxPyCBH_findCallback(m_myInst, "GetControl")) {
602 PyObject* ro;
603 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
604 if (ro) {
605 if (!wxPyConvertSwigPtr(ro, (void**)&rval, wxT("wxWindow")))
606 PyErr_SetString(PyExc_TypeError, errmsg);
607 Py_DECREF(ro);
608 }
609 }
610 else
611 PyErr_SetString(PyExc_TypeError, errmsg);
612 wxPyEndBlockThreads(blocked);
613 return rval;
614 }
615
616
617 virtual void PaintComboControl( wxDC& dc, const wxRect& rect )
618 {
619 bool found;
620 wxPyBlock_t blocked = wxPyBeginBlockThreads();
621 if ((found = wxPyCBH_findCallback(m_myInst, "PaintComboControl"))) {
622 PyObject* odc = wxPyMake_wxObject(&dc,false);
623 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
624 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
625 Py_DECREF(odc);
626 Py_DECREF(orect);
627 }
628 wxPyEndBlockThreads(blocked);
629 if (! found)
630 wxComboPopup::PaintComboControl(dc, rect);
631 }
632
633
634 virtual void OnComboKeyEvent( wxKeyEvent& event )
635 {
636 bool found;
637 wxPyBlock_t blocked = wxPyBeginBlockThreads();
638 if ((found = wxPyCBH_findCallback(m_myInst, "OnComboKeyEvent"))) {
639 PyObject* oevt = wxPyConstructObject((void*)&event, wxT("wxKeyEvent"), 0);
640 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", oevt));
641 Py_DECREF(oevt);
642 }
643 wxPyEndBlockThreads(blocked);
644 if (! found)
645 wxComboPopup::OnComboKeyEvent(event);
646 }
647
648
649 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
650 {
651 const char* errmsg = "GetAdjustedSize should return a wx.Size or a 2-tuple of integers.";
652 bool found;
653 wxSize rval(0,0);
654 wxSize* rptr = &rval;
655 wxPyBlock_t blocked = wxPyBeginBlockThreads();
656 if ((found = wxPyCBH_findCallback(m_myInst, "GetAdjustedSize"))) {
657 PyObject* ro;
658 ro = wxPyCBH_callCallbackObj(
659 m_myInst, Py_BuildValue("(iii)", minWidth, prefHeight, maxHeight));
660 if (ro) {
661 if (! wxSize_helper(ro, &rptr))
662 PyErr_SetString(PyExc_TypeError, errmsg);
663 else
664 rval = *rptr;
665 Py_DECREF(ro);
666 }
667 }
668 wxPyEndBlockThreads(blocked);
669 if (! found)
670 rval = wxComboPopup::GetAdjustedSize(minWidth, prefHeight, maxHeight);
671 return rval;
672 }
673
674 wxComboCtrl* GetCombo() { return (wxComboCtrl*)m_combo; }
675
676 PYPRIVATE;
677 };
678
679
680 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
681 IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
682 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
683 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
684 IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
685 IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
686 IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
687 IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
688
689 %}
690
691
692
693 // Now declare wxPyComboPopup for Python
694 DocStr(wxPyComboPopup,
695 "In order to use a custom popup with `wx.combo.ComboCtrl` an interface
696 class derived from wx.combo.ComboPopup is used to manage the interface
697 between the popup control and the popup. You can either derive a new
698 class from both the widget class and this ComboPopup class, or the
699 derived class can have a reference to the widget used for the popup.
700 In either case you simply need to return the widget from the
701 `GetControl` method to allow the ComboCtrl to interact with it.
702
703 Nearly all of the methods of this class are overridable in Python.", "");
704
705
706 MustHaveApp(wxPyComboPopup);
707 %rename(ComboPopup) wxPyComboPopup;
708
709 class wxPyComboPopup
710 {
711 public:
712 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
713
714 DocCtorStr(
715 wxPyComboPopup(),
716 "Constructor", "");
717
718 DocCtorStr(
719 ~wxPyComboPopup(),
720 "Destructor", "");
721
722
723 void _setCallbackInfo(PyObject* self, PyObject* _class);
724
725 DocDeclStr(
726 virtual void , Init(),
727 "This method is called after the popup is contructed and has been
728 assigned to the ComboCtrl. Derived classes can override this to do
729 extra inialization or whatever.", "");
730
731
732 // Create the popup child control.
733 // Return true for success.
734 DocDeclStr(
735 virtual bool , Create(wxWindow* parent),
736 "The derived class must implement this method to create the popup
737 control. It should be a child of the ``parent`` passed in, but other
738 than that there is much flexibility in what the widget can be, its
739 style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
740 this return value is not currently checked...)", "");
741
742
743 DocDeclStr(
744 virtual wxWindow *, GetControl(),
745 "The derived class must implement this method and it should return a
746 reference to the widget created in the `Create` method. If the
747 derived class inherits from both the widget class and ComboPopup then
748 the return value is probably just ``self``.", "");
749
750
751 DocDeclStr(
752 virtual void , OnPopup(),
753 "The derived class may implement this to do special processing when
754 popup is shown.", "");
755
756
757 DocDeclStr(
758 virtual void , OnDismiss(),
759 "The derived class may implement this to do special processing when
760 popup is hidden.", "");
761
762
763 DocDeclStr(
764 virtual void , SetStringValue( const wxString& value ),
765 "Called just prior to displaying the popup. The derived class can
766 implement this to \"select\" the item in the popup that coresponds to
767 the passed in string value, if appropriate. The default
768 implementation does nothing.", "");
769
770
771 DocDeclStr(
772 virtual wxString , GetStringValue() const,
773 "Gets the string representation of the currently selected value to be
774 used to display in the combo widget.", "");
775
776
777 DocDeclStr(
778 virtual void , PaintComboControl( wxDC& dc, const wxRect& rect ),
779 "This is called to custom paint in the combo control itself (ie. not
780 the popup). Default implementation draws the current value as string.", "");
781
782
783 DocDeclStr(
784 virtual void , OnComboKeyEvent( wxKeyEvent& event ),
785 "Receives key events from the parent ComboCtrl. Events not handled
786 should be skipped, as usual.", "");
787
788
789 DocDeclStr(
790 virtual void , OnComboDoubleClick(),
791 "Implement this method in the derived class if you need to support
792 special actions when the user double-clicks on the parent ComboCtrl.", "");
793
794
795 DocDeclStr(
796 virtual wxSize , GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ),
797 "The derived class may implement this method to return adjusted size
798 for the popup control, according to the variables given. It is called
799 on every popup, just prior to `OnPopup`.
800
801 :param minWidth: Preferred minimum width.
802 :param prefHeight: Preferred height. May be -1 to indicate no preference.
803 :maxWidth: Max height for window, as limited by screen size, and
804 should only be rounded down, if necessary.
805 ", "");
806
807
808 DocDeclStr(
809 virtual bool , LazyCreate(),
810 "The derived class may implement this to return ``True`` if it wants to
811 delay the call to `Create` until the popup is shown for the first
812 time. It is more efficient, but on the other hand it is often more
813 convenient to have the control created immediately. The default
814 implementation returns ``False``.", "");
815
816
817 //
818 // Utilies
819 //
820
821
822 DocDeclStr(
823 void , Dismiss(),
824 "Hides the popup", "");
825
826
827 DocDeclStr(
828 bool , IsCreated() const,
829 "Returns true if `Create` has been called.", "");
830
831
832 DocDeclStr(
833 static void , DefaultPaintComboControl( wxComboCtrlBase* combo,
834 wxDC& dc,
835 const wxRect& rect ),
836 "Default PaintComboControl behaviour", "");
837
838
839 DocDeclStr(
840 wxPyComboCtrl* , GetCombo(),
841 "Returns a reference to the `wx.combo.ComboCtrl` this ComboPopup object
842 is associated with.", "");
843
844 };
845
846
847
848 //---------------------------------------------------------------------------
849 %newgroup
850
851
852 enum {
853 wxODCB_DCLICK_CYCLES,
854 wxODCB_STD_CONTROL_PAINT,
855 wxODCB_PAINTING_CONTROL,
856 wxODCB_PAINTING_SELECTED
857 };
858
859
860
861 // C++ implemetation of Python aware wxOwnerDrawnComboBox
862 %{
863 class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
864 {
865 public:
866 wxPyOwnerDrawnComboBox() : wxOwnerDrawnComboBox() {}
867 wxPyOwnerDrawnComboBox(wxWindow *parent,
868 wxWindowID id,
869 const wxString& value,
870 const wxPoint& pos,
871 const wxSize& size,
872 const wxArrayString& choices,
873 long style,
874 const wxValidator& validator = wxDefaultValidator,
875 const wxString& name = wxPyComboBoxNameStr)
876 : wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style,
877 validator, name)
878 {}
879
880 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawItem);
881 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItem);
882 DEC_PYCALLBACK_COORD_SIZET_const(OnMeasureItemWidth);
883 DEC_PYCALLBACK__DCRECTINTINT_const(OnDrawBackground);
884
885
886 PYPRIVATE;
887 };
888
889 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
890 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
891 IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
892 IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
893
894 %}
895
896
897
898 // Now declare wxPyOwnerDrawnComboBox for Python
899
900 DocStr(wxPyOwnerDrawnComboBox,
901 "wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
902 items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
903 popup and a `wx.ControlWithItems` API.
904
905 Implementing item drawing and measuring is similar to wx.VListBox.
906 The application needs to subclass wx.combo.OwnerDrawnComboBox and
907 implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
908 methods.", "");
909
910 MustHaveApp(wxPyOwnerDrawnComboBox);
911 %rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
912
913 class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
914 public wxItemContainer
915 {
916 public:
917 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
918 %pythonAppend wxPyOwnerDrawnComboBox() "";
919
920 DocCtorStr(
921 wxPyOwnerDrawnComboBox(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 "Standard constructor.", "");
931
932 DocCtorStrName(wxPyOwnerDrawnComboBox(),
933 "2-phase create constructor.", "",
934 PreOwnerDrawnComboBox);
935
936 void _setCallbackInfo(PyObject* self, PyObject* _class);
937
938
939 DocDeclStr(
940 bool , Create(wxWindow *parent,
941 wxWindowID id = -1,
942 const wxString& value = wxPyEmptyString,
943 const wxPoint& pos = wxDefaultPosition,
944 const wxSize& size = wxDefaultSize,
945 const wxArrayString& choices = wxPyEmptyStringArray,
946 long style = 0,
947 const wxValidator& validator = wxDefaultValidator,
948 const wxString& name = wxPyComboBoxNameStr),
949 "Create the UI object, and other initialization.", "");
950
951
952 DocDeclStr(
953 virtual int , GetWidestItemWidth(),
954 "Return the widest item width (recalculating it if necessary.)", "");
955
956
957 DocDeclStr(
958 virtual int , GetWidestItem(),
959 "Return the index of the widest item (recalculating it if necessary.)", "");
960
961
962 void SetSelection(int n);
963 %Rename(SetMark, void , SetSelection(long from, long to));
964
965
966 // Callback for drawing. Font, background and text colour have been
967 // prepared according to selection, focus and such.
968 // item: item index to be drawn, may be wxNOT_FOUND when painting combo control itself
969 // and there is no valid selection
970 // flags: wxODCB_PAINTING_CONTROL is set if painting to combo control instead of list
971 DocDeclStr(
972 virtual void , OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const,
973 "The derived class may implement this function to actually draw the
974 item with the given index on the provided DC. If this method is not
975 overridden, the item text is simply drawn as if the control was a
976 normal combobox.
977
978 :param dc: The device context to use for drawing.
979 :param rect: The bounding rectangle for the item being drawn, the
980 DC's clipping region is set to this rectangle before
981 calling this method.
982 :param item: The index of the item to be drawn.
983
984 :param flags: ``wx.combo.ODCB_PAINTING_CONTROL`` (The Combo control itself
985 is being painted, instead of a list item. The ``item``
986 parameter may be ``wx.NOT_FOUND`` in this case.
987 ``wx.combo.ODCB_PAINTING_SELECTED`` (An item with
988 selection background is being painted. The DC's text colour
989 should already be correct.
990 ", "");
991
992
993 DocDeclStr(
994 virtual wxCoord , OnMeasureItem( size_t item ) const,
995 "The derived class may implement this method to return the height of
996 the specified item (in pixels). The default implementation returns
997 text height, as if this control was a normal combobox.", "");
998
999
1000 DocDeclStr(
1001 virtual wxCoord , OnMeasureItemWidth( size_t item ) const,
1002 "The derived class may implement this method to return the width of the
1003 specified item (in pixels). If -1 is returned, then the item text
1004 width is used. The default implementation returns -1.", "");
1005
1006
1007 DocDeclStr(
1008 virtual void , OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const,
1009 "This method is used to draw the items background and, maybe, a border
1010 around it.
1011
1012 The base class version implements a reasonable default behaviour which
1013 consists in drawing the selected item with the standard background
1014 colour and drawing a border around the item if it is either selected
1015 or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1016
1017
1018 };
1019
1020 //---------------------------------------------------------------------------
1021
1022 %{
1023 #include <wx/bmpcbox.h>
1024 %}
1025
1026 DocStr(wxBitmapComboBox,
1027 "A combobox that displays a bitmap in front of the list items. It
1028 currently only allows using bitmaps of one size, and resizes itself so
1029 that a bitmap can be shown next to the text field.",
1030 "
1031
1032 Window Styles
1033 -------------
1034 =================== ============================================
1035 wx.CB_READONLY Creates a combobox without a text editor. On
1036 some platforms the control may appear very
1037 different when this style is used.
1038 wx.CB_SORT Sorts the entries in the list alphabetically.
1039 wx.TE_PROCESS_ENTER The control will generate the event
1040 wx.EVT__TEXT_ENTER (otherwise pressing Enter
1041 key is either processed internally by the
1042 control or used for navigation between dialog
1043 controls).
1044 =================== ============================================
1045 ");
1046
1047 MustHaveApp(wxBitmapComboBox);
1048
1049 class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1050 {
1051 public:
1052 %pythonAppend wxBitmapComboBox "self._setOORInfo(self);";
1053 %pythonAppend wxBitmapComboBox() "";
1054
1055 DocCtorStr(
1056 wxBitmapComboBox(wxWindow *parent,
1057 wxWindowID id = -1,
1058 const wxString& value = wxPyEmptyString,
1059 const wxPoint& pos = wxDefaultPosition,
1060 const wxSize& size = wxDefaultSize,
1061 const wxArrayString& choices = wxPyEmptyStringArray,
1062 long style = 0,
1063 const wxValidator& validator = wxDefaultValidator,
1064 const wxString& name = wxBitmapComboBoxNameStr),
1065 "Standard constructor", "");
1066
1067 DocCtorStrName(wxBitmapComboBox(),
1068 "2-phase create constructor.", "",
1069 PreBitmapComboBox);
1070
1071 DocDeclStr(
1072 bool , Create(wxWindow *parent,
1073 wxWindowID id = -1,
1074 const wxString& value = wxPyEmptyString,
1075 const wxPoint& pos = wxDefaultPosition,
1076 const wxSize& size = wxDefaultSize,
1077 const wxArrayString& choices = wxPyEmptyStringArray,
1078 long style = 0,
1079 const wxValidator& validator = wxDefaultValidator,
1080 const wxString& name = wxBitmapComboBoxNameStr),
1081 "Create the UI object, and other initialization.", "");
1082
1083
1084
1085 %extend {
1086 DocStr(Append,
1087 "Adds the item to the control, associating the given data with the item
1088 if not None. The return value is the index of the newly added item.", "");
1089 int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap, PyObject* clientData=NULL) {
1090 if (clientData) {
1091 wxPyClientData* data = new wxPyClientData(clientData);
1092 return self->Append(item, bitmap, data);
1093 } else
1094 return self->Append(item, bitmap);
1095 }
1096 }
1097
1098
1099 DocDeclStr(
1100 virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
1101 "Returns the image of the item with the given index.", "");
1102
1103
1104 %extend {
1105 DocStr(Insert,
1106 "Insert an item into the control before the item at the ``pos`` index,
1107 optionally associating some data object with the item.", "");
1108 int Insert(const wxString& item, const wxBitmap& bitmap,
1109 /*unsigned*/ int pos, PyObject* clientData=NULL) {
1110 if (clientData) {
1111 wxPyClientData* data = new wxPyClientData(clientData);
1112 return self->Insert(item, bitmap, pos, data);
1113 } else
1114 return self->Insert(item, bitmap, pos);
1115 }
1116 }
1117
1118
1119 DocDeclStr(
1120 virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
1121 "Sets the image for the given item.", "");
1122
1123
1124 DocDeclStr(
1125 virtual wxSize , GetBitmapSize() const,
1126 "Returns size of the image used in list.", "");
1127
1128
1129 };
1130
1131 //---------------------------------------------------------------------------
1132
1133 %init %{
1134 // Map renamed classes back to their common name for OOR
1135 wxPyPtrTypeMap_Add("wxComboCtrl", "wxPyComboCtrl");
1136 wxPyPtrTypeMap_Add("wxComboPopup", "wxPyComboPopup");
1137 wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
1138 %}
1139 //---------------------------------------------------------------------------
1140