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