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) {
335 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
336 self->SetSize(rect, sizeFlags);
340 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
341 %name(SetClientSizeWH)void SetClientSize(int width, int height);
342 void SetClientSize(const wxSize& size);
343 //void SetPalette(wxPalette* palette);
344 void SetCursor(const wxCursor&cursor);
345 void SetEventHandler(wxEvtHandler* handler);
346 void SetTitle(const wxString& title);
347 bool Show(bool show);
348 bool TransferDataFromWindow();
349 bool TransferDataToWindow();
351 void WarpPointer(int x, int y);
353 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
354 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
356 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
357 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
359 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
360 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
362 %name(SetToolTipString)void SetToolTip(const wxString &tip);
363 void SetToolTip(wxToolTip *tooltip);
364 wxToolTip* GetToolTip();
366 void SetSizer(wxSizer* sizer);
369 wxValidator* GetValidator();
370 void SetValidator(const wxValidator& validator);
372 void SetDropTarget(wxDropTarget* target);
373 wxDropTarget* GetDropTarget();
374 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
376 wxSize GetBestSize();
378 void SetCaret(wxCaret *caret);
380 %pragma(python) addtoclass = "# replaces broken shadow methods
381 def GetCaret(self, *_args, **_kwargs):
382 from misc2 import wxCaretPtr
383 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
384 if val: val = wxCaretPtr(val)
387 def GetSizer(self, *_args, **_kwargs):
388 from sizers import wxSizerPtr
389 val = apply(windowsc.wxWindow_GetSizer,(self,) + _args, _kwargs)
390 if val: val = wxSizerPtr(val)
393 def GetToolTip(self, *_args, **_kwargs):
394 from misc2 import wxToolTipPtr
395 val = apply(windowsc.wxWindow_GetToolTip,(self,) + _args, _kwargs)
396 if val: val = wxToolTipPtr(val)
401 // // Properties list
402 // %pragma(python) addtoclass = "
404 // 'size' : ('GetSize', 'SetSize'),
405 // 'enabled' : ('IsEnabled', 'Enable'),
406 // 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
407 // 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
408 // 'children' : ('GetChildren', None),
409 // 'charHeight' : ('GetCharHeight', None),
410 // 'charWidth' : ('GetCharWidth', None),
411 // 'clientSize' : ('GetClientSize', 'SetClientSize'),
412 // 'font' : ('GetFont', 'SetFont'),
413 // 'grandParent' : ('GetGrandParent', None),
414 // 'handle' : ('GetHandle', None),
415 // 'label' : ('GetLabel', 'SetLabel'),
416 // 'name' : ('GetName', 'SetName'),
417 // 'parent' : ('GetParent', None),
418 // 'position' : ('GetPosition', 'SetPosition'),
419 // 'title' : ('GetTitle', 'SetTitle'),
420 // 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
421 // 'visible' : ('IsShown', 'Show'),
422 // 'toolTip' : ('GetToolTip', 'SetToolTip'),
423 // 'sizer' : ('GetSizer', 'SetSizer'),
424 // 'validator' : ('GetValidator', 'SetValidator'),
425 // 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
426 // 'caret' : ('GetCaret', 'SetCaret'),
427 // 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
428 // 'constraints' : ('GetConstraints', 'SetConstraints'),
431 // _prop_list_.update(wxEvtHandler._prop_list_)
438 %pragma(python) code = "
439 def wxDLG_PNT(win, point_or_x, y=None):
441 return win.ConvertDialogPointToPixels(point_or_x)
443 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
445 def wxDLG_SZE(win, size_width, height=None):
447 return win.ConvertDialogSizeToPixels(size_width)
449 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
453 wxWindow* wxWindow_FindFocus() {
454 return wxWindow::FindFocus();
461 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
462 wxWindow* win = new wxWindow;
464 win->SubclassWin(hWnd);
471 int wxWindow_NewControlId() {
472 return wxWindow::NewControlId();
474 int wxWindow_NextControlId(int id) {
475 return wxWindow::NextControlId(id);
477 int wxWindow_PrevControlId(int id) {
478 return wxWindow::PrevControlId(id);
483 //---------------------------------------------------------------------------
485 class wxPanel : public wxWindow {
487 wxPanel(wxWindow* parent,
489 const wxPoint& pos = wxPyDefaultPosition,
490 const wxSize& size = wxPyDefaultSize,
491 long style = wxTAB_TRAVERSAL,
492 const char* name = "panel");
494 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
497 wxButton* GetDefaultItem();
498 void SetDefaultItem(wxButton *btn);
500 // fix some SWIG trouble...
501 %pragma(python) addtoclass = "
502 def GetDefaultItem(self):
504 val = windowsc.wxPanel_GetDefaultItem(self.this)
505 val = controls.wxButtonPtr(val)
510 //---------------------------------------------------------------------------
512 class wxDialog : public wxPanel {
514 wxDialog(wxWindow* parent,
516 const wxString& title,
517 const wxPoint& pos = wxPyDefaultPosition,
518 const wxSize& size = wxPyDefaultSize,
519 long style = wxDEFAULT_DIALOG_STYLE,
520 const char* name = "dialogBox");
522 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
524 void Centre(int direction = wxBOTH);
525 void EndModal(int retCode);
527 void Iconize(bool iconize);
529 void SetModal(bool flag);
531 void SetTitle(const wxString& title);
532 bool Show(bool show);
536 void SetReturnCode(int retCode);
539 //---------------------------------------------------------------------------
541 class wxScrolledWindow : public wxPanel {
543 wxScrolledWindow(wxWindow* parent,
544 const wxWindowID id = -1,
545 const wxPoint& pos = wxPyDefaultPosition,
546 const wxSize& size = wxPyDefaultSize,
547 long style = wxHSCROLL | wxVSCROLL,
548 char* name = "scrolledWindow");
550 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
551 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
553 void EnableScrolling(bool xScrolling, bool yScrolling);
554 int GetScrollPageSize(int orient);
555 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
556 wxWindow* GetTargetWindow();
557 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
559 void PrepareDC(wxDC& dc);
560 void Scroll(int x, int y);
561 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
562 int noUnitsX, int noUnitsY,
563 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
564 void SetScrollPageSize(int orient, int pageSize);
565 void SetTargetWindow(wxWindow* window);
566 void GetViewStart(int* OUTPUT, int* OUTPUT);
567 void ViewStart(int* OUTPUT, int* OUTPUT);
569 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
570 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
574 //----------------------------------------------------------------------
577 class wxMenu : public wxEvtHandler {
579 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
581 void Append(int id, const wxString& item,
582 const wxString& helpString = wxPyEmptyStr,
583 int checkable = FALSE);
584 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
585 const wxString& helpString = wxPyEmptyStr);
586 %name(AppendItem)void Append(const wxMenuItem* item);
588 void AppendSeparator();
590 void Check(int id, bool flag);
591 bool IsChecked(int id);
592 void Enable(int id, bool enable);
593 bool IsEnabled(int id);
595 int FindItem(const wxString& itemString);
596 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
599 void SetTitle(const wxString& title);
601 wxString GetLabel(int id);
602 void SetLabel(int id, const wxString& label);
604 wxString GetHelpString(int id);
605 void SetHelpString(int id, const wxString& helpString);
606 void UpdateUI(wxEvtHandler* source = NULL);
609 %name(DeleteItem)bool Delete(wxMenuItem *item);
610 bool Insert(size_t pos, wxMenuItem *item);
611 wxMenuItem *Remove(int id);
612 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
615 void Destroy() { delete self; }
617 %name(DestroyId)bool Destroy(int id);
618 %name(DestroyItem)bool Destroy(wxMenuItem *item);
620 size_t GetMenuItemCount();
621 //wxMenuItemList& GetMenuItems();
623 PyObject* GetMenuItems() {
624 wxMenuItemList& list = self->GetMenuItems();
625 return wxPy_ConvertList(&list, "wxMenuItem");
629 void SetEventHandler(wxEvtHandler *handler);
630 wxEvtHandler *GetEventHandler();
632 void SetInvokingWindow(wxWindow *win);
633 wxWindow *GetInvokingWindow();
639 void SetParent(wxMenu *parent);
644 //----------------------------------------------------------------------
646 class wxMenuBar : public wxWindow {
648 wxMenuBar(long style = 0);
650 bool Append(wxMenu *menu, const wxString& title);
651 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
652 size_t GetMenuCount();
653 wxMenu *GetMenu(size_t pos);
654 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
655 wxMenu *Remove(size_t pos);
656 void EnableTop(size_t pos, bool enable);
657 void SetLabelTop(size_t pos, const wxString& label);
658 wxString GetLabelTop(size_t pos);
659 int FindMenuItem(const wxString& menuString, const wxString& itemString);
660 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
661 void Enable(int id, bool enable);
662 void Check(int id, bool check);
663 bool IsChecked(int id);
664 bool IsEnabled(int id);
666 void SetLabel(int id, const wxString &label);
667 wxString GetLabel(int id);
669 void SetHelpString(int id, const wxString& helpString);
670 wxString GetHelpString(int id);
675 //----------------------------------------------------------------------
679 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
680 const wxString& text = wxPyEmptyStr,
681 const wxString& help = wxPyEmptyStr,
682 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
689 void SetText(const wxString& str);
691 const wxString& GetText();
692 void SetCheckable(bool checkable);
695 void SetSubMenu(wxMenu *menu);
696 wxMenu *GetSubMenu();
697 void Enable(bool enable = TRUE);
699 void Check(bool check = TRUE);
702 void SetHelp(const wxString& str);
703 const wxString& GetHelp();
704 wxAcceleratorEntry *GetAccel();
705 void SetAccel(wxAcceleratorEntry *accel);
709 //---------------------------------------------------------------------------