]> git.saurik.com Git - wxWidgets.git/blob - src/generic/dcbuffer.cpp
added wxEXEC_MAKE_GROUP_LEADER (patch 535422)
[wxWidgets.git] / src / generic / dcbuffer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcbuffer.cpp
3 // Purpose: wxBufferedDC class
4 // Author: Ron Lee <ron@debian.org>
5 // Modified by:
6 // Created: 16/03/02
7 // RCS-ID: $Id$
8 // Copyright: (c) Ron Lee
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 #ifdef __GNUG__
14 #pragma implementation "dcbuffer.h"
15 #endif
16
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/window.h"
25 #endif
26
27 #include "wx/dcbuffer.h"
28
29
30 // ==============================================================
31 // Double buffering helper.
32 // --------------------------------------------------------------
33
34 wxBufferedDC::wxBufferedDC( wxDC *dc, const wxBitmap &buffer )
35 : m_dc( dc )
36 , m_buffer( buffer )
37 {
38 SelectObject( m_buffer );
39 }
40
41 wxBufferedDC::wxBufferedDC( wxDC *dc, const wxSize &area )
42 : m_dc( dc )
43 , m_buffer( area.GetWidth(), area.GetHeight() )
44 {
45 SelectObject( m_buffer );
46 }
47
48 wxBufferedDC::~wxBufferedDC()
49 {
50 if( m_dc != 0 )
51 {
52 UnMask();
53 }
54 }
55
56 void wxBufferedDC::Init( wxDC *dc, const wxBitmap &buffer )
57 {
58 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
59 _T("wxBufferedDC already initialised") );
60
61 m_dc = dc;
62 m_buffer = buffer;
63 SelectObject( m_buffer );
64 }
65
66 void wxBufferedDC::Init( wxDC *dc, const wxSize &area )
67 {
68 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
69 _T("wxBufferedDC already initialised") );
70
71 m_dc = dc;
72 m_buffer = wxBitmap( area.GetWidth(), area.GetHeight() );
73 SelectObject( m_buffer );
74 }
75
76 void wxBufferedDC::UnMask()
77 {
78 wxASSERT_MSG( m_dc != 0, _T("No low level DC associated with buffer (anymore)") );
79
80 m_dc->Blit( 0, 0, m_buffer.GetWidth(), m_buffer.GetHeight(), this, 0, 0 );
81 m_dc = 0;
82 }
83
84
85 // ==============================================================
86 // Double buffered PaintDC.
87 // --------------------------------------------------------------
88
89 wxBufferedPaintDC::wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer )
90 : m_paintdc( window )
91 {
92 window->PrepareDC( m_paintdc );
93
94 if( buffer != wxNullBitmap )
95 Init( &m_paintdc, buffer );
96 else
97 Init( &m_paintdc, window->GetClientSize() );
98 }
99
100 wxBufferedPaintDC::~wxBufferedPaintDC()
101 {
102 // We must UnMask here, else by the time the base class
103 // does it, the PaintDC will have already been destroyed.
104
105 UnMask();
106 }
107
108
109 // vi:sts=4:sw=4:et