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