]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_gdicmn.i
added wxString::FromAscii(char*,size_t) for consistency with FromUTF8()
[wxWidgets.git] / wxPython / src / _gdicmn.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _gdicmn.i
3// Purpose: SWIG interface for common GDI stuff and misc classes
4//
5// Author: Robin Dunn
6//
7// Created: 13-Sept-2003
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19
debe38c9
RD
20// Turn off the aquisition of the Global Interpreter Lock for the classes and
21// functions in this file
22%threadWrapperOff
23
24
d14a1e28
RD
25enum wxBitmapType
26{
27 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
28 wxBITMAP_TYPE_BMP,
d14a1e28 29 wxBITMAP_TYPE_ICO,
d14a1e28 30 wxBITMAP_TYPE_CUR,
d14a1e28
RD
31 wxBITMAP_TYPE_XBM,
32 wxBITMAP_TYPE_XBM_DATA,
33 wxBITMAP_TYPE_XPM,
34 wxBITMAP_TYPE_XPM_DATA,
35 wxBITMAP_TYPE_TIF,
d14a1e28 36 wxBITMAP_TYPE_GIF,
d14a1e28 37 wxBITMAP_TYPE_PNG,
d14a1e28 38 wxBITMAP_TYPE_JPEG,
d14a1e28 39 wxBITMAP_TYPE_PNM,
d14a1e28 40 wxBITMAP_TYPE_PCX,
d14a1e28 41 wxBITMAP_TYPE_PICT,
d14a1e28 42 wxBITMAP_TYPE_ICON,
d14a1e28
RD
43 wxBITMAP_TYPE_ANI,
44 wxBITMAP_TYPE_IFF,
8f514ab4 45 wxBITMAP_TYPE_TGA,
d14a1e28 46 wxBITMAP_TYPE_MACCURSOR,
64e8a1f0
RD
47
48// wxBITMAP_TYPE_BMP_RESOURCE,
49// wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
50// wxBITMAP_TYPE_ICO_RESOURCE,
51// wxBITMAP_TYPE_CUR_RESOURCE,
52// wxBITMAP_TYPE_TIF_RESOURCE,
53// wxBITMAP_TYPE_GIF_RESOURCE,
54// wxBITMAP_TYPE_PNG_RESOURCE,
55// wxBITMAP_TYPE_JPEG_RESOURCE,
56// wxBITMAP_TYPE_PNM_RESOURCE,
57// wxBITMAP_TYPE_PCX_RESOURCE,
58// wxBITMAP_TYPE_PICT_RESOURCE,
59// wxBITMAP_TYPE_ICON_RESOURCE,
60// wxBITMAP_TYPE_MACCURSOR_RESOURCE,
61
d14a1e28
RD
62 wxBITMAP_TYPE_ANY = 50
63};
64
65// Standard cursors
66enum wxStockCursor
67{
68 wxCURSOR_NONE, // should be 0
69 wxCURSOR_ARROW,
70 wxCURSOR_RIGHT_ARROW,
71 wxCURSOR_BULLSEYE,
72 wxCURSOR_CHAR,
73 wxCURSOR_CROSS,
74 wxCURSOR_HAND,
75 wxCURSOR_IBEAM,
76 wxCURSOR_LEFT_BUTTON,
77 wxCURSOR_MAGNIFIER,
78 wxCURSOR_MIDDLE_BUTTON,
79 wxCURSOR_NO_ENTRY,
80 wxCURSOR_PAINT_BRUSH,
81 wxCURSOR_PENCIL,
82 wxCURSOR_POINT_LEFT,
83 wxCURSOR_POINT_RIGHT,
84 wxCURSOR_QUESTION_ARROW,
85 wxCURSOR_RIGHT_BUTTON,
86 wxCURSOR_SIZENESW,
87 wxCURSOR_SIZENS,
88 wxCURSOR_SIZENWSE,
89 wxCURSOR_SIZEWE,
90 wxCURSOR_SIZING,
91 wxCURSOR_SPRAYCAN,
92 wxCURSOR_WAIT,
93 wxCURSOR_WATCH,
94 wxCURSOR_BLANK,
95 wxCURSOR_DEFAULT, // standard X11 cursor
96 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
97
98// #ifdef __X__
99// // Not yet implemented for Windows
100// wxCURSOR_CROSS_REVERSE,
101// wxCURSOR_DOUBLE_ARROW,
102// wxCURSOR_BASED_ARROW_UP,
103// wxCURSOR_BASED_ARROW_DOWN,
104// #endif // X11
105
106 wxCURSOR_ARROWWAIT,
107
108 wxCURSOR_MAX
109};
110
111%{
112#ifndef __WXMAC__
113#define wxCURSOR_COPY_ARROW wxCURSOR_ARROW
114#endif
115%}
116
117//---------------------------------------------------------------------------
118%newgroup
d14a1e28 119
dd9f7fea 120DocStr( wxSize,
d07d2bc9 121"wx.Size is a useful data structure used to represent the size of
bea992c8
RD
122something. It simply contains integer width and height
123properties. In most places in wxPython where a wx.Size is
1b8c7ba6 124expected a (width, height) tuple can be used instead.", "");
dd9f7fea 125
d14a1e28
RD
126class wxSize
127{
128public:
1b8c7ba6
RD
129 %Rename(width, int, x);
130 %Rename(height,int, y);
61c5a8ac
RD
131 %pythoncode { x = width; y = height }
132
dd9f7fea
RD
133 DocCtorStr(
134 wxSize(int w=0, int h=0),
d07d2bc9 135 "Creates a size object.", "");
dd9f7fea 136
d14a1e28
RD
137 ~wxSize();
138
1fce4e96
RD
139
140 %extend {
debe38c9 141 //KeepGIL(__eq__);
1fce4e96
RD
142 DocStr(__eq__, "Test for equality of wx.Size objects.", "");
143 bool __eq__(PyObject* other) {
144 wxSize temp, *obj = &temp;
145 if ( other == Py_None ) return false;
146 if ( ! wxSize_helper(other, &obj) ) {
147 PyErr_Clear();
148 return false;
149 }
150 return self->operator==(*obj);
151 }
dd9f7fea 152
1fce4e96 153
debe38c9 154 //KeepGIL(__ne__);
1fce4e96
RD
155 DocStr(__ne__, "Test for inequality of wx.Size objects.", "");
156 bool __ne__(PyObject* other) {
157 wxSize temp, *obj = &temp;
158 if ( other == Py_None ) return true;
159 if ( ! wxSize_helper(other, &obj)) {
160 PyErr_Clear();
161 return true;
162 }
163 return self->operator!=(*obj);
164 }
165 }
d14a1e28 166
dd9f7fea
RD
167 DocDeclStr(
168 wxSize, operator+(const wxSize& sz),
d07d2bc9 169 "Add sz's proprties to this and return the result.", "");
d14a1e28 170
dd9f7fea
RD
171 DocDeclStr(
172 wxSize, operator-(const wxSize& sz),
d07d2bc9 173 "Subtract sz's properties from this and return the result.", "");
d14a1e28 174
dd9f7fea
RD
175 DocDeclStr(
176 void, IncTo(const wxSize& sz),
d07d2bc9
RD
177 "Increments this object so that both of its dimensions are not less
178than the corresponding dimensions of the size.", "");
dd9f7fea
RD
179
180 DocDeclStr(
181 void, DecTo(const wxSize& sz),
d07d2bc9
RD
182 "Decrements this object so that both of its dimensions are not greater
183than the corresponding dimensions of the size.", "");
dd9f7fea 184
f5263701
RD
185
186 DocDeclStr(
187 void , IncBy(int dx, int dy),
188 "", "");
189
190
191 DocDeclStr(
192 void , DecBy(int dx, int dy),
193 "", "");
194
195// TODO: handle these overloads too?
196// void IncBy(const wxSize& sz);
197// void IncBy(int d);
198// void DecBy(const wxSize& sz);
199// void DecBy(int d);
6aaca5ba
RD
200
201 DocDeclStr(
202 void , Scale(float xscale, float yscale),
203 "Scales the dimensions of this object by the given factors.", "");
204
dd9f7fea
RD
205 DocDeclStr(
206 void, Set(int w, int h),
d07d2bc9 207 "Set both width and height.", "");
dd9f7fea 208
d14a1e28
RD
209 void SetWidth(int w);
210 void SetHeight(int h);
211 int GetWidth() const;
212 int GetHeight() const;
213
93a163f6
RD
214
215 DocDeclStr(
216 bool , IsFullySpecified() const,
d07d2bc9 217 "Returns True if both components of the size are non-default values.", "");
93a163f6
RD
218
219
220 DocDeclStr(
221 void , SetDefaults(const wxSize& size),
d07d2bc9
RD
222 "Combine this size with the other one replacing the default components
223of this object (i.e. equal to -1) with those of the other.", "");
93a163f6
RD
224
225
dd9f7fea
RD
226 //int GetX() const;
227 //int GetY() const;
d14a1e28
RD
228
229 %extend {
dd9f7fea
RD
230 DocAStr(Get,
231 "Get() -> (width,height)",
d07d2bc9 232 "Returns the width and height properties as a tuple.", "");
dd9f7fea 233 PyObject* Get() {
debe38c9 234 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
235 PyObject* tup = PyTuple_New(2);
236 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
237 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
debe38c9 238 //wxPyEndBlockThreads(blocked);
d14a1e28
RD
239 return tup;
240 }
241 }
242 %pythoncode {
d07d2bc9 243 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
244 def __str__(self): return str(self.Get())
245 def __repr__(self): return 'wx.Size'+str(self.Get())
246 def __len__(self): return len(self.Get())
247 def __getitem__(self, index): return self.Get()[index]
d14a1e28
RD
248 def __setitem__(self, index, val):
249 if index == 0: self.width = val
250 elif index == 1: self.height = val
251 else: raise IndexError
dd9f7fea 252 def __nonzero__(self): return self.Get() != (0,0)
02376d73
RD
253 __safe_for_unpickling__ = True
254 def __reduce__(self): return (wx.Size, self.Get())
d14a1e28
RD
255 }
256
257};
258
259//---------------------------------------------------------------------------
260%newgroup
94d33c49 261
dd9f7fea 262DocStr( wxRealPoint,
d07d2bc9
RD
263"A data structure for representing a point or position with floating
264point x and y properties. In wxPython most places that expect a
265wx.RealPoint can also accept a (x,y) tuple.", "");
d14a1e28
RD
266class wxRealPoint
267{
268public:
269 double x;
270 double y;
271
dd9f7fea
RD
272 DocCtorStr(
273 wxRealPoint(double x=0.0, double y=0.0),
d07d2bc9 274 "Create a wx.RealPoint object", "");
dd9f7fea 275
d14a1e28
RD
276 ~wxRealPoint();
277
1fce4e96 278 %extend {
debe38c9 279 //KeepGIL(__eq__);
1fce4e96
RD
280 DocStr(__eq__, "Test for equality of wx.RealPoint objects.", "");
281 bool __eq__(PyObject* other) {
282 wxRealPoint temp, *obj = &temp;
283 if ( other == Py_None ) return false;
284 if ( ! wxRealPoint_helper(other, &obj) ) {
285 PyErr_Clear();
286 return false;
287 }
288 return self->operator==(*obj);
289 }
dd9f7fea 290
1fce4e96 291
debe38c9 292 //KeepGIL(__ne__);
1fce4e96
RD
293 DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", "");
294 bool __ne__(PyObject* other) {
295 wxRealPoint temp, *obj = &temp;
296 if ( other == Py_None ) return true;
297 if ( ! wxRealPoint_helper(other, &obj)) {
298 PyErr_Clear();
299 return true;
300 }
301 return self->operator!=(*obj);
302 }
303 }
dd9f7fea
RD
304
305
306 DocDeclStr(
307 wxRealPoint, operator+(const wxRealPoint& pt),
d07d2bc9 308 "Add pt's proprties to this and return the result.", "");
dd9f7fea
RD
309
310 DocDeclStr(
311 wxRealPoint, operator-(const wxRealPoint& pt),
d07d2bc9 312 "Subtract pt's proprties from this and return the result", "");
d14a1e28 313
d14a1e28
RD
314
315 %extend {
d07d2bc9 316 DocStr(Set, "Set both the x and y properties", "");
d14a1e28
RD
317 void Set(double x, double y) {
318 self->x = x;
319 self->y = y;
320 }
dd9f7fea
RD
321
322 DocAStr(Get,
323 "Get() -> (x,y)",
d07d2bc9 324 "Return the x and y properties as a tuple. ", "");
dd9f7fea 325 PyObject* Get() {
debe38c9 326 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
327 PyObject* tup = PyTuple_New(2);
328 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
329 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
debe38c9 330 //PyEndBlockThreads(blocked);
d14a1e28
RD
331 return tup;
332 }
333 }
334
335 %pythoncode {
d07d2bc9 336 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
337 def __str__(self): return str(self.Get())
338 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
339 def __len__(self): return len(self.Get())
340 def __getitem__(self, index): return self.Get()[index]
d14a1e28 341 def __setitem__(self, index, val):
dd9f7fea
RD
342 if index == 0: self.x = val
343 elif index == 1: self.y = val
d14a1e28 344 else: raise IndexError
dd9f7fea 345 def __nonzero__(self): return self.Get() != (0.0, 0.0)
02376d73
RD
346 __safe_for_unpickling__ = True
347 def __reduce__(self): return (wx.RealPoint, self.Get())
d14a1e28
RD
348 }
349};
350
dd9f7fea 351
d14a1e28
RD
352//---------------------------------------------------------------------------
353%newgroup
94d33c49 354
d14a1e28 355
dd9f7fea 356DocStr(wxPoint,
d07d2bc9
RD
357"A data structure for representing a point or position with integer x
358and y properties. Most places in wxPython that expect a wx.Point can
359also accept a (x,y) tuple.", "");
dd9f7fea 360
d14a1e28
RD
361class wxPoint
362{
363public:
364 int x, y;
365
dd9f7fea
RD
366 DocCtorStr(
367 wxPoint(int x=0, int y=0),
d07d2bc9 368 "Create a wx.Point object", "");
dd9f7fea 369
d14a1e28
RD
370 ~wxPoint();
371
dd9f7fea 372
1fce4e96 373 %extend {
debe38c9 374 //KeepGIL(__eq__);
1fce4e96
RD
375 DocStr(__eq__, "Test for equality of wx.Point objects.", "");
376 bool __eq__(PyObject* other) {
377 wxPoint temp, *obj = &temp;
378 if ( other == Py_None ) return false;
379 if ( ! wxPoint_helper(other, &obj) ) {
380 PyErr_Clear();
381 return false;
382 }
383 return self->operator==(*obj);
384 }
d14a1e28 385
1fce4e96 386
debe38c9 387 //KeepGIL(__ne__);
1fce4e96
RD
388 DocStr(__ne__, "Test for inequality of wx.Point objects.", "");
389 bool __ne__(PyObject* other) {
390 wxPoint temp, *obj = &temp;
391 if ( other == Py_None ) return true;
392 if ( ! wxPoint_helper(other, &obj)) {
393 PyErr_Clear();
394 return true;
395 }
396 return self->operator!=(*obj);
397 }
398 }
093d613e
RD
399
400
401// %nokwargs operator+;
402// %nokwargs operator-;
403// %nokwargs operator+=;
404// %nokwargs operator-=;
dd9f7fea
RD
405
406 DocDeclStr(
407 wxPoint, operator+(const wxPoint& pt),
d07d2bc9 408 "Add pt's proprties to this and return the result.", "");
d14a1e28 409
093d613e 410
dd9f7fea
RD
411 DocDeclStr(
412 wxPoint, operator-(const wxPoint& pt),
d07d2bc9 413 "Subtract pt's proprties from this and return the result", "");
dd9f7fea
RD
414
415
416 DocDeclStr(
417 wxPoint&, operator+=(const wxPoint& pt),
d07d2bc9 418 "Add pt to this object.", "");
dd9f7fea
RD
419
420 DocDeclStr(
421 wxPoint&, operator-=(const wxPoint& pt),
d07d2bc9 422 "Subtract pt from this object.", "");
dd9f7fea 423
093d613e
RD
424
425
426// DocDeclStr(
427// wxPoint, operator+(const wxSize& sz),
d07d2bc9 428// "Add sz to this Point and return the result.", "");
093d613e
RD
429
430// DocDeclStr(
431// wxPoint, operator-(const wxSize& sz),
d07d2bc9 432// "Subtract sz from this Point and return the result", "");
093d613e
RD
433
434
435// DocDeclStr(
436// wxPoint&, operator+=(const wxSize& sz),
d07d2bc9 437// "Add sz to this object.", "");
093d613e
RD
438
439// DocDeclStr(
440// wxPoint&, operator-=(const wxSize& sz),
d07d2bc9 441// "Subtract sz from this object.", "");
093d613e
RD
442
443
444
dd9f7fea 445
d14a1e28 446 %extend {
d07d2bc9 447 DocStr(Set, "Set both the x and y properties", "");
d14a1e28
RD
448 void Set(long x, long y) {
449 self->x = x;
450 self->y = y;
451 }
dd9f7fea
RD
452
453 DocAStr(Get,
454 "Get() -> (x,y)",
d07d2bc9 455 "Return the x and y properties as a tuple. ", "");
dd9f7fea 456 PyObject* Get() {
debe38c9 457 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
458 PyObject* tup = PyTuple_New(2);
459 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
460 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
debe38c9 461 //wxPyEndBlockThreads(blocked);
d14a1e28
RD
462 return tup;
463 }
464 }
465
466 %pythoncode {
d07d2bc9 467 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
468 def __str__(self): return str(self.Get())
469 def __repr__(self): return 'wx.Point'+str(self.Get())
470 def __len__(self): return len(self.Get())
471 def __getitem__(self, index): return self.Get()[index]
d14a1e28
RD
472 def __setitem__(self, index, val):
473 if index == 0: self.x = val
474 elif index == 1: self.y = val
475 else: raise IndexError
dd9f7fea 476 def __nonzero__(self): return self.Get() != (0,0)
02376d73
RD
477 __safe_for_unpickling__ = True
478 def __reduce__(self): return (wx.Point, self.Get())
d14a1e28
RD
479 }
480};
481
482//---------------------------------------------------------------------------
483%newgroup
94d33c49 484
d14a1e28 485
dd9f7fea 486DocStr(wxRect,
d07d2bc9
RD
487"A class for representing and manipulating rectangles. It has x, y,
488width and height properties. In wxPython most palces that expect a
489wx.Rect can also accept a (x,y,width,height) tuple.", "");
dd9f7fea 490
fe45b493
RD
491
492%typemap(in) wxRect*;
493
d14a1e28
RD
494class wxRect
495{
496public:
dd9f7fea
RD
497 DocCtorStr(
498 wxRect(int x=0, int y=0, int width=0, int height=0),
d07d2bc9 499 "Create a new Rect object.", "");
dd9f7fea
RD
500
501 DocCtorStrName(
502 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
d07d2bc9 503 "Create a new Rect object from Points representing two corners.", "",
dd9f7fea
RD
504 RectPP);
505
506 DocCtorStrName(
507 wxRect(const wxPoint& pos, const wxSize& size),
d07d2bc9 508 "Create a new Rect from a position and size.", "",
dd9f7fea 509 RectPS);
7aada1e0
RD
510
511 DocCtorStrName(
512 wxRect(const wxSize& size),
513 "Create a new Rect from a size only.", "",
514 RectS);
515
d14a1e28
RD
516 ~wxRect();
517
518 int GetX() const;
519 void SetX(int x);
520
521 int GetY();
522 void SetY(int y);
523
524 int GetWidth() const;
525 void SetWidth(int w);
526
527 int GetHeight() const;
528 void SetHeight(int h);
529
530 wxPoint GetPosition() const;
531 void SetPosition( const wxPoint &p );
532
533 wxSize GetSize() const;
534 void SetSize( const wxSize &s );
535
c3fc056e
RD
536 bool IsEmpty() const;
537
3f0ff538
RD
538 wxPoint GetTopLeft() const;
539 void SetTopLeft(const wxPoint &p);
540 wxPoint GetBottomRight() const;
541 void SetBottomRight(const wxPoint &p);
542
5acb46e0
RD
543 wxPoint GetTopRight() const;
544 void SetTopRight(const wxPoint &p);
545 wxPoint GetBottomLeft() const;
546 void SetBottomLeft(const wxPoint &p);
547
3f0ff538
RD
548// wxPoint GetLeftTop() const;
549// void SetLeftTop(const wxPoint &p);
550// wxPoint GetRightBottom() const;
551// void SetRightBottom(const wxPoint &p);
5acb46e0
RD
552// wxPoint GetRightTop() const;
553// void SetRightTop(const wxPoint &p);
554// wxPoint GetLeftBottom() const;
555// void SetLeftBottom(const wxPoint &p);
3f0ff538 556
d14a1e28
RD
557 int GetLeft() const;
558 int GetTop() const;
559 int GetBottom() const;
560 int GetRight() const;
561
562 void SetLeft(int left);
563 void SetRight(int right);
564 void SetTop(int top);
565 void SetBottom(int bottom);
566
dd9f7fea
RD
567 %pythoncode {
568 position = property(GetPosition, SetPosition)
569 size = property(GetSize, SetSize)
570 left = property(GetLeft, SetLeft)
571 right = property(GetRight, SetRight)
572 top = property(GetTop, SetTop)
573 bottom = property(GetBottom, SetBottom)
574 }
575
a9b95496 576
dd9f7fea 577 DocDeclStr(
3c69a2ec 578 wxRect, Inflate(wxCoord dx, wxCoord dy),
ca30acad
RD
579 "Increases the size of the rectangle.
580
581The left border is moved farther left and the right border is moved
582farther right by ``dx``. The upper border is moved farther up and the
583bottom border is moved farther down by ``dy``. (Note the the width and
584height of the rectangle thus change by ``2*dx`` and ``2*dy``,
585respectively.) If one or both of ``dx`` and ``dy`` are negative, the
586opposite happens: the rectangle size decreases in the respective
587direction.
588
589The change is made to the rectangle inplace, if instead you need a
590copy that is inflated, preserving the original then make the copy
591first::
592
593 copy = wx.Rect(*original)
594 copy.Inflate(10,15)
595
596", "
597Inflating and deflating behaves *naturally*. Defined more precisely,
598that means:
599
600 * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not
601 constrained. Thus inflating a rectangle can cause its upper left
602 corner to move into the negative numbers. (The versions prior to
603 2.5.4 forced the top left coordinate to not fall below (0, 0),
604 which implied a forced move of the rectangle.)
605
606 * Deflates are clamped to not reduce the width or height of the
607 rectangle below zero. In such cases, the top-left corner is
608 nonetheless handled properly. For example, a rectangle at (10,
609 10) with size (20, 40) that is inflated by (-15, -15) will
610 become located at (20, 25) at size (0, 10). Finally, observe
611 that the width and height are treated independently. In the
612 above example, the width is reduced by 20, whereas the height is
613 reduced by the full 30 (rather than also stopping at 20, when
614 the width reached zero).
615
616:see: `Deflate`
617");
dd9f7fea 618
a9b95496
RD
619 // There are also these versions...
620 //wxRect& Inflate(const wxSize& d);
621 //wxRect& Inflate(wxCoord d);
622
623
dd9f7fea
RD
624 DocDeclStr(
625 wxRect&, Deflate(wxCoord dx, wxCoord dy),
ca30acad
RD
626 "Decrease the rectangle size. This method is the opposite of `Inflate`
627in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to
628`Inflate` for a full description.", "");
dd9f7fea 629
a9b95496
RD
630 // There are also these versions...
631 //wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); }
632 //wxRect& Deflate(wxCoord d) { return Inflate(-d); }
633
dd9f7fea
RD
634 DocDeclStrName(
635 void, Offset(wxCoord dx, wxCoord dy),
d07d2bc9
RD
636 "Moves the rectangle by the specified offset. If dx is positive, the
637rectangle is moved to the right, if dy is positive, it is moved to the
638bottom, otherwise it is moved to the left or top respectively.", "",
dd9f7fea
RD
639 OffsetXY);
640
641 DocDeclStr(
642 void, Offset(const wxPoint& pt),
096e3ea1 643 "Same as `OffsetXY` but uses dx,dy from Point", "");
dd9f7fea
RD
644
645 DocDeclStr(
9eefe9f0
RD
646 wxRect, Intersect(const wxRect& rect),
647 "Returns the intersectsion of this rectangle and rect.", "");
d14a1e28 648
9eefe9f0
RD
649 DocDeclStr(
650 wxRect , Union(const wxRect& rect),
651 "Returns the union of this rectangle and rect.", "");
652
653
dd9f7fea
RD
654 DocDeclStr(
655 wxRect, operator+(const wxRect& rect) const,
d07d2bc9 656 "Add the properties of rect to this rectangle and return the result.", "");
d14a1e28 657
dd9f7fea
RD
658 DocDeclStr(
659 wxRect&, operator+=(const wxRect& rect),
d07d2bc9 660 "Add the properties of rect to this rectangle, updating this rectangle.", "");
d14a1e28 661
1fce4e96 662 %extend {
debe38c9 663 //KeepGIL(__eq__);
1fce4e96
RD
664 DocStr(__eq__, "Test for equality of wx.Rect objects.", "");
665 bool __eq__(PyObject* other) {
666 wxRect temp, *obj = &temp;
667 if ( other == Py_None ) return false;
668 if ( ! wxRect_helper(other, &obj) ) {
669 PyErr_Clear();
670 return false;
671 }
672 return self->operator==(*obj);
673 }
d14a1e28 674
1fce4e96 675
debe38c9 676 //KeepGIL(__ne__);
1fce4e96
RD
677 DocStr(__ne__, "Test for inequality of wx.Rect objects.", "");
678 bool __ne__(PyObject* other) {
679 wxRect temp, *obj = &temp;
680 if ( other == Py_None ) return true;
681 if ( ! wxRect_helper(other, &obj)) {
682 PyErr_Clear();
683 return true;
684 }
685 return self->operator!=(*obj);
686 }
687 }
d14a1e28 688
dd9f7fea 689
8546a549
RD
690 DocStr( Contains, "Return True if the point is inside the rect.", "");
691 %Rename(ContainsXY, bool, Contains(int x, int y) const);
692 bool Contains(const wxPoint& pt) const;
d14a1e28 693
8e1222c7 694 DocDeclStrName(
8546a549 695 bool, Contains(const wxRect& rect) const,
8e1222c7
RD
696 "Returns ``True`` if the given rectangle is completely inside this
697rectangle or touches its boundary.", "",
8546a549 698 ContainsRect);
ce60dd8e 699
8546a549 700 %pythoncode {
ce60dd8e
RD
701 %#Inside = wx._deprecated(Contains, "Use `Contains` instead.")
702 %#InsideXY = wx._deprecated(ContainsXY, "Use `ContainsXY` instead.")
703 %#InsideRect = wx._deprecated(ContainsRect, "Use `ContainsRect` instead.")
704 Inside = Contains
705 InsideXY = ContainsXY
706 InsideRect = ContainsRect
8546a549 707 }
8e1222c7 708
dd9f7fea
RD
709 DocDeclStr(
710 bool, Intersects(const wxRect& rect) const,
d07d2bc9 711 "Returns True if the rectangles have a non empty intersection.", "");
d14a1e28 712
096e3ea1
RD
713 DocDeclStr(
714 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
715 "Center this rectangle within the one passed to the method, which is
716usually, but not necessarily, the larger one.", "");
717 %pythoncode { CentreIn = CenterIn }
718
dd9f7fea 719
d14a1e28
RD
720 int x, y, width, height;
721
722
723 %extend {
d07d2bc9 724 DocStr(Set, "Set all rectangle properties.", "");
dd9f7fea 725 void Set(int x=0, int y=0, int width=0, int height=0) {
d14a1e28
RD
726 self->x = x;
727 self->y = y;
728 self->width = width;
729 self->height = height;
730 }
731
dd9f7fea
RD
732 DocAStr(Get,
733 "Get() -> (x,y,width,height)",
d07d2bc9 734 "Return the rectangle properties as a tuple.", "");
dd9f7fea 735 PyObject* Get() {
debe38c9 736 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
737 PyObject* tup = PyTuple_New(4);
738 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
739 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
740 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
741 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
debe38c9 742 //wxPyEndBlockThreads(blocked);
d14a1e28
RD
743 return tup;
744 }
745 }
746
747 %pythoncode {
d07d2bc9 748 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
749 def __str__(self): return str(self.Get())
750 def __repr__(self): return 'wx.Rect'+str(self.Get())
751 def __len__(self): return len(self.Get())
752 def __getitem__(self, index): return self.Get()[index]
d14a1e28
RD
753 def __setitem__(self, index, val):
754 if index == 0: self.x = val
755 elif index == 1: self.y = val
756 elif index == 2: self.width = val
757 elif index == 3: self.height = val
758 else: raise IndexError
dd9f7fea 759 def __nonzero__(self): return self.Get() != (0,0,0,0)
02376d73
RD
760 __safe_for_unpickling__ = True
761 def __reduce__(self): return (wx.Rect, self.Get())
d14a1e28 762 }
7012bb9f
RD
763
764
765 %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`");
766 %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`");
5acb46e0 767 %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`");
7012bb9f
RD
768 %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`");
769 %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`");
770 %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`");
771 %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`");
772 %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`");
773 %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`");
774 %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`");
5acb46e0 775 %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`");
7012bb9f
RD
776 %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`");
777 %property(X, GetX, SetX, doc="See `GetX` and `SetX`");
778 %property(Y, GetY, SetY, doc="See `GetY` and `SetY`");
779
780 %property(Empty, IsEmpty, doc="See `IsEmpty`");
d14a1e28
RD
781};
782
fe45b493
RD
783%apply wxRect& { wxRect* };
784
785
d14a1e28 786
ab1f7d2a
RD
787MustHaveApp(wxIntersectRect);
788
dd9f7fea
RD
789DocAStr(wxIntersectRect,
790 "IntersectRect(Rect r1, Rect r2) -> Rect",
d07d2bc9 791 "Calculate and return the intersection of r1 and r2.", "");
d14a1e28
RD
792%inline %{
793 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
794 wxRegion reg1(*r1);
795 wxRegion reg2(*r2);
796 wxRect dest(0,0,0,0);
797 PyObject* obj;
798
799 reg1.Intersect(reg2);
800 dest = reg1.GetBox();
801
802 if (dest != wxRect(0,0,0,0)) {
debe38c9 803 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 804 wxRect* newRect = new wxRect(dest);
a72f4631 805 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
debe38c9 806 //wxPyEndBlockThreads(blocked);
d14a1e28
RD
807 return obj;
808 }
809 Py_INCREF(Py_None);
810 return Py_None;
811 }
812%}
813
814//---------------------------------------------------------------------------
815%newgroup
94d33c49 816
d14a1e28 817
dd9f7fea 818DocStr(wxPoint2D,
d07d2bc9
RD
819 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
820with floating point values.", "");
d14a1e28
RD
821
822class wxPoint2D
823{
dd9f7fea 824public:
d07d2bc9 825 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
d14a1e28 826 wxPoint2D( double x=0.0 , double y=0.0 );
1b8c7ba6
RD
827 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
828 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
d14a1e28 829
7b497846
RD
830 ~wxPoint2D();
831
dd9f7fea
RD
832 DocDeclAStr(
833 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
834 "GetFloor() -> (x,y)",
d07d2bc9 835 "Convert to integer", "");
dd9f7fea
RD
836
837 DocDeclAStr(
838 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
839 "GetRounded() -> (x,y)",
d07d2bc9 840 "Convert to integer", "");
d14a1e28
RD
841
842 double GetVectorLength() const;
843 double GetVectorAngle() const ;
844 void SetVectorLength( double length );
845 void SetVectorAngle( double degrees );
dd9f7fea 846
d14a1e28
RD
847 // LinkError: void SetPolarCoordinates( double angle , double length );
848 // LinkError: void Normalize();
849 %pythoncode {
850 def SetPolarCoordinates(self, angle, length):
851 self.SetVectorLength(length)
852 self.SetVectorAngle(angle)
853 def Normalize(self):
854 self.SetVectorLength(1.0)
855 }
856
857 double GetDistance( const wxPoint2D &pt ) const;
858 double GetDistanceSquare( const wxPoint2D &pt ) const;
859 double GetDotProduct( const wxPoint2D &vec ) const;
860 double GetCrossProduct( const wxPoint2D &vec ) const;
861
dd9f7fea
RD
862 DocDeclStr(
863 wxPoint2D, operator-(),
d07d2bc9 864 "the reflection of this point", "");
d14a1e28
RD
865
866 wxPoint2D& operator+=(const wxPoint2D& pt);
867 wxPoint2D& operator-=(const wxPoint2D& pt);
868
869 wxPoint2D& operator*=(const wxPoint2D& pt);
870 wxPoint2D& operator/=(const wxPoint2D& pt);
871
1fce4e96 872 %extend {
debe38c9 873 //KeepGIL(__eq__);
1fce4e96
RD
874 DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
875 bool __eq__(PyObject* other) {
876 wxPoint2D temp, *obj = &temp;
877 if ( other == Py_None ) return false;
878 if ( ! wxPoint2D_helper(other, &obj) ) {
879 PyErr_Clear();
880 return false;
881 }
882 return self->operator==(*obj);
883 }
884
885
debe38c9 886 //KeepGIL(__ne__);
1fce4e96
RD
887 DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
888 bool __ne__(PyObject* other) {
889 wxPoint2D temp, *obj = &temp;
890 if ( other == Py_None ) return true;
891 if ( ! wxPoint2D_helper(other, &obj)) {
892 PyErr_Clear();
893 return true;
894 }
895 return self->operator!=(*obj);
896 }
897 }
d14a1e28 898
1b8c7ba6
RD
899 %Rename(x, double, m_x);
900 %Rename(y, double, m_y);
d14a1e28
RD
901
902 %extend {
903 void Set( double x=0 , double y=0 ) {
904 self->m_x = x;
905 self->m_y = y;
906 }
dd9f7fea
RD
907
908 DocAStr(Get,
909 "Get() -> (x,y)",
d07d2bc9 910 "Return x and y properties as a tuple.", "");
dd9f7fea 911 PyObject* Get() {
debe38c9 912 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
913 PyObject* tup = PyTuple_New(2);
914 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
915 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
debe38c9 916 //wxPyEndBlockThreads(blocked);
d14a1e28
RD
917 return tup;
918 }
919 }
920
921 %pythoncode {
d07d2bc9 922 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
923 def __str__(self): return str(self.Get())
924 def __repr__(self): return 'wx.Point2D'+str(self.Get())
925 def __len__(self): return len(self.Get())
926 def __getitem__(self, index): return self.Get()[index]
d14a1e28 927 def __setitem__(self, index, val):
dd9f7fea
RD
928 if index == 0: self.x = val
929 elif index == 1: self.y = val
d14a1e28 930 else: raise IndexError
dd9f7fea 931 def __nonzero__(self): return self.Get() != (0.0, 0.0)
02376d73
RD
932 __safe_for_unpickling__ = True
933 def __reduce__(self): return (wx.Point2D, self.Get())
d14a1e28 934 }
7012bb9f
RD
935
936 %property(Floor, GetFloor, doc="See `GetFloor`");
937 %property(Rounded, GetRounded, doc="See `GetRounded`");
938 %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`");
939 %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`");
940
d14a1e28
RD
941};
942
943
debe38c9
RD
944//---------------------------------------------------------------------------
945%newgroup
946
947
948enum wxOutCode
949{
950 wxInside = 0x00 ,
951 wxOutLeft = 0x01 ,
952 wxOutRight = 0x02 ,
953 wxOutTop = 0x08 ,
954 wxOutBottom = 0x04
955};
956
957
958DocStr(wxRect2D,
959 "wx.Rect2D is a rectangle, with position and size, in a 2D coordinate system
960with floating point component values.", "");
961
962class wxRect2D
963{
964public:
965 wxRect2D(wxDouble x=0.0, wxDouble y=0.0, wxDouble w=0.0, wxDouble h=0.0);
966
967 ~wxRect2D();
968
969 wxPoint2D GetPosition();
970 wxSize GetSize();
971
972 // for the edge and corner accessors there are two setters conterparts,
973 // the Set.. functions keep the other corners at their position whenever
974 // sensible, the Move.. functions keep the size of the rect and move the
975 // other corners apropriately
976
977 wxDouble GetLeft() const;
978 void SetLeft( wxDouble n );
979 void MoveLeftTo( wxDouble n );
980 wxDouble GetTop() const;
981 void SetTop( wxDouble n );
982 void MoveTopTo( wxDouble n );
983 wxDouble GetBottom() const;
984 void SetBottom( wxDouble n );
985 void MoveBottomTo( wxDouble n );
986 wxDouble GetRight() const;
987 void SetRight( wxDouble n );
988 void MoveRightTo( wxDouble n );
989
990 wxPoint2D GetLeftTop() const;
991 void SetLeftTop( const wxPoint2D &pt );
992 void MoveLeftTopTo( const wxPoint2D &pt );
993 wxPoint2D GetLeftBottom() const;
994 void SetLeftBottom( const wxPoint2D &pt );
995 void MoveLeftBottomTo( const wxPoint2D &pt );
996 wxPoint2D GetRightTop() const;
997 void SetRightTop( const wxPoint2D &pt );
998 void MoveRightTopTo( const wxPoint2D &pt );
999 wxPoint2D GetRightBottom() const;
1000 void SetRightBottom( const wxPoint2D &pt );
1001 void MoveRightBottomTo( const wxPoint2D &pt );
1002 wxPoint2D GetCentre() const;
1003 void SetCentre( const wxPoint2D &pt );
1004 void MoveCentreTo( const wxPoint2D &pt );
1005 wxOutCode GetOutcode(const wxPoint2D &pt) const;
1006 bool Contains( const wxPoint2D &pt ) const;
1007 %Rename(ContainsRect, bool , Contains( const wxRect2D &rect ) const);
1008 bool IsEmpty() const;
1009 bool HaveEqualSize( const wxRect2D &rect ) const;
1010
1011 %nokwargs Inset;
1012 void Inset( wxDouble x , wxDouble y );
1013 void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom );
1014 void Offset( const wxPoint2D &pt );
1015
1016 void ConstrainTo( const wxRect2D &rect );
1017
1018 wxPoint2D Interpolate( wxInt32 widthfactor , wxInt32 heightfactor );
1019
1020 //static void Intersect( const wxRect2D &src1 , const wxRect2D &src2 , wxRect2D *dest );
1021
1022 void Intersect( const wxRect2D &otherRect );
1023 wxRect2D CreateIntersection( const wxRect2D &otherRect ) const;
1024 bool Intersects( const wxRect2D &rect ) const;
1025
1026 // static void Union( const wxRect2D &src1 , const wxRect2D &src2 , wxRect2D *dest );
1027
1028 void Union( const wxRect2D &otherRect );
1029 //void Union( const wxPoint2D &pt );
1030
1031 wxRect2D CreateUnion( const wxRect2D &otherRect ) const;
1032
1033 %nokwargs Scale;
1034 void Scale( wxDouble f );
1035 void Scale( int num , int denum );
1036
1037 //wxRect2D& operator = (const wxRect2D& rect);
1038 //bool operator == (const wxRect2D& rect) const;
1039 //bool operator != (const wxRect2D& rect) const;
1040
1041 %extend {
1042 //KeepGIL(__eq__);
1043 DocStr(__eq__, "Test for equality of wx.Rect2D objects.", "");
1044 bool __eq__(PyObject* other) {
1045 wxRect2D temp, *obj = &temp;
1046 if ( other == Py_None ) return false;
1047 if ( ! wxRect2D_helper(other, &obj) ) {
1048 PyErr_Clear();
1049 return false;
1050 }
1051 return self->operator==(*obj);
1052 }
1053
1054
1055 //KeepGIL(__ne__);
1056 DocStr(__ne__, "Test for inequality of wx.Rect2D objects.", "");
1057 bool __ne__(PyObject* other) {
1058 wxRect2D temp, *obj = &temp;
1059 if ( other == Py_None ) return true;
1060 if ( ! wxRect2D_helper(other, &obj)) {
1061 PyErr_Clear();
1062 return true;
1063 }
1064 return self->operator!=(*obj);
1065 }
1066 }
1067
1068
1069 %Rename(x, wxDouble , m_x);
1070 %Rename(y, wxDouble , m_y);
1071 %Rename(width, wxDouble , m_width);
1072 %Rename(height, wxDouble , m_height);
1073
1074 %extend {
1075 void Set( wxDouble x=0 , wxDouble y=0, wxDouble width=0, wxDouble height=0 ) {
1076 self->m_x = x;
1077 self->m_y = y;
1078 self->m_width = width;
1079 self->m_height = height;
1080 }
1081
1082 DocAStr(Get,
1083 "Get() -> (x,y, width, height)",
1084 "Return x, y, width and height y properties as a tuple.", "");
1085 PyObject* Get() {
1086 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
1087 PyObject* tup = PyTuple_New(4);
1088 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
1089 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
1090 PyTuple_SET_ITEM(tup, 2, PyFloat_FromDouble(self->m_width));
1091 PyTuple_SET_ITEM(tup, 3, PyFloat_FromDouble(self->m_height));
1092 //wxPyEndBlockThreads(blocked);
1093 return tup;
1094 }
1095 }
1096
1097 %pythoncode {
1098 def __str__(self): return str(self.Get())
1099 def __repr__(self): return 'wx.Rect2D'+str(self.Get())
1100 def __len__(self): return len(self.Get())
1101 def __getitem__(self, index): return self.Get()[index]
1102 def __setitem__(self, index, val):
1103 if index == 0: self.x = val
1104 elif index == 1: self.y = val
1105 elif index == 2: self.width = val
1106 elif index == 3: self.height = val
1107 else: raise IndexError
1108 def __nonzero__(self): return self.Get() != (0.0, 0.0, 0.0, 0.0)
1109 __safe_for_unpickling__ = True
1110 def __reduce__(self): return (wx.Rect2D, self.Get())
1111 }
1112
1113};
1114
363868e5
RD
1115//---------------------------------------------------------------------------
1116
1117class wxPosition
1118{
1119public:
1120 wxPosition(int row=0, int col=0);
1121 ~wxPosition();
1122
1123 int GetRow() const;
1124 int GetColumn() const;
1125 int GetCol() const;
1126 void SetRow(int row);
1127 void SetColumn(int column);
1128 void SetCol(int column);
1129
1130 %extend {
1131 DocStr(__eq__, "Test for equality of wx.Position objects.", "");
1132 bool __eq__(PyObject* other) {
1133 wxPosition temp, *obj = &temp;
1134 if ( other == Py_None ) return false;
1135 if ( ! wxPosition_helper(other, &obj) ) {
1136 PyErr_Clear();
1137 return false;
1138 }
1139 return self->operator==(*obj);
1140 }
1141
1142
1143 DocStr(__ne__, "Test for inequality of wx.Position objects.", "");
1144 bool __ne__(PyObject* other) {
1145 wxPosition temp, *obj = &temp;
1146 if ( other == Py_None ) return true;
1147 if ( ! wxPosition_helper(other, &obj)) {
1148 PyErr_Clear();
1149 return true;
1150 }
1151 return self->operator!=(*obj);
1152 }
1153 }
1154
1155 %nokwargs operator+;
1156 %nokwargs operator-;
1157 wxPosition operator+(const wxPosition& p) const;
1158 wxPosition operator-(const wxPosition& p) const;
1159 wxPosition operator+(const wxSize& s) const;
1160 wxPosition operator-(const wxSize& s) const;
1161
1162 %property(row, GetRow, SetRow);
1163 %property(col, GetCol, SetCol);
1164};
1165
1166
1167
d14a1e28
RD
1168//---------------------------------------------------------------------------
1169
1170%immutable;
1171const wxPoint wxDefaultPosition;
1172const wxSize wxDefaultSize;
1173%mutable;
1174
1175//---------------------------------------------------------------------------
debe38c9
RD
1176
1177// Turn GIL acquisition back on.
1178%threadWrapperOn