]>
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 | ||
34 | class wxSize { | |
35 | public: | |
af309447 RD |
36 | long x; |
37 | long y; | |
7bf85405 RD |
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); | |
af309447 RD |
44 | long GetX(); |
45 | long GetY(); | |
bb0054cd RD |
46 | long GetWidth(); |
47 | long GetHeight(); | |
48 | void SetWidth(long w); | |
49 | void SetHeight(long h); | |
7bf85405 RD |
50 | |
51 | %addmethods { | |
af309447 | 52 | PyObject* asTuple() { |
7bf85405 RD |
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 | } | |
af309447 RD |
59 | %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())" |
60 | %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())" | |
61 | ||
7bf85405 RD |
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(); | |
efc5f224 RD |
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())" | |
7bf85405 RD |
87 | }; |
88 | ||
efc5f224 | 89 | |
7bf85405 RD |
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 | } | |
af309447 | 102 | PyObject* asTuple() { |
7bf85405 RD |
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 | } | |
af309447 RD |
109 | %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())" |
110 | %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())" | |
7bf85405 RD |
111 | }; |
112 | ||
113 | //--------------------------------------------------------------------------- | |
114 | ||
115 | class wxRect { | |
116 | public: | |
eb715945 RD |
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(); | |
7bf85405 | 120 | |
eb715945 RD |
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); | |
7bf85405 RD |
129 | |
130 | ||
eb715945 RD |
131 | wxPoint GetPosition(); |
132 | wxSize GetSize(); | |
7bf85405 | 133 | |
eb715945 RD |
134 | int GetLeft(); |
135 | int GetTop(); | |
136 | int GetBottom(); | |
137 | int GetRight(); | |
7bf85405 | 138 | |
eb715945 RD |
139 | void SetLeft(int left); |
140 | void SetRight(int right); | |
141 | void SetTop(int top); | |
142 | void SetBottom(int bottom); | |
143 | ||
144 | ||
145 | int x, y, width, height; | |
af309447 RD |
146 | |
147 | %addmethods { | |
148 | PyObject* asTuple() { | |
149 | PyObject* tup = PyTuple_New(4); | |
150 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
151 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
f0261a72 RD |
152 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); |
153 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
af309447 RD |
154 | return tup; |
155 | } | |
156 | } | |
157 | %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())" | |
158 | %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())" | |
9b3d3bc4 RD |
159 | %pragma(python) addtoclass = " |
160 | # override the __getattr__ made by SWIG | |
161 | def __getattr__(self, name): | |
162 | d = { | |
163 | 'x' : miscc.wxRect_x_get, | |
164 | 'y' : miscc.wxRect_y_get, | |
165 | 'width' : miscc.wxRect_width_get, | |
166 | 'height' : miscc.wxRect_height_get, | |
167 | 'top' : miscc.wxRect_GetTop, | |
168 | 'bottom' : miscc.wxRect_GetBottom, | |
169 | 'left' : miscc.wxRect_GetLeft, | |
170 | 'right' : miscc.wxRect_GetRight, | |
171 | } | |
172 | try: | |
173 | func = d[name] | |
174 | except KeyError: | |
175 | raise AttributeError,name | |
176 | return func(self) | |
177 | ||
178 | # and also the __setattr__ | |
179 | def __setattr__(self, name, value): | |
180 | d = { | |
181 | 'x' : miscc.wxRect_x_set, | |
182 | 'y' : miscc.wxRect_y_set, | |
183 | 'width' : miscc.wxRect_width_set, | |
184 | 'height' : miscc.wxRect_height_set, | |
185 | 'top' : miscc.wxRect_SetTop, | |
186 | 'bottom' : miscc.wxRect_SetBottom, | |
187 | 'left' : miscc.wxRect_SetLeft, | |
188 | 'right' : miscc.wxRect_SetRight, | |
189 | } | |
190 | try: | |
191 | func = d[name] | |
192 | except KeyError: | |
193 | self.__dict__[name] = value | |
194 | return | |
195 | func(self, value) | |
196 | " | |
197 | ||
7bf85405 RD |
198 | }; |
199 | ||
200 | ||
eb715945 RD |
201 | // %inline %{ |
202 | // bool wxIntersectRect(wxRect* dest, wxRect* r1, wxRect* r2) { | |
203 | // wxRegion reg1(*r1); | |
204 | // wxRegion reg2(*r2); | |
205 | // bool success; | |
206 | // *dest = wxRect(0,0,0,0); | |
207 | // success = reg1.Intersect(reg2); | |
208 | // if (success) { | |
209 | // *dest = reg1.GetBox(); | |
210 | // return *dest != wxRect(0,0,0,0); | |
211 | // } | |
212 | // return FALSE; | |
213 | // } | |
214 | // %} | |
215 | ||
216 | ||
217 | %inline %{ | |
218 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
219 | wxRegion reg1(*r1); | |
220 | wxRegion reg2(*r2); | |
221 | wxRect dest(0,0,0,0); | |
222 | PyObject* obj; | |
223 | ||
224 | reg1.Intersect(reg2); | |
225 | dest = reg1.GetBox(); | |
226 | ||
227 | if (dest != wxRect(0,0,0,0)) { | |
228 | bool doSave = wxPyRestoreThread(); | |
229 | wxRect* newRect = new wxRect(dest); | |
230 | obj = wxPyConstructObject((void*)newRect, "wxRect"); | |
231 | PyObject_SetAttrString(obj, "thisown", PyInt_FromLong(1)); | |
232 | wxPySaveThread(doSave); | |
233 | return obj; | |
234 | } | |
235 | Py_INCREF(Py_None); | |
236 | return Py_None; | |
237 | } | |
238 | %} | |
7bf85405 | 239 | |
7bf85405 RD |
240 | |
241 | //--------------------------------------------------------------------------- | |
242 | // Miscellaneous functions | |
243 | ||
cf694132 RD |
244 | long wxNewId(); |
245 | void wxRegisterId(long id); | |
246 | %name(NewId) long wxNewId(); | |
247 | %name(RegisterId) void wxRegisterId(long id); | |
248 | ||
7bf85405 RD |
249 | void wxBell(); |
250 | void wxDisplaySize(int *OUTPUT, int *OUTPUT); | |
251 | void wxEndBusyCursor(); | |
eb715945 | 252 | long wxExecute(const wxString& command, int sync = FALSE); |
7bf85405 | 253 | long wxGetElapsedTime(bool resetTimer = TRUE); |
bc29c5e0 | 254 | #ifdef __WXMSW__ |
7bf85405 | 255 | long wxGetFreeMemory(); |
bc29c5e0 | 256 | #endif |
7bf85405 RD |
257 | void wxGetMousePosition(int* OUTPUT, int* OUTPUT); |
258 | bool wxIsBusy(); | |
259 | wxString wxNow(); | |
fb5e0af0 | 260 | bool wxShell(const wxString& command = wxPyEmptyStr); |
7bf85405 | 261 | void wxStartTimer(); |
fb5e0af0 | 262 | int wxGetOsVersion(int *OUTPUT, int *OUTPUT); |
fb5e0af0 | 263 | |
bb0054cd | 264 | void wxSleep(int secs); |
7bf85405 | 265 | bool wxYield(); |
cf694132 | 266 | bool wxSafeYield(); |
bb0054cd | 267 | void wxEnableTopLevelWindows(bool enable); |
7bf85405 | 268 | |
7bf85405 RD |
269 | %inline %{ |
270 | char* wxGetResource(char *section, char *entry, char *file = NULL) { | |
271 | char * retval; | |
272 | wxGetResource(section, entry, &retval, file); | |
273 | return retval; | |
274 | } | |
275 | %} | |
276 | ||
694759cf | 277 | wxString wxStripMenuCodes(const wxString& in); |
7bf85405 RD |
278 | |
279 | //---------------------------------------------------------------------- | |
280 | ||
281 | class wxPyTimer { | |
282 | public: | |
283 | wxPyTimer(PyObject* notify); | |
284 | ~wxPyTimer(); | |
694759cf RD |
285 | int GetInterval(); |
286 | bool IsOneShot(); | |
7bf85405 RD |
287 | void Start(int milliseconds=-1, int oneShot=FALSE); |
288 | void Stop(); | |
289 | }; | |
290 | ||
291 | //--------------------------------------------------------------------------- | |
292 | ||
293 | enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight, | |
294 | wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY }; | |
295 | enum wxRelationship { wxUnconstrained = 0, | |
296 | wxAsIs, | |
297 | wxPercentOf, | |
298 | wxAbove, | |
299 | wxBelow, | |
300 | wxLeftOf, | |
301 | wxRightOf, | |
302 | wxSameAs, | |
303 | wxAbsolute }; | |
304 | ||
305 | ||
306 | class wxIndividualLayoutConstraint { | |
307 | public: | |
308 | // wxIndividualLayoutConstraint(); | |
309 | // ~wxIndividualLayoutConstraint(); | |
310 | ||
311 | void Above(wxWindow *otherWin, int margin=0); | |
312 | void Absolute(int value); | |
08127323 | 313 | void AsIs(); |
7bf85405 | 314 | void Below(wxWindow *otherWin, int margin=0); |
08127323 | 315 | void Unconstrained(); |
7bf85405 RD |
316 | void LeftOf(wxWindow *otherWin, int margin=0); |
317 | void PercentOf(wxWindow *otherWin, wxEdge edge, int percent); | |
318 | void RightOf(wxWindow *otherWin, int margin=0); | |
319 | void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0); | |
320 | void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0); | |
321 | }; | |
322 | ||
323 | ||
324 | class wxLayoutConstraints { | |
325 | public: | |
326 | wxLayoutConstraints(); | |
327 | ||
328 | %readonly | |
329 | wxIndividualLayoutConstraint bottom; | |
330 | wxIndividualLayoutConstraint centreX; | |
331 | wxIndividualLayoutConstraint centreY; | |
332 | wxIndividualLayoutConstraint height; | |
333 | wxIndividualLayoutConstraint left; | |
334 | wxIndividualLayoutConstraint right; | |
335 | wxIndividualLayoutConstraint top; | |
336 | wxIndividualLayoutConstraint width; | |
337 | %readwrite | |
338 | } | |
339 | ||
340 | ||
b639c3c5 RD |
341 | //--------------------------------------------------------------------------- |
342 | // Regions, etc. | |
343 | ||
344 | enum wxRegionContain { | |
345 | wxOutRegion, wxPartRegion, wxInRegion | |
346 | }; | |
347 | ||
348 | ||
349 | class wxRegion { | |
350 | public: | |
351 | wxRegion(); | |
352 | ~wxRegion(); | |
353 | ||
354 | void Clear(); | |
355 | wxRegionContain Contains(long x, long y); | |
356 | %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt); | |
357 | %name(ContainsRect)wxRegionContain Contains(const wxRect& rect); | |
eb715945 | 358 | %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h); |
b639c3c5 RD |
359 | |
360 | wxRect GetBox(); | |
eb715945 RD |
361 | |
362 | bool Intersect(long x, long y, long width, long height); | |
363 | %name(IntersectRect)bool Intersect(const wxRect& rect); | |
364 | %name(IntersectRegion)bool Intersect(const wxRegion& region); | |
365 | ||
b639c3c5 | 366 | bool IsEmpty(); |
eb715945 RD |
367 | |
368 | bool Union(long x, long y, long width, long height); | |
369 | %name(UnionRect)bool Union(const wxRect& rect); | |
370 | %name(UnionRegion)bool Union(const wxRegion& region); | |
371 | ||
372 | bool Subtract(long x, long y, long width, long height); | |
373 | %name(SubtractRect)bool Subtract(const wxRect& rect); | |
374 | %name(SubtractRegion)bool Subtract(const wxRegion& region); | |
375 | ||
376 | bool Xor(long x, long y, long width, long height); | |
377 | %name(XorRect)bool Xor(const wxRect& rect); | |
378 | %name(XorRegion)bool Xor(const wxRegion& region); | |
b639c3c5 RD |
379 | }; |
380 | ||
381 | ||
382 | ||
383 | class wxRegionIterator { | |
384 | public: | |
385 | wxRegionIterator(const wxRegion& region); | |
386 | ~wxRegionIterator(); | |
387 | ||
388 | long GetX(); | |
389 | long GetY(); | |
390 | long GetW(); | |
391 | long GetWidth(); | |
392 | long GetH(); | |
393 | long GetHeight(); | |
394 | wxRect GetRect(); | |
395 | bool HaveRects(); | |
396 | void Reset(); | |
397 | ||
398 | %addmethods { | |
399 | void Next() { | |
400 | (*self) ++; | |
401 | } | |
402 | }; | |
403 | }; | |
404 | ||
405 | ||
406 | ||
7bf85405 RD |
407 | //--------------------------------------------------------------------------- |
408 | // Accelerator Entry and Table | |
409 | ||
410 | class wxAcceleratorEntry { | |
411 | public: | |
412 | wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0); | |
2f90df85 | 413 | ~wxAcceleratorEntry(); |
7bf85405 RD |
414 | |
415 | void Set(int flags, int keyCode, int Cmd); | |
416 | int GetFlags(); | |
417 | int GetKeyCode(); | |
418 | int GetCommand(); | |
419 | }; | |
420 | ||
421 | ||
422 | class wxAcceleratorTable { | |
423 | public: | |
424 | // Can also accept a list of 3-tuples | |
eec92d76 | 425 | wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices); |
2f90df85 | 426 | ~wxAcceleratorTable(); |
7bf85405 RD |
427 | |
428 | }; | |
faf3cb35 | 429 | |
8bf5d46e | 430 | //--------------------------------------------------------------------------- |
2abc0a0f RD |
431 | |
432 | class wxBusyInfo { | |
433 | public: | |
434 | wxBusyInfo(const wxString& message); | |
435 | ~wxBusyInfo(); | |
436 | }; | |
437 | ||
438 | ||
439 | ||
8bf5d46e RD |
440 | //--------------------------------------------------------------------------- |
441 | ||
442 |