]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/dc.h
fixed wxUSE_MAC not being defined under Unix => -D_REENTRANT was missing resulting...
[wxWidgets.git] / include / wx / mac / dc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.h
3 // Purpose: wxDC class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DC_H_
13 #define _WX_DC_H_
14
15 #ifdef __GNUG__
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 #include "wx/mac/aga.h"
25
26 //-----------------------------------------------------------------------------
27 // constants
28 //-----------------------------------------------------------------------------
29
30 #ifndef MM_TEXT
31 #define MM_TEXT 0
32 #define MM_ISOTROPIC 1
33 #define MM_ANISOTROPIC 2
34 #define MM_LOMETRIC 3
35 #define MM_HIMETRIC 4
36 #define MM_TWIPS 5
37 #define MM_POINTS 6
38 #define MM_METRIC 7
39 #endif
40
41 //-----------------------------------------------------------------------------
42 // global variables
43 //-----------------------------------------------------------------------------
44
45 extern int wxPageNumber;
46
47 //-----------------------------------------------------------------------------
48 // wxDC
49 //-----------------------------------------------------------------------------
50
51 class WXDLLEXPORT wxDC: public wxDCBase
52 {
53 DECLARE_DYNAMIC_CLASS(wxDC)
54
55 public:
56
57 wxDC();
58 ~wxDC();
59
60
61 // implement base class pure virtuals
62 // ----------------------------------
63
64 virtual void Clear();
65
66 virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; };
67 virtual void EndDoc(void) {};
68
69 virtual void StartPage(void) {};
70 virtual void EndPage(void) {};
71
72 virtual void SetFont(const wxFont& font);
73 virtual void SetPen(const wxPen& pen);
74 virtual void SetBrush(const wxBrush& brush);
75 virtual void SetBackground(const wxBrush& brush);
76 virtual void SetBackgroundMode(int mode);
77 virtual void SetPalette(const wxPalette& palette);
78
79 virtual void DestroyClippingRegion();
80
81 virtual wxCoord GetCharHeight() const;
82 virtual wxCoord GetCharWidth() const;
83 virtual void DoGetTextExtent(const wxString& string,
84 wxCoord *x, wxCoord *y,
85 wxCoord *descent = NULL,
86 wxCoord *externalLeading = NULL,
87 wxFont *theFont = NULL) const;
88
89 virtual bool CanDrawBitmap() const;
90 virtual bool CanGetTextExtent() const;
91 virtual int GetDepth() const;
92 virtual wxSize GetPPI() const;
93
94 virtual void SetMapMode(int mode);
95 virtual void SetUserScale(double x, double y);
96
97 virtual void SetLogicalScale(double x, double y);
98 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
99 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
100 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
101 virtual void SetLogicalFunction(int function);
102
103 virtual void SetTextForeground(const wxColour& colour) ;
104 virtual void SetTextBackground(const wxColour& colour) ;
105
106 //
107 //
108
109 /*
110 void BeginDrawing(void) {};
111 void EndDrawing(void) {};
112
113 virtual bool Ok(void) const { return m_ok; };
114
115 virtual void FloodFill( long x1, long y1, const wxColour& col, int style=wxFLOOD_SURFACE );
116 inline void FloodFill(const wxPoint& pt, const wxColour& col, int style=wxFLOOD_SURFACE)
117 {
118 FloodFill(pt.x, pt.y, col, style);
119 }
120
121 virtual bool GetPixel( long x1, long y1, wxColour *col ) const ;
122 inline bool GetPixel(const wxPoint& pt, wxColour *col) const
123 {
124 return GetPixel(pt.x, pt.y, col);
125 }
126
127 virtual void DrawLine( long x1, long y1, long x2, long y2 );
128 inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
129 {
130 DrawLine(pt1.x, pt1.y, pt2.x, pt2.y);
131 }
132
133 virtual void CrossHair( long x, long y );
134 inline void CrossHair(const wxPoint& pt)
135 {
136 CrossHair(pt.x, pt.y);
137 }
138
139 virtual void DrawArc( long x1, long y1, long x2, long y2, long xc, long yc );
140 inline void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
141 {
142 DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y);
143 }
144
145 virtual void DrawEllipticArc( long x, long y, long width, long height, double sa, double ea );
146 virtual void DrawEllipticArc (const wxPoint& pt, const wxSize& sz, double sa, double ea)
147 {
148 DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea);
149 }
150
151 virtual void DrawPoint( long x, long y );
152 virtual void DrawPoint( wxPoint& point );
153
154 virtual void DrawLines( int n, wxPoint points[], long xoffset = 0, long yoffset = 0 );
155 virtual void DrawLines( wxList *points, long xoffset = 0, long yoffset = 0 );
156 virtual void DrawPolygon( int n, wxPoint points[], long xoffset = 0, long yoffset = 0,
157 int fillStyle=wxODDEVEN_RULE );
158 virtual void DrawPolygon( wxList *lines, long xoffset = 0, long yoffset = 0,
159 int fillStyle=wxODDEVEN_RULE );
160
161 virtual void DrawRectangle( long x, long y, long width, long height );
162 inline void DrawRectangle(const wxPoint& pt, const wxSize& sz)
163 {
164 DrawRectangle(pt.x, pt.y, sz.x, sz.y);
165 }
166 inline void DrawRectangle(const wxRect& rect)
167 {
168 DrawRectangle(rect.x, rect.y, rect.width, rect.height);
169 }
170 virtual void DrawRoundedRectangle( long x, long y, long width, long height, double radius = 20.0 );
171 inline void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius = 20.0)
172 {
173 DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius);
174 }
175 inline void DrawRoundedRectangle(const wxRect& rect, double radius = 20.0)
176 {
177 DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, radius);
178 }
179
180 virtual void DrawEllipse( long x, long y, long width, long height );
181 inline void DrawEllipse(const wxPoint& pt, const wxSize& sz)
182 {
183 DrawEllipse(pt.x, pt.y, sz.x, sz.y);
184 }
185 inline void DrawEllipse(const wxRect& rect)
186 {
187 DrawEllipse(rect.x, rect.y, rect.width, rect.height);
188 }
189
190 virtual void DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 );
191 virtual void DrawSpline( wxList *points );
192 virtual void DrawSpline( int n, wxPoint points[] );
193
194 virtual bool CanDrawBitmap(void) const ;
195
196 virtual void DrawIcon( const wxIcon &icon, long x, long y, bool useMask=FALSE );
197 inline void DrawIcon(const wxIcon& icon, const wxPoint& pt)
198 {
199 DrawIcon(icon, pt.x, pt.y);
200 }
201
202 void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE ) ;
203
204 virtual bool Blit( long xdest, long ydest, long width, long height,
205 wxDC *source, long xsrc, long ysrc, int logical_func = wxCOPY, bool useMask=FALSE );
206 inline bool Blit(const wxPoint& destPt, const wxSize& sz,
207 wxDC *source, const wxPoint& srcPt, int rop = wxCOPY, bool useMask = FALSE)
208 {
209 return Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, rop, useMask);
210 }
211
212 virtual void DrawText( const wxString &text, long x, long y, bool use16 = FALSE );
213 inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE)
214 {
215 DrawText(text, pt.x, pt.y, use16bit);
216 }
217
218 virtual bool CanGetTextExtent(void) const ;
219 virtual void GetTextExtent( const wxString &string, int *width, int *height,
220 int *descent = NULL, int *externalLeading = NULL,
221 wxFont *theFont = NULL, bool use16 = FALSE ) const ;
222 virtual wxCoord GetCharWidth(void) const;
223 virtual wxCoord GetCharHeight(void) const;
224
225 virtual void Clear(void);
226
227 virtual void SetFont( const wxFont &font );
228 virtual wxFont& GetFont(void) const { return (wxFont&) m_font; };
229
230 virtual void SetPen( const wxPen &pen );
231 virtual wxPen& GetPen(void) const { return (wxPen&) m_pen; };
232
233 virtual void SetBrush( const wxBrush &brush );
234 virtual wxBrush& GetBrush(void) const { return (wxBrush&) m_brush; };
235
236 virtual void SetBackground( const wxBrush &brush );
237 virtual wxBrush& GetBackground(void) const { return (wxBrush&) m_backgroundBrush; };
238
239 virtual void SetLogicalFunction( int function );
240 virtual int GetLogicalFunction(void) const { return m_logicalFunction; };
241
242 virtual void SetTextForeground( const wxColour &col );
243 virtual void SetTextBackground( const wxColour &col );
244 virtual wxColour& GetTextBackground(void) const { return (wxColour&)m_textBackgroundColour; };
245 virtual wxColour& GetTextForeground(void) const { return (wxColour&)m_textForegroundColour; };
246
247 virtual void SetBackgroundMode( int mode );
248 virtual int GetBackgroundMode(void) const { return m_backgroundMode; };
249
250 virtual void SetPalette( const wxPalette& palette );
251 void SetColourMap( const wxPalette& palette ) { SetPalette(palette); };
252
253 // the first two must be overridden and called
254 virtual void SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
255 virtual void SetClippingRegion( const wxRect& rect );
256 virtual void DestroyClippingRegion(void);
257 virtual void GetClippingBox( wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height ) const;
258 virtual void GetClippingBox( long *x, long *y, long *width, long *height ) const;
259 virtual void GetClippingBox(wxRect& rect) const;
260
261 virtual inline long MinX(void) const { return m_minX; }
262 virtual inline long MaxX(void) const { return m_maxX; }
263 virtual inline long MinY(void) const { return m_minY; }
264 virtual inline long MaxY(void) const { return m_maxY; }
265
266 virtual void GetSize( int* width, int* height ) const;
267 inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); }
268 virtual void GetSizeMM( long* width, long* height ) const;
269
270
271 virtual int GetMapMode(void) const { return m_mappingMode; };
272
273 virtual void GetUserScale( double *x, double *y );
274 virtual void GetLogicalScale( double *x, double *y );
275
276 virtual void GetLogicalOrigin( long *x, long *y );
277 virtual void GetDeviceOrigin( long *x, long *y );
278 virtual void SetInternalDeviceOrigin( long x, long y );
279 virtual void GetInternalDeviceOrigin( long *x, long *y );
280
281 virtual void SetOptimization( bool WXUNUSED(optimize) ) {};
282 virtual bool GetOptimization(void) { return m_optimize; };
283
284 virtual long DeviceToLogicalX(long x) const;
285 virtual long DeviceToLogicalY(long y) const;
286 virtual long DeviceToLogicalXRel(long x) const;
287 virtual long DeviceToLogicalYRel(long y) const;
288 virtual long LogicalToDeviceX(long x) const;
289 virtual long LogicalToDeviceY(long y) const;
290 virtual long LogicalToDeviceXRel(long x) const;
291 virtual long LogicalToDeviceYRel(long y) const;
292
293 void CalcBoundingBox( long x, long y );
294 */
295
296 void ComputeScaleAndOrigin(void);
297 public:
298
299
300 wxCoord XDEV2LOG(wxCoord x) const
301 {
302 long new_x = x - m_deviceOriginX;
303 if (new_x > 0)
304 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
305 else
306 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
307 }
308 wxCoord XDEV2LOGREL(wxCoord x) const
309 {
310 if (x > 0)
311 return (wxCoord)((double)(x) / m_scaleX + 0.5);
312 else
313 return (wxCoord)((double)(x) / m_scaleX - 0.5);
314 }
315 wxCoord YDEV2LOG(wxCoord y) const
316 {
317 long new_y = y - m_deviceOriginY;
318 if (new_y > 0)
319 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
320 else
321 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
322 }
323 wxCoord YDEV2LOGREL(wxCoord y) const
324 {
325 if (y > 0)
326 return (wxCoord)((double)(y) / m_scaleY + 0.5);
327 else
328 return (wxCoord)((double)(y) / m_scaleY - 0.5);
329 }
330 wxCoord XLOG2DEV(wxCoord x) const
331 {
332 long new_x = x - m_logicalOriginX;
333 if (new_x > 0)
334 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
335 else
336 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
337 }
338 wxCoord XLOG2DEVREL(wxCoord x) const
339 {
340 if (x > 0)
341 return (wxCoord)((double)(x) * m_scaleX + 0.5);
342 else
343 return (wxCoord)((double)(x) * m_scaleX - 0.5);
344 }
345 wxCoord YLOG2DEV(wxCoord y) const
346 {
347 long new_y = y - m_logicalOriginY;
348 if (new_y > 0)
349 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
350 else
351 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
352 }
353 wxCoord YLOG2DEVREL(wxCoord y) const
354 {
355 if (y > 0)
356 return (wxCoord)((double)(y) * m_scaleY + 0.5);
357 else
358 return (wxCoord)((double)(y) * m_scaleY - 0.5);
359 }
360
361 //
362
363 protected:
364 virtual void DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
365 int style = wxFLOOD_SURFACE);
366
367 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
368
369 virtual void DoDrawPoint(wxCoord x, wxCoord y);
370 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
371
372 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
373 wxCoord x2, wxCoord y2,
374 wxCoord xc, wxCoord yc);
375
376 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
377 double sa, double ea);
378
379 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
380 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
381 wxCoord width, wxCoord height,
382 double radius);
383 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
384
385 virtual void DoCrossHair(wxCoord x, wxCoord y);
386
387 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
388 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
389 bool useMask = FALSE);
390
391 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
392 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
393 double angle);
394
395 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
396 wxDC *source, wxCoord xsrc, wxCoord ysrc,
397 int rop = wxCOPY, bool useMask = FALSE);
398
399 // this is gnarly - we can't even call this function DoSetClippingRegion()
400 // because of virtual function hiding
401 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
402 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
403 wxCoord width, wxCoord height);
404 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
405 wxCoord *width, wxCoord *height)
406 {
407 GetClippingBox(x, y, width, height);
408 }
409
410 virtual void DoGetSize(int *width, int *height) const;
411 virtual void DoGetSizeMM(int* width, int* height) const;
412
413 virtual void DoDrawLines(int n, wxPoint points[],
414 wxCoord xoffset, wxCoord yoffset);
415 virtual void DoDrawPolygon(int n, wxPoint points[],
416 wxCoord xoffset, wxCoord yoffset,
417 int fillStyle = wxODDEVEN_RULE);
418
419
420
421 //
422
423 public:
424 //begin wxmac
425 double m_mm_to_pix_x,m_mm_to_pix_y;
426 bool m_needComputeScaleX,m_needComputeScaleY; // not yet used
427 long m_internalDeviceOriginX,m_internalDeviceOriginY; // If un-scrolled is non-zero or
428 // d.o. changes with scrolling.
429 // Set using SetInternalDeviceOrigin().
430
431 long m_externalDeviceOriginX,m_externalDeviceOriginY; // To be set by external classes
432 // such as wxScrolledWindow
433 // using SetDeviceOrigin()
434 GrafPtr m_macPort ;
435 GWorldPtr m_macMask ;
436
437 // in order to preserve the const inheritance of the virtual functions, we have to
438 // use mutable variables starting from CWPro 5
439
440 void MacInstallFont() const ;
441 void MacInstallPen() const ;
442 void MacInstallBrush() const ;
443
444 mutable bool m_macFontInstalled ;
445 mutable bool m_macPenInstalled ;
446 mutable bool m_macBrushInstalled ;
447
448 mutable long m_macPortId ;
449 GrafPtr m_macOrigPort ;
450 Rect m_macClipRect ;
451 Point m_macLocalOrigin ;
452 mutable AGAPortHelper m_macPortHelper ;
453 void MacSetupPort() const ;
454 void MacVerifySetup() const { if ( m_macPortId != m_macCurrentPortId ) MacSetupPort() ; }
455 static void MacInvalidateSetup() { m_macCurrentPortId++ ; }
456 static long m_macCurrentPortId ;
457 };
458
459 #endif
460 // _WX_DC_H_