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
;
47 class wxMacCGContext
;
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 class WXDLLEXPORT wxDC
: public wxDCBase
54 DECLARE_DYNAMIC_CLASS(wxDC
)
55 DECLARE_NO_COPY_CLASS(wxDC
)
63 // implement base class pure virtuals
64 // ----------------------------------
68 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
69 virtual void EndDoc(void) {};
71 virtual void StartPage(void) {};
72 virtual void EndPage(void) {};
74 virtual void SetFont(const wxFont
& font
);
75 virtual void SetPen(const wxPen
& pen
);
76 virtual void SetBrush(const wxBrush
& brush
);
77 virtual void SetBackground(const wxBrush
& brush
);
78 virtual void SetBackgroundMode(int mode
);
79 virtual void SetPalette(const wxPalette
& palette
);
81 virtual void DestroyClippingRegion();
83 virtual wxCoord
GetCharHeight() const;
84 virtual wxCoord
GetCharWidth() const;
85 virtual void DoGetTextExtent(const wxString
& string
,
86 wxCoord
*x
, wxCoord
*y
,
87 wxCoord
*descent
= NULL
,
88 wxCoord
*externalLeading
= NULL
,
89 wxFont
*theFont
= NULL
) const;
90 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
92 virtual bool CanDrawBitmap() const;
93 virtual bool CanGetTextExtent() const;
94 virtual int GetDepth() const;
95 virtual wxSize
GetPPI() const;
97 virtual void SetMapMode(int mode
);
98 virtual void SetUserScale(double x
, double y
);
100 virtual void SetLogicalScale(double x
, double y
);
101 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
102 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
103 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
104 virtual void SetLogicalFunction(int function
);
106 virtual void SetTextForeground(const wxColour
& colour
) ;
107 virtual void SetTextBackground(const wxColour
& colour
) ;
109 virtual void ComputeScaleAndOrigin();
113 wxCoord
XDEV2LOG(wxCoord x
) const
115 long new_x
= x
- m_deviceOriginX
;
117 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
119 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
121 wxCoord
XDEV2LOGREL(wxCoord x
) const
124 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
126 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
128 wxCoord
YDEV2LOG(wxCoord y
) const
130 long new_y
= y
- m_deviceOriginY
;
132 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
134 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
136 wxCoord
YDEV2LOGREL(wxCoord y
) const
139 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
141 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
143 wxCoord
XLOG2DEV(wxCoord x
) const
145 long new_x
= x
- m_logicalOriginX
;
147 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
149 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
151 wxCoord
XLOG2DEVREL(wxCoord x
) const
154 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
156 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
158 wxCoord
YLOG2DEV(wxCoord y
) const
160 long new_y
= y
- m_logicalOriginY
;
162 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
164 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
166 wxCoord
YLOG2DEVREL(wxCoord y
) const
169 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
171 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
173 wxCoord
XLOG2DEVMAC(wxCoord x
) const
175 long new_x
= x
- m_logicalOriginX
;
177 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
179 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
181 wxCoord
YLOG2DEVMAC(wxCoord y
) const
183 long new_y
= y
- m_logicalOriginY
;
185 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
187 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
190 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
191 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
195 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
196 int style
= wxFLOOD_SURFACE
);
198 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
200 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
201 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
203 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
204 wxCoord x2
, wxCoord y2
,
205 wxCoord xc
, wxCoord yc
);
207 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
208 double sa
, double ea
);
210 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
211 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
212 wxCoord width
, wxCoord height
,
214 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
216 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
218 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
219 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
220 bool useMask
= false);
222 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
223 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
226 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
227 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
228 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
230 // this is gnarly - we can't even call this function DoSetClippingRegion()
231 // because of virtual function hiding
232 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
233 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
234 wxCoord width
, wxCoord height
);
236 virtual void DoGetSizeMM(int* width
, int* height
) const;
238 virtual void DoDrawLines(int n
, wxPoint points
[],
239 wxCoord xoffset
, wxCoord yoffset
);
240 virtual void DoDrawPolygon(int n
, wxPoint points
[],
241 wxCoord xoffset
, wxCoord yoffset
,
242 int fillStyle
= wxODDEVEN_RULE
);
246 // Variables used for scaling
247 double m_mm_to_pix_x
,m_mm_to_pix_y
;
249 bool m_needComputeScaleX
,m_needComputeScaleY
;
250 // If un-scrolled is non-zero or d.o. changes with scrolling.
251 // Set using SetInternalDeviceOrigin().
252 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
253 // To be set by external classes such as wxScrolledWindow
254 // using SetDeviceOrigin()
255 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
257 // Begin implementation for Mac
261 WXHBITMAP m_macMask
;
263 // in order to preserve the const inheritance of the virtual functions, we have to
264 // use mutable variables starting from CWPro 5
266 void MacInstallFont() const ;
267 void MacInstallPen() const ;
268 void MacInstallBrush() const ;
270 mutable bool m_macFontInstalled
;
271 mutable bool m_macPenInstalled
;
272 mutable bool m_macBrushInstalled
;
274 WXHRGN m_macBoundaryClipRgn
;
275 WXHRGN m_macCurrentClipRgn
;
276 wxPoint m_macLocalOrigin
;
277 void MacSetupPort( wxMacPortStateHelper
* ph
) const ;
278 void MacCleanupPort( wxMacPortStateHelper
* ph
) const ;
279 mutable void* m_macATSUIStyle
;
280 mutable wxMacPortStateHelper
* m_macCurrentPortStateHelper
;
281 mutable bool m_macFormerAliasState
;
282 mutable short m_macFormerAliasSize
;
283 mutable bool m_macAliasWasEnabled
;
284 mutable void* m_macForegroundPixMap
;
285 mutable void* m_macBackgroundPixMap
;
289 wxMacCGContext
* m_macGraphicContext
;
290 void MacSetupGraphicContext() ;