use wxBitmap object as m_buffer and not a pointer to it (replaces patch 1582878)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42309 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-10-23 22:06:01 +00:00
parent e3cec970d7
commit 1a9a3ce9a3
2 changed files with 17 additions and 24 deletions

View File

@ -43,7 +43,6 @@ public:
// Default ctor, must subsequently call Init for two stage construction.
wxBufferedDC()
: m_dc(NULL),
m_buffer(NULL),
m_style(0)
{
}
@ -52,8 +51,7 @@ public:
wxBufferedDC(wxDC *dc,
const wxBitmap& buffer = wxNullBitmap,
int style = wxBUFFER_CLIENT_AREA)
: m_dc(NULL),
m_buffer(NULL)
: m_dc(NULL)
{
Init(dc, buffer, style);
}
@ -62,9 +60,7 @@ public:
// (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),
m_buffer(NULL)
: m_dc(NULL)
{
Init(dc, area, style);
}
@ -83,7 +79,7 @@ public:
{
InitCommon(dc, style);
m_buffer = &buffer;
m_buffer = buffer;
UseBuffer();
}
@ -103,7 +99,8 @@ public:
// blitting to) is destroyed.
void UnMask()
{
wxCHECK_RET( m_dc, _T("No underlying DC in wxBufferedDC") );
wxCHECK_RET( m_dc, _T("no underlying wxDC?") );
wxASSERT_MSG( m_buffer.IsOk(), _T("invalid backing store") );
wxCoord x = 0,
y = 0;
@ -111,7 +108,7 @@ public:
if ( m_style & wxBUFFER_CLIENT_AREA )
GetDeviceOrigin(&x, &y);
m_dc->Blit(0, 0, m_buffer->GetWidth(), m_buffer->GetHeight(),
m_dc->Blit(0, 0, m_buffer.GetWidth(), m_buffer.GetHeight(),
this, -x, -y );
m_dc = NULL;
}
@ -124,7 +121,7 @@ private:
// common part of Init()s
void InitCommon(wxDC *dc, int style)
{
wxASSERT_MSG( !m_dc && !m_buffer, _T("wxBufferedDC already initialised") );
wxASSERT_MSG( !m_dc, _T("wxBufferedDC already initialised") );
wxCHECK_RET( dc, _T("can't associate NULL DC with wxBufferedDC") );
m_dc = dc;
@ -144,8 +141,8 @@ private:
// could probably be a reference.
wxDC *m_dc;
// the buffer (selected in this DC)
const wxBitmap *m_buffer;
// the buffer (selected in this DC), initially invalid
wxBitmap m_buffer;
// the buffering style
int m_style;

View File

@ -29,25 +29,21 @@
#include "wx/dcbuffer.h"
// ============================================================================
// implementation
// ============================================================================
// ============================================================================
// wxSharedDCBufferManager
// Helper class to free shared buffer when the app exists.
// ============================================================================
// ----------------------------------------------------------------------------
// wxSharedDCBufferManager: helper class maintaining backing store bitmap
// ----------------------------------------------------------------------------
class wxSharedDCBufferManager
{
friend class wxBufferedDC;
public:
wxSharedDCBufferManager() { }
~wxSharedDCBufferManager() { }
wxBitmap* GetBuffer(int w, int h)
wxBitmap GetBuffer(int w, int h)
{
if ( !m_buffer.IsOk() ||
w > m_buffer.GetWidth() ||
@ -59,11 +55,11 @@ public:
m_buffer = wxBitmap(w, h);
}
return &m_buffer;
return m_buffer;
}
private:
wxBitmap m_buffer;
wxBitmap m_buffer;
};
static wxSharedDCBufferManager gs_sharedDCBufferManager;
@ -75,7 +71,7 @@ static wxSharedDCBufferManager gs_sharedDCBufferManager;
void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
{
if ( !m_buffer )
if ( !m_buffer.IsOk() )
{
if ( w == -1 || h == -1 )
m_dc->GetSize(&w, &h);
@ -83,6 +79,6 @@ void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
m_buffer = gs_sharedDCBufferManager.GetBuffer(w, h);
}
SelectObject(*m_buffer);
SelectObject(m_buffer);
}