]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.h | |
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 |
a23fd0e1 | 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 RR |
19 | #include "wx/defs.h" |
20 | #include "wx/dc.h" | |
21 | ||
e6f1ad22 HH |
22 | // --------------------------------------------------------------------------- |
23 | // macros | |
24 | // --------------------------------------------------------------------------- | |
25 | ||
0cbff120 JS |
26 | #if wxUSE_DC_CACHEING |
27 | /* | |
28 | * Cached blitting, maintaining a cache | |
29 | * of bitmaps required for transparent blitting | |
30 | * instead of constant creation/deletion | |
31 | */ | |
32 | ||
33 | class wxDCCacheEntry: public wxObject | |
34 | { | |
35 | public: | |
36 | wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth); | |
37 | wxDCCacheEntry(WXHDC hDC, int depth); | |
38 | ~wxDCCacheEntry(); | |
39 | ||
40 | WXHBITMAP m_bitmap; | |
41 | WXHDC m_dc; | |
42 | int m_width; | |
43 | int m_height; | |
44 | int m_depth; | |
45 | }; | |
46 | #endif | |
47 | ||
a23fd0e1 | 48 | class WXDLLEXPORT wxDC : public wxDCBase |
2bda0e17 | 49 | { |
2bda0e17 | 50 | public: |
a23fd0e1 VZ |
51 | wxDC(); |
52 | ~wxDC(); | |
53 | ||
54 | // implement base class pure virtuals | |
55 | // ---------------------------------- | |
56 | ||
57 | virtual void Clear(); | |
58 | ||
59 | virtual bool StartDoc(const wxString& message); | |
60 | virtual void EndDoc(); | |
61 | ||
62 | virtual void StartPage(); | |
63 | virtual void EndPage(); | |
64 | ||
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); | |
d275c7eb | 70 | #if wxUSE_PALETTE |
a23fd0e1 | 71 | virtual void SetPalette(const wxPalette& palette); |
d275c7eb | 72 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
73 | |
74 | virtual void DestroyClippingRegion(); | |
75 | ||
72cdf4c9 VZ |
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; | |
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; } | |
116 | void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) | |
117 | { | |
118 | m_hDC = dc; | |
119 | m_bOwnsDC = bOwnsDC; | |
120 | } | |
2bda0e17 | 121 | |
4b7f2165 VZ |
122 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } |
123 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
124 | ||
1e6feb95 VZ |
125 | // update the internal clip box variables |
126 | void UpdateClipBox(); | |
127 | ||
0cbff120 JS |
128 | #if wxUSE_DC_CACHEING |
129 | static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h); | |
130 | static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC); | |
131 | ||
132 | static void AddToBitmapCache(wxDCCacheEntry* entry); | |
133 | static void AddToDCCache(wxDCCacheEntry* entry); | |
134 | static void ClearCache(); | |
135 | #endif | |
136 | ||
a23fd0e1 | 137 | protected: |
387ebd3e | 138 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
a23fd0e1 VZ |
139 | int style = wxFLOOD_SURFACE); |
140 | ||
72cdf4c9 | 141 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; |
a23fd0e1 | 142 | |
72cdf4c9 VZ |
143 | virtual void DoDrawPoint(wxCoord x, wxCoord y); |
144 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
a23fd0e1 | 145 | |
72cdf4c9 VZ |
146 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
147 | wxCoord x2, wxCoord y2, | |
148 | wxCoord xc, wxCoord yc); | |
cd9da200 VZ |
149 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
150 | wxCoord width, wxCoord height); | |
72cdf4c9 | 151 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
152 | double sa, double ea); |
153 | ||
72cdf4c9 VZ |
154 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
155 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
156 | wxCoord width, wxCoord height, | |
a23fd0e1 | 157 | double radius); |
72cdf4c9 | 158 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
a23fd0e1 | 159 | |
72cdf4c9 | 160 | virtual void DoCrossHair(wxCoord x, wxCoord y); |
a23fd0e1 | 161 | |
72cdf4c9 VZ |
162 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); |
163 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
a23fd0e1 VZ |
164 | bool useMask = FALSE); |
165 | ||
72cdf4c9 | 166 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); |
95724b1a VZ |
167 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, |
168 | double angle); | |
a23fd0e1 | 169 | |
72cdf4c9 VZ |
170 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
171 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
0cbff120 | 172 | int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); |
a23fd0e1 VZ |
173 | |
174 | // this is gnarly - we can't even call this function DoSetClippingRegion() | |
175 | // because of virtual function hiding | |
176 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
72cdf4c9 VZ |
177 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
178 | wxCoord width, wxCoord height); | |
179 | virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, | |
180 | wxCoord *width, wxCoord *height) | |
a23fd0e1 VZ |
181 | { |
182 | GetClippingBox(x, y, width, height); | |
183 | } | |
184 | ||
185 | virtual void DoGetSize(int *width, int *height) const; | |
186 | virtual void DoGetSizeMM(int* width, int* height) const; | |
187 | ||
188 | virtual void DoDrawLines(int n, wxPoint points[], | |
72cdf4c9 | 189 | wxCoord xoffset, wxCoord yoffset); |
a23fd0e1 | 190 | virtual void DoDrawPolygon(int n, wxPoint points[], |
72cdf4c9 | 191 | wxCoord xoffset, wxCoord yoffset, |
a23fd0e1 | 192 | int fillStyle = wxODDEVEN_RULE); |
6e76b35d VZ |
193 | virtual void DoDrawPolyPolygon(int n, int start[], wxPoint points[], |
194 | wxCoord xoffset, wxCoord yoffset, | |
195 | int fillStyle = wxODDEVEN_RULE); | |
6a6c0a8b | 196 | |
a23fd0e1 | 197 | |
574c939e KB |
198 | #if wxUSE_PALETTE |
199 | // MSW specific, select a logical palette into the HDC | |
200 | // (tell windows to translate pixel from other palettes to our custom one | |
201 | // and vice versa) | |
202 | // Realize tells it to also reset the system palette to this one. | |
b95edd47 VZ |
203 | void DoSelectPalette(bool realize = FALSE); |
204 | ||
574c939e KB |
205 | // Find out what palette our parent window has, then select it into the dc |
206 | void InitializePalette(); | |
b95edd47 VZ |
207 | #endif // wxUSE_PALETTE |
208 | ||
4314ec48 VZ |
209 | // common part of DoDrawText() and DoDrawRotatedText() |
210 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
211 | ||
5230934a VZ |
212 | // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion() |
213 | void SetClippingHrgn(WXHRGN hrgn); | |
214 | ||
a23fd0e1 | 215 | // MSW-specific member variables |
1e2081a1 | 216 | // ----------------------------- |
a23fd0e1 VZ |
217 | |
218 | // the window associated with this DC (may be NULL) | |
219 | wxWindow *m_canvas; | |
220 | ||
221 | wxBitmap m_selectedBitmap; | |
222 | ||
223 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
224 | bool m_bOwnsDC:1; | |
225 | ||
b5badcb5 | 226 | // our HDC |
a23fd0e1 | 227 | WXHDC m_hDC; |
a23fd0e1 VZ |
228 | |
229 | // Store all old GDI objects when do a SelectObject, so we can select them | |
230 | // back in (this unselecting user's objects) so we can safely delete the | |
231 | // DC. | |
232 | WXHBITMAP m_oldBitmap; | |
233 | WXHPEN m_oldPen; | |
234 | WXHBRUSH m_oldBrush; | |
235 | WXHFONT m_oldFont; | |
d275c7eb VZ |
236 | |
237 | #if wxUSE_PALETTE | |
a23fd0e1 | 238 | WXHPALETTE m_oldPalette; |
d275c7eb | 239 | #endif // wxUSE_PALETTE |
7561aacd | 240 | |
0cbff120 JS |
241 | #if wxUSE_DC_CACHEING |
242 | static wxList sm_bitmapCache; | |
243 | static wxList sm_dcCache; | |
244 | #endif | |
245 | ||
7561aacd | 246 | DECLARE_DYNAMIC_CLASS(wxDC) |
22f3361e | 247 | DECLARE_NO_COPY_CLASS(wxDC) |
7561aacd VZ |
248 | }; |
249 | ||
250 | // ---------------------------------------------------------------------------- | |
251 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWindows | |
252 | // only/mainly) | |
253 | // ---------------------------------------------------------------------------- | |
254 | ||
255 | class WXDLLEXPORT wxDCTemp : public wxDC | |
256 | { | |
257 | public: | |
258 | wxDCTemp(WXHDC hdc) { SetHDC(hdc); } | |
259 | virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); } | |
fc7a2a60 VZ |
260 | |
261 | private: | |
262 | DECLARE_NO_COPY_CLASS(wxDCTemp) | |
2bda0e17 KB |
263 | }; |
264 | ||
2bda0e17 | 265 | #endif |
bbcdf8bc | 266 | // _WX_DC_H_ |