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 {
145 %addmethods { void Destroy() { delete self; } }
147 void _setSelf(PyObject* self, int incref=TRUE);
148 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
152 //----------------------------------------------------------------------
154 %apply int * INOUT { int* x, int* y };
156 class wxWindow : public wxEvtHandler {
159 wxWindow(wxWindow* parent, const wxWindowID id,
160 const wxPoint& pos = wxPyDefaultPosition,
161 const wxSize& size = wxPyDefaultSize,
163 char* name = "panel");
165 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
168 void Center(int direction = wxBOTH);
169 void Centre(int direction = wxBOTH);
170 void CentreOnParent(int direction = wxBOTH );
171 void CenterOnParent(int direction = wxBOTH );
173 // (uses apply'ed INOUT typemap, see above)
174 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
175 wxPoint ClientToScreen(const wxPoint& pt);
177 bool Close(int force = FALSE);
179 void DestroyChildren();
181 void DragAcceptFiles(bool accept);
183 void Enable(bool enable);
184 //bool FakePopupMenu(wxMenu* menu, int x, int y);
185 %name(FindWindowById) wxWindow* FindWindow(long id);
186 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
188 wxColour GetBackgroundColour();
190 //wxList& GetChildren();
192 PyObject* GetChildren() {
193 wxWindowList& list = self->GetChildren();
194 return wxPy_ConvertList(&list, "wxWindow");
200 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
201 wxSize GetClientSize();
202 wxLayoutConstraints * GetConstraints();
203 wxEvtHandler* GetEventHandler();
206 wxColour GetForegroundColour();
207 wxWindow * GetGrandParent();
210 return wxPyGetWinHandle(self); //(long)self->GetHandle();
215 void SetLabel(const wxString& label);
217 wxWindow * GetParent();
218 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
219 wxPoint GetPosition();
221 int GetScrollThumb(int orientation);
222 int GetScrollPos(int orientation);
223 int GetScrollRange(int orientation);
224 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
226 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
227 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
228 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
229 const wxFont* font = NULL); //, bool use16 = FALSE)
231 wxRegion GetUpdateRegion();
232 long GetWindowStyleFlag();
236 bool IsExposed( int x, int y, int w=0, int h=0 );
237 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
238 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
243 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
245 void MakeModal(bool flag);
246 %name(MoveXY)void Move(int x, int y);
247 void Move(const wxPoint& point);
249 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
250 void PushEventHandler(wxEvtHandler* handler);
252 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
253 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
256 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
258 void RemoveChild(wxWindow* child);
259 bool Reparent( wxWindow* newParent );
261 // (uses apply'ed INOUT typemap, see above)
262 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
263 wxPoint ScreenToClient(const wxPoint& pt);
265 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
266 void SetAcceleratorTable(const wxAcceleratorTable& accel);
267 void SetAutoLayout(bool autoLayout);
268 bool GetAutoLayout();
269 void SetBackgroundColour(const wxColour& colour);
270 void SetConstraints(wxLayoutConstraints *constraints);
271 void UnsetConstraints(wxLayoutConstraints *constraints);
274 void SetFont(const wxFont& font);
275 void SetForegroundColour(const wxColour& colour);
277 void SetName(const wxString& name);
278 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
279 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
281 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
283 void SetSize(const wxSize& size) {
287 void SetPosition(const wxPoint& pos) {
292 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
293 %name(SetClientSizeWH)void SetClientSize(int width, int height);
294 void SetClientSize(const wxSize& size);
295 //void SetPalette(wxPalette* palette);
296 void SetCursor(const wxCursor&cursor);
297 void SetEventHandler(wxEvtHandler* handler);
298 void SetTitle(const wxString& title);
299 bool Show(bool show);
300 bool TransferDataFromWindow();
301 bool TransferDataToWindow();
303 void WarpPointer(int x, int y);
305 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
306 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
308 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
309 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
311 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
312 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
314 %name(SetToolTipString)void SetToolTip(const wxString &tip);
315 void SetToolTip(wxToolTip *tooltip);
316 wxToolTip* GetToolTip();
318 void SetSizer(wxSizer* sizer);
319 wxValidator* GetValidator();
320 void SetValidator(const wxValidator& validator);
322 void SetDropTarget(wxDropTarget* target);
323 wxDropTarget* GetDropTarget();
324 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
326 wxSize GetBestSize();
328 void SetCaret(wxCaret *caret);
330 %pragma(python) addtoclass = "# replaces broken shadow method
331 def GetCaret(self, *_args, **_kwargs):
332 from misc2 import wxCaretPtr
333 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
334 if val: val = wxCaretPtr(val)
339 //%clear int* x, int* y;
343 %pragma(python) code = "
344 def wxDLG_PNT(win, point_or_x, y=None):
346 return win.ConvertDialogPointToPixels(point_or_x)
348 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
350 def wxDLG_SZE(win, size_width, height=None):
352 return win.ConvertDialogSizeToPixels(size_width)
354 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
359 wxWindow* wxWindow_FindFocus() {
360 return wxWindow::FindFocus();
366 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
367 wxWindow* win = new wxWindow;
369 win->SubclassWin(hWnd);
376 int wxWindow_NewControlId() {
377 return wxWindow::NewControlId();
379 int wxWindow_NextControlId(int id) {
380 return wxWindow::NextControlId(id);
382 int wxWindow_PrevControlId(int id) {
383 return wxWindow::PrevControlId(id);
388 //---------------------------------------------------------------------------
390 class wxPanel : public wxWindow {
392 wxPanel(wxWindow* parent,
394 const wxPoint& pos = wxPyDefaultPosition,
395 const wxSize& size = wxPyDefaultSize,
396 long style = wxTAB_TRAVERSAL,
397 const char* name = "panel");
399 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
402 wxButton* GetDefaultItem();
403 void SetDefaultItem(wxButton *btn);
405 // fix some SWIG trouble...
406 %pragma(python) addtoclass = "
407 def GetDefaultItem(self):
409 val = windowsc.wxPanel_GetDefaultItem(self.this)
410 val = controls.wxButtonPtr(val)
415 //---------------------------------------------------------------------------
417 class wxDialog : public wxPanel {
419 wxDialog(wxWindow* parent,
421 const wxString& title,
422 const wxPoint& pos = wxPyDefaultPosition,
423 const wxSize& size = wxPyDefaultSize,
424 long style = wxDEFAULT_DIALOG_STYLE,
425 const char* name = "dialogBox");
427 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
429 void Centre(int direction = wxBOTH);
430 void EndModal(int retCode);
432 void Iconize(bool iconize);
434 void SetModal(bool flag);
436 void SetTitle(const wxString& title);
437 bool Show(bool show);
441 void SetReturnCode(int retCode);
444 //---------------------------------------------------------------------------
446 class wxScrolledWindow : public wxPanel {
448 wxScrolledWindow(wxWindow* parent,
449 const wxWindowID id = -1,
450 const wxPoint& pos = wxPyDefaultPosition,
451 const wxSize& size = wxPyDefaultSize,
452 long style = wxHSCROLL | wxVSCROLL,
453 char* name = "scrolledWindow");
455 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
456 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
458 void EnableScrolling(bool xScrolling, bool yScrolling);
459 int GetScrollPageSize(int orient);
460 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
461 wxWindow* GetTargetWindow();
462 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
464 void PrepareDC(wxDC& dc);
465 void Scroll(int x, int y);
466 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
467 int noUnitsX, int noUnitsY,
468 int xPos = 0, int yPos = 0);
469 void SetScrollPageSize(int orient, int pageSize);
470 void SetTargetWindow(wxWindow* window);
471 void ViewStart(int* OUTPUT, int* OUTPUT);
473 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
474 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
478 //----------------------------------------------------------------------
481 class wxMenu : public wxEvtHandler {
483 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
485 void Append(int id, const wxString& item,
486 const wxString& helpString = wxPyEmptyStr,
487 int checkable = FALSE);
488 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
489 const wxString& helpString = wxPyEmptyStr);
490 %name(AppendItem)void Append(const wxMenuItem* item);
492 void AppendSeparator();
494 void Check(int id, bool flag);
495 bool IsChecked(int id);
496 void Enable(int id, bool enable);
497 bool IsEnabled(int id);
499 int FindItem(const wxString& itemString);
500 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
503 void SetTitle(const wxString& title);
505 wxString GetLabel(int id);
506 void SetLabel(int id, const wxString& label);
508 wxString GetHelpString(int id);
509 void SetHelpString(int id, const wxString& helpString);
510 void UpdateUI(wxEvtHandler* source = NULL);
513 %name(DeleteItem)bool Delete(wxMenuItem *item);
514 bool Insert(size_t pos, wxMenuItem *item);
515 wxMenuItem *Remove(int id);
516 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
519 void Destroy() { delete self; }
521 %name(DestroyId)bool Destroy(int id);
522 %name(DestroyItem)bool Destroy(wxMenuItem *item);
524 size_t GetMenuItemCount();
525 //wxMenuItemList& GetMenuItems();
527 PyObject* GetMenuItems() {
528 wxMenuItemList& list = self->GetMenuItems();
529 return wxPy_ConvertList(&list, "wxMenuItem");
533 void SetEventHandler(wxEvtHandler *handler);
534 wxEvtHandler *GetEventHandler();
536 void SetInvokingWindow(wxWindow *win);
537 wxWindow *GetInvokingWindow();
543 void SetParent(wxMenu *parent);
548 //----------------------------------------------------------------------
550 class wxMenuBar : public wxWindow {
554 bool Append(wxMenu *menu, const wxString& title);
555 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
556 size_t GetMenuCount();
557 wxMenu *GetMenu(size_t pos);
558 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
559 wxMenu *Remove(size_t pos);
560 void EnableTop(size_t pos, bool enable);
561 void SetLabelTop(size_t pos, const wxString& label);
562 wxString GetLabelTop(size_t pos);
563 int FindMenuItem(const wxString& menuString, const wxString& itemString);
564 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
565 void Enable(int id, bool enable);
566 void Check(int id, bool check);
567 bool IsChecked(int id);
568 bool IsEnabled(int id);
570 void SetLabel(int id, const wxString &label);
571 wxString GetLabel(int id);
573 void SetHelpString(int id, const wxString& helpString);
574 wxString GetHelpString(int id);
579 //----------------------------------------------------------------------
583 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
584 const wxString& text = wxPyEmptyStr,
585 const wxString& help = wxPyEmptyStr,
586 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
593 void SetText(const wxString& str);
595 const wxString& GetText();
596 void SetCheckable(bool checkable);
599 void SetSubMenu(wxMenu *menu);
600 wxMenu *GetSubMenu();
601 void Enable(bool enable = TRUE);
603 void Check(bool check = TRUE);
606 void SetHelp(const wxString& str);
607 const wxString& GetHelp();
608 wxAcceleratorEntry *GetAccel();
609 void SetAccel(wxAcceleratorEntry *accel);
613 //---------------------------------------------------------------------------