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 contians integer width and height
117 proprtites. 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.", "");
133 // None/NULL is now handled properly by the typemap, so these are not needed.
135 // bool __eq__(const wxSize* other) { return other ? (*self == *other) : false; }
136 // bool __ne__(const wxSize* other) { return other ? (*self != *other) : true; }
140 bool, operator==(const wxSize& sz),
141 "Test for equality of wx.Size objects.", "");
144 bool, operator!=(const wxSize& sz),
145 "Test for inequality.", "");
148 wxSize, operator+(const wxSize& sz),
149 "Add sz's proprties to this and return the result.", "");
152 wxSize, operator-(const wxSize& sz),
153 "Subtract sz's properties from this and return the result.", "");
156 void, IncTo(const wxSize& sz),
157 "Increments this object so that both of its dimensions are not less
158 than the corresponding dimensions of the size.", "");
161 void, DecTo(const wxSize& sz),
162 "Decrements this object so that both of its dimensions are not greater
163 than the corresponding dimensions of the size.", "");
166 void, Set(int w, int h),
167 "Set both width and height.", "");
169 void SetWidth(int w);
170 void SetHeight(int h);
171 int GetWidth() const;
172 int GetHeight() const;
176 bool , IsFullySpecified() const,
177 "Returns True if both components of the size are non-default values.", "");
181 void , SetDefaults(const wxSize& size),
182 "Combine this size with the other one replacing the default components
183 of this object (i.e. equal to -1) with those of the other.", "");
191 "Get() -> (width,height)",
192 "Returns the width and height properties as a tuple.", "");
194 wxPyBlock_t blocked = wxPyBeginBlockThreads();
195 PyObject* tup = PyTuple_New(2);
196 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
197 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
198 wxPyEndBlockThreads(blocked);
203 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
204 def __str__(self): return str(self.Get())
205 def __repr__(self): return 'wx.Size'+str(self.Get())
206 def __len__(self): return len(self.Get())
207 def __getitem__(self, index): return self.Get()[index]
208 def __setitem__(self, index, val):
209 if index == 0: self.width = val
210 elif index == 1: self.height = val
211 else: raise IndexError
212 def __nonzero__(self): return self.Get() != (0,0)
213 __safe_for_unpickling__ = True
214 def __reduce__(self): return (wx.Size, self.Get())
219 //---------------------------------------------------------------------------
223 "A data structure for representing a point or position with floating
224 point x and y properties. In wxPython most places that expect a
225 wx.RealPoint can also accept a (x,y) tuple.", "");
233 wxRealPoint(double x=0.0, double y=0.0),
234 "Create a wx.RealPoint object", "");
239 bool, operator==(const wxRealPoint& pt),
240 "Test for equality of wx.RealPoint objects.", "");
243 bool, operator!=(const wxRealPoint& pt),
244 "Test for inequality of wx.RealPoint objects.", "");
248 wxRealPoint, operator+(const wxRealPoint& pt),
249 "Add pt's proprties to this and return the result.", "");
252 wxRealPoint, operator-(const wxRealPoint& pt),
253 "Subtract pt's proprties from this and return the result", "");
257 DocStr(Set, "Set both the x and y properties", "");
258 void Set(double x, double y) {
265 "Return the x and y properties as a tuple. ", "");
267 wxPyBlock_t blocked = wxPyBeginBlockThreads();
268 PyObject* tup = PyTuple_New(2);
269 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
270 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
271 wxPyEndBlockThreads(blocked);
277 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
278 def __str__(self): return str(self.Get())
279 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
280 def __len__(self): return len(self.Get())
281 def __getitem__(self, index): return self.Get()[index]
282 def __setitem__(self, index, val):
283 if index == 0: self.x = val
284 elif index == 1: self.y = val
285 else: raise IndexError
286 def __nonzero__(self): return self.Get() != (0.0, 0.0)
287 __safe_for_unpickling__ = True
288 def __reduce__(self): return (wx.RealPoint, self.Get())
293 //---------------------------------------------------------------------------
298 "A data structure for representing a point or position with integer x
299 and y properties. Most places in wxPython that expect a wx.Point can
300 also accept a (x,y) tuple.", "");
308 wxPoint(int x=0, int y=0),
309 "Create a wx.Point object", "");
315 bool, operator==(const wxPoint& pt),
316 "Test for equality of wx.Point objects.", "");
319 bool, operator!=(const wxPoint& pt),
320 "Test for inequality of wx.Point objects.", "");
324 // %nokwargs operator+;
325 // %nokwargs operator-;
326 // %nokwargs operator+=;
327 // %nokwargs operator-=;
330 wxPoint, operator+(const wxPoint& pt),
331 "Add pt's proprties to this and return the result.", "");
335 wxPoint, operator-(const wxPoint& pt),
336 "Subtract pt's proprties from this and return the result", "");
340 wxPoint&, operator+=(const wxPoint& pt),
341 "Add pt to this object.", "");
344 wxPoint&, operator-=(const wxPoint& pt),
345 "Subtract pt from this object.", "");
350 // wxPoint, operator+(const wxSize& sz),
351 // "Add sz to this Point and return the result.", "");
354 // wxPoint, operator-(const wxSize& sz),
355 // "Subtract sz from this Point and return the result", "");
359 // wxPoint&, operator+=(const wxSize& sz),
360 // "Add sz to this object.", "");
363 // wxPoint&, operator-=(const wxSize& sz),
364 // "Subtract sz from this object.", "");
370 DocStr(Set, "Set both the x and y properties", "");
371 void Set(long x, long y) {
378 "Return the x and y properties as a tuple. ", "");
380 wxPyBlock_t blocked = wxPyBeginBlockThreads();
381 PyObject* tup = PyTuple_New(2);
382 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
383 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
384 wxPyEndBlockThreads(blocked);
390 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
391 def __str__(self): return str(self.Get())
392 def __repr__(self): return 'wx.Point'+str(self.Get())
393 def __len__(self): return len(self.Get())
394 def __getitem__(self, index): return self.Get()[index]
395 def __setitem__(self, index, val):
396 if index == 0: self.x = val
397 elif index == 1: self.y = val
398 else: raise IndexError
399 def __nonzero__(self): return self.Get() != (0,0)
400 __safe_for_unpickling__ = True
401 def __reduce__(self): return (wx.Point, self.Get())
405 //---------------------------------------------------------------------------
410 "A class for representing and manipulating rectangles. It has x, y,
411 width and height properties. In wxPython most palces that expect a
412 wx.Rect can also accept a (x,y,width,height) tuple.", "");
418 wxRect(int x=0, int y=0, int width=0, int height=0),
419 "Create a new Rect object.", "");
422 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
423 "Create a new Rect object from Points representing two corners.", "",
427 wxRect(const wxPoint& pos, const wxSize& size),
428 "Create a new Rect from a position and size.", "",
432 wxRect(const wxSize& size),
433 "Create a new Rect from a size only.", "",
444 int GetWidth() const;
445 void SetWidth(int w);
447 int GetHeight() const;
448 void SetHeight(int h);
450 wxPoint GetPosition() const;
451 void SetPosition( const wxPoint &p );
453 wxSize GetSize() const;
454 void SetSize( const wxSize &s );
456 bool IsEmpty() const;
458 wxPoint GetTopLeft() const;
459 void SetTopLeft(const wxPoint &p);
460 wxPoint GetBottomRight() const;
461 void SetBottomRight(const wxPoint &p);
463 // wxPoint GetLeftTop() const;
464 // void SetLeftTop(const wxPoint &p);
465 // wxPoint GetRightBottom() const;
466 // void SetRightBottom(const wxPoint &p);
470 int GetBottom() const;
471 int GetRight() const;
473 void SetLeft(int left);
474 void SetRight(int right);
475 void SetTop(int top);
476 void SetBottom(int bottom);
479 position = property(GetPosition, SetPosition)
480 size = property(GetSize, SetSize)
481 left = property(GetLeft, SetLeft)
482 right = property(GetRight, SetRight)
483 top = property(GetTop, SetTop)
484 bottom = property(GetBottom, SetBottom)
488 wxRect&, Inflate(wxCoord dx, wxCoord dy),
489 "Increases the size of the rectangle.
491 The left border is moved farther left and the right border is moved
492 farther right by ``dx``. The upper border is moved farther up and the
493 bottom border is moved farther down by ``dy``. (Note the the width and
494 height of the rectangle thus change by ``2*dx`` and ``2*dy``,
495 respectively.) If one or both of ``dx`` and ``dy`` are negative, the
496 opposite happens: the rectangle size decreases in the respective
499 The change is made to the rectangle inplace, if instead you need a
500 copy that is inflated, preserving the original then make the copy
503 copy = wx.Rect(*original)
507 Inflating and deflating behaves *naturally*. Defined more precisely,
510 * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not
511 constrained. Thus inflating a rectangle can cause its upper left
512 corner to move into the negative numbers. (The versions prior to
513 2.5.4 forced the top left coordinate to not fall below (0, 0),
514 which implied a forced move of the rectangle.)
516 * Deflates are clamped to not reduce the width or height of the
517 rectangle below zero. In such cases, the top-left corner is
518 nonetheless handled properly. For example, a rectangle at (10,
519 10) with size (20, 40) that is inflated by (-15, -15) will
520 become located at (20, 25) at size (0, 10). Finally, observe
521 that the width and height are treated independently. In the
522 above example, the width is reduced by 20, whereas the height is
523 reduced by the full 30 (rather than also stopping at 20, when
524 the width reached zero).
530 wxRect&, Deflate(wxCoord dx, wxCoord dy),
531 "Decrease the rectangle size. This method is the opposite of `Inflate`
532 in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to
533 `Inflate` for a full description.", "");
536 void, Offset(wxCoord dx, wxCoord dy),
537 "Moves the rectangle by the specified offset. If dx is positive, the
538 rectangle is moved to the right, if dy is positive, it is moved to the
539 bottom, otherwise it is moved to the left or top respectively.", "",
543 void, Offset(const wxPoint& pt),
544 "Same as `OffsetXY` but uses dx,dy from Point", "");
547 wxRect, Intersect(const wxRect& rect),
548 "Returns the intersectsion of this rectangle and rect.", "");
551 wxRect , Union(const wxRect& rect),
552 "Returns the union of this rectangle and rect.", "");
556 wxRect, operator+(const wxRect& rect) const,
557 "Add the properties of rect to this rectangle and return the result.", "");
560 wxRect&, operator+=(const wxRect& rect),
561 "Add the properties of rect to this rectangle, updating this rectangle.", "");
564 bool, operator==(const wxRect& rect) const,
565 "Test for equality.", "");
568 bool, operator!=(const wxRect& rect) const,
569 "Test for inequality.", "");
572 DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", "");
573 %Rename(InsideXY, bool, Inside(int x, int y) const);
574 bool Inside(const wxPoint& pt) const;
577 bool, Intersects(const wxRect& rect) const,
578 "Returns True if the rectangles have a non empty intersection.", "");
581 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
582 "Center this rectangle within the one passed to the method, which is
583 usually, but not necessarily, the larger one.", "");
584 %pythoncode { CentreIn = CenterIn }
587 int x, y, width, height;
591 DocStr(Set, "Set all rectangle properties.", "");
592 void Set(int x=0, int y=0, int width=0, int height=0) {
596 self->height = height;
600 "Get() -> (x,y,width,height)",
601 "Return the rectangle properties as a tuple.", "");
603 wxPyBlock_t blocked = wxPyBeginBlockThreads();
604 PyObject* tup = PyTuple_New(4);
605 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
606 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
607 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
608 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
609 wxPyEndBlockThreads(blocked);
615 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
616 def __str__(self): return str(self.Get())
617 def __repr__(self): return 'wx.Rect'+str(self.Get())
618 def __len__(self): return len(self.Get())
619 def __getitem__(self, index): return self.Get()[index]
620 def __setitem__(self, index, val):
621 if index == 0: self.x = val
622 elif index == 1: self.y = val
623 elif index == 2: self.width = val
624 elif index == 3: self.height = val
625 else: raise IndexError
626 def __nonzero__(self): return self.Get() != (0,0,0,0)
627 __safe_for_unpickling__ = True
628 def __reduce__(self): return (wx.Rect, self.Get())
633 MustHaveApp(wxIntersectRect);
635 DocAStr(wxIntersectRect,
636 "IntersectRect(Rect r1, Rect r2) -> Rect",
637 "Calculate and return the intersection of r1 and r2.", "");
639 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
642 wxRect dest(0,0,0,0);
645 reg1.Intersect(reg2);
646 dest = reg1.GetBox();
648 if (dest != wxRect(0,0,0,0)) {
649 wxPyBlock_t blocked = wxPyBeginBlockThreads();
650 wxRect* newRect = new wxRect(dest);
651 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
652 wxPyEndBlockThreads(blocked);
660 //---------------------------------------------------------------------------
665 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
666 with floating point values.", "");
671 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
672 wxPoint2D( double x=0.0 , double y=0.0 );
673 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
674 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
677 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
678 "GetFloor() -> (x,y)",
679 "Convert to integer", "");
682 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
683 "GetRounded() -> (x,y)",
684 "Convert to integer", "");
686 double GetVectorLength() const;
687 double GetVectorAngle() const ;
688 void SetVectorLength( double length );
689 void SetVectorAngle( double degrees );
691 // LinkError: void SetPolarCoordinates( double angle , double length );
692 // LinkError: void Normalize();
694 def SetPolarCoordinates(self, angle, length):
695 self.SetVectorLength(length)
696 self.SetVectorAngle(angle)
698 self.SetVectorLength(1.0)
701 double GetDistance( const wxPoint2D &pt ) const;
702 double GetDistanceSquare( const wxPoint2D &pt ) const;
703 double GetDotProduct( const wxPoint2D &vec ) const;
704 double GetCrossProduct( const wxPoint2D &vec ) const;
707 wxPoint2D, operator-(),
708 "the reflection of this point", "");
710 wxPoint2D& operator+=(const wxPoint2D& pt);
711 wxPoint2D& operator-=(const wxPoint2D& pt);
713 wxPoint2D& operator*=(const wxPoint2D& pt);
714 wxPoint2D& operator/=(const wxPoint2D& pt);
717 bool, operator==(const wxPoint2D& pt) const,
718 "Test for equality", "");
721 bool, operator!=(const wxPoint2D& pt) const,
722 "Test for inequality", "");
724 %Rename(x, double, m_x);
725 %Rename(y, double, m_y);
728 void Set( double x=0 , double y=0 ) {
735 "Return x and y properties as a tuple.", "");
737 wxPyBlock_t blocked = wxPyBeginBlockThreads();
738 PyObject* tup = PyTuple_New(2);
739 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
740 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
741 wxPyEndBlockThreads(blocked);
747 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
748 def __str__(self): return str(self.Get())
749 def __repr__(self): return 'wx.Point2D'+str(self.Get())
750 def __len__(self): return len(self.Get())
751 def __getitem__(self, index): return self.Get()[index]
752 def __setitem__(self, index, val):
753 if index == 0: self.x = val
754 elif index == 1: self.y = val
755 else: raise IndexError
756 def __nonzero__(self): return self.Get() != (0.0, 0.0)
757 __safe_for_unpickling__ = True
758 def __reduce__(self): return (wx.Point2D, self.Get())
763 //---------------------------------------------------------------------------
766 const wxPoint wxDefaultPosition;
767 const wxSize wxDefaultSize;
770 //---------------------------------------------------------------------------