]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/dc.h
fixed GetMargins() compilation
[wxWidgets.git] / include / wx / mac / dc.h
CommitLineData
0dbd6262
SC
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"
05adb9d2 24#include "wx/mac/aga.h"
0dbd6262
SC
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
45extern int wxPageNumber;
46
47//-----------------------------------------------------------------------------
48// wxDC
49//-----------------------------------------------------------------------------
50
05adb9d2 51class WXDLLEXPORT wxDC: public wxDCBase
0dbd6262 52{
05adb9d2 53 DECLARE_DYNAMIC_CLASS(wxDC)
0dbd6262
SC
54
55 public:
56
05adb9d2
SC
57 wxDC();
58 ~wxDC();
0dbd6262 59
05adb9d2
SC
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/*
0dbd6262
SC
110 void BeginDrawing(void) {};
111 void EndDrawing(void) {};
112
113 virtual bool Ok(void) const { return m_ok; };
114
519cb848 115 virtual void FloodFill( long x1, long y1, const wxColour& col, int style=wxFLOOD_SURFACE );
0dbd6262
SC
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
519cb848 121 virtual bool GetPixel( long x1, long y1, wxColour *col ) const ;
0dbd6262
SC
122 inline bool GetPixel(const wxPoint& pt, wxColour *col) const
123 {
124 return GetPixel(pt.x, pt.y, col);
125 }
126
519cb848 127 virtual void DrawLine( long x1, long y1, long x2, long y2 );
0dbd6262
SC
128 inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
129 {
130 DrawLine(pt1.x, pt1.y, pt2.x, pt2.y);
131 }
132
519cb848 133 virtual void CrossHair( long x, long y );
0dbd6262
SC
134 inline void CrossHair(const wxPoint& pt)
135 {
136 CrossHair(pt.x, pt.y);
137 }
138
519cb848 139 virtual void DrawArc( long x1, long y1, long x2, long y2, long xc, long yc );
0dbd6262
SC
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
519cb848 145 virtual void DrawEllipticArc( long x, long y, long width, long height, double sa, double ea );
0dbd6262
SC
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
519cb848 151 virtual void DrawPoint( long x, long y );
0dbd6262
SC
152 virtual void DrawPoint( wxPoint& point );
153
519cb848 154 virtual void DrawLines( int n, wxPoint points[], long xoffset = 0, long yoffset = 0 );
0dbd6262
SC
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,
519cb848 157 int fillStyle=wxODDEVEN_RULE );
0dbd6262
SC
158 virtual void DrawPolygon( wxList *lines, long xoffset = 0, long yoffset = 0,
159 int fillStyle=wxODDEVEN_RULE );
160
519cb848 161 virtual void DrawRectangle( long x, long y, long width, long height );
0dbd6262
SC
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 }
519cb848 170 virtual void DrawRoundedRectangle( long x, long y, long width, long height, double radius = 20.0 );
0dbd6262
SC
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
519cb848 180 virtual void DrawEllipse( long x, long y, long width, long height );
0dbd6262
SC
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 );
519cb848 191 virtual void DrawSpline( wxList *points );
0dbd6262
SC
192 virtual void DrawSpline( int n, wxPoint points[] );
193
519cb848 194 virtual bool CanDrawBitmap(void) const ;
0dbd6262
SC
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
519cb848 202 void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE ) ;
0dbd6262
SC
203
204 virtual bool Blit( long xdest, long ydest, long width, long height,
519cb848 205 wxDC *source, long xsrc, long ysrc, int logical_func = wxCOPY, bool useMask=FALSE );
0dbd6262
SC
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
519cb848 212 virtual void DrawText( const wxString &text, long x, long y, bool use16 = FALSE );
0dbd6262
SC
213 inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE)
214 {
215 DrawText(text, pt.x, pt.y, use16bit);
216 }
217
519cb848 218 virtual bool CanGetTextExtent(void) const ;
4765d335
SC
219 virtual void GetTextExtent( const wxString &string, int *width, int *height,
220 int *descent = NULL, int *externalLeading = NULL,
05adb9d2 221 wxFont *theFont = NULL, bool use16 = FALSE ) const ;
2fc70a88
UJ
222 virtual wxCoord GetCharWidth(void) const;
223 virtual wxCoord GetCharHeight(void) const;
0dbd6262 224
519cb848 225 virtual void Clear(void);
0dbd6262 226
519cb848 227 virtual void SetFont( const wxFont &font );
0dbd6262
SC
228 virtual wxFont& GetFont(void) const { return (wxFont&) m_font; };
229
519cb848 230 virtual void SetPen( const wxPen &pen );
0dbd6262
SC
231 virtual wxPen& GetPen(void) const { return (wxPen&) m_pen; };
232
519cb848 233 virtual void SetBrush( const wxBrush &brush );
0dbd6262
SC
234 virtual wxBrush& GetBrush(void) const { return (wxBrush&) m_brush; };
235
519cb848 236 virtual void SetBackground( const wxBrush &brush );
0dbd6262
SC
237 virtual wxBrush& GetBackground(void) const { return (wxBrush&) m_backgroundBrush; };
238
519cb848 239 virtual void SetLogicalFunction( int function );
0dbd6262
SC
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
519cb848 247 virtual void SetBackgroundMode( int mode );
0dbd6262
SC
248 virtual int GetBackgroundMode(void) const { return m_backgroundMode; };
249
519cb848 250 virtual void SetPalette( const wxPalette& palette );
0dbd6262
SC
251 void SetColourMap( const wxPalette& palette ) { SetPalette(palette); };
252
253 // the first two must be overridden and called
2fc70a88
UJ
254 virtual void SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
255 virtual void SetClippingRegion( const wxRect& rect );
0dbd6262 256 virtual void DestroyClippingRegion(void);
2fc70a88 257 virtual void GetClippingBox( wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height ) const;
0dbd6262 258 virtual void GetClippingBox( long *x, long *y, long *width, long *height ) const;
2fc70a88 259 virtual void GetClippingBox(wxRect& rect) const;
0dbd6262
SC
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
0dbd6262 270
0dbd6262
SC
271 virtual int GetMapMode(void) const { return m_mappingMode; };
272
0dbd6262 273 virtual void GetUserScale( double *x, double *y );
0dbd6262
SC
274 virtual void GetLogicalScale( double *x, double *y );
275
0dbd6262 276 virtual void GetLogicalOrigin( long *x, long *y );
0dbd6262
SC
277 virtual void GetDeviceOrigin( long *x, long *y );
278 virtual void SetInternalDeviceOrigin( long x, long y );
279 virtual void GetInternalDeviceOrigin( long *x, long *y );
0dbd6262
SC
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
0dbd6262 293 void CalcBoundingBox( long x, long y );
05adb9d2
SC
294*/
295
0dbd6262 296 void ComputeScaleAndOrigin(void);
05adb9d2
SC
297 public:
298
0dbd6262 299
03e11df5 300 wxCoord XDEV2LOG(wxCoord x) const
0dbd6262
SC
301 {
302 long new_x = x - m_deviceOriginX;
303 if (new_x > 0)
03e11df5 304 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
0dbd6262 305 else
03e11df5 306 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
0dbd6262 307 }
03e11df5 308 wxCoord XDEV2LOGREL(wxCoord x) const
0dbd6262
SC
309 {
310 if (x > 0)
03e11df5 311 return (wxCoord)((double)(x) / m_scaleX + 0.5);
0dbd6262 312 else
03e11df5 313 return (wxCoord)((double)(x) / m_scaleX - 0.5);
0dbd6262 314 }
03e11df5 315 wxCoord YDEV2LOG(wxCoord y) const
0dbd6262
SC
316 {
317 long new_y = y - m_deviceOriginY;
318 if (new_y > 0)
03e11df5 319 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
0dbd6262 320 else
03e11df5 321 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
0dbd6262 322 }
03e11df5 323 wxCoord YDEV2LOGREL(wxCoord y) const
0dbd6262
SC
324 {
325 if (y > 0)
03e11df5 326 return (wxCoord)((double)(y) / m_scaleY + 0.5);
0dbd6262 327 else
03e11df5 328 return (wxCoord)((double)(y) / m_scaleY - 0.5);
0dbd6262 329 }
03e11df5 330 wxCoord XLOG2DEV(wxCoord x) const
0dbd6262
SC
331 {
332 long new_x = x - m_logicalOriginX;
333 if (new_x > 0)
03e11df5 334 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
0dbd6262 335 else
03e11df5 336 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
0dbd6262 337 }
03e11df5 338 wxCoord XLOG2DEVREL(wxCoord x) const
0dbd6262
SC
339 {
340 if (x > 0)
03e11df5 341 return (wxCoord)((double)(x) * m_scaleX + 0.5);
0dbd6262 342 else
03e11df5 343 return (wxCoord)((double)(x) * m_scaleX - 0.5);
0dbd6262 344 }
03e11df5 345 wxCoord YLOG2DEV(wxCoord y) const
0dbd6262
SC
346 {
347 long new_y = y - m_logicalOriginY;
348 if (new_y > 0)
03e11df5 349 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
0dbd6262 350 else
03e11df5 351 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
0dbd6262 352 }
03e11df5 353 wxCoord YLOG2DEVREL(wxCoord y) const
0dbd6262
SC
354 {
355 if (y > 0)
03e11df5 356 return (wxCoord)((double)(y) * m_scaleY + 0.5);
0dbd6262 357 else
03e11df5 358 return (wxCoord)((double)(y) * m_scaleY - 0.5);
0dbd6262
SC
359 }
360
05adb9d2
SC
361//
362
363protected:
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
0dbd6262
SC
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
05adb9d2
SC
474 float m_scaleFactor; // wxPSDC wants to have this. Will disappear.
475
0dbd6262
SC
476 long m_clipX1,m_clipY1,m_clipX2,m_clipY2;
477 long m_minX,m_maxX,m_minY,m_maxY;
519cb848
SC
478
479//begin wxmac
480 GrafPtr m_macPort ;
8208e181 481 GWorldPtr m_macMask ;
519cb848
SC
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 ;
03e11df5 498 mutable AGAPortHelper m_macPortHelper ;
519cb848
SC
499 void MacSetupPort() const ;
500 void MacVerifySetup() const { if ( m_macPortId != m_macCurrentPortId ) MacSetupPort() ; }
501
502 static long m_macCurrentPortId ;
0dbd6262
SC
503};
504
505#endif
506 // _WX_DC_H_