]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/misc.i
Implemented the first phase of OOR (Original Object Return). See the
[wxWidgets.git] / wxPython / src / misc.i
... / ...
CommitLineData
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
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
54class wxSize {
55public:
56 long x;
57 long y;
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);
64 long GetX();
65 long GetY();
66 long GetWidth();
67 long GetHeight();
68 void SetWidth(long w);
69 void SetHeight(long h);
70
71 %addmethods {
72 PyObject* asTuple() {
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 }
79
80 %pragma(python) addtoclass = "
81 def __str__(self): return str(self.asTuple())
82 def __repr__(self): return str(self.asTuple())
83 def __len__(self): return len(self.asTuple())
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"
90
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();
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 }
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 }
128 }
129 %pragma(python) addtoclass = "
130 def __str__(self): return str(self.asTuple())
131 def __repr__(self): return str(self.asTuple())
132 def __len__(self): return len(self.asTuple())
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"
139};
140
141
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 }
154 PyObject* asTuple() {
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 }
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 }
175 }
176 %pragma(python) addtoclass = "
177 def __str__(self): return str(self.asTuple())
178 def __repr__(self): return str(self.asTuple())
179 def __len__(self): return len(self.asTuple())
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"
186};
187
188//---------------------------------------------------------------------------
189
190class wxRect {
191public:
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();
195
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);
204
205
206 wxPoint GetPosition();
207 wxSize GetSize();
208
209 int GetLeft();
210 int GetTop();
211 int GetBottom();
212 int GetRight();
213
214 void SetLeft(int left);
215 void SetRight(int right);
216 void SetTop(int top);
217 void SetBottom(int bottom);
218
219 void Inflate(int dx, int dy);
220 bool Inside(int cx, int cy);
221
222 int x, y, width, height;
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));
229 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
230 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
231 return tup;
232 }
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 }
243 }
244
245 %pragma(python) addtoclass = "
246 def __str__(self): return str(self.asTuple())
247 def __repr__(self): return str(self.asTuple())
248 def __len__(self): return len(self.asTuple())
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
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
295};
296
297
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");
312 PyObject* one = PyInt_FromLong(1);
313 PyObject_SetAttrString(obj, "thisown", one);
314 Py_DECREF(one);
315 wxPySaveThread(doSave);
316 return obj;
317 }
318 Py_INCREF(Py_None);
319 return Py_None;
320 }
321%}
322
323
324//---------------------------------------------------------------------------
325// Miscellaneous functions
326
327long wxNewId();
328void wxRegisterId(long id);
329%name(NewId) long wxNewId();
330%name(RegisterId) void wxRegisterId(long id);
331long wxGetCurrentId();
332
333void wxBell();
334void wxEndBusyCursor();
335
336long wxGetElapsedTime(bool resetTimer = TRUE);
337#ifdef __WXMSW__
338long wxGetFreeMemory();
339#endif
340void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
341bool wxIsBusy();
342wxString wxNow();
343bool wxShell(const wxString& command = wxPyEmptyStr);
344void wxStartTimer();
345int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
346wxString wxGetOsDescription();
347
348void wxSleep(int secs);
349void wxUsleep(unsigned long milliseconds);
350bool wxYield();
351bool wxYieldIfNeeded();
352void wxEnableTopLevelWindows(bool enable);
353
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
362wxString wxStripMenuCodes(const wxString& in);
363
364
365wxString wxGetEmailAddress();
366wxString wxGetHostName();
367wxString wxGetFullHostName();
368wxString wxGetUserId();
369wxString wxGetUserName();
370wxString wxGetHomeDir();
371
372
373//----------------------------------------------------------------------
374
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
388class wxIndividualLayoutConstraint : public wxObject {
389public:
390// wxIndividualLayoutConstraint();
391// ~wxIndividualLayoutConstraint();
392
393 void Above(wxWindow *otherWin, int margin=0);
394 void Absolute(int value);
395 void AsIs();
396 void Below(wxWindow *otherWin, int margin=0);
397 void Unconstrained();
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
406class wxLayoutConstraints : public wxObject {
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
423
424//---------------------------------------------------------------------------
425// Accelerator Entry and Table
426
427class wxAcceleratorEntry {
428public:
429 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
430 ~wxAcceleratorEntry();
431
432 void Set(int flags, int keyCode, int Cmd);
433 int GetFlags();
434 int GetKeyCode();
435 int GetCommand();
436};
437
438
439class wxAcceleratorTable : public wxObject {
440public:
441 // Can also accept a list of 3-tuples
442 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
443 ~wxAcceleratorTable();
444
445};
446
447wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
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
460//---------------------------------------------------------------------------
461
462class wxBusyInfo : public wxObject {
463public:
464 wxBusyInfo(const wxString& message);
465 ~wxBusyInfo();
466};
467
468//---------------------------------------------------------------------------
469
470
471