]>
Commit | Line | Data |
---|---|---|
b3c86150 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/dfb/dcclient.cpp | |
3 | // Purpose: wxWindowDC, wxClientDC and wxPaintDC | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2006-08-10 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2006 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // =========================================================================== | |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | // For compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #include "wx/dcclient.h" | |
27 | ||
28 | #ifndef WX_PRECOMP | |
29 | #include "wx/window.h" | |
30 | #endif | |
31 | ||
32 | #include "wx/dfb/private.h" | |
33 | ||
20671963 VS |
34 | #define TRACE_PAINT _T("paint") |
35 | ||
b3c86150 VS |
36 | // =========================================================================== |
37 | // implementation | |
38 | // =========================================================================== | |
39 | ||
4dc9a81d VS |
40 | //----------------------------------------------------------------------------- |
41 | // helpers | |
42 | //----------------------------------------------------------------------------- | |
43 | ||
44 | // Returns subrect of the window that is not outside of its parent's | |
45 | // boundaries ("hidden behind its borders"), recursively: | |
46 | static wxRect GetUncoveredWindowArea(wxWindow *win) | |
47 | { | |
48 | wxRect r(win->GetRect()); | |
49 | ||
50 | if ( win->IsTopLevel() ) | |
51 | return r; | |
52 | ||
53 | wxWindow *parent = win->GetParent(); | |
54 | if ( !parent ) | |
55 | return r; | |
56 | ||
57 | // intersect with parent's uncovered area, after offsetting it into win's | |
58 | // coordinates; this will remove parts of 'r' that are outside of the | |
59 | // parent's area: | |
60 | wxRect rp(GetUncoveredWindowArea(parent)); | |
61 | rp.Offset(-win->GetPosition()); | |
62 | rp.Offset(-parent->GetClientAreaOrigin()); | |
63 | r.Intersect(rp); | |
64 | ||
65 | return r; | |
66 | } | |
67 | ||
68 | // creates a dummy surface that has the same format as the real window's | |
69 | // surface, but is not visible and so can be painted on even if the window | |
70 | // is hidden | |
71 | static | |
72 | wxIDirectFBSurfacePtr CreateDummySurface(wxWindow *win, const wxRect *rect) | |
73 | { | |
74 | wxLogTrace(TRACE_PAINT, _T("%p ('%s'): creating dummy DC surface"), | |
75 | win, win->GetName().c_str()); | |
76 | wxSize size(rect ? rect->GetSize() : win->GetSize()); | |
77 | return win->GetDfbSurface()->CreateCompatible(size); | |
78 | } | |
79 | ||
b3c86150 VS |
80 | //----------------------------------------------------------------------------- |
81 | // wxWindowDC | |
82 | //----------------------------------------------------------------------------- | |
83 | ||
84 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) | |
85 | ||
86 | wxWindowDC::wxWindowDC(wxWindow *win) | |
b3c86150 | 87 | { |
78d2c241 | 88 | InitForWin(win, NULL); |
b3c86150 VS |
89 | } |
90 | ||
78d2c241 | 91 | void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect) |
b3c86150 | 92 | { |
20671963 | 93 | wxCHECK_RET( win, _T("invalid window") ); |
17dd5538 | 94 | |
78d2c241 | 95 | // obtain the surface used for painting: |
20671963 | 96 | wxPoint origin; |
78d2c241 | 97 | wxIDirectFBSurfacePtr surface; |
2582bcdc | 98 | |
d18a7061 VS |
99 | wxRect rectOrig(rect ? *rect : wxRect(win->GetSize())); |
100 | wxRect r; | |
101 | ||
865a74c7 | 102 | if ( !win->IsShownOnScreen() ) |
2582bcdc | 103 | { |
d18a7061 VS |
104 | // leave 'r' rectangle empty to indicate the window is not visible, |
105 | // see below (below "create the surface:") for how is this case handled | |
2582bcdc | 106 | } |
78d2c241 VS |
107 | else |
108 | { | |
20671963 VS |
109 | // compute painting rectangle after clipping if we're in PaintWindow |
110 | // code, otherwise paint on the entire window: | |
d18a7061 | 111 | r = rectOrig; |
20671963 | 112 | |
4dc9a81d VS |
113 | const wxRegion& updateRegion = win->GetUpdateRegion(); |
114 | if ( win->GetTLW()->IsPainting() && !updateRegion.IsEmpty() ) | |
115 | { | |
116 | r.Intersect(updateRegion.AsRect()); | |
d18a7061 VS |
117 | wxCHECK_RET( !r.IsEmpty(), _T("invalid painting rectangle") ); |
118 | ||
4dc9a81d VS |
119 | // parent TLW will flip the entire surface when painting is done |
120 | m_shouldFlip = false; | |
4dc9a81d VS |
121 | } |
122 | else | |
123 | { | |
124 | // One of two things happened: | |
125 | // (1) the TLW is not being painted by PaintWindow() now; or | |
126 | // (2) we're drawing on some window other than the one that is | |
127 | // currently painted on by PaintWindow() | |
128 | // In either case, we need to flip the surface when we're done | |
129 | // painting and we don't have to use updateRegion for clipping. | |
130 | // OTOH, if the window is (partially) hidden by being | |
131 | // out of its parent's area, we must clip the surface accordingly. | |
132 | r.Intersect(GetUncoveredWindowArea(win)); | |
d18a7061 | 133 | m_shouldFlip = true; // paint the results immediately |
4dc9a81d | 134 | } |
d18a7061 | 135 | } |
20671963 | 136 | |
d18a7061 VS |
137 | // create the surface: |
138 | if ( r.IsEmpty() ) | |
139 | { | |
140 | // we're painting on invisible window: the changes won't have any | |
141 | // effect, as the window will be repainted anyhow when it is shown, | |
142 | // but we still need a valid DC so that e.g. text extents can be | |
143 | // measured, so let's create a dummy surface that has the same | |
144 | // format as the real one would have and let the code paint on it: | |
145 | surface = CreateDummySurface(win, rect); | |
146 | ||
147 | // painting on hidden window has no effect on TLW's surface, don't | |
148 | // waste time flipping the dummy surface: | |
149 | m_shouldFlip = false; | |
150 | } | |
151 | else | |
152 | { | |
153 | DFBRectangle dfbrect = { r.x, r.y, r.width, r.height }; | |
154 | surface = win->GetDfbSurface()->GetSubSurface(&dfbrect); | |
155 | ||
156 | // if the DC was clipped thanks to rectPaint, we must adjust the | |
157 | // origin accordingly; but we do *not* adjust for 'rect', because | |
20671963 VS |
158 | // rect.GetPosition() has coordinates (0,0) in the DC: |
159 | origin.x = rectOrig.x - r.x; | |
160 | origin.y = rectOrig.y - r.y; | |
161 | ||
d18a7061 | 162 | // m_shouldFlip was set in the "if" block above this one |
78d2c241 VS |
163 | } |
164 | ||
165 | if ( !surface ) | |
166 | return; | |
167 | ||
d18a7061 VS |
168 | wxLogTrace(TRACE_PAINT, |
169 | _T("%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]"), | |
170 | win, win->GetName().c_str(), | |
171 | rectOrig.x, rectOrig.y, rectOrig.GetRight(), rectOrig.GetBottom(), | |
172 | r.x, r.y, r.GetRight(), r.GetBottom(), | |
173 | origin.x, origin.y); | |
174 | ||
78d2c241 | 175 | Init(surface); |
b3c86150 | 176 | SetFont(win->GetFont()); |
78d2c241 VS |
177 | |
178 | // offset coordinates to account for subsurface's origin coordinates: | |
20671963 | 179 | SetDeviceOrigin(origin.x, origin.y); |
b3c86150 VS |
180 | } |
181 | ||
20671963 | 182 | wxWindowDC::~wxWindowDC() |
b3c86150 | 183 | { |
20671963 | 184 | wxIDirectFBSurfacePtr surface(GetDirectFBSurface()); |
4dc9a81d | 185 | if ( !surface ) |
20671963 VS |
186 | return; |
187 | ||
188 | // if no painting was done on the DC, we don't have to flip the surface: | |
189 | if ( !m_isBBoxValid ) | |
190 | return; | |
191 | ||
4dc9a81d | 192 | if ( m_shouldFlip ) |
20671963 VS |
193 | { |
194 | // FIXME: flip only modified parts of the surface | |
195 | surface->FlipToFront(); | |
196 | } | |
197 | // else: don't flip the surface, wxTLW will do it when it finishes | |
198 | // painting of its invalidated areas | |
b3c86150 VS |
199 | } |
200 | ||
201 | //----------------------------------------------------------------------------- | |
202 | // wxClientDC | |
203 | //----------------------------------------------------------------------------- | |
204 | ||
205 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
206 | ||
20671963 | 207 | wxClientDC::wxClientDC(wxWindow *win) |
b3c86150 | 208 | { |
20671963 | 209 | wxCHECK_RET( win, _T("invalid window") ); |
17dd5538 | 210 | |
20671963 VS |
211 | wxRect rect = win->GetClientRect(); |
212 | InitForWin(win, &rect); | |
b3c86150 VS |
213 | } |
214 | ||
215 | //----------------------------------------------------------------------------- | |
216 | // wxPaintDC | |
217 | //----------------------------------------------------------------------------- | |
218 | ||
219 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) |