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