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