1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of various window classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/menuitem.h>
21 //----------------------------------------------------------------------
24 %include my_typemaps.i
26 // Import some definitions of other classes, etc.
32 %pragma(python) code = "import wx"
36 static wxString wxPyEmptyStr("");
39 //---------------------------------------------------------------------------
45 bool ProcessEvent(wxEvent& event);
46 void AddPendingEvent(wxEvent& event);
47 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
49 bool GetEvtHandlerEnabled();
50 void SetEvtHandlerEnabled(bool enabled);
52 wxEvtHandler* GetNextHandler();
53 wxEvtHandler* GetPreviousHandler();
54 void SetNextHandler(wxEvtHandler* handler);
55 void SetPreviousHandler(wxEvtHandler* handler);
59 void Connect( int id, int lastId, int eventType, PyObject* func) {
60 if (PyCallable_Check(func)) {
61 self->Connect(id, lastId, eventType,
62 (wxObjectEventFunction) &wxPyCallback::EventThunker,
63 new wxPyCallback(func));
67 bool Disconnect(int id, int lastId = -1,
68 wxEventType eventType = wxEVT_NULL) {
69 return self->Disconnect(id, lastId, eventType,
70 (wxObjectEventFunction)
71 &wxPyCallback::EventThunker);
74 // This really belongs in the wxObject base class. It's probably
75 // time to actually add it...
76 const char* GetClassName() {
77 return self->GetClassInfo()->GetClassName();
81 // %pragma(python) addtoclass = "
84 // %pragma(python) addtoclass = "
85 // def __getattr__(self, name):
86 // pl = self._prop_list_
87 // if pl.has_key(name):
88 // getFunc, setFunc = pl[name]
90 // return getattr(self, getFunc)()
92 // raise TypeError, '%s property is write-only' % name
93 // raise AttributeError, name
95 // def __setattr__(self, name, value):
96 // pl = self._prop_list_
97 // if pl.has_key(name):
98 // getFunc, setFunc = pl[name]
100 // return getattr(self, setFunc)(value)
102 // raise TypeError, '%s property is read-only' % name
103 // self.__dict__[name] = value
108 //----------------------------------------------------------------------
110 class wxValidator : public wxEvtHandler {
115 wxValidator* Clone();
116 wxWindow* GetWindow();
117 void SetWindow(wxWindow* window);
119 // // Properties list
120 // %pragma(python) addtoclass = "
122 // 'window' : ('GetWindow', 'SetWindow'),
124 // _prop_list_.update(wxEvtHandler._prop_list_)
129 bool wxValidator_IsSilent() {
130 return wxValidator::IsSilent();
133 void wxValidator_SetBellOnError(int doIt = TRUE) {
134 wxValidator::SetBellOnError(doIt);
138 //----------------------------------------------------------------------
140 class wxPyValidator : public wxValidator {
141 DECLARE_DYNAMIC_CLASS(wxPyValidator);
145 // wxPyValidator(const wxPyValidator& other);
150 wxObject* wxPyValidator::Clone() const {
151 wxPyValidator* ptr = NULL;
152 wxPyValidator* self = (wxPyValidator*)this;
154 bool doSave = wxPyRestoreThread();
155 if (self->m_myInst.findCallback("Clone")) {
157 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
159 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
163 // This is very dangerous!!! But is the only way I could find
164 // to squash a memory leak. Currently it is okay, but if the
165 // validator architecture in wxWindows ever changes, problems
169 wxPySaveThread(doSave);
173 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
174 DEC_PYCALLBACK_BOOL_(TransferToWindow);
175 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
181 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
182 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
183 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
185 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
189 class wxPyValidator : public wxValidator {
194 %addmethods { void Destroy() { delete self; } }
196 void _setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
197 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyValidator, 0)"
201 //----------------------------------------------------------------------
203 %apply int * INOUT { int* x, int* y };
205 class wxWindow : public wxEvtHandler {
208 wxWindow(wxWindow* parent, const wxWindowID id,
209 const wxPoint& pos = wxDefaultPosition,
210 const wxSize& size = wxDefaultSize,
212 char* name = "panel");
214 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
217 void Center(int direction = wxBOTH);
218 void Centre(int direction = wxBOTH);
219 void CentreOnParent(int direction = wxBOTH );
220 void CenterOnParent(int direction = wxBOTH );
221 void CentreOnScreen(int direction = wxBOTH );
222 void CenterOnScreen(int direction = wxBOTH );
224 // (uses apply'ed INOUT typemap, see above)
225 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
226 wxPoint ClientToScreen(const wxPoint& pt);
228 bool Close(int force = FALSE);
230 void DestroyChildren();
232 void DragAcceptFiles(bool accept);
234 void Enable(bool enable);
235 //bool FakePopupMenu(wxMenu* menu, int x, int y);
236 %name(FindWindowById) wxWindow* FindWindow(long id);
237 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
239 wxColour GetBackgroundColour();
241 //wxList& GetChildren();
243 PyObject* GetChildren() {
244 wxWindowList& list = self->GetChildren();
245 return wxPy_ConvertList(&list, "wxWindow");
251 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
252 wxSize GetClientSize();
253 wxLayoutConstraints * GetConstraints();
254 wxEvtHandler* GetEventHandler();
257 wxColour GetForegroundColour();
258 wxWindow * GetGrandParent();
261 return wxPyGetWinHandle(self); //(long)self->GetHandle();
266 void SetLabel(const wxString& label);
268 wxWindow * GetParent();
269 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
270 wxPoint GetPosition();
272 int GetScrollThumb(int orientation);
273 int GetScrollPos(int orientation);
274 int GetScrollRange(int orientation);
275 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
277 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
278 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
279 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
280 const wxFont* font = NULL); //, bool use16 = FALSE)
282 wxRegion GetUpdateRegion();
283 long GetWindowStyleFlag();
284 void SetWindowStyleFlag(long style);
285 void SetWindowStyle(long style);
289 bool IsExposed( int x, int y, int w=0, int h=0 );
290 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
291 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
296 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
298 void MakeModal(bool flag);
299 %name(MoveXY)void Move(int x, int y);
300 void Move(const wxPoint& point);
302 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
303 void PushEventHandler(wxEvtHandler* handler);
305 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
306 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
309 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
311 void RemoveChild(wxWindow* child);
312 bool Reparent( wxWindow* newParent );
314 // (uses apply'ed INOUT typemap, see above)
315 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
316 wxPoint ScreenToClient(const wxPoint& pt);
318 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
319 void SetAcceleratorTable(const wxAcceleratorTable& accel);
320 void SetAutoLayout(bool autoLayout);
321 bool GetAutoLayout();
322 void SetBackgroundColour(const wxColour& colour);
323 void SetConstraints(wxLayoutConstraints *constraints);
324 void UnsetConstraints(wxLayoutConstraints *constraints);
327 void SetFont(const wxFont& font);
328 void SetForegroundColour(const wxColour& colour);
330 void SetName(const wxString& name);
331 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
332 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
334 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
336 void SetSize(const wxSize& size) {
340 void SetPosition(const wxPoint& pos) {
344 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
345 self->SetSize(rect, sizeFlags);
349 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
350 %name(SetClientSizeWH)void SetClientSize(int width, int height);
351 void SetClientSize(const wxSize& size);
352 //void SetPalette(wxPalette* palette);
353 void SetCursor(const wxCursor&cursor);
354 void SetEventHandler(wxEvtHandler* handler);
355 void SetExtraStyle(long exStyle);
356 void SetTitle(const wxString& title);
357 bool Show(bool show);
358 bool TransferDataFromWindow();
359 bool TransferDataToWindow();
361 void WarpPointer(int x, int y);
363 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
364 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
366 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
367 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
369 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
370 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
372 %name(SetToolTipString)void SetToolTip(const wxString &tip);
373 void SetToolTip(wxToolTip *tooltip);
374 wxToolTip* GetToolTip();
376 void SetSizer(wxSizer* sizer);
379 wxValidator* GetValidator();
380 void SetValidator(const wxValidator& validator);
382 void SetDropTarget(wxDropTarget* target);
383 wxDropTarget* GetDropTarget();
384 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
386 wxSize GetBestSize();
388 void SetCaret(wxCaret *caret);
390 %pragma(python) addtoclass = "# replaces broken shadow methods
391 def GetCaret(self, *_args, **_kwargs):
392 from misc2 import wxCaretPtr
393 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
394 if val: val = wxCaretPtr(val)
397 def GetSizer(self, *_args, **_kwargs):
398 from sizers import wxSizerPtr
399 val = apply(windowsc.wxWindow_GetSizer,(self,) + _args, _kwargs)
400 if val: val = wxSizerPtr(val)
403 def GetToolTip(self, *_args, **_kwargs):
404 from misc2 import wxToolTipPtr
405 val = apply(windowsc.wxWindow_GetToolTip,(self,) + _args, _kwargs)
406 if val: val = wxToolTipPtr(val)
411 // // Properties list
412 // %pragma(python) addtoclass = "
414 // 'size' : ('GetSize', 'SetSize'),
415 // 'enabled' : ('IsEnabled', 'Enable'),
416 // 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
417 // 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
418 // 'children' : ('GetChildren', None),
419 // 'charHeight' : ('GetCharHeight', None),
420 // 'charWidth' : ('GetCharWidth', None),
421 // 'clientSize' : ('GetClientSize', 'SetClientSize'),
422 // 'font' : ('GetFont', 'SetFont'),
423 // 'grandParent' : ('GetGrandParent', None),
424 // 'handle' : ('GetHandle', None),
425 // 'label' : ('GetLabel', 'SetLabel'),
426 // 'name' : ('GetName', 'SetName'),
427 // 'parent' : ('GetParent', None),
428 // 'position' : ('GetPosition', 'SetPosition'),
429 // 'title' : ('GetTitle', 'SetTitle'),
430 // 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
431 // 'visible' : ('IsShown', 'Show'),
432 // 'toolTip' : ('GetToolTip', 'SetToolTip'),
433 // 'sizer' : ('GetSizer', 'SetSizer'),
434 // 'validator' : ('GetValidator', 'SetValidator'),
435 // 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
436 // 'caret' : ('GetCaret', 'SetCaret'),
437 // 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
438 // 'constraints' : ('GetConstraints', 'SetConstraints'),
441 // _prop_list_.update(wxEvtHandler._prop_list_)
448 %pragma(python) code = "
449 def wxDLG_PNT(win, point_or_x, y=None):
451 return win.ConvertDialogPointToPixels(point_or_x)
453 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
455 def wxDLG_SZE(win, size_width, height=None):
457 return win.ConvertDialogSizeToPixels(size_width)
459 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
463 wxWindow* wxWindow_FindFocus() {
464 return wxWindow::FindFocus();
471 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
472 wxWindow* win = new wxWindow;
474 win->SubclassWin(hWnd);
481 int wxWindow_NewControlId() {
482 return wxWindow::NewControlId();
484 int wxWindow_NextControlId(int id) {
485 return wxWindow::NextControlId(id);
487 int wxWindow_PrevControlId(int id) {
488 return wxWindow::PrevControlId(id);
493 //---------------------------------------------------------------------------
495 class wxPanel : public wxWindow {
497 wxPanel(wxWindow* parent,
499 const wxPoint& pos = wxDefaultPosition,
500 const wxSize& size = wxDefaultSize,
501 long style = wxTAB_TRAVERSAL,
502 const char* name = "panel");
504 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
507 wxButton* GetDefaultItem();
508 void SetDefaultItem(wxButton *btn);
510 // fix some SWIG trouble...
511 %pragma(python) addtoclass = "
512 def GetDefaultItem(self):
514 val = windowsc.wxPanel_GetDefaultItem(self.this)
515 val = controls.wxButtonPtr(val)
520 //---------------------------------------------------------------------------
522 class wxDialog : public wxPanel {
524 wxDialog(wxWindow* parent,
526 const wxString& title,
527 const wxPoint& pos = wxDefaultPosition,
528 const wxSize& size = wxDefaultSize,
529 long style = wxDEFAULT_DIALOG_STYLE,
530 const char* name = "dialogBox");
532 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
534 void Centre(int direction = wxBOTH);
535 void EndModal(int retCode);
537 void Iconize(bool iconize);
539 void SetModal(bool flag);
541 void SetTitle(const wxString& title);
542 bool Show(bool show);
546 void SetReturnCode(int retCode);
548 wxSizer* CreateTextSizer( const wxString &message );
549 wxSizer* CreateButtonSizer( long flags );
551 %pragma(python) addtoclass = "
552 # replace swig generated shadow methods to resolve import issues
553 def CreateTextSizer(self, *_args, **_kwargs):
555 val = apply(windowsc.wxDialog_CreateTextSizer,(self,) + _args, _kwargs)
556 if val: val = sizers.wxSizerPtr(val)
558 def CreateButtonSizer(self, *_args, **_kwargs):
560 val = apply(windowsc.wxDialog_CreateButtonSizer,(self,) + _args, _kwargs)
561 if val: val = sizers.wxSizerPtr(val)
567 //---------------------------------------------------------------------------
569 class wxScrolledWindow : public wxPanel {
571 wxScrolledWindow(wxWindow* parent,
572 const wxWindowID id = -1,
573 const wxPoint& pos = wxDefaultPosition,
574 const wxSize& size = wxDefaultSize,
575 long style = wxHSCROLL | wxVSCROLL,
576 char* name = "scrolledWindow");
578 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
579 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
581 void EnableScrolling(bool xScrolling, bool yScrolling);
582 int GetScrollPageSize(int orient);
583 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
584 wxWindow* GetTargetWindow();
585 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
587 void PrepareDC(wxDC& dc);
588 void Scroll(int x, int y);
589 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
590 int noUnitsX, int noUnitsY,
591 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
592 void SetScrollPageSize(int orient, int pageSize);
593 void SetTargetWindow(wxWindow* window);
594 void GetViewStart(int* OUTPUT, int* OUTPUT);
595 void ViewStart(int* OUTPUT, int* OUTPUT);
597 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
598 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
602 //----------------------------------------------------------------------
605 class wxMenu : public wxEvtHandler {
607 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
609 void Append(int id, const wxString& item,
610 const wxString& helpString = wxPyEmptyStr,
611 int checkable = FALSE);
612 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
613 const wxString& helpString = wxPyEmptyStr);
614 %name(AppendItem)void Append(const wxMenuItem* item);
616 void AppendSeparator();
618 void Check(int id, bool flag);
619 bool IsChecked(int id);
620 void Enable(int id, bool enable);
621 bool IsEnabled(int id);
623 int FindItem(const wxString& itemString);
624 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
627 void SetTitle(const wxString& title);
629 wxString GetLabel(int id);
630 void SetLabel(int id, const wxString& label);
632 wxString GetHelpString(int id);
633 void SetHelpString(int id, const wxString& helpString);
634 void UpdateUI(wxEvtHandler* source = NULL);
637 %name(DeleteItem)bool Delete(wxMenuItem *item);
638 bool Insert(size_t pos, wxMenuItem *item);
639 wxMenuItem *Remove(int id);
640 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
643 void Destroy() { delete self; }
645 %name(DestroyId)bool Destroy(int id);
646 %name(DestroyItem)bool Destroy(wxMenuItem *item);
648 size_t GetMenuItemCount();
649 //wxMenuItemList& GetMenuItems();
651 PyObject* GetMenuItems() {
652 wxMenuItemList& list = self->GetMenuItems();
653 return wxPy_ConvertList(&list, "wxMenuItem");
657 void SetEventHandler(wxEvtHandler *handler);
658 wxEvtHandler *GetEventHandler();
660 void SetInvokingWindow(wxWindow *win);
661 wxWindow *GetInvokingWindow();
667 void SetParent(wxMenu *parent);
672 //----------------------------------------------------------------------
674 class wxMenuBar : public wxWindow {
676 wxMenuBar(long style = 0);
678 bool Append(wxMenu *menu, const wxString& title);
679 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
680 size_t GetMenuCount();
681 wxMenu *GetMenu(size_t pos);
682 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
683 wxMenu *Remove(size_t pos);
684 void EnableTop(size_t pos, bool enable);
685 void SetLabelTop(size_t pos, const wxString& label);
686 wxString GetLabelTop(size_t pos);
687 int FindMenuItem(const wxString& menuString, const wxString& itemString);
688 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
689 void Enable(int id, bool enable);
690 void Check(int id, bool check);
691 bool IsChecked(int id);
692 bool IsEnabled(int id);
694 void SetLabel(int id, const wxString &label);
695 wxString GetLabel(int id);
697 void SetHelpString(int id, const wxString& helpString);
698 wxString GetHelpString(int id);
703 //----------------------------------------------------------------------
707 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
708 const wxString& text = wxPyEmptyStr,
709 const wxString& help = wxPyEmptyStr,
710 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
717 void SetText(const wxString& str);
719 const wxString& GetText();
720 void SetCheckable(bool checkable);
723 void SetSubMenu(wxMenu *menu);
724 wxMenu *GetSubMenu();
725 void Enable(bool enable = TRUE);
727 void Check(bool check = TRUE);
730 void SetHelp(const wxString& str);
731 const wxString& GetHelp();
732 wxAcceleratorEntry *GetAccel();
733 void SetAccel(wxAcceleratorEntry *accel);
735 static wxString GetLabelFromText(const wxString& text);
737 // wxOwnerDrawn methods
739 void SetFont(const wxFont& font);
741 void SetTextColour(const wxColour& colText);
742 wxColour& GetTextColour();
743 void SetBackgroundColour(const wxColour& colBack);
744 wxColour& GetBackgroundColour();
745 void SetBitmaps(const wxBitmap& bmpChecked,
746 const wxBitmap& bmpUnchecked = wxNullBitmap);
747 void SetBitmap(const wxBitmap& bmpChecked);
748 const wxBitmap& GetBitmap(bool bChecked = TRUE);
749 void SetMarginWidth(int nWidth);
750 int GetMarginWidth();
751 static int GetDefaultMarginWidth();
752 //void SetName(const wxString& strName);
753 //const wxString& GetName();
754 //void SetCheckable(bool checkable);
755 //bool IsCheckable();
757 void ResetOwnerDrawn();
761 //---------------------------------------------------------------------------