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();
216 bool IsBeingDeleted();
218 void DragAcceptFiles(bool accept);
220 void Enable(bool enable);
221 //bool FakePopupMenu(wxMenu* menu, int x, int y);
222 %name(FindWindowById) wxWindow* FindWindow(long id);
223 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
225 wxColour GetBackgroundColour();
227 //wxList& GetChildren();
229 PyObject* GetChildren() {
230 wxWindowList& list = self->GetChildren();
231 return wxPy_ConvertList(&list, "wxWindow");
237 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
238 wxSize GetClientSize();
239 wxLayoutConstraints * GetConstraints();
240 wxEvtHandler* GetEventHandler();
243 wxColour GetForegroundColour();
244 wxWindow * GetGrandParent();
247 return wxPyGetWinHandle(self); //(long)self->GetHandle();
252 void SetLabel(const wxString& label);
254 wxWindow * GetParent();
255 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
256 wxPoint GetPosition();
258 int GetScrollThumb(int orientation);
259 int GetScrollPos(int orientation);
260 int GetScrollRange(int orientation);
261 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
263 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
264 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
265 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
266 const wxFont* font = NULL); //, bool use16 = FALSE)
268 wxRegion GetUpdateRegion();
269 long GetWindowStyleFlag();
270 void SetWindowStyleFlag(long style);
271 void SetWindowStyle(long style);
275 bool IsExposed( int x, int y, int w=0, int h=0 );
276 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
277 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
282 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
284 void MakeModal(bool flag);
285 %name(MoveXY)void Move(int x, int y);
286 void Move(const wxPoint& point);
288 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
289 void PushEventHandler(wxEvtHandler* handler);
291 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
292 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
295 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
297 void RemoveChild(wxWindow* child);
298 bool Reparent( wxWindow* newParent );
300 // (uses apply'ed INOUT typemap, see above)
301 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
302 wxPoint ScreenToClient(const wxPoint& pt);
304 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
305 void SetAcceleratorTable(const wxAcceleratorTable& accel);
306 void SetAutoLayout(bool autoLayout);
307 bool GetAutoLayout();
308 void SetBackgroundColour(const wxColour& colour);
309 void SetConstraints(wxLayoutConstraints *constraints);
310 void UnsetConstraints(wxLayoutConstraints *constraints);
313 void SetFont(const wxFont& font);
314 void SetForegroundColour(const wxColour& colour);
316 void SetName(const wxString& name);
317 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
318 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
320 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
322 void SetSize(const wxSize& size) {
326 void SetPosition(const wxPoint& pos) {
330 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
331 self->SetSize(rect, sizeFlags);
335 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
336 %name(SetClientSizeWH)void SetClientSize(int width, int height);
337 void SetClientSize(const wxSize& size);
338 //void SetPalette(wxPalette* palette);
339 void SetCursor(const wxCursor&cursor);
340 void SetEventHandler(wxEvtHandler* handler);
341 void SetExtraStyle(long exStyle);
342 void SetTitle(const wxString& title);
343 bool Show(bool show);
344 bool TransferDataFromWindow();
345 bool TransferDataToWindow();
347 void WarpPointer(int x, int y);
349 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
350 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
352 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
353 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
355 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
356 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
358 %name(SetToolTipString)void SetToolTip(const wxString &tip);
359 void SetToolTip(wxToolTip *tooltip);
360 wxToolTip* GetToolTip();
362 void SetSizer(wxSizer* sizer);
365 wxValidator* GetValidator();
366 void SetValidator(const wxValidator& validator);
368 void SetDropTarget(wxDropTarget* target);
369 wxDropTarget* GetDropTarget();
370 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
372 wxSize GetBestSize();
374 void SetCaret(wxCaret *caret);
376 %pragma(python) addtoclass = "# replaces broken shadow method
377 def GetCaret(self, *_args, **_kwargs):
378 from misc2 import wxCaretPtr
379 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
380 if val: val = wxCaretPtr(val)
385 // // Properties list
386 // %pragma(python) addtoclass = "
388 // 'size' : ('GetSize', 'SetSize'),
389 // 'enabled' : ('IsEnabled', 'Enable'),
390 // 'background' : ('GetBackgroundColour', 'SetBackgroundColour'),
391 // 'foreground' : ('GetForegroundColour', 'SetForegroundColour'),
392 // 'children' : ('GetChildren', None),
393 // 'charHeight' : ('GetCharHeight', None),
394 // 'charWidth' : ('GetCharWidth', None),
395 // 'clientSize' : ('GetClientSize', 'SetClientSize'),
396 // 'font' : ('GetFont', 'SetFont'),
397 // 'grandParent' : ('GetGrandParent', None),
398 // 'handle' : ('GetHandle', None),
399 // 'label' : ('GetLabel', 'SetLabel'),
400 // 'name' : ('GetName', 'SetName'),
401 // 'parent' : ('GetParent', None),
402 // 'position' : ('GetPosition', 'SetPosition'),
403 // 'title' : ('GetTitle', 'SetTitle'),
404 // 'style' : ('GetWindowStyleFlag', 'SetWindowStyleFlag'),
405 // 'visible' : ('IsShown', 'Show'),
406 // 'toolTip' : ('GetToolTip', 'SetToolTip'),
407 // 'sizer' : ('GetSizer', 'SetSizer'),
408 // 'validator' : ('GetValidator', 'SetValidator'),
409 // 'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
410 // 'caret' : ('GetCaret', 'SetCaret'),
411 // 'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
412 // 'constraints' : ('GetConstraints', 'SetConstraints'),
415 // _prop_list_.update(wxEvtHandler._prop_list_)
422 %pragma(python) code = "
423 def wxDLG_PNT(win, point_or_x, y=None):
425 return win.ConvertDialogPointToPixels(point_or_x)
427 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
429 def wxDLG_SZE(win, size_width, height=None):
431 return win.ConvertDialogSizeToPixels(size_width)
433 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
437 wxWindow* wxWindow_FindFocus() {
438 return wxWindow::FindFocus();
445 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
446 wxWindow* win = new wxWindow;
448 win->SubclassWin(hWnd);
455 int wxWindow_NewControlId() {
456 return wxWindow::NewControlId();
458 int wxWindow_NextControlId(int id) {
459 return wxWindow::NextControlId(id);
461 int wxWindow_PrevControlId(int id) {
462 return wxWindow::PrevControlId(id);
467 //---------------------------------------------------------------------------
469 class wxPanel : public wxWindow {
471 wxPanel(wxWindow* parent,
473 const wxPoint& pos = wxDefaultPosition,
474 const wxSize& size = wxDefaultSize,
475 long style = wxTAB_TRAVERSAL,
476 const char* name = "panel");
478 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
481 wxButton* GetDefaultItem();
482 void SetDefaultItem(wxButton *btn);
486 //---------------------------------------------------------------------------
488 class wxDialog : public wxPanel {
490 wxDialog(wxWindow* parent,
492 const wxString& title,
493 const wxPoint& pos = wxDefaultPosition,
494 const wxSize& size = wxDefaultSize,
495 long style = wxDEFAULT_DIALOG_STYLE,
496 const char* name = "dialogBox");
498 %pragma(python) addtomethod = "__init__:#wx._StdDialogCallbacks(self)"
500 void Centre(int direction = wxBOTH);
501 void EndModal(int retCode);
503 void Iconize(bool iconize);
505 void SetModal(bool flag);
507 void SetTitle(const wxString& title);
508 bool Show(bool show);
512 void SetReturnCode(int retCode);
514 wxSizer* CreateTextSizer( const wxString &message );
515 wxSizer* CreateButtonSizer( long flags );
519 //---------------------------------------------------------------------------
521 class wxScrolledWindow : public wxPanel {
523 wxScrolledWindow(wxWindow* parent,
524 const wxWindowID id = -1,
525 const wxPoint& pos = wxDefaultPosition,
526 const wxSize& size = wxDefaultSize,
527 long style = wxHSCROLL | wxVSCROLL,
528 char* name = "scrolledWindow");
530 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
531 %pragma(python) addtomethod = "__init__:#wx._StdOnScrollCallbacks(self)"
533 void EnableScrolling(bool xScrolling, bool yScrolling);
534 int GetScrollPageSize(int orient);
535 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
536 wxWindow* GetTargetWindow();
537 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
539 void PrepareDC(wxDC& dc);
540 void Scroll(int x, int y);
541 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
542 int noUnitsX, int noUnitsY,
543 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
544 void SetScrollPageSize(int orient, int pageSize);
545 void SetTargetWindow(wxWindow* window);
546 void GetViewStart(int* OUTPUT, int* OUTPUT);
547 void ViewStart(int* OUTPUT, int* OUTPUT);
549 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
550 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
552 void SetScale(double xs, double ys);
556 void AdjustScrollbars();
559 //----------------------------------------------------------------------
562 class wxMenu : public wxEvtHandler {
564 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
566 void Append(int id, const wxString& item,
567 const wxString& helpString = wxPyEmptyStr,
568 int checkable = FALSE);
569 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
570 const wxString& helpString = wxPyEmptyStr);
571 %name(AppendItem)void Append(const wxMenuItem* item);
573 void AppendSeparator();
575 void Check(int id, bool flag);
576 bool IsChecked(int id);
577 void Enable(int id, bool enable);
578 bool IsEnabled(int id);
580 int FindItem(const wxString& itemString);
581 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
584 void SetTitle(const wxString& title);
586 wxString GetLabel(int id);
587 void SetLabel(int id, const wxString& label);
589 wxString GetHelpString(int id);
590 void SetHelpString(int id, const wxString& helpString);
591 void UpdateUI(wxEvtHandler* source = NULL);
594 %name(DeleteItem)bool Delete(wxMenuItem *item);
595 bool Insert(size_t pos, wxMenuItem *item);
596 wxMenuItem *Remove(int id);
597 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
600 void Destroy() { delete self; }
602 %name(DestroyId)bool Destroy(int id);
603 %name(DestroyItem)bool Destroy(wxMenuItem *item);
605 size_t GetMenuItemCount();
606 //wxMenuItemList& GetMenuItems();
608 PyObject* GetMenuItems() {
609 wxMenuItemList& list = self->GetMenuItems();
610 return wxPy_ConvertList(&list, "wxMenuItem");
614 void SetEventHandler(wxEvtHandler *handler);
615 wxEvtHandler *GetEventHandler();
617 void SetInvokingWindow(wxWindow *win);
618 wxWindow *GetInvokingWindow();
624 void SetParent(wxMenu *parent);
629 //----------------------------------------------------------------------
631 class wxMenuBar : public wxWindow {
633 wxMenuBar(long style = 0);
635 bool Append(wxMenu *menu, const wxString& title);
636 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
637 size_t GetMenuCount();
638 wxMenu *GetMenu(size_t pos);
639 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
640 wxMenu *Remove(size_t pos);
641 void EnableTop(size_t pos, bool enable);
642 void SetLabelTop(size_t pos, const wxString& label);
643 wxString GetLabelTop(size_t pos);
644 int FindMenuItem(const wxString& menuString, const wxString& itemString);
645 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
646 void Enable(int id, bool enable);
647 void Check(int id, bool check);
648 bool IsChecked(int id);
649 bool IsEnabled(int id);
651 void SetLabel(int id, const wxString &label);
652 wxString GetLabel(int id);
654 void SetHelpString(int id, const wxString& helpString);
655 wxString GetHelpString(int id);
660 //----------------------------------------------------------------------
662 class wxMenuItem : public wxObject {
664 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
665 const wxString& text = wxPyEmptyStr,
666 const wxString& help = wxPyEmptyStr,
667 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
674 void SetText(const wxString& str);
676 const wxString& GetText();
677 void SetCheckable(bool checkable);
680 void SetSubMenu(wxMenu *menu);
681 wxMenu *GetSubMenu();
682 void Enable(bool enable = TRUE);
684 void Check(bool check = TRUE);
687 void SetHelp(const wxString& str);
688 const wxString& GetHelp();
689 wxAcceleratorEntry *GetAccel();
690 void SetAccel(wxAcceleratorEntry *accel);
692 static wxString GetLabelFromText(const wxString& text);
694 // wxOwnerDrawn methods
696 void SetFont(const wxFont& font);
698 void SetTextColour(const wxColour& colText);
699 wxColour GetTextColour();
700 void SetBackgroundColour(const wxColour& colBack);
701 wxColour GetBackgroundColour();
702 void SetBitmaps(const wxBitmap& bmpChecked,
703 const wxBitmap& bmpUnchecked = wxNullBitmap);
704 void SetBitmap(const wxBitmap& bmpChecked);
705 const wxBitmap& GetBitmap(bool bChecked = TRUE);
706 void SetMarginWidth(int nWidth);
707 int GetMarginWidth();
708 static int GetDefaultMarginWidth();
709 //void SetName(const wxString& strName);
710 //const wxString& GetName();
711 //void SetCheckable(bool checkable);
712 //bool IsCheckable();
714 void ResetOwnerDrawn();
718 //---------------------------------------------------------------------------