]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/mac/carbon/dc.h
added test for Blit()ting OnEraseBackground() results in OnPaint()
[wxWidgets.git] / include / wx / mac / carbon / dc.h
... / ...
CommitLineData
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#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16#pragma interface "dc.h"
17#endif
18
19#include "wx/pen.h"
20#include "wx/brush.h"
21#include "wx/icon.h"
22#include "wx/font.h"
23#include "wx/gdicmn.h"
24
25//-----------------------------------------------------------------------------
26// constants
27//-----------------------------------------------------------------------------
28
29#ifndef MM_TEXT
30#define MM_TEXT 0
31#define MM_ISOTROPIC 1
32#define MM_ANISOTROPIC 2
33#define MM_LOMETRIC 3
34#define MM_HIMETRIC 4
35#define MM_TWIPS 5
36#define MM_POINTS 6
37#define MM_METRIC 7
38#endif
39
40//-----------------------------------------------------------------------------
41// global variables
42//-----------------------------------------------------------------------------
43
44extern int wxPageNumber;
45
46class wxMacPortStateHelper ;
47
48class WXDLLEXPORT wxGraphicPath
49{
50public :
51 virtual ~wxGraphicPath() {}
52
53 virtual void MoveToPoint( wxCoord x1 , wxCoord y1 ) = 0 ;
54
55 virtual void AddLineToPoint( wxCoord x1 , wxCoord y1 ) = 0 ;
56
57 virtual void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) = 0 ;
58
59 virtual void AddCircle( wxCoord x, wxCoord y , wxCoord r ) = 0 ;
60
61 virtual void CloseSubpath() = 0 ;
62} ;
63
64class WXDLLEXPORT wxGraphicContext
65{
66public:
67 virtual ~wxGraphicContext() {}
68
69 virtual void Clip( const wxRegion &region ) = 0 ;
70
71 virtual void StrokePath( const wxGraphicPath *path ) = 0 ;
72
73 virtual void DrawPath( const wxGraphicPath *path , int fillStyle = wxWINDING_RULE ) = 0 ;
74
75 virtual void FillPath( const wxGraphicPath *path , const wxColor &fillColor , int fillStyle = wxWINDING_RULE ) = 0 ;
76
77 virtual void SetPen( const wxPen &pen ) = 0 ;
78
79 virtual void SetBrush( const wxBrush &brush ) = 0 ;
80
81 virtual wxGraphicPath* CreatePath() = 0 ;
82} ;
83
84//-----------------------------------------------------------------------------
85// wxDC
86//-----------------------------------------------------------------------------
87
88class WXDLLEXPORT wxDC: public wxDCBase
89{
90 DECLARE_DYNAMIC_CLASS(wxDC)
91 DECLARE_NO_COPY_CLASS(wxDC)
92
93 public:
94
95 wxDC();
96 ~wxDC();
97
98
99 // implement base class pure virtuals
100 // ----------------------------------
101
102 virtual void Clear();
103
104 virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; }
105 virtual void EndDoc(void) {};
106
107 virtual void StartPage(void) {};
108 virtual void EndPage(void) {};
109
110 virtual void SetFont(const wxFont& font);
111 virtual void SetPen(const wxPen& pen);
112 virtual void SetBrush(const wxBrush& brush);
113 virtual void SetBackground(const wxBrush& brush);
114 virtual void SetBackgroundMode(int mode);
115 virtual void SetPalette(const wxPalette& palette);
116
117 virtual void DestroyClippingRegion();
118
119 virtual wxCoord GetCharHeight() const;
120 virtual wxCoord GetCharWidth() const;
121 virtual void DoGetTextExtent(const wxString& string,
122 wxCoord *x, wxCoord *y,
123 wxCoord *descent = NULL,
124 wxCoord *externalLeading = NULL,
125 wxFont *theFont = NULL) const;
126 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
127
128 virtual bool CanDrawBitmap() const;
129 virtual bool CanGetTextExtent() const;
130 virtual int GetDepth() const;
131 virtual wxSize GetPPI() const;
132
133 virtual void SetMapMode(int mode);
134 virtual void SetUserScale(double x, double y);
135
136 virtual void SetLogicalScale(double x, double y);
137 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
138 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
139 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
140 virtual void SetLogicalFunction(int function);
141
142 virtual void SetTextForeground(const wxColour& colour) ;
143 virtual void SetTextBackground(const wxColour& colour) ;
144
145 virtual void ComputeScaleAndOrigin();
146
147 public:
148
149 wxCoord XDEV2LOG(wxCoord x) const
150 {
151 long new_x = x - m_deviceOriginX ;
152 if (new_x > 0)
153 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
154 else
155 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
156 }
157 wxCoord XDEV2LOGREL(wxCoord x) const
158 {
159 if (x > 0)
160 return (wxCoord)((double)(x) / m_scaleX + 0.5);
161 else
162 return (wxCoord)((double)(x) / m_scaleX - 0.5);
163 }
164 wxCoord YDEV2LOG(wxCoord y) const
165 {
166 long new_y = y - m_deviceOriginY ;
167 if (new_y > 0)
168 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
169 else
170 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
171 }
172 wxCoord YDEV2LOGREL(wxCoord y) const
173 {
174 if (y > 0)
175 return (wxCoord)((double)(y) / m_scaleY + 0.5);
176 else
177 return (wxCoord)((double)(y) / m_scaleY - 0.5);
178 }
179 wxCoord XLOG2DEV(wxCoord x) const
180 {
181 long new_x = x - m_logicalOriginX;
182 if (new_x > 0)
183 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX ;
184 else
185 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX ;
186 }
187 wxCoord XLOG2DEVREL(wxCoord x) const
188 {
189 if (x > 0)
190 return (wxCoord)((double)(x) * m_scaleX + 0.5);
191 else
192 return (wxCoord)((double)(x) * m_scaleX - 0.5);
193 }
194 wxCoord YLOG2DEV(wxCoord y) const
195 {
196 long new_y = y - m_logicalOriginY ;
197 if (new_y > 0)
198 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY ;
199 else
200 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY ;
201 }
202 wxCoord YLOG2DEVREL(wxCoord y) const
203 {
204 if (y > 0)
205 return (wxCoord)((double)(y) * m_scaleY + 0.5);
206 else
207 return (wxCoord)((double)(y) * m_scaleY - 0.5);
208 }
209 wxCoord XLOG2DEVMAC(wxCoord x) const
210 {
211 long new_x = x - m_logicalOriginX;
212 if (new_x > 0)
213 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ;
214 else
215 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ;
216 }
217 wxCoord YLOG2DEVMAC(wxCoord y) const
218 {
219 long new_y = y - m_logicalOriginY ;
220 if (new_y > 0)
221 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ;
222 else
223 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ;
224 }
225#if !wxMAC_USE_CORE_GRAPHICS
226 WXHRGN MacGetCurrentClipRgn() { return m_macCurrentClipRgn ; }
227 static void MacSetupBackgroundForCurrentPort(const wxBrush& background ) ;
228#endif
229//
230
231protected:
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 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 // this is gnarly - we can't even call this function DoSetClippingRegion()
268 // because of virtual function hiding
269 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
270 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
271 wxCoord width, wxCoord height);
272
273 virtual void DoGetSizeMM(int* width, int* height) const;
274
275 virtual void DoDrawLines(int n, wxPoint points[],
276 wxCoord xoffset, wxCoord yoffset);
277 virtual void DoDrawPolygon(int n, wxPoint points[],
278 wxCoord xoffset, wxCoord yoffset,
279 int fillStyle = wxODDEVEN_RULE);
280
281 protected:
282 //begin wxmac
283 // Variables used for scaling
284 double m_mm_to_pix_x,m_mm_to_pix_y;
285 // not yet used
286 bool m_needComputeScaleX,m_needComputeScaleY;
287 // If un-scrolled is non-zero or d.o. changes with scrolling.
288 // Set using SetInternalDeviceOrigin().
289 long m_internalDeviceOriginX,m_internalDeviceOriginY;
290 // To be set by external classes such as wxScrolledWindow
291 // using SetDeviceOrigin()
292 long m_externalDeviceOriginX,m_externalDeviceOriginY;
293
294 // Begin implementation for Mac
295 public:
296
297#if !wxMAC_USE_CORE_GRAPHICS
298 WXHBITMAP m_macMask ;
299#endif
300
301 // in order to preserve the const inheritance of the virtual functions, we have to
302 // use mutable variables starting from CWPro 5
303
304 void MacInstallFont() const ;
305#if !wxMAC_USE_CORE_GRAPHICS
306 void MacInstallPen() const ;
307 void MacInstallBrush() const ;
308#endif
309
310 wxPoint m_macLocalOrigin ;
311 mutable void* m_macATSUIStyle ;
312
313#if wxMAC_USE_CORE_GRAPHICS
314 // CoreGraphics
315 wxGraphicContext * m_graphicContext ;
316#else
317 WXHDC m_macPort ;
318 mutable bool m_macFontInstalled ;
319 mutable bool m_macPenInstalled ;
320 mutable bool m_macBrushInstalled ;
321
322 WXHRGN m_macBoundaryClipRgn ;
323 WXHRGN m_macCurrentClipRgn ;
324 void MacSetupPort( wxMacPortStateHelper* ph ) const ;
325 void MacCleanupPort( wxMacPortStateHelper* ph ) const ;
326 mutable wxMacPortStateHelper* m_macCurrentPortStateHelper ;
327 mutable bool m_macFormerAliasState ;
328 mutable short m_macFormerAliasSize ;
329 mutable bool m_macAliasWasEnabled ;
330 mutable void* m_macForegroundPixMap ;
331 mutable void* m_macBackgroundPixMap ;
332#endif
333
334#if wxMAC_USE_CORE_GRAPHICS
335#endif
336};
337
338#endif
339 // _WX_DC_H_