1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "dc.h"
21 // ---------------------------------------------------------------------------
23 // ---------------------------------------------------------------------------
27 * Cached blitting, maintaining a cache
28 * of bitmaps required for transparent blitting
29 * instead of constant creation/deletion
32 class wxDCCacheEntry
: public wxObject
35 wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
);
36 wxDCCacheEntry(WXHDC hDC
, int depth
);
47 class WXDLLEXPORT wxDC
: public wxDCBase
53 // implement base class pure virtuals
54 // ----------------------------------
58 virtual bool StartDoc(const wxString
& message
);
59 virtual void EndDoc();
61 virtual void StartPage();
62 virtual void EndPage();
64 virtual void SetFont(const wxFont
& font
);
65 virtual void SetPen(const wxPen
& pen
);
66 virtual void SetBrush(const wxBrush
& brush
);
67 virtual void SetBackground(const wxBrush
& brush
);
68 virtual void SetBackgroundMode(int mode
);
70 virtual void SetPalette(const wxPalette
& palette
);
71 #endif // wxUSE_PALETTE
73 virtual void DestroyClippingRegion();
75 virtual wxCoord
GetCharHeight() const;
76 virtual wxCoord
GetCharWidth() const;
77 virtual void DoGetTextExtent(const wxString
& string
,
78 wxCoord
*x
, wxCoord
*y
,
79 wxCoord
*descent
= NULL
,
80 wxCoord
*externalLeading
= NULL
,
81 wxFont
*theFont
= NULL
) const;
82 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
84 virtual bool CanDrawBitmap() const;
85 virtual bool CanGetTextExtent() const;
86 virtual int GetDepth() const;
87 virtual wxSize
GetPPI() const;
89 virtual void SetMapMode(int mode
);
90 virtual void SetUserScale(double x
, double y
);
91 virtual void SetSystemScale(double x
, double y
);
92 virtual void SetLogicalScale(double x
, double y
);
93 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
94 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
95 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
96 virtual void SetLogicalFunction(int function
);
98 // implementation from now on
99 // --------------------------
101 virtual void SetRop(WXHDC cdc
);
102 virtual void SelectOldObjects(WXHDC dc
);
104 wxWindow
*GetWindow() const { return m_canvas
; }
105 void SetWindow(wxWindow
*win
)
110 // if we have palettes use the correct one for this window
112 #endif // wxUSE_PALETTE
115 WXHDC
GetHDC() const { return m_hDC
; }
116 void SetHDC(WXHDC dc
, bool bOwnsDC
= false)
121 // we might have a pre existing clipping region, make sure that we
122 // return it if asked -- but avoid calling ::GetClipBox() right now as
123 // it could be unnecessary wasteful
129 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
130 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
132 // update the internal clip box variables
133 void UpdateClipBox();
135 #if wxUSE_DC_CACHEING
136 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
137 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
139 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
140 static void AddToDCCache(wxDCCacheEntry
* entry
);
141 static void ClearCache();
145 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
146 int style
= wxFLOOD_SURFACE
);
148 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
150 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
151 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
153 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
154 wxCoord x2
, wxCoord y2
,
155 wxCoord xc
, wxCoord yc
);
156 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
157 wxCoord width
, wxCoord height
);
158 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
159 double sa
, double ea
);
161 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
162 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
163 wxCoord width
, wxCoord height
,
165 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
167 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
169 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
170 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
171 bool useMask
= false);
173 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
174 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
177 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
178 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
179 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
181 // this is gnarly - we can't even call this function DoSetClippingRegion()
182 // because of virtual function hiding
183 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
184 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
185 wxCoord width
, wxCoord height
);
186 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
187 wxCoord
*width
, wxCoord
*height
)
189 GetClippingBox(x
, y
, width
, height
);
191 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
192 wxCoord
*w
, wxCoord
*h
) const;
194 virtual void DoGetSize(int *width
, int *height
) const;
195 virtual void DoGetSizeMM(int* width
, int* height
) const;
197 virtual void DoDrawLines(int n
, wxPoint points
[],
198 wxCoord xoffset
, wxCoord yoffset
);
199 virtual void DoDrawPolygon(int n
, wxPoint points
[],
200 wxCoord xoffset
, wxCoord yoffset
,
201 int fillStyle
= wxODDEVEN_RULE
);
202 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
203 wxCoord xoffset
, wxCoord yoffset
,
204 int fillStyle
= wxODDEVEN_RULE
);
208 // MSW specific, select a logical palette into the HDC
209 // (tell windows to translate pixel from other palettes to our custom one
211 // Realize tells it to also reset the system palette to this one.
212 void DoSelectPalette(bool realize
= false);
214 // Find out what palette our parent window has, then select it into the dc
215 void InitializePalette();
216 #endif // wxUSE_PALETTE
218 // common part of DoDrawText() and DoDrawRotatedText()
219 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
221 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
222 void SetClippingHrgn(WXHRGN hrgn
);
224 // MSW-specific member variables
225 // -----------------------------
227 // the window associated with this DC (may be NULL)
230 wxBitmap m_selectedBitmap
;
232 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
238 // Store all old GDI objects when do a SelectObject, so we can select them
239 // back in (this unselecting user's objects) so we can safely delete the
241 WXHBITMAP m_oldBitmap
;
247 WXHPALETTE m_oldPalette
;
248 #endif // wxUSE_PALETTE
250 #if wxUSE_DC_CACHEING
251 static wxList sm_bitmapCache
;
252 static wxList sm_dcCache
;
255 DECLARE_DYNAMIC_CLASS(wxDC
)
256 DECLARE_NO_COPY_CLASS(wxDC
)
259 // ----------------------------------------------------------------------------
260 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
262 // ----------------------------------------------------------------------------
264 class WXDLLEXPORT wxDCTemp
: public wxDC
267 wxDCTemp(WXHDC hdc
) { SetHDC(hdc
); }
268 virtual ~wxDCTemp() { SetHDC((WXHDC
)NULL
); }
271 DECLARE_NO_COPY_CLASS(wxDCTemp
)