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