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