1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBufferedDC class
4 // Author: Ron Lee <ron@debian.org>
5 // Modified by: Vadim Zeitlin (refactored, added bg preservation)
8 // Copyright: (c) Ron Lee
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DCBUFFER_H_
13 #define _WX_DCBUFFER_H_
15 #include "wx/dcmemory.h"
16 #include "wx/dcclient.h"
17 #include "wx/window.h"
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
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
32 #define wxALWAYS_NATIVE_DOUBLE_BUFFER 0
36 #if wxTEST_PAINTDCDELEGATION || wxTEST_MEMORYDCDELEGATION
37 #undef wxALWAYS_NATIVE_DOUBLE_BUFFER
38 #define wxALWAYS_NATIVE_DOUBLE_BUFFER 0
42 // ----------------------------------------------------------------------------
43 // Double buffering helper.
44 // ----------------------------------------------------------------------------
46 // Assumes the buffer bitmap covers the entire scrolled window,
47 // and prepares the window DC accordingly
48 #define wxBUFFER_VIRTUAL_AREA 0x01
50 // Assumes the buffer bitmap only covers the client area;
51 // does not prepare the window DC
52 #define wxBUFFER_CLIENT_AREA 0x02
54 class WXDLLEXPORT wxBufferedDC
: public wxDC
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)
63 // Construct a wxBufferedDC using a user supplied buffer.
64 wxBufferedDC(wxDC
*dc
,
65 const wxBitmap
&buffer
= wxNullBitmap
,
66 int style
= wxBUFFER_CLIENT_AREA
)
71 // All other members except dcs are initialized in Init
72 Init(dc
, buffer
, style
);
75 // Construct a wxBufferedDC with an internal buffer of 'area'
76 // (where area is usually something like the size of the window
78 wxBufferedDC(wxDC
*dc
, const wxSize
&area
, int style
= wxBUFFER_CLIENT_AREA
)
83 // All other members except dcs are initialized in Init
84 Init(NULL
, dc
, area
, style
);
87 // Same, but also receives window to detect whether it is
88 // natively double-buffered.
89 wxBufferedDC(wxWindow
* win
,
92 int style
= wxBUFFER_CLIENT_AREA
)
97 // All other members except dcs are initialized in Init
98 Init(win
, dc
, area
, style
);
101 // default copy ctor ok.
103 // The usually desired action in the dtor is to blit the buffer.
104 virtual ~wxBufferedDC()
110 const wxBitmap
&buffer
,
111 int style
= wxBUFFER_CLIENT_AREA
)
113 wxASSERT_MSG( m_mainDc
== NULL
,
114 wxT("wxBufferedDC already initialised") );
115 wxASSERT_MSG( buffer
.Ok(),
116 wxT("invalid bitmap") );
123 void Init(wxWindow
* win
,
125 const wxSize
&area
= wxDefaultSize
,
126 int style
= wxBUFFER_CLIENT_AREA
)
128 wxASSERT_MSG( m_mainDc
== NULL
,
129 wxT("wxBufferedDC already initialised") );
134 #if wxTEST_MEMORYDCDELEGATION
136 #elif wxTEST_PAINTDCDELEGATION
139 if ( win
&& win
->IsDoubleBuffered() )
147 PrepareBuffer(win
, area
);
152 void Init(wxDC
*dc
, const wxSize
&area
= wxDefaultSize
, int style
= wxBUFFER_CLIENT_AREA
)
154 Init(NULL
, dc
, area
, style
);
157 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
158 // can be effectively used once only).
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.
165 // Set and get the style
166 void SetStyle(int style
) { m_style
= style
; }
167 int GetStyle() const { return m_style
; }
170 // Prepares wxMemoryDC.
173 // Allocate m_buffer, if necessary.
174 void PrepareBuffer(wxWindow
* win
, const wxSize
& area
);
176 // DC to which calls are delegated.
179 // This the underlying DC to which we copy everything drawn on
180 // this one in UnMask().
182 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
183 // could probably be a reference.
186 // the buffer (selected in this DC)
187 const wxBitmap
* m_buffer
;
189 // the buffering style
192 DECLARE_NO_COPY_CLASS(wxBufferedDC
)
195 // BEGIN DC-DELEGATION IMPLEMENTATION
198 wxDC
& GetAttachedDC()
203 // Use this to set the DC which receives delegated calls.
204 void AttachDC(wxDC
* dc
)
208 SetHDC( dc
? dc
->GetHDC() : NULL
);
215 wxDC
* retDc
= m_targetDc
;
221 virtual GdkWindow
* GetGDKWindow() const
223 return m_targetDc
->GetGDKWindow();
227 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
228 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
229 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
230 { return m_targetDc
->Blit(xdest
, ydest
, width
, height
,
231 source
, xsrc
, ysrc
, rop
,
232 useMask
, xsrcMask
, ysrcMask
); }
233 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
234 wxDC
*source
, const wxPoint
& srcPt
,
235 int rop
= wxCOPY
, bool useMask
= false, const wxPoint
& srcPtMask
= wxDefaultPosition
)
236 { return m_targetDc
->Blit(destPt
, sz
, source
, srcPt
,
237 rop
, useMask
, srcPtMask
); }
238 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
) { m_targetDc
->CalcBoundingBox(x
, y
); }
239 #if defined(__WXWINCE__)
240 void CalculateEllipticPoints( wxList
* points
,
241 wxCoord xStart
, wxCoord yStart
,
242 wxCoord w
, wxCoord h
,
243 double sa
, double ea
)
244 { m_targetDc
->CalculateEllipticPoints(points
, xStart
, yStart
, w
,
246 #endif // defined(__WXWINCE__)
247 virtual bool CanDrawBitmap() const { return m_targetDc
->CanDrawBitmap(); }
248 virtual bool CanGetTextExtent() const { return m_targetDc
->CanGetTextExtent(); }
249 virtual void Clear() { m_targetDc
->Clear(); }
250 virtual void ComputeScaleAndOrigin() { m_targetDc
->ComputeScaleAndOrigin(); }
251 void CrossHair(wxCoord x
, wxCoord y
) { m_targetDc
->CrossHair(x
, y
); }
252 void CrossHair(const wxPoint
& pt
) { m_targetDc
->CrossHair(pt
); }
253 virtual void DestroyClippingRegion() { m_targetDc
->DestroyClippingRegion(); }
254 wxCoord
DeviceToLogicalX(wxCoord x
) const { return m_targetDc
->DeviceToLogicalX(x
); }
255 wxCoord
DeviceToLogicalXRel(wxCoord x
) const { return m_targetDc
->DeviceToLogicalXRel(x
); }
256 wxCoord
DeviceToLogicalY(wxCoord y
) const { return m_targetDc
->DeviceToLogicalY(y
); }
257 wxCoord
DeviceToLogicalYRel(wxCoord y
) const { return m_targetDc
->DeviceToLogicalYRel(y
); }
258 #if defined(__WXWINCE__)
259 virtual void DoDrawEllipticArcRot( wxCoord x
, wxCoord y
,
260 wxCoord w
, wxCoord h
,
261 double sa
= 0, double ea
= 0, double angle
= 0 )
262 { m_targetDc
->DoDrawEllipticArcRot(x
, y
, w
, h
,
264 #endif // defined(__WXWINCE__)
265 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
266 wxCoord xc
, wxCoord yc
)
267 { m_targetDc
->DrawArc(x1
, y1
, x2
, y2
,
269 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
270 { m_targetDc
->DrawArc(pt1
, pt2
, centre
); }
271 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
272 bool useMask
= false)
273 { m_targetDc
->DrawBitmap(bmp
, x
, y
, useMask
); }
274 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
275 bool useMask
= false)
276 { m_targetDc
->DrawBitmap(bmp
, pt
, useMask
); }
277 void DrawCheckMark(wxCoord x
, wxCoord y
,
278 wxCoord width
, wxCoord height
)
279 { m_targetDc
->DrawCheckMark(x
, y
, width
, height
); }
280 void DrawCheckMark(const wxRect
& rect
) { m_targetDc
->DrawCheckMark(rect
); }
281 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
) { m_targetDc
->DrawCircle(x
, y
, radius
); }
282 void DrawCircle(const wxPoint
& pt
, wxCoord radius
) { m_targetDc
->DrawCircle(pt
, radius
); }
283 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
284 { m_targetDc
->DrawEllipse(x
, y
, width
, height
); }
285 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
) { m_targetDc
->DrawEllipse(pt
, sz
); }
286 void DrawEllipse(const wxRect
& rect
) { m_targetDc
->DrawEllipse(rect
); }
287 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
288 double sa
, double ea
)
289 { m_targetDc
->DrawEllipticArc(x
, y
, w
, h
,
291 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
292 double sa
, double ea
)
293 { m_targetDc
->DrawEllipticArc(pt
, sz
, sa
, ea
); }
294 #if defined(__WXWINCE__)
295 void DrawEllipticArcRot( wxCoord x
, wxCoord y
,
296 wxCoord width
, wxCoord height
,
297 double sa
= 0, double ea
= 0, double angle
= 0 )
298 { m_targetDc
->DrawEllipticArcRot(x
, y
, width
, height
,
300 void DrawEllipticArcRot( const wxPoint
& pt
,
302 double sa
= 0, double ea
= 0, double angle
= 0 )
303 { m_targetDc
->DrawEllipticArcRot(pt
, sz
, sa
, ea
,
305 void DrawEllipticArcRot( const wxRect
& rect
,
306 double sa
= 0, double ea
= 0, double angle
= 0 )
307 { m_targetDc
->DrawEllipticArcRot(rect
, sa
, ea
, angle
); }
308 #endif // defined(__WXWINCE__)
309 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) { m_targetDc
->DrawIcon(icon
, x
, y
); }
310 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
) { m_targetDc
->DrawIcon(icon
, pt
); }
311 virtual void DrawLabel(const wxString
& text
,
312 const wxBitmap
& image
,
314 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
316 wxRect
*rectBounding
= NULL
)
317 { m_targetDc
->DrawLabel(text
, image
, rect
, alignment
,
318 indexAccel
, rectBounding
); }
319 void DrawLabel(const wxString
& text
, const wxRect
& rect
,
320 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
322 { m_targetDc
->DrawLabel(text
, rect
, alignment
, indexAccel
); }
323 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
324 { m_targetDc
->DrawLine(x1
, y1
, x2
, y2
); }
325 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
) { m_targetDc
->DrawLine(pt1
, pt2
); }
326 void DrawLines(int n
, wxPoint points
[],
327 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
328 { m_targetDc
->DrawLines(n
, points
, xoffset
, yoffset
); }
329 void DrawLines(const wxList
*list
,
330 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
331 { m_targetDc
->DrawLines(list
, xoffset
, yoffset
); }
332 virtual void DrawObject(wxDrawObject
* drawobject
) { m_targetDc
->DrawObject(drawobject
); }
333 void DrawPoint(wxCoord x
, wxCoord y
) { m_targetDc
->DrawPoint(x
, y
); }
334 void DrawPoint(const wxPoint
& pt
) { m_targetDc
->DrawPoint(pt
); }
335 void DrawPolyPolygon(int n
, int count
[], wxPoint points
[],
336 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
337 int fillStyle
= wxODDEVEN_RULE
)
338 { m_targetDc
->DrawPolyPolygon(n
, count
, points
, xoffset
,
339 yoffset
, fillStyle
); }
340 void DrawPolygon(int n
, wxPoint points
[],
341 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
342 int fillStyle
= wxODDEVEN_RULE
)
343 { m_targetDc
->DrawPolygon(n
, points
, xoffset
, yoffset
,
345 void DrawPolygon(const wxList
*list
,
346 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
347 int fillStyle
= wxODDEVEN_RULE
)
348 { m_targetDc
->DrawPolygon(list
, xoffset
, yoffset
, fillStyle
); }
349 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
350 { m_targetDc
->DrawRectangle(x
, y
, width
, height
); }
351 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
) { m_targetDc
->DrawRectangle(pt
, sz
); }
352 void DrawRectangle(const wxRect
& rect
) { m_targetDc
->DrawRectangle(rect
); }
353 void DrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
354 { m_targetDc
->DrawRotatedText(text
, x
, y
, angle
); }
355 void DrawRotatedText(const wxString
& text
, const wxPoint
& pt
, double angle
)
356 { m_targetDc
->DrawRotatedText(text
, pt
, angle
); }
357 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
359 { m_targetDc
->DrawRoundedRectangle(x
, y
, width
, height
,
361 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
363 { m_targetDc
->DrawRoundedRectangle(pt
, sz
, radius
); }
364 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
365 { m_targetDc
->DrawRoundedRectangle(r
, radius
); }
367 void DrawSpline(wxCoord x1
, wxCoord y1
,
368 wxCoord x2
, wxCoord y2
,
369 wxCoord x3
, wxCoord y3
)
370 { m_targetDc
->DrawSpline(x1
, y1
, x2
, y2
,
372 void DrawSpline(int n
, wxPoint points
[]) { m_targetDc
->DrawSpline(n
, points
); }
373 void DrawSpline(wxList
*points
) { m_targetDc
->DrawSpline(points
); }
374 #endif // wxUSE_SPLINES
375 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
376 { m_targetDc
->DrawText(text
, x
, y
); }
377 void DrawText(const wxString
& text
, const wxPoint
& pt
) { m_targetDc
->DrawText(text
, pt
); }
378 virtual void EndDoc() { m_targetDc
->EndDoc(); }
379 virtual void EndPage() { m_targetDc
->EndPage(); }
380 bool FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
381 int style
= wxFLOOD_SURFACE
)
382 { return m_targetDc
->FloodFill(x
, y
, col
, style
); }
383 bool FloodFill(const wxPoint
& pt
, const wxColour
& col
,
384 int style
= wxFLOOD_SURFACE
)
385 { return m_targetDc
->FloodFill(pt
, col
, style
); }
386 virtual const wxBrush
& GetBackground() const { return m_targetDc
->GetBackground(); }
387 virtual int GetBackgroundMode() const { return m_targetDc
->GetBackgroundMode(); }
388 virtual const wxBrush
& GetBrush() const { return m_targetDc
->GetBrush(); }
389 virtual wxCoord
GetCharHeight() const { return m_targetDc
->GetCharHeight(); }
390 virtual wxCoord
GetCharWidth() const { return m_targetDc
->GetCharWidth(); }
391 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
392 { m_targetDc
->GetClippingBox(x
, y
, w
, h
); }
393 void GetClippingBox(wxRect
& rect
) const { m_targetDc
->GetClippingBox(rect
); }
394 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
395 { m_targetDc
->GetClippingBox(x
, y
, w
, h
); }
396 virtual int GetDepth() const { return m_targetDc
->GetDepth(); }
397 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const { m_targetDc
->GetDeviceOrigin(x
, y
); }
398 wxPoint
GetDeviceOrigin() const { return m_targetDc
->GetDeviceOrigin(); }
399 void GetDeviceOrigin(long *x
, long *y
) const { m_targetDc
->GetDeviceOrigin(x
, y
); }
400 virtual const wxFont
& GetFont() const { return m_targetDc
->GetFont(); }
401 virtual int GetLogicalFunction() const { return m_targetDc
->GetLogicalFunction(); }
402 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const { m_targetDc
->GetLogicalOrigin(x
, y
); }
403 wxPoint
GetLogicalOrigin() const { return m_targetDc
->GetLogicalOrigin(); }
404 void GetLogicalOrigin(long *x
, long *y
) const { m_targetDc
->GetLogicalOrigin(x
, y
); }
405 virtual void GetLogicalScale(double *x
, double *y
) { m_targetDc
->GetLogicalScale(x
, y
); }
406 virtual int GetMapMode() const { return m_targetDc
->GetMapMode(); }
407 virtual void GetMultiLineTextExtent(const wxString
& text
,
410 wxCoord
*heightLine
= NULL
,
412 { m_targetDc
->GetMultiLineTextExtent(text
, width
, height
, heightLine
,
414 #if WXWIN_COMPATIBILITY_2_4
415 virtual bool GetOptimization() { return m_targetDc
->GetOptimization(); }
416 #endif // WXWIN_COMPATIBILITY_2_4
417 virtual wxSize
GetPPI() const { return m_targetDc
->GetPPI(); }
418 bool GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
419 { return m_targetDc
->GetPartialTextExtents(text
, widths
); }
420 virtual const wxPen
& GetPen() const { return m_targetDc
->GetPen(); }
421 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
422 { return m_targetDc
->GetPixel(x
, y
, col
); }
423 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const { return m_targetDc
->GetPixel(pt
, col
); }
424 void GetSize(int *width
, int *height
) const { m_targetDc
->GetSize(width
, height
); }
425 wxSize
GetSize() const { return m_targetDc
->GetSize(); }
426 void GetSizeMM(int* width
, int* height
) const { m_targetDc
->GetSizeMM(width
, height
); }
427 wxSize
GetSizeMM() const { return m_targetDc
->GetSizeMM(); }
428 virtual const wxColour
& GetTextBackground() const { return m_targetDc
->GetTextBackground(); }
429 void GetTextExtent(const wxString
& string
,
430 wxCoord
*x
, wxCoord
*y
,
431 wxCoord
*descent
= NULL
,
432 wxCoord
*externalLeading
= NULL
,
433 wxFont
*theFont
= NULL
) const
434 { m_targetDc
->GetTextExtent(string
, x
, y
, descent
,
435 externalLeading
, theFont
); }
436 void GetTextExtent(const wxString
& string
,
438 long *descent
= NULL
,
439 long *externalLeading
= NULL
,
440 wxFont
*theFont
= NULL
) const
441 { m_targetDc
->GetTextExtent(string
, x
, y
, descent
,
442 externalLeading
, theFont
); }
443 virtual const wxColour
& GetTextForeground() const { return m_targetDc
->GetTextForeground(); }
444 virtual void GetUserScale(double *x
, double *y
) const { m_targetDc
->GetUserScale(x
, y
); }
445 void GradientFillConcentric(const wxRect
& rect
,
446 const wxColour
& initialColour
,
447 const wxColour
& destColour
)
448 { m_targetDc
->GradientFillConcentric(rect
, initialColour
, destColour
); }
449 void GradientFillConcentric(const wxRect
& rect
,
450 const wxColour
& initialColour
,
451 const wxColour
& destColour
,
452 const wxPoint
& circleCenter
)
453 { m_targetDc
->GradientFillConcentric(rect
, initialColour
, destColour
, circleCenter
); }
454 void GradientFillLinear(const wxRect
& rect
,
455 const wxColour
& initialColour
,
456 const wxColour
& destColour
,
457 wxDirection nDirection
= wxEAST
)
458 { m_targetDc
->GradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
459 wxCoord
LogicalToDeviceX(wxCoord x
) const { return m_targetDc
->LogicalToDeviceX(x
); }
460 wxCoord
LogicalToDeviceXRel(wxCoord x
) const { return m_targetDc
->LogicalToDeviceXRel(x
); }
461 wxCoord
LogicalToDeviceY(wxCoord y
) const { return m_targetDc
->LogicalToDeviceY(y
); }
462 wxCoord
LogicalToDeviceYRel(wxCoord y
) const { return m_targetDc
->LogicalToDeviceYRel(y
); }
463 wxCoord
MaxX() const { return m_targetDc
->MaxX(); }
464 wxCoord
MaxY() const { return m_targetDc
->MaxY(); }
465 wxCoord
MinX() const { return m_targetDc
->MinX(); }
466 wxCoord
MinY() const { return m_targetDc
->MinY(); }
467 virtual bool Ok() const { return m_targetDc
->Ok(); }
468 void ResetBoundingBox()
469 { m_targetDc
->ResetBoundingBox(); }
470 #if defined(__WXWINCE__)
471 void Rotate( wxList
* points
, double angle
, wxPoint center
= wxPoint(0,0) )
472 { m_targetDc
->Rotate(points
, angle
, center
, 0)); }
473 #endif // defined(__WXWINCE__)
474 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
)
475 { m_targetDc
->SetAxisOrientation(xLeftRight
, yBottomUp
); }
476 virtual void SetBackground(const wxBrush
& brush
) { m_targetDc
->SetBackground(brush
); }
477 virtual void SetBackgroundMode(int mode
) { m_targetDc
->SetBackgroundMode(mode
); }
478 virtual void SetBrush(const wxBrush
& brush
) { m_targetDc
->SetBrush(brush
); }
479 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
480 { m_targetDc
->SetClippingRegion(x
, y
, width
, height
); }
481 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
482 { m_targetDc
->SetClippingRegion(pt
, sz
); }
483 void SetClippingRegion(const wxRect
& rect
) { m_targetDc
->SetClippingRegion(rect
); }
484 void SetClippingRegion(const wxRegion
& region
) { m_targetDc
->SetClippingRegion(region
); }
485 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
) { m_targetDc
->SetDeviceOrigin(x
, y
); }
486 virtual void SetFont(const wxFont
& font
) { m_targetDc
->SetFont(font
); }
487 virtual void SetLogicalFunction(int function
) { m_targetDc
->SetLogicalFunction(function
); }
488 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
) { m_targetDc
->SetLogicalOrigin(x
, y
); }
489 virtual void SetLogicalScale(double x
, double y
) { m_targetDc
->SetLogicalScale(x
, y
); }
490 virtual void SetMapMode(int mode
) { m_targetDc
->SetMapMode(mode
); }
491 #if WXWIN_COMPATIBILITY_2_4
492 virtual void SetOptimization(bool opt
) { m_targetDc
->SetOptimization(opt
); }
493 #endif // WXWIN_COMPATIBILITY_2_4
495 virtual void SetPalette(const wxPalette
& palette
) { m_targetDc
->SetPalette(palette
); }
496 #endif // wxUSE_PALETTE
497 virtual void SetPen(const wxPen
& pen
) { m_targetDc
->SetPen(pen
); }
498 virtual void SetTextBackground(const wxColour
& colour
) { m_targetDc
->SetTextBackground(colour
); }
499 virtual void SetTextForeground(const wxColour
& colour
) { m_targetDc
->SetTextForeground(colour
); }
500 virtual void SetUserScale(double x
, double y
) { m_targetDc
->SetUserScale(x
, y
); }
501 virtual bool StartDoc(const wxString
& message
) { return m_targetDc
->StartDoc(message
); }
502 virtual void StartPage() { m_targetDc
->StartPage(); }
504 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
505 wxCoord width
, wxCoord height
,
506 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
507 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
)
508 { return m_targetDc
->Blit(xdest
, ydest
, width
, height
,
509 source
, xsrc
, ysrc
, rop
,
510 useMask
, xsrcMask
, ysrcMask
); }
511 virtual void DoCrossHair(wxCoord x
, wxCoord y
) { m_targetDc
->CrossHair(x
, y
); }
512 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
513 wxCoord x2
, wxCoord y2
,
514 wxCoord xc
, wxCoord yc
)
515 { m_targetDc
->DrawArc(x1
, y1
, x2
, y2
,
517 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
518 bool useMask
= false)
519 { m_targetDc
->DrawBitmap(bmp
, x
, y
, useMask
); }
520 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
521 wxCoord width
, wxCoord height
)
522 { m_targetDc
->DrawCheckMark(x
, y
, width
, height
); }
523 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
524 wxCoord width
, wxCoord height
)
525 { m_targetDc
->DrawEllipse(x
, y
, width
, height
); }
526 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
527 double sa
, double ea
)
528 { m_targetDc
->DrawEllipticArc(x
, y
, w
, h
,
530 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
531 { m_targetDc
->DrawIcon(icon
, x
, y
); }
532 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
533 { m_targetDc
->DrawLine(x1
, y1
, x2
, y2
); }
534 virtual void DoDrawLines(int n
, wxPoint points
[],
535 wxCoord xoffset
, wxCoord yoffset
)
536 { m_targetDc
->DrawLines(n
, points
, xoffset
, yoffset
); }
537 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) { m_targetDc
->DrawPoint(x
, y
); }
538 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
539 wxCoord xoffset
, wxCoord yoffset
,
541 { m_targetDc
->DrawPolyPolygon(n
, count
, points
, xoffset
,
542 yoffset
, fillStyle
); }
543 virtual void DoDrawPolygon(int n
, wxPoint points
[],
544 wxCoord xoffset
, wxCoord yoffset
,
545 int fillStyle
= wxODDEVEN_RULE
)
546 { m_targetDc
->DrawPolygon(n
, points
, xoffset
, yoffset
,
548 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
549 { m_targetDc
->DrawRectangle(x
, y
, width
, height
); }
550 virtual void DoDrawRotatedText(const wxString
& text
,
551 wxCoord x
, wxCoord y
, double angle
)
552 { m_targetDc
->DrawRotatedText(text
, x
, y
, angle
); }
553 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
554 wxCoord width
, wxCoord height
,
556 { m_targetDc
->DrawRoundedRectangle(x
, y
, width
, height
,
559 virtual void DoDrawSpline(wxList
*points
) { m_targetDc
->DrawSpline(points
); }
560 #endif // wxUSE_SPLINES
561 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
562 { m_targetDc
->DrawText(text
, x
, y
); }
563 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
564 int style
= wxFLOOD_SURFACE
)
565 { return m_targetDc
->FloodFill(x
, y
, col
, style
); }
566 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
567 wxCoord
*w
, wxCoord
*h
) const
568 { m_targetDc
->GetClippingBox(x
, y
, w
, h
); }
569 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
570 { m_targetDc
->GetDeviceOrigin(x
, y
); }
571 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
572 { m_targetDc
->GetLogicalOrigin(x
, y
); }
573 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
574 { return m_targetDc
->GetPartialTextExtents(text
, widths
); }
575 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
576 { return m_targetDc
->GetPixel(x
, y
, col
); }
577 virtual void DoGetSize(int *width
, int *height
) const { m_targetDc
->GetSize(width
, height
); }
578 virtual void DoGetSizeMM(int* width
, int* height
) const { m_targetDc
->GetSizeMM(width
, height
); }
579 virtual void DoGetTextExtent(const wxString
& string
,
580 wxCoord
*x
, wxCoord
*y
,
581 wxCoord
*descent
= NULL
,
582 wxCoord
*externalLeading
= NULL
,
583 wxFont
*theFont
= NULL
) const
584 { m_targetDc
->GetTextExtent(string
, x
, y
, descent
,
585 externalLeading
, theFont
); }
586 virtual void DoGradientFillLinear(const wxRect
& rect
,
587 const wxColour
& initialColour
,
588 const wxColour
& destColour
,
589 wxDirection nDirection
= wxEAST
)
590 { m_targetDc
->GradientFillLinear(rect
, initialColour
, destColour
, nDirection
); }
591 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
592 wxCoord width
, wxCoord height
)
593 { m_targetDc
->SetClippingRegion(x
, y
, width
, height
); }
594 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
)
595 { m_targetDc
->SetClippingRegion(region
); }
599 // ----------------------------------------------------------------------------
600 // Double buffered PaintDC.
601 // ----------------------------------------------------------------------------
603 // Creates a double buffered wxPaintDC, optionally allowing the
604 // user to specify their own buffer to use.
605 class wxBufferedPaintDC
: public wxBufferedDC
608 // If no bitmap is supplied by the user, a temporary one will be created.
609 wxBufferedPaintDC(wxWindow
*window
, const wxBitmap
& buffer
, int style
= wxBUFFER_CLIENT_AREA
)
612 // If we're buffering the virtual window, scale the paint DC as well
613 if (style
& wxBUFFER_VIRTUAL_AREA
)
614 window
->PrepareDC( m_paintdc
);
616 if( buffer
!= wxNullBitmap
)
617 Init(&m_paintdc
, buffer
, style
);
619 Init(window
, &m_paintdc
, window
->GetClientSize(), style
);
622 // If no bitmap is supplied by the user, a temporary one will be created.
623 wxBufferedPaintDC(wxWindow
*window
, int style
= wxBUFFER_CLIENT_AREA
)
626 // If we're using the virtual window, scale the paint DC as well
627 if (style
& wxBUFFER_VIRTUAL_AREA
)
628 window
->PrepareDC( m_paintdc
);
630 Init(window
, &m_paintdc
, window
->GetClientSize(), style
);
633 // default copy ctor ok.
635 virtual ~wxBufferedPaintDC()
637 // We must UnMask here, else by the time the base class
638 // does it, the PaintDC will have already been destroyed.
645 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC
)
651 // wxAutoBufferedPaintDC is a wxPaintDC in toolkits which have double-
652 // buffering by default. Otherwise it is a wxBufferedPaintDC. Thus,
653 // you can only expect it work with a simple constructor that
654 // accepts single wxWindow* argument.
656 #if wxALWAYS_NATIVE_DOUBLE_BUFFER
657 #define wxAutoBufferedPaintDCBase wxPaintDC
659 #define wxAutoBufferedPaintDCBase wxBufferedPaintDC
665 class wxAutoBufferedPaintDC
: public wxAutoBufferedPaintDCBase
669 wxAutoBufferedPaintDC(wxWindow
* win
)
670 : wxAutoBufferedPaintDCBase(win
)
675 virtual ~wxAutoBufferedPaintDC() { }
679 void TestWinStyle(wxWindow
* win
)
681 // Help the user to get the double-buffering working properly.
682 wxASSERT_MSG( win
->GetBackgroundStyle() == wxBG_STYLE_CUSTOM
,
683 wxT("In constructor, you need to call GetBackgroundStyle(wxBG_STYLE_CUSTOM), ")
684 wxT("and also, if needed, paint the background manually in the paint event handler."));
687 DECLARE_NO_COPY_CLASS(wxAutoBufferedPaintDC
)
690 #else // !__WXDEBUG__
692 // In release builds, just use typedef
693 typedef wxAutoBufferedPaintDCBase wxAutoBufferedPaintDC
;
698 #endif // _WX_DCBUFFER_H_