]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dc.h
no message
[wxWidgets.git] / include / wx / msw / dc.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.h
3// Purpose: wxDC class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
bbcdf8bc
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_DC_H_
13#define _WX_DC_H_
2bda0e17
KB
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"
2432b92d 24#include "wx/window.h"
2bda0e17 25
3f1af920
JS
26// Clash with Windows header files
27#ifdef StartDoc
28#undef StartDoc
29#endif
30
31#ifdef DrawText
32#undef DrawText
33#endif
34
35#ifdef GetCharWidth
36#undef GetCharWidth
37#endif
38
2bda0e17
KB
39class WXDLLEXPORT wxDC: public wxObject
40{
41 DECLARE_ABSTRACT_CLASS(wxDC)
42 protected:
43public:
44 wxDC(void);
45 ~wxDC(void);
46
518f33a4
SC
47#ifdef WX_COMP_INLINE_NO_CLASS
48 inline void BeginDrawing(void) {}
49 inline void EndDrawing(void) {}
50#else
2bda0e17
KB
51 inline void wxDC::BeginDrawing(void) {}
52 inline void wxDC::EndDrawing(void) {}
518f33a4 53#endif
2bda0e17 54
6a6c0a8b
JS
55 virtual void FloodFill(long x1, long y1, const wxColour& col, int style=wxFLOOD_SURFACE) ;
56 inline void FloodFill(const wxPoint& pt, const wxColour& col, int style=wxFLOOD_SURFACE)
57 {
58 FloodFill(pt.x, pt.y, col, style);
59 }
60
2bda0e17 61 virtual bool GetPixel(long x1, long y1, wxColour *col) const ;
6a6c0a8b
JS
62 inline bool GetPixel(const wxPoint& pt, wxColour *col) const
63 {
64 return GetPixel(pt.x, pt.y, col);
65 }
2bda0e17
KB
66
67 virtual void DrawLine(long x1, long y1, long x2, long y2);
6a6c0a8b
JS
68 inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
69 {
70 DrawLine(pt1.x, pt1.y, pt2.x, pt2.y);
71 }
72
2bda0e17 73 virtual void CrossHair(long x, long y) ;
b823f5a1 74 inline void CrossHair(const wxPoint& pt)
6a6c0a8b
JS
75 {
76 CrossHair(pt.x, pt.y);
77 }
78
34138703
JS
79 virtual void DrawArc(long x1,long y1,long x2,long y2,long xc, long yc);
80 inline void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
6a6c0a8b 81 {
34138703 82 DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y);
6a6c0a8b
JS
83 }
84
2bda0e17 85 virtual void DrawEllipticArc (long x, long y, long w, long h, double sa, double ea);
6a6c0a8b
JS
86 virtual void DrawEllipticArc (const wxPoint& pt, const wxSize& sz, double sa, double ea)
87 {
88 DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea);
89 }
90
2bda0e17 91 virtual void DrawPoint(long x, long y);
6a6c0a8b
JS
92 inline void DrawPoint(const wxPoint& pt)
93 {
94 DrawPoint(pt.x, pt.y);
95 }
2bda0e17
KB
96
97 virtual void DrawLines(int n, wxPoint points[], long xoffset = 0, long yoffset = 0);
98
99 virtual void DrawPolygon(int n, wxPoint points[], long xoffset = 0, long yoffset = 0, int fillStyle=wxODDEVEN_RULE);
100
101 virtual void DrawRectangle(long x, long y, long width, long height);
6a6c0a8b
JS
102 inline void DrawRectangle(const wxPoint& pt, const wxSize& sz)
103 {
104 DrawRectangle(pt.x, pt.y, sz.x, sz.y);
105 }
106 inline void DrawRectangle(const wxRect& rect)
107 {
108 DrawRectangle(rect.x, rect.y, rect.width, rect.height);
109 }
110
2bda0e17 111 virtual void DrawRoundedRectangle(long x, long y, long width, long height, double radius = 20.0);
6a6c0a8b
JS
112 inline void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius = 20.0)
113 {
114 DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius);
115 }
116 inline void DrawRoundedRectangle(const wxRect& rect, double radius = 20.0)
117 {
118 DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, radius);
119 }
120
2bda0e17 121 virtual void DrawEllipse(long x, long y, long width, long height);
6a6c0a8b
JS
122 inline void DrawEllipse(const wxPoint& pt, const wxSize& sz)
123 {
124 DrawEllipse(pt.x, pt.y, sz.x, sz.y);
125 }
126 inline void DrawEllipse(const wxRect& rect)
127 {
128 DrawEllipse(rect.x, rect.y, rect.width, rect.height);
129 }
2bda0e17
KB
130
131 virtual void DrawIcon(const wxIcon& icon, long x, long y);
6a6c0a8b
JS
132 inline void DrawIcon(const wxIcon& icon, const wxPoint& pt)
133 {
134 DrawIcon(icon, pt.x, pt.y);
135 }
2bda0e17 136
f5419957
JS
137 virtual void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE );
138
6a6c0a8b
JS
139 inline void DrawPoint(wxPoint& point) { DrawPoint(point.x, point.y); }
140 virtual void DrawLines(wxList *list, long xoffset = 0, long yoffset = 0);
141 virtual void DrawPolygon(wxList *list, long xoffset = 0, long yoffset = 0, int fillStyle=wxODDEVEN_RULE);
142
143 virtual void DrawText(const wxString& text, long x, long y, bool use16bit = FALSE);
144 inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE)
145 {
146 DrawText(text, pt.x, pt.y, use16bit);
147 }
148
149 virtual bool Blit(long xdest, long ydest, long width, long height,
150 wxDC *source, long xsrc, long ysrc, int rop = wxCOPY, bool useMask = FALSE);
151 inline bool Blit(const wxPoint& destPt, const wxSize& sz,
152 wxDC *source, const wxPoint& srcPt, int rop = wxCOPY, bool useMask = FALSE)
153 {
154 return Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, rop, useMask);
155 }
156
47d67540 157#if wxUSE_SPLINES
6a6c0a8b
JS
158 // Splines
159 // 3-point spline
160 virtual void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3);
161 // Any number of control points - a list of pointers to wxPoints
162 virtual void DrawSpline(wxList *points);
163 virtual void DrawSpline(int n, wxPoint points[]);
164#endif
2bda0e17
KB
165 virtual void Clear(void);
166 virtual void SetFont(const wxFont& font);
167 virtual void SetPen(const wxPen& pen);
168 virtual void SetBrush(const wxBrush& brush);
169 virtual void SetLogicalFunction(int function);
170 virtual void SetBackground(const wxBrush& brush);
171 virtual void SetBackgroundMode(int mode);
6a6c0a8b 172
2bda0e17 173 virtual void SetClippingRegion(long x, long y, long width, long height);
6a6c0a8b
JS
174 inline void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
175 {
176 SetClippingRegion(pt.x, pt.y, sz.x, sz.y);
177 }
178 inline void SetClippingRegion(const wxRect& rect)
179 {
180 SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
181 }
a724d789 182 virtual void SetClippingRegion(const wxRegion& region);
6a6c0a8b 183
2bda0e17
KB
184 virtual void SetPalette(const wxPalette& palette);
185#if WXWIN_COMPATIBILITY
186 virtual inline void SetColourMap(const wxPalette& palette) { SetPalette(palette); };
187#endif
188 virtual void DestroyClippingRegion(void);
2bda0e17
KB
189 virtual long GetCharHeight(void) const;
190 virtual long GetCharWidth(void) const;
191 virtual void GetTextExtent(const wxString& string, long *x, long *y,
192 long *descent = NULL, long *externalLeading = NULL,
193 wxFont *theFont = NULL, bool use16bit = FALSE) const;
194#if WXWIN_COMPATIBILITY
195 void GetTextExtent(const wxString& string, float *x, float *y,
196 float *descent = NULL, float *externalLeading = NULL,
197 wxFont *theFont = NULL, bool use16bit = FALSE) const ;
198#endif
199
200 // Size in device units
201 virtual void GetSize(int* width, int* height) const;
202 inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); }
203
204 // Size in mm
205 virtual void GetSizeMM(long* width, long* height) const ;
206
207 // Compatibility
208#if WXWIN_COMPATIBILITY
209 inline void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; }
210 inline void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; }
211#endif
212
213 virtual bool StartDoc(const wxString& message);
214 virtual void EndDoc(void);
215 virtual void StartPage(void);
216 virtual void EndPage(void);
217 virtual void SetMapMode(int mode);
218 virtual void SetUserScale(double x, double y);
219 virtual void SetSystemScale(double x, double y);
220 virtual void SetLogicalOrigin(long x, long y);
221 virtual void SetDeviceOrigin(long x, long y);
6f65e337 222 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
2bda0e17
KB
223
224 // This group of functions does actual conversion
225 // of the input, as you'd expect.
226
227 long DeviceToLogicalX(long x) const;
228 long DeviceToLogicalY(long y) const;
229 long DeviceToLogicalXRel(long x) const;
230 long DeviceToLogicalYRel(long y) const;
231 long LogicalToDeviceX(long x) const;
232 long LogicalToDeviceY(long y) const;
233 long LogicalToDeviceXRel(long x) const;
234 long LogicalToDeviceYRel(long y) const;
235
236 // This group of functions may not do any conversion
237 // if m_scaleGDI is TRUE, since the HDC does the
238 // conversion automatically.
239 // m_scaleGDI NOW OBSOLETE
240 long ImplDeviceToLogicalX(long x) const;
241 long ImplDeviceToLogicalY(long y) const;
242 long ImplDeviceToLogicalXRel(long x) const;
243 long ImplDeviceToLogicalYRel(long y) const;
244 long ImplLogicalToDeviceX(long x) const;
245 long ImplLogicalToDeviceY(long y) const;
246 long ImplLogicalToDeviceXRel(long x) const;
247 long ImplLogicalToDeviceYRel(long y) const;
248
2bda0e17
KB
249 virtual bool CanDrawBitmap(void) const;
250 virtual bool CanGetTextExtent(void) const;
251
2bda0e17
KB
252 virtual void SetTextForeground(const wxColour& colour);
253 virtual void SetTextBackground(const wxColour& colour);
254 inline virtual bool Ok(void) const {return m_ok;};
255 inline virtual int GetMapMode(void) const {return m_mappingMode;};
256
c0ed460c
JS
257 inline virtual wxBrush& GetBackground(void) const { return (wxBrush&) m_backgroundBrush ;}
258 inline virtual wxBrush& GetBrush(void) const { return (wxBrush&) m_brush ;}
259 inline virtual wxFont& GetFont(void) const { return (wxFont&) m_font ;}
2bda0e17 260 inline virtual int GetLogicalFunction(void) const { return m_logicalFunction ;}
c0ed460c 261 inline virtual wxPen& GetPen(void) const { return (wxPen&) m_pen ;}
2bda0e17
KB
262 inline virtual wxColour&GetTextBackground(void) const { return (wxColour&) m_textBackgroundColour ;}
263 inline virtual wxColour&GetTextForeground(void) const { return (wxColour&) m_textForegroundColour ;}
264
265 virtual void SetLogicalScale(double x, double y);
266 virtual inline void GetUserScale(double* x, double *y) const { *x = m_userScaleX; *y = m_userScaleY; }
267 virtual void CalcBoundingBox(long x, long y);
268 // Get the final bounding box of the PostScript or Metafile picture.
269 virtual inline long MinX(void) const { return m_minX; }
270 virtual inline long MaxX(void) const { return m_maxX; }
271 virtual inline long MinY(void) const { return m_minY; }
272 virtual inline long MaxY(void) const { return m_maxY; }
273 // Sometimes we need to override optimization, e.g.
274 // if other software is drawing onto our surface and we
275 // can't be sure of who's done what.
276 virtual inline void SetOptimization(bool WXUNUSED(opt)) { }
277 virtual inline bool GetOptimization(void) { return FALSE; }
278
279 virtual void GetClippingBox(long *x,long *y,long *w,long *h) const ;
6a6c0a8b
JS
280 inline void GetClippingBox(wxRect& rect) const
281 {
282 long x, y, w, h;
283 GetClippingBox(&x, &y, &w, &h); rect.x = x; rect.y = y; rect.width = w; rect.height = h;
284 }
2bda0e17 285
7b46ecac 286 // This should probably be made available on other platforms
518f33a4
SC
287#ifdef WX_COMP_INLINE_NO_CLASS
288 int GetDepth(void) const ;
289#else
7b46ecac 290 int wxDC::GetDepth(void) const ;
518f33a4 291#endif
7b46ecac
JS
292
293// Implementation
2bda0e17
KB
294 virtual void SetRop(WXHDC cdc);
295 virtual void DoClipping(WXHDC cdc);
296 virtual void SelectOldObjects(WXHDC dc);
297
298 inline wxWindow *GetWindow(void) const { return m_canvas; }
299 inline void SetWindow(wxWindow *win) { m_canvas = win; }
300 inline WXHDC GetHDC(void) const { return m_hDC; }
301 inline void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) { m_hDC = dc; m_bOwnsDC = bOwnsDC; }
2bda0e17
KB
302
303protected:
304 bool m_colour;
305 bool m_ok;
306 bool m_clipping;
307 bool m_isInteractive;
308
309 // Coordinate system variables
310 long m_logicalOriginX;
311 long m_logicalOriginY;
312
313 long m_deviceOriginX;
314 long m_deviceOriginY;
315
316 double m_logicalScaleX;
317 double m_logicalScaleY;
318
319 double m_userScaleX;
320 double m_userScaleY;
321
6f65e337
JS
322 int m_signX; // Used by SetAxisOrientation() to
323 int m_signY; // invert the axes
324
2bda0e17
KB
325 int m_mappingMode;
326
327 long m_minX; // bounding box
328 long m_minY;
329 long m_maxX;
330 long m_maxY;
331
332 int m_logicalFunction;
333 int m_backgroundMode;
334
335 wxPen m_pen;
336 wxBrush m_brush;
337 wxBrush m_backgroundBrush;
338 wxColour m_textForegroundColour;
339 wxColour m_textBackgroundColour;
340 wxFont m_font;
341 wxPalette m_palette;
2bda0e17
KB
342 int m_clipX1;
343 int m_clipY1;
344 int m_clipX2;
345 int m_clipY2;
346// bool m_dontDelete;
347 int m_windowExtX;
348 int m_windowExtY;
349 double m_systemScaleX;
350 double m_systemScaleY;
351
352 wxWindow * m_canvas;
353 wxBitmap m_selectedBitmap;
354 wxString m_filename;
355
356 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
357 bool m_bOwnsDC;
358
359 WXHDC m_hDC;
360 int m_hDCCount;
361
362 // Store all old GDI objects when do a SelectObject,
363 // so we can select them back in (this unselecting user's
364 // objects) so we can safely delete the DC.
365 WXHBITMAP m_oldBitmap;
366 WXHPEN m_oldPen;
367 WXHBRUSH m_oldBrush;
368 WXHFONT m_oldFont;
369 WXHPALETTE m_oldPalette;
370
371 // Stores scaling, translation, rotation
372// wxTransformMatrix m_transformMatrix;
373
374 // Do we wish to scale GDI objects too, e.g. pen width?
375// bool m_scaleGDI;
376};
377
378// Logical to device
379// Absolute
380#define XLOG2DEV(x) ImplLogicalToDeviceX(x)
381
382#define YLOG2DEV(y) ImplLogicalToDeviceY(y)
383
384// Relative
385#define XLOG2DEVREL(x) ImplLogicalToDeviceXRel(x)
386#define YLOG2DEVREL(y) ImplLogicalToDeviceYRel(y)
387
388// Device to logical
389// Absolute
390#define XDEV2LOG(x) ImplDeviceToLogicalX(x)
391
392#define YDEV2LOG(y) ImplDeviceToLogicalY(y)
393
394// Relative
395#define XDEV2LOGREL(x) ImplDeviceToLogicalXRel(x)
396#define YDEV2LOGREL(y) ImplDeviceToLogicalYRel(y)
397
398/*
399 * Have the same macros as for XView but not for every operation:
400 * just for calculating window/viewport extent (a better way of scaling).
401 */
402
403// Logical to device
404// Absolute
405#define MS_XLOG2DEV(x) LogicalToDevice(x)
406
407#define MS_YLOG2DEV(y) LogicalToDevice(y)
408
409// Relative
410#define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x)
411#define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y)
412
413// Device to logical
414// Absolute
415#define MS_XDEV2LOG(x) DeviceToLogicalX(x)
416
417#define MS_YDEV2LOG(y) DeviceToLogicalY(y)
418
419// Relative
420#define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x)
421#define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y)
422
423#define MM_POINTS 7
424#define MM_METRIC 8
425
426extern int wxPageNumber;
427
428// Conversion
429#define METRIC_CONVERSION_CONSTANT 0.0393700787
430
431// Scaling factors for various unit conversions
432#define mm2inches (METRIC_CONVERSION_CONSTANT)
433#define inches2mm (1/METRIC_CONVERSION_CONSTANT)
434
435#define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
436#define twips2mm (1/(METRIC_CONVERSION_CONSTANT*1440))
437
438#define mm2pt (METRIC_CONVERSION_CONSTANT*72)
439#define pt2mm (1/(METRIC_CONVERSION_CONSTANT*72))
440
441#define wx_round(a) (int)((a)+.5)
442
443
444#endif
bbcdf8bc 445 // _WX_DC_H_