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