]>
Commit | Line | Data |
---|---|---|
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 | 8 | // Copyright: (c) Julian Smart |
a23fd0e1 | 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__ | |
a23fd0e1 | 16 | #pragma interface "dc.h" |
2bda0e17 KB |
17 | #endif |
18 | ||
2662e49e RR |
19 | #include "wx/defs.h" |
20 | #include "wx/dc.h" | |
21 | ||
e6f1ad22 HH |
22 | // --------------------------------------------------------------------------- |
23 | // macros | |
24 | // --------------------------------------------------------------------------- | |
25 | ||
26 | // Logical to device | |
27 | // Absolute | |
28 | #define XLOG2DEV(x) (x) | |
29 | #define YLOG2DEV(y) (y) | |
30 | ||
31 | // Relative | |
32 | #define XLOG2DEVREL(x) (x) | |
33 | #define YLOG2DEVREL(y) (y) | |
34 | ||
35 | // Device to logical | |
36 | // Absolute | |
37 | #define XDEV2LOG(x) (x) | |
38 | ||
39 | #define YDEV2LOG(y) (y) | |
40 | ||
41 | // Relative | |
42 | #define XDEV2LOGREL(x) (x) | |
43 | #define YDEV2LOGREL(y) (y) | |
44 | ||
45 | /* | |
46 | * Have the same macros as for XView but not for every operation: | |
47 | * just for calculating window/viewport extent (a better way of scaling). | |
48 | */ | |
49 | ||
50 | // Logical to device | |
51 | // Absolute | |
52 | #define MS_XLOG2DEV(x) LogicalToDevice(x) | |
53 | ||
54 | #define MS_YLOG2DEV(y) LogicalToDevice(y) | |
55 | ||
56 | // Relative | |
57 | #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
58 | #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y) | |
59 | ||
60 | // Device to logical | |
61 | // Absolute | |
62 | #define MS_XDEV2LOG(x) DeviceToLogicalX(x) | |
63 | ||
64 | #define MS_YDEV2LOG(y) DeviceToLogicalY(y) | |
65 | ||
66 | // Relative | |
67 | #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x) | |
68 | #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y) | |
69 | ||
70 | #define YSCALE(y) (yorigin - (y)) | |
71 | ||
72 | #define wx_round(a) (int)((a)+.5) | |
73 | ||
0cbff120 JS |
74 | #if wxUSE_DC_CACHEING |
75 | /* | |
76 | * Cached blitting, maintaining a cache | |
77 | * of bitmaps required for transparent blitting | |
78 | * instead of constant creation/deletion | |
79 | */ | |
80 | ||
81 | class wxDCCacheEntry: public wxObject | |
82 | { | |
83 | public: | |
84 | wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth); | |
85 | wxDCCacheEntry(WXHDC hDC, int depth); | |
86 | ~wxDCCacheEntry(); | |
87 | ||
88 | WXHBITMAP m_bitmap; | |
89 | WXHDC m_dc; | |
90 | int m_width; | |
91 | int m_height; | |
92 | int m_depth; | |
93 | }; | |
94 | #endif | |
95 | ||
a23fd0e1 | 96 | class WXDLLEXPORT wxDC : public wxDCBase |
2bda0e17 | 97 | { |
2bda0e17 | 98 | public: |
a23fd0e1 VZ |
99 | wxDC(); |
100 | ~wxDC(); | |
101 | ||
102 | // implement base class pure virtuals | |
103 | // ---------------------------------- | |
104 | ||
105 | virtual void Clear(); | |
106 | ||
107 | virtual bool StartDoc(const wxString& message); | |
108 | virtual void EndDoc(); | |
109 | ||
110 | virtual void StartPage(); | |
111 | virtual void EndPage(); | |
112 | ||
113 | virtual void SetFont(const wxFont& font); | |
114 | virtual void SetPen(const wxPen& pen); | |
115 | virtual void SetBrush(const wxBrush& brush); | |
116 | virtual void SetBackground(const wxBrush& brush); | |
117 | virtual void SetBackgroundMode(int mode); | |
d275c7eb | 118 | #if wxUSE_PALETTE |
a23fd0e1 | 119 | virtual void SetPalette(const wxPalette& palette); |
d275c7eb | 120 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
121 | |
122 | virtual void DestroyClippingRegion(); | |
123 | ||
72cdf4c9 VZ |
124 | virtual wxCoord GetCharHeight() const; |
125 | virtual wxCoord GetCharWidth() const; | |
126 | virtual void DoGetTextExtent(const wxString& string, | |
127 | wxCoord *x, wxCoord *y, | |
128 | wxCoord *descent = NULL, | |
129 | wxCoord *externalLeading = NULL, | |
130 | wxFont *theFont = NULL) const; | |
a23fd0e1 VZ |
131 | |
132 | virtual bool CanDrawBitmap() const; | |
133 | virtual bool CanGetTextExtent() const; | |
134 | virtual int GetDepth() const; | |
135 | virtual wxSize GetPPI() const; | |
136 | ||
137 | virtual void SetMapMode(int mode); | |
138 | virtual void SetUserScale(double x, double y); | |
139 | virtual void SetSystemScale(double x, double y); | |
140 | virtual void SetLogicalScale(double x, double y); | |
72cdf4c9 VZ |
141 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); |
142 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
a23fd0e1 VZ |
143 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); |
144 | virtual void SetLogicalFunction(int function); | |
145 | ||
146 | // implementation from now on | |
147 | // -------------------------- | |
148 | ||
149 | virtual void SetRop(WXHDC cdc); | |
a23fd0e1 VZ |
150 | virtual void SelectOldObjects(WXHDC dc); |
151 | ||
152 | wxWindow *GetWindow() const { return m_canvas; } | |
153 | void SetWindow(wxWindow *win) { m_canvas = win; } | |
154 | ||
155 | WXHDC GetHDC() const { return m_hDC; } | |
156 | void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) | |
157 | { | |
158 | m_hDC = dc; | |
159 | m_bOwnsDC = bOwnsDC; | |
160 | } | |
2bda0e17 | 161 | |
4b7f2165 VZ |
162 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } |
163 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
164 | ||
1e6feb95 VZ |
165 | // update the internal clip box variables |
166 | void UpdateClipBox(); | |
167 | ||
0cbff120 JS |
168 | #if wxUSE_DC_CACHEING |
169 | static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h); | |
170 | static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC); | |
171 | ||
172 | static void AddToBitmapCache(wxDCCacheEntry* entry); | |
173 | static void AddToDCCache(wxDCCacheEntry* entry); | |
174 | static void ClearCache(); | |
175 | #endif | |
176 | ||
a23fd0e1 | 177 | protected: |
72cdf4c9 | 178 | virtual void DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
a23fd0e1 VZ |
179 | int style = wxFLOOD_SURFACE); |
180 | ||
72cdf4c9 | 181 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; |
a23fd0e1 | 182 | |
72cdf4c9 VZ |
183 | virtual void DoDrawPoint(wxCoord x, wxCoord y); |
184 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
a23fd0e1 | 185 | |
72cdf4c9 VZ |
186 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
187 | wxCoord x2, wxCoord y2, | |
188 | wxCoord xc, wxCoord yc); | |
cd9da200 VZ |
189 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
190 | wxCoord width, wxCoord height); | |
72cdf4c9 | 191 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
192 | double sa, double ea); |
193 | ||
72cdf4c9 VZ |
194 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
195 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
196 | wxCoord width, wxCoord height, | |
a23fd0e1 | 197 | double radius); |
72cdf4c9 | 198 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
a23fd0e1 | 199 | |
72cdf4c9 | 200 | virtual void DoCrossHair(wxCoord x, wxCoord y); |
a23fd0e1 | 201 | |
72cdf4c9 VZ |
202 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); |
203 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
a23fd0e1 VZ |
204 | bool useMask = FALSE); |
205 | ||
72cdf4c9 | 206 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); |
95724b1a VZ |
207 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, |
208 | double angle); | |
a23fd0e1 | 209 | |
72cdf4c9 VZ |
210 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
211 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
0cbff120 | 212 | int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); |
a23fd0e1 VZ |
213 | |
214 | // this is gnarly - we can't even call this function DoSetClippingRegion() | |
215 | // because of virtual function hiding | |
216 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
72cdf4c9 VZ |
217 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
218 | wxCoord width, wxCoord height); | |
219 | virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, | |
220 | wxCoord *width, wxCoord *height) | |
a23fd0e1 VZ |
221 | { |
222 | GetClippingBox(x, y, width, height); | |
223 | } | |
224 | ||
225 | virtual void DoGetSize(int *width, int *height) const; | |
226 | virtual void DoGetSizeMM(int* width, int* height) const; | |
227 | ||
228 | virtual void DoDrawLines(int n, wxPoint points[], | |
72cdf4c9 | 229 | wxCoord xoffset, wxCoord yoffset); |
a23fd0e1 | 230 | virtual void DoDrawPolygon(int n, wxPoint points[], |
72cdf4c9 | 231 | wxCoord xoffset, wxCoord yoffset, |
a23fd0e1 | 232 | int fillStyle = wxODDEVEN_RULE); |
6a6c0a8b | 233 | |
a23fd0e1 | 234 | |
4314ec48 VZ |
235 | // common part of DoDrawText() and DoDrawRotatedText() |
236 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
237 | ||
a23fd0e1 VZ |
238 | // MSW-specific member variables |
239 | int m_windowExtX; | |
240 | int m_windowExtY; | |
241 | ||
242 | // the window associated with this DC (may be NULL) | |
243 | wxWindow *m_canvas; | |
244 | ||
245 | wxBitmap m_selectedBitmap; | |
246 | ||
247 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
248 | bool m_bOwnsDC:1; | |
249 | ||
b5badcb5 | 250 | // our HDC |
a23fd0e1 | 251 | WXHDC m_hDC; |
a23fd0e1 VZ |
252 | |
253 | // Store all old GDI objects when do a SelectObject, so we can select them | |
254 | // back in (this unselecting user's objects) so we can safely delete the | |
255 | // DC. | |
256 | WXHBITMAP m_oldBitmap; | |
257 | WXHPEN m_oldPen; | |
258 | WXHBRUSH m_oldBrush; | |
259 | WXHFONT m_oldFont; | |
d275c7eb VZ |
260 | |
261 | #if wxUSE_PALETTE | |
a23fd0e1 | 262 | WXHPALETTE m_oldPalette; |
d275c7eb | 263 | #endif // wxUSE_PALETTE |
7561aacd | 264 | |
0cbff120 JS |
265 | #if wxUSE_DC_CACHEING |
266 | static wxList sm_bitmapCache; | |
267 | static wxList sm_dcCache; | |
268 | #endif | |
269 | ||
7561aacd VZ |
270 | DECLARE_DYNAMIC_CLASS(wxDC) |
271 | }; | |
272 | ||
273 | // ---------------------------------------------------------------------------- | |
274 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWindows | |
275 | // only/mainly) | |
276 | // ---------------------------------------------------------------------------- | |
277 | ||
278 | class WXDLLEXPORT wxDCTemp : public wxDC | |
279 | { | |
280 | public: | |
281 | wxDCTemp(WXHDC hdc) { SetHDC(hdc); } | |
282 | virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); } | |
2bda0e17 KB |
283 | }; |
284 | ||
2bda0e17 | 285 | #endif |
bbcdf8bc | 286 | // _WX_DC_H_ |