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);
116 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
117 DEC_PYCALLBACK_BOOL_(TransferToWindow);
118 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
124 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
125 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
126 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
128 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
132 class wxPyValidator : public wxValidator {
138 void Destroy() { delete self; }
141 void _setSelf(PyObject* self, int incref=TRUE);
142 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
146 //----------------------------------------------------------------------
148 %apply int * INOUT { int* x, int* y };
150 class wxWindow : public wxEvtHandler {
153 wxWindow(wxWindow* parent, const wxWindowID id,
154 const wxPoint& pos = wxPyDefaultPosition,
155 const wxSize& size = wxPyDefaultSize,
157 char* name = "panel");
159 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
162 void Center(int direction = wxBOTH);
163 void Centre(int direction = wxBOTH);
164 void CentreOnParent(int direction = wxBOTH );
165 void CenterOnParent(int direction = wxBOTH );
167 // (uses apply'ed INOUT typemap, see above)
168 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
169 wxPoint ClientToScreen(const wxPoint& pt);
171 bool Close(int force = FALSE);
173 void DestroyChildren();
175 void DragAcceptFiles(bool accept);
177 void Enable(bool enable);
178 //bool FakePopupMenu(wxMenu* menu, int x, int y);
179 %name(FindWindowById) wxWindow* FindWindow(long id);
180 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
182 wxColour GetBackgroundColour();
184 //wxList& GetChildren();
186 PyObject* GetChildren() {
187 wxWindowList& list = self->GetChildren();
188 return wxPy_ConvertList(&list, "wxWindow");
194 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
195 wxSize GetClientSize();
196 wxLayoutConstraints * GetConstraints();
197 wxEvtHandler* GetEventHandler();
200 wxColour GetForegroundColour();
201 wxWindow * GetGrandParent();
204 return (long)self->GetHandle();
209 void SetLabel(const wxString& label);
211 wxWindow * GetParent();
212 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
213 wxPoint GetPosition();
215 int GetScrollThumb(int orientation);
216 int GetScrollPos(int orientation);
217 int GetScrollRange(int orientation);
218 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
220 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
221 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
222 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
223 const wxFont* font = NULL); //, bool use16 = FALSE)
225 wxRegion GetUpdateRegion();
226 long GetWindowStyleFlag();
234 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
236 void MakeModal(bool flag);
237 %name(MoveXY)void Move(int x, int y);
238 void Move(const wxPoint& point);
240 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
241 void PushEventHandler(wxEvtHandler* handler);
243 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
244 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
247 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
249 bool Reparent( wxWindow* newParent );
251 // (uses apply'ed INOUT typemap, see above)
252 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
253 wxPoint ScreenToClient(const wxPoint& pt);
255 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
256 void SetAcceleratorTable(const wxAcceleratorTable& accel);
257 void SetAutoLayout(bool autoLayout);
258 bool GetAutoLayout();
259 void SetBackgroundColour(const wxColour& colour);
260 void SetConstraints(wxLayoutConstraints *constraints);
261 void UnsetConstraints(wxLayoutConstraints *constraints);
264 void SetFont(const wxFont& font);
265 void SetForegroundColour(const wxColour& colour);
267 void SetName(const wxString& name);
268 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
269 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
271 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
273 void SetSize(const wxSize& size) {
274 self->SetSize(size.x, size.y);
277 void SetPosition(const wxPoint& pos) {
278 self->SetSize(pos.x, pos.y, -1, -1);
282 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
283 %name(SetClientSizeWH)void SetClientSize(int width, int height);
284 void SetClientSize(const wxSize& size);
285 //void SetPalette(wxPalette* palette);
286 void SetCursor(const wxCursor&cursor);
287 void SetEventHandler(wxEvtHandler* handler);
288 void SetTitle(const wxString& title);
289 bool Show(bool show);
290 bool TransferDataFromWindow();
291 bool TransferDataToWindow();
293 void WarpPointer(int x, int y);
295 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
296 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
298 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
299 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
301 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
302 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
304 %name(SetToolTipString)void SetToolTip(const wxString &tip);
305 void SetToolTip(wxToolTip *tooltip);
306 wxToolTip* GetToolTip();
308 void SetSizer(wxSizer* sizer);
309 wxValidator* GetValidator();
310 void SetValidator(const wxValidator& validator);
312 void SetDropTarget(wxDropTarget* target);
313 wxDropTarget* GetDropTarget();
314 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
316 wxSize GetBestSize();
319 //%clear int* x, int* y;
323 %pragma(python) code = "
324 def wxDLG_PNT(win, point_or_x, y=None):
326 return win.ConvertDialogPointToPixels(point_or_x)
328 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
330 def wxDLG_SZE(win, size_width, height=None):
332 return win.ConvertDialogSizeToPixels(size_width)
334 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
339 wxWindow* wxWindow_FindFocus() {
340 return wxWindow::FindFocus();
346 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
347 wxWindow* win = new wxWindow;
349 win->SubclassWin(hWnd);
357 //---------------------------------------------------------------------------
359 class wxPanel : public wxWindow {
361 wxPanel(wxWindow* parent,
363 const wxPoint& pos = wxPyDefaultPosition,
364 const wxSize& size = wxPyDefaultSize,
365 long style = wxTAB_TRAVERSAL,
366 const char* name = "panel");
368 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
371 wxButton* GetDefaultItem();
372 void SetDefaultItem(wxButton *btn);
374 // fix some SWIG trouble...
375 %pragma(python) addtoclass = "
376 def GetDefaultItem(self):
378 val = windowsc.wxPanel_GetDefaultItem(self.this)
379 val = controls.wxButtonPtr(val)
384 //---------------------------------------------------------------------------
386 class wxDialog : public wxPanel {
388 wxDialog(wxWindow* parent,
390 const wxString& title,
391 const wxPoint& pos = wxPyDefaultPosition,
392 const wxSize& size = wxPyDefaultSize,
393 long style = wxDEFAULT_DIALOG_STYLE,
394 const char* name = "dialogBox");
396 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
398 void Centre(int direction = wxBOTH);
399 void EndModal(int retCode);
401 void Iconize(bool iconize);
403 void SetModal(bool flag);
405 void SetTitle(const wxString& title);
406 bool Show(bool show);
410 void SetReturnCode(int retCode);
413 //---------------------------------------------------------------------------
415 class wxScrolledWindow : public wxPanel {
417 wxScrolledWindow(wxWindow* parent,
418 const wxWindowID id = -1,
419 const wxPoint& pos = wxPyDefaultPosition,
420 const wxSize& size = wxPyDefaultSize,
421 long style = wxHSCROLL | wxVSCROLL,
422 char* name = "scrolledWindow");
424 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
425 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
427 void EnableScrolling(bool xScrolling, bool yScrolling);
428 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
429 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
431 void PrepareDC(wxDC& dc);
432 void Scroll(int x, int y);
433 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
434 int noUnitsX, int noUnitsY,
435 int xPos = 0, int yPos = 0);
436 void ViewStart(int* OUTPUT, int* OUTPUT);
438 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
439 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
443 //----------------------------------------------------------------------
446 class wxMenu : public wxEvtHandler {
448 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
450 void Append(int id, const wxString& item,
451 const wxString& helpString = wxPyEmptyStr,
452 int checkable = FALSE);
453 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
454 const wxString& helpString = wxPyEmptyStr);
455 %name(AppendItem)void Append(const wxMenuItem* item);
457 void AppendSeparator();
459 void Check(int id, bool flag);
460 bool IsChecked(int id);
461 void Enable(int id, bool enable);
462 bool IsEnabled(int id);
464 int FindItem(const wxString& itemString);
465 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
468 void SetTitle(const wxString& title);
470 wxString GetLabel(int id);
471 void SetLabel(int id, const wxString& label);
473 wxString GetHelpString(int id);
474 void SetHelpString(int id, const wxString& helpString);
475 void UpdateUI(wxEvtHandler* source = NULL);
478 %name(DeleteItem)bool Delete(wxMenuItem *item);
479 bool Insert(size_t pos, wxMenuItem *item);
480 wxMenuItem *Remove(int id);
481 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
488 %name(DestroyId)bool Destroy(int id);
489 %name(DestroyItem)bool Destroy(wxMenuItem *item);
491 size_t GetMenuItemCount();
492 //wxMenuItemList& GetMenuItems();
494 PyObject* GetMenuItems() {
495 wxMenuItemList& list = self->GetMenuItems();
496 return wxPy_ConvertList(&list, "wxMenuItem");
500 void SetEventHandler(wxEvtHandler *handler);
501 wxEvtHandler *GetEventHandler();
503 void SetInvokingWindow(wxWindow *win);
504 wxWindow *GetInvokingWindow();
510 void SetParent(wxMenu *parent);
515 //----------------------------------------------------------------------
517 class wxMenuBar : public wxWindow {
521 bool Append(wxMenu *menu, const wxString& title);
522 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
523 size_t GetMenuCount();
524 wxMenu *GetMenu(size_t pos);
525 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
526 wxMenu *Remove(size_t pos);
527 void EnableTop(size_t pos, bool enable);
528 void SetLabelTop(size_t pos, const wxString& label);
529 wxString GetLabelTop(size_t pos);
530 int FindMenuItem(const wxString& menuString, const wxString& itemString);
531 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
532 void Enable(int id, bool enable);
533 void Check(int id, bool check);
534 bool IsChecked(int id);
535 bool IsEnabled(int id);
537 void SetLabel(int id, const wxString &label);
538 wxString GetLabel(int id);
540 void SetHelpString(int id, const wxString& helpString);
541 wxString GetHelpString(int id);
546 //----------------------------------------------------------------------
550 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
551 const wxString& text = wxPyEmptyStr,
552 const wxString& help = wxPyEmptyStr,
553 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
560 void SetText(const wxString& str);
562 const wxString& GetText();
563 void SetCheckable(bool checkable);
566 void SetSubMenu(wxMenu *menu);
567 wxMenu *GetSubMenu();
568 void Enable(bool enable = TRUE);
570 void Check(bool check = TRUE);
573 void SetHelp(const wxString& str);
574 const wxString& GetHelp();
575 wxAcceleratorEntry *GetAccel();
576 void SetAccel(wxAcceleratorEntry *accel);
580 //---------------------------------------------------------------------------