]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gdicmn.i
Tweaks to work around wxMac bugs
[wxWidgets.git] / wxPython / src / _gdicmn.i
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
20 enum wxBitmapType
21 {
22 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
23 wxBITMAP_TYPE_BMP,
24 wxBITMAP_TYPE_ICO,
25 wxBITMAP_TYPE_CUR,
26 wxBITMAP_TYPE_XBM,
27 wxBITMAP_TYPE_XBM_DATA,
28 wxBITMAP_TYPE_XPM,
29 wxBITMAP_TYPE_XPM_DATA,
30 wxBITMAP_TYPE_TIF,
31 wxBITMAP_TYPE_GIF,
32 wxBITMAP_TYPE_PNG,
33 wxBITMAP_TYPE_JPEG,
34 wxBITMAP_TYPE_PNM,
35 wxBITMAP_TYPE_PCX,
36 wxBITMAP_TYPE_PICT,
37 wxBITMAP_TYPE_ICON,
38 wxBITMAP_TYPE_ANI,
39 wxBITMAP_TYPE_IFF,
40 wxBITMAP_TYPE_MACCURSOR,
41
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,
55
56 wxBITMAP_TYPE_ANY = 50
57 };
58
59 // Standard cursors
60 enum wxStockCursor
61 {
62 wxCURSOR_NONE, // should be 0
63 wxCURSOR_ARROW,
64 wxCURSOR_RIGHT_ARROW,
65 wxCURSOR_BULLSEYE,
66 wxCURSOR_CHAR,
67 wxCURSOR_CROSS,
68 wxCURSOR_HAND,
69 wxCURSOR_IBEAM,
70 wxCURSOR_LEFT_BUTTON,
71 wxCURSOR_MAGNIFIER,
72 wxCURSOR_MIDDLE_BUTTON,
73 wxCURSOR_NO_ENTRY,
74 wxCURSOR_PAINT_BRUSH,
75 wxCURSOR_PENCIL,
76 wxCURSOR_POINT_LEFT,
77 wxCURSOR_POINT_RIGHT,
78 wxCURSOR_QUESTION_ARROW,
79 wxCURSOR_RIGHT_BUTTON,
80 wxCURSOR_SIZENESW,
81 wxCURSOR_SIZENS,
82 wxCURSOR_SIZENWSE,
83 wxCURSOR_SIZEWE,
84 wxCURSOR_SIZING,
85 wxCURSOR_SPRAYCAN,
86 wxCURSOR_WAIT,
87 wxCURSOR_WATCH,
88 wxCURSOR_BLANK,
89 wxCURSOR_DEFAULT, // standard X11 cursor
90 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
91
92 // #ifdef __X__
93 // // Not yet implemented for Windows
94 // wxCURSOR_CROSS_REVERSE,
95 // wxCURSOR_DOUBLE_ARROW,
96 // wxCURSOR_BASED_ARROW_UP,
97 // wxCURSOR_BASED_ARROW_DOWN,
98 // #endif // X11
99
100 wxCURSOR_ARROWWAIT,
101
102 wxCURSOR_MAX
103 };
104
105 %{
106 #ifndef __WXMAC__
107 #define wxCURSOR_COPY_ARROW wxCURSOR_ARROW
108 #endif
109 %}
110
111 //---------------------------------------------------------------------------
112 %newgroup
113
114 DocStr( wxSize,
115 "wx.Size is a useful data structure used to represent the size of something.
116 It simply contians integer width and height proprtites. In most places in
117 wxPython where a wx.Size is expected a (width,height) tuple can be used
118 instead.");
119
120 class wxSize
121 {
122 public:
123 %name(width) int x;
124 %name(height)int y;
125 %pythoncode { x = width; y = height }
126
127 DocCtorStr(
128 wxSize(int w=0, int h=0),
129 "Creates a size object.");
130
131 ~wxSize();
132
133 // None/NULL is now handled properly by the typemap, so these are not needed.
134 // %extend {
135 // bool __eq__(const wxSize* other) { return other ? (*self == *other) : False; }
136 // bool __ne__(const wxSize* other) { return other ? (*self != *other) : True; }
137 // }
138
139 DocDeclStr(
140 bool, operator==(const wxSize& sz),
141 "Test for equality of wx.Size objects.");
142
143 DocDeclStr(
144 bool, operator!=(const wxSize& sz),
145 "Test for inequality.");
146
147 DocDeclStr(
148 wxSize, operator+(const wxSize& sz),
149 "Add sz's proprties to this and return the result.");
150
151 DocDeclStr(
152 wxSize, operator-(const wxSize& sz),
153 "Subtract sz's properties from this and return the result.");
154
155 DocDeclStr(
156 void, IncTo(const wxSize& sz),
157 "Increments this object so that both of its dimensions are not less\n"
158 "than the corresponding dimensions of the size.");
159
160 DocDeclStr(
161 void, DecTo(const wxSize& sz),
162 "Decrements this object so that both of its dimensions are not greater\n"
163 "than the corresponding dimensions of the size.");
164
165 DocDeclStr(
166 void, Set(int w, int h),
167 "Set both width and height.");
168
169 void SetWidth(int w);
170 void SetHeight(int h);
171 int GetWidth() const;
172 int GetHeight() const;
173
174
175 DocDeclStr(
176 bool , IsFullySpecified() const,
177 "Returns True if both components of the size are non-default values.");
178
179
180 DocDeclStr(
181 void , SetDefaults(const wxSize& size),
182 "Combine this size with the other one replacing the default
183 components of this object (i.e. equal to -1) with those of the
184 other.");
185
186
187 //int GetX() const;
188 //int GetY() const;
189
190 %extend {
191 DocAStr(Get,
192 "Get() -> (width,height)",
193 "Returns the width and height properties as a tuple.");
194 PyObject* Get() {
195 bool blocked = wxPyBeginBlockThreads();
196 PyObject* tup = PyTuple_New(2);
197 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
198 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
199 wxPyEndBlockThreads(blocked);
200 return tup;
201 }
202 }
203 %pythoncode {
204 asTuple = Get
205 def __str__(self): return str(self.Get())
206 def __repr__(self): return 'wx.Size'+str(self.Get())
207 def __len__(self): return len(self.Get())
208 def __getitem__(self, index): return self.Get()[index]
209 def __setitem__(self, index, val):
210 if index == 0: self.width = val
211 elif index == 1: self.height = val
212 else: raise IndexError
213 def __nonzero__(self): return self.Get() != (0,0)
214 __safe_for_unpickling__ = True
215 def __reduce__(self): return (wx.Size, self.Get())
216 }
217
218 };
219
220 //---------------------------------------------------------------------------
221 %newgroup
222
223 DocStr( wxRealPoint,
224 "A data structure for representing a point or position with floating point x
225 and y properties. In wxPython most places that expect a wx.RealPoint can also
226 accept a (x,y) tuple.");
227 class wxRealPoint
228 {
229 public:
230 double x;
231 double y;
232
233 DocCtorStr(
234 wxRealPoint(double x=0.0, double y=0.0),
235 "Create a wx.RealPoint object");
236
237 ~wxRealPoint();
238
239 DocDeclStr(
240 bool, operator==(const wxRealPoint& pt),
241 "Test for equality of wx.RealPoint objects.");
242
243 DocDeclStr(
244 bool, operator!=(const wxRealPoint& pt),
245 "Test for inequality of wx.RealPoint objects.");
246
247
248 DocDeclStr(
249 wxRealPoint, operator+(const wxRealPoint& pt),
250 "Add pt's proprties to this and return the result.");
251
252 DocDeclStr(
253 wxRealPoint, operator-(const wxRealPoint& pt),
254 "Subtract pt's proprties from this and return the result");
255
256
257 %extend {
258 DocStr(Set, "Set both the x and y properties");
259 void Set(double x, double y) {
260 self->x = x;
261 self->y = y;
262 }
263
264 DocAStr(Get,
265 "Get() -> (x,y)",
266 "Return the x and y properties as a tuple. ");
267 PyObject* Get() {
268 bool blocked = wxPyBeginBlockThreads();
269 PyObject* tup = PyTuple_New(2);
270 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
271 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
272 wxPyEndBlockThreads(blocked);
273 return tup;
274 }
275 }
276
277 %pythoncode {
278 asTuple = Get
279 def __str__(self): return str(self.Get())
280 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
281 def __len__(self): return len(self.Get())
282 def __getitem__(self, index): return self.Get()[index]
283 def __setitem__(self, index, val):
284 if index == 0: self.x = val
285 elif index == 1: self.y = val
286 else: raise IndexError
287 def __nonzero__(self): return self.Get() != (0.0, 0.0)
288 __safe_for_unpickling__ = True
289 def __reduce__(self): return (wx.RealPoint, self.Get())
290 }
291 };
292
293
294 //---------------------------------------------------------------------------
295 %newgroup
296
297
298 DocStr(wxPoint,
299 "A data structure for representing a point or position with integer x and y
300 properties. Most places in wxPython that expect a wx.Point can also accept a
301 (x,y) tuple.");
302
303 class wxPoint
304 {
305 public:
306 int x, y;
307
308 DocCtorStr(
309 wxPoint(int x=0, int y=0),
310 "Create a wx.Point object");
311
312 ~wxPoint();
313
314
315 DocDeclStr(
316 bool, operator==(const wxPoint& pt),
317 "Test for equality of wx.Point objects.");
318
319 DocDeclStr(
320 bool, operator!=(const wxPoint& pt),
321 "Test for inequality of wx.Point objects.");
322
323
324
325 // %nokwargs operator+;
326 // %nokwargs operator-;
327 // %nokwargs operator+=;
328 // %nokwargs operator-=;
329
330 DocDeclStr(
331 wxPoint, operator+(const wxPoint& pt),
332 "Add pt's proprties to this and return the result.");
333
334
335 DocDeclStr(
336 wxPoint, operator-(const wxPoint& pt),
337 "Subtract pt's proprties from this and return the result");
338
339
340 DocDeclStr(
341 wxPoint&, operator+=(const wxPoint& pt),
342 "Add pt to this object.");
343
344 DocDeclStr(
345 wxPoint&, operator-=(const wxPoint& pt),
346 "Subtract pt from this object.");
347
348
349
350 // DocDeclStr(
351 // wxPoint, operator+(const wxSize& sz),
352 // "Add sz to this Point and return the result.");
353
354 // DocDeclStr(
355 // wxPoint, operator-(const wxSize& sz),
356 // "Subtract sz from this Point and return the result");
357
358
359 // DocDeclStr(
360 // wxPoint&, operator+=(const wxSize& sz),
361 // "Add sz to this object.");
362
363 // DocDeclStr(
364 // wxPoint&, operator-=(const wxSize& sz),
365 // "Subtract sz from this object.");
366
367
368
369
370 %extend {
371 DocStr(Set, "Set both the x and y properties");
372 void Set(long x, long y) {
373 self->x = x;
374 self->y = y;
375 }
376
377 DocAStr(Get,
378 "Get() -> (x,y)",
379 "Return the x and y properties as a tuple. ");
380 PyObject* Get() {
381 bool blocked = wxPyBeginBlockThreads();
382 PyObject* tup = PyTuple_New(2);
383 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
384 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
385 wxPyEndBlockThreads(blocked);
386 return tup;
387 }
388 }
389
390 %pythoncode {
391 asTuple = Get
392 def __str__(self): return str(self.Get())
393 def __repr__(self): return 'wx.Point'+str(self.Get())
394 def __len__(self): return len(self.Get())
395 def __getitem__(self, index): return self.Get()[index]
396 def __setitem__(self, index, val):
397 if index == 0: self.x = val
398 elif index == 1: self.y = val
399 else: raise IndexError
400 def __nonzero__(self): return self.Get() != (0,0)
401 __safe_for_unpickling__ = True
402 def __reduce__(self): return (wx.Point, self.Get())
403 }
404 };
405
406 //---------------------------------------------------------------------------
407 %newgroup
408
409
410 DocStr(wxRect,
411 "A class for representing and manipulating rectangles. It has x, y, width and
412 height properties. In wxPython most palces that expect a wx.Rect can also
413 accept a (x,y,width,height) tuple.");
414
415 class wxRect
416 {
417 public:
418 DocCtorStr(
419 wxRect(int x=0, int y=0, int width=0, int height=0),
420 "Create a new Rect object.");
421
422 DocCtorStrName(
423 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
424 "Create a new Rect object from Points representing two corners.",
425 RectPP);
426
427 DocCtorStrName(
428 wxRect(const wxPoint& pos, const wxSize& size),
429 "Create a new Rect from a position and size.",
430 RectPS);
431
432 ~wxRect();
433
434 int GetX() const;
435 void SetX(int x);
436
437 int GetY();
438 void SetY(int y);
439
440 int GetWidth() const;
441 void SetWidth(int w);
442
443 int GetHeight() const;
444 void SetHeight(int h);
445
446 wxPoint GetPosition() const;
447 void SetPosition( const wxPoint &p );
448
449 wxSize GetSize() const;
450 void SetSize( const wxSize &s );
451
452 wxPoint GetTopLeft() const;
453 void SetTopLeft(const wxPoint &p);
454 wxPoint GetBottomRight() const;
455 void SetBottomRight(const wxPoint &p);
456
457 // wxPoint GetLeftTop() const;
458 // void SetLeftTop(const wxPoint &p);
459 // wxPoint GetRightBottom() const;
460 // void SetRightBottom(const wxPoint &p);
461
462 int GetLeft() const;
463 int GetTop() const;
464 int GetBottom() const;
465 int GetRight() const;
466
467 void SetLeft(int left);
468 void SetRight(int right);
469 void SetTop(int top);
470 void SetBottom(int bottom);
471
472 %pythoncode {
473 position = property(GetPosition, SetPosition)
474 size = property(GetSize, SetSize)
475 left = property(GetLeft, SetLeft)
476 right = property(GetRight, SetRight)
477 top = property(GetTop, SetTop)
478 bottom = property(GetBottom, SetBottom)
479 }
480
481 DocDeclStr(
482 wxRect&, Inflate(wxCoord dx, wxCoord dy),
483 "Increase the rectangle size by dx in x direction and dy in y direction. Both\n"
484 "(or one of) parameters may be negative to decrease the rectangle size.");
485
486 DocDeclStr(
487 wxRect&, Deflate(wxCoord dx, wxCoord dy),
488 "Decrease the rectangle size by dx in x direction and dy in y direction. Both\n"
489 "(or one of) parameters may be negative to increase the rectngle size. This\n"
490 "method is the opposite of Inflate.");
491
492 DocDeclStrName(
493 void, Offset(wxCoord dx, wxCoord dy),
494 "Moves the rectangle by the specified offset. If dx is positive, the rectangle\n"
495 "is moved to the right, if dy is positive, it is moved to the bottom, otherwise\n"
496 "it is moved to the left or top respectively.",
497 OffsetXY);
498
499 DocDeclStr(
500 void, Offset(const wxPoint& pt),
501 "Same as OffsetXY but uses dx,dy from Point");
502
503 DocDeclStr(
504 wxRect&, Intersect(const wxRect& rect),
505 "Return the intersectsion of this rectangle and rect.");
506
507 DocDeclStr(
508 wxRect, operator+(const wxRect& rect) const,
509 "Add the properties of rect to this rectangle and return the result.");
510
511 DocDeclStr(
512 wxRect&, operator+=(const wxRect& rect),
513 "Add the properties of rect to this rectangle, updating this rectangle.");
514
515 DocDeclStr(
516 bool, operator==(const wxRect& rect) const,
517 "Test for equality.");
518
519 DocDeclStr(
520 bool, operator!=(const wxRect& rect) const,
521 "Test for inequality.");
522
523
524 DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.");
525 %name(InsideXY)bool Inside(int x, int y) const;
526 bool Inside(const wxPoint& pt) const;
527
528 DocDeclStr(
529 bool, Intersects(const wxRect& rect) const,
530 "Returns True if the rectangles have a non empty intersection.");
531
532
533 int x, y, width, height;
534
535
536 %extend {
537 DocStr(Set, "Set all rectangle properties.");
538 void Set(int x=0, int y=0, int width=0, int height=0) {
539 self->x = x;
540 self->y = y;
541 self->width = width;
542 self->height = height;
543 }
544
545 DocAStr(Get,
546 "Get() -> (x,y,width,height)",
547 "Return the rectangle properties as a tuple.");
548 PyObject* Get() {
549 bool blocked = wxPyBeginBlockThreads();
550 PyObject* tup = PyTuple_New(4);
551 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
552 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
553 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
554 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
555 wxPyEndBlockThreads(blocked);
556 return tup;
557 }
558 }
559
560 %pythoncode {
561 asTuple = Get
562 def __str__(self): return str(self.Get())
563 def __repr__(self): return 'wx.Rect'+str(self.Get())
564 def __len__(self): return len(self.Get())
565 def __getitem__(self, index): return self.Get()[index]
566 def __setitem__(self, index, val):
567 if index == 0: self.x = val
568 elif index == 1: self.y = val
569 elif index == 2: self.width = val
570 elif index == 3: self.height = val
571 else: raise IndexError
572 def __nonzero__(self): return self.Get() != (0,0,0,0)
573 __safe_for_unpickling__ = True
574 def __reduce__(self): return (wx.Rect, self.Get())
575 }
576 };
577
578
579 DocAStr(wxIntersectRect,
580 "IntersectRect(Rect r1, Rect r2) -> Rect",
581 "Calculate and return the intersection of r1 and r2.");
582 %inline %{
583 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
584 wxRegion reg1(*r1);
585 wxRegion reg2(*r2);
586 wxRect dest(0,0,0,0);
587 PyObject* obj;
588
589 reg1.Intersect(reg2);
590 dest = reg1.GetBox();
591
592 if (dest != wxRect(0,0,0,0)) {
593 bool blocked = wxPyBeginBlockThreads();
594 wxRect* newRect = new wxRect(dest);
595 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), True);
596 wxPyEndBlockThreads(blocked);
597 return obj;
598 }
599 Py_INCREF(Py_None);
600 return Py_None;
601 }
602 %}
603
604 //---------------------------------------------------------------------------
605 %newgroup
606
607
608 DocStr(wxPoint2D,
609 "wx.Point2Ds represent a point or a vector in a 2d coordinate system with floating point values.");
610
611 class wxPoint2D
612 {
613 public:
614 DocStr(wxPoint2D, "Create a w.Point2D object.");
615 wxPoint2D( double x=0.0 , double y=0.0 );
616 %name(Point2DCopy) wxPoint2D( const wxPoint2D &pt );
617 %name(Point2DFromPoint) wxPoint2D( const wxPoint &pt );
618
619 DocDeclAStr(
620 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
621 "GetFloor() -> (x,y)",
622 "Convert to integer");
623
624 DocDeclAStr(
625 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
626 "GetRounded() -> (x,y)",
627 "Convert to integer");
628
629 double GetVectorLength() const;
630 double GetVectorAngle() const ;
631 void SetVectorLength( double length );
632 void SetVectorAngle( double degrees );
633
634 // LinkError: void SetPolarCoordinates( double angle , double length );
635 // LinkError: void Normalize();
636 %pythoncode {
637 def SetPolarCoordinates(self, angle, length):
638 self.SetVectorLength(length)
639 self.SetVectorAngle(angle)
640 def Normalize(self):
641 self.SetVectorLength(1.0)
642 }
643
644 double GetDistance( const wxPoint2D &pt ) const;
645 double GetDistanceSquare( const wxPoint2D &pt ) const;
646 double GetDotProduct( const wxPoint2D &vec ) const;
647 double GetCrossProduct( const wxPoint2D &vec ) const;
648
649 DocDeclStr(
650 wxPoint2D, operator-(),
651 "the reflection of this point");
652
653 wxPoint2D& operator+=(const wxPoint2D& pt);
654 wxPoint2D& operator-=(const wxPoint2D& pt);
655
656 wxPoint2D& operator*=(const wxPoint2D& pt);
657 wxPoint2D& operator/=(const wxPoint2D& pt);
658
659 DocDeclStr(
660 bool, operator==(const wxPoint2D& pt) const,
661 "Test for equality");
662
663 DocDeclStr(
664 bool, operator!=(const wxPoint2D& pt) const,
665 "Test for inequality");
666
667 %name(x)double m_x;
668 %name(y)double m_y;
669
670 %extend {
671 void Set( double x=0 , double y=0 ) {
672 self->m_x = x;
673 self->m_y = y;
674 }
675
676 DocAStr(Get,
677 "Get() -> (x,y)",
678 "Return x and y properties as a tuple.");
679 PyObject* Get() {
680 bool blocked = wxPyBeginBlockThreads();
681 PyObject* tup = PyTuple_New(2);
682 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
683 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
684 wxPyEndBlockThreads(blocked);
685 return tup;
686 }
687 }
688
689 %pythoncode {
690 asTuple = Get
691 def __str__(self): return str(self.Get())
692 def __repr__(self): return 'wx.Point2D'+str(self.Get())
693 def __len__(self): return len(self.Get())
694 def __getitem__(self, index): return self.Get()[index]
695 def __setitem__(self, index, val):
696 if index == 0: self.x = val
697 elif index == 1: self.y = val
698 else: raise IndexError
699 def __nonzero__(self): return self.Get() != (0.0, 0.0)
700 __safe_for_unpickling__ = True
701 def __reduce__(self): return (wx.Point2D, self.Get())
702 }
703 };
704
705
706 //---------------------------------------------------------------------------
707
708 %immutable;
709 const wxPoint wxDefaultPosition;
710 const wxSize wxDefaultSize;
711 %mutable;
712
713 //---------------------------------------------------------------------------