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 extern int wxPageNumber
;
40 class wxMacPortStateHelper
;
42 class WXDLLEXPORT wxGraphicPath
45 virtual ~wxGraphicPath() {}
47 virtual void MoveToPoint( wxCoord x1
, wxCoord y1
) = 0;
49 virtual void AddLineToPoint( wxCoord x1
, wxCoord y1
) = 0;
51 virtual void AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
) = 0;
53 virtual void AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0;
55 virtual void AddCircle( wxCoord x
, wxCoord y
, wxCoord r
) = 0;
57 virtual void CloseSubpath() = 0;
60 class WXDLLEXPORT wxGraphicContext
63 virtual ~wxGraphicContext() {}
65 virtual void Clip( const wxRegion
®ion
) = 0;
67 virtual void StrokePath( const wxGraphicPath
*path
) = 0;
69 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0;
71 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0;
73 virtual void SetPen( const wxPen
&pen
) = 0;
75 virtual void SetBrush( const wxBrush
&brush
) = 0;
77 virtual wxGraphicPath
* CreatePath() = 0;
80 class WXDLLEXPORT wxDC
: public wxDCBase
82 DECLARE_DYNAMIC_CLASS(wxDC
)
83 DECLARE_NO_COPY_CLASS(wxDC
)
89 // implement base class pure virtuals
90 // ----------------------------------
94 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
95 virtual void EndDoc(void) {}
97 virtual void StartPage(void) {}
98 virtual void EndPage(void) {}
100 virtual void SetFont(const wxFont
& font
);
101 virtual void SetPen(const wxPen
& pen
);
102 virtual void SetBrush(const wxBrush
& brush
);
103 virtual void SetBackground(const wxBrush
& brush
);
104 virtual void SetBackgroundMode(int mode
);
105 virtual void SetPalette(const wxPalette
& palette
);
107 virtual void DestroyClippingRegion();
109 virtual wxCoord
GetCharHeight() const;
110 virtual wxCoord
GetCharWidth() const;
112 virtual bool CanDrawBitmap() const;
113 virtual bool CanGetTextExtent() const;
114 virtual int GetDepth() const;
115 virtual wxSize
GetPPI() const;
117 virtual void SetMapMode(int mode
);
118 virtual void SetUserScale(double x
, double y
);
120 virtual void SetLogicalScale(double x
, double y
);
121 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
122 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
123 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
124 virtual void SetLogicalFunction(int function
);
126 virtual void SetTextForeground(const wxColour
& colour
);
127 virtual void SetTextBackground(const wxColour
& colour
);
129 virtual void ComputeScaleAndOrigin();
132 wxCoord
XDEV2LOG(wxCoord x
) const
134 long new_x
= x
- m_deviceOriginX
;
136 return (wxCoord
)((double)new_x
/ m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
138 return (wxCoord
)((double)new_x
/ m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
141 wxCoord
XDEV2LOGREL(wxCoord x
) const
144 return (wxCoord
)((double)x
/ m_scaleX
+ 0.5);
146 return (wxCoord
)((double)x
/ m_scaleX
- 0.5);
149 wxCoord
YDEV2LOG(wxCoord y
) const
151 long new_y
= y
- m_deviceOriginY
;
153 return (wxCoord
)((double)new_y
/ m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
155 return (wxCoord
)((double)new_y
/ m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
158 wxCoord
YDEV2LOGREL(wxCoord y
) const
161 return (wxCoord
)((double)y
/ m_scaleY
+ 0.5);
163 return (wxCoord
)((double)y
/ m_scaleY
- 0.5);
166 wxCoord
XLOG2DEV(wxCoord x
) const
168 long new_x
= x
- m_logicalOriginX
;
170 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
172 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
175 wxCoord
XLOG2DEVREL(wxCoord x
) const
178 return (wxCoord
)((double)x
* m_scaleX
+ 0.5);
180 return (wxCoord
)((double)x
* m_scaleX
- 0.5);
183 wxCoord
YLOG2DEV(wxCoord y
) const
185 long new_y
= y
- m_logicalOriginY
;
187 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
189 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
192 wxCoord
YLOG2DEVREL(wxCoord y
) const
195 return (wxCoord
)((double)y
* m_scaleY
+ 0.5);
197 return (wxCoord
)((double)y
* m_scaleY
- 0.5);
200 wxCoord
XLOG2DEVMAC(wxCoord x
) const
202 long new_x
= x
- m_logicalOriginX
;
204 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
206 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
209 wxCoord
YLOG2DEVMAC(wxCoord y
) const
211 long new_y
= y
- m_logicalOriginY
;
213 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
215 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
218 #if wxMAC_USE_CORE_GRAPHICS
219 wxGraphicContext
* GetGraphicContext() { return m_graphicContext
; }
221 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
222 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
);
226 virtual void DoGetTextExtent(const wxString
& string
,
227 wxCoord
*x
, wxCoord
*y
,
228 wxCoord
*descent
= NULL
,
229 wxCoord
*externalLeading
= NULL
,
230 wxFont
*theFont
= NULL
) const;
232 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
234 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
235 int style
= wxFLOOD_SURFACE
);
237 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
239 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
241 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
242 virtual void DoDrawSpline(wxList
*points
);
245 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
247 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
248 wxCoord x2
, wxCoord y2
,
249 wxCoord xc
, wxCoord yc
);
251 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
252 double sa
, double ea
);
254 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
255 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
256 wxCoord width
, wxCoord height
,
258 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
260 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
262 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
263 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
264 bool useMask
= false);
266 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
267 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
270 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
271 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
272 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
274 // this is gnarly - we can't even call this function DoSetClippingRegion()
275 // because of virtual function hiding
277 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
278 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
279 wxCoord width
, wxCoord height
);
281 virtual void DoGetSizeMM(int *width
, int *height
) const;
283 virtual void DoDrawLines(int n
, wxPoint points
[],
284 wxCoord xoffset
, wxCoord yoffset
);
285 virtual void DoDrawPolygon(int n
, wxPoint points
[],
286 wxCoord xoffset
, wxCoord yoffset
,
287 int fillStyle
= wxODDEVEN_RULE
);
291 double m_mm_to_pix_x
, m_mm_to_pix_y
;
293 // To be set using SetDeviceOrigin()
294 // by external classes such as wxScrolledWindow
295 long m_externalDeviceOriginX
, m_externalDeviceOriginY
;
297 #if !wxMAC_USE_CORE_GRAPHICS
298 // If un-scrolled is non-zero or d.o. changes with scrolling.
299 // Set using SetInternalDeviceOrigin().
300 long m_internalDeviceOriginX
, m_internalDeviceOriginY
;
306 bool m_needComputeScaleX
, m_needComputeScaleY
;
310 void MacInstallFont() const;
312 // in order to preserve the const inheritance of the virtual functions,
313 // we have to use mutable variables starting from CWPro 5
314 wxPoint m_macLocalOrigin
;
315 mutable void *m_macATSUIStyle
;
319 #if wxMAC_USE_CORE_GRAPHICS
320 wxGraphicContext
*m_graphicContext
;
321 wxPoint m_macLocalOriginInPort
;
323 void MacInstallPen() const;
324 void MacInstallBrush() const;
326 void MacSetupPort( wxMacPortStateHelper
*ph
) const;
327 void MacCleanupPort( wxMacPortStateHelper
*ph
) const;
329 mutable wxMacPortStateHelper
*m_macCurrentPortStateHelper
;
331 mutable bool m_macFontInstalled
;
332 mutable bool m_macPenInstalled
;
333 mutable bool m_macBrushInstalled
;
335 WXHRGN m_macBoundaryClipRgn
;
336 WXHRGN m_macCurrentClipRgn
;
337 mutable bool m_macFormerAliasState
;
338 mutable short m_macFormerAliasSize
;
339 mutable bool m_macAliasWasEnabled
;
340 mutable void *m_macForegroundPixMap
;
341 mutable void *m_macBackgroundPixMap
;