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