]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
Committing in .
[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 bool Disconnect(int id, int lastId = -1,
60 wxEventType eventType = wxEVT_NULL) {
61 return self->Disconnect(id, lastId, eventType,
62 (wxObjectEventFunction)
63 &wxPyCallback::EventThunker);
64 }
65
66 }
67 };
68
69
70 //----------------------------------------------------------------------
71
72 class wxValidator : public wxEvtHandler {
73 public:
74 wxValidator();
75 //~wxValidator();
76
77 wxValidator* Clone();
78 wxWindow* GetWindow();
79 void SetWindow(wxWindow* window);
80 };
81
82 %inline %{
83 bool wxValidator_IsSilent() {
84 return wxValidator::IsSilent();
85 }
86
87 void wxValidator_SetBellOnError(int doIt = TRUE) {
88 wxValidator::SetBellOnError(doIt);
89 }
90 %}
91
92 //----------------------------------------------------------------------
93 %{
94 class wxPyValidator : public wxValidator {
95 DECLARE_DYNAMIC_CLASS(wxPyValidator);
96 public:
97 wxPyValidator() {
98 }
99 // wxPyValidator(const wxPyValidator& other);
100
101 ~wxPyValidator() {
102 }
103
104 wxObject* wxPyValidator::Clone() const {
105 wxPyValidator* ptr = NULL;
106 wxPyValidator* self = (wxPyValidator*)this;
107
108 bool doSave = wxPyRestoreThread();
109 if (self->m_myInst.findCallback("Clone")) {
110 PyObject* ro;
111 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
112 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
113 }
114 // This is very dangerous!!! But is the only way I could find
115 // to squash a memory leak. Currently it is okay, but if the
116 // validator architecture in wxWindows ever changes, problems
117 // could arise.
118 delete self;
119
120 wxPySaveThread(doSave);
121 return ptr;
122 }
123
124 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
125 DEC_PYCALLBACK_BOOL_(TransferToWindow);
126 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
127
128 PYPRIVATE;
129 // PyObject* m_data;
130 };
131
132 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
133 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
134 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
135
136 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
137
138 %}
139
140 class wxPyValidator : public wxValidator {
141 public:
142 wxPyValidator();
143 // ~wxPyValidator();
144
145 %addmethods {
146 void Destroy() { delete self; }
147 }
148
149 void _setSelf(PyObject* self, int incref=TRUE);
150 %pragma(python) addtomethod = "__init__:self._setSelf(self, 0)"
151
152 };
153
154 //----------------------------------------------------------------------
155
156 %apply int * INOUT { int* x, int* y };
157
158 class wxWindow : public wxEvtHandler {
159 public:
160
161 wxWindow(wxWindow* parent, const wxWindowID id,
162 const wxPoint& pos = wxPyDefaultPosition,
163 const wxSize& size = wxPyDefaultSize,
164 long style = 0,
165 char* name = "panel");
166
167 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
168
169 void CaptureMouse();
170 void Center(int direction = wxBOTH);
171 void Centre(int direction = wxBOTH);
172 void CentreOnParent(int direction = wxBOTH );
173 void CenterOnParent(int direction = wxBOTH );
174
175 // (uses apply'ed INOUT typemap, see above)
176 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
177 wxPoint ClientToScreen(const wxPoint& pt);
178
179 bool Close(int force = FALSE);
180 bool Destroy();
181 void DestroyChildren();
182 #ifdef __WXMSW__
183 void DragAcceptFiles(bool accept);
184 #endif
185 void Enable(bool enable);
186 //bool FakePopupMenu(wxMenu* menu, int x, int y);
187 %name(FindWindowById) wxWindow* FindWindow(long id);
188 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
189 void Fit();
190 wxColour GetBackgroundColour();
191
192 //wxList& GetChildren();
193 %addmethods {
194 PyObject* GetChildren() {
195 wxWindowList& list = self->GetChildren();
196 return wxPy_ConvertList(&list, "wxWindow");
197 }
198 }
199
200 int GetCharHeight();
201 int GetCharWidth();
202 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
203 wxSize GetClientSize();
204 wxLayoutConstraints * GetConstraints();
205 wxEvtHandler* GetEventHandler();
206
207 wxFont& GetFont();
208 wxColour GetForegroundColour();
209 wxWindow * GetGrandParent();
210 %addmethods {
211 long GetHandle() {
212 return (long)self->GetHandle();
213 }
214 }
215 int GetId();
216 wxString GetLabel();
217 void SetLabel(const wxString& label);
218 wxString GetName();
219 wxWindow * GetParent();
220 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
221 wxPoint GetPosition();
222 wxRect GetRect();
223 int GetScrollThumb(int orientation);
224 int GetScrollPos(int orientation);
225 int GetScrollRange(int orientation);
226 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
227 wxSize GetSize();
228 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
229 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
230 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
231 const wxFont* font = NULL); //, bool use16 = FALSE)
232 wxString GetTitle();
233 wxRegion GetUpdateRegion();
234 long GetWindowStyleFlag();
235 bool Hide();
236 void InitDialog();
237 bool IsEnabled();
238 bool IsRetained();
239 bool IsShown();
240 bool IsTopLevel();
241 void Layout();
242 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
243 void Lower();
244 void MakeModal(bool flag);
245 %name(MoveXY)void Move(int x, int y);
246 void Move(const wxPoint& point);
247
248 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
249 void PushEventHandler(wxEvtHandler* handler);
250
251 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
252 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
253
254 void Raise();
255 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
256 void ReleaseMouse();
257 bool Reparent( wxWindow* newParent );
258
259 // (uses apply'ed INOUT typemap, see above)
260 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
261 wxPoint ScreenToClient(const wxPoint& pt);
262
263 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
264 void SetAcceleratorTable(const wxAcceleratorTable& accel);
265 void SetAutoLayout(bool autoLayout);
266 bool GetAutoLayout();
267 void SetBackgroundColour(const wxColour& colour);
268 void SetConstraints(wxLayoutConstraints *constraints);
269 void UnsetConstraints(wxLayoutConstraints *constraints);
270 void SetFocus();
271 bool AcceptsFocus();
272 void SetFont(const wxFont& font);
273 void SetForegroundColour(const wxColour& colour);
274 void SetId(int id);
275 void SetName(const wxString& name);
276 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
277 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
278
279 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
280 %addmethods {
281 void SetSize(const wxSize& size) {
282 self->SetSize(size.x, size.y);
283 }
284
285 void SetPosition(const wxPoint& pos) {
286 self->SetSize(pos.x, pos.y, -1, -1);
287 }
288 }
289
290 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
291 %name(SetClientSizeWH)void SetClientSize(int width, int height);
292 void SetClientSize(const wxSize& size);
293 //void SetPalette(wxPalette* palette);
294 void SetCursor(const wxCursor&cursor);
295 void SetEventHandler(wxEvtHandler* handler);
296 void SetTitle(const wxString& title);
297 bool Show(bool show);
298 bool TransferDataFromWindow();
299 bool TransferDataToWindow();
300 bool Validate();
301 void WarpPointer(int x, int y);
302
303 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
304 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
305
306 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
307 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
308
309 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
310 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
311
312 %name(SetToolTipString)void SetToolTip(const wxString &tip);
313 void SetToolTip(wxToolTip *tooltip);
314 wxToolTip* GetToolTip();
315
316 void SetSizer(wxSizer* sizer);
317 wxValidator* GetValidator();
318 void SetValidator(const wxValidator& validator);
319
320 void SetDropTarget(wxDropTarget* target);
321 wxDropTarget* GetDropTarget();
322 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
323
324 wxSize GetBestSize();
325 };
326
327 //%clear int* x, int* y;
328
329
330
331 %pragma(python) code = "
332 def wxDLG_PNT(win, point_or_x, y=None):
333 if y is None:
334 return win.ConvertDialogPointToPixels(point_or_x)
335 else:
336 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
337
338 def wxDLG_SZE(win, size_width, height=None):
339 if height is None:
340 return win.ConvertDialogSizeToPixels(size_width)
341 else:
342 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
343 "
344
345 #ifdef __WXMSW__
346 %inline %{
347 wxWindow* wxWindow_FindFocus() {
348 return wxWindow::FindFocus();
349 }
350 %}
351
352
353 %inline %{
354 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
355 wxWindow* win = new wxWindow;
356 win->SetHWND(hWnd);
357 win->SubclassWin(hWnd);
358 return win;
359 }
360 %}
361 #endif
362
363
364
365 //---------------------------------------------------------------------------
366
367 class wxPanel : public wxWindow {
368 public:
369 wxPanel(wxWindow* parent,
370 const wxWindowID id,
371 const wxPoint& pos = wxPyDefaultPosition,
372 const wxSize& size = wxPyDefaultSize,
373 long style = wxTAB_TRAVERSAL,
374 const char* name = "panel");
375
376 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
377
378 void InitDialog();
379 wxButton* GetDefaultItem();
380 void SetDefaultItem(wxButton *btn);
381
382 // fix some SWIG trouble...
383 %pragma(python) addtoclass = "
384 def GetDefaultItem(self):
385 import controls
386 val = windowsc.wxPanel_GetDefaultItem(self.this)
387 val = controls.wxButtonPtr(val)
388 return val
389 "
390 };
391
392 //---------------------------------------------------------------------------
393
394 class wxDialog : public wxPanel {
395 public:
396 wxDialog(wxWindow* parent,
397 const wxWindowID id,
398 const wxString& title,
399 const wxPoint& pos = wxPyDefaultPosition,
400 const wxSize& size = wxPyDefaultSize,
401 long style = wxDEFAULT_DIALOG_STYLE,
402 const char* name = "dialogBox");
403
404 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
405
406 void Centre(int direction = wxBOTH);
407 void EndModal(int retCode);
408 wxString GetTitle();
409 void Iconize(bool iconize);
410 bool IsIconized();
411 void SetModal(bool flag);
412 bool IsModal();
413 void SetTitle(const wxString& title);
414 bool Show(bool show);
415 int ShowModal();
416
417 int GetReturnCode();
418 void SetReturnCode(int retCode);
419 };
420
421 //---------------------------------------------------------------------------
422
423 class wxScrolledWindow : public wxPanel {
424 public:
425 wxScrolledWindow(wxWindow* parent,
426 const wxWindowID id = -1,
427 const wxPoint& pos = wxPyDefaultPosition,
428 const wxSize& size = wxPyDefaultSize,
429 long style = wxHSCROLL | wxVSCROLL,
430 char* name = "scrolledWindow");
431
432 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
433 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
434
435 void EnableScrolling(bool xScrolling, bool yScrolling);
436 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
437 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
438 bool IsRetained();
439 void PrepareDC(wxDC& dc);
440 void Scroll(int x, int y);
441 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
442 int noUnitsX, int noUnitsY,
443 int xPos = 0, int yPos = 0);
444 void SetTargetWindow(wxWindow* window);
445 void ViewStart(int* OUTPUT, int* OUTPUT);
446
447 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
448 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
449
450 };
451
452 //----------------------------------------------------------------------
453
454
455 class wxMenu : public wxEvtHandler {
456 public:
457 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
458
459 void Append(int id, const wxString& item,
460 const wxString& helpString = wxPyEmptyStr,
461 int checkable = FALSE);
462 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
463 const wxString& helpString = wxPyEmptyStr);
464 %name(AppendItem)void Append(const wxMenuItem* item);
465
466 void AppendSeparator();
467 void Break();
468 void Check(int id, bool flag);
469 bool IsChecked(int id);
470 void Enable(int id, bool enable);
471 bool IsEnabled(int id);
472
473 int FindItem(const wxString& itemString);
474 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
475
476 wxString GetTitle();
477 void SetTitle(const wxString& title);
478
479 wxString GetLabel(int id);
480 void SetLabel(int id, const wxString& label);
481
482 wxString GetHelpString(int id);
483 void SetHelpString(int id, const wxString& helpString);
484 void UpdateUI(wxEvtHandler* source = NULL);
485
486 bool Delete(int id);
487 %name(DeleteItem)bool Delete(wxMenuItem *item);
488 bool Insert(size_t pos, wxMenuItem *item);
489 wxMenuItem *Remove(int id);
490 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
491
492 %addmethods {
493 void Destroy() { delete self; }
494 }
495 %name(DestroyId)bool Destroy(int id);
496 %name(DestroyItem)bool Destroy(wxMenuItem *item);
497
498 size_t GetMenuItemCount();
499 //wxMenuItemList& GetMenuItems();
500 %addmethods {
501 PyObject* GetMenuItems() {
502 wxMenuItemList& list = self->GetMenuItems();
503 return wxPy_ConvertList(&list, "wxMenuItem");
504 }
505 }
506
507 void SetEventHandler(wxEvtHandler *handler);
508 wxEvtHandler *GetEventHandler();
509
510 void SetInvokingWindow(wxWindow *win);
511 wxWindow *GetInvokingWindow();
512
513 long GetStyle();
514
515 bool IsAttached();
516
517 void SetParent(wxMenu *parent);
518 wxMenu *GetParent();
519 };
520
521
522 //----------------------------------------------------------------------
523
524 class wxMenuBar : public wxWindow {
525 public:
526 wxMenuBar();
527
528 bool Append(wxMenu *menu, const wxString& title);
529 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
530 size_t GetMenuCount();
531 wxMenu *GetMenu(size_t pos);
532 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
533 wxMenu *Remove(size_t pos);
534 void EnableTop(size_t pos, bool enable);
535 void SetLabelTop(size_t pos, const wxString& label);
536 wxString GetLabelTop(size_t pos);
537 int FindMenuItem(const wxString& menuString, const wxString& itemString);
538 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
539 void Enable(int id, bool enable);
540 void Check(int id, bool check);
541 bool IsChecked(int id);
542 bool IsEnabled(int id);
543
544 void SetLabel(int id, const wxString &label);
545 wxString GetLabel(int id);
546
547 void SetHelpString(int id, const wxString& helpString);
548 wxString GetHelpString(int id);
549
550 };
551
552
553 //----------------------------------------------------------------------
554
555 class wxMenuItem {
556 public:
557 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
558 const wxString& text = wxPyEmptyStr,
559 const wxString& help = wxPyEmptyStr,
560 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
561
562
563 wxMenu *GetMenu();
564 void SetId(int id);
565 int GetId();
566 bool IsSeparator();
567 void SetText(const wxString& str);
568 wxString GetLabel();
569 const wxString& GetText();
570 void SetCheckable(bool checkable);
571 bool IsCheckable();
572 bool IsSubMenu();
573 void SetSubMenu(wxMenu *menu);
574 wxMenu *GetSubMenu();
575 void Enable(bool enable = TRUE);
576 bool IsEnabled();
577 void Check(bool check = TRUE);
578 bool IsChecked();
579 void Toggle();
580 void SetHelp(const wxString& str);
581 const wxString& GetHelp();
582 wxAcceleratorEntry *GetAccel();
583 void SetAccel(wxAcceleratorEntry *accel);
584
585 };
586
587 //---------------------------------------------------------------------------
588
589
590