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 return wxRound((double)(x
- m_deviceOriginX
) / m_scaleX
) * m_signX
+ m_logicalOriginX
;
110 wxCoord
XDEV2LOGREL(wxCoord x
) const
112 return wxRound((double)(x
) / m_scaleX
);
114 wxCoord
YDEV2LOG(wxCoord y
) const
116 return wxRound((double)(y
- m_deviceOriginY
) / m_scaleY
) * m_signY
+ m_logicalOriginY
;
118 wxCoord
YDEV2LOGREL(wxCoord y
) const
120 return wxRound((double)(y
) / m_scaleY
);
122 wxCoord
XLOG2DEV(wxCoord x
) const
124 return wxRound((double)(x
- m_logicalOriginX
) * m_scaleX
) * m_signX
+ m_deviceOriginX
;
126 wxCoord
XLOG2DEVREL(wxCoord x
) const
128 return wxRound((double)(x
) * m_scaleX
);
130 wxCoord
YLOG2DEV(wxCoord y
) const
132 return wxRound((double)(y
- m_logicalOriginY
) * m_scaleY
) * m_signY
+ m_deviceOriginY
;
134 wxCoord
YLOG2DEVREL(wxCoord y
) const
136 return wxRound((double)(y
) * m_scaleY
);
139 wxCoord
XLOG2DEVMAC(wxCoord x
) const
141 return wxRound((double)(x
- m_logicalOriginX
) * m_scaleX
) * m_signX
+ m_deviceOriginX
+ m_macLocalOrigin
.x
;
144 wxCoord
YLOG2DEVMAC(wxCoord y
) const
146 return wxRound((double)(y
- m_logicalOriginY
) * m_scaleY
) * m_signY
+ m_deviceOriginY
+ m_macLocalOrigin
.y
;
149 WXHRGN
MacGetCurrentClipRgn() { return m_macCurrentClipRgn
; }
150 static void MacSetupBackgroundForCurrentPort(const wxBrush
& background
) ;
154 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
155 int style
= wxFLOOD_SURFACE
);
157 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
159 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
160 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
162 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
163 wxCoord x2
, wxCoord y2
,
164 wxCoord xc
, wxCoord yc
);
166 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
167 double sa
, double ea
);
169 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
170 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
171 wxCoord width
, wxCoord height
,
173 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
175 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
177 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
178 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
179 bool useMask
= false);
181 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
182 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
185 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
186 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
187 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
189 // this is gnarly - we can't even call this function DoSetClippingRegion()
190 // because of virtual function hiding
191 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
192 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
193 wxCoord width
, wxCoord height
);
195 virtual void DoGetSizeMM(int* width
, int* height
) const;
197 virtual void DoDrawLines(int n
, wxPoint points
[],
198 wxCoord xoffset
, wxCoord yoffset
);
199 virtual void DoDrawPolygon(int n
, wxPoint points
[],
200 wxCoord xoffset
, wxCoord yoffset
,
201 int fillStyle
= wxODDEVEN_RULE
);
205 // Variables used for scaling
206 double m_mm_to_pix_x
,m_mm_to_pix_y
;
208 bool m_needComputeScaleX
,m_needComputeScaleY
;
209 // If un-scrolled is non-zero or d.o. changes with scrolling.
210 // Set using SetInternalDeviceOrigin().
211 long m_internalDeviceOriginX
,m_internalDeviceOriginY
;
212 // To be set by external classes such as wxScrolledWindow
213 // using SetDeviceOrigin()
214 long m_externalDeviceOriginX
,m_externalDeviceOriginY
;
216 // Begin implementation for Mac
220 WXHBITMAP m_macMask
;
222 // in order to preserve the const inheritance of the virtual functions, we have to
223 // use mutable variables starting from CWPro 5
225 void MacInstallFont() const ;
226 void MacInstallPen() const ;
227 void MacInstallBrush() const ;
229 mutable bool m_macFontInstalled
;
230 mutable bool m_macPenInstalled
;
231 mutable bool m_macBrushInstalled
;
233 WXHRGN m_macBoundaryClipRgn
;
234 WXHRGN m_macCurrentClipRgn
;
235 wxPoint m_macLocalOrigin
;
236 void MacSetupPort( wxMacPortStateHelper
* ph
) const ;
237 void MacCleanupPort( wxMacPortStateHelper
* ph
) const ;
238 mutable void* m_macATSUIStyle
;
239 mutable wxMacPortStateHelper
* m_macCurrentPortStateHelper
;
240 mutable bool m_macFormerAliasState
;
241 mutable short m_macFormerAliasSize
;
242 mutable bool m_macAliasWasEnabled
;
243 mutable void* m_macForegroundPixMap
;
244 mutable void* m_macBackgroundPixMap
;