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