+ // 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=wxNullBitmap,
+ int style = wxBUFFER_CLIENT_AREA)
+ {
+ wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
+ _T("wxBufferedDC already initialised") );
+ m_dc = dc;
+ m_buffer = buffer;
+ m_style = style;
+ UseBuffer();
+ }
+
+ void Init(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
+ {
+ Init(dc, wxBitmap(area.GetWidth(), area.GetHeight()), style);
+ }
+
+ // 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)") );
+
+ 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; }