]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
wxPython stuff:
[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
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 void SetDropTarget(wxDropTarget* target);
314 wxDropTarget* GetDropTarget();
315 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
316 };
317
318 //%clear int* x, int* y;
319
320
321
322 %pragma(python) code = "
323 def wxDLG_PNT(win, point_or_x, y=None):
324 if y is None:
325 return win.ConvertDialogPointToPixels(point_or_x)
326 else:
327 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
328
329 def wxDLG_SZE(win, size_width, height=None):
330 if height is None:
331 return win.ConvertDialogSizeToPixels(size_width)
332 else:
333 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
334 "
335
336 #ifdef __WXMSW__
337 %inline %{
338 wxWindow* wxWindow_FindFocus() {
339 return wxWindow::FindFocus();
340 }
341 %}
342
343
344 %inline %{
345 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
346 wxWindow* win = new wxWindow;
347 win->SetHWND(hWnd);
348 win->SubclassWin(hWnd);
349 return win;
350 }
351 %}
352 #endif
353
354
355
356 //---------------------------------------------------------------------------
357
358 class wxPanel : public wxWindow {
359 public:
360 wxPanel(wxWindow* parent,
361 const wxWindowID id,
362 const wxPoint& pos = wxPyDefaultPosition,
363 const wxSize& size = wxPyDefaultSize,
364 long style = wxTAB_TRAVERSAL,
365 const char* name = "panel");
366
367 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
368
369 void InitDialog();
370 wxButton* GetDefaultItem();
371 void SetDefaultItem(wxButton *btn);
372
373 // fix some SWIG trouble...
374 %pragma(python) addtoclass = "
375 def GetDefaultItem(self):
376 import controls
377 val = windowsc.wxPanel_GetDefaultItem(self.this)
378 val = controls.wxButtonPtr(val)
379 return val
380 "
381 };
382
383 //---------------------------------------------------------------------------
384
385 class wxDialog : public wxPanel {
386 public:
387 wxDialog(wxWindow* parent,
388 const wxWindowID id,
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");
394
395 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
396
397 void Centre(int direction = wxBOTH);
398 void EndModal(int retCode);
399 wxString GetTitle();
400 void Iconize(bool iconize);
401 bool IsIconized();
402 void SetModal(bool flag);
403 bool IsModal();
404 void SetTitle(const wxString& title);
405 bool Show(bool show);
406 int ShowModal();
407
408 int GetReturnCode();
409 void SetReturnCode(int retCode);
410 };
411
412 //---------------------------------------------------------------------------
413
414 class wxScrolledWindow : public wxPanel {
415 public:
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");
422
423 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
424 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
425
426 void EnableScrolling(bool xScrolling, bool yScrolling);
427 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
428 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
429 bool IsRetained();
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);
436
437 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
438 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
439
440 };
441
442 //----------------------------------------------------------------------
443
444
445 class wxMenu : public wxEvtHandler {
446 public:
447 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
448
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);
455
456 void AppendSeparator();
457 void Break();
458 void Check(int id, bool flag);
459 bool IsChecked(int id);
460 void Enable(int id, bool enable);
461 bool IsEnabled(int id);
462
463 int FindItem(const wxString& itemString);
464 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
465
466 wxString GetTitle();
467 void SetTitle(const wxString& title);
468
469 wxString GetLabel(int id);
470 void SetLabel(int id, const wxString& label);
471
472 wxString GetHelpString(int id);
473 void SetHelpString(int id, const wxString& helpString);
474 void UpdateUI(wxEvtHandler* source = NULL);
475
476 bool Delete(int id);
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);
481
482 %addmethods {
483 void Destroy() {
484 delete self;
485 }
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 // #ifdef __WXMSW__
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);
593 // #endif
594 };
595
596 //---------------------------------------------------------------------------
597
598