]>
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 | ||
e2fc40b4 VZ |
12 | #ifndef _WX_PALM_DC_H_ |
13 | #define _WX_PALM_DC_H_ | |
ffecfa5a | 14 | |
ffecfa5a JS |
15 | #include "wx/defs.h" |
16 | #include "wx/dc.h" | |
17 | ||
18 | // --------------------------------------------------------------------------- | |
19 | // macros | |
20 | // --------------------------------------------------------------------------- | |
21 | ||
22 | #if wxUSE_DC_CACHEING | |
23 | /* | |
24 | * Cached blitting, maintaining a cache | |
25 | * of bitmaps required for transparent blitting | |
26 | * instead of constant creation/deletion | |
27 | */ | |
28 | ||
29 | class wxDCCacheEntry: public wxObject | |
30 | { | |
31 | public: | |
32 | wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth); | |
33 | wxDCCacheEntry(WXHDC hDC, int depth); | |
d3c7fc99 | 34 | virtual ~wxDCCacheEntry(); |
ffecfa5a JS |
35 | |
36 | WXHBITMAP m_bitmap; | |
37 | WXHDC m_dc; | |
38 | int m_width; | |
39 | int m_height; | |
40 | int m_depth; | |
41 | }; | |
42 | #endif | |
43 | ||
e2fc40b4 VZ |
44 | // this is an ABC: use one of the derived classes to create a DC associated |
45 | // with a window, screen, printer and so on | |
53a2db12 | 46 | class WXDLLIMPEXP_CORE wxPalmDCImpl: public wxDCImpl |
ffecfa5a JS |
47 | { |
48 | public: | |
e2fc40b4 VZ |
49 | wxPalmDCImpl(wxDC *owner, WXHDC hDC); |
50 | virtual ~wxPalmDCImpl(); | |
ffecfa5a JS |
51 | |
52 | // implement base class pure virtuals | |
53 | // ---------------------------------- | |
54 | ||
55 | virtual void Clear(); | |
56 | ||
57 | virtual bool StartDoc(const wxString& message); | |
58 | virtual void EndDoc(); | |
59 | ||
60 | virtual void StartPage(); | |
61 | virtual void EndPage(); | |
62 | ||
63 | virtual void SetFont(const wxFont& font); | |
64 | virtual void SetPen(const wxPen& pen); | |
65 | virtual void SetBrush(const wxBrush& brush); | |
66 | virtual void SetBackground(const wxBrush& brush); | |
67 | virtual void SetBackgroundMode(int mode); | |
68 | #if wxUSE_PALETTE | |
69 | virtual void SetPalette(const wxPalette& palette); | |
70 | #endif // wxUSE_PALETTE | |
71 | ||
72 | virtual void DestroyClippingRegion(); | |
73 | ||
74 | virtual wxCoord GetCharHeight() const; | |
75 | virtual wxCoord GetCharWidth() const; | |
ffecfa5a JS |
76 | |
77 | virtual bool CanDrawBitmap() const; | |
78 | virtual bool CanGetTextExtent() const; | |
79 | virtual int GetDepth() const; | |
80 | virtual wxSize GetPPI() const; | |
81 | ||
e2fc40b4 | 82 | |
ffecfa5a JS |
83 | virtual void SetMapMode(int mode); |
84 | virtual void SetUserScale(double x, double y); | |
ffecfa5a JS |
85 | virtual void SetLogicalScale(double x, double y); |
86 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); | |
87 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
88 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); | |
e2fc40b4 | 89 | |
ffecfa5a JS |
90 | virtual void SetLogicalFunction(int function); |
91 | ||
92 | // implementation from now on | |
93 | // -------------------------- | |
94 | ||
95 | virtual void SetRop(WXHDC cdc); | |
96 | virtual void SelectOldObjects(WXHDC dc); | |
97 | ||
ffecfa5a JS |
98 | void SetWindow(wxWindow *win) |
99 | { | |
e2fc40b4 | 100 | m_window = win; |
ffecfa5a JS |
101 | |
102 | #if wxUSE_PALETTE | |
103 | // if we have palettes use the correct one for this window | |
104 | InitializePalette(); | |
105 | #endif // wxUSE_PALETTE | |
106 | } | |
107 | ||
108 | WXHDC GetHDC() const { return m_hDC; } | |
e2fc40b4 | 109 | void SetHDC(WXHDC dc, bool bOwnsDC = false) |
ffecfa5a JS |
110 | { |
111 | m_hDC = dc; | |
112 | m_bOwnsDC = bOwnsDC; | |
113 | ||
114 | // we might have a pre existing clipping region, make sure that we | |
115 | // return it if asked -- but avoid calling ::GetClipBox() right now as | |
116 | // it could be unnecessary wasteful | |
117 | m_clipping = true; | |
118 | m_clipX1 = | |
119 | m_clipX2 = 0; | |
120 | } | |
121 | ||
122 | const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; } | |
123 | wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; } | |
124 | ||
125 | // update the internal clip box variables | |
126 | void UpdateClipBox(); | |
127 | ||
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 | ||
e2fc40b4 VZ |
137 | // RTL related functions |
138 | // --------------------- | |
139 | ||
140 | // get or change the layout direction (LTR or RTL) for this dc, | |
141 | // wxLayout_Default is returned if layout direction is not supported | |
142 | virtual wxLayoutDirection GetLayoutDirection() const; | |
143 | virtual void SetLayoutDirection(wxLayoutDirection dir); | |
144 | ||
ffecfa5a | 145 | protected: |
e2fc40b4 VZ |
146 | void Init() |
147 | { | |
148 | m_bOwnsDC = false; | |
149 | m_hDC = NULL; | |
150 | ||
151 | m_oldBitmap = NULL; | |
152 | m_oldPen = NULL; | |
153 | m_oldBrush = NULL; | |
154 | m_oldFont = NULL; | |
155 | ||
156 | #if wxUSE_PALETTE | |
157 | m_oldPalette = NULL; | |
158 | #endif // wxUSE_PALETTE | |
159 | } | |
160 | ||
161 | // create an uninitialized DC: this should be only used by the derived | |
162 | // classes | |
163 | wxPalmDCImpl( wxDC *owner ) : wxDCImpl( owner ) { Init(); } | |
164 | ||
165 | void RealizeScaleAndOrigin(); | |
166 | ||
167 | public: | |
168 | virtual void DoGetTextExtent(const wxString& string, | |
169 | wxCoord *x, wxCoord *y, | |
170 | wxCoord *descent = NULL, | |
171 | wxCoord *externalLeading = NULL, | |
172 | const wxFont *theFont = NULL) const; | |
173 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; | |
174 | ||
ffecfa5a JS |
175 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
176 | int style = wxFLOOD_SURFACE); | |
177 | ||
e2fc40b4 VZ |
178 | virtual void DoGradientFillLinear(const wxRect& rect, |
179 | const wxColour& initialColour, | |
180 | const wxColour& destColour, | |
181 | wxDirection nDirection = wxEAST); | |
182 | ||
ffecfa5a JS |
183 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; |
184 | ||
185 | virtual void DoDrawPoint(wxCoord x, wxCoord y); | |
186 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
187 | ||
188 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
189 | wxCoord x2, wxCoord y2, | |
190 | wxCoord xc, wxCoord yc); | |
191 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
192 | wxCoord width, wxCoord height); | |
193 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
194 | double sa, double ea); | |
195 | ||
196 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
197 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
198 | wxCoord width, wxCoord height, | |
199 | double radius); | |
200 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
201 | ||
e2fc40b4 VZ |
202 | #if wxUSE_SPLINES |
203 | virtual void DoDrawSpline(const wxPointList *points); | |
204 | #endif | |
205 | ||
ffecfa5a JS |
206 | virtual void DoCrossHair(wxCoord x, wxCoord y); |
207 | ||
208 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); | |
209 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
e2fc40b4 | 210 | bool useMask = false); |
ffecfa5a JS |
211 | |
212 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); | |
213 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, | |
214 | double angle); | |
215 | ||
216 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
217 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
e2fc40b4 VZ |
218 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); |
219 | ||
220 | virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest, | |
221 | wxCoord dstWidth, wxCoord dstHeight, | |
222 | wxDC *source, | |
223 | wxCoord xsrc, wxCoord ysrc, | |
224 | wxCoord srcWidth, wxCoord srcHeight, | |
225 | int rop = wxCOPY, bool useMask = false, | |
226 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord); | |
ffecfa5a | 227 | |
ffecfa5a JS |
228 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
229 | wxCoord width, wxCoord height); | |
fdaad94e | 230 | virtual void DoSetDeviceClippingRegion(const wxRegion& region); |
ffecfa5a JS |
231 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
232 | wxCoord *w, wxCoord *h) const; | |
233 | ||
ffecfa5a JS |
234 | virtual void DoGetSizeMM(int* width, int* height) const; |
235 | ||
236 | virtual void DoDrawLines(int n, wxPoint points[], | |
237 | wxCoord xoffset, wxCoord yoffset); | |
238 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
239 | wxCoord xoffset, wxCoord yoffset, | |
240 | int fillStyle = wxODDEVEN_RULE); | |
241 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], | |
242 | wxCoord xoffset, wxCoord yoffset, | |
243 | int fillStyle = wxODDEVEN_RULE); | |
e2fc40b4 VZ |
244 | virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const |
245 | { | |
246 | return subrect == NULL ? GetSelectedBitmap() | |
247 | : GetSelectedBitmap().GetSubBitmap(*subrect); | |
248 | } | |
ffecfa5a JS |
249 | |
250 | ||
251 | #if wxUSE_PALETTE | |
252 | // MSW specific, select a logical palette into the HDC | |
253 | // (tell windows to translate pixel from other palettes to our custom one | |
254 | // and vice versa) | |
255 | // Realize tells it to also reset the system palette to this one. | |
e2fc40b4 | 256 | void DoSelectPalette(bool realize = false); |
ffecfa5a JS |
257 | |
258 | // Find out what palette our parent window has, then select it into the dc | |
259 | void InitializePalette(); | |
260 | #endif // wxUSE_PALETTE | |
261 | ||
e2fc40b4 | 262 | protected: |
ffecfa5a JS |
263 | // common part of DoDrawText() and DoDrawRotatedText() |
264 | void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); | |
265 | ||
e2fc40b4 VZ |
266 | // implementation of DoGetSize() for wxScreen/PrinterDC: this simply |
267 | // returns the size of the entire device this DC is associated with | |
268 | // | |
269 | // notice that we intentionally put it in a separate function instead of | |
270 | // DoGetSize() itself because we want it to remain pure virtual both | |
271 | // because each derived class should take care to define it as needed (this | |
272 | // implementation is not at all always appropriate) and because we want | |
273 | // wxDC to be an ABC to prevent it from being created directly | |
274 | void GetDeviceSize(int *width, int *height) const; | |
275 | ||
276 | ||
ffecfa5a JS |
277 | // MSW-specific member variables |
278 | // ----------------------------- | |
279 | ||
280 | // the window associated with this DC (may be NULL) | |
281 | wxWindow *m_canvas; | |
282 | ||
283 | wxBitmap m_selectedBitmap; | |
284 | ||
285 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
286 | bool m_bOwnsDC:1; | |
287 | ||
288 | // our HDC | |
289 | WXHDC m_hDC; | |
290 | ||
291 | // Store all old GDI objects when do a SelectObject, so we can select them | |
292 | // back in (this unselecting user's objects) so we can safely delete the | |
293 | // DC. | |
294 | WXHBITMAP m_oldBitmap; | |
295 | WXHPEN m_oldPen; | |
296 | WXHBRUSH m_oldBrush; | |
297 | WXHFONT m_oldFont; | |
298 | ||
299 | #if wxUSE_PALETTE | |
300 | WXHPALETTE m_oldPalette; | |
301 | #endif // wxUSE_PALETTE | |
302 | ||
303 | #if wxUSE_DC_CACHEING | |
e2fc40b4 VZ |
304 | static wxObjectList sm_bitmapCache; |
305 | static wxObjectList sm_dcCache; | |
ffecfa5a JS |
306 | #endif |
307 | ||
e2fc40b4 VZ |
308 | DECLARE_CLASS(wxPalmDCImpl) |
309 | DECLARE_NO_COPY_CLASS(wxPalmDCImpl) | |
ffecfa5a JS |
310 | }; |
311 | ||
312 | // ---------------------------------------------------------------------------- | |
313 | // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets | |
314 | // only/mainly) | |
315 | // ---------------------------------------------------------------------------- | |
316 | ||
53a2db12 | 317 | class WXDLLIMPEXP_CORE wxDCTempImpl : public wxPalmDCImpl |
ffecfa5a JS |
318 | { |
319 | public: | |
e2fc40b4 VZ |
320 | // construct a temporary DC with the specified HDC and size (it should be |
321 | // specified whenever we know it for this HDC) | |
322 | wxDCTempImpl(wxDC *owner, WXHDC hdc, const wxSize& size ) | |
323 | : wxPalmDCImpl( owner, hdc ), | |
324 | m_size(size) | |
325 | { | |
326 | } | |
327 | ||
328 | virtual ~wxDCTempImpl() | |
329 | { | |
330 | // prevent base class dtor from freeing it | |
331 | SetHDC((WXHDC)NULL); | |
332 | } | |
333 | ||
334 | virtual void DoGetSize(int *w, int *h) const | |
335 | { | |
336 | wxASSERT_MSG( m_size.IsFullySpecified(), | |
337 | _T("size of this DC hadn't been set and is unknown") ); | |
338 | ||
339 | if ( w ) | |
340 | *w = m_size.x; | |
341 | if ( h ) | |
342 | *h = m_size.y; | |
343 | } | |
ffecfa5a JS |
344 | |
345 | private: | |
e2fc40b4 VZ |
346 | // size of this DC must be explicitly set by SetSize() as we have no way to |
347 | // find it ourselves | |
348 | const wxSize m_size; | |
349 | ||
350 | DECLARE_NO_COPY_CLASS(wxDCTempImpl) | |
351 | }; | |
352 | ||
53a2db12 | 353 | class WXDLLIMPEXP_CORE wxDCTemp : public wxDC |
e2fc40b4 VZ |
354 | { |
355 | public: | |
356 | wxDCTemp(WXHDC hdc, const wxSize& size = wxDefaultSize) | |
357 | : wxDC(new wxDCTempImpl(this, hdc, size)) | |
358 | { | |
359 | } | |
ffecfa5a JS |
360 | }; |
361 | ||
362 | #endif | |
e2fc40b4 | 363 | // _WX_PALM_DC_H_ |