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));
59 bool Disconnect(int id, int lastId = -1,
60 wxEventType eventType = wxEVT_NULL) {
61 return self->Disconnect(id, lastId, eventType,
62 (wxObjectEventFunction)
63 &wxPyCallback::EventThunker);
70 //----------------------------------------------------------------------
72 class wxValidator : public wxEvtHandler {
78 wxWindow* GetWindow();
79 void SetWindow(wxWindow* window);
83 bool wxValidator_IsSilent() {
84 return wxValidator::IsSilent();
87 void wxValidator_SetBellOnError(int doIt = TRUE) {
88 wxValidator::SetBellOnError(doIt);
92 //----------------------------------------------------------------------
94 class wxPyValidator : public wxValidator {
95 DECLARE_DYNAMIC_CLASS(wxPyValidator);
99 // wxPyValidator(const wxPyValidator& other);
104 wxObject* wxPyValidator::Clone() const {
105 wxPyValidator* ptr = NULL;
106 wxPyValidator* self = (wxPyValidator*)this;
108 bool doSave = wxPyRestoreThread();
109 if (self->m_myInst.findCallback("Clone")) {
111 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
112 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
114 // This is very dangerous!!! But is the only way I could find
115 // to squash a memory leak. Currently it is okay, but if the
116 // validator architecture in wxWindows ever changes, problems
120 wxPySaveThread(doSave);
124 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
125 DEC_PYCALLBACK_BOOL_(TransferToWindow);
126 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
132 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
133 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
134 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
136 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
140 class wxPyValidator : public wxValidator {
146 void Destroy() { delete self; }
149 void _setSelf(PyObject* self, int incref=TRUE);
150 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
154 //----------------------------------------------------------------------
156 %apply int * INOUT { int* x, int* y };
158 class wxWindow : public wxEvtHandler {
161 wxWindow(wxWindow* parent, const wxWindowID id,
162 const wxPoint& pos = wxPyDefaultPosition,
163 const wxSize& size = wxPyDefaultSize,
165 char* name = "panel");
167 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
170 void Center(int direction = wxBOTH);
171 void Centre(int direction = wxBOTH);
172 void CentreOnParent(int direction = wxBOTH );
173 void CenterOnParent(int direction = wxBOTH );
175 // (uses apply'ed INOUT typemap, see above)
176 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
177 wxPoint ClientToScreen(const wxPoint& pt);
179 bool Close(int force = FALSE);
181 void DestroyChildren();
183 void DragAcceptFiles(bool accept);
185 void Enable(bool enable);
186 //bool FakePopupMenu(wxMenu* menu, int x, int y);
187 %name(FindWindowById) wxWindow* FindWindow(long id);
188 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
190 wxColour GetBackgroundColour();
192 //wxList& GetChildren();
194 PyObject* GetChildren() {
195 wxWindowList& list = self->GetChildren();
196 return wxPy_ConvertList(&list, "wxWindow");
202 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
203 wxSize GetClientSize();
204 wxLayoutConstraints * GetConstraints();
205 wxEvtHandler* GetEventHandler();
208 wxColour GetForegroundColour();
209 wxWindow * GetGrandParent();
212 return (long)self->GetHandle();
217 void SetLabel(const wxString& label);
219 wxWindow * GetParent();
220 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
221 wxPoint GetPosition();
223 int GetScrollThumb(int orientation);
224 int GetScrollPos(int orientation);
225 int GetScrollRange(int orientation);
226 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
228 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
229 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
230 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
231 const wxFont* font = NULL); //, bool use16 = FALSE)
233 wxRegion GetUpdateRegion();
234 long GetWindowStyleFlag();
242 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
244 void MakeModal(bool flag);
245 %name(MoveXY)void Move(int x, int y);
246 void Move(const wxPoint& point);
248 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
249 void PushEventHandler(wxEvtHandler* handler);
251 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
252 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
255 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
257 bool Reparent( wxWindow* newParent );
259 // (uses apply'ed INOUT typemap, see above)
260 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
261 wxPoint ScreenToClient(const wxPoint& pt);
263 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
264 void SetAcceleratorTable(const wxAcceleratorTable& accel);
265 void SetAutoLayout(bool autoLayout);
266 bool GetAutoLayout();
267 void SetBackgroundColour(const wxColour& colour);
268 void SetConstraints(wxLayoutConstraints *constraints);
269 void UnsetConstraints(wxLayoutConstraints *constraints);
272 void SetFont(const wxFont& font);
273 void SetForegroundColour(const wxColour& colour);
275 void SetName(const wxString& name);
276 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
277 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
279 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
281 void SetSize(const wxSize& size) {
282 self->SetSize(size.x, size.y);
285 void SetPosition(const wxPoint& pos) {
286 self->SetSize(pos.x, pos.y, -1, -1);
290 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
291 %name(SetClientSizeWH)void SetClientSize(int width, int height);
292 void SetClientSize(const wxSize& size);
293 //void SetPalette(wxPalette* palette);
294 void SetCursor(const wxCursor&cursor);
295 void SetEventHandler(wxEvtHandler* handler);
296 void SetTitle(const wxString& title);
297 bool Show(bool show);
298 bool TransferDataFromWindow();
299 bool TransferDataToWindow();
301 void WarpPointer(int x, int y);
303 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
304 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
306 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
307 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
309 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
310 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
312 %name(SetToolTipString)void SetToolTip(const wxString &tip);
313 void SetToolTip(wxToolTip *tooltip);
314 wxToolTip* GetToolTip();
316 void SetSizer(wxSizer* sizer);
317 wxValidator* GetValidator();
318 void SetValidator(const wxValidator& validator);
320 void SetDropTarget(wxDropTarget* target);
321 wxDropTarget* GetDropTarget();
322 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
324 wxSize GetBestSize();
327 //%clear int* x, int* y;
331 %pragma(python) code = "
332 def wxDLG_PNT(win, point_or_x, y=None):
334 return win.ConvertDialogPointToPixels(point_or_x)
336 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
338 def wxDLG_SZE(win, size_width, height=None):
340 return win.ConvertDialogSizeToPixels(size_width)
342 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
347 wxWindow* wxWindow_FindFocus() {
348 return wxWindow::FindFocus();
354 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
355 wxWindow* win = new wxWindow;
357 win->SubclassWin(hWnd);
365 //---------------------------------------------------------------------------
367 class wxPanel : public wxWindow {
369 wxPanel(wxWindow* parent,
371 const wxPoint& pos = wxPyDefaultPosition,
372 const wxSize& size = wxPyDefaultSize,
373 long style = wxTAB_TRAVERSAL,
374 const char* name = "panel");
376 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
379 wxButton* GetDefaultItem();
380 void SetDefaultItem(wxButton *btn);
382 // fix some SWIG trouble...
383 %pragma(python) addtoclass = "
384 def GetDefaultItem(self):
386 val = windowsc.wxPanel_GetDefaultItem(self.this)
387 val = controls.wxButtonPtr(val)
392 //---------------------------------------------------------------------------
394 class wxDialog : public wxPanel {
396 wxDialog(wxWindow* parent,
398 const wxString& title,
399 const wxPoint& pos = wxPyDefaultPosition,
400 const wxSize& size = wxPyDefaultSize,
401 long style = wxDEFAULT_DIALOG_STYLE,
402 const char* name = "dialogBox");
404 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
406 void Centre(int direction = wxBOTH);
407 void EndModal(int retCode);
409 void Iconize(bool iconize);
411 void SetModal(bool flag);
413 void SetTitle(const wxString& title);
414 bool Show(bool show);
418 void SetReturnCode(int retCode);
421 //---------------------------------------------------------------------------
423 class wxScrolledWindow : public wxPanel {
425 wxScrolledWindow(wxWindow* parent,
426 const wxWindowID id = -1,
427 const wxPoint& pos = wxPyDefaultPosition,
428 const wxSize& size = wxPyDefaultSize,
429 long style = wxHSCROLL | wxVSCROLL,
430 char* name = "scrolledWindow");
432 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
433 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
435 void EnableScrolling(bool xScrolling, bool yScrolling);
436 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
437 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
439 void PrepareDC(wxDC& dc);
440 void Scroll(int x, int y);
441 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
442 int noUnitsX, int noUnitsY,
443 int xPos = 0, int yPos = 0);
444 void SetTargetWindow(wxWindow* window);
445 void ViewStart(int* OUTPUT, int* OUTPUT);
447 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
448 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
452 //----------------------------------------------------------------------
455 class wxMenu : public wxEvtHandler {
457 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
459 void Append(int id, const wxString& item,
460 const wxString& helpString = wxPyEmptyStr,
461 int checkable = FALSE);
462 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
463 const wxString& helpString = wxPyEmptyStr);
464 %name(AppendItem)void Append(const wxMenuItem* item);
466 void AppendSeparator();
468 void Check(int id, bool flag);
469 bool IsChecked(int id);
470 void Enable(int id, bool enable);
471 bool IsEnabled(int id);
473 int FindItem(const wxString& itemString);
474 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
477 void SetTitle(const wxString& title);
479 wxString GetLabel(int id);
480 void SetLabel(int id, const wxString& label);
482 wxString GetHelpString(int id);
483 void SetHelpString(int id, const wxString& helpString);
484 void UpdateUI(wxEvtHandler* source = NULL);
487 %name(DeleteItem)bool Delete(wxMenuItem *item);
488 bool Insert(size_t pos, wxMenuItem *item);
489 wxMenuItem *Remove(int id);
490 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
493 void Destroy() { delete self; }
495 %name(DestroyId)bool Destroy(int id);
496 %name(DestroyItem)bool Destroy(wxMenuItem *item);
498 size_t GetMenuItemCount();
499 //wxMenuItemList& GetMenuItems();
501 PyObject* GetMenuItems() {
502 wxMenuItemList& list = self->GetMenuItems();
503 return wxPy_ConvertList(&list, "wxMenuItem");
507 void SetEventHandler(wxEvtHandler *handler);
508 wxEvtHandler *GetEventHandler();
510 void SetInvokingWindow(wxWindow *win);
511 wxWindow *GetInvokingWindow();
517 void SetParent(wxMenu *parent);
522 //----------------------------------------------------------------------
524 class wxMenuBar : public wxWindow {
528 bool Append(wxMenu *menu, const wxString& title);
529 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
530 size_t GetMenuCount();
531 wxMenu *GetMenu(size_t pos);
532 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
533 wxMenu *Remove(size_t pos);
534 void EnableTop(size_t pos, bool enable);
535 void SetLabelTop(size_t pos, const wxString& label);
536 wxString GetLabelTop(size_t pos);
537 int FindMenuItem(const wxString& menuString, const wxString& itemString);
538 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
539 void Enable(int id, bool enable);
540 void Check(int id, bool check);
541 bool IsChecked(int id);
542 bool IsEnabled(int id);
544 void SetLabel(int id, const wxString &label);
545 wxString GetLabel(int id);
547 void SetHelpString(int id, const wxString& helpString);
548 wxString GetHelpString(int id);
553 //----------------------------------------------------------------------
557 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
558 const wxString& text = wxPyEmptyStr,
559 const wxString& help = wxPyEmptyStr,
560 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
567 void SetText(const wxString& str);
569 const wxString& GetText();
570 void SetCheckable(bool checkable);
573 void SetSubMenu(wxMenu *menu);
574 wxMenu *GetSubMenu();
575 void Enable(bool enable = TRUE);
577 void Check(bool check = TRUE);
580 void SetHelp(const wxString& str);
581 const wxString& GetHelp();
582 wxAcceleratorEntry *GetAccel();
583 void SetAccel(wxAcceleratorEntry *accel);
587 //---------------------------------------------------------------------------