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 //---------------------------------------------------------------------------
38 bool ProcessEvent(wxEvent& event);
39 void AddPendingEvent(wxEvent& event);
40 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
42 bool GetEvtHandlerEnabled();
43 void SetEvtHandlerEnabled(bool enabled);
45 wxEvtHandler* GetNextHandler();
46 wxEvtHandler* GetPreviousHandler();
47 void SetNextHandler(wxEvtHandler* handler);
48 void SetPreviousHandler(wxEvtHandler* handler);
52 void Connect( int id, int lastId, int eventType, PyObject* func) {
53 if (PyCallable_Check(func)) {
54 self->Connect(id, lastId, eventType,
55 (wxObjectEventFunction) &wxPyCallback::EventThunker,
56 new wxPyCallback(func));
60 bool Disconnect(int id, int lastId = -1,
61 wxEventType eventType = wxEVT_NULL) {
62 return self->Disconnect(id, lastId, eventType,
63 (wxObjectEventFunction)
64 &wxPyCallback::EventThunker);
69 %pragma(python) addtoclass = "
73 // %pragma(python) addtoclass = "
74 // def __getattr__(self, name):
75 // pl = self._prop_list_
76 // if pl.has_key(name):
77 // getFunc, setFunc = pl[name]
79 // return getattr(self, getFunc)()
81 // raise TypeError, '%s property is write-only' % name
82 // raise AttributeError, name
84 // def __setattr__(self, name, value):
85 // pl = self._prop_list_
86 // if pl.has_key(name):
87 // getFunc, setFunc = pl[name]
89 // return getattr(self, setFunc)(value)
91 // raise TypeError, '%s property is read-only' % name
92 // self.__dict__[name] = value
97 //----------------------------------------------------------------------
99 class wxValidator : public wxEvtHandler {
104 wxValidator* Clone();
105 wxWindow* GetWindow();
106 void SetWindow(wxWindow* window);
109 %pragma(python) addtoclass = "
111 'window' : ('GetWindow', 'SetWindow'),
113 _prop_list_.update(wxEvtHandler._prop_list_)
118 bool wxValidator_IsSilent() {
119 return wxValidator::IsSilent();
122 void wxValidator_SetBellOnError(int doIt = TRUE) {
123 wxValidator::SetBellOnError(doIt);
127 //----------------------------------------------------------------------
129 class wxPyValidator : public wxValidator {
130 DECLARE_DYNAMIC_CLASS(wxPyValidator);
134 // wxPyValidator(const wxPyValidator& other);
139 wxObject* wxPyValidator::Clone() const {
140 wxPyValidator* ptr = NULL;
141 wxPyValidator* self = (wxPyValidator*)this;
143 bool doSave = wxPyRestoreThread();
144 if (self->m_myInst.findCallback("Clone")) {
146 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
148 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
152 // This is very dangerous!!! But is the only way I could find
153 // to squash a memory leak. Currently it is okay, but if the
154 // validator architecture in wxWindows ever changes, problems
158 wxPySaveThread(doSave);
162 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
163 DEC_PYCALLBACK_BOOL_(TransferToWindow);
164 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
170 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
171 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
172 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
174 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
178 class wxPyValidator : public wxValidator {
183 %addmethods { void Destroy() { delete self; } }
185 void _setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
186 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyValidator, 0)"
190 //----------------------------------------------------------------------
192 %apply int * INOUT { int* x, int* y };
194 class wxWindow : public wxEvtHandler {
197 wxWindow(wxWindow* parent, const wxWindowID id,
198 const wxPoint& pos = wxPyDefaultPosition,
199 const wxSize& size = wxPyDefaultSize,
201 char* name = "panel");
203 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
206 void Center(int direction = wxBOTH);
207 void Centre(int direction = wxBOTH);
208 void CentreOnParent(int direction = wxBOTH );
209 void CenterOnParent(int direction = wxBOTH );
210 void CentreOnScreen(int direction = wxBOTH );
211 void CenterOnScreen(int direction = wxBOTH );
213 // (uses apply'ed INOUT typemap, see above)
214 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
215 wxPoint ClientToScreen(const wxPoint& pt);
217 bool Close(int force = FALSE);
219 void DestroyChildren();
221 void DragAcceptFiles(bool accept);
223 void Enable(bool enable);
224 //bool FakePopupMenu(wxMenu* menu, int x, int y);
225 %name(FindWindowById) wxWindow* FindWindow(long id);
226 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
228 wxColour GetBackgroundColour();
230 //wxList& GetChildren();
232 PyObject* GetChildren() {
233 wxWindowList& list = self->GetChildren();
234 return wxPy_ConvertList(&list, "wxWindow");
240 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
241 wxSize GetClientSize();
242 wxLayoutConstraints * GetConstraints();
243 wxEvtHandler* GetEventHandler();
246 wxColour GetForegroundColour();
247 wxWindow * GetGrandParent();
250 return wxPyGetWinHandle(self); //(long)self->GetHandle();
255 void SetLabel(const wxString& label);
257 wxWindow * GetParent();
258 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
259 wxPoint GetPosition();
261 int GetScrollThumb(int orientation);
262 int GetScrollPos(int orientation);
263 int GetScrollRange(int orientation);
264 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
266 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
267 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
268 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
269 const wxFont* font = NULL); //, bool use16 = FALSE)
271 wxRegion GetUpdateRegion();
272 long GetWindowStyleFlag();
273 void SetWindowStyleFlag(long style);
274 void SetWindowStyle(long style);
278 bool IsExposed( int x, int y, int w=0, int h=0 );
279 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
280 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
285 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
287 void MakeModal(bool flag);
288 %name(MoveXY)void Move(int x, int y);
289 void Move(const wxPoint& point);
291 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
292 void PushEventHandler(wxEvtHandler* handler);
294 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
295 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
298 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
300 void RemoveChild(wxWindow* child);
301 bool Reparent( wxWindow* newParent );
303 // (uses apply'ed INOUT typemap, see above)
304 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
305 wxPoint ScreenToClient(const wxPoint& pt);
307 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
308 void SetAcceleratorTable(const wxAcceleratorTable& accel);
309 void SetAutoLayout(bool autoLayout);
310 bool GetAutoLayout();
311 void SetBackgroundColour(const wxColour& colour);
312 void SetConstraints(wxLayoutConstraints *constraints);
313 void UnsetConstraints(wxLayoutConstraints *constraints);
316 void SetFont(const wxFont& font);
317 void SetForegroundColour(const wxColour& colour);
319 void SetName(const wxString& name);
320 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
321 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
323 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
325 void SetSize(const wxSize& size) {
329 void SetPosition(const wxPoint& pos) {
334 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
335 %name(SetClientSizeWH)void SetClientSize(int width, int height);
336 void SetClientSize(const wxSize& size);
337 //void SetPalette(wxPalette* palette);
338 void SetCursor(const wxCursor&cursor);
339 void SetEventHandler(wxEvtHandler* handler);
340 void SetTitle(const wxString& title);
341 bool Show(bool show);
342 bool TransferDataFromWindow();
343 bool TransferDataToWindow();
345 void WarpPointer(int x, int y);
347 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
348 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
350 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
351 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
353 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
354 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
356 %name(SetToolTipString)void SetToolTip(const wxString &tip);
357 void SetToolTip(wxToolTip *tooltip);
358 wxToolTip* GetToolTip();
360 void SetSizer(wxSizer* sizer);
363 wxValidator* GetValidator();
364 void SetValidator(const wxValidator& validator);
366 void SetDropTarget(wxDropTarget* target);
367 wxDropTarget* GetDropTarget();
368 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
370 wxSize GetBestSize();
372 void SetCaret(wxCaret *caret);
374 %pragma(python) addtoclass = "# replaces broken shadow method
375 def GetCaret(self, *_args, **_kwargs):
376 from misc2 import wxCaretPtr
377 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
378 if val: val = wxCaretPtr(val)
384 %pragma(python) addtoclass = "
386 'size' : ('GetSize', 'SetSize'),
387 'enabled' : ('IsEnabled', 'Enable'),
388 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
389 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
390 'children' : ('GetChildren', None),
391 'charHeight' : ('GetCharHeight', None),
392 'charWidth' : ('GetCharWidth', None),
393 'clientSize' : ('GetClientSize', 'SetClientSize'),
394 'font' : ('GetFont', 'SetFont'),
395 'grandParent' : ('GetGrandParent', None),
396 'handle' : ('GetHandle', None),
397 'label' : ('GetLabel', 'SetLabel'),
398 'name' : ('GetName', 'SetName'),
399 'parent' : ('GetParent', None),
400 'position' : ('GetPosition', 'SetPosition'),
401 'title' : ('GetTitle', 'SetTitle'),
402 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
403 'visible' : ('IsShown', 'Show'),
404 'toolTip' : ('GetToolTip', 'SetToolTip'),
405 'sizer' : ('GetSizer', 'SetSizer'),
406 'validator' : ('GetValidator', 'SetValidator'),
407 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
408 'caret' : ('GetCaret', 'SetCaret'),
409 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
410 'constraints' : ('GetConstraints', 'SetConstraints'),
413 _prop_list_.update(wxEvtHandler._prop_list_)
417 //%clear int* x, int* y;
421 %pragma(python) code = "
422 def wxDLG_PNT(win, point_or_x, y=None):
424 return win.ConvertDialogPointToPixels(point_or_x)
426 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
428 def wxDLG_SZE(win, size_width, height=None):
430 return win.ConvertDialogSizeToPixels(size_width)
432 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
437 wxWindow* wxWindow_FindFocus() {
438 return wxWindow::FindFocus();
444 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
445 wxWindow* win = new wxWindow;
447 win->SubclassWin(hWnd);
454 int wxWindow_NewControlId() {
455 return wxWindow::NewControlId();
457 int wxWindow_NextControlId(int id) {
458 return wxWindow::NextControlId(id);
460 int wxWindow_PrevControlId(int id) {
461 return wxWindow::PrevControlId(id);
466 //---------------------------------------------------------------------------
468 class wxPanel : public wxWindow {
470 wxPanel(wxWindow* parent,
472 const wxPoint& pos = wxPyDefaultPosition,
473 const wxSize& size = wxPyDefaultSize,
474 long style = wxTAB_TRAVERSAL,
475 const char* name = "panel");
477 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
480 wxButton* GetDefaultItem();
481 void SetDefaultItem(wxButton *btn);
483 // fix some SWIG trouble...
484 %pragma(python) addtoclass = "
485 def GetDefaultItem(self):
487 val = windowsc.wxPanel_GetDefaultItem(self.this)
488 val = controls.wxButtonPtr(val)
493 //---------------------------------------------------------------------------
495 class wxDialog : public wxPanel {
497 wxDialog(wxWindow* parent,
499 const wxString& title,
500 const wxPoint& pos = wxPyDefaultPosition,
501 const wxSize& size = wxPyDefaultSize,
502 long style = wxDEFAULT_DIALOG_STYLE,
503 const char* name = "dialogBox");
505 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
507 void Centre(int direction = wxBOTH);
508 void EndModal(int retCode);
510 void Iconize(bool iconize);
512 void SetModal(bool flag);
514 void SetTitle(const wxString& title);
515 bool Show(bool show);
519 void SetReturnCode(int retCode);
522 //---------------------------------------------------------------------------
524 class wxScrolledWindow : public wxPanel {
526 wxScrolledWindow(wxWindow* parent,
527 const wxWindowID id = -1,
528 const wxPoint& pos = wxPyDefaultPosition,
529 const wxSize& size = wxPyDefaultSize,
530 long style = wxHSCROLL | wxVSCROLL,
531 char* name = "scrolledWindow");
533 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
534 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
536 void EnableScrolling(bool xScrolling, bool yScrolling);
537 int GetScrollPageSize(int orient);
538 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
539 wxWindow* GetTargetWindow();
540 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
542 void PrepareDC(wxDC& dc);
543 void Scroll(int x, int y);
544 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
545 int noUnitsX, int noUnitsY,
546 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
547 void SetScrollPageSize(int orient, int pageSize);
548 void SetTargetWindow(wxWindow* window);
549 void GetViewStart(int* OUTPUT, int* OUTPUT);
550 void ViewStart(int* OUTPUT, int* OUTPUT);
552 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
553 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
557 //----------------------------------------------------------------------
560 class wxMenu : public wxEvtHandler {
562 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
564 void Append(int id, const wxString& item,
565 const wxString& helpString = wxPyEmptyStr,
566 int checkable = FALSE);
567 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
568 const wxString& helpString = wxPyEmptyStr);
569 %name(AppendItem)void Append(const wxMenuItem* item);
571 void AppendSeparator();
573 void Check(int id, bool flag);
574 bool IsChecked(int id);
575 void Enable(int id, bool enable);
576 bool IsEnabled(int id);
578 int FindItem(const wxString& itemString);
579 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
582 void SetTitle(const wxString& title);
584 wxString GetLabel(int id);
585 void SetLabel(int id, const wxString& label);
587 wxString GetHelpString(int id);
588 void SetHelpString(int id, const wxString& helpString);
589 void UpdateUI(wxEvtHandler* source = NULL);
592 %name(DeleteItem)bool Delete(wxMenuItem *item);
593 bool Insert(size_t pos, wxMenuItem *item);
594 wxMenuItem *Remove(int id);
595 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
598 void Destroy() { delete self; }
600 %name(DestroyId)bool Destroy(int id);
601 %name(DestroyItem)bool Destroy(wxMenuItem *item);
603 size_t GetMenuItemCount();
604 //wxMenuItemList& GetMenuItems();
606 PyObject* GetMenuItems() {
607 wxMenuItemList& list = self->GetMenuItems();
608 return wxPy_ConvertList(&list, "wxMenuItem");
612 void SetEventHandler(wxEvtHandler *handler);
613 wxEvtHandler *GetEventHandler();
615 void SetInvokingWindow(wxWindow *win);
616 wxWindow *GetInvokingWindow();
622 void SetParent(wxMenu *parent);
627 //----------------------------------------------------------------------
629 class wxMenuBar : public wxWindow {
633 bool Append(wxMenu *menu, const wxString& title);
634 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
635 size_t GetMenuCount();
636 wxMenu *GetMenu(size_t pos);
637 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
638 wxMenu *Remove(size_t pos);
639 void EnableTop(size_t pos, bool enable);
640 void SetLabelTop(size_t pos, const wxString& label);
641 wxString GetLabelTop(size_t pos);
642 int FindMenuItem(const wxString& menuString, const wxString& itemString);
643 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
644 void Enable(int id, bool enable);
645 void Check(int id, bool check);
646 bool IsChecked(int id);
647 bool IsEnabled(int id);
649 void SetLabel(int id, const wxString &label);
650 wxString GetLabel(int id);
652 void SetHelpString(int id, const wxString& helpString);
653 wxString GetHelpString(int id);
658 //----------------------------------------------------------------------
662 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
663 const wxString& text = wxPyEmptyStr,
664 const wxString& help = wxPyEmptyStr,
665 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
672 void SetText(const wxString& str);
674 const wxString& GetText();
675 void SetCheckable(bool checkable);
678 void SetSubMenu(wxMenu *menu);
679 wxMenu *GetSubMenu();
680 void Enable(bool enable = TRUE);
682 void Check(bool check = TRUE);
685 void SetHelp(const wxString& str);
686 const wxString& GetHelp();
687 wxAcceleratorEntry *GetAccel();
688 void SetAccel(wxAcceleratorEntry *accel);
692 //---------------------------------------------------------------------------