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
;
43 class WXDLLIMPEXP_FWD_CORE wxPrintData
;
45 //-----------------------------------------------------------------------------
46 // wxDrawObject helper class
47 //-----------------------------------------------------------------------------
49 class WXDLLEXPORT wxDrawObject
54 : m_isBBoxValid(false)
55 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
58 virtual ~wxDrawObject() { }
60 virtual void Draw(wxDC
&) const { }
62 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
66 if ( x
< m_minX
) m_minX
= x
;
67 if ( y
< m_minY
) m_minY
= y
;
68 if ( x
> m_maxX
) m_maxX
= x
;
69 if ( y
> m_maxY
) m_maxY
= y
;
82 void ResetBoundingBox()
84 m_isBBoxValid
= false;
86 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
89 // Get the final bounding box of the PostScript or Metafile picture.
91 wxCoord
MinX() const { return m_minX
; }
92 wxCoord
MaxX() const { return m_maxX
; }
93 wxCoord
MinY() const { return m_minY
; }
94 wxCoord
MaxY() const { return m_maxY
; }
96 //to define the type of object for derived objects
97 virtual int GetType()=0;
100 //for boundingbox calculation
101 bool m_isBBoxValid
:1;
102 //for boundingbox calculation
103 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
111 class WXDLLIMPEXP_FWD_CORE wxDCImpl
;
113 class WXDLLIMPEXP_CORE wxDCFactory
117 virtual ~wxDCFactory() {}
119 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
) = 0;
120 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
, wxWindow
*window
) = 0;
121 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
) = 0;
122 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
, wxWindow
*window
) = 0;
123 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
) = 0;
124 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
, wxWindow
*window
) = 0;
125 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
) = 0;
126 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxBitmap
&bitmap
) = 0;
127 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxDC
*dc
) = 0;
128 virtual wxDCImpl
* CreateScreenDC( wxScreenDC
*owner
) = 0;
129 #if wxUSE_PRINTING_ARCHITECTURE
130 virtual wxDCImpl
* CreatePrinterDC( wxPrinterDC
*owner
, const wxPrintData
&data
) = 0;
133 static void Set(wxDCFactory
*factory
);
134 static wxDCFactory
*Get();
137 static wxDCFactory
*m_factory
;
140 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
144 class WXDLLIMPEXP_CORE wxNativeDCFactory
: public wxDCFactory
147 wxNativeDCFactory() {}
149 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
);
150 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
, wxWindow
*window
);
151 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
);
152 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
, wxWindow
*window
);
153 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
);
154 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
, wxWindow
*window
);
155 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
);
156 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxBitmap
&bitmap
);
157 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxDC
*dc
);
158 virtual wxDCImpl
* CreateScreenDC( wxScreenDC
*owner
);
159 #if wxUSE_PRINTING_ARCHITECTURE
160 virtual wxDCImpl
* CreatePrinterDC( wxPrinterDC
*owner
, const wxPrintData
&data
);
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
168 class WXDLLIMPEXP_CORE wxDCImpl
: public wxObject
171 wxDCImpl( wxDC
*owner
);
174 wxDC
*GetOwner() const { return m_owner
; }
176 wxWindow
* GetWindow() const { return m_window
; }
178 virtual bool IsOk() const { return m_ok
; }
180 // query capabilities
182 virtual bool CanDrawBitmap() const = 0;
183 virtual bool CanGetTextExtent() const = 0;
185 // query dimension, colour deps, resolution
187 virtual void DoGetSize(int *width
, int *height
) const = 0;
188 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
190 virtual int GetDepth() const = 0;
191 virtual wxSize
GetPPI() const = 0;
193 // Right-To-Left (RTL) modes
195 virtual void SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
)) { }
196 virtual wxLayoutDirection
GetLayoutDirection() const { return wxLayout_Default
; }
200 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return true; }
201 virtual void EndDoc() { }
203 virtual void StartPage() { }
204 virtual void EndPage() { }
206 // flushing the content of this dc immediately eg onto screen
207 virtual void Flush() { }
211 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
215 if ( x
< m_minX
) m_minX
= x
;
216 if ( y
< m_minY
) m_minY
= y
;
217 if ( x
> m_maxX
) m_maxX
= x
;
218 if ( y
> m_maxY
) m_maxY
= y
;
222 m_isBBoxValid
= true;
230 void ResetBoundingBox()
232 m_isBBoxValid
= false;
234 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
237 wxCoord
MinX() const { return m_minX
; }
238 wxCoord
MaxX() const { return m_maxX
; }
239 wxCoord
MinY() const { return m_minY
; }
240 wxCoord
MaxY() const { return m_maxY
; }
242 // setters and getters
244 virtual void SetFont(const wxFont
& font
) = 0;
245 virtual const wxFont
& GetFont() const { return m_font
; }
247 virtual void SetPen(const wxPen
& pen
) = 0;
248 virtual const wxPen
& GetPen() const { return m_pen
; }
250 virtual void SetBrush(const wxBrush
& brush
) = 0;
251 virtual const wxBrush
& GetBrush() const { return m_brush
; }
253 virtual void SetBackground(const wxBrush
& brush
) = 0;
254 virtual const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
256 virtual void SetBackgroundMode(int mode
) = 0;
257 virtual int GetBackgroundMode() const { return m_backgroundMode
; }
259 virtual void SetTextForeground(const wxColour
& colour
)
260 { m_textForegroundColour
= colour
; }
261 virtual const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
263 virtual void SetTextBackground(const wxColour
& colour
)
264 { m_textBackgroundColour
= colour
; }
265 virtual const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
268 virtual void SetPalette(const wxPalette
& palette
) = 0;
269 #endif // wxUSE_PALETTE
273 virtual void SetLogicalFunction(int function
) = 0;
274 virtual int GetLogicalFunction() const { return m_logicalFunction
; }
278 virtual wxCoord
GetCharHeight() const = 0;
279 virtual wxCoord
GetCharWidth() const = 0;
280 virtual void DoGetTextExtent(const wxString
& string
,
281 wxCoord
*x
, wxCoord
*y
,
282 wxCoord
*descent
= NULL
,
283 wxCoord
*externalLeading
= NULL
,
284 const wxFont
*theFont
= NULL
) const = 0;
285 virtual void GetMultiLineTextExtent(const wxString
& string
,
288 wxCoord
*heightLine
= NULL
,
289 const wxFont
*font
= NULL
) const;
290 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
294 virtual void Clear() = 0;
298 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
299 wxCoord width
, wxCoord height
) = 0;
300 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
302 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
303 wxCoord
*w
, wxCoord
*h
) const
310 *w
= m_clipX2
- m_clipX1
;
312 *h
= m_clipY2
- m_clipY1
;
315 virtual void DestroyClippingRegion() { ResetClipping(); }
318 // coordinates conversions and transforms
320 virtual wxCoord
DeviceToLogicalX(wxCoord x
) const;
321 virtual wxCoord
DeviceToLogicalY(wxCoord y
) const;
322 virtual wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
323 virtual wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
324 virtual wxCoord
LogicalToDeviceX(wxCoord x
) const;
325 virtual wxCoord
LogicalToDeviceY(wxCoord y
) const;
326 virtual wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
327 virtual wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
329 virtual void SetMapMode(int mode
);
330 virtual int GetMapMode() const { return m_mappingMode
; }
332 virtual void SetUserScale(double x
, double y
);
333 virtual void GetUserScale(double *x
, double *y
) const
335 if ( x
) *x
= m_userScaleX
;
336 if ( y
) *y
= m_userScaleY
;
339 virtual void SetLogicalScale(double x
, double y
);
340 virtual void GetLogicalScale(double *x
, double *y
)
342 if ( x
) *x
= m_logicalScaleX
;
343 if ( y
) *y
= m_logicalScaleY
;
346 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
347 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
349 if ( x
) *x
= m_logicalOriginX
;
350 if ( y
) *y
= m_logicalOriginY
;
353 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
354 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
356 if ( x
) *x
= m_deviceOriginX
;
357 if ( y
) *y
= m_deviceOriginY
;
360 virtual void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
);
362 virtual void ComputeScaleAndOrigin();
364 // this needs to overidden if the axis is inverted
365 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
367 // ---------------------------------------------------------
368 // the actual drawing API
370 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
371 int style
= wxFLOOD_SURFACE
) = 0;
373 virtual void DoGradientFillLinear(const wxRect
& rect
,
374 const wxColour
& initialColour
,
375 const wxColour
& destColour
,
376 wxDirection nDirection
= wxEAST
);
378 virtual void DoGradientFillConcentric(const wxRect
& rect
,
379 const wxColour
& initialColour
,
380 const wxColour
& destColour
,
381 const wxPoint
& circleCenter
);
383 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
385 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
386 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
388 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
389 wxCoord x2
, wxCoord y2
,
390 wxCoord xc
, wxCoord yc
) = 0;
391 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
392 wxCoord width
, wxCoord height
);
393 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
394 double sa
, double ea
) = 0;
396 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
397 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
398 wxCoord width
, wxCoord height
,
400 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
401 wxCoord width
, wxCoord height
) = 0;
403 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
405 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
406 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
407 bool useMask
= false) = 0;
409 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
410 virtual void DoDrawRotatedText(const wxString
& text
,
411 wxCoord x
, wxCoord y
, double angle
) = 0;
413 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
414 wxCoord width
, wxCoord height
,
416 wxCoord xsrc
, wxCoord ysrc
,
418 bool useMask
= false,
419 wxCoord xsrcMask
= wxDefaultCoord
,
420 wxCoord ysrcMask
= wxDefaultCoord
) = 0;
422 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
423 wxCoord dstWidth
, wxCoord dstHeight
,
425 wxCoord xsrc
, wxCoord ysrc
,
426 wxCoord srcWidth
, wxCoord srcHeight
,
428 bool useMask
= false,
429 wxCoord xsrcMask
= wxDefaultCoord
,
430 wxCoord ysrcMask
= wxDefaultCoord
);
432 virtual wxBitmap
DoGetAsBitmap(const wxRect
*WXUNUSED(subrect
)) const
433 { return wxNullBitmap
; }
436 virtual void DoDrawLines(int n
, wxPoint points
[],
437 wxCoord xoffset
, wxCoord yoffset
) = 0;
438 virtual void DrawLines(const wxPointList
*list
,
439 wxCoord xoffset
, wxCoord yoffset
);
441 virtual void DoDrawPolygon(int n
, wxPoint points
[],
442 wxCoord xoffset
, wxCoord yoffset
,
443 int fillStyle
= wxODDEVEN_RULE
) = 0;
444 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
445 wxCoord xoffset
, wxCoord yoffset
,
447 void DrawPolygon(const wxPointList
*list
,
448 wxCoord xoffset
, wxCoord yoffset
,
453 virtual void DoDrawSpline(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord x3
, wxCoord y3
);
454 virtual void DoDrawSpline(int n
, wxPoint points
[]);
455 virtual void DoDrawSpline(const wxPointList
*points
);
458 // ---------------------------------------------------------
459 // wxMemoryDC Impl API
461 virtual void DoSelect(const wxBitmap
& WXUNUSED(bmp
))
464 virtual const wxBitmap
& GetSelectedBitmap() const
465 { return wxNullBitmap
; }
466 virtual wxBitmap
& GetSelectedBitmap()
467 { return wxNullBitmap
; }
469 // ---------------------------------------------------------
470 // wxPrinterDC Impl API
472 virtual wxRect
GetPaperRect()
473 { int w
= 0; int h
= 0; DoGetSize( &w
, &h
); return wxRect(0,0,w
,h
); }
475 virtual int GetResolution()
482 // unset clipping variables (after clipping region was destroyed)
487 m_clipX1
= m_clipX2
= m_clipY1
= m_clipY2
= 0;
490 // window on which the DC draws or NULL
497 bool m_isInteractive
:1;
498 bool m_isBBoxValid
:1;
500 // coordinate system variables
502 wxCoord m_logicalOriginX
, m_logicalOriginY
;
503 wxCoord m_deviceOriginX
, m_deviceOriginY
; // Usually 0,0, can be change by user
505 wxCoord m_deviceLocalOriginX
, m_deviceLocalOriginY
; // non-zero if native top-left corner
506 // is not at 0,0. This was the case under
507 // Mac's GrafPorts (coordinate system
508 // used toplevel window's origin) and
509 // e.g. for Postscript, where the native
510 // origin in the bottom left corner.
511 double m_logicalScaleX
, m_logicalScaleY
;
512 double m_userScaleX
, m_userScaleY
;
513 double m_scaleX
, m_scaleY
; // calculated from logical scale and user scale
515 int m_signX
, m_signY
; // Used by SetAxisOrientation() to invert the axes
517 // what is a mm on a screen you don't know the size of?
518 double m_mm_to_pix_x
,
521 // bounding and clipping boxes
522 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
523 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
525 int m_logicalFunction
;
526 int m_backgroundMode
;
531 wxBrush m_backgroundBrush
;
532 wxColour m_textForegroundColour
;
533 wxColour m_textBackgroundColour
;
538 bool m_hasCustomPalette
;
539 #endif // wxUSE_PALETTE
542 DECLARE_ABSTRACT_CLASS(wxDCImpl
)
546 class WXDLLIMPEXP_CORE wxDC
: public wxObject
549 virtual ~wxDC() { delete m_pimpl
; }
553 const wxDCImpl
*GetImpl() const
556 wxWindow
*GetWindow()
557 { return m_pimpl
->GetWindow(); }
560 { return m_pimpl
&& m_pimpl
->IsOk(); }
562 // query capabilities
564 bool CanDrawBitmap() const
565 { return m_pimpl
->CanDrawBitmap(); }
566 bool CanGetTextExtent() const
567 { return m_pimpl
->CanGetTextExtent(); }
569 // query dimension, colour deps, resolution
571 void GetSize(int *width
, int *height
) const
572 { m_pimpl
->DoGetSize(width
, height
); }
574 wxSize
GetSize() const
577 m_pimpl
->DoGetSize(&w
, &h
);
581 void GetSizeMM(int* width
, int* height
) const
582 { m_pimpl
->DoGetSizeMM(width
, height
); }
583 wxSize
GetSizeMM() const
586 m_pimpl
->DoGetSizeMM(&w
, &h
);
591 { return m_pimpl
->GetDepth(); }
592 wxSize
GetPPI() const
593 { return m_pimpl
->GetPPI(); }
595 virtual int GetResolution()
596 { return m_pimpl
->GetResolution(); }
598 // Right-To-Left (RTL) modes
600 void SetLayoutDirection(wxLayoutDirection dir
)
601 { m_pimpl
->SetLayoutDirection( dir
); }
602 wxLayoutDirection
GetLayoutDirection() const
603 { return m_pimpl
->GetLayoutDirection(); }
607 bool StartDoc(const wxString
& message
)
608 { return m_pimpl
->StartDoc(message
); }
610 { m_pimpl
->EndDoc(); }
613 { m_pimpl
->StartPage(); }
615 { m_pimpl
->EndPage(); }
619 void CalcBoundingBox(wxCoord x
, wxCoord y
)
620 { m_pimpl
->CalcBoundingBox(x
,y
); }
621 void ResetBoundingBox()
622 { m_pimpl
->ResetBoundingBox(); }
625 { return m_pimpl
->MinX(); }
627 { return m_pimpl
->MaxX(); }
629 { return m_pimpl
->MinY(); }
631 { return m_pimpl
->MaxY(); }
633 // setters and getters
635 void SetFont(const wxFont
& font
)
636 { m_pimpl
->SetFont( font
); }
637 const wxFont
& GetFont() const
638 { return m_pimpl
->GetFont(); }
640 void SetPen(const wxPen
& pen
)
641 { m_pimpl
->SetPen( pen
); }
642 const wxPen
& GetPen() const
643 { return m_pimpl
->GetPen(); }
645 void SetBrush(const wxBrush
& brush
)
646 { m_pimpl
->SetBrush( brush
); }
647 const wxBrush
& GetBrush() const
648 { return m_pimpl
->GetBrush(); }
650 void SetBackground(const wxBrush
& brush
)
651 { m_pimpl
->SetBackground( brush
); }
652 const wxBrush
& GetBackground() const
653 { return m_pimpl
->GetBackground(); }
655 void SetBackgroundMode(int mode
)
656 { m_pimpl
->SetBackgroundMode( mode
); }
657 int GetBackgroundMode() const
658 { return m_pimpl
->GetBackgroundMode(); }
660 void SetTextForeground(const wxColour
& colour
)
661 { m_pimpl
->SetTextForeground(colour
); }
662 const wxColour
& GetTextForeground() const
663 { return m_pimpl
->GetTextForeground(); }
665 void SetTextBackground(const wxColour
& colour
)
666 { m_pimpl
->SetTextBackground(colour
); }
667 const wxColour
& GetTextBackground() const
668 { return m_pimpl
->GetTextBackground(); }
671 void SetPalette(const wxPalette
& palette
)
672 { m_pimpl
->SetPalette(palette
); }
673 #endif // wxUSE_PALETTE
677 void SetLogicalFunction(int function
)
678 { m_pimpl
->SetLogicalFunction(function
); }
679 int GetLogicalFunction() const
680 { return m_pimpl
->GetLogicalFunction(); }
684 wxCoord
GetCharHeight() const
685 { return m_pimpl
->GetCharHeight(); }
686 wxCoord
GetCharWidth() const
687 { return m_pimpl
->GetCharWidth(); }
689 void GetTextExtent(const wxString
& string
,
690 wxCoord
*x
, wxCoord
*y
,
691 wxCoord
*descent
= NULL
,
692 wxCoord
*externalLeading
= NULL
,
693 const wxFont
*theFont
= NULL
) const
694 { m_pimpl
->DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
696 wxSize
GetTextExtent(const wxString
& string
) const
699 m_pimpl
->DoGetTextExtent(string
, &w
, &h
);
703 void GetMultiLineTextExtent(const wxString
& string
,
706 wxCoord
*heightLine
= NULL
,
707 const wxFont
*font
= NULL
) const
708 { m_pimpl
->GetMultiLineTextExtent( string
, width
, height
, heightLine
, font
); }
710 wxSize
GetMultiLineTextExtent(const wxString
& string
) const
713 m_pimpl
->GetMultiLineTextExtent(string
, &w
, &h
);
717 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
718 { return m_pimpl
->DoGetPartialTextExtents(text
, widths
); }
723 { m_pimpl
->Clear(); }
727 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
728 { m_pimpl
->DoSetClippingRegion(x
, y
, width
, height
); }
729 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
730 { m_pimpl
->DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
731 void SetClippingRegion(const wxRect
& rect
)
732 { m_pimpl
->DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
733 void SetClippingRegion(const wxRegion
& region
)
734 { m_pimpl
->DoSetClippingRegionAsRegion(region
); }
736 void DestroyClippingRegion()
737 { m_pimpl
->DestroyClippingRegion(); }
739 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
740 { m_pimpl
->DoGetClippingBox(x
, y
, w
, h
); }
741 void GetClippingBox(wxRect
& rect
) const
742 { m_pimpl
->DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
744 // coordinates conversions and transforms
746 wxCoord
DeviceToLogicalX(wxCoord x
) const
747 { return m_pimpl
->DeviceToLogicalX(x
); }
748 wxCoord
DeviceToLogicalY(wxCoord y
) const
749 { return m_pimpl
->DeviceToLogicalY(y
); }
750 wxCoord
DeviceToLogicalXRel(wxCoord x
) const
751 { return m_pimpl
->DeviceToLogicalXRel(x
); }
752 wxCoord
DeviceToLogicalYRel(wxCoord y
) const
753 { return m_pimpl
->DeviceToLogicalYRel(y
); }
754 wxCoord
LogicalToDeviceX(wxCoord x
) const
755 { return m_pimpl
->LogicalToDeviceX(x
); }
756 wxCoord
LogicalToDeviceY(wxCoord y
) const
757 { return m_pimpl
->LogicalToDeviceY(y
); }
758 wxCoord
LogicalToDeviceXRel(wxCoord x
) const
759 { return m_pimpl
->LogicalToDeviceXRel(x
); }
760 wxCoord
LogicalToDeviceYRel(wxCoord y
) const
761 { return m_pimpl
->LogicalToDeviceYRel(y
); }
763 void SetMapMode(int mode
)
764 { m_pimpl
->SetMapMode(mode
); }
765 int GetMapMode() const
766 { return m_pimpl
->GetMapMode(); }
768 void SetUserScale(double x
, double y
)
769 { m_pimpl
->SetUserScale(x
,y
); }
770 void GetUserScale(double *x
, double *y
) const
771 { m_pimpl
->GetUserScale( x
, y
); }
773 void SetLogicalScale(double x
, double y
)
774 { m_pimpl
->SetLogicalScale( x
, y
); }
775 void GetLogicalScale(double *x
, double *y
)
776 { m_pimpl
->GetLogicalScale( x
, y
); }
778 void SetLogicalOrigin(wxCoord x
, wxCoord y
)
779 { m_pimpl
->SetLogicalOrigin(x
,y
); }
780 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
781 { m_pimpl
->DoGetLogicalOrigin(x
, y
); }
782 wxPoint
GetLogicalOrigin() const
783 { wxCoord x
, y
; m_pimpl
->DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
785 void SetDeviceOrigin(wxCoord x
, wxCoord y
)
786 { m_pimpl
->SetDeviceOrigin( x
, y
); }
787 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
788 { m_pimpl
->DoGetDeviceOrigin(x
, y
); }
789 wxPoint
GetDeviceOrigin() const
790 { wxCoord x
, y
; m_pimpl
->DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
792 void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
793 { m_pimpl
->SetAxisOrientation(xLeftRight
, yBottomUp
); }
796 void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
)
797 { m_pimpl
->SetDeviceLocalOrigin( x
, y
); }
800 // draw generic object
802 void DrawObject(wxDrawObject
* drawobject
)
804 drawobject
->Draw(*this);
805 CalcBoundingBox(drawobject
->MinX(),drawobject
->MinY());
806 CalcBoundingBox(drawobject
->MaxX(),drawobject
->MaxY());
809 // -----------------------------------------------
810 // the actual drawing API
812 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
813 int style
= wxFLOOD_SURFACE
)
814 { return m_pimpl
->DoFloodFill(x
, y
, col
, style
); }
815 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
816 int style
= wxFLOOD_SURFACE
)
817 { return m_pimpl
->DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
819 // fill the area specified by rect with a radial gradient, starting from
820 // initialColour in the centre of the cercle and fading to destColour.
821 void GradientFillConcentric(const wxRect
& rect
,
822 const wxColour
& initialColour
,
823 const wxColour
& destColour
)
824 { m_pimpl
->DoGradientFillConcentric( rect
, initialColour
, destColour
,
825 wxPoint(rect
.GetWidth() / 2,
826 rect
.GetHeight() / 2)); }
828 void GradientFillConcentric(const wxRect
& rect
,
829 const wxColour
& initialColour
,
830 const wxColour
& destColour
,
831 const wxPoint
& circleCenter
)
832 { m_pimpl
->DoGradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
834 // fill the area specified by rect with a linear gradient
835 void GradientFillLinear(const wxRect
& rect
,
836 const wxColour
& initialColour
,
837 const wxColour
& destColour
,
838 wxDirection nDirection
= wxEAST
)
839 { m_pimpl
->DoGradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
841 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
842 { return m_pimpl
->DoGetPixel(x
, y
, col
); }
843 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
844 { return m_pimpl
->DoGetPixel(pt
.x
, pt
.y
, col
); }
846 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
847 { m_pimpl
->DoDrawLine(x1
, y1
, x2
, y2
); }
848 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
849 { m_pimpl
->DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
851 void CrossHair(wxCoord x
, wxCoord y
)
852 { m_pimpl
->DoCrossHair(x
, y
); }
853 void CrossHair(const wxPoint
& pt
)
854 { m_pimpl
->DoCrossHair(pt
.x
, pt
.y
); }
856 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
857 wxCoord xc
, wxCoord yc
)
858 { m_pimpl
->DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
859 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
860 { m_pimpl
->DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
862 void DrawCheckMark(wxCoord x
, wxCoord y
,
863 wxCoord width
, wxCoord height
)
864 { m_pimpl
->DoDrawCheckMark(x
, y
, width
, height
); }
865 void DrawCheckMark(const wxRect
& rect
)
866 { m_pimpl
->DoDrawCheckMark(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
868 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
869 double sa
, double ea
)
870 { m_pimpl
->DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
871 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
872 double sa
, double ea
)
873 { m_pimpl
->DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
875 void DrawPoint(wxCoord x
, wxCoord y
)
876 { m_pimpl
->DoDrawPoint(x
, y
); }
877 void DrawPoint(const wxPoint
& pt
)
878 { m_pimpl
->DoDrawPoint(pt
.x
, pt
.y
); }
880 void DrawLines(int n
, wxPoint points
[],
881 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
882 { m_pimpl
->DoDrawLines(n
, points
, xoffset
, yoffset
); }
883 void DrawLines(const wxPointList
*list
,
884 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
885 { m_pimpl
->DrawLines( list
, xoffset
, yoffset
); }
886 #if WXWIN_COMPATIBILITY_2_8
887 wxDEPRECATED( void DrawLines(const wxList
*list
,
888 wxCoord xoffset
= 0, wxCoord yoffset
= 0) );
889 #endif // WXWIN_COMPATIBILITY_2_8
891 void DrawPolygon(int n
, wxPoint points
[],
892 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
893 int fillStyle
= wxODDEVEN_RULE
)
894 { m_pimpl
->DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
895 void DrawPolygon(const wxPointList
*list
,
896 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
897 int fillStyle
= wxODDEVEN_RULE
)
898 { m_pimpl
->DrawPolygon( list
, xoffset
, yoffset
, fillStyle
); }
899 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
900 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
901 int fillStyle
= wxODDEVEN_RULE
)
902 { m_pimpl
->DoDrawPolyPolygon(n
, count
, points
, xoffset
, yoffset
, fillStyle
); }
903 #if WXWIN_COMPATIBILITY_2_8
904 wxDEPRECATED( void DrawPolygon(const wxList
*list
,
905 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
906 int fillStyle
= wxODDEVEN_RULE
) );
907 #endif // WXWIN_COMPATIBILITY_2_8
909 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
910 { m_pimpl
->DoDrawRectangle(x
, y
, width
, height
); }
911 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
912 { m_pimpl
->DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
913 void DrawRectangle(const wxRect
& rect
)
914 { m_pimpl
->DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
916 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
918 { m_pimpl
->DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
919 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
921 { m_pimpl
->DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
922 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
923 { m_pimpl
->DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
925 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
926 { m_pimpl
->DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
927 void DrawCircle(const wxPoint
& pt
, wxCoord radius
)
928 { m_pimpl
->DoDrawEllipse(pt
.x
- radius
, pt
.y
- radius
, 2*radius
, 2*radius
); }
930 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
931 { m_pimpl
->DoDrawEllipse(x
, y
, width
, height
); }
932 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
933 { m_pimpl
->DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
934 void DrawEllipse(const wxRect
& rect
)
935 { m_pimpl
->DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
937 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
938 { m_pimpl
->DoDrawIcon(icon
, x
, y
); }
939 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
940 { m_pimpl
->DoDrawIcon(icon
, pt
.x
, pt
.y
); }
942 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
943 bool useMask
= false)
944 { m_pimpl
->DoDrawBitmap(bmp
, x
, y
, useMask
); }
945 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
946 bool useMask
= false)
947 { m_pimpl
->DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
949 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
950 { m_pimpl
->DoDrawText(text
, x
, y
); }
951 void DrawText(const wxString
& text
, const wxPoint
& pt
)
952 { m_pimpl
->DoDrawText(text
, pt
.x
, pt
.y
); }
954 void DrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
955 { m_pimpl
->DoDrawRotatedText(text
, x
, y
, angle
); }
956 void DrawRotatedText(const wxString
& text
, const wxPoint
& pt
, double angle
)
957 { m_pimpl
->DoDrawRotatedText(text
, pt
.x
, pt
.y
, angle
); }
959 // this version puts both optional bitmap and the text into the given
960 // rectangle and aligns is as specified by alignment parameter; it also
961 // will emphasize the character with the given index if it is != -1 and
962 // return the bounding rectangle if required
963 void DrawLabel(const wxString
& text
,
964 const wxBitmap
& image
,
966 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
968 wxRect
*rectBounding
= NULL
);
970 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
971 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
973 { DrawLabel(text
, wxNullBitmap
, rect
, alignment
, indexAccel
); }
975 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
976 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
977 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
979 return m_pimpl
->DoBlit(xdest
, ydest
, width
, height
,
980 source
, xsrc
, ysrc
, rop
, useMask
, xsrcMask
, ysrcMask
);
982 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
983 wxDC
*source
, const wxPoint
& srcPt
,
984 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
986 return m_pimpl
->DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
987 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
, srcPtMask
.x
, srcPtMask
.y
);
990 bool StretchBlit(wxCoord dstX
, wxCoord dstY
,
991 wxCoord dstWidth
, wxCoord dstHeight
,
993 wxCoord srcX
, wxCoord srcY
,
994 wxCoord srcWidth
, wxCoord srcHeight
,
995 int rop
= wxCOPY
, bool useMask
= false,
996 wxCoord srcMaskX
= wxDefaultCoord
, wxCoord srcMaskY
= wxDefaultCoord
)
998 return m_pimpl
->DoStretchBlit(dstX
, dstY
, dstWidth
, dstHeight
,
999 source
, srcX
, srcY
, srcWidth
, srcHeight
, rop
, useMask
, srcMaskX
, srcMaskY
);
1001 bool StretchBlit(const wxPoint
& dstPt
, const wxSize
& dstSize
,
1002 wxDC
*source
, const wxPoint
& srcPt
, const wxSize
& srcSize
,
1003 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcMaskPt
= wxDefaultPosition
)
1005 return m_pimpl
->DoStretchBlit(dstPt
.x
, dstPt
.y
, dstSize
.x
, dstSize
.y
,
1006 source
, srcPt
.x
, srcPt
.y
, srcSize
.x
, srcSize
.y
, rop
, useMask
, srcMaskPt
.x
, srcMaskPt
.y
);
1009 wxBitmap
GetAsBitmap(const wxRect
*subrect
= (const wxRect
*) NULL
) const
1011 return m_pimpl
->DoGetAsBitmap(subrect
);
1015 void DrawSpline(wxCoord x1
, wxCoord y1
,
1016 wxCoord x2
, wxCoord y2
,
1017 wxCoord x3
, wxCoord y3
)
1018 { m_pimpl
->DoDrawSpline(x1
,y1
,x2
,y2
,x3
,y3
); }
1019 void DrawSpline(int n
, wxPoint points
[])
1020 { m_pimpl
->DoDrawSpline(n
,points
); }
1021 void DrawSpline(const wxPointList
*points
)
1022 { m_pimpl
->DoDrawSpline(points
); }
1023 #endif // wxUSE_SPLINES
1026 #if WXWIN_COMPATIBILITY_2_8
1027 // for compatibility with the old code when wxCoord was long everywhere
1028 wxDEPRECATED( void GetTextExtent(const wxString
& string
,
1030 long *descent
= NULL
,
1031 long *externalLeading
= NULL
,
1032 const wxFont
*theFont
= NULL
) const );
1033 wxDEPRECATED( void GetLogicalOrigin(long *x
, long *y
) const );
1034 wxDEPRECATED( void GetDeviceOrigin(long *x
, long *y
) const );
1035 wxDEPRECATED( void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const );
1036 #endif // WXWIN_COMPATIBILITY_2_8
1040 // ctor takes ownership of the pointer
1041 wxDC(wxDCImpl
*pimpl
) : m_pimpl(pimpl
) { }
1043 wxDCImpl
* const m_pimpl
;
1046 DECLARE_ABSTRACT_CLASS(wxDC
)
1047 DECLARE_NO_COPY_CLASS(wxDC
)
1050 // ----------------------------------------------------------------------------
1051 // helper class: you can use it to temporarily change the DC text colour and
1052 // restore it automatically when the object goes out of scope
1053 // ----------------------------------------------------------------------------
1055 class WXDLLEXPORT wxDCTextColourChanger
1058 wxDCTextColourChanger(wxDC
& dc
) : m_dc(dc
), m_colFgOld() { }
1060 wxDCTextColourChanger(wxDC
& dc
, const wxColour
& col
) : m_dc(dc
)
1065 ~wxDCTextColourChanger()
1067 if ( m_colFgOld
.Ok() )
1068 m_dc
.SetTextForeground(m_colFgOld
);
1071 void Set(const wxColour
& col
)
1073 if ( !m_colFgOld
.Ok() )
1074 m_colFgOld
= m_dc
.GetTextForeground();
1075 m_dc
.SetTextForeground(col
);
1081 wxColour m_colFgOld
;
1083 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger
)
1086 // ----------------------------------------------------------------------------
1087 // helper class: you can use it to temporarily change the DC pen and
1088 // restore it automatically when the object goes out of scope
1089 // ----------------------------------------------------------------------------
1091 class WXDLLEXPORT wxDCPenChanger
1094 wxDCPenChanger(wxDC
& dc
, const wxPen
& pen
) : m_dc(dc
), m_penOld(dc
.GetPen())
1101 if ( m_penOld
.Ok() )
1102 m_dc
.SetPen(m_penOld
);
1110 DECLARE_NO_COPY_CLASS(wxDCPenChanger
)
1113 // ----------------------------------------------------------------------------
1114 // helper class: you can use it to temporarily change the DC brush and
1115 // restore it automatically when the object goes out of scope
1116 // ----------------------------------------------------------------------------
1118 class WXDLLEXPORT wxDCBrushChanger
1121 wxDCBrushChanger(wxDC
& dc
, const wxBrush
& brush
) : m_dc(dc
), m_brushOld(dc
.GetBrush())
1123 m_dc
.SetBrush(brush
);
1128 if ( m_brushOld
.Ok() )
1129 m_dc
.SetBrush(m_brushOld
);
1137 DECLARE_NO_COPY_CLASS(wxDCBrushChanger
)
1140 // ----------------------------------------------------------------------------
1141 // another small helper class: sets the clipping region in its ctor and
1142 // destroys it in the dtor
1143 // ----------------------------------------------------------------------------
1145 class WXDLLEXPORT wxDCClipper
1148 wxDCClipper(wxDC
& dc
, const wxRegion
& r
) : m_dc(dc
)
1149 { dc
.SetClippingRegion(r
); }
1150 wxDCClipper(wxDC
& dc
, const wxRect
& r
) : m_dc(dc
)
1151 { dc
.SetClippingRegion(r
.x
, r
.y
, r
.width
, r
.height
); }
1152 wxDCClipper(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) : m_dc(dc
)
1153 { dc
.SetClippingRegion(x
, y
, w
, h
); }
1155 ~wxDCClipper() { m_dc
.DestroyClippingRegion(); }
1160 DECLARE_NO_COPY_CLASS(wxDCClipper
)
1163 #endif // _WX_DC_H_BASE_