]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/combo.i
All platforms have the same GLCanvas API now
[wxWidgets.git] / wxPython / src / combo.i
CommitLineData
84bc0d49
RD
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
9745cf4d 14"ComboCtrl class that can have any type of popup widget, and also an
84bc0d49
RD
15owner-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
37MAKE_CONST_WXSTRING_NOSWIG(ComboBoxNameStr);
38MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
39
40%{
41 const wxArrayString wxPyEmptyStringArray;
42%}
43
44
45enum {
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,
cbfc9df6
RD
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
84bc0d49
RD
59};
60
61
62// Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
63enum
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
84dd1dd8
RD
71DocStr( wxComboCtrlFeatures,
72 "Namespace for `wx.combo.ComboCtrl` feature flags. See
73`wx.combo.ComboCtrl.GetFeatures`.", "");
84bc0d49
RD
74struct 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%{
104class wxPyComboCtrl : public wxComboCtrl
105{
106 DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
107public:
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
84dd1dd8
RD
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
f27895d2
RD
151 virtual wxWindow *GetMainWindowOfCompositeControl()
152 {
153 return wxComboCtrl::GetMainWindowOfCompositeControl();
154 }
155
156
84bc0d49
RD
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
84dd1dd8
RD
165 DEC_PYCALLBACK_VOID_(ShowPopup);
166 DEC_PYCALLBACK_VOID_(HidePopup);
84bc0d49
RD
167 DEC_PYCALLBACK_VOID_(OnButtonClick);
168 DEC_PYCALLBACK__RECTINT(DoShowPopup);
169 DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
170
171 PYPRIVATE;
172};
173
174IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
175
84dd1dd8
RD
176IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
177IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
84bc0d49
RD
178IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
179IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
180IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
181
182%}
183
184
185
186// Now declare wxPyComboCtrl for Python
84dd1dd8
RD
187
188DocStr(wxPyComboCtrl,
189"A combo control is a generic combobox that allows for a totally custom
190popup. In addition it has other customization features. For instance,
191position and size of the dropdown button can be changed.
192
193To specify what to use for the popup control you need to derive a
194class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
195`SetPopupControl`. It doesn't derive from any widget class so it can
196be used either as a mixin class combined with some standard or custom
197widget, or you can use the derived ComboPopup to create and hold an
198independent reference to the widget to be used for the popup.
199", "
a6794ed8 200
84dd1dd8
RD
201Window 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
84bc0d49
RD
221MustHaveApp(wxPyComboCtrl);
222%rename(ComboCtrl) wxPyComboCtrl;
223
224class wxPyComboCtrl : public wxControl
225{
226public:
227 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
228 %pythonAppend wxPyComboCtrl() "";
229
84dd1dd8
RD
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);
84bc0d49 245
84bc0d49
RD
246
247 void _setCallbackInfo(PyObject* self, PyObject* _class);
248
84dd1dd8
RD
249 DocDeclStr(
250 virtual void , ShowPopup(),
251 "Show the popup window.", "");
252
253 DocDeclStr(
254 virtual void , HidePopup(),
255 "Dismisses the popup window.", "");
256
84bc0d49
RD
257
258 // Override for totally custom combo action
84dd1dd8
RD
259 DocDeclStr(
260 virtual void , OnButtonClick(),
261 "Implement in a derived class to define what happens on dropdown button
262click. Default action is to show the popup. ", "");
263
84bc0d49
RD
264
265 // return true if the popup is currently shown
84dd1dd8
RD
266 DocDeclStr(
267 bool , IsPopupShown() const,
268 "Returns true if the popup is currently shown.", "");
84bc0d49
RD
269
270
84bc0d49 271 %disownarg(wxPyComboPopup* popup);
84dd1dd8
RD
272 DocDeclStr(
273 void , SetPopupControl( wxPyComboPopup* popup ),
274 "Set popup interface class derived from `wx.combo.ComboPopup`. This
275method should be called as soon as possible after the control has been
276created, unless `OnButtonClick` has been overridden.", "");
84bc0d49
RD
277 %cleardisown(wxPyComboPopup* popup);
278
279
84dd1dd8
RD
280 DocDeclStr(
281 wxPyComboPopup* , GetPopupControl(),
282 "Returns the current popup interface that has been set with
283`SetPopupControl`.", "");
284
84bc0d49 285
84dd1dd8
RD
286 DocDeclStr(
287 wxWindow *, GetPopupWindow() const,
288 "Returns the popup window containing the popup control.", "");
84bc0d49 289
84bc0d49 290
84dd1dd8
RD
291 DocDeclStr(
292 wxTextCtrl *, GetTextCtrl() const,
293 "Get the text control which is part of the combo control.", "");
84bc0d49 294
84dd1dd8
RD
295
296 DocDeclStr(
297 wxWindow *, GetButton() const,
298 "Get the dropdown button which is part of the combobox. Note: it's not
299necessarily a wx.Button or wx.BitmapButton.", "");
300
a6794ed8
RD
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...
84dd1dd8
RD
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);
a6794ed8
RD
308// virtual void SetValidator(const wxValidator &validator);
309// virtual wxValidator *GetValidator();
84bc0d49 310
a6794ed8 311
84bc0d49
RD
312 // wxTextCtrl methods - for readonly combo they should return
313 // without errors.
84dd1dd8
RD
314
315 DocDeclStr(
316 virtual wxString , GetValue() const,
317 "Returns text representation of the current value. For writable combo
318control 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
323with wx.CB_READONLY style the string must be accepted by the popup (for
324instance, exist in the dropdown list), otherwise the call to
325SetValue is ignored.", "");
326
84bc0d49
RD
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
84bc0d49 340
84dd1dd8
RD
341 DocDeclStr(
342 void , SetText(const wxString& value),
343 "Sets the text for the text field without affecting the popup. Thus,
344unlike `SetValue`, it works equally well with combo control using
345wx.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
84bc0d49
RD
352
353 //
354 // Popup customization methods
355 //
356
84dd1dd8
RD
357 DocDeclStr(
358 void , SetPopupMinWidth( int width ),
359 "Sets minimum width of the popup. If wider than combo control, it will
360extend to the left. A value of -1 indicates to use the default. The
361popup 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
367use 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
373control. Values are given in pixels, and the defaults are zero. It
f27895d2 374is up to the popup to fully take these values into account.", "");
84dd1dd8
RD
375
376
377 DocDeclStr(
378 void , SetCustomPaintWidth( int width ),
379 "Set width, in pixels, of custom painted area in control without
380wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
381to indicate the area that is not covered by the focus rectangle.", "");
382
84bc0d49
RD
383 int GetCustomPaintWidth() const;
384
84bc0d49 385
84dd1dd8
RD
386 DocDeclStr(
387 void , SetPopupAnchor( int anchorSide ),
388 "Set side of the control to which the popup will align itself. Valid
389values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
390most 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", "");
84bc0d49 420
84bc0d49 421
84dd1dd8
RD
422 DocDeclStr(
423 void , SetTextIndent( int indent ),
424 "This will set the space in pixels between left edge of the control and
425the text, regardless whether control is read-only or not. A value of -1 can
426be given to indicate platform default.", "");
84bc0d49 427
84bc0d49 428
84dd1dd8
RD
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
437borders 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
443guarantees ability to focus the popup control, and allows common
444native controls to function normally. This alternative popup window is
445usually a wxDialog, and as such, when it is shown, its parent
446top-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
452the argument.", "");
84bc0d49 453
84bc0d49
RD
454
455 //
456 // Utilies needed by the popups or native implementations
457 //
458
84dd1dd8
RD
459 DocDeclStr(
460 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
461 "Returns true if given key combination should toggle the popup.", "");
462
84bc0d49 463
84dd1dd8
RD
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
467way typical on platform. This includes painting the focus/disabled
468background and setting the clipping region. Unless you plan to paint
469your own focus indicator, you should always call this in your
470wxComboPopup::PaintComboControl implementation. In addition, it sets
471pen and text colour to what looks good and proper against the
472background.
473
474flags 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.", "");
84bc0d49 488
84bc0d49 489
84bc0d49
RD
490 const wxBitmap& GetBitmapNormal() const;
491 const wxBitmap& GetBitmapPressed() const;
492 const wxBitmap& GetBitmapHover() const;
493 const wxBitmap& GetBitmapDisabled() const;
494
84bc0d49
RD
495 wxUint32 GetInternalFlags() const;
496
84dd1dd8
RD
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", "");
84bc0d49 505
84bc0d49
RD
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 );
f27895d2 522 virtual wxWindow *GetMainWindowOfCompositeControl();
84bc0d49 523
84dd1dd8
RD
524 DocDeclStr(
525 static int , GetFeatures(),
526 "Returns a bit-list of flags indicating which features of the ComboCtrl
527functionality are implemented by this implemetation. See
528`wx.combo.ComboCtrlFeatures`.", "");
529
84bc0d49
RD
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.
84dd1dd8
RD
541 DocDeclStr(
542 virtual void , DoShowPopup( const wxRect& rect, int flags ),
543 "Shows and positions the popup.
544
545Flags:
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
559derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
560", "");
84bc0d49 561
84bc0d49 562
f27895d2
RD
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
84bc0d49
RD
579};
580
581//---------------------------------------------------------------------------
582%newgroup
583
584
585// C++ implemetation of Python aware wxComboCtrl
586%{
587class wxPyComboPopup : public wxComboPopup
588{
589public:
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
687IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
688IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
689IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
690IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
691IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
692IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
693IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
694IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
695
696%}
697
698
699
84dd1dd8
RD
700// Now declare wxPyComboPopup for Python
701DocStr(wxPyComboPopup,
702"In order to use a custom popup with `wx.combo.ComboCtrl` an interface
703class derived from wx.combo.ComboPopup is used to manage the interface
704between the popup control and the popup. You can either derive a new
705class from both the widget class and this ComboPopup class, or the
706derived class can have a reference to the widget used for the popup.
707In either case you simply need to return the widget from the
708`GetControl` method to allow the ComboCtrl to interact with it.
709
710Nearly all of the methods of this class are overridable in Python.", "");
711
712
84bc0d49
RD
713MustHaveApp(wxPyComboPopup);
714%rename(ComboPopup) wxPyComboPopup;
715
716class wxPyComboPopup
717{
718public:
719 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
720
84dd1dd8
RD
721 DocCtorStr(
722 wxPyComboPopup(),
723 "Constructor", "");
724
725 DocCtorStr(
726 ~wxPyComboPopup(),
727 "Destructor", "");
728
84bc0d49
RD
729
730 void _setCallbackInfo(PyObject* self, PyObject* _class);
731
84dd1dd8
RD
732 DocDeclStr(
733 virtual void , Init(),
734 "This method is called after the popup is contructed and has been
735assigned to the ComboCtrl. Derived classes can override this to do
736extra inialization or whatever.", "");
737
84bc0d49
RD
738
739 // Create the popup child control.
740 // Return true for success.
84dd1dd8
RD
741 DocDeclStr(
742 virtual bool , Create(wxWindow* parent),
743 "The derived class must implement this method to create the popup
744control. It should be a child of the ``parent`` passed in, but other
745than that there is much flexibility in what the widget can be, its
746style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
747this return value is not currently checked...)", "");
748
84bc0d49 749
84dd1dd8
RD
750 DocDeclStr(
751 virtual wxWindow *, GetControl(),
752 "The derived class must implement this method and it should return a
753reference to the widget created in the `Create` method. If the
754derived class inherits from both the widget class and ComboPopup then
755the return value is probably just ``self``.", "");
84bc0d49 756
84bc0d49 757
84dd1dd8
RD
758 DocDeclStr(
759 virtual void , OnPopup(),
760 "The derived class may implement this to do special processing when
761popup is shown.", "");
84bc0d49 762
84bc0d49 763
84dd1dd8
RD
764 DocDeclStr(
765 virtual void , OnDismiss(),
766 "The derived class may implement this to do special processing when
767popup is hidden.", "");
84bc0d49 768
84bc0d49 769
84dd1dd8
RD
770 DocDeclStr(
771 virtual void , SetStringValue( const wxString& value ),
772 "Called just prior to displaying the popup. The derived class can
773implement this to \"select\" the item in the popup that coresponds to
774the passed in string value, if appropriate. The default
775implementation does nothing.", "");
84bc0d49 776
84bc0d49 777
84dd1dd8
RD
778 DocDeclStr(
779 virtual wxString , GetStringValue() const,
780 "Gets the string representation of the currently selected value to be
781used 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
787the 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
793should 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
799special 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
805for the popup control, according to the variables given. It is called
806on 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
818delay the call to `Create` until the popup is shown for the first
819time. It is more efficient, but on the other hand it is often more
820convenient to have the control created immediately. The default
821implementation returns ``False``.", "");
84bc0d49 822
84bc0d49
RD
823
824 //
825 // Utilies
826 //
827
84bc0d49 828
84dd1dd8
RD
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.", "");
84bc0d49 837
84bc0d49 838
84dd1dd8
RD
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
849is associated with.", "");
84bc0d49
RD
850
851};
852
853
854
855//---------------------------------------------------------------------------
856%newgroup
857
858
859enum {
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%{
870class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
871{
872public:
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
896IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
897IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
898IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
899IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
900
901%}
902
903
904
84dd1dd8
RD
905// Now declare wxPyOwnerDrawnComboBox for Python
906
907DocStr(wxPyOwnerDrawnComboBox,
908"wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
909items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
910popup and a `wx.ControlWithItems` API.
911
912Implementing item drawing and measuring is similar to wx.VListBox.
913The application needs to subclass wx.combo.OwnerDrawnComboBox and
914implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
915methods.", "");
916
84bc0d49
RD
917MustHaveApp(wxPyOwnerDrawnComboBox);
918%rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
919
920class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
921 public wxItemContainer
922{
923public:
924 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
925 %pythonAppend wxPyOwnerDrawnComboBox() "";
926
84dd1dd8
RD
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);
84bc0d49 942
84dd1dd8 943 void _setCallbackInfo(PyObject* self, PyObject* _class);
84bc0d49 944
84dd1dd8
RD
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
84bc0d49 968
84dd1dd8
RD
969 void SetSelection(int n);
970 %Rename(SetMark, void , SetSelection(long from, long to));
84bc0d49 971
84bc0d49 972
84dd1dd8
RD
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
981item with the given index on the provided DC. If this method is not
982overridden, the item text is simply drawn as if the control was a
983normal 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
1003the specified item (in pixels). The default implementation returns
1004text 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
1010specified item (in pixels). If -1 is returned, then the item text
1011width 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
1017around it.
1018
1019The base class version implements a reasonable default behaviour which
1020consists in drawing the selected item with the standard background
1021colour and drawing a border around the item if it is either selected
1022or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1023
84bc0d49 1024
84bc0d49
RD
1025};
1026
f27895d2
RD
1027//---------------------------------------------------------------------------
1028
1029%{
1030#include <wx/bmpcbox.h>
1031%}
1032
1033DocStr(wxBitmapComboBox,
1034 "A combobox that displays a bitmap in front of the list items. It
1035currently only allows using bitmaps of one size, and resizes itself so
1036that a bitmap can be shown next to the text field.",
1037"
a6794ed8 1038
f27895d2
RD
1039Window 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
1054MustHaveApp(wxBitmapComboBox);
1055
1056class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1057{
1058public:
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
1095if 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(
9745cf4d 1107 virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
f27895d2
RD
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,
1114optionally associating some data object with the item.", "");
1115 int Insert(const wxString& item, const wxBitmap& bitmap,
9745cf4d 1116 /*unsigned*/ int pos, PyObject* clientData=NULL) {
f27895d2
RD
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(
9745cf4d 1127 virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
f27895d2
RD
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};
84bc0d49
RD
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");
84dd1dd8 1144 wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
84bc0d49
RD
1145%}
1146//---------------------------------------------------------------------------
1147