1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/dcbufcmn.cpp
3 // Purpose: Buffered DC implementation
4 // Author: Ron Lee, Jaakko Salli
6 // Created: Sep-20-2006
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/dcbuffer.h"
33 // ============================================================================
35 // ============================================================================
37 // ============================================================================
38 // wxSharedDCBufferManager
39 // Helper class to free shared buffer when the app exists.
40 // ============================================================================
42 class wxSharedDCBufferManager
44 friend class wxBufferedDC
;
47 wxSharedDCBufferManager() { }
48 ~wxSharedDCBufferManager() { }
50 wxBitmap
* GetBuffer(int w
, int h
)
52 if ( !m_buffer
.IsOk() ||
53 w
> m_buffer
.GetWidth() ||
54 h
> m_buffer
.GetHeight() )
56 // Create slightly larger bitmap so we don't need to
57 // be reallocating constantly when the user enlarges
58 // the frame for the first time.
59 m_buffer
= wxBitmap(w
, h
);
69 static wxSharedDCBufferManager gs_sharedDCBufferManager
;
72 // ============================================================================
74 // ============================================================================
76 void wxBufferedDC::UseBuffer(wxCoord w
, wxCoord h
)
80 if ( w
== -1 || h
== -1 )
81 m_dc
->GetSize(&w
, &h
);
83 m_buffer
= gs_sharedDCBufferManager
.GetBuffer(w
, h
);
86 SelectObject(*m_buffer
);