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));
66 else if (func == Py_None) {
67 self->Disconnect(id, lastId, eventType,
68 (wxObjectEventFunction)
69 &wxPyCallback::EventThunker);
72 PyErr_SetString(PyExc_TypeError, "Expected callable object or None.");
76 bool Disconnect(int id, int lastId = -1,
77 wxEventType eventType = wxEVT_NULL) {
78 return self->Disconnect(id, lastId, eventType,
79 (wxObjectEventFunction)
80 &wxPyCallback::EventThunker);
85 void _setOORInfo(PyObject* _self) {
86 self->SetClientObject(new wxPyClientData(_self));
92 //----------------------------------------------------------------------
94 class wxValidator : public wxEvtHandler {
99 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
101 wxValidator* Clone();
102 wxWindow* GetWindow();
103 void SetWindow(wxWindow* window);
105 static bool IsSilent();
106 static void SetBellOnError(int doIt = TRUE);
111 //----------------------------------------------------------------------
113 class wxPyValidator : public wxValidator {
114 DECLARE_DYNAMIC_CLASS(wxPyValidator);
122 wxObject* Clone() const {
123 wxPyValidator* ptr = NULL;
124 wxPyValidator* self = (wxPyValidator*)this;
126 wxPyBeginBlockThreads();
127 if (self->m_myInst.findCallback("Clone")) {
129 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
131 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
135 wxPyEndBlockThreads();
137 // This is very dangerous!!! But is the only way I could find
138 // to squash a memory leak. Currently it is okay, but if the
139 // validator architecture in wxWindows ever changes, problems
146 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
147 DEC_PYCALLBACK_BOOL_(TransferToWindow);
148 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
153 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
154 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
155 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
157 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
161 class wxPyValidator : public wxValidator {
165 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=TRUE);
166 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyValidator, 1)"
168 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
171 //----------------------------------------------------------------------
173 %apply int * INOUT { int* x, int* y };
175 class wxWindow : public wxEvtHandler {
177 wxWindow(wxWindow* parent, const wxWindowID id,
178 const wxPoint& pos = wxDefaultPosition,
179 const wxSize& size = wxDefaultSize,
181 char* name = "panel");
182 %name(wxPreWindow)wxWindow();
184 bool Create(wxWindow* parent, const wxWindowID id,
185 const wxPoint& pos = wxDefaultPosition,
186 const wxSize& size = wxDefaultSize,
188 char* name = "panel");
190 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
191 %pragma(python) addtomethod = "wxPreWindow:val._setOORInfo(val)"
195 void Center(int direction = wxBOTH);
196 void Centre(int direction = wxBOTH);
197 void CentreOnParent(int direction = wxBOTH );
198 void CenterOnParent(int direction = wxBOTH );
199 void CentreOnScreen(int direction = wxBOTH );
200 void CenterOnScreen(int direction = wxBOTH );
204 // (uses apply'ed INOUT typemap, see above)
205 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
206 wxPoint ClientToScreen(const wxPoint& pt);
208 bool Close(int force = FALSE);
210 void DestroyChildren();
211 bool IsBeingDeleted();
213 void DragAcceptFiles(bool accept);
215 void Enable(bool enable);
216 //bool FakePopupMenu(wxMenu* menu, int x, int y);
217 %name(FindWindowById) wxWindow* FindWindow(long id);
218 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
220 wxColour GetBackgroundColour();
222 //wxList& GetChildren();
224 PyObject* GetChildren() {
225 wxWindowList& list = self->GetChildren();
226 return wxPy_ConvertList(&list, "wxWindow");
232 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
233 wxSize GetClientSize();
234 wxLayoutConstraints * GetConstraints();
235 wxEvtHandler* GetEventHandler();
238 wxColour GetForegroundColour();
239 wxWindow * GetGrandParent();
242 return wxPyGetWinHandle(self); //(long)self->GetHandle();
247 void SetLabel(const wxString& label);
249 wxWindow * GetParent();
250 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
251 wxPoint GetPosition();
253 int GetScrollThumb(int orientation);
254 int GetScrollPos(int orientation);
255 int GetScrollRange(int orientation);
256 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
258 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
259 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
260 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
261 const wxFont* font = NULL); //, bool use16 = FALSE)
263 wxRegion GetUpdateRegion();
264 long GetWindowStyleFlag();
265 void SetWindowStyleFlag(long style);
266 void SetWindowStyle(long style);
270 bool IsExposed( int x, int y, int w=0, int h=0 );
271 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
272 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
277 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
279 void MakeModal(bool flag=TRUE);
280 %name(MoveXY)void Move(int x, int y);
281 void Move(const wxPoint& point);
283 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
284 void PushEventHandler(wxEvtHandler* handler);
286 // find the given handler in the event handler chain and remove (but
287 // not delete) it from the event handler chain, return TRUE if it was
288 // found and FALSE otherwise (this also results in an assert failure so
289 // this function should only be called when the handler is supposed to
291 bool RemoveEventHandler(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);
298 void RefreshRect(const wxRect& rect);
301 void RemoveChild(wxWindow* child);
302 bool Reparent( wxWindow* newParent );
304 // (uses apply'ed INOUT typemap, see above)
305 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
306 wxPoint ScreenToClient(const wxPoint& pt);
308 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
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) {
333 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
334 self->SetSize(rect, sizeFlags);
338 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
339 %name(SetClientSizeWH)void SetClientSize(int width, int height);
340 void SetClientSize(const wxSize& size);
341 //void SetPalette(wxPalette* palette);
342 void SetCursor(const wxCursor& cursor);
343 void SetEventHandler(wxEvtHandler* handler);
344 void SetExtraStyle(long exStyle);
345 void SetTitle(const wxString& title);
346 bool Show(bool show=TRUE);
347 bool TransferDataFromWindow();
348 bool TransferDataToWindow();
350 void WarpPointer(int x, int y);
352 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
353 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
355 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
356 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
358 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
359 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
361 %name(SetToolTipString)void SetToolTip(const wxString &tip);
362 void SetToolTip(wxToolTip *tooltip);
363 wxToolTip* GetToolTip();
365 void SetSizer(wxSizer* sizer);
368 wxValidator* GetValidator();
369 void SetValidator(const wxValidator& validator);
372 void SetDropTarget(wxDropTarget* target);
373 wxDropTarget* GetDropTarget();
374 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
377 wxSize GetBestSize();
379 void SetCaret(wxCaret *caret);
381 %pragma(python) addtoclass = "# replaces broken shadow method
382 def GetCaret(self, *_args, **_kwargs):
383 from misc2 import wxCaretPtr
384 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
385 if val: val = wxCaretPtr(val)
393 wxString GetHelpText();
394 void SetHelpText(const wxString& helpText);
396 bool ScrollLines(int lines);
397 bool ScrollPages(int pages);
403 static wxWindow* FindFocus();
404 static int NewControlId();
405 static int NextControlId(int id);
406 static int PrevControlId(int id);
408 void SetAcceleratorTable(const wxAcceleratorTable& accel);
409 wxAcceleratorTable *GetAcceleratorTable();
412 // A way to do the native draw first... Too bad it isn't in wxGTK too.
413 void OnPaint(wxPaintEvent& event);
416 wxButton* GetDefaultItem();
417 void SetDefaultItem(wxButton *btn);
423 %pragma(python) code = "
424 def wxDLG_PNT(win, point_or_x, y=None):
426 return win.ConvertDialogPointToPixels(point_or_x)
428 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
430 def wxDLG_SZE(win, size_width, height=None):
432 return win.ConvertDialogSizeToPixels(size_width)
434 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
440 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
441 wxWindow* win = new wxWindow;
443 win->SubclassWin(hWnd);
450 //---------------------------------------------------------------------------
452 class wxPanel : public wxWindow {
454 wxPanel(wxWindow* parent,
456 const wxPoint& pos = wxDefaultPosition,
457 const wxSize& size = wxDefaultSize,
458 long style = wxTAB_TRAVERSAL,
459 const char* name = "panel");
460 %name(wxPrePanel)wxPanel();
462 bool Create(wxWindow* parent,
464 const wxPoint& pos = wxDefaultPosition,
465 const wxSize& size = wxDefaultSize,
466 long style = wxTAB_TRAVERSAL,
467 const char* name = "panel");
469 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
470 %pragma(python) addtomethod = "wxPrePanel:val._setOORInfo(val)"
476 //---------------------------------------------------------------------------
479 // TODO: Add wrappers for the wxScrollHelper class, make wxScrolledWindow
480 // derive from it and wxPanel.
483 class wxScrolledWindow : public wxPanel {
485 wxScrolledWindow(wxWindow* parent,
486 const wxWindowID id = -1,
487 const wxPoint& pos = wxDefaultPosition,
488 const wxSize& size = wxDefaultSize,
489 long style = wxHSCROLL | wxVSCROLL,
490 char* name = "scrolledWindow");
491 %name(wxPreScrolledWindow)wxScrolledWindow();
493 bool Create(wxWindow* parent,
494 const wxWindowID id = -1,
495 const wxPoint& pos = wxDefaultPosition,
496 const wxSize& size = wxDefaultSize,
497 long style = wxHSCROLL | wxVSCROLL,
498 char* name = "scrolledWindow");
500 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
501 %pragma(python) addtomethod = "wxPreScrolledWindow:val._setOORInfo(val)"
503 void EnableScrolling(bool xScrolling, bool yScrolling);
504 int GetScrollPageSize(int orient);
505 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
506 wxWindow* GetTargetWindow();
507 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
509 void PrepareDC(wxDC& dc);
510 void Scroll(int x, int y);
511 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
512 int noUnitsX, int noUnitsY,
513 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
514 void SetScrollPageSize(int orient, int pageSize);
515 void SetTargetWindow(wxWindow* window);
516 void GetViewStart(int* OUTPUT, int* OUTPUT);
517 %pragma(python) addtoclass = "ViewStart = GetViewStart"
519 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
520 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
522 void SetScale(double xs, double ys);
526 void AdjustScrollbars();
529 //----------------------------------------------------------------------
532 class wxMenu : public wxEvtHandler {
534 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
536 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
538 void Append(int id, const wxString& item,
539 const wxString& helpString = wxPyEmptyStr,
540 int checkable = FALSE);
541 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
542 const wxString& helpString = wxPyEmptyStr);
543 %name(AppendItem)void Append(const wxMenuItem* item);
545 void AppendSeparator();
547 void Check(int id, bool flag);
548 bool IsChecked(int id);
549 void Enable(int id, bool enable);
550 bool IsEnabled(int id);
552 int FindItem(const wxString& itemString);
553 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
556 void SetTitle(const wxString& title);
558 wxString GetLabel(int id);
559 void SetLabel(int id, const wxString& label);
561 wxString GetHelpString(int id);
562 void SetHelpString(int id, const wxString& helpString);
563 void UpdateUI(wxEvtHandler* source = NULL);
566 %name(DeleteItem)bool Delete(wxMenuItem *item);
567 bool Insert(size_t pos, wxMenuItem *item);
568 wxMenuItem *Remove(int id);
569 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
572 void Destroy() { delete self; }
574 %name(DestroyId)bool Destroy(int id);
575 %name(DestroyItem)bool Destroy(wxMenuItem *item);
577 size_t GetMenuItemCount();
578 //wxMenuItemList& GetMenuItems();
580 PyObject* GetMenuItems() {
581 wxMenuItemList& list = self->GetMenuItems();
582 return wxPy_ConvertList(&list, "wxMenuItem");
586 void SetEventHandler(wxEvtHandler *handler);
587 wxEvtHandler *GetEventHandler();
589 void SetInvokingWindow(wxWindow *win);
590 wxWindow *GetInvokingWindow();
596 void SetParent(wxMenu *parent);
601 //----------------------------------------------------------------------
603 class wxMenuBar : public wxWindow {
605 wxMenuBar(long style = 0);
607 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
609 bool Append(wxMenu *menu, const wxString& title);
610 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
611 size_t GetMenuCount();
612 wxMenu *GetMenu(size_t pos);
613 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
614 wxMenu *Remove(size_t pos);
615 void EnableTop(size_t pos, bool enable);
616 void SetLabelTop(size_t pos, const wxString& label);
617 wxString GetLabelTop(size_t pos);
618 int FindMenu(const wxString& title);
619 int FindMenuItem(const wxString& menuString, const wxString& itemString);
620 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
621 void Enable(int id, bool enable);
622 void Check(int id, bool check);
623 bool IsChecked(int id);
624 bool IsEnabled(int id);
626 void SetLabel(int id, const wxString &label);
627 wxString GetLabel(int id);
629 void SetHelpString(int id, const wxString& helpString);
630 wxString GetHelpString(int id);
635 //----------------------------------------------------------------------
637 class wxMenuItem : public wxObject {
639 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
640 const wxString& text = wxPyEmptyStr,
641 const wxString& help = wxPyEmptyStr,
642 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
649 void SetText(const wxString& str);
651 const wxString& GetText();
652 void SetCheckable(bool checkable);
655 void SetSubMenu(wxMenu *menu);
656 wxMenu *GetSubMenu();
657 void Enable(bool enable = TRUE);
659 void Check(bool check = TRUE);
662 void SetHelp(const wxString& str);
663 const wxString& GetHelp();
664 wxAcceleratorEntry *GetAccel();
665 void SetAccel(wxAcceleratorEntry *accel);
667 static wxString GetLabelFromText(const wxString& text);
669 // wxOwnerDrawn methods
671 void SetFont(const wxFont& font);
673 void SetTextColour(const wxColour& colText);
674 wxColour GetTextColour();
675 void SetBackgroundColour(const wxColour& colBack);
676 wxColour GetBackgroundColour();
677 void SetBitmaps(const wxBitmap& bmpChecked,
678 const wxBitmap& bmpUnchecked = wxNullBitmap);
679 void SetBitmap(const wxBitmap& bmpChecked);
680 wxBitmap GetBitmap(bool bChecked = TRUE);
681 void SetMarginWidth(int nWidth);
682 int GetMarginWidth();
683 static int GetDefaultMarginWidth();
684 //void SetName(const wxString& strName);
685 //const wxString& GetName();
686 //void SetCheckable(bool checkable);
687 //bool IsCheckable();
689 void ResetOwnerDrawn();
693 //---------------------------------------------------------------------------