]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/misc.i
added CodeWarrior project for Classic Mac OS
[wxWidgets.git] / wxPython / src / misc.i
CommitLineData
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
38class wxSize {
39public:
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 }
af309447
RD
63 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
64 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
65
7bf85405
RD
66};
67
68//---------------------------------------------------------------------------
69
70class wxRealPoint {
71public:
72 double x;
73 double y;
74 wxRealPoint(double x=0.0, double y=0.0);
75 ~wxRealPoint();
efc5f224
RD
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 }
c368d904
RD
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 }
efc5f224
RD
103 }
104 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
105 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
7bf85405
RD
106};
107
efc5f224 108
7bf85405
RD
109class wxPoint {
110public:
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 }
af309447 121 PyObject* asTuple() {
7bf85405
RD
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 }
c368d904
RD
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 }
7bf85405 142 }
af309447
RD
143 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
144 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
7bf85405
RD
145};
146
147//---------------------------------------------------------------------------
148
149class wxRect {
150public:
eb715945
RD
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();
7bf85405 154
eb715945
RD
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);
7bf85405
RD
163
164
eb715945
RD
165 wxPoint GetPosition();
166 wxSize GetSize();
7bf85405 167
eb715945
RD
168 int GetLeft();
169 int GetTop();
170 int GetBottom();
171 int GetRight();
7bf85405 172
eb715945
RD
173 void SetLeft(int left);
174 void SetRight(int right);
175 void SetTop(int top);
176 void SetBottom(int bottom);
177
f6bcfd97
BP
178 void Inflate(int dx, int dy);
179 bool Inside(int cx, int cy);
eb715945
RD
180
181 int x, y, width, height;
af309447
RD
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));
f0261a72
RD
188 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
189 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
af309447
RD
190 return tup;
191 }
f6bcfd97
BP
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 }
af309447 202 }
f6bcfd97 203
af309447
RD
204 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
205 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
9b3d3bc4
RD
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
7bf85405
RD
245};
246
247
eb715945
RD
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");
de20db99
RD
262 PyObject* one = PyInt_FromLong(1);
263 PyObject_SetAttrString(obj, "thisown", one);
264 Py_DECREF(one);
eb715945
RD
265 wxPySaveThread(doSave);
266 return obj;
267 }
268 Py_INCREF(Py_None);
269 return Py_None;
270 }
271%}
7bf85405 272
7bf85405
RD
273
274//---------------------------------------------------------------------------
275// Miscellaneous functions
276
cf694132
RD
277long wxNewId();
278void wxRegisterId(long id);
279%name(NewId) long wxNewId();
280%name(RegisterId) void wxRegisterId(long id);
281
7bf85405
RD
282void wxBell();
283void wxDisplaySize(int *OUTPUT, int *OUTPUT);
284void wxEndBusyCursor();
c368d904 285
7bf85405 286long wxGetElapsedTime(bool resetTimer = TRUE);
bc29c5e0 287#ifdef __WXMSW__
7bf85405 288long wxGetFreeMemory();
bc29c5e0 289#endif
7bf85405
RD
290void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
291bool wxIsBusy();
292wxString wxNow();
fb5e0af0 293bool wxShell(const wxString& command = wxPyEmptyStr);
7bf85405 294void wxStartTimer();
fb5e0af0 295int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
c368d904 296wxString wxGetOsDescription();
fb5e0af0 297
bb0054cd 298void wxSleep(int secs);
c368d904 299void wxUsleep(unsigned long milliseconds);
7bf85405 300bool wxYield();
bb0054cd 301void wxEnableTopLevelWindows(bool enable);
7bf85405 302
7bf85405
RD
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
694759cf 311wxString wxStripMenuCodes(const wxString& in);
7bf85405 312
c368d904
RD
313
314wxString wxGetEmailAddress();
315wxString wxGetHostName();
316wxString wxGetFullHostName();
317wxString wxGetUserId();
318wxString wxGetUserName();
319wxString wxGetHomeDir();
320
321
7bf85405
RD
322//----------------------------------------------------------------------
323
7bf85405
RD
324enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
325 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
326enum wxRelationship { wxUnconstrained = 0,
327 wxAsIs,
328 wxPercentOf,
329 wxAbove,
330 wxBelow,
331 wxLeftOf,
332 wxRightOf,
333 wxSameAs,
334 wxAbsolute };
335
336
337class wxIndividualLayoutConstraint {
338public:
339// wxIndividualLayoutConstraint();
340// ~wxIndividualLayoutConstraint();
341
342 void Above(wxWindow *otherWin, int margin=0);
343 void Absolute(int value);
08127323 344 void AsIs();
7bf85405 345 void Below(wxWindow *otherWin, int margin=0);
08127323 346 void Unconstrained();
7bf85405
RD
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
355class wxLayoutConstraints {
356public:
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
b639c3c5
RD
372//---------------------------------------------------------------------------
373// Regions, etc.
374
375enum wxRegionContain {
376 wxOutRegion, wxPartRegion, wxInRegion
377};
378
379
380class wxRegion {
381public:
c368d904 382 wxRegion(long x=0, long y=0, long width=0, long height=0);
b639c3c5
RD
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);
eb715945 389 %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
b639c3c5
RD
390
391 wxRect GetBox();
eb715945
RD
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
b639c3c5 397 bool IsEmpty();
eb715945
RD
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);
b639c3c5
RD
410};
411
412
413
414class wxRegionIterator {
415public:
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
7bf85405
RD
438//---------------------------------------------------------------------------
439// Accelerator Entry and Table
440
441class wxAcceleratorEntry {
442public:
443 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
2f90df85 444 ~wxAcceleratorEntry();
7bf85405
RD
445
446 void Set(int flags, int keyCode, int Cmd);
447 int GetFlags();
448 int GetKeyCode();
449 int GetCommand();
450};
451
452
453class wxAcceleratorTable {
454public:
455 // Can also accept a list of 3-tuples
eec92d76 456 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
2f90df85 457 ~wxAcceleratorTable();
7bf85405
RD
458
459};
faf3cb35 460
c368d904 461wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
f6bcfd97
BP
462
463%readonly
464%{
465#if 0 // we want to use the definition from the header, not the
466 // one SWIG will generate.
467%}
468extern wxAcceleratorTable wxNullAcceleratorTable;
469%{
470#endif
471%}
472%readwrite
473
8bf5d46e 474//---------------------------------------------------------------------------
2abc0a0f
RD
475
476class wxBusyInfo {
477public:
478 wxBusyInfo(const wxString& message);
479 ~wxBusyInfo();
480};
481
8bf5d46e
RD
482//---------------------------------------------------------------------------
483
484
c368d904 485