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