]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/combo.i
comment out test code
[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,
52};
53
54
55// Flags used by PreprocessMouseEvent and HandleButtonMouseEvent
56enum
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
84dd1dd8
RD
64DocStr( wxComboCtrlFeatures,
65 "Namespace for `wx.combo.ComboCtrl` feature flags. See
66`wx.combo.ComboCtrl.GetFeatures`.", "");
84bc0d49
RD
67struct 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%{
97class wxPyComboCtrl : public wxComboCtrl
98{
99 DECLARE_ABSTRACT_CLASS(wxPyComboCtrl)
100public:
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
84dd1dd8
RD
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
f27895d2
RD
144 virtual wxWindow *GetMainWindowOfCompositeControl()
145 {
146 return wxComboCtrl::GetMainWindowOfCompositeControl();
147 }
148
149
84bc0d49
RD
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
84dd1dd8
RD
158 DEC_PYCALLBACK_VOID_(ShowPopup);
159 DEC_PYCALLBACK_VOID_(HidePopup);
84bc0d49
RD
160 DEC_PYCALLBACK_VOID_(OnButtonClick);
161 DEC_PYCALLBACK__RECTINT(DoShowPopup);
162 DEC_PYCALLBACK_BOOL_RECTINT(AnimateShow);
163
164 PYPRIVATE;
165};
166
167IMPLEMENT_ABSTRACT_CLASS(wxPyComboCtrl, wxComboCtrl);
168
84dd1dd8
RD
169IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, ShowPopup);
170IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, HidePopup);
84bc0d49
RD
171IMP_PYCALLBACK_VOID_(wxPyComboCtrl, wxComboCtrl, OnButtonClick);
172IMP_PYCALLBACK__RECTINT(wxPyComboCtrl, wxComboCtrl, DoShowPopup);
173IMP_PYCALLBACK_BOOL_RECTINT(wxPyComboCtrl, wxComboCtrl, AnimateShow);
174
175%}
176
177
178
179// Now declare wxPyComboCtrl for Python
84dd1dd8
RD
180
181DocStr(wxPyComboCtrl,
182"A combo control is a generic combobox that allows for a totally custom
183popup. In addition it has other customization features. For instance,
184position and size of the dropdown button can be changed.
185
186To specify what to use for the popup control you need to derive a
187class from `wx.combo.ComboPopup` and pass it to the ComboCtrl with
188`SetPopupControl`. It doesn't derive from any widget class so it can
189be used either as a mixin class combined with some standard or custom
190widget, or you can use the derived ComboPopup to create and hold an
191independent reference to the widget to be used for the popup.
192", "
a6794ed8 193
84dd1dd8
RD
194Window 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
84bc0d49
RD
214MustHaveApp(wxPyComboCtrl);
215%rename(ComboCtrl) wxPyComboCtrl;
216
217class wxPyComboCtrl : public wxControl
218{
219public:
220 %pythonAppend wxPyComboCtrl "self._setOORInfo(self);" setCallbackInfo(ComboCtrl)
221 %pythonAppend wxPyComboCtrl() "";
222
84dd1dd8
RD
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);
84bc0d49 238
84bc0d49
RD
239
240 void _setCallbackInfo(PyObject* self, PyObject* _class);
241
84dd1dd8
RD
242 DocDeclStr(
243 virtual void , ShowPopup(),
244 "Show the popup window.", "");
245
246 DocDeclStr(
247 virtual void , HidePopup(),
248 "Dismisses the popup window.", "");
249
84bc0d49
RD
250
251 // Override for totally custom combo action
84dd1dd8
RD
252 DocDeclStr(
253 virtual void , OnButtonClick(),
254 "Implement in a derived class to define what happens on dropdown button
255click. Default action is to show the popup. ", "");
256
84bc0d49
RD
257
258 // return true if the popup is currently shown
84dd1dd8
RD
259 DocDeclStr(
260 bool , IsPopupShown() const,
261 "Returns true if the popup is currently shown.", "");
84bc0d49
RD
262
263
84bc0d49 264 %disownarg(wxPyComboPopup* popup);
84dd1dd8
RD
265 DocDeclStr(
266 void , SetPopupControl( wxPyComboPopup* popup ),
267 "Set popup interface class derived from `wx.combo.ComboPopup`. This
268method should be called as soon as possible after the control has been
269created, unless `OnButtonClick` has been overridden.", "");
84bc0d49
RD
270 %cleardisown(wxPyComboPopup* popup);
271
272
84dd1dd8
RD
273 DocDeclStr(
274 wxPyComboPopup* , GetPopupControl(),
275 "Returns the current popup interface that has been set with
276`SetPopupControl`.", "");
277
84bc0d49 278
84dd1dd8
RD
279 DocDeclStr(
280 wxWindow *, GetPopupWindow() const,
281 "Returns the popup window containing the popup control.", "");
84bc0d49 282
84bc0d49 283
84dd1dd8
RD
284 DocDeclStr(
285 wxTextCtrl *, GetTextCtrl() const,
286 "Get the text control which is part of the combo control.", "");
84bc0d49 287
84dd1dd8
RD
288
289 DocDeclStr(
290 wxWindow *, GetButton() const,
291 "Get the dropdown button which is part of the combobox. Note: it's not
292necessarily a wx.Button or wx.BitmapButton.", "");
293
a6794ed8
RD
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...
84dd1dd8
RD
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);
a6794ed8
RD
301// virtual void SetValidator(const wxValidator &validator);
302// virtual wxValidator *GetValidator();
84bc0d49 303
a6794ed8 304
84bc0d49
RD
305 // wxTextCtrl methods - for readonly combo they should return
306 // without errors.
84dd1dd8
RD
307
308 DocDeclStr(
309 virtual wxString , GetValue() const,
310 "Returns text representation of the current value. For writable combo
311control 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
316with wx.CB_READONLY style the string must be accepted by the popup (for
317instance, exist in the dropdown list), otherwise the call to
318SetValue is ignored.", "");
319
84bc0d49
RD
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
84bc0d49 333
84dd1dd8
RD
334 DocDeclStr(
335 void , SetText(const wxString& value),
336 "Sets the text for the text field without affecting the popup. Thus,
337unlike `SetValue`, it works equally well with combo control using
338wx.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
84bc0d49
RD
345
346 //
347 // Popup customization methods
348 //
349
84dd1dd8
RD
350 DocDeclStr(
351 void , SetPopupMinWidth( int width ),
352 "Sets minimum width of the popup. If wider than combo control, it will
353extend to the left. A value of -1 indicates to use the default. The
354popup 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
360use 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
366control. Values are given in pixels, and the defaults are zero. It
f27895d2 367is up to the popup to fully take these values into account.", "");
84dd1dd8
RD
368
369
370 DocDeclStr(
371 void , SetCustomPaintWidth( int width ),
372 "Set width, in pixels, of custom painted area in control without
373wx.CB_READONLY style. In read-only OwnerDrawnComboBox, this is used
374to indicate the area that is not covered by the focus rectangle.", "");
375
84bc0d49
RD
376 int GetCustomPaintWidth() const;
377
84bc0d49 378
84dd1dd8
RD
379 DocDeclStr(
380 void , SetPopupAnchor( int anchorSide ),
381 "Set side of the control to which the popup will align itself. Valid
382values are wx.LEFT, wx.RIGHT and 0. The default value 0 means that the
383most 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", "");
84bc0d49 413
84bc0d49 414
84dd1dd8
RD
415 DocDeclStr(
416 void , SetTextIndent( int indent ),
417 "This will set the space in pixels between left edge of the control and
418the text, regardless whether control is read-only or not. A value of -1 can
419be given to indicate platform default.", "");
84bc0d49 420
84bc0d49 421
84dd1dd8
RD
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
430borders 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
436guarantees ability to focus the popup control, and allows common
437native controls to function normally. This alternative popup window is
438usually a wxDialog, and as such, when it is shown, its parent
439top-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
445the argument.", "");
84bc0d49 446
84bc0d49
RD
447
448 //
449 // Utilies needed by the popups or native implementations
450 //
451
84dd1dd8
RD
452 DocDeclStr(
453 virtual bool , IsKeyPopupToggle(const wxKeyEvent& event) const,
454 "Returns true if given key combination should toggle the popup.", "");
455
84bc0d49 456
84dd1dd8
RD
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
460way typical on platform. This includes painting the focus/disabled
461background and setting the clipping region. Unless you plan to paint
462your own focus indicator, you should always call this in your
463wxComboPopup::PaintComboControl implementation. In addition, it sets
464pen and text colour to what looks good and proper against the
465background.
466
467flags 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.", "");
84bc0d49 481
84bc0d49 482
84bc0d49
RD
483 const wxBitmap& GetBitmapNormal() const;
484 const wxBitmap& GetBitmapPressed() const;
485 const wxBitmap& GetBitmapHover() const;
486 const wxBitmap& GetBitmapDisabled() const;
487
84bc0d49
RD
488 wxUint32 GetInternalFlags() const;
489
84dd1dd8
RD
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", "");
84bc0d49 498
84bc0d49
RD
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 );
f27895d2 515 virtual wxWindow *GetMainWindowOfCompositeControl();
84bc0d49 516
84dd1dd8
RD
517 DocDeclStr(
518 static int , GetFeatures(),
519 "Returns a bit-list of flags indicating which features of the ComboCtrl
520functionality are implemented by this implemetation. See
521`wx.combo.ComboCtrlFeatures`.", "");
522
84bc0d49
RD
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.
84dd1dd8
RD
534 DocDeclStr(
535 virtual void , DoShowPopup( const wxRect& rect, int flags ),
536 "Shows and positions the popup.
537
538Flags:
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
552derived class calls `DoShowPopup`. Flags are same as for `DoShowPopup`.
553", "");
84bc0d49 554
84bc0d49 555
f27895d2
RD
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
84bc0d49
RD
572};
573
574//---------------------------------------------------------------------------
575%newgroup
576
577
578// C++ implemetation of Python aware wxComboCtrl
579%{
580class wxPyComboPopup : public wxComboPopup
581{
582public:
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
680IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, Init);
681IMP_PYCALLBACK_BOOL_WXWIN_pure(wxPyComboPopup, wxComboPopup, Create);
682IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnPopup);
683IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnDismiss);
684IMP_PYCALLBACK__STRING(wxPyComboPopup, wxComboPopup, SetStringValue);
685IMP_PYCALLBACK_STRING__constpure(wxPyComboPopup, wxComboPopup, GetStringValue);
686IMP_PYCALLBACK_VOID_(wxPyComboPopup, wxComboPopup, OnComboDoubleClick);
687IMP_PYCALLBACK_BOOL_(wxPyComboPopup, wxComboPopup, LazyCreate);
688
689%}
690
691
692
84dd1dd8
RD
693// Now declare wxPyComboPopup for Python
694DocStr(wxPyComboPopup,
695"In order to use a custom popup with `wx.combo.ComboCtrl` an interface
696class derived from wx.combo.ComboPopup is used to manage the interface
697between the popup control and the popup. You can either derive a new
698class from both the widget class and this ComboPopup class, or the
699derived class can have a reference to the widget used for the popup.
700In either case you simply need to return the widget from the
701`GetControl` method to allow the ComboCtrl to interact with it.
702
703Nearly all of the methods of this class are overridable in Python.", "");
704
705
84bc0d49
RD
706MustHaveApp(wxPyComboPopup);
707%rename(ComboPopup) wxPyComboPopup;
708
709class wxPyComboPopup
710{
711public:
712 %pythonAppend wxPyComboPopup setCallbackInfo(ComboPopup);
713
84dd1dd8
RD
714 DocCtorStr(
715 wxPyComboPopup(),
716 "Constructor", "");
717
718 DocCtorStr(
719 ~wxPyComboPopup(),
720 "Destructor", "");
721
84bc0d49
RD
722
723 void _setCallbackInfo(PyObject* self, PyObject* _class);
724
84dd1dd8
RD
725 DocDeclStr(
726 virtual void , Init(),
727 "This method is called after the popup is contructed and has been
728assigned to the ComboCtrl. Derived classes can override this to do
729extra inialization or whatever.", "");
730
84bc0d49
RD
731
732 // Create the popup child control.
733 // Return true for success.
84dd1dd8
RD
734 DocDeclStr(
735 virtual bool , Create(wxWindow* parent),
736 "The derived class must implement this method to create the popup
737control. It should be a child of the ``parent`` passed in, but other
738than that there is much flexibility in what the widget can be, its
739style, etc. Return ``True`` for success, ``False`` otherwise. (NOTE:
740this return value is not currently checked...)", "");
741
84bc0d49 742
84dd1dd8
RD
743 DocDeclStr(
744 virtual wxWindow *, GetControl(),
745 "The derived class must implement this method and it should return a
746reference to the widget created in the `Create` method. If the
747derived class inherits from both the widget class and ComboPopup then
748the return value is probably just ``self``.", "");
84bc0d49 749
84bc0d49 750
84dd1dd8
RD
751 DocDeclStr(
752 virtual void , OnPopup(),
753 "The derived class may implement this to do special processing when
754popup is shown.", "");
84bc0d49 755
84bc0d49 756
84dd1dd8
RD
757 DocDeclStr(
758 virtual void , OnDismiss(),
759 "The derived class may implement this to do special processing when
760popup is hidden.", "");
84bc0d49 761
84bc0d49 762
84dd1dd8
RD
763 DocDeclStr(
764 virtual void , SetStringValue( const wxString& value ),
765 "Called just prior to displaying the popup. The derived class can
766implement this to \"select\" the item in the popup that coresponds to
767the passed in string value, if appropriate. The default
768implementation does nothing.", "");
84bc0d49 769
84bc0d49 770
84dd1dd8
RD
771 DocDeclStr(
772 virtual wxString , GetStringValue() const,
773 "Gets the string representation of the currently selected value to be
774used 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
780the 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
786should 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
792special 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
798for the popup control, according to the variables given. It is called
799on 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
811delay the call to `Create` until the popup is shown for the first
812time. It is more efficient, but on the other hand it is often more
813convenient to have the control created immediately. The default
814implementation returns ``False``.", "");
84bc0d49 815
84bc0d49
RD
816
817 //
818 // Utilies
819 //
820
84bc0d49 821
84dd1dd8
RD
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.", "");
84bc0d49 830
84bc0d49 831
84dd1dd8
RD
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
842is associated with.", "");
84bc0d49
RD
843
844};
845
846
847
848//---------------------------------------------------------------------------
849%newgroup
850
851
852enum {
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%{
863class wxPyOwnerDrawnComboBox : public wxOwnerDrawnComboBox
864{
865public:
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
889IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawItem);
890IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItem);
891IMP_PYCALLBACK_COORD_SIZET_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnMeasureItemWidth);
892IMP_PYCALLBACK__DCRECTINTINT_const(wxPyOwnerDrawnComboBox, wxOwnerDrawnComboBox, OnDrawBackground);
893
894%}
895
896
897
84dd1dd8
RD
898// Now declare wxPyOwnerDrawnComboBox for Python
899
900DocStr(wxPyOwnerDrawnComboBox,
901"wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list
902items. In essence, it is a `wx.combo.ComboCtrl` with a `wx.VListBox`
903popup and a `wx.ControlWithItems` API.
904
905Implementing item drawing and measuring is similar to wx.VListBox.
906The application needs to subclass wx.combo.OwnerDrawnComboBox and
907implement the `OnDrawItem`, `OnMeasureItem` and `OnMeasureItemWidth`
908methods.", "");
909
84bc0d49
RD
910MustHaveApp(wxPyOwnerDrawnComboBox);
911%rename(OwnerDrawnComboBox) wxPyOwnerDrawnComboBox;
912
913class wxPyOwnerDrawnComboBox : public wxPyComboCtrl,
914 public wxItemContainer
915{
916public:
917 %pythonAppend wxPyOwnerDrawnComboBox "self._setOORInfo(self);" setCallbackInfo(OwnerDrawnComboBox)
918 %pythonAppend wxPyOwnerDrawnComboBox() "";
919
84dd1dd8
RD
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);
84bc0d49 935
84dd1dd8 936 void _setCallbackInfo(PyObject* self, PyObject* _class);
84bc0d49 937
84dd1dd8
RD
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
84bc0d49 961
84dd1dd8
RD
962 void SetSelection(int n);
963 %Rename(SetMark, void , SetSelection(long from, long to));
84bc0d49 964
84bc0d49 965
84dd1dd8
RD
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
974item with the given index on the provided DC. If this method is not
975overridden, the item text is simply drawn as if the control was a
976normal 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
996the specified item (in pixels). The default implementation returns
997text 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
1003specified item (in pixels). If -1 is returned, then the item text
1004width 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
1010around it.
1011
1012The base class version implements a reasonable default behaviour which
1013consists in drawing the selected item with the standard background
1014colour and drawing a border around the item if it is either selected
1015or current. ``flags`` has the sam meaning as with `OnDrawItem`.", "");
1016
84bc0d49 1017
84bc0d49
RD
1018};
1019
f27895d2
RD
1020//---------------------------------------------------------------------------
1021
1022%{
1023#include <wx/bmpcbox.h>
1024%}
1025
1026DocStr(wxBitmapComboBox,
1027 "A combobox that displays a bitmap in front of the list items. It
1028currently only allows using bitmaps of one size, and resizes itself so
1029that a bitmap can be shown next to the text field.",
1030"
a6794ed8 1031
f27895d2
RD
1032Window 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
1047MustHaveApp(wxBitmapComboBox);
1048
1049class wxBitmapComboBox : public wxPyOwnerDrawnComboBox
1050{
1051public:
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
1088if 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(
9745cf4d 1100 virtual wxBitmap , GetItemBitmap(/*unsigned*/ int n) const,
f27895d2
RD
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,
1107optionally associating some data object with the item.", "");
1108 int Insert(const wxString& item, const wxBitmap& bitmap,
9745cf4d 1109 /*unsigned*/ int pos, PyObject* clientData=NULL) {
f27895d2
RD
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(
9745cf4d 1120 virtual void , SetItemBitmap(/*unsigned*/ int n, const wxBitmap& bitmap),
f27895d2
RD
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};
84bc0d49
RD
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");
84dd1dd8 1137 wxPyPtrTypeMap_Add("wxOwnerDrawnComboBox", "wxPyOwnerDrawnComboBox");
84bc0d49
RD
1138%}
1139//---------------------------------------------------------------------------
1140