]>
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 | |
7 | // RCS-ID: $Id$ | |
bbcdf8bc | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
7d09b97f VZ |
12 | #ifndef _WX_MSW_DC_H_ |
13 | #define _WX_MSW_DC_H_ | |
2bda0e17 | 14 | |
2662e49e | 15 | #include "wx/defs.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 | |
a23fd0e1 | 45 | class WXDLLEXPORT wxDC : public wxDCBase |
2bda0e17 | 46 | { |
2bda0e17 | 47 | public: |
7d09b97f | 48 | wxDC(WXHDC hDC) { Init(); m_hDC = hDC; } |
d3c7fc99 | 49 | virtual ~wxDC(); |
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 | ||
81 | virtual void SetMapMode(int mode); | |
82 | virtual void SetUserScale(double x, double y); | |
83 | virtual void SetSystemScale(double x, double y); | |
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 VZ |
87 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); |
88 | virtual void SetLogicalFunction(int function); | |
89 | ||
90 | // implementation from now on | |
91 | // -------------------------- | |
92 | ||
93 | virtual void SetRop(WXHDC cdc); | |
a23fd0e1 VZ |
94 | virtual void SelectOldObjects(WXHDC dc); |
95 | ||
96 | wxWindow *GetWindow() const { return m_canvas; } | |
b95edd47 VZ |
97 | void SetWindow(wxWindow *win) |
98 | { | |
574c939e | 99 | m_canvas = win; |
b95edd47 | 100 | |
574c939e KB |
101 | #if wxUSE_PALETTE |
102 | // if we have palettes use the correct one for this window | |
103 | InitializePalette(); | |
b95edd47 VZ |
104 | #endif // wxUSE_PALETTE |
105 | } | |
a23fd0e1 VZ |
106 | |
107 | WXHDC GetHDC() const { return m_hDC; } | |
d71cc120 | 108 | void SetHDC(WXHDC dc, bool bOwnsDC = false) |
a23fd0e1 VZ |
109 | { |
110 | m_hDC = dc; | |
111 | m_bOwnsDC = bOwnsDC; | |
2e76da54 VZ |
112 | |
113 | // we might have a pre existing clipping region, make sure that we | |
114 | // return it if asked -- but avoid calling ::GetClipBox() right now as | |
115 | // it could be unnecessary wasteful | |
116 | m_clipping = true; | |
117 | m_clipX1 = | |
118 | m_clipX2 = 0; | |
a23fd0e1 | 119 | } |
2bda0e17 | 120 | |
4b7f2165 VZ |
121 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } |
122 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
123 | ||
1e6feb95 VZ |
124 | // update the internal clip box variables |
125 | void UpdateClipBox(); | |
126 | ||
0cbff120 JS |
127 | #if wxUSE_DC_CACHEING |
128 | static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h); | |
129 | static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC); | |
130 | ||
131 | static void AddToBitmapCache(wxDCCacheEntry* entry); | |
132 | static void AddToDCCache(wxDCCacheEntry* entry); | |
133 | static void ClearCache(); | |
134 | #endif | |
135 | ||
6ae7410f VZ |
136 | // RTL related functions |
137 | // --------------------- | |
138 | ||
139 | // get or change the layout direction (LTR or RTL) for this dc, | |
140 | // wxLayout_Default is returned if layout direction is not supported | |
141 | virtual wxLayoutDirection GetLayoutDirection() const; | |
142 | virtual void SetLayoutDirection(wxLayoutDirection dir); | |
143 | ||
a23fd0e1 | 144 | protected: |
7d09b97f VZ |
145 | void Init() |
146 | { | |
147 | m_canvas = NULL; | |
148 | m_bOwnsDC = false; | |
149 | m_hDC = NULL; | |
150 | ||
151 | m_oldBitmap = NULL; | |
152 | m_oldPen = NULL; | |
153 | m_oldBrush = NULL; | |
154 | m_oldFont = NULL; | |
155 | ||
156 | #if wxUSE_PALETTE | |
157 | m_oldPalette = NULL; | |
158 | #endif // wxUSE_PALETTE | |
159 | } | |
160 | ||
161 | // create an uninitialized DC: this should be only used by the derived | |
162 | // classes | |
163 | wxDC() { Init(); } | |
164 | ||
6f02a879 VZ |
165 | virtual void DoGetTextExtent(const wxString& string, |
166 | wxCoord *x, wxCoord *y, | |
167 | wxCoord *descent = NULL, | |
168 | wxCoord *externalLeading = NULL, | |
169 | wxFont *theFont = NULL) const; | |
170 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; | |
171 | ||
387ebd3e | 172 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
a23fd0e1 VZ |
173 | int style = wxFLOOD_SURFACE); |
174 | ||
213ad8e7 VZ |
175 | virtual void DoGradientFillLinear(const wxRect& rect, |
176 | const wxColour& initialColour, | |
177 | const wxColour& destColour, | |
178 | wxDirection nDirection = wxEAST); | |
179 | ||
72cdf4c9 | 180 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; |
a23fd0e1 | 181 | |
72cdf4c9 VZ |
182 | virtual void DoDrawPoint(wxCoord x, wxCoord y); |
183 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
a23fd0e1 | 184 | |
72cdf4c9 VZ |
185 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
186 | wxCoord x2, wxCoord y2, | |
187 | wxCoord xc, wxCoord yc); | |
cd9da200 VZ |
188 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
189 | wxCoord width, wxCoord height); | |
72cdf4c9 | 190 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
191 | double sa, double ea); |
192 | ||
72cdf4c9 VZ |
193 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
194 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
195 | wxCoord width, wxCoord height, | |
a23fd0e1 | 196 | double radius); |
72cdf4c9 | 197 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
a23fd0e1 | 198 | |
ad0ac642 WS |
199 | #if wxUSE_SPLINES |
200 | virtual void DoDrawSpline(wxList *points); | |
201 | #endif | |
202 | ||
72cdf4c9 | 203 | virtual void DoCrossHair(wxCoord x, wxCoord y); |
a23fd0e1 | 204 | |
72cdf4c9 VZ |
205 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); |
206 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
d71cc120 | 207 | bool useMask = false); |
a23fd0e1 | 208 | |
72cdf4c9 | 209 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); |
95724b1a VZ |
210 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, |
211 | double angle); | |
a23fd0e1 | 212 | |
72cdf4c9 VZ |
213 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
214 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
d71cc120 | 215 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); |
a23fd0e1 | 216 | |
e3b81044 VZ |
217 | virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest, |
218 | wxCoord dstWidth, wxCoord dstHeight, | |
219 | wxDC *source, | |
220 | wxCoord xsrc, wxCoord ysrc, | |
221 | wxCoord srcWidth, wxCoord srcHeight, | |
222 | int rop = wxCOPY, bool useMask = false, | |
223 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); | |
224 | ||
a23fd0e1 VZ |
225 | // this is gnarly - we can't even call this function DoSetClippingRegion() |
226 | // because of virtual function hiding | |
227 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
72cdf4c9 VZ |
228 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
229 | wxCoord width, wxCoord height); | |
2e76da54 VZ |
230 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
231 | wxCoord *w, wxCoord *h) const; | |
a23fd0e1 | 232 | |
a23fd0e1 VZ |
233 | virtual void DoGetSizeMM(int* width, int* height) const; |
234 | ||
235 | virtual void DoDrawLines(int n, wxPoint points[], | |
72cdf4c9 | 236 | wxCoord xoffset, wxCoord yoffset); |
a23fd0e1 | 237 | virtual void DoDrawPolygon(int n, wxPoint points[], |
72cdf4c9 | 238 | wxCoord xoffset, wxCoord yoffset, |
a23fd0e1 | 239 | int fillStyle = wxODDEVEN_RULE); |
793db755 | 240 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], |
6e76b35d VZ |
241 | wxCoord xoffset, wxCoord yoffset, |
242 | int fillStyle = wxODDEVEN_RULE); | |
d888a332 SC |
243 | virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const |
244 | { return subrect == NULL ? GetSelectedBitmap() : GetSelectedBitmap().GetSubBitmap(*subrect); } | |
6a6c0a8b | 245 | |
a23fd0e1 | 246 | |
574c939e KB |
247 | #if wxUSE_PALETTE |
248 | // MSW specific, select a logical palette into the HDC | |
249 | // (tell windows to translate pixel from other palettes to our custom one | |
250 | // and vice versa) | |
251 | // Realize tells it to also reset the system palette to this one. | |
d71cc120 | 252 | void DoSelectPalette(bool realize = false); |
b95edd47 | 253 | |
574c939e KB |
254 | // Find out what palette our parent window has, then select it into the dc |
255 | void InitializePalette(); | |
b95edd47 VZ |
256 | #endif // wxUSE_PALETTE |
257 | ||
4314ec48 VZ |
258 | // common part of DoDrawText() and DoDrawRotatedText() |
259 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
260 | ||
5230934a VZ |
261 | // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion() |
262 | void SetClippingHrgn(WXHRGN hrgn); | |
263 | ||
7d09b97f VZ |
264 | // implementation of DoGetSize() for wxScreen/PrinterDC: this simply |
265 | // returns the size of the entire device this DC is associated with | |
266 | // | |
267 | // notice that we intentionally put it in a separate function instead of | |
268 | // DoGetSize() itself because we want it to remain pure virtual both | |
269 | // because each derived class should take care to define it as needed (this | |
270 | // implementation is not at all always appropriate) and because we want | |
271 | // wxDC to be an ABC to prevent it from being created directly | |
272 | void GetDeviceSize(int *width, int *height) const; | |
273 | ||
274 | ||
a23fd0e1 | 275 | // MSW-specific member variables |
1e2081a1 | 276 | // ----------------------------- |
a23fd0e1 VZ |
277 | |
278 | // the window associated with this DC (may be NULL) | |
279 | wxWindow *m_canvas; | |
280 | ||
281 | wxBitmap m_selectedBitmap; | |
282 | ||
283 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
284 | bool m_bOwnsDC:1; | |
285 | ||
b5badcb5 | 286 | // our HDC |
a23fd0e1 | 287 | WXHDC m_hDC; |
a23fd0e1 VZ |
288 | |
289 | // Store all old GDI objects when do a SelectObject, so we can select them | |
290 | // back in (this unselecting user's objects) so we can safely delete the | |
291 | // DC. | |
292 | WXHBITMAP m_oldBitmap; | |
293 | WXHPEN m_oldPen; | |
294 | WXHBRUSH m_oldBrush; | |
295 | WXHFONT m_oldFont; | |
d275c7eb VZ |
296 | |
297 | #if wxUSE_PALETTE | |
a23fd0e1 | 298 | WXHPALETTE m_oldPalette; |
d275c7eb | 299 | #endif // wxUSE_PALETTE |
7561aacd | 300 | |
0cbff120 JS |
301 | #if wxUSE_DC_CACHEING |
302 | static wxList sm_bitmapCache; | |
303 | static wxList sm_dcCache; | |
304 | #endif | |
305 | ||
7561aacd | 306 | DECLARE_DYNAMIC_CLASS(wxDC) |
22f3361e | 307 | DECLARE_NO_COPY_CLASS(wxDC) |
7561aacd VZ |
308 | }; |
309 | ||
310 | // ---------------------------------------------------------------------------- | |
77ffb593 | 311 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets |
7561aacd VZ |
312 | // only/mainly) |
313 | // ---------------------------------------------------------------------------- | |
314 | ||
315 | class WXDLLEXPORT wxDCTemp : public wxDC | |
316 | { | |
317 | public: | |
e0e6ac8a VZ |
318 | // construct a temporary DC with the specified HDC and size (it should be |
319 | // specified whenever we know it for this HDC) | |
320 | wxDCTemp(WXHDC hdc, const wxSize& size = wxDefaultSize) | |
321 | : wxDC(hdc), | |
322 | m_size(size) | |
7d09b97f VZ |
323 | { |
324 | } | |
325 | ||
326 | virtual ~wxDCTemp() | |
327 | { | |
328 | // prevent base class dtor from freeing it | |
329 | SetHDC((WXHDC)NULL); | |
330 | } | |
331 | ||
6f02a879 | 332 | protected: |
7d09b97f VZ |
333 | virtual void DoGetSize(int *w, int *h) const |
334 | { | |
e0e6ac8a VZ |
335 | wxASSERT_MSG( m_size.IsFullySpecified(), |
336 | _T("size of this DC hadn't been set and is unknown") ); | |
7d09b97f VZ |
337 | |
338 | if ( w ) | |
e0e6ac8a | 339 | *w = m_size.x; |
7d09b97f | 340 | if ( h ) |
e0e6ac8a | 341 | *h = m_size.y; |
7d09b97f | 342 | } |
fc7a2a60 VZ |
343 | |
344 | private: | |
e0e6ac8a VZ |
345 | // size of this DC must be explicitly set by SetSize() as we have no way to |
346 | // find it ourselves | |
347 | const wxSize m_size; | |
348 | ||
fc7a2a60 | 349 | DECLARE_NO_COPY_CLASS(wxDCTemp) |
2bda0e17 KB |
350 | }; |
351 | ||
7d09b97f VZ |
352 | #endif // _WX_MSW_DC_H_ |
353 |