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