1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dc.h"
22 // ---------------------------------------------------------------------------
24 // ---------------------------------------------------------------------------
28 * Cached blitting, maintaining a cache
29 * of bitmaps required for transparent blitting
30 * instead of constant creation/deletion
33 class wxDCCacheEntry
: public wxObject
36 wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
);
37 wxDCCacheEntry(WXHDC hDC
, int depth
);
48 class WXDLLEXPORT wxDC
: public wxDCBase
54 // implement base class pure virtuals
55 // ----------------------------------
59 virtual bool StartDoc(const wxString
& message
);
60 virtual void EndDoc();
62 virtual void StartPage();
63 virtual void EndPage();
65 virtual void SetFont(const wxFont
& font
);
66 virtual void SetPen(const wxPen
& pen
);
67 virtual void SetBrush(const wxBrush
& brush
);
68 virtual void SetBackground(const wxBrush
& brush
);
69 virtual void SetBackgroundMode(int mode
);
71 virtual void SetPalette(const wxPalette
& palette
);
72 #endif // wxUSE_PALETTE
74 virtual void DestroyClippingRegion();
76 virtual wxCoord
GetCharHeight() const;
77 virtual wxCoord
GetCharWidth() const;
78 virtual void DoGetTextExtent(const wxString
& string
,
79 wxCoord
*x
, wxCoord
*y
,
80 wxCoord
*descent
= NULL
,
81 wxCoord
*externalLeading
= NULL
,
82 wxFont
*theFont
= NULL
) 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
) { m_canvas
= win
; }
107 WXHDC
GetHDC() const { return m_hDC
; }
108 void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
)
114 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
115 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
117 // update the internal clip box variables
118 void UpdateClipBox();
120 #if wxUSE_DC_CACHEING
121 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
122 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
124 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
125 static void AddToDCCache(wxDCCacheEntry
* entry
);
126 static void ClearCache();
130 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
131 int style
= wxFLOOD_SURFACE
);
133 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
135 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
136 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
138 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
139 wxCoord x2
, wxCoord y2
,
140 wxCoord xc
, wxCoord yc
);
141 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
142 wxCoord width
, wxCoord height
);
143 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
144 double sa
, double ea
);
146 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
147 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
148 wxCoord width
, wxCoord height
,
150 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
152 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
154 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
155 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
156 bool useMask
= FALSE
);
158 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
159 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
162 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
163 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
164 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
166 // this is gnarly - we can't even call this function DoSetClippingRegion()
167 // because of virtual function hiding
168 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
169 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
170 wxCoord width
, wxCoord height
);
171 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
172 wxCoord
*width
, wxCoord
*height
)
174 GetClippingBox(x
, y
, width
, height
);
177 virtual void DoGetSize(int *width
, int *height
) const;
178 virtual void DoGetSizeMM(int* width
, int* height
) const;
180 virtual void DoDrawLines(int n
, wxPoint points
[],
181 wxCoord xoffset
, wxCoord yoffset
);
182 virtual void DoDrawPolygon(int n
, wxPoint points
[],
183 wxCoord xoffset
, wxCoord yoffset
,
184 int fillStyle
= wxODDEVEN_RULE
);
187 // common part of DoDrawText() and DoDrawRotatedText()
188 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
190 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
191 void SetClippingHrgn(WXHRGN hrgn
);
193 // MSW-specific member variables
194 // -----------------------------
196 // the window associated with this DC (may be NULL)
199 wxBitmap m_selectedBitmap
;
201 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
207 // Store all old GDI objects when do a SelectObject, so we can select them
208 // back in (this unselecting user's objects) so we can safely delete the
210 WXHBITMAP m_oldBitmap
;
216 WXHPALETTE m_oldPalette
;
217 #endif // wxUSE_PALETTE
219 #if wxUSE_DC_CACHEING
220 static wxList sm_bitmapCache
;
221 static wxList sm_dcCache
;
224 DECLARE_DYNAMIC_CLASS(wxDC
)
227 // ----------------------------------------------------------------------------
228 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWindows
230 // ----------------------------------------------------------------------------
232 class WXDLLEXPORT wxDCTemp
: public wxDC
235 wxDCTemp(WXHDC hdc
) { SetHDC(hdc
); }
236 virtual ~wxDCTemp() { SetHDC((WXHDC
)NULL
); }