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>
21 //----------------------------------------------------------------------
24 %include my_typemaps.i
26 // Import some definitions of other classes, etc.
32 %pragma(python) code = "import wx"
34 //---------------------------------------------------------------------------
38 bool ProcessEvent(wxEvent& event);
39 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
41 bool GetEvtHandlerEnabled();
42 void SetEvtHandlerEnabled(bool enabled);
44 wxEvtHandler* GetNextHandler();
45 wxEvtHandler* GetPreviousHandler();
46 void SetNextHandler(wxEvtHandler* handler);
47 void SetPreviousHandler(wxEvtHandler* handler);
51 void Connect( int id, int lastId, int eventType, PyObject* func) {
52 if (PyCallable_Check(func)) {
53 self->Connect(id, lastId, eventType,
54 (wxObjectEventFunction) &wxPyCallback::EventThunker,
55 new wxPyCallback(func));
62 //----------------------------------------------------------------------
64 class wxValidator : public wxEvtHandler {
70 wxWindow* GetWindow();
71 void SetWindow(wxWindow* window);
75 bool wxValidator_IsSilent() {
76 return wxValidator::IsSilent();
79 void wxValidator_SetBellOnError(int doIt = TRUE) {
80 wxValidator::SetBellOnError(doIt);
84 //----------------------------------------------------------------------
86 class wxPyValidator : public wxValidator {
87 DECLARE_DYNAMIC_CLASS(wxPyValidator);
91 // wxPyValidator(const wxPyValidator& other);
96 wxObject* wxPyValidator::Clone() const {
97 wxPyValidator* ptr = NULL;
98 wxPyValidator* self = (wxPyValidator*)this;
100 bool doSave = wxPyRestoreThread();
101 if (self->m_myInst.findCallback("Clone")) {
103 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
104 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
106 // This is very dangerous!!! But is the only way I could find
107 // to squash a memory leak. Currently it is okay, but if the
108 // validator architecture in wxWindows ever changes, problems
112 wxPySaveThread(doSave);
117 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
118 DEC_PYCALLBACK_BOOL_(TransferToWindow);
119 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
125 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
126 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
127 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
129 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
133 class wxPyValidator : public wxValidator {
139 void Destroy() { delete self; }
142 void _setSelf(PyObject* self, int incref=TRUE);
143 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
147 //----------------------------------------------------------------------
149 %apply int * INOUT { int* x, int* y };
151 class wxWindow : public wxEvtHandler {
154 wxWindow(wxWindow* parent, const wxWindowID id,
155 const wxPoint& pos = wxPyDefaultPosition,
156 const wxSize& size = wxPyDefaultSize,
158 char* name = "panel");
160 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
163 void Center(int direction = wxBOTH);
164 void Centre(int direction = wxBOTH);
165 void CentreOnParent(int direction = wxBOTH );
166 void CenterOnParent(int direction = wxBOTH );
168 // (uses apply'ed INOUT typemap, see above)
169 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
170 wxPoint ClientToScreen(const wxPoint& pt);
172 bool Close(int force = FALSE);
174 void DestroyChildren();
176 void DragAcceptFiles(bool accept);
178 void Enable(bool enable);
179 //bool FakePopupMenu(wxMenu* menu, int x, int y);
180 %name(FindWindowById) wxWindow* FindWindow(long id);
181 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
183 wxColour GetBackgroundColour();
185 //wxList& GetChildren();
187 PyObject* GetChildren() {
188 wxWindowList& list = self->GetChildren();
189 return wxPy_ConvertList(&list, "wxWindow");
196 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
197 wxSize GetClientSize();
198 wxLayoutConstraints * GetConstraints();
199 wxEvtHandler* GetEventHandler();
202 wxColour GetForegroundColour();
203 wxWindow * GetGrandParent();
206 void SetLabel(const wxString& label);
208 wxWindow * GetParent();
209 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
210 wxPoint GetPosition();
212 int GetScrollThumb(int orientation);
213 int GetScrollPos(int orientation);
214 int GetScrollRange(int orientation);
215 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
217 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
218 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
219 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
220 const wxFont* font = NULL); //, bool use16 = FALSE)
222 wxRegion GetUpdateRegion();
223 long GetWindowStyleFlag();
231 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
233 void MakeModal(bool flag);
234 %name(MoveXY)void Move(int x, int y);
235 void Move(const wxPoint& point);
237 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
238 void PushEventHandler(wxEvtHandler* handler);
240 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
241 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
244 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
246 bool Reparent( wxWindow* newParent );
248 // (uses apply'ed INOUT typemap, see above)
249 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
250 wxPoint ScreenToClient(const wxPoint& pt);
252 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
253 void SetAcceleratorTable(const wxAcceleratorTable& accel);
254 void SetAutoLayout(bool autoLayout);
255 bool GetAutoLayout();
256 void SetBackgroundColour(const wxColour& colour);
257 void SetConstraints(wxLayoutConstraints *constraints);
258 void UnsetConstraints(wxLayoutConstraints *constraints);
261 void SetFont(const wxFont& font);
262 void SetForegroundColour(const wxColour& colour);
264 void SetName(const wxString& name);
265 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
266 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
268 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
270 void SetSize(const wxSize& size) {
271 self->SetSize(size.x, size.y);
274 void SetPosition(const wxPoint& pos) {
275 self->SetSize(pos.x, pos.y, -1, -1);
279 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
280 %name(SetClientSizeWH)void SetClientSize(int width, int height);
281 void SetClientSize(const wxSize& size);
282 //void SetPalette(wxPalette* palette);
283 void SetCursor(const wxCursor&cursor);
284 void SetEventHandler(wxEvtHandler* handler);
285 void SetTitle(const wxString& title);
286 bool Show(bool show);
287 bool TransferDataFromWindow();
288 bool TransferDataToWindow();
290 void WarpPointer(int x, int y);
292 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
293 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
295 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
296 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
298 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
299 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
301 %name(SetToolTipString)void SetToolTip(const wxString &tip);
302 void SetToolTip(wxToolTip *tooltip);
303 wxToolTip* GetToolTip();
305 void SetSizer(wxSizer* sizer);
306 wxValidator* GetValidator();
307 void SetValidator(const wxValidator& validator);
311 //%clear int* x, int* y;
315 %pragma(python) code = "
316 def wxDLG_PNT(win, point_or_x, y=None):
318 return win.ConvertDialogPointToPixels(point_or_x)
320 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
322 def wxDLG_SZE(win, size_width, height=None):
324 return win.ConvertDialogSizeToPixels(size_width)
326 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
331 wxWindow* wxWindow_FindFocus() {
332 return wxWindow::FindFocus();
338 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
339 wxWindow* win = new wxWindow;
341 win->SubclassWin(hWnd);
349 //---------------------------------------------------------------------------
351 class wxPanel : public wxWindow {
353 wxPanel(wxWindow* parent,
355 const wxPoint& pos = wxPyDefaultPosition,
356 const wxSize& size = wxPyDefaultSize,
357 long style = wxTAB_TRAVERSAL,
358 const char* name = "panel");
360 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
363 wxButton* GetDefaultItem();
364 void SetDefaultItem(wxButton *btn);
366 // fix some SWIG trouble...
367 %pragma(python) addtoclass = "
368 def GetDefaultItem(self):
370 val = windowsc.wxPanel_GetDefaultItem(self.this)
371 val = controls.wxButtonPtr(val)
376 //---------------------------------------------------------------------------
378 class wxDialog : public wxPanel {
380 wxDialog(wxWindow* parent,
382 const wxString& title,
383 const wxPoint& pos = wxPyDefaultPosition,
384 const wxSize& size = wxPyDefaultSize,
385 long style = wxDEFAULT_DIALOG_STYLE,
386 const char* name = "dialogBox");
388 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
390 void Centre(int direction = wxBOTH);
391 void EndModal(int retCode);
393 void Iconize(bool iconize);
395 void SetModal(bool flag);
397 void SetTitle(const wxString& title);
398 bool Show(bool show);
402 void SetReturnCode(int retCode);
405 //---------------------------------------------------------------------------
407 class wxScrolledWindow : public wxPanel {
409 wxScrolledWindow(wxWindow* parent,
410 const wxWindowID id = -1,
411 const wxPoint& pos = wxPyDefaultPosition,
412 const wxSize& size = wxPyDefaultSize,
413 long style = wxHSCROLL | wxVSCROLL,
414 char* name = "scrolledWindow");
416 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
417 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
419 void EnableScrolling(bool xScrolling, bool yScrolling);
420 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
421 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
423 void PrepareDC(wxDC& dc);
424 void Scroll(int x, int y);
425 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
426 int noUnitsX, int noUnitsY,
427 int xPos = 0, int yPos = 0);
428 void ViewStart(int* OUTPUT, int* OUTPUT);
430 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
431 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
435 //----------------------------------------------------------------------
438 class wxMenu : public wxEvtHandler {
440 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
442 void Append(int id, const wxString& item,
443 const wxString& helpString = wxPyEmptyStr,
444 int checkable = FALSE);
445 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
446 const wxString& helpString = wxPyEmptyStr);
447 %name(AppendItem)void Append(const wxMenuItem* item);
449 void AppendSeparator();
451 void Check(int id, bool flag);
452 void Enable(int id, bool enable);
453 int FindItem(const wxString& itemString);
455 void SetTitle(const wxString& title);
456 wxMenuItem* FindItemForId(int id);
457 wxString GetHelpString(int id);
458 wxString GetLabel(int id);
459 void SetHelpString(int id, const wxString& helpString);
460 bool IsChecked(int id);
461 bool IsEnabled(int id);
462 void SetLabel(int id, const wxString& label);
463 void UpdateUI(wxEvtHandler* source = NULL);
475 // This one knows how to set a callback and handle INC- and DECREFing it. To
476 // be used for PopupMenus, but you must retain a referece to it while using
479 // class wxPyMenu : public wxMenu {
481 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
485 //----------------------------------------------------------------------
487 class wxMenuBar : public wxEvtHandler {
491 void Append(wxMenu *menu, const wxString& title);
492 void Check(int id, bool flag);
493 bool Checked(int id);
494 void Enable(int id, bool enable);
495 bool Enabled(int id);
496 int FindMenuItem(const wxString& menuString, const wxString& itemString);
497 wxMenuItem * FindItemForId(int id);
498 void SetLabel(int id, const wxString& label);
499 void EnableTop(int pos, bool enable);
500 wxString GetHelpString(int id);
501 wxString GetLabel(int id);
502 void SetHelpString(int id, const wxString& helpString);
503 wxString GetLabelTop(int pos);
504 void SetLabelTop(int pos, const wxString& label);
506 wxMenu* GetMenu(int i);
511 //----------------------------------------------------------------------
516 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
517 const wxString& text = wxPyEmptyStr,
518 const wxString& helpString = wxPyEmptyStr,
519 bool checkable = FALSE, wxMenu* subMenu = NULL);
529 wxMenu* GetSubMenu();
530 void SetName(const wxString& strName);
533 void SetHelp(const wxString& strHelp);
534 void Enable(bool bDoEnable = TRUE);
535 void Check(bool bDoCheck = TRUE);
538 wxColour& GetBackgroundColour();
539 wxBitmap GetBitmap(bool checked = TRUE);
541 int GetMarginWidth();
542 wxColour& GetTextColour();
543 void SetBackgroundColour(const wxColour& colour);
544 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
545 void SetFont(const wxFont& font);
546 void SetMarginWidth(int width);
547 void SetTextColour(const wxColour& colour);
548 void DeleteSubMenu();
552 //---------------------------------------------------------------------------