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);
313 void SetDropTarget(wxDropTarget* target);
314 wxDropTarget* GetDropTarget();
315 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
318 //%clear int* x, int* y;
322 %pragma(python) code = "
323 def wxDLG_PNT(win, point_or_x, y=None):
325 return win.ConvertDialogPointToPixels(point_or_x)
327 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
329 def wxDLG_SZE(win, size_width, height=None):
331 return win.ConvertDialogSizeToPixels(size_width)
333 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
338 wxWindow* wxWindow_FindFocus() {
339 return wxWindow::FindFocus();
345 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
346 wxWindow* win = new wxWindow;
348 win->SubclassWin(hWnd);
356 //---------------------------------------------------------------------------
358 class wxPanel : public wxWindow {
360 wxPanel(wxWindow* parent,
362 const wxPoint& pos = wxPyDefaultPosition,
363 const wxSize& size = wxPyDefaultSize,
364 long style = wxTAB_TRAVERSAL,
365 const char* name = "panel");
367 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
370 wxButton* GetDefaultItem();
371 void SetDefaultItem(wxButton *btn);
373 // fix some SWIG trouble...
374 %pragma(python) addtoclass = "
375 def GetDefaultItem(self):
377 val = windowsc.wxPanel_GetDefaultItem(self.this)
378 val = controls.wxButtonPtr(val)
383 //---------------------------------------------------------------------------
385 class wxDialog : public wxPanel {
387 wxDialog(wxWindow* parent,
389 const wxString& title,
390 const wxPoint& pos = wxPyDefaultPosition,
391 const wxSize& size = wxPyDefaultSize,
392 long style = wxDEFAULT_DIALOG_STYLE,
393 const char* name = "dialogBox");
395 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
397 void Centre(int direction = wxBOTH);
398 void EndModal(int retCode);
400 void Iconize(bool iconize);
402 void SetModal(bool flag);
404 void SetTitle(const wxString& title);
405 bool Show(bool show);
409 void SetReturnCode(int retCode);
412 //---------------------------------------------------------------------------
414 class wxScrolledWindow : public wxPanel {
416 wxScrolledWindow(wxWindow* parent,
417 const wxWindowID id = -1,
418 const wxPoint& pos = wxPyDefaultPosition,
419 const wxSize& size = wxPyDefaultSize,
420 long style = wxHSCROLL | wxVSCROLL,
421 char* name = "scrolledWindow");
423 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
424 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
426 void EnableScrolling(bool xScrolling, bool yScrolling);
427 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
428 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
430 void PrepareDC(wxDC& dc);
431 void Scroll(int x, int y);
432 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
433 int noUnitsX, int noUnitsY,
434 int xPos = 0, int yPos = 0);
435 void ViewStart(int* OUTPUT, int* OUTPUT);
437 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
438 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
442 //----------------------------------------------------------------------
445 class wxMenu : public wxEvtHandler {
447 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
449 void Append(int id, const wxString& item,
450 const wxString& helpString = wxPyEmptyStr,
451 int checkable = FALSE);
452 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
453 const wxString& helpString = wxPyEmptyStr);
454 %name(AppendItem)void Append(const wxMenuItem* item);
456 void AppendSeparator();
458 void Check(int id, bool flag);
459 bool IsChecked(int id);
460 void Enable(int id, bool enable);
461 bool IsEnabled(int id);
463 int FindItem(const wxString& itemString);
464 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
467 void SetTitle(const wxString& title);
469 wxString GetLabel(int id);
470 void SetLabel(int id, const wxString& label);
472 wxString GetHelpString(int id);
473 void SetHelpString(int id, const wxString& helpString);
474 void UpdateUI(wxEvtHandler* source = NULL);
477 %name(DeleteItem)bool Delete(wxMenuItem *item);
478 bool Insert(size_t pos, wxMenuItem *item);
479 wxMenuItem *Remove(int id);
480 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
487 %name(DestroyId)bool Destroy(int id);
488 %name(DestroyItem)bool Destroy(wxMenuItem *item);
490 size_t GetMenuItemCount();
491 //wxMenuItemList& GetMenuItems();
493 PyObject* GetMenuItems() {
494 wxMenuItemList& list = self->GetMenuItems();
495 return wxPy_ConvertList(&list, "wxMenuItem");
499 void SetEventHandler(wxEvtHandler *handler);
500 wxEvtHandler *GetEventHandler();
502 void SetInvokingWindow(wxWindow *win);
503 wxWindow *GetInvokingWindow();
509 void SetParent(wxMenu *parent);
514 //----------------------------------------------------------------------
516 class wxMenuBar : public wxWindow {
520 bool Append(wxMenu *menu, const wxString& title);
521 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
522 size_t GetMenuCount();
523 wxMenu *GetMenu(size_t pos);
524 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
525 wxMenu *Remove(size_t pos);
526 void EnableTop(size_t pos, bool enable);
527 void SetLabelTop(size_t pos, const wxString& label);
528 wxString GetLabelTop(size_t pos);
529 int FindMenuItem(const wxString& menuString, const wxString& itemString);
530 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
531 void Enable(int id, bool enable);
532 void Check(int id, bool check);
533 bool IsChecked(int id);
534 bool IsEnabled(int id);
536 void SetLabel(int id, const wxString &label);
537 wxString GetLabel(int id);
539 void SetHelpString(int id, const wxString& helpString);
540 wxString GetHelpString(int id);
545 //----------------------------------------------------------------------
549 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
550 const wxString& text = wxPyEmptyStr,
551 const wxString& help = wxPyEmptyStr,
552 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
559 void SetText(const wxString& str);
561 const wxString& GetText();
562 void SetCheckable(bool checkable);
565 void SetSubMenu(wxMenu *menu);
566 wxMenu *GetSubMenu();
567 void Enable(bool enable = TRUE);
569 void Check(bool check = TRUE);
572 void SetHelp(const wxString& str);
573 const wxString& GetHelp();
574 wxAcceleratorEntry *GetAccel();
575 void SetAccel(wxAcceleratorEntry *accel);
578 // wxColour& GetBackgroundColour();
579 // wxBitmap GetBitmap(bool checked = TRUE);
580 // wxFont& GetFont();
581 // int GetMarginWidth();
582 // wxColour& GetTextColour();
583 // void SetBackgroundColour(const wxColour& colour);
584 // void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
585 // void SetFont(const wxFont& font);
586 // void SetMarginWidth(int width);
587 // void SetText(const wxString& str);
588 // const wxString& GetText();
589 // void SetTextColour(const wxColour& colour);
590 // void DeleteSubMenu();
591 // void SetCheckable(bool checkable);
592 // void SetSubMenu(wxMenu *menu);
596 //---------------------------------------------------------------------------