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);
72 void IncTo(const wxSize& sz);
73 void DecTo(const wxSize& sz);
77 wxPyBeginBlockThreads();
78 PyObject* tup = PyTuple_New(2);
79 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
80 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
81 wxPyEndBlockThreads();
85 bool __eq__(PyObject* obj) {
88 if (obj == Py_None) return FALSE;
89 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
90 if (! success) return FALSE;
93 bool __ne__(PyObject* obj) {
96 if (obj == Py_None) return TRUE;
97 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
98 if (! success) return TRUE;
104 %pragma(python) addtoclass = "
105 def __str__(self): return str(self.asTuple())
106 def __repr__(self): return 'wxSize'+str(self.asTuple())
107 def __len__(self): return len(self.asTuple())
108 def __getitem__(self, index): return self.asTuple()[index]
109 def __setitem__(self, index, val):
110 if index == 0: self.width = val
111 elif index == 1: self.height = val
112 else: raise IndexError
113 def __nonzero__(self): return self.asTuple() != (0,0)
114 def __getinitargs__(self): return ()
115 def __getstate__(self): return self.asTuple()
116 def __setstate__(self, state): self.Set(*state)
121 //---------------------------------------------------------------------------
127 wxRealPoint(double x=0.0, double y=0.0);
131 void Set(double x, double y) {
135 PyObject* asTuple() {
136 wxPyBeginBlockThreads();
137 PyObject* tup = PyTuple_New(2);
138 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
139 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
140 wxPyEndBlockThreads();
144 wxRealPoint __add__(const wxRealPoint& p) {
148 wxRealPoint __sub__(const wxRealPoint& p) {
152 bool __eq__(PyObject* obj) {
154 wxRealPoint* ptr = &tmp;
155 if (obj == Py_None) return FALSE;
156 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
157 if (! success) return FALSE;
158 return *self == *ptr;
160 bool __ne__(PyObject* obj) {
162 wxRealPoint* ptr = &tmp;
163 if (obj == Py_None) return TRUE;
164 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
165 if (! success) return TRUE;
166 return *self != *ptr;
171 %pragma(python) addtoclass = "
172 def __str__(self): return str(self.asTuple())
173 def __repr__(self): return 'wxRealPoint'+str(self.asTuple())
174 def __len__(self): return len(self.asTuple())
175 def __getitem__(self, index): return self.asTuple()[index]
176 def __setitem__(self, index, val):
177 if index == 0: self.width = val
178 elif index == 1: self.height = val
179 else: raise IndexError
180 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
181 def __getinitargs__(self): return ()
182 def __getstate__(self): return self.asTuple()
183 def __setstate__(self, state): self.Set(*state)
192 wxPoint(long x=0, long y=0);
196 void Set(long x, long y) {
200 PyObject* asTuple() {
201 wxPyBeginBlockThreads();
202 PyObject* tup = PyTuple_New(2);
203 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
204 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
205 wxPyEndBlockThreads();
209 wxPoint __add__(const wxPoint& p) {
213 wxPoint __sub__(const wxPoint& p) {
217 bool __eq__(PyObject* obj) {
220 if (obj == Py_None) return FALSE;
221 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
222 if (! success) return FALSE;
223 return *self == *ptr;
225 bool __ne__(PyObject* obj) {
228 if (obj == Py_None) return TRUE;
229 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
230 if (! success) return TRUE;
231 return *self != *ptr;
236 %pragma(python) addtoclass = "
237 def __str__(self): return str(self.asTuple())
238 def __repr__(self): return 'wxPoint'+str(self.asTuple())
239 def __len__(self): return len(self.asTuple())
240 def __getitem__(self, index): return self.asTuple()[index]
241 def __setitem__(self, index, val):
242 if index == 0: self.x = val
243 elif index == 1: self.y = val
244 else: raise IndexError
245 def __nonzero__(self): return self.asTuple() != (0,0)
246 def __getinitargs__(self): return ()
247 def __getstate__(self): return self.asTuple()
248 def __setstate__(self, state): self.Set(*state)
252 //---------------------------------------------------------------------------
256 wxRect(int x=0, int y=0, int width=0, int height=0);
257 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
265 void SetWidth(int w);
267 void SetHeight(int h);
270 wxPoint GetPosition();
272 void SetPosition( const wxPoint &p );
273 void SetSize( const wxSize &s );
280 void SetLeft(int left);
281 void SetRight(int right);
282 void SetTop(int top);
283 void SetBottom(int bottom);
285 void Deflate(int dx, int dy);
286 void Inflate(int dx, int dy);
287 %name(InsideXY)bool Inside(int cx, int cy);
288 bool Inside(const wxPoint& pt);
289 bool Intersects(const wxRect& rect);
290 %name(OffsetXY) void Offset(int dx, int dy);
291 void Offset(const wxPoint& pt);
293 int x, y, width, height;
296 void Set(int x=0, int y=0, int width=0, int height=0) {
300 self->height = height;
303 PyObject* asTuple() {
304 wxPyBeginBlockThreads();
305 PyObject* tup = PyTuple_New(4);
306 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
307 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
308 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
309 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
310 wxPyEndBlockThreads();
314 wxRect __add__(const wxRect& rect) {
318 bool __eq__(PyObject* obj) {
321 if (obj == Py_None) return FALSE;
322 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
323 if (! success) return FALSE;
324 return *self == *ptr;
326 bool __ne__(PyObject* obj) {
329 if (obj == Py_None) return TRUE;
330 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
331 if (! success) return TRUE;
332 return *self != *ptr;
337 %pragma(python) addtoclass = "
338 def __str__(self): return str(self.asTuple())
339 def __repr__(self): return 'wxRect'+str(self.asTuple())
340 def __len__(self): return len(self.asTuple())
341 def __getitem__(self, index): return self.asTuple()[index]
342 def __setitem__(self, index, val):
343 if index == 0: self.x = val
344 elif index == 1: self.y = val
345 elif index == 2: self.width = val
346 elif index == 3: self.height = val
347 else: raise IndexError
348 def __nonzero__(self): return self.asTuple() != (0,0,0,0)
349 def __getinitargs__(self): return ()
350 def __getstate__(self): return self.asTuple()
351 def __setstate__(self, state): self.Set(*state)
353 # override the __getattr__ made by SWIG
354 def __getattr__(self, name):
356 'x' : miscc.wxRect_x_get,
357 'y' : miscc.wxRect_y_get,
358 'width' : miscc.wxRect_width_get,
359 'height' : miscc.wxRect_height_get,
360 'top' : miscc.wxRect_GetTop,
361 'bottom' : miscc.wxRect_GetBottom,
362 'left' : miscc.wxRect_GetLeft,
363 'right' : miscc.wxRect_GetRight,
368 raise AttributeError,name
371 # and also the __setattr__
372 def __setattr__(self, name, value):
374 'x' : miscc.wxRect_x_set,
375 'y' : miscc.wxRect_y_set,
376 'width' : miscc.wxRect_width_set,
377 'height' : miscc.wxRect_height_set,
378 'top' : miscc.wxRect_SetTop,
379 'bottom' : miscc.wxRect_SetBottom,
380 'left' : miscc.wxRect_SetLeft,
381 'right' : miscc.wxRect_SetRight,
386 self.__dict__[name] = value
395 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
398 wxRect dest(0,0,0,0);
401 reg1.Intersect(reg2);
402 dest = reg1.GetBox();
404 if (dest != wxRect(0,0,0,0)) {
405 wxPyBeginBlockThreads();
406 wxRect* newRect = new wxRect(dest);
407 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"));
408 PyObject* one = PyInt_FromLong(1);
409 PyObject_SetAttrString(obj, "thisown", one);
411 wxPyEndBlockThreads();
421 //---------------------------------------------------------------------------
422 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
424 class wxPoint2DDouble
433 wxPoint2DDouble( double x=0 , double y=0 );
434 %name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
435 %name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
437 // two different conversions to integers, floor and rounding
438 void GetFloor( int* OUTPUT , int* OUTPUT ) const;
439 void GetRounded( int* OUTPUT , int* OUTPUT ) const;
441 double GetVectorLength() const;
442 double GetVectorAngle() const ;
443 void SetVectorLength( double length );
444 void SetVectorAngle( double degrees );
445 // LinkError: void SetPolarCoordinates( double angle , double length );
446 // LinkError: void Normalize();
447 %pragma(python) addtoclass = "
448 def SetPolarCoordinates(self, angle, length):
449 self.SetVectorLength(length)
450 self.SetVectorAngle(angle)
452 self.SetVectorLength(1.0)
455 double GetDistance( const wxPoint2DDouble &pt ) const;
456 double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
457 double GetDotProduct( const wxPoint2DDouble &vec ) const;
458 double GetCrossProduct( const wxPoint2DDouble &vec ) const;
461 void Set( double x=0 , double y=0 ) {
466 // the reflection of this point
467 wxPoint2DDouble __neg__() { return -(*self); }
469 wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
470 wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
471 wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
472 wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
475 //wxPoint2DDouble& operator*=(double n);
476 //wxPoint2DDouble& operator*=(int n);
477 //wxPoint2DDouble& operator/=(double n);
478 //wxPoint2DDouble& operator/=(int n);
480 bool __eq__(PyObject* obj) {
482 wxPoint2DDouble* ptr = &tmp;
483 if (obj == Py_None) return FALSE;
484 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
485 if (! success) return FALSE;
486 return *self == *ptr;
488 bool __ne__(PyObject* obj) {
490 wxPoint2DDouble* ptr = &tmp;
491 if (obj == Py_None) return TRUE;
492 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
493 if (! success) return TRUE;
494 return *self != *ptr;
498 PyObject* asTuple() {
499 wxPyBeginBlockThreads();
500 PyObject* tup = PyTuple_New(2);
501 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
502 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
503 wxPyEndBlockThreads();
508 %pragma(python) addtoclass = "
509 def __str__(self): return str(self.asTuple())
510 def __repr__(self): return 'wxPoint2DDouble'+str(self.asTuple())
511 def __len__(self): return len(self.asTuple())
512 def __getitem__(self, index): return self.asTuple()[index]
513 def __setitem__(self, index, val):
514 if index == 0: self.m_x = val
515 elif index == 1: self.m_yt = val
516 else: raise IndexError
517 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
518 def __getinitargs__(self): return ()
519 def __getstate__(self): return self.asTuple()
520 def __setstate__(self, state): self.Set(*state)
525 //---------------------------------------------------------------------------
526 // Miscellaneous functions
529 void wxRegisterId(long id);
530 long wxGetCurrentId();
533 void wxEndBusyCursor();
535 long wxGetElapsedTime(bool resetTimer = TRUE);
537 long wxGetFreeMemory();
539 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
542 bool wxShell(const wxString& command = wxPyEmptyString);
544 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
545 wxString wxGetOsDescription();
549 wxSHUTDOWN_POWEROFF, // power off the computer
550 wxSHUTDOWN_REBOOT // shutdown and reboot
553 // Shutdown or reboot the PC
554 bool wxShutdown(wxShutdownFlags wFlags);
557 void wxSleep(int secs);
558 void wxUsleep(unsigned long milliseconds);
560 bool wxYieldIfNeeded();
561 void wxEnableTopLevelWindows(bool enable);
563 #ifdef wxUSE_RESOURCES
565 wxString wxGetResource(const wxString& section, const wxString& entry,
566 const wxString& file = wxPyEmptyString) {
568 wxGetResource(section, entry, &retval, file);
574 wxString wxStripMenuCodes(const wxString& in);
577 wxString wxGetEmailAddress();
578 wxString wxGetHostName();
579 wxString wxGetFullHostName();
580 wxString wxGetUserId();
581 wxString wxGetUserName();
582 wxString wxGetHomeDir();
583 wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
585 unsigned long wxGetProcessId();
587 // When wxApp gets the virtual method magic then enable this.
588 // bool wxHandleFatalExceptions(bool doIt = TRUE);
592 //----------------------------------------------------------------------
594 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
595 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
596 enum wxRelationship { wxUnconstrained = 0,
607 class wxIndividualLayoutConstraint : public wxObject {
609 // wxIndividualLayoutConstraint();
610 // ~wxIndividualLayoutConstraint();
612 void Above(wxWindow *otherWin, int margin=0);
613 void Absolute(int value);
615 void Below(wxWindow *otherWin, int margin=0);
616 void Unconstrained();
617 void LeftOf(wxWindow *otherWin, int margin=0);
618 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
619 void RightOf(wxWindow *otherWin, int margin=0);
620 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
621 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
625 class wxLayoutConstraints : public wxObject {
627 wxLayoutConstraints();
630 wxIndividualLayoutConstraint bottom;
631 wxIndividualLayoutConstraint centreX;
632 wxIndividualLayoutConstraint centreY;
633 wxIndividualLayoutConstraint height;
634 wxIndividualLayoutConstraint left;
635 wxIndividualLayoutConstraint right;
636 wxIndividualLayoutConstraint top;
637 wxIndividualLayoutConstraint width;
643 //---------------------------------------------------------------------------
644 // Accelerator Entry and Table
646 class wxAcceleratorEntry {
648 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
649 ~wxAcceleratorEntry();
651 void Set(int flags, int keyCode, int Cmd);
658 class wxAcceleratorTable : public wxObject {
660 // Can also accept a list of 3-tuples
661 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
662 ~wxAcceleratorTable();
666 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
670 #if 0 // we want to use the definition from the header, not the
671 // one SWIG will generate.
673 // See also wxPy_ReinitStockObjects in helpers.cpp
674 extern wxAcceleratorTable wxNullAcceleratorTable;
680 //---------------------------------------------------------------------------
682 class wxBusyInfo : public wxObject {
684 wxBusyInfo(const wxString& message);
689 //---------------------------------------------------------------------------