]> git.saurik.com Git - wxWidgets.git/blame - src/common/dcbufcmn.cpp
Corrected bug in in revision 47973
[wxWidgets.git] / src / common / dcbufcmn.cpp
CommitLineData
2e992e06
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/dcbufcmn.cpp
3// Purpose: Buffered DC implementation
4// Author: Ron Lee, Jaakko Salli
5// Modified by:
6// Created: Sep-20-2006
7// RCS-ID: $Id$
8// Copyright: (c) wxWidgets team
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
576bdf85
PC
27#include "wx/dcbuffer.h"
28
2e992e06 29#ifndef WX_PRECOMP
37747da8 30 #include "wx/module.h"
2e992e06
VZ
31#endif
32
2e992e06
VZ
33// ============================================================================
34// implementation
35// ============================================================================
36
1a9a3ce9
VZ
37// ----------------------------------------------------------------------------
38// wxSharedDCBufferManager: helper class maintaining backing store bitmap
39// ----------------------------------------------------------------------------
77f62aa7 40
37747da8 41class wxSharedDCBufferManager : public wxModule
77f62aa7 42{
77f62aa7 43public:
77f62aa7 44 wxSharedDCBufferManager() { }
77f62aa7 45
37747da8
VZ
46 virtual bool OnInit() { return true; }
47 virtual void OnExit() { wxDELETE(ms_buffer); }
48
3754c856 49 static wxBitmap* GetBuffer(int w, int h)
77f62aa7 50 {
125817d0
VZ
51 if ( ms_usingSharedBuffer )
52 return new wxBitmap(w, h);
53
37747da8
VZ
54 if ( !ms_buffer ||
55 w > ms_buffer->GetWidth() ||
56 h > ms_buffer->GetHeight() )
77f62aa7 57 {
37747da8
VZ
58 delete ms_buffer;
59 ms_buffer = new wxBitmap(w, h);
77f62aa7 60 }
125817d0
VZ
61
62 ms_usingSharedBuffer = true;
3754c856 63 return ms_buffer;
77f62aa7
RD
64 }
65
125817d0
VZ
66 static void ReleaseBuffer(wxBitmap* buffer)
67 {
68 if ( buffer == ms_buffer )
69 {
70 wxASSERT_MSG( ms_usingSharedBuffer, wxT("shared buffer already released") );
71 ms_usingSharedBuffer = false;
72 }
73 else
74 {
75 delete buffer;
76 }
77 }
78
77f62aa7 79private:
37747da8 80 static wxBitmap *ms_buffer;
125817d0 81 static bool ms_usingSharedBuffer;
77f62aa7 82
37747da8
VZ
83 DECLARE_DYNAMIC_CLASS(wxSharedDCBufferManager)
84};
77f62aa7 85
3754c856 86wxBitmap* wxSharedDCBufferManager::ms_buffer = NULL;
125817d0 87bool wxSharedDCBufferManager::ms_usingSharedBuffer = false;
576bdf85 88
37747da8 89IMPLEMENT_DYNAMIC_CLASS(wxSharedDCBufferManager, wxModule)
77f62aa7
RD
90
91// ============================================================================
92// wxBufferedDC
93// ============================================================================
94
95void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
96{
3754c856 97 if ( !m_buffer || !m_buffer->IsOk() )
77f62aa7
RD
98 {
99 if ( w == -1 || h == -1 )
100 m_dc->GetSize(&w, &h);
101
37747da8 102 m_buffer = wxSharedDCBufferManager::GetBuffer(w, h);
125817d0 103 m_style |= wxBUFFER_USES_SHARED_BUFFER;
77f62aa7
RD
104 }
105
3754c856 106 SelectObject(*m_buffer);
77f62aa7 107}
2e992e06 108
125817d0
VZ
109void wxBufferedDC::UnMask()
110{
111 wxCHECK_RET( m_dc, _T("no underlying wxDC?") );
112 wxASSERT_MSG( m_buffer && m_buffer->IsOk(), _T("invalid backing store") );
113
114 wxCoord x = 0,
115 y = 0;
116
117 if ( m_style & wxBUFFER_CLIENT_AREA )
118 GetDeviceOrigin(&x, &y);
119
120 m_dc->Blit(0, 0, m_buffer->GetWidth(), m_buffer->GetHeight(),
121 this, -x, -y );
122 m_dc = NULL;
123
124 if ( m_style & wxBUFFER_USES_SHARED_BUFFER )
125 wxSharedDCBufferManager::ReleaseBuffer(m_buffer);
126}