1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
17 // ---------------------------------------------------------------------------
19 // ---------------------------------------------------------------------------
23 * Cached blitting, maintaining a cache
24 * of bitmaps required for transparent blitting
25 * instead of constant creation/deletion
28 class wxDCCacheEntry
: public wxObject
31 wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
);
32 wxDCCacheEntry(WXHDC hDC
, int depth
);
33 virtual ~wxDCCacheEntry();
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
48 wxMSWDCImpl(wxDC
*owner
, WXHDC hDC
);
49 virtual ~wxMSWDCImpl();
51 // implement base class pure virtuals
52 // ----------------------------------
56 virtual bool StartDoc(const wxString
& message
);
57 virtual void EndDoc();
59 virtual void StartPage();
60 virtual void EndPage();
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
);
68 virtual void SetPalette(const wxPalette
& palette
);
69 #endif // wxUSE_PALETTE
71 virtual void DestroyClippingRegion();
73 virtual wxCoord
GetCharHeight() const;
74 virtual wxCoord
GetCharWidth() const;
76 virtual bool CanDrawBitmap() const;
77 virtual bool CanGetTextExtent() const;
78 virtual int GetDepth() const;
79 virtual wxSize
GetPPI() const;
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
);
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
96 virtual void SetLogicalFunction(wxRasterOperationMode function
);
98 // implementation from now on
99 // --------------------------
101 virtual void SetRop(WXHDC cdc
);
102 virtual void SelectOldObjects(WXHDC dc
);
104 void SetWindow(wxWindow
*win
)
109 // if we have palettes use the correct one for this window
111 #endif // wxUSE_PALETTE
114 WXHDC
GetHDC() const { return m_hDC
; }
115 void SetHDC(WXHDC dc
, bool bOwnsDC
= false)
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
128 void* GetHandle() const { return (void*)GetHDC(); }
130 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
131 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
133 // update the internal clip box variables
134 void UpdateClipBox();
136 #if wxUSE_DC_CACHEING
137 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
138 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
140 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
141 static void AddToDCCache(wxDCCacheEntry
* entry
);
142 static void ClearCache();
145 // RTL related functions
146 // ---------------------
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
);
166 #endif // wxUSE_PALETTE
169 // create an uninitialized DC: this should be only used by the derived
171 wxMSWDCImpl( wxDC
*owner
) : wxDCImpl( owner
) { Init(); }
173 void RealizeScaleAndOrigin();
176 virtual void DoGetFontMetrics(int *height
,
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;
189 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
190 wxFloodFillStyle style
= wxFLOOD_SURFACE
);
192 virtual void DoGradientFillLinear(const wxRect
& rect
,
193 const wxColour
& initialColour
,
194 const wxColour
& destColour
,
195 wxDirection nDirection
= wxEAST
);
197 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
199 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
200 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
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
);
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
,
214 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
216 #if wxUSE_SPLINES && !defined(__WXWINCE__)
217 virtual void DoDrawSpline(const wxPointList
*points
);
220 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
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);
226 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
227 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
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
);
235 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
236 wxCoord dstWidth
, wxCoord dstHeight
,
238 wxCoord xsrc
, wxCoord ysrc
,
239 wxCoord srcWidth
, wxCoord srcHeight
,
240 wxRasterOperationMode rop
= wxCOPY
, bool useMask
= false,
241 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
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;
249 virtual void DoGetSizeMM(int* width
, int* height
) const;
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
261 return subrect
== NULL
? GetSelectedBitmap()
262 : GetSelectedBitmap().GetSubBitmap(*subrect
);
267 // MSW specific, select a logical palette into the HDC
268 // (tell windows to translate pixel from other palettes to our custom one
270 // Realize tells it to also reset the system palette to this one.
271 void DoSelectPalette(bool realize
= false);
273 // Find out what palette our parent window has, then select it into the dc
274 void InitializePalette();
275 #endif // wxUSE_PALETTE
278 // common part of DoDrawText() and DoDrawRotatedText()
279 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
281 // common part of DoSetClippingRegion() and DoSetDeviceClippingRegion()
282 void SetClippingHrgn(WXHRGN hrgn
);
284 // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
285 // returns the size of the entire device this DC is associated with
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;
295 // MSW-specific member variables
296 // -----------------------------
298 // the window associated with this DC (may be NULL)
301 wxBitmap m_selectedBitmap
;
303 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
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
312 WXHBITMAP m_oldBitmap
;
318 WXHPALETTE m_oldPalette
;
319 #endif // wxUSE_PALETTE
321 #if wxUSE_DC_CACHEING
322 static wxObjectList sm_bitmapCache
;
323 static wxObjectList sm_dcCache
;
326 DECLARE_CLASS(wxMSWDCImpl
)
327 wxDECLARE_NO_COPY_CLASS(wxMSWDCImpl
);
330 // ----------------------------------------------------------------------------
331 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
333 // ----------------------------------------------------------------------------
335 class WXDLLIMPEXP_CORE wxDCTempImpl
: public wxMSWDCImpl
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
),
346 virtual ~wxDCTempImpl()
348 // prevent base class dtor from freeing it
352 virtual void DoGetSize(int *w
, int *h
) const
354 wxASSERT_MSG( m_size
.IsFullySpecified(),
355 wxT("size of this DC hadn't been set and is unknown") );
364 // size of this DC must be explicitly set by SetSize() as we have no way to
368 wxDECLARE_NO_COPY_CLASS(wxDCTempImpl
);
371 class WXDLLIMPEXP_CORE wxDCTemp
: public wxDC
374 wxDCTemp(WXHDC hdc
, const wxSize
& size
= wxDefaultSize
)
375 : wxDC(new wxDCTempImpl(this, hdc
, size
))
380 #endif // _WX_MSW_DC_H_