]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc.i
second merge of the 2.2 branch (RL)
[wxWidgets.git] / wxPython / src / misc.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: misc.i
3 // Purpose: Definitions of miscelaneous functions and classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7/3/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module misc
14
15 %{
16 #include "helpers.h"
17 #include <wx/resource.h>
18 #include <wx/tooltip.h>
19 #include <wx/busyinfo.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
30
31 //---------------------------------------------------------------------------
32
33
34 class wxSize {
35 public:
36 long x;
37 long y;
38 %name(width) long x;
39 %name(height)long y;
40
41 wxSize(long w=0, long h=0);
42 ~wxSize();
43 void Set(long w, long h);
44 long GetX();
45 long GetY();
46 long GetWidth();
47 long GetHeight();
48 void SetWidth(long w);
49 void SetHeight(long h);
50
51 %addmethods {
52 PyObject* asTuple() {
53 PyObject* tup = PyTuple_New(2);
54 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
55 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
56 return tup;
57 }
58 }
59 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
60 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
61
62 };
63
64 //---------------------------------------------------------------------------
65
66 class wxRealPoint {
67 public:
68 double x;
69 double y;
70 wxRealPoint(double x=0.0, double y=0.0);
71 ~wxRealPoint();
72
73 %addmethods {
74 void Set(double x, double y) {
75 self->x = x;
76 self->y = y;
77 }
78 PyObject* asTuple() {
79 PyObject* tup = PyTuple_New(2);
80 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
81 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
82 return tup;
83 }
84 }
85 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
86 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
87 };
88
89
90 class wxPoint {
91 public:
92 long x;
93 long y;
94 wxPoint(long x=0, long y=0);
95 ~wxPoint();
96
97 %addmethods {
98 void Set(long x, long y) {
99 self->x = x;
100 self->y = y;
101 }
102 PyObject* asTuple() {
103 PyObject* tup = PyTuple_New(2);
104 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
105 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
106 return tup;
107 }
108 }
109 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
110 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
111 };
112
113 //---------------------------------------------------------------------------
114
115 class wxRect {
116 public:
117 wxRect(int x=0, int y=0, int w=0, int h=0);
118 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
119 ~wxRect();
120
121 int GetX();
122 void SetX(int X);
123 int GetY();
124 void SetY(int Y);
125 int GetWidth();
126 void SetWidth(int w);
127 int GetHeight();
128 void SetHeight(int h);
129
130
131 wxPoint GetPosition();
132 wxSize GetSize();
133
134 int GetLeft();
135 int GetTop();
136 int GetBottom();
137 int GetRight();
138
139 void SetLeft(int left);
140 void SetRight(int right);
141 void SetTop(int top);
142 void SetBottom(int bottom);
143
144 void Inflate(int dx, int dy);
145 bool Inside(int cx, int cy);
146
147 int x, y, width, height;
148
149 %addmethods {
150 PyObject* asTuple() {
151 PyObject* tup = PyTuple_New(4);
152 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
153 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
154 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
155 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
156 return tup;
157 }
158
159 wxRect __add__(const wxRect* rect) {
160 if (! rect) return *self;
161 return *self + *rect;
162 }
163
164 int __cmp__(const wxRect* rect) {
165 if (! rect) return 0;
166 return *self == *rect;
167 }
168 }
169
170 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
171 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
172 %pragma(python) addtoclass = "
173 # override the __getattr__ made by SWIG
174 def __getattr__(self, name):
175 d = {
176 'x' : miscc.wxRect_x_get,
177 'y' : miscc.wxRect_y_get,
178 'width' : miscc.wxRect_width_get,
179 'height' : miscc.wxRect_height_get,
180 'top' : miscc.wxRect_GetTop,
181 'bottom' : miscc.wxRect_GetBottom,
182 'left' : miscc.wxRect_GetLeft,
183 'right' : miscc.wxRect_GetRight,
184 }
185 try:
186 func = d[name]
187 except KeyError:
188 raise AttributeError,name
189 return func(self)
190
191 # and also the __setattr__
192 def __setattr__(self, name, value):
193 d = {
194 'x' : miscc.wxRect_x_set,
195 'y' : miscc.wxRect_y_set,
196 'width' : miscc.wxRect_width_set,
197 'height' : miscc.wxRect_height_set,
198 'top' : miscc.wxRect_SetTop,
199 'bottom' : miscc.wxRect_SetBottom,
200 'left' : miscc.wxRect_SetLeft,
201 'right' : miscc.wxRect_SetRight,
202 }
203 try:
204 func = d[name]
205 except KeyError:
206 self.__dict__[name] = value
207 return
208 func(self, value)
209 "
210
211 };
212
213
214 %inline %{
215 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
216 wxRegion reg1(*r1);
217 wxRegion reg2(*r2);
218 wxRect dest(0,0,0,0);
219 PyObject* obj;
220
221 reg1.Intersect(reg2);
222 dest = reg1.GetBox();
223
224 if (dest != wxRect(0,0,0,0)) {
225 bool doSave = wxPyRestoreThread();
226 wxRect* newRect = new wxRect(dest);
227 obj = wxPyConstructObject((void*)newRect, "wxRect");
228 PyObject_SetAttrString(obj, "thisown", PyInt_FromLong(1));
229 wxPySaveThread(doSave);
230 return obj;
231 }
232 Py_INCREF(Py_None);
233 return Py_None;
234 }
235 %}
236
237
238 //---------------------------------------------------------------------------
239 // Miscellaneous functions
240
241 long wxNewId();
242 void wxRegisterId(long id);
243 %name(NewId) long wxNewId();
244 %name(RegisterId) void wxRegisterId(long id);
245
246 void wxBell();
247 void wxDisplaySize(int *OUTPUT, int *OUTPUT);
248 void wxEndBusyCursor();
249 long wxExecute(const wxString& command, int sync = FALSE);
250 long wxGetElapsedTime(bool resetTimer = TRUE);
251 #ifdef __WXMSW__
252 long wxGetFreeMemory();
253 #endif
254 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
255 bool wxIsBusy();
256 wxString wxNow();
257 bool wxShell(const wxString& command = wxPyEmptyStr);
258 void wxStartTimer();
259 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
260
261 void wxSleep(int secs);
262 bool wxYield();
263 bool wxSafeYield();
264 void wxEnableTopLevelWindows(bool enable);
265
266 %inline %{
267 char* wxGetResource(char *section, char *entry, char *file = NULL) {
268 char * retval;
269 wxGetResource(section, entry, &retval, file);
270 return retval;
271 }
272 %}
273
274 wxString wxStripMenuCodes(const wxString& in);
275
276 //----------------------------------------------------------------------
277
278 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
279 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
280 enum wxRelationship { wxUnconstrained = 0,
281 wxAsIs,
282 wxPercentOf,
283 wxAbove,
284 wxBelow,
285 wxLeftOf,
286 wxRightOf,
287 wxSameAs,
288 wxAbsolute };
289
290
291 class wxIndividualLayoutConstraint {
292 public:
293 // wxIndividualLayoutConstraint();
294 // ~wxIndividualLayoutConstraint();
295
296 void Above(wxWindow *otherWin, int margin=0);
297 void Absolute(int value);
298 void AsIs();
299 void Below(wxWindow *otherWin, int margin=0);
300 void Unconstrained();
301 void LeftOf(wxWindow *otherWin, int margin=0);
302 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
303 void RightOf(wxWindow *otherWin, int margin=0);
304 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
305 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
306 };
307
308
309 class wxLayoutConstraints {
310 public:
311 wxLayoutConstraints();
312
313 %readonly
314 wxIndividualLayoutConstraint bottom;
315 wxIndividualLayoutConstraint centreX;
316 wxIndividualLayoutConstraint centreY;
317 wxIndividualLayoutConstraint height;
318 wxIndividualLayoutConstraint left;
319 wxIndividualLayoutConstraint right;
320 wxIndividualLayoutConstraint top;
321 wxIndividualLayoutConstraint width;
322 %readwrite
323 }
324
325
326 //---------------------------------------------------------------------------
327 // Regions, etc.
328
329 enum wxRegionContain {
330 wxOutRegion, wxPartRegion, wxInRegion
331 };
332
333
334 class wxRegion {
335 public:
336 wxRegion();
337 ~wxRegion();
338
339 void Clear();
340 wxRegionContain Contains(long x, long y);
341 %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt);
342 %name(ContainsRect)wxRegionContain Contains(const wxRect& rect);
343 %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
344
345 wxRect GetBox();
346
347 bool Intersect(long x, long y, long width, long height);
348 %name(IntersectRect)bool Intersect(const wxRect& rect);
349 %name(IntersectRegion)bool Intersect(const wxRegion& region);
350
351 bool IsEmpty();
352
353 bool Union(long x, long y, long width, long height);
354 %name(UnionRect)bool Union(const wxRect& rect);
355 %name(UnionRegion)bool Union(const wxRegion& region);
356
357 bool Subtract(long x, long y, long width, long height);
358 %name(SubtractRect)bool Subtract(const wxRect& rect);
359 %name(SubtractRegion)bool Subtract(const wxRegion& region);
360
361 bool Xor(long x, long y, long width, long height);
362 %name(XorRect)bool Xor(const wxRect& rect);
363 %name(XorRegion)bool Xor(const wxRegion& region);
364 };
365
366
367
368 class wxRegionIterator {
369 public:
370 wxRegionIterator(const wxRegion& region);
371 ~wxRegionIterator();
372
373 long GetX();
374 long GetY();
375 long GetW();
376 long GetWidth();
377 long GetH();
378 long GetHeight();
379 wxRect GetRect();
380 bool HaveRects();
381 void Reset();
382
383 %addmethods {
384 void Next() {
385 (*self) ++;
386 }
387 };
388 };
389
390
391
392 //---------------------------------------------------------------------------
393 // Accelerator Entry and Table
394
395 class wxAcceleratorEntry {
396 public:
397 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
398 ~wxAcceleratorEntry();
399
400 void Set(int flags, int keyCode, int Cmd);
401 int GetFlags();
402 int GetKeyCode();
403 int GetCommand();
404 };
405
406
407 class wxAcceleratorTable {
408 public:
409 // Can also accept a list of 3-tuples
410 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
411 ~wxAcceleratorTable();
412
413 };
414
415
416 %readonly
417 %{
418 #if 0 // we want to use the definition from the header, not the
419 // one SWIG will generate.
420 %}
421 extern wxAcceleratorTable wxNullAcceleratorTable;
422 %{
423 #endif
424 %}
425 %readwrite
426
427 //---------------------------------------------------------------------------
428
429 class wxBusyInfo {
430 public:
431 wxBusyInfo(const wxString& message);
432 ~wxBusyInfo();
433 };
434
435
436
437 //---------------------------------------------------------------------------
438
439