]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/dcbuffer.h
Try native method first in LoadFile() and SaveFile()
[wxWidgets.git] / interface / wx / dcbuffer.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcbuffer.h
e54c96f1 3// Purpose: interface of wxBufferedDC
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
ba4f890e
RD
8// Assumes the buffer bitmap covers the entire scrolled window,
9// and prepares the window DC accordingly
10#define wxBUFFER_VIRTUAL_AREA 0x01
11
12// Assumes the buffer bitmap only covers the client area;
13// does not prepare the window DC
14#define wxBUFFER_CLIENT_AREA 0x02
15
16// Set when not using specific buffer bitmap. Note that this
17// is private style and not returned by GetStyle.
18#define wxBUFFER_USES_SHARED_BUFFER 0x04
19
20
23324ae1
FM
21/**
22 @class wxBufferedDC
7c913512 23
23324ae1 24 This class provides a simple way to avoid flicker: when drawing on it,
d13b34d3 25 everything is in fact first drawn on an in-memory buffer (a wxBitmap) and
f09b5681
BP
26 then copied to the screen, using the associated wxDC, only once, when this
27 object is destroyed. wxBufferedDC itself is typically associated with
28 wxClientDC, if you want to use it in your @c EVT_PAINT handler, you should
29 look at wxBufferedPaintDC instead.
30
31 When used like this, a valid @e DC must be specified in the constructor
23324ae1 32 while the @e buffer bitmap doesn't have to be explicitly provided, by
f09b5681
BP
33 default this class will allocate the bitmap of required size itself.
34 However using a dedicated bitmap can speed up the redrawing process by
35 eliminating the repeated creation and destruction of a possibly big bitmap.
36 Otherwise, wxBufferedDC can be used in the same way as any other device
37 context.
7c913512 38
23324ae1 39 There is another possible use for wxBufferedDC is to use it to maintain a
f09b5681 40 backing store for the window contents. In this case, the associated @e DC
23324ae1 41 may be @NULL but a valid backing store bitmap should be specified.
7c913512 42
23324ae1 43 Finally, please note that GTK+ 2.0 as well as OS X provide double buffering
f09b5681
BP
44 themselves natively. You can either use wxWindow::IsDoubleBuffered() to
45 determine whether you need to use buffering or not, or use
46 wxAutoBufferedPaintDC to avoid needless double buffering on the systems
47 which already do it automatically.
7c913512 48
23324ae1
FM
49 @library{wxcore}
50 @category{dc}
7c913512 51
e54c96f1 52 @see wxDC, wxMemoryDC, wxBufferedPaintDC, wxAutoBufferedPaintDC
23324ae1
FM
53*/
54class wxBufferedDC : public wxMemoryDC
55{
56public:
f09b5681
BP
57 /**
58 Default constructor. You must call one of the Init() methods later in
59 order to use the device context.
60 */
61 wxBufferedDC();
62
23324ae1 63 /**
4050e98d 64 Creates a buffer for the provided @a dc. Init() must not be called when
f09b5681 65 using this constructor.
3c4f71cc 66
7c913512 67 @param dc
f09b5681
BP
68 The underlying DC: everything drawn to this object will be flushed
69 to this DC when this object is destroyed. You may pass @NULL in
70 order to just initialize the buffer, and not flush it.
7c913512 71 @param area
4cc4bfaf
FM
72 The size of the bitmap to be used for buffering (this bitmap is
73 created internally when it is not given explicitly).
4050e98d
BP
74 @param style
75 wxBUFFER_CLIENT_AREA to indicate that just the client area of the
76 window is buffered, or wxBUFFER_VIRTUAL_AREA to indicate that the
77 buffer bitmap covers the virtual area.
78 */
79 wxBufferedDC(wxDC* dc, const wxSize& area,
80 int style = wxBUFFER_CLIENT_AREA);
98ccd545 81
4050e98d
BP
82 /**
83 Creates a buffer for the provided dc. Init() must not be called when
84 using this constructor.
85
86 @param dc
87 The underlying DC: everything drawn to this object will be flushed
88 to this DC when this object is destroyed. You may pass @NULL in
89 order to just initialize the buffer, and not flush it.
7c913512 90 @param buffer
f09b5681
BP
91 Explicitly provided bitmap to be used for buffering: this is the
92 most efficient solution as the bitmap doesn't have to be recreated
93 each time but it also requires more memory as the bitmap is never
94 freed. The bitmap should have appropriate size, anything drawn
95 outside of its bounds is clipped.
4cc4bfaf 96 @param style
f09b5681
BP
97 wxBUFFER_CLIENT_AREA to indicate that just the client area of the
98 window is buffered, or wxBUFFER_VIRTUAL_AREA to indicate that the
99 buffer bitmap covers the virtual area.
23324ae1 100 */
882678eb 101 wxBufferedDC(wxDC* dc, wxBitmap& buffer = wxNullBitmap,
7c913512 102 int style = wxBUFFER_CLIENT_AREA);
23324ae1
FM
103
104 /**
f09b5681
BP
105 Copies everything drawn on the DC so far to the underlying DC
106 associated with this object, if any.
23324ae1 107 */
98ccd545 108 virtual ~wxBufferedDC();
23324ae1
FM
109
110 //@{
111 /**
f09b5681
BP
112 Initializes the object created using the default constructor. Please
113 see the constructors for parameter details.
23324ae1 114 */
4cc4bfaf 115 void Init(wxDC* dc, const wxSize& area,
23324ae1 116 int style = wxBUFFER_CLIENT_AREA);
882678eb 117 void Init(wxDC* dc, wxBitmap& buffer = wxNullBitmap,
7c913512 118 int style = wxBUFFER_CLIENT_AREA);
23324ae1 119 //@}
deb21d7f
RD
120
121
122 /**
123 Blits the buffer to the dc, and detaches the dc from the buffer (so it
124 can be effectively used once only).
125
126 Usually only called in the destructor or by the destructor of derived
127 classes if the BufferedDC must blit before the derived class (which may
128 own the dc it's blitting to) is destroyed.
129 */
130 void UnMask();
131
132 /**
133 Set the style.
134 */
135 void SetStyle(int style);
136
137 /**
138 Get the style.
139 */
140 int GetStyle() const;
23324ae1
FM
141};
142
143
e54c96f1 144
23324ae1
FM
145/**
146 @class wxAutoBufferedPaintDC
7c913512 147
f09b5681
BP
148 This wxDC derivative can be used inside of an @c EVT_PAINT() event handler
149 to achieve double-buffered drawing. Just use this class instead of
150 wxPaintDC and make sure wxWindow::SetBackgroundStyle() is called with
ba4f890e 151 wxBG_STYLE_PAINT somewhere in the class initialization code, and that's
f09b5681
BP
152 all you have to do to (mostly) avoid flicker.
153
154 The difference between wxBufferedPaintDC and this class is that this class
155 won't double-buffer on platforms which have native double-buffering
d13b34d3 156 already, avoiding any unnecessary buffering to avoid flicker.
7c913512 157
f09b5681
BP
158 wxAutoBufferedPaintDC is simply a typedef of wxPaintDC on platforms that
159 have native double-buffering, otherwise, it is a typedef of
160 wxBufferedPaintDC.
7c913512 161
f00f01b3 162 @library{wxcore}
23324ae1 163 @category{dc}
7c913512 164
f09b5681 165 @see wxDC, wxBufferedPaintDC, wxPaintDC
23324ae1
FM
166*/
167class wxAutoBufferedPaintDC : public wxBufferedPaintDC
168{
169public:
170 /**
171 Constructor. Pass a pointer to the window on which you wish to paint.
172 */
4cc4bfaf 173 wxAutoBufferedPaintDC(wxWindow* window);
23324ae1
FM
174};
175
176
123919a9
RD
177/**
178 * Check if the window is natively double buffered and will return a wxPaintDC
179 * if it is, a wxBufferedPaintDC otherwise. It is the caller's responsibility
180 * to delete the wxDC pointer when finished with it.
181 */
182wxDC* wxAutoBufferedPaintDCFactory(wxWindow* window);
183
e54c96f1 184
23324ae1
FM
185/**
186 @class wxBufferedPaintDC
7c913512 187
f09b5681
BP
188 This is a subclass of wxBufferedDC which can be used inside of an
189 @c EVT_PAINT() event handler to achieve double-buffered drawing. Just use
190 this class instead of wxPaintDC and make sure
ba4f890e 191 wxWindow::SetBackgroundStyle() is called with wxBG_STYLE_PAINT somewhere
f09b5681
BP
192 in the class initialization code, and that's all you have to do to (mostly)
193 avoid flicker. The only thing to watch out for is that if you are using
194 this class together with wxScrolled, you probably do @b not want to call
195 wxScrolled::PrepareDC() on it as it already does this internally for the
196 real underlying wxPaintDC.
7c913512 197
23324ae1
FM
198 @library{wxcore}
199 @category{dc}
7c913512 200
f09b5681 201 @see wxDC, wxBufferedDC, wxAutoBufferedPaintDC, wxPaintDC
23324ae1
FM
202*/
203class wxBufferedPaintDC : public wxBufferedDC
204{
205public:
206 //@{
207 /**
f09b5681
BP
208 As with wxBufferedDC, you may either provide the bitmap to be used for
209 buffering or let this object create one internally (in the latter case,
210 the size of the client part of the window is used).
211
212 Pass wxBUFFER_CLIENT_AREA for the @a style parameter to indicate that
213 just the client area of the window is buffered, or
214 wxBUFFER_VIRTUAL_AREA to indicate that the buffer bitmap covers the
215 virtual area.
23324ae1 216 */
4cc4bfaf 217 wxBufferedPaintDC(wxWindow* window, wxBitmap& buffer,
23324ae1 218 int style = wxBUFFER_CLIENT_AREA);
4cc4bfaf 219 wxBufferedPaintDC(wxWindow* window,
7c913512 220 int style = wxBUFFER_CLIENT_AREA);
23324ae1
FM
221 //@}
222
223 /**
f09b5681
BP
224 Copies everything drawn on the DC so far to the window associated with
225 this object, using a wxPaintDC.
23324ae1 226 */
98ccd545 227 virtual ~wxBufferedPaintDC();
23324ae1 228};
e54c96f1 229