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 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
);
90 // implementation from now on
91 // --------------------------
93 virtual void SetRop(WXHDC cdc
);
94 virtual void SelectOldObjects(WXHDC dc
);
96 wxWindow
*GetWindow() const { return m_canvas
; }
97 void SetWindow(wxWindow
*win
)
102 // if we have palettes use the correct one for this window
104 #endif // wxUSE_PALETTE
107 WXHDC
GetHDC() const { return m_hDC
; }
108 void SetHDC(WXHDC dc
, bool bOwnsDC
= false)
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
121 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
122 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
124 // update the internal clip box variables
125 void UpdateClipBox();
127 #if wxUSE_DC_CACHEING
128 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
129 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
131 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
132 static void AddToDCCache(wxDCCacheEntry
* entry
);
133 static void ClearCache();
136 // RTL related functions
137 // ---------------------
139 // get or change the layout direction (LTR or RTL) for this dc,
140 // wxLayout_Default is returned if layout direction is not supported
141 virtual wxLayoutDirection
GetLayoutDirection() const;
142 virtual void SetLayoutDirection(wxLayoutDirection dir
);
158 #endif // wxUSE_PALETTE
161 // create an uninitialized DC: this should be only used by the derived
165 virtual void DoGetTextExtent(const wxString
& string
,
166 wxCoord
*x
, wxCoord
*y
,
167 wxCoord
*descent
= NULL
,
168 wxCoord
*externalLeading
= NULL
,
169 wxFont
*theFont
= NULL
) const;
170 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
172 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
173 int style
= wxFLOOD_SURFACE
);
175 virtual void DoGradientFillLinear(const wxRect
& rect
,
176 const wxColour
& initialColour
,
177 const wxColour
& destColour
,
178 wxDirection nDirection
= wxEAST
);
180 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
182 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
183 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
185 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
186 wxCoord x2
, wxCoord y2
,
187 wxCoord xc
, wxCoord yc
);
188 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
189 wxCoord width
, wxCoord height
);
190 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
191 double sa
, double ea
);
193 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
194 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
195 wxCoord width
, wxCoord height
,
197 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
200 virtual void DoDrawSpline(wxList
*points
);
203 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
205 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
206 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
207 bool useMask
= false);
209 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
210 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
213 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
214 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
215 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
217 // this is gnarly - we can't even call this function DoSetClippingRegion()
218 // because of virtual function hiding
219 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
220 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
221 wxCoord width
, wxCoord height
);
222 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
223 wxCoord
*w
, wxCoord
*h
) const;
225 virtual void DoGetSizeMM(int* width
, int* height
) const;
227 virtual void DoDrawLines(int n
, wxPoint points
[],
228 wxCoord xoffset
, wxCoord yoffset
);
229 virtual void DoDrawPolygon(int n
, wxPoint points
[],
230 wxCoord xoffset
, wxCoord yoffset
,
231 int fillStyle
= wxODDEVEN_RULE
);
232 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
233 wxCoord xoffset
, wxCoord yoffset
,
234 int fillStyle
= wxODDEVEN_RULE
);
235 virtual wxBitmap
DoGetAsBitmap(const wxRect
*subrect
) const
236 { return subrect
== NULL
? GetSelectedBitmap() : GetSelectedBitmap().GetSubBitmap(*subrect
); }
240 // MSW specific, select a logical palette into the HDC
241 // (tell windows to translate pixel from other palettes to our custom one
243 // Realize tells it to also reset the system palette to this one.
244 void DoSelectPalette(bool realize
= false);
246 // Find out what palette our parent window has, then select it into the dc
247 void InitializePalette();
248 #endif // wxUSE_PALETTE
250 // common part of DoDrawText() and DoDrawRotatedText()
251 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
253 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
254 void SetClippingHrgn(WXHRGN hrgn
);
256 // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
257 // returns the size of the entire device this DC is associated with
259 // notice that we intentionally put it in a separate function instead of
260 // DoGetSize() itself because we want it to remain pure virtual both
261 // because each derived class should take care to define it as needed (this
262 // implementation is not at all always appropriate) and because we want
263 // wxDC to be an ABC to prevent it from being created directly
264 void GetDeviceSize(int *width
, int *height
) const;
267 // MSW-specific member variables
268 // -----------------------------
270 // the window associated with this DC (may be NULL)
273 wxBitmap m_selectedBitmap
;
275 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
281 // Store all old GDI objects when do a SelectObject, so we can select them
282 // back in (this unselecting user's objects) so we can safely delete the
284 WXHBITMAP m_oldBitmap
;
290 WXHPALETTE m_oldPalette
;
291 #endif // wxUSE_PALETTE
293 #if wxUSE_DC_CACHEING
294 static wxList sm_bitmapCache
;
295 static wxList sm_dcCache
;
298 DECLARE_DYNAMIC_CLASS(wxDC
)
299 DECLARE_NO_COPY_CLASS(wxDC
)
302 // ----------------------------------------------------------------------------
303 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
305 // ----------------------------------------------------------------------------
307 class WXDLLEXPORT wxDCTemp
: public wxDC
310 // construct a temporary DC with the specified HDC and size (it should be
311 // specified whenever we know it for this HDC)
312 wxDCTemp(WXHDC hdc
, const wxSize
& size
= wxDefaultSize
)
320 // prevent base class dtor from freeing it
325 virtual void DoGetSize(int *w
, int *h
) const
327 wxASSERT_MSG( m_size
.IsFullySpecified(),
328 _T("size of this DC hadn't been set and is unknown") );
337 // size of this DC must be explicitly set by SetSize() as we have no way to
341 DECLARE_NO_COPY_CLASS(wxDCTemp
)
344 #endif // _WX_MSW_DC_H_