1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "dc.h"
23 #include "wx/gdicmn.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
31 #define MM_ISOTROPIC 1
32 #define MM_ANISOTROPIC 2
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 extern int wxPageNumber
;
46 class wxMacPortStateHelper
;
48 class WXDLLEXPORT wxGraphicPath
51 virtual ~wxGraphicPath() {}
53 virtual void MoveToPoint( wxCoord x1
, wxCoord y1
) = 0 ;
55 virtual void AddLineToPoint( wxCoord x1
, wxCoord y1
) = 0 ;
57 virtual void AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
) = 0 ;
59 virtual void AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
61 virtual void AddCircle( wxCoord x
, wxCoord y
, wxCoord r
) = 0 ;
63 virtual void CloseSubpath() = 0 ;
66 class WXDLLEXPORT wxGraphicContext
69 virtual ~wxGraphicContext() {}
71 virtual void Clip( const wxRegion
®ion
) = 0 ;
73 virtual void StrokePath( const wxGraphicPath
*path
) = 0 ;
75 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0 ;
77 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0 ;
79 virtual void SetPen( const wxPen
&pen
) = 0 ;
81 virtual void SetBrush( const wxBrush
&brush
) = 0 ;
83 virtual wxGraphicPath
* CreatePath() = 0 ;
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
90 class WXDLLEXPORT wxDC
: public wxDCBase
92 DECLARE_DYNAMIC_CLASS(wxDC
)
93 DECLARE_NO_COPY_CLASS(wxDC
)
101 // implement base class pure virtuals
102 // ----------------------------------
104 virtual void Clear();
106 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
107 virtual void EndDoc(void) {};
109 virtual void StartPage(void) {};
110 virtual void EndPage(void) {};
112 virtual void SetFont(const wxFont
& font
);
113 virtual void SetPen(const wxPen
& pen
);
114 virtual void SetBrush(const wxBrush
& brush
);
115 virtual void SetBackground(const wxBrush
& brush
);
116 virtual void SetBackgroundMode(int mode
);
117 virtual void SetPalette(const wxPalette
& palette
);
119 virtual void DestroyClippingRegion();
121 virtual wxCoord
GetCharHeight() const;
122 virtual wxCoord
GetCharWidth() const;
123 virtual void DoGetTextExtent(const wxString
& string
,
124 wxCoord
*x
, wxCoord
*y
,
125 wxCoord
*descent
= NULL
,
126 wxCoord
*externalLeading
= NULL
,
127 wxFont
*theFont
= NULL
) const;
128 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
130 virtual bool CanDrawBitmap() const;
131 virtual bool CanGetTextExtent() const;
132 virtual int GetDepth() const;
133 virtual wxSize
GetPPI() const;
135 virtual void SetMapMode(int mode
);
136 virtual void SetUserScale(double x
, double y
);
138 virtual void SetLogicalScale(double x
, double y
);
139 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
140 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
141 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
142 virtual void SetLogicalFunction(int function
);
144 virtual void SetTextForeground(const wxColour
& colour
) ;
145 virtual void SetTextBackground(const wxColour
& colour
) ;
147 virtual void ComputeScaleAndOrigin();
151 wxCoord
XDEV2LOG(wxCoord x
) const
153 long new_x
= x
- m_deviceOriginX
;
155 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
157 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
159 wxCoord
XDEV2LOGREL(wxCoord x
) const
162 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
164 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
166 wxCoord
YDEV2LOG(wxCoord y
) const
168 long new_y
= y
- m_deviceOriginY
;
170 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
172 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
174 wxCoord
YDEV2LOGREL(wxCoord y
) const
177 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
179 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
181 wxCoord
XLOG2DEV(wxCoord x
) const
183 long new_x
= x
- m_logicalOriginX
;
185 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
187 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
189 wxCoord
XLOG2DEVREL(wxCoord x
) const
192 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
194 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
196 wxCoord
YLOG2DEV(wxCoord y
) const
198 long new_y
= y
- m_logicalOriginY
;
200 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
202 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
204 wxCoord
YLOG2DEVREL(wxCoord y
) const
207 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
209 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
211 wxCoord
XLOG2DEVMAC(wxCoord x
) const
213 long new_x
= x
- m_logicalOriginX
;
215 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
217 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
219 wxCoord
YLOG2DEVMAC(wxCoord y
) const
221 long new_y
= y
- m_logicalOriginY
;
223 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
225 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
227 #if wxMAC_USE_CORE_GRAPHICS
228 wxGraphicContext
* GetGraphicContext() { return m_graphicContext
; }
230 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
231 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
236 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
237 int style
= wxFLOOD_SURFACE
);
239 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
241 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
242 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
243 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
276 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
277 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
278 wxCoord width
, wxCoord height
);
280 virtual void DoGetSizeMM(int* width
, int* height
) const;
282 virtual void DoDrawLines(int n
, wxPoint points
[],
283 wxCoord xoffset
, wxCoord yoffset
);
284 virtual void DoDrawPolygon(int n
, wxPoint points
[],
285 wxCoord xoffset
, wxCoord yoffset
,
286 int fillStyle
= wxODDEVEN_RULE
);
290 // Variables used for scaling
291 double m_mm_to_pix_x
,m_mm_to_pix_y
;
293 bool m_needComputeScaleX
,m_needComputeScaleY
;
294 // If un-scrolled is non-zero or d.o. changes with scrolling.
295 // Set using SetInternalDeviceOrigin().
296 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
297 // To be set by external classes such as wxScrolledWindow
298 // using SetDeviceOrigin()
299 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
301 // Begin implementation for Mac
304 #if !wxMAC_USE_CORE_GRAPHICS
305 WXHBITMAP m_macMask
;
308 // in order to preserve the const inheritance of the virtual functions, we have to
309 // use mutable variables starting from CWPro 5
311 void MacInstallFont() const ;
312 #if !wxMAC_USE_CORE_GRAPHICS
313 void MacInstallPen() const ;
314 void MacInstallBrush() const ;
317 wxPoint m_macLocalOrigin
;
318 mutable void* m_macATSUIStyle
;
321 #if wxMAC_USE_CORE_GRAPHICS
323 wxGraphicContext
* m_graphicContext
;
324 wxPoint m_macLocalOriginInPort
;
326 mutable bool m_macFontInstalled
;
327 mutable bool m_macPenInstalled
;
328 mutable bool m_macBrushInstalled
;
330 WXHRGN m_macBoundaryClipRgn
;
331 WXHRGN m_macCurrentClipRgn
;
332 void MacSetupPort( wxMacPortStateHelper
* ph
) const ;
333 void MacCleanupPort( wxMacPortStateHelper
* ph
) const ;
334 mutable wxMacPortStateHelper
* m_macCurrentPortStateHelper
;
335 mutable bool m_macFormerAliasState
;
336 mutable short m_macFormerAliasSize
;
337 mutable bool m_macAliasWasEnabled
;
338 mutable void* m_macForegroundPixMap
;
339 mutable void* m_macBackgroundPixMap
;
342 #if wxMAC_USE_CORE_GRAPHICS