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