]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_dc.i
Need to navigate to "about:blank" in order for the internal docuemnt
[wxWidgets.git] / wxPython / src / _dc.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _dc.i
3 // Purpose: SWIG interface defs for wxDC and releated classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7-July-1997
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 //---------------------------------------------------------------------------
18
19 %{
20 #include "wx/wxPython/pydrawxxx.h"
21 %}
22
23 // TODO: 1. wrappers for wxDrawObject and wxDC::DrawObject
24
25
26 //---------------------------------------------------------------------------
27
28 %typemap(in) (int points, wxPoint* points_array ) {
29 $2 = wxPoint_LIST_helper($input, &$1);
30 if ($2 == NULL) SWIG_fail;
31 }
32 %typemap(freearg) (int points, wxPoint* points_array ) {
33 if ($2) delete [] $2;
34 }
35
36
37 //---------------------------------------------------------------------------
38 %newgroup;
39
40
41 // wxDC is the device context - object on which any drawing is done
42 class wxDC : public wxObject {
43 public:
44 // wxDC(); **** abstract base class, can't instantiate.
45 ~wxDC();
46
47
48 virtual void BeginDrawing();
49 virtual void EndDrawing();
50
51
52 // virtual void DrawObject(wxDrawObject* drawobject);
53
54
55
56 #if defined(wxUSE_DC_OLD_METHODS)
57
58 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
59 //bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const;
60 %extend {
61 wxColour GetPixel(wxCoord x, wxCoord y) {
62 wxColour col;
63 self->GetPixel(x, y, &col);
64 return col;
65 }
66 }
67 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
68 void CrossHair(wxCoord x, wxCoord y);
69 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
70 void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
71 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea);
72 void DrawPoint(wxCoord x, wxCoord y);
73 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
74 %name(DrawRectangleRect)void DrawRectangle(const wxRect& rect);
75 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
76 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
77 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
78 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
79 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = False);
80 void DrawText(const wxString& text, wxCoord x, wxCoord y);
81 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
82 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
83 wxDC *source, wxCoord xsrc, wxCoord ysrc,
84 int rop = wxCOPY, bool useMask = False,
85 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
86
87
88
89 #else // The new way
90
91 %name(FloodFillXY) bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
92 bool FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE);
93
94 //%name(GetPixelXY) bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const;
95 //bool GetPixel(const wxPoint& pt, wxColour *col) const;
96 %extend {
97 wxColour GetPixelXY(wxCoord x, wxCoord y) {
98 wxColour col;
99 self->GetPixel(x, y, &col);
100 return col;
101 }
102 wxColour GetPixel(const wxPoint& pt) {
103 wxColour col;
104 self->GetPixel(pt, &col);
105 return col;
106 }
107 }
108 %name(DrawLineXY) void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
109 void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
110
111 %name(CrossHairXY) void CrossHair(wxCoord x, wxCoord y);
112 void CrossHair(const wxPoint& pt);
113
114 %name(DrawArcXY) void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
115 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre);
116
117 %name(DrawCheckMarkXY) void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
118 void DrawCheckMark(const wxRect& rect);
119
120 %name(DrawEllipticArcXY) void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea);
121 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double sa, double ea);
122
123 %name(DrawPointXY) void DrawPoint(wxCoord x, wxCoord y);
124 void DrawPoint(const wxPoint& pt);
125
126 %name(DrawRectangleXY) void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
127 void DrawRectangle(const wxPoint& pt, const wxSize& sz);
128 %name(DrawRectangleRect) void DrawRectangle(const wxRect& rect);
129
130 %name(DrawRoundedRectangleXY) void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
131 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius);
132 %name(DrawRoundedRectangleRect) void DrawRoundedRectangle(const wxRect& r, double radius);
133
134 %name(DrawCircleXY) void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
135 void DrawCircle(const wxPoint& pt, wxCoord radius);
136
137 %name(DrawEllipseXY) void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
138 void DrawEllipse(const wxPoint& pt, const wxSize& sz);
139 %name(DrawEllipseRect) void DrawEllipse(const wxRect& rect);
140
141 %name(DrawIconXY) void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
142 void DrawIcon(const wxIcon& icon, const wxPoint& pt);
143
144 %name(DrawBitmapXY) void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = False);
145 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = False);
146
147 %name(DrawTextXY) void DrawText(const wxString& text, wxCoord x, wxCoord y);
148 void DrawText(const wxString& text, const wxPoint& pt);
149
150 %name(DrawRotatedTextXY) void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
151 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle);
152
153
154 %name(BlitXY) bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
155 wxDC *source, wxCoord xsrc, wxCoord ysrc,
156 int rop = wxCOPY, bool useMask = False,
157 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
158 bool Blit(const wxPoint& destPt, const wxSize& sz,
159 wxDC *source, const wxPoint& srcPt,
160 int rop = wxCOPY, bool useMask = False,
161 const wxPoint& srcPtMask = wxDefaultPosition);
162
163 #endif
164
165 void DrawLines(int points, wxPoint* points_array, wxCoord xoffset = 0, wxCoord yoffset = 0);
166
167 void DrawPolygon(int points, wxPoint* points_array,
168 wxCoord xoffset = 0, wxCoord yoffset = 0,
169 int fillStyle = wxODDEVEN_RULE);
170
171 // TODO: Figure out a good typemap for this...
172 // Convert the first 3 args from a sequence of sequences?
173 // void DrawPolyPolygon(int n, int count[], wxPoint points[],
174 // wxCoord xoffset = 0, wxCoord yoffset = 0,
175 // int fillStyle = wxODDEVEN_RULE);
176
177
178 // this version puts both optional bitmap and the text into the given
179 // rectangle and aligns is as specified by alignment parameter; it also
180 // will emphasize the character with the given index if it is != -1 and
181 // return the bounding rectangle if required
182 void DrawLabel(const wxString& text, const wxRect& rect,
183 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
184 int indexAccel = -1);
185 %extend {
186 wxRect DrawImageLabel(const wxString& text,
187 const wxBitmap& image,
188 const wxRect& rect,
189 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
190 int indexAccel = -1) {
191 wxRect rv;
192 self->DrawLabel(text, image, rect, alignment, indexAccel, &rv);
193 return rv;
194 }
195 }
196
197
198
199 void DrawSpline(int points, wxPoint* points_array);
200
201
202
203 // global DC operations
204 // --------------------
205
206 virtual void Clear();
207
208 virtual bool StartDoc(const wxString& message);
209 virtual void EndDoc();
210
211 virtual void StartPage();
212 virtual void EndPage();
213
214
215 // set objects to use for drawing
216 // ------------------------------
217
218 virtual void SetFont(const wxFont& font);
219 virtual void SetPen(const wxPen& pen);
220 virtual void SetBrush(const wxBrush& brush);
221 virtual void SetBackground(const wxBrush& brush);
222 virtual void SetBackgroundMode(int mode);
223 virtual void SetPalette(const wxPalette& palette);
224
225
226 // clipping region
227 // ---------------
228
229 %name(SetClippingRegionXY)void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
230 void SetClippingRegion(const wxPoint& pt, const wxSize& sz);
231 %name(SetClippingRect) void SetClippingRegion(const wxRect& rect);
232 %name(SetClippingRegionAsRegion) void SetClippingRegion(const wxRegion& region);
233
234 virtual void DestroyClippingRegion();
235
236 DocDeclA(
237 void, GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT) const,
238 "GetClippingBox() -> (x, y, width, height)");
239
240 %extend {
241 wxRect GetClippingRect() {
242 wxRect rect;
243 self->GetClippingBox(rect);
244 return rect;
245 }
246 }
247
248
249
250 // text extent
251 // -----------
252
253 virtual wxCoord GetCharHeight() const;
254 virtual wxCoord GetCharWidth() const;
255
256
257 DocDeclAStr(
258 void, GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT),
259 "GetTextExtent(wxString string) -> (width, height)",
260 "Get the width and height of the text using the current font.\n"
261 "Only works for single line strings.");
262 DocDeclAStrName(
263 void, GetTextExtent(const wxString& string,
264 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT,
265 wxFont* font = NULL),
266 "GetFullTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)",
267 "Get the width, height, decent and leading of the text using the current or specified font.\n"
268 "Only works for single line strings.",
269 GetFullTextExtent);
270
271
272 // works for single as well as multi-line strings
273 DocDeclAStr(
274 void, GetMultiLineTextExtent(const wxString& text,
275 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT,
276 wxFont *font = NULL),
277 "GetMultiLineTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)",
278 "Get the width, height, decent and leading of the text using the current or specified font.\n"
279 "Works for single as well as multi-line strings.");
280
281
282 %extend {
283 wxArrayInt GetPartialTextExtents(const wxString& text) {
284 wxArrayInt widths;
285 self->GetPartialTextExtents(text, widths);
286 return widths;
287 }
288 }
289
290
291 // size and resolution
292 // -------------------
293
294 DocStr(GetSize, "Get the DC size in device units.");
295 wxSize GetSize();
296 DocDeclAName(
297 void, GetSize( int *OUTPUT, int *OUTPUT ),
298 "GetSizeTuple() -> (width, height)",
299 GetSizeTuple);
300
301
302 DocStr(GetSizeMM, "Get the DC size in milimeters.");
303 wxSize GetSizeMM() const;
304 DocDeclAName(
305 void, GetSizeMM( int *OUTPUT, int *OUTPUT ) const,
306 "GetSizeMMTuple() -> (width, height)",
307 GetSizeMMTuple);
308
309
310
311 // coordinates conversions
312 // -----------------------
313
314 // This group of functions does actual conversion of the input, as you'd
315 // expect.
316 wxCoord DeviceToLogicalX(wxCoord x) const;
317 wxCoord DeviceToLogicalY(wxCoord y) const;
318 wxCoord DeviceToLogicalXRel(wxCoord x) const;
319 wxCoord DeviceToLogicalYRel(wxCoord y) const;
320 wxCoord LogicalToDeviceX(wxCoord x) const;
321 wxCoord LogicalToDeviceY(wxCoord y) const;
322 wxCoord LogicalToDeviceXRel(wxCoord x) const;
323 wxCoord LogicalToDeviceYRel(wxCoord y) const;
324
325 // query DC capabilities
326 // ---------------------
327
328 virtual bool CanDrawBitmap() const;
329 virtual bool CanGetTextExtent() const;
330
331 // colour depth
332 virtual int GetDepth() const;
333
334 // Resolution in Pixels per inch
335 virtual wxSize GetPPI() const;
336
337 virtual bool Ok() const;
338
339
340
341 int GetBackgroundMode() const;
342 const wxBrush& GetBackground() const;
343 const wxBrush& GetBrush() const;
344 const wxFont& GetFont() const;
345 const wxPen& GetPen() const;
346 const wxColour& GetTextBackground() const;
347 const wxColour& GetTextForeground() const;
348
349 virtual void SetTextForeground(const wxColour& colour);
350 virtual void SetTextBackground(const wxColour& colour);
351
352 int GetMapMode() const;
353 virtual void SetMapMode(int mode);
354
355
356 DocDeclA(
357 virtual void, GetUserScale(double *OUTPUT, double *OUTPUT) const,
358 "GetUserScale() -> (xScale, yScale)");
359
360 virtual void SetUserScale(double x, double y);
361
362
363 DocDeclA(
364 virtual void, GetLogicalScale(double *OUTPUT, double *OUTPUT),
365 "GetLogicalScale() -> (xScale, yScale)");
366
367 virtual void SetLogicalScale(double x, double y);
368
369
370 wxPoint GetLogicalOrigin() const;
371 DocDeclAName(
372 void, GetLogicalOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const,
373 "GetLogicalOriginTuple() -> (x,y)",
374 GetLogicalOriginTuple);
375
376 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
377
378
379 wxPoint GetDeviceOrigin() const;
380 DocDeclAName(
381 void, GetDeviceOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const,
382 "GetDeviceOriginTuple() -> (x,y)",
383 GetDeviceOriginTuple);
384
385 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
386
387 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
388
389 int GetLogicalFunction() const;
390 virtual void SetLogicalFunction(int function);
391
392 virtual void SetOptimization(bool opt);
393 virtual bool GetOptimization();
394
395
396 // bounding box
397 // ------------
398
399 virtual void CalcBoundingBox(wxCoord x, wxCoord y);
400 void ResetBoundingBox();
401
402 // Get the final bounding box of the PostScript or Metafile picture.
403 wxCoord MinX() const;
404 wxCoord MaxX() const;
405 wxCoord MinY() const;
406 wxCoord MaxY() const;
407
408
409 DocA(GetBoundingBox,
410 "GetBoundingBox() -> (x1,y1, x2,y2)");
411 %extend {
412 void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT);
413 // See below for implementation
414 }
415 %pythoncode { def __nonzero__(self): return self.Ok() };
416
417
418
419 %extend { // See drawlist.cpp for impplementaion of these...
420 PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
421 {
422 return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes);
423 }
424
425 PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
426 {
427 return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes);
428 }
429
430 PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
431 {
432 return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes);
433 }
434
435 PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
436 {
437 return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes);
438 }
439
440 PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
441 {
442 return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes);
443 }
444
445 PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints,
446 PyObject* foregroundList, PyObject* backgroundList) {
447 return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList);
448 }
449 }
450
451 %pythoncode {
452 def DrawPointList(self, points, pens=None):
453 if pens is None:
454 pens = []
455 elif isinstance(pens, wx.Pen):
456 pens = [pens]
457 elif len(pens) != len(points):
458 raise ValueError('points and pens must have same length')
459 return self._DrawPointList(points, pens, [])
460
461
462 def DrawLineList(self, lines, pens=None):
463 if pens is None:
464 pens = []
465 elif isinstance(pens, wx.Pen):
466 pens = [pens]
467 elif len(pens) != len(lines):
468 raise ValueError('lines and pens must have same length')
469 return self._DrawLineList(lines, pens, [])
470
471
472 def DrawRectangleList(self, rectangles, pens=None, brushes=None):
473 if pens is None:
474 pens = []
475 elif isinstance(pens, wx.Pen):
476 pens = [pens]
477 elif len(pens) != len(rectangles):
478 raise ValueError('rectangles and pens must have same length')
479 if brushes is None:
480 brushes = []
481 elif isinstance(brushes, wx.Brush):
482 brushes = [brushes]
483 elif len(brushes) != len(rectangles):
484 raise ValueError('rectangles and brushes must have same length')
485 return self._DrawRectangleList(rectangles, pens, brushes)
486
487
488 def DrawEllipseList(self, ellipses, pens=None, brushes=None):
489 if pens is None:
490 pens = []
491 elif isinstance(pens, wx.Pen):
492 pens = [pens]
493 elif len(pens) != len(ellipses):
494 raise ValueError('ellipses and pens must have same length')
495 if brushes is None:
496 brushes = []
497 elif isinstance(brushes, wx.Brush):
498 brushes = [brushes]
499 elif len(brushes) != len(ellipses):
500 raise ValueError('ellipses and brushes must have same length')
501 return self._DrawEllipseList(ellipses, pens, brushes)
502
503
504 def DrawPolygonList(self, polygons, pens=None, brushes=None):
505 %## Note: This does not currently support fill style or offset
506 %## you can always use the non-List version if need be.
507 if pens is None:
508 pens = []
509 elif isinstance(pens, wx.Pen):
510 pens = [pens]
511 elif len(pens) != len(polygons):
512 raise ValueError('polygons and pens must have same length')
513 if brushes is None:
514 brushes = []
515 elif isinstance(brushes, wx.Brush):
516 brushes = [brushes]
517 elif len(brushes) != len(polygons):
518 raise ValueError('polygons and brushes must have same length')
519 return self._DrawPolygonList(polygons, pens, brushes)
520
521
522 def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None):
523 %## NOTE: this does not currently support changing the font
524 %## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode)
525 %## If you want backgounds to do anything.
526 if type(textList) == type(''):
527 textList = [textList]
528 elif len(textList) != len(coords):
529 raise ValueError('textlist and coords must have same length')
530 if foregrounds is None:
531 foregrounds = []
532 elif isinstance(foregrounds, wx.Colour):
533 foregrounds = [foregrounds]
534 elif len(foregrounds) != len(coords):
535 raise ValueError('foregrounds and coords must have same length')
536 if backgrounds is None:
537 backgrounds = []
538 elif isinstance(backgrounds, wx.Colour):
539 backgrounds = [backgrounds]
540 elif len(backgrounds) != len(coords):
541 raise ValueError('backgrounds and coords must have same length')
542 return self._DrawTextList(textList, coords, foregrounds, backgrounds)
543 }
544
545 };
546
547
548
549 %{
550 static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) {
551 *x1 = dc->MinX();
552 *y1 = dc->MinY();
553 *x2 = dc->MaxX();
554 *y2 = dc->MaxY();
555 }
556 %}
557
558
559 //---------------------------------------------------------------------------
560 %newgroup
561
562 class wxMemoryDC : public wxDC {
563 public:
564 wxMemoryDC();
565 %name(MemoryDCFromDC) wxMemoryDC(wxDC* oldDC);
566
567 void SelectObject(const wxBitmap& bitmap);
568 };
569
570 //---------------------------------------------------------------------------
571 %newgroup
572
573
574 %{
575 //-=-=-=-=-=-=-=-=-=-=-
576
577 #if 1
578 // Use the standard wxBufferedDC
579 #include <wx/dcbuffer.h>
580
581 #else
582
583 // Or, temporarily put a set of classes here similar to the old buffered DC
584 // classes until the real ones can be fixed to work "correctly" again.
585
586 class wxBufferedDC : public wxMemoryDC
587 {
588 private:
589 wxDC *m_dc;
590 wxBitmap m_buffer;
591
592 public:
593
594 wxBufferedDC() : m_dc( 0 ) {}
595
596 wxBufferedDC( wxDC *dc, const wxBitmap &buffer )
597 : m_dc( dc ), m_buffer( buffer )
598 {
599 SelectObject( m_buffer );
600 }
601
602 wxBufferedDC( wxDC *dc, const wxSize &area )
603 : m_dc( dc ), m_buffer( area.GetWidth(), area.GetHeight() )
604 {
605 SelectObject( m_buffer );
606 }
607
608 ~wxBufferedDC() {
609 if( m_dc != 0 )
610 UnMask();
611 }
612
613
614 void Init( wxDC *dc, const wxBitmap &buffer ) {
615 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
616 _T("wxBufferedDC already initialised") );
617 m_dc = dc;
618 m_buffer = buffer;
619 SelectObject( m_buffer );
620 }
621
622 void Init( wxDC *dc, const wxSize &area ) {
623 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
624 _T("wxBufferedDC already initialised") );
625 m_dc = dc;
626 m_buffer = wxBitmap( area.GetWidth(), area.GetHeight() );
627 SelectObject( m_buffer );
628 }
629
630 void UnMask() {
631 wxASSERT_MSG( m_dc != 0, _T("No low level DC associated with buffer (anymore)") );
632 m_dc->Blit( 0, 0, m_buffer.GetWidth(), m_buffer.GetHeight(), this, 0, 0 );
633 m_dc = 0;
634 }
635 };
636
637
638 class wxBufferedPaintDC : public wxBufferedDC
639 {
640 private:
641 wxPaintDC m_paintdc;
642
643 public:
644 wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap )
645 : m_paintdc( window )
646 {
647 window->PrepareDC( m_paintdc );
648
649 if( buffer != wxNullBitmap )
650 Init( &m_paintdc, buffer );
651 else
652 Init( &m_paintdc, window->GetClientSize() );
653 }
654
655 ~wxBufferedPaintDC() {
656 UnMask();
657 }
658 };
659
660 #endif
661 //-=-=-=-=-=-=-=-=-=-=-
662 %}
663
664
665
666
667 class wxBufferedDC : public wxMemoryDC
668 {
669 public:
670 %pythonAppend wxBufferedDC
671 "self._dc = args[0] # save a ref so the other dc will not be deleted before self";
672
673 %nokwargs wxBufferedDC;
674
675 // Construct a wxBufferedDC using a user supplied buffer.
676 wxBufferedDC( wxDC *dc, const wxBitmap &buffer );
677
678 // Construct a wxBufferedDC with an internal buffer of 'area'
679 // (where area is usually something like the size of the window
680 // being buffered)
681 wxBufferedDC( wxDC *dc, const wxSize &area );
682
683
684 // TODO: Keep this one too?
685 %pythonAppend wxBufferedDC( wxDC *dc, const wxSize &area )
686 "val._dc = args[0] # save a ref so the other dc will not be deleted before self";
687 %name(BufferedDCInternalBuffer) wxBufferedDC( wxDC *dc, const wxSize &area );
688
689
690 // The buffer is blit to the real DC when the BufferedDC is destroyed.
691 ~wxBufferedDC();
692
693
694 // Blits the buffer to the dc, and detaches the dc from
695 // the buffer. Usually called in the dtor or by the dtor
696 // of derived classes if the BufferedDC must blit before
697 // the derived class (which may own the dc it's blitting
698 // to) is destroyed.
699 void UnMask();
700 };
701
702
703
704
705 // Creates a double buffered wxPaintDC, optionally allowing the
706 // user to specify their own buffer to use.
707 class wxBufferedPaintDC : public wxBufferedDC
708 {
709 public:
710
711 // If no bitmap is supplied by the user, a temporary one will be created.
712 wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap );
713
714 };
715
716
717 //---------------------------------------------------------------------------
718 %newgroup
719
720 class wxScreenDC : public wxDC {
721 public:
722 wxScreenDC();
723
724 %name(StartDrawingOnTopWin) bool StartDrawingOnTop(wxWindow* window);
725 bool StartDrawingOnTop(wxRect* rect = NULL);
726 bool EndDrawingOnTop();
727 };
728
729 //---------------------------------------------------------------------------
730 %newgroup
731
732 class wxClientDC : public wxDC {
733 public:
734 wxClientDC(wxWindow* win);
735 };
736
737 //---------------------------------------------------------------------------
738 %newgroup
739
740 class wxPaintDC : public wxDC {
741 public:
742 wxPaintDC(wxWindow* win);
743 };
744
745 //---------------------------------------------------------------------------
746 %newgroup
747
748 class wxWindowDC : public wxDC {
749 public:
750 wxWindowDC(wxWindow* win);
751 };
752
753 //---------------------------------------------------------------------------
754 %newgroup
755
756 class wxMirrorDC : public wxDC
757 {
758 public:
759 // constructs a mirror DC associated with the given real DC
760 //
761 // if mirror parameter is True, all vertical and horizontal coordinates are
762 // exchanged, otherwise this class behaves in exactly the same way as a
763 // plain DC
764 //
765 wxMirrorDC(wxDC& dc, bool mirror);
766 };
767
768 //---------------------------------------------------------------------------
769 %newgroup
770
771 %{
772 #include <wx/dcps.h>
773 %}
774
775 class wxPostScriptDC : public wxDC {
776 public:
777 wxPostScriptDC(const wxPrintData& printData);
778 // %name(PostScriptDC2)wxPostScriptDC(const wxString& output,
779 // bool interactive = True,
780 // wxWindow* parent = NULL);
781
782 wxPrintData& GetPrintData();
783 void SetPrintData(const wxPrintData& data);
784
785 static void SetResolution(int ppi);
786 static int GetResolution();
787 };
788
789 //---------------------------------------------------------------------------
790 %newgroup
791
792
793 #if defined(__WXMSW__) || defined(__WXMAC__)
794
795 %{
796 #include <wx/metafile.h>
797 %}
798
799 class wxMetaFile : public wxObject {
800 public:
801 wxMetaFile(const wxString& filename = wxPyEmptyString);
802 ~wxMetaFile();
803
804 bool Ok();
805 bool SetClipboard(int width = 0, int height = 0);
806
807 wxSize GetSize();
808 int GetWidth();
809 int GetHeight();
810
811 #ifdef __WXMSW__
812 const wxString& GetFileName() const;
813 #endif
814
815 %pythoncode { def __nonzero__(self): return self.Ok() }
816 };
817
818 // bool wxMakeMetaFilePlaceable(const wxString& filename,
819 // int minX, int minY, int maxX, int maxY, float scale=1.0);
820
821
822 class wxMetaFileDC : public wxDC {
823 public:
824 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
825 int width = 0, int height = 0,
826 const wxString& description = wxPyEmptyString);
827 wxMetaFile* Close();
828 };
829
830
831
832 #else // Make some dummies for the other platforms
833
834 %{
835 class wxMetaFile : public wxObject {
836 public:
837 wxMetaFile(const wxString&)
838 { wxPyRaiseNotImplemented(); }
839 };
840
841 class wxMetaFileDC : public wxClientDC {
842 public:
843 wxMetaFileDC(const wxString&, int, int, const wxString&)
844 { wxPyRaiseNotImplemented(); }
845 };
846
847 %}
848
849 class wxMetaFile : public wxObject {
850 public:
851 wxMetaFile(const wxString& filename = wxPyEmptyString);
852 };
853
854 class wxMetaFileDC : public wxDC {
855 public:
856 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
857 int width = 0, int height = 0,
858 const wxString& description = wxPyEmptyString);
859 };
860
861
862 #endif
863
864
865 //---------------------------------------------------------------------------
866
867 #if defined(__WXMSW__) || defined(__WXMAC__)
868
869 class wxPrinterDC : public wxDC {
870 public:
871 wxPrinterDC(const wxPrintData& printData);
872 // %name(PrinterDC2) wxPrinterDC(const wxString& driver,
873 // const wxString& device,
874 // const wxString& output,
875 // bool interactive = True,
876 // int orientation = wxPORTRAIT);
877 };
878
879 #else
880 %{
881 class wxPrinterDC : public wxClientDC {
882 public:
883 wxPrinterDC(const wxPrintData&)
884 { wxPyRaiseNotImplemented(); }
885
886 // wxPrinterDC(const wxString&, const wxString&, const wxString&, bool, int)
887 // { wxPyRaiseNotImplemented(); }
888 };
889 %}
890
891 class wxPrinterDC : public wxDC {
892 public:
893 wxPrinterDC(const wxPrintData& printData);
894 // %name(PrinterDC2) wxPrinterDC(const wxString& driver,
895 // const wxString& device,
896 // const wxString& output,
897 // bool interactive = True,
898 // int orientation = wxPORTRAIT);
899 };
900 #endif
901
902 //---------------------------------------------------------------------------
903 //---------------------------------------------------------------------------
904
905 // Now define some Python classes that rename the Draw methods to be
906 // compatible with the DC Draw methods in 2.4. See also wxPython/_wx.py.
907
908
909 %define MAKE_OLD_DC_CLASS(classname)
910 %pythoncode {
911 class classname##_old(classname):
912 """DC class that has methods with 2.4 compatible parameters."""
913 FloodFill = classname.FloodFillXY
914 GetPixel = classname.GetPixelXY
915 DrawLine = classname.DrawLineXY
916 CrossHair = classname.CrossHairXY
917 DrawArc = classname.DrawArcXY
918 DrawCheckMark = classname.DrawCheckMarkXY
919 DrawEllipticArc = classname.DrawEllipticArcXY
920 DrawPoint = classname.DrawPointXY
921 DrawRectangle = classname.DrawRectangleXY
922 DrawRoundedRectangle = classname.DrawRoundedRectangleXY
923 DrawCircle = classname.DrawCircleXY
924 DrawEllipse = classname.DrawEllipseXY
925 DrawIcon = classname.DrawIconXY
926 DrawBitmap = classname.DrawBitmapXY
927 DrawText = classname.DrawTextXY
928 DrawRotatedText = classname.DrawRotatedTextXY
929 Blit = classname.BlitXY
930 }
931 %enddef
932
933 MAKE_OLD_DC_CLASS(DC);
934 MAKE_OLD_DC_CLASS(MemoryDC);
935 MAKE_OLD_DC_CLASS(BufferedDC);
936 MAKE_OLD_DC_CLASS(BufferedPaintDC);
937 MAKE_OLD_DC_CLASS(ScreenDC);
938 MAKE_OLD_DC_CLASS(ClientDC);
939 MAKE_OLD_DC_CLASS(PaintDC);
940 MAKE_OLD_DC_CLASS(WindowDC);
941 MAKE_OLD_DC_CLASS(MirrorDC);
942 MAKE_OLD_DC_CLASS(PostScriptDC);
943 MAKE_OLD_DC_CLASS(MetaFileDC);
944 MAKE_OLD_DC_CLASS(PrinterDC);
945
946
947 //---------------------------------------------------------------------------