]> git.saurik.com Git - wxWidgets.git/blob - src/common/dcbufcmn.cpp
while gcc 4 works under xcode, 3.3. builds don't, therefore this workaround for sourc...
[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 {
49 m_buffer = NULL;
50 }
51
52 ~wxSharedDCBufferManager()
53 {
54 delete m_buffer;
55 }
56
57 wxBitmap* GetBuffer(wxWindow* win, const wxSize& area)
58 {
59 int width = area.x;
60 int height = area.y;
61
62 if ( width <= 0 )
63 win->GetClientSize(&width, &height);
64
65 if ( !m_buffer ||
66 width > m_buffer->GetWidth() ||
67 height > m_buffer->GetHeight() )
68 {
69 delete m_buffer;
70
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);
75 }
76
77 return m_buffer;
78 }
79
80 private:
81 wxBitmap* m_buffer;
82 };
83
84 static wxSharedDCBufferManager gs_sharedDCBufferManager;
85
86 // ============================================================================
87 // wxBufferedDC
88 // ============================================================================
89
90 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
91 // can be effectively used once only).
92 //
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()
97 {
98 if ( m_buffer )
99 {
100 wxDC* bufferDc = DetachDC();
101
102 wxASSERT( bufferDc->IsKindOf(CLASSINFO(wxMemoryDC)) );
103
104 if (m_mainDc)
105 {
106 wxCoord x=0, y=0;
107
108 if (m_style & wxBUFFER_CLIENT_AREA)
109 bufferDc->GetDeviceOrigin(&x, &y);
110
111 m_mainDc->Blit( 0, 0,
112 m_buffer->GetWidth(), m_buffer->GetHeight(), bufferDc,
113 -x, -y );
114 m_mainDc = NULL;
115 }
116
117 m_buffer = NULL;
118 delete bufferDc;
119 }
120 }
121
122 void wxBufferedDC::PrepareBuffer(wxWindow* win, const wxSize& area)
123 {
124 m_buffer = gs_sharedDCBufferManager.GetBuffer(win, area);
125 }
126
127 void wxBufferedDC::UseBuffer()
128 {
129 wxASSERT(m_buffer);
130
131 wxMemoryDC* memoryDc = m_mainDc ? new wxMemoryDC(m_mainDc): new wxMemoryDC();
132 memoryDc->SelectObject(*m_buffer);
133
134 AttachDC(memoryDc);
135 }
136
137