]>
Commit | Line | Data |
---|---|---|
ffecfa5a | 1 | ///////////////////////////////////////////////////////////////////////////// |
e1d63b79 | 2 | // Name: wx/palmos/dc.h |
ffecfa5a | 3 | // Purpose: wxDC class |
e1d63b79 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
ffecfa5a JS |
5 | // Modified by: |
6 | // Created: 10/13/04 | |
e1d63b79 | 7 | // RCS-ID: $Id$ |
ffecfa5a JS |
8 | // Copyright: (c) William Osborne |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_DC_H_ | |
13 | #define _WX_DC_H_ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "dc.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/dc.h" | |
21 | ||
22 | // --------------------------------------------------------------------------- | |
23 | // macros | |
24 | // --------------------------------------------------------------------------- | |
25 | ||
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 | ||
48 | class WXDLLEXPORT wxDC : public wxDCBase | |
49 | { | |
50 | public: | |
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); | |
70 | #if wxUSE_PALETTE | |
71 | virtual void SetPalette(const wxPalette& palette); | |
72 | #endif // wxUSE_PALETTE | |
73 | ||
74 | virtual void DestroyClippingRegion(); | |
75 | ||
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; | |
83 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; | |
84 | ||
85 | virtual bool CanDrawBitmap() const; | |
86 | virtual bool CanGetTextExtent() const; | |
87 | virtual int GetDepth() const; | |
88 | virtual wxSize GetPPI() const; | |
89 | ||
90 | virtual void SetMapMode(int mode); | |
91 | virtual void SetUserScale(double x, double y); | |
92 | virtual void SetSystemScale(double x, double y); | |
93 | virtual void SetLogicalScale(double x, double y); | |
94 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); | |
95 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
96 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); | |
97 | virtual void SetLogicalFunction(int function); | |
98 | ||
99 | // implementation from now on | |
100 | // -------------------------- | |
101 | ||
102 | virtual void SetRop(WXHDC cdc); | |
103 | virtual void SelectOldObjects(WXHDC dc); | |
104 | ||
105 | wxWindow *GetWindow() const { return m_canvas; } | |
106 | void SetWindow(wxWindow *win) | |
107 | { | |
108 | m_canvas = win; | |
109 | ||
110 | #if wxUSE_PALETTE | |
111 | // if we have palettes use the correct one for this window | |
112 | InitializePalette(); | |
113 | #endif // wxUSE_PALETTE | |
114 | } | |
115 | ||
116 | WXHDC GetHDC() const { return m_hDC; } | |
117 | void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) | |
118 | { | |
119 | m_hDC = dc; | |
120 | m_bOwnsDC = bOwnsDC; | |
121 | ||
122 | // we might have a pre existing clipping region, make sure that we | |
123 | // return it if asked -- but avoid calling ::GetClipBox() right now as | |
124 | // it could be unnecessary wasteful | |
125 | m_clipping = true; | |
126 | m_clipX1 = | |
127 | m_clipX2 = 0; | |
128 | } | |
129 | ||
130 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } | |
131 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
132 | ||
133 | // update the internal clip box variables | |
134 | void UpdateClipBox(); | |
135 | ||
136 | #if wxUSE_DC_CACHEING | |
137 | static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h); | |
138 | static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC); | |
139 | ||
140 | static void AddToBitmapCache(wxDCCacheEntry* entry); | |
141 | static void AddToDCCache(wxDCCacheEntry* entry); | |
142 | static void ClearCache(); | |
143 | #endif | |
144 | ||
145 | protected: | |
146 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
147 | int style = wxFLOOD_SURFACE); | |
148 | ||
149 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; | |
150 | ||
151 | virtual void DoDrawPoint(wxCoord x, wxCoord y); | |
152 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
153 | ||
154 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
155 | wxCoord x2, wxCoord y2, | |
156 | wxCoord xc, wxCoord yc); | |
157 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
158 | wxCoord width, wxCoord height); | |
159 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
160 | double sa, double ea); | |
161 | ||
162 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
163 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
164 | wxCoord width, wxCoord height, | |
165 | double radius); | |
166 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
167 | ||
168 | virtual void DoCrossHair(wxCoord x, wxCoord y); | |
169 | ||
170 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); | |
171 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
172 | bool useMask = FALSE); | |
173 | ||
174 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); | |
175 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, | |
176 | double angle); | |
177 | ||
178 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
179 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
180 | int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); | |
181 | ||
182 | // this is gnarly - we can't even call this function DoSetClippingRegion() | |
183 | // because of virtual function hiding | |
184 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
185 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
186 | wxCoord width, wxCoord height); | |
ffecfa5a JS |
187 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
188 | wxCoord *w, wxCoord *h) const; | |
189 | ||
190 | virtual void DoGetSize(int *width, int *height) const; | |
191 | virtual void DoGetSizeMM(int* width, int* height) const; | |
192 | ||
193 | virtual void DoDrawLines(int n, wxPoint points[], | |
194 | wxCoord xoffset, wxCoord yoffset); | |
195 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
196 | wxCoord xoffset, wxCoord yoffset, | |
197 | int fillStyle = wxODDEVEN_RULE); | |
198 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], | |
199 | wxCoord xoffset, wxCoord yoffset, | |
200 | int fillStyle = wxODDEVEN_RULE); | |
201 | ||
202 | ||
203 | #if wxUSE_PALETTE | |
204 | // MSW specific, select a logical palette into the HDC | |
205 | // (tell windows to translate pixel from other palettes to our custom one | |
206 | // and vice versa) | |
207 | // Realize tells it to also reset the system palette to this one. | |
208 | void DoSelectPalette(bool realize = FALSE); | |
209 | ||
210 | // Find out what palette our parent window has, then select it into the dc | |
211 | void InitializePalette(); | |
212 | #endif // wxUSE_PALETTE | |
213 | ||
214 | // common part of DoDrawText() and DoDrawRotatedText() | |
215 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
216 | ||
217 | // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion() | |
218 | void SetClippingHrgn(WXHRGN hrgn); | |
219 | ||
220 | // MSW-specific member variables | |
221 | // ----------------------------- | |
222 | ||
223 | // the window associated with this DC (may be NULL) | |
224 | wxWindow *m_canvas; | |
225 | ||
226 | wxBitmap m_selectedBitmap; | |
227 | ||
228 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
229 | bool m_bOwnsDC:1; | |
230 | ||
231 | // our HDC | |
232 | WXHDC m_hDC; | |
233 | ||
234 | // Store all old GDI objects when do a SelectObject, so we can select them | |
235 | // back in (this unselecting user's objects) so we can safely delete the | |
236 | // DC. | |
237 | WXHBITMAP m_oldBitmap; | |
238 | WXHPEN m_oldPen; | |
239 | WXHBRUSH m_oldBrush; | |
240 | WXHFONT m_oldFont; | |
241 | ||
242 | #if wxUSE_PALETTE | |
243 | WXHPALETTE m_oldPalette; | |
244 | #endif // wxUSE_PALETTE | |
245 | ||
246 | #if wxUSE_DC_CACHEING | |
247 | static wxList sm_bitmapCache; | |
248 | static wxList sm_dcCache; | |
249 | #endif | |
250 | ||
251 | DECLARE_DYNAMIC_CLASS(wxDC) | |
252 | DECLARE_NO_COPY_CLASS(wxDC) | |
253 | }; | |
254 | ||
255 | // ---------------------------------------------------------------------------- | |
256 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets | |
257 | // only/mainly) | |
258 | // ---------------------------------------------------------------------------- | |
259 | ||
260 | class WXDLLEXPORT wxDCTemp : public wxDC | |
261 | { | |
262 | public: | |
263 | wxDCTemp(WXHDC hdc) { SetHDC(hdc); } | |
264 | virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); } | |
265 | ||
266 | private: | |
267 | DECLARE_NO_COPY_CLASS(wxDCTemp) | |
268 | }; | |
269 | ||
270 | #endif | |
271 | // _WX_DC_H_ |