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 void GetSize(int *width
, int *height
) const
190 return DoGetSize(width
, height
);
193 wxSize
GetSize() const
200 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
202 virtual int GetDepth() const = 0;
203 virtual wxSize
GetPPI() const = 0;
205 // Right-To-Left (RTL) modes
207 virtual void SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
)) { }
208 virtual wxLayoutDirection
GetLayoutDirection() const { return wxLayout_Default
; }
212 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return true; }
213 virtual void EndDoc() { }
215 virtual void StartPage() { }
216 virtual void EndPage() { }
218 // flushing the content of this dc immediately eg onto screen
219 virtual void Flush() { }
223 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
227 if ( x
< m_minX
) m_minX
= x
;
228 if ( y
< m_minY
) m_minY
= y
;
229 if ( x
> m_maxX
) m_maxX
= x
;
230 if ( y
> m_maxY
) m_maxY
= y
;
234 m_isBBoxValid
= true;
242 void ResetBoundingBox()
244 m_isBBoxValid
= false;
246 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
249 wxCoord
MinX() const { return m_minX
; }
250 wxCoord
MaxX() const { return m_maxX
; }
251 wxCoord
MinY() const { return m_minY
; }
252 wxCoord
MaxY() const { return m_maxY
; }
254 // setters and getters
256 virtual void SetFont(const wxFont
& font
) = 0;
257 virtual const wxFont
& GetFont() const { return m_font
; }
259 virtual void SetPen(const wxPen
& pen
) = 0;
260 virtual const wxPen
& GetPen() const { return m_pen
; }
262 virtual void SetBrush(const wxBrush
& brush
) = 0;
263 virtual const wxBrush
& GetBrush() const { return m_brush
; }
265 virtual void SetBackground(const wxBrush
& brush
) = 0;
266 virtual const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
268 virtual void SetBackgroundMode(int mode
) = 0;
269 virtual int GetBackgroundMode() const { return m_backgroundMode
; }
271 virtual void SetTextForeground(const wxColour
& colour
)
272 { m_textForegroundColour
= colour
; }
273 virtual const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
275 virtual void SetTextBackground(const wxColour
& colour
)
276 { m_textBackgroundColour
= colour
; }
277 virtual const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
280 virtual void SetPalette(const wxPalette
& palette
) = 0;
281 #endif // wxUSE_PALETTE
285 virtual void SetLogicalFunction(int function
) = 0;
286 virtual int GetLogicalFunction() const { return m_logicalFunction
; }
290 virtual wxCoord
GetCharHeight() const = 0;
291 virtual wxCoord
GetCharWidth() const = 0;
292 virtual void DoGetTextExtent(const wxString
& string
,
293 wxCoord
*x
, wxCoord
*y
,
294 wxCoord
*descent
= NULL
,
295 wxCoord
*externalLeading
= NULL
,
296 const wxFont
*theFont
= NULL
) const = 0;
297 virtual void GetMultiLineTextExtent(const wxString
& string
,
300 wxCoord
*heightLine
= NULL
,
301 const wxFont
*font
= NULL
) const;
302 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
306 virtual void Clear() = 0;
310 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
311 wxCoord width
, wxCoord height
) = 0;
312 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
314 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
315 wxCoord
*w
, wxCoord
*h
) const
322 *w
= m_clipX2
- m_clipX1
;
324 *h
= m_clipY2
- m_clipY1
;
327 virtual void DestroyClippingRegion() { ResetClipping(); }
330 // coordinates conversions and transforms
332 virtual wxCoord
DeviceToLogicalX(wxCoord x
) const;
333 virtual wxCoord
DeviceToLogicalY(wxCoord y
) const;
334 virtual wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
335 virtual wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
336 virtual wxCoord
LogicalToDeviceX(wxCoord x
) const;
337 virtual wxCoord
LogicalToDeviceY(wxCoord y
) const;
338 virtual wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
339 virtual wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
341 virtual void SetMapMode(int mode
);
342 virtual int GetMapMode() const { return m_mappingMode
; }
344 virtual void SetUserScale(double x
, double y
);
345 virtual void GetUserScale(double *x
, double *y
) const
347 if ( x
) *x
= m_userScaleX
;
348 if ( y
) *y
= m_userScaleY
;
351 virtual void SetLogicalScale(double x
, double y
);
352 virtual void GetLogicalScale(double *x
, double *y
)
354 if ( x
) *x
= m_logicalScaleX
;
355 if ( y
) *y
= m_logicalScaleY
;
358 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
359 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
361 if ( x
) *x
= m_logicalOriginX
;
362 if ( y
) *y
= m_logicalOriginY
;
365 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
366 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
368 if ( x
) *x
= m_deviceOriginX
;
369 if ( y
) *y
= m_deviceOriginY
;
372 virtual void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
);
374 virtual void ComputeScaleAndOrigin();
376 // this needs to overidden if the axis is inverted
377 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
379 // ---------------------------------------------------------
380 // the actual drawing API
382 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
383 int style
= wxFLOOD_SURFACE
) = 0;
385 virtual void DoGradientFillLinear(const wxRect
& rect
,
386 const wxColour
& initialColour
,
387 const wxColour
& destColour
,
388 wxDirection nDirection
= wxEAST
);
390 virtual void DoGradientFillConcentric(const wxRect
& rect
,
391 const wxColour
& initialColour
,
392 const wxColour
& destColour
,
393 const wxPoint
& circleCenter
);
395 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
397 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
398 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
400 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
401 wxCoord x2
, wxCoord y2
,
402 wxCoord xc
, wxCoord yc
) = 0;
403 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
404 wxCoord width
, wxCoord height
);
405 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
406 double sa
, double ea
) = 0;
408 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
409 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
410 wxCoord width
, wxCoord height
,
412 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
413 wxCoord width
, wxCoord height
) = 0;
415 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
417 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
418 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
419 bool useMask
= false) = 0;
421 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
422 virtual void DoDrawRotatedText(const wxString
& text
,
423 wxCoord x
, wxCoord y
, double angle
) = 0;
425 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
426 wxCoord width
, wxCoord height
,
428 wxCoord xsrc
, wxCoord ysrc
,
430 bool useMask
= false,
431 wxCoord xsrcMask
= wxDefaultCoord
,
432 wxCoord ysrcMask
= wxDefaultCoord
) = 0;
434 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
435 wxCoord dstWidth
, wxCoord dstHeight
,
437 wxCoord xsrc
, wxCoord ysrc
,
438 wxCoord srcWidth
, wxCoord srcHeight
,
440 bool useMask
= false,
441 wxCoord xsrcMask
= wxDefaultCoord
,
442 wxCoord ysrcMask
= wxDefaultCoord
);
444 virtual wxBitmap
DoGetAsBitmap(const wxRect
*WXUNUSED(subrect
)) const
445 { return wxNullBitmap
; }
448 virtual void DoDrawLines(int n
, wxPoint points
[],
449 wxCoord xoffset
, wxCoord yoffset
) = 0;
450 virtual void DrawLines(const wxPointList
*list
,
451 wxCoord xoffset
, wxCoord yoffset
);
453 virtual void DoDrawPolygon(int n
, wxPoint points
[],
454 wxCoord xoffset
, wxCoord yoffset
,
455 int fillStyle
= wxODDEVEN_RULE
) = 0;
456 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
457 wxCoord xoffset
, wxCoord yoffset
,
459 void DrawPolygon(const wxPointList
*list
,
460 wxCoord xoffset
, wxCoord yoffset
,
465 virtual void DoDrawSpline(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord x3
, wxCoord y3
);
466 virtual void DoDrawSpline(int n
, wxPoint points
[]);
467 virtual void DoDrawSpline(const wxPointList
*points
);
470 // ---------------------------------------------------------
471 // wxMemoryDC Impl API
473 virtual void DoSelect(const wxBitmap
& WXUNUSED(bmp
))
476 virtual const wxBitmap
& GetSelectedBitmap() const
477 { return wxNullBitmap
; }
478 virtual wxBitmap
& GetSelectedBitmap()
479 { return wxNullBitmap
; }
481 // ---------------------------------------------------------
482 // wxPrinterDC Impl API
484 virtual wxRect
GetPaperRect()
485 { int w
= 0; int h
= 0; DoGetSize( &w
, &h
); return wxRect(0,0,w
,h
); }
487 virtual int GetResolution()
494 // unset clipping variables (after clipping region was destroyed)
499 m_clipX1
= m_clipX2
= m_clipY1
= m_clipY2
= 0;
502 // window on which the DC draws or NULL
509 bool m_isInteractive
:1;
510 bool m_isBBoxValid
:1;
512 // coordinate system variables
514 wxCoord m_logicalOriginX
, m_logicalOriginY
;
515 wxCoord m_deviceOriginX
, m_deviceOriginY
; // Usually 0,0, can be change by user
517 wxCoord m_deviceLocalOriginX
, m_deviceLocalOriginY
; // non-zero if native top-left corner
518 // is not at 0,0. This was the case under
519 // Mac's GrafPorts (coordinate system
520 // used toplevel window's origin) and
521 // e.g. for Postscript, where the native
522 // origin in the bottom left corner.
523 double m_logicalScaleX
, m_logicalScaleY
;
524 double m_userScaleX
, m_userScaleY
;
525 double m_scaleX
, m_scaleY
; // calculated from logical scale and user scale
527 int m_signX
, m_signY
; // Used by SetAxisOrientation() to invert the axes
529 // what is a mm on a screen you don't know the size of?
530 double m_mm_to_pix_x
,
533 // bounding and clipping boxes
534 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
535 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
537 int m_logicalFunction
;
538 int m_backgroundMode
;
543 wxBrush m_backgroundBrush
;
544 wxColour m_textForegroundColour
;
545 wxColour m_textBackgroundColour
;
550 bool m_hasCustomPalette
;
551 #endif // wxUSE_PALETTE
554 DECLARE_ABSTRACT_CLASS(wxDCImpl
)
558 class WXDLLIMPEXP_CORE wxDC
: public wxObject
561 virtual ~wxDC() { delete m_pimpl
; }
565 const wxDCImpl
*GetImpl() const
568 wxWindow
*GetWindow()
569 { return m_pimpl
->GetWindow(); }
572 { return m_pimpl
&& m_pimpl
->IsOk(); }
574 // query capabilities
576 bool CanDrawBitmap() const
577 { return m_pimpl
->CanDrawBitmap(); }
578 bool CanGetTextExtent() const
579 { return m_pimpl
->CanGetTextExtent(); }
581 // query dimension, colour deps, resolution
583 void GetSize(int *width
, int *height
) const
584 { m_pimpl
->DoGetSize(width
, height
); }
585 wxSize
GetSize() const
586 { return m_pimpl
->GetSize(); }
588 void GetSizeMM(int* width
, int* height
) const
589 { m_pimpl
->DoGetSizeMM(width
, height
); }
590 wxSize
GetSizeMM() const
593 m_pimpl
->DoGetSizeMM(&w
, &h
);
598 { return m_pimpl
->GetDepth(); }
599 wxSize
GetPPI() const
600 { return m_pimpl
->GetPPI(); }
602 virtual int GetResolution()
603 { return m_pimpl
->GetResolution(); }
605 // Right-To-Left (RTL) modes
607 void SetLayoutDirection(wxLayoutDirection dir
)
608 { m_pimpl
->SetLayoutDirection( dir
); }
609 wxLayoutDirection
GetLayoutDirection() const
610 { return m_pimpl
->GetLayoutDirection(); }
614 bool StartDoc(const wxString
& message
)
615 { return m_pimpl
->StartDoc(message
); }
617 { m_pimpl
->EndDoc(); }
620 { m_pimpl
->StartPage(); }
622 { m_pimpl
->EndPage(); }
626 void CalcBoundingBox(wxCoord x
, wxCoord y
)
627 { m_pimpl
->CalcBoundingBox(x
,y
); }
628 void ResetBoundingBox()
629 { m_pimpl
->ResetBoundingBox(); }
632 { return m_pimpl
->MinX(); }
634 { return m_pimpl
->MaxX(); }
636 { return m_pimpl
->MinY(); }
638 { return m_pimpl
->MaxY(); }
640 // setters and getters
642 void SetFont(const wxFont
& font
)
643 { m_pimpl
->SetFont( font
); }
644 const wxFont
& GetFont() const
645 { return m_pimpl
->GetFont(); }
647 void SetPen(const wxPen
& pen
)
648 { m_pimpl
->SetPen( pen
); }
649 const wxPen
& GetPen() const
650 { return m_pimpl
->GetPen(); }
652 void SetBrush(const wxBrush
& brush
)
653 { m_pimpl
->SetBrush( brush
); }
654 const wxBrush
& GetBrush() const
655 { return m_pimpl
->GetBrush(); }
657 void SetBackground(const wxBrush
& brush
)
658 { m_pimpl
->SetBackground( brush
); }
659 const wxBrush
& GetBackground() const
660 { return m_pimpl
->GetBackground(); }
662 void SetBackgroundMode(int mode
)
663 { m_pimpl
->SetBackgroundMode( mode
); }
664 int GetBackgroundMode() const
665 { return m_pimpl
->GetBackgroundMode(); }
667 void SetTextForeground(const wxColour
& colour
)
668 { m_pimpl
->SetTextForeground(colour
); }
669 const wxColour
& GetTextForeground() const
670 { return m_pimpl
->GetTextForeground(); }
672 void SetTextBackground(const wxColour
& colour
)
673 { m_pimpl
->SetTextBackground(colour
); }
674 const wxColour
& GetTextBackground() const
675 { return m_pimpl
->GetTextBackground(); }
678 void SetPalette(const wxPalette
& palette
)
679 { m_pimpl
->SetPalette(palette
); }
680 #endif // wxUSE_PALETTE
684 void SetLogicalFunction(int function
)
685 { m_pimpl
->SetLogicalFunction(function
); }
686 int GetLogicalFunction() const
687 { return m_pimpl
->GetLogicalFunction(); }
691 wxCoord
GetCharHeight() const
692 { return m_pimpl
->GetCharHeight(); }
693 wxCoord
GetCharWidth() const
694 { return m_pimpl
->GetCharWidth(); }
696 void GetTextExtent(const wxString
& string
,
697 wxCoord
*x
, wxCoord
*y
,
698 wxCoord
*descent
= NULL
,
699 wxCoord
*externalLeading
= NULL
,
700 const wxFont
*theFont
= NULL
) const
701 { m_pimpl
->DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
703 wxSize
GetTextExtent(const wxString
& string
) const
706 m_pimpl
->DoGetTextExtent(string
, &w
, &h
);
710 void GetMultiLineTextExtent(const wxString
& string
,
713 wxCoord
*heightLine
= NULL
,
714 const wxFont
*font
= NULL
) const
715 { m_pimpl
->GetMultiLineTextExtent( string
, width
, height
, heightLine
, font
); }
717 wxSize
GetMultiLineTextExtent(const wxString
& string
) const
720 m_pimpl
->GetMultiLineTextExtent(string
, &w
, &h
);
724 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
725 { return m_pimpl
->DoGetPartialTextExtents(text
, widths
); }
730 { m_pimpl
->Clear(); }
734 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
735 { m_pimpl
->DoSetClippingRegion(x
, y
, width
, height
); }
736 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
737 { m_pimpl
->DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
738 void SetClippingRegion(const wxRect
& rect
)
739 { m_pimpl
->DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
740 void SetClippingRegion(const wxRegion
& region
)
741 { m_pimpl
->DoSetClippingRegionAsRegion(region
); }
743 void DestroyClippingRegion()
744 { m_pimpl
->DestroyClippingRegion(); }
746 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
747 { m_pimpl
->DoGetClippingBox(x
, y
, w
, h
); }
748 void GetClippingBox(wxRect
& rect
) const
749 { m_pimpl
->DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
751 // coordinates conversions and transforms
753 wxCoord
DeviceToLogicalX(wxCoord x
) const
754 { return m_pimpl
->DeviceToLogicalX(x
); }
755 wxCoord
DeviceToLogicalY(wxCoord y
) const
756 { return m_pimpl
->DeviceToLogicalY(y
); }
757 wxCoord
DeviceToLogicalXRel(wxCoord x
) const
758 { return m_pimpl
->DeviceToLogicalXRel(x
); }
759 wxCoord
DeviceToLogicalYRel(wxCoord y
) const
760 { return m_pimpl
->DeviceToLogicalYRel(y
); }
761 wxCoord
LogicalToDeviceX(wxCoord x
) const
762 { return m_pimpl
->LogicalToDeviceX(x
); }
763 wxCoord
LogicalToDeviceY(wxCoord y
) const
764 { return m_pimpl
->LogicalToDeviceY(y
); }
765 wxCoord
LogicalToDeviceXRel(wxCoord x
) const
766 { return m_pimpl
->LogicalToDeviceXRel(x
); }
767 wxCoord
LogicalToDeviceYRel(wxCoord y
) const
768 { return m_pimpl
->LogicalToDeviceYRel(y
); }
770 void SetMapMode(int mode
)
771 { m_pimpl
->SetMapMode(mode
); }
772 int GetMapMode() const
773 { return m_pimpl
->GetMapMode(); }
775 void SetUserScale(double x
, double y
)
776 { m_pimpl
->SetUserScale(x
,y
); }
777 void GetUserScale(double *x
, double *y
) const
778 { m_pimpl
->GetUserScale( x
, y
); }
780 void SetLogicalScale(double x
, double y
)
781 { m_pimpl
->SetLogicalScale( x
, y
); }
782 void GetLogicalScale(double *x
, double *y
)
783 { m_pimpl
->GetLogicalScale( x
, y
); }
785 void SetLogicalOrigin(wxCoord x
, wxCoord y
)
786 { m_pimpl
->SetLogicalOrigin(x
,y
); }
787 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
788 { m_pimpl
->DoGetLogicalOrigin(x
, y
); }
789 wxPoint
GetLogicalOrigin() const
790 { wxCoord x
, y
; m_pimpl
->DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
792 void SetDeviceOrigin(wxCoord x
, wxCoord y
)
793 { m_pimpl
->SetDeviceOrigin( x
, y
); }
794 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
795 { m_pimpl
->DoGetDeviceOrigin(x
, y
); }
796 wxPoint
GetDeviceOrigin() const
797 { wxCoord x
, y
; m_pimpl
->DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
799 void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
800 { m_pimpl
->SetAxisOrientation(xLeftRight
, yBottomUp
); }
803 void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
)
804 { m_pimpl
->SetDeviceLocalOrigin( x
, y
); }
807 // draw generic object
809 void DrawObject(wxDrawObject
* drawobject
)
811 drawobject
->Draw(*this);
812 CalcBoundingBox(drawobject
->MinX(),drawobject
->MinY());
813 CalcBoundingBox(drawobject
->MaxX(),drawobject
->MaxY());
816 // -----------------------------------------------
817 // the actual drawing API
819 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
820 int style
= wxFLOOD_SURFACE
)
821 { return m_pimpl
->DoFloodFill(x
, y
, col
, style
); }
822 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
823 int style
= wxFLOOD_SURFACE
)
824 { return m_pimpl
->DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
826 // fill the area specified by rect with a radial gradient, starting from
827 // initialColour in the centre of the cercle and fading to destColour.
828 void GradientFillConcentric(const wxRect
& rect
,
829 const wxColour
& initialColour
,
830 const wxColour
& destColour
)
831 { m_pimpl
->DoGradientFillConcentric( rect
, initialColour
, destColour
,
832 wxPoint(rect
.GetWidth() / 2,
833 rect
.GetHeight() / 2)); }
835 void GradientFillConcentric(const wxRect
& rect
,
836 const wxColour
& initialColour
,
837 const wxColour
& destColour
,
838 const wxPoint
& circleCenter
)
839 { m_pimpl
->DoGradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
841 // fill the area specified by rect with a linear gradient
842 void GradientFillLinear(const wxRect
& rect
,
843 const wxColour
& initialColour
,
844 const wxColour
& destColour
,
845 wxDirection nDirection
= wxEAST
)
846 { m_pimpl
->DoGradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
848 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
849 { return m_pimpl
->DoGetPixel(x
, y
, col
); }
850 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
851 { return m_pimpl
->DoGetPixel(pt
.x
, pt
.y
, col
); }
853 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
854 { m_pimpl
->DoDrawLine(x1
, y1
, x2
, y2
); }
855 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
856 { m_pimpl
->DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
858 void CrossHair(wxCoord x
, wxCoord y
)
859 { m_pimpl
->DoCrossHair(x
, y
); }
860 void CrossHair(const wxPoint
& pt
)
861 { m_pimpl
->DoCrossHair(pt
.x
, pt
.y
); }
863 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
864 wxCoord xc
, wxCoord yc
)
865 { m_pimpl
->DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
866 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
867 { m_pimpl
->DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
869 void DrawCheckMark(wxCoord x
, wxCoord y
,
870 wxCoord width
, wxCoord height
)
871 { m_pimpl
->DoDrawCheckMark(x
, y
, width
, height
); }
872 void DrawCheckMark(const wxRect
& rect
)
873 { m_pimpl
->DoDrawCheckMark(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
875 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
876 double sa
, double ea
)
877 { m_pimpl
->DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
878 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
879 double sa
, double ea
)
880 { m_pimpl
->DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
882 void DrawPoint(wxCoord x
, wxCoord y
)
883 { m_pimpl
->DoDrawPoint(x
, y
); }
884 void DrawPoint(const wxPoint
& pt
)
885 { m_pimpl
->DoDrawPoint(pt
.x
, pt
.y
); }
887 void DrawLines(int n
, wxPoint points
[],
888 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
889 { m_pimpl
->DoDrawLines(n
, points
, xoffset
, yoffset
); }
890 void DrawLines(const wxPointList
*list
,
891 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
892 { m_pimpl
->DrawLines( list
, xoffset
, yoffset
); }
893 #if WXWIN_COMPATIBILITY_2_8
894 wxDEPRECATED( void DrawLines(const wxList
*list
,
895 wxCoord xoffset
= 0, wxCoord yoffset
= 0) );
896 #endif // WXWIN_COMPATIBILITY_2_8
898 void DrawPolygon(int n
, wxPoint points
[],
899 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
900 int fillStyle
= wxODDEVEN_RULE
)
901 { m_pimpl
->DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
902 void DrawPolygon(const wxPointList
*list
,
903 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
904 int fillStyle
= wxODDEVEN_RULE
)
905 { m_pimpl
->DrawPolygon( list
, xoffset
, yoffset
, fillStyle
); }
906 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
907 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
908 int fillStyle
= wxODDEVEN_RULE
)
909 { m_pimpl
->DoDrawPolyPolygon(n
, count
, points
, xoffset
, yoffset
, fillStyle
); }
910 #if WXWIN_COMPATIBILITY_2_8
911 wxDEPRECATED( void DrawPolygon(const wxList
*list
,
912 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
913 int fillStyle
= wxODDEVEN_RULE
) );
914 #endif // WXWIN_COMPATIBILITY_2_8
916 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
917 { m_pimpl
->DoDrawRectangle(x
, y
, width
, height
); }
918 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
919 { m_pimpl
->DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
920 void DrawRectangle(const wxRect
& rect
)
921 { m_pimpl
->DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
923 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
925 { m_pimpl
->DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
926 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
928 { m_pimpl
->DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
929 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
930 { m_pimpl
->DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
932 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
933 { m_pimpl
->DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
934 void DrawCircle(const wxPoint
& pt
, wxCoord radius
)
935 { m_pimpl
->DoDrawEllipse(pt
.x
- radius
, pt
.y
- radius
, 2*radius
, 2*radius
); }
937 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
938 { m_pimpl
->DoDrawEllipse(x
, y
, width
, height
); }
939 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
940 { m_pimpl
->DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
941 void DrawEllipse(const wxRect
& rect
)
942 { m_pimpl
->DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
944 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
945 { m_pimpl
->DoDrawIcon(icon
, x
, y
); }
946 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
947 { m_pimpl
->DoDrawIcon(icon
, pt
.x
, pt
.y
); }
949 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
950 bool useMask
= false)
951 { m_pimpl
->DoDrawBitmap(bmp
, x
, y
, useMask
); }
952 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
953 bool useMask
= false)
954 { m_pimpl
->DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
956 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
957 { m_pimpl
->DoDrawText(text
, x
, y
); }
958 void DrawText(const wxString
& text
, const wxPoint
& pt
)
959 { m_pimpl
->DoDrawText(text
, pt
.x
, pt
.y
); }
961 void DrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
962 { m_pimpl
->DoDrawRotatedText(text
, x
, y
, angle
); }
963 void DrawRotatedText(const wxString
& text
, const wxPoint
& pt
, double angle
)
964 { m_pimpl
->DoDrawRotatedText(text
, pt
.x
, pt
.y
, angle
); }
966 // this version puts both optional bitmap and the text into the given
967 // rectangle and aligns is as specified by alignment parameter; it also
968 // will emphasize the character with the given index if it is != -1 and
969 // return the bounding rectangle if required
970 void DrawLabel(const wxString
& text
,
971 const wxBitmap
& image
,
973 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
975 wxRect
*rectBounding
= NULL
);
977 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
978 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
980 { DrawLabel(text
, wxNullBitmap
, rect
, alignment
, indexAccel
); }
982 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
983 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
984 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
986 return m_pimpl
->DoBlit(xdest
, ydest
, width
, height
,
987 source
, xsrc
, ysrc
, rop
, useMask
, xsrcMask
, ysrcMask
);
989 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
990 wxDC
*source
, const wxPoint
& srcPt
,
991 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
993 return m_pimpl
->DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
994 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
, srcPtMask
.x
, srcPtMask
.y
);
997 bool StretchBlit(wxCoord dstX
, wxCoord dstY
,
998 wxCoord dstWidth
, wxCoord dstHeight
,
1000 wxCoord srcX
, wxCoord srcY
,
1001 wxCoord srcWidth
, wxCoord srcHeight
,
1002 int rop
= wxCOPY
, bool useMask
= false,
1003 wxCoord srcMaskX
= wxDefaultCoord
, wxCoord srcMaskY
= wxDefaultCoord
)
1005 return m_pimpl
->DoStretchBlit(dstX
, dstY
, dstWidth
, dstHeight
,
1006 source
, srcX
, srcY
, srcWidth
, srcHeight
, rop
, useMask
, srcMaskX
, srcMaskY
);
1008 bool StretchBlit(const wxPoint
& dstPt
, const wxSize
& dstSize
,
1009 wxDC
*source
, const wxPoint
& srcPt
, const wxSize
& srcSize
,
1010 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcMaskPt
= wxDefaultPosition
)
1012 return m_pimpl
->DoStretchBlit(dstPt
.x
, dstPt
.y
, dstSize
.x
, dstSize
.y
,
1013 source
, srcPt
.x
, srcPt
.y
, srcSize
.x
, srcSize
.y
, rop
, useMask
, srcMaskPt
.x
, srcMaskPt
.y
);
1016 wxBitmap
GetAsBitmap(const wxRect
*subrect
= (const wxRect
*) NULL
) const
1018 return m_pimpl
->DoGetAsBitmap(subrect
);
1022 void DrawSpline(wxCoord x1
, wxCoord y1
,
1023 wxCoord x2
, wxCoord y2
,
1024 wxCoord x3
, wxCoord y3
)
1025 { m_pimpl
->DoDrawSpline(x1
,y1
,x2
,y2
,x3
,y3
); }
1026 void DrawSpline(int n
, wxPoint points
[])
1027 { m_pimpl
->DoDrawSpline(n
,points
); }
1028 void DrawSpline(const wxPointList
*points
)
1029 { m_pimpl
->DoDrawSpline(points
); }
1030 #endif // wxUSE_SPLINES
1033 #if WXWIN_COMPATIBILITY_2_8
1034 // for compatibility with the old code when wxCoord was long everywhere
1035 wxDEPRECATED( void GetTextExtent(const wxString
& string
,
1037 long *descent
= NULL
,
1038 long *externalLeading
= NULL
,
1039 const wxFont
*theFont
= NULL
) const );
1040 wxDEPRECATED( void GetLogicalOrigin(long *x
, long *y
) const );
1041 wxDEPRECATED( void GetDeviceOrigin(long *x
, long *y
) const );
1042 wxDEPRECATED( void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const );
1043 #endif // WXWIN_COMPATIBILITY_2_8
1047 // ctor takes ownership of the pointer
1048 wxDC(wxDCImpl
*pimpl
) : m_pimpl(pimpl
) { }
1050 wxDCImpl
* const m_pimpl
;
1053 DECLARE_ABSTRACT_CLASS(wxDC
)
1054 DECLARE_NO_COPY_CLASS(wxDC
)
1057 // ----------------------------------------------------------------------------
1058 // helper class: you can use it to temporarily change the DC text colour and
1059 // restore it automatically when the object goes out of scope
1060 // ----------------------------------------------------------------------------
1062 class WXDLLEXPORT wxDCTextColourChanger
1065 wxDCTextColourChanger(wxDC
& dc
) : m_dc(dc
), m_colFgOld() { }
1067 wxDCTextColourChanger(wxDC
& dc
, const wxColour
& col
) : m_dc(dc
)
1072 ~wxDCTextColourChanger()
1074 if ( m_colFgOld
.Ok() )
1075 m_dc
.SetTextForeground(m_colFgOld
);
1078 void Set(const wxColour
& col
)
1080 if ( !m_colFgOld
.Ok() )
1081 m_colFgOld
= m_dc
.GetTextForeground();
1082 m_dc
.SetTextForeground(col
);
1088 wxColour m_colFgOld
;
1090 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger
)
1093 // ----------------------------------------------------------------------------
1094 // helper class: you can use it to temporarily change the DC pen and
1095 // restore it automatically when the object goes out of scope
1096 // ----------------------------------------------------------------------------
1098 class WXDLLEXPORT wxDCPenChanger
1101 wxDCPenChanger(wxDC
& dc
, const wxPen
& pen
) : m_dc(dc
), m_penOld(dc
.GetPen())
1108 if ( m_penOld
.Ok() )
1109 m_dc
.SetPen(m_penOld
);
1117 DECLARE_NO_COPY_CLASS(wxDCPenChanger
)
1120 // ----------------------------------------------------------------------------
1121 // helper class: you can use it to temporarily change the DC brush and
1122 // restore it automatically when the object goes out of scope
1123 // ----------------------------------------------------------------------------
1125 class WXDLLEXPORT wxDCBrushChanger
1128 wxDCBrushChanger(wxDC
& dc
, const wxBrush
& brush
) : m_dc(dc
), m_brushOld(dc
.GetBrush())
1130 m_dc
.SetBrush(brush
);
1135 if ( m_brushOld
.Ok() )
1136 m_dc
.SetBrush(m_brushOld
);
1144 DECLARE_NO_COPY_CLASS(wxDCBrushChanger
)
1147 // ----------------------------------------------------------------------------
1148 // another small helper class: sets the clipping region in its ctor and
1149 // destroys it in the dtor
1150 // ----------------------------------------------------------------------------
1152 class WXDLLEXPORT wxDCClipper
1155 wxDCClipper(wxDC
& dc
, const wxRegion
& r
) : m_dc(dc
)
1156 { dc
.SetClippingRegion(r
); }
1157 wxDCClipper(wxDC
& dc
, const wxRect
& r
) : m_dc(dc
)
1158 { dc
.SetClippingRegion(r
.x
, r
.y
, r
.width
, r
.height
); }
1159 wxDCClipper(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) : m_dc(dc
)
1160 { dc
.SetClippingRegion(x
, y
, w
, h
); }
1162 ~wxDCClipper() { m_dc
.DestroyClippingRegion(); }
1167 DECLARE_NO_COPY_CLASS(wxDCClipper
)
1170 #endif // _WX_DC_H_BASE_