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
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 class wxMacPortStateHelper
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 class WXDLLEXPORT wxDC
: public wxDCBase
47 DECLARE_DYNAMIC_CLASS(wxDC
)
48 DECLARE_NO_COPY_CLASS(wxDC
)
56 // implement base class pure virtuals
57 // ----------------------------------
61 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
62 virtual void EndDoc(void) {};
64 virtual void StartPage(void) {};
65 virtual void EndPage(void) {};
67 virtual void SetFont(const wxFont
& font
);
68 virtual void SetPen(const wxPen
& pen
);
69 virtual void SetBrush(const wxBrush
& brush
);
70 virtual void SetBackground(const wxBrush
& brush
);
71 virtual void SetBackgroundMode(int mode
);
72 virtual void SetPalette(const wxPalette
& palette
);
74 virtual void DestroyClippingRegion();
76 virtual wxCoord
GetCharHeight() const;
77 virtual wxCoord
GetCharWidth() const;
78 virtual void DoGetTextExtent(const wxString
& string
,
79 wxCoord
*x
, wxCoord
*y
,
80 wxCoord
*descent
= NULL
,
81 wxCoord
*externalLeading
= NULL
,
82 wxFont
*theFont
= NULL
) const;
83 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
85 virtual bool CanDrawBitmap() const;
86 virtual bool CanGetTextExtent() const;
87 virtual int GetDepth() const;
88 virtual wxSize
GetPPI() const;
90 virtual void SetMapMode(int mode
);
91 virtual void SetUserScale(double x
, double y
);
93 virtual void SetLogicalScale(double x
, double y
);
94 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
95 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
96 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
97 virtual void SetLogicalFunction(int function
);
99 virtual void SetTextForeground(const wxColour
& colour
) ;
100 virtual void SetTextBackground(const wxColour
& colour
) ;
102 virtual void ComputeScaleAndOrigin();
106 wxCoord
XDEV2LOG(wxCoord x
) const
108 long new_x
= x
- m_deviceOriginX
;
110 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
112 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
114 wxCoord
XDEV2LOGREL(wxCoord x
) const
117 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
119 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
121 wxCoord
YDEV2LOG(wxCoord y
) const
123 long new_y
= y
- m_deviceOriginY
;
125 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
127 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
129 wxCoord
YDEV2LOGREL(wxCoord y
) const
132 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
134 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
136 wxCoord
XLOG2DEV(wxCoord x
) const
138 long new_x
= x
- m_logicalOriginX
;
140 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
142 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
144 wxCoord
XLOG2DEVREL(wxCoord x
) const
147 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
149 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
151 wxCoord
YLOG2DEV(wxCoord y
) const
153 long new_y
= y
- m_logicalOriginY
;
155 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
157 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
159 wxCoord
YLOG2DEVREL(wxCoord y
) const
162 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
164 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
166 wxCoord
XLOG2DEVMAC(wxCoord x
) const
168 long new_x
= x
- m_logicalOriginX
;
170 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
172 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
174 wxCoord
YLOG2DEVMAC(wxCoord y
) const
176 long new_y
= y
- m_logicalOriginY
;
178 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
180 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
183 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
184 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
188 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
189 int style
= wxFLOOD_SURFACE
);
191 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
193 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
194 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
196 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
197 wxCoord x2
, wxCoord y2
,
198 wxCoord xc
, wxCoord yc
);
200 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
201 double sa
, double ea
);
203 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
204 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
205 wxCoord width
, wxCoord height
,
207 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
209 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
211 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
212 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
213 bool useMask
= false);
215 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
216 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
219 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
220 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
221 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
223 // this is gnarly - we can't even call this function DoSetClippingRegion()
224 // because of virtual function hiding
225 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
226 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
227 wxCoord width
, wxCoord height
);
229 virtual void DoGetSizeMM(int* width
, int* height
) const;
231 virtual void DoDrawLines(int n
, wxPoint points
[],
232 wxCoord xoffset
, wxCoord yoffset
);
233 virtual void DoDrawPolygon(int n
, wxPoint points
[],
234 wxCoord xoffset
, wxCoord yoffset
,
235 int fillStyle
= wxODDEVEN_RULE
);
239 // Variables used for scaling
240 double m_mm_to_pix_x
,m_mm_to_pix_y
;
242 bool m_needComputeScaleX
,m_needComputeScaleY
;
243 // If un-scrolled is non-zero or d.o. changes with scrolling.
244 // Set using SetInternalDeviceOrigin().
245 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
246 // To be set by external classes such as wxScrolledWindow
247 // using SetDeviceOrigin()
248 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
250 // Begin implementation for Mac
254 WXHBITMAP m_macMask
;
256 // in order to preserve the const inheritance of the virtual functions, we have to
257 // use mutable variables starting from CWPro 5
259 void MacInstallFont() const ;
260 void MacInstallPen() const ;
261 void MacInstallBrush() const ;
263 mutable bool m_macFontInstalled
;
264 mutable bool m_macPenInstalled
;
265 mutable bool m_macBrushInstalled
;
267 WXHRGN m_macBoundaryClipRgn
;
268 WXHRGN m_macCurrentClipRgn
;
269 wxPoint m_macLocalOrigin
;
270 void MacSetupPort( wxMacPortStateHelper
* ph
) const ;
271 void MacCleanupPort( wxMacPortStateHelper
* ph
) const ;
272 mutable void* m_macATSUIStyle
;
273 mutable wxMacPortStateHelper
* m_macCurrentPortStateHelper
;
274 mutable bool m_macFormerAliasState
;
275 mutable short m_macFormerAliasSize
;
276 mutable bool m_macAliasWasEnabled
;
277 mutable void* m_macForegroundPixMap
;
278 mutable void* m_macBackgroundPixMap
;