]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
Squashed another threading and interpreter lock bug
[wxWidgets.git] / utils / wxPython / src / windows.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.i
3 // Purpose: SWIG definitions of various window classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 6/24/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 %module windows
15
16 %{
17 #include "helpers.h"
18 #include <wx/menuitem.h>
19 %}
20
21 //----------------------------------------------------------------------
22
23 %include typemaps.i
24 %include my_typemaps.i
25
26 // Import some definitions of other classes, etc.
27 %import _defs.i
28 %import misc.i
29 %import gdi.i
30
31
32 %pragma(python) code = "import wx"
33
34 //---------------------------------------------------------------------------
35
36 class wxEvtHandler {
37 public:
38 bool ProcessEvent(wxEvent& event);
39 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
40
41 bool GetEvtHandlerEnabled();
42 void SetEvtHandlerEnabled(bool enabled);
43
44 wxEvtHandler* GetNextHandler();
45 wxEvtHandler* GetPreviousHandler();
46 void SetNextHandler(wxEvtHandler* handler);
47 void SetPreviousHandler(wxEvtHandler* handler);
48
49
50 %addmethods {
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));
56 }
57 }
58 }
59 };
60
61
62 //----------------------------------------------------------------------
63
64 class wxValidator : public wxEvtHandler {
65 public:
66 wxValidator();
67 //~wxValidator();
68
69 wxValidator* Clone();
70 wxWindow* GetWindow();
71 void SetWindow(wxWindow* window);
72 };
73
74 %inline %{
75 bool wxValidator_IsSilent() {
76 return wxValidator::IsSilent();
77 }
78
79 void wxValidator_SetBellOnError(int doIt = TRUE) {
80 wxValidator::SetBellOnError(doIt);
81 }
82 %}
83
84 //----------------------------------------------------------------------
85 %{
86 class wxPyValidator : public wxValidator {
87 DECLARE_DYNAMIC_CLASS(wxPyValidator);
88 public:
89 wxPyValidator() {
90 }
91 // wxPyValidator(const wxPyValidator& other);
92
93 ~wxPyValidator() {
94 }
95
96 wxObject* wxPyValidator::Clone() const {
97 wxPyValidator* ptr = NULL;
98 wxPyValidator* self = (wxPyValidator*)this;
99
100 bool doSave = wxPyRestoreThread();
101 if (self->m_myInst.findCallback("Clone")) {
102 PyObject* ro;
103 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
104 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
105 }
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
109 // could arise.
110 delete self;
111
112 wxPySaveThread(doSave);
113 return ptr;
114 }
115
116
117 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
118 DEC_PYCALLBACK_BOOL_(TransferToWindow);
119 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
120
121 PYPRIVATE;
122 // PyObject* m_data;
123 };
124
125 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
126 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
127 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
128
129 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
130
131 %}
132
133 class wxPyValidator : public wxValidator {
134 public:
135 wxPyValidator();
136 // ~wxPyValidator();
137
138 %addmethods {
139 void Destroy() { delete self; }
140 }
141
142 void _setSelf(PyObject* self, int incref=TRUE);
143 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
144
145 };
146
147 //----------------------------------------------------------------------
148
149 %apply int * INOUT { int* x, int* y };
150
151 class wxWindow : public wxEvtHandler {
152 public:
153
154 wxWindow(wxWindow* parent, const wxWindowID id,
155 const wxPoint& pos = wxPyDefaultPosition,
156 const wxSize& size = wxPyDefaultSize,
157 long style = 0,
158 char* name = "panel");
159
160 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
161
162 void CaptureMouse();
163 void Center(int direction = wxBOTH);
164 void Centre(int direction = wxBOTH);
165 void CentreOnParent(int direction = wxBOTH );
166 void CenterOnParent(int direction = wxBOTH );
167
168 // (uses apply'ed INOUT typemap, see above)
169 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
170 wxPoint ClientToScreen(const wxPoint& pt);
171
172 bool Close(int force = FALSE);
173 bool Destroy();
174 void DestroyChildren();
175 #ifdef __WXMSW__
176 void DragAcceptFiles(bool accept);
177 #endif
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);
182 void Fit();
183 wxColour GetBackgroundColour();
184
185 //wxList& GetChildren();
186 %addmethods {
187 PyObject* GetChildren() {
188 wxWindowList& list = self->GetChildren();
189 return wxPy_ConvertList(&list, "wxWindow");
190 }
191 }
192
193
194 int GetCharHeight();
195 int GetCharWidth();
196 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
197 wxSize GetClientSize();
198 wxLayoutConstraints * GetConstraints();
199 wxEvtHandler* GetEventHandler();
200
201 wxFont& GetFont();
202 wxColour GetForegroundColour();
203 wxWindow * GetGrandParent();
204 int GetId();
205 wxString GetLabel();
206 void SetLabel(const wxString& label);
207 wxString GetName();
208 wxWindow * GetParent();
209 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
210 wxPoint GetPosition();
211 wxRect GetRect();
212 int GetScrollThumb(int orientation);
213 int GetScrollPos(int orientation);
214 int GetScrollRange(int orientation);
215 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
216 wxSize GetSize();
217 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
218 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
219 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
220 const wxFont* font = NULL); //, bool use16 = FALSE)
221 wxString GetTitle();
222 wxRegion GetUpdateRegion();
223 long GetWindowStyleFlag();
224 bool Hide();
225 void InitDialog();
226 bool IsEnabled();
227 bool IsRetained();
228 bool IsShown();
229 bool IsTopLevel();
230 void Layout();
231 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
232 void Lower();
233 void MakeModal(bool flag);
234 %name(MoveXY)void Move(int x, int y);
235 void Move(const wxPoint& point);
236
237 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
238 void PushEventHandler(wxEvtHandler* handler);
239
240 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
241 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
242
243 void Raise();
244 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
245 void ReleaseMouse();
246 bool Reparent( wxWindow* newParent );
247
248 // (uses apply'ed INOUT typemap, see above)
249 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
250 wxPoint ScreenToClient(const wxPoint& pt);
251
252 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
253 void SetAcceleratorTable(const wxAcceleratorTable& accel);
254 void SetAutoLayout(bool autoLayout);
255 bool GetAutoLayout();
256 void SetBackgroundColour(const wxColour& colour);
257 void SetConstraints(wxLayoutConstraints *constraints);
258 void UnsetConstraints(wxLayoutConstraints *constraints);
259 void SetFocus();
260 bool AcceptsFocus();
261 void SetFont(const wxFont& font);
262 void SetForegroundColour(const wxColour& colour);
263 void SetId(int id);
264 void SetName(const wxString& name);
265 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
266 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
267
268 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
269 %addmethods {
270 void SetSize(const wxSize& size) {
271 self->SetSize(size.x, size.y);
272 }
273
274 void SetPosition(const wxPoint& pos) {
275 self->SetSize(pos.x, pos.y, -1, -1);
276 }
277 }
278
279 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
280 %name(SetClientSizeWH)void SetClientSize(int width, int height);
281 void SetClientSize(const wxSize& size);
282 //void SetPalette(wxPalette* palette);
283 void SetCursor(const wxCursor&cursor);
284 void SetEventHandler(wxEvtHandler* handler);
285 void SetTitle(const wxString& title);
286 bool Show(bool show);
287 bool TransferDataFromWindow();
288 bool TransferDataToWindow();
289 bool Validate();
290 void WarpPointer(int x, int y);
291
292 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
293 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
294
295 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
296 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
297
298 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
299 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
300
301 %name(SetToolTipString)void SetToolTip(const wxString &tip);
302 void SetToolTip(wxToolTip *tooltip);
303 wxToolTip* GetToolTip();
304
305 void SetSizer(wxSizer* sizer);
306 wxValidator* GetValidator();
307 void SetValidator(const wxValidator& validator);
308
309 };
310
311 //%clear int* x, int* y;
312
313
314
315 %pragma(python) code = "
316 def wxDLG_PNT(win, point_or_x, y=None):
317 if y is None:
318 return win.ConvertDialogPointToPixels(point_or_x)
319 else:
320 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
321
322 def wxDLG_SZE(win, size_width, height=None):
323 if height is None:
324 return win.ConvertDialogSizeToPixels(size_width)
325 else:
326 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
327 "
328
329 #ifdef __WXMSW__
330 %inline %{
331 wxWindow* wxWindow_FindFocus() {
332 return wxWindow::FindFocus();
333 }
334 %}
335
336
337 %inline %{
338 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
339 wxWindow* win = new wxWindow;
340 win->SetHWND(hWnd);
341 win->SubclassWin(hWnd);
342 return win;
343 }
344 %}
345 #endif
346
347
348
349 //---------------------------------------------------------------------------
350
351 class wxPanel : public wxWindow {
352 public:
353 wxPanel(wxWindow* parent,
354 const wxWindowID id,
355 const wxPoint& pos = wxPyDefaultPosition,
356 const wxSize& size = wxPyDefaultSize,
357 long style = wxTAB_TRAVERSAL,
358 const char* name = "panel");
359
360 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
361
362 void InitDialog();
363 wxButton* GetDefaultItem();
364 void SetDefaultItem(wxButton *btn);
365
366 // fix some SWIG trouble...
367 %pragma(python) addtoclass = "
368 def GetDefaultItem(self):
369 import controls
370 val = windowsc.wxPanel_GetDefaultItem(self.this)
371 val = controls.wxButtonPtr(val)
372 return val
373 "
374 };
375
376 //---------------------------------------------------------------------------
377
378 class wxDialog : public wxPanel {
379 public:
380 wxDialog(wxWindow* parent,
381 const wxWindowID id,
382 const wxString& title,
383 const wxPoint& pos = wxPyDefaultPosition,
384 const wxSize& size = wxPyDefaultSize,
385 long style = wxDEFAULT_DIALOG_STYLE,
386 const char* name = "dialogBox");
387
388 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
389
390 void Centre(int direction = wxBOTH);
391 void EndModal(int retCode);
392 wxString GetTitle();
393 void Iconize(bool iconize);
394 bool IsIconized();
395 void SetModal(bool flag);
396 bool IsModal();
397 void SetTitle(const wxString& title);
398 bool Show(bool show);
399 int ShowModal();
400
401 int GetReturnCode();
402 void SetReturnCode(int retCode);
403 };
404
405 //---------------------------------------------------------------------------
406
407 class wxScrolledWindow : public wxPanel {
408 public:
409 wxScrolledWindow(wxWindow* parent,
410 const wxWindowID id = -1,
411 const wxPoint& pos = wxPyDefaultPosition,
412 const wxSize& size = wxPyDefaultSize,
413 long style = wxHSCROLL | wxVSCROLL,
414 char* name = "scrolledWindow");
415
416 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
417 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
418
419 void EnableScrolling(bool xScrolling, bool yScrolling);
420 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
421 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
422 bool IsRetained();
423 void PrepareDC(wxDC& dc);
424 void Scroll(int x, int y);
425 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
426 int noUnitsX, int noUnitsY,
427 int xPos = 0, int yPos = 0);
428 void ViewStart(int* OUTPUT, int* OUTPUT);
429
430 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
431 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
432
433 };
434
435 //----------------------------------------------------------------------
436
437
438 class wxMenu : public wxEvtHandler {
439 public:
440 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
441
442 void Append(int id, const wxString& item,
443 const wxString& helpString = wxPyEmptyStr,
444 int checkable = FALSE);
445 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
446 const wxString& helpString = wxPyEmptyStr);
447 %name(AppendItem)void Append(const wxMenuItem* item);
448
449 void AppendSeparator();
450 void Break();
451 void Check(int id, bool flag);
452 void Enable(int id, bool enable);
453 int FindItem(const wxString& itemString);
454 wxString GetTitle();
455 void SetTitle(const wxString& title);
456 wxMenuItem* FindItemForId(int id);
457 wxString GetHelpString(int id);
458 wxString GetLabel(int id);
459 void SetHelpString(int id, const wxString& helpString);
460 bool IsChecked(int id);
461 bool IsEnabled(int id);
462 void SetLabel(int id, const wxString& label);
463 void UpdateUI(wxEvtHandler* source = NULL);
464
465 %addmethods {
466 void Destroy() {
467 delete self;
468 }
469 }
470
471 };
472
473
474 //
475 // This one knows how to set a callback and handle INC- and DECREFing it. To
476 // be used for PopupMenus, but you must retain a referece to it while using
477 // it.
478 //
479 // class wxPyMenu : public wxMenu {
480 // public:
481 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
482 // ~wxPyMenu();
483 // };
484
485 //----------------------------------------------------------------------
486
487 class wxMenuBar : public wxEvtHandler {
488 public:
489 wxMenuBar();
490
491 void Append(wxMenu *menu, const wxString& title);
492 void Check(int id, bool flag);
493 bool Checked(int id);
494 void Enable(int id, bool enable);
495 bool Enabled(int id);
496 int FindMenuItem(const wxString& menuString, const wxString& itemString);
497 wxMenuItem * FindItemForId(int id);
498 void SetLabel(int id, const wxString& label);
499 void EnableTop(int pos, bool enable);
500 wxString GetHelpString(int id);
501 wxString GetLabel(int id);
502 void SetHelpString(int id, const wxString& helpString);
503 wxString GetLabelTop(int pos);
504 void SetLabelTop(int pos, const wxString& label);
505 int GetMenuCount();
506 wxMenu* GetMenu(int i);
507 void Refresh();
508 };
509
510
511 //----------------------------------------------------------------------
512
513 class wxMenuItem {
514 public:
515 #ifndef __WXGTK__
516 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
517 const wxString& text = wxPyEmptyStr,
518 const wxString& helpString = wxPyEmptyStr,
519 bool checkable = FALSE, wxMenu* subMenu = NULL);
520 #else
521 wxMenuItem();
522 #endif
523
524 bool IsSeparator();
525 bool IsEnabled();
526 bool IsChecked();
527 bool IsCheckable();
528 int GetId();
529 wxMenu* GetSubMenu();
530 void SetName(const wxString& strName);
531 wxString GetName();
532 wxString GetHelp();
533 void SetHelp(const wxString& strHelp);
534 void Enable(bool bDoEnable = TRUE);
535 void Check(bool bDoCheck = TRUE);
536
537 #ifdef __WXMSW__
538 wxColour& GetBackgroundColour();
539 wxBitmap GetBitmap(bool checked = TRUE);
540 wxFont& GetFont();
541 int GetMarginWidth();
542 wxColour& GetTextColour();
543 void SetBackgroundColour(const wxColour& colour);
544 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
545 void SetFont(const wxFont& font);
546 void SetMarginWidth(int width);
547 void SetTextColour(const wxColour& colour);
548 void DeleteSubMenu();
549 #endif
550 };
551
552 //---------------------------------------------------------------------------
553
554