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 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 class WXDLLEXPORT wxDC
: public wxDCBase
53 DECLARE_DYNAMIC_CLASS(wxDC
)
54 DECLARE_NO_COPY_CLASS(wxDC
)
62 // implement base class pure virtuals
63 // ----------------------------------
67 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return TRUE
; }
68 virtual void EndDoc(void) {};
70 virtual void StartPage(void) {};
71 virtual void EndPage(void) {};
73 virtual void SetFont(const wxFont
& font
);
74 virtual void SetPen(const wxPen
& pen
);
75 virtual void SetBrush(const wxBrush
& brush
);
76 virtual void SetBackground(const wxBrush
& brush
);
77 virtual void SetBackgroundMode(int mode
);
78 virtual void SetPalette(const wxPalette
& palette
);
80 virtual void DestroyClippingRegion();
82 virtual wxCoord
GetCharHeight() const;
83 virtual wxCoord
GetCharWidth() const;
84 virtual void DoGetTextExtent(const wxString
& string
,
85 wxCoord
*x
, wxCoord
*y
,
86 wxCoord
*descent
= NULL
,
87 wxCoord
*externalLeading
= NULL
,
88 wxFont
*theFont
= NULL
) const;
89 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
91 virtual bool CanDrawBitmap() const;
92 virtual bool CanGetTextExtent() const;
93 virtual int GetDepth() const;
94 virtual wxSize
GetPPI() const;
96 virtual void SetMapMode(int mode
);
97 virtual void SetUserScale(double x
, double y
);
99 virtual void SetLogicalScale(double x
, double y
);
100 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
101 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
102 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
103 virtual void SetLogicalFunction(int function
);
105 virtual void SetTextForeground(const wxColour
& colour
) ;
106 virtual void SetTextBackground(const wxColour
& colour
) ;
108 void ComputeScaleAndOrigin(void);
112 wxCoord
XDEV2LOG(wxCoord x
) const
114 long new_x
= x
- m_deviceOriginX
;
116 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
118 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
120 wxCoord
XDEV2LOGREL(wxCoord x
) const
123 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
125 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
127 wxCoord
YDEV2LOG(wxCoord y
) const
129 long new_y
= y
- m_deviceOriginY
;
131 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
133 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
135 wxCoord
YDEV2LOGREL(wxCoord y
) const
138 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
140 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
142 wxCoord
XLOG2DEV(wxCoord x
) const
144 long new_x
= x
- m_logicalOriginX
;
146 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
148 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
150 wxCoord
XLOG2DEVREL(wxCoord x
) const
153 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
155 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
157 wxCoord
YLOG2DEV(wxCoord y
) const
159 long new_y
= y
- m_logicalOriginY
;
161 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
163 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
165 wxCoord
YLOG2DEVREL(wxCoord y
) const
168 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
170 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
172 wxCoord
XLOG2DEVMAC(wxCoord x
) const
174 long new_x
= x
- m_logicalOriginX
;
176 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
178 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
180 wxCoord
YLOG2DEVMAC(wxCoord y
) const
182 long new_y
= y
- m_logicalOriginY
;
184 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
186 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
189 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
190 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
194 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
195 int style
= wxFLOOD_SURFACE
);
197 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
199 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
200 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
202 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
203 wxCoord x2
, wxCoord y2
,
204 wxCoord xc
, wxCoord yc
);
206 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
207 double sa
, double ea
);
209 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
210 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
211 wxCoord width
, wxCoord height
,
213 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
215 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
217 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
218 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
219 bool useMask
= FALSE
);
221 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
222 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
225 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
226 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
227 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
229 // this is gnarly - we can't even call this function DoSetClippingRegion()
230 // because of virtual function hiding
231 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
232 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
233 wxCoord width
, wxCoord height
);
234 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
235 wxCoord
*width
, wxCoord
*height
)
237 GetClippingBox(x
, y
, width
, height
);
240 virtual void DoGetSizeMM(int* width
, int* height
) const;
242 virtual void DoDrawLines(int n
, wxPoint points
[],
243 wxCoord xoffset
, wxCoord yoffset
);
244 virtual void DoDrawPolygon(int n
, wxPoint points
[],
245 wxCoord xoffset
, wxCoord yoffset
,
246 int fillStyle
= wxODDEVEN_RULE
);
250 // Variables used for scaling
251 double m_mm_to_pix_x
,m_mm_to_pix_y
;
253 bool m_needComputeScaleX
,m_needComputeScaleY
;
254 // If un-scrolled is non-zero or d.o. changes with scrolling.
255 // Set using SetInternalDeviceOrigin().
256 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
257 // To be set by external classes such as wxScrolledWindow
258 // using SetDeviceOrigin()
259 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
261 // Begin implementation for Mac
265 WXHBITMAP m_macMask
;
267 // in order to preserve the const inheritance of the virtual functions, we have to
268 // use mutable variables starting from CWPro 5
270 void MacInstallFont() const ;
271 void MacInstallPen() const ;
272 void MacInstallBrush() const ;
274 mutable bool m_macFontInstalled
;
275 mutable bool m_macPenInstalled
;
276 mutable bool m_macBrushInstalled
;
278 WXHRGN m_macBoundaryClipRgn
;
279 WXHRGN m_macCurrentClipRgn
;
280 wxPoint m_macLocalOrigin
;
281 void MacSetupPort( wxMacPortStateHelper
* ph
) const ;
282 void MacCleanupPort( wxMacPortStateHelper
* ph
) const ;
283 mutable void* m_macATSUIStyle
;
284 mutable wxMacPortStateHelper
* m_macCurrentPortStateHelper
;
285 mutable bool m_macFormerAliasState
;
286 mutable short m_macFormerAliasSize
;
287 mutable bool m_macAliasWasEnabled
;
288 mutable void* m_macForegroundPixMap
;
289 mutable void* m_macBackgroundPixMap
;