]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/src/windows.i
code cleanup
[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
b1462dfa 30%import clip_dnd.i
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 {
694759cf
RD
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;
2f90df85 114 }
2f90df85
RD
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
124IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
125IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
126IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
127
128IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
129
130%}
131
132class wxPyValidator : public wxValidator {
133public:
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
7bf85405
RD
146//----------------------------------------------------------------------
147
efc5f224 148%apply int * INOUT { int* x, int* y };
7bf85405
RD
149
150class wxWindow : public wxEvtHandler {
151public:
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
b8b8dda7 159 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
7bf85405
RD
160
161 void CaptureMouse();
8bf5d46e
RD
162 void Center(int direction = wxBOTH);
163 void Centre(int direction = wxBOTH);
164 void CentreOnParent(int direction = wxBOTH );
165 void CenterOnParent(int direction = wxBOTH );
efc5f224
RD
166
167 // (uses apply'ed INOUT typemap, see above)
168 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
af309447 169 wxPoint ClientToScreen(const wxPoint& pt);
efc5f224 170
7bf85405
RD
171 bool Close(int force = FALSE);
172 bool Destroy();
173 void DestroyChildren();
853b255a 174#ifdef __WXMSW__
7bf85405 175 void DragAcceptFiles(bool accept);
853b255a 176#endif
7bf85405
RD
177 void Enable(bool enable);
178 //bool FakePopupMenu(wxMenu* menu, int x, int y);
af309447 179 %name(FindWindowById) wxWindow* FindWindow(long id);
714e6a9e 180 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
7bf85405
RD
181 void Fit();
182 wxColour GetBackgroundColour();
d426c97e
RD
183
184 //wxList& GetChildren();
185 %addmethods {
186 PyObject* GetChildren() {
187 wxWindowList& list = self->GetChildren();
188 return wxPy_ConvertList(&list, "wxWindow");
189 }
190 }
191
7bf85405
RD
192 int GetCharHeight();
193 int GetCharWidth();
b8b8dda7
RD
194 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
195 wxSize GetClientSize();
7bf85405 196 wxLayoutConstraints * GetConstraints();
3ab72185 197 wxEvtHandler* GetEventHandler();
105e45b9 198
b8b8dda7 199 wxFont& GetFont();
7bf85405
RD
200 wxColour GetForegroundColour();
201 wxWindow * GetGrandParent();
2abc0a0f
RD
202 %addmethods {
203 long GetHandle() {
204 return (long)self->GetHandle();
205 }
206 }
7bf85405 207 int GetId();
853b255a 208 wxString GetLabel();
bb0054cd 209 void SetLabel(const wxString& label);
853b255a 210 wxString GetName();
7bf85405 211 wxWindow * GetParent();
b8b8dda7
RD
212 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
213 wxPoint GetPosition();
214 wxRect GetRect();
7bf85405
RD
215 int GetScrollThumb(int orientation);
216 int GetScrollPos(int orientation);
217 int GetScrollRange(int orientation);
b8b8dda7
RD
218 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
219 wxSize GetSize();
af309447
RD
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)
853b255a 224 wxString GetTitle();
8bf5d46e 225 wxRegion GetUpdateRegion();
7bf85405 226 long GetWindowStyleFlag();
bb0054cd 227 bool Hide();
7bf85405
RD
228 void InitDialog();
229 bool IsEnabled();
230 bool IsRetained();
231 bool IsShown();
bb0054cd 232 bool IsTopLevel();
7bf85405
RD
233 void Layout();
234 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
235 void Lower();
236 void MakeModal(bool flag);
af309447
RD
237 %name(MoveXY)void Move(int x, int y);
238 void Move(const wxPoint& point);
7bf85405 239
3ab72185
RD
240 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
241 void PushEventHandler(wxEvtHandler* handler);
7bf85405 242
8bf5d46e
RD
243 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
244 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
245
7bf85405
RD
246 void Raise();
247 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
248 void ReleaseMouse();
bb0054cd
RD
249 bool Reparent( wxWindow* newParent );
250
efc5f224
RD
251 // (uses apply'ed INOUT typemap, see above)
252 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
af309447
RD
253 wxPoint ScreenToClient(const wxPoint& pt);
254
7bf85405 255 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
b8b8dda7 256 void SetAcceleratorTable(const wxAcceleratorTable& accel);
7bf85405 257 void SetAutoLayout(bool autoLayout);
1dec68aa 258 bool GetAutoLayout();
7bf85405
RD
259 void SetBackgroundColour(const wxColour& colour);
260 void SetConstraints(wxLayoutConstraints *constraints);
2f90df85 261 void UnsetConstraints(wxLayoutConstraints *constraints);
7bf85405 262 void SetFocus();
2f90df85 263 bool AcceptsFocus();
7bf85405
RD
264 void SetFont(const wxFont& font);
265 void SetForegroundColour(const wxColour& colour);
266 void SetId(int id);
267 void SetName(const wxString& name);
eb715945 268 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
7bf85405
RD
269 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
270
7bf85405
RD
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);
af309447
RD
283 %name(SetClientSizeWH)void SetClientSize(int width, int height);
284 void SetClientSize(const wxSize& size);
7bf85405 285 //void SetPalette(wxPalette* palette);
7bf85405 286 void SetCursor(const wxCursor&cursor);
3ab72185 287 void SetEventHandler(wxEvtHandler* handler);
7bf85405
RD
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
b8b8dda7
RD
295 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
296 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
297
cf694132
RD
298 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
299 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
300
b8b8dda7
RD
301 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
302 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
303
af309447
RD
304 %name(SetToolTipString)void SetToolTip(const wxString &tip);
305 void SetToolTip(wxToolTip *tooltip);
306 wxToolTip* GetToolTip();
2f90df85
RD
307
308 void SetSizer(wxSizer* sizer);
309 wxValidator* GetValidator();
310 void SetValidator(const wxValidator& validator);
311
b1462dfa
RD
312 void SetDropTarget(wxDropTarget* target);
313 wxDropTarget* GetDropTarget();
314 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
694759cf
RD
315
316 wxSize GetBestSize();
7bf85405
RD
317};
318
efc5f224
RD
319//%clear int* x, int* y;
320
321
322
b8b8dda7 323%pragma(python) code = "
bb0054cd
RD
324def 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
330def 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))
b8b8dda7 335"
7bf85405 336
853b255a 337#ifdef __WXMSW__
7bf85405
RD
338%inline %{
339 wxWindow* wxWindow_FindFocus() {
340 return wxWindow::FindFocus();
341 }
342%}
af309447
RD
343
344
345%inline %{
346wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
347 wxWindow* win = new wxWindow;
348 win->SetHWND(hWnd);
349 win->SubclassWin(hWnd);
350 return win;
351}
352%}
853b255a 353#endif
7bf85405 354
7bf85405 355
efc5f224 356
7bf85405
RD
357//---------------------------------------------------------------------------
358
359class wxPanel : public wxWindow {
360public:
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
b8b8dda7 368 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
9c039d08 369
7bf85405 370 void InitDialog();
bb0054cd
RD
371 wxButton* GetDefaultItem();
372 void SetDefaultItem(wxButton *btn);
373
3ab72185 374 // fix some SWIG trouble...
bb0054cd
RD
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"
7bf85405
RD
382};
383
384//---------------------------------------------------------------------------
385
386class wxDialog : public wxPanel {
387public:
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
b8b8dda7 396 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
9c039d08 397
7bf85405
RD
398 void Centre(int direction = wxBOTH);
399 void EndModal(int retCode);
400 wxString GetTitle();
401 void Iconize(bool iconize);
402 bool IsIconized();
7bf85405 403 void SetModal(bool flag);
853b255a 404 bool IsModal();
7bf85405
RD
405 void SetTitle(const wxString& title);
406 bool Show(bool show);
407 int ShowModal();
4cd9591a
RD
408
409 int GetReturnCode();
410 void SetReturnCode(int retCode);
7bf85405
RD
411};
412
413//---------------------------------------------------------------------------
414
bb0054cd 415class wxScrolledWindow : public wxPanel {
7bf85405
RD
416public:
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
b8b8dda7
RD
424 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
425 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
9c039d08 426
7bf85405
RD
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);
eb715945 436 void SetTargetWindow(wxWindow* window);
7bf85405 437 void ViewStart(int* OUTPUT, int* OUTPUT);
9d8bd15f
RD
438
439 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
440 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
441
7bf85405
RD
442};
443
444//----------------------------------------------------------------------
445
446
447class wxMenu : public wxEvtHandler {
448public:
8bf5d46e 449 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
7bf85405
RD
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);
af309447
RD
456 %name(AppendItem)void Append(const wxMenuItem* item);
457
7bf85405
RD
458 void AppendSeparator();
459 void Break();
460 void Check(int id, bool flag);
b1462dfa 461 bool IsChecked(int id);
7bf85405 462 void Enable(int id, bool enable);
b1462dfa
RD
463 bool IsEnabled(int id);
464
7bf85405 465 int FindItem(const wxString& itemString);
b1462dfa
RD
466 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
467
7bf85405 468 wxString GetTitle();
7bf85405 469 void SetTitle(const wxString& title);
b1462dfa 470
714e6a9e 471 wxString GetLabel(int id);
853b255a 472 void SetLabel(int id, const wxString& label);
b1462dfa
RD
473
474 wxString GetHelpString(int id);
475 void SetHelpString(int id, const wxString& helpString);
8bf5d46e 476 void UpdateUI(wxEvtHandler* source = NULL);
efc5f224 477
b1462dfa
RD
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
efc5f224 484 %addmethods {
eb715945 485 void Destroy() { delete self; }
efc5f224 486 }
b1462dfa
RD
487 %name(DestroyId)bool Destroy(int id);
488 %name(DestroyItem)bool Destroy(wxMenuItem *item);
efc5f224 489
b1462dfa
RD
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 }
7bf85405 498
b1462dfa
RD
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};
7bf85405 512
7bf85405
RD
513
514//----------------------------------------------------------------------
515
b1462dfa 516class wxMenuBar : public wxWindow {
7bf85405
RD
517public:
518 wxMenuBar();
519
b1462dfa
RD
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*/);
7bf85405 531 void Enable(int id, bool enable);
b1462dfa 532 void Check(int id, bool check);
2abc0a0f
RD
533 bool IsChecked(int id);
534 bool IsEnabled(int id);
b1462dfa
RD
535
536 void SetLabel(int id, const wxString &label);
7bf85405 537 wxString GetLabel(int id);
b1462dfa 538
7bf85405 539 void SetHelpString(int id, const wxString& helpString);
b1462dfa 540 wxString GetHelpString(int id);
2abc0a0f 541
7bf85405
RD
542};
543
544
545//----------------------------------------------------------------------
546
547class wxMenuItem {
548public:
cf694132
RD
549 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
550 const wxString& text = wxPyEmptyStr,
b1462dfa
RD
551 const wxString& help = wxPyEmptyStr,
552 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
cf694132 553
b1462dfa
RD
554
555 wxMenu *GetMenu();
2abc0a0f 556 void SetId(int id);
b1462dfa
RD
557 int GetId();
558 bool IsSeparator();
2abc0a0f 559 void SetText(const wxString& str);
b1462dfa 560 wxString GetLabel();
2abc0a0f 561 const wxString& GetText();
2abc0a0f 562 void SetCheckable(bool checkable);
b1462dfa
RD
563 bool IsCheckable();
564 bool IsSubMenu();
2abc0a0f 565 void SetSubMenu(wxMenu *menu);
b1462dfa
RD
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
7bf85405
RD
577};
578
579//---------------------------------------------------------------------------
7bf85405
RD
580
581
694759cf 582