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)
74 class WXDLLEXPORT wxDC
: public wxDCBase
76 DECLARE_DYNAMIC_CLASS(wxDC
)
82 // implement base class pure virtuals
83 // ----------------------------------
87 virtual bool StartDoc(const wxString
& message
);
88 virtual void EndDoc();
90 virtual void StartPage();
91 virtual void EndPage();
93 virtual void SetFont(const wxFont
& font
);
94 virtual void SetPen(const wxPen
& pen
);
95 virtual void SetBrush(const wxBrush
& brush
);
96 virtual void SetBackground(const wxBrush
& brush
);
97 virtual void SetBackgroundMode(int mode
);
98 virtual void SetPalette(const wxPalette
& palette
);
100 virtual void DestroyClippingRegion();
102 virtual wxCoord
GetCharHeight() const;
103 virtual wxCoord
GetCharWidth() const;
104 virtual void DoGetTextExtent(const wxString
& string
,
105 wxCoord
*x
, wxCoord
*y
,
106 wxCoord
*descent
= NULL
,
107 wxCoord
*externalLeading
= NULL
,
108 wxFont
*theFont
= NULL
) const;
110 virtual bool CanDrawBitmap() const;
111 virtual bool CanGetTextExtent() const;
112 virtual int GetDepth() const;
113 virtual wxSize
GetPPI() const;
115 virtual void SetMapMode(int mode
);
116 virtual void SetUserScale(double x
, double y
);
117 virtual void SetSystemScale(double x
, double y
);
118 virtual void SetLogicalScale(double x
, double y
);
119 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
120 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
121 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
122 virtual void SetLogicalFunction(int function
);
124 // implementation from now on
125 // --------------------------
127 virtual void SetRop(WXHDC cdc
);
128 virtual void DoClipping(WXHDC cdc
);
129 virtual void SelectOldObjects(WXHDC dc
);
131 wxWindow
*GetWindow() const { return m_canvas
; }
132 void SetWindow(wxWindow
*win
) { m_canvas
= win
; }
134 WXHDC
GetHDC() const { return m_hDC
; }
135 void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
)
141 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
142 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
145 virtual void 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
);
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
);
192 virtual void DoGetSize(int *width
, int *height
) const;
193 virtual void DoGetSizeMM(int* width
, int* height
) const;
195 virtual void DoDrawLines(int n
, wxPoint points
[],
196 wxCoord xoffset
, wxCoord yoffset
);
197 virtual void DoDrawPolygon(int n
, wxPoint points
[],
198 wxCoord xoffset
, wxCoord yoffset
,
199 int fillStyle
= wxODDEVEN_RULE
);
202 virtual void DoDrawSpline(wxList
*points
);
203 #endif // wxUSE_SPLINES
205 // common part of DoDrawText() and DoDrawRotatedText()
206 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
208 // MSW-specific member variables
212 // the window associated with this DC (may be NULL)
215 wxBitmap m_selectedBitmap
;
217 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
220 // our HDC and its usage count: we only free it when the usage count drops
225 // Store all old GDI objects when do a SelectObject, so we can select them
226 // back in (this unselecting user's objects) so we can safely delete the
228 WXHBITMAP m_oldBitmap
;
232 WXHPALETTE m_oldPalette
;