1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
18 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
24 * Cached blitting, maintaining a cache
25 * of bitmaps required for transparent blitting
26 * instead of constant creation/deletion
29 class wxDCCacheEntry
: public wxObject
32 wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
);
33 wxDCCacheEntry(WXHDC hDC
, int depth
);
34 virtual ~wxDCCacheEntry();
44 // this is an ABC: use one of the derived classes to create a DC associated
45 // with a window, screen, printer and so on
46 class WXDLLIMPEXP_CORE wxMSWDCImpl
: public wxDCImpl
49 wxMSWDCImpl(wxDC
*owner
, WXHDC hDC
);
50 virtual ~wxMSWDCImpl();
52 // implement base class pure virtuals
53 // ----------------------------------
57 virtual bool StartDoc(const wxString
& message
);
58 virtual void EndDoc();
60 virtual void StartPage();
61 virtual void EndPage();
63 virtual void SetFont(const wxFont
& font
);
64 virtual void SetPen(const wxPen
& pen
);
65 virtual void SetBrush(const wxBrush
& brush
);
66 virtual void SetBackground(const wxBrush
& brush
);
67 virtual void SetBackgroundMode(int mode
);
69 virtual void SetPalette(const wxPalette
& palette
);
70 #endif // wxUSE_PALETTE
72 virtual void DestroyClippingRegion();
74 virtual wxCoord
GetCharHeight() const;
75 virtual wxCoord
GetCharWidth() const;
77 virtual bool CanDrawBitmap() const;
78 virtual bool CanGetTextExtent() const;
79 virtual int GetDepth() const;
80 virtual wxSize
GetPPI() const;
83 virtual void SetMapMode(wxMappingMode mode
);
84 virtual void SetUserScale(double x
, double y
);
85 virtual void SetLogicalScale(double x
, double y
);
86 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
87 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
88 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
90 virtual void SetLogicalFunction(wxRasterOperationMode function
);
92 // implementation from now on
93 // --------------------------
95 virtual void SetRop(WXHDC cdc
);
96 virtual void SelectOldObjects(WXHDC dc
);
98 void SetWindow(wxWindow
*win
)
103 // if we have palettes use the correct one for this window
105 #endif // wxUSE_PALETTE
108 WXHDC
GetHDC() const { return m_hDC
; }
109 void SetHDC(WXHDC dc
, bool bOwnsDC
= false)
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
122 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
123 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
125 // update the internal clip box variables
126 void UpdateClipBox();
128 #if wxUSE_DC_CACHEING
129 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
130 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
132 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
133 static void AddToDCCache(wxDCCacheEntry
* entry
);
134 static void ClearCache();
137 // RTL related functions
138 // ---------------------
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
);
158 #endif // wxUSE_PALETTE
161 // create an uninitialized DC: this should be only used by the derived
163 wxMSWDCImpl( wxDC
*owner
) : wxDCImpl( owner
) { Init(); }
165 void RealizeScaleAndOrigin();
168 virtual void DoGetFontMetrics(int *height
,
171 int *internalLeading
,
172 int *externalLeading
,
173 int *averageWidth
) const;
174 virtual void DoGetTextExtent(const wxString
& string
,
175 wxCoord
*x
, wxCoord
*y
,
176 wxCoord
*descent
= NULL
,
177 wxCoord
*externalLeading
= NULL
,
178 const wxFont
*theFont
= NULL
) const;
179 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
181 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
182 wxFloodFillStyle style
= wxFLOOD_SURFACE
);
184 virtual void DoGradientFillLinear(const wxRect
& rect
,
185 const wxColour
& initialColour
,
186 const wxColour
& destColour
,
187 wxDirection nDirection
= wxEAST
);
189 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
191 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
192 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
194 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
195 wxCoord x2
, wxCoord y2
,
196 wxCoord xc
, wxCoord yc
);
197 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
198 wxCoord width
, wxCoord height
);
199 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
200 double sa
, double ea
);
202 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
203 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
204 wxCoord width
, wxCoord height
,
206 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
208 #if wxUSE_SPLINES && !defined(__WXWINCE__)
209 virtual void DoDrawSpline(const wxPointList
*points
);
212 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
214 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
215 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
216 bool useMask
= false);
218 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
219 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
222 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
223 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
224 wxRasterOperationMode rop
= wxCOPY
, bool useMask
= false,
225 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
227 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
228 wxCoord dstWidth
, wxCoord dstHeight
,
230 wxCoord xsrc
, wxCoord ysrc
,
231 wxCoord srcWidth
, wxCoord srcHeight
,
232 wxRasterOperationMode rop
= wxCOPY
, bool useMask
= false,
233 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
235 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
236 wxCoord width
, wxCoord height
);
237 virtual void DoSetDeviceClippingRegion(const wxRegion
& region
);
238 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
239 wxCoord
*w
, wxCoord
*h
) const;
241 virtual void DoGetSizeMM(int* width
, int* height
) const;
243 virtual void DoDrawLines(int n
, wxPoint points
[],
244 wxCoord xoffset
, wxCoord yoffset
);
245 virtual void DoDrawPolygon(int n
, wxPoint points
[],
246 wxCoord xoffset
, wxCoord yoffset
,
247 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
248 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
249 wxCoord xoffset
, wxCoord yoffset
,
250 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
251 virtual wxBitmap
DoGetAsBitmap(const wxRect
*subrect
) const
253 return subrect
== NULL
? GetSelectedBitmap()
254 : GetSelectedBitmap().GetSubBitmap(*subrect
);
259 // MSW specific, select a logical palette into the HDC
260 // (tell windows to translate pixel from other palettes to our custom one
262 // Realize tells it to also reset the system palette to this one.
263 void DoSelectPalette(bool realize
= false);
265 // Find out what palette our parent window has, then select it into the dc
266 void InitializePalette();
267 #endif // wxUSE_PALETTE
270 // common part of DoDrawText() and DoDrawRotatedText()
271 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
273 // common part of DoSetClippingRegion() and DoSetDeviceClippingRegion()
274 void SetClippingHrgn(WXHRGN hrgn
);
276 // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
277 // returns the size of the entire device this DC is associated with
279 // notice that we intentionally put it in a separate function instead of
280 // DoGetSize() itself because we want it to remain pure virtual both
281 // because each derived class should take care to define it as needed (this
282 // implementation is not at all always appropriate) and because we want
283 // wxDC to be an ABC to prevent it from being created directly
284 void GetDeviceSize(int *width
, int *height
) const;
287 // MSW-specific member variables
288 // -----------------------------
290 // the window associated with this DC (may be NULL)
293 wxBitmap m_selectedBitmap
;
295 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
301 // Store all old GDI objects when do a SelectObject, so we can select them
302 // back in (this unselecting user's objects) so we can safely delete the
304 WXHBITMAP m_oldBitmap
;
310 WXHPALETTE m_oldPalette
;
311 #endif // wxUSE_PALETTE
313 #if wxUSE_DC_CACHEING
314 static wxObjectList sm_bitmapCache
;
315 static wxObjectList sm_dcCache
;
318 DECLARE_CLASS(wxMSWDCImpl
)
319 wxDECLARE_NO_COPY_CLASS(wxMSWDCImpl
);
322 // ----------------------------------------------------------------------------
323 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
325 // ----------------------------------------------------------------------------
327 class WXDLLIMPEXP_CORE wxDCTempImpl
: public wxMSWDCImpl
330 // construct a temporary DC with the specified HDC and size (it should be
331 // specified whenever we know it for this HDC)
332 wxDCTempImpl(wxDC
*owner
, WXHDC hdc
, const wxSize
& size
)
333 : wxMSWDCImpl( owner
, hdc
),
338 virtual ~wxDCTempImpl()
340 // prevent base class dtor from freeing it
344 virtual void DoGetSize(int *w
, int *h
) const
346 wxASSERT_MSG( m_size
.IsFullySpecified(),
347 wxT("size of this DC hadn't been set and is unknown") );
356 // size of this DC must be explicitly set by SetSize() as we have no way to
360 wxDECLARE_NO_COPY_CLASS(wxDCTempImpl
);
363 class WXDLLIMPEXP_CORE wxDCTemp
: public wxDC
366 wxDCTemp(WXHDC hdc
, const wxSize
& size
= wxDefaultSize
)
367 : wxDC(new wxDCTempImpl(this, hdc
, size
))
372 #endif // _WX_MSW_DC_H_