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