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>
19 #include <wx/tooltip.h>
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
33 %pragma(python) code = "import wx"
37 static wxString wxPyEmptyStr("");
40 //---------------------------------------------------------------------------
42 class wxEvtHandler : public wxObject {
46 bool ProcessEvent(wxEvent& event);
47 void AddPendingEvent(wxEvent& event);
48 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
50 bool GetEvtHandlerEnabled();
51 void SetEvtHandlerEnabled(bool enabled);
53 wxEvtHandler* GetNextHandler();
54 wxEvtHandler* GetPreviousHandler();
55 void SetNextHandler(wxEvtHandler* handler);
56 void SetPreviousHandler(wxEvtHandler* handler);
60 void Connect( int id, int lastId, int eventType, PyObject* func) {
61 if (PyCallable_Check(func)) {
62 self->Connect(id, lastId, eventType,
63 (wxObjectEventFunction) &wxPyCallback::EventThunker,
64 new wxPyCallback(func));
68 bool Disconnect(int id, int lastId = -1,
69 wxEventType eventType = wxEVT_NULL) {
70 return self->Disconnect(id, lastId, eventType,
71 (wxObjectEventFunction)
72 &wxPyCallback::EventThunker);
76 // %pragma(python) addtoclass = "
79 // %pragma(python) addtoclass = "
80 // def __getattr__(self, name):
81 // pl = self._prop_list_
82 // if pl.has_key(name):
83 // getFunc, setFunc = pl[name]
85 // return getattr(self, getFunc)()
87 // raise TypeError, '%s property is write-only' % name
88 // raise AttributeError, name
90 // def __setattr__(self, name, value):
91 // pl = self._prop_list_
92 // if pl.has_key(name):
93 // getFunc, setFunc = pl[name]
95 // return getattr(self, setFunc)(value)
97 // raise TypeError, '%s property is read-only' % name
98 // self.__dict__[name] = value
103 //----------------------------------------------------------------------
105 class wxValidator : public wxEvtHandler {
110 wxValidator* Clone();
111 wxWindow* GetWindow();
112 void SetWindow(wxWindow* window);
114 static bool IsSilent();
115 static void SetBellOnError(int doIt = TRUE);
117 // // Properties list
118 // %pragma(python) addtoclass = "
120 // 'window' : ('GetWindow', 'SetWindow'),
122 // _prop_list_.update(wxEvtHandler._prop_list_)
127 //----------------------------------------------------------------------
129 class wxPyValidator : public wxValidator {
130 DECLARE_DYNAMIC_CLASS(wxPyValidator);
138 wxObject* wxPyValidator::Clone() const {
139 wxPyValidator* ptr = NULL;
140 wxPyValidator* self = (wxPyValidator*)this;
142 bool doSave = wxPyRestoreThread();
143 if (self->m_myInst.findCallback("Clone")) {
145 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
147 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
151 // This is very dangerous!!! But is the only way I could find
152 // to squash a memory leak. Currently it is okay, but if the
153 // validator architecture in wxWindows ever changes, problems
157 wxPySaveThread(doSave);
162 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
163 DEC_PYCALLBACK_BOOL_(TransferToWindow);
164 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
169 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
170 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
171 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
173 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
177 class wxPyValidator : public wxValidator {
181 void _setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
182 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyValidator, 1)"
186 //----------------------------------------------------------------------
188 %apply int * INOUT { int* x, int* y };
190 class wxWindow : public wxEvtHandler {
193 wxWindow(wxWindow* parent, const wxWindowID id,
194 const wxPoint& pos = wxDefaultPosition,
195 const wxSize& size = wxDefaultSize,
197 char* name = "panel");
199 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
202 void Center(int direction = wxBOTH);
203 void Centre(int direction = wxBOTH);
204 void CentreOnParent(int direction = wxBOTH );
205 void CenterOnParent(int direction = wxBOTH );
206 void CentreOnScreen(int direction = wxBOTH );
207 void CenterOnScreen(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();
218 bool IsBeingDeleted();
220 void DragAcceptFiles(bool accept);
222 void Enable(bool enable);
223 //bool FakePopupMenu(wxMenu* menu, int x, int y);
224 %name(FindWindowById) wxWindow* FindWindow(long id);
225 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
227 wxColour GetBackgroundColour();
229 //wxList& GetChildren();
231 PyObject* GetChildren() {
232 wxWindowList& list = self->GetChildren();
233 return wxPy_ConvertList(&list, "wxWindow");
239 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
240 wxSize GetClientSize();
241 wxLayoutConstraints * GetConstraints();
242 wxEvtHandler* GetEventHandler();
245 wxColour GetForegroundColour();
246 wxWindow * GetGrandParent();
249 return wxPyGetWinHandle(self); //(long)self->GetHandle();
254 void SetLabel(const wxString& label);
256 wxWindow * GetParent();
257 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
258 wxPoint GetPosition();
260 int GetScrollThumb(int orientation);
261 int GetScrollPos(int orientation);
262 int GetScrollRange(int orientation);
263 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
265 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
266 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
267 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
268 const wxFont* font = NULL); //, bool use16 = FALSE)
270 wxRegion GetUpdateRegion();
271 long GetWindowStyleFlag();
272 void SetWindowStyleFlag(long style);
273 void SetWindowStyle(long style);
277 bool IsExposed( int x, int y, int w=0, int h=0 );
278 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
279 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
284 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
286 void MakeModal(bool flag);
287 %name(MoveXY)void Move(int x, int y);
288 void Move(const wxPoint& point);
290 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
291 void PushEventHandler(wxEvtHandler* handler);
293 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
294 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
297 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
299 void RemoveChild(wxWindow* child);
300 bool Reparent( wxWindow* newParent );
302 // (uses apply'ed INOUT typemap, see above)
303 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
304 wxPoint ScreenToClient(const wxPoint& pt);
306 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
307 void SetAcceleratorTable(const wxAcceleratorTable& accel);
308 void SetAutoLayout(bool autoLayout);
309 bool GetAutoLayout();
310 void SetBackgroundColour(const wxColour& colour);
311 void SetConstraints(wxLayoutConstraints *constraints);
312 void UnsetConstraints(wxLayoutConstraints *constraints);
315 void SetFont(const wxFont& font);
316 void SetForegroundColour(const wxColour& colour);
318 void SetName(const wxString& name);
319 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
320 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
322 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
324 void SetSize(const wxSize& size) {
328 void SetPosition(const wxPoint& pos) {
332 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
333 self->SetSize(rect, sizeFlags);
337 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
338 %name(SetClientSizeWH)void SetClientSize(int width, int height);
339 void SetClientSize(const wxSize& size);
340 //void SetPalette(wxPalette* palette);
341 void SetCursor(const wxCursor&cursor);
342 void SetEventHandler(wxEvtHandler* handler);
343 void SetExtraStyle(long exStyle);
344 void SetTitle(const wxString& title);
345 bool Show(bool show);
346 bool TransferDataFromWindow();
347 bool TransferDataToWindow();
349 void WarpPointer(int x, int y);
351 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
352 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
354 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
355 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
357 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
358 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
360 %name(SetToolTipString)void SetToolTip(const wxString &tip);
361 void SetToolTip(wxToolTip *tooltip);
362 wxToolTip* GetToolTip();
364 void SetSizer(wxSizer* sizer);
367 wxValidator* GetValidator();
368 void SetValidator(const wxValidator& validator);
370 void SetDropTarget(wxDropTarget* target);
371 wxDropTarget* GetDropTarget();
372 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
374 wxSize GetBestSize();
376 void SetCaret(wxCaret *caret);
378 %pragma(python) addtoclass = "# replaces broken shadow method
379 def GetCaret(self, *_args, **_kwargs):
380 from misc2 import wxCaretPtr
381 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
382 if val: val = wxCaretPtr(val)
387 // // Properties list
388 // %pragma(python) addtoclass = "
390 // 'size' : ('GetSize', 'SetSize'),
391 // 'enabled' : ('IsEnabled', 'Enable'),
392 // 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
393 // 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
394 // 'children' : ('GetChildren', None),
395 // 'charHeight' : ('GetCharHeight', None),
396 // 'charWidth' : ('GetCharWidth', None),
397 // 'clientSize' : ('GetClientSize', 'SetClientSize'),
398 // 'font' : ('GetFont', 'SetFont'),
399 // 'grandParent' : ('GetGrandParent', None),
400 // 'handle' : ('GetHandle', None),
401 // 'label' : ('GetLabel', 'SetLabel'),
402 // 'name' : ('GetName', 'SetName'),
403 // 'parent' : ('GetParent', None),
404 // 'position' : ('GetPosition', 'SetPosition'),
405 // 'title' : ('GetTitle', 'SetTitle'),
406 // 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
407 // 'visible' : ('IsShown', 'Show'),
408 // 'toolTip' : ('GetToolTip', 'SetToolTip'),
409 // 'sizer' : ('GetSizer', 'SetSizer'),
410 // 'validator' : ('GetValidator', 'SetValidator'),
411 // 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
412 // 'caret' : ('GetCaret', 'SetCaret'),
413 // 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
414 // 'constraints' : ('GetConstraints', 'SetConstraints'),
417 // _prop_list_.update(wxEvtHandler._prop_list_)
424 %pragma(python) code = "
425 def wxDLG_PNT(win, point_or_x, y=None):
427 return win.ConvertDialogPointToPixels(point_or_x)
429 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
431 def wxDLG_SZE(win, size_width, height=None):
433 return win.ConvertDialogSizeToPixels(size_width)
435 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
439 wxWindow* wxWindow_FindFocus() {
440 return wxWindow::FindFocus();
447 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
448 wxWindow* win = new wxWindow;
450 win->SubclassWin(hWnd);
457 int wxWindow_NewControlId() {
458 return wxWindow::NewControlId();
460 int wxWindow_NextControlId(int id) {
461 return wxWindow::NextControlId(id);
463 int wxWindow_PrevControlId(int id) {
464 return wxWindow::PrevControlId(id);
469 //---------------------------------------------------------------------------
471 class wxPanel : public wxWindow {
473 wxPanel(wxWindow* parent,
475 const wxPoint& pos = wxDefaultPosition,
476 const wxSize& size = wxDefaultSize,
477 long style = wxTAB_TRAVERSAL,
478 const char* name = "panel");
480 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
483 wxButton* GetDefaultItem();
484 void SetDefaultItem(wxButton *btn);
488 //---------------------------------------------------------------------------
490 class wxDialog : public wxPanel {
492 wxDialog(wxWindow* parent,
494 const wxString& title,
495 const wxPoint& pos = wxDefaultPosition,
496 const wxSize& size = wxDefaultSize,
497 long style = wxDEFAULT_DIALOG_STYLE,
498 const char* name = "dialogBox");
500 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
502 void Centre(int direction = wxBOTH);
503 void EndModal(int retCode);
505 void Iconize(bool iconize);
507 void SetModal(bool flag);
509 void SetTitle(const wxString& title);
510 bool Show(bool show);
514 void SetReturnCode(int retCode);
516 wxSizer* CreateTextSizer( const wxString &message );
517 wxSizer* CreateButtonSizer( long flags );
521 //---------------------------------------------------------------------------
524 // TODO: Add wrappers for the wxScrollHelper class, make wxScrolledWindow
525 // derive from it and wxPanel.
528 class wxScrolledWindow : public wxPanel {
530 wxScrolledWindow(wxWindow* parent,
531 const wxWindowID id = -1,
532 const wxPoint& pos = wxDefaultPosition,
533 const wxSize& size = wxDefaultSize,
534 long style = wxHSCROLL | wxVSCROLL,
535 char* name = "scrolledWindow");
537 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
538 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
540 void EnableScrolling(bool xScrolling, bool yScrolling);
541 int GetScrollPageSize(int orient);
542 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
543 wxWindow* GetTargetWindow();
544 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
546 void PrepareDC(wxDC& dc);
547 void Scroll(int x, int y);
548 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
549 int noUnitsX, int noUnitsY,
550 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
551 void SetScrollPageSize(int orient, int pageSize);
552 void SetTargetWindow(wxWindow* window);
553 void GetViewStart(int* OUTPUT, int* OUTPUT);
554 %pragma(python) addtoclass = "ViewStart = GetViewStart"
556 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
557 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
559 void SetScale(double xs, double ys);
563 void AdjustScrollbars();
566 //----------------------------------------------------------------------
569 class wxMenu : public wxEvtHandler {
571 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
573 void Append(int id, const wxString& item,
574 const wxString& helpString = wxPyEmptyStr,
575 int checkable = FALSE);
576 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
577 const wxString& helpString = wxPyEmptyStr);
578 %name(AppendItem)void Append(const wxMenuItem* item);
580 void AppendSeparator();
582 void Check(int id, bool flag);
583 bool IsChecked(int id);
584 void Enable(int id, bool enable);
585 bool IsEnabled(int id);
587 int FindItem(const wxString& itemString);
588 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
591 void SetTitle(const wxString& title);
593 wxString GetLabel(int id);
594 void SetLabel(int id, const wxString& label);
596 wxString GetHelpString(int id);
597 void SetHelpString(int id, const wxString& helpString);
598 void UpdateUI(wxEvtHandler* source = NULL);
601 %name(DeleteItem)bool Delete(wxMenuItem *item);
602 bool Insert(size_t pos, wxMenuItem *item);
603 wxMenuItem *Remove(int id);
604 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
607 void Destroy() { delete self; }
609 %name(DestroyId)bool Destroy(int id);
610 %name(DestroyItem)bool Destroy(wxMenuItem *item);
612 size_t GetMenuItemCount();
613 //wxMenuItemList& GetMenuItems();
615 PyObject* GetMenuItems() {
616 wxMenuItemList& list = self->GetMenuItems();
617 return wxPy_ConvertList(&list, "wxMenuItem");
621 void SetEventHandler(wxEvtHandler *handler);
622 wxEvtHandler *GetEventHandler();
624 void SetInvokingWindow(wxWindow *win);
625 wxWindow *GetInvokingWindow();
631 void SetParent(wxMenu *parent);
636 //----------------------------------------------------------------------
638 class wxMenuBar : public wxWindow {
640 wxMenuBar(long style = 0);
642 bool Append(wxMenu *menu, const wxString& title);
643 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
644 size_t GetMenuCount();
645 wxMenu *GetMenu(size_t pos);
646 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
647 wxMenu *Remove(size_t pos);
648 void EnableTop(size_t pos, bool enable);
649 void SetLabelTop(size_t pos, const wxString& label);
650 wxString GetLabelTop(size_t pos);
651 int FindMenuItem(const wxString& menuString, const wxString& itemString);
652 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
653 void Enable(int id, bool enable);
654 void Check(int id, bool check);
655 bool IsChecked(int id);
656 bool IsEnabled(int id);
658 void SetLabel(int id, const wxString &label);
659 wxString GetLabel(int id);
661 void SetHelpString(int id, const wxString& helpString);
662 wxString GetHelpString(int id);
667 //----------------------------------------------------------------------
669 class wxMenuItem : public wxObject {
671 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
672 const wxString& text = wxPyEmptyStr,
673 const wxString& help = wxPyEmptyStr,
674 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
681 void SetText(const wxString& str);
683 const wxString& GetText();
684 void SetCheckable(bool checkable);
687 void SetSubMenu(wxMenu *menu);
688 wxMenu *GetSubMenu();
689 void Enable(bool enable = TRUE);
691 void Check(bool check = TRUE);
694 void SetHelp(const wxString& str);
695 const wxString& GetHelp();
696 wxAcceleratorEntry *GetAccel();
697 void SetAccel(wxAcceleratorEntry *accel);
699 static wxString GetLabelFromText(const wxString& text);
701 // wxOwnerDrawn methods
703 void SetFont(const wxFont& font);
705 void SetTextColour(const wxColour& colText);
706 wxColour GetTextColour();
707 void SetBackgroundColour(const wxColour& colBack);
708 wxColour GetBackgroundColour();
709 void SetBitmaps(const wxBitmap& bmpChecked,
710 const wxBitmap& bmpUnchecked = wxNullBitmap);
711 void SetBitmap(const wxBitmap& bmpChecked);
712 const wxBitmap& GetBitmap(bool bChecked = TRUE);
713 void SetMarginWidth(int nWidth);
714 int GetMarginWidth();
715 static int GetDefaultMarginWidth();
716 //void SetName(const wxString& strName);
717 //const wxString& GetName();
718 //void SetCheckable(bool checkable);
719 //bool IsCheckable();
721 void ResetOwnerDrawn();
725 //---------------------------------------------------------------------------