]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
a test file
[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 %import clip_dnd.i
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 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
117 DEC_PYCALLBACK_BOOL_(TransferToWindow);
118 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
119
120 PYPRIVATE;
121 // PyObject* m_data;
122 };
123
124 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
125 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
126 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
127
128 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
129
130 %}
131
132 class wxPyValidator : public wxValidator {
133 public:
134 wxPyValidator();
135 // ~wxPyValidator();
136
137 %addmethods {
138 void Destroy() { delete self; }
139 }
140
141 void _setSelf(PyObject* self, int incref=TRUE);
142 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
143
144 };
145
146 //----------------------------------------------------------------------
147
148 %apply int * INOUT { int* x, int* y };
149
150 class wxWindow : public wxEvtHandler {
151 public:
152
153 wxWindow(wxWindow* parent, const wxWindowID id,
154 const wxPoint& pos = wxPyDefaultPosition,
155 const wxSize& size = wxPyDefaultSize,
156 long style = 0,
157 char* name = "panel");
158
159 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
160
161 void CaptureMouse();
162 void Center(int direction = wxBOTH);
163 void Centre(int direction = wxBOTH);
164 void CentreOnParent(int direction = wxBOTH );
165 void CenterOnParent(int direction = wxBOTH );
166
167 // (uses apply'ed INOUT typemap, see above)
168 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
169 wxPoint ClientToScreen(const wxPoint& pt);
170
171 bool Close(int force = FALSE);
172 bool Destroy();
173 void DestroyChildren();
174 #ifdef __WXMSW__
175 void DragAcceptFiles(bool accept);
176 #endif
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);
181 void Fit();
182 wxColour GetBackgroundColour();
183
184 //wxList& GetChildren();
185 %addmethods {
186 PyObject* GetChildren() {
187 wxWindowList& list = self->GetChildren();
188 return wxPy_ConvertList(&list, "wxWindow");
189 }
190 }
191
192 int GetCharHeight();
193 int GetCharWidth();
194 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
195 wxSize GetClientSize();
196 wxLayoutConstraints * GetConstraints();
197 wxEvtHandler* GetEventHandler();
198
199 wxFont& GetFont();
200 wxColour GetForegroundColour();
201 wxWindow * GetGrandParent();
202 %addmethods {
203 long GetHandle() {
204 return (long)self->GetHandle();
205 }
206 }
207 int GetId();
208 wxString GetLabel();
209 void SetLabel(const wxString& label);
210 wxString GetName();
211 wxWindow * GetParent();
212 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
213 wxPoint GetPosition();
214 wxRect GetRect();
215 int GetScrollThumb(int orientation);
216 int GetScrollPos(int orientation);
217 int GetScrollRange(int orientation);
218 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
219 wxSize GetSize();
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)
224 wxString GetTitle();
225 wxRegion GetUpdateRegion();
226 long GetWindowStyleFlag();
227 bool Hide();
228 void InitDialog();
229 bool IsEnabled();
230 bool IsRetained();
231 bool IsShown();
232 bool IsTopLevel();
233 void Layout();
234 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
235 void Lower();
236 void MakeModal(bool flag);
237 %name(MoveXY)void Move(int x, int y);
238 void Move(const wxPoint& point);
239
240 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
241 void PushEventHandler(wxEvtHandler* handler);
242
243 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
244 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
245
246 void Raise();
247 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
248 void ReleaseMouse();
249 bool Reparent( wxWindow* newParent );
250
251 // (uses apply'ed INOUT typemap, see above)
252 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
253 wxPoint ScreenToClient(const wxPoint& pt);
254
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);
262 void SetFocus();
263 bool AcceptsFocus();
264 void SetFont(const wxFont& font);
265 void SetForegroundColour(const wxColour& colour);
266 void SetId(int id);
267 void SetName(const wxString& name);
268 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
269 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
270
271 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
272 %addmethods {
273 void SetSize(const wxSize& size) {
274 self->SetSize(size.x, size.y);
275 }
276
277 void SetPosition(const wxPoint& pos) {
278 self->SetSize(pos.x, pos.y, -1, -1);
279 }
280 }
281
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();
292 bool Validate();
293 void WarpPointer(int x, int y);
294
295 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
296 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
297
298 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
299 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
300
301 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
302 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
303
304 %name(SetToolTipString)void SetToolTip(const wxString &tip);
305 void SetToolTip(wxToolTip *tooltip);
306 wxToolTip* GetToolTip();
307
308 void SetSizer(wxSizer* sizer);
309 wxValidator* GetValidator();
310 void SetValidator(const wxValidator& validator);
311
312 void SetDropTarget(wxDropTarget* target);
313 wxDropTarget* GetDropTarget();
314 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
315
316 wxSize GetBestSize();
317 };
318
319 //%clear int* x, int* y;
320
321
322
323 %pragma(python) code = "
324 def wxDLG_PNT(win, point_or_x, y=None):
325 if y is None:
326 return win.ConvertDialogPointToPixels(point_or_x)
327 else:
328 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
329
330 def wxDLG_SZE(win, size_width, height=None):
331 if height is None:
332 return win.ConvertDialogSizeToPixels(size_width)
333 else:
334 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
335 "
336
337 #ifdef __WXMSW__
338 %inline %{
339 wxWindow* wxWindow_FindFocus() {
340 return wxWindow::FindFocus();
341 }
342 %}
343
344
345 %inline %{
346 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
347 wxWindow* win = new wxWindow;
348 win->SetHWND(hWnd);
349 win->SubclassWin(hWnd);
350 return win;
351 }
352 %}
353 #endif
354
355
356
357 //---------------------------------------------------------------------------
358
359 class wxPanel : public wxWindow {
360 public:
361 wxPanel(wxWindow* parent,
362 const wxWindowID id,
363 const wxPoint& pos = wxPyDefaultPosition,
364 const wxSize& size = wxPyDefaultSize,
365 long style = wxTAB_TRAVERSAL,
366 const char* name = "panel");
367
368 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
369
370 void InitDialog();
371 wxButton* GetDefaultItem();
372 void SetDefaultItem(wxButton *btn);
373
374 // fix some SWIG trouble...
375 %pragma(python) addtoclass = "
376 def GetDefaultItem(self):
377 import controls
378 val = windowsc.wxPanel_GetDefaultItem(self.this)
379 val = controls.wxButtonPtr(val)
380 return val
381 "
382 };
383
384 //---------------------------------------------------------------------------
385
386 class wxDialog : public wxPanel {
387 public:
388 wxDialog(wxWindow* parent,
389 const wxWindowID id,
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");
395
396 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
397
398 void Centre(int direction = wxBOTH);
399 void EndModal(int retCode);
400 wxString GetTitle();
401 void Iconize(bool iconize);
402 bool IsIconized();
403 void SetModal(bool flag);
404 bool IsModal();
405 void SetTitle(const wxString& title);
406 bool Show(bool show);
407 int ShowModal();
408
409 int GetReturnCode();
410 void SetReturnCode(int retCode);
411 };
412
413 //---------------------------------------------------------------------------
414
415 class wxScrolledWindow : public wxPanel {
416 public:
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");
423
424 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
425 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
426
427 void EnableScrolling(bool xScrolling, bool yScrolling);
428 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
429 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
430 bool IsRetained();
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 SetTargetWindow(wxWindow* window);
437 void ViewStart(int* OUTPUT, int* OUTPUT);
438
439 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
440 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
441
442 };
443
444 //----------------------------------------------------------------------
445
446
447 class wxMenu : public wxEvtHandler {
448 public:
449 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
450
451 void Append(int id, const wxString& item,
452 const wxString& helpString = wxPyEmptyStr,
453 int checkable = FALSE);
454 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
455 const wxString& helpString = wxPyEmptyStr);
456 %name(AppendItem)void Append(const wxMenuItem* item);
457
458 void AppendSeparator();
459 void Break();
460 void Check(int id, bool flag);
461 bool IsChecked(int id);
462 void Enable(int id, bool enable);
463 bool IsEnabled(int id);
464
465 int FindItem(const wxString& itemString);
466 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
467
468 wxString GetTitle();
469 void SetTitle(const wxString& title);
470
471 wxString GetLabel(int id);
472 void SetLabel(int id, const wxString& label);
473
474 wxString GetHelpString(int id);
475 void SetHelpString(int id, const wxString& helpString);
476 void UpdateUI(wxEvtHandler* source = NULL);
477
478 bool Delete(int id);
479 %name(DeleteItem)bool Delete(wxMenuItem *item);
480 bool Insert(size_t pos, wxMenuItem *item);
481 wxMenuItem *Remove(int id);
482 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
483
484 %addmethods {
485 void Destroy() { delete self; }
486 }
487 %name(DestroyId)bool Destroy(int id);
488 %name(DestroyItem)bool Destroy(wxMenuItem *item);
489
490 size_t GetMenuItemCount();
491 //wxMenuItemList& GetMenuItems();
492 %addmethods {
493 PyObject* GetMenuItems() {
494 wxMenuItemList& list = self->GetMenuItems();
495 return wxPy_ConvertList(&list, "wxMenuItem");
496 }
497 }
498
499 void SetEventHandler(wxEvtHandler *handler);
500 wxEvtHandler *GetEventHandler();
501
502 void SetInvokingWindow(wxWindow *win);
503 wxWindow *GetInvokingWindow();
504
505 long GetStyle();
506
507 bool IsAttached();
508
509 void SetParent(wxMenu *parent);
510 wxMenu *GetParent();
511 };
512
513
514 //----------------------------------------------------------------------
515
516 class wxMenuBar : public wxWindow {
517 public:
518 wxMenuBar();
519
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);
535
536 void SetLabel(int id, const wxString &label);
537 wxString GetLabel(int id);
538
539 void SetHelpString(int id, const wxString& helpString);
540 wxString GetHelpString(int id);
541
542 };
543
544
545 //----------------------------------------------------------------------
546
547 class wxMenuItem {
548 public:
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);
553
554
555 wxMenu *GetMenu();
556 void SetId(int id);
557 int GetId();
558 bool IsSeparator();
559 void SetText(const wxString& str);
560 wxString GetLabel();
561 const wxString& GetText();
562 void SetCheckable(bool checkable);
563 bool IsCheckable();
564 bool IsSubMenu();
565 void SetSubMenu(wxMenu *menu);
566 wxMenu *GetSubMenu();
567 void Enable(bool enable = TRUE);
568 bool IsEnabled();
569 void Check(bool check = TRUE);
570 bool IsChecked();
571 void Toggle();
572 void SetHelp(const wxString& str);
573 const wxString& GetHelp();
574 wxAcceleratorEntry *GetAccel();
575 void SetAccel(wxAcceleratorEntry *accel);
576
577 };
578
579 //---------------------------------------------------------------------------
580
581
582