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"
36 //---------------------------------------------------------------------------
38 class wxEvtHandler : public wxObject {
42 bool ProcessEvent(wxEvent& event);
43 void AddPendingEvent(wxEvent& event);
44 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
46 bool GetEvtHandlerEnabled();
47 void SetEvtHandlerEnabled(bool enabled);
49 wxEvtHandler* GetNextHandler();
50 wxEvtHandler* GetPreviousHandler();
51 void SetNextHandler(wxEvtHandler* handler);
52 void SetPreviousHandler(wxEvtHandler* handler);
56 void Connect( int id, int lastId, int eventType, PyObject* func) {
57 if (PyCallable_Check(func)) {
58 self->Connect(id, lastId, eventType,
59 (wxObjectEventFunction) &wxPyCallback::EventThunker,
60 new wxPyCallback(func));
62 else if (func == Py_None) {
63 self->Disconnect(id, lastId, eventType,
64 (wxObjectEventFunction)
65 &wxPyCallback::EventThunker);
68 PyErr_SetString(PyExc_TypeError, "Expected callable object or None.");
72 bool Disconnect(int id, int lastId = -1,
73 wxEventType eventType = wxEVT_NULL) {
74 return self->Disconnect(id, lastId, eventType,
75 (wxObjectEventFunction)
76 &wxPyCallback::EventThunker);
81 void _setOORInfo(PyObject* _self) {
82 self->SetClientObject(new wxPyClientData(_self));
88 //----------------------------------------------------------------------
90 class wxValidator : public wxEvtHandler {
95 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
98 wxWindow* GetWindow();
99 void SetWindow(wxWindow* window);
101 static bool IsSilent();
102 static void SetBellOnError(int doIt = TRUE);
107 //----------------------------------------------------------------------
109 class wxPyValidator : public wxValidator {
110 DECLARE_DYNAMIC_CLASS(wxPyValidator);
118 wxObject* Clone() const {
119 wxPyValidator* ptr = NULL;
120 wxPyValidator* self = (wxPyValidator*)this;
122 wxPyBeginBlockThreads();
123 if (self->m_myInst.findCallback("Clone")) {
125 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
127 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
131 wxPyEndBlockThreads();
133 // This is very dangerous!!! But is the only way I could find
134 // to squash a memory leak. Currently it is okay, but if the
135 // validator architecture in wxWindows ever changes, problems
142 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
143 DEC_PYCALLBACK_BOOL_(TransferToWindow);
144 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
149 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
150 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
151 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
153 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
157 class wxPyValidator : public wxValidator {
161 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=TRUE);
162 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyValidator, 1)"
164 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
167 //----------------------------------------------------------------------
169 %apply int * INOUT { int* x, int* y };
171 class wxWindow : public wxEvtHandler {
173 wxWindow(wxWindow* parent, const wxWindowID id,
174 const wxPoint& pos = wxDefaultPosition,
175 const wxSize& size = wxDefaultSize,
177 char* name = "panel");
178 %name(wxPreWindow)wxWindow();
180 bool Create(wxWindow* parent, const wxWindowID id,
181 const wxPoint& pos = wxDefaultPosition,
182 const wxSize& size = wxDefaultSize,
184 char* name = "panel");
186 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
187 %pragma(python) addtomethod = "wxPreWindow:val._setOORInfo(val)"
191 void Center(int direction = wxBOTH);
192 void Centre(int direction = wxBOTH);
193 void CentreOnParent(int direction = wxBOTH );
194 void CenterOnParent(int direction = wxBOTH );
195 void CentreOnScreen(int direction = wxBOTH );
196 void CenterOnScreen(int direction = wxBOTH );
200 // (uses apply'ed INOUT typemap, see above)
201 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
202 wxPoint ClientToScreen(const wxPoint& pt);
204 bool Close(int force = FALSE);
206 void DestroyChildren();
207 bool IsBeingDeleted();
209 void DragAcceptFiles(bool accept);
211 void Enable(bool enable);
212 //bool FakePopupMenu(wxMenu* menu, int x, int y);
213 %name(FindWindowById) wxWindow* FindWindow(long id);
214 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
216 wxColour GetBackgroundColour();
217 wxBorder GetBorder() const;
219 //wxList& GetChildren();
221 PyObject* GetChildren() {
222 wxWindowList& list = self->GetChildren();
223 return wxPy_ConvertList(&list, "wxWindow");
229 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
230 wxSize GetClientSize();
232 // get the origin of the client area of the window relative to the
233 // window top left corner (the client area may be shifted because of
234 // the borders, scrollbars, other decorations...)
235 wxPoint GetClientAreaOrigin() const;
237 // get the client rectangle in window (i.e. client) coordinates
238 wxRect GetClientRect() const;
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);
273 bool HasScrollbar(int orient) const;
275 wxHitTest HitTest(const wxPoint& pt);
278 bool IsExposed( int x, int y, int w=0, int h=0 );
279 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
280 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
285 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
287 void MakeModal(bool flag=TRUE);
288 %name(MoveXY)void Move(int x, int y, int flags = wxSIZE_USE_EXISTING);
289 void Move(const wxPoint& point, int flags = wxSIZE_USE_EXISTING);
291 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
292 void PushEventHandler(wxEvtHandler* handler);
294 // find the given handler in the event handler chain and remove (but
295 // not delete) it from the event handler chain, return TRUE if it was
296 // found and FALSE otherwise (this also results in an assert failure so
297 // this function should only be called when the handler is supposed to
299 bool RemoveEventHandler(wxEvtHandler *handler);
301 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
302 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
305 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
306 void RefreshRect(const wxRect& rect);
309 void RemoveChild(wxWindow* child);
310 bool Reparent( wxWindow* newParent );
312 // (uses apply'ed INOUT typemap, see above)
313 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
314 wxPoint ScreenToClient(const wxPoint& pt);
316 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
317 void SetAutoLayout(bool autoLayout);
318 bool GetAutoLayout();
319 void SetBackgroundColour(const wxColour& colour);
320 void SetConstraints(wxLayoutConstraints *constraints);
321 void UnsetConstraints(wxLayoutConstraints *constraints);
324 void SetFont(const wxFont& font);
325 void SetForegroundColour(const wxColour& colour);
327 void SetName(const wxString& name);
328 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
329 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
331 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
333 void SetSize(const wxSize& size) {
337 void SetPosition(const wxPoint& pos, int flags = wxSIZE_USE_EXISTING) {
338 self->Move(pos, flags);
341 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
342 self->SetSize(rect, sizeFlags);
346 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
347 %name(SetClientSizeWH)void SetClientSize(int width, int height);
348 void SetClientSize(const wxSize& size);
349 //void SetPalette(wxPalette* palette);
350 void SetCursor(const wxCursor& cursor);
351 void SetEventHandler(wxEvtHandler* handler);
352 void SetExtraStyle(long exStyle);
353 void SetTitle(const wxString& title);
354 bool Show(bool show=TRUE);
355 bool TransferDataFromWindow();
356 bool TransferDataToWindow();
357 void UpdateWindowUI();
359 void WarpPointer(int x, int y);
361 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
362 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
364 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
365 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
367 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
368 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
370 %name(SetToolTipString)void SetToolTip(const wxString &tip);
371 void SetToolTip(wxToolTip *tooltip);
372 wxToolTip* GetToolTip();
374 void SetSizer(wxSizer* sizer, bool deleteOld=TRUE);
377 // Track if this window is a member of a sizer
378 void SetContainingSizer(wxSizer* sizer);
379 wxSizer *GetContainingSizer() const;
381 wxValidator* GetValidator();
382 void SetValidator(const wxValidator& validator);
385 void SetDropTarget(wxDropTarget* target);
386 wxDropTarget* GetDropTarget();
387 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
390 wxSize GetBestSize();
393 void SetCaret(wxCaret *caret);
395 %pragma(python) addtoclass = "# replaces broken shadow method
396 def GetCaret(self, *_args, **_kwargs):
397 from misc2 import wxCaretPtr
398 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
399 if val: val = wxCaretPtr(val)
407 wxString GetHelpText();
408 void SetHelpText(const wxString& helpText);
409 void SetHelpTextForId(const wxString& text);
411 bool ScrollLines(int lines);
412 bool ScrollPages(int pages);
418 static wxWindow* FindFocus();
419 static int NewControlId();
420 static int NextControlId(int id);
421 static int PrevControlId(int id);
423 void SetAcceleratorTable(const wxAcceleratorTable& accel);
424 wxAcceleratorTable *GetAcceleratorTable();
427 // A way to do the native draw first... Too bad it isn't in wxGTK too.
428 void OnPaint(wxPaintEvent& event);
431 wxWindow* GetDefaultItem();
432 wxWindow* SetDefaultItem(wxWindow *btn);
438 %pragma(python) code = "
439 def wxDLG_PNT(win, point_or_x, y=None):
441 return win.ConvertDialogPointToPixels(point_or_x)
443 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
445 def wxDLG_SZE(win, size_width, height=None):
447 return win.ConvertDialogSizeToPixels(size_width)
449 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
455 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
456 wxWindow* win = new wxWindow;
458 win->SubclassWin(hWnd);
465 //---------------------------------------------------------------------------
467 class wxPanel : public wxWindow {
469 wxPanel(wxWindow* parent,
471 const wxPoint& pos = wxDefaultPosition,
472 const wxSize& size = wxDefaultSize,
473 long style = wxTAB_TRAVERSAL,
474 const char* name = "panel");
475 %name(wxPrePanel)wxPanel();
477 bool Create(wxWindow* parent,
479 const wxPoint& pos = wxDefaultPosition,
480 const wxSize& size = wxDefaultSize,
481 long style = wxTAB_TRAVERSAL,
482 const char* name = "panel");
484 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
485 %pragma(python) addtomethod = "wxPrePanel:val._setOORInfo(val)"
491 //---------------------------------------------------------------------------
494 // TODO: Add wrappers for the wxScrollHelper class, make wxScrolledWindow
495 // derive from it and wxPanel.
498 class wxScrolledWindow : public wxPanel {
500 wxScrolledWindow(wxWindow* parent,
501 const wxWindowID id = -1,
502 const wxPoint& pos = wxDefaultPosition,
503 const wxSize& size = wxDefaultSize,
504 long style = wxHSCROLL | wxVSCROLL,
505 char* name = "scrolledWindow");
506 %name(wxPreScrolledWindow)wxScrolledWindow();
508 bool Create(wxWindow* parent,
509 const wxWindowID id = -1,
510 const wxPoint& pos = wxDefaultPosition,
511 const wxSize& size = wxDefaultSize,
512 long style = wxHSCROLL | wxVSCROLL,
513 char* name = "scrolledWindow");
515 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
516 %pragma(python) addtomethod = "wxPreScrolledWindow:val._setOORInfo(val)"
518 void EnableScrolling(bool xScrolling, bool yScrolling);
519 int GetScrollPageSize(int orient);
520 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
521 wxWindow* GetTargetWindow();
522 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
524 void PrepareDC(wxDC& dc);
525 void Scroll(int x, int y);
526 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
527 int noUnitsX, int noUnitsY,
528 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
529 void SetScrollPageSize(int orient, int pageSize);
530 void SetTargetWindow(wxWindow* window);
531 void GetViewStart(int* OUTPUT, int* OUTPUT);
532 %pragma(python) addtoclass = "ViewStart = GetViewStart"
534 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
535 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
537 void SetScale(double xs, double ys);
541 void AdjustScrollbars();
546 //----------------------------------------------------------------------
549 class wxMenu : public wxEvtHandler {
551 wxMenu(const wxString& title = wxEmptyString, long style = 0);
553 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
555 void Append(int id, const wxString& item,
556 const wxString& helpString = wxEmptyString,
557 int checkable = FALSE);
558 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
559 const wxString& helpString = wxEmptyString);
560 %name(AppendItem)void Append(const wxMenuItem* item);
562 void AppendSeparator();
564 void Check(int id, bool flag);
565 bool IsChecked(int id);
566 void Enable(int id, bool enable);
567 bool IsEnabled(int id);
569 int FindItem(const wxString& itemString);
570 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
573 void SetTitle(const wxString& title);
575 wxString GetLabel(int id);
576 void SetLabel(int id, const wxString& label);
578 wxString GetHelpString(int id);
579 void SetHelpString(int id, const wxString& helpString);
580 void UpdateUI(wxEvtHandler* source = NULL);
583 %name(DeleteItem)bool Delete(wxMenuItem *item);
584 bool Insert(size_t pos, wxMenuItem *item);
585 wxMenuItem *Remove(int id);
586 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
589 void Destroy() { delete self; }
591 %name(DestroyId)bool Destroy(int id);
592 %name(DestroyItem)bool Destroy(wxMenuItem *item);
594 size_t GetMenuItemCount();
595 //wxMenuItemList& GetMenuItems();
597 PyObject* GetMenuItems() {
598 wxMenuItemList& list = self->GetMenuItems();
599 return wxPy_ConvertList(&list, "wxMenuItem");
603 void SetEventHandler(wxEvtHandler *handler);
604 wxEvtHandler *GetEventHandler();
606 void SetInvokingWindow(wxWindow *win);
607 wxWindow *GetInvokingWindow();
613 void SetParent(wxMenu *parent);
618 //----------------------------------------------------------------------
620 class wxMenuBar : public wxWindow {
622 wxMenuBar(long style = 0);
624 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
626 bool Append(wxMenu *menu, const wxString& title);
627 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
628 size_t GetMenuCount();
629 wxMenu *GetMenu(size_t pos);
630 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
631 wxMenu *Remove(size_t pos);
632 void EnableTop(size_t pos, bool enable);
633 void SetLabelTop(size_t pos, const wxString& label);
634 wxString GetLabelTop(size_t pos);
635 int FindMenu(const wxString& title);
636 int FindMenuItem(const wxString& menuString, const wxString& itemString);
637 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
638 void Enable(int id, bool enable);
639 void Check(int id, bool check);
640 bool IsChecked(int id);
641 bool IsEnabled(int id);
643 void SetLabel(int id, const wxString &label);
644 wxString GetLabel(int id);
646 void SetHelpString(int id, const wxString& helpString);
647 wxString GetHelpString(int id);
652 //----------------------------------------------------------------------
654 class wxMenuItem : public wxObject {
656 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
657 const wxString& text = wxEmptyString,
658 const wxString& help = wxEmptyString,
659 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
666 void SetText(const wxString& str);
668 const wxString& GetText();
669 void SetCheckable(bool checkable);
672 void SetSubMenu(wxMenu *menu);
673 wxMenu *GetSubMenu();
674 void Enable(bool enable = TRUE);
676 void Check(bool check = TRUE);
679 void SetHelp(const wxString& str);
680 const wxString& GetHelp();
681 wxAcceleratorEntry *GetAccel();
682 void SetAccel(wxAcceleratorEntry *accel);
684 static wxString GetLabelFromText(const wxString& text);
686 // wxOwnerDrawn methods
688 void SetFont(const wxFont& font);
690 void SetTextColour(const wxColour& colText);
691 wxColour GetTextColour();
692 void SetBackgroundColour(const wxColour& colBack);
693 wxColour GetBackgroundColour();
694 void SetBitmaps(const wxBitmap& bmpChecked,
695 const wxBitmap& bmpUnchecked = wxNullBitmap);
696 void SetBitmap(const wxBitmap& bmpChecked);
697 wxBitmap GetBitmap(bool bChecked = TRUE);
698 void SetMarginWidth(int nWidth);
699 int GetMarginWidth();
700 static int GetDefaultMarginWidth();
701 //void SetName(const wxString& strName);
702 //const wxString& GetName();
703 //void SetCheckable(bool checkable);
704 //bool IsCheckable();
706 void ResetOwnerDrawn();
710 //---------------------------------------------------------------------------