]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/dc.h
applied wxNativeFontInfo patch from Derry Bryson (with minor changes)
[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 long XDEV2LOG(long x) const
301 {
302 long new_x = x - m_deviceOriginX;
303 if (new_x > 0)
304 return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
305 else
306 return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
307 }
308 long XDEV2LOGREL(long x) const
309 {
310 if (x > 0)
311 return (long)((double)(x) / m_scaleX + 0.5);
312 else
313 return (long)((double)(x) / m_scaleX - 0.5);
314 }
315 long YDEV2LOG(long y) const
316 {
317 long new_y = y - m_deviceOriginY;
318 if (new_y > 0)
319 return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
320 else
321 return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
322 }
323 long YDEV2LOGREL(long y) const
324 {
325 if (y > 0)
326 return (long)((double)(y) / m_scaleY + 0.5);
327 else
328 return (long)((double)(y) / m_scaleY - 0.5);
329 }
330 long XLOG2DEV(long x) const
331 {
332 long new_x = x - m_logicalOriginX;
333 if (new_x > 0)
334 return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
335 else
336 return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
337 }
338 long XLOG2DEVREL(long x) const
339 {
340 if (x > 0)
341 return (long)((double)(x) * m_scaleX + 0.5);
342 else
343 return (long)((double)(x) * m_scaleX - 0.5);
344 }
345 long YLOG2DEV(long y) const
346 {
347 long new_y = y - m_logicalOriginY;
348 if (new_y > 0)
349 return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
350 else
351 return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
352 }
353 long YLOG2DEVREL(long y) const
354 {
355 if (y > 0)
356 return (long)((double)(y) * m_scaleY + 0.5);
357 else
358 return (long)((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 #if wxUSE_SPLINES
420 virtual void DoDrawSpline(wxList *points);
421 #endif // wxUSE_SPLINES
422
423
424 //
425
426 public:
427
428 bool m_ok;
429 bool m_colour;
430
431 // not sure, what these mean
432 bool m_clipping; // Is clipping on right now ?
433 bool m_isInteractive; // Is GetPixel possible ?
434 bool m_autoSetting; // wxMSW only ?
435 bool m_dontDelete; // wxMSW only ?
436 bool m_optimize; // wxMSW only ?
437 wxString m_filename; // Not sure where this belongs.
438
439 wxPen m_pen;
440 wxBrush m_brush;
441 wxBrush m_backgroundBrush;
442 wxColour m_textForegroundColour;
443 wxColour m_textBackgroundColour;
444 wxFont m_font;
445
446 int m_logicalFunction;
447 int m_backgroundMode;
448 int m_textAlignment; // gone in wxWin 2.0 ?
449
450 int m_mappingMode;
451
452 // not sure what for, but what is a mm on a screen you don't know the size of?
453 double m_mm_to_pix_x,m_mm_to_pix_y;
454
455 long m_internalDeviceOriginX,m_internalDeviceOriginY; // If un-scrolled is non-zero or
456 // d.o. changes with scrolling.
457 // Set using SetInternalDeviceOrigin().
458
459 long m_externalDeviceOriginX,m_externalDeviceOriginY; // To be set by external classes
460 // such as wxScrolledWindow
461 // using SetDeviceOrigin()
462
463 long m_deviceOriginX,m_deviceOriginY; // Sum of the two above.
464
465 long m_logicalOriginX,m_logicalOriginY; // User defined.
466
467 double m_scaleX,m_scaleY;
468 double m_logicalScaleX,m_logicalScaleY;
469 double m_userScaleX,m_userScaleY;
470 long m_signX,m_signY;
471
472 bool m_needComputeScaleX,m_needComputeScaleY; // not yet used
473
474 float m_scaleFactor; // wxPSDC wants to have this. Will disappear.
475
476 long m_clipX1,m_clipY1,m_clipX2,m_clipY2;
477 long m_minX,m_maxX,m_minY,m_maxY;
478
479 //begin wxmac
480 GrafPtr m_macPort ;
481 GWorldPtr m_macMask ;
482
483 // in order to preserve the const inheritance of the virtual functions, we have to
484 // use mutable variables starting from CWPro 5
485
486 void MacInstallFont() const ;
487 void MacInstallPen() const ;
488 void MacInstallBrush() const ;
489
490 mutable bool m_macFontInstalled ;
491 mutable bool m_macPenInstalled ;
492 mutable bool m_macBrushInstalled ;
493
494 mutable long m_macPortId ;
495 GrafPtr m_macOrigPort ;
496 Rect m_macClipRect ;
497 Point m_macLocalOrigin ;
498 AGAPortHelper m_macPortHelper ;
499 void MacSetupPort() const ;
500 void MacVerifySetup() const { if ( m_macPortId != m_macCurrentPortId ) MacSetupPort() ; }
501
502 static long m_macCurrentPortId ;
503 };
504
505 #endif
506 // _WX_DC_H_