1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
19 #include "wx/gdicmn.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
27 #define MM_ISOTROPIC 1
28 #define MM_ANISOTROPIC 2
37 class wxMacPortStateHelper
;
39 class WXDLLEXPORT wxGraphicPath
42 virtual ~wxGraphicPath() {}
44 virtual void MoveToPoint( wxCoord x1
, wxCoord y1
) = 0;
46 virtual void AddLineToPoint( wxCoord x1
, wxCoord y1
) = 0;
48 virtual void AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
) = 0;
50 virtual void AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0;
52 virtual void AddCircle( wxCoord x
, wxCoord y
, wxCoord r
) = 0;
54 virtual void CloseSubpath() = 0;
57 class WXDLLEXPORT wxGraphicContext
60 virtual ~wxGraphicContext() {}
62 virtual void Clip( const wxRegion
®ion
) = 0;
64 virtual void StrokePath( const wxGraphicPath
*path
) = 0;
66 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0;
68 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0;
70 virtual void SetPen( const wxPen
&pen
) = 0;
72 virtual void SetBrush( const wxBrush
&brush
) = 0;
74 virtual wxGraphicPath
* CreatePath() = 0;
77 class WXDLLEXPORT wxDC
: public wxDCBase
79 DECLARE_DYNAMIC_CLASS(wxDC
)
80 DECLARE_NO_COPY_CLASS(wxDC
)
86 // implement base class pure virtuals
87 // ----------------------------------
91 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
92 virtual void EndDoc(void) {}
94 virtual void StartPage(void) {}
95 virtual void EndPage(void) {}
97 virtual void SetFont(const wxFont
& font
);
98 virtual void SetPen(const wxPen
& pen
);
99 virtual void SetBrush(const wxBrush
& brush
);
100 virtual void SetBackground(const wxBrush
& brush
);
101 virtual void SetBackgroundMode(int mode
);
102 virtual void SetPalette(const wxPalette
& palette
);
104 virtual void DestroyClippingRegion();
106 virtual wxCoord
GetCharHeight() const;
107 virtual wxCoord
GetCharWidth() const;
109 virtual bool CanDrawBitmap() const;
110 virtual bool CanGetTextExtent() const;
111 virtual int GetDepth() const;
112 virtual wxSize
GetPPI() const;
114 virtual void SetMapMode(int mode
);
115 virtual void SetUserScale(double x
, double y
);
117 virtual void SetLogicalScale(double x
, double y
);
118 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
119 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
120 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
121 virtual void SetLogicalFunction(int function
);
123 virtual void SetTextForeground(const wxColour
& colour
);
124 virtual void SetTextBackground(const wxColour
& colour
);
126 virtual void ComputeScaleAndOrigin();
129 wxCoord
XDEV2LOG(wxCoord x
) const
131 long new_x
= x
- m_deviceOriginX
;
133 return (wxCoord
)((double)new_x
/ m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
135 return (wxCoord
)((double)new_x
/ m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
138 wxCoord
XDEV2LOGREL(wxCoord x
) const
141 return (wxCoord
)((double)x
/ m_scaleX
+ 0.5);
143 return (wxCoord
)((double)x
/ m_scaleX
- 0.5);
146 wxCoord
YDEV2LOG(wxCoord y
) const
148 long new_y
= y
- m_deviceOriginY
;
150 return (wxCoord
)((double)new_y
/ m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
152 return (wxCoord
)((double)new_y
/ m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
155 wxCoord
YDEV2LOGREL(wxCoord y
) const
158 return (wxCoord
)((double)y
/ m_scaleY
+ 0.5);
160 return (wxCoord
)((double)y
/ m_scaleY
- 0.5);
163 wxCoord
XLOG2DEV(wxCoord x
) const
165 long new_x
= x
- m_logicalOriginX
;
167 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
169 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
172 wxCoord
XLOG2DEVREL(wxCoord x
) const
175 return (wxCoord
)((double)x
* m_scaleX
+ 0.5);
177 return (wxCoord
)((double)x
* m_scaleX
- 0.5);
180 wxCoord
YLOG2DEV(wxCoord y
) const
182 long new_y
= y
- m_logicalOriginY
;
184 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
186 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
189 wxCoord
YLOG2DEVREL(wxCoord y
) const
192 return (wxCoord
)((double)y
* m_scaleY
+ 0.5);
194 return (wxCoord
)((double)y
* m_scaleY
- 0.5);
197 wxCoord
XLOG2DEVMAC(wxCoord x
) const
199 long new_x
= x
- m_logicalOriginX
;
201 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
203 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
206 wxCoord
YLOG2DEVMAC(wxCoord y
) const
208 long new_y
= y
- m_logicalOriginY
;
210 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
212 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
215 #if wxMAC_USE_CORE_GRAPHICS
216 wxGraphicContext
* GetGraphicContext() { return m_graphicContext
; }
218 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
219 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
);
223 virtual void DoGetTextExtent(const wxString
& string
,
224 wxCoord
*x
, wxCoord
*y
,
225 wxCoord
*descent
= NULL
,
226 wxCoord
*externalLeading
= NULL
,
227 wxFont
*theFont
= NULL
) const;
229 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
231 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
232 int style
= wxFLOOD_SURFACE
);
234 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
236 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
238 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
239 virtual void DoDrawSpline(wxList
*points
);
242 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
244 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
245 wxCoord x2
, wxCoord y2
,
246 wxCoord xc
, wxCoord yc
);
248 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
249 double sa
, double ea
);
251 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
252 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
253 wxCoord width
, wxCoord height
,
255 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
257 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
259 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
260 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
261 bool useMask
= false);
263 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
264 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
267 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
268 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
269 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
271 // this is gnarly - we can't even call this function DoSetClippingRegion()
272 // because of virtual function hiding
274 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
275 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
276 wxCoord width
, wxCoord height
);
278 virtual void DoGetSizeMM(int *width
, int *height
) const;
280 virtual void DoDrawLines(int n
, wxPoint points
[],
281 wxCoord xoffset
, wxCoord yoffset
);
282 virtual void DoDrawPolygon(int n
, wxPoint points
[],
283 wxCoord xoffset
, wxCoord yoffset
,
284 int fillStyle
= wxODDEVEN_RULE
);
288 double m_mm_to_pix_x
, m_mm_to_pix_y
;
290 // To be set using SetDeviceOrigin()
291 // by external classes such as wxScrolledWindow
292 long m_externalDeviceOriginX
, m_externalDeviceOriginY
;
294 #if !wxMAC_USE_CORE_GRAPHICS
295 // If un-scrolled is non-zero or d.o. changes with scrolling.
296 // Set using SetInternalDeviceOrigin().
297 long m_internalDeviceOriginX
, m_internalDeviceOriginY
;
303 bool m_needComputeScaleX
, m_needComputeScaleY
;
307 void MacInstallFont() const;
309 // in order to preserve the const inheritance of the virtual functions,
310 // we have to use mutable variables starting from CWPro 5
311 wxPoint m_macLocalOrigin
;
312 mutable void *m_macATSUIStyle
;
316 #if wxMAC_USE_CORE_GRAPHICS
317 wxGraphicContext
*m_graphicContext
;
318 wxPoint m_macLocalOriginInPort
;
320 void MacInstallPen() const;
321 void MacInstallBrush() const;
323 void MacSetupPort( wxMacPortStateHelper
*ph
) const;
324 void MacCleanupPort( wxMacPortStateHelper
*ph
) const;
326 mutable wxMacPortStateHelper
*m_macCurrentPortStateHelper
;
328 mutable bool m_macFontInstalled
;
329 mutable bool m_macPenInstalled
;
330 mutable bool m_macBrushInstalled
;
332 WXHRGN m_macBoundaryClipRgn
;
333 WXHRGN m_macCurrentClipRgn
;
334 mutable bool m_macFormerAliasState
;
335 mutable short m_macFormerAliasSize
;
336 mutable bool m_macAliasWasEnabled
;
337 mutable void *m_macForegroundPixMap
;
338 mutable void *m_macBackgroundPixMap
;