]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc.i
Added missing header files
[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/tooltip.h>
18 #include <wx/busyinfo.h>
19 #include <wx/geometry.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 // Put some wx default wxChar* values into wxStrings.
34 static const wxString wxPyEmptyString(wxT(""));
35 %}
36 //---------------------------------------------------------------------------
37
38
39 class wxObject {
40 public:
41
42 %addmethods {
43 wxString GetClassName() {
44 return self->GetClassInfo()->GetClassName();
45 }
46
47 void Destroy() {
48 delete self;
49 }
50 }
51 };
52
53 //---------------------------------------------------------------------------
54
55 class wxSize {
56 public:
57 long x;
58 long y;
59 %name(width) long x;
60 %name(height)long y;
61
62 wxSize(long w=0, long h=0);
63 ~wxSize();
64 void Set(long w, long h);
65 long GetX();
66 long GetY();
67 long GetWidth();
68 long GetHeight();
69 void SetWidth(long w);
70 void SetHeight(long h);
71
72 %addmethods {
73 PyObject* asTuple() {
74 wxPyBeginBlockThreads();
75 PyObject* tup = PyTuple_New(2);
76 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
77 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
78 wxPyEndBlockThreads();
79 return tup;
80 }
81
82 bool __eq__(PyObject* obj) {
83 wxSize tmp;
84 wxSize* ptr = &tmp;
85 if (obj == Py_None) return FALSE;
86 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
87 if (! success) return FALSE;
88 return *self == *ptr;
89 }
90 bool __ne__(PyObject* obj) {
91 wxSize tmp;
92 wxSize* ptr = &tmp;
93 if (obj == Py_None) return TRUE;
94 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
95 if (! success) return TRUE;
96 return *self != *ptr;
97 }
98
99 }
100
101 %pragma(python) addtoclass = "
102 def __str__(self): return str(self.asTuple())
103 def __repr__(self): return 'wxSize'+str(self.asTuple())
104 def __len__(self): return len(self.asTuple())
105 def __getitem__(self, index): return self.asTuple()[index]
106 def __setitem__(self, index, val):
107 if index == 0: self.width = val
108 elif index == 1: self.height = val
109 else: raise IndexError
110 def __nonzero__(self): return self.asTuple() != (0,0)
111 def __getinitargs__(self): return ()
112 def __getstate__(self): return self.asTuple()
113 def __setstate__(self, state): self.Set(*state)
114 "
115
116 };
117
118 //---------------------------------------------------------------------------
119
120 class wxRealPoint {
121 public:
122 double x;
123 double y;
124 wxRealPoint(double x=0.0, double y=0.0);
125 ~wxRealPoint();
126
127 %addmethods {
128 void Set(double x, double y) {
129 self->x = x;
130 self->y = y;
131 }
132 PyObject* asTuple() {
133 wxPyBeginBlockThreads();
134 PyObject* tup = PyTuple_New(2);
135 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
136 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
137 wxPyEndBlockThreads();
138 return tup;
139 }
140
141 wxRealPoint __add__(const wxRealPoint& p) {
142 return *self + p;
143 }
144
145 wxRealPoint __sub__(const wxRealPoint& p) {
146 return *self - p;
147 }
148
149 bool __eq__(PyObject* obj) {
150 wxRealPoint tmp;
151 wxRealPoint* ptr = &tmp;
152 if (obj == Py_None) return FALSE;
153 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
154 if (! success) return FALSE;
155 return *self == *ptr;
156 }
157 bool __ne__(PyObject* obj) {
158 wxRealPoint tmp;
159 wxRealPoint* ptr = &tmp;
160 if (obj == Py_None) return TRUE;
161 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
162 if (! success) return TRUE;
163 return *self != *ptr;
164 }
165
166 }
167
168 %pragma(python) addtoclass = "
169 def __str__(self): return str(self.asTuple())
170 def __repr__(self): return 'wxRealPoint'+str(self.asTuple())
171 def __len__(self): return len(self.asTuple())
172 def __getitem__(self, index): return self.asTuple()[index]
173 def __setitem__(self, index, val):
174 if index == 0: self.width = val
175 elif index == 1: self.height = val
176 else: raise IndexError
177 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
178 def __getinitargs__(self): return ()
179 def __getstate__(self): return self.asTuple()
180 def __setstate__(self, state): self.Set(*state)
181 "
182 };
183
184
185 class wxPoint {
186 public:
187 long x;
188 long y;
189 wxPoint(long x=0, long y=0);
190 ~wxPoint();
191
192 %addmethods {
193 void Set(long x, long y) {
194 self->x = x;
195 self->y = y;
196 }
197 PyObject* asTuple() {
198 wxPyBeginBlockThreads();
199 PyObject* tup = PyTuple_New(2);
200 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
201 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
202 wxPyEndBlockThreads();
203 return tup;
204 }
205
206 wxPoint __add__(const wxPoint& p) {
207 return *self + p;
208 }
209
210 wxPoint __sub__(const wxPoint& p) {
211 return *self - p;
212 }
213
214 bool __eq__(PyObject* obj) {
215 wxPoint tmp;
216 wxPoint* ptr = &tmp;
217 if (obj == Py_None) return FALSE;
218 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
219 if (! success) return FALSE;
220 return *self == *ptr;
221 }
222 bool __ne__(PyObject* obj) {
223 wxPoint tmp;
224 wxPoint* ptr = &tmp;
225 if (obj == Py_None) return TRUE;
226 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
227 if (! success) return TRUE;
228 return *self != *ptr;
229 }
230
231 }
232
233 %pragma(python) addtoclass = "
234 def __str__(self): return str(self.asTuple())
235 def __repr__(self): return 'wxPoint'+str(self.asTuple())
236 def __len__(self): return len(self.asTuple())
237 def __getitem__(self, index): return self.asTuple()[index]
238 def __setitem__(self, index, val):
239 if index == 0: self.x = val
240 elif index == 1: self.y = val
241 else: raise IndexError
242 def __nonzero__(self): return self.asTuple() != (0,0)
243 def __getinitargs__(self): return ()
244 def __getstate__(self): return self.asTuple()
245 def __setstate__(self, state): self.Set(*state)
246 "
247 };
248
249 //---------------------------------------------------------------------------
250
251 class wxRect {
252 public:
253 wxRect(int x=0, int y=0, int width=0, int height=0);
254 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
255 ~wxRect();
256
257 int GetX();
258 void SetX(int X);
259 int GetY();
260 void SetY(int Y);
261 int GetWidth();
262 void SetWidth(int w);
263 int GetHeight();
264 void SetHeight(int h);
265
266
267 wxPoint GetPosition();
268 wxSize GetSize();
269 void SetPosition( const wxPoint &p );
270 void SetSize( const wxSize &s );
271
272 int GetLeft();
273 int GetTop();
274 int GetBottom();
275 int GetRight();
276
277 void SetLeft(int left);
278 void SetRight(int right);
279 void SetTop(int top);
280 void SetBottom(int bottom);
281
282 void Deflate(int dx, int dy);
283 void Inflate(int dx, int dy);
284 %name(InsideXY)bool Inside(int cx, int cy);
285 bool Inside(const wxPoint& pt);
286 bool Intersects(const wxRect& rect);
287 %name(OffsetXY) void Offset(int dx, int dy);
288 void Offset(const wxPoint& pt);
289
290 int x, y, width, height;
291
292 %addmethods {
293 void Set(int x=0, int y=0, int width=0, int height=0) {
294 self->x = x;
295 self->y = y;
296 self->width = width;
297 self->height = height;
298 }
299
300 PyObject* asTuple() {
301 wxPyBeginBlockThreads();
302 PyObject* tup = PyTuple_New(4);
303 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
304 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
305 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
306 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
307 wxPyEndBlockThreads();
308 return tup;
309 }
310
311 wxRect __add__(const wxRect& rect) {
312 return *self + rect;
313 }
314
315 bool __eq__(PyObject* obj) {
316 wxRect tmp;
317 wxRect* ptr = &tmp;
318 if (obj == Py_None) return FALSE;
319 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
320 if (! success) return FALSE;
321 return *self == *ptr;
322 }
323 bool __ne__(PyObject* obj) {
324 wxRect tmp;
325 wxRect* ptr = &tmp;
326 if (obj == Py_None) return TRUE;
327 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
328 if (! success) return TRUE;
329 return *self != *ptr;
330 }
331
332 }
333
334 %pragma(python) addtoclass = "
335 def __str__(self): return str(self.asTuple())
336 def __repr__(self): return 'wxRect'+str(self.asTuple())
337 def __len__(self): return len(self.asTuple())
338 def __getitem__(self, index): return self.asTuple()[index]
339 def __setitem__(self, index, val):
340 if index == 0: self.x = val
341 elif index == 1: self.y = val
342 elif index == 2: self.width = val
343 elif index == 3: self.height = val
344 else: raise IndexError
345 def __nonzero__(self): return self.asTuple() != (0,0,0,0)
346 def __getinitargs__(self): return ()
347 def __getstate__(self): return self.asTuple()
348 def __setstate__(self, state): self.Set(*state)
349
350 # override the __getattr__ made by SWIG
351 def __getattr__(self, name):
352 d = {
353 'x' : miscc.wxRect_x_get,
354 'y' : miscc.wxRect_y_get,
355 'width' : miscc.wxRect_width_get,
356 'height' : miscc.wxRect_height_get,
357 'top' : miscc.wxRect_GetTop,
358 'bottom' : miscc.wxRect_GetBottom,
359 'left' : miscc.wxRect_GetLeft,
360 'right' : miscc.wxRect_GetRight,
361 }
362 try:
363 func = d[name]
364 except KeyError:
365 raise AttributeError,name
366 return func(self)
367
368 # and also the __setattr__
369 def __setattr__(self, name, value):
370 d = {
371 'x' : miscc.wxRect_x_set,
372 'y' : miscc.wxRect_y_set,
373 'width' : miscc.wxRect_width_set,
374 'height' : miscc.wxRect_height_set,
375 'top' : miscc.wxRect_SetTop,
376 'bottom' : miscc.wxRect_SetBottom,
377 'left' : miscc.wxRect_SetLeft,
378 'right' : miscc.wxRect_SetRight,
379 }
380 try:
381 func = d[name]
382 except KeyError:
383 self.__dict__[name] = value
384 return
385 func(self, value)
386 "
387
388 };
389
390
391 %inline %{
392 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
393 wxRegion reg1(*r1);
394 wxRegion reg2(*r2);
395 wxRect dest(0,0,0,0);
396 PyObject* obj;
397
398 reg1.Intersect(reg2);
399 dest = reg1.GetBox();
400
401 if (dest != wxRect(0,0,0,0)) {
402 wxPyBeginBlockThreads();
403 wxRect* newRect = new wxRect(dest);
404 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"));
405 PyObject* one = PyInt_FromLong(1);
406 PyObject_SetAttrString(obj, "thisown", one);
407 Py_DECREF(one);
408 wxPyEndBlockThreads();
409 return obj;
410 }
411 Py_INCREF(Py_None);
412 return Py_None;
413 }
414 %}
415
416
417
418 //---------------------------------------------------------------------------
419 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
420
421 class wxPoint2DDouble
422 {
423 public:
424 double m_x;
425 double m_y;
426
427 %name(x)double m_x;
428 %name(y)double m_y;
429
430 wxPoint2DDouble( double x=0 , double y=0 );
431 %name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
432 %name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
433
434 // two different conversions to integers, floor and rounding
435 void GetFloor( int* OUTPUT , int* OUTPUT ) const;
436 void GetRounded( int* OUTPUT , int* OUTPUT ) const;
437
438 double GetVectorLength() const;
439 double GetVectorAngle() const ;
440 void SetVectorLength( double length );
441 void SetVectorAngle( double degrees );
442 // LinkError: void SetPolarCoordinates( double angle , double length );
443 // LinkError: void Normalize();
444 %pragma(python) addtoclass = "
445 def SetPolarCoordinates(self, angle, length):
446 self.SetVectorLength(length)
447 self.SetVectorAngle(angle)
448 def Normalize(self):
449 self.SetVectorLength(1.0)
450 "
451
452 double GetDistance( const wxPoint2DDouble &pt ) const;
453 double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
454 double GetDotProduct( const wxPoint2DDouble &vec ) const;
455 double GetCrossProduct( const wxPoint2DDouble &vec ) const;
456
457 %addmethods {
458 void Set( double x=0 , double y=0 ) {
459 self->m_x = x;
460 self->m_y = y;
461 }
462
463 // the reflection of this point
464 wxPoint2DDouble __neg__() { return -(*self); }
465
466 wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
467 wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
468 wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
469 wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
470
471 // TODO:
472 //wxPoint2DDouble& operator*=(double n);
473 //wxPoint2DDouble& operator*=(int n);
474 //wxPoint2DDouble& operator/=(double n);
475 //wxPoint2DDouble& operator/=(int n);
476
477 bool __eq__(PyObject* obj) {
478 wxPoint2DDouble tmp;
479 wxPoint2DDouble* ptr = &tmp;
480 if (obj == Py_None) return FALSE;
481 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
482 if (! success) return FALSE;
483 return *self == *ptr;
484 }
485 bool __ne__(PyObject* obj) {
486 wxPoint2DDouble tmp;
487 wxPoint2DDouble* ptr = &tmp;
488 if (obj == Py_None) return TRUE;
489 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
490 if (! success) return TRUE;
491 return *self != *ptr;
492 }
493
494
495 PyObject* asTuple() {
496 wxPyBeginBlockThreads();
497 PyObject* tup = PyTuple_New(2);
498 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
499 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
500 wxPyEndBlockThreads();
501 return tup;
502 }
503 }
504
505 %pragma(python) addtoclass = "
506 def __str__(self): return str(self.asTuple())
507 def __repr__(self): return 'wxPoint2DDouble'+str(self.asTuple())
508 def __len__(self): return len(self.asTuple())
509 def __getitem__(self, index): return self.asTuple()[index]
510 def __setitem__(self, index, val):
511 if index == 0: self.m_x = val
512 elif index == 1: self.m_yt = val
513 else: raise IndexError
514 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
515 def __getinitargs__(self): return ()
516 def __getstate__(self): return self.asTuple()
517 def __setstate__(self, state): self.Set(*state)
518 "
519 };
520
521
522 //---------------------------------------------------------------------------
523 // Miscellaneous functions
524
525 long wxNewId();
526 void wxRegisterId(long id);
527 long wxGetCurrentId();
528
529 void wxBell();
530 void wxEndBusyCursor();
531
532 long wxGetElapsedTime(bool resetTimer = TRUE);
533 #ifdef __WXMSW__
534 long wxGetFreeMemory();
535 #endif
536 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
537 bool wxIsBusy();
538 wxString wxNow();
539 bool wxShell(const wxString& command = wxPyEmptyString);
540 void wxStartTimer();
541 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
542 wxString wxGetOsDescription();
543
544 enum wxShutdownFlags
545 {
546 wxSHUTDOWN_POWEROFF, // power off the computer
547 wxSHUTDOWN_REBOOT // shutdown and reboot
548 };
549
550 // Shutdown or reboot the PC
551 bool wxShutdown(wxShutdownFlags wFlags);
552
553
554 void wxSleep(int secs);
555 void wxUsleep(unsigned long milliseconds);
556 bool wxYield();
557 bool wxYieldIfNeeded();
558 void wxEnableTopLevelWindows(bool enable);
559
560 #ifdef wxUSE_RESOURCES
561 inline %{
562 wxString wxGetResource(const wxString& section, const wxString& entry,
563 const wxString& file = wxPyEmptyString) {
564 wxChar* retval;
565 wxGetResource(section, entry, &retval, file);
566 return retval;
567 }
568 %}
569 #endif
570
571 wxString wxStripMenuCodes(const wxString& in);
572
573
574 wxString wxGetEmailAddress();
575 wxString wxGetHostName();
576 wxString wxGetFullHostName();
577 wxString wxGetUserId();
578 wxString wxGetUserName();
579 wxString wxGetHomeDir();
580 wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
581
582 unsigned long wxGetProcessId();
583
584 // When wxApp gets the virtual method magic then enable this.
585 // bool wxHandleFatalExceptions(bool doIt = TRUE);
586
587 //----------------------------------------------------------------------
588
589 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
590 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
591 enum wxRelationship { wxUnconstrained = 0,
592 wxAsIs,
593 wxPercentOf,
594 wxAbove,
595 wxBelow,
596 wxLeftOf,
597 wxRightOf,
598 wxSameAs,
599 wxAbsolute };
600
601
602 class wxIndividualLayoutConstraint : public wxObject {
603 public:
604 // wxIndividualLayoutConstraint();
605 // ~wxIndividualLayoutConstraint();
606
607 void Above(wxWindow *otherWin, int margin=0);
608 void Absolute(int value);
609 void AsIs();
610 void Below(wxWindow *otherWin, int margin=0);
611 void Unconstrained();
612 void LeftOf(wxWindow *otherWin, int margin=0);
613 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
614 void RightOf(wxWindow *otherWin, int margin=0);
615 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
616 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
617 };
618
619
620 class wxLayoutConstraints : public wxObject {
621 public:
622 wxLayoutConstraints();
623
624 %readonly
625 wxIndividualLayoutConstraint bottom;
626 wxIndividualLayoutConstraint centreX;
627 wxIndividualLayoutConstraint centreY;
628 wxIndividualLayoutConstraint height;
629 wxIndividualLayoutConstraint left;
630 wxIndividualLayoutConstraint right;
631 wxIndividualLayoutConstraint top;
632 wxIndividualLayoutConstraint width;
633 %readwrite
634 }
635
636
637
638 //---------------------------------------------------------------------------
639 // Accelerator Entry and Table
640
641 class wxAcceleratorEntry {
642 public:
643 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
644 ~wxAcceleratorEntry();
645
646 void Set(int flags, int keyCode, int Cmd);
647 int GetFlags();
648 int GetKeyCode();
649 int GetCommand();
650 };
651
652
653 class wxAcceleratorTable : public wxObject {
654 public:
655 // Can also accept a list of 3-tuples
656 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
657 ~wxAcceleratorTable();
658
659 };
660
661 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
662
663 %readonly
664 %{
665 #if 0 // we want to use the definition from the header, not the
666 // one SWIG will generate.
667 %}
668 // See also wxPy_ReinitStockObjects in helpers.cpp
669 extern wxAcceleratorTable wxNullAcceleratorTable;
670 %{
671 #endif
672 %}
673 %readwrite
674
675 //---------------------------------------------------------------------------
676
677 class wxBusyInfo : public wxObject {
678 public:
679 wxBusyInfo(const wxString& message);
680 ~wxBusyInfo();
681 };
682
683
684 //---------------------------------------------------------------------------
685
686
687