]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dc.h
miscellaneous wxFont enhancements (patch 1496606):
[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 ~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 ~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 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);
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 virtual void SetLogicalFunction(int function);
89
90 // implementation from now on
91 // --------------------------
92
93 virtual void SetRop(WXHDC cdc);
94 virtual void SelectOldObjects(WXHDC dc);
95
96 wxWindow *GetWindow() const { return m_canvas; }
97 void SetWindow(wxWindow *win)
98 {
99 m_canvas = win;
100
101 #if wxUSE_PALETTE
102 // if we have palettes use the correct one for this window
103 InitializePalette();
104 #endif // wxUSE_PALETTE
105 }
106
107 WXHDC GetHDC() const { return m_hDC; }
108 void SetHDC(WXHDC dc, bool bOwnsDC = false)
109 {
110 m_hDC = dc;
111 m_bOwnsDC = bOwnsDC;
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;
119 }
120
121 const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; }
122 wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; }
123
124 // update the internal clip box variables
125 void UpdateClipBox();
126
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
136 protected:
137 void Init()
138 {
139 m_canvas = NULL;
140 m_bOwnsDC = false;
141 m_hDC = NULL;
142
143 m_oldBitmap = NULL;
144 m_oldPen = NULL;
145 m_oldBrush = NULL;
146 m_oldFont = NULL;
147
148 #if wxUSE_PALETTE
149 m_oldPalette = NULL;
150 #endif // wxUSE_PALETTE
151 }
152
153 // create an uninitialized DC: this should be only used by the derived
154 // classes
155 wxDC() { Init(); }
156
157 virtual void DoGetTextExtent(const wxString& string,
158 wxCoord *x, wxCoord *y,
159 wxCoord *descent = NULL,
160 wxCoord *externalLeading = NULL,
161 wxFont *theFont = NULL) const;
162 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
163
164 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
165 int style = wxFLOOD_SURFACE);
166
167 virtual void DoGradientFillLinear(const wxRect& rect,
168 const wxColour& initialColour,
169 const wxColour& destColour,
170 wxDirection nDirection = wxEAST);
171
172 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
173
174 virtual void DoDrawPoint(wxCoord x, wxCoord y);
175 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
176
177 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
178 wxCoord x2, wxCoord y2,
179 wxCoord xc, wxCoord yc);
180 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
181 wxCoord width, wxCoord height);
182 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
183 double sa, double ea);
184
185 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
186 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
187 wxCoord width, wxCoord height,
188 double radius);
189 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
190
191 #if wxUSE_SPLINES
192 virtual void DoDrawSpline(wxList *points);
193 #endif
194
195 virtual void DoCrossHair(wxCoord x, wxCoord y);
196
197 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
198 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
199 bool useMask = false);
200
201 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
202 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
203 double angle);
204
205 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
206 wxDC *source, wxCoord xsrc, wxCoord ysrc,
207 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
208
209 // this is gnarly - we can't even call this function DoSetClippingRegion()
210 // because of virtual function hiding
211 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
212 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
213 wxCoord width, wxCoord height);
214 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
215 wxCoord *w, wxCoord *h) const;
216
217 virtual void DoGetSizeMM(int* width, int* height) const;
218
219 virtual void DoDrawLines(int n, wxPoint points[],
220 wxCoord xoffset, wxCoord yoffset);
221 virtual void DoDrawPolygon(int n, wxPoint points[],
222 wxCoord xoffset, wxCoord yoffset,
223 int fillStyle = wxODDEVEN_RULE);
224 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
225 wxCoord xoffset, wxCoord yoffset,
226 int fillStyle = wxODDEVEN_RULE);
227
228
229 #if wxUSE_PALETTE
230 // MSW specific, select a logical palette into the HDC
231 // (tell windows to translate pixel from other palettes to our custom one
232 // and vice versa)
233 // Realize tells it to also reset the system palette to this one.
234 void DoSelectPalette(bool realize = false);
235
236 // Find out what palette our parent window has, then select it into the dc
237 void InitializePalette();
238 #endif // wxUSE_PALETTE
239
240 // common part of DoDrawText() and DoDrawRotatedText()
241 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
242
243 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
244 void SetClippingHrgn(WXHRGN hrgn);
245
246 // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
247 // returns the size of the entire device this DC is associated with
248 //
249 // notice that we intentionally put it in a separate function instead of
250 // DoGetSize() itself because we want it to remain pure virtual both
251 // because each derived class should take care to define it as needed (this
252 // implementation is not at all always appropriate) and because we want
253 // wxDC to be an ABC to prevent it from being created directly
254 void GetDeviceSize(int *width, int *height) const;
255
256
257 // MSW-specific member variables
258 // -----------------------------
259
260 // the window associated with this DC (may be NULL)
261 wxWindow *m_canvas;
262
263 wxBitmap m_selectedBitmap;
264
265 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
266 bool m_bOwnsDC:1;
267
268 // our HDC
269 WXHDC m_hDC;
270
271 // Store all old GDI objects when do a SelectObject, so we can select them
272 // back in (this unselecting user's objects) so we can safely delete the
273 // DC.
274 WXHBITMAP m_oldBitmap;
275 WXHPEN m_oldPen;
276 WXHBRUSH m_oldBrush;
277 WXHFONT m_oldFont;
278
279 #if wxUSE_PALETTE
280 WXHPALETTE m_oldPalette;
281 #endif // wxUSE_PALETTE
282
283 #if wxUSE_DC_CACHEING
284 static wxList sm_bitmapCache;
285 static wxList sm_dcCache;
286 #endif
287
288 DECLARE_DYNAMIC_CLASS(wxDC)
289 DECLARE_NO_COPY_CLASS(wxDC)
290 };
291
292 // ----------------------------------------------------------------------------
293 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
294 // only/mainly)
295 // ----------------------------------------------------------------------------
296
297 class WXDLLEXPORT wxDCTemp : public wxDC
298 {
299 public:
300 wxDCTemp(WXHDC hdc) : wxDC(hdc)
301 {
302 }
303
304 virtual ~wxDCTemp()
305 {
306 // prevent base class dtor from freeing it
307 SetHDC((WXHDC)NULL);
308 }
309
310 protected:
311 virtual void DoGetSize(int *w, int *h) const
312 {
313 wxFAIL_MSG( _T("no way to retrieve the size of generic DC") );
314
315 if ( w )
316 *w = 0;
317 if ( h )
318 *h = 0;
319 }
320
321 private:
322 DECLARE_NO_COPY_CLASS(wxDCTemp)
323 };
324
325 #endif // _WX_MSW_DC_H_
326