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()
52 ~wxSharedDCBufferManager()
57 wxBitmap
* GetBuffer(wxWindow
* win
, const wxSize
& area
)
63 win
->GetClientSize(&width
, &height
);
66 width
> m_buffer
->GetWidth() ||
67 height
> m_buffer
->GetHeight() )
71 // Create slightly larger bitmap so we don't need to
72 // be reallocating constantly when the user enlarges
73 // the frame for the first time.
74 m_buffer
= new wxBitmap(width
+20, height
+20);
84 static wxSharedDCBufferManager gs_sharedDCBufferManager
;
86 // ============================================================================
88 // ============================================================================
90 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
91 // can be effectively used once only).
93 // Usually called in the dtor or by the dtor of derived classes if the
94 // BufferedDC must blit before the derived class (which may own the dc it's
95 // blitting to) is destroyed.
96 void wxBufferedDC::UnMask()
100 wxDC
* bufferDc
= DetachDC();
102 wxASSERT( bufferDc
->IsKindOf(CLASSINFO(wxMemoryDC
)) );
108 if (m_style
& wxBUFFER_CLIENT_AREA
)
109 bufferDc
->GetDeviceOrigin(&x
, &y
);
111 m_mainDc
->Blit( 0, 0,
112 m_buffer
->GetWidth(), m_buffer
->GetHeight(), bufferDc
,
122 void wxBufferedDC::PrepareBuffer(wxWindow
* win
, const wxSize
& area
)
124 m_buffer
= gs_sharedDCBufferManager
.GetBuffer(win
, area
);
127 void wxBufferedDC::UseBuffer()
131 wxMemoryDC
* memoryDc
= m_mainDc
? new wxMemoryDC(m_mainDc
): new wxMemoryDC();
132 memoryDc
->SelectObject(*m_buffer
);