]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dcbuffer.h
Updated Univ setup.
[wxWidgets.git] / include / wx / dcbuffer.h
CommitLineData
67e2efca
RL
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/dcbuffer.h
3// Purpose: wxBufferedDC class
4// Author: Ron Lee <ron@debian.org>
1cc8c8b7 5// Modified by: Vadim Zeitlin (refactored, added bg preservation)
67e2efca
RL
6// Created: 16/03/02
7// RCS-ID: $Id$
8// Copyright: (c) Ron Lee
65571936 9// Licence: wxWindows licence
67e2efca
RL
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DCBUFFER_H_
13#define _WX_DCBUFFER_H_
14
67e2efca 15#include "wx/dcmemory.h"
aeb500e6 16#include "wx/dcclient.h"
d910fe28 17#include "wx/window.h"
67e2efca 18
2e992e06
VZ
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
1cc8c8b7
VZ
42// ----------------------------------------------------------------------------
43// Double buffering helper.
44// ----------------------------------------------------------------------------
67e2efca 45
265a3864
JS
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
2e992e06 54class WXDLLEXPORT wxBufferedDC : public wxDC
1cc8c8b7
VZ
55{
56public:
57 // Default ctor, must subsequently call Init for two stage construction.
2e992e06
VZ
58 wxBufferedDC() : wxDC(), m_targetDc(NULL), m_mainDc(NULL),
59 m_buffer(NULL), m_style(0)
1cc8c8b7
VZ
60 {
61 }
67e2efca 62
1cc8c8b7 63 // Construct a wxBufferedDC using a user supplied buffer.
116627da
RD
64 wxBufferedDC(wxDC *dc,
65 const wxBitmap &buffer = wxNullBitmap,
66 int style = wxBUFFER_CLIENT_AREA)
2e992e06
VZ
67 : wxDC(),
68 m_targetDc(NULL),
69 m_mainDc(NULL)
dbd22c6a 70 {
2e992e06
VZ
71 // All other members except dcs are initialized in Init
72 Init(dc, buffer, style);
dbd22c6a 73 }
67e2efca 74
1cc8c8b7
VZ
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)
265a3864 78 wxBufferedDC(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
2e992e06
VZ
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 }
265a3864 86
2e992e06
VZ
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)
dbd22c6a 96 {
2e992e06
VZ
97 // All other members except dcs are initialized in Init
98 Init(win, dc, area, style);
dbd22c6a 99 }
67e2efca
RL
100
101 // default copy ctor ok.
102
1cc8c8b7 103 // The usually desired action in the dtor is to blit the buffer.
dbd22c6a
RL
104 virtual ~wxBufferedDC()
105 {
2e992e06 106 UnMask();
dbd22c6a 107 }
67e2efca 108
116627da 109 void Init(wxDC *dc,
2e992e06 110 const wxBitmap &buffer,
116627da 111 int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 112 {
2e992e06
VZ
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;
265a3864 119 m_style = style;
dbd22c6a
RL
120 UseBuffer();
121 }
122
2e992e06
VZ
123 void Init(wxWindow* win,
124 wxDC *dc,
125 const wxSize &area = wxDefaultSize,
126 int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 127 {
2e992e06
VZ
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);
dbd22c6a 155 }
67e2efca 156
1cc8c8b7
VZ
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.
2e992e06 163 void UnMask();
67e2efca 164
265a3864
JS
165 // Set and get the style
166 void SetStyle(int style) { m_style = style; }
167 int GetStyle() const { return m_style; }
168
1cc8c8b7 169private:
2e992e06
VZ
170 // Prepares wxMemoryDC.
171 void UseBuffer();
1cc8c8b7 172
2e992e06
VZ
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;
1cc8c8b7 178
2e992e06
VZ
179 // This the underlying DC to which we copy everything drawn on
180 // this one in UnMask().
74f4dabb
VZ
181 //
182 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
183 // could probably be a reference.
2e992e06 184 wxDC* m_mainDc;
67e2efca 185
74f4dabb 186 // the buffer (selected in this DC)
2e992e06 187 const wxBitmap* m_buffer;
22f3361e 188
265a3864 189 // the buffering style
2e992e06 190 int m_style;
265a3864 191
22f3361e 192 DECLARE_NO_COPY_CLASS(wxBufferedDC)
2e992e06
VZ
193public:
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#endif
226
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,
245 h, sa, ea); }
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,
263 sa, ea, angle); }
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,
268 xc, yc); }
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,
290 sa, ea); }
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,
299 sa, ea, angle); }
300 void DrawEllipticArcRot( const wxPoint& pt,
301 const wxSize& sz,
302 double sa = 0, double ea = 0, double angle = 0 )
303 { m_targetDc->DrawEllipticArcRot(pt, sz, sa, ea,
304 angle); }
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,
313 const wxRect& rect,
314 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
315 int indexAccel = -1,
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,
321 int indexAccel = -1)
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,
344 fillStyle); }
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,
358 double radius)
359 { m_targetDc->DrawRoundedRectangle(x, y, width, height,
360 radius); }
361 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
362 double radius)
363 { m_targetDc->DrawRoundedRectangle(pt, sz, radius); }
364 void DrawRoundedRectangle(const wxRect& r, double radius)
365 { m_targetDc->DrawRoundedRectangle(r, radius); }
366#if wxUSE_SPLINES
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,
371 x3, y3); }
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,
408 wxCoord *width,
409 wxCoord *height,
410 wxCoord *heightLine = NULL,
411 wxFont *font = NULL)
412 { m_targetDc->GetMultiLineTextExtent(text, width, height, heightLine,
413 font); }
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,
437 long *x, long *y,
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
494#if wxUSE_PALETTE
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(); }
503protected:
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,
516 xc, yc); }
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,
529 sa, ea); }
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,
540 int fillStyle)
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,
547 fillStyle); }
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,
555 double radius)
556 { m_targetDc->DrawRoundedRectangle(x, y, width, height,
557 radius); }
558#if wxUSE_SPLINES
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); }
67e2efca
RL
596};
597
598
1cc8c8b7
VZ
599// ----------------------------------------------------------------------------
600// Double buffered PaintDC.
601// ----------------------------------------------------------------------------
67e2efca
RL
602
603// Creates a double buffered wxPaintDC, optionally allowing the
604// user to specify their own buffer to use.
c0b15381 605class wxBufferedPaintDC : public wxBufferedDC
67e2efca 606{
67e2efca 607public:
265a3864
JS
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)
a66f2f42 610 : m_paintdc(window)
1cc8c8b7 611 {
265a3864
JS
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 );
615
dbd22c6a 616 if( buffer != wxNullBitmap )
265a3864 617 Init(&m_paintdc, buffer, style);
dbd22c6a 618 else
2e992e06 619 Init(window, &m_paintdc, window->GetClientSize(), style);
265a3864
JS
620 }
621
622 // If no bitmap is supplied by the user, a temporary one will be created.
623 wxBufferedPaintDC(wxWindow *window, int style = wxBUFFER_CLIENT_AREA)
624 : m_paintdc(window)
625 {
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 );
629
2e992e06 630 Init(window, &m_paintdc, window->GetClientSize(), style);
1cc8c8b7 631 }
67e2efca
RL
632
633 // default copy ctor ok.
634
1cc8c8b7
VZ
635 virtual ~wxBufferedPaintDC()
636 {
637 // We must UnMask here, else by the time the base class
638 // does it, the PaintDC will have already been destroyed.
639 UnMask();
640 }
641
642private:
1cc8c8b7 643 wxPaintDC m_paintdc;
fc7a2a60
VZ
644
645 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC)
67e2efca
RL
646};
647
67e2efca 648
2e992e06
VZ
649
650//
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.
655//
656#if wxALWAYS_NATIVE_DOUBLE_BUFFER
657 #define wxAutoBufferedPaintDCBase wxPaintDC
658#else
659 #define wxAutoBufferedPaintDCBase wxBufferedPaintDC
660#endif
661
662
663#ifdef __WXDEBUG__
664
665class wxAutoBufferedPaintDC : public wxAutoBufferedPaintDCBase
666{
667public:
668
669 wxAutoBufferedPaintDC(wxWindow* win)
670 : wxAutoBufferedPaintDCBase(win)
671 {
672 TestWinStyle(win);
673 }
674
675 virtual ~wxAutoBufferedPaintDC() { }
676
677private:
678
679 void TestWinStyle(wxWindow* win)
680 {
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."));
685 }
686
687 DECLARE_NO_COPY_CLASS(wxAutoBufferedPaintDC)
688};
689
690#else // !__WXDEBUG__
691
692// In release builds, just use typedef
693typedef wxAutoBufferedPaintDCBase wxAutoBufferedPaintDC;
694
695#endif
696
697
698#endif // _WX_DCBUFFER_H_