+ // 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, but
+ // are not used by the ctors themselves to save a few cpu cycles.
+ void Init(wxDC *dc, const wxBitmap &buffer)
+ {
+ wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
+ _T("wxBufferedDC already initialised") );
+ m_dc = dc;
+ m_buffer = buffer;
+ UseBuffer();
+ }
+
+ void Init(wxDC *dc, const wxSize &area)
+ {
+ Init(dc, wxBitmap(area.GetWidth(), area.GetHeight()));
+ }
+
+ // 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()
+ {
+ wxASSERT_MSG( m_dc != 0,
+ _T("No underlying DC associated with wxBufferedDC (anymore)") );
+
+ m_dc->Blit( 0, 0,
+ m_buffer.GetWidth(), m_buffer.GetHeight(), this,
+ 0, 0 );
+ m_dc = NULL;
+ }