1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
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 WXDLLEXPORT wxDC
: public wxDCBase
48 wxDC(WXHDC hDC
) { Init(); m_hDC
= hDC
; }
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;
81 virtual wxCoord
DeviceToLogicalX(wxCoord x
) const;
82 virtual wxCoord
DeviceToLogicalY(wxCoord y
) const;
83 virtual wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
84 virtual wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
85 virtual wxCoord
LogicalToDeviceX(wxCoord x
) const;
86 virtual wxCoord
LogicalToDeviceY(wxCoord y
) const;
87 virtual wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
88 virtual wxCoord
LogicalToDeviceYRel(wxCoord y
) const ;
90 virtual void SetMapMode(int mode
);
91 virtual void SetUserScale(double x
, double y
);
92 virtual void SetSystemScale(double x
, double y
);
93 virtual void SetLogicalScale(double x
, double y
);
94 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
95 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
96 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
97 virtual void SetLogicalFunction(int function
);
99 // implementation from now on
100 // --------------------------
102 virtual void SetRop(WXHDC cdc
);
103 virtual void SelectOldObjects(WXHDC dc
);
105 wxWindow
*GetWindow() const { return m_canvas
; }
106 void SetWindow(wxWindow
*win
)
111 // if we have palettes use the correct one for this window
113 #endif // wxUSE_PALETTE
116 WXHDC
GetHDC() const { return m_hDC
; }
117 void SetHDC(WXHDC dc
, bool bOwnsDC
= false)
122 // we might have a pre existing clipping region, make sure that we
123 // return it if asked -- but avoid calling ::GetClipBox() right now as
124 // it could be unnecessary wasteful
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
);
167 #endif // wxUSE_PALETTE
170 // create an uninitialized DC: this should be only used by the derived
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 int 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
);
209 virtual void DoDrawSpline(wxList
*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 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
226 virtual bool DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
227 wxCoord dstWidth
, wxCoord dstHeight
,
229 wxCoord xsrc
, wxCoord ysrc
,
230 wxCoord srcWidth
, wxCoord srcHeight
,
231 int rop
= wxCOPY
, bool useMask
= false,
232 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
234 // this is gnarly - we can't even call this function DoSetClippingRegion()
235 // because of virtual function hiding
236 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
237 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
238 wxCoord width
, wxCoord height
);
239 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
240 wxCoord
*w
, wxCoord
*h
) const;
242 virtual void DoGetSizeMM(int* width
, int* height
) const;
244 virtual void DoDrawLines(int n
, wxPoint points
[],
245 wxCoord xoffset
, wxCoord yoffset
);
246 virtual void DoDrawPolygon(int n
, wxPoint points
[],
247 wxCoord xoffset
, wxCoord yoffset
,
248 int fillStyle
= wxODDEVEN_RULE
);
249 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
250 wxCoord xoffset
, wxCoord yoffset
,
251 int fillStyle
= wxODDEVEN_RULE
);
252 virtual wxBitmap
DoGetAsBitmap(const wxRect
*subrect
) const
253 { return subrect
== NULL
? GetSelectedBitmap() : GetSelectedBitmap().GetSubBitmap(*subrect
); }
257 // MSW specific, select a logical palette into the HDC
258 // (tell windows to translate pixel from other palettes to our custom one
260 // Realize tells it to also reset the system palette to this one.
261 void DoSelectPalette(bool realize
= false);
263 // Find out what palette our parent window has, then select it into the dc
264 void InitializePalette();
265 #endif // wxUSE_PALETTE
267 // common part of DoDrawText() and DoDrawRotatedText()
268 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
270 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
271 void SetClippingHrgn(WXHRGN hrgn
);
273 // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
274 // returns the size of the entire device this DC is associated with
276 // notice that we intentionally put it in a separate function instead of
277 // DoGetSize() itself because we want it to remain pure virtual both
278 // because each derived class should take care to define it as needed (this
279 // implementation is not at all always appropriate) and because we want
280 // wxDC to be an ABC to prevent it from being created directly
281 void GetDeviceSize(int *width
, int *height
) const;
284 // MSW-specific member variables
285 // -----------------------------
287 // the window associated with this DC (may be NULL)
290 wxBitmap m_selectedBitmap
;
292 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
298 // Store all old GDI objects when do a SelectObject, so we can select them
299 // back in (this unselecting user's objects) so we can safely delete the
301 WXHBITMAP m_oldBitmap
;
307 WXHPALETTE m_oldPalette
;
308 #endif // wxUSE_PALETTE
310 #if wxUSE_DC_CACHEING
311 static wxList sm_bitmapCache
;
312 static wxList sm_dcCache
;
315 DECLARE_DYNAMIC_CLASS(wxDC
)
316 DECLARE_NO_COPY_CLASS(wxDC
)
319 // ----------------------------------------------------------------------------
320 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
322 // ----------------------------------------------------------------------------
324 class WXDLLEXPORT wxDCTemp
: public wxDC
327 // construct a temporary DC with the specified HDC and size (it should be
328 // specified whenever we know it for this HDC)
329 wxDCTemp(WXHDC hdc
, const wxSize
& size
= wxDefaultSize
)
337 // prevent base class dtor from freeing it
342 virtual void DoGetSize(int *w
, int *h
) const
344 wxASSERT_MSG( m_size
.IsFullySpecified(),
345 _T("size of this DC hadn't been set and is unknown") );
354 // size of this DC must be explicitly set by SetSize() as we have no way to
358 DECLARE_NO_COPY_CLASS(wxDCTemp
)
361 #endif // _WX_MSW_DC_H_