]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/windows.i
Minor tweaks and some typos fixed
[wxWidgets.git] / 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 #include <wx/tooltip.h>
20 %}
21
22 //----------------------------------------------------------------------
23
24 %include typemaps.i
25 %include my_typemaps.i
26
27 // Import some definitions of other classes, etc.
28 %import _defs.i
29 %import misc.i
30 %import gdi.i
31 %import clip_dnd.i
32
33 %pragma(python) code = "import wx"
34
35
36 %{
37 static wxString wxPyEmptyStr("");
38 %}
39
40 //---------------------------------------------------------------------------
41
42 class wxEvtHandler : public wxObject {
43 public:
44 wxEvtHandler();
45
46 bool ProcessEvent(wxEvent& event);
47 void AddPendingEvent(wxEvent& event);
48 //bool SearchEventTable(wxEventTable& table, wxEvent& event);
49
50 bool GetEvtHandlerEnabled();
51 void SetEvtHandlerEnabled(bool enabled);
52
53 wxEvtHandler* GetNextHandler();
54 wxEvtHandler* GetPreviousHandler();
55 void SetNextHandler(wxEvtHandler* handler);
56 void SetPreviousHandler(wxEvtHandler* handler);
57
58
59 %addmethods {
60 void Connect( int id, int lastId, int eventType, PyObject* func) {
61 if (PyCallable_Check(func)) {
62 self->Connect(id, lastId, eventType,
63 (wxObjectEventFunction) &wxPyCallback::EventThunker,
64 new wxPyCallback(func));
65 }
66 }
67
68 bool Disconnect(int id, int lastId = -1,
69 wxEventType eventType = wxEVT_NULL) {
70 return self->Disconnect(id, lastId, eventType,
71 (wxObjectEventFunction)
72 &wxPyCallback::EventThunker);
73 }
74 }
75
76 };
77
78
79 //----------------------------------------------------------------------
80
81 class wxValidator : public wxEvtHandler {
82 public:
83 wxValidator();
84 //~wxValidator();
85
86 wxValidator* Clone();
87 wxWindow* GetWindow();
88 void SetWindow(wxWindow* window);
89
90 static bool IsSilent();
91 static void SetBellOnError(int doIt = TRUE);
92
93 };
94
95
96 //----------------------------------------------------------------------
97 %{
98 class wxPyValidator : public wxValidator {
99 DECLARE_DYNAMIC_CLASS(wxPyValidator);
100 public:
101 wxPyValidator() {
102 }
103
104 ~wxPyValidator() {
105 }
106
107 wxObject* Clone() const {
108 wxPyValidator* ptr = NULL;
109 wxPyValidator* self = (wxPyValidator*)this;
110
111 wxPyTState* state = wxPyBeginBlockThreads();
112 if (self->m_myInst.findCallback("Clone")) {
113 PyObject* ro;
114 ro = self->m_myInst.callCallbackObj(Py_BuildValue("()"));
115 if (ro) {
116 SWIG_GetPtrObj(ro, (void **)&ptr, "_wxPyValidator_p");
117 Py_DECREF(ro);
118 }
119 }
120 wxPyEndBlockThreads(state);
121
122 // This is very dangerous!!! But is the only way I could find
123 // to squash a memory leak. Currently it is okay, but if the
124 // validator architecture in wxWindows ever changes, problems
125 // could arise.
126 delete self;
127 return ptr;
128 }
129
130
131 DEC_PYCALLBACK_BOOL_WXWIN(Validate);
132 DEC_PYCALLBACK_BOOL_(TransferToWindow);
133 DEC_PYCALLBACK_BOOL_(TransferFromWindow);
134
135 PYPRIVATE;
136 };
137
138 IMP_PYCALLBACK_BOOL_WXWIN(wxPyValidator, wxValidator, Validate);
139 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferToWindow);
140 IMP_PYCALLBACK_BOOL_(wxPyValidator, wxValidator, TransferFromWindow);
141
142 IMPLEMENT_DYNAMIC_CLASS(wxPyValidator, wxValidator);
143
144 %}
145
146 class wxPyValidator : public wxValidator {
147 public:
148 wxPyValidator();
149
150 void _setSelf(PyObject* self, PyObject* _class, int incref=TRUE);
151 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxPyValidator, 1)"
152
153 };
154
155 //----------------------------------------------------------------------
156
157 %apply int * INOUT { int* x, int* y };
158
159 class wxWindow : public wxEvtHandler {
160 public:
161 wxWindow(wxWindow* parent, const wxWindowID id,
162 const wxPoint& pos = wxDefaultPosition,
163 const wxSize& size = wxDefaultSize,
164 long style = 0,
165 char* name = "panel");
166 %name(wxPreWindow)wxWindow();
167
168 bool Create(wxWindow* parent, const wxWindowID id,
169 const wxPoint& pos = wxDefaultPosition,
170 const wxSize& size = wxDefaultSize,
171 long style = 0,
172 char* name = "panel");
173
174 void CaptureMouse();
175 void Center(int direction = wxBOTH);
176 void Centre(int direction = wxBOTH);
177 void CentreOnParent(int direction = wxBOTH );
178 void CenterOnParent(int direction = wxBOTH );
179 void CentreOnScreen(int direction = wxBOTH );
180 void CenterOnScreen(int direction = wxBOTH );
181
182 void Clear();
183
184 // (uses apply'ed INOUT typemap, see above)
185 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
186 wxPoint ClientToScreen(const wxPoint& pt);
187
188 bool Close(int force = FALSE);
189 bool Destroy();
190 void DestroyChildren();
191 bool IsBeingDeleted();
192 #ifdef __WXMSW__
193 void DragAcceptFiles(bool accept);
194 #endif
195 void Enable(bool enable);
196 //bool FakePopupMenu(wxMenu* menu, int x, int y);
197 %name(FindWindowById) wxWindow* FindWindow(long id);
198 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
199 void Fit();
200 wxColour GetBackgroundColour();
201
202 //wxList& GetChildren();
203 %addmethods {
204 PyObject* GetChildren() {
205 wxWindowList& list = self->GetChildren();
206 return wxPy_ConvertList(&list, "wxWindow");
207 }
208 }
209
210 int GetCharHeight();
211 int GetCharWidth();
212 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
213 wxSize GetClientSize();
214 wxLayoutConstraints * GetConstraints();
215 wxEvtHandler* GetEventHandler();
216
217 wxFont& GetFont();
218 wxColour GetForegroundColour();
219 wxWindow * GetGrandParent();
220 %addmethods {
221 long GetHandle() {
222 return wxPyGetWinHandle(self); //(long)self->GetHandle();
223 }
224 }
225 int GetId();
226 wxString GetLabel();
227 void SetLabel(const wxString& label);
228 wxString GetName();
229 wxWindow * GetParent();
230 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
231 wxPoint GetPosition();
232 wxRect GetRect();
233 int GetScrollThumb(int orientation);
234 int GetScrollPos(int orientation);
235 int GetScrollRange(int orientation);
236 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
237 wxSize GetSize();
238 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
239 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
240 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
241 const wxFont* font = NULL); //, bool use16 = FALSE)
242 wxString GetTitle();
243 wxRegion GetUpdateRegion();
244 long GetWindowStyleFlag();
245 void SetWindowStyleFlag(long style);
246 void SetWindowStyle(long style);
247 bool Hide();
248 void InitDialog();
249 bool IsEnabled();
250 bool IsExposed( int x, int y, int w=0, int h=0 );
251 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt );
252 %name(IsExposedRect) bool IsExposed( const wxRect& rect );
253 bool IsRetained();
254 bool IsShown();
255 bool IsTopLevel();
256 void Layout();
257 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
258 void Lower();
259 void MakeModal(bool flag=TRUE);
260 %name(MoveXY)void Move(int x, int y);
261 void Move(const wxPoint& point);
262
263 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
264 void PushEventHandler(wxEvtHandler* handler);
265
266 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
267 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
268
269 void Raise();
270 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
271 void RefreshRect(const wxRect& rect);
272
273 void ReleaseMouse();
274 void RemoveChild(wxWindow* child);
275 bool Reparent( wxWindow* newParent );
276
277 // (uses apply'ed INOUT typemap, see above)
278 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
279 wxPoint ScreenToClient(const wxPoint& pt);
280
281 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
282 void SetAcceleratorTable(const wxAcceleratorTable& accel);
283 void SetAutoLayout(bool autoLayout);
284 bool GetAutoLayout();
285 void SetBackgroundColour(const wxColour& colour);
286 void SetConstraints(wxLayoutConstraints *constraints);
287 void UnsetConstraints(wxLayoutConstraints *constraints);
288 void SetFocus();
289 bool AcceptsFocus();
290 void SetFont(const wxFont& font);
291 void SetForegroundColour(const wxColour& colour);
292 void SetId(int id);
293 void SetName(const wxString& name);
294 void SetScrollbar(int orientation, int position, int thumbSize, int range, int refresh = TRUE);
295 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
296
297 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
298 %addmethods {
299 void SetSize(const wxSize& size) {
300 self->SetSize(size);
301 }
302
303 void SetPosition(const wxPoint& pos) {
304 self->Move(pos);
305 }
306
307 void SetRect(const wxRect& rect, int sizeFlags=wxSIZE_AUTO) {
308 self->SetSize(rect, sizeFlags);
309 }
310 }
311
312 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
313 %name(SetClientSizeWH)void SetClientSize(int width, int height);
314 void SetClientSize(const wxSize& size);
315 //void SetPalette(wxPalette* palette);
316 void SetCursor(const wxCursor&cursor);
317 void SetEventHandler(wxEvtHandler* handler);
318 void SetExtraStyle(long exStyle);
319 void SetTitle(const wxString& title);
320 bool Show(bool show);
321 bool TransferDataFromWindow();
322 bool TransferDataToWindow();
323 bool Validate();
324 void WarpPointer(int x, int y);
325
326 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
327 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
328
329 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
330 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
331
332 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
333 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
334
335 %name(SetToolTipString)void SetToolTip(const wxString &tip);
336 void SetToolTip(wxToolTip *tooltip);
337 wxToolTip* GetToolTip();
338
339 void SetSizer(wxSizer* sizer);
340 wxSizer* GetSizer();
341
342 wxValidator* GetValidator();
343 void SetValidator(const wxValidator& validator);
344
345 void SetDropTarget(wxDropTarget* target);
346 wxDropTarget* GetDropTarget();
347 %pragma(python) addtomethod = "SetDropTarget:_args[0].thisown = 0"
348
349 wxSize GetBestSize();
350
351 void SetCaret(wxCaret *caret);
352 wxCaret *GetCaret();
353 %pragma(python) addtoclass = "# replaces broken shadow method
354 def GetCaret(self, *_args, **_kwargs):
355 from misc2 import wxCaretPtr
356 val = apply(windowsc.wxWindow_GetCaret,(self,) + _args, _kwargs)
357 if val: val = wxCaretPtr(val)
358 return val
359 "
360
361 void Freeze();
362 void Thaw();
363 void Update();
364
365 wxString GetHelpText();
366 void SetHelpText(const wxString& helpText);
367
368 bool ScrollLines(int lines);
369 bool ScrollPages(int pages);
370 bool LineUp();
371 bool LineDown();
372 bool PageUp();
373 bool PageDown();
374
375 static wxWindow* FindFocus();
376 static int NewControlId();
377 static int NextControlId(int id);
378 static int PrevControlId(int id);
379
380 void SetAcceleratorTable(const wxAcceleratorTable& accel);
381 wxAcceleratorTable *GetAcceleratorTable();
382 };
383
384
385
386
387 %pragma(python) code = "
388 def wxDLG_PNT(win, point_or_x, y=None):
389 if y is None:
390 return win.ConvertDialogPointToPixels(point_or_x)
391 else:
392 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
393
394 def wxDLG_SZE(win, size_width, height=None):
395 if height is None:
396 return win.ConvertDialogSizeToPixels(size_width)
397 else:
398 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
399 "
400
401
402 #ifdef __WXMSW__
403 %inline %{
404 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
405 wxWindow* win = new wxWindow;
406 win->SetHWND(hWnd);
407 win->SubclassWin(hWnd);
408 return win;
409 }
410 %}
411 #endif
412
413
414 //---------------------------------------------------------------------------
415
416 class wxPanel : public wxWindow {
417 public:
418 wxPanel(wxWindow* parent,
419 const wxWindowID id,
420 const wxPoint& pos = wxDefaultPosition,
421 const wxSize& size = wxDefaultSize,
422 long style = wxTAB_TRAVERSAL,
423 const char* name = "panel");
424 %name(wxPrePanel)wxPanel();
425
426 bool Create(wxWindow* parent,
427 const wxWindowID id,
428 const wxPoint& pos = wxDefaultPosition,
429 const wxSize& size = wxDefaultSize,
430 long style = wxTAB_TRAVERSAL,
431 const char* name = "panel");
432
433 void InitDialog();
434 wxButton* GetDefaultItem();
435 void SetDefaultItem(wxButton *btn);
436
437 };
438
439 //---------------------------------------------------------------------------
440
441
442 // TODO: Add wrappers for the wxScrollHelper class, make wxScrolledWindow
443 // derive from it and wxPanel.
444
445
446 class wxScrolledWindow : public wxPanel {
447 public:
448 wxScrolledWindow(wxWindow* parent,
449 const wxWindowID id = -1,
450 const wxPoint& pos = wxDefaultPosition,
451 const wxSize& size = wxDefaultSize,
452 long style = wxHSCROLL | wxVSCROLL,
453 char* name = "scrolledWindow");
454 %name(wxPreScrolledWindow)wxScrolledWindow();
455
456 bool Create(wxWindow* parent,
457 const wxWindowID id = -1,
458 const wxPoint& pos = wxDefaultPosition,
459 const wxSize& size = wxDefaultSize,
460 long style = wxHSCROLL | wxVSCROLL,
461 char* name = "scrolledWindow");
462
463 void EnableScrolling(bool xScrolling, bool yScrolling);
464 int GetScrollPageSize(int orient);
465 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
466 wxWindow* GetTargetWindow();
467 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
468 bool IsRetained();
469 void PrepareDC(wxDC& dc);
470 void Scroll(int x, int y);
471 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
472 int noUnitsX, int noUnitsY,
473 int xPos = 0, int yPos = 0, int noRefresh=FALSE);
474 void SetScrollPageSize(int orient, int pageSize);
475 void SetTargetWindow(wxWindow* window);
476 void GetViewStart(int* OUTPUT, int* OUTPUT);
477 %pragma(python) addtoclass = "ViewStart = GetViewStart"
478
479 void CalcScrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
480 void CalcUnscrolledPosition( int x, int y, int *OUTPUT, int *OUTPUT);
481
482 void SetScale(double xs, double ys);
483 double GetScaleX();
484 double GetScaleY();
485
486 void AdjustScrollbars();
487 };
488
489 //----------------------------------------------------------------------
490
491
492 class wxMenu : public wxEvtHandler {
493 public:
494 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
495
496 void Append(int id, const wxString& item,
497 const wxString& helpString = wxPyEmptyStr,
498 int checkable = FALSE);
499 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
500 const wxString& helpString = wxPyEmptyStr);
501 %name(AppendItem)void Append(const wxMenuItem* item);
502
503 void AppendSeparator();
504 void Break();
505 void Check(int id, bool flag);
506 bool IsChecked(int id);
507 void Enable(int id, bool enable);
508 bool IsEnabled(int id);
509
510 int FindItem(const wxString& itemString);
511 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
512
513 wxString GetTitle();
514 void SetTitle(const wxString& title);
515
516 wxString GetLabel(int id);
517 void SetLabel(int id, const wxString& label);
518
519 wxString GetHelpString(int id);
520 void SetHelpString(int id, const wxString& helpString);
521 void UpdateUI(wxEvtHandler* source = NULL);
522
523 bool Delete(int id);
524 %name(DeleteItem)bool Delete(wxMenuItem *item);
525 bool Insert(size_t pos, wxMenuItem *item);
526 wxMenuItem *Remove(int id);
527 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
528
529 %addmethods {
530 void Destroy() { delete self; }
531 }
532 %name(DestroyId)bool Destroy(int id);
533 %name(DestroyItem)bool Destroy(wxMenuItem *item);
534
535 size_t GetMenuItemCount();
536 //wxMenuItemList& GetMenuItems();
537 %addmethods {
538 PyObject* GetMenuItems() {
539 wxMenuItemList& list = self->GetMenuItems();
540 return wxPy_ConvertList(&list, "wxMenuItem");
541 }
542 }
543
544 void SetEventHandler(wxEvtHandler *handler);
545 wxEvtHandler *GetEventHandler();
546
547 void SetInvokingWindow(wxWindow *win);
548 wxWindow *GetInvokingWindow();
549
550 long GetStyle();
551
552 bool IsAttached();
553
554 void SetParent(wxMenu *parent);
555 wxMenu *GetParent();
556 };
557
558
559 //----------------------------------------------------------------------
560
561 class wxMenuBar : public wxWindow {
562 public:
563 wxMenuBar(long style = 0);
564
565 bool Append(wxMenu *menu, const wxString& title);
566 bool Insert(size_t pos, wxMenu *menu, const wxString& title);
567 size_t GetMenuCount();
568 wxMenu *GetMenu(size_t pos);
569 wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
570 wxMenu *Remove(size_t pos);
571 void EnableTop(size_t pos, bool enable);
572 void SetLabelTop(size_t pos, const wxString& label);
573 wxString GetLabelTop(size_t pos);
574 int FindMenu(const wxString& title);
575 int FindMenuItem(const wxString& menuString, const wxString& itemString);
576 %name(FindItemById)wxMenuItem* FindItem(int id/*, wxMenu **menu = NULL*/);
577 void Enable(int id, bool enable);
578 void Check(int id, bool check);
579 bool IsChecked(int id);
580 bool IsEnabled(int id);
581
582 void SetLabel(int id, const wxString &label);
583 wxString GetLabel(int id);
584
585 void SetHelpString(int id, const wxString& helpString);
586 wxString GetHelpString(int id);
587
588 };
589
590
591 //----------------------------------------------------------------------
592
593 class wxMenuItem : public wxObject {
594 public:
595 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
596 const wxString& text = wxPyEmptyStr,
597 const wxString& help = wxPyEmptyStr,
598 bool isCheckable = FALSE, wxMenu* subMenu = NULL);
599
600
601 wxMenu *GetMenu();
602 void SetId(int id);
603 int GetId();
604 bool IsSeparator();
605 void SetText(const wxString& str);
606 wxString GetLabel();
607 const wxString& GetText();
608 void SetCheckable(bool checkable);
609 bool IsCheckable();
610 bool IsSubMenu();
611 void SetSubMenu(wxMenu *menu);
612 wxMenu *GetSubMenu();
613 void Enable(bool enable = TRUE);
614 bool IsEnabled();
615 void Check(bool check = TRUE);
616 bool IsChecked();
617 void Toggle();
618 void SetHelp(const wxString& str);
619 const wxString& GetHelp();
620 wxAcceleratorEntry *GetAccel();
621 void SetAccel(wxAcceleratorEntry *accel);
622
623 static wxString GetLabelFromText(const wxString& text);
624
625 // wxOwnerDrawn methods
626 #ifdef __WXMSW__
627 void SetFont(const wxFont& font);
628 wxFont& GetFont();
629 void SetTextColour(const wxColour& colText);
630 wxColour GetTextColour();
631 void SetBackgroundColour(const wxColour& colBack);
632 wxColour GetBackgroundColour();
633 void SetBitmaps(const wxBitmap& bmpChecked,
634 const wxBitmap& bmpUnchecked = wxNullBitmap);
635 void SetBitmap(const wxBitmap& bmpChecked);
636 const wxBitmap& GetBitmap(bool bChecked = TRUE);
637 void SetMarginWidth(int nWidth);
638 int GetMarginWidth();
639 static int GetDefaultMarginWidth();
640 //void SetName(const wxString& strName);
641 //const wxString& GetName();
642 //void SetCheckable(bool checkable);
643 //bool IsCheckable();
644 bool IsOwnerDrawn();
645 void ResetOwnerDrawn();
646 #endif
647 };
648
649 //---------------------------------------------------------------------------
650
651
652