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
) {
108 // if we have palettes use the correct one for this window
113 WXHDC
GetHDC() const { return m_hDC
; }
114 void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
)
120 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
121 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
123 // update the internal clip box variables
124 void UpdateClipBox();
126 #if wxUSE_DC_CACHEING
127 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
128 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
130 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
131 static void AddToDCCache(wxDCCacheEntry
* entry
);
132 static void ClearCache();
136 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
137 int style
= wxFLOOD_SURFACE
);
139 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
141 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
142 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
144 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
145 wxCoord x2
, wxCoord y2
,
146 wxCoord xc
, wxCoord yc
);
147 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
148 wxCoord width
, wxCoord height
);
149 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
150 double sa
, double ea
);
152 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
153 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
154 wxCoord width
, wxCoord height
,
156 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
158 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
160 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
161 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
162 bool useMask
= FALSE
);
164 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
165 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
168 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
169 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
170 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
172 // this is gnarly - we can't even call this function DoSetClippingRegion()
173 // because of virtual function hiding
174 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
175 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
176 wxCoord width
, wxCoord height
);
177 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
178 wxCoord
*width
, wxCoord
*height
)
180 GetClippingBox(x
, y
, width
, height
);
183 virtual void DoGetSize(int *width
, int *height
) const;
184 virtual void DoGetSizeMM(int* width
, int* height
) const;
186 virtual void DoDrawLines(int n
, wxPoint points
[],
187 wxCoord xoffset
, wxCoord yoffset
);
188 virtual void DoDrawPolygon(int n
, wxPoint points
[],
189 wxCoord xoffset
, wxCoord yoffset
,
190 int fillStyle
= wxODDEVEN_RULE
);
194 // MSW specific, select a logical palette into the HDC
195 // (tell windows to translate pixel from other palettes to our custom one
197 // Realize tells it to also reset the system palette to this one.
198 void DoSelectPalette(bool realize
= false);
199 // Find out what palette our parent window has, then select it into the dc
200 void InitializePalette();
202 // common part of DoDrawText() and DoDrawRotatedText()
203 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
205 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
206 void SetClippingHrgn(WXHRGN hrgn
);
208 // MSW-specific member variables
209 // -----------------------------
211 // the window associated with this DC (may be NULL)
214 wxBitmap m_selectedBitmap
;
216 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
222 // Store all old GDI objects when do a SelectObject, so we can select them
223 // back in (this unselecting user's objects) so we can safely delete the
225 WXHBITMAP m_oldBitmap
;
231 WXHPALETTE m_oldPalette
;
232 #endif // wxUSE_PALETTE
234 #if wxUSE_DC_CACHEING
235 static wxList sm_bitmapCache
;
236 static wxList sm_dcCache
;
239 DECLARE_DYNAMIC_CLASS(wxDC
)
242 // ----------------------------------------------------------------------------
243 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWindows
245 // ----------------------------------------------------------------------------
247 class WXDLLEXPORT wxDCTemp
: public wxDC
250 wxDCTemp(WXHDC hdc
) { SetHDC(hdc
); }
251 virtual ~wxDCTemp() { SetHDC((WXHDC
)NULL
); }