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