1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dc.h"
23 #include "wx/gdicmn.h"
24 #include "wx/mac/aga.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
32 #define MM_ISOTROPIC 1
33 #define MM_ANISOTROPIC 2
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 extern int wxPageNumber
;
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 class WXDLLEXPORT wxMacPortSetter
54 wxMacPortSetter( const wxDC
* dc
) ;
60 class WXDLLEXPORT wxDC
: public wxDCBase
62 DECLARE_DYNAMIC_CLASS(wxDC
)
70 // implement base class pure virtuals
71 // ----------------------------------
75 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return TRUE
; }
76 virtual void EndDoc(void) {};
78 virtual void StartPage(void) {};
79 virtual void EndPage(void) {};
81 virtual void SetFont(const wxFont
& font
);
82 virtual void SetPen(const wxPen
& pen
);
83 virtual void SetBrush(const wxBrush
& brush
);
84 virtual void SetBackground(const wxBrush
& brush
);
85 virtual void SetBackgroundMode(int mode
);
86 virtual void SetPalette(const wxPalette
& palette
);
88 virtual void DestroyClippingRegion();
90 virtual wxCoord
GetCharHeight() const;
91 virtual wxCoord
GetCharWidth() const;
92 virtual void DoGetTextExtent(const wxString
& string
,
93 wxCoord
*x
, wxCoord
*y
,
94 wxCoord
*descent
= NULL
,
95 wxCoord
*externalLeading
= NULL
,
96 wxFont
*theFont
= NULL
) const;
98 virtual bool CanDrawBitmap() const;
99 virtual bool CanGetTextExtent() const;
100 virtual int GetDepth() const;
101 virtual wxSize
GetPPI() const;
103 virtual void SetMapMode(int mode
);
104 virtual void SetUserScale(double x
, double y
);
106 virtual void SetLogicalScale(double x
, double y
);
107 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
108 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
109 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
110 virtual void SetLogicalFunction(int function
);
112 virtual void SetTextForeground(const wxColour
& colour
) ;
113 virtual void SetTextBackground(const wxColour
& colour
) ;
115 void ComputeScaleAndOrigin(void);
119 wxCoord
XDEV2LOG(wxCoord x
) const
121 long new_x
= x
- m_deviceOriginX
;
123 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
125 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
127 wxCoord
XDEV2LOGREL(wxCoord x
) const
130 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
132 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
134 wxCoord
YDEV2LOG(wxCoord y
) const
136 long new_y
= y
- m_deviceOriginY
;
138 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
140 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
142 wxCoord
YDEV2LOGREL(wxCoord y
) const
145 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
147 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
149 wxCoord
XLOG2DEV(wxCoord x
) const
151 long new_x
= x
- m_logicalOriginX
;
153 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
155 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
157 wxCoord
XLOG2DEVREL(wxCoord x
) const
160 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
162 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
164 wxCoord
YLOG2DEV(wxCoord y
) const
166 long new_y
= y
- m_logicalOriginY
;
168 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
170 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
172 wxCoord
YLOG2DEVREL(wxCoord y
) const
175 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
177 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
180 RgnHandle
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
181 static MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
185 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
186 int style
= wxFLOOD_SURFACE
);
188 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
190 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
191 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
193 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
194 wxCoord x2
, wxCoord y2
,
195 wxCoord xc
, wxCoord yc
);
197 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
198 double sa
, double ea
);
200 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
201 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
202 wxCoord width
, wxCoord height
,
204 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
206 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
208 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
209 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
210 bool useMask
= FALSE
);
212 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
213 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
216 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
217 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
218 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
220 // this is gnarly - we can't even call this function DoSetClippingRegion()
221 // because of virtual function hiding
222 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
223 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
224 wxCoord width
, wxCoord height
);
225 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
226 wxCoord
*width
, wxCoord
*height
)
228 GetClippingBox(x
, y
, width
, height
);
231 virtual void DoGetSize(int *width
, int *height
) const;
232 virtual void DoGetSizeMM(int* width
, int* height
) const;
234 virtual void DoDrawLines(int n
, wxPoint points
[],
235 wxCoord xoffset
, wxCoord yoffset
);
236 virtual void DoDrawPolygon(int n
, wxPoint points
[],
237 wxCoord xoffset
, wxCoord yoffset
,
238 int fillStyle
= wxODDEVEN_RULE
);
242 // Variables used for scaling
243 double m_mm_to_pix_x
,m_mm_to_pix_y
;
245 bool m_needComputeScaleX
,m_needComputeScaleY
;
246 // If un-scrolled is non-zero or d.o. changes with scrolling.
247 // Set using SetInternalDeviceOrigin().
248 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
249 // To be set by external classes such as wxScrolledWindow
250 // using SetDeviceOrigin()
251 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
253 // Begin implementation for Mac
257 GWorldPtr m_macMask
;
259 // in order to preserve the const inheritance of the virtual functions, we have to
260 // use mutable variables starting from CWPro 5
262 void MacInstallFont() const ;
263 void MacInstallPen() const ;
264 void MacInstallBrush() const ;
266 mutable bool m_macFontInstalled
;
267 mutable bool m_macPenInstalled
;
268 mutable bool m_macBrushInstalled
;
270 RgnHandle m_macBoundaryClipRgn
;
271 RgnHandle m_macCurrentClipRgn
;
272 Point m_macLocalOrigin
;
273 void MacSetupPort( AGAPortHelper
* ph
) const ;