1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Definitions of miscelaneous functions and classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include <wx/tooltip.h>
18 #include <wx/busyinfo.h>
19 #include <wx/geometry.h>
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
31 //---------------------------------------------------------------------------
33 // Put some wx default wxChar* values into wxStrings.
34 static const wxString wxPyEmptyString(wxT(""));
36 //---------------------------------------------------------------------------
43 wxString GetClassName() {
44 return self->GetClassInfo()->GetClassName();
53 //---------------------------------------------------------------------------
62 wxSize(long w=0, long h=0);
64 void Set(long w, long h);
69 void SetWidth(long w);
70 void SetHeight(long h);
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();
82 bool __eq__(PyObject* obj) {
85 if (obj == Py_None) return FALSE;
86 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
87 if (! success) return FALSE;
90 bool __ne__(PyObject* obj) {
93 if (obj == Py_None) return TRUE;
94 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
95 if (! success) return TRUE;
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)
118 //---------------------------------------------------------------------------
124 wxRealPoint(double x=0.0, double y=0.0);
128 void Set(double x, double y) {
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();
141 wxRealPoint __add__(const wxRealPoint& p) {
145 wxRealPoint __sub__(const wxRealPoint& p) {
149 bool __eq__(PyObject* obj) {
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;
157 bool __ne__(PyObject* obj) {
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;
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)
189 wxPoint(long x=0, long y=0);
193 void Set(long x, long y) {
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();
206 wxPoint __add__(const wxPoint& p) {
210 wxPoint __sub__(const wxPoint& p) {
214 bool __eq__(PyObject* obj) {
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;
222 bool __ne__(PyObject* obj) {
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;
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)
249 //---------------------------------------------------------------------------
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);
262 void SetWidth(int w);
264 void SetHeight(int h);
267 wxPoint GetPosition();
269 void SetPosition( const wxPoint &p );
270 void SetSize( const wxSize &s );
277 void SetLeft(int left);
278 void SetRight(int right);
279 void SetTop(int top);
280 void SetBottom(int bottom);
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);
290 int x, y, width, height;
293 void Set(int x=0, int y=0, int width=0, int height=0) {
297 self->height = height;
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();
311 wxRect __add__(const wxRect& rect) {
315 bool __eq__(PyObject* obj) {
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;
323 bool __ne__(PyObject* obj) {
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;
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)
350 # override the __getattr__ made by SWIG
351 def __getattr__(self, name):
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,
365 raise AttributeError,name
368 # and also the __setattr__
369 def __setattr__(self, name, value):
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,
383 self.__dict__[name] = value
392 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
395 wxRect dest(0,0,0,0);
398 reg1.Intersect(reg2);
399 dest = reg1.GetBox();
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);
408 wxPyEndBlockThreads();
418 //---------------------------------------------------------------------------
419 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
421 class wxPoint2DDouble
430 wxPoint2DDouble( double x=0 , double y=0 );
431 %name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
432 %name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
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;
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)
449 self.SetVectorLength(1.0)
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;
458 void Set( double x=0 , double y=0 ) {
463 // the reflection of this point
464 wxPoint2DDouble __neg__() { return -(*self); }
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; }
472 //wxPoint2DDouble& operator*=(double n);
473 //wxPoint2DDouble& operator*=(int n);
474 //wxPoint2DDouble& operator/=(double n);
475 //wxPoint2DDouble& operator/=(int n);
477 bool __eq__(PyObject* obj) {
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;
485 bool __ne__(PyObject* obj) {
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;
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();
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)
522 //---------------------------------------------------------------------------
523 // Miscellaneous functions
526 void wxRegisterId(long id);
527 long wxGetCurrentId();
530 void wxEndBusyCursor();
532 long wxGetElapsedTime(bool resetTimer = TRUE);
534 long wxGetFreeMemory();
536 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
539 bool wxShell(const wxString& command = wxPyEmptyString);
541 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
542 wxString wxGetOsDescription();
546 wxSHUTDOWN_POWEROFF, // power off the computer
547 wxSHUTDOWN_REBOOT // shutdown and reboot
550 // Shutdown or reboot the PC
551 bool wxShutdown(wxShutdownFlags wFlags);
554 void wxSleep(int secs);
555 void wxUsleep(unsigned long milliseconds);
557 bool wxYieldIfNeeded();
558 void wxEnableTopLevelWindows(bool enable);
560 #ifdef wxUSE_RESOURCES
562 wxString wxGetResource(const wxString& section, const wxString& entry,
563 const wxString& file = wxPyEmptyString) {
565 wxGetResource(section, entry, &retval, file);
571 wxString wxStripMenuCodes(const wxString& in);
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);
582 unsigned long wxGetProcessId();
584 // When wxApp gets the virtual method magic then enable this.
585 // bool wxHandleFatalExceptions(bool doIt = TRUE);
587 //----------------------------------------------------------------------
589 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
590 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
591 enum wxRelationship { wxUnconstrained = 0,
602 class wxIndividualLayoutConstraint : public wxObject {
604 // wxIndividualLayoutConstraint();
605 // ~wxIndividualLayoutConstraint();
607 void Above(wxWindow *otherWin, int margin=0);
608 void Absolute(int value);
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);
620 class wxLayoutConstraints : public wxObject {
622 wxLayoutConstraints();
625 wxIndividualLayoutConstraint bottom;
626 wxIndividualLayoutConstraint centreX;
627 wxIndividualLayoutConstraint centreY;
628 wxIndividualLayoutConstraint height;
629 wxIndividualLayoutConstraint left;
630 wxIndividualLayoutConstraint right;
631 wxIndividualLayoutConstraint top;
632 wxIndividualLayoutConstraint width;
638 //---------------------------------------------------------------------------
639 // Accelerator Entry and Table
641 class wxAcceleratorEntry {
643 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
644 ~wxAcceleratorEntry();
646 void Set(int flags, int keyCode, int Cmd);
653 class wxAcceleratorTable : public wxObject {
655 // Can also accept a list of 3-tuples
656 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
657 ~wxAcceleratorTable();
661 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
665 #if 0 // we want to use the definition from the header, not the
666 // one SWIG will generate.
668 // See also wxPy_ReinitStockObjects in helpers.cpp
669 extern wxAcceleratorTable wxNullAcceleratorTable;
675 //---------------------------------------------------------------------------
677 class wxBusyInfo : public wxObject {
679 wxBusyInfo(const wxString& message);
684 //---------------------------------------------------------------------------