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