+public:
+ // Default ctor, must subsequently call Init for two stage construction.
+ wxBufferedDC()
+ : m_dc(NULL),
+ m_style(0)
+ {
+ }
+
+ // Construct a wxBufferedDC using a user supplied buffer.
+ wxBufferedDC(wxDC *dc,
+ const wxBitmap& buffer = wxNullBitmap,
+ int style = wxBUFFER_CLIENT_AREA)
+ : m_dc(NULL)
+ {
+ Init(dc, buffer, style);
+ }
+
+ // Construct a wxBufferedDC with an internal buffer of 'area'
+ // (where area is usually something like the size of the window
+ // being buffered)
+ wxBufferedDC(wxDC *dc, const wxSize& area, int style = wxBUFFER_CLIENT_AREA)
+ : m_dc(NULL)
+ {
+ Init(dc, area, style);
+ }
+
+ // The usually desired action in the dtor is to blit the buffer.
+ virtual ~wxBufferedDC()
+ {
+ if ( m_dc )
+ UnMask();
+ }
+
+ // These reimplement the actions of the ctors for two stage creation
+ void Init(wxDC *dc,
+ const wxBitmap& buffer = wxNullBitmap,
+ int style = wxBUFFER_CLIENT_AREA)
+ {
+ InitCommon(dc, style);
+
+ m_buffer = buffer;
+
+ UseBuffer();
+ }
+
+ void Init(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
+ {
+ InitCommon(dc, style);
+
+ UseBuffer(area.x, area.y);
+ }
+
+ // Blits the buffer to the dc, and detaches the dc from the buffer (so it
+ // can be effectively used once only).
+ //
+ // Usually called in the dtor or by the dtor of derived classes if the
+ // BufferedDC must blit before the derived class (which may own the dc it's
+ // blitting to) is destroyed.
+ void UnMask()
+ {
+ wxCHECK_RET( m_dc, _T("no underlying wxDC?") );
+ wxASSERT_MSG( m_buffer.IsOk(), _T("invalid backing store") );
+
+ wxCoord x = 0,
+ y = 0;
+
+ if ( m_style & wxBUFFER_CLIENT_AREA )
+ GetDeviceOrigin(&x, &y);
+
+ m_dc->Blit(0, 0, m_buffer.GetWidth(), m_buffer.GetHeight(),
+ this, -x, -y );
+ m_dc = NULL;
+ }
+
+ // Set and get the style
+ void SetStyle(int style) { m_style = style; }
+ int GetStyle() const { return m_style; }
+