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");
195 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
196 wxSize GetClientSize();
197 wxLayoutConstraints * GetConstraints();
198 wxEvtHandler* GetEventHandler();
201 wxColour GetForegroundColour();
202 wxWindow * GetGrandParent();
205 return (long)self->GetHandle();
210 void SetLabel(const wxString& label);
212 wxWindow * GetParent();
213 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
214 wxPoint GetPosition();
216 int GetScrollThumb(int orientation);
217 int GetScrollPos(int orientation);
218 int GetScrollRange(int orientation);
219 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
221 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
222 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
223 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
224 const wxFont* font = NULL); //, bool use16 = FALSE)
226 wxRegion GetUpdateRegion();
227 long GetWindowStyleFlag();
235 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
237 void MakeModal(bool flag);
238 %name(MoveXY)void Move(int x, int y);
239 void Move(const wxPoint& point);
241 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
242 void PushEventHandler(wxEvtHandler* handler);
244 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
245 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
248 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
250 bool Reparent( wxWindow* newParent );
252 // (uses apply'ed INOUT typemap, see above)
253 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
254 wxPoint ScreenToClient(const wxPoint& pt);
256 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
257 void SetAcceleratorTable(const wxAcceleratorTable& accel);
258 void SetAutoLayout(bool autoLayout);
259 bool GetAutoLayout();
260 void SetBackgroundColour(const wxColour& colour);
261 void SetConstraints(wxLayoutConstraints *constraints);
262 void UnsetConstraints(wxLayoutConstraints *constraints);
265 void SetFont(const wxFont& font);
266 void SetForegroundColour(const wxColour& colour);
268 void SetName(const wxString& name);
269 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
270 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
272 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
274 void SetSize(const wxSize& size) {
275 self->SetSize(size.x, size.y);
278 void SetPosition(const wxPoint& pos) {
279 self->SetSize(pos.x, pos.y, -1, -1);
283 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
284 %name(SetClientSizeWH)void SetClientSize(int width, int height);
285 void SetClientSize(const wxSize& size);
286 //void SetPalette(wxPalette* palette);
287 void SetCursor(const wxCursor&cursor);
288 void SetEventHandler(wxEvtHandler* handler);
289 void SetTitle(const wxString& title);
290 bool Show(bool show);
291 bool TransferDataFromWindow();
292 bool TransferDataToWindow();
294 void WarpPointer(int x, int y);
296 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
297 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
299 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
300 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
302 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
303 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
305 %name(SetToolTipString)void SetToolTip(const wxString &tip);
306 void SetToolTip(wxToolTip *tooltip);
307 wxToolTip* GetToolTip();
309 void SetSizer(wxSizer* sizer);
310 wxValidator* GetValidator();
311 void SetValidator(const wxValidator& validator);
315 //%clear int* x, int* y;
319 %pragma(python) code = "
320 def wxDLG_PNT(win, point_or_x, y=None):
322 return win.ConvertDialogPointToPixels(point_or_x)
324 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
326 def wxDLG_SZE(win, size_width, height=None):
328 return win.ConvertDialogSizeToPixels(size_width)
330 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
335 wxWindow* wxWindow_FindFocus() {
336 return wxWindow::FindFocus();
342 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
343 wxWindow* win = new wxWindow;
345 win->SubclassWin(hWnd);
353 //---------------------------------------------------------------------------
355 class wxPanel : public wxWindow {
357 wxPanel(wxWindow* parent,
359 const wxPoint& pos = wxPyDefaultPosition,
360 const wxSize& size = wxPyDefaultSize,
361 long style = wxTAB_TRAVERSAL,
362 const char* name = "panel");
364 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
367 wxButton* GetDefaultItem();
368 void SetDefaultItem(wxButton *btn);
370 // fix some SWIG trouble...
371 %pragma(python) addtoclass = "
372 def GetDefaultItem(self):
374 val = windowsc.wxPanel_GetDefaultItem(self.this)
375 val = controls.wxButtonPtr(val)
380 //---------------------------------------------------------------------------
382 class wxDialog : public wxPanel {
384 wxDialog(wxWindow* parent,
386 const wxString& title,
387 const wxPoint& pos = wxPyDefaultPosition,
388 const wxSize& size = wxPyDefaultSize,
389 long style = wxDEFAULT_DIALOG_STYLE,
390 const char* name = "dialogBox");
392 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
394 void Centre(int direction = wxBOTH);
395 void EndModal(int retCode);
397 void Iconize(bool iconize);
399 void SetModal(bool flag);
401 void SetTitle(const wxString& title);
402 bool Show(bool show);
406 void SetReturnCode(int retCode);
409 //---------------------------------------------------------------------------
411 class wxScrolledWindow : public wxPanel {
413 wxScrolledWindow(wxWindow* parent,
414 const wxWindowID id = -1,
415 const wxPoint& pos = wxPyDefaultPosition,
416 const wxSize& size = wxPyDefaultSize,
417 long style = wxHSCROLL | wxVSCROLL,
418 char* name = "scrolledWindow");
420 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
421 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
423 void EnableScrolling(bool xScrolling, bool yScrolling);
424 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
425 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
427 void PrepareDC(wxDC& dc);
428 void Scroll(int x, int y);
429 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
430 int noUnitsX, int noUnitsY,
431 int xPos = 0, int yPos = 0);
432 void ViewStart(int* OUTPUT, int* OUTPUT);
434 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
435 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
439 //----------------------------------------------------------------------
442 class wxMenu : public wxEvtHandler {
444 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
446 void Append(int id, const wxString& item,
447 const wxString& helpString = wxPyEmptyStr,
448 int checkable = FALSE);
449 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
450 const wxString& helpString = wxPyEmptyStr);
451 %name(AppendItem)void Append(const wxMenuItem* item);
453 void AppendSeparator();
455 void Check(int id, bool flag);
456 void Enable(int id, bool enable);
457 int FindItem(const wxString& itemString);
459 void SetTitle(const wxString& title);
460 wxMenuItem* FindItemForId(int id);
461 wxString GetHelpString(int id);
462 wxString GetLabel(int id);
463 void SetHelpString(int id, const wxString& helpString);
464 bool IsChecked(int id);
465 bool IsEnabled(int id);
466 void SetLabel(int id, const wxString& label);
467 void UpdateUI(wxEvtHandler* source = NULL);
479 // This one knows how to set a callback and handle INC- and DECREFing it. To
480 // be used for PopupMenus, but you must retain a referece to it while using
483 // class wxPyMenu : public wxMenu {
485 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
489 //----------------------------------------------------------------------
491 class wxMenuBar : public wxEvtHandler {
495 void Append(wxMenu *menu, const wxString& title);
496 void Check(int id, bool flag);
497 // bool Checked(int id);
498 void Enable(int id, bool enable);
499 // bool Enabled(int id);
500 bool IsChecked(int id);
501 bool IsEnabled(int id);
502 int FindMenuItem(const wxString& menuString, const wxString& itemString);
503 wxMenuItem * FindItemForId(int id);
504 void SetLabel(int id, const wxString& label);
505 void EnableTop(int pos, bool enable);
506 wxString GetHelpString(int id);
507 wxString GetLabel(int id);
508 void SetHelpString(int id, const wxString& helpString);
509 wxString GetLabelTop(int pos);
510 void SetLabelTop(int pos, const wxString& label);
512 wxMenu* GetMenu(int i);
514 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
515 wxMenu *Remove(size_t pos);
520 //----------------------------------------------------------------------
525 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
526 const wxString& text = wxPyEmptyStr,
527 const wxString& helpString = wxPyEmptyStr,
528 bool checkable = FALSE, wxMenu* subMenu = NULL);
540 wxMenu* GetSubMenu();
542 void SetHelp(const wxString& strHelp);
543 void Enable(bool bDoEnable = TRUE);
544 void Check(bool bDoCheck = TRUE);
547 wxColour& GetBackgroundColour();
548 wxBitmap GetBitmap(bool checked = TRUE);
550 int GetMarginWidth();
551 wxColour& GetTextColour();
552 void SetBackgroundColour(const wxColour& colour);
553 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
554 void SetFont(const wxFont& font);
555 void SetMarginWidth(int width);
556 void SetText(const wxString& str);
557 const wxString& GetText();
558 void SetTextColour(const wxColour& colour);
559 void DeleteSubMenu();
560 void SetCheckable(bool checkable);
561 void SetSubMenu(wxMenu *menu);
565 //---------------------------------------------------------------------------