Fixup Blit so it can be used with a source that is a wxBufferedDC,
[wxWidgets.git] / include / wx / dcbuffer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dcbuffer.h
3 // Purpose: wxBufferedDC class
4 // Author: Ron Lee <ron@debian.org>
5 // Modified by: Vadim Zeitlin (refactored, added bg preservation)
6 // Created: 16/03/02
7 // RCS-ID: $Id$
8 // Copyright: (c) Ron Lee
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DCBUFFER_H_
13 #define _WX_DCBUFFER_H_
14
15 #include "wx/dcmemory.h"
16 #include "wx/dcclient.h"
17 #include "wx/window.h"
18
19
20 // I think this patch should be test on wxMac with
21 // wxTEST_PAINTDCDELEGATION as 1, and then with
22 // with wxTEST_MEMORYDCDELEGATION as 1.
23 #define wxTEST_PAINTDCDELEGATION 0
24 #define wxTEST_MEMORYDCDELEGATION 0
25
26
27 // Split platforms into two groups - those which have well-working
28 // double-buffering by default, and those which do not.
29 #if defined(__WXMAC__) || defined(__WXGTK20__)
30 #define wxALWAYS_NATIVE_DOUBLE_BUFFER 1
31 #else
32 #define wxALWAYS_NATIVE_DOUBLE_BUFFER 0
33 #endif
34
35
36 #if wxTEST_PAINTDCDELEGATION || wxTEST_MEMORYDCDELEGATION
37 #undef wxALWAYS_NATIVE_DOUBLE_BUFFER
38 #define wxALWAYS_NATIVE_DOUBLE_BUFFER 0
39 #endif
40
41
42 // ----------------------------------------------------------------------------
43 // Double buffering helper.
44 // ----------------------------------------------------------------------------
45
46 // Assumes the buffer bitmap covers the entire scrolled window,
47 // and prepares the window DC accordingly
48 #define wxBUFFER_VIRTUAL_AREA 0x01
49
50 // Assumes the buffer bitmap only covers the client area;
51 // does not prepare the window DC
52 #define wxBUFFER_CLIENT_AREA 0x02
53
54 class WXDLLEXPORT wxBufferedDC : public wxDC
55 {
56 public:
57 // Default ctor, must subsequently call Init for two stage construction.
58 wxBufferedDC() : wxDC(), m_targetDc(NULL), m_mainDc(NULL),
59 m_buffer(NULL), m_style(0)
60 {
61 }
62
63 // Construct a wxBufferedDC using a user supplied buffer.
64 wxBufferedDC(wxDC *dc,
65 const wxBitmap &buffer = wxNullBitmap,
66 int style = wxBUFFER_CLIENT_AREA)
67 : wxDC(),
68 m_targetDc(NULL),
69 m_mainDc(NULL)
70 {
71 // All other members except dcs are initialized in Init
72 Init(dc, buffer, style);
73 }
74
75 // Construct a wxBufferedDC with an internal buffer of 'area'
76 // (where area is usually something like the size of the window
77 // being buffered)
78 wxBufferedDC(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
79 : wxDC(),
80 m_targetDc(NULL),
81 m_mainDc(NULL)
82 {
83 // All other members except dcs are initialized in Init
84 Init(NULL, dc, area, style);
85 }
86
87 // Same, but also receives window to detect whether it is
88 // natively double-buffered.
89 wxBufferedDC(wxWindow* win,
90 wxDC *dc,
91 const wxSize &area,
92 int style = wxBUFFER_CLIENT_AREA)
93 : wxDC(),
94 m_targetDc(NULL),
95 m_mainDc(NULL)
96 {
97 // All other members except dcs are initialized in Init
98 Init(win, dc, area, style);
99 }
100
101 // default copy ctor ok.
102
103 // The usually desired action in the dtor is to blit the buffer.
104 virtual ~wxBufferedDC()
105 {
106 UnMask();
107 }
108
109 void Init(wxDC *dc,
110 const wxBitmap &buffer,
111 int style = wxBUFFER_CLIENT_AREA)
112 {
113 wxASSERT_MSG( m_mainDc == NULL,
114 wxT("wxBufferedDC already initialised") );
115 wxASSERT_MSG( buffer.Ok(),
116 wxT("invalid bitmap") );
117 m_mainDc = dc;
118 m_buffer = &buffer;
119 m_style = style;
120 UseBuffer();
121 }
122
123 void Init(wxWindow* win,
124 wxDC *dc,
125 const wxSize &area = wxDefaultSize,
126 int style = wxBUFFER_CLIENT_AREA)
127 {
128 wxASSERT_MSG( m_mainDc == NULL,
129 wxT("wxBufferedDC already initialised") );
130
131 m_mainDc = dc;
132 m_style = style;
133
134 #if wxTEST_MEMORYDCDELEGATION
135 if ( 0 )
136 #elif wxTEST_PAINTDCDELEGATION
137 if ( 1 )
138 #else
139 if ( win && win->IsDoubleBuffered() )
140 #endif
141 {
142 AttachDC(dc);
143 m_buffer = NULL;
144 }
145 else
146 {
147 PrepareBuffer(win, area);
148 UseBuffer();
149 }
150 }
151
152 void Init(wxDC *dc, const wxSize &area = wxDefaultSize, int style = wxBUFFER_CLIENT_AREA)
153 {
154 Init(NULL, dc, area, style);
155 }
156
157 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
158 // can be effectively used once only).
159 //
160 // Usually called in the dtor or by the dtor of derived classes if the
161 // BufferedDC must blit before the derived class (which may own the dc it's
162 // blitting to) is destroyed.
163 void UnMask();
164
165 // Set and get the style
166 void SetStyle(int style) { m_style = style; }
167 int GetStyle() const { return m_style; }
168
169 private:
170 // Prepares wxMemoryDC.
171 void UseBuffer();
172
173 // Allocate m_buffer, if necessary.
174 void PrepareBuffer(wxWindow* win, const wxSize& area);
175
176 // DC to which calls are delegated.
177 wxDC* m_targetDc;
178
179 // This the underlying DC to which we copy everything drawn on
180 // this one in UnMask().
181 //
182 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
183 // could probably be a reference.
184 wxDC* m_mainDc;
185
186 // the buffer (selected in this DC)
187 const wxBitmap* m_buffer;
188
189 // the buffering style
190 int m_style;
191
192 DECLARE_NO_COPY_CLASS(wxBufferedDC)
193 public:
194 //
195 // BEGIN DC-DELEGATION IMPLEMENTATION
196 //
197
198 wxDC& GetAttachedDC()
199 {
200 return *m_targetDc;
201 }
202
203 // Use this to set the DC which receives delegated calls.
204 void AttachDC(wxDC* dc)
205 {
206 m_targetDc = dc;
207 #ifdef __WXMSW__
208 SetHDC( dc ? dc->GetHDC() : NULL );
209 #endif
210 }
211
212 // Sets DC to NULL
213 wxDC* DetachDC()
214 {
215 wxDC* retDc = m_targetDc;
216 AttachDC(NULL);
217 return retDc;
218 }
219
220 #ifdef __WXGTK__
221 virtual GdkWindow* GetGDKWindow() const
222 {
223 return m_targetDc->GetGDKWindow();
224 }
225 virtual wxBitmap GetSelectedBitmap() const
226 {
227 return m_targetDc->GetSelectedBitmap();
228 }
229 #endif
230
231 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
232 wxDC *source, wxCoord xsrc, wxCoord ysrc,
233 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
234 { return m_targetDc->Blit(xdest, ydest, width, height,
235 source, xsrc, ysrc, rop,
236 useMask, xsrcMask, ysrcMask); }
237 bool Blit(const wxPoint& destPt, const wxSize& sz,
238 wxDC *source, const wxPoint& srcPt,
239 int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
240 { return m_targetDc->Blit(destPt, sz, source, srcPt,
241 rop, useMask, srcPtMask); }
242 virtual void CalcBoundingBox(wxCoord x, wxCoord y) { m_targetDc->CalcBoundingBox(x, y); }
243 #if defined(__WXWINCE__)
244 void CalculateEllipticPoints( wxList* points,
245 wxCoord xStart, wxCoord yStart,
246 wxCoord w, wxCoord h,
247 double sa, double ea )
248 { m_targetDc->CalculateEllipticPoints(points, xStart, yStart, w,
249 h, sa, ea); }
250 #endif // defined(__WXWINCE__)
251 virtual bool CanDrawBitmap() const { return m_targetDc->CanDrawBitmap(); }
252 virtual bool CanGetTextExtent() const { return m_targetDc->CanGetTextExtent(); }
253 virtual void Clear() { m_targetDc->Clear(); }
254 virtual void ComputeScaleAndOrigin() { m_targetDc->ComputeScaleAndOrigin(); }
255 void CrossHair(wxCoord x, wxCoord y) { m_targetDc->CrossHair(x, y); }
256 void CrossHair(const wxPoint& pt) { m_targetDc->CrossHair(pt); }
257 virtual void DestroyClippingRegion() { m_targetDc->DestroyClippingRegion(); }
258 wxCoord DeviceToLogicalX(wxCoord x) const { return m_targetDc->DeviceToLogicalX(x); }
259 wxCoord DeviceToLogicalXRel(wxCoord x) const { return m_targetDc->DeviceToLogicalXRel(x); }
260 wxCoord DeviceToLogicalY(wxCoord y) const { return m_targetDc->DeviceToLogicalY(y); }
261 wxCoord DeviceToLogicalYRel(wxCoord y) const { return m_targetDc->DeviceToLogicalYRel(y); }
262 #if defined(__WXWINCE__)
263 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
264 wxCoord w, wxCoord h,
265 double sa = 0, double ea = 0, double angle = 0 )
266 { m_targetDc->DoDrawEllipticArcRot(x, y, w, h,
267 sa, ea, angle); }
268 #endif // defined(__WXWINCE__)
269 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
270 wxCoord xc, wxCoord yc)
271 { m_targetDc->DrawArc(x1, y1, x2, y2,
272 xc, yc); }
273 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
274 { m_targetDc->DrawArc(pt1, pt2, centre); }
275 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
276 bool useMask = false)
277 { m_targetDc->DrawBitmap(bmp, x, y, useMask); }
278 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
279 bool useMask = false)
280 { m_targetDc->DrawBitmap(bmp, pt, useMask); }
281 void DrawCheckMark(wxCoord x, wxCoord y,
282 wxCoord width, wxCoord height)
283 { m_targetDc->DrawCheckMark(x, y, width, height); }
284 void DrawCheckMark(const wxRect& rect) { m_targetDc->DrawCheckMark(rect); }
285 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius) { m_targetDc->DrawCircle(x, y, radius); }
286 void DrawCircle(const wxPoint& pt, wxCoord radius) { m_targetDc->DrawCircle(pt, radius); }
287 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
288 { m_targetDc->DrawEllipse(x, y, width, height); }
289 void DrawEllipse(const wxPoint& pt, const wxSize& sz) { m_targetDc->DrawEllipse(pt, sz); }
290 void DrawEllipse(const wxRect& rect) { m_targetDc->DrawEllipse(rect); }
291 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
292 double sa, double ea)
293 { m_targetDc->DrawEllipticArc(x, y, w, h,
294 sa, ea); }
295 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
296 double sa, double ea)
297 { m_targetDc->DrawEllipticArc(pt, sz, sa, ea); }
298 #if defined(__WXWINCE__)
299 void DrawEllipticArcRot( wxCoord x, wxCoord y,
300 wxCoord width, wxCoord height,
301 double sa = 0, double ea = 0, double angle = 0 )
302 { m_targetDc->DrawEllipticArcRot(x, y, width, height,
303 sa, ea, angle); }
304 void DrawEllipticArcRot( const wxPoint& pt,
305 const wxSize& sz,
306 double sa = 0, double ea = 0, double angle = 0 )
307 { m_targetDc->DrawEllipticArcRot(pt, sz, sa, ea,
308 angle); }
309 void DrawEllipticArcRot( const wxRect& rect,
310 double sa = 0, double ea = 0, double angle = 0 )
311 { m_targetDc->DrawEllipticArcRot(rect, sa, ea, angle); }
312 #endif // defined(__WXWINCE__)
313 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) { m_targetDc->DrawIcon(icon, x, y); }
314 void DrawIcon(const wxIcon& icon, const wxPoint& pt) { m_targetDc->DrawIcon(icon, pt); }
315 virtual void DrawLabel(const wxString& text,
316 const wxBitmap& image,
317 const wxRect& rect,
318 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
319 int indexAccel = -1,
320 wxRect *rectBounding = NULL)
321 { m_targetDc->DrawLabel(text, image, rect, alignment,
322 indexAccel, rectBounding); }
323 void DrawLabel(const wxString& text, const wxRect& rect,
324 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
325 int indexAccel = -1)
326 { m_targetDc->DrawLabel(text, rect, alignment, indexAccel); }
327 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
328 { m_targetDc->DrawLine(x1, y1, x2, y2); }
329 void DrawLine(const wxPoint& pt1, const wxPoint& pt2) { m_targetDc->DrawLine(pt1, pt2); }
330 void DrawLines(int n, wxPoint points[],
331 wxCoord xoffset = 0, wxCoord yoffset = 0)
332 { m_targetDc->DrawLines(n, points, xoffset, yoffset); }
333 void DrawLines(const wxList *list,
334 wxCoord xoffset = 0, wxCoord yoffset = 0)
335 { m_targetDc->DrawLines(list, xoffset, yoffset); }
336 virtual void DrawObject(wxDrawObject* drawobject) { m_targetDc->DrawObject(drawobject); }
337 void DrawPoint(wxCoord x, wxCoord y) { m_targetDc->DrawPoint(x, y); }
338 void DrawPoint(const wxPoint& pt) { m_targetDc->DrawPoint(pt); }
339 void DrawPolyPolygon(int n, int count[], wxPoint points[],
340 wxCoord xoffset = 0, wxCoord yoffset = 0,
341 int fillStyle = wxODDEVEN_RULE)
342 { m_targetDc->DrawPolyPolygon(n, count, points, xoffset,
343 yoffset, fillStyle); }
344 void DrawPolygon(int n, wxPoint points[],
345 wxCoord xoffset = 0, wxCoord yoffset = 0,
346 int fillStyle = wxODDEVEN_RULE)
347 { m_targetDc->DrawPolygon(n, points, xoffset, yoffset,
348 fillStyle); }
349 void DrawPolygon(const wxList *list,
350 wxCoord xoffset = 0, wxCoord yoffset = 0,
351 int fillStyle = wxODDEVEN_RULE)
352 { m_targetDc->DrawPolygon(list, xoffset, yoffset, fillStyle); }
353 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
354 { m_targetDc->DrawRectangle(x, y, width, height); }
355 void DrawRectangle(const wxPoint& pt, const wxSize& sz) { m_targetDc->DrawRectangle(pt, sz); }
356 void DrawRectangle(const wxRect& rect) { m_targetDc->DrawRectangle(rect); }
357 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
358 { m_targetDc->DrawRotatedText(text, x, y, angle); }
359 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
360 { m_targetDc->DrawRotatedText(text, pt, angle); }
361 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
362 double radius)
363 { m_targetDc->DrawRoundedRectangle(x, y, width, height,
364 radius); }
365 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
366 double radius)
367 { m_targetDc->DrawRoundedRectangle(pt, sz, radius); }
368 void DrawRoundedRectangle(const wxRect& r, double radius)
369 { m_targetDc->DrawRoundedRectangle(r, radius); }
370 #if wxUSE_SPLINES
371 void DrawSpline(wxCoord x1, wxCoord y1,
372 wxCoord x2, wxCoord y2,
373 wxCoord x3, wxCoord y3)
374 { m_targetDc->DrawSpline(x1, y1, x2, y2,
375 x3, y3); }
376 void DrawSpline(int n, wxPoint points[]) { m_targetDc->DrawSpline(n, points); }
377 void DrawSpline(wxList *points) { m_targetDc->DrawSpline(points); }
378 #endif // wxUSE_SPLINES
379 void DrawText(const wxString& text, wxCoord x, wxCoord y)
380 { m_targetDc->DrawText(text, x, y); }
381 void DrawText(const wxString& text, const wxPoint& pt) { m_targetDc->DrawText(text, pt); }
382 virtual void EndDoc() { m_targetDc->EndDoc(); }
383 virtual void EndPage() { m_targetDc->EndPage(); }
384 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
385 int style = wxFLOOD_SURFACE)
386 { return m_targetDc->FloodFill(x, y, col, style); }
387 bool FloodFill(const wxPoint& pt, const wxColour& col,
388 int style = wxFLOOD_SURFACE)
389 { return m_targetDc->FloodFill(pt, col, style); }
390 virtual const wxBrush& GetBackground() const { return m_targetDc->GetBackground(); }
391 virtual int GetBackgroundMode() const { return m_targetDc->GetBackgroundMode(); }
392 virtual const wxBrush& GetBrush() const { return m_targetDc->GetBrush(); }
393 virtual wxCoord GetCharHeight() const { return m_targetDc->GetCharHeight(); }
394 virtual wxCoord GetCharWidth() const { return m_targetDc->GetCharWidth(); }
395 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
396 { m_targetDc->GetClippingBox(x, y, w, h); }
397 void GetClippingBox(wxRect& rect) const { m_targetDc->GetClippingBox(rect); }
398 void GetClippingBox(long *x, long *y, long *w, long *h) const
399 { m_targetDc->GetClippingBox(x, y, w, h); }
400 virtual int GetDepth() const { return m_targetDc->GetDepth(); }
401 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const { m_targetDc->GetDeviceOrigin(x, y); }
402 wxPoint GetDeviceOrigin() const { return m_targetDc->GetDeviceOrigin(); }
403 void GetDeviceOrigin(long *x, long *y) const { m_targetDc->GetDeviceOrigin(x, y); }
404 virtual const wxFont& GetFont() const { return m_targetDc->GetFont(); }
405 virtual int GetLogicalFunction() const { return m_targetDc->GetLogicalFunction(); }
406 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const { m_targetDc->GetLogicalOrigin(x, y); }
407 wxPoint GetLogicalOrigin() const { return m_targetDc->GetLogicalOrigin(); }
408 void GetLogicalOrigin(long *x, long *y) const { m_targetDc->GetLogicalOrigin(x, y); }
409 virtual void GetLogicalScale(double *x, double *y) { m_targetDc->GetLogicalScale(x, y); }
410 virtual int GetMapMode() const { return m_targetDc->GetMapMode(); }
411 virtual void GetMultiLineTextExtent(const wxString& text,
412 wxCoord *width,
413 wxCoord *height,
414 wxCoord *heightLine = NULL,
415 wxFont *font = NULL)
416 { m_targetDc->GetMultiLineTextExtent(text, width, height, heightLine,
417 font); }
418 #if WXWIN_COMPATIBILITY_2_4
419 virtual bool GetOptimization() { return m_targetDc->GetOptimization(); }
420 #endif // WXWIN_COMPATIBILITY_2_4
421 virtual wxSize GetPPI() const { return m_targetDc->GetPPI(); }
422 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
423 { return m_targetDc->GetPartialTextExtents(text, widths); }
424 virtual const wxPen& GetPen() const { return m_targetDc->GetPen(); }
425 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
426 { return m_targetDc->GetPixel(x, y, col); }
427 bool GetPixel(const wxPoint& pt, wxColour *col) const { return m_targetDc->GetPixel(pt, col); }
428 void GetSize(int *width, int *height) const { m_targetDc->GetSize(width, height); }
429 wxSize GetSize() const { return m_targetDc->GetSize(); }
430 void GetSizeMM(int* width, int* height) const { m_targetDc->GetSizeMM(width, height); }
431 wxSize GetSizeMM() const { return m_targetDc->GetSizeMM(); }
432 virtual const wxColour& GetTextBackground() const { return m_targetDc->GetTextBackground(); }
433 void GetTextExtent(const wxString& string,
434 wxCoord *x, wxCoord *y,
435 wxCoord *descent = NULL,
436 wxCoord *externalLeading = NULL,
437 wxFont *theFont = NULL) const
438 { m_targetDc->GetTextExtent(string, x, y, descent,
439 externalLeading, theFont); }
440 void GetTextExtent(const wxString& string,
441 long *x, long *y,
442 long *descent = NULL,
443 long *externalLeading = NULL,
444 wxFont *theFont = NULL) const
445 { m_targetDc->GetTextExtent(string, x, y, descent,
446 externalLeading, theFont); }
447 virtual const wxColour& GetTextForeground() const { return m_targetDc->GetTextForeground(); }
448 virtual void GetUserScale(double *x, double *y) const { m_targetDc->GetUserScale(x, y); }
449 void GradientFillConcentric(const wxRect& rect,
450 const wxColour& initialColour,
451 const wxColour& destColour)
452 { m_targetDc->GradientFillConcentric(rect, initialColour, destColour); }
453 void GradientFillConcentric(const wxRect& rect,
454 const wxColour& initialColour,
455 const wxColour& destColour,
456 const wxPoint& circleCenter)
457 { m_targetDc->GradientFillConcentric(rect, initialColour, destColour, circleCenter); }
458 void GradientFillLinear(const wxRect& rect,
459 const wxColour& initialColour,
460 const wxColour& destColour,
461 wxDirection nDirection = wxEAST)
462 { m_targetDc->GradientFillLinear(rect, initialColour, destColour, nDirection); }
463 wxCoord LogicalToDeviceX(wxCoord x) const { return m_targetDc->LogicalToDeviceX(x); }
464 wxCoord LogicalToDeviceXRel(wxCoord x) const { return m_targetDc->LogicalToDeviceXRel(x); }
465 wxCoord LogicalToDeviceY(wxCoord y) const { return m_targetDc->LogicalToDeviceY(y); }
466 wxCoord LogicalToDeviceYRel(wxCoord y) const { return m_targetDc->LogicalToDeviceYRel(y); }
467 wxCoord MaxX() const { return m_targetDc->MaxX(); }
468 wxCoord MaxY() const { return m_targetDc->MaxY(); }
469 wxCoord MinX() const { return m_targetDc->MinX(); }
470 wxCoord MinY() const { return m_targetDc->MinY(); }
471 virtual bool Ok() const { return m_targetDc->Ok(); }
472 void ResetBoundingBox()
473 { m_targetDc->ResetBoundingBox(); }
474 #if defined(__WXWINCE__)
475 void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) )
476 { m_targetDc->Rotate(points, angle, center); }
477 #endif // defined(__WXWINCE__)
478 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
479 { m_targetDc->SetAxisOrientation(xLeftRight, yBottomUp); }
480 virtual void SetBackground(const wxBrush& brush) { m_targetDc->SetBackground(brush); }
481 virtual void SetBackgroundMode(int mode) { m_targetDc->SetBackgroundMode(mode); }
482 virtual void SetBrush(const wxBrush& brush) { m_targetDc->SetBrush(brush); }
483 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
484 { m_targetDc->SetClippingRegion(x, y, width, height); }
485 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
486 { m_targetDc->SetClippingRegion(pt, sz); }
487 void SetClippingRegion(const wxRect& rect) { m_targetDc->SetClippingRegion(rect); }
488 void SetClippingRegion(const wxRegion& region) { m_targetDc->SetClippingRegion(region); }
489 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) { m_targetDc->SetDeviceOrigin(x, y); }
490 virtual void SetFont(const wxFont& font) { m_targetDc->SetFont(font); }
491 virtual void SetLogicalFunction(int function) { m_targetDc->SetLogicalFunction(function); }
492 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) { m_targetDc->SetLogicalOrigin(x, y); }
493 virtual void SetLogicalScale(double x, double y) { m_targetDc->SetLogicalScale(x, y); }
494 virtual void SetMapMode(int mode) { m_targetDc->SetMapMode(mode); }
495 #if WXWIN_COMPATIBILITY_2_4
496 virtual void SetOptimization(bool opt) { m_targetDc->SetOptimization(opt); }
497 #endif // WXWIN_COMPATIBILITY_2_4
498 #if wxUSE_PALETTE
499 virtual void SetPalette(const wxPalette& palette) { m_targetDc->SetPalette(palette); }
500 #endif // wxUSE_PALETTE
501 virtual void SetPen(const wxPen& pen) { m_targetDc->SetPen(pen); }
502 virtual void SetTextBackground(const wxColour& colour) { m_targetDc->SetTextBackground(colour); }
503 virtual void SetTextForeground(const wxColour& colour) { m_targetDc->SetTextForeground(colour); }
504 virtual void SetUserScale(double x, double y) { m_targetDc->SetUserScale(x, y); }
505 virtual bool StartDoc(const wxString& message) { return m_targetDc->StartDoc(message); }
506 virtual void StartPage() { m_targetDc->StartPage(); }
507 protected:
508 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
509 wxCoord width, wxCoord height,
510 wxDC *source, wxCoord xsrc, wxCoord ysrc,
511 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
512 { return m_targetDc->Blit(xdest, ydest, width, height,
513 source, xsrc, ysrc, rop,
514 useMask, xsrcMask, ysrcMask); }
515 virtual void DoCrossHair(wxCoord x, wxCoord y) { m_targetDc->CrossHair(x, y); }
516 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
517 wxCoord x2, wxCoord y2,
518 wxCoord xc, wxCoord yc)
519 { m_targetDc->DrawArc(x1, y1, x2, y2,
520 xc, yc); }
521 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
522 bool useMask = false)
523 { m_targetDc->DrawBitmap(bmp, x, y, useMask); }
524 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
525 wxCoord width, wxCoord height)
526 { m_targetDc->DrawCheckMark(x, y, width, height); }
527 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
528 wxCoord width, wxCoord height)
529 { m_targetDc->DrawEllipse(x, y, width, height); }
530 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
531 double sa, double ea)
532 { m_targetDc->DrawEllipticArc(x, y, w, h,
533 sa, ea); }
534 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
535 { m_targetDc->DrawIcon(icon, x, y); }
536 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
537 { m_targetDc->DrawLine(x1, y1, x2, y2); }
538 virtual void DoDrawLines(int n, wxPoint points[],
539 wxCoord xoffset, wxCoord yoffset)
540 { m_targetDc->DrawLines(n, points, xoffset, yoffset); }
541 virtual void DoDrawPoint(wxCoord x, wxCoord y) { m_targetDc->DrawPoint(x, y); }
542 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
543 wxCoord xoffset, wxCoord yoffset,
544 int fillStyle)
545 { m_targetDc->DrawPolyPolygon(n, count, points, xoffset,
546 yoffset, fillStyle); }
547 virtual void DoDrawPolygon(int n, wxPoint points[],
548 wxCoord xoffset, wxCoord yoffset,
549 int fillStyle = wxODDEVEN_RULE)
550 { m_targetDc->DrawPolygon(n, points, xoffset, yoffset,
551 fillStyle); }
552 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
553 { m_targetDc->DrawRectangle(x, y, width, height); }
554 virtual void DoDrawRotatedText(const wxString& text,
555 wxCoord x, wxCoord y, double angle)
556 { m_targetDc->DrawRotatedText(text, x, y, angle); }
557 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
558 wxCoord width, wxCoord height,
559 double radius)
560 { m_targetDc->DrawRoundedRectangle(x, y, width, height,
561 radius); }
562 #if wxUSE_SPLINES
563 virtual void DoDrawSpline(wxList *points) { m_targetDc->DrawSpline(points); }
564 #endif // wxUSE_SPLINES
565 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y)
566 { m_targetDc->DrawText(text, x, y); }
567 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
568 int style = wxFLOOD_SURFACE)
569 { return m_targetDc->FloodFill(x, y, col, style); }
570 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
571 wxCoord *w, wxCoord *h) const
572 { m_targetDc->GetClippingBox(x, y, w, h); }
573 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
574 { m_targetDc->GetDeviceOrigin(x, y); }
575 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
576 { m_targetDc->GetLogicalOrigin(x, y); }
577 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
578 { return m_targetDc->GetPartialTextExtents(text, widths); }
579 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
580 { return m_targetDc->GetPixel(x, y, col); }
581 virtual void DoGetSize(int *width, int *height) const { m_targetDc->GetSize(width, height); }
582 virtual void DoGetSizeMM(int* width, int* height) const { m_targetDc->GetSizeMM(width, height); }
583 virtual void DoGetTextExtent(const wxString& string,
584 wxCoord *x, wxCoord *y,
585 wxCoord *descent = NULL,
586 wxCoord *externalLeading = NULL,
587 wxFont *theFont = NULL) const
588 { m_targetDc->GetTextExtent(string, x, y, descent,
589 externalLeading, theFont); }
590 virtual void DoGradientFillLinear(const wxRect& rect,
591 const wxColour& initialColour,
592 const wxColour& destColour,
593 wxDirection nDirection = wxEAST)
594 { m_targetDc->GradientFillLinear(rect, initialColour, destColour, nDirection); }
595 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
596 wxCoord width, wxCoord height)
597 { m_targetDc->SetClippingRegion(x, y, width, height); }
598 virtual void DoSetClippingRegionAsRegion(const wxRegion& region)
599 { m_targetDc->SetClippingRegion(region); }
600 };
601
602
603 // ----------------------------------------------------------------------------
604 // Double buffered PaintDC.
605 // ----------------------------------------------------------------------------
606
607 // Creates a double buffered wxPaintDC, optionally allowing the
608 // user to specify their own buffer to use.
609 class wxBufferedPaintDC : public wxBufferedDC
610 {
611 public:
612 // If no bitmap is supplied by the user, a temporary one will be created.
613 wxBufferedPaintDC(wxWindow *window, const wxBitmap& buffer, int style = wxBUFFER_CLIENT_AREA)
614 : m_paintdc(window)
615 {
616 // If we're buffering the virtual window, scale the paint DC as well
617 if (style & wxBUFFER_VIRTUAL_AREA)
618 window->PrepareDC( m_paintdc );
619
620 if( buffer != wxNullBitmap )
621 Init(&m_paintdc, buffer, style);
622 else
623 Init(window, &m_paintdc, window->GetClientSize(), style);
624 }
625
626 // If no bitmap is supplied by the user, a temporary one will be created.
627 wxBufferedPaintDC(wxWindow *window, int style = wxBUFFER_CLIENT_AREA)
628 : m_paintdc(window)
629 {
630 // If we're using the virtual window, scale the paint DC as well
631 if (style & wxBUFFER_VIRTUAL_AREA)
632 window->PrepareDC( m_paintdc );
633
634 Init(window, &m_paintdc, window->GetClientSize(), style);
635 }
636
637 // default copy ctor ok.
638
639 virtual ~wxBufferedPaintDC()
640 {
641 // We must UnMask here, else by the time the base class
642 // does it, the PaintDC will have already been destroyed.
643 UnMask();
644 }
645
646 private:
647 wxPaintDC m_paintdc;
648
649 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC)
650 };
651
652
653
654 //
655 // wxAutoBufferedPaintDC is a wxPaintDC in toolkits which have double-
656 // buffering by default. Otherwise it is a wxBufferedPaintDC. Thus,
657 // you can only expect it work with a simple constructor that
658 // accepts single wxWindow* argument.
659 //
660 #if wxALWAYS_NATIVE_DOUBLE_BUFFER
661 #define wxAutoBufferedPaintDCBase wxPaintDC
662 #else
663 #define wxAutoBufferedPaintDCBase wxBufferedPaintDC
664 #endif
665
666
667 #ifdef __WXDEBUG__
668
669 class wxAutoBufferedPaintDC : public wxAutoBufferedPaintDCBase
670 {
671 public:
672
673 wxAutoBufferedPaintDC(wxWindow* win)
674 : wxAutoBufferedPaintDCBase(win)
675 {
676 TestWinStyle(win);
677 }
678
679 virtual ~wxAutoBufferedPaintDC() { }
680
681 private:
682
683 void TestWinStyle(wxWindow* win)
684 {
685 // Help the user to get the double-buffering working properly.
686 wxASSERT_MSG( win->GetBackgroundStyle() == wxBG_STYLE_CUSTOM,
687 wxT("In constructor, you need to call GetBackgroundStyle(wxBG_STYLE_CUSTOM), ")
688 wxT("and also, if needed, paint the background manually in the paint event handler."));
689 }
690
691 DECLARE_NO_COPY_CLASS(wxAutoBufferedPaintDC)
692 };
693
694 #else // !__WXDEBUG__
695
696 // In release builds, just use typedef
697 typedef wxAutoBufferedPaintDCBase wxAutoBufferedPaintDC;
698
699 #endif
700
701
702 #endif // _WX_DCBUFFER_H_