]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
more updates
[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 void SetBackgroundColour(const wxColour& colour);
256 void SetConstraints(wxLayoutConstraints *constraints);
257 void UnsetConstraints(wxLayoutConstraints *constraints);
258 void SetFocus();
259 bool AcceptsFocus();
260 void SetFont(const wxFont& font);
261 void SetForegroundColour(const wxColour& colour);
262 void SetId(int id);
263 void SetName(const wxString& name);
264 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
265 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
266
267 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
268 %addmethods {
269 void SetSize(const wxSize& size) {
270 self->SetSize(size.x, size.y);
271 }
272
273 void SetPosition(const wxPoint& pos) {
274 self->SetSize(pos.x, pos.y, -1, -1);
275 }
276 }
277
278 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
279 %name(SetClientSizeWH)void SetClientSize(int width, int height);
280 void SetClientSize(const wxSize& size);
281 //void SetPalette(wxPalette* palette);
282 void SetCursor(const wxCursor&cursor);
283 void SetEventHandler(wxEvtHandler* handler);
284 void SetTitle(const wxString& title);
285 bool Show(bool show);
286 bool TransferDataFromWindow();
287 bool TransferDataToWindow();
288 bool Validate();
289 void WarpPointer(int x, int y);
290
291 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
292 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
293
294 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
295 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
296
297 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
298 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
299
300 %name(SetToolTipString)void SetToolTip(const wxString &tip);
301 void SetToolTip(wxToolTip *tooltip);
302 wxToolTip* GetToolTip();
303
304 void SetSizer(wxSizer* sizer);
305 wxValidator* GetValidator();
306 void SetValidator(const wxValidator& validator);
307
308 };
309
310 //%clear int* x, int* y;
311
312
313
314 %pragma(python) code = "
315 def wxDLG_PNT(win, point_or_x, y=None):
316 if y is None:
317 return win.ConvertDialogPointToPixels(point_or_x)
318 else:
319 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
320
321 def wxDLG_SZE(win, size_width, height=None):
322 if height is None:
323 return win.ConvertDialogSizeToPixels(size_width)
324 else:
325 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
326 "
327
328 #ifdef __WXMSW__
329 %inline %{
330 wxWindow* wxWindow_FindFocus() {
331 return wxWindow::FindFocus();
332 }
333 %}
334
335
336 %inline %{
337 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
338 wxWindow* win = new wxWindow;
339 win->SetHWND(hWnd);
340 win->SubclassWin(hWnd);
341 return win;
342 }
343 %}
344 #endif
345
346
347
348 //---------------------------------------------------------------------------
349
350 class wxPanel : public wxWindow {
351 public:
352 wxPanel(wxWindow* parent,
353 const wxWindowID id,
354 const wxPoint& pos = wxPyDefaultPosition,
355 const wxSize& size = wxPyDefaultSize,
356 long style = wxTAB_TRAVERSAL,
357 const char* name = "panel");
358
359 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
360
361 void InitDialog();
362 wxButton* GetDefaultItem();
363 void SetDefaultItem(wxButton *btn);
364
365 // fix some SWIG trouble...
366 %pragma(python) addtoclass = "
367 def GetDefaultItem(self):
368 import controls
369 val = windowsc.wxPanel_GetDefaultItem(self.this)
370 val = controls.wxButtonPtr(val)
371 return val
372 "
373 };
374
375 //---------------------------------------------------------------------------
376
377 class wxDialog : public wxPanel {
378 public:
379 wxDialog(wxWindow* parent,
380 const wxWindowID id,
381 const wxString& title,
382 const wxPoint& pos = wxPyDefaultPosition,
383 const wxSize& size = wxPyDefaultSize,
384 long style = wxDEFAULT_DIALOG_STYLE,
385 const char* name = "dialogBox");
386
387 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
388
389 void Centre(int direction = wxBOTH);
390 void EndModal(int retCode);
391 wxString GetTitle();
392 void Iconize(bool iconize);
393 bool IsIconized();
394 void SetModal(bool flag);
395 bool IsModal();
396 void SetTitle(const wxString& title);
397 bool Show(bool show);
398 int ShowModal();
399
400 int GetReturnCode();
401 void SetReturnCode(int retCode);
402 };
403
404 //---------------------------------------------------------------------------
405
406 class wxScrolledWindow : public wxPanel {
407 public:
408 wxScrolledWindow(wxWindow* parent,
409 const wxWindowID id = -1,
410 const wxPoint& pos = wxPyDefaultPosition,
411 const wxSize& size = wxPyDefaultSize,
412 long style = wxHSCROLL | wxVSCROLL,
413 char* name = "scrolledWindow");
414
415 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
416 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
417
418 void EnableScrolling(bool xScrolling, bool yScrolling);
419 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
420 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
421 bool IsRetained();
422 void PrepareDC(wxDC& dc);
423 void Scroll(int x, int y);
424 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
425 int noUnitsX, int noUnitsY,
426 int xPos = 0, int yPos = 0);
427 void ViewStart(int* OUTPUT, int* OUTPUT);
428 };
429
430 //----------------------------------------------------------------------
431
432
433 class wxMenu : public wxEvtHandler {
434 public:
435 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
436
437 void Append(int id, const wxString& item,
438 const wxString& helpString = wxPyEmptyStr,
439 int checkable = FALSE);
440 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
441 const wxString& helpString = wxPyEmptyStr);
442 %name(AppendItem)void Append(const wxMenuItem* item);
443
444 void AppendSeparator();
445 void Break();
446 void Check(int id, bool flag);
447 void Enable(int id, bool enable);
448 int FindItem(const wxString& itemString);
449 wxString GetTitle();
450 void SetTitle(const wxString& title);
451 wxMenuItem* FindItemForId(int id);
452 wxString GetHelpString(int id);
453 wxString GetLabel(int id);
454 void SetHelpString(int id, const wxString& helpString);
455 bool IsChecked(int id);
456 bool IsEnabled(int id);
457 void SetLabel(int id, const wxString& label);
458 void UpdateUI(wxEvtHandler* source = NULL);
459
460 %addmethods {
461 void Destroy() {
462 delete self;
463 }
464 }
465
466 };
467
468
469 //
470 // This one knows how to set a callback and handle INC- and DECREFing it. To
471 // be used for PopupMenus, but you must retain a referece to it while using
472 // it.
473 //
474 // class wxPyMenu : public wxMenu {
475 // public:
476 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
477 // ~wxPyMenu();
478 // };
479
480 //----------------------------------------------------------------------
481
482 class wxMenuBar : public wxEvtHandler {
483 public:
484 wxMenuBar();
485
486 void Append(wxMenu *menu, const wxString& title);
487 void Check(int id, bool flag);
488 bool Checked(int id);
489 void Enable(int id, bool enable);
490 bool Enabled(int id);
491 int FindMenuItem(const wxString& menuString, const wxString& itemString);
492 wxMenuItem * FindItemForId(int id);
493 void SetLabel(int id, const wxString& label);
494 void EnableTop(int pos, bool enable);
495 wxString GetHelpString(int id);
496 wxString GetLabel(int id);
497 void SetHelpString(int id, const wxString& helpString);
498 wxString GetLabelTop(int pos);
499 void SetLabelTop(int pos, const wxString& label);
500 int GetMenuCount();
501 wxMenu* GetMenu(int i);
502 };
503
504
505 //----------------------------------------------------------------------
506
507 class wxMenuItem {
508 public:
509 #ifndef __WXGTK__
510 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
511 const wxString& text = wxPyEmptyStr,
512 const wxString& helpString = wxPyEmptyStr,
513 bool checkable = FALSE, wxMenu* subMenu = NULL);
514 #else
515 wxMenuItem();
516 #endif
517
518 bool IsSeparator();
519 bool IsEnabled();
520 bool IsChecked();
521 bool IsCheckable();
522 int GetId();
523 wxMenu* GetSubMenu();
524 void SetName(const wxString& strName);
525 wxString GetName();
526 wxString GetHelp();
527 void SetHelp(const wxString& strHelp);
528 void Enable(bool bDoEnable = TRUE);
529 void Check(bool bDoCheck = TRUE);
530
531 #ifdef __WXMSW__
532 wxColour& GetBackgroundColour();
533 wxBitmap GetBitmap(bool checked = TRUE);
534 wxFont& GetFont();
535 int GetMarginWidth();
536 wxColour& GetTextColour();
537 void SetBackgroundColour(const wxColour& colour);
538 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
539 void SetFont(const wxFont& font);
540 void SetMarginWidth(int width);
541 void SetTextColour(const wxColour& colour);
542 void DeleteSubMenu();
543 #endif
544 };
545
546 //---------------------------------------------------------------------------
547
548