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 );
211 // (uses apply'ed INOUT typemap, see above)
212 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
213 wxPoint ClientToScreen(const wxPoint& pt);
215 bool Close(int force = FALSE);
217 void DestroyChildren();
219 void DragAcceptFiles(bool accept);
221 void Enable(bool enable);
222 //bool FakePopupMenu(wxMenu* menu, int x, int y);
223 %name(FindWindowById) wxWindow* FindWindow(long id);
224 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
226 wxColour GetBackgroundColour();
228 //wxList& GetChildren();
230 PyObject* GetChildren() {
231 wxWindowList& list = self->GetChildren();
232 return wxPy_ConvertList(&list, "wxWindow");
238 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
239 wxSize GetClientSize();
240 wxLayoutConstraints * GetConstraints();
241 wxEvtHandler* GetEventHandler();
244 wxColour GetForegroundColour();
245 wxWindow * GetGrandParent();
248 return wxPyGetWinHandle(self); //(long)self->GetHandle();
253 void SetLabel(const wxString& label);
255 wxWindow * GetParent();
256 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
257 wxPoint GetPosition();
259 int GetScrollThumb(int orientation);
260 int GetScrollPos(int orientation);
261 int GetScrollRange(int orientation);
262 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
264 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
265 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
266 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
267 const wxFont* font = NULL); //, bool use16 = FALSE)
269 wxRegion GetUpdateRegion();
270 long GetWindowStyleFlag();
271 void SetWindowStyleFlag(long style);
272 void SetWindowStyle(long style);
276 bool IsExposed( int x, int y, int w=0, int h=0 );
277 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
278 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
283 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
285 void MakeModal(bool flag);
286 %name(MoveXY)void Move(int x, int y);
287 void Move(const wxPoint& point);
289 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
290 void PushEventHandler(wxEvtHandler* handler);
292 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
293 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
296 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
298 void RemoveChild(wxWindow* child);
299 bool Reparent( wxWindow* newParent );
301 // (uses apply'ed INOUT typemap, see above)
302 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
303 wxPoint ScreenToClient(const wxPoint& pt);
305 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
306 void SetAcceleratorTable(const wxAcceleratorTable& accel);
307 void SetAutoLayout(bool autoLayout);
308 bool GetAutoLayout();
309 void SetBackgroundColour(const wxColour& colour);
310 void SetConstraints(wxLayoutConstraints *constraints);
311 void UnsetConstraints(wxLayoutConstraints *constraints);
314 void SetFont(const wxFont& font);
315 void SetForegroundColour(const wxColour& colour);
317 void SetName(const wxString& name);
318 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
319 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
321 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
323 void SetSize(const wxSize& size) {
327 void SetPosition(const wxPoint& pos) {
332 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
333 %name(SetClientSizeWH)void SetClientSize(int width, int height);
334 void SetClientSize(const wxSize& size);
335 //void SetPalette(wxPalette* palette);
336 void SetCursor(const wxCursor&cursor);
337 void SetEventHandler(wxEvtHandler* handler);
338 void SetTitle(const wxString& title);
339 bool Show(bool show);
340 bool TransferDataFromWindow();
341 bool TransferDataToWindow();
343 void WarpPointer(int x, int y);
345 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
346 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
348 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
349 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
351 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
352 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
354 %name(SetToolTipString)void SetToolTip(const wxString &tip);
355 void SetToolTip(wxToolTip *tooltip);
356 wxToolTip* GetToolTip();
358 void SetSizer(wxSizer* sizer);
361 wxValidator* GetValidator();
362 void SetValidator(const wxValidator& validator);
364 void SetDropTarget(wxDropTarget* target);
365 wxDropTarget* GetDropTarget();
366 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
368 wxSize GetBestSize();
370 void SetCaret(wxCaret *caret);
372 %pragma(python) addtoclass = "# replaces broken shadow method
373 def GetCaret(self, *_args, **_kwargs):
374 from misc2 import wxCaretPtr
375 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
376 if val: val = wxCaretPtr(val)
382 %pragma(python) addtoclass = "
384 'size' : ('GetSize', 'SetSize'),
385 'enabled' : ('IsEnabled', 'Enable'),
386 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
387 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
388 'children' : ('GetChildren', None),
389 'charHeight' : ('GetCharHeight', None),
390 'charWidth' : ('GetCharWidth', None),
391 'clientSize' : ('GetClientSize', 'SetClientSize'),
392 'font' : ('GetFont', 'SetFont'),
393 'grandParent' : ('GetGrandParent', None),
394 'handle' : ('GetHandle', None),
395 'label' : ('GetLabel', 'SetLabel'),
396 'name' : ('GetName', 'SetName'),
397 'parent' : ('GetParent', None),
398 'position' : ('GetPosition', 'SetPosition'),
399 'title' : ('GetTitle', 'SetTitle'),
400 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
401 'visible' : ('IsShown', 'Show'),
402 'toolTip' : ('GetToolTip', 'SetToolTip'),
403 'sizer' : ('GetSizer', 'SetSizer'),
404 'validator' : ('GetValidator', 'SetValidator'),
405 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
406 'caret' : ('GetCaret', 'SetCaret'),
407 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
408 'constraints' : ('GetConstraints', 'SetConstraints'),
411 _prop_list_.update(wxEvtHandler._prop_list_)
415 //%clear int* x, int* y;
419 %pragma(python) code = "
420 def wxDLG_PNT(win, point_or_x, y=None):
422 return win.ConvertDialogPointToPixels(point_or_x)
424 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
426 def wxDLG_SZE(win, size_width, height=None):
428 return win.ConvertDialogSizeToPixels(size_width)
430 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
435 wxWindow* wxWindow_FindFocus() {
436 return wxWindow::FindFocus();
442 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
443 wxWindow* win = new wxWindow;
445 win->SubclassWin(hWnd);
452 int wxWindow_NewControlId() {
453 return wxWindow::NewControlId();
455 int wxWindow_NextControlId(int id) {
456 return wxWindow::NextControlId(id);
458 int wxWindow_PrevControlId(int id) {
459 return wxWindow::PrevControlId(id);
464 //---------------------------------------------------------------------------
466 class wxPanel : public wxWindow {
468 wxPanel(wxWindow* parent,
470 const wxPoint& pos = wxPyDefaultPosition,
471 const wxSize& size = wxPyDefaultSize,
472 long style = wxTAB_TRAVERSAL,
473 const char* name = "panel");
475 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
478 wxButton* GetDefaultItem();
479 void SetDefaultItem(wxButton *btn);
481 // fix some SWIG trouble...
482 %pragma(python) addtoclass = "
483 def GetDefaultItem(self):
485 val = windowsc.wxPanel_GetDefaultItem(self.this)
486 val = controls.wxButtonPtr(val)
491 //---------------------------------------------------------------------------
493 class wxDialog : public wxPanel {
495 wxDialog(wxWindow* parent,
497 const wxString& title,
498 const wxPoint& pos = wxPyDefaultPosition,
499 const wxSize& size = wxPyDefaultSize,
500 long style = wxDEFAULT_DIALOG_STYLE,
501 const char* name = "dialogBox");
503 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
505 void Centre(int direction = wxBOTH);
506 void EndModal(int retCode);
508 void Iconize(bool iconize);
510 void SetModal(bool flag);
512 void SetTitle(const wxString& title);
513 bool Show(bool show);
517 void SetReturnCode(int retCode);
520 //---------------------------------------------------------------------------
522 class wxScrolledWindow : public wxPanel {
524 wxScrolledWindow(wxWindow* parent,
525 const wxWindowID id = -1,
526 const wxPoint& pos = wxPyDefaultPosition,
527 const wxSize& size = wxPyDefaultSize,
528 long style = wxHSCROLL | wxVSCROLL,
529 char* name = "scrolledWindow");
531 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
532 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
534 void EnableScrolling(bool xScrolling, bool yScrolling);
535 int GetScrollPageSize(int orient);
536 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
537 wxWindow* GetTargetWindow();
538 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
540 void PrepareDC(wxDC& dc);
541 void Scroll(int x, int y);
542 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
543 int noUnitsX, int noUnitsY,
544 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
545 void SetScrollPageSize(int orient, int pageSize);
546 void SetTargetWindow(wxWindow* window);
547 void GetViewStart(int* OUTPUT, int* OUTPUT);
548 void ViewStart(int* OUTPUT, int* OUTPUT);
550 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
551 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
555 //----------------------------------------------------------------------
558 class wxMenu : public wxEvtHandler {
560 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
562 void Append(int id, const wxString& item,
563 const wxString& helpString = wxPyEmptyStr,
564 int checkable = FALSE);
565 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
566 const wxString& helpString = wxPyEmptyStr);
567 %name(AppendItem)void Append(const wxMenuItem* item);
569 void AppendSeparator();
571 void Check(int id, bool flag);
572 bool IsChecked(int id);
573 void Enable(int id, bool enable);
574 bool IsEnabled(int id);
576 int FindItem(const wxString& itemString);
577 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
580 void SetTitle(const wxString& title);
582 wxString GetLabel(int id);
583 void SetLabel(int id, const wxString& label);
585 wxString GetHelpString(int id);
586 void SetHelpString(int id, const wxString& helpString);
587 void UpdateUI(wxEvtHandler* source = NULL);
590 %name(DeleteItem)bool Delete(wxMenuItem *item);
591 bool Insert(size_t pos, wxMenuItem *item);
592 wxMenuItem *Remove(int id);
593 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
596 void Destroy() { delete self; }
598 %name(DestroyId)bool Destroy(int id);
599 %name(DestroyItem)bool Destroy(wxMenuItem *item);
601 size_t GetMenuItemCount();
602 //wxMenuItemList& GetMenuItems();
604 PyObject* GetMenuItems() {
605 wxMenuItemList& list = self->GetMenuItems();
606 return wxPy_ConvertList(&list, "wxMenuItem");
610 void SetEventHandler(wxEvtHandler *handler);
611 wxEvtHandler *GetEventHandler();
613 void SetInvokingWindow(wxWindow *win);
614 wxWindow *GetInvokingWindow();
620 void SetParent(wxMenu *parent);
625 //----------------------------------------------------------------------
627 class wxMenuBar : public wxWindow {
631 bool Append(wxMenu *menu, const wxString& title);
632 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
633 size_t GetMenuCount();
634 wxMenu *GetMenu(size_t pos);
635 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
636 wxMenu *Remove(size_t pos);
637 void EnableTop(size_t pos, bool enable);
638 void SetLabelTop(size_t pos, const wxString& label);
639 wxString GetLabelTop(size_t pos);
640 int FindMenuItem(const wxString& menuString, const wxString& itemString);
641 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
642 void Enable(int id, bool enable);
643 void Check(int id, bool check);
644 bool IsChecked(int id);
645 bool IsEnabled(int id);
647 void SetLabel(int id, const wxString &label);
648 wxString GetLabel(int id);
650 void SetHelpString(int id, const wxString& helpString);
651 wxString GetHelpString(int id);
656 //----------------------------------------------------------------------
660 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
661 const wxString& text = wxPyEmptyStr,
662 const wxString& help = wxPyEmptyStr,
663 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
670 void SetText(const wxString& str);
672 const wxString& GetText();
673 void SetCheckable(bool checkable);
676 void SetSubMenu(wxMenu *menu);
677 wxMenu *GetSubMenu();
678 void Enable(bool enable = TRUE);
680 void Check(bool check = TRUE);
683 void SetHelp(const wxString& str);
684 const wxString& GetHelp();
685 wxAcceleratorEntry *GetAccel();
686 void SetAccel(wxAcceleratorEntry *accel);
690 //---------------------------------------------------------------------------