]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/dc.h
tentative fix for BestSize problems (non-native toolbar)
[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
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 ;
20b69855
SC
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
e828c96a
SC
57 virtual void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 ) = 0 ;
58
20b69855
SC
59 virtual void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) = 0 ;
60
61 virtual void AddCircle( wxCoord x, wxCoord y , wxCoord r ) = 0 ;
62
63 virtual void CloseSubpath() = 0 ;
64} ;
65
66class WXDLLEXPORT wxGraphicContext
67{
68public:
69 virtual ~wxGraphicContext() {}
70
71 virtual void Clip( const wxRegion &region ) = 0 ;
72
73 virtual void StrokePath( const wxGraphicPath *path ) = 0 ;
74
75 virtual void DrawPath( const wxGraphicPath *path , int fillStyle = wxWINDING_RULE ) = 0 ;
76
77 virtual void FillPath( const wxGraphicPath *path , const wxColor &fillColor , int fillStyle = wxWINDING_RULE ) = 0 ;
78
79 virtual void SetPen( const wxPen &pen ) = 0 ;
80
81 virtual void SetBrush( const wxBrush &brush ) = 0 ;
82
83 virtual wxGraphicPath* CreatePath() = 0 ;
84} ;
85
8cf73271
SC
86//-----------------------------------------------------------------------------
87// wxDC
88//-----------------------------------------------------------------------------
89
90class WXDLLEXPORT wxDC: public wxDCBase
91{
92 DECLARE_DYNAMIC_CLASS(wxDC)
93 DECLARE_NO_COPY_CLASS(wxDC)
94
95 public:
96
97 wxDC();
98 ~wxDC();
c5789d15 99
8cf73271
SC
100
101 // implement base class pure virtuals
102 // ----------------------------------
103
104 virtual void Clear();
105
b1263dcf 106 virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; }
8cf73271 107 virtual void EndDoc(void) {};
c5789d15 108
8cf73271
SC
109 virtual void StartPage(void) {};
110 virtual void EndPage(void) {};
111
112 virtual void SetFont(const wxFont& font);
113 virtual void SetPen(const wxPen& pen);
114 virtual void SetBrush(const wxBrush& brush);
115 virtual void SetBackground(const wxBrush& brush);
116 virtual void SetBackgroundMode(int mode);
117 virtual void SetPalette(const wxPalette& palette);
118
119 virtual void DestroyClippingRegion();
120
121 virtual wxCoord GetCharHeight() const;
122 virtual wxCoord GetCharWidth() const;
123 virtual void DoGetTextExtent(const wxString& string,
124 wxCoord *x, wxCoord *y,
125 wxCoord *descent = NULL,
126 wxCoord *externalLeading = NULL,
127 wxFont *theFont = NULL) const;
128 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
129
130 virtual bool CanDrawBitmap() const;
131 virtual bool CanGetTextExtent() const;
132 virtual int GetDepth() const;
133 virtual wxSize GetPPI() const;
134
135 virtual void SetMapMode(int mode);
136 virtual void SetUserScale(double x, double y);
137
138 virtual void SetLogicalScale(double x, double y);
139 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
140 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
141 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
142 virtual void SetLogicalFunction(int function);
143
144 virtual void SetTextForeground(const wxColour& colour) ;
145 virtual void SetTextBackground(const wxColour& colour) ;
146
b1263dcf 147 virtual void ComputeScaleAndOrigin();
c5789d15 148
b1263dcf 149 public:
c5789d15 150
8cf73271
SC
151 wxCoord XDEV2LOG(wxCoord x) const
152 {
153 long new_x = x - m_deviceOriginX ;
154 if (new_x > 0)
155 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
156 else
157 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
158 }
159 wxCoord XDEV2LOGREL(wxCoord x) const
c5789d15 160 {
8cf73271
SC
161 if (x > 0)
162 return (wxCoord)((double)(x) / m_scaleX + 0.5);
163 else
164 return (wxCoord)((double)(x) / m_scaleX - 0.5);
165 }
166 wxCoord YDEV2LOG(wxCoord y) const
167 {
168 long new_y = y - m_deviceOriginY ;
169 if (new_y > 0)
170 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
171 else
172 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
173 }
174 wxCoord YDEV2LOGREL(wxCoord y) const
c5789d15 175 {
8cf73271
SC
176 if (y > 0)
177 return (wxCoord)((double)(y) / m_scaleY + 0.5);
178 else
179 return (wxCoord)((double)(y) / m_scaleY - 0.5);
180 }
181 wxCoord XLOG2DEV(wxCoord x) const
c5789d15 182 {
8cf73271
SC
183 long new_x = x - m_logicalOriginX;
184 if (new_x > 0)
185 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX ;
186 else
187 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX ;
188 }
189 wxCoord XLOG2DEVREL(wxCoord x) const
c5789d15 190 {
8cf73271
SC
191 if (x > 0)
192 return (wxCoord)((double)(x) * m_scaleX + 0.5);
193 else
194 return (wxCoord)((double)(x) * m_scaleX - 0.5);
195 }
196 wxCoord YLOG2DEV(wxCoord y) const
197 {
198 long new_y = y - m_logicalOriginY ;
199 if (new_y > 0)
200 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY ;
201 else
202 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY ;
203 }
204 wxCoord YLOG2DEVREL(wxCoord y) const
c5789d15 205 {
8cf73271
SC
206 if (y > 0)
207 return (wxCoord)((double)(y) * m_scaleY + 0.5);
208 else
209 return (wxCoord)((double)(y) * m_scaleY - 0.5);
210 }
211 wxCoord XLOG2DEVMAC(wxCoord x) const
c5789d15 212 {
8cf73271
SC
213 long new_x = x - m_logicalOriginX;
214 if (new_x > 0)
215 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ;
216 else
217 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ;
218 }
219 wxCoord YLOG2DEVMAC(wxCoord y) const
220 {
221 long new_y = y - m_logicalOriginY ;
222 if (new_y > 0)
223 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ;
224 else
225 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ;
226 }
71cc158e
SC
227#if wxMAC_USE_CORE_GRAPHICS
228 wxGraphicContext* GetGraphicContext() { return m_graphicContext ; }
229#else
8cf73271
SC
230 WXHRGN MacGetCurrentClipRgn() { return m_macCurrentClipRgn ; }
231 static void MacSetupBackgroundForCurrentPort(const wxBrush& background ) ;
20b69855 232#endif
8cf73271
SC
233//
234
235protected:
236 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
237 int style = wxFLOOD_SURFACE);
238
239 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
240
241 virtual void DoDrawPoint(wxCoord x, wxCoord y);
e828c96a
SC
242#if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES
243 virtual void DoDrawSpline(wxList *points);
244#endif
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
276 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
277 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
278 wxCoord width, wxCoord height);
8cf73271
SC
279
280 virtual void DoGetSizeMM(int* width, int* height) const;
281
282 virtual void DoDrawLines(int n, wxPoint points[],
283 wxCoord xoffset, wxCoord yoffset);
284 virtual void DoDrawPolygon(int n, wxPoint points[],
285 wxCoord xoffset, wxCoord yoffset,
286 int fillStyle = wxODDEVEN_RULE);
287
288 protected:
289 //begin wxmac
290 // Variables used for scaling
c5789d15 291 double m_mm_to_pix_x,m_mm_to_pix_y;
8cf73271 292 // not yet used
c5789d15 293 bool m_needComputeScaleX,m_needComputeScaleY;
8cf73271
SC
294 // If un-scrolled is non-zero or d.o. changes with scrolling.
295 // Set using SetInternalDeviceOrigin().
296 long m_internalDeviceOriginX,m_internalDeviceOriginY;
297 // To be set by external classes such as wxScrolledWindow
298 // using SetDeviceOrigin()
299 long m_externalDeviceOriginX,m_externalDeviceOriginY;
c5789d15 300
8cf73271
SC
301 // Begin implementation for Mac
302 public:
c5789d15 303
20b69855 304#if !wxMAC_USE_CORE_GRAPHICS
8cf73271 305 WXHBITMAP m_macMask ;
20b69855 306#endif
8cf73271 307
c5789d15 308 // in order to preserve the const inheritance of the virtual functions, we have to
8cf73271
SC
309 // use mutable variables starting from CWPro 5
310
311 void MacInstallFont() const ;
20b69855 312#if !wxMAC_USE_CORE_GRAPHICS
8cf73271
SC
313 void MacInstallPen() const ;
314 void MacInstallBrush() const ;
20b69855
SC
315#endif
316
ddb08e02 317 wxPoint m_macLocalOrigin ;
20b69855 318 mutable void* m_macATSUIStyle ;
8cf73271 319
ddb08e02 320 WXHDC m_macPort ;
20b69855
SC
321#if wxMAC_USE_CORE_GRAPHICS
322 // CoreGraphics
323 wxGraphicContext * m_graphicContext ;
880f5369 324 wxPoint m_macLocalOriginInPort ;
20b69855 325#else
880f5369
SC
326 mutable bool m_macFontInstalled ;
327 mutable bool m_macPenInstalled ;
328 mutable bool m_macBrushInstalled ;
329
330 WXHRGN m_macBoundaryClipRgn ;
331 WXHRGN m_macCurrentClipRgn ;
332 void MacSetupPort( wxMacPortStateHelper* ph ) const ;
333 void MacCleanupPort( wxMacPortStateHelper* ph ) const ;
8cf73271
SC
334 mutable wxMacPortStateHelper* m_macCurrentPortStateHelper ;
335 mutable bool m_macFormerAliasState ;
336 mutable short m_macFormerAliasSize ;
337 mutable bool m_macAliasWasEnabled ;
338 mutable void* m_macForegroundPixMap ;
339 mutable void* m_macBackgroundPixMap ;
20b69855 340#endif
613a24f7 341
20b69855
SC
342#if wxMAC_USE_CORE_GRAPHICS
343#endif
8cf73271
SC
344};
345
346#endif
347 // _WX_DC_H_