1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DC_H_BASE_
13 #define _WX_DC_H_BASE_
15 // ----------------------------------------------------------------------------
16 // headers which we must include here
17 // ----------------------------------------------------------------------------
19 #include "wx/object.h" // the base class
21 #include "wx/intl.h" // for wxLayoutDirection
22 #include "wx/cursor.h" // we have member variables of these classes
23 #include "wx/font.h" // so we can't do without them
24 #include "wx/colour.h"
25 #include "wx/bitmap.h" // for wxNullBitmap
28 #include "wx/palette.h"
29 #include "wx/dynarray.h"
32 #include "wx/cmndata.h"
34 #define wxUSE_NEW_DC 1
36 class WXDLLIMPEXP_FWD_CORE wxDC
;
37 class WXDLLIMPEXP_FWD_CORE wxClientDC
;
38 class WXDLLIMPEXP_FWD_CORE wxPaintDC
;
39 class WXDLLIMPEXP_FWD_CORE wxWindowDC
;
40 class WXDLLIMPEXP_FWD_CORE wxScreenDC
;
41 class WXDLLIMPEXP_FWD_CORE wxMemoryDC
;
42 class WXDLLIMPEXP_FWD_CORE wxPrinterDC
;
44 //-----------------------------------------------------------------------------
45 // wxDrawObject helper class
46 //-----------------------------------------------------------------------------
48 class WXDLLEXPORT wxDrawObject
53 : m_isBBoxValid(false)
54 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
57 virtual ~wxDrawObject() { }
59 virtual void Draw(wxDC
&) const { }
61 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
65 if ( x
< m_minX
) m_minX
= x
;
66 if ( y
< m_minY
) m_minY
= y
;
67 if ( x
> m_maxX
) m_maxX
= x
;
68 if ( y
> m_maxY
) m_maxY
= y
;
81 void ResetBoundingBox()
83 m_isBBoxValid
= false;
85 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
88 // Get the final bounding box of the PostScript or Metafile picture.
90 wxCoord
MinX() const { return m_minX
; }
91 wxCoord
MaxX() const { return m_maxX
; }
92 wxCoord
MinY() const { return m_minY
; }
93 wxCoord
MaxY() const { return m_maxY
; }
95 //to define the type of object for derived objects
96 virtual int GetType()=0;
99 //for boundingbox calculation
100 bool m_isBBoxValid
:1;
101 //for boundingbox calculation
102 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
110 class WXDLLIMPEXP_FWD_CORE wxDCImpl
;
112 class WXDLLIMPEXP_CORE wxDCFactory
116 virtual ~wxDCFactory() {}
118 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
) = 0;
119 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
, wxWindow
*window
) = 0;
120 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
) = 0;
121 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
, wxWindow
*window
) = 0;
122 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
) = 0;
123 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
, wxWindow
*window
) = 0;
124 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
) = 0;
125 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxBitmap
&bitmap
) = 0;
126 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxDC
*dc
) = 0;
127 virtual wxDCImpl
* CreateScreenDC( wxScreenDC
*owner
) = 0;
128 #if wxUSE_PRINTING_ARCHITECTURE
129 virtual wxDCImpl
* CreatePrinterDC( wxPrinterDC
*owner
, const wxPrintData
&data
) = 0;
132 static void Set(wxDCFactory
*factory
);
133 static wxDCFactory
*Get();
136 static wxDCFactory
*m_factory
;
139 //-----------------------------------------------------------------------------
141 //-----------------------------------------------------------------------------
143 class WXDLLIMPEXP_CORE wxNativeDCFactory
: public wxDCFactory
146 wxNativeDCFactory() {}
148 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
);
149 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
, wxWindow
*window
);
150 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
);
151 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
, wxWindow
*window
);
152 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
);
153 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
, wxWindow
*window
);
154 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
);
155 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxBitmap
&bitmap
);
156 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxDC
*dc
);
157 virtual wxDCImpl
* CreateScreenDC( wxScreenDC
*owner
);
158 #if wxUSE_PRINTING_ARCHITECTURE
159 virtual wxDCImpl
* CreatePrinterDC( wxPrinterDC
*owner
, const wxPrintData
&data
);
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
167 class WXDLLIMPEXP_CORE wxDCImpl
: public wxObject
170 wxDCImpl( wxDC
*owner
);
173 wxDC
*GetOwner() const { return m_owner
; }
175 wxWindow
* GetWindow() const { return m_window
; }
177 virtual bool IsOk() const { return m_ok
; }
179 // query capabilities
181 virtual bool CanDrawBitmap() const = 0;
182 virtual bool CanGetTextExtent() const = 0;
184 // query dimension, colour deps, resolution
186 virtual void DoGetSize(int *width
, int *height
) const = 0;
187 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
189 virtual int GetDepth() const = 0;
190 virtual wxSize
GetPPI() const = 0;
192 // Right-To-Left (RTL) modes
194 virtual void SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
)) { }
195 virtual wxLayoutDirection
GetLayoutDirection() const { return wxLayout_Default
; }
199 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return true; }
200 virtual void EndDoc() { }
202 virtual void StartPage() { }
203 virtual void EndPage() { }
205 // flushing the content of this dc immediately eg onto screen
206 virtual void Flush() { }
210 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
214 if ( x
< m_minX
) m_minX
= x
;
215 if ( y
< m_minY
) m_minY
= y
;
216 if ( x
> m_maxX
) m_maxX
= x
;
217 if ( y
> m_maxY
) m_maxY
= y
;
221 m_isBBoxValid
= true;
229 void ResetBoundingBox()
231 m_isBBoxValid
= false;
233 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
236 wxCoord
MinX() const { return m_minX
; }
237 wxCoord
MaxX() const { return m_maxX
; }
238 wxCoord
MinY() const { return m_minY
; }
239 wxCoord
MaxY() const { return m_maxY
; }
241 // setters and getters
243 virtual void SetFont(const wxFont
& font
) = 0;
244 virtual const wxFont
& GetFont() const { return m_font
; }
246 virtual void SetPen(const wxPen
& pen
) = 0;
247 virtual const wxPen
& GetPen() const { return m_pen
; }
249 virtual void SetBrush(const wxBrush
& brush
) = 0;
250 virtual const wxBrush
& GetBrush() const { return m_brush
; }
252 virtual void SetBackground(const wxBrush
& brush
) = 0;
253 virtual const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
255 virtual void SetBackgroundMode(int mode
) = 0;
256 virtual int GetBackgroundMode() const { return m_backgroundMode
; }
258 virtual void SetTextForeground(const wxColour
& colour
)
259 { m_textForegroundColour
= colour
; }
260 virtual const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
262 virtual void SetTextBackground(const wxColour
& colour
)
263 { m_textBackgroundColour
= colour
; }
264 virtual const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
267 virtual void SetPalette(const wxPalette
& palette
) = 0;
268 #endif // wxUSE_PALETTE
272 virtual void SetLogicalFunction(int function
) = 0;
273 virtual int GetLogicalFunction() const { return m_logicalFunction
; }
277 virtual wxCoord
GetCharHeight() const = 0;
278 virtual wxCoord
GetCharWidth() const = 0;
279 virtual void DoGetTextExtent(const wxString
& string
,
280 wxCoord
*x
, wxCoord
*y
,
281 wxCoord
*descent
= NULL
,
282 wxCoord
*externalLeading
= NULL
,
283 const wxFont
*theFont
= NULL
) const = 0;
284 virtual void GetMultiLineTextExtent(const wxString
& string
,
287 wxCoord
*heightLine
= NULL
,
288 const wxFont
*font
= NULL
) const;
289 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
293 virtual void Clear() = 0;
297 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
298 wxCoord width
, wxCoord height
) = 0;
299 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
301 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
302 wxCoord
*w
, wxCoord
*h
) const
309 *w
= m_clipX2
- m_clipX1
;
311 *h
= m_clipY2
- m_clipY1
;
314 virtual void DestroyClippingRegion() { ResetClipping(); }
317 // coordinates conversions and transforms
319 virtual wxCoord
DeviceToLogicalX(wxCoord x
) const;
320 virtual wxCoord
DeviceToLogicalY(wxCoord y
) const;
321 virtual wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
322 virtual wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
323 virtual wxCoord
LogicalToDeviceX(wxCoord x
) const;
324 virtual wxCoord
LogicalToDeviceY(wxCoord y
) const;
325 virtual wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
326 virtual wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
328 virtual void SetMapMode(int mode
);
329 virtual int GetMapMode() const { return m_mappingMode
; }
331 virtual void SetUserScale(double x
, double y
);
332 virtual void GetUserScale(double *x
, double *y
) const
334 if ( x
) *x
= m_userScaleX
;
335 if ( y
) *y
= m_userScaleY
;
338 virtual void SetLogicalScale(double x
, double y
);
339 virtual void GetLogicalScale(double *x
, double *y
)
341 if ( x
) *x
= m_logicalScaleX
;
342 if ( y
) *y
= m_logicalScaleY
;
345 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
346 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
348 if ( x
) *x
= m_logicalOriginX
;
349 if ( y
) *y
= m_logicalOriginY
;
352 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
353 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
355 if ( x
) *x
= m_deviceOriginX
;
356 if ( y
) *y
= m_deviceOriginY
;
359 virtual void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
);
361 virtual void ComputeScaleAndOrigin();
363 // this needs to overidden if the axis is inverted
364 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
366 // ---------------------------------------------------------
367 // the actual drawing API
369 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
370 int style
= wxFLOOD_SURFACE
) = 0;
372 virtual void DoGradientFillLinear(const wxRect
& rect
,
373 const wxColour
& initialColour
,
374 const wxColour
& destColour
,
375 wxDirection nDirection
= wxEAST
);
377 virtual void DoGradientFillConcentric(const wxRect
& rect
,
378 const wxColour
& initialColour
,
379 const wxColour
& destColour
,
380 const wxPoint
& circleCenter
);
382 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
384 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
385 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
387 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
388 wxCoord x2
, wxCoord y2
,
389 wxCoord xc
, wxCoord yc
) = 0;
390 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
391 wxCoord width
, wxCoord height
);
392 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
393 double sa
, double ea
) = 0;
395 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
396 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
397 wxCoord width
, wxCoord height
,
399 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
400 wxCoord width
, wxCoord height
) = 0;
402 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
404 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
405 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
406 bool useMask
= false) = 0;
408 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
409 virtual void DoDrawRotatedText(const wxString
& text
,
410 wxCoord x
, wxCoord y
, double angle
) = 0;
412 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
413 wxCoord width
, wxCoord height
,
415 wxCoord xsrc
, wxCoord ysrc
,
417 bool useMask
= false,
418 wxCoord xsrcMask
= wxDefaultCoord
,
419 wxCoord ysrcMask
= wxDefaultCoord
) = 0;
421 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
422 wxCoord dstWidth
, wxCoord dstHeight
,
424 wxCoord xsrc
, wxCoord ysrc
,
425 wxCoord srcWidth
, wxCoord srcHeight
,
427 bool useMask
= false,
428 wxCoord xsrcMask
= wxDefaultCoord
,
429 wxCoord ysrcMask
= wxDefaultCoord
);
431 virtual wxBitmap
DoGetAsBitmap(const wxRect
*WXUNUSED(subrect
)) const
432 { return wxNullBitmap
; }
435 virtual void DoDrawLines(int n
, wxPoint points
[],
436 wxCoord xoffset
, wxCoord yoffset
) = 0;
437 virtual void DrawLines(const wxPointList
*list
,
438 wxCoord xoffset
, wxCoord yoffset
);
440 virtual void DoDrawPolygon(int n
, wxPoint points
[],
441 wxCoord xoffset
, wxCoord yoffset
,
442 int fillStyle
= wxODDEVEN_RULE
) = 0;
443 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
444 wxCoord xoffset
, wxCoord yoffset
,
446 void DrawPolygon(const wxPointList
*list
,
447 wxCoord xoffset
, wxCoord yoffset
,
452 virtual void DoDrawSpline(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord x3
, wxCoord y3
);
453 virtual void DoDrawSpline(int n
, wxPoint points
[]);
454 virtual void DoDrawSpline(const wxPointList
*points
);
457 // ---------------------------------------------------------
458 // wxMemoryDC Impl API
460 virtual void DoSelect(const wxBitmap
& WXUNUSED(bmp
))
463 virtual const wxBitmap
& GetSelectedBitmap() const
464 { return wxNullBitmap
; }
465 virtual wxBitmap
& GetSelectedBitmap()
466 { return wxNullBitmap
; }
468 // ---------------------------------------------------------
469 // wxPrinterDC Impl API
471 virtual wxRect
GetPaperRect()
472 { int w
= 0; int h
= 0; DoGetSize( &w
, &h
); return wxRect(0,0,w
,h
); }
474 virtual int GetResolution()
481 // unset clipping variables (after clipping region was destroyed)
486 m_clipX1
= m_clipX2
= m_clipY1
= m_clipY2
= 0;
489 // window on which the DC draws or NULL
496 bool m_isInteractive
:1;
497 bool m_isBBoxValid
:1;
499 // coordinate system variables
501 wxCoord m_logicalOriginX
, m_logicalOriginY
;
502 wxCoord m_deviceOriginX
, m_deviceOriginY
; // Usually 0,0, can be change by user
504 wxCoord m_deviceLocalOriginX
, m_deviceLocalOriginY
; // non-zero if native top-left corner
505 // is not at 0,0. This was the case under
506 // Mac's GrafPorts (coordinate system
507 // used toplevel window's origin) and
508 // e.g. for Postscript, where the native
509 // origin in the bottom left corner.
510 double m_logicalScaleX
, m_logicalScaleY
;
511 double m_userScaleX
, m_userScaleY
;
512 double m_scaleX
, m_scaleY
; // calculated from logical scale and user scale
514 int m_signX
, m_signY
; // Used by SetAxisOrientation() to invert the axes
516 // what is a mm on a screen you don't know the size of?
517 double m_mm_to_pix_x
,
520 // bounding and clipping boxes
521 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
522 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
524 int m_logicalFunction
;
525 int m_backgroundMode
;
530 wxBrush m_backgroundBrush
;
531 wxColour m_textForegroundColour
;
532 wxColour m_textBackgroundColour
;
537 bool m_hasCustomPalette
;
538 #endif // wxUSE_PALETTE
541 DECLARE_ABSTRACT_CLASS(wxDCImpl
)
545 class WXDLLIMPEXP_CORE wxDC
: public wxObject
548 virtual ~wxDC() { delete m_pimpl
; }
552 const wxDCImpl
*GetImpl() const
555 wxWindow
*GetWindow()
556 { return m_pimpl
->GetWindow(); }
559 { return m_pimpl
&& m_pimpl
->IsOk(); }
561 // query capabilities
563 bool CanDrawBitmap() const
564 { return m_pimpl
->CanDrawBitmap(); }
565 bool CanGetTextExtent() const
566 { return m_pimpl
->CanGetTextExtent(); }
568 // query dimension, colour deps, resolution
570 void GetSize(int *width
, int *height
) const
571 { m_pimpl
->DoGetSize(width
, height
); }
573 wxSize
GetSize() const
576 m_pimpl
->DoGetSize(&w
, &h
);
580 void GetSizeMM(int* width
, int* height
) const
581 { m_pimpl
->DoGetSizeMM(width
, height
); }
582 wxSize
GetSizeMM() const
585 m_pimpl
->DoGetSizeMM(&w
, &h
);
590 { return m_pimpl
->GetDepth(); }
591 wxSize
GetPPI() const
592 { return m_pimpl
->GetPPI(); }
594 virtual int GetResolution()
595 { return m_pimpl
->GetResolution(); }
597 // Right-To-Left (RTL) modes
599 void SetLayoutDirection(wxLayoutDirection dir
)
600 { m_pimpl
->SetLayoutDirection( dir
); }
601 wxLayoutDirection
GetLayoutDirection() const
602 { return m_pimpl
->GetLayoutDirection(); }
606 bool StartDoc(const wxString
& message
)
607 { return m_pimpl
->StartDoc(message
); }
609 { m_pimpl
->EndDoc(); }
612 { m_pimpl
->StartPage(); }
614 { m_pimpl
->EndPage(); }
618 void CalcBoundingBox(wxCoord x
, wxCoord y
)
619 { m_pimpl
->CalcBoundingBox(x
,y
); }
620 void ResetBoundingBox()
621 { m_pimpl
->ResetBoundingBox(); }
624 { return m_pimpl
->MinX(); }
626 { return m_pimpl
->MaxX(); }
628 { return m_pimpl
->MinY(); }
630 { return m_pimpl
->MaxY(); }
632 // setters and getters
634 void SetFont(const wxFont
& font
)
635 { m_pimpl
->SetFont( font
); }
636 const wxFont
& GetFont() const
637 { return m_pimpl
->GetFont(); }
639 void SetPen(const wxPen
& pen
)
640 { m_pimpl
->SetPen( pen
); }
641 const wxPen
& GetPen() const
642 { return m_pimpl
->GetPen(); }
644 void SetBrush(const wxBrush
& brush
)
645 { m_pimpl
->SetBrush( brush
); }
646 const wxBrush
& GetBrush() const
647 { return m_pimpl
->GetBrush(); }
649 void SetBackground(const wxBrush
& brush
)
650 { m_pimpl
->SetBackground( brush
); }
651 const wxBrush
& GetBackground() const
652 { return m_pimpl
->GetBackground(); }
654 void SetBackgroundMode(int mode
)
655 { m_pimpl
->SetBackgroundMode( mode
); }
656 int GetBackgroundMode() const
657 { return m_pimpl
->GetBackgroundMode(); }
659 void SetTextForeground(const wxColour
& colour
)
660 { m_pimpl
->SetTextForeground(colour
); }
661 const wxColour
& GetTextForeground() const
662 { return m_pimpl
->GetTextForeground(); }
664 void SetTextBackground(const wxColour
& colour
)
665 { m_pimpl
->SetTextBackground(colour
); }
666 const wxColour
& GetTextBackground() const
667 { return m_pimpl
->GetTextBackground(); }
670 void SetPalette(const wxPalette
& palette
)
671 { m_pimpl
->SetPalette(palette
); }
672 #endif // wxUSE_PALETTE
676 void SetLogicalFunction(int function
)
677 { m_pimpl
->SetLogicalFunction(function
); }
678 int GetLogicalFunction() const
679 { return m_pimpl
->GetLogicalFunction(); }
683 wxCoord
GetCharHeight() const
684 { return m_pimpl
->GetCharHeight(); }
685 wxCoord
GetCharWidth() const
686 { return m_pimpl
->GetCharWidth(); }
688 void GetTextExtent(const wxString
& string
,
689 wxCoord
*x
, wxCoord
*y
,
690 wxCoord
*descent
= NULL
,
691 wxCoord
*externalLeading
= NULL
,
692 const wxFont
*theFont
= NULL
) const
693 { m_pimpl
->DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
695 wxSize
GetTextExtent(const wxString
& string
) const
698 m_pimpl
->DoGetTextExtent(string
, &w
, &h
);
702 void GetMultiLineTextExtent(const wxString
& string
,
705 wxCoord
*heightLine
= NULL
,
706 const wxFont
*font
= NULL
) const
707 { m_pimpl
->GetMultiLineTextExtent( string
, width
, height
, heightLine
, font
); }
709 wxSize
GetMultiLineTextExtent(const wxString
& string
) const
712 m_pimpl
->GetMultiLineTextExtent(string
, &w
, &h
);
716 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
717 { return m_pimpl
->DoGetPartialTextExtents(text
, widths
); }
722 { m_pimpl
->Clear(); }
726 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
727 { m_pimpl
->DoSetClippingRegion(x
, y
, width
, height
); }
728 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
729 { m_pimpl
->DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
730 void SetClippingRegion(const wxRect
& rect
)
731 { m_pimpl
->DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
732 void SetClippingRegion(const wxRegion
& region
)
733 { m_pimpl
->DoSetClippingRegionAsRegion(region
); }
735 void DestroyClippingRegion()
736 { m_pimpl
->DestroyClippingRegion(); }
738 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
739 { m_pimpl
->DoGetClippingBox(x
, y
, w
, h
); }
740 void GetClippingBox(wxRect
& rect
) const
741 { m_pimpl
->DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
743 // coordinates conversions and transforms
745 wxCoord
DeviceToLogicalX(wxCoord x
) const
746 { return m_pimpl
->DeviceToLogicalX(x
); }
747 wxCoord
DeviceToLogicalY(wxCoord y
) const
748 { return m_pimpl
->DeviceToLogicalY(y
); }
749 wxCoord
DeviceToLogicalXRel(wxCoord x
) const
750 { return m_pimpl
->DeviceToLogicalXRel(x
); }
751 wxCoord
DeviceToLogicalYRel(wxCoord y
) const
752 { return m_pimpl
->DeviceToLogicalYRel(y
); }
753 wxCoord
LogicalToDeviceX(wxCoord x
) const
754 { return m_pimpl
->LogicalToDeviceX(x
); }
755 wxCoord
LogicalToDeviceY(wxCoord y
) const
756 { return m_pimpl
->LogicalToDeviceY(y
); }
757 wxCoord
LogicalToDeviceXRel(wxCoord x
) const
758 { return m_pimpl
->LogicalToDeviceXRel(x
); }
759 wxCoord
LogicalToDeviceYRel(wxCoord y
) const
760 { return m_pimpl
->LogicalToDeviceYRel(y
); }
762 void SetMapMode(int mode
)
763 { m_pimpl
->SetMapMode(mode
); }
764 int GetMapMode() const
765 { return m_pimpl
->GetMapMode(); }
767 void SetUserScale(double x
, double y
)
768 { m_pimpl
->SetUserScale(x
,y
); }
769 void GetUserScale(double *x
, double *y
) const
770 { m_pimpl
->GetUserScale( x
, y
); }
772 void SetLogicalScale(double x
, double y
)
773 { m_pimpl
->SetLogicalScale( x
, y
); }
774 void GetLogicalScale(double *x
, double *y
)
775 { m_pimpl
->GetLogicalScale( x
, y
); }
777 void SetLogicalOrigin(wxCoord x
, wxCoord y
)
778 { m_pimpl
->SetLogicalOrigin(x
,y
); }
779 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
780 { m_pimpl
->DoGetLogicalOrigin(x
, y
); }
781 wxPoint
GetLogicalOrigin() const
782 { wxCoord x
, y
; m_pimpl
->DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
784 void SetDeviceOrigin(wxCoord x
, wxCoord y
)
785 { m_pimpl
->SetDeviceOrigin( x
, y
); }
786 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
787 { m_pimpl
->DoGetDeviceOrigin(x
, y
); }
788 wxPoint
GetDeviceOrigin() const
789 { wxCoord x
, y
; m_pimpl
->DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
791 void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
792 { m_pimpl
->SetAxisOrientation(xLeftRight
, yBottomUp
); }
795 void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
)
796 { m_pimpl
->SetDeviceLocalOrigin( x
, y
); }
799 // draw generic object
801 void DrawObject(wxDrawObject
* drawobject
)
803 drawobject
->Draw(*this);
804 CalcBoundingBox(drawobject
->MinX(),drawobject
->MinY());
805 CalcBoundingBox(drawobject
->MaxX(),drawobject
->MaxY());
808 // -----------------------------------------------
809 // the actual drawing API
811 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
812 int style
= wxFLOOD_SURFACE
)
813 { return m_pimpl
->DoFloodFill(x
, y
, col
, style
); }
814 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
815 int style
= wxFLOOD_SURFACE
)
816 { return m_pimpl
->DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
818 // fill the area specified by rect with a radial gradient, starting from
819 // initialColour in the centre of the cercle and fading to destColour.
820 void GradientFillConcentric(const wxRect
& rect
,
821 const wxColour
& initialColour
,
822 const wxColour
& destColour
)
823 { m_pimpl
->DoGradientFillConcentric( rect
, initialColour
, destColour
,
824 wxPoint(rect
.GetWidth() / 2,
825 rect
.GetHeight() / 2)); }
827 void GradientFillConcentric(const wxRect
& rect
,
828 const wxColour
& initialColour
,
829 const wxColour
& destColour
,
830 const wxPoint
& circleCenter
)
831 { m_pimpl
->DoGradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
833 // fill the area specified by rect with a linear gradient
834 void GradientFillLinear(const wxRect
& rect
,
835 const wxColour
& initialColour
,
836 const wxColour
& destColour
,
837 wxDirection nDirection
= wxEAST
)
838 { m_pimpl
->DoGradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
840 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
841 { return m_pimpl
->DoGetPixel(x
, y
, col
); }
842 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
843 { return m_pimpl
->DoGetPixel(pt
.x
, pt
.y
, col
); }
845 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
846 { m_pimpl
->DoDrawLine(x1
, y1
, x2
, y2
); }
847 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
848 { m_pimpl
->DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
850 void CrossHair(wxCoord x
, wxCoord y
)
851 { m_pimpl
->DoCrossHair(x
, y
); }
852 void CrossHair(const wxPoint
& pt
)
853 { m_pimpl
->DoCrossHair(pt
.x
, pt
.y
); }
855 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
856 wxCoord xc
, wxCoord yc
)
857 { m_pimpl
->DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
858 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
859 { m_pimpl
->DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
861 void DrawCheckMark(wxCoord x
, wxCoord y
,
862 wxCoord width
, wxCoord height
)
863 { m_pimpl
->DoDrawCheckMark(x
, y
, width
, height
); }
864 void DrawCheckMark(const wxRect
& rect
)
865 { m_pimpl
->DoDrawCheckMark(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
867 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
868 double sa
, double ea
)
869 { m_pimpl
->DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
870 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
871 double sa
, double ea
)
872 { m_pimpl
->DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
874 void DrawPoint(wxCoord x
, wxCoord y
)
875 { m_pimpl
->DoDrawPoint(x
, y
); }
876 void DrawPoint(const wxPoint
& pt
)
877 { m_pimpl
->DoDrawPoint(pt
.x
, pt
.y
); }
879 void DrawLines(int n
, wxPoint points
[],
880 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
881 { m_pimpl
->DoDrawLines(n
, points
, xoffset
, yoffset
); }
882 void DrawLines(const wxPointList
*list
,
883 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
884 { m_pimpl
->DrawLines( list
, xoffset
, yoffset
); }
885 #if WXWIN_COMPATIBILITY_2_8
886 wxDEPRECATED( void DrawLines(const wxList
*list
,
887 wxCoord xoffset
= 0, wxCoord yoffset
= 0) );
888 #endif // WXWIN_COMPATIBILITY_2_8
890 void DrawPolygon(int n
, wxPoint points
[],
891 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
892 int fillStyle
= wxODDEVEN_RULE
)
893 { m_pimpl
->DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
894 void DrawPolygon(const wxPointList
*list
,
895 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
896 int fillStyle
= wxODDEVEN_RULE
)
897 { m_pimpl
->DrawPolygon( list
, xoffset
, yoffset
, fillStyle
); }
898 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
899 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
900 int fillStyle
= wxODDEVEN_RULE
)
901 { m_pimpl
->DoDrawPolyPolygon(n
, count
, points
, xoffset
, yoffset
, fillStyle
); }
902 #if WXWIN_COMPATIBILITY_2_8
903 wxDEPRECATED( void DrawPolygon(const wxList
*list
,
904 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
905 int fillStyle
= wxODDEVEN_RULE
) );
906 #endif // WXWIN_COMPATIBILITY_2_8
908 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
909 { m_pimpl
->DoDrawRectangle(x
, y
, width
, height
); }
910 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
911 { m_pimpl
->DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
912 void DrawRectangle(const wxRect
& rect
)
913 { m_pimpl
->DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
915 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
917 { m_pimpl
->DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
918 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
920 { m_pimpl
->DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
921 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
922 { m_pimpl
->DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
924 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
925 { m_pimpl
->DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
926 void DrawCircle(const wxPoint
& pt
, wxCoord radius
)
927 { m_pimpl
->DoDrawEllipse(pt
.x
- radius
, pt
.y
- radius
, 2*radius
, 2*radius
); }
929 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
930 { m_pimpl
->DoDrawEllipse(x
, y
, width
, height
); }
931 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
932 { m_pimpl
->DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
933 void DrawEllipse(const wxRect
& rect
)
934 { m_pimpl
->DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
936 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
937 { m_pimpl
->DoDrawIcon(icon
, x
, y
); }
938 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
939 { m_pimpl
->DoDrawIcon(icon
, pt
.x
, pt
.y
); }
941 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
942 bool useMask
= false)
943 { m_pimpl
->DoDrawBitmap(bmp
, x
, y
, useMask
); }
944 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
945 bool useMask
= false)
946 { m_pimpl
->DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
948 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
949 { m_pimpl
->DoDrawText(text
, x
, y
); }
950 void DrawText(const wxString
& text
, const wxPoint
& pt
)
951 { m_pimpl
->DoDrawText(text
, pt
.x
, pt
.y
); }
953 void DrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
954 { m_pimpl
->DoDrawRotatedText(text
, x
, y
, angle
); }
955 void DrawRotatedText(const wxString
& text
, const wxPoint
& pt
, double angle
)
956 { m_pimpl
->DoDrawRotatedText(text
, pt
.x
, pt
.y
, angle
); }
958 // this version puts both optional bitmap and the text into the given
959 // rectangle and aligns is as specified by alignment parameter; it also
960 // will emphasize the character with the given index if it is != -1 and
961 // return the bounding rectangle if required
962 void DrawLabel(const wxString
& text
,
963 const wxBitmap
& image
,
965 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
967 wxRect
*rectBounding
= NULL
);
969 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
970 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
972 { DrawLabel(text
, wxNullBitmap
, rect
, alignment
, indexAccel
); }
974 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
975 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
976 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
978 return m_pimpl
->DoBlit(xdest
, ydest
, width
, height
,
979 source
, xsrc
, ysrc
, rop
, useMask
, xsrcMask
, ysrcMask
);
981 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
982 wxDC
*source
, const wxPoint
& srcPt
,
983 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
985 return m_pimpl
->DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
986 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
, srcPtMask
.x
, srcPtMask
.y
);
989 bool StretchBlit(wxCoord dstX
, wxCoord dstY
,
990 wxCoord dstWidth
, wxCoord dstHeight
,
992 wxCoord srcX
, wxCoord srcY
,
993 wxCoord srcWidth
, wxCoord srcHeight
,
994 int rop
= wxCOPY
, bool useMask
= false,
995 wxCoord srcMaskX
= wxDefaultCoord
, wxCoord srcMaskY
= wxDefaultCoord
)
997 return m_pimpl
->DoStretchBlit(dstX
, dstY
, dstWidth
, dstHeight
,
998 source
, srcX
, srcY
, srcWidth
, srcHeight
, rop
, useMask
, srcMaskX
, srcMaskY
);
1000 bool StretchBlit(const wxPoint
& dstPt
, const wxSize
& dstSize
,
1001 wxDC
*source
, const wxPoint
& srcPt
, const wxSize
& srcSize
,
1002 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcMaskPt
= wxDefaultPosition
)
1004 return m_pimpl
->DoStretchBlit(dstPt
.x
, dstPt
.y
, dstSize
.x
, dstSize
.y
,
1005 source
, srcPt
.x
, srcPt
.y
, srcSize
.x
, srcSize
.y
, rop
, useMask
, srcMaskPt
.x
, srcMaskPt
.y
);
1008 wxBitmap
GetAsBitmap(const wxRect
*subrect
= (const wxRect
*) NULL
) const
1010 return m_pimpl
->DoGetAsBitmap(subrect
);
1014 void DrawSpline(wxCoord x1
, wxCoord y1
,
1015 wxCoord x2
, wxCoord y2
,
1016 wxCoord x3
, wxCoord y3
)
1017 { m_pimpl
->DoDrawSpline(x1
,y1
,x2
,y2
,x3
,y3
); }
1018 void DrawSpline(int n
, wxPoint points
[])
1019 { m_pimpl
->DoDrawSpline(n
,points
); }
1020 void DrawSpline(const wxPointList
*points
)
1021 { m_pimpl
->DoDrawSpline(points
); }
1022 #endif // wxUSE_SPLINES
1025 #if WXWIN_COMPATIBILITY_2_8
1026 // for compatibility with the old code when wxCoord was long everywhere
1027 wxDEPRECATED( void GetTextExtent(const wxString
& string
,
1029 long *descent
= NULL
,
1030 long *externalLeading
= NULL
,
1031 const wxFont
*theFont
= NULL
) const );
1032 wxDEPRECATED( void GetLogicalOrigin(long *x
, long *y
) const );
1033 wxDEPRECATED( void GetDeviceOrigin(long *x
, long *y
) const );
1034 wxDEPRECATED( void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const );
1035 #endif // WXWIN_COMPATIBILITY_2_8
1039 // ctor takes ownership of the pointer
1040 wxDC(wxDCImpl
*pimpl
) : m_pimpl(pimpl
) { }
1042 wxDCImpl
* const m_pimpl
;
1045 DECLARE_ABSTRACT_CLASS(wxDC
)
1046 DECLARE_NO_COPY_CLASS(wxDC
)
1049 // ----------------------------------------------------------------------------
1050 // helper class: you can use it to temporarily change the DC text colour and
1051 // restore it automatically when the object goes out of scope
1052 // ----------------------------------------------------------------------------
1054 class WXDLLEXPORT wxDCTextColourChanger
1057 wxDCTextColourChanger(wxDC
& dc
) : m_dc(dc
), m_colFgOld() { }
1059 wxDCTextColourChanger(wxDC
& dc
, const wxColour
& col
) : m_dc(dc
)
1064 ~wxDCTextColourChanger()
1066 if ( m_colFgOld
.Ok() )
1067 m_dc
.SetTextForeground(m_colFgOld
);
1070 void Set(const wxColour
& col
)
1072 if ( !m_colFgOld
.Ok() )
1073 m_colFgOld
= m_dc
.GetTextForeground();
1074 m_dc
.SetTextForeground(col
);
1080 wxColour m_colFgOld
;
1082 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger
)
1085 // ----------------------------------------------------------------------------
1086 // helper class: you can use it to temporarily change the DC pen and
1087 // restore it automatically when the object goes out of scope
1088 // ----------------------------------------------------------------------------
1090 class WXDLLEXPORT wxDCPenChanger
1093 wxDCPenChanger(wxDC
& dc
, const wxPen
& pen
) : m_dc(dc
), m_penOld(dc
.GetPen())
1100 if ( m_penOld
.Ok() )
1101 m_dc
.SetPen(m_penOld
);
1109 DECLARE_NO_COPY_CLASS(wxDCPenChanger
)
1112 // ----------------------------------------------------------------------------
1113 // helper class: you can use it to temporarily change the DC brush and
1114 // restore it automatically when the object goes out of scope
1115 // ----------------------------------------------------------------------------
1117 class WXDLLEXPORT wxDCBrushChanger
1120 wxDCBrushChanger(wxDC
& dc
, const wxBrush
& brush
) : m_dc(dc
), m_brushOld(dc
.GetBrush())
1122 m_dc
.SetBrush(brush
);
1127 if ( m_brushOld
.Ok() )
1128 m_dc
.SetBrush(m_brushOld
);
1136 DECLARE_NO_COPY_CLASS(wxDCBrushChanger
)
1139 // ----------------------------------------------------------------------------
1140 // another small helper class: sets the clipping region in its ctor and
1141 // destroys it in the dtor
1142 // ----------------------------------------------------------------------------
1144 class WXDLLEXPORT wxDCClipper
1147 wxDCClipper(wxDC
& dc
, const wxRegion
& r
) : m_dc(dc
)
1148 { dc
.SetClippingRegion(r
); }
1149 wxDCClipper(wxDC
& dc
, const wxRect
& r
) : m_dc(dc
)
1150 { dc
.SetClippingRegion(r
.x
, r
.y
, r
.width
, r
.height
); }
1151 wxDCClipper(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) : m_dc(dc
)
1152 { dc
.SetClippingRegion(x
, y
, w
, h
); }
1154 ~wxDCClipper() { m_dc
.DestroyClippingRegion(); }
1159 DECLARE_NO_COPY_CLASS(wxDCClipper
)
1162 #endif // _WX_DC_H_BASE_