]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/src/windows.i
minor additions and bugfixes
[wxWidgets.git] / utils / wxPython / src / windows.i
CommitLineData
7bf85405
RD
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
03e9bead
RD
14%module windows
15
16%{
7bf85405 17#include "helpers.h"
7bf85405
RD
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
efc5f224 31
2f90df85 32%pragma(python) code = "import wx"
7bf85405
RD
33
34//---------------------------------------------------------------------------
35
36class wxEvtHandler {
37public:
cf694132 38 bool ProcessEvent(wxEvent& event);
2f90df85
RD
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
7bf85405
RD
50 %addmethods {
51 void Connect( int id, int lastId, int eventType, PyObject* func) {
52 if (PyCallable_Check(func)) {
53 self->Connect(id, lastId, eventType,
853b255a 54 (wxObjectEventFunction) &wxPyCallback::EventThunker,
7bf85405
RD
55 new wxPyCallback(func));
56 }
57 }
58 }
59};
60
61
2f90df85
RD
62//----------------------------------------------------------------------
63
64class wxValidator : public wxEvtHandler {
65public:
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%{
86class wxPyValidator : public wxValidator {
87 DECLARE_DYNAMIC_CLASS(wxPyValidator);
88public:
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
125IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
126IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
127IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
128
129IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
130
131%}
132
133class wxPyValidator : public wxValidator {
134public:
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
7bf85405
RD
147//----------------------------------------------------------------------
148
efc5f224 149%apply int * INOUT { int* x, int* y };
7bf85405
RD
150
151class wxWindow : public wxEvtHandler {
152public:
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
b8b8dda7 160 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
7bf85405
RD
161
162 void CaptureMouse();
8bf5d46e
RD
163 void Center(int direction = wxBOTH);
164 void Centre(int direction = wxBOTH);
165 void CentreOnParent(int direction = wxBOTH );
166 void CenterOnParent(int direction = wxBOTH );
efc5f224
RD
167
168 // (uses apply'ed INOUT typemap, see above)
169 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
af309447 170 wxPoint ClientToScreen(const wxPoint& pt);
efc5f224 171
7bf85405
RD
172 bool Close(int force = FALSE);
173 bool Destroy();
174 void DestroyChildren();
853b255a 175#ifdef __WXMSW__
7bf85405 176 void DragAcceptFiles(bool accept);
853b255a 177#endif
7bf85405
RD
178 void Enable(bool enable);
179 //bool FakePopupMenu(wxMenu* menu, int x, int y);
af309447 180 %name(FindWindowById) wxWindow* FindWindow(long id);
714e6a9e 181 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
7bf85405
RD
182 void Fit();
183 wxColour GetBackgroundColour();
d426c97e
RD
184
185 //wxList& GetChildren();
186 %addmethods {
187 PyObject* GetChildren() {
188 wxWindowList& list = self->GetChildren();
189 return wxPy_ConvertList(&list, "wxWindow");
190 }
191 }
192
193
7bf85405
RD
194 int GetCharHeight();
195 int GetCharWidth();
b8b8dda7
RD
196 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
197 wxSize GetClientSize();
7bf85405 198 wxLayoutConstraints * GetConstraints();
3ab72185 199 wxEvtHandler* GetEventHandler();
105e45b9 200
b8b8dda7 201 wxFont& GetFont();
7bf85405
RD
202 wxColour GetForegroundColour();
203 wxWindow * GetGrandParent();
204 int GetId();
853b255a 205 wxString GetLabel();
bb0054cd 206 void SetLabel(const wxString& label);
853b255a 207 wxString GetName();
7bf85405 208 wxWindow * GetParent();
b8b8dda7
RD
209 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
210 wxPoint GetPosition();
211 wxRect GetRect();
7bf85405
RD
212 int GetScrollThumb(int orientation);
213 int GetScrollPos(int orientation);
214 int GetScrollRange(int orientation);
b8b8dda7
RD
215 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
216 wxSize GetSize();
af309447
RD
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)
853b255a 221 wxString GetTitle();
8bf5d46e 222 wxRegion GetUpdateRegion();
7bf85405 223 long GetWindowStyleFlag();
bb0054cd 224 bool Hide();
7bf85405
RD
225 void InitDialog();
226 bool IsEnabled();
227 bool IsRetained();
228 bool IsShown();
bb0054cd 229 bool IsTopLevel();
7bf85405
RD
230 void Layout();
231 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
232 void Lower();
233 void MakeModal(bool flag);
af309447
RD
234 %name(MoveXY)void Move(int x, int y);
235 void Move(const wxPoint& point);
7bf85405 236
3ab72185
RD
237 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
238 void PushEventHandler(wxEvtHandler* handler);
7bf85405 239
8bf5d46e
RD
240 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
241 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
242
7bf85405
RD
243 void Raise();
244 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
245 void ReleaseMouse();
bb0054cd
RD
246 bool Reparent( wxWindow* newParent );
247
efc5f224
RD
248 // (uses apply'ed INOUT typemap, see above)
249 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
af309447
RD
250 wxPoint ScreenToClient(const wxPoint& pt);
251
7bf85405 252 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
b8b8dda7 253 void SetAcceleratorTable(const wxAcceleratorTable& accel);
7bf85405
RD
254 void SetAutoLayout(bool autoLayout);
255 void SetBackgroundColour(const wxColour& colour);
256 void SetConstraints(wxLayoutConstraints *constraints);
2f90df85 257 void UnsetConstraints(wxLayoutConstraints *constraints);
7bf85405 258 void SetFocus();
2f90df85 259 bool AcceptsFocus();
7bf85405
RD
260 void SetFont(const wxFont& font);
261 void SetForegroundColour(const wxColour& colour);
262 void SetId(int id);
263 void SetName(const wxString& name);
7bf85405
RD
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
7bf85405
RD
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);
af309447
RD
279 %name(SetClientSizeWH)void SetClientSize(int width, int height);
280 void SetClientSize(const wxSize& size);
7bf85405 281 //void SetPalette(wxPalette* palette);
7bf85405 282 void SetCursor(const wxCursor&cursor);
3ab72185 283 void SetEventHandler(wxEvtHandler* handler);
7bf85405
RD
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
b8b8dda7
RD
291 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
292 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
293
cf694132
RD
294 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
295 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
296
b8b8dda7
RD
297 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
298 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
299
af309447
RD
300 %name(SetToolTipString)void SetToolTip(const wxString &tip);
301 void SetToolTip(wxToolTip *tooltip);
302 wxToolTip* GetToolTip();
2f90df85
RD
303
304 void SetSizer(wxSizer* sizer);
305 wxValidator* GetValidator();
306 void SetValidator(const wxValidator& validator);
307
7bf85405
RD
308};
309
efc5f224
RD
310//%clear int* x, int* y;
311
312
313
b8b8dda7 314%pragma(python) code = "
bb0054cd
RD
315def 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
321def 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))
b8b8dda7 326"
7bf85405 327
853b255a 328#ifdef __WXMSW__
7bf85405
RD
329%inline %{
330 wxWindow* wxWindow_FindFocus() {
331 return wxWindow::FindFocus();
332 }
333%}
af309447
RD
334
335
336%inline %{
337wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
338 wxWindow* win = new wxWindow;
339 win->SetHWND(hWnd);
340 win->SubclassWin(hWnd);
341 return win;
342}
343%}
853b255a 344#endif
7bf85405 345
7bf85405 346
efc5f224 347
7bf85405
RD
348//---------------------------------------------------------------------------
349
350class wxPanel : public wxWindow {
351public:
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
b8b8dda7 359 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
9c039d08 360
7bf85405 361 void InitDialog();
bb0054cd
RD
362 wxButton* GetDefaultItem();
363 void SetDefaultItem(wxButton *btn);
364
3ab72185 365 // fix some SWIG trouble...
bb0054cd
RD
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"
7bf85405
RD
373};
374
375//---------------------------------------------------------------------------
376
377class wxDialog : public wxPanel {
378public:
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
b8b8dda7 387 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
9c039d08 388
7bf85405
RD
389 void Centre(int direction = wxBOTH);
390 void EndModal(int retCode);
391 wxString GetTitle();
392 void Iconize(bool iconize);
393 bool IsIconized();
7bf85405 394 void SetModal(bool flag);
853b255a 395 bool IsModal();
7bf85405
RD
396 void SetTitle(const wxString& title);
397 bool Show(bool show);
398 int ShowModal();
4cd9591a
RD
399
400 int GetReturnCode();
401 void SetReturnCode(int retCode);
7bf85405
RD
402};
403
404//---------------------------------------------------------------------------
405
bb0054cd 406class wxScrolledWindow : public wxPanel {
7bf85405
RD
407public:
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
b8b8dda7
RD
415 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
416 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
9c039d08 417
7bf85405
RD
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
433class wxMenu : public wxEvtHandler {
434public:
8bf5d46e 435 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
7bf85405
RD
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);
af309447
RD
442 %name(AppendItem)void Append(const wxMenuItem* item);
443
7bf85405
RD
444 void AppendSeparator();
445 void Break();
446 void Check(int id, bool flag);
7bf85405
RD
447 void Enable(int id, bool enable);
448 int FindItem(const wxString& itemString);
7bf85405 449 wxString GetTitle();
7bf85405 450 void SetTitle(const wxString& title);
714e6a9e
RD
451 wxMenuItem* FindItemForId(int id);
452 wxString GetHelpString(int id);
453 wxString GetLabel(int id);
454 void SetHelpString(int id, const wxString& helpString);
853b255a
RD
455 bool IsChecked(int id);
456 bool IsEnabled(int id);
457 void SetLabel(int id, const wxString& label);
8bf5d46e 458 void UpdateUI(wxEvtHandler* source = NULL);
efc5f224
RD
459
460 %addmethods {
461 void Destroy() {
462 delete self;
463 }
464 }
465
7bf85405
RD
466};
467
468
7bf85405
RD
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//
8bf5d46e
RD
474// class wxPyMenu : public wxMenu {
475// public:
476// wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
477// ~wxPyMenu();
478// };
7bf85405
RD
479
480//----------------------------------------------------------------------
481
482class wxMenuBar : public wxEvtHandler {
483public:
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);
714e6a9e 490 bool Enabled(int id);
7bf85405 491 int FindMenuItem(const wxString& menuString, const wxString& itemString);
c95e68d8 492 wxMenuItem * FindItemForId(int id);
10534c0b 493 void SetLabel(int id, const wxString& label);
714e6a9e 494 void EnableTop(int pos, bool enable);
7bf85405
RD
495 wxString GetHelpString(int id);
496 wxString GetLabel(int id);
7bf85405 497 void SetHelpString(int id, const wxString& helpString);
853b255a 498 wxString GetLabelTop(int pos);
7bf85405 499 void SetLabelTop(int pos, const wxString& label);
714e6a9e
RD
500 int GetMenuCount();
501 wxMenu* GetMenu(int i);
06c0fba4 502 void Refresh();
7bf85405
RD
503};
504
505
506//----------------------------------------------------------------------
507
508class wxMenuItem {
509public:
cf694132
RD
510#ifndef __WXGTK__
511 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
512 const wxString& text = wxPyEmptyStr,
513 const wxString& helpString = wxPyEmptyStr,
514 bool checkable = FALSE, wxMenu* subMenu = NULL);
515#else
516 wxMenuItem();
517#endif
518
7bf85405
RD
519 bool IsSeparator();
520 bool IsEnabled();
521 bool IsChecked();
714e6a9e 522 bool IsCheckable();
7bf85405 523 int GetId();
7bf85405
RD
524 wxMenu* GetSubMenu();
525 void SetName(const wxString& strName);
cf694132
RD
526 wxString GetName();
527 wxString GetHelp();
714e6a9e
RD
528 void SetHelp(const wxString& strHelp);
529 void Enable(bool bDoEnable = TRUE);
530 void Check(bool bDoCheck = TRUE);
c95e68d8 531
4f22cf8d 532#ifdef __WXMSW__
cf694132
RD
533 wxColour& GetBackgroundColour();
534 wxBitmap GetBitmap(bool checked = TRUE);
535 wxFont& GetFont();
536 int GetMarginWidth();
537 wxColour& GetTextColour();
538 void SetBackgroundColour(const wxColour& colour);
539 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
540 void SetFont(const wxFont& font);
541 void SetMarginWidth(int width);
542 void SetTextColour(const wxColour& colour);
4f22cf8d
RR
543 void DeleteSubMenu();
544#endif
7bf85405
RD
545};
546
547//---------------------------------------------------------------------------
7bf85405
RD
548
549