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);
77 void _setOORInfo(PyObject* _self) {
78 self->SetClientObject(new wxPyClientData(_self));
84 //----------------------------------------------------------------------
86 class wxValidator : public wxEvtHandler {
91 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
94 wxWindow* GetWindow();
95 void SetWindow(wxWindow* window);
97 static bool IsSilent();
98 static void SetBellOnError(int doIt = TRUE);
103 //----------------------------------------------------------------------
105 class wxPyValidator : public wxValidator {
106 DECLARE_DYNAMIC_CLASS(wxPyValidator);
114 wxObject* Clone() const {
115 wxPyValidator* ptr = NULL;
116 wxPyValidator* self = (wxPyValidator*)this;
118 wxPyTState* state = wxPyBeginBlockThreads();
119 if (self->m_myInst.findCallback("Clone")) {
121 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
123 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
127 wxPyEndBlockThreads(state);
129 // This is very dangerous!!! But is the only way I could find
130 // to squash a memory leak. Currently it is okay, but if the
131 // validator architecture in wxWindows ever changes, problems
138 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
139 DEC_PYCALLBACK_BOOL_(TransferToWindow);
140 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
145 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
146 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
147 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
149 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
153 class wxPyValidator : public wxValidator {
157 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=TRUE);
158 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyValidator, 1)"
160 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
163 //----------------------------------------------------------------------
165 %apply int * INOUT { int* x, int* y };
167 class wxWindow : public wxEvtHandler {
169 wxWindow(wxWindow* parent, const wxWindowID id,
170 const wxPoint& pos = wxDefaultPosition,
171 const wxSize& size = wxDefaultSize,
173 char* name = "panel");
174 %name(wxPreWindow)wxWindow();
176 bool Create(wxWindow* parent, const wxWindowID id,
177 const wxPoint& pos = wxDefaultPosition,
178 const wxSize& size = wxDefaultSize,
180 char* name = "panel");
182 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
183 %pragma(python) addtomethod = "wxPreWindow:val._setOORInfo(val)"
187 void Center(int direction = wxBOTH);
188 void Centre(int direction = wxBOTH);
189 void CentreOnParent(int direction = wxBOTH );
190 void CenterOnParent(int direction = wxBOTH );
191 void CentreOnScreen(int direction = wxBOTH );
192 void CenterOnScreen(int direction = wxBOTH );
196 // (uses apply'ed INOUT typemap, see above)
197 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
198 wxPoint ClientToScreen(const wxPoint& pt);
200 bool Close(int force = FALSE);
202 void DestroyChildren();
203 bool IsBeingDeleted();
205 void DragAcceptFiles(bool accept);
207 void Enable(bool enable);
208 //bool FakePopupMenu(wxMenu* menu, int x, int y);
209 %name(FindWindowById) wxWindow* FindWindow(long id);
210 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
212 wxColour GetBackgroundColour();
214 //wxList& GetChildren();
216 PyObject* GetChildren() {
217 wxWindowList& list = self->GetChildren();
218 return wxPy_ConvertList(&list, "wxWindow");
224 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
225 wxSize GetClientSize();
226 wxLayoutConstraints * GetConstraints();
227 wxEvtHandler* GetEventHandler();
230 wxColour GetForegroundColour();
231 wxWindow * GetGrandParent();
234 return wxPyGetWinHandle(self); //(long)self->GetHandle();
239 void SetLabel(const wxString& label);
241 wxWindow * GetParent();
242 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
243 wxPoint GetPosition();
245 int GetScrollThumb(int orientation);
246 int GetScrollPos(int orientation);
247 int GetScrollRange(int orientation);
248 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
250 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
251 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
252 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
253 const wxFont* font = NULL); //, bool use16 = FALSE)
255 wxRegion GetUpdateRegion();
256 long GetWindowStyleFlag();
257 void SetWindowStyleFlag(long style);
258 void SetWindowStyle(long style);
262 bool IsExposed( int x, int y, int w=0, int h=0 );
263 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
264 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
269 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
271 void MakeModal(bool flag=TRUE);
272 %name(MoveXY)void Move(int x, int y);
273 void Move(const wxPoint& point);
275 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
276 void PushEventHandler(wxEvtHandler* handler);
278 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
279 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
282 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
283 void RefreshRect(const wxRect& rect);
286 void RemoveChild(wxWindow* child);
287 bool Reparent( wxWindow* newParent );
289 // (uses apply'ed INOUT typemap, see above)
290 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
291 wxPoint ScreenToClient(const wxPoint& pt);
293 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
294 void SetAutoLayout(bool autoLayout);
295 bool GetAutoLayout();
296 void SetBackgroundColour(const wxColour& colour);
297 void SetConstraints(wxLayoutConstraints *constraints);
298 void UnsetConstraints(wxLayoutConstraints *constraints);
301 void SetFont(const wxFont& font);
302 void SetForegroundColour(const wxColour& colour);
304 void SetName(const wxString& name);
305 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
306 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
308 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
310 void SetSize(const wxSize& size) {
314 void SetPosition(const wxPoint& pos) {
318 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
319 self->SetSize(rect, sizeFlags);
323 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
324 %name(SetClientSizeWH)void SetClientSize(int width, int height);
325 void SetClientSize(const wxSize& size);
326 //void SetPalette(wxPalette* palette);
327 void SetCursor(const wxCursor&cursor);
328 void SetEventHandler(wxEvtHandler* handler);
329 void SetExtraStyle(long exStyle);
330 void SetTitle(const wxString& title);
331 bool Show(bool show);
332 bool TransferDataFromWindow();
333 bool TransferDataToWindow();
335 void WarpPointer(int x, int y);
337 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
338 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
340 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
341 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
343 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
344 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
346 %name(SetToolTipString)void SetToolTip(const wxString &tip);
347 void SetToolTip(wxToolTip *tooltip);
348 wxToolTip* GetToolTip();
350 void SetSizer(wxSizer* sizer);
353 wxValidator* GetValidator();
354 void SetValidator(const wxValidator& validator);
357 void SetDropTarget(wxDropTarget* target);
358 wxDropTarget* GetDropTarget();
359 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
362 wxSize GetBestSize();
364 void SetCaret(wxCaret *caret);
366 %pragma(python) addtoclass = "# replaces broken shadow method
367 def GetCaret(self, *_args, **_kwargs):
368 from misc2 import wxCaretPtr
369 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
370 if val: val = wxCaretPtr(val)
378 wxString GetHelpText();
379 void SetHelpText(const wxString& helpText);
381 bool ScrollLines(int lines);
382 bool ScrollPages(int pages);
388 static wxWindow* FindFocus();
389 static int NewControlId();
390 static int NextControlId(int id);
391 static int PrevControlId(int id);
393 void SetAcceleratorTable(const wxAcceleratorTable& accel);
394 wxAcceleratorTable *GetAcceleratorTable();
400 %pragma(python) code = "
401 def wxDLG_PNT(win, point_or_x, y=None):
403 return win.ConvertDialogPointToPixels(point_or_x)
405 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
407 def wxDLG_SZE(win, size_width, height=None):
409 return win.ConvertDialogSizeToPixels(size_width)
411 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
417 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
418 wxWindow* win = new wxWindow;
420 win->SubclassWin(hWnd);
427 //---------------------------------------------------------------------------
429 class wxPanel : public wxWindow {
431 wxPanel(wxWindow* parent,
433 const wxPoint& pos = wxDefaultPosition,
434 const wxSize& size = wxDefaultSize,
435 long style = wxTAB_TRAVERSAL,
436 const char* name = "panel");
437 %name(wxPrePanel)wxPanel();
439 bool Create(wxWindow* parent,
441 const wxPoint& pos = wxDefaultPosition,
442 const wxSize& size = wxDefaultSize,
443 long style = wxTAB_TRAVERSAL,
444 const char* name = "panel");
446 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
447 %pragma(python) addtomethod = "XXX:val._setOORInfo(self)"
450 wxButton* GetDefaultItem();
451 void SetDefaultItem(wxButton *btn);
455 //---------------------------------------------------------------------------
458 // TODO: Add wrappers for the wxScrollHelper class, make wxScrolledWindow
459 // derive from it and wxPanel.
462 class wxScrolledWindow : public wxPanel {
464 wxScrolledWindow(wxWindow* parent,
465 const wxWindowID id = -1,
466 const wxPoint& pos = wxDefaultPosition,
467 const wxSize& size = wxDefaultSize,
468 long style = wxHSCROLL | wxVSCROLL,
469 char* name = "scrolledWindow");
470 %name(wxPreScrolledWindow)wxScrolledWindow();
472 bool Create(wxWindow* parent,
473 const wxWindowID id = -1,
474 const wxPoint& pos = wxDefaultPosition,
475 const wxSize& size = wxDefaultSize,
476 long style = wxHSCROLL | wxVSCROLL,
477 char* name = "scrolledWindow");
479 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
480 %pragma(python) addtomethod = "wxPreScrolledWindow:val._setOORInfo(val)"
482 void EnableScrolling(bool xScrolling, bool yScrolling);
483 int GetScrollPageSize(int orient);
484 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
485 wxWindow* GetTargetWindow();
486 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
488 void PrepareDC(wxDC& dc);
489 void Scroll(int x, int y);
490 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
491 int noUnitsX, int noUnitsY,
492 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
493 void SetScrollPageSize(int orient, int pageSize);
494 void SetTargetWindow(wxWindow* window);
495 void GetViewStart(int* OUTPUT, int* OUTPUT);
496 %pragma(python) addtoclass = "ViewStart = GetViewStart"
498 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
499 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
501 void SetScale(double xs, double ys);
505 void AdjustScrollbars();
508 //----------------------------------------------------------------------
511 class wxMenu : public wxEvtHandler {
513 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
515 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
517 void Append(int id, const wxString& item,
518 const wxString& helpString = wxPyEmptyStr,
519 int checkable = FALSE);
520 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
521 const wxString& helpString = wxPyEmptyStr);
522 %name(AppendItem)void Append(const wxMenuItem* item);
524 void AppendSeparator();
526 void Check(int id, bool flag);
527 bool IsChecked(int id);
528 void Enable(int id, bool enable);
529 bool IsEnabled(int id);
531 int FindItem(const wxString& itemString);
532 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
535 void SetTitle(const wxString& title);
537 wxString GetLabel(int id);
538 void SetLabel(int id, const wxString& label);
540 wxString GetHelpString(int id);
541 void SetHelpString(int id, const wxString& helpString);
542 void UpdateUI(wxEvtHandler* source = NULL);
545 %name(DeleteItem)bool Delete(wxMenuItem *item);
546 bool Insert(size_t pos, wxMenuItem *item);
547 wxMenuItem *Remove(int id);
548 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
551 void Destroy() { delete self; }
553 %name(DestroyId)bool Destroy(int id);
554 %name(DestroyItem)bool Destroy(wxMenuItem *item);
556 size_t GetMenuItemCount();
557 //wxMenuItemList& GetMenuItems();
559 PyObject* GetMenuItems() {
560 wxMenuItemList& list = self->GetMenuItems();
561 return wxPy_ConvertList(&list, "wxMenuItem");
565 void SetEventHandler(wxEvtHandler *handler);
566 wxEvtHandler *GetEventHandler();
568 void SetInvokingWindow(wxWindow *win);
569 wxWindow *GetInvokingWindow();
575 void SetParent(wxMenu *parent);
580 //----------------------------------------------------------------------
582 class wxMenuBar : public wxWindow {
584 wxMenuBar(long style = 0);
586 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
588 bool Append(wxMenu *menu, const wxString& title);
589 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
590 size_t GetMenuCount();
591 wxMenu *GetMenu(size_t pos);
592 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
593 wxMenu *Remove(size_t pos);
594 void EnableTop(size_t pos, bool enable);
595 void SetLabelTop(size_t pos, const wxString& label);
596 wxString GetLabelTop(size_t pos);
597 int FindMenu(const wxString& title);
598 int FindMenuItem(const wxString& menuString, const wxString& itemString);
599 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
600 void Enable(int id, bool enable);
601 void Check(int id, bool check);
602 bool IsChecked(int id);
603 bool IsEnabled(int id);
605 void SetLabel(int id, const wxString &label);
606 wxString GetLabel(int id);
608 void SetHelpString(int id, const wxString& helpString);
609 wxString GetHelpString(int id);
614 //----------------------------------------------------------------------
616 class wxMenuItem : public wxObject {
618 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
619 const wxString& text = wxPyEmptyStr,
620 const wxString& help = wxPyEmptyStr,
621 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
628 void SetText(const wxString& str);
630 const wxString& GetText();
631 void SetCheckable(bool checkable);
634 void SetSubMenu(wxMenu *menu);
635 wxMenu *GetSubMenu();
636 void Enable(bool enable = TRUE);
638 void Check(bool check = TRUE);
641 void SetHelp(const wxString& str);
642 const wxString& GetHelp();
643 wxAcceleratorEntry *GetAccel();
644 void SetAccel(wxAcceleratorEntry *accel);
646 static wxString GetLabelFromText(const wxString& text);
648 // wxOwnerDrawn methods
650 void SetFont(const wxFont& font);
652 void SetTextColour(const wxColour& colText);
653 wxColour GetTextColour();
654 void SetBackgroundColour(const wxColour& colBack);
655 wxColour GetBackgroundColour();
656 void SetBitmaps(const wxBitmap& bmpChecked,
657 const wxBitmap& bmpUnchecked = wxNullBitmap);
658 void SetBitmap(const wxBitmap& bmpChecked);
659 const wxBitmap& GetBitmap(bool bChecked = TRUE);
660 void SetMarginWidth(int nWidth);
661 int GetMarginWidth();
662 static int GetDefaultMarginWidth();
663 //void SetName(const wxString& strName);
664 //const wxString& GetName();
665 //void SetCheckable(bool checkable);
666 //bool IsCheckable();
668 void ResetOwnerDrawn();
672 //---------------------------------------------------------------------------