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