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 (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();
240 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
242 void MakeModal(bool flag);
243 %name(MoveXY)void Move(int x, int y);
244 void Move(const wxPoint& point);
246 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
247 void PushEventHandler(wxEvtHandler* handler);
249 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
250 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
253 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
255 bool Reparent( wxWindow* newParent );
257 // (uses apply'ed INOUT typemap, see above)
258 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
259 wxPoint ScreenToClient(const wxPoint& pt);
261 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
262 void SetAcceleratorTable(const wxAcceleratorTable& accel);
263 void SetAutoLayout(bool autoLayout);
264 bool GetAutoLayout();
265 void SetBackgroundColour(const wxColour& colour);
266 void SetConstraints(wxLayoutConstraints *constraints);
267 void UnsetConstraints(wxLayoutConstraints *constraints);
270 void SetFont(const wxFont& font);
271 void SetForegroundColour(const wxColour& colour);
273 void SetName(const wxString& name);
274 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
275 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
277 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
279 void SetSize(const wxSize& size) {
280 self->SetSize(size.x, size.y);
283 void SetPosition(const wxPoint& pos) {
284 self->SetSize(pos.x, pos.y, -1, -1);
288 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
289 %name(SetClientSizeWH)void SetClientSize(int width, int height);
290 void SetClientSize(const wxSize& size);
291 //void SetPalette(wxPalette* palette);
292 void SetCursor(const wxCursor&cursor);
293 void SetEventHandler(wxEvtHandler* handler);
294 void SetTitle(const wxString& title);
295 bool Show(bool show);
296 bool TransferDataFromWindow();
297 bool TransferDataToWindow();
299 void WarpPointer(int x, int y);
301 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
302 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
304 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
305 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
307 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
308 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
310 %name(SetToolTipString)void SetToolTip(const wxString &tip);
311 void SetToolTip(wxToolTip *tooltip);
312 wxToolTip* GetToolTip();
314 void SetSizer(wxSizer* sizer);
315 wxValidator* GetValidator();
316 void SetValidator(const wxValidator& validator);
318 void SetDropTarget(wxDropTarget* target);
319 wxDropTarget* GetDropTarget();
320 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
322 wxSize GetBestSize();
325 //%clear int* x, int* y;
329 %pragma(python) code = "
330 def wxDLG_PNT(win, point_or_x, y=None):
332 return win.ConvertDialogPointToPixels(point_or_x)
334 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
336 def wxDLG_SZE(win, size_width, height=None):
338 return win.ConvertDialogSizeToPixels(size_width)
340 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
345 wxWindow* wxWindow_FindFocus() {
346 return wxWindow::FindFocus();
352 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
353 wxWindow* win = new wxWindow;
355 win->SubclassWin(hWnd);
363 //---------------------------------------------------------------------------
365 class wxPanel : public wxWindow {
367 wxPanel(wxWindow* parent,
369 const wxPoint& pos = wxPyDefaultPosition,
370 const wxSize& size = wxPyDefaultSize,
371 long style = wxTAB_TRAVERSAL,
372 const char* name = "panel");
374 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
377 wxButton* GetDefaultItem();
378 void SetDefaultItem(wxButton *btn);
380 // fix some SWIG trouble...
381 %pragma(python) addtoclass = "
382 def GetDefaultItem(self):
384 val = windowsc.wxPanel_GetDefaultItem(self.this)
385 val = controls.wxButtonPtr(val)
390 //---------------------------------------------------------------------------
392 class wxDialog : public wxPanel {
394 wxDialog(wxWindow* parent,
396 const wxString& title,
397 const wxPoint& pos = wxPyDefaultPosition,
398 const wxSize& size = wxPyDefaultSize,
399 long style = wxDEFAULT_DIALOG_STYLE,
400 const char* name = "dialogBox");
402 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
404 void Centre(int direction = wxBOTH);
405 void EndModal(int retCode);
407 void Iconize(bool iconize);
409 void SetModal(bool flag);
411 void SetTitle(const wxString& title);
412 bool Show(bool show);
416 void SetReturnCode(int retCode);
419 //---------------------------------------------------------------------------
421 class wxScrolledWindow : public wxPanel {
423 wxScrolledWindow(wxWindow* parent,
424 const wxWindowID id = -1,
425 const wxPoint& pos = wxPyDefaultPosition,
426 const wxSize& size = wxPyDefaultSize,
427 long style = wxHSCROLL | wxVSCROLL,
428 char* name = "scrolledWindow");
430 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
431 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
433 void EnableScrolling(bool xScrolling, bool yScrolling);
434 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
435 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
437 void PrepareDC(wxDC& dc);
438 void Scroll(int x, int y);
439 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
440 int noUnitsX, int noUnitsY,
441 int xPos = 0, int yPos = 0);
442 void SetTargetWindow(wxWindow* window);
443 void ViewStart(int* OUTPUT, int* OUTPUT);
445 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
446 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
450 //----------------------------------------------------------------------
453 class wxMenu : public wxEvtHandler {
455 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
457 void Append(int id, const wxString& item,
458 const wxString& helpString = wxPyEmptyStr,
459 int checkable = FALSE);
460 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
461 const wxString& helpString = wxPyEmptyStr);
462 %name(AppendItem)void Append(const wxMenuItem* item);
464 void AppendSeparator();
466 void Check(int id, bool flag);
467 bool IsChecked(int id);
468 void Enable(int id, bool enable);
469 bool IsEnabled(int id);
471 int FindItem(const wxString& itemString);
472 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
475 void SetTitle(const wxString& title);
477 wxString GetLabel(int id);
478 void SetLabel(int id, const wxString& label);
480 wxString GetHelpString(int id);
481 void SetHelpString(int id, const wxString& helpString);
482 void UpdateUI(wxEvtHandler* source = NULL);
485 %name(DeleteItem)bool Delete(wxMenuItem *item);
486 bool Insert(size_t pos, wxMenuItem *item);
487 wxMenuItem *Remove(int id);
488 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
491 void Destroy() { delete self; }
493 %name(DestroyId)bool Destroy(int id);
494 %name(DestroyItem)bool Destroy(wxMenuItem *item);
496 size_t GetMenuItemCount();
497 //wxMenuItemList& GetMenuItems();
499 PyObject* GetMenuItems() {
500 wxMenuItemList& list = self->GetMenuItems();
501 return wxPy_ConvertList(&list, "wxMenuItem");
505 void SetEventHandler(wxEvtHandler *handler);
506 wxEvtHandler *GetEventHandler();
508 void SetInvokingWindow(wxWindow *win);
509 wxWindow *GetInvokingWindow();
515 void SetParent(wxMenu *parent);
520 //----------------------------------------------------------------------
522 class wxMenuBar : public wxWindow {
526 bool Append(wxMenu *menu, const wxString& title);
527 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
528 size_t GetMenuCount();
529 wxMenu *GetMenu(size_t pos);
530 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
531 wxMenu *Remove(size_t pos);
532 void EnableTop(size_t pos, bool enable);
533 void SetLabelTop(size_t pos, const wxString& label);
534 wxString GetLabelTop(size_t pos);
535 int FindMenuItem(const wxString& menuString, const wxString& itemString);
536 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
537 void Enable(int id, bool enable);
538 void Check(int id, bool check);
539 bool IsChecked(int id);
540 bool IsEnabled(int id);
542 void SetLabel(int id, const wxString &label);
543 wxString GetLabel(int id);
545 void SetHelpString(int id, const wxString& helpString);
546 wxString GetHelpString(int id);
551 //----------------------------------------------------------------------
555 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
556 const wxString& text = wxPyEmptyStr,
557 const wxString& help = wxPyEmptyStr,
558 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
565 void SetText(const wxString& str);
567 const wxString& GetText();
568 void SetCheckable(bool checkable);
571 void SetSubMenu(wxMenu *menu);
572 wxMenu *GetSubMenu();
573 void Enable(bool enable = TRUE);
575 void Check(bool check = TRUE);
578 void SetHelp(const wxString& str);
579 const wxString& GetHelp();
580 wxAcceleratorEntry *GetAccel();
581 void SetAccel(wxAcceleratorEntry *accel);
585 //---------------------------------------------------------------------------