]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ad0ac642 | 2 | // Name: wx/msw/dc.h |
2bda0e17 KB |
3 | // Purpose: wxDC class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
bbcdf8bc | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_DC_H_ |
13 | #define _WX_DC_H_ | |
2bda0e17 | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a23fd0e1 | 16 | #pragma interface "dc.h" |
2bda0e17 KB |
17 | #endif |
18 | ||
2662e49e | 19 | #include "wx/defs.h" |
2662e49e | 20 | |
e6f1ad22 HH |
21 | // --------------------------------------------------------------------------- |
22 | // macros | |
23 | // --------------------------------------------------------------------------- | |
24 | ||
0cbff120 JS |
25 | #if wxUSE_DC_CACHEING |
26 | /* | |
27 | * Cached blitting, maintaining a cache | |
28 | * of bitmaps required for transparent blitting | |
29 | * instead of constant creation/deletion | |
30 | */ | |
31 | ||
32 | class wxDCCacheEntry: public wxObject | |
33 | { | |
34 | public: | |
35 | wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth); | |
36 | wxDCCacheEntry(WXHDC hDC, int depth); | |
37 | ~wxDCCacheEntry(); | |
38 | ||
39 | WXHBITMAP m_bitmap; | |
40 | WXHDC m_dc; | |
41 | int m_width; | |
42 | int m_height; | |
43 | int m_depth; | |
44 | }; | |
45 | #endif | |
46 | ||
a23fd0e1 | 47 | class WXDLLEXPORT wxDC : public wxDCBase |
2bda0e17 | 48 | { |
2bda0e17 | 49 | public: |
a23fd0e1 VZ |
50 | wxDC(); |
51 | ~wxDC(); | |
52 | ||
53 | // implement base class pure virtuals | |
54 | // ---------------------------------- | |
55 | ||
56 | virtual void Clear(); | |
57 | ||
58 | virtual bool StartDoc(const wxString& message); | |
59 | virtual void EndDoc(); | |
60 | ||
61 | virtual void StartPage(); | |
62 | virtual void EndPage(); | |
63 | ||
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); | |
d275c7eb | 69 | #if wxUSE_PALETTE |
a23fd0e1 | 70 | virtual void SetPalette(const wxPalette& palette); |
d275c7eb | 71 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
72 | |
73 | virtual void DestroyClippingRegion(); | |
74 | ||
72cdf4c9 VZ |
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; | |
553aa032 | 82 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; |
a23fd0e1 VZ |
83 | |
84 | virtual bool CanDrawBitmap() const; | |
85 | virtual bool CanGetTextExtent() const; | |
86 | virtual int GetDepth() const; | |
87 | virtual wxSize GetPPI() const; | |
88 | ||
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); | |
72cdf4c9 VZ |
93 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); |
94 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
a23fd0e1 VZ |
95 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); |
96 | virtual void SetLogicalFunction(int function); | |
97 | ||
98 | // implementation from now on | |
99 | // -------------------------- | |
100 | ||
101 | virtual void SetRop(WXHDC cdc); | |
a23fd0e1 VZ |
102 | virtual void SelectOldObjects(WXHDC dc); |
103 | ||
104 | wxWindow *GetWindow() const { return m_canvas; } | |
b95edd47 VZ |
105 | void SetWindow(wxWindow *win) |
106 | { | |
574c939e | 107 | m_canvas = win; |
b95edd47 | 108 | |
574c939e KB |
109 | #if wxUSE_PALETTE |
110 | // if we have palettes use the correct one for this window | |
111 | InitializePalette(); | |
b95edd47 VZ |
112 | #endif // wxUSE_PALETTE |
113 | } | |
a23fd0e1 VZ |
114 | |
115 | WXHDC GetHDC() const { return m_hDC; } | |
d71cc120 | 116 | void SetHDC(WXHDC dc, bool bOwnsDC = false) |
a23fd0e1 VZ |
117 | { |
118 | m_hDC = dc; | |
119 | m_bOwnsDC = bOwnsDC; | |
2e76da54 VZ |
120 | |
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 | |
124 | m_clipping = true; | |
125 | m_clipX1 = | |
126 | m_clipX2 = 0; | |
a23fd0e1 | 127 | } |
2bda0e17 | 128 | |
4b7f2165 VZ |
129 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } |
130 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
131 | ||
1e6feb95 VZ |
132 | // update the internal clip box variables |
133 | void UpdateClipBox(); | |
134 | ||
0cbff120 JS |
135 | #if wxUSE_DC_CACHEING |
136 | static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h); | |
137 | static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC); | |
138 | ||
139 | static void AddToBitmapCache(wxDCCacheEntry* entry); | |
140 | static void AddToDCCache(wxDCCacheEntry* entry); | |
141 | static void ClearCache(); | |
142 | #endif | |
143 | ||
a23fd0e1 | 144 | protected: |
387ebd3e | 145 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
a23fd0e1 VZ |
146 | int style = wxFLOOD_SURFACE); |
147 | ||
72cdf4c9 | 148 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; |
a23fd0e1 | 149 | |
72cdf4c9 VZ |
150 | virtual void DoDrawPoint(wxCoord x, wxCoord y); |
151 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
a23fd0e1 | 152 | |
72cdf4c9 VZ |
153 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
154 | wxCoord x2, wxCoord y2, | |
155 | wxCoord xc, wxCoord yc); | |
cd9da200 VZ |
156 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
157 | wxCoord width, wxCoord height); | |
72cdf4c9 | 158 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
159 | double sa, double ea); |
160 | ||
72cdf4c9 VZ |
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, | |
a23fd0e1 | 164 | double radius); |
72cdf4c9 | 165 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
a23fd0e1 | 166 | |
ad0ac642 WS |
167 | #if wxUSE_SPLINES |
168 | virtual void DoDrawSpline(wxList *points); | |
169 | #endif | |
170 | ||
72cdf4c9 | 171 | virtual void DoCrossHair(wxCoord x, wxCoord y); |
a23fd0e1 | 172 | |
72cdf4c9 VZ |
173 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); |
174 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
d71cc120 | 175 | bool useMask = false); |
a23fd0e1 | 176 | |
72cdf4c9 | 177 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); |
95724b1a VZ |
178 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, |
179 | double angle); | |
a23fd0e1 | 180 | |
72cdf4c9 VZ |
181 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
182 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
d71cc120 | 183 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); |
a23fd0e1 VZ |
184 | |
185 | // this is gnarly - we can't even call this function DoSetClippingRegion() | |
186 | // because of virtual function hiding | |
187 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
72cdf4c9 VZ |
188 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
189 | wxCoord width, wxCoord height); | |
2e76da54 VZ |
190 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
191 | wxCoord *w, wxCoord *h) const; | |
a23fd0e1 VZ |
192 | |
193 | virtual void DoGetSize(int *width, int *height) const; | |
194 | virtual void DoGetSizeMM(int* width, int* height) const; | |
195 | ||
196 | virtual void DoDrawLines(int n, wxPoint points[], | |
72cdf4c9 | 197 | wxCoord xoffset, wxCoord yoffset); |
a23fd0e1 | 198 | virtual void DoDrawPolygon(int n, wxPoint points[], |
72cdf4c9 | 199 | wxCoord xoffset, wxCoord yoffset, |
a23fd0e1 | 200 | int fillStyle = wxODDEVEN_RULE); |
793db755 | 201 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], |
6e76b35d VZ |
202 | wxCoord xoffset, wxCoord yoffset, |
203 | int fillStyle = wxODDEVEN_RULE); | |
6a6c0a8b | 204 | |
a23fd0e1 | 205 | |
574c939e KB |
206 | #if wxUSE_PALETTE |
207 | // MSW specific, select a logical palette into the HDC | |
208 | // (tell windows to translate pixel from other palettes to our custom one | |
209 | // and vice versa) | |
210 | // Realize tells it to also reset the system palette to this one. | |
d71cc120 | 211 | void DoSelectPalette(bool realize = false); |
b95edd47 | 212 | |
574c939e KB |
213 | // Find out what palette our parent window has, then select it into the dc |
214 | void InitializePalette(); | |
b95edd47 VZ |
215 | #endif // wxUSE_PALETTE |
216 | ||
4314ec48 VZ |
217 | // common part of DoDrawText() and DoDrawRotatedText() |
218 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
219 | ||
5230934a VZ |
220 | // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion() |
221 | void SetClippingHrgn(WXHRGN hrgn); | |
222 | ||
a23fd0e1 | 223 | // MSW-specific member variables |
1e2081a1 | 224 | // ----------------------------- |
a23fd0e1 VZ |
225 | |
226 | // the window associated with this DC (may be NULL) | |
227 | wxWindow *m_canvas; | |
228 | ||
229 | wxBitmap m_selectedBitmap; | |
230 | ||
231 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
232 | bool m_bOwnsDC:1; | |
233 | ||
b5badcb5 | 234 | // our HDC |
a23fd0e1 | 235 | WXHDC m_hDC; |
a23fd0e1 VZ |
236 | |
237 | // Store all old GDI objects when do a SelectObject, so we can select them | |
238 | // back in (this unselecting user's objects) so we can safely delete the | |
239 | // DC. | |
240 | WXHBITMAP m_oldBitmap; | |
241 | WXHPEN m_oldPen; | |
242 | WXHBRUSH m_oldBrush; | |
243 | WXHFONT m_oldFont; | |
d275c7eb VZ |
244 | |
245 | #if wxUSE_PALETTE | |
a23fd0e1 | 246 | WXHPALETTE m_oldPalette; |
d275c7eb | 247 | #endif // wxUSE_PALETTE |
7561aacd | 248 | |
0cbff120 JS |
249 | #if wxUSE_DC_CACHEING |
250 | static wxList sm_bitmapCache; | |
251 | static wxList sm_dcCache; | |
252 | #endif | |
253 | ||
7561aacd | 254 | DECLARE_DYNAMIC_CLASS(wxDC) |
22f3361e | 255 | DECLARE_NO_COPY_CLASS(wxDC) |
7561aacd VZ |
256 | }; |
257 | ||
258 | // ---------------------------------------------------------------------------- | |
77ffb593 | 259 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets |
7561aacd VZ |
260 | // only/mainly) |
261 | // ---------------------------------------------------------------------------- | |
262 | ||
263 | class WXDLLEXPORT wxDCTemp : public wxDC | |
264 | { | |
265 | public: | |
266 | wxDCTemp(WXHDC hdc) { SetHDC(hdc); } | |
267 | virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); } | |
fc7a2a60 VZ |
268 | |
269 | private: | |
270 | DECLARE_NO_COPY_CLASS(wxDCTemp) | |
2bda0e17 KB |
271 | }; |
272 | ||
2bda0e17 | 273 | #endif |
bbcdf8bc | 274 | // _WX_DC_H_ |