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/resource.h>
18 #include <wx/tooltip.h>
19 #include <wx/busyinfo.h>
20 #include <wx/geometry.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
32 //---------------------------------------------------------------------------
34 // Put some wx default wxChar* values into wxStrings.
35 static const wxString wxPyEmptyString(wxT(""));
37 //---------------------------------------------------------------------------
44 wxString GetClassName() {
45 return self->GetClassInfo()->GetClassName();
54 //---------------------------------------------------------------------------
63 wxSize(long w=0, long h=0);
65 void Set(long w, long h);
70 void SetWidth(long w);
71 void SetHeight(long h);
75 wxPyBeginBlockThreads();
76 PyObject* tup = PyTuple_New(2);
77 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
78 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
79 wxPyEndBlockThreads();
83 bool __eq__(PyObject* obj) {
86 if (obj == Py_None) return FALSE;
87 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
88 if (! success) return FALSE;
91 bool __ne__(PyObject* obj) {
94 if (obj == Py_None) return TRUE;
95 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
96 if (! success) return TRUE;
102 %pragma(python) addtoclass = "
103 def __str__(self): return str(self.asTuple())
104 def __repr__(self): return 'wxSize'+str(self.asTuple())
105 def __len__(self): return len(self.asTuple())
106 def __getitem__(self, index): return self.asTuple()[index]
107 def __setitem__(self, index, val):
108 if index == 0: self.width = val
109 elif index == 1: self.height = val
110 else: raise IndexError
111 def __nonzero__(self): return self.asTuple() != (0,0)
112 def __getinitargs__(self): return ()
113 def __getstate__(self): return self.asTuple()
114 def __setstate__(self, state): self.Set(*state)
119 //---------------------------------------------------------------------------
125 wxRealPoint(double x=0.0, double y=0.0);
129 void Set(double x, double y) {
133 PyObject* asTuple() {
134 wxPyBeginBlockThreads();
135 PyObject* tup = PyTuple_New(2);
136 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
137 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
138 wxPyEndBlockThreads();
142 wxRealPoint __add__(const wxRealPoint& p) {
146 wxRealPoint __sub__(const wxRealPoint& p) {
150 bool __eq__(PyObject* obj) {
152 wxRealPoint* ptr = &tmp;
153 if (obj == Py_None) return FALSE;
154 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
155 if (! success) return FALSE;
156 return *self == *ptr;
158 bool __ne__(PyObject* obj) {
160 wxRealPoint* ptr = &tmp;
161 if (obj == Py_None) return TRUE;
162 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
163 if (! success) return TRUE;
164 return *self != *ptr;
169 %pragma(python) addtoclass = "
170 def __str__(self): return str(self.asTuple())
171 def __repr__(self): return 'wxRealPoint'+str(self.asTuple())
172 def __len__(self): return len(self.asTuple())
173 def __getitem__(self, index): return self.asTuple()[index]
174 def __setitem__(self, index, val):
175 if index == 0: self.width = val
176 elif index == 1: self.height = val
177 else: raise IndexError
178 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
179 def __getinitargs__(self): return ()
180 def __getstate__(self): return self.asTuple()
181 def __setstate__(self, state): self.Set(*state)
190 wxPoint(long x=0, long y=0);
194 void Set(long x, long y) {
198 PyObject* asTuple() {
199 wxPyBeginBlockThreads();
200 PyObject* tup = PyTuple_New(2);
201 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
202 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
203 wxPyEndBlockThreads();
207 wxPoint __add__(const wxPoint& p) {
211 wxPoint __sub__(const wxPoint& p) {
215 bool __eq__(PyObject* obj) {
218 if (obj == Py_None) return FALSE;
219 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
220 if (! success) return FALSE;
221 return *self == *ptr;
223 bool __ne__(PyObject* obj) {
226 if (obj == Py_None) return TRUE;
227 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
228 if (! success) return TRUE;
229 return *self != *ptr;
234 %pragma(python) addtoclass = "
235 def __str__(self): return str(self.asTuple())
236 def __repr__(self): return 'wxPoint'+str(self.asTuple())
237 def __len__(self): return len(self.asTuple())
238 def __getitem__(self, index): return self.asTuple()[index]
239 def __setitem__(self, index, val):
240 if index == 0: self.x = val
241 elif index == 1: self.y = val
242 else: raise IndexError
243 def __nonzero__(self): return self.asTuple() != (0,0)
244 def __getinitargs__(self): return ()
245 def __getstate__(self): return self.asTuple()
246 def __setstate__(self, state): self.Set(*state)
250 //---------------------------------------------------------------------------
254 wxRect(int x=0, int y=0, int width=0, int height=0);
255 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
263 void SetWidth(int w);
265 void SetHeight(int h);
268 wxPoint GetPosition();
270 void SetPosition( const wxPoint &p );
271 void SetSize( const wxSize &s );
278 void SetLeft(int left);
279 void SetRight(int right);
280 void SetTop(int top);
281 void SetBottom(int bottom);
283 void Deflate(int dx, int dy);
284 void Inflate(int dx, int dy);
285 %name(InsideXY)bool Inside(int cx, int cy);
286 bool Inside(const wxPoint& pt);
287 bool Intersects(const wxRect& rect);
288 %name(OffsetXY) void Offset(int dx, int dy);
289 void Offset(const wxPoint& pt);
291 int x, y, width, height;
294 void Set(int x=0, int y=0, int width=0, int height=0) {
298 self->height = height;
301 PyObject* asTuple() {
302 wxPyBeginBlockThreads();
303 PyObject* tup = PyTuple_New(4);
304 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
305 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
306 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
307 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
308 wxPyEndBlockThreads();
312 wxRect __add__(const wxRect& rect) {
316 bool __eq__(PyObject* obj) {
319 if (obj == Py_None) return FALSE;
320 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
321 if (! success) return FALSE;
322 return *self == *ptr;
324 bool __ne__(PyObject* obj) {
327 if (obj == Py_None) return TRUE;
328 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
329 if (! success) return TRUE;
330 return *self != *ptr;
335 %pragma(python) addtoclass = "
336 def __str__(self): return str(self.asTuple())
337 def __repr__(self): return 'wxRect'+str(self.asTuple())
338 def __len__(self): return len(self.asTuple())
339 def __getitem__(self, index): return self.asTuple()[index]
340 def __setitem__(self, index, val):
341 if index == 0: self.x = val
342 elif index == 1: self.y = val
343 elif index == 2: self.width = val
344 elif index == 3: self.height = val
345 else: raise IndexError
346 def __nonzero__(self): return self.asTuple() != (0,0,0,0)
347 def __getinitargs__(self): return ()
348 def __getstate__(self): return self.asTuple()
349 def __setstate__(self, state): self.Set(*state)
351 # override the __getattr__ made by SWIG
352 def __getattr__(self, name):
354 'x' : miscc.wxRect_x_get,
355 'y' : miscc.wxRect_y_get,
356 'width' : miscc.wxRect_width_get,
357 'height' : miscc.wxRect_height_get,
358 'top' : miscc.wxRect_GetTop,
359 'bottom' : miscc.wxRect_GetBottom,
360 'left' : miscc.wxRect_GetLeft,
361 'right' : miscc.wxRect_GetRight,
366 raise AttributeError,name
369 # and also the __setattr__
370 def __setattr__(self, name, value):
372 'x' : miscc.wxRect_x_set,
373 'y' : miscc.wxRect_y_set,
374 'width' : miscc.wxRect_width_set,
375 'height' : miscc.wxRect_height_set,
376 'top' : miscc.wxRect_SetTop,
377 'bottom' : miscc.wxRect_SetBottom,
378 'left' : miscc.wxRect_SetLeft,
379 'right' : miscc.wxRect_SetRight,
384 self.__dict__[name] = value
393 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
396 wxRect dest(0,0,0,0);
399 reg1.Intersect(reg2);
400 dest = reg1.GetBox();
402 if (dest != wxRect(0,0,0,0)) {
403 wxPyBeginBlockThreads();
404 wxRect* newRect = new wxRect(dest);
405 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"));
406 PyObject* one = PyInt_FromLong(1);
407 PyObject_SetAttrString(obj, "thisown", one);
409 wxPyEndBlockThreads();
419 //---------------------------------------------------------------------------
420 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
422 class wxPoint2DDouble
431 wxPoint2DDouble( double x=0 , double y=0 );
432 %name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
433 %name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
435 // two different conversions to integers, floor and rounding
436 void GetFloor( int* OUTPUT , int* OUTPUT ) const;
437 void GetRounded( int* OUTPUT , int* OUTPUT ) const;
439 double GetVectorLength() const;
440 double GetVectorAngle() const ;
441 void SetVectorLength( double length );
442 void SetVectorAngle( double degrees );
443 // LinkError: void SetPolarCoordinates( double angle , double length );
444 // LinkError: void Normalize();
445 %pragma(python) addtoclass = "
446 def SetPolarCoordinates(self, angle, length):
447 self.SetVectorLength(length)
448 self.SetVectorAngle(angle)
450 self.SetVectorLength(1.0)
453 double GetDistance( const wxPoint2DDouble &pt ) const;
454 double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
455 double GetDotProduct( const wxPoint2DDouble &vec ) const;
456 double GetCrossProduct( const wxPoint2DDouble &vec ) const;
459 void Set( double x=0 , double y=0 ) {
464 // the reflection of this point
465 wxPoint2DDouble __neg__() { return -(*self); }
467 wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
468 wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
469 wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
470 wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
473 //wxPoint2DDouble& operator*=(double n);
474 //wxPoint2DDouble& operator*=(int n);
475 //wxPoint2DDouble& operator/=(double n);
476 //wxPoint2DDouble& operator/=(int n);
478 bool __eq__(PyObject* obj) {
480 wxPoint2DDouble* ptr = &tmp;
481 if (obj == Py_None) return FALSE;
482 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
483 if (! success) return FALSE;
484 return *self == *ptr;
486 bool __ne__(PyObject* obj) {
488 wxPoint2DDouble* ptr = &tmp;
489 if (obj == Py_None) return TRUE;
490 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
491 if (! success) return TRUE;
492 return *self != *ptr;
496 PyObject* asTuple() {
497 wxPyBeginBlockThreads();
498 PyObject* tup = PyTuple_New(2);
499 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
500 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
501 wxPyEndBlockThreads();
506 %pragma(python) addtoclass = "
507 def __str__(self): return str(self.asTuple())
508 def __repr__(self): return 'wxPoint2DDouble'+str(self.asTuple())
509 def __len__(self): return len(self.asTuple())
510 def __getitem__(self, index): return self.asTuple()[index]
511 def __setitem__(self, index, val):
512 if index == 0: self.m_x = val
513 elif index == 1: self.m_yt = val
514 else: raise IndexError
515 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
516 def __getinitargs__(self): return ()
517 def __getstate__(self): return self.asTuple()
518 def __setstate__(self, state): self.Set(*state)
523 //---------------------------------------------------------------------------
524 // Miscellaneous functions
527 void wxRegisterId(long id);
528 long wxGetCurrentId();
531 void wxEndBusyCursor();
533 long wxGetElapsedTime(bool resetTimer = TRUE);
535 long wxGetFreeMemory();
537 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
540 bool wxShell(const wxString& command = wxPyEmptyString);
542 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
543 wxString wxGetOsDescription();
547 wxSHUTDOWN_POWEROFF, // power off the computer
548 wxSHUTDOWN_REBOOT // shutdown and reboot
551 // Shutdown or reboot the PC
552 bool wxShutdown(wxShutdownFlags wFlags);
555 void wxSleep(int secs);
556 void wxUsleep(unsigned long milliseconds);
558 bool wxYieldIfNeeded();
559 void wxEnableTopLevelWindows(bool enable);
561 #ifdef wxUSE_RESOURCES
563 wxString wxGetResource(const wxString& section, const wxString& entry,
564 const wxString& file = wxPyEmptyString) {
566 wxGetResource(section, entry, &retval, file);
572 wxString wxStripMenuCodes(const wxString& in);
575 wxString wxGetEmailAddress();
576 wxString wxGetHostName();
577 wxString wxGetFullHostName();
578 wxString wxGetUserId();
579 wxString wxGetUserName();
580 wxString wxGetHomeDir();
581 wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
583 unsigned long wxGetProcessId();
585 // When wxApp gets the virtual method magic then enable this.
586 // bool wxHandleFatalExceptions(bool doIt = TRUE);
588 //----------------------------------------------------------------------
590 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
591 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
592 enum wxRelationship { wxUnconstrained = 0,
603 class wxIndividualLayoutConstraint : public wxObject {
605 // wxIndividualLayoutConstraint();
606 // ~wxIndividualLayoutConstraint();
608 void Above(wxWindow *otherWin, int margin=0);
609 void Absolute(int value);
611 void Below(wxWindow *otherWin, int margin=0);
612 void Unconstrained();
613 void LeftOf(wxWindow *otherWin, int margin=0);
614 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
615 void RightOf(wxWindow *otherWin, int margin=0);
616 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
617 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
621 class wxLayoutConstraints : public wxObject {
623 wxLayoutConstraints();
626 wxIndividualLayoutConstraint bottom;
627 wxIndividualLayoutConstraint centreX;
628 wxIndividualLayoutConstraint centreY;
629 wxIndividualLayoutConstraint height;
630 wxIndividualLayoutConstraint left;
631 wxIndividualLayoutConstraint right;
632 wxIndividualLayoutConstraint top;
633 wxIndividualLayoutConstraint width;
639 //---------------------------------------------------------------------------
640 // Accelerator Entry and Table
642 class wxAcceleratorEntry {
644 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
645 ~wxAcceleratorEntry();
647 void Set(int flags, int keyCode, int Cmd);
654 class wxAcceleratorTable : public wxObject {
656 // Can also accept a list of 3-tuples
657 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
658 ~wxAcceleratorTable();
662 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
666 #if 0 // we want to use the definition from the header, not the
667 // one SWIG will generate.
669 extern wxAcceleratorTable wxNullAcceleratorTable;
675 //---------------------------------------------------------------------------
677 class wxBusyInfo : public wxObject {
679 wxBusyInfo(const wxString& message);
684 //---------------------------------------------------------------------------