]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dcbuffer.h
fix top margin for static box sizer when wxDIALOG_UNIT_COMPATIBILITY == 0
[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.
265a3864 40 wxBufferedDC(wxDC *dc, const wxBitmap &buffer, int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 41 : m_dc( dc ),
265a3864
JS
42 m_buffer( buffer ),
43 m_style(style)
dbd22c6a
RL
44 {
45 UseBuffer();
46 }
67e2efca 47
1cc8c8b7
VZ
48 // Construct a wxBufferedDC with an internal buffer of 'area'
49 // (where area is usually something like the size of the window
50 // being buffered)
265a3864 51 wxBufferedDC(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 52 : m_dc( dc ),
265a3864
JS
53 m_buffer( area.GetWidth(), area.GetHeight() ),
54 m_style(style)
55
dbd22c6a
RL
56 {
57 UseBuffer();
58 }
67e2efca
RL
59
60 // default copy ctor ok.
61
1cc8c8b7 62 // The usually desired action in the dtor is to blit the buffer.
dbd22c6a
RL
63 virtual ~wxBufferedDC()
64 {
65 if ( m_dc ) UnMask();
66 }
67e2efca 67
1cc8c8b7
VZ
68 // These reimplement the actions of the ctors for two stage creation, but
69 // are not used by the ctors themselves to save a few cpu cycles.
265a3864 70 void Init(wxDC *dc, const wxBitmap &buffer, int style = wxBUFFER_CLIENT_AREA)
dbd22c6a
RL
71 {
72 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
73 _T("wxBufferedDC already initialised") );
74 m_dc = dc;
75 m_buffer = buffer;
265a3864 76 m_style = style;
dbd22c6a
RL
77 UseBuffer();
78 }
79
265a3864 80 void Init(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
dbd22c6a 81 {
265a3864 82 Init(dc, wxBitmap(area.GetWidth(), area.GetHeight()), style);
dbd22c6a 83 }
67e2efca 84
1cc8c8b7
VZ
85 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
86 // can be effectively used once only).
87 //
88 // Usually called in the dtor or by the dtor of derived classes if the
89 // BufferedDC must blit before the derived class (which may own the dc it's
90 // blitting to) is destroyed.
dbd22c6a
RL
91 void UnMask()
92 {
93 wxASSERT_MSG( m_dc != 0,
94 _T("No underlying DC associated with wxBufferedDC (anymore)") );
95
265a3864
JS
96 wxCoord x=0, y=0;
97
98 if (m_style & wxBUFFER_CLIENT_AREA)
99 GetDeviceOrigin(& x, & y);
96991c58 100
7775e41f 101 m_dc->Blit( 0, 0,
dbd22c6a 102 m_buffer.GetWidth(), m_buffer.GetHeight(), this,
96991c58 103 -x, -y );
dbd22c6a
RL
104 m_dc = NULL;
105 }
67e2efca 106
265a3864
JS
107 // Set and get the style
108 void SetStyle(int style) { m_style = style; }
109 int GetStyle() const { return m_style; }
110
1cc8c8b7
VZ
111private:
112 // check that the bitmap is valid and use it
113 void UseBuffer()
114 {
115 wxASSERT_MSG( m_buffer.Ok(), _T("invalid bitmap in wxBufferedDC") );
116
117 SelectObject(m_buffer);
118 }
119
74f4dabb
VZ
120 // the underlying DC to which we copy everything drawn on this one in
121 // UnMask()
122 //
123 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
124 // could probably be a reference.
125 wxDC *m_dc;
67e2efca 126
74f4dabb
VZ
127 // the buffer (selected in this DC)
128 wxBitmap m_buffer;
22f3361e 129
265a3864
JS
130 // the buffering style
131 int m_style;
132
22f3361e 133 DECLARE_NO_COPY_CLASS(wxBufferedDC)
67e2efca
RL
134};
135
136
1cc8c8b7
VZ
137// ----------------------------------------------------------------------------
138// Double buffered PaintDC.
139// ----------------------------------------------------------------------------
67e2efca
RL
140
141// Creates a double buffered wxPaintDC, optionally allowing the
142// user to specify their own buffer to use.
c0b15381 143class wxBufferedPaintDC : public wxBufferedDC
67e2efca 144{
67e2efca 145public:
265a3864
JS
146 // If no bitmap is supplied by the user, a temporary one will be created.
147 wxBufferedPaintDC(wxWindow *window, const wxBitmap& buffer, int style = wxBUFFER_CLIENT_AREA)
a66f2f42 148 : m_paintdc(window)
1cc8c8b7 149 {
265a3864
JS
150 // If we're buffering the virtual window, scale the paint DC as well
151 if (style & wxBUFFER_VIRTUAL_AREA)
152 window->PrepareDC( m_paintdc );
153
dbd22c6a 154 if( buffer != wxNullBitmap )
265a3864 155 Init(&m_paintdc, buffer, style);
dbd22c6a 156 else
265a3864
JS
157 Init(&m_paintdc, window->GetClientSize(), style);
158 }
159
160 // If no bitmap is supplied by the user, a temporary one will be created.
161 wxBufferedPaintDC(wxWindow *window, int style = wxBUFFER_CLIENT_AREA)
162 : m_paintdc(window)
163 {
164 // If we're using the virtual window, scale the paint DC as well
165 if (style & wxBUFFER_VIRTUAL_AREA)
166 window->PrepareDC( m_paintdc );
167
168 Init(&m_paintdc, window->GetClientSize(), style);
1cc8c8b7 169 }
67e2efca
RL
170
171 // default copy ctor ok.
172
1cc8c8b7
VZ
173 virtual ~wxBufferedPaintDC()
174 {
175 // We must UnMask here, else by the time the base class
176 // does it, the PaintDC will have already been destroyed.
177 UnMask();
178 }
179
180private:
1cc8c8b7 181 wxPaintDC m_paintdc;
fc7a2a60
VZ
182
183 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC)
67e2efca
RL
184};
185
67e2efca
RL
186#endif // _WX_DCBUFFER_H_
187