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 // 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)
55 virtual void AddArcToPoint( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord r
) = 0 ;
57 virtual void AddArc( wxCoord x
, wxCoord y
, wxCoord r
, double startAngle
, double endAngle
, bool clockwise
) = 0 ;
59 virtual void CloseSubpath() = 0;
62 class WXDLLEXPORT wxGraphicContext
65 virtual ~wxGraphicContext() {}
67 virtual wxGraphicPath
* CreatePath() = 0;
69 virtual void PushState() = 0 ;
71 virtual void PopState() = 0 ;
73 virtual void Clip( const wxRegion
®ion
) = 0;
75 virtual void SetPen( const wxPen
&pen
) = 0;
77 virtual void SetBrush( const wxBrush
&brush
) = 0;
79 virtual void SetFont( const wxFont
&font
) = 0 ;
81 virtual void SetTextColor( const wxColour
&col
) = 0 ;
83 virtual void StrokePath( const wxGraphicPath
*path
) = 0;
85 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0;
87 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0;
89 virtual void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
91 virtual void DrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
93 virtual void DrawText( const wxString
&str
, wxCoord x
, wxCoord y
, double angle
) = 0 ;
95 virtual void GetTextExtent( const wxString
&text
, wxCoord
*width
, wxCoord
*height
,
96 wxCoord
*descent
, wxCoord
*externalLeading
) const = 0 ;
98 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const = 0 ;
100 virtual void Translate( wxCoord dx
, wxCoord dy
) = 0 ;
102 virtual void Scale( wxCoord xScale
, wxCoord yScale
) = 0 ;
105 class WXDLLEXPORT wxDC
: public wxDCBase
107 DECLARE_DYNAMIC_CLASS(wxDC
)
108 DECLARE_NO_COPY_CLASS(wxDC
)
114 // implement base class pure virtuals
115 // ----------------------------------
117 virtual void Clear();
119 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
120 virtual void EndDoc(void) {}
122 virtual void StartPage(void) {}
123 virtual void EndPage(void) {}
125 virtual void SetFont(const wxFont
& font
);
126 virtual void SetPen(const wxPen
& pen
);
127 virtual void SetBrush(const wxBrush
& brush
);
128 virtual void SetBackground(const wxBrush
& brush
);
129 virtual void SetBackgroundMode(int mode
);
130 virtual void SetPalette(const wxPalette
& palette
);
132 virtual void DestroyClippingRegion();
134 virtual wxCoord
GetCharHeight() const;
135 virtual wxCoord
GetCharWidth() const;
137 virtual bool CanDrawBitmap() const;
138 virtual bool CanGetTextExtent() const;
139 virtual int GetDepth() const;
140 virtual wxSize
GetPPI() const;
142 virtual void SetMapMode(int mode
);
143 virtual void SetUserScale(double x
, double y
);
145 virtual void SetLogicalScale(double x
, double y
);
146 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
147 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
148 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
149 virtual void SetLogicalFunction(int function
);
151 virtual void SetTextForeground(const wxColour
& colour
);
152 virtual void SetTextBackground(const wxColour
& colour
);
154 virtual void ComputeScaleAndOrigin();
157 wxCoord
XDEV2LOG(wxCoord x
) const
159 long new_x
= x
- m_deviceOriginX
;
161 return (wxCoord
)((double)new_x
/ m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
163 return (wxCoord
)((double)new_x
/ m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
166 wxCoord
XDEV2LOGREL(wxCoord x
) const
169 return (wxCoord
)((double)x
/ m_scaleX
+ 0.5);
171 return (wxCoord
)((double)x
/ m_scaleX
- 0.5);
174 wxCoord
YDEV2LOG(wxCoord y
) const
176 long new_y
= y
- m_deviceOriginY
;
178 return (wxCoord
)((double)new_y
/ m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
180 return (wxCoord
)((double)new_y
/ m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
183 wxCoord
YDEV2LOGREL(wxCoord y
) const
186 return (wxCoord
)((double)y
/ m_scaleY
+ 0.5);
188 return (wxCoord
)((double)y
/ m_scaleY
- 0.5);
191 wxCoord
XLOG2DEV(wxCoord x
) const
193 long new_x
= x
- m_logicalOriginX
;
195 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
197 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
200 wxCoord
XLOG2DEVREL(wxCoord x
) const
203 return (wxCoord
)((double)x
* m_scaleX
+ 0.5);
205 return (wxCoord
)((double)x
* m_scaleX
- 0.5);
208 wxCoord
YLOG2DEV(wxCoord y
) const
210 long new_y
= y
- m_logicalOriginY
;
212 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
214 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
217 wxCoord
YLOG2DEVREL(wxCoord y
) const
220 return (wxCoord
)((double)y
* m_scaleY
+ 0.5);
222 return (wxCoord
)((double)y
* m_scaleY
- 0.5);
225 wxCoord
XLOG2DEVMAC(wxCoord x
) const
227 long new_x
= x
- m_logicalOriginX
;
229 return (wxCoord
)((double)new_x
* m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
231 return (wxCoord
)((double)new_x
* m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
234 wxCoord
YLOG2DEVMAC(wxCoord y
) const
236 long new_y
= y
- m_logicalOriginY
;
238 return (wxCoord
)((double)new_y
* m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
240 return (wxCoord
)((double)new_y
* m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
243 #if wxMAC_USE_CORE_GRAPHICS
244 wxGraphicContext
* GetGraphicContext() { return m_graphicContext
; }
246 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
247 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
);
251 virtual void DoGetTextExtent(const wxString
& string
,
252 wxCoord
*x
, wxCoord
*y
,
253 wxCoord
*descent
= NULL
,
254 wxCoord
*externalLeading
= NULL
,
255 wxFont
*theFont
= NULL
) const;
257 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
259 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
260 int style
= wxFLOOD_SURFACE
);
262 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
264 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
266 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
267 virtual void DoDrawSpline(wxList
*points
);
270 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
272 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
273 wxCoord x2
, wxCoord y2
,
274 wxCoord xc
, wxCoord yc
);
276 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
277 double sa
, double ea
);
279 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
280 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
281 wxCoord width
, wxCoord height
,
283 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
285 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
287 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
288 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
289 bool useMask
= false);
291 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
292 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
295 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
296 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
297 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
299 // this is gnarly - we can't even call this function DoSetClippingRegion()
300 // because of virtual function hiding
302 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
303 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
304 wxCoord width
, wxCoord height
);
306 virtual void DoGetSizeMM(int *width
, int *height
) const;
308 virtual void DoDrawLines(int n
, wxPoint points
[],
309 wxCoord xoffset
, wxCoord yoffset
);
310 virtual void DoDrawPolygon(int n
, wxPoint points
[],
311 wxCoord xoffset
, wxCoord yoffset
,
312 int fillStyle
= wxODDEVEN_RULE
);
316 double m_mm_to_pix_x
, m_mm_to_pix_y
;
318 // To be set using SetDeviceOrigin()
319 // by external classes such as wxScrolledWindow
320 long m_externalDeviceOriginX
, m_externalDeviceOriginY
;
322 #if !wxMAC_USE_CORE_GRAPHICS
323 // If un-scrolled is non-zero or d.o. changes with scrolling.
324 // Set using SetInternalDeviceOrigin().
325 long m_internalDeviceOriginX
, m_internalDeviceOriginY
;
331 bool m_needComputeScaleX
, m_needComputeScaleY
;
335 void MacInstallFont() const;
337 // in order to preserve the const inheritance of the virtual functions,
338 // we have to use mutable variables starting from CWPro 5
339 wxPoint m_macLocalOrigin
;
340 mutable void *m_macATSUIStyle
;
344 #if wxMAC_USE_CORE_GRAPHICS
345 wxGraphicContext
*m_graphicContext
;
346 wxPoint m_macLocalOriginInPort
;
348 void MacInstallPen() const;
349 void MacInstallBrush() const;
351 void MacSetupPort( wxMacPortStateHelper
*ph
) const;
352 void MacCleanupPort( wxMacPortStateHelper
*ph
) const;
354 mutable wxMacPortStateHelper
*m_macCurrentPortStateHelper
;
356 mutable bool m_macFontInstalled
;
357 mutable bool m_macPenInstalled
;
358 mutable bool m_macBrushInstalled
;
360 WXHRGN m_macBoundaryClipRgn
;
361 WXHRGN m_macCurrentClipRgn
;
362 mutable bool m_macFormerAliasState
;
363 mutable short m_macFormerAliasSize
;
364 mutable bool m_macAliasWasEnabled
;
365 mutable void *m_macForegroundPixMap
;
366 mutable void *m_macBackgroundPixMap
;