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 );
209 // (uses apply'ed INOUT typemap, see above)
210 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
211 wxPoint ClientToScreen(const wxPoint& pt);
213 bool Close(int force = FALSE);
215 void DestroyChildren();
217 void DragAcceptFiles(bool accept);
219 void Enable(bool enable);
220 //bool FakePopupMenu(wxMenu* menu, int x, int y);
221 %name(FindWindowById) wxWindow* FindWindow(long id);
222 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
224 wxColour GetBackgroundColour();
226 //wxList& GetChildren();
228 PyObject* GetChildren() {
229 wxWindowList& list = self->GetChildren();
230 return wxPy_ConvertList(&list, "wxWindow");
236 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
237 wxSize GetClientSize();
238 wxLayoutConstraints * GetConstraints();
239 wxEvtHandler* GetEventHandler();
242 wxColour GetForegroundColour();
243 wxWindow * GetGrandParent();
246 return wxPyGetWinHandle(self); //(long)self->GetHandle();
251 void SetLabel(const wxString& label);
253 wxWindow * GetParent();
254 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
255 wxPoint GetPosition();
257 int GetScrollThumb(int orientation);
258 int GetScrollPos(int orientation);
259 int GetScrollRange(int orientation);
260 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
262 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
263 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
264 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
265 const wxFont* font = NULL); //, bool use16 = FALSE)
267 wxRegion GetUpdateRegion();
268 long GetWindowStyleFlag();
269 void SetWindowStyleFlag(long style);
270 void SetWindowStyle(long style);
274 bool IsExposed( int x, int y, int w=0, int h=0 );
275 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
276 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
281 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
283 void MakeModal(bool flag);
284 %name(MoveXY)void Move(int x, int y);
285 void Move(const wxPoint& point);
287 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
288 void PushEventHandler(wxEvtHandler* handler);
290 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
291 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
294 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
296 void RemoveChild(wxWindow* child);
297 bool Reparent( wxWindow* newParent );
299 // (uses apply'ed INOUT typemap, see above)
300 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
301 wxPoint ScreenToClient(const wxPoint& pt);
303 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
304 void SetAcceleratorTable(const wxAcceleratorTable& accel);
305 void SetAutoLayout(bool autoLayout);
306 bool GetAutoLayout();
307 void SetBackgroundColour(const wxColour& colour);
308 void SetConstraints(wxLayoutConstraints *constraints);
309 void UnsetConstraints(wxLayoutConstraints *constraints);
312 void SetFont(const wxFont& font);
313 void SetForegroundColour(const wxColour& colour);
315 void SetName(const wxString& name);
316 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
317 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
319 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
321 void SetSize(const wxSize& size) {
325 void SetPosition(const wxPoint& pos) {
329 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
330 self->SetSize(rect, sizeFlags);
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 SetExtraStyle(long exStyle);
341 void SetTitle(const wxString& title);
342 bool Show(bool show);
343 bool TransferDataFromWindow();
344 bool TransferDataToWindow();
346 void WarpPointer(int x, int y);
348 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
349 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
351 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
352 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
354 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
355 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
357 %name(SetToolTipString)void SetToolTip(const wxString &tip);
358 void SetToolTip(wxToolTip *tooltip);
359 wxToolTip* GetToolTip();
361 void SetSizer(wxSizer* sizer);
364 wxValidator* GetValidator();
365 void SetValidator(const wxValidator& validator);
367 void SetDropTarget(wxDropTarget* target);
368 wxDropTarget* GetDropTarget();
369 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
371 wxSize GetBestSize();
373 void SetCaret(wxCaret *caret);
375 %pragma(python) addtoclass = "# replaces broken shadow method
376 def GetCaret(self, *_args, **_kwargs):
377 from misc2 import wxCaretPtr
378 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
379 if val: val = wxCaretPtr(val)
384 // // Properties list
385 // %pragma(python) addtoclass = "
387 // 'size' : ('GetSize', 'SetSize'),
388 // 'enabled' : ('IsEnabled', 'Enable'),
389 // 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
390 // 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
391 // 'children' : ('GetChildren', None),
392 // 'charHeight' : ('GetCharHeight', None),
393 // 'charWidth' : ('GetCharWidth', None),
394 // 'clientSize' : ('GetClientSize', 'SetClientSize'),
395 // 'font' : ('GetFont', 'SetFont'),
396 // 'grandParent' : ('GetGrandParent', None),
397 // 'handle' : ('GetHandle', None),
398 // 'label' : ('GetLabel', 'SetLabel'),
399 // 'name' : ('GetName', 'SetName'),
400 // 'parent' : ('GetParent', None),
401 // 'position' : ('GetPosition', 'SetPosition'),
402 // 'title' : ('GetTitle', 'SetTitle'),
403 // 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
404 // 'visible' : ('IsShown', 'Show'),
405 // 'toolTip' : ('GetToolTip', 'SetToolTip'),
406 // 'sizer' : ('GetSizer', 'SetSizer'),
407 // 'validator' : ('GetValidator', 'SetValidator'),
408 // 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
409 // 'caret' : ('GetCaret', 'SetCaret'),
410 // 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
411 // 'constraints' : ('GetConstraints', 'SetConstraints'),
414 // _prop_list_.update(wxEvtHandler._prop_list_)
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))
436 wxWindow* wxWindow_FindFocus() {
437 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 = wxDefaultPosition,
473 const wxSize& size = wxDefaultSize,
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);
485 //---------------------------------------------------------------------------
487 class wxDialog : public wxPanel {
489 wxDialog(wxWindow* parent,
491 const wxString& title,
492 const wxPoint& pos = wxDefaultPosition,
493 const wxSize& size = wxDefaultSize,
494 long style = wxDEFAULT_DIALOG_STYLE,
495 const char* name = "dialogBox");
497 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
499 void Centre(int direction = wxBOTH);
500 void EndModal(int retCode);
502 void Iconize(bool iconize);
504 void SetModal(bool flag);
506 void SetTitle(const wxString& title);
507 bool Show(bool show);
511 void SetReturnCode(int retCode);
513 wxSizer* CreateTextSizer( const wxString &message );
514 wxSizer* CreateButtonSizer( long flags );
518 //---------------------------------------------------------------------------
520 class wxScrolledWindow : public wxPanel {
522 wxScrolledWindow(wxWindow* parent,
523 const wxWindowID id = -1,
524 const wxPoint& pos = wxDefaultPosition,
525 const wxSize& size = wxDefaultSize,
526 long style = wxHSCROLL | wxVSCROLL,
527 char* name = "scrolledWindow");
529 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
530 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
532 void EnableScrolling(bool xScrolling, bool yScrolling);
533 int GetScrollPageSize(int orient);
534 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
535 wxWindow* GetTargetWindow();
536 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
538 void PrepareDC(wxDC& dc);
539 void Scroll(int x, int y);
540 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
541 int noUnitsX, int noUnitsY,
542 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
543 void SetScrollPageSize(int orient, int pageSize);
544 void SetTargetWindow(wxWindow* window);
545 void GetViewStart(int* OUTPUT, int* OUTPUT);
546 void ViewStart(int* OUTPUT, int* OUTPUT);
548 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
549 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
551 void SetScale(double xs, double ys);
555 void AdjustScrollbars();
558 //----------------------------------------------------------------------
561 class wxMenu : public wxEvtHandler {
563 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
565 void Append(int id, const wxString& item,
566 const wxString& helpString = wxPyEmptyStr,
567 int checkable = FALSE);
568 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
569 const wxString& helpString = wxPyEmptyStr);
570 %name(AppendItem)void Append(const wxMenuItem* item);
572 void AppendSeparator();
574 void Check(int id, bool flag);
575 bool IsChecked(int id);
576 void Enable(int id, bool enable);
577 bool IsEnabled(int id);
579 int FindItem(const wxString& itemString);
580 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
583 void SetTitle(const wxString& title);
585 wxString GetLabel(int id);
586 void SetLabel(int id, const wxString& label);
588 wxString GetHelpString(int id);
589 void SetHelpString(int id, const wxString& helpString);
590 void UpdateUI(wxEvtHandler* source = NULL);
593 %name(DeleteItem)bool Delete(wxMenuItem *item);
594 bool Insert(size_t pos, wxMenuItem *item);
595 wxMenuItem *Remove(int id);
596 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
599 void Destroy() { delete self; }
601 %name(DestroyId)bool Destroy(int id);
602 %name(DestroyItem)bool Destroy(wxMenuItem *item);
604 size_t GetMenuItemCount();
605 //wxMenuItemList& GetMenuItems();
607 PyObject* GetMenuItems() {
608 wxMenuItemList& list = self->GetMenuItems();
609 return wxPy_ConvertList(&list, "wxMenuItem");
613 void SetEventHandler(wxEvtHandler *handler);
614 wxEvtHandler *GetEventHandler();
616 void SetInvokingWindow(wxWindow *win);
617 wxWindow *GetInvokingWindow();
623 void SetParent(wxMenu *parent);
628 //----------------------------------------------------------------------
630 class wxMenuBar : public wxWindow {
632 wxMenuBar(long style = 0);
634 bool Append(wxMenu *menu, const wxString& title);
635 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
636 size_t GetMenuCount();
637 wxMenu *GetMenu(size_t pos);
638 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
639 wxMenu *Remove(size_t pos);
640 void EnableTop(size_t pos, bool enable);
641 void SetLabelTop(size_t pos, const wxString& label);
642 wxString GetLabelTop(size_t pos);
643 int FindMenuItem(const wxString& menuString, const wxString& itemString);
644 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
645 void Enable(int id, bool enable);
646 void Check(int id, bool check);
647 bool IsChecked(int id);
648 bool IsEnabled(int id);
650 void SetLabel(int id, const wxString &label);
651 wxString GetLabel(int id);
653 void SetHelpString(int id, const wxString& helpString);
654 wxString GetHelpString(int id);
659 //----------------------------------------------------------------------
661 class wxMenuItem : public wxObject {
663 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
664 const wxString& text = wxPyEmptyStr,
665 const wxString& help = wxPyEmptyStr,
666 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
673 void SetText(const wxString& str);
675 const wxString& GetText();
676 void SetCheckable(bool checkable);
679 void SetSubMenu(wxMenu *menu);
680 wxMenu *GetSubMenu();
681 void Enable(bool enable = TRUE);
683 void Check(bool check = TRUE);
686 void SetHelp(const wxString& str);
687 const wxString& GetHelp();
688 wxAcceleratorEntry *GetAccel();
689 void SetAccel(wxAcceleratorEntry *accel);
691 static wxString GetLabelFromText(const wxString& text);
693 // wxOwnerDrawn methods
695 void SetFont(const wxFont& font);
697 void SetTextColour(const wxColour& colText);
698 wxColour& GetTextColour();
699 void SetBackgroundColour(const wxColour& colBack);
700 wxColour& GetBackgroundColour();
701 void SetBitmaps(const wxBitmap& bmpChecked,
702 const wxBitmap& bmpUnchecked = wxNullBitmap);
703 void SetBitmap(const wxBitmap& bmpChecked);
704 const wxBitmap& GetBitmap(bool bChecked = TRUE);
705 void SetMarginWidth(int nWidth);
706 int GetMarginWidth();
707 static int GetDefaultMarginWidth();
708 //void SetName(const wxString& strName);
709 //const wxString& GetName();
710 //void SetCheckable(bool checkable);
711 //bool IsCheckable();
713 void ResetOwnerDrawn();
717 //---------------------------------------------------------------------------