]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dcbuffer.h
Removed no longer needed "DECLARE_EVENT_TABLE()" completing the previous change.
[wxWidgets.git] / include / wx / dcbuffer.h
CommitLineData
67e2efca
RL
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/dcbuffer.h
3// Purpose: wxBufferedDC class
4// Author: Ron Lee <ron@debian.org>
1cc8c8b7 5// Modified by: Vadim Zeitlin (refactored, added bg preservation)
67e2efca
RL
6// Created: 16/03/02
7// RCS-ID: $Id$
8// Copyright: (c) Ron Lee
65571936 9// Licence: wxWindows licence
67e2efca
RL
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DCBUFFER_H_
13#define _WX_DCBUFFER_H_
14
67e2efca 15#include "wx/dcmemory.h"
aeb500e6 16#include "wx/dcclient.h"
d910fe28 17#include "wx/window.h"
67e2efca 18
1cc8c8b7
VZ
19// ----------------------------------------------------------------------------
20// Double buffering helper.
21// ----------------------------------------------------------------------------
67e2efca 22
265a3864
JS
23// Assumes the buffer bitmap covers the entire scrolled window,
24// and prepares the window DC accordingly
25#define wxBUFFER_VIRTUAL_AREA 0x01
26
27// Assumes the buffer bitmap only covers the client area;
28// does not prepare the window DC
29#define wxBUFFER_CLIENT_AREA 0x02
30
c0b15381 31class wxBufferedDC : public wxMemoryDC
1cc8c8b7
VZ
32{
33public:
34 // Default ctor, must subsequently call Init for two stage construction.
265a3864 35 wxBufferedDC() : m_dc( 0 ), m_style(0)
1cc8c8b7
VZ
36 {
37 }
67e2efca 38
1cc8c8b7 39 // Construct a wxBufferedDC using a user supplied buffer.
116627da
RD
40 wxBufferedDC(wxDC *dc,
41 const wxBitmap &buffer = wxNullBitmap,
42 int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 43 : m_dc( dc ),
265a3864
JS
44 m_buffer( buffer ),
45 m_style(style)
dbd22c6a
RL
46 {
47 UseBuffer();
48 }
67e2efca 49
1cc8c8b7
VZ
50 // Construct a wxBufferedDC with an internal buffer of 'area'
51 // (where area is usually something like the size of the window
52 // being buffered)
265a3864 53 wxBufferedDC(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 54 : m_dc( dc ),
265a3864
JS
55 m_buffer( area.GetWidth(), area.GetHeight() ),
56 m_style(style)
57
dbd22c6a
RL
58 {
59 UseBuffer();
60 }
67e2efca
RL
61
62 // default copy ctor ok.
63
1cc8c8b7 64 // The usually desired action in the dtor is to blit the buffer.
dbd22c6a
RL
65 virtual ~wxBufferedDC()
66 {
67 if ( m_dc ) UnMask();
68 }
67e2efca 69
1cc8c8b7
VZ
70 // These reimplement the actions of the ctors for two stage creation, but
71 // are not used by the ctors themselves to save a few cpu cycles.
116627da
RD
72 void Init(wxDC *dc,
73 const wxBitmap &buffer=wxNullBitmap,
74 int style = wxBUFFER_CLIENT_AREA)
dbd22c6a
RL
75 {
76 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
77 _T("wxBufferedDC already initialised") );
78 m_dc = dc;
79 m_buffer = buffer;
265a3864 80 m_style = style;
dbd22c6a
RL
81 UseBuffer();
82 }
83
265a3864 84 void Init(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 85 {
265a3864 86 Init(dc, wxBitmap(area.GetWidth(), area.GetHeight()), style);
dbd22c6a 87 }
67e2efca 88
1cc8c8b7
VZ
89 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
90 // can be effectively used once only).
91 //
92 // Usually called in the dtor or by the dtor of derived classes if the
93 // BufferedDC must blit before the derived class (which may own the dc it's
94 // blitting to) is destroyed.
dbd22c6a
RL
95 void UnMask()
96 {
97 wxASSERT_MSG( m_dc != 0,
98 _T("No underlying DC associated with wxBufferedDC (anymore)") );
99
265a3864
JS
100 wxCoord x=0, y=0;
101
102 if (m_style & wxBUFFER_CLIENT_AREA)
103 GetDeviceOrigin(& x, & y);
96991c58 104
7775e41f 105 m_dc->Blit( 0, 0,
dbd22c6a 106 m_buffer.GetWidth(), m_buffer.GetHeight(), this,
96991c58 107 -x, -y );
dbd22c6a
RL
108 m_dc = NULL;
109 }
67e2efca 110
265a3864
JS
111 // Set and get the style
112 void SetStyle(int style) { m_style = style; }
113 int GetStyle() const { return m_style; }
114
1cc8c8b7
VZ
115private:
116 // check that the bitmap is valid and use it
117 void UseBuffer()
118 {
116627da
RD
119 if (!m_buffer.Ok())
120 {
121 wxCoord w, h;
122 m_dc->GetSize(&w, &h);
123 m_buffer = wxBitmap(w, h);
124 }
1cc8c8b7
VZ
125
126 SelectObject(m_buffer);
127 }
128
74f4dabb
VZ
129 // the underlying DC to which we copy everything drawn on this one in
130 // UnMask()
131 //
132 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
133 // could probably be a reference.
134 wxDC *m_dc;
67e2efca 135
74f4dabb
VZ
136 // the buffer (selected in this DC)
137 wxBitmap m_buffer;
22f3361e 138
265a3864
JS
139 // the buffering style
140 int m_style;
141
22f3361e 142 DECLARE_NO_COPY_CLASS(wxBufferedDC)
67e2efca
RL
143};
144
145
1cc8c8b7
VZ
146// ----------------------------------------------------------------------------
147// Double buffered PaintDC.
148// ----------------------------------------------------------------------------
67e2efca
RL
149
150// Creates a double buffered wxPaintDC, optionally allowing the
151// user to specify their own buffer to use.
c0b15381 152class wxBufferedPaintDC : public wxBufferedDC
67e2efca 153{
67e2efca 154public:
265a3864
JS
155 // If no bitmap is supplied by the user, a temporary one will be created.
156 wxBufferedPaintDC(wxWindow *window, const wxBitmap& buffer, int style = wxBUFFER_CLIENT_AREA)
a66f2f42 157 : m_paintdc(window)
1cc8c8b7 158 {
265a3864
JS
159 // If we're buffering the virtual window, scale the paint DC as well
160 if (style & wxBUFFER_VIRTUAL_AREA)
161 window->PrepareDC( m_paintdc );
162
dbd22c6a 163 if( buffer != wxNullBitmap )
265a3864 164 Init(&m_paintdc, buffer, style);
dbd22c6a 165 else
265a3864
JS
166 Init(&m_paintdc, window->GetClientSize(), style);
167 }
168
169 // If no bitmap is supplied by the user, a temporary one will be created.
170 wxBufferedPaintDC(wxWindow *window, int style = wxBUFFER_CLIENT_AREA)
171 : m_paintdc(window)
172 {
173 // If we're using the virtual window, scale the paint DC as well
174 if (style & wxBUFFER_VIRTUAL_AREA)
175 window->PrepareDC( m_paintdc );
176
177 Init(&m_paintdc, window->GetClientSize(), style);
1cc8c8b7 178 }
67e2efca
RL
179
180 // default copy ctor ok.
181
1cc8c8b7
VZ
182 virtual ~wxBufferedPaintDC()
183 {
184 // We must UnMask here, else by the time the base class
185 // does it, the PaintDC will have already been destroyed.
186 UnMask();
187 }
188
189private:
1cc8c8b7 190 wxPaintDC m_paintdc;
fc7a2a60
VZ
191
192 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC)
67e2efca
RL
193};
194
67e2efca
RL
195#endif // _WX_DCBUFFER_H_
196