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 AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) = 0 ;
59 virtual void AddCircle( wxCoord x
, wxCoord y
, wxCoord r
) = 0 ;
61 virtual void CloseSubpath() = 0 ;
64 class WXDLLEXPORT wxGraphicContext
67 virtual ~wxGraphicContext() {}
69 virtual void Clip( const wxRegion
®ion
) = 0 ;
71 virtual void StrokePath( const wxGraphicPath
*path
) = 0 ;
73 virtual void DrawPath( const wxGraphicPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0 ;
75 virtual void FillPath( const wxGraphicPath
*path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
) = 0 ;
77 virtual void SetPen( const wxPen
&pen
) = 0 ;
79 virtual void SetBrush( const wxBrush
&brush
) = 0 ;
81 virtual wxGraphicPath
* CreatePath() = 0 ;
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 class WXDLLEXPORT wxDC
: public wxDCBase
90 DECLARE_DYNAMIC_CLASS(wxDC
)
91 DECLARE_NO_COPY_CLASS(wxDC
)
99 // implement base class pure virtuals
100 // ----------------------------------
102 virtual void Clear();
104 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
105 virtual void EndDoc(void) {};
107 virtual void StartPage(void) {};
108 virtual void EndPage(void) {};
110 virtual void SetFont(const wxFont
& font
);
111 virtual void SetPen(const wxPen
& pen
);
112 virtual void SetBrush(const wxBrush
& brush
);
113 virtual void SetBackground(const wxBrush
& brush
);
114 virtual void SetBackgroundMode(int mode
);
115 virtual void SetPalette(const wxPalette
& palette
);
117 virtual void DestroyClippingRegion();
119 virtual wxCoord
GetCharHeight() const;
120 virtual wxCoord
GetCharWidth() const;
121 virtual void DoGetTextExtent(const wxString
& string
,
122 wxCoord
*x
, wxCoord
*y
,
123 wxCoord
*descent
= NULL
,
124 wxCoord
*externalLeading
= NULL
,
125 wxFont
*theFont
= NULL
) const;
126 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
128 virtual bool CanDrawBitmap() const;
129 virtual bool CanGetTextExtent() const;
130 virtual int GetDepth() const;
131 virtual wxSize
GetPPI() const;
133 virtual void SetMapMode(int mode
);
134 virtual void SetUserScale(double x
, double y
);
136 virtual void SetLogicalScale(double x
, double y
);
137 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
138 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
139 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
140 virtual void SetLogicalFunction(int function
);
142 virtual void SetTextForeground(const wxColour
& colour
) ;
143 virtual void SetTextBackground(const wxColour
& colour
) ;
145 virtual void ComputeScaleAndOrigin();
149 wxCoord
XDEV2LOG(wxCoord x
) const
151 long new_x
= x
- m_deviceOriginX
;
153 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
155 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
157 wxCoord
XDEV2LOGREL(wxCoord x
) const
160 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
162 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
164 wxCoord
YDEV2LOG(wxCoord y
) const
166 long new_y
= y
- m_deviceOriginY
;
168 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
170 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
172 wxCoord
YDEV2LOGREL(wxCoord y
) const
175 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
177 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
179 wxCoord
XLOG2DEV(wxCoord x
) const
181 long new_x
= x
- m_logicalOriginX
;
183 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
185 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
187 wxCoord
XLOG2DEVREL(wxCoord x
) const
190 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
192 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
194 wxCoord
YLOG2DEV(wxCoord y
) const
196 long new_y
= y
- m_logicalOriginY
;
198 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
200 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
202 wxCoord
YLOG2DEVREL(wxCoord y
) const
205 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
207 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
209 wxCoord
XLOG2DEVMAC(wxCoord x
) const
211 long new_x
= x
- m_logicalOriginX
;
213 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
215 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
217 wxCoord
YLOG2DEVMAC(wxCoord y
) const
219 long new_y
= y
- m_logicalOriginY
;
221 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
223 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
225 #if wxMAC_USE_CORE_GRAPHICS
226 wxGraphicContext
* GetGraphicContext() { return m_graphicContext
; }
228 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
229 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
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
);
240 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
242 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
243 wxCoord x2
, wxCoord y2
,
244 wxCoord xc
, wxCoord yc
);
246 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
247 double sa
, double ea
);
249 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
250 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
251 wxCoord width
, wxCoord height
,
253 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
255 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
257 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
258 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
259 bool useMask
= false);
261 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
262 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
265 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
266 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
267 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
269 // this is gnarly - we can't even call this function DoSetClippingRegion()
270 // because of virtual function hiding
271 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
272 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
273 wxCoord width
, wxCoord height
);
275 virtual void DoGetSizeMM(int* width
, int* height
) const;
277 virtual void DoDrawLines(int n
, wxPoint points
[],
278 wxCoord xoffset
, wxCoord yoffset
);
279 virtual void DoDrawPolygon(int n
, wxPoint points
[],
280 wxCoord xoffset
, wxCoord yoffset
,
281 int fillStyle
= wxODDEVEN_RULE
);
285 // Variables used for scaling
286 double m_mm_to_pix_x
,m_mm_to_pix_y
;
288 bool m_needComputeScaleX
,m_needComputeScaleY
;
289 // If un-scrolled is non-zero or d.o. changes with scrolling.
290 // Set using SetInternalDeviceOrigin().
291 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
292 // To be set by external classes such as wxScrolledWindow
293 // using SetDeviceOrigin()
294 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
296 // Begin implementation for Mac
299 #if !wxMAC_USE_CORE_GRAPHICS
300 WXHBITMAP m_macMask
;
303 // in order to preserve the const inheritance of the virtual functions, we have to
304 // use mutable variables starting from CWPro 5
306 void MacInstallFont() const ;
307 #if !wxMAC_USE_CORE_GRAPHICS
308 void MacInstallPen() const ;
309 void MacInstallBrush() const ;
312 wxPoint m_macLocalOrigin
;
313 mutable void* m_macATSUIStyle
;
316 #if wxMAC_USE_CORE_GRAPHICS
318 wxGraphicContext
* m_graphicContext
;
319 wxPoint m_macLocalOriginInPort
;
321 mutable bool m_macFontInstalled
;
322 mutable bool m_macPenInstalled
;
323 mutable bool m_macBrushInstalled
;
325 WXHRGN m_macBoundaryClipRgn
;
326 WXHRGN m_macCurrentClipRgn
;
327 void MacSetupPort( wxMacPortStateHelper
* ph
) const ;
328 void MacCleanupPort( wxMacPortStateHelper
* ph
) const ;
329 mutable wxMacPortStateHelper
* m_macCurrentPortStateHelper
;
330 mutable bool m_macFormerAliasState
;
331 mutable short m_macFormerAliasSize
;
332 mutable bool m_macAliasWasEnabled
;
333 mutable void* m_macForegroundPixMap
;
334 mutable void* m_macBackgroundPixMap
;
337 #if wxMAC_USE_CORE_GRAPHICS