]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
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 | ||
03e9bead | 13 | %module misc |
7bf85405 | 14 | |
03e9bead | 15 | %{ |
7bf85405 RD |
16 | #include "helpers.h" |
17 | #include <wx/resource.h> | |
af309447 | 18 | #include <wx/tooltip.h> |
2abc0a0f | 19 | #include <wx/busyinfo.h> |
7bf85405 RD |
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 | ||
7bf85405 | 30 | |
b68dc582 RD |
31 | %{ |
32 | static wxString wxPyEmptyStr(""); | |
33 | %} | |
34 | ||
bb0054cd | 35 | //--------------------------------------------------------------------------- |
7bf85405 RD |
36 | |
37 | ||
38 | class wxSize { | |
39 | public: | |
af309447 RD |
40 | long x; |
41 | long y; | |
7bf85405 RD |
42 | %name(width) long x; |
43 | %name(height)long y; | |
44 | ||
45 | wxSize(long w=0, long h=0); | |
46 | ~wxSize(); | |
47 | void Set(long w, long h); | |
af309447 RD |
48 | long GetX(); |
49 | long GetY(); | |
bb0054cd RD |
50 | long GetWidth(); |
51 | long GetHeight(); | |
52 | void SetWidth(long w); | |
53 | void SetHeight(long h); | |
7bf85405 RD |
54 | |
55 | %addmethods { | |
af309447 | 56 | PyObject* asTuple() { |
7bf85405 RD |
57 | PyObject* tup = PyTuple_New(2); |
58 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
59 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
60 | return tup; | |
61 | } | |
62 | } | |
1b62f00d RD |
63 | |
64 | %pragma(python) addtoclass = " | |
65 | def __str__(self): return str(self.asTuple()) | |
66 | def __repr__(self): return str(self.asTuple()) | |
211a46cf | 67 | def __len__(self): return len(self.asTuple()) |
1b62f00d RD |
68 | def __getitem__(self, index): return self.asTuple()[index] |
69 | def __setitem__(self, index, val): | |
70 | if index == 0: self.width = val | |
71 | elif index == 1: self.height = val | |
72 | else: raise IndexError | |
73 | " | |
af309447 | 74 | |
7bf85405 RD |
75 | }; |
76 | ||
77 | //--------------------------------------------------------------------------- | |
78 | ||
79 | class wxRealPoint { | |
80 | public: | |
81 | double x; | |
82 | double y; | |
83 | wxRealPoint(double x=0.0, double y=0.0); | |
84 | ~wxRealPoint(); | |
efc5f224 RD |
85 | |
86 | %addmethods { | |
87 | void Set(double x, double y) { | |
88 | self->x = x; | |
89 | self->y = y; | |
90 | } | |
91 | PyObject* asTuple() { | |
92 | PyObject* tup = PyTuple_New(2); | |
93 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); | |
94 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); | |
95 | return tup; | |
96 | } | |
c368d904 RD |
97 | |
98 | wxRealPoint __add__(const wxRealPoint* p) { | |
99 | if (! p) return *self; | |
100 | return *self + *p; | |
101 | } | |
102 | ||
103 | wxRealPoint __sub__(const wxRealPoint* p) { | |
104 | if (! p) return *self; | |
105 | return *self - *p; | |
106 | } | |
107 | ||
108 | int __cmp__(const wxRealPoint* p) { | |
109 | if (! p) return 0; | |
110 | return *self == *p; | |
111 | } | |
efc5f224 | 112 | } |
1b62f00d RD |
113 | %pragma(python) addtoclass = " |
114 | def __str__(self): return str(self.asTuple()) | |
115 | def __repr__(self): return str(self.asTuple()) | |
211a46cf | 116 | def __len__(self): return len(self.asTuple()) |
1b62f00d RD |
117 | def __getitem__(self, index): return self.asTuple()[index] |
118 | def __setitem__(self, index, val): | |
119 | if index == 0: self.width = val | |
120 | elif index == 1: self.height = val | |
121 | else: raise IndexError | |
122 | " | |
7bf85405 RD |
123 | }; |
124 | ||
efc5f224 | 125 | |
7bf85405 RD |
126 | class wxPoint { |
127 | public: | |
128 | long x; | |
129 | long y; | |
130 | wxPoint(long x=0, long y=0); | |
131 | ~wxPoint(); | |
132 | ||
133 | %addmethods { | |
134 | void Set(long x, long y) { | |
135 | self->x = x; | |
136 | self->y = y; | |
137 | } | |
af309447 | 138 | PyObject* asTuple() { |
7bf85405 RD |
139 | PyObject* tup = PyTuple_New(2); |
140 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
141 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
142 | return tup; | |
143 | } | |
c368d904 RD |
144 | |
145 | wxPoint __add__(const wxPoint* p) { | |
146 | if (! p) return *self; | |
147 | return *self + *p; | |
148 | } | |
149 | ||
150 | wxPoint __sub__(const wxPoint* p) { | |
151 | if (! p) return *self; | |
152 | return *self - *p; | |
153 | } | |
154 | ||
155 | int __cmp__(const wxPoint* p) { | |
156 | if (! p) return 0; | |
157 | return *self == *p; | |
158 | } | |
7bf85405 | 159 | } |
1b62f00d RD |
160 | %pragma(python) addtoclass = " |
161 | def __str__(self): return str(self.asTuple()) | |
162 | def __repr__(self): return str(self.asTuple()) | |
211a46cf | 163 | def __len__(self): return len(self.asTuple()) |
1b62f00d RD |
164 | def __getitem__(self, index): return self.asTuple()[index] |
165 | def __setitem__(self, index, val): | |
166 | if index == 0: self.x = val | |
167 | elif index == 1: self.y = val | |
168 | else: raise IndexError | |
169 | " | |
7bf85405 RD |
170 | }; |
171 | ||
172 | //--------------------------------------------------------------------------- | |
173 | ||
174 | class wxRect { | |
175 | public: | |
eb715945 RD |
176 | wxRect(int x=0, int y=0, int w=0, int h=0); |
177 | // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size); | |
178 | ~wxRect(); | |
7bf85405 | 179 | |
eb715945 RD |
180 | int GetX(); |
181 | void SetX(int X); | |
182 | int GetY(); | |
183 | void SetY(int Y); | |
184 | int GetWidth(); | |
185 | void SetWidth(int w); | |
186 | int GetHeight(); | |
187 | void SetHeight(int h); | |
7bf85405 RD |
188 | |
189 | ||
eb715945 RD |
190 | wxPoint GetPosition(); |
191 | wxSize GetSize(); | |
7bf85405 | 192 | |
eb715945 RD |
193 | int GetLeft(); |
194 | int GetTop(); | |
195 | int GetBottom(); | |
196 | int GetRight(); | |
7bf85405 | 197 | |
eb715945 RD |
198 | void SetLeft(int left); |
199 | void SetRight(int right); | |
200 | void SetTop(int top); | |
201 | void SetBottom(int bottom); | |
202 | ||
f6bcfd97 BP |
203 | void Inflate(int dx, int dy); |
204 | bool Inside(int cx, int cy); | |
eb715945 RD |
205 | |
206 | int x, y, width, height; | |
af309447 RD |
207 | |
208 | %addmethods { | |
209 | PyObject* asTuple() { | |
210 | PyObject* tup = PyTuple_New(4); | |
211 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
212 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
f0261a72 RD |
213 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); |
214 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
af309447 RD |
215 | return tup; |
216 | } | |
f6bcfd97 BP |
217 | |
218 | wxRect __add__(const wxRect* rect) { | |
219 | if (! rect) return *self; | |
220 | return *self + *rect; | |
221 | } | |
222 | ||
223 | int __cmp__(const wxRect* rect) { | |
224 | if (! rect) return 0; | |
225 | return *self == *rect; | |
226 | } | |
af309447 | 227 | } |
f6bcfd97 | 228 | |
9b3d3bc4 | 229 | %pragma(python) addtoclass = " |
1b62f00d RD |
230 | def __str__(self): return str(self.asTuple()) |
231 | def __repr__(self): return str(self.asTuple()) | |
211a46cf | 232 | def __len__(self): return len(self.asTuple()) |
1b62f00d RD |
233 | def __getitem__(self, index): return self.asTuple()[index] |
234 | def __setitem__(self, index, val): | |
235 | if index == 0: self.x = val | |
236 | elif index == 1: self.y = val | |
237 | elif index == 2: self.width = val | |
238 | elif index == 3: self.height = val | |
239 | else: raise IndexError | |
240 | ||
9b3d3bc4 RD |
241 | # override the __getattr__ made by SWIG |
242 | def __getattr__(self, name): | |
243 | d = { | |
244 | 'x' : miscc.wxRect_x_get, | |
245 | 'y' : miscc.wxRect_y_get, | |
246 | 'width' : miscc.wxRect_width_get, | |
247 | 'height' : miscc.wxRect_height_get, | |
248 | 'top' : miscc.wxRect_GetTop, | |
249 | 'bottom' : miscc.wxRect_GetBottom, | |
250 | 'left' : miscc.wxRect_GetLeft, | |
251 | 'right' : miscc.wxRect_GetRight, | |
252 | } | |
253 | try: | |
254 | func = d[name] | |
255 | except KeyError: | |
256 | raise AttributeError,name | |
257 | return func(self) | |
258 | ||
259 | # and also the __setattr__ | |
260 | def __setattr__(self, name, value): | |
261 | d = { | |
262 | 'x' : miscc.wxRect_x_set, | |
263 | 'y' : miscc.wxRect_y_set, | |
264 | 'width' : miscc.wxRect_width_set, | |
265 | 'height' : miscc.wxRect_height_set, | |
266 | 'top' : miscc.wxRect_SetTop, | |
267 | 'bottom' : miscc.wxRect_SetBottom, | |
268 | 'left' : miscc.wxRect_SetLeft, | |
269 | 'right' : miscc.wxRect_SetRight, | |
270 | } | |
271 | try: | |
272 | func = d[name] | |
273 | except KeyError: | |
274 | self.__dict__[name] = value | |
275 | return | |
276 | func(self, value) | |
277 | " | |
278 | ||
7bf85405 RD |
279 | }; |
280 | ||
281 | ||
eb715945 RD |
282 | %inline %{ |
283 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
284 | wxRegion reg1(*r1); | |
285 | wxRegion reg2(*r2); | |
286 | wxRect dest(0,0,0,0); | |
287 | PyObject* obj; | |
288 | ||
289 | reg1.Intersect(reg2); | |
290 | dest = reg1.GetBox(); | |
291 | ||
292 | if (dest != wxRect(0,0,0,0)) { | |
293 | bool doSave = wxPyRestoreThread(); | |
294 | wxRect* newRect = new wxRect(dest); | |
295 | obj = wxPyConstructObject((void*)newRect, "wxRect"); | |
de20db99 RD |
296 | PyObject* one = PyInt_FromLong(1); |
297 | PyObject_SetAttrString(obj, "thisown", one); | |
298 | Py_DECREF(one); | |
eb715945 RD |
299 | wxPySaveThread(doSave); |
300 | return obj; | |
301 | } | |
302 | Py_INCREF(Py_None); | |
303 | return Py_None; | |
304 | } | |
305 | %} | |
7bf85405 | 306 | |
7bf85405 RD |
307 | |
308 | //--------------------------------------------------------------------------- | |
309 | // Miscellaneous functions | |
310 | ||
cf694132 RD |
311 | long wxNewId(); |
312 | void wxRegisterId(long id); | |
313 | %name(NewId) long wxNewId(); | |
314 | %name(RegisterId) void wxRegisterId(long id); | |
83b18bab | 315 | long wxGetCurrentId(); |
cf694132 | 316 | |
7bf85405 RD |
317 | void wxBell(); |
318 | void wxDisplaySize(int *OUTPUT, int *OUTPUT); | |
319 | void wxEndBusyCursor(); | |
c368d904 | 320 | |
7bf85405 | 321 | long wxGetElapsedTime(bool resetTimer = TRUE); |
bc29c5e0 | 322 | #ifdef __WXMSW__ |
7bf85405 | 323 | long wxGetFreeMemory(); |
bc29c5e0 | 324 | #endif |
7bf85405 RD |
325 | void wxGetMousePosition(int* OUTPUT, int* OUTPUT); |
326 | bool wxIsBusy(); | |
327 | wxString wxNow(); | |
fb5e0af0 | 328 | bool wxShell(const wxString& command = wxPyEmptyStr); |
7bf85405 | 329 | void wxStartTimer(); |
fb5e0af0 | 330 | int wxGetOsVersion(int *OUTPUT, int *OUTPUT); |
c368d904 | 331 | wxString wxGetOsDescription(); |
fb5e0af0 | 332 | |
bb0054cd | 333 | void wxSleep(int secs); |
c368d904 | 334 | void wxUsleep(unsigned long milliseconds); |
7bf85405 | 335 | bool wxYield(); |
83b18bab | 336 | bool wxYieldIfNeeded(); |
bb0054cd | 337 | void wxEnableTopLevelWindows(bool enable); |
7bf85405 | 338 | |
7bf85405 RD |
339 | %inline %{ |
340 | char* wxGetResource(char *section, char *entry, char *file = NULL) { | |
341 | char * retval; | |
342 | wxGetResource(section, entry, &retval, file); | |
343 | return retval; | |
344 | } | |
345 | %} | |
346 | ||
694759cf | 347 | wxString wxStripMenuCodes(const wxString& in); |
7bf85405 | 348 | |
c368d904 RD |
349 | |
350 | wxString wxGetEmailAddress(); | |
351 | wxString wxGetHostName(); | |
352 | wxString wxGetFullHostName(); | |
353 | wxString wxGetUserId(); | |
354 | wxString wxGetUserName(); | |
355 | wxString wxGetHomeDir(); | |
356 | ||
357 | ||
7bf85405 RD |
358 | //---------------------------------------------------------------------- |
359 | ||
7bf85405 RD |
360 | enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight, |
361 | wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY }; | |
362 | enum wxRelationship { wxUnconstrained = 0, | |
363 | wxAsIs, | |
364 | wxPercentOf, | |
365 | wxAbove, | |
366 | wxBelow, | |
367 | wxLeftOf, | |
368 | wxRightOf, | |
369 | wxSameAs, | |
370 | wxAbsolute }; | |
371 | ||
372 | ||
373 | class wxIndividualLayoutConstraint { | |
374 | public: | |
375 | // wxIndividualLayoutConstraint(); | |
376 | // ~wxIndividualLayoutConstraint(); | |
377 | ||
378 | void Above(wxWindow *otherWin, int margin=0); | |
379 | void Absolute(int value); | |
08127323 | 380 | void AsIs(); |
7bf85405 | 381 | void Below(wxWindow *otherWin, int margin=0); |
08127323 | 382 | void Unconstrained(); |
7bf85405 RD |
383 | void LeftOf(wxWindow *otherWin, int margin=0); |
384 | void PercentOf(wxWindow *otherWin, wxEdge edge, int percent); | |
385 | void RightOf(wxWindow *otherWin, int margin=0); | |
386 | void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0); | |
387 | void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0); | |
388 | }; | |
389 | ||
390 | ||
391 | class wxLayoutConstraints { | |
392 | public: | |
393 | wxLayoutConstraints(); | |
394 | ||
395 | %readonly | |
396 | wxIndividualLayoutConstraint bottom; | |
397 | wxIndividualLayoutConstraint centreX; | |
398 | wxIndividualLayoutConstraint centreY; | |
399 | wxIndividualLayoutConstraint height; | |
400 | wxIndividualLayoutConstraint left; | |
401 | wxIndividualLayoutConstraint right; | |
402 | wxIndividualLayoutConstraint top; | |
403 | wxIndividualLayoutConstraint width; | |
404 | %readwrite | |
405 | } | |
406 | ||
407 | ||
b639c3c5 RD |
408 | //--------------------------------------------------------------------------- |
409 | // Regions, etc. | |
410 | ||
411 | enum wxRegionContain { | |
412 | wxOutRegion, wxPartRegion, wxInRegion | |
413 | }; | |
414 | ||
415 | ||
416 | class wxRegion { | |
417 | public: | |
c368d904 | 418 | wxRegion(long x=0, long y=0, long width=0, long height=0); |
b639c3c5 RD |
419 | ~wxRegion(); |
420 | ||
421 | void Clear(); | |
422 | wxRegionContain Contains(long x, long y); | |
423 | %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt); | |
424 | %name(ContainsRect)wxRegionContain Contains(const wxRect& rect); | |
eb715945 | 425 | %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h); |
b639c3c5 RD |
426 | |
427 | wxRect GetBox(); | |
eb715945 RD |
428 | |
429 | bool Intersect(long x, long y, long width, long height); | |
430 | %name(IntersectRect)bool Intersect(const wxRect& rect); | |
431 | %name(IntersectRegion)bool Intersect(const wxRegion& region); | |
432 | ||
b639c3c5 | 433 | bool IsEmpty(); |
eb715945 RD |
434 | |
435 | bool Union(long x, long y, long width, long height); | |
436 | %name(UnionRect)bool Union(const wxRect& rect); | |
437 | %name(UnionRegion)bool Union(const wxRegion& region); | |
438 | ||
439 | bool Subtract(long x, long y, long width, long height); | |
440 | %name(SubtractRect)bool Subtract(const wxRect& rect); | |
441 | %name(SubtractRegion)bool Subtract(const wxRegion& region); | |
442 | ||
443 | bool Xor(long x, long y, long width, long height); | |
444 | %name(XorRect)bool Xor(const wxRect& rect); | |
445 | %name(XorRegion)bool Xor(const wxRegion& region); | |
b639c3c5 RD |
446 | }; |
447 | ||
448 | ||
449 | ||
450 | class wxRegionIterator { | |
451 | public: | |
452 | wxRegionIterator(const wxRegion& region); | |
453 | ~wxRegionIterator(); | |
454 | ||
455 | long GetX(); | |
456 | long GetY(); | |
457 | long GetW(); | |
458 | long GetWidth(); | |
459 | long GetH(); | |
460 | long GetHeight(); | |
461 | wxRect GetRect(); | |
462 | bool HaveRects(); | |
463 | void Reset(); | |
464 | ||
465 | %addmethods { | |
466 | void Next() { | |
467 | (*self) ++; | |
468 | } | |
469 | }; | |
470 | }; | |
471 | ||
472 | ||
473 | ||
7bf85405 RD |
474 | //--------------------------------------------------------------------------- |
475 | // Accelerator Entry and Table | |
476 | ||
477 | class wxAcceleratorEntry { | |
478 | public: | |
479 | wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0); | |
2f90df85 | 480 | ~wxAcceleratorEntry(); |
7bf85405 RD |
481 | |
482 | void Set(int flags, int keyCode, int Cmd); | |
483 | int GetFlags(); | |
484 | int GetKeyCode(); | |
485 | int GetCommand(); | |
486 | }; | |
487 | ||
488 | ||
489 | class wxAcceleratorTable { | |
490 | public: | |
491 | // Can also accept a list of 3-tuples | |
eec92d76 | 492 | wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices); |
2f90df85 | 493 | ~wxAcceleratorTable(); |
7bf85405 RD |
494 | |
495 | }; | |
faf3cb35 | 496 | |
c368d904 | 497 | wxAcceleratorEntry *wxGetAccelFromString(const wxString& label); |
f6bcfd97 BP |
498 | |
499 | %readonly | |
500 | %{ | |
501 | #if 0 // we want to use the definition from the header, not the | |
502 | // one SWIG will generate. | |
503 | %} | |
504 | extern wxAcceleratorTable wxNullAcceleratorTable; | |
505 | %{ | |
506 | #endif | |
507 | %} | |
508 | %readwrite | |
509 | ||
8bf5d46e | 510 | //--------------------------------------------------------------------------- |
2abc0a0f RD |
511 | |
512 | class wxBusyInfo { | |
513 | public: | |
514 | wxBusyInfo(const wxString& message); | |
515 | ~wxBusyInfo(); | |
516 | }; | |
517 | ||
8bf5d46e RD |
518 | //--------------------------------------------------------------------------- |
519 | ||
520 | ||
c368d904 | 521 |