1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for common GDI stuff and misc classes
7 // Created: 13-Sept-2003
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
22 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
27 wxBITMAP_TYPE_XBM_DATA,
29 wxBITMAP_TYPE_XPM_DATA,
40 wxBITMAP_TYPE_MACCURSOR,
42 // wxBITMAP_TYPE_BMP_RESOURCE,
43 // wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
44 // wxBITMAP_TYPE_ICO_RESOURCE,
45 // wxBITMAP_TYPE_CUR_RESOURCE,
46 // wxBITMAP_TYPE_TIF_RESOURCE,
47 // wxBITMAP_TYPE_GIF_RESOURCE,
48 // wxBITMAP_TYPE_PNG_RESOURCE,
49 // wxBITMAP_TYPE_JPEG_RESOURCE,
50 // wxBITMAP_TYPE_PNM_RESOURCE,
51 // wxBITMAP_TYPE_PCX_RESOURCE,
52 // wxBITMAP_TYPE_PICT_RESOURCE,
53 // wxBITMAP_TYPE_ICON_RESOURCE,
54 // wxBITMAP_TYPE_MACCURSOR_RESOURCE,
56 wxBITMAP_TYPE_ANY = 50
62 wxCURSOR_NONE, // should be 0
72 wxCURSOR_MIDDLE_BUTTON,
78 wxCURSOR_QUESTION_ARROW,
79 wxCURSOR_RIGHT_BUTTON,
89 wxCURSOR_DEFAULT, // standard X11 cursor
90 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
93 // // Not yet implemented for Windows
94 // wxCURSOR_CROSS_REVERSE,
95 // wxCURSOR_DOUBLE_ARROW,
96 // wxCURSOR_BASED_ARROW_UP,
97 // wxCURSOR_BASED_ARROW_DOWN,
107 #define wxCURSOR_COPY_ARROW wxCURSOR_ARROW
111 //---------------------------------------------------------------------------
115 "wx.Size is a useful data structure used to represent the size of
116 something. It simply contains integer width and height
117 properties. In most places in wxPython where a wx.Size is
118 expected a (width, height) tuple can be used instead.", "");
123 %Rename(width, int, x);
124 %Rename(height,int, y);
125 %pythoncode { x = width; y = height }
128 wxSize(int w=0, int h=0),
129 "Creates a size object.", "");
136 DocStr(__eq__, "Test for equality of wx.Size objects.", "");
137 bool __eq__(PyObject* other) {
138 wxSize temp, *obj = &temp;
139 if ( other == Py_None ) return false;
140 if ( ! wxSize_helper(other, &obj) ) {
144 return self->operator==(*obj);
149 DocStr(__ne__, "Test for inequality of wx.Size objects.", "");
150 bool __ne__(PyObject* other) {
151 wxSize temp, *obj = &temp;
152 if ( other == Py_None ) return true;
153 if ( ! wxSize_helper(other, &obj)) {
157 return self->operator!=(*obj);
162 wxSize, operator+(const wxSize& sz),
163 "Add sz's proprties to this and return the result.", "");
166 wxSize, operator-(const wxSize& sz),
167 "Subtract sz's properties from this and return the result.", "");
170 void, IncTo(const wxSize& sz),
171 "Increments this object so that both of its dimensions are not less
172 than the corresponding dimensions of the size.", "");
175 void, DecTo(const wxSize& sz),
176 "Decrements this object so that both of its dimensions are not greater
177 than the corresponding dimensions of the size.", "");
180 void, Set(int w, int h),
181 "Set both width and height.", "");
183 void SetWidth(int w);
184 void SetHeight(int h);
185 int GetWidth() const;
186 int GetHeight() const;
190 bool , IsFullySpecified() const,
191 "Returns True if both components of the size are non-default values.", "");
195 void , SetDefaults(const wxSize& size),
196 "Combine this size with the other one replacing the default components
197 of this object (i.e. equal to -1) with those of the other.", "");
205 "Get() -> (width,height)",
206 "Returns the width and height properties as a tuple.", "");
208 wxPyBlock_t blocked = wxPyBeginBlockThreads();
209 PyObject* tup = PyTuple_New(2);
210 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
211 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
212 wxPyEndBlockThreads(blocked);
217 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
218 def __str__(self): return str(self.Get())
219 def __repr__(self): return 'wx.Size'+str(self.Get())
220 def __len__(self): return len(self.Get())
221 def __getitem__(self, index): return self.Get()[index]
222 def __setitem__(self, index, val):
223 if index == 0: self.width = val
224 elif index == 1: self.height = val
225 else: raise IndexError
226 def __nonzero__(self): return self.Get() != (0,0)
227 __safe_for_unpickling__ = True
228 def __reduce__(self): return (wx.Size, self.Get())
233 //---------------------------------------------------------------------------
237 "A data structure for representing a point or position with floating
238 point x and y properties. In wxPython most places that expect a
239 wx.RealPoint can also accept a (x,y) tuple.", "");
247 wxRealPoint(double x=0.0, double y=0.0),
248 "Create a wx.RealPoint object", "");
254 DocStr(__eq__, "Test for equality of wx.RealPoint objects.", "");
255 bool __eq__(PyObject* other) {
256 wxRealPoint temp, *obj = &temp;
257 if ( other == Py_None ) return false;
258 if ( ! wxRealPoint_helper(other, &obj) ) {
262 return self->operator==(*obj);
267 DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", "");
268 bool __ne__(PyObject* other) {
269 wxRealPoint temp, *obj = &temp;
270 if ( other == Py_None ) return true;
271 if ( ! wxRealPoint_helper(other, &obj)) {
275 return self->operator!=(*obj);
281 wxRealPoint, operator+(const wxRealPoint& pt),
282 "Add pt's proprties to this and return the result.", "");
285 wxRealPoint, operator-(const wxRealPoint& pt),
286 "Subtract pt's proprties from this and return the result", "");
290 DocStr(Set, "Set both the x and y properties", "");
291 void Set(double x, double y) {
298 "Return the x and y properties as a tuple. ", "");
300 wxPyBlock_t blocked = wxPyBeginBlockThreads();
301 PyObject* tup = PyTuple_New(2);
302 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
303 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
304 wxPyEndBlockThreads(blocked);
310 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
311 def __str__(self): return str(self.Get())
312 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
313 def __len__(self): return len(self.Get())
314 def __getitem__(self, index): return self.Get()[index]
315 def __setitem__(self, index, val):
316 if index == 0: self.x = val
317 elif index == 1: self.y = val
318 else: raise IndexError
319 def __nonzero__(self): return self.Get() != (0.0, 0.0)
320 __safe_for_unpickling__ = True
321 def __reduce__(self): return (wx.RealPoint, self.Get())
326 //---------------------------------------------------------------------------
331 "A data structure for representing a point or position with integer x
332 and y properties. Most places in wxPython that expect a wx.Point can
333 also accept a (x,y) tuple.", "");
341 wxPoint(int x=0, int y=0),
342 "Create a wx.Point object", "");
349 DocStr(__eq__, "Test for equality of wx.Point objects.", "");
350 bool __eq__(PyObject* other) {
351 wxPoint temp, *obj = &temp;
352 if ( other == Py_None ) return false;
353 if ( ! wxPoint_helper(other, &obj) ) {
357 return self->operator==(*obj);
362 DocStr(__ne__, "Test for inequality of wx.Point objects.", "");
363 bool __ne__(PyObject* other) {
364 wxPoint temp, *obj = &temp;
365 if ( other == Py_None ) return true;
366 if ( ! wxPoint_helper(other, &obj)) {
370 return self->operator!=(*obj);
375 // %nokwargs operator+;
376 // %nokwargs operator-;
377 // %nokwargs operator+=;
378 // %nokwargs operator-=;
381 wxPoint, operator+(const wxPoint& pt),
382 "Add pt's proprties to this and return the result.", "");
386 wxPoint, operator-(const wxPoint& pt),
387 "Subtract pt's proprties from this and return the result", "");
391 wxPoint&, operator+=(const wxPoint& pt),
392 "Add pt to this object.", "");
395 wxPoint&, operator-=(const wxPoint& pt),
396 "Subtract pt from this object.", "");
401 // wxPoint, operator+(const wxSize& sz),
402 // "Add sz to this Point and return the result.", "");
405 // wxPoint, operator-(const wxSize& sz),
406 // "Subtract sz from this Point and return the result", "");
410 // wxPoint&, operator+=(const wxSize& sz),
411 // "Add sz to this object.", "");
414 // wxPoint&, operator-=(const wxSize& sz),
415 // "Subtract sz from this object.", "");
421 DocStr(Set, "Set both the x and y properties", "");
422 void Set(long x, long y) {
429 "Return the x and y properties as a tuple. ", "");
431 wxPyBlock_t blocked = wxPyBeginBlockThreads();
432 PyObject* tup = PyTuple_New(2);
433 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
434 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
435 wxPyEndBlockThreads(blocked);
441 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
442 def __str__(self): return str(self.Get())
443 def __repr__(self): return 'wx.Point'+str(self.Get())
444 def __len__(self): return len(self.Get())
445 def __getitem__(self, index): return self.Get()[index]
446 def __setitem__(self, index, val):
447 if index == 0: self.x = val
448 elif index == 1: self.y = val
449 else: raise IndexError
450 def __nonzero__(self): return self.Get() != (0,0)
451 __safe_for_unpickling__ = True
452 def __reduce__(self): return (wx.Point, self.Get())
456 //---------------------------------------------------------------------------
461 "A class for representing and manipulating rectangles. It has x, y,
462 width and height properties. In wxPython most palces that expect a
463 wx.Rect can also accept a (x,y,width,height) tuple.", "");
469 wxRect(int x=0, int y=0, int width=0, int height=0),
470 "Create a new Rect object.", "");
473 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
474 "Create a new Rect object from Points representing two corners.", "",
478 wxRect(const wxPoint& pos, const wxSize& size),
479 "Create a new Rect from a position and size.", "",
483 wxRect(const wxSize& size),
484 "Create a new Rect from a size only.", "",
495 int GetWidth() const;
496 void SetWidth(int w);
498 int GetHeight() const;
499 void SetHeight(int h);
501 wxPoint GetPosition() const;
502 void SetPosition( const wxPoint &p );
504 wxSize GetSize() const;
505 void SetSize( const wxSize &s );
507 bool IsEmpty() const;
509 wxPoint GetTopLeft() const;
510 void SetTopLeft(const wxPoint &p);
511 wxPoint GetBottomRight() const;
512 void SetBottomRight(const wxPoint &p);
514 // wxPoint GetLeftTop() const;
515 // void SetLeftTop(const wxPoint &p);
516 // wxPoint GetRightBottom() const;
517 // void SetRightBottom(const wxPoint &p);
521 int GetBottom() const;
522 int GetRight() const;
524 void SetLeft(int left);
525 void SetRight(int right);
526 void SetTop(int top);
527 void SetBottom(int bottom);
530 position = property(GetPosition, SetPosition)
531 size = property(GetSize, SetSize)
532 left = property(GetLeft, SetLeft)
533 right = property(GetRight, SetRight)
534 top = property(GetTop, SetTop)
535 bottom = property(GetBottom, SetBottom)
539 wxRect&, Inflate(wxCoord dx, wxCoord dy),
540 "Increases the size of the rectangle.
542 The left border is moved farther left and the right border is moved
543 farther right by ``dx``. The upper border is moved farther up and the
544 bottom border is moved farther down by ``dy``. (Note the the width and
545 height of the rectangle thus change by ``2*dx`` and ``2*dy``,
546 respectively.) If one or both of ``dx`` and ``dy`` are negative, the
547 opposite happens: the rectangle size decreases in the respective
550 The change is made to the rectangle inplace, if instead you need a
551 copy that is inflated, preserving the original then make the copy
554 copy = wx.Rect(*original)
558 Inflating and deflating behaves *naturally*. Defined more precisely,
561 * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not
562 constrained. Thus inflating a rectangle can cause its upper left
563 corner to move into the negative numbers. (The versions prior to
564 2.5.4 forced the top left coordinate to not fall below (0, 0),
565 which implied a forced move of the rectangle.)
567 * Deflates are clamped to not reduce the width or height of the
568 rectangle below zero. In such cases, the top-left corner is
569 nonetheless handled properly. For example, a rectangle at (10,
570 10) with size (20, 40) that is inflated by (-15, -15) will
571 become located at (20, 25) at size (0, 10). Finally, observe
572 that the width and height are treated independently. In the
573 above example, the width is reduced by 20, whereas the height is
574 reduced by the full 30 (rather than also stopping at 20, when
575 the width reached zero).
581 wxRect&, Deflate(wxCoord dx, wxCoord dy),
582 "Decrease the rectangle size. This method is the opposite of `Inflate`
583 in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to
584 `Inflate` for a full description.", "");
587 void, Offset(wxCoord dx, wxCoord dy),
588 "Moves the rectangle by the specified offset. If dx is positive, the
589 rectangle is moved to the right, if dy is positive, it is moved to the
590 bottom, otherwise it is moved to the left or top respectively.", "",
594 void, Offset(const wxPoint& pt),
595 "Same as `OffsetXY` but uses dx,dy from Point", "");
598 wxRect, Intersect(const wxRect& rect),
599 "Returns the intersectsion of this rectangle and rect.", "");
602 wxRect , Union(const wxRect& rect),
603 "Returns the union of this rectangle and rect.", "");
607 wxRect, operator+(const wxRect& rect) const,
608 "Add the properties of rect to this rectangle and return the result.", "");
611 wxRect&, operator+=(const wxRect& rect),
612 "Add the properties of rect to this rectangle, updating this rectangle.", "");
616 DocStr(__eq__, "Test for equality of wx.Rect objects.", "");
617 bool __eq__(PyObject* other) {
618 wxRect temp, *obj = &temp;
619 if ( other == Py_None ) return false;
620 if ( ! wxRect_helper(other, &obj) ) {
624 return self->operator==(*obj);
629 DocStr(__ne__, "Test for inequality of wx.Rect objects.", "");
630 bool __ne__(PyObject* other) {
631 wxRect temp, *obj = &temp;
632 if ( other == Py_None ) return true;
633 if ( ! wxRect_helper(other, &obj)) {
637 return self->operator!=(*obj);
642 DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", "");
643 %Rename(InsideXY, bool, Inside(int x, int y) const);
644 bool Inside(const wxPoint& pt) const;
647 bool, Intersects(const wxRect& rect) const,
648 "Returns True if the rectangles have a non empty intersection.", "");
651 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
652 "Center this rectangle within the one passed to the method, which is
653 usually, but not necessarily, the larger one.", "");
654 %pythoncode { CentreIn = CenterIn }
657 int x, y, width, height;
661 DocStr(Set, "Set all rectangle properties.", "");
662 void Set(int x=0, int y=0, int width=0, int height=0) {
666 self->height = height;
670 "Get() -> (x,y,width,height)",
671 "Return the rectangle properties as a tuple.", "");
673 wxPyBlock_t blocked = wxPyBeginBlockThreads();
674 PyObject* tup = PyTuple_New(4);
675 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
676 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
677 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
678 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
679 wxPyEndBlockThreads(blocked);
685 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
686 def __str__(self): return str(self.Get())
687 def __repr__(self): return 'wx.Rect'+str(self.Get())
688 def __len__(self): return len(self.Get())
689 def __getitem__(self, index): return self.Get()[index]
690 def __setitem__(self, index, val):
691 if index == 0: self.x = val
692 elif index == 1: self.y = val
693 elif index == 2: self.width = val
694 elif index == 3: self.height = val
695 else: raise IndexError
696 def __nonzero__(self): return self.Get() != (0,0,0,0)
697 __safe_for_unpickling__ = True
698 def __reduce__(self): return (wx.Rect, self.Get())
703 MustHaveApp(wxIntersectRect);
705 DocAStr(wxIntersectRect,
706 "IntersectRect(Rect r1, Rect r2) -> Rect",
707 "Calculate and return the intersection of r1 and r2.", "");
709 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
712 wxRect dest(0,0,0,0);
715 reg1.Intersect(reg2);
716 dest = reg1.GetBox();
718 if (dest != wxRect(0,0,0,0)) {
719 wxPyBlock_t blocked = wxPyBeginBlockThreads();
720 wxRect* newRect = new wxRect(dest);
721 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
722 wxPyEndBlockThreads(blocked);
730 //---------------------------------------------------------------------------
735 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
736 with floating point values.", "");
741 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
742 wxPoint2D( double x=0.0 , double y=0.0 );
743 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
744 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
747 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
748 "GetFloor() -> (x,y)",
749 "Convert to integer", "");
752 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
753 "GetRounded() -> (x,y)",
754 "Convert to integer", "");
756 double GetVectorLength() const;
757 double GetVectorAngle() const ;
758 void SetVectorLength( double length );
759 void SetVectorAngle( double degrees );
761 // LinkError: void SetPolarCoordinates( double angle , double length );
762 // LinkError: void Normalize();
764 def SetPolarCoordinates(self, angle, length):
765 self.SetVectorLength(length)
766 self.SetVectorAngle(angle)
768 self.SetVectorLength(1.0)
771 double GetDistance( const wxPoint2D &pt ) const;
772 double GetDistanceSquare( const wxPoint2D &pt ) const;
773 double GetDotProduct( const wxPoint2D &vec ) const;
774 double GetCrossProduct( const wxPoint2D &vec ) const;
777 wxPoint2D, operator-(),
778 "the reflection of this point", "");
780 wxPoint2D& operator+=(const wxPoint2D& pt);
781 wxPoint2D& operator-=(const wxPoint2D& pt);
783 wxPoint2D& operator*=(const wxPoint2D& pt);
784 wxPoint2D& operator/=(const wxPoint2D& pt);
788 DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
789 bool __eq__(PyObject* other) {
790 wxPoint2D temp, *obj = &temp;
791 if ( other == Py_None ) return false;
792 if ( ! wxPoint2D_helper(other, &obj) ) {
796 return self->operator==(*obj);
801 DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
802 bool __ne__(PyObject* other) {
803 wxPoint2D temp, *obj = &temp;
804 if ( other == Py_None ) return true;
805 if ( ! wxPoint2D_helper(other, &obj)) {
809 return self->operator!=(*obj);
813 %Rename(x, double, m_x);
814 %Rename(y, double, m_y);
817 void Set( double x=0 , double y=0 ) {
824 "Return x and y properties as a tuple.", "");
826 wxPyBlock_t blocked = wxPyBeginBlockThreads();
827 PyObject* tup = PyTuple_New(2);
828 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
829 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
830 wxPyEndBlockThreads(blocked);
836 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
837 def __str__(self): return str(self.Get())
838 def __repr__(self): return 'wx.Point2D'+str(self.Get())
839 def __len__(self): return len(self.Get())
840 def __getitem__(self, index): return self.Get()[index]
841 def __setitem__(self, index, val):
842 if index == 0: self.x = val
843 elif index == 1: self.y = val
844 else: raise IndexError
845 def __nonzero__(self): return self.Get() != (0.0, 0.0)
846 __safe_for_unpickling__ = True
847 def __reduce__(self): return (wx.Point2D, self.Get())
852 //---------------------------------------------------------------------------
855 const wxPoint wxDefaultPosition;
856 const wxSize wxDefaultSize;
859 //---------------------------------------------------------------------------