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