]> git.saurik.com Git - wxWidgets.git/blob - src/common/dcbufcmn.cpp
avoiding nesting dcs on the same window concurrently
[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 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 // ============================================================================
38 // wxSharedDCBufferManager
39 // Helper class to free shared buffer when the app exists.
40 // ============================================================================
41
42 class wxSharedDCBufferManager
43 {
44 friend class wxBufferedDC;
45 public:
46
47 wxSharedDCBufferManager() { }
48 ~wxSharedDCBufferManager() { }
49
50 wxBitmap* GetBuffer(int w, int h)
51 {
52 if ( !m_buffer.IsOk() ||
53 w > m_buffer.GetWidth() ||
54 h > m_buffer.GetHeight() )
55 {
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);
60 }
61
62 return &m_buffer;
63 }
64
65 private:
66 wxBitmap m_buffer;
67 };
68
69 static wxSharedDCBufferManager gs_sharedDCBufferManager;
70
71
72 // ============================================================================
73 // wxBufferedDC
74 // ============================================================================
75
76 void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
77 {
78 if ( !m_buffer )
79 {
80 if ( w == -1 || h == -1 )
81 m_dc->GetSize(&w, &h);
82
83 m_buffer = gs_sharedDCBufferManager.GetBuffer(w, h);
84 }
85
86 SelectObject(*m_buffer);
87 }
88