]> git.saurik.com Git - wxWidgets.git/blob - src/common/dcbufcmn.cpp
use wxBitmap object as m_buffer and not a pointer to it (replaces patch 1582878)
[wxWidgets.git] / src / common / dcbufcmn.cpp
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
27 #ifndef WX_PRECOMP
28 #endif
29
30 #include "wx/dcbuffer.h"
31
32 // ============================================================================
33 // implementation
34 // ============================================================================
35
36 // ----------------------------------------------------------------------------
37 // wxSharedDCBufferManager: helper class maintaining backing store bitmap
38 // ----------------------------------------------------------------------------
39
40 class wxSharedDCBufferManager
41 {
42 public:
43 wxSharedDCBufferManager() { }
44 ~wxSharedDCBufferManager() { }
45
46 wxBitmap GetBuffer(int w, int h)
47 {
48 if ( !m_buffer.IsOk() ||
49 w > m_buffer.GetWidth() ||
50 h > m_buffer.GetHeight() )
51 {
52 // Create slightly larger bitmap so we don't need to
53 // be reallocating constantly when the user enlarges
54 // the frame for the first time.
55 m_buffer = wxBitmap(w, h);
56 }
57
58 return m_buffer;
59 }
60
61 private:
62 wxBitmap m_buffer;
63 };
64
65 static wxSharedDCBufferManager gs_sharedDCBufferManager;
66
67
68 // ============================================================================
69 // wxBufferedDC
70 // ============================================================================
71
72 void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
73 {
74 if ( !m_buffer.IsOk() )
75 {
76 if ( w == -1 || h == -1 )
77 m_dc->GetSize(&w, &h);
78
79 m_buffer = gs_sharedDCBufferManager.GetBuffer(w, h);
80 }
81
82 SelectObject(m_buffer);
83 }
84