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 #if !wxUSE_GRAPHICS_CONTEXT
41 class WXDLLEXPORT wxGraphicPath
44 virtual ~wxGraphicPath() {}
46 virtual void MoveToPoint( wxCoord x1
, wxCoord y1
) = 0;
48 virtual void AddLineToPoint( wxCoord x1
, wxCoord y1
) = 0;
50 virtual void AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
) = 0;
52 virtual void AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0;
54 virtual void AddCircle( wxCoord x
, wxCoord y
, wxCoord r
) = 0;
56 // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
57 virtual void AddArcToPoint( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord r
) = 0 ;
59 virtual void AddArc( wxCoord x
, wxCoord y
, wxCoord r
, double startAngle
, double endAngle
, bool clockwise
) = 0 ;
61 virtual void CloseSubpath() = 0;
64 class WXDLLEXPORT wxGraphicContext
67 virtual ~wxGraphicContext() {}
69 virtual wxGraphicPath
* CreatePath() = 0;
71 virtual void PushState() = 0 ;
73 virtual void PopState() = 0 ;
75 virtual void Clip( const wxRegion
®ion
) = 0;
77 virtual void SetPen( const wxPen
&pen
) = 0;
79 virtual void SetBrush( const wxBrush
&brush
) = 0;
81 virtual void SetFont( const wxFont
&font
) = 0 ;
83 virtual void SetTextColor( const wxColour
&col
) = 0 ;
85 virtual void StrokePath( const wxGraphicPath
*path
) = 0;
87 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0;
89 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0;
91 virtual void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
93 virtual void DrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
95 virtual void DrawText( const wxString
&str
, wxCoord x
, wxCoord y
, double angle
) = 0 ;
97 virtual void GetTextExtent( const wxString
&text
, wxCoord
*width
, wxCoord
*height
,
98 wxCoord
*descent
, wxCoord
*externalLeading
) const = 0 ;
100 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const = 0 ;
102 virtual void Translate( wxCoord dx
, wxCoord dy
) = 0 ;
104 virtual void Scale( wxCoord xScale
, wxCoord yScale
) = 0 ;
107 class WXDLLEXPORT wxDC
: public wxDCBase
109 DECLARE_DYNAMIC_CLASS(wxDC
)
110 DECLARE_NO_COPY_CLASS(wxDC
)
116 // implement base class pure virtuals
117 // ----------------------------------
119 virtual void Clear();
121 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
122 virtual void EndDoc(void) {}
124 virtual void StartPage(void) {}
125 virtual void EndPage(void) {}
127 virtual void SetFont(const wxFont
& font
);
128 virtual void SetPen(const wxPen
& pen
);
129 virtual void SetBrush(const wxBrush
& brush
);
130 virtual void SetBackground(const wxBrush
& brush
);
131 virtual void SetBackgroundMode(int mode
);
132 virtual void SetPalette(const wxPalette
& palette
);
134 virtual void DestroyClippingRegion();
136 virtual wxCoord
GetCharHeight() const;
137 virtual wxCoord
GetCharWidth() const;
139 virtual bool CanDrawBitmap() const;
140 virtual bool CanGetTextExtent() const;
141 virtual int GetDepth() const;
142 virtual wxSize
GetPPI() const;
144 virtual void SetMapMode(int mode
);
145 virtual void SetUserScale(double x
, double y
);
147 virtual void SetLogicalScale(double x
, double y
);
148 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
149 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
150 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
151 virtual void SetLogicalFunction(int function
);
153 virtual void SetTextForeground(const wxColour
& colour
);
154 virtual void SetTextBackground(const wxColour
& colour
);
156 virtual void ComputeScaleAndOrigin();
159 wxCoord
XDEV2LOG(wxCoord x
) const
161 long new_x
= x
- m_deviceOriginX
;
163 return (wxCoord
)((double)new_x
/ m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
165 return (wxCoord
)((double)new_x
/ m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
168 wxCoord
XDEV2LOGREL(wxCoord x
) const
171 return (wxCoord
)((double)x
/ m_scaleX
+ 0.5);
173 return (wxCoord
)((double)x
/ m_scaleX
- 0.5);
176 wxCoord
YDEV2LOG(wxCoord y
) const
178 long new_y
= y
- m_deviceOriginY
;
180 return (wxCoord
)((double)new_y
/ m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
182 return (wxCoord
)((double)new_y
/ m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
185 wxCoord
YDEV2LOGREL(wxCoord y
) const
188 return (wxCoord
)((double)y
/ m_scaleY
+ 0.5);
190 return (wxCoord
)((double)y
/ m_scaleY
- 0.5);
193 wxCoord
XLOG2DEV(wxCoord x
) const
195 long new_x
= x
- m_logicalOriginX
;
197 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
199 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
202 wxCoord
XLOG2DEVREL(wxCoord x
) const
205 return (wxCoord
)((double)x
* m_scaleX
+ 0.5);
207 return (wxCoord
)((double)x
* m_scaleX
- 0.5);
210 wxCoord
YLOG2DEV(wxCoord y
) const
212 long new_y
= y
- m_logicalOriginY
;
214 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
216 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
219 wxCoord
YLOG2DEVREL(wxCoord y
) const
222 return (wxCoord
)((double)y
* m_scaleY
+ 0.5);
224 return (wxCoord
)((double)y
* m_scaleY
- 0.5);
227 wxCoord
XLOG2DEVMAC(wxCoord x
) const
229 long new_x
= x
- m_logicalOriginX
;
231 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
233 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
236 wxCoord
YLOG2DEVMAC(wxCoord y
) const
238 long new_y
= y
- m_logicalOriginY
;
240 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
242 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
245 #if wxMAC_USE_CORE_GRAPHICS
246 wxGraphicsContext
* GetGraphicsContext() { return m_graphicContext
; }
248 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
249 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
);
253 virtual void DoGetTextExtent(const wxString
& string
,
254 wxCoord
*x
, wxCoord
*y
,
255 wxCoord
*descent
= NULL
,
256 wxCoord
*externalLeading
= NULL
,
257 wxFont
*theFont
= NULL
) const;
259 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
261 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
262 int style
= wxFLOOD_SURFACE
);
264 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
266 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
268 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
269 virtual void DoDrawSpline(wxList
*points
);
272 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
274 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
275 wxCoord x2
, wxCoord y2
,
276 wxCoord xc
, wxCoord yc
);
278 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
279 double sa
, double ea
);
281 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
282 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
283 wxCoord width
, wxCoord height
,
285 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
287 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
289 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
290 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
291 bool useMask
= false);
293 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
294 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
297 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
298 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
299 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
301 // this is gnarly - we can't even call this function DoSetClippingRegion()
302 // because of virtual function hiding
304 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
305 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
306 wxCoord width
, wxCoord height
);
308 virtual void DoGetSizeMM(int *width
, int *height
) const;
310 virtual void DoDrawLines(int n
, wxPoint points
[],
311 wxCoord xoffset
, wxCoord yoffset
);
312 virtual void DoDrawPolygon(int n
, wxPoint points
[],
313 wxCoord xoffset
, wxCoord yoffset
,
314 int fillStyle
= wxODDEVEN_RULE
);
318 double m_mm_to_pix_x
, m_mm_to_pix_y
;
320 // To be set using SetDeviceOrigin()
321 // by external classes such as wxScrolledWindow
322 long m_externalDeviceOriginX
, m_externalDeviceOriginY
;
324 #if !wxMAC_USE_CORE_GRAPHICS
325 // If un-scrolled is non-zero or d.o. changes with scrolling.
326 // Set using SetInternalDeviceOrigin().
327 long m_internalDeviceOriginX
, m_internalDeviceOriginY
;
333 bool m_needComputeScaleX
, m_needComputeScaleY
;
337 void MacInstallFont() const;
339 // in order to preserve the const inheritance of the virtual functions,
340 // we have to use mutable variables starting from CWPro 5
341 wxPoint m_macLocalOrigin
;
342 mutable void *m_macATSUIStyle
;
346 #if wxMAC_USE_CORE_GRAPHICS
347 wxGraphicsContext
*m_graphicContext
;
349 void MacInstallPen() const;
350 void MacInstallBrush() const;
352 void MacSetupPort( wxMacPortStateHelper
*ph
) const;
353 void MacCleanupPort( wxMacPortStateHelper
*ph
) const;
355 mutable wxMacPortStateHelper
*m_macCurrentPortStateHelper
;
357 mutable bool m_macFontInstalled
;
358 mutable bool m_macPenInstalled
;
359 mutable bool m_macBrushInstalled
;
361 WXHRGN m_macBoundaryClipRgn
;
362 WXHRGN m_macCurrentClipRgn
;
363 mutable bool m_macFormerAliasState
;
364 mutable short m_macFormerAliasSize
;
365 mutable bool m_macAliasWasEnabled
;
366 mutable void *m_macForegroundPixMap
;
367 mutable void *m_macBackgroundPixMap
;