]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gdicmn.i
No need to explicitly delete the tbicon
[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 // %extend {
134 // bool __eq__(const wxSize* other) { return other ? (*self == *other) : False; }
135 // bool __ne__(const wxSize* other) { return other ? (*self != *other) : True; }
136 // }
137
138 DocDeclStr(
139 bool, operator==(const wxSize& sz),
140 "Test for equality of wx.Size objects.");
141
142 DocDeclStr(
143 bool, operator!=(const wxSize& sz),
144 "Test for inequality.");
145
146 DocDeclStr(
147 wxSize, operator+(const wxSize& sz),
148 "Add sz's proprties to this and return the result.");
149
150 DocDeclStr(
151 wxSize, operator-(const wxSize& sz),
152 "Subtract sz's properties from this and return the result.");
153
154 DocDeclStr(
155 void, IncTo(const wxSize& sz),
156 "Increments this object so that both of its dimensions are not less\n"
157 "than the corresponding dimensions of the size.");
158
159 DocDeclStr(
160 void, DecTo(const wxSize& sz),
161 "Decrements this object so that both of its dimensions are not greater\n"
162 "than the corresponding dimensions of the size.");
163
164 DocDeclStr(
165 void, Set(int w, int h),
166 "Set both width and height.");
167
168 void SetWidth(int w);
169 void SetHeight(int h);
170 int GetWidth() const;
171 int GetHeight() const;
172
173 //int GetX() const;
174 //int GetY() const;
175
176 %extend {
177 DocAStr(Get,
178 "Get() -> (width,height)",
179 "Returns the width and height properties as a tuple.");
180 PyObject* Get() {
181 bool blocked = wxPyBeginBlockThreads();
182 PyObject* tup = PyTuple_New(2);
183 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
184 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
185 wxPyEndBlockThreads(blocked);
186 return tup;
187 }
188 }
189 %pythoncode {
190 asTuple = Get
191 def __str__(self): return str(self.Get())
192 def __repr__(self): return 'wx.Size'+str(self.Get())
193 def __len__(self): return len(self.Get())
194 def __getitem__(self, index): return self.Get()[index]
195 def __setitem__(self, index, val):
196 if index == 0: self.width = val
197 elif index == 1: self.height = val
198 else: raise IndexError
199 def __nonzero__(self): return self.Get() != (0,0)
200 __safe_for_unpickling__ = True
201 def __reduce__(self): return (wx.Size, self.Get())
202 }
203
204 };
205
206 //---------------------------------------------------------------------------
207 %newgroup
208
209 DocStr( wxRealPoint,
210 "A data structure for representing a point or position with floating point x
211 and y properties. In wxPython most places that expect a wx.RealPoint can also
212 accept a (x,y) tuple.");
213 class wxRealPoint
214 {
215 public:
216 double x;
217 double y;
218
219 DocCtorStr(
220 wxRealPoint(double x=0.0, double y=0.0),
221 "Create a wx.RealPoint object");
222
223 ~wxRealPoint();
224
225 DocDeclStr(
226 bool, operator==(const wxRealPoint& pt),
227 "Test for equality of wx.RealPoint objects.");
228
229 DocDeclStr(
230 bool, operator!=(const wxRealPoint& pt),
231 "Test for inequality of wx.RealPoint objects.");
232
233
234 DocDeclStr(
235 wxRealPoint, operator+(const wxRealPoint& pt),
236 "Add pt's proprties to this and return the result.");
237
238 DocDeclStr(
239 wxRealPoint, operator-(const wxRealPoint& pt),
240 "Subtract pt's proprties from this and return the result");
241
242
243 %extend {
244 DocStr(Set, "Set both the x and y properties");
245 void Set(double x, double y) {
246 self->x = x;
247 self->y = y;
248 }
249
250 DocAStr(Get,
251 "Get() -> (x,y)",
252 "Return the x and y properties as a tuple. ");
253 PyObject* Get() {
254 bool blocked = wxPyBeginBlockThreads();
255 PyObject* tup = PyTuple_New(2);
256 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
257 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
258 wxPyEndBlockThreads(blocked);
259 return tup;
260 }
261 }
262
263 %pythoncode {
264 asTuple = Get
265 def __str__(self): return str(self.Get())
266 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
267 def __len__(self): return len(self.Get())
268 def __getitem__(self, index): return self.Get()[index]
269 def __setitem__(self, index, val):
270 if index == 0: self.x = val
271 elif index == 1: self.y = val
272 else: raise IndexError
273 def __nonzero__(self): return self.Get() != (0.0, 0.0)
274 __safe_for_unpickling__ = True
275 def __reduce__(self): return (wx.RealPoint, self.Get())
276 }
277 };
278
279
280 //---------------------------------------------------------------------------
281 %newgroup
282
283
284 DocStr(wxPoint,
285 "A data structure for representing a point or position with integer x and y
286 properties. Most places in wxPython that expect a wx.Point can also accept a
287 (x,y) tuple.");
288
289 class wxPoint
290 {
291 public:
292 int x, y;
293
294 DocCtorStr(
295 wxPoint(int x=0, int y=0),
296 "Create a wx.Point object");
297
298 ~wxPoint();
299
300
301 DocDeclStr(
302 bool, operator==(const wxPoint& pt),
303 "Test for equality of wx.Point objects.");
304
305 DocDeclStr(
306 bool, operator!=(const wxPoint& pt),
307 "Test for inequality of wx.Point objects.");
308
309
310
311 // %nokwargs operator+;
312 // %nokwargs operator-;
313 // %nokwargs operator+=;
314 // %nokwargs operator-=;
315
316 DocDeclStr(
317 wxPoint, operator+(const wxPoint& pt),
318 "Add pt's proprties to this and return the result.");
319
320
321 DocDeclStr(
322 wxPoint, operator-(const wxPoint& pt),
323 "Subtract pt's proprties from this and return the result");
324
325
326 DocDeclStr(
327 wxPoint&, operator+=(const wxPoint& pt),
328 "Add pt to this object.");
329
330 DocDeclStr(
331 wxPoint&, operator-=(const wxPoint& pt),
332 "Subtract pt from this object.");
333
334
335
336 // DocDeclStr(
337 // wxPoint, operator+(const wxSize& sz),
338 // "Add sz to this Point and return the result.");
339
340 // DocDeclStr(
341 // wxPoint, operator-(const wxSize& sz),
342 // "Subtract sz from this Point and return the result");
343
344
345 // DocDeclStr(
346 // wxPoint&, operator+=(const wxSize& sz),
347 // "Add sz to this object.");
348
349 // DocDeclStr(
350 // wxPoint&, operator-=(const wxSize& sz),
351 // "Subtract sz from this object.");
352
353
354
355
356 %extend {
357 DocStr(Set, "Set both the x and y properties");
358 void Set(long x, long y) {
359 self->x = x;
360 self->y = y;
361 }
362
363 DocAStr(Get,
364 "Get() -> (x,y)",
365 "Return the x and y properties as a tuple. ");
366 PyObject* Get() {
367 bool blocked = wxPyBeginBlockThreads();
368 PyObject* tup = PyTuple_New(2);
369 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
370 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
371 wxPyEndBlockThreads(blocked);
372 return tup;
373 }
374 }
375
376 %pythoncode {
377 asTuple = Get
378 def __str__(self): return str(self.Get())
379 def __repr__(self): return 'wx.Point'+str(self.Get())
380 def __len__(self): return len(self.Get())
381 def __getitem__(self, index): return self.Get()[index]
382 def __setitem__(self, index, val):
383 if index == 0: self.x = val
384 elif index == 1: self.y = val
385 else: raise IndexError
386 def __nonzero__(self): return self.Get() != (0,0)
387 __safe_for_unpickling__ = True
388 def __reduce__(self): return (wx.Point, self.Get())
389 }
390 };
391
392 //---------------------------------------------------------------------------
393 %newgroup
394
395
396 DocStr(wxRect,
397 "A class for representing and manipulating rectangles. It has x, y, width and
398 height properties. In wxPython most palces that expect a wx.Rect can also
399 accept a (x,y,width,height) tuple.");
400
401 class wxRect
402 {
403 public:
404 DocCtorStr(
405 wxRect(int x=0, int y=0, int width=0, int height=0),
406 "Create a new Rect object.");
407
408 DocCtorStrName(
409 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
410 "Create a new Rect object from Points representing two corners.",
411 RectPP);
412
413 DocCtorStrName(
414 wxRect(const wxPoint& pos, const wxSize& size),
415 "Create a new Rect from a position and size.",
416 RectPS);
417
418 ~wxRect();
419
420 int GetX() const;
421 void SetX(int x);
422
423 int GetY();
424 void SetY(int y);
425
426 int GetWidth() const;
427 void SetWidth(int w);
428
429 int GetHeight() const;
430 void SetHeight(int h);
431
432 wxPoint GetPosition() const;
433 void SetPosition( const wxPoint &p );
434
435 wxSize GetSize() const;
436 void SetSize( const wxSize &s );
437
438 wxPoint GetTopLeft() const;
439 void SetTopLeft(const wxPoint &p);
440 wxPoint GetBottomRight() const;
441 void SetBottomRight(const wxPoint &p);
442
443 // wxPoint GetLeftTop() const;
444 // void SetLeftTop(const wxPoint &p);
445 // wxPoint GetRightBottom() const;
446 // void SetRightBottom(const wxPoint &p);
447
448 int GetLeft() const;
449 int GetTop() const;
450 int GetBottom() const;
451 int GetRight() const;
452
453 void SetLeft(int left);
454 void SetRight(int right);
455 void SetTop(int top);
456 void SetBottom(int bottom);
457
458 %pythoncode {
459 position = property(GetPosition, SetPosition)
460 size = property(GetSize, SetSize)
461 left = property(GetLeft, SetLeft)
462 right = property(GetRight, SetRight)
463 top = property(GetTop, SetTop)
464 bottom = property(GetBottom, SetBottom)
465 }
466
467 DocDeclStr(
468 wxRect&, Inflate(wxCoord dx, wxCoord dy),
469 "Increase the rectangle size by dx in x direction and dy in y direction. Both\n"
470 "(or one of) parameters may be negative to decrease the rectangle size.");
471
472 DocDeclStr(
473 wxRect&, Deflate(wxCoord dx, wxCoord dy),
474 "Decrease the rectangle size by dx in x direction and dy in y direction. Both\n"
475 "(or one of) parameters may be negative to increase the rectngle size. This\n"
476 "method is the opposite of Inflate.");
477
478 DocDeclStrName(
479 void, Offset(wxCoord dx, wxCoord dy),
480 "Moves the rectangle by the specified offset. If dx is positive, the rectangle\n"
481 "is moved to the right, if dy is positive, it is moved to the bottom, otherwise\n"
482 "it is moved to the left or top respectively.",
483 OffsetXY);
484
485 DocDeclStr(
486 void, Offset(const wxPoint& pt),
487 "Same as OffsetXY but uses dx,dy from Point");
488
489 DocDeclStr(
490 wxRect&, Intersect(const wxRect& rect),
491 "Return the intersectsion of this rectangle and rect.");
492
493 DocDeclStr(
494 wxRect, operator+(const wxRect& rect) const,
495 "Add the properties of rect to this rectangle and return the result.");
496
497 DocDeclStr(
498 wxRect&, operator+=(const wxRect& rect),
499 "Add the properties of rect to this rectangle, updating this rectangle.");
500
501 DocDeclStr(
502 bool, operator==(const wxRect& rect) const,
503 "Test for equality.");
504
505 DocDeclStr(
506 bool, operator!=(const wxRect& rect) const,
507 "Test for inequality.");
508
509
510 DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.");
511 %name(InsideXY)bool Inside(int x, int y) const;
512 bool Inside(const wxPoint& pt) const;
513
514 DocDeclStr(
515 bool, Intersects(const wxRect& rect) const,
516 "Returns True if the rectangles have a non empty intersection.");
517
518
519 int x, y, width, height;
520
521
522 %extend {
523 DocStr(Set, "Set all rectangle properties.");
524 void Set(int x=0, int y=0, int width=0, int height=0) {
525 self->x = x;
526 self->y = y;
527 self->width = width;
528 self->height = height;
529 }
530
531 DocAStr(Get,
532 "Get() -> (x,y,width,height)",
533 "Return the rectangle properties as a tuple.");
534 PyObject* Get() {
535 bool blocked = wxPyBeginBlockThreads();
536 PyObject* tup = PyTuple_New(4);
537 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
538 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
539 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
540 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
541 wxPyEndBlockThreads(blocked);
542 return tup;
543 }
544 }
545
546 %pythoncode {
547 asTuple = Get
548 def __str__(self): return str(self.Get())
549 def __repr__(self): return 'wx.Rect'+str(self.Get())
550 def __len__(self): return len(self.Get())
551 def __getitem__(self, index): return self.Get()[index]
552 def __setitem__(self, index, val):
553 if index == 0: self.x = val
554 elif index == 1: self.y = val
555 elif index == 2: self.width = val
556 elif index == 3: self.height = val
557 else: raise IndexError
558 def __nonzero__(self): return self.Get() != (0,0,0,0)
559 __safe_for_unpickling__ = True
560 def __reduce__(self): return (wx.Rect, self.Get())
561 }
562 };
563
564
565 DocAStr(wxIntersectRect,
566 "IntersectRect(Rect r1, Rect r2) -> Rect",
567 "Calculate and return the intersection of r1 and r2.");
568 %inline %{
569 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
570 wxRegion reg1(*r1);
571 wxRegion reg2(*r2);
572 wxRect dest(0,0,0,0);
573 PyObject* obj;
574
575 reg1.Intersect(reg2);
576 dest = reg1.GetBox();
577
578 if (dest != wxRect(0,0,0,0)) {
579 bool blocked = wxPyBeginBlockThreads();
580 wxRect* newRect = new wxRect(dest);
581 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), True);
582 wxPyEndBlockThreads(blocked);
583 return obj;
584 }
585 Py_INCREF(Py_None);
586 return Py_None;
587 }
588 %}
589
590 //---------------------------------------------------------------------------
591 %newgroup
592
593
594 DocStr(wxPoint2D,
595 "wx.Point2Ds represent a point or a vector in a 2d coordinate system with floating point values.");
596
597 class wxPoint2D
598 {
599 public:
600 DocStr(wxPoint2D, "Create a w.Point2D object.");
601 wxPoint2D( double x=0.0 , double y=0.0 );
602 %name(Point2DCopy) wxPoint2D( const wxPoint2D &pt );
603 %name(Point2DFromPoint) wxPoint2D( const wxPoint &pt );
604
605 DocDeclAStr(
606 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
607 "GetFloor() -> (x,y)",
608 "Convert to integer");
609
610 DocDeclAStr(
611 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
612 "GetRounded() -> (x,y)",
613 "Convert to integer");
614
615 double GetVectorLength() const;
616 double GetVectorAngle() const ;
617 void SetVectorLength( double length );
618 void SetVectorAngle( double degrees );
619
620 // LinkError: void SetPolarCoordinates( double angle , double length );
621 // LinkError: void Normalize();
622 %pythoncode {
623 def SetPolarCoordinates(self, angle, length):
624 self.SetVectorLength(length)
625 self.SetVectorAngle(angle)
626 def Normalize(self):
627 self.SetVectorLength(1.0)
628 }
629
630 double GetDistance( const wxPoint2D &pt ) const;
631 double GetDistanceSquare( const wxPoint2D &pt ) const;
632 double GetDotProduct( const wxPoint2D &vec ) const;
633 double GetCrossProduct( const wxPoint2D &vec ) const;
634
635 DocDeclStr(
636 wxPoint2D, operator-(),
637 "the reflection of this point");
638
639 wxPoint2D& operator+=(const wxPoint2D& pt);
640 wxPoint2D& operator-=(const wxPoint2D& pt);
641
642 wxPoint2D& operator*=(const wxPoint2D& pt);
643 wxPoint2D& operator/=(const wxPoint2D& pt);
644
645 DocDeclStr(
646 bool, operator==(const wxPoint2D& pt) const,
647 "Test for equality");
648
649 DocDeclStr(
650 bool, operator!=(const wxPoint2D& pt) const,
651 "Test for inequality");
652
653 %name(x)double m_x;
654 %name(y)double m_y;
655
656 %extend {
657 void Set( double x=0 , double y=0 ) {
658 self->m_x = x;
659 self->m_y = y;
660 }
661
662 DocAStr(Get,
663 "Get() -> (x,y)",
664 "Return x and y properties as a tuple.");
665 PyObject* Get() {
666 bool blocked = wxPyBeginBlockThreads();
667 PyObject* tup = PyTuple_New(2);
668 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
669 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
670 wxPyEndBlockThreads(blocked);
671 return tup;
672 }
673 }
674
675 %pythoncode {
676 asTuple = Get
677 def __str__(self): return str(self.Get())
678 def __repr__(self): return 'wx.Point2D'+str(self.Get())
679 def __len__(self): return len(self.Get())
680 def __getitem__(self, index): return self.Get()[index]
681 def __setitem__(self, index, val):
682 if index == 0: self.x = val
683 elif index == 1: self.y = val
684 else: raise IndexError
685 def __nonzero__(self): return self.Get() != (0.0, 0.0)
686 __safe_for_unpickling__ = True
687 def __reduce__(self): return (wx.Point2D, self.Get())
688 }
689 };
690
691
692 //---------------------------------------------------------------------------
693
694 %immutable;
695 const wxPoint wxDefaultPosition;
696 const wxSize wxDefaultSize;
697 %mutable;
698
699 //---------------------------------------------------------------------------