1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/dcgraph.h
3 // Purpose:     graphics context device bridge header
4 // Author:      Stefan Csomor
5 // Modified by:
6 // Created:
7 // Copyright:   (c) Stefan Csomor
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_GRAPHICS_DC_H_
12 #define _WX_GRAPHICS_DC_H_
13 
14 #if wxUSE_GRAPHICS_CONTEXT
15 
16 #include "wx/dc.h"
17 #include "wx/geometry.h"
18 #include "wx/graphics.h"
19 
20 class WXDLLIMPEXP_FWD_CORE wxWindowDC;
21 
22 
23 class WXDLLIMPEXP_CORE wxGCDC: public wxDC
24 {
25 public:
26     wxGCDC( const wxWindowDC& dc );
27     wxGCDC( const wxMemoryDC& dc );
28 #if wxUSE_PRINTING_ARCHITECTURE
29     wxGCDC( const wxPrinterDC& dc );
30 #endif
31 #if defined(__WXMSW__) && wxUSE_ENH_METAFILE
32     wxGCDC( const wxEnhMetaFileDC& dc );
33 #endif
34     wxGCDC(wxGraphicsContext* context);
35 
36     wxGCDC();
37     virtual ~wxGCDC();
38 
39 #ifdef __WXMSW__
40     // override wxDC virtual functions to provide access to HDC associated with
41     // this Graphics object (implemented in src/msw/graphics.cpp)
42     virtual WXHDC AcquireHDC() wxOVERRIDE;
43     virtual void ReleaseHDC(WXHDC hdc) wxOVERRIDE;
44 #endif // __WXMSW__
45 
46 private:
47     wxDECLARE_DYNAMIC_CLASS(wxGCDC);
48     wxDECLARE_NO_COPY_CLASS(wxGCDC);
49 };
50 
51 
52 class WXDLLIMPEXP_CORE wxGCDCImpl: public wxDCImpl
53 {
54 public:
55     wxGCDCImpl( wxDC *owner, const wxWindowDC& dc );
56     wxGCDCImpl( wxDC *owner, const wxMemoryDC& dc );
57 #if wxUSE_PRINTING_ARCHITECTURE
58     wxGCDCImpl( wxDC *owner, const wxPrinterDC& dc );
59 #endif
60 #if defined(__WXMSW__) && wxUSE_ENH_METAFILE
61     wxGCDCImpl( wxDC *owner, const wxEnhMetaFileDC& dc );
62 #endif
63 
64     // Ctor using an existing graphics context given to wxGCDC ctor.
65     wxGCDCImpl(wxDC *owner, wxGraphicsContext* context);
66 
67     wxGCDCImpl( wxDC *owner );
68 
69     virtual ~wxGCDCImpl();
70 
71     // implement base class pure virtuals
72     // ----------------------------------
73 
74     virtual void Clear() wxOVERRIDE;
75 
76     virtual bool StartDoc( const wxString& message ) wxOVERRIDE;
77     virtual void EndDoc() wxOVERRIDE;
78 
79     virtual void StartPage() wxOVERRIDE;
80     virtual void EndPage() wxOVERRIDE;
81 
82     // flushing the content of this dc immediately onto screen
83     virtual void Flush() wxOVERRIDE;
84 
85     virtual void SetFont(const wxFont& font) wxOVERRIDE;
86     virtual void SetPen(const wxPen& pen) wxOVERRIDE;
87     virtual void SetBrush(const wxBrush& brush) wxOVERRIDE;
88     virtual void SetBackground(const wxBrush& brush) wxOVERRIDE;
89     virtual void SetBackgroundMode(int mode) wxOVERRIDE;
90 
91 #if wxUSE_PALETTE
92     virtual void SetPalette(const wxPalette& palette) wxOVERRIDE;
93 #endif
94 
95     virtual void DestroyClippingRegion() wxOVERRIDE;
96 
97     virtual wxCoord GetCharHeight() const wxOVERRIDE;
98     virtual wxCoord GetCharWidth() const wxOVERRIDE;
99 
100     virtual bool CanDrawBitmap() const wxOVERRIDE;
101     virtual bool CanGetTextExtent() const wxOVERRIDE;
102     virtual int GetDepth() const wxOVERRIDE;
103     virtual wxSize GetPPI() const wxOVERRIDE;
104 
105     virtual void SetLogicalFunction(wxRasterOperationMode function) wxOVERRIDE;
106 
107     virtual void SetTextForeground(const wxColour& colour) wxOVERRIDE;
108     virtual void SetTextBackground(const wxColour& colour) wxOVERRIDE;
109 
110     virtual void ComputeScaleAndOrigin() wxOVERRIDE;
111 
GetGraphicsContext()112     wxGraphicsContext* GetGraphicsContext() const wxOVERRIDE { return m_graphicContext; }
113     virtual void SetGraphicsContext( wxGraphicsContext* ctx ) wxOVERRIDE;
114 
115     virtual void* GetHandle() const wxOVERRIDE;
116 
117 #if wxUSE_DC_TRANSFORM_MATRIX
118     virtual bool CanUseTransformMatrix() const wxOVERRIDE;
119     virtual bool SetTransformMatrix(const wxAffineMatrix2D& matrix) wxOVERRIDE;
120     virtual wxAffineMatrix2D GetTransformMatrix() const wxOVERRIDE;
121     virtual void ResetTransformMatrix() wxOVERRIDE;
122 #endif // wxUSE_DC_TRANSFORM_MATRIX
123 
124     // coordinates conversions and transforms
125     virtual wxPoint DeviceToLogical(wxCoord x, wxCoord y) const wxOVERRIDE;
126     virtual wxPoint LogicalToDevice(wxCoord x, wxCoord y) const wxOVERRIDE;
127     virtual wxSize DeviceToLogicalRel(int x, int y) const wxOVERRIDE;
128     virtual wxSize LogicalToDeviceRel(int x, int y) const wxOVERRIDE;
129 
130     // the true implementations
131     virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
132                              wxFloodFillStyle style = wxFLOOD_SURFACE) wxOVERRIDE;
133 
134     virtual void DoGradientFillLinear(const wxRect& rect,
135         const wxColour& initialColour,
136         const wxColour& destColour,
137         wxDirection nDirection = wxEAST) wxOVERRIDE;
138 
139     virtual void DoGradientFillConcentric(const wxRect& rect,
140         const wxColour& initialColour,
141         const wxColour& destColour,
142         const wxPoint& circleCenter) wxOVERRIDE;
143 
144     virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const wxOVERRIDE;
145 
146     virtual void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE;
147 
148 #if wxUSE_SPLINES
149     virtual void DoDrawSpline(const wxPointList *points) wxOVERRIDE;
150 #endif
151 
152     virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE;
153 
154     virtual void DoDrawArc(wxCoord x1, wxCoord y1,
155         wxCoord x2, wxCoord y2,
156         wxCoord xc, wxCoord yc) wxOVERRIDE;
157 
158     virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
159         wxCoord width, wxCoord height) wxOVERRIDE;
160 
161     virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
162         double sa, double ea) wxOVERRIDE;
163 
164     virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE;
165     virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
166         wxCoord width, wxCoord height,
167         double radius) wxOVERRIDE;
168     virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE;
169 
170     virtual void DoCrossHair(wxCoord x, wxCoord y) wxOVERRIDE;
171 
172     virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxOVERRIDE;
173     virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
174         bool useMask = false) wxOVERRIDE;
175 
176     virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE;
177     virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
178         double angle) wxOVERRIDE;
179 
180     virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
181                         wxDC *source, wxCoord xsrc, wxCoord ysrc,
182                         wxRasterOperationMode rop = wxCOPY, bool useMask = false,
183                         wxCoord xsrcMask = -1, wxCoord ysrcMask = -1) wxOVERRIDE;
184 
185     virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
186                                wxCoord dstWidth, wxCoord dstHeight,
187                                wxDC *source,
188                                wxCoord xsrc, wxCoord ysrc,
189                                wxCoord srcWidth, wxCoord srcHeight,
190                                wxRasterOperationMode = wxCOPY, bool useMask = false,
191                                wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) wxOVERRIDE;
192 
193     virtual void DoGetSize(int *,int *) const wxOVERRIDE;
194     virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE;
195 
196     virtual void DoDrawLines(int n, const wxPoint points[],
197         wxCoord xoffset, wxCoord yoffset) wxOVERRIDE;
198     virtual void DoDrawPolygon(int n, const wxPoint points[],
199                                wxCoord xoffset, wxCoord yoffset,
200                                wxPolygonFillMode fillStyle = wxODDEVEN_RULE) wxOVERRIDE;
201     virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
202                                    wxCoord xoffset, wxCoord yoffset,
203                                    wxPolygonFillMode fillStyle) wxOVERRIDE;
204 
205     virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE;
206     virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
207         wxCoord width, wxCoord height) wxOVERRIDE;
208     virtual bool DoGetClippingRect(wxRect& rect) const wxOVERRIDE;
209 
210     virtual void DoGetTextExtent(const wxString& string,
211         wxCoord *x, wxCoord *y,
212         wxCoord *descent = NULL,
213         wxCoord *externalLeading = NULL,
214         const wxFont *theFont = NULL) const wxOVERRIDE;
215 
216     virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const wxOVERRIDE;
217 
218 #ifdef __WXMSW__
219     virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const wxOVERRIDE;
220 #endif // __WXMSW__
221 
222     // update the internal clip box variables
223     void UpdateClipBox();
224 
225 protected:
226     // unused int parameter distinguishes this version, which does not create a
227     // wxGraphicsContext, in the expectation that the derived class will do it
228     wxGCDCImpl(wxDC* owner, int);
229 
230 #ifdef __WXOSX__
OSXGetOrigin()231     virtual wxPoint OSXGetOrigin() const { return wxPoint(); }
232 #endif
233 
234     // scaling variables
235     bool m_logicalFunctionSupported;
236     wxGraphicsMatrix m_matrixOriginal;
237     wxGraphicsMatrix m_matrixCurrent;
238     wxGraphicsMatrix m_matrixCurrentInv;
239 #if wxUSE_DC_TRANSFORM_MATRIX
240     wxAffineMatrix2D m_matrixExtTransform;
241 #endif // wxUSE_DC_TRANSFORM_MATRIX
242 
243     wxGraphicsContext* m_graphicContext;
244 
245     bool m_isClipBoxValid;
246 
247 private:
248     // This method only initializes trivial fields.
249     void CommonInit();
250 
251     // This method initializes all fields (including those initialized by
252     // CommonInit() as it calls it) and the given context, if non-null, which
253     // is assumed to be newly created.
254     void Init(wxGraphicsContext*);
255 
256     // This method initializes m_graphicContext, m_ok and m_matrixOriginal
257     // fields, returns true if the context was valid.
258     bool DoInitContext(wxGraphicsContext* ctx);
259 
260     wxDECLARE_CLASS(wxGCDCImpl);
261     wxDECLARE_NO_COPY_CLASS(wxGCDCImpl);
262 };
263 
264 #endif // wxUSE_GRAPHICS_CONTEXT
265 #endif // _WX_GRAPHICS_DC_H_
266