]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dc.h
Use wxGetTranslation() instead of _() in the public headers.
[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 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MSW_DC_H_
12 #define _WX_MSW_DC_H_
13
14 #include "wx/defs.h"
15 #include "wx/dc.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 WXDLLIMPEXP_CORE wxMSWDCImpl: public wxDCImpl
46 {
47 public:
48 wxMSWDCImpl(wxDC *owner, WXHDC hDC);
49 virtual ~wxMSWDCImpl();
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(wxMappingMode 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 #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
96 virtual void SetLogicalFunction(wxRasterOperationMode function);
97
98 // implementation from now on
99 // --------------------------
100
101 virtual void SetRop(WXHDC cdc);
102 virtual void SelectOldObjects(WXHDC dc);
103
104 void SetWindow(wxWindow *win)
105 {
106 m_window = win;
107
108 #if wxUSE_PALETTE
109 // if we have palettes use the correct one for this window
110 InitializePalette();
111 #endif // wxUSE_PALETTE
112 }
113
114 WXHDC GetHDC() const { return m_hDC; }
115 void SetHDC(WXHDC dc, bool bOwnsDC = false)
116 {
117 m_hDC = dc;
118 m_bOwnsDC = bOwnsDC;
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;
126 }
127
128 void* GetHandle() const { return (void*)GetHDC(); }
129
130 const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; }
131 wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; }
132
133 // update the internal clip box variables
134 void UpdateClipBox();
135
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
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
153 protected:
154 void Init()
155 {
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
171 wxMSWDCImpl( wxDC *owner ) : wxDCImpl( owner ) { Init(); }
172
173 void RealizeScaleAndOrigin();
174
175 public:
176 virtual void DoGetFontMetrics(int *height,
177 int *ascent,
178 int *descent,
179 int *internalLeading,
180 int *externalLeading,
181 int *averageWidth) const;
182 virtual void DoGetTextExtent(const wxString& string,
183 wxCoord *x, wxCoord *y,
184 wxCoord *descent = NULL,
185 wxCoord *externalLeading = NULL,
186 const wxFont *theFont = NULL) const;
187 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
188
189 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
190 wxFloodFillStyle style = wxFLOOD_SURFACE);
191
192 virtual void DoGradientFillLinear(const wxRect& rect,
193 const wxColour& initialColour,
194 const wxColour& destColour,
195 wxDirection nDirection = wxEAST);
196
197 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
198
199 virtual void DoDrawPoint(wxCoord x, wxCoord y);
200 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
201
202 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
203 wxCoord x2, wxCoord y2,
204 wxCoord xc, wxCoord yc);
205 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
206 wxCoord width, wxCoord height);
207 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
208 double sa, double ea);
209
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,
213 double radius);
214 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
215
216 #if wxUSE_SPLINES && !defined(__WXWINCE__)
217 virtual void DoDrawSpline(const wxPointList *points);
218 #endif
219
220 virtual void DoCrossHair(wxCoord x, wxCoord y);
221
222 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
223 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
224 bool useMask = false);
225
226 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
227 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
228 double angle);
229
230 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
231 wxDC *source, wxCoord xsrc, wxCoord ysrc,
232 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
233 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
234
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,
240 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
241 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
242
243 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
244 wxCoord width, wxCoord height);
245 virtual void DoSetDeviceClippingRegion(const wxRegion& region);
246 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
247 wxCoord *w, wxCoord *h) const;
248
249 virtual void DoGetSizeMM(int* width, int* height) const;
250
251 virtual void DoDrawLines(int n, const wxPoint points[],
252 wxCoord xoffset, wxCoord yoffset);
253 virtual void DoDrawPolygon(int n, const wxPoint points[],
254 wxCoord xoffset, wxCoord yoffset,
255 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
256 virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
257 wxCoord xoffset, wxCoord yoffset,
258 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
259 virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const
260 {
261 return subrect == NULL ? GetSelectedBitmap()
262 : GetSelectedBitmap().GetSubBitmap(*subrect);
263 }
264
265
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.
271 void DoSelectPalette(bool realize = false);
272
273 // Find out what palette our parent window has, then select it into the dc
274 void InitializePalette();
275 #endif // wxUSE_PALETTE
276
277 protected:
278 // common part of DoDrawText() and DoDrawRotatedText()
279 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
280
281 // common part of DoSetClippingRegion() and DoSetDeviceClippingRegion()
282 void SetClippingHrgn(WXHRGN hrgn);
283
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
295 // MSW-specific member variables
296 // -----------------------------
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
306 // our HDC
307 WXHDC m_hDC;
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;
316
317 #if wxUSE_PALETTE
318 WXHPALETTE m_oldPalette;
319 #endif // wxUSE_PALETTE
320
321 #if wxUSE_DC_CACHEING
322 static wxObjectList sm_bitmapCache;
323 static wxObjectList sm_dcCache;
324 #endif
325
326 DECLARE_CLASS(wxMSWDCImpl)
327 wxDECLARE_NO_COPY_CLASS(wxMSWDCImpl);
328 };
329
330 // ----------------------------------------------------------------------------
331 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
332 // only/mainly)
333 // ----------------------------------------------------------------------------
334
335 class WXDLLIMPEXP_CORE wxDCTempImpl : public wxMSWDCImpl
336 {
337 public:
338 // construct a temporary DC with the specified HDC and size (it should be
339 // specified whenever we know it for this HDC)
340 wxDCTempImpl(wxDC *owner, WXHDC hdc, const wxSize& size )
341 : wxMSWDCImpl( owner, hdc ),
342 m_size(size)
343 {
344 }
345
346 virtual ~wxDCTempImpl()
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 {
354 wxASSERT_MSG( m_size.IsFullySpecified(),
355 wxT("size of this DC hadn't been set and is unknown") );
356
357 if ( w )
358 *w = m_size.x;
359 if ( h )
360 *h = m_size.y;
361 }
362
363 private:
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
368 wxDECLARE_NO_COPY_CLASS(wxDCTempImpl);
369 };
370
371 class WXDLLIMPEXP_CORE wxDCTemp : public wxDC
372 {
373 public:
374 wxDCTemp(WXHDC hdc, const wxSize& size = wxDefaultSize)
375 : wxDC(new wxDCTempImpl(this, hdc, size))
376 {
377 }
378 };
379
380 #endif // _WX_MSW_DC_H_
381