]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/dc.h
0996cabe44de71b5402e04dbf7b7fcd7275c2926
[wxWidgets.git] / include / wx / mac / carbon / dc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.h
3 // Purpose: wxDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DC_H_
13 #define _WX_DC_H_
14
15 #include "wx/pen.h"
16 #include "wx/brush.h"
17 #include "wx/icon.h"
18 #include "wx/font.h"
19 #include "wx/gdicmn.h"
20
21 //-----------------------------------------------------------------------------
22 // constants
23 //-----------------------------------------------------------------------------
24
25 #ifndef MM_TEXT
26 #define MM_TEXT 0
27 #define MM_ISOTROPIC 1
28 #define MM_ANISOTROPIC 2
29 #define MM_LOMETRIC 3
30 #define MM_HIMETRIC 4
31 #define MM_TWIPS 5
32 #define MM_POINTS 6
33 #define MM_METRIC 7
34 #endif
35
36
37 class wxMacPortStateHelper;
38
39 #if !wxUSE_GRAPHICS_CONTEXT
40
41 class WXDLLEXPORT wxGraphicPath
42 {
43 public :
44 virtual ~wxGraphicPath() {}
45
46 virtual void MoveToPoint( wxCoord x1, wxCoord y1 ) = 0;
47
48 virtual void AddLineToPoint( wxCoord x1, wxCoord y1 ) = 0;
49
50 virtual void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 ) = 0;
51
52 virtual void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) = 0;
53
54 virtual void AddCircle( wxCoord x, wxCoord y, wxCoord r ) = 0;
55
56 // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
57 virtual void AddArcToPoint( wxCoord x1, wxCoord y1 , wxCoord x2, wxCoord y2, wxCoord r ) = 0 ;
58
59 virtual void AddArc( wxCoord x, wxCoord y, wxCoord r, double startAngle, double endAngle, bool clockwise ) = 0 ;
60
61 virtual void CloseSubpath() = 0;
62 };
63
64 class WXDLLEXPORT wxGraphicContext
65 {
66 public:
67 virtual ~wxGraphicContext() {}
68
69 virtual wxGraphicPath * CreatePath() = 0;
70
71 virtual void PushState() = 0 ;
72
73 virtual void PopState() = 0 ;
74
75 virtual void Clip( const wxRegion &region ) = 0;
76
77 virtual void SetPen( const wxPen &pen ) = 0;
78
79 virtual void SetBrush( const wxBrush &brush ) = 0;
80
81 virtual void SetFont( const wxFont &font ) = 0 ;
82
83 virtual void SetTextColor( const wxColour &col ) = 0 ;
84
85 virtual void StrokePath( const wxGraphicPath *path ) = 0;
86
87 virtual void DrawPath( const wxGraphicPath *path, int fillStyle = wxWINDING_RULE ) = 0;
88
89 virtual void FillPath( const wxGraphicPath *path, const wxColor &fillColor, int fillStyle = wxWINDING_RULE ) = 0;
90
91 virtual void DrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, wxCoord w, wxCoord h ) = 0 ;
92
93 virtual void DrawIcon( const wxIcon &icon, wxCoord x, wxCoord y, wxCoord w, wxCoord h ) = 0 ;
94
95 virtual void DrawText( const wxString &str, wxCoord x, wxCoord y, double angle ) = 0 ;
96
97 virtual void GetTextExtent( const wxString &text, wxCoord *width, wxCoord *height,
98 wxCoord *descent, wxCoord *externalLeading ) const = 0 ;
99
100 virtual void GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const = 0 ;
101
102 virtual void Translate( wxCoord dx , wxCoord dy ) = 0 ;
103
104 virtual void Scale( wxCoord xScale , wxCoord yScale ) = 0 ;
105 };
106
107 class WXDLLEXPORT wxDC: public wxDCBase
108 {
109 DECLARE_DYNAMIC_CLASS(wxDC)
110 DECLARE_NO_COPY_CLASS(wxDC)
111
112 public:
113 wxDC();
114 virtual ~wxDC();
115
116 // implement base class pure virtuals
117 // ----------------------------------
118
119 virtual void Clear();
120
121 virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; }
122 virtual void EndDoc(void) {}
123
124 virtual void StartPage(void) {}
125 virtual void EndPage(void) {}
126
127 virtual void SetFont(const wxFont& font);
128 virtual void SetPen(const wxPen& pen);
129 virtual void SetBrush(const wxBrush& brush);
130 virtual void SetBackground(const wxBrush& brush);
131 virtual void SetBackgroundMode(int mode);
132 virtual void SetPalette(const wxPalette& palette);
133
134 virtual void DestroyClippingRegion();
135
136 virtual wxCoord GetCharHeight() const;
137 virtual wxCoord GetCharWidth() const;
138
139 virtual bool CanDrawBitmap() const;
140 virtual bool CanGetTextExtent() const;
141 virtual int GetDepth() const;
142 virtual wxSize GetPPI() const;
143
144 virtual void SetMapMode(int mode);
145 virtual void SetUserScale(double x, double y);
146
147 virtual void SetLogicalScale(double x, double y);
148 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
149 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
150 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
151 virtual void SetLogicalFunction(int function);
152
153 virtual void SetTextForeground(const wxColour& colour);
154 virtual void SetTextBackground(const wxColour& colour);
155
156 virtual void ComputeScaleAndOrigin();
157
158 virtual wxCoord DeviceToLogicalX(wxCoord x) const;
159 virtual wxCoord DeviceToLogicalY(wxCoord y) const;
160 virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
161 virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
162 virtual wxCoord LogicalToDeviceX(wxCoord x) const;
163 virtual wxCoord LogicalToDeviceY(wxCoord y) const;
164 virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
165 virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ;
166
167 public:
168 wxCoord XDEV2LOG(wxCoord x) const
169 {
170 return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX;
171 }
172 wxCoord XDEV2LOGREL(wxCoord x) const
173 {
174 return wxRound((double)(x) / m_scaleX);
175 }
176 wxCoord YDEV2LOG(wxCoord y) const
177 {
178 return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY;
179 }
180 wxCoord YDEV2LOGREL(wxCoord y) const
181 {
182 return wxRound((double)(y) / m_scaleY);
183 }
184 wxCoord XLOG2DEV(wxCoord x) const
185 {
186 return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX;
187 }
188 wxCoord XLOG2DEVREL(wxCoord x) const
189 {
190 return wxRound((double)(x) * m_scaleX);
191 }
192 wxCoord YLOG2DEV(wxCoord y) const
193 {
194 return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY;
195 }
196 wxCoord YLOG2DEVREL(wxCoord y) const
197 {
198 return wxRound((double)(y) * m_scaleY);
199 }
200
201 wxCoord XLOG2DEVMAC(wxCoord x) const
202 {
203 return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX + m_macLocalOrigin.x;
204 }
205
206 wxCoord YLOG2DEVMAC(wxCoord y) const
207 {
208 return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY + m_macLocalOrigin.y;
209 }
210
211 #if wxMAC_USE_CORE_GRAPHICS
212 wxGraphicsContext* GetGraphicsContext() { return m_graphicContext; }
213 #else
214 WXHRGN MacGetCurrentClipRgn() { return m_macCurrentClipRgn; }
215 static void MacSetupBackgroundForCurrentPort(const wxBrush& background );
216 #endif
217
218 protected:
219 virtual void DoGetTextExtent(const wxString& string,
220 wxCoord *x, wxCoord *y,
221 wxCoord *descent = NULL,
222 wxCoord *externalLeading = NULL,
223 const wxFont *theFont = NULL) const;
224
225 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
226
227 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
228 int style = wxFLOOD_SURFACE);
229
230 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
231
232 virtual void DoDrawPoint(wxCoord x, wxCoord y);
233
234 #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
235 virtual void DoDrawSpline(wxList *points);
236 #endif
237
238 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
239
240 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
241 wxCoord x2, wxCoord y2,
242 wxCoord xc, wxCoord yc);
243
244 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
245 double sa, double ea);
246
247 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
248 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
249 wxCoord width, wxCoord height,
250 double radius);
251 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
252
253 virtual void DoCrossHair(wxCoord x, wxCoord y);
254
255 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
256 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
257 bool useMask = false);
258
259 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
260 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
261 double angle);
262
263 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
264 wxDC *source, wxCoord xsrc, wxCoord ysrc,
265 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
266
267 virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
268 wxCoord dstWidth, wxCoord dstHeight,
269 wxDC *source,
270 wxCoord xsrc, wxCoord ysrc,
271 wxCoord srcWidth, wxCoord srcHeight,
272 int rop = wxCOPY, bool useMask = false,
273 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
274
275 // this is gnarly - we can't even call this function DoSetClippingRegion()
276 // because of virtual function hiding
277
278 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
279 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
280 wxCoord width, wxCoord height);
281
282 virtual void DoGetSizeMM(int *width, int *height) const;
283
284 virtual void DoDrawLines(int n, wxPoint points[],
285 wxCoord xoffset, wxCoord yoffset);
286 virtual void DoDrawPolygon(int n, wxPoint points[],
287 wxCoord xoffset, wxCoord yoffset,
288 int fillStyle = wxODDEVEN_RULE);
289
290 protected:
291 // scaling variables
292 double m_mm_to_pix_x, m_mm_to_pix_y;
293
294 // To be set using SetDeviceOrigin()
295 // by external classes such as wxScrolledWindow
296 long m_externalDeviceOriginX, m_externalDeviceOriginY;
297
298 #if !wxMAC_USE_CORE_GRAPHICS
299 // If un-scrolled is non-zero or d.o. changes with scrolling.
300 // Set using SetInternalDeviceOrigin().
301 long m_internalDeviceOriginX, m_internalDeviceOriginY;
302
303 WXHBITMAP m_macMask;
304 #endif
305
306 // not yet used
307 bool m_needComputeScaleX, m_needComputeScaleY;
308
309 public:
310 // implementation
311 void MacInstallFont() const;
312
313 // in order to preserve the const inheritance of the virtual functions,
314 // we have to use mutable variables starting from CWPro 5
315 wxPoint m_macLocalOrigin;
316 mutable void *m_macATSUIStyle;
317
318 WXHDC m_macPort;
319
320 #if wxMAC_USE_CORE_GRAPHICS
321 wxGraphicsContext *m_graphicContext;
322 #else
323 void MacInstallPen() const;
324 void MacInstallBrush() const;
325
326 void MacSetupPort( wxMacPortStateHelper *ph ) const;
327 void MacCleanupPort( wxMacPortStateHelper *ph ) const;
328
329 mutable wxMacPortStateHelper *m_macCurrentPortStateHelper;
330
331 mutable bool m_macFontInstalled;
332 mutable bool m_macPenInstalled;
333 mutable bool m_macBrushInstalled;
334
335 WXHRGN m_macBoundaryClipRgn;
336 WXHRGN m_macCurrentClipRgn;
337 mutable bool m_macFormerAliasState;
338 mutable short m_macFormerAliasSize;
339 mutable bool m_macAliasWasEnabled;
340 mutable void *m_macForegroundPixMap;
341 mutable void *m_macBackgroundPixMap;
342 #endif
343 };
344
345 #endif
346
347 #endif // _WX_DC_H_