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