]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/misc.i
test commit, no real change
[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
bb0054cd 31//---------------------------------------------------------------------------
7bf85405
RD
32
33
34class wxSize {
35public:
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
66class wxRealPoint {
67public:
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 }
c368d904
RD
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 }
efc5f224
RD
99 }
100 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
101 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
7bf85405
RD
102};
103
efc5f224 104
7bf85405
RD
105class wxPoint {
106public:
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 }
af309447 117 PyObject* asTuple() {
7bf85405
RD
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 }
c368d904
RD
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 }
7bf85405 138 }
af309447
RD
139 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
140 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
7bf85405
RD
141};
142
143//---------------------------------------------------------------------------
144
145class wxRect {
146public:
eb715945
RD
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();
7bf85405 150
eb715945
RD
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);
7bf85405
RD
159
160
eb715945
RD
161 wxPoint GetPosition();
162 wxSize GetSize();
7bf85405 163
eb715945
RD
164 int GetLeft();
165 int GetTop();
166 int GetBottom();
167 int GetRight();
7bf85405 168
eb715945
RD
169 void SetLeft(int left);
170 void SetRight(int right);
171 void SetTop(int top);
172 void SetBottom(int bottom);
173
f6bcfd97
BP
174 void Inflate(int dx, int dy);
175 bool Inside(int cx, int cy);
eb715945
RD
176
177 int x, y, width, height;
af309447
RD
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));
f0261a72
RD
184 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
185 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
af309447
RD
186 return tup;
187 }
f6bcfd97
BP
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 }
af309447 198 }
f6bcfd97 199
af309447
RD
200 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
201 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
9b3d3bc4
RD
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
7bf85405
RD
241};
242
243
eb715945
RD
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");
de20db99
RD
258 PyObject* one = PyInt_FromLong(1);
259 PyObject_SetAttrString(obj, "thisown", one);
260 Py_DECREF(one);
eb715945
RD
261 wxPySaveThread(doSave);
262 return obj;
263 }
264 Py_INCREF(Py_None);
265 return Py_None;
266 }
267%}
7bf85405 268
7bf85405
RD
269
270//---------------------------------------------------------------------------
271// Miscellaneous functions
272
cf694132
RD
273long wxNewId();
274void wxRegisterId(long id);
275%name(NewId) long wxNewId();
276%name(RegisterId) void wxRegisterId(long id);
277
7bf85405
RD
278void wxBell();
279void wxDisplaySize(int *OUTPUT, int *OUTPUT);
280void wxEndBusyCursor();
c368d904 281
7bf85405 282long wxGetElapsedTime(bool resetTimer = TRUE);
bc29c5e0 283#ifdef __WXMSW__
7bf85405 284long wxGetFreeMemory();
bc29c5e0 285#endif
7bf85405
RD
286void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
287bool wxIsBusy();
288wxString wxNow();
fb5e0af0 289bool wxShell(const wxString& command = wxPyEmptyStr);
7bf85405 290void wxStartTimer();
fb5e0af0 291int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
c368d904 292wxString wxGetOsDescription();
fb5e0af0 293
bb0054cd 294void wxSleep(int secs);
c368d904 295void wxUsleep(unsigned long milliseconds);
7bf85405 296bool wxYield();
bb0054cd 297void wxEnableTopLevelWindows(bool enable);
7bf85405 298
7bf85405
RD
299%inline %{
300 char* wxGetResource(char *section, char *entry, char *file = NULL) {
301 char * retval;
302 wxGetResource(section, entry, &retval, file);
303 return retval;
304 }
305%}
306
694759cf 307wxString wxStripMenuCodes(const wxString& in);
7bf85405 308
c368d904
RD
309
310wxString wxGetEmailAddress();
311wxString wxGetHostName();
312wxString wxGetFullHostName();
313wxString wxGetUserId();
314wxString wxGetUserName();
315wxString wxGetHomeDir();
316
317
7bf85405
RD
318//----------------------------------------------------------------------
319
7bf85405
RD
320enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
321 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
322enum wxRelationship { wxUnconstrained = 0,
323 wxAsIs,
324 wxPercentOf,
325 wxAbove,
326 wxBelow,
327 wxLeftOf,
328 wxRightOf,
329 wxSameAs,
330 wxAbsolute };
331
332
333class wxIndividualLayoutConstraint {
334public:
335// wxIndividualLayoutConstraint();
336// ~wxIndividualLayoutConstraint();
337
338 void Above(wxWindow *otherWin, int margin=0);
339 void Absolute(int value);
08127323 340 void AsIs();
7bf85405 341 void Below(wxWindow *otherWin, int margin=0);
08127323 342 void Unconstrained();
7bf85405
RD
343 void LeftOf(wxWindow *otherWin, int margin=0);
344 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
345 void RightOf(wxWindow *otherWin, int margin=0);
346 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
347 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
348};
349
350
351class wxLayoutConstraints {
352public:
353 wxLayoutConstraints();
354
355%readonly
356 wxIndividualLayoutConstraint bottom;
357 wxIndividualLayoutConstraint centreX;
358 wxIndividualLayoutConstraint centreY;
359 wxIndividualLayoutConstraint height;
360 wxIndividualLayoutConstraint left;
361 wxIndividualLayoutConstraint right;
362 wxIndividualLayoutConstraint top;
363 wxIndividualLayoutConstraint width;
364%readwrite
365}
366
367
b639c3c5
RD
368//---------------------------------------------------------------------------
369// Regions, etc.
370
371enum wxRegionContain {
372 wxOutRegion, wxPartRegion, wxInRegion
373};
374
375
376class wxRegion {
377public:
c368d904 378 wxRegion(long x=0, long y=0, long width=0, long height=0);
b639c3c5
RD
379 ~wxRegion();
380
381 void Clear();
382 wxRegionContain Contains(long x, long y);
383 %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt);
384 %name(ContainsRect)wxRegionContain Contains(const wxRect& rect);
eb715945 385 %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
b639c3c5
RD
386
387 wxRect GetBox();
eb715945
RD
388
389 bool Intersect(long x, long y, long width, long height);
390 %name(IntersectRect)bool Intersect(const wxRect& rect);
391 %name(IntersectRegion)bool Intersect(const wxRegion& region);
392
b639c3c5 393 bool IsEmpty();
eb715945
RD
394
395 bool Union(long x, long y, long width, long height);
396 %name(UnionRect)bool Union(const wxRect& rect);
397 %name(UnionRegion)bool Union(const wxRegion& region);
398
399 bool Subtract(long x, long y, long width, long height);
400 %name(SubtractRect)bool Subtract(const wxRect& rect);
401 %name(SubtractRegion)bool Subtract(const wxRegion& region);
402
403 bool Xor(long x, long y, long width, long height);
404 %name(XorRect)bool Xor(const wxRect& rect);
405 %name(XorRegion)bool Xor(const wxRegion& region);
b639c3c5
RD
406};
407
408
409
410class wxRegionIterator {
411public:
412 wxRegionIterator(const wxRegion& region);
413 ~wxRegionIterator();
414
415 long GetX();
416 long GetY();
417 long GetW();
418 long GetWidth();
419 long GetH();
420 long GetHeight();
421 wxRect GetRect();
422 bool HaveRects();
423 void Reset();
424
425 %addmethods {
426 void Next() {
427 (*self) ++;
428 }
429 };
430};
431
432
433
7bf85405
RD
434//---------------------------------------------------------------------------
435// Accelerator Entry and Table
436
437class wxAcceleratorEntry {
438public:
439 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
2f90df85 440 ~wxAcceleratorEntry();
7bf85405
RD
441
442 void Set(int flags, int keyCode, int Cmd);
443 int GetFlags();
444 int GetKeyCode();
445 int GetCommand();
446};
447
448
449class wxAcceleratorTable {
450public:
451 // Can also accept a list of 3-tuples
eec92d76 452 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
2f90df85 453 ~wxAcceleratorTable();
7bf85405
RD
454
455};
faf3cb35 456
c368d904 457wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
f6bcfd97
BP
458
459%readonly
460%{
461#if 0 // we want to use the definition from the header, not the
462 // one SWIG will generate.
463%}
464extern wxAcceleratorTable wxNullAcceleratorTable;
465%{
466#endif
467%}
468%readwrite
469
8bf5d46e 470//---------------------------------------------------------------------------
2abc0a0f
RD
471
472class wxBusyInfo {
473public:
474 wxBusyInfo(const wxString& message);
475 ~wxBusyInfo();
476};
477
8bf5d46e
RD
478//---------------------------------------------------------------------------
479
480
c368d904 481