1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dc.h"
22 // ---------------------------------------------------------------------------
24 // ---------------------------------------------------------------------------
28 #define XLOG2DEV(x) (x)
29 #define YLOG2DEV(y) (y)
32 #define XLOG2DEVREL(x) (x)
33 #define YLOG2DEVREL(y) (y)
37 #define XDEV2LOG(x) (x)
39 #define YDEV2LOG(y) (y)
42 #define XDEV2LOGREL(x) (x)
43 #define YDEV2LOGREL(y) (y)
46 * Have the same macros as for XView but not for every operation:
47 * just for calculating window/viewport extent (a better way of scaling).
52 #define MS_XLOG2DEV(x) LogicalToDevice(x)
54 #define MS_YLOG2DEV(y) LogicalToDevice(y)
57 #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x)
58 #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y)
62 #define MS_XDEV2LOG(x) DeviceToLogicalX(x)
64 #define MS_YDEV2LOG(y) DeviceToLogicalY(y)
67 #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x)
68 #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y)
70 #define YSCALE(y) (yorigin - (y))
72 #define wx_round(a) (int)((a)+.5)
76 * Cached blitting, maintaining a cache
77 * of bitmaps required for transparent blitting
78 * instead of constant creation/deletion
81 class wxDCCacheEntry
: public wxObject
84 wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
);
85 wxDCCacheEntry(WXHDC hDC
, int depth
);
96 class WXDLLEXPORT wxDC
: public wxDCBase
102 // implement base class pure virtuals
103 // ----------------------------------
105 virtual void Clear();
107 virtual bool StartDoc(const wxString
& message
);
108 virtual void EndDoc();
110 virtual void StartPage();
111 virtual void EndPage();
113 virtual void SetFont(const wxFont
& font
);
114 virtual void SetPen(const wxPen
& pen
);
115 virtual void SetBrush(const wxBrush
& brush
);
116 virtual void SetBackground(const wxBrush
& brush
);
117 virtual void SetBackgroundMode(int mode
);
118 virtual void SetPalette(const wxPalette
& palette
);
120 virtual void DestroyClippingRegion();
122 virtual wxCoord
GetCharHeight() const;
123 virtual wxCoord
GetCharWidth() const;
124 virtual void DoGetTextExtent(const wxString
& string
,
125 wxCoord
*x
, wxCoord
*y
,
126 wxCoord
*descent
= NULL
,
127 wxCoord
*externalLeading
= NULL
,
128 wxFont
*theFont
= NULL
) const;
130 virtual bool CanDrawBitmap() const;
131 virtual bool CanGetTextExtent() const;
132 virtual int GetDepth() const;
133 virtual wxSize
GetPPI() const;
135 virtual void SetMapMode(int mode
);
136 virtual void SetUserScale(double x
, double y
);
137 virtual void SetSystemScale(double x
, double y
);
138 virtual void SetLogicalScale(double x
, double y
);
139 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
140 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
141 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
142 virtual void SetLogicalFunction(int function
);
144 // implementation from now on
145 // --------------------------
147 virtual void SetRop(WXHDC cdc
);
148 virtual void SelectOldObjects(WXHDC dc
);
150 wxWindow
*GetWindow() const { return m_canvas
; }
151 void SetWindow(wxWindow
*win
) { m_canvas
= win
; }
153 WXHDC
GetHDC() const { return m_hDC
; }
154 void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
)
160 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
161 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
163 // update the internal clip box variables
164 void UpdateClipBox();
166 #if wxUSE_DC_CACHEING
167 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
168 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
170 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
171 static void AddToDCCache(wxDCCacheEntry
* entry
);
172 static void ClearCache();
176 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
177 int style
= wxFLOOD_SURFACE
);
179 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
181 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
182 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
184 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
185 wxCoord x2
, wxCoord y2
,
186 wxCoord xc
, wxCoord yc
);
187 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
188 wxCoord width
, wxCoord height
);
189 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
190 double sa
, double ea
);
192 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
193 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
194 wxCoord width
, wxCoord height
,
196 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
198 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
200 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
201 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
202 bool useMask
= FALSE
);
204 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
205 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
208 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
209 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
210 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
212 // this is gnarly - we can't even call this function DoSetClippingRegion()
213 // because of virtual function hiding
214 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
215 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
216 wxCoord width
, wxCoord height
);
217 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
218 wxCoord
*width
, wxCoord
*height
)
220 GetClippingBox(x
, y
, width
, height
);
223 virtual void DoGetSize(int *width
, int *height
) const;
224 virtual void DoGetSizeMM(int* width
, int* height
) const;
226 virtual void DoDrawLines(int n
, wxPoint points
[],
227 wxCoord xoffset
, wxCoord yoffset
);
228 virtual void DoDrawPolygon(int n
, wxPoint points
[],
229 wxCoord xoffset
, wxCoord yoffset
,
230 int fillStyle
= wxODDEVEN_RULE
);
233 // common part of DoDrawText() and DoDrawRotatedText()
234 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
236 // MSW-specific member variables
240 // the window associated with this DC (may be NULL)
243 wxBitmap m_selectedBitmap
;
245 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
251 // Store all old GDI objects when do a SelectObject, so we can select them
252 // back in (this unselecting user's objects) so we can safely delete the
254 WXHBITMAP m_oldBitmap
;
258 WXHPALETTE m_oldPalette
;
260 #if wxUSE_DC_CACHEING
261 static wxList sm_bitmapCache
;
262 static wxList sm_dcCache
;
265 DECLARE_DYNAMIC_CLASS(wxDC
)
268 // ----------------------------------------------------------------------------
269 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWindows
271 // ----------------------------------------------------------------------------
273 class WXDLLEXPORT wxDCTemp
: public wxDC
276 wxDCTemp(WXHDC hdc
) { SetHDC(hdc
); }
277 virtual ~wxDCTemp() { SetHDC((WXHDC
)NULL
); }