]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
Cleaned up paint DC cache in ~wxPaintDC to avoid spurious memory warning
[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 int GetCharHeight();
194 int GetCharWidth();
195 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
196 wxSize GetClientSize();
197 wxLayoutConstraints * GetConstraints();
198 wxEvtHandler* GetEventHandler();
199
200 wxFont& GetFont();
201 wxColour GetForegroundColour();
202 wxWindow * GetGrandParent();
203 %addmethods {
204 long GetHandle() {
205 return (long)self->GetHandle();
206 }
207 }
208 int GetId();
209 wxString GetLabel();
210 void SetLabel(const wxString& label);
211 wxString GetName();
212 wxWindow * GetParent();
213 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
214 wxPoint GetPosition();
215 wxRect GetRect();
216 int GetScrollThumb(int orientation);
217 int GetScrollPos(int orientation);
218 int GetScrollRange(int orientation);
219 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
220 wxSize GetSize();
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)
225 wxString GetTitle();
226 wxRegion GetUpdateRegion();
227 long GetWindowStyleFlag();
228 bool Hide();
229 void InitDialog();
230 bool IsEnabled();
231 bool IsRetained();
232 bool IsShown();
233 bool IsTopLevel();
234 void Layout();
235 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
236 void Lower();
237 void MakeModal(bool flag);
238 %name(MoveXY)void Move(int x, int y);
239 void Move(const wxPoint& point);
240
241 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
242 void PushEventHandler(wxEvtHandler* handler);
243
244 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
245 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
246
247 void Raise();
248 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
249 void ReleaseMouse();
250 bool Reparent( wxWindow* newParent );
251
252 // (uses apply'ed INOUT typemap, see above)
253 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
254 wxPoint ScreenToClient(const wxPoint& pt);
255
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);
263 void SetFocus();
264 bool AcceptsFocus();
265 void SetFont(const wxFont& font);
266 void SetForegroundColour(const wxColour& colour);
267 void SetId(int id);
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);
271
272 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
273 %addmethods {
274 void SetSize(const wxSize& size) {
275 self->SetSize(size.x, size.y);
276 }
277
278 void SetPosition(const wxPoint& pos) {
279 self->SetSize(pos.x, pos.y, -1, -1);
280 }
281 }
282
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();
293 bool Validate();
294 void WarpPointer(int x, int y);
295
296 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
297 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
298
299 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
300 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
301
302 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
303 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
304
305 %name(SetToolTipString)void SetToolTip(const wxString &tip);
306 void SetToolTip(wxToolTip *tooltip);
307 wxToolTip* GetToolTip();
308
309 void SetSizer(wxSizer* sizer);
310 wxValidator* GetValidator();
311 void SetValidator(const wxValidator& validator);
312
313 };
314
315 //%clear int* x, int* y;
316
317
318
319 %pragma(python) code = "
320 def wxDLG_PNT(win, point_or_x, y=None):
321 if y is None:
322 return win.ConvertDialogPointToPixels(point_or_x)
323 else:
324 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
325
326 def wxDLG_SZE(win, size_width, height=None):
327 if height is None:
328 return win.ConvertDialogSizeToPixels(size_width)
329 else:
330 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
331 "
332
333 #ifdef __WXMSW__
334 %inline %{
335 wxWindow* wxWindow_FindFocus() {
336 return wxWindow::FindFocus();
337 }
338 %}
339
340
341 %inline %{
342 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
343 wxWindow* win = new wxWindow;
344 win->SetHWND(hWnd);
345 win->SubclassWin(hWnd);
346 return win;
347 }
348 %}
349 #endif
350
351
352
353 //---------------------------------------------------------------------------
354
355 class wxPanel : public wxWindow {
356 public:
357 wxPanel(wxWindow* parent,
358 const wxWindowID id,
359 const wxPoint& pos = wxPyDefaultPosition,
360 const wxSize& size = wxPyDefaultSize,
361 long style = wxTAB_TRAVERSAL,
362 const char* name = "panel");
363
364 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
365
366 void InitDialog();
367 wxButton* GetDefaultItem();
368 void SetDefaultItem(wxButton *btn);
369
370 // fix some SWIG trouble...
371 %pragma(python) addtoclass = "
372 def GetDefaultItem(self):
373 import controls
374 val = windowsc.wxPanel_GetDefaultItem(self.this)
375 val = controls.wxButtonPtr(val)
376 return val
377 "
378 };
379
380 //---------------------------------------------------------------------------
381
382 class wxDialog : public wxPanel {
383 public:
384 wxDialog(wxWindow* parent,
385 const wxWindowID id,
386 const wxString& title,
387 const wxPoint& pos = wxPyDefaultPosition,
388 const wxSize& size = wxPyDefaultSize,
389 long style = wxDEFAULT_DIALOG_STYLE,
390 const char* name = "dialogBox");
391
392 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
393
394 void Centre(int direction = wxBOTH);
395 void EndModal(int retCode);
396 wxString GetTitle();
397 void Iconize(bool iconize);
398 bool IsIconized();
399 void SetModal(bool flag);
400 bool IsModal();
401 void SetTitle(const wxString& title);
402 bool Show(bool show);
403 int ShowModal();
404
405 int GetReturnCode();
406 void SetReturnCode(int retCode);
407 };
408
409 //---------------------------------------------------------------------------
410
411 class wxScrolledWindow : public wxPanel {
412 public:
413 wxScrolledWindow(wxWindow* parent,
414 const wxWindowID id = -1,
415 const wxPoint& pos = wxPyDefaultPosition,
416 const wxSize& size = wxPyDefaultSize,
417 long style = wxHSCROLL | wxVSCROLL,
418 char* name = "scrolledWindow");
419
420 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
421 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
422
423 void EnableScrolling(bool xScrolling, bool yScrolling);
424 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
425 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
426 bool IsRetained();
427 void PrepareDC(wxDC& dc);
428 void Scroll(int x, int y);
429 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
430 int noUnitsX, int noUnitsY,
431 int xPos = 0, int yPos = 0);
432 void ViewStart(int* OUTPUT, int* OUTPUT);
433
434 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
435 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
436
437 };
438
439 //----------------------------------------------------------------------
440
441
442 class wxMenu : public wxEvtHandler {
443 public:
444 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
445
446 void Append(int id, const wxString& item,
447 const wxString& helpString = wxPyEmptyStr,
448 int checkable = FALSE);
449 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
450 const wxString& helpString = wxPyEmptyStr);
451 %name(AppendItem)void Append(const wxMenuItem* item);
452
453 void AppendSeparator();
454 void Break();
455 void Check(int id, bool flag);
456 void Enable(int id, bool enable);
457 int FindItem(const wxString& itemString);
458 wxString GetTitle();
459 void SetTitle(const wxString& title);
460 wxMenuItem* FindItemForId(int id);
461 wxString GetHelpString(int id);
462 wxString GetLabel(int id);
463 void SetHelpString(int id, const wxString& helpString);
464 bool IsChecked(int id);
465 bool IsEnabled(int id);
466 void SetLabel(int id, const wxString& label);
467 void UpdateUI(wxEvtHandler* source = NULL);
468
469 %addmethods {
470 void Destroy() {
471 delete self;
472 }
473 }
474
475 };
476
477
478 //
479 // This one knows how to set a callback and handle INC- and DECREFing it. To
480 // be used for PopupMenus, but you must retain a referece to it while using
481 // it.
482 //
483 // class wxPyMenu : public wxMenu {
484 // public:
485 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
486 // ~wxPyMenu();
487 // };
488
489 //----------------------------------------------------------------------
490
491 class wxMenuBar : public wxEvtHandler {
492 public:
493 wxMenuBar();
494
495 void Append(wxMenu *menu, const wxString& title);
496 void Check(int id, bool flag);
497 // bool Checked(int id);
498 void Enable(int id, bool enable);
499 // bool Enabled(int id);
500 bool IsChecked(int id);
501 bool IsEnabled(int id);
502 int FindMenuItem(const wxString& menuString, const wxString& itemString);
503 wxMenuItem * FindItemForId(int id);
504 void SetLabel(int id, const wxString& label);
505 void EnableTop(int pos, bool enable);
506 wxString GetHelpString(int id);
507 wxString GetLabel(int id);
508 void SetHelpString(int id, const wxString& helpString);
509 wxString GetLabelTop(int pos);
510 void SetLabelTop(int pos, const wxString& label);
511 int GetMenuCount();
512 wxMenu* GetMenu(int i);
513 void Refresh();
514 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
515 wxMenu *Remove(size_t pos);
516
517 };
518
519
520 //----------------------------------------------------------------------
521
522 class wxMenuItem {
523 public:
524 //#ifndef __WXGTK__
525 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
526 const wxString& text = wxPyEmptyStr,
527 const wxString& helpString = wxPyEmptyStr,
528 bool checkable = FALSE, wxMenu* subMenu = NULL);
529 //#else
530 // wxMenuItem();
531 //#endif
532
533 bool IsSeparator();
534 bool IsEnabled();
535 bool IsChecked();
536 bool IsCheckable();
537 bool IsSubMenu();
538 int GetId();
539 void SetId(int id);
540 wxMenu* GetSubMenu();
541 wxString GetHelp();
542 void SetHelp(const wxString& strHelp);
543 void Enable(bool bDoEnable = TRUE);
544 void Check(bool bDoCheck = TRUE);
545
546 //#ifdef __WXMSW__
547 wxColour& GetBackgroundColour();
548 wxBitmap GetBitmap(bool checked = TRUE);
549 wxFont& GetFont();
550 int GetMarginWidth();
551 wxColour& GetTextColour();
552 void SetBackgroundColour(const wxColour& colour);
553 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
554 void SetFont(const wxFont& font);
555 void SetMarginWidth(int width);
556 void SetText(const wxString& str);
557 const wxString& GetText();
558 void SetTextColour(const wxColour& colour);
559 void DeleteSubMenu();
560 void SetCheckable(bool checkable);
561 void SetSubMenu(wxMenu *menu);
562 //#endif
563 };
564
565 //---------------------------------------------------------------------------
566
567