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);
79 //----------------------------------------------------------------------
81 class wxValidator : public wxEvtHandler {
87 wxWindow* GetWindow();
88 void SetWindow(wxWindow* window);
90 static bool IsSilent();
91 static void SetBellOnError(int doIt = TRUE);
96 //----------------------------------------------------------------------
98 class wxPyValidator : public wxValidator {
99 DECLARE_DYNAMIC_CLASS(wxPyValidator);
107 wxObject* Clone() const {
108 wxPyValidator* ptr = NULL;
109 wxPyValidator* self = (wxPyValidator*)this;
111 wxPyTState* state = wxPyBeginBlockThreads();
112 if (self->m_myInst.findCallback("Clone")) {
114 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
116 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
120 wxPyEndBlockThreads(state);
122 // This is very dangerous!!! But is the only way I could find
123 // to squash a memory leak. Currently it is okay, but if the
124 // validator architecture in wxWindows ever changes, problems
131 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
132 DEC_PYCALLBACK_BOOL_(TransferToWindow);
133 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
138 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
139 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
140 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
142 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
146 class wxPyValidator : public wxValidator {
150 void _setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
151 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyValidator, 1)"
155 //----------------------------------------------------------------------
157 %apply int * INOUT { int* x, int* y };
159 class wxWindow : public wxEvtHandler {
161 wxWindow(wxWindow* parent, const wxWindowID id,
162 const wxPoint& pos = wxDefaultPosition,
163 const wxSize& size = wxDefaultSize,
165 char* name = "panel");
166 %name(wxPreWindow)wxWindow();
168 bool Create(wxWindow* parent, const wxWindowID id,
169 const wxPoint& pos = wxDefaultPosition,
170 const wxSize& size = wxDefaultSize,
172 char* name = "panel");
175 void Center(int direction = wxBOTH);
176 void Centre(int direction = wxBOTH);
177 void CentreOnParent(int direction = wxBOTH );
178 void CenterOnParent(int direction = wxBOTH );
179 void CentreOnScreen(int direction = wxBOTH );
180 void CenterOnScreen(int direction = wxBOTH );
184 // (uses apply'ed INOUT typemap, see above)
185 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
186 wxPoint ClientToScreen(const wxPoint& pt);
188 bool Close(int force = FALSE);
190 void DestroyChildren();
191 bool IsBeingDeleted();
193 void DragAcceptFiles(bool accept);
195 void Enable(bool enable);
196 //bool FakePopupMenu(wxMenu* menu, int x, int y);
197 %name(FindWindowById) wxWindow* FindWindow(long id);
198 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
200 wxColour GetBackgroundColour();
202 //wxList& GetChildren();
204 PyObject* GetChildren() {
205 wxWindowList& list = self->GetChildren();
206 return wxPy_ConvertList(&list, "wxWindow");
212 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
213 wxSize GetClientSize();
214 wxLayoutConstraints * GetConstraints();
215 wxEvtHandler* GetEventHandler();
218 wxColour GetForegroundColour();
219 wxWindow * GetGrandParent();
222 return wxPyGetWinHandle(self); //(long)self->GetHandle();
227 void SetLabel(const wxString& label);
229 wxWindow * GetParent();
230 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
231 wxPoint GetPosition();
233 int GetScrollThumb(int orientation);
234 int GetScrollPos(int orientation);
235 int GetScrollRange(int orientation);
236 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
238 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
239 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
240 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
241 const wxFont* font = NULL); //, bool use16 = FALSE)
243 wxRegion GetUpdateRegion();
244 long GetWindowStyleFlag();
245 void SetWindowStyleFlag(long style);
246 void SetWindowStyle(long style);
250 bool IsExposed( int x, int y, int w=0, int h=0 );
251 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
252 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
257 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
259 void MakeModal(bool flag);
260 %name(MoveXY)void Move(int x, int y);
261 void Move(const wxPoint& point);
263 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
264 void PushEventHandler(wxEvtHandler* handler);
266 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
267 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
270 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
271 void RefreshRect(const wxRect& rect);
274 void RemoveChild(wxWindow* child);
275 bool Reparent( wxWindow* newParent );
277 // (uses apply'ed INOUT typemap, see above)
278 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
279 wxPoint ScreenToClient(const wxPoint& pt);
281 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
282 void SetAcceleratorTable(const wxAcceleratorTable& accel);
283 void SetAutoLayout(bool autoLayout);
284 bool GetAutoLayout();
285 void SetBackgroundColour(const wxColour& colour);
286 void SetConstraints(wxLayoutConstraints *constraints);
287 void UnsetConstraints(wxLayoutConstraints *constraints);
290 void SetFont(const wxFont& font);
291 void SetForegroundColour(const wxColour& colour);
293 void SetName(const wxString& name);
294 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
295 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
297 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
299 void SetSize(const wxSize& size) {
303 void SetPosition(const wxPoint& pos) {
307 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
308 self->SetSize(rect, sizeFlags);
312 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
313 %name(SetClientSizeWH)void SetClientSize(int width, int height);
314 void SetClientSize(const wxSize& size);
315 //void SetPalette(wxPalette* palette);
316 void SetCursor(const wxCursor&cursor);
317 void SetEventHandler(wxEvtHandler* handler);
318 void SetExtraStyle(long exStyle);
319 void SetTitle(const wxString& title);
320 bool Show(bool show);
321 bool TransferDataFromWindow();
322 bool TransferDataToWindow();
324 void WarpPointer(int x, int y);
326 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
327 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
329 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
330 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
332 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
333 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
335 %name(SetToolTipString)void SetToolTip(const wxString &tip);
336 void SetToolTip(wxToolTip *tooltip);
337 wxToolTip* GetToolTip();
339 void SetSizer(wxSizer* sizer);
342 wxValidator* GetValidator();
343 void SetValidator(const wxValidator& validator);
345 void SetDropTarget(wxDropTarget* target);
346 wxDropTarget* GetDropTarget();
347 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
349 wxSize GetBestSize();
351 void SetCaret(wxCaret *caret);
353 %pragma(python) addtoclass = "# replaces broken shadow method
354 def GetCaret(self, *_args, **_kwargs):
355 from misc2 import wxCaretPtr
356 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
357 if val: val = wxCaretPtr(val)
365 wxString GetHelpText();
366 void SetHelpText(const wxString& helpText);
368 bool ScrollLines(int lines);
369 bool ScrollPages(int pages);
375 static wxWindow* FindFocus();
376 static int NewControlId();
377 static int NextControlId(int id);
378 static int PrevControlId(int id);
385 %pragma(python) code = "
386 def wxDLG_PNT(win, point_or_x, y=None):
388 return win.ConvertDialogPointToPixels(point_or_x)
390 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
392 def wxDLG_SZE(win, size_width, height=None):
394 return win.ConvertDialogSizeToPixels(size_width)
396 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
402 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
403 wxWindow* win = new wxWindow;
405 win->SubclassWin(hWnd);
412 //---------------------------------------------------------------------------
414 class wxPanel : public wxWindow {
416 wxPanel(wxWindow* parent,
418 const wxPoint& pos = wxDefaultPosition,
419 const wxSize& size = wxDefaultSize,
420 long style = wxTAB_TRAVERSAL,
421 const char* name = "panel");
422 %name(wxPrePanel)wxPanel();
424 bool Create(wxWindow* parent,
426 const wxPoint& pos = wxDefaultPosition,
427 const wxSize& size = wxDefaultSize,
428 long style = wxTAB_TRAVERSAL,
429 const char* name = "panel");
432 wxButton* GetDefaultItem();
433 void SetDefaultItem(wxButton *btn);
437 //---------------------------------------------------------------------------
439 class wxDialog : public wxPanel {
441 wxDialog(wxWindow* parent,
443 const wxString& title,
444 const wxPoint& pos = wxDefaultPosition,
445 const wxSize& size = wxDefaultSize,
446 long style = wxDEFAULT_DIALOG_STYLE,
447 const char* name = "dialogBox");
448 %name(wxPreDialog)wxDialog();
450 bool Create(wxWindow* parent,
452 const wxString& title,
453 const wxPoint& pos = wxDefaultPosition,
454 const wxSize& size = wxDefaultSize,
455 long style = wxDEFAULT_DIALOG_STYLE,
456 const char* name = "dialogBox");
458 void Centre(int direction = wxBOTH);
459 void EndModal(int retCode);
461 void Iconize(bool iconize);
463 void SetModal(bool flag);
465 void SetTitle(const wxString& title);
466 bool Show(bool show);
470 void SetReturnCode(int retCode);
472 wxSizer* CreateTextSizer( const wxString &message );
473 wxSizer* CreateButtonSizer( long flags );
477 //---------------------------------------------------------------------------
480 // TODO: Add wrappers for the wxScrollHelper class, make wxScrolledWindow
481 // derive from it and wxPanel.
484 class wxScrolledWindow : public wxPanel {
486 wxScrolledWindow(wxWindow* parent,
487 const wxWindowID id = -1,
488 const wxPoint& pos = wxDefaultPosition,
489 const wxSize& size = wxDefaultSize,
490 long style = wxHSCROLL | wxVSCROLL,
491 char* name = "scrolledWindow");
492 %name(wxPreScrolledWindow)wxScrolledWindow();
494 bool Create(wxWindow* parent,
495 const wxWindowID id = -1,
496 const wxPoint& pos = wxDefaultPosition,
497 const wxSize& size = wxDefaultSize,
498 long style = wxHSCROLL | wxVSCROLL,
499 char* name = "scrolledWindow");
501 void EnableScrolling(bool xScrolling, bool yScrolling);
502 int GetScrollPageSize(int orient);
503 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
504 wxWindow* GetTargetWindow();
505 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
507 void PrepareDC(wxDC& dc);
508 void Scroll(int x, int y);
509 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
510 int noUnitsX, int noUnitsY,
511 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
512 void SetScrollPageSize(int orient, int pageSize);
513 void SetTargetWindow(wxWindow* window);
514 void GetViewStart(int* OUTPUT, int* OUTPUT);
515 %pragma(python) addtoclass = "ViewStart = GetViewStart"
517 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
518 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
520 void SetScale(double xs, double ys);
524 void AdjustScrollbars();
527 //----------------------------------------------------------------------
530 class wxMenu : public wxEvtHandler {
532 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
534 void Append(int id, const wxString& item,
535 const wxString& helpString = wxPyEmptyStr,
536 int checkable = FALSE);
537 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
538 const wxString& helpString = wxPyEmptyStr);
539 %name(AppendItem)void Append(const wxMenuItem* item);
541 void AppendSeparator();
543 void Check(int id, bool flag);
544 bool IsChecked(int id);
545 void Enable(int id, bool enable);
546 bool IsEnabled(int id);
548 int FindItem(const wxString& itemString);
549 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
552 void SetTitle(const wxString& title);
554 wxString GetLabel(int id);
555 void SetLabel(int id, const wxString& label);
557 wxString GetHelpString(int id);
558 void SetHelpString(int id, const wxString& helpString);
559 void UpdateUI(wxEvtHandler* source = NULL);
562 %name(DeleteItem)bool Delete(wxMenuItem *item);
563 bool Insert(size_t pos, wxMenuItem *item);
564 wxMenuItem *Remove(int id);
565 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
568 void Destroy() { delete self; }
570 %name(DestroyId)bool Destroy(int id);
571 %name(DestroyItem)bool Destroy(wxMenuItem *item);
573 size_t GetMenuItemCount();
574 //wxMenuItemList& GetMenuItems();
576 PyObject* GetMenuItems() {
577 wxMenuItemList& list = self->GetMenuItems();
578 return wxPy_ConvertList(&list, "wxMenuItem");
582 void SetEventHandler(wxEvtHandler *handler);
583 wxEvtHandler *GetEventHandler();
585 void SetInvokingWindow(wxWindow *win);
586 wxWindow *GetInvokingWindow();
592 void SetParent(wxMenu *parent);
597 //----------------------------------------------------------------------
599 class wxMenuBar : public wxWindow {
601 wxMenuBar(long style = 0);
603 bool Append(wxMenu *menu, const wxString& title);
604 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
605 size_t GetMenuCount();
606 wxMenu *GetMenu(size_t pos);
607 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
608 wxMenu *Remove(size_t pos);
609 void EnableTop(size_t pos, bool enable);
610 void SetLabelTop(size_t pos, const wxString& label);
611 wxString GetLabelTop(size_t pos);
612 int FindMenu(const wxString& title);
613 int FindMenuItem(const wxString& menuString, const wxString& itemString);
614 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
615 void Enable(int id, bool enable);
616 void Check(int id, bool check);
617 bool IsChecked(int id);
618 bool IsEnabled(int id);
620 void SetLabel(int id, const wxString &label);
621 wxString GetLabel(int id);
623 void SetHelpString(int id, const wxString& helpString);
624 wxString GetHelpString(int id);
629 //----------------------------------------------------------------------
631 class wxMenuItem : public wxObject {
633 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
634 const wxString& text = wxPyEmptyStr,
635 const wxString& help = wxPyEmptyStr,
636 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
643 void SetText(const wxString& str);
645 const wxString& GetText();
646 void SetCheckable(bool checkable);
649 void SetSubMenu(wxMenu *menu);
650 wxMenu *GetSubMenu();
651 void Enable(bool enable = TRUE);
653 void Check(bool check = TRUE);
656 void SetHelp(const wxString& str);
657 const wxString& GetHelp();
658 wxAcceleratorEntry *GetAccel();
659 void SetAccel(wxAcceleratorEntry *accel);
661 static wxString GetLabelFromText(const wxString& text);
663 // wxOwnerDrawn methods
665 void SetFont(const wxFont& font);
667 void SetTextColour(const wxColour& colText);
668 wxColour GetTextColour();
669 void SetBackgroundColour(const wxColour& colBack);
670 wxColour GetBackgroundColour();
671 void SetBitmaps(const wxBitmap& bmpChecked,
672 const wxBitmap& bmpUnchecked = wxNullBitmap);
673 void SetBitmap(const wxBitmap& bmpChecked);
674 const wxBitmap& GetBitmap(bool bChecked = TRUE);
675 void SetMarginWidth(int nWidth);
676 int GetMarginWidth();
677 static int GetDefaultMarginWidth();
678 //void SetName(const wxString& strName);
679 //const wxString& GetName();
680 //void SetCheckable(bool checkable);
681 //bool IsCheckable();
683 void ResetOwnerDrawn();
687 //---------------------------------------------------------------------------