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"
34 //---------------------------------------------------------------------------
40 bool ProcessEvent(wxEvent& event);
41 void AddPendingEvent(wxEvent& event);
42 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
44 bool GetEvtHandlerEnabled();
45 void SetEvtHandlerEnabled(bool enabled);
47 wxEvtHandler* GetNextHandler();
48 wxEvtHandler* GetPreviousHandler();
49 void SetNextHandler(wxEvtHandler* handler);
50 void SetPreviousHandler(wxEvtHandler* handler);
54 void Connect( int id, int lastId, int eventType, PyObject* func) {
55 if (PyCallable_Check(func)) {
56 self->Connect(id, lastId, eventType,
57 (wxObjectEventFunction) &wxPyCallback::EventThunker,
58 new wxPyCallback(func));
62 bool Disconnect(int id, int lastId = -1,
63 wxEventType eventType = wxEVT_NULL) {
64 return self->Disconnect(id, lastId, eventType,
65 (wxObjectEventFunction)
66 &wxPyCallback::EventThunker);
71 %pragma(python) addtoclass = "
75 // %pragma(python) addtoclass = "
76 // def __getattr__(self, name):
77 // pl = self._prop_list_
78 // if pl.has_key(name):
79 // getFunc, setFunc = pl[name]
81 // return getattr(self, getFunc)()
83 // raise TypeError, '%s property is write-only' % name
84 // raise AttributeError, name
86 // def __setattr__(self, name, value):
87 // pl = self._prop_list_
88 // if pl.has_key(name):
89 // getFunc, setFunc = pl[name]
91 // return getattr(self, setFunc)(value)
93 // raise TypeError, '%s property is read-only' % name
94 // self.__dict__[name] = value
99 //----------------------------------------------------------------------
101 class wxValidator : public wxEvtHandler {
106 wxValidator* Clone();
107 wxWindow* GetWindow();
108 void SetWindow(wxWindow* window);
110 // // Properties list
111 // %pragma(python) addtoclass = "
113 // 'window' : ('GetWindow', 'SetWindow'),
115 // _prop_list_.update(wxEvtHandler._prop_list_)
120 bool wxValidator_IsSilent() {
121 return wxValidator::IsSilent();
124 void wxValidator_SetBellOnError(int doIt = TRUE) {
125 wxValidator::SetBellOnError(doIt);
129 //----------------------------------------------------------------------
131 class wxPyValidator : public wxValidator {
132 DECLARE_DYNAMIC_CLASS(wxPyValidator);
136 // wxPyValidator(const wxPyValidator& other);
141 wxObject* wxPyValidator::Clone() const {
142 wxPyValidator* ptr = NULL;
143 wxPyValidator* self = (wxPyValidator*)this;
145 bool doSave = wxPyRestoreThread();
146 if (self->m_myInst.findCallback("Clone")) {
148 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
150 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
154 // This is very dangerous!!! But is the only way I could find
155 // to squash a memory leak. Currently it is okay, but if the
156 // validator architecture in wxWindows ever changes, problems
160 wxPySaveThread(doSave);
164 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
165 DEC_PYCALLBACK_BOOL_(TransferToWindow);
166 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
172 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
173 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
174 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
176 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
180 class wxPyValidator : public wxValidator {
185 %addmethods { void Destroy() { delete self; } }
187 void _setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
188 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyValidator, 0)"
192 //----------------------------------------------------------------------
194 %apply int * INOUT { int* x, int* y };
196 class wxWindow : public wxEvtHandler {
199 wxWindow(wxWindow* parent, const wxWindowID id,
200 const wxPoint& pos = wxPyDefaultPosition,
201 const wxSize& size = wxPyDefaultSize,
203 char* name = "panel");
205 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
208 void Center(int direction = wxBOTH);
209 void Centre(int direction = wxBOTH);
210 void CentreOnParent(int direction = wxBOTH );
211 void CenterOnParent(int direction = wxBOTH );
212 void CentreOnScreen(int direction = wxBOTH );
213 void CenterOnScreen(int direction = wxBOTH );
215 // (uses apply'ed INOUT typemap, see above)
216 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
217 wxPoint ClientToScreen(const wxPoint& pt);
219 bool Close(int force = FALSE);
221 void DestroyChildren();
223 void DragAcceptFiles(bool accept);
225 void Enable(bool enable);
226 //bool FakePopupMenu(wxMenu* menu, int x, int y);
227 %name(FindWindowById) wxWindow* FindWindow(long id);
228 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
230 wxColour GetBackgroundColour();
232 //wxList& GetChildren();
234 PyObject* GetChildren() {
235 wxWindowList& list = self->GetChildren();
236 return wxPy_ConvertList(&list, "wxWindow");
242 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
243 wxSize GetClientSize();
244 wxLayoutConstraints * GetConstraints();
245 wxEvtHandler* GetEventHandler();
248 wxColour GetForegroundColour();
249 wxWindow * GetGrandParent();
252 return wxPyGetWinHandle(self); //(long)self->GetHandle();
257 void SetLabel(const wxString& label);
259 wxWindow * GetParent();
260 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
261 wxPoint GetPosition();
263 int GetScrollThumb(int orientation);
264 int GetScrollPos(int orientation);
265 int GetScrollRange(int orientation);
266 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
268 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
269 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
270 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
271 const wxFont* font = NULL); //, bool use16 = FALSE)
273 wxRegion GetUpdateRegion();
274 long GetWindowStyleFlag();
275 void SetWindowStyleFlag(long style);
276 void SetWindowStyle(long style);
280 bool IsExposed( int x, int y, int w=0, int h=0 );
281 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
282 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
287 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
289 void MakeModal(bool flag);
290 %name(MoveXY)void Move(int x, int y);
291 void Move(const wxPoint& point);
293 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
294 void PushEventHandler(wxEvtHandler* handler);
296 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
297 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
300 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
302 void RemoveChild(wxWindow* child);
303 bool Reparent( wxWindow* newParent );
305 // (uses apply'ed INOUT typemap, see above)
306 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
307 wxPoint ScreenToClient(const wxPoint& pt);
309 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
310 void SetAcceleratorTable(const wxAcceleratorTable& accel);
311 void SetAutoLayout(bool autoLayout);
312 bool GetAutoLayout();
313 void SetBackgroundColour(const wxColour& colour);
314 void SetConstraints(wxLayoutConstraints *constraints);
315 void UnsetConstraints(wxLayoutConstraints *constraints);
318 void SetFont(const wxFont& font);
319 void SetForegroundColour(const wxColour& colour);
321 void SetName(const wxString& name);
322 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
323 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
325 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
327 void SetSize(const wxSize& size) {
331 void SetPosition(const wxPoint& pos) {
336 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
337 %name(SetClientSizeWH)void SetClientSize(int width, int height);
338 void SetClientSize(const wxSize& size);
339 //void SetPalette(wxPalette* palette);
340 void SetCursor(const wxCursor&cursor);
341 void SetEventHandler(wxEvtHandler* handler);
342 void SetTitle(const wxString& title);
343 bool Show(bool show);
344 bool TransferDataFromWindow();
345 bool TransferDataToWindow();
347 void WarpPointer(int x, int y);
349 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
350 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
352 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
353 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
355 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
356 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
358 %name(SetToolTipString)void SetToolTip(const wxString &tip);
359 void SetToolTip(wxToolTip *tooltip);
360 wxToolTip* GetToolTip();
362 void SetSizer(wxSizer* sizer);
365 wxValidator* GetValidator();
366 void SetValidator(const wxValidator& validator);
368 void SetDropTarget(wxDropTarget* target);
369 wxDropTarget* GetDropTarget();
370 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
372 wxSize GetBestSize();
374 void SetCaret(wxCaret *caret);
376 %pragma(python) addtoclass = "# replaces broken shadow methods
377 def GetCaret(self, *_args, **_kwargs):
378 from misc2 import wxCaretPtr
379 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
380 if val: val = wxCaretPtr(val)
383 def GetSizer(self, *_args, **_kwargs):
384 from sizers import wxSizerPtr
385 val = apply(windowsc.wxWindow_GetSizer,(self,) + _args, _kwargs)
386 if val: val = wxSizerPtr(val)
389 def GetToolTip(self, *_args, **_kwargs):
390 from misc2 import wxToolTipPtr
391 val = apply(windowsc.wxWindow_GetToolTip,(self,) + _args, _kwargs)
392 if val: val = wxToolTipPtr(val)
397 // // Properties list
398 // %pragma(python) addtoclass = "
400 // 'size' : ('GetSize', 'SetSize'),
401 // 'enabled' : ('IsEnabled', 'Enable'),
402 // 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
403 // 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
404 // 'children' : ('GetChildren', None),
405 // 'charHeight' : ('GetCharHeight', None),
406 // 'charWidth' : ('GetCharWidth', None),
407 // 'clientSize' : ('GetClientSize', 'SetClientSize'),
408 // 'font' : ('GetFont', 'SetFont'),
409 // 'grandParent' : ('GetGrandParent', None),
410 // 'handle' : ('GetHandle', None),
411 // 'label' : ('GetLabel', 'SetLabel'),
412 // 'name' : ('GetName', 'SetName'),
413 // 'parent' : ('GetParent', None),
414 // 'position' : ('GetPosition', 'SetPosition'),
415 // 'title' : ('GetTitle', 'SetTitle'),
416 // 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
417 // 'visible' : ('IsShown', 'Show'),
418 // 'toolTip' : ('GetToolTip', 'SetToolTip'),
419 // 'sizer' : ('GetSizer', 'SetSizer'),
420 // 'validator' : ('GetValidator', 'SetValidator'),
421 // 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
422 // 'caret' : ('GetCaret', 'SetCaret'),
423 // 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
424 // 'constraints' : ('GetConstraints', 'SetConstraints'),
427 // _prop_list_.update(wxEvtHandler._prop_list_)
434 %pragma(python) code = "
435 def wxDLG_PNT(win, point_or_x, y=None):
437 return win.ConvertDialogPointToPixels(point_or_x)
439 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
441 def wxDLG_SZE(win, size_width, height=None):
443 return win.ConvertDialogSizeToPixels(size_width)
445 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
449 wxWindow* wxWindow_FindFocus() {
450 return wxWindow::FindFocus();
457 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
458 wxWindow* win = new wxWindow;
460 win->SubclassWin(hWnd);
467 int wxWindow_NewControlId() {
468 return wxWindow::NewControlId();
470 int wxWindow_NextControlId(int id) {
471 return wxWindow::NextControlId(id);
473 int wxWindow_PrevControlId(int id) {
474 return wxWindow::PrevControlId(id);
479 //---------------------------------------------------------------------------
481 class wxPanel : public wxWindow {
483 wxPanel(wxWindow* parent,
485 const wxPoint& pos = wxPyDefaultPosition,
486 const wxSize& size = wxPyDefaultSize,
487 long style = wxTAB_TRAVERSAL,
488 const char* name = "panel");
490 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
493 wxButton* GetDefaultItem();
494 void SetDefaultItem(wxButton *btn);
496 // fix some SWIG trouble...
497 %pragma(python) addtoclass = "
498 def GetDefaultItem(self):
500 val = windowsc.wxPanel_GetDefaultItem(self.this)
501 val = controls.wxButtonPtr(val)
506 //---------------------------------------------------------------------------
508 class wxDialog : public wxPanel {
510 wxDialog(wxWindow* parent,
512 const wxString& title,
513 const wxPoint& pos = wxPyDefaultPosition,
514 const wxSize& size = wxPyDefaultSize,
515 long style = wxDEFAULT_DIALOG_STYLE,
516 const char* name = "dialogBox");
518 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
520 void Centre(int direction = wxBOTH);
521 void EndModal(int retCode);
523 void Iconize(bool iconize);
525 void SetModal(bool flag);
527 void SetTitle(const wxString& title);
528 bool Show(bool show);
532 void SetReturnCode(int retCode);
535 //---------------------------------------------------------------------------
537 class wxScrolledWindow : public wxPanel {
539 wxScrolledWindow(wxWindow* parent,
540 const wxWindowID id = -1,
541 const wxPoint& pos = wxPyDefaultPosition,
542 const wxSize& size = wxPyDefaultSize,
543 long style = wxHSCROLL | wxVSCROLL,
544 char* name = "scrolledWindow");
546 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
547 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
549 void EnableScrolling(bool xScrolling, bool yScrolling);
550 int GetScrollPageSize(int orient);
551 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
552 wxWindow* GetTargetWindow();
553 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
555 void PrepareDC(wxDC& dc);
556 void Scroll(int x, int y);
557 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
558 int noUnitsX, int noUnitsY,
559 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
560 void SetScrollPageSize(int orient, int pageSize);
561 void SetTargetWindow(wxWindow* window);
562 void GetViewStart(int* OUTPUT, int* OUTPUT);
563 void ViewStart(int* OUTPUT, int* OUTPUT);
565 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
566 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
570 //----------------------------------------------------------------------
573 class wxMenu : public wxEvtHandler {
575 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
577 void Append(int id, const wxString& item,
578 const wxString& helpString = wxPyEmptyStr,
579 int checkable = FALSE);
580 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
581 const wxString& helpString = wxPyEmptyStr);
582 %name(AppendItem)void Append(const wxMenuItem* item);
584 void AppendSeparator();
586 void Check(int id, bool flag);
587 bool IsChecked(int id);
588 void Enable(int id, bool enable);
589 bool IsEnabled(int id);
591 int FindItem(const wxString& itemString);
592 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
595 void SetTitle(const wxString& title);
597 wxString GetLabel(int id);
598 void SetLabel(int id, const wxString& label);
600 wxString GetHelpString(int id);
601 void SetHelpString(int id, const wxString& helpString);
602 void UpdateUI(wxEvtHandler* source = NULL);
605 %name(DeleteItem)bool Delete(wxMenuItem *item);
606 bool Insert(size_t pos, wxMenuItem *item);
607 wxMenuItem *Remove(int id);
608 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
611 void Destroy() { delete self; }
613 %name(DestroyId)bool Destroy(int id);
614 %name(DestroyItem)bool Destroy(wxMenuItem *item);
616 size_t GetMenuItemCount();
617 //wxMenuItemList& GetMenuItems();
619 PyObject* GetMenuItems() {
620 wxMenuItemList& list = self->GetMenuItems();
621 return wxPy_ConvertList(&list, "wxMenuItem");
625 void SetEventHandler(wxEvtHandler *handler);
626 wxEvtHandler *GetEventHandler();
628 void SetInvokingWindow(wxWindow *win);
629 wxWindow *GetInvokingWindow();
635 void SetParent(wxMenu *parent);
640 //----------------------------------------------------------------------
642 class wxMenuBar : public wxWindow {
644 wxMenuBar(long style = 0);
646 bool Append(wxMenu *menu, const wxString& title);
647 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
648 size_t GetMenuCount();
649 wxMenu *GetMenu(size_t pos);
650 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
651 wxMenu *Remove(size_t pos);
652 void EnableTop(size_t pos, bool enable);
653 void SetLabelTop(size_t pos, const wxString& label);
654 wxString GetLabelTop(size_t pos);
655 int FindMenuItem(const wxString& menuString, const wxString& itemString);
656 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
657 void Enable(int id, bool enable);
658 void Check(int id, bool check);
659 bool IsChecked(int id);
660 bool IsEnabled(int id);
662 void SetLabel(int id, const wxString &label);
663 wxString GetLabel(int id);
665 void SetHelpString(int id, const wxString& helpString);
666 wxString GetHelpString(int id);
671 //----------------------------------------------------------------------
675 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
676 const wxString& text = wxPyEmptyStr,
677 const wxString& help = wxPyEmptyStr,
678 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
685 void SetText(const wxString& str);
687 const wxString& GetText();
688 void SetCheckable(bool checkable);
691 void SetSubMenu(wxMenu *menu);
692 wxMenu *GetSubMenu();
693 void Enable(bool enable = TRUE);
695 void Check(bool check = TRUE);
698 void SetHelp(const wxString& str);
699 const wxString& GetHelp();
700 wxAcceleratorEntry *GetAccel();
701 void SetAccel(wxAcceleratorEntry *accel);
705 //---------------------------------------------------------------------------