]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
Add detachmenu, insert menu, replace menu.
[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
31 %pragma(python) code = "import wx"
32
33
34 //---------------------------------------------------------------------------
35
36 class wxEvtHandler {
37 public:
38 bool ProcessEvent(wxEvent& event);
39 %addmethods {
40 void Connect( int id, int lastId, int eventType, PyObject* func) {
41 if (PyCallable_Check(func)) {
42 self->Connect(id, lastId, eventType,
43 (wxObjectEventFunction) &wxPyCallback::EventThunker,
44 new wxPyCallback(func));
45 }
46 }
47 }
48 };
49
50
51 //----------------------------------------------------------------------
52
53 %apply int * INOUT { int* x, int* y };
54
55 class wxWindow : public wxEvtHandler {
56 public:
57
58 wxWindow(wxWindow* parent, const wxWindowID id,
59 const wxPoint& pos = wxPyDefaultPosition,
60 const wxSize& size = wxPyDefaultSize,
61 long style = 0,
62 char* name = "panel");
63
64 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
65
66 void CaptureMouse();
67 void Center(int direction = wxBOTH);
68 void Centre(int direction = wxBOTH);
69 void CentreOnParent(int direction = wxBOTH );
70 void CenterOnParent(int direction = wxBOTH );
71
72 // (uses apply'ed INOUT typemap, see above)
73 %name(ClientToScreenXY)void ClientToScreen(int* x, int* y);
74 wxPoint ClientToScreen(const wxPoint& pt);
75
76 bool Close(int force = FALSE);
77 bool Destroy();
78 void DestroyChildren();
79 #ifdef __WXMSW__
80 void DragAcceptFiles(bool accept);
81 #endif
82 void Enable(bool enable);
83 //bool FakePopupMenu(wxMenu* menu, int x, int y);
84 %name(FindWindowById) wxWindow* FindWindow(long id);
85 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
86 void Fit();
87 wxColour GetBackgroundColour();
88 int GetCharHeight();
89 int GetCharWidth();
90 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
91 wxSize GetClientSize();
92 wxLayoutConstraints * GetConstraints();
93 wxEvtHandler* GetEventHandler();
94
95 wxFont& GetFont();
96 wxColour GetForegroundColour();
97 wxWindow * GetGrandParent();
98 int GetId();
99 wxString GetLabel();
100 void SetLabel(const wxString& label);
101 wxString GetName();
102 wxWindow * GetParent();
103 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
104 wxPoint GetPosition();
105 wxRect GetRect();
106 int GetScrollThumb(int orientation);
107 int GetScrollPos(int orientation);
108 int GetScrollRange(int orientation);
109 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
110 wxSize GetSize();
111 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
112 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
113 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
114 const wxFont* font = NULL); //, bool use16 = FALSE)
115 wxString GetTitle();
116 wxRegion GetUpdateRegion();
117 long GetWindowStyleFlag();
118 bool Hide();
119 void InitDialog();
120 bool IsEnabled();
121 bool IsRetained();
122 bool IsShown();
123 bool IsTopLevel();
124 void Layout();
125 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
126 void Lower();
127 void MakeModal(bool flag);
128 %name(MoveXY)void Move(int x, int y);
129 void Move(const wxPoint& point);
130
131 wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
132 void PushEventHandler(wxEvtHandler* handler);
133
134 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
135 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
136
137 void Raise();
138 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
139 void ReleaseMouse();
140 bool Reparent( wxWindow* newParent );
141
142 // (uses apply'ed INOUT typemap, see above)
143 %name(ScreenToClientXY)void ScreenToClient(int *x, int *y);
144 wxPoint ScreenToClient(const wxPoint& pt);
145
146 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
147 void SetAcceleratorTable(const wxAcceleratorTable& accel);
148 void SetAutoLayout(bool autoLayout);
149 void SetBackgroundColour(const wxColour& colour);
150 void SetConstraints(wxLayoutConstraints *constraints);
151 void SetFocus();
152 void SetFont(const wxFont& font);
153 void SetForegroundColour(const wxColour& colour);
154 void SetId(int id);
155 void SetName(const wxString& name);
156 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
157 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
158
159 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
160 %addmethods {
161 void SetSize(const wxSize& size) {
162 self->SetSize(size.x, size.y);
163 }
164
165 void SetPosition(const wxPoint& pos) {
166 self->SetSize(pos.x, pos.y, -1, -1);
167 }
168 }
169
170 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
171 %name(SetClientSizeWH)void SetClientSize(int width, int height);
172 void SetClientSize(const wxSize& size);
173 //void SetPalette(wxPalette* palette);
174 void SetCursor(const wxCursor&cursor);
175 void SetEventHandler(wxEvtHandler* handler);
176 void SetTitle(const wxString& title);
177 bool Show(bool show);
178 bool TransferDataFromWindow();
179 bool TransferDataToWindow();
180 bool Validate();
181 void WarpPointer(int x, int y);
182
183 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
184 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
185
186 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
187 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
188
189 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
190 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
191
192 %name(SetToolTipString)void SetToolTip(const wxString &tip);
193 void SetToolTip(wxToolTip *tooltip);
194 wxToolTip* GetToolTip();
195 };
196
197 //%clear int* x, int* y;
198
199
200
201 %pragma(python) code = "
202 def wxDLG_PNT(win, point_or_x, y=None):
203 if y is None:
204 return win.ConvertDialogPointToPixels(point_or_x)
205 else:
206 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
207
208 def wxDLG_SZE(win, size_width, height=None):
209 if height is None:
210 return win.ConvertDialogSizeToPixels(size_width)
211 else:
212 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
213 "
214
215 #ifdef __WXMSW__
216 %inline %{
217 wxWindow* wxWindow_FindFocus() {
218 return wxWindow::FindFocus();
219 }
220 %}
221
222
223 %inline %{
224 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
225 wxWindow* win = new wxWindow;
226 win->SetHWND(hWnd);
227 win->SubclassWin(hWnd);
228 return win;
229 }
230 %}
231 #endif
232
233
234
235 //---------------------------------------------------------------------------
236
237 class wxPanel : public wxWindow {
238 public:
239 wxPanel(wxWindow* parent,
240 const wxWindowID id,
241 const wxPoint& pos = wxPyDefaultPosition,
242 const wxSize& size = wxPyDefaultSize,
243 long style = wxTAB_TRAVERSAL,
244 const char* name = "panel");
245
246 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
247
248 void InitDialog();
249 wxButton* GetDefaultItem();
250 void SetDefaultItem(wxButton *btn);
251
252 // fix some SWIG trouble...
253 %pragma(python) addtoclass = "
254 def GetDefaultItem(self):
255 import controls
256 val = windowsc.wxPanel_GetDefaultItem(self.this)
257 val = controls.wxButtonPtr(val)
258 return val
259 "
260 };
261
262 //---------------------------------------------------------------------------
263
264 class wxDialog : public wxPanel {
265 public:
266 wxDialog(wxWindow* parent,
267 const wxWindowID id,
268 const wxString& title,
269 const wxPoint& pos = wxPyDefaultPosition,
270 const wxSize& size = wxPyDefaultSize,
271 long style = wxDEFAULT_DIALOG_STYLE,
272 const char* name = "dialogBox");
273
274 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
275
276 void Centre(int direction = wxBOTH);
277 void EndModal(int retCode);
278 wxString GetTitle();
279 void Iconize(bool iconize);
280 bool IsIconized();
281 void SetModal(bool flag);
282 bool IsModal();
283 void SetTitle(const wxString& title);
284 bool Show(bool show);
285 int ShowModal();
286
287 int GetReturnCode();
288 void SetReturnCode(int retCode);
289 };
290
291 //---------------------------------------------------------------------------
292
293 class wxScrolledWindow : public wxPanel {
294 public:
295 wxScrolledWindow(wxWindow* parent,
296 const wxWindowID id = -1,
297 const wxPoint& pos = wxPyDefaultPosition,
298 const wxSize& size = wxPyDefaultSize,
299 long style = wxHSCROLL | wxVSCROLL,
300 char* name = "scrolledWindow");
301
302 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
303 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
304
305 void EnableScrolling(bool xScrolling, bool yScrolling);
306 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
307 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
308 bool IsRetained();
309 void PrepareDC(wxDC& dc);
310 void Scroll(int x, int y);
311 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
312 int noUnitsX, int noUnitsY,
313 int xPos = 0, int yPos = 0);
314 void ViewStart(int* OUTPUT, int* OUTPUT);
315 };
316
317 //----------------------------------------------------------------------
318
319
320 class wxMenu : public wxEvtHandler {
321 public:
322 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
323
324 void Append(int id, const wxString& item,
325 const wxString& helpString = wxPyEmptyStr,
326 int checkable = FALSE);
327 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
328 const wxString& helpString = wxPyEmptyStr);
329 #ifndef __WXGTK__
330 %name(AppendItem)void Append(const wxMenuItem* item);
331 #endif
332
333 void AppendSeparator();
334 void Break();
335 void Check(int id, bool flag);
336 void Enable(int id, bool enable);
337 int FindItem(const wxString& itemString);
338 wxString GetTitle();
339 void SetTitle(const wxString& title);
340 wxMenuItem* FindItemForId(int id);
341 wxString GetHelpString(int id);
342 wxString GetLabel(int id);
343 void SetHelpString(int id, const wxString& helpString);
344 bool IsChecked(int id);
345 bool IsEnabled(int id);
346 void SetLabel(int id, const wxString& label);
347 void UpdateUI(wxEvtHandler* source = NULL);
348
349 %addmethods {
350 void Destroy() {
351 delete self;
352 }
353 }
354
355 };
356
357
358 //
359 // This one knows how to set a callback and handle INC- and DECREFing it. To
360 // be used for PopupMenus, but you must retain a referece to it while using
361 // it.
362 //
363 // class wxPyMenu : public wxMenu {
364 // public:
365 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
366 // ~wxPyMenu();
367 // };
368
369 //----------------------------------------------------------------------
370
371 class wxMenuBar : public wxEvtHandler {
372 public:
373 wxMenuBar();
374
375 void Append(wxMenu *menu, const wxString& title);
376 void Check(int id, bool flag);
377 bool Checked(int id);
378 void Enable(int id, bool enable);
379 bool Enabled(int id);
380 int FindMenuItem(const wxString& menuString, const wxString& itemString);
381 wxMenuItem * FindItemForId(int id);
382 #ifdef __WXMSW__
383 void EnableTop(int pos, bool enable);
384 wxString GetHelpString(int id);
385 wxString GetLabel(int id);
386 void SetHelpString(int id, const wxString& helpString);
387 void SetLabel(int id, const wxString& label);
388 wxString GetLabelTop(int pos);
389 void SetLabelTop(int pos, const wxString& label);
390 #endif
391 int GetMenuCount();
392 wxMenu* GetMenu(int i);
393 };
394
395
396 //----------------------------------------------------------------------
397
398 class wxMenuItem {
399 public:
400 #ifndef __WXGTK__
401 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
402 const wxString& text = wxPyEmptyStr,
403 const wxString& helpString = wxPyEmptyStr,
404 bool checkable = FALSE, wxMenu* subMenu = NULL);
405 #else
406 wxMenuItem();
407 #endif
408
409 bool IsSeparator();
410 bool IsEnabled();
411 bool IsChecked();
412 bool IsCheckable();
413 int GetId();
414 wxMenu* GetSubMenu();
415 void SetName(const wxString& strName);
416 wxString GetName();
417 wxString GetHelp();
418 void SetHelp(const wxString& strHelp);
419 void Enable(bool bDoEnable = TRUE);
420 void Check(bool bDoCheck = TRUE);
421
422 #ifdef __WXMSW__
423 wxColour& GetBackgroundColour();
424 wxBitmap GetBitmap(bool checked = TRUE);
425 wxFont& GetFont();
426 int GetMarginWidth();
427 wxColour& GetTextColour();
428 void SetBackgroundColour(const wxColour& colour);
429 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
430 void SetFont(const wxFont& font);
431 void SetMarginWidth(int width);
432 void SetTextColour(const wxColour& colour);
433 void DeleteSubMenu();
434 #endif
435 };
436
437 //---------------------------------------------------------------------------
438
439