]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/windows.i
Fixed wxImage GetData and SetData to properly use String objects for
[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 //%pragma(python) code = "import controls"
33 //%pragma(python) code = "wxButtonPtr = controls.wxWindowPtr"
34
35 //---------------------------------------------------------------------------
36
37 class wxEvtHandler {
38 public:
39 bool ProcessEvent(wxEvent& event);
40 %addmethods {
41 void Connect( int id, int lastId, int eventType, PyObject* func) {
42 if (PyCallable_Check(func)) {
43 self->Connect(id, lastId, eventType,
44 (wxObjectEventFunction) &wxPyCallback::EventThunker,
45 new wxPyCallback(func));
46 }
47 }
48 }
49 };
50
51
52 //----------------------------------------------------------------------
53
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 %name(ClientToScreenXY)void ClientToScreen(int *BOTH, int *BOTH);
72 wxPoint ClientToScreen(const wxPoint& pt);
73 bool Close(int force = FALSE);
74 bool Destroy();
75 void DestroyChildren();
76 #ifdef __WXMSW__
77 void DragAcceptFiles(bool accept);
78 #endif
79 void Enable(bool enable);
80 //bool FakePopupMenu(wxMenu* menu, int x, int y);
81 %name(FindWindowById) wxWindow* FindWindow(long id);
82 %name(FindWindowByName) wxWindow* FindWindow(const wxString& name);
83 void Fit();
84 wxColour GetBackgroundColour();
85 int GetCharHeight();
86 int GetCharWidth();
87 %name(GetClientSizeTuple) void GetClientSize(int *OUTPUT, int *OUTPUT);
88 wxSize GetClientSize();
89 wxLayoutConstraints * GetConstraints();
90 //wxEvtHandler* GetEventHandler();
91
92 wxFont& GetFont();
93 wxColour GetForegroundColour();
94 wxWindow * GetGrandParent();
95 int GetId();
96 wxString GetLabel();
97 void SetLabel(const wxString& label);
98 wxString GetName();
99 wxWindow * GetParent();
100 %name(GetPositionTuple) void GetPosition(int *OUTPUT, int *OUTPUT);
101 wxPoint GetPosition();
102 wxRect GetRect();
103 int GetScrollThumb(int orientation);
104 int GetScrollPos(int orientation);
105 int GetScrollRange(int orientation);
106 %name(GetSizeTuple) void GetSize(int *OUTPUT, int *OUTPUT);
107 wxSize GetSize();
108 void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT);
109 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
110 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
111 const wxFont* font = NULL); //, bool use16 = FALSE)
112 wxString GetTitle();
113 wxRegion GetUpdateRegion();
114 long GetWindowStyleFlag();
115 bool Hide();
116 void InitDialog();
117 bool IsEnabled();
118 bool IsRetained();
119 bool IsShown();
120 bool IsTopLevel();
121 void Layout();
122 bool LoadFromResource(wxWindow* parent, const wxString& resourceName, const wxResourceTable* resourceTable = NULL);
123 void Lower();
124 void MakeModal(bool flag);
125 %name(MoveXY)void Move(int x, int y);
126 void Move(const wxPoint& point);
127
128 //wxEvtHandler* PopEventHandler(bool deleteHandler = FALSE);
129 //void PushEventHandler(wxEvtHandler* handler);
130
131 %name(PopupMenuXY)bool PopupMenu(wxMenu *menu, int x, int y);
132 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
133
134 void Raise();
135 void Refresh(bool eraseBackground = TRUE, const wxRect* rect = NULL);
136 void ReleaseMouse();
137 bool Reparent( wxWindow* newParent );
138
139 %name(ScreenToClientXY)void ScreenToClient(int *BOTH, int *BOTH);
140 wxPoint ScreenToClient(const wxPoint& pt);
141
142 void ScrollWindow(int dx, int dy, const wxRect* rect = NULL);
143 void SetAcceleratorTable(const wxAcceleratorTable& accel);
144 void SetAutoLayout(bool autoLayout);
145 void SetBackgroundColour(const wxColour& colour);
146 void SetConstraints(wxLayoutConstraints *constraints);
147 void SetFocus();
148 void SetFont(const wxFont& font);
149 void SetForegroundColour(const wxColour& colour);
150 void SetId(int id);
151 void SetName(const wxString& name);
152 void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = TRUE);
153 void SetScrollPos(int orientation, int pos, bool refresh = TRUE);
154
155 %name(SetDimensions) void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO);
156 %addmethods {
157 void SetSize(const wxSize& size) {
158 self->SetSize(size.x, size.y);
159 }
160
161 void SetPosition(const wxPoint& pos) {
162 self->SetSize(pos.x, pos.y, -1, -1);
163 }
164 }
165
166 void SetSizeHints(int minW=-1, int minH=-1, int maxW=-1, int maxH=-1, int incW=-1, int incH=-1);
167 %name(SetClientSizeWH)void SetClientSize(int width, int height);
168 void SetClientSize(const wxSize& size);
169 //void SetPalette(wxPalette* palette);
170 void SetCursor(const wxCursor&cursor);
171 //void SetEventHandler(wxEvtHandler* handler);
172 void SetTitle(const wxString& title);
173 bool Show(bool show);
174 bool TransferDataFromWindow();
175 bool TransferDataToWindow();
176 bool Validate();
177 void WarpPointer(int x, int y);
178
179 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
180 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
181
182 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
183 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
184
185 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
186 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
187
188 %name(SetToolTipString)void SetToolTip(const wxString &tip);
189 void SetToolTip(wxToolTip *tooltip);
190 wxToolTip* GetToolTip();
191 };
192
193 %pragma(python) code = "
194 def wxDLG_PNT(win, point_or_x, y=None):
195 if y is None:
196 return win.ConvertDialogPointToPixels(point_or_x)
197 else:
198 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
199
200 def wxDLG_SZE(win, size_width, height=None):
201 if height is None:
202 return win.ConvertDialogSizeToPixels(size_width)
203 else:
204 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
205 "
206
207 #ifdef __WXMSW__
208 %inline %{
209 wxWindow* wxWindow_FindFocus() {
210 return wxWindow::FindFocus();
211 }
212 %}
213
214
215 %inline %{
216 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
217 wxWindow* win = new wxWindow;
218 win->SetHWND(hWnd);
219 win->SubclassWin(hWnd);
220 return win;
221 }
222 %}
223 #endif
224
225
226 //---------------------------------------------------------------------------
227
228 class wxPanel : public wxWindow {
229 public:
230 wxPanel(wxWindow* parent,
231 const wxWindowID id,
232 const wxPoint& pos = wxPyDefaultPosition,
233 const wxSize& size = wxPyDefaultSize,
234 long style = wxTAB_TRAVERSAL,
235 const char* name = "panel");
236
237 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
238
239 void InitDialog();
240 wxButton* GetDefaultItem();
241 void SetDefaultItem(wxButton *btn);
242
243 // fix a SWIG turd...
244 %pragma(python) addtoclass = "
245 def GetDefaultItem(self):
246 import controls
247 val = windowsc.wxPanel_GetDefaultItem(self.this)
248 val = controls.wxButtonPtr(val)
249 return val
250 "
251 };
252
253 //---------------------------------------------------------------------------
254
255 class wxDialog : public wxPanel {
256 public:
257 wxDialog(wxWindow* parent,
258 const wxWindowID id,
259 const wxString& title,
260 const wxPoint& pos = wxPyDefaultPosition,
261 const wxSize& size = wxPyDefaultSize,
262 long style = wxDEFAULT_DIALOG_STYLE,
263 const char* name = "dialogBox");
264
265 %pragma(python) addtomethod = "__init__:wx._StdDialogCallbacks(self)"
266
267 void Centre(int direction = wxBOTH);
268 void EndModal(int retCode);
269 wxString GetTitle();
270 void Iconize(bool iconize);
271 bool IsIconized();
272 void SetModal(bool flag);
273 bool IsModal();
274 void SetTitle(const wxString& title);
275 bool Show(bool show);
276 int ShowModal();
277
278 int GetReturnCode();
279 void SetReturnCode(int retCode);
280 };
281
282 //---------------------------------------------------------------------------
283
284 class wxScrolledWindow : public wxPanel {
285 public:
286 wxScrolledWindow(wxWindow* parent,
287 const wxWindowID id = -1,
288 const wxPoint& pos = wxPyDefaultPosition,
289 const wxSize& size = wxPyDefaultSize,
290 long style = wxHSCROLL | wxVSCROLL,
291 char* name = "scrolledWindow");
292
293 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
294 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
295
296 void EnableScrolling(bool xScrolling, bool yScrolling);
297 void GetScrollPixelsPerUnit(int* OUTPUT, int* OUTPUT);
298 void GetVirtualSize(int* OUTPUT, int* OUTPUT);
299 bool IsRetained();
300 void PrepareDC(wxDC& dc);
301 void Scroll(int x, int y);
302 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
303 int noUnitsX, int noUnitsY,
304 int xPos = 0, int yPos = 0);
305 void ViewStart(int* OUTPUT, int* OUTPUT);
306 };
307
308 //----------------------------------------------------------------------
309
310
311 class wxMenu : public wxEvtHandler {
312 public:
313 wxMenu(const wxString& title = wxPyEmptyStr, long style = 0);
314
315 void Append(int id, const wxString& item,
316 const wxString& helpString = wxPyEmptyStr,
317 int checkable = FALSE);
318 %name(AppendMenu)void Append(int id, const wxString& item, wxMenu *subMenu,
319 const wxString& helpString = wxPyEmptyStr);
320 #ifndef __WXGTK__
321 %name(AppendItem)void Append(const wxMenuItem* item);
322 #endif
323
324 void AppendSeparator();
325 void Break();
326 void Check(int id, bool flag);
327 void Enable(int id, bool enable);
328 int FindItem(const wxString& itemString);
329 wxString GetTitle();
330 void SetTitle(const wxString& title);
331 wxMenuItem* FindItemForId(int id);
332 wxString GetHelpString(int id);
333 wxString GetLabel(int id);
334 void SetHelpString(int id, const wxString& helpString);
335 bool IsChecked(int id);
336 bool IsEnabled(int id);
337 void SetLabel(int id, const wxString& label);
338 void UpdateUI(wxEvtHandler* source = NULL);
339 };
340
341
342 //
343 // This one knows how to set a callback and handle INC- and DECREFing it. To
344 // be used for PopupMenus, but you must retain a referece to it while using
345 // it.
346 //
347 // class wxPyMenu : public wxMenu {
348 // public:
349 // wxPyMenu(const wxString& title = wxPyEmptyStr, PyObject* func = NULL);
350 // ~wxPyMenu();
351 // };
352
353 //----------------------------------------------------------------------
354
355 class wxMenuBar : public wxEvtHandler {
356 public:
357 wxMenuBar();
358
359 void Append(wxMenu *menu, const wxString& title);
360 void Check(int id, bool flag);
361 bool Checked(int id);
362 void Enable(int id, bool enable);
363 bool Enabled(int id);
364 int FindMenuItem(const wxString& menuString, const wxString& itemString);
365 wxMenuItem * FindItemForId(int id);
366 #ifdef __WXMSW__
367 void EnableTop(int pos, bool enable);
368 wxString GetHelpString(int id);
369 wxString GetLabel(int id);
370 void SetHelpString(int id, const wxString& helpString);
371 void SetLabel(int id, const wxString& label);
372 wxString GetLabelTop(int pos);
373 void SetLabelTop(int pos, const wxString& label);
374 #endif
375 int GetMenuCount();
376 wxMenu* GetMenu(int i);
377 };
378
379
380 //----------------------------------------------------------------------
381
382 class wxMenuItem {
383 public:
384 #ifndef __WXGTK__
385 wxMenuItem(wxMenu* parentMenu=NULL, int id=ID_SEPARATOR,
386 const wxString& text = wxPyEmptyStr,
387 const wxString& helpString = wxPyEmptyStr,
388 bool checkable = FALSE, wxMenu* subMenu = NULL);
389 #else
390 wxMenuItem();
391 #endif
392
393 bool IsSeparator();
394 bool IsEnabled();
395 bool IsChecked();
396 bool IsCheckable();
397 int GetId();
398 wxMenu* GetSubMenu();
399 void SetName(const wxString& strName);
400 wxString GetName();
401 wxString GetHelp();
402 void SetHelp(const wxString& strHelp);
403 void Enable(bool bDoEnable = TRUE);
404 void Check(bool bDoCheck = TRUE);
405
406 #ifdef __WXMSW__
407 wxColour& GetBackgroundColour();
408 wxBitmap GetBitmap(bool checked = TRUE);
409 wxFont& GetFont();
410 int GetMarginWidth();
411 wxColour& GetTextColour();
412 void SetBackgroundColour(const wxColour& colour);
413 void SetBitmaps(const wxBitmap& checked, const wxBitmap& unchecked = wxNullBitmap);
414 void SetFont(const wxFont& font);
415 void SetMarginWidth(int width);
416 void SetTextColour(const wxColour& colour);
417 void DeleteSubMenu();
418 #endif
419 };
420
421 //---------------------------------------------------------------------------
422 /////////////////////////////////////////////////////////////////////////////
423 //
424 // $Log$
425 // Revision 1.18 1999/07/31 07:54:35 RD
426 // wxPython 2.1b1:
427 //
428 // Added the missing wxWindow.GetUpdateRegion() method.
429 //
430 // Made a new change in SWIG (update your patches everybody) that
431 // provides a fix for global shadow objects that get an exception in
432 // their __del__ when their extension module has already been deleted.
433 // It was only a 1 line change in .../SWIG/Modules/pycpp.cxx at about
434 // line 496 if you want to do it by hand.
435 //
436 // It is now possible to run through MainLoop more than once in any one
437 // process. The cleanup that used to happen as MainLoop completed (and
438 // prevented it from running again) has been delayed until the wxc module
439 // is being unloaded by Python.
440 //
441 // wxWindow.PopupMenu() now takes a wxPoint instead of x,y. Added
442 // wxWindow.PopupMenuXY to be consistent with some other methods.
443 //
444 // Added wxGrid.SetEditInPlace and wxGrid.GetEditInPlace.
445 //
446 // You can now provide your own app.MainLoop method. See
447 // wxPython/demo/demoMainLoop.py for an example and some explaination.
448 //
449 // Got the in-place-edit for the wxTreeCtrl fixed and added some demo
450 // code to show how to use it.
451 //
452 // Put the wxIcon constructor back in for GTK as it now has one that
453 // matches MSW's.
454 //
455 // Added wxGrid.GetCells
456 //
457 // Added wxSystemSettings static methods as functions with names like
458 // wxSystemSettings_GetSystemColour.
459 //
460 // Removed wxPyMenu since using menu callbacks have been depreciated in
461 // wxWindows. Use wxMenu and events instead.
462 //
463 // Added alternate wxBitmap constructor (for MSW only) as
464 // wxBitmapFromData(data, type, width, height, depth = 1)
465 //
466 // Added a helper function named wxPyTypeCast that can convert shadow
467 // objects of one type into shadow objects of another type. (Like doing
468 // a down-cast.) See the implementation in wx.py for some docs.
469 //
470 // Revision 1.17 1999/06/22 07:03:03 RD
471 //
472 // wxPython 2.1b1 for wxMSW (wxGTK coming soon)
473 // Lots of changes, see the README.txt for details...
474 //
475 // Revision 1.16 1999/05/15 00:56:04 RD
476 //
477 // fixes for GetReturnCode/SetReturnCode
478 //
479 // Revision 1.15 1999/04/30 03:29:19 RD
480 //
481 // wxPython 2.0b9, first phase (win32)
482 // Added gobs of stuff, see wxPython/README.txt for details
483 //
484 // Revision 1.14.4.3 1999/03/27 23:29:15 RD
485 //
486 // wxPython 2.0b8
487 // Python thread support
488 // various minor additions
489 // various minor fixes
490 //
491 // Revision 1.14.4.2 1999/03/16 06:26:29 RD
492 //
493 // wxPython 2.0b7
494 //
495 // Revision 1.14.4.1 1999/03/16 06:04:04 RD
496 //
497 // wxPython 2.0b7
498 //
499 // Revision 1.14 1999/02/23 23:48:33 RD
500 //
501 // reenabled some methods for wxPython on wxGTK
502 //
503 // Revision 1.13 1999/02/20 10:02:38 RD
504 //
505 // Changes needed to enable wxGTK compatibility.
506 //
507 // Revision 1.12 1999/02/20 09:03:03 RD
508 // Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
509 // window handle. If you can get the window handle into the python code,
510 // it should just work... More news on this later.
511 //
512 // Added wxImageList, wxToolTip.
513 //
514 // Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
515 // wxRegConfig class.
516 //
517 // As usual, some bug fixes, tweaks, etc.
518 //
519 // Revision 1.11 1998/12/18 15:49:10 RR
520 //
521 // wxClipboard now serves the primary selection as well
522 // wxPython fixes
523 // warning mesages
524 //
525 // Revision 1.10 1998/12/17 17:52:20 RD
526 //
527 // wxPython 0.5.2
528 // Minor fixes and SWIG code generation for RR's changes. MSW and GTK
529 // versions are much closer now!
530 //
531 // Revision 1.9 1998/12/17 14:07:46 RR
532 //
533 // Removed minor differences between wxMSW and wxGTK
534 //
535 // Revision 1.8 1998/12/16 22:10:56 RD
536 //
537 // Tweaks needed to be able to build wxPython with wxGTK.
538 //
539 // Revision 1.7 1998/12/15 20:41:25 RD
540 // Changed the import semantics from "from wxPython import *" to "from
541 // wxPython.wx import *" This is for people who are worried about
542 // namespace pollution, they can use "from wxPython import wx" and then
543 // prefix all the wxPython identifiers with "wx."
544 //
545 // Added wxTaskbarIcon for wxMSW.
546 //
547 // Made the events work for wxGrid.
548 //
549 // Added wxConfig.
550 //
551 // Added wxMiniFrame for wxGTK, (untested.)
552 //
553 // Changed many of the args and return values that were pointers to gdi
554 // objects to references to reflect changes in the wxWindows API.
555 //
556 // Other assorted fixes and additions.
557 //
558 // Revision 1.6 1998/10/02 06:40:43 RD
559 //
560 // Version 0.4 of wxPython for MSW.
561 //
562 // Revision 1.5 1998/08/17 18:29:40 RD
563 // Removed an extra method definition
564 //
565 // Revision 1.4 1998/08/16 04:31:11 RD
566 // More wxGTK work.
567 //
568 // Revision 1.3 1998/08/15 07:36:47 RD
569 // - Moved the header in the .i files out of the code that gets put into
570 // the .cpp files. It caused CVS conflicts because of the RCS ID being
571 // different each time.
572 //
573 // - A few minor fixes.
574 //
575 // Revision 1.2 1998/08/14 23:36:46 RD
576 // Beginings of wxGTK compatibility
577 //
578 // Revision 1.1 1998/08/09 08:25:52 RD
579 // Initial version
580 //
581 //
582
583