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 virtual wxDCImpl
* CreatePrinterDC( wxPrinterDC
*owner
, const wxPrintData
&data
) = 0;
130 static void SetDCFactory( wxDCFactory
*factory
);
131 static wxDCFactory
*GetFactory();
133 static wxDCFactory
*m_factory
;
136 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
140 class WXDLLIMPEXP_CORE wxNativeDCFactory
: public wxDCFactory
143 wxNativeDCFactory() {}
145 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
);
146 virtual wxDCImpl
* CreateWindowDC( wxWindowDC
*owner
, wxWindow
*window
);
147 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
);
148 virtual wxDCImpl
* CreateClientDC( wxClientDC
*owner
, wxWindow
*window
);
149 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
);
150 virtual wxDCImpl
* CreatePaintDC( wxPaintDC
*owner
, wxWindow
*window
);
151 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
);
152 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxBitmap
&bitmap
);
153 virtual wxDCImpl
* CreateMemoryDC( wxMemoryDC
*owner
, wxDC
*dc
);
154 virtual wxDCImpl
* CreateScreenDC( wxScreenDC
*owner
);
155 virtual wxDCImpl
* CreatePrinterDC( wxPrinterDC
*owner
, const wxPrintData
&data
);
158 //-----------------------------------------------------------------------------
160 //-----------------------------------------------------------------------------
162 class WXDLLIMPEXP_CORE wxDCImpl
: public wxObject
165 wxDCImpl( wxDC
*owner
);
168 wxDC
*GetOwner() const { return m_owner
; }
170 wxWindow
* GetWindow() const { return m_window
; }
172 virtual bool IsOk() const { return m_ok
; }
174 // query capabilities
176 virtual bool CanDrawBitmap() const = 0;
177 virtual bool CanGetTextExtent() const = 0;
179 // query dimension, colour deps, resolution
181 virtual void DoGetSize(int *width
, int *height
) const = 0;
182 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
184 virtual int GetDepth() const = 0;
185 virtual wxSize
GetPPI() const = 0;
187 // Right-To-Left (RTL) modes
189 virtual void SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
)) { }
190 virtual wxLayoutDirection
GetLayoutDirection() const { return wxLayout_Default
; }
194 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return true; }
195 virtual void EndDoc() { }
197 virtual void StartPage() { }
198 virtual void EndPage() { }
200 // flushing the content of this dc immediately eg onto screen
201 virtual void Flush() { }
205 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
209 if ( x
< m_minX
) m_minX
= x
;
210 if ( y
< m_minY
) m_minY
= y
;
211 if ( x
> m_maxX
) m_maxX
= x
;
212 if ( y
> m_maxY
) m_maxY
= y
;
216 m_isBBoxValid
= true;
224 void ResetBoundingBox()
226 m_isBBoxValid
= false;
228 m_minX
= m_maxX
= m_minY
= m_maxY
= 0;
231 wxCoord
MinX() const { return m_minX
; }
232 wxCoord
MaxX() const { return m_maxX
; }
233 wxCoord
MinY() const { return m_minY
; }
234 wxCoord
MaxY() const { return m_maxY
; }
236 // setters and getters
238 virtual void SetFont(const wxFont
& font
) = 0;
239 virtual const wxFont
& GetFont() const { return m_font
; }
241 virtual void SetPen(const wxPen
& pen
) = 0;
242 virtual const wxPen
& GetPen() const { return m_pen
; }
244 virtual void SetBrush(const wxBrush
& brush
) = 0;
245 virtual const wxBrush
& GetBrush() const { return m_brush
; }
247 virtual void SetBackground(const wxBrush
& brush
) = 0;
248 virtual const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
250 virtual void SetBackgroundMode(int mode
) = 0;
251 virtual int GetBackgroundMode() const { return m_backgroundMode
; }
253 virtual void SetTextForeground(const wxColour
& colour
)
254 { m_textForegroundColour
= colour
; }
255 virtual const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
257 virtual void SetTextBackground(const wxColour
& colour
)
258 { m_textBackgroundColour
= colour
; }
259 virtual const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
262 virtual void SetPalette(const wxPalette
& palette
) = 0;
263 #endif // wxUSE_PALETTE
267 virtual void SetLogicalFunction(int function
) = 0;
268 virtual int GetLogicalFunction() const { return m_logicalFunction
; }
272 virtual wxCoord
GetCharHeight() const = 0;
273 virtual wxCoord
GetCharWidth() const = 0;
274 virtual void DoGetTextExtent(const wxString
& string
,
275 wxCoord
*x
, wxCoord
*y
,
276 wxCoord
*descent
= NULL
,
277 wxCoord
*externalLeading
= NULL
,
278 const wxFont
*theFont
= NULL
) const = 0;
279 virtual void GetMultiLineTextExtent(const wxString
& string
,
282 wxCoord
*heightLine
= NULL
,
283 const wxFont
*font
= NULL
) const;
284 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
288 virtual void Clear() = 0;
292 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
293 wxCoord width
, wxCoord height
) = 0;
294 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
296 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
297 wxCoord
*w
, wxCoord
*h
) const
304 *w
= m_clipX2
- m_clipX1
;
306 *h
= m_clipY2
- m_clipY1
;
309 virtual void DestroyClippingRegion() { ResetClipping(); }
312 // coordinates conversions and transforms
314 virtual wxCoord
DeviceToLogicalX(wxCoord x
) const;
315 virtual wxCoord
DeviceToLogicalY(wxCoord y
) const;
316 virtual wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
317 virtual wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
318 virtual wxCoord
LogicalToDeviceX(wxCoord x
) const;
319 virtual wxCoord
LogicalToDeviceY(wxCoord y
) const;
320 virtual wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
321 virtual wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
323 virtual void SetMapMode(int mode
);
324 virtual int GetMapMode() const { return m_mappingMode
; }
326 virtual void SetUserScale(double x
, double y
);
327 virtual void GetUserScale(double *x
, double *y
) const
329 if ( x
) *x
= m_userScaleX
;
330 if ( y
) *y
= m_userScaleY
;
333 virtual void SetLogicalScale(double x
, double y
);
334 virtual void GetLogicalScale(double *x
, double *y
)
336 if ( x
) *x
= m_logicalScaleX
;
337 if ( y
) *y
= m_logicalScaleY
;
340 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
341 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
343 if ( x
) *x
= m_logicalOriginX
;
344 if ( y
) *y
= m_logicalOriginY
;
347 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
348 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
350 if ( x
) *x
= m_deviceOriginX
;
351 if ( y
) *y
= m_deviceOriginY
;
354 virtual void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
);
356 virtual void ComputeScaleAndOrigin();
358 // this needs to overidden if the axis is inverted
359 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
361 // ---------------------------------------------------------
362 // the actual drawing API
364 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
365 int style
= wxFLOOD_SURFACE
) = 0;
367 virtual void DoGradientFillLinear(const wxRect
& rect
,
368 const wxColour
& initialColour
,
369 const wxColour
& destColour
,
370 wxDirection nDirection
= wxEAST
);
372 virtual void DoGradientFillConcentric(const wxRect
& rect
,
373 const wxColour
& initialColour
,
374 const wxColour
& destColour
,
375 const wxPoint
& circleCenter
);
377 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
379 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
380 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
382 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
383 wxCoord x2
, wxCoord y2
,
384 wxCoord xc
, wxCoord yc
) = 0;
385 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
386 wxCoord width
, wxCoord height
);
387 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
388 double sa
, double ea
) = 0;
390 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
391 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
392 wxCoord width
, wxCoord height
,
394 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
395 wxCoord width
, wxCoord height
) = 0;
397 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
399 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
400 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
401 bool useMask
= false) = 0;
403 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
404 virtual void DoDrawRotatedText(const wxString
& text
,
405 wxCoord x
, wxCoord y
, double angle
) = 0;
407 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
408 wxCoord width
, wxCoord height
,
410 wxCoord xsrc
, wxCoord ysrc
,
412 bool useMask
= false,
413 wxCoord xsrcMask
= wxDefaultCoord
,
414 wxCoord ysrcMask
= wxDefaultCoord
) = 0;
416 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
417 wxCoord dstWidth
, wxCoord dstHeight
,
419 wxCoord xsrc
, wxCoord ysrc
,
420 wxCoord srcWidth
, wxCoord srcHeight
,
422 bool useMask
= false,
423 wxCoord xsrcMask
= wxDefaultCoord
,
424 wxCoord ysrcMask
= wxDefaultCoord
);
426 virtual wxBitmap
DoGetAsBitmap(const wxRect
*WXUNUSED(subrect
)) const
427 { return wxNullBitmap
; }
430 virtual void DoDrawLines(int n
, wxPoint points
[],
431 wxCoord xoffset
, wxCoord yoffset
) = 0;
432 virtual void DrawLines(const wxPointList
*list
,
433 wxCoord xoffset
, wxCoord yoffset
);
435 virtual void DoDrawPolygon(int n
, wxPoint points
[],
436 wxCoord xoffset
, wxCoord yoffset
,
437 int fillStyle
= wxODDEVEN_RULE
) = 0;
438 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
439 wxCoord xoffset
, wxCoord yoffset
,
441 void DrawPolygon(const wxPointList
*list
,
442 wxCoord xoffset
, wxCoord yoffset
,
447 virtual void DoDrawSpline(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord x3
, wxCoord y3
);
448 virtual void DoDrawSpline(int n
, wxPoint points
[]);
449 virtual void DoDrawSpline(const wxPointList
*points
);
452 // ---------------------------------------------------------
453 // wxMemoryDC Impl API
455 virtual void DoSelect(const wxBitmap
& WXUNUSED(bmp
))
458 virtual const wxBitmap
& GetSelectedBitmap() const
459 { return wxNullBitmap
; }
460 virtual wxBitmap
& GetSelectedBitmap()
461 { return wxNullBitmap
; }
463 // ---------------------------------------------------------
464 // wxPrinterDC Impl API
466 virtual wxRect
GetPaperRect()
467 { int w
= 0; int h
= 0; DoGetSize( &w
, &h
); return wxRect(0,0,w
,h
); }
469 virtual int GetResolution()
476 // unset clipping variables (after clipping region was destroyed)
481 m_clipX1
= m_clipX2
= m_clipY1
= m_clipY2
= 0;
484 // window on which the DC draws or NULL
491 bool m_isInteractive
:1;
492 bool m_isBBoxValid
:1;
494 // coordinate system variables
496 wxCoord m_logicalOriginX
, m_logicalOriginY
;
497 wxCoord m_deviceOriginX
, m_deviceOriginY
; // Usually 0,0, can be change by user
499 wxCoord m_deviceLocalOriginX
, m_deviceLocalOriginY
; // non-zero if native top-left corner
500 // is not at 0,0. This was the case under
501 // Mac's GrafPorts (coordinate system
502 // used toplevel window's origin) and
503 // e.g. for Postscript, where the native
504 // origin in the bottom left corner.
505 double m_logicalScaleX
, m_logicalScaleY
;
506 double m_userScaleX
, m_userScaleY
;
507 double m_scaleX
, m_scaleY
; // calculated from logical scale and user scale
509 int m_signX
, m_signY
; // Used by SetAxisOrientation() to invert the axes
511 // what is a mm on a screen you don't know the size of?
512 double m_mm_to_pix_x
,
515 // bounding and clipping boxes
516 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
517 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
519 int m_logicalFunction
;
520 int m_backgroundMode
;
525 wxBrush m_backgroundBrush
;
526 wxColour m_textForegroundColour
;
527 wxColour m_textBackgroundColour
;
532 bool m_hasCustomPalette
;
533 #endif // wxUSE_PALETTE
536 DECLARE_ABSTRACT_CLASS(wxDCImpl
)
540 class WXDLLIMPEXP_CORE wxDC
: public wxObject
543 wxDC() { m_pimpl
= NULL
; }
544 ~wxDC() { if (m_pimpl
) delete m_pimpl
; }
548 const wxDCImpl
*GetImpl() const
551 wxWindow
*GetWindow()
552 { return m_pimpl
->GetWindow(); }
555 { return m_pimpl
&& m_pimpl
->IsOk(); }
557 // query capabilities
559 bool CanDrawBitmap() const
560 { return m_pimpl
->CanDrawBitmap(); }
561 bool CanGetTextExtent() const
562 { return m_pimpl
->CanGetTextExtent(); }
564 // query dimension, colour deps, resolution
566 void GetSize(int *width
, int *height
) const
567 { m_pimpl
->DoGetSize(width
, height
); }
569 wxSize
GetSize() const
572 m_pimpl
->DoGetSize(&w
, &h
);
576 void GetSizeMM(int* width
, int* height
) const
577 { m_pimpl
->DoGetSizeMM(width
, height
); }
578 wxSize
GetSizeMM() const
581 m_pimpl
->DoGetSizeMM(&w
, &h
);
586 { return m_pimpl
->GetDepth(); }
587 wxSize
GetPPI() const
588 { return m_pimpl
->GetPPI(); }
590 virtual int GetResolution()
591 { return m_pimpl
->GetResolution(); }
593 // Right-To-Left (RTL) modes
595 void SetLayoutDirection(wxLayoutDirection dir
)
596 { m_pimpl
->SetLayoutDirection( dir
); }
597 wxLayoutDirection
GetLayoutDirection() const
598 { return m_pimpl
->GetLayoutDirection(); }
602 bool StartDoc(const wxString
& message
)
603 { return m_pimpl
->StartDoc(message
); }
605 { m_pimpl
->EndDoc(); }
608 { m_pimpl
->StartPage(); }
610 { m_pimpl
->EndPage(); }
614 void CalcBoundingBox(wxCoord x
, wxCoord y
)
615 { m_pimpl
->CalcBoundingBox(x
,y
); }
616 void ResetBoundingBox()
617 { m_pimpl
->ResetBoundingBox(); }
620 { return m_pimpl
->MinX(); }
622 { return m_pimpl
->MaxX(); }
624 { return m_pimpl
->MinY(); }
626 { return m_pimpl
->MaxY(); }
628 // setters and getters
630 void SetFont(const wxFont
& font
)
631 { m_pimpl
->SetFont( font
); }
632 const wxFont
& GetFont() const
633 { return m_pimpl
->GetFont(); }
635 void SetPen(const wxPen
& pen
)
636 { m_pimpl
->SetPen( pen
); }
637 const wxPen
& GetPen() const
638 { return m_pimpl
->GetPen(); }
640 void SetBrush(const wxBrush
& brush
)
641 { m_pimpl
->SetBrush( brush
); }
642 const wxBrush
& GetBrush() const
643 { return m_pimpl
->GetBrush(); }
645 void SetBackground(const wxBrush
& brush
)
646 { m_pimpl
->SetBackground( brush
); }
647 const wxBrush
& GetBackground() const
648 { return m_pimpl
->GetBackground(); }
650 void SetBackgroundMode(int mode
)
651 { m_pimpl
->SetBackgroundMode( mode
); }
652 int GetBackgroundMode() const
653 { return m_pimpl
->GetBackgroundMode(); }
655 void SetTextForeground(const wxColour
& colour
)
656 { m_pimpl
->SetTextForeground(colour
); }
657 const wxColour
& GetTextForeground() const
658 { return m_pimpl
->GetTextForeground(); }
660 void SetTextBackground(const wxColour
& colour
)
661 { m_pimpl
->SetTextBackground(colour
); }
662 const wxColour
& GetTextBackground() const
663 { return m_pimpl
->GetTextBackground(); }
666 void SetPalette(const wxPalette
& palette
)
667 { m_pimpl
->SetPalette(palette
); }
668 #endif // wxUSE_PALETTE
672 void SetLogicalFunction(int function
)
673 { m_pimpl
->SetLogicalFunction(function
); }
674 int GetLogicalFunction() const
675 { return m_pimpl
->GetLogicalFunction(); }
679 wxCoord
GetCharHeight() const
680 { return m_pimpl
->GetCharHeight(); }
681 wxCoord
GetCharWidth() const
682 { return m_pimpl
->GetCharWidth(); }
684 void GetTextExtent(const wxString
& string
,
685 wxCoord
*x
, wxCoord
*y
,
686 wxCoord
*descent
= NULL
,
687 wxCoord
*externalLeading
= NULL
,
688 const wxFont
*theFont
= NULL
) const
689 { m_pimpl
->DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
691 wxSize
GetTextExtent(const wxString
& string
) const
694 m_pimpl
->DoGetTextExtent(string
, &w
, &h
);
698 void GetMultiLineTextExtent(const wxString
& string
,
701 wxCoord
*heightLine
= NULL
,
702 const wxFont
*font
= NULL
) const
703 { m_pimpl
->GetMultiLineTextExtent( string
, width
, height
, heightLine
, font
); }
705 wxSize
GetMultiLineTextExtent(const wxString
& string
) const
708 m_pimpl
->GetMultiLineTextExtent(string
, &w
, &h
);
712 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
713 { return m_pimpl
->DoGetPartialTextExtents(text
, widths
); }
718 { m_pimpl
->Clear(); }
722 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
723 { m_pimpl
->DoSetClippingRegion(x
, y
, width
, height
); }
724 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
725 { m_pimpl
->DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
726 void SetClippingRegion(const wxRect
& rect
)
727 { m_pimpl
->DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
728 void SetClippingRegion(const wxRegion
& region
)
729 { m_pimpl
->DoSetClippingRegionAsRegion(region
); }
731 void DestroyClippingRegion()
732 { m_pimpl
->DestroyClippingRegion(); }
734 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
735 { m_pimpl
->DoGetClippingBox(x
, y
, w
, h
); }
736 void GetClippingBox(wxRect
& rect
) const
737 { m_pimpl
->DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
739 // coordinates conversions and transforms
741 wxCoord
DeviceToLogicalX(wxCoord x
) const
742 { return m_pimpl
->DeviceToLogicalX(x
); }
743 wxCoord
DeviceToLogicalY(wxCoord y
) const
744 { return m_pimpl
->DeviceToLogicalY(y
); }
745 wxCoord
DeviceToLogicalXRel(wxCoord x
) const
746 { return m_pimpl
->DeviceToLogicalXRel(x
); }
747 wxCoord
DeviceToLogicalYRel(wxCoord y
) const
748 { return m_pimpl
->DeviceToLogicalYRel(y
); }
749 wxCoord
LogicalToDeviceX(wxCoord x
) const
750 { return m_pimpl
->LogicalToDeviceX(x
); }
751 wxCoord
LogicalToDeviceY(wxCoord y
) const
752 { return m_pimpl
->LogicalToDeviceY(y
); }
753 wxCoord
LogicalToDeviceXRel(wxCoord x
) const
754 { return m_pimpl
->LogicalToDeviceXRel(x
); }
755 wxCoord
LogicalToDeviceYRel(wxCoord y
) const
756 { return m_pimpl
->LogicalToDeviceYRel(y
); }
758 void SetMapMode(int mode
)
759 { m_pimpl
->SetMapMode(mode
); }
760 int GetMapMode() const
761 { return m_pimpl
->GetMapMode(); }
763 void SetUserScale(double x
, double y
)
764 { m_pimpl
->SetUserScale(x
,y
); }
765 void GetUserScale(double *x
, double *y
) const
766 { m_pimpl
->GetUserScale( x
, y
); }
768 void SetLogicalScale(double x
, double y
)
769 { m_pimpl
->SetLogicalScale( x
, y
); }
770 void GetLogicalScale(double *x
, double *y
)
771 { m_pimpl
->GetLogicalScale( x
, y
); }
773 void SetLogicalOrigin(wxCoord x
, wxCoord y
)
774 { m_pimpl
->SetLogicalOrigin(x
,y
); }
775 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
776 { m_pimpl
->DoGetLogicalOrigin(x
, y
); }
777 wxPoint
GetLogicalOrigin() const
778 { wxCoord x
, y
; m_pimpl
->DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
780 void SetDeviceOrigin(wxCoord x
, wxCoord y
)
781 { m_pimpl
->SetDeviceOrigin( x
, y
); }
782 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
783 { m_pimpl
->DoGetDeviceOrigin(x
, y
); }
784 wxPoint
GetDeviceOrigin() const
785 { wxCoord x
, y
; m_pimpl
->DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
787 void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
788 { m_pimpl
->SetAxisOrientation(xLeftRight
, yBottomUp
); }
791 void SetDeviceLocalOrigin( wxCoord x
, wxCoord y
)
792 { m_pimpl
->SetDeviceLocalOrigin( x
, y
); }
795 // draw generic object
797 void DrawObject(wxDrawObject
* drawobject
)
799 drawobject
->Draw(*this);
800 CalcBoundingBox(drawobject
->MinX(),drawobject
->MinY());
801 CalcBoundingBox(drawobject
->MaxX(),drawobject
->MaxY());
804 // -----------------------------------------------
805 // the actual drawing API
807 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
808 int style
= wxFLOOD_SURFACE
)
809 { return m_pimpl
->DoFloodFill(x
, y
, col
, style
); }
810 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
811 int style
= wxFLOOD_SURFACE
)
812 { return m_pimpl
->DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
814 // fill the area specified by rect with a radial gradient, starting from
815 // initialColour in the centre of the cercle and fading to destColour.
816 void GradientFillConcentric(const wxRect
& rect
,
817 const wxColour
& initialColour
,
818 const wxColour
& destColour
)
819 { m_pimpl
->DoGradientFillConcentric( rect
, initialColour
, destColour
,
820 wxPoint(rect
.GetWidth() / 2,
821 rect
.GetHeight() / 2)); }
823 void GradientFillConcentric(const wxRect
& rect
,
824 const wxColour
& initialColour
,
825 const wxColour
& destColour
,
826 const wxPoint
& circleCenter
)
827 { m_pimpl
->DoGradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
829 // fill the area specified by rect with a linear gradient
830 void GradientFillLinear(const wxRect
& rect
,
831 const wxColour
& initialColour
,
832 const wxColour
& destColour
,
833 wxDirection nDirection
= wxEAST
)
834 { m_pimpl
->DoGradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
836 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
837 { return m_pimpl
->DoGetPixel(x
, y
, col
); }
838 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
839 { return m_pimpl
->DoGetPixel(pt
.x
, pt
.y
, col
); }
841 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
842 { m_pimpl
->DoDrawLine(x1
, y1
, x2
, y2
); }
843 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
844 { m_pimpl
->DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
846 void CrossHair(wxCoord x
, wxCoord y
)
847 { m_pimpl
->DoCrossHair(x
, y
); }
848 void CrossHair(const wxPoint
& pt
)
849 { m_pimpl
->DoCrossHair(pt
.x
, pt
.y
); }
851 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
852 wxCoord xc
, wxCoord yc
)
853 { m_pimpl
->DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
854 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
855 { m_pimpl
->DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
857 void DrawCheckMark(wxCoord x
, wxCoord y
,
858 wxCoord width
, wxCoord height
)
859 { m_pimpl
->DoDrawCheckMark(x
, y
, width
, height
); }
860 void DrawCheckMark(const wxRect
& rect
)
861 { m_pimpl
->DoDrawCheckMark(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
863 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
864 double sa
, double ea
)
865 { m_pimpl
->DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
866 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
867 double sa
, double ea
)
868 { m_pimpl
->DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
870 void DrawPoint(wxCoord x
, wxCoord y
)
871 { m_pimpl
->DoDrawPoint(x
, y
); }
872 void DrawPoint(const wxPoint
& pt
)
873 { m_pimpl
->DoDrawPoint(pt
.x
, pt
.y
); }
875 void DrawLines(int n
, wxPoint points
[],
876 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
877 { m_pimpl
->DoDrawLines(n
, points
, xoffset
, yoffset
); }
878 void DrawLines(const wxPointList
*list
,
879 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
880 { m_pimpl
->DrawLines( list
, xoffset
, yoffset
); }
881 #if WXWIN_COMPATIBILITY_2_8
882 wxDEPRECATED( void DrawLines(const wxList
*list
,
883 wxCoord xoffset
= 0, wxCoord yoffset
= 0) );
884 #endif // WXWIN_COMPATIBILITY_2_8
886 void DrawPolygon(int n
, wxPoint points
[],
887 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
888 int fillStyle
= wxODDEVEN_RULE
)
889 { m_pimpl
->DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
890 void DrawPolygon(const wxPointList
*list
,
891 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
892 int fillStyle
= wxODDEVEN_RULE
)
893 { m_pimpl
->DrawPolygon( list
, xoffset
, yoffset
, fillStyle
); }
894 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
895 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
896 int fillStyle
= wxODDEVEN_RULE
)
897 { m_pimpl
->DoDrawPolyPolygon(n
, count
, points
, xoffset
, yoffset
, fillStyle
); }
898 #if WXWIN_COMPATIBILITY_2_8
899 wxDEPRECATED( void DrawPolygon(const wxList
*list
,
900 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
901 int fillStyle
= wxODDEVEN_RULE
) );
902 #endif // WXWIN_COMPATIBILITY_2_8
904 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
905 { m_pimpl
->DoDrawRectangle(x
, y
, width
, height
); }
906 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
907 { m_pimpl
->DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
908 void DrawRectangle(const wxRect
& rect
)
909 { m_pimpl
->DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
911 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
913 { m_pimpl
->DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
914 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
916 { m_pimpl
->DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
917 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
918 { m_pimpl
->DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
920 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
921 { m_pimpl
->DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
922 void DrawCircle(const wxPoint
& pt
, wxCoord radius
)
923 { m_pimpl
->DoDrawEllipse(pt
.x
- radius
, pt
.y
- radius
, 2*radius
, 2*radius
); }
925 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
926 { m_pimpl
->DoDrawEllipse(x
, y
, width
, height
); }
927 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
928 { m_pimpl
->DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
929 void DrawEllipse(const wxRect
& rect
)
930 { m_pimpl
->DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
932 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
933 { m_pimpl
->DoDrawIcon(icon
, x
, y
); }
934 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
935 { m_pimpl
->DoDrawIcon(icon
, pt
.x
, pt
.y
); }
937 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
938 bool useMask
= false)
939 { m_pimpl
->DoDrawBitmap(bmp
, x
, y
, useMask
); }
940 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
941 bool useMask
= false)
942 { m_pimpl
->DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
944 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
945 { m_pimpl
->DoDrawText(text
, x
, y
); }
946 void DrawText(const wxString
& text
, const wxPoint
& pt
)
947 { m_pimpl
->DoDrawText(text
, pt
.x
, pt
.y
); }
949 void DrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
950 { m_pimpl
->DoDrawRotatedText(text
, x
, y
, angle
); }
951 void DrawRotatedText(const wxString
& text
, const wxPoint
& pt
, double angle
)
952 { m_pimpl
->DoDrawRotatedText(text
, pt
.x
, pt
.y
, angle
); }
954 // this version puts both optional bitmap and the text into the given
955 // rectangle and aligns is as specified by alignment parameter; it also
956 // will emphasize the character with the given index if it is != -1 and
957 // return the bounding rectangle if required
958 void DrawLabel(const wxString
& text
,
959 const wxBitmap
& image
,
961 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
963 wxRect
*rectBounding
= NULL
);
965 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
966 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
968 { DrawLabel(text
, wxNullBitmap
, rect
, alignment
, indexAccel
); }
970 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
971 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
972 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
974 return m_pimpl
->DoBlit(xdest
, ydest
, width
, height
,
975 source
, xsrc
, ysrc
, rop
, useMask
, xsrcMask
, ysrcMask
);
977 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
978 wxDC
*source
, const wxPoint
& srcPt
,
979 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
981 return m_pimpl
->DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
982 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
, srcPtMask
.x
, srcPtMask
.y
);
985 bool StretchBlit(wxCoord dstX
, wxCoord dstY
,
986 wxCoord dstWidth
, wxCoord dstHeight
,
988 wxCoord srcX
, wxCoord srcY
,
989 wxCoord srcWidth
, wxCoord srcHeight
,
990 int rop
= wxCOPY
, bool useMask
= false,
991 wxCoord srcMaskX
= wxDefaultCoord
, wxCoord srcMaskY
= wxDefaultCoord
)
993 return m_pimpl
->DoStretchBlit(dstX
, dstY
, dstWidth
, dstHeight
,
994 source
, srcX
, srcY
, srcWidth
, srcHeight
, rop
, useMask
, srcMaskX
, srcMaskY
);
996 bool StretchBlit(const wxPoint
& dstPt
, const wxSize
& dstSize
,
997 wxDC
*source
, const wxPoint
& srcPt
, const wxSize
& srcSize
,
998 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcMaskPt
= wxDefaultPosition
)
1000 return m_pimpl
->DoStretchBlit(dstPt
.x
, dstPt
.y
, dstSize
.x
, dstSize
.y
,
1001 source
, srcPt
.x
, srcPt
.y
, srcSize
.x
, srcSize
.y
, rop
, useMask
, srcMaskPt
.x
, srcMaskPt
.y
);
1004 wxBitmap
GetAsBitmap(const wxRect
*subrect
= (const wxRect
*) NULL
) const
1006 return m_pimpl
->DoGetAsBitmap(subrect
);
1010 void DrawSpline(wxCoord x1
, wxCoord y1
,
1011 wxCoord x2
, wxCoord y2
,
1012 wxCoord x3
, wxCoord y3
)
1013 { m_pimpl
->DoDrawSpline(x1
,y1
,x2
,y2
,x3
,y3
); }
1014 void DrawSpline(int n
, wxPoint points
[])
1015 { m_pimpl
->DoDrawSpline(n
,points
); }
1016 void DrawSpline(const wxPointList
*points
)
1017 { m_pimpl
->DoDrawSpline(points
); }
1018 #endif // wxUSE_SPLINES
1021 #if WXWIN_COMPATIBILITY_2_8
1022 // for compatibility with the old code when wxCoord was long everywhere
1023 wxDEPRECATED( void GetTextExtent(const wxString
& string
,
1025 long *descent
= NULL
,
1026 long *externalLeading
= NULL
,
1027 const wxFont
*theFont
= NULL
) const );
1028 wxDEPRECATED( void GetLogicalOrigin(long *x
, long *y
) const );
1029 wxDEPRECATED( void GetDeviceOrigin(long *x
, long *y
) const );
1030 wxDEPRECATED( void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const );
1031 #endif // WXWIN_COMPATIBILITY_2_8
1038 DECLARE_ABSTRACT_CLASS(wxDC
)
1041 // ----------------------------------------------------------------------------
1042 // helper class: you can use it to temporarily change the DC text colour and
1043 // restore it automatically when the object goes out of scope
1044 // ----------------------------------------------------------------------------
1046 class WXDLLEXPORT wxDCTextColourChanger
1049 wxDCTextColourChanger(wxDC
& dc
) : m_dc(dc
), m_colFgOld() { }
1051 wxDCTextColourChanger(wxDC
& dc
, const wxColour
& col
) : m_dc(dc
)
1056 ~wxDCTextColourChanger()
1058 if ( m_colFgOld
.Ok() )
1059 m_dc
.SetTextForeground(m_colFgOld
);
1062 void Set(const wxColour
& col
)
1064 if ( !m_colFgOld
.Ok() )
1065 m_colFgOld
= m_dc
.GetTextForeground();
1066 m_dc
.SetTextForeground(col
);
1072 wxColour m_colFgOld
;
1074 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger
)
1077 // ----------------------------------------------------------------------------
1078 // helper class: you can use it to temporarily change the DC pen and
1079 // restore it automatically when the object goes out of scope
1080 // ----------------------------------------------------------------------------
1082 class WXDLLEXPORT wxDCPenChanger
1085 wxDCPenChanger(wxDC
& dc
, const wxPen
& pen
) : m_dc(dc
), m_penOld(dc
.GetPen())
1092 if ( m_penOld
.Ok() )
1093 m_dc
.SetPen(m_penOld
);
1101 DECLARE_NO_COPY_CLASS(wxDCPenChanger
)
1104 // ----------------------------------------------------------------------------
1105 // helper class: you can use it to temporarily change the DC brush and
1106 // restore it automatically when the object goes out of scope
1107 // ----------------------------------------------------------------------------
1109 class WXDLLEXPORT wxDCBrushChanger
1112 wxDCBrushChanger(wxDC
& dc
, const wxBrush
& brush
) : m_dc(dc
), m_brushOld(dc
.GetBrush())
1114 m_dc
.SetBrush(brush
);
1119 if ( m_brushOld
.Ok() )
1120 m_dc
.SetBrush(m_brushOld
);
1128 DECLARE_NO_COPY_CLASS(wxDCBrushChanger
)
1131 // ----------------------------------------------------------------------------
1132 // another small helper class: sets the clipping region in its ctor and
1133 // destroys it in the dtor
1134 // ----------------------------------------------------------------------------
1136 class WXDLLEXPORT wxDCClipper
1139 wxDCClipper(wxDC
& dc
, const wxRegion
& r
) : m_dc(dc
)
1140 { dc
.SetClippingRegion(r
); }
1141 wxDCClipper(wxDC
& dc
, const wxRect
& r
) : m_dc(dc
)
1142 { dc
.SetClippingRegion(r
.x
, r
.y
, r
.width
, r
.height
); }
1143 wxDCClipper(wxDC
& dc
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) : m_dc(dc
)
1144 { dc
.SetClippingRegion(x
, y
, w
, h
); }
1146 ~wxDCClipper() { m_dc
.DestroyClippingRegion(); }
1151 DECLARE_NO_COPY_CLASS(wxDCClipper
)
1154 #endif // _WX_DC_H_BASE_