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 #include "wx/graphics.h"
45 class WXDLLEXPORT wxGraphicPath
48 virtual ~wxGraphicPath() {}
50 virtual void MoveToPoint( wxCoord x1
, wxCoord y1
) = 0;
52 virtual void AddLineToPoint( wxCoord x1
, wxCoord y1
) = 0;
54 virtual void AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
) = 0;
56 virtual void AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0;
58 virtual void AddCircle( wxCoord x
, wxCoord y
, wxCoord r
) = 0;
60 // 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)
61 virtual void AddArcToPoint( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord r
) = 0 ;
63 virtual void AddArc( wxCoord x
, wxCoord y
, wxCoord r
, double startAngle
, double endAngle
, bool clockwise
) = 0 ;
65 virtual void CloseSubpath() = 0;
68 class WXDLLEXPORT wxGraphicContext
71 virtual ~wxGraphicContext() {}
73 virtual wxGraphicPath
* CreatePath() = 0;
75 virtual void PushState() = 0 ;
77 virtual void PopState() = 0 ;
79 virtual void Clip( const wxRegion
®ion
) = 0;
81 virtual void SetPen( const wxPen
&pen
) = 0;
83 virtual void SetBrush( const wxBrush
&brush
) = 0;
85 virtual void SetFont( const wxFont
&font
) = 0 ;
87 virtual void SetTextColor( const wxColour
&col
) = 0 ;
89 virtual void StrokePath( const wxGraphicPath
*path
) = 0;
91 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0;
93 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0;
95 virtual void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
97 virtual void DrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
99 virtual void DrawText( const wxString
&str
, wxCoord x
, wxCoord y
, double angle
) = 0 ;
101 virtual void GetTextExtent( const wxString
&text
, wxCoord
*width
, wxCoord
*height
,
102 wxCoord
*descent
, wxCoord
*externalLeading
) const = 0 ;
104 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const = 0 ;
106 virtual void Translate( wxCoord dx
, wxCoord dy
) = 0 ;
108 virtual void Scale( wxCoord xScale
, wxCoord yScale
) = 0 ;
111 class WXDLLEXPORT wxDC
: public wxDCBase
113 DECLARE_DYNAMIC_CLASS(wxDC
)
114 DECLARE_NO_COPY_CLASS(wxDC
)
120 // implement base class pure virtuals
121 // ----------------------------------
123 virtual void Clear();
125 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
126 virtual void EndDoc(void) {}
128 virtual void StartPage(void) {}
129 virtual void EndPage(void) {}
131 virtual void SetFont(const wxFont
& font
);
132 virtual void SetPen(const wxPen
& pen
);
133 virtual void SetBrush(const wxBrush
& brush
);
134 virtual void SetBackground(const wxBrush
& brush
);
135 virtual void SetBackgroundMode(int mode
);
136 virtual void SetPalette(const wxPalette
& palette
);
138 virtual void DestroyClippingRegion();
140 virtual wxCoord
GetCharHeight() const;
141 virtual wxCoord
GetCharWidth() const;
143 virtual bool CanDrawBitmap() const;
144 virtual bool CanGetTextExtent() const;
145 virtual int GetDepth() const;
146 virtual wxSize
GetPPI() const;
148 virtual void SetMapMode(int mode
);
149 virtual void SetUserScale(double x
, double y
);
151 virtual void SetLogicalScale(double x
, double y
);
152 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
153 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
154 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
155 virtual void SetLogicalFunction(int function
);
157 virtual void SetTextForeground(const wxColour
& colour
);
158 virtual void SetTextBackground(const wxColour
& colour
);
160 virtual void ComputeScaleAndOrigin();
163 wxCoord
XDEV2LOG(wxCoord x
) const
165 long new_x
= x
- m_deviceOriginX
;
167 return (wxCoord
)((double)new_x
/ m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
169 return (wxCoord
)((double)new_x
/ m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
172 wxCoord
XDEV2LOGREL(wxCoord x
) const
175 return (wxCoord
)((double)x
/ m_scaleX
+ 0.5);
177 return (wxCoord
)((double)x
/ m_scaleX
- 0.5);
180 wxCoord
YDEV2LOG(wxCoord y
) const
182 long new_y
= y
- m_deviceOriginY
;
184 return (wxCoord
)((double)new_y
/ m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
186 return (wxCoord
)((double)new_y
/ m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
189 wxCoord
YDEV2LOGREL(wxCoord y
) const
192 return (wxCoord
)((double)y
/ m_scaleY
+ 0.5);
194 return (wxCoord
)((double)y
/ m_scaleY
- 0.5);
197 wxCoord
XLOG2DEV(wxCoord x
) const
199 long new_x
= x
- m_logicalOriginX
;
201 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
203 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
206 wxCoord
XLOG2DEVREL(wxCoord x
) const
209 return (wxCoord
)((double)x
* m_scaleX
+ 0.5);
211 return (wxCoord
)((double)x
* m_scaleX
- 0.5);
214 wxCoord
YLOG2DEV(wxCoord y
) const
216 long new_y
= y
- m_logicalOriginY
;
218 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
220 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
223 wxCoord
YLOG2DEVREL(wxCoord y
) const
226 return (wxCoord
)((double)y
* m_scaleY
+ 0.5);
228 return (wxCoord
)((double)y
* m_scaleY
- 0.5);
231 wxCoord
XLOG2DEVMAC(wxCoord x
) const
233 long new_x
= x
- m_logicalOriginX
;
235 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
237 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
240 wxCoord
YLOG2DEVMAC(wxCoord y
) const
242 long new_y
= y
- m_logicalOriginY
;
244 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
246 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
249 #if wxMAC_USE_CORE_GRAPHICS
250 wxGraphicContext
* GetGraphicContext() { return m_graphicContext
; }
252 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
253 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
);
257 virtual void DoGetTextExtent(const wxString
& string
,
258 wxCoord
*x
, wxCoord
*y
,
259 wxCoord
*descent
= NULL
,
260 wxCoord
*externalLeading
= NULL
,
261 wxFont
*theFont
= NULL
) const;
263 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
265 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
266 int style
= wxFLOOD_SURFACE
);
268 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
270 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
272 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
273 virtual void DoDrawSpline(wxList
*points
);
276 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
278 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
279 wxCoord x2
, wxCoord y2
,
280 wxCoord xc
, wxCoord yc
);
282 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
283 double sa
, double ea
);
285 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
286 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
287 wxCoord width
, wxCoord height
,
289 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
291 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
293 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
294 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
295 bool useMask
= false);
297 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
298 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
301 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
302 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
303 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
305 // this is gnarly - we can't even call this function DoSetClippingRegion()
306 // because of virtual function hiding
308 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
309 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
310 wxCoord width
, wxCoord height
);
312 virtual void DoGetSizeMM(int *width
, int *height
) const;
314 virtual void DoDrawLines(int n
, wxPoint points
[],
315 wxCoord xoffset
, wxCoord yoffset
);
316 virtual void DoDrawPolygon(int n
, wxPoint points
[],
317 wxCoord xoffset
, wxCoord yoffset
,
318 int fillStyle
= wxODDEVEN_RULE
);
322 double m_mm_to_pix_x
, m_mm_to_pix_y
;
324 // To be set using SetDeviceOrigin()
325 // by external classes such as wxScrolledWindow
326 long m_externalDeviceOriginX
, m_externalDeviceOriginY
;
328 #if !wxMAC_USE_CORE_GRAPHICS
329 // If un-scrolled is non-zero or d.o. changes with scrolling.
330 // Set using SetInternalDeviceOrigin().
331 long m_internalDeviceOriginX
, m_internalDeviceOriginY
;
337 bool m_needComputeScaleX
, m_needComputeScaleY
;
341 void MacInstallFont() const;
343 // in order to preserve the const inheritance of the virtual functions,
344 // we have to use mutable variables starting from CWPro 5
345 wxPoint m_macLocalOrigin
;
346 mutable void *m_macATSUIStyle
;
350 #if wxMAC_USE_CORE_GRAPHICS
351 wxGraphicContext
*m_graphicContext
;
353 void MacInstallPen() const;
354 void MacInstallBrush() const;
356 void MacSetupPort( wxMacPortStateHelper
*ph
) const;
357 void MacCleanupPort( wxMacPortStateHelper
*ph
) const;
359 mutable wxMacPortStateHelper
*m_macCurrentPortStateHelper
;
361 mutable bool m_macFontInstalled
;
362 mutable bool m_macPenInstalled
;
363 mutable bool m_macBrushInstalled
;
365 WXHRGN m_macBoundaryClipRgn
;
366 WXHRGN m_macCurrentClipRgn
;
367 mutable bool m_macFormerAliasState
;
368 mutable short m_macFormerAliasSize
;
369 mutable bool m_macAliasWasEnabled
;
370 mutable void *m_macForegroundPixMap
;
371 mutable void *m_macBackgroundPixMap
;