]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ad0ac642 | 2 | // Name: wx/msw/dc.h |
2bda0e17 KB |
3 | // Purpose: wxDC class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
bbcdf8bc | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
2bda0e17 KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
7d09b97f VZ |
11 | #ifndef _WX_MSW_DC_H_ |
12 | #define _WX_MSW_DC_H_ | |
2bda0e17 | 13 | |
2662e49e | 14 | #include "wx/defs.h" |
888dde65 | 15 | #include "wx/dc.h" |
2662e49e | 16 | |
e6f1ad22 HH |
17 | // --------------------------------------------------------------------------- |
18 | // macros | |
19 | // --------------------------------------------------------------------------- | |
20 | ||
0cbff120 JS |
21 | #if wxUSE_DC_CACHEING |
22 | /* | |
23 | * Cached blitting, maintaining a cache | |
24 | * of bitmaps required for transparent blitting | |
25 | * instead of constant creation/deletion | |
26 | */ | |
27 | ||
28 | class wxDCCacheEntry: public wxObject | |
29 | { | |
30 | public: | |
31 | wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth); | |
32 | wxDCCacheEntry(WXHDC hDC, int depth); | |
d3c7fc99 | 33 | virtual ~wxDCCacheEntry(); |
0cbff120 JS |
34 | |
35 | WXHBITMAP m_bitmap; | |
36 | WXHDC m_dc; | |
37 | int m_width; | |
38 | int m_height; | |
39 | int m_depth; | |
40 | }; | |
41 | #endif | |
42 | ||
7d09b97f VZ |
43 | // this is an ABC: use one of the derived classes to create a DC associated |
44 | // with a window, screen, printer and so on | |
53a2db12 | 45 | class WXDLLIMPEXP_CORE wxMSWDCImpl: public wxDCImpl |
2bda0e17 | 46 | { |
2bda0e17 | 47 | public: |
888dde65 RR |
48 | wxMSWDCImpl(wxDC *owner, WXHDC hDC); |
49 | virtual ~wxMSWDCImpl(); | |
a23fd0e1 VZ |
50 | |
51 | // implement base class pure virtuals | |
52 | // ---------------------------------- | |
53 | ||
54 | virtual void Clear(); | |
55 | ||
56 | virtual bool StartDoc(const wxString& message); | |
57 | virtual void EndDoc(); | |
58 | ||
59 | virtual void StartPage(); | |
60 | virtual void EndPage(); | |
61 | ||
62 | virtual void SetFont(const wxFont& font); | |
63 | virtual void SetPen(const wxPen& pen); | |
64 | virtual void SetBrush(const wxBrush& brush); | |
65 | virtual void SetBackground(const wxBrush& brush); | |
66 | virtual void SetBackgroundMode(int mode); | |
d275c7eb | 67 | #if wxUSE_PALETTE |
a23fd0e1 | 68 | virtual void SetPalette(const wxPalette& palette); |
d275c7eb | 69 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
70 | |
71 | virtual void DestroyClippingRegion(); | |
72 | ||
72cdf4c9 VZ |
73 | virtual wxCoord GetCharHeight() const; |
74 | virtual wxCoord GetCharWidth() const; | |
a23fd0e1 VZ |
75 | |
76 | virtual bool CanDrawBitmap() const; | |
77 | virtual bool CanGetTextExtent() const; | |
78 | virtual int GetDepth() const; | |
79 | virtual wxSize GetPPI() const; | |
80 | ||
621b83d9 | 81 | |
89efaf2b | 82 | virtual void SetMapMode(wxMappingMode mode); |
a23fd0e1 | 83 | virtual void SetUserScale(double x, double y); |
a23fd0e1 | 84 | virtual void SetLogicalScale(double x, double y); |
72cdf4c9 VZ |
85 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); |
86 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
a23fd0e1 | 87 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); |
f0875501 | 88 | |
e71508e1 VZ |
89 | #if wxUSE_DC_TRANSFORM_MATRIX |
90 | virtual bool CanUseTransformMatrix() const; | |
91 | virtual bool SetTransformMatrix(const wxAffineMatrix2D& matrix); | |
92 | virtual wxAffineMatrix2D GetTransformMatrix() const; | |
93 | virtual void ResetTransformMatrix(); | |
94 | #endif // wxUSE_DC_TRANSFORM_MATRIX | |
95 | ||
89efaf2b | 96 | virtual void SetLogicalFunction(wxRasterOperationMode function); |
a23fd0e1 VZ |
97 | |
98 | // implementation from now on | |
99 | // -------------------------- | |
100 | ||
101 | virtual void SetRop(WXHDC cdc); | |
a23fd0e1 VZ |
102 | virtual void SelectOldObjects(WXHDC dc); |
103 | ||
b95edd47 VZ |
104 | void SetWindow(wxWindow *win) |
105 | { | |
888dde65 | 106 | m_window = win; |
b95edd47 | 107 | |
574c939e KB |
108 | #if wxUSE_PALETTE |
109 | // if we have palettes use the correct one for this window | |
110 | InitializePalette(); | |
b95edd47 VZ |
111 | #endif // wxUSE_PALETTE |
112 | } | |
a23fd0e1 VZ |
113 | |
114 | WXHDC GetHDC() const { return m_hDC; } | |
d71cc120 | 115 | void SetHDC(WXHDC dc, bool bOwnsDC = false) |
a23fd0e1 VZ |
116 | { |
117 | m_hDC = dc; | |
118 | m_bOwnsDC = bOwnsDC; | |
2e76da54 VZ |
119 | |
120 | // we might have a pre existing clipping region, make sure that we | |
121 | // return it if asked -- but avoid calling ::GetClipBox() right now as | |
122 | // it could be unnecessary wasteful | |
123 | m_clipping = true; | |
124 | m_clipX1 = | |
125 | m_clipX2 = 0; | |
a23fd0e1 | 126 | } |
2bda0e17 | 127 | |
6d4b1e27 RD |
128 | void* GetHandle() const { return (void*)GetHDC(); } |
129 | ||
4b7f2165 VZ |
130 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } |
131 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
132 | ||
1e6feb95 VZ |
133 | // update the internal clip box variables |
134 | void UpdateClipBox(); | |
135 | ||
0cbff120 JS |
136 | #if wxUSE_DC_CACHEING |
137 | static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h); | |
138 | static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC); | |
139 | ||
140 | static void AddToBitmapCache(wxDCCacheEntry* entry); | |
141 | static void AddToDCCache(wxDCCacheEntry* entry); | |
142 | static void ClearCache(); | |
143 | #endif | |
144 | ||
6ae7410f VZ |
145 | // RTL related functions |
146 | // --------------------- | |
147 | ||
148 | // get or change the layout direction (LTR or RTL) for this dc, | |
149 | // wxLayout_Default is returned if layout direction is not supported | |
150 | virtual wxLayoutDirection GetLayoutDirection() const; | |
151 | virtual void SetLayoutDirection(wxLayoutDirection dir); | |
152 | ||
a23fd0e1 | 153 | protected: |
7d09b97f VZ |
154 | void Init() |
155 | { | |
7d09b97f VZ |
156 | m_bOwnsDC = false; |
157 | m_hDC = NULL; | |
158 | ||
159 | m_oldBitmap = NULL; | |
160 | m_oldPen = NULL; | |
161 | m_oldBrush = NULL; | |
162 | m_oldFont = NULL; | |
163 | ||
164 | #if wxUSE_PALETTE | |
165 | m_oldPalette = NULL; | |
166 | #endif // wxUSE_PALETTE | |
167 | } | |
168 | ||
169 | // create an uninitialized DC: this should be only used by the derived | |
170 | // classes | |
888dde65 | 171 | wxMSWDCImpl( wxDC *owner ) : wxDCImpl( owner ) { Init(); } |
7d09b97f | 172 | |
04ab8b6d RR |
173 | void RealizeScaleAndOrigin(); |
174 | ||
512cfcc3 | 175 | public: |
e29bf4b0 VZ |
176 | virtual void DoGetFontMetrics(int *height, |
177 | int *ascent, | |
178 | int *descent, | |
179 | int *internalLeading, | |
180 | int *externalLeading, | |
181 | int *averageWidth) const; | |
6f02a879 VZ |
182 | virtual void DoGetTextExtent(const wxString& string, |
183 | wxCoord *x, wxCoord *y, | |
184 | wxCoord *descent = NULL, | |
185 | wxCoord *externalLeading = NULL, | |
c94f845b | 186 | const wxFont *theFont = NULL) const; |
6f02a879 VZ |
187 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; |
188 | ||
387ebd3e | 189 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
89efaf2b | 190 | wxFloodFillStyle style = wxFLOOD_SURFACE); |
a23fd0e1 | 191 | |
213ad8e7 VZ |
192 | virtual void DoGradientFillLinear(const wxRect& rect, |
193 | const wxColour& initialColour, | |
194 | const wxColour& destColour, | |
195 | wxDirection nDirection = wxEAST); | |
196 | ||
72cdf4c9 | 197 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; |
a23fd0e1 | 198 | |
72cdf4c9 VZ |
199 | virtual void DoDrawPoint(wxCoord x, wxCoord y); |
200 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
a23fd0e1 | 201 | |
72cdf4c9 VZ |
202 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
203 | wxCoord x2, wxCoord y2, | |
204 | wxCoord xc, wxCoord yc); | |
cd9da200 VZ |
205 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
206 | wxCoord width, wxCoord height); | |
72cdf4c9 | 207 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
208 | double sa, double ea); |
209 | ||
72cdf4c9 VZ |
210 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
211 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
212 | wxCoord width, wxCoord height, | |
a23fd0e1 | 213 | double radius); |
72cdf4c9 | 214 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
a23fd0e1 | 215 | |
3e9db38e | 216 | #if wxUSE_SPLINES && !defined(__WXWINCE__) |
b0d7707b | 217 | virtual void DoDrawSpline(const wxPointList *points); |
ad0ac642 WS |
218 | #endif |
219 | ||
72cdf4c9 | 220 | virtual void DoCrossHair(wxCoord x, wxCoord y); |
a23fd0e1 | 221 | |
72cdf4c9 VZ |
222 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); |
223 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
d71cc120 | 224 | bool useMask = false); |
a23fd0e1 | 225 | |
72cdf4c9 | 226 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); |
95724b1a VZ |
227 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, |
228 | double angle); | |
a23fd0e1 | 229 | |
72cdf4c9 VZ |
230 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
231 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
03647350 | 232 | wxRasterOperationMode rop = wxCOPY, bool useMask = false, |
89efaf2b | 233 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); |
a23fd0e1 | 234 | |
e3b81044 VZ |
235 | virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest, |
236 | wxCoord dstWidth, wxCoord dstHeight, | |
237 | wxDC *source, | |
238 | wxCoord xsrc, wxCoord ysrc, | |
239 | wxCoord srcWidth, wxCoord srcHeight, | |
89efaf2b | 240 | wxRasterOperationMode rop = wxCOPY, bool useMask = false, |
e3b81044 VZ |
241 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); |
242 | ||
72cdf4c9 VZ |
243 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
244 | wxCoord width, wxCoord height); | |
fdaad94e | 245 | virtual void DoSetDeviceClippingRegion(const wxRegion& region); |
2e76da54 VZ |
246 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
247 | wxCoord *w, wxCoord *h) const; | |
a23fd0e1 | 248 | |
a23fd0e1 VZ |
249 | virtual void DoGetSizeMM(int* width, int* height) const; |
250 | ||
4787c92d | 251 | virtual void DoDrawLines(int n, const wxPoint points[], |
72cdf4c9 | 252 | wxCoord xoffset, wxCoord yoffset); |
4787c92d | 253 | virtual void DoDrawPolygon(int n, const wxPoint points[], |
72cdf4c9 | 254 | wxCoord xoffset, wxCoord yoffset, |
89efaf2b | 255 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE); |
4787c92d | 256 | virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], |
6e76b35d | 257 | wxCoord xoffset, wxCoord yoffset, |
89efaf2b | 258 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE); |
f0875501 VZ |
259 | virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const |
260 | { | |
261 | return subrect == NULL ? GetSelectedBitmap() | |
262 | : GetSelectedBitmap().GetSubBitmap(*subrect); | |
263 | } | |
6a6c0a8b | 264 | |
a23fd0e1 | 265 | |
574c939e KB |
266 | #if wxUSE_PALETTE |
267 | // MSW specific, select a logical palette into the HDC | |
268 | // (tell windows to translate pixel from other palettes to our custom one | |
269 | // and vice versa) | |
270 | // Realize tells it to also reset the system palette to this one. | |
d71cc120 | 271 | void DoSelectPalette(bool realize = false); |
b95edd47 | 272 | |
574c939e KB |
273 | // Find out what palette our parent window has, then select it into the dc |
274 | void InitializePalette(); | |
b95edd47 VZ |
275 | #endif // wxUSE_PALETTE |
276 | ||
512cfcc3 | 277 | protected: |
4314ec48 VZ |
278 | // common part of DoDrawText() and DoDrawRotatedText() |
279 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
280 | ||
fdaad94e | 281 | // common part of DoSetClippingRegion() and DoSetDeviceClippingRegion() |
5230934a VZ |
282 | void SetClippingHrgn(WXHRGN hrgn); |
283 | ||
7d09b97f VZ |
284 | // implementation of DoGetSize() for wxScreen/PrinterDC: this simply |
285 | // returns the size of the entire device this DC is associated with | |
286 | // | |
287 | // notice that we intentionally put it in a separate function instead of | |
288 | // DoGetSize() itself because we want it to remain pure virtual both | |
289 | // because each derived class should take care to define it as needed (this | |
290 | // implementation is not at all always appropriate) and because we want | |
291 | // wxDC to be an ABC to prevent it from being created directly | |
292 | void GetDeviceSize(int *width, int *height) const; | |
293 | ||
294 | ||
a23fd0e1 | 295 | // MSW-specific member variables |
1e2081a1 | 296 | // ----------------------------- |
a23fd0e1 VZ |
297 | |
298 | // the window associated with this DC (may be NULL) | |
299 | wxWindow *m_canvas; | |
300 | ||
301 | wxBitmap m_selectedBitmap; | |
302 | ||
303 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
304 | bool m_bOwnsDC:1; | |
305 | ||
b5badcb5 | 306 | // our HDC |
a23fd0e1 | 307 | WXHDC m_hDC; |
a23fd0e1 VZ |
308 | |
309 | // Store all old GDI objects when do a SelectObject, so we can select them | |
310 | // back in (this unselecting user's objects) so we can safely delete the | |
311 | // DC. | |
312 | WXHBITMAP m_oldBitmap; | |
313 | WXHPEN m_oldPen; | |
314 | WXHBRUSH m_oldBrush; | |
315 | WXHFONT m_oldFont; | |
d275c7eb VZ |
316 | |
317 | #if wxUSE_PALETTE | |
a23fd0e1 | 318 | WXHPALETTE m_oldPalette; |
d275c7eb | 319 | #endif // wxUSE_PALETTE |
7561aacd | 320 | |
0cbff120 | 321 | #if wxUSE_DC_CACHEING |
888dde65 RR |
322 | static wxObjectList sm_bitmapCache; |
323 | static wxObjectList sm_dcCache; | |
0cbff120 JS |
324 | #endif |
325 | ||
888dde65 | 326 | DECLARE_CLASS(wxMSWDCImpl) |
c0c133e1 | 327 | wxDECLARE_NO_COPY_CLASS(wxMSWDCImpl); |
7561aacd VZ |
328 | }; |
329 | ||
330 | // ---------------------------------------------------------------------------- | |
77ffb593 | 331 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets |
7561aacd VZ |
332 | // only/mainly) |
333 | // ---------------------------------------------------------------------------- | |
334 | ||
53a2db12 | 335 | class WXDLLIMPEXP_CORE wxDCTempImpl : public wxMSWDCImpl |
7561aacd VZ |
336 | { |
337 | public: | |
e0e6ac8a VZ |
338 | // construct a temporary DC with the specified HDC and size (it should be |
339 | // specified whenever we know it for this HDC) | |
888dde65 RR |
340 | wxDCTempImpl(wxDC *owner, WXHDC hdc, const wxSize& size ) |
341 | : wxMSWDCImpl( owner, hdc ), | |
e0e6ac8a | 342 | m_size(size) |
7d09b97f VZ |
343 | { |
344 | } | |
345 | ||
888dde65 | 346 | virtual ~wxDCTempImpl() |
7d09b97f VZ |
347 | { |
348 | // prevent base class dtor from freeing it | |
349 | SetHDC((WXHDC)NULL); | |
350 | } | |
351 | ||
352 | virtual void DoGetSize(int *w, int *h) const | |
353 | { | |
e0e6ac8a | 354 | wxASSERT_MSG( m_size.IsFullySpecified(), |
9a83f860 | 355 | wxT("size of this DC hadn't been set and is unknown") ); |
7d09b97f VZ |
356 | |
357 | if ( w ) | |
e0e6ac8a | 358 | *w = m_size.x; |
7d09b97f | 359 | if ( h ) |
e0e6ac8a | 360 | *h = m_size.y; |
7d09b97f | 361 | } |
fc7a2a60 VZ |
362 | |
363 | private: | |
e0e6ac8a VZ |
364 | // size of this DC must be explicitly set by SetSize() as we have no way to |
365 | // find it ourselves | |
366 | const wxSize m_size; | |
367 | ||
c0c133e1 | 368 | wxDECLARE_NO_COPY_CLASS(wxDCTempImpl); |
2bda0e17 KB |
369 | }; |
370 | ||
53a2db12 | 371 | class WXDLLIMPEXP_CORE wxDCTemp : public wxDC |
888dde65 RR |
372 | { |
373 | public: | |
f0875501 VZ |
374 | wxDCTemp(WXHDC hdc, const wxSize& size = wxDefaultSize) |
375 | : wxDC(new wxDCTempImpl(this, hdc, size)) | |
888dde65 | 376 | { |
888dde65 | 377 | } |
888dde65 RR |
378 | }; |
379 | ||
7d09b97f VZ |
380 | #endif // _WX_MSW_DC_H_ |
381 |