1. MSW message handling simplifications
[wxWidgets.git] / include / wx / msw / dc.h
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$
8 // Copyright: (c) Julian Smart
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 class WXDLLEXPORT wxDC : public wxDCBase
20 {
21 DECLARE_DYNAMIC_CLASS(wxDC)
22
23 public:
24 wxDC();
25 ~wxDC();
26
27 // implement base class pure virtuals
28 // ----------------------------------
29
30 virtual void Clear();
31
32 virtual bool StartDoc(const wxString& message);
33 virtual void EndDoc();
34
35 virtual void StartPage();
36 virtual void EndPage();
37
38 virtual void SetFont(const wxFont& font);
39 virtual void SetPen(const wxPen& pen);
40 virtual void SetBrush(const wxBrush& brush);
41 virtual void SetBackground(const wxBrush& brush);
42 virtual void SetBackgroundMode(int mode);
43 virtual void SetPalette(const wxPalette& palette);
44
45 virtual void DestroyClippingRegion();
46
47 virtual long GetCharHeight() const;
48 virtual long GetCharWidth() const;
49 virtual void GetTextExtent(const wxString& string,
50 long *x, long *y,
51 long *descent = NULL,
52 long *externalLeading = NULL,
53 wxFont *theFont = NULL) const;
54
55 virtual bool CanDrawBitmap() const;
56 virtual bool CanGetTextExtent() const;
57 virtual int GetDepth() const;
58 virtual wxSize GetPPI() const;
59
60 virtual void SetMapMode(int mode);
61 virtual void SetUserScale(double x, double y);
62 virtual void SetSystemScale(double x, double y);
63 virtual void SetLogicalScale(double x, double y);
64 virtual void SetLogicalOrigin(long x, long y);
65 virtual void SetDeviceOrigin(long x, long y);
66 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
67 virtual void SetLogicalFunction(int function);
68
69 // implementation from now on
70 // --------------------------
71
72 virtual void SetRop(WXHDC cdc);
73 virtual void DoClipping(WXHDC cdc);
74 virtual void SelectOldObjects(WXHDC dc);
75
76 wxWindow *GetWindow() const { return m_canvas; }
77 void SetWindow(wxWindow *win) { m_canvas = win; }
78
79 WXHDC GetHDC() const { return m_hDC; }
80 void SetHDC(WXHDC dc, bool bOwnsDC = FALSE)
81 {
82 m_hDC = dc;
83 m_bOwnsDC = bOwnsDC;
84 }
85
86 protected:
87 virtual void DoFloodFill(long x, long y, const wxColour& col,
88 int style = wxFLOOD_SURFACE);
89
90 virtual bool DoGetPixel(long x, long y, wxColour *col) const;
91
92 virtual void DoDrawPoint(long x, long y);
93 virtual void DoDrawLine(long x1, long y1, long x2, long y2);
94
95 virtual void DoDrawArc(long x1, long y1,
96 long x2, long y2,
97 long xc, long yc);
98 virtual void DoDrawEllipticArc(long x, long y, long w, long h,
99 double sa, double ea);
100
101 virtual void DoDrawRectangle(long x, long y, long width, long height);
102 virtual void DoDrawRoundedRectangle(long x, long y,
103 long width, long height,
104 double radius);
105 virtual void DoDrawEllipse(long x, long y, long width, long height);
106
107 virtual void DoCrossHair(long x, long y);
108
109 virtual void DoDrawIcon(const wxIcon& icon, long x, long y);
110 virtual void DoDrawBitmap(const wxBitmap &bmp, long x, long y,
111 bool useMask = FALSE);
112
113 virtual void DoDrawText(const wxString& text, long x, long y);
114
115 virtual bool DoBlit(long xdest, long ydest, long width, long height,
116 wxDC *source, long xsrc, long ysrc,
117 int rop = wxCOPY, bool useMask = FALSE);
118
119 // this is gnarly - we can't even call this function DoSetClippingRegion()
120 // because of virtual function hiding
121 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
122 virtual void DoSetClippingRegion(long x, long y,
123 long width, long height);
124 virtual void DoGetClippingRegion(long *x, long *y,
125 long *width, long *height)
126 {
127 GetClippingBox(x, y, width, height);
128 }
129
130 virtual void DoGetSize(int *width, int *height) const;
131 virtual void DoGetSizeMM(int* width, int* height) const;
132
133 virtual void DoDrawLines(int n, wxPoint points[],
134 long xoffset, long yoffset);
135 virtual void DoDrawPolygon(int n, wxPoint points[],
136 long xoffset, long yoffset,
137 int fillStyle = wxODDEVEN_RULE);
138
139 #if wxUSE_SPLINES
140 virtual void DoDrawSpline(wxList *points);
141 #endif // wxUSE_SPLINES
142
143 // MSW-specific member variables
144 int m_windowExtX;
145 int m_windowExtY;
146
147 // the window associated with this DC (may be NULL)
148 wxWindow *m_canvas;
149
150 wxBitmap m_selectedBitmap;
151
152 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
153 bool m_bOwnsDC:1;
154
155 // our HDC and its usage count: we only free it when the usage count drops
156 // to 0
157 WXHDC m_hDC;
158 int m_hDCCount;
159
160 // Store all old GDI objects when do a SelectObject, so we can select them
161 // back in (this unselecting user's objects) so we can safely delete the
162 // DC.
163 WXHBITMAP m_oldBitmap;
164 WXHPEN m_oldPen;
165 WXHBRUSH m_oldBrush;
166 WXHFONT m_oldFont;
167 WXHPALETTE m_oldPalette;
168 };
169
170 // Logical to device
171 // Absolute
172 #define XLOG2DEV(x) (x)
173 #define YLOG2DEV(y) (y)
174
175 // Relative
176 #define XLOG2DEVREL(x) (x)
177 #define YLOG2DEVREL(y) (y)
178
179 // Device to logical
180 // Absolute
181 #define XDEV2LOG(x) (x)
182
183 #define YDEV2LOG(y) (y)
184
185 // Relative
186 #define XDEV2LOGREL(x) (x)
187 #define YDEV2LOGREL(y) (y)
188
189 /*
190 * Have the same macros as for XView but not for every operation:
191 * just for calculating window/viewport extent (a better way of scaling).
192 */
193
194 // Logical to device
195 // Absolute
196 #define MS_XLOG2DEV(x) LogicalToDevice(x)
197
198 #define MS_YLOG2DEV(y) LogicalToDevice(y)
199
200 // Relative
201 #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x)
202 #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y)
203
204 // Device to logical
205 // Absolute
206 #define MS_XDEV2LOG(x) DeviceToLogicalX(x)
207
208 #define MS_YDEV2LOG(y) DeviceToLogicalY(y)
209
210 // Relative
211 #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x)
212 #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y)
213
214 #define MM_POINTS 9
215 #define MM_METRIC 10
216
217 // Conversion
218 #define METRIC_CONVERSION_CONSTANT 0.0393700787
219
220 // Scaling factors for various unit conversions
221 #define mm2inches (METRIC_CONVERSION_CONSTANT)
222 #define inches2mm (1/METRIC_CONVERSION_CONSTANT)
223
224 #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
225 #define twips2mm (1/(METRIC_CONVERSION_CONSTANT*1440))
226
227 #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
228 #define pt2mm (1/(METRIC_CONVERSION_CONSTANT*72))
229
230 #define wx_round(a) (int)((a)+.5)
231
232 #endif
233 // _WX_DC_H_