1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/dcclient.cpp
3 // Purpose: wxWindowDCImpl, wxClientDCImpl and wxPaintDC
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2006 REA Elektronik GmbH
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ===========================================================================
12 // ===========================================================================
14 // ---------------------------------------------------------------------------
16 // ---------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
26 #include "wx/window.h"
27 #include "wx/nonownedwnd.h"
30 #include "wx/dfb/dcclient.h"
31 #include "wx/dfb/private.h"
33 #define TRACE_PAINT "paint"
35 // ===========================================================================
37 // ===========================================================================
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 // Returns subrect of the window that is not outside of its parent's
44 // boundaries ("hidden behind its borders"), recursively:
45 static wxRect
GetUncoveredWindowArea(wxWindow
*win
)
47 wxRect
r(win
->GetSize());
49 if ( win
->IsTopLevel() )
52 wxWindow
*parent
= win
->GetParent();
56 // intersect with parent's uncovered area, after offsetting it into win's
57 // coordinates; this will remove parts of 'r' that are outside of the
59 wxRect
rp(GetUncoveredWindowArea(parent
));
61 // normal windows cannot extend out of its parent's client area:
62 if ( !win
->CanBeOutsideClientArea() )
63 rp
.Intersect(parent
->GetClientRect());
65 rp
.Offset(-win
->GetPosition());
66 rp
.Offset(-parent
->GetClientAreaOrigin());
72 // creates a dummy surface that has the same format as the real window's
73 // surface, but is not visible and so can be painted on even if the window
76 wxIDirectFBSurfacePtr
CreateDummySurface(wxWindow
*win
, const wxRect
*rect
)
78 wxLogTrace(TRACE_PAINT
, "%p ('%s'): creating dummy DC surface",
79 win
, win
->GetName().c_str());
80 wxSize
size(rect
? rect
->GetSize() : win
->GetSize());
82 // we can't create a surface of 0 size but the size of the window may be 0,
83 // so ensure that we have at least a single pixel to draw on
84 size
.IncTo(wxSize(1, 1));
86 return win
->GetDfbSurface()->CreateCompatible
89 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxDFBDCImpl
)
99 wxWindowDCImpl::wxWindowDCImpl(wxDC
*owner
, wxWindow
*win
)
102 InitForWin(win
, NULL
);
105 void wxWindowDCImpl::InitForWin(wxWindow
*win
, const wxRect
*rect
)
107 wxCHECK_RET( win
, "invalid window" );
111 // obtain the surface used for painting:
113 wxIDirectFBSurfacePtr surface
;
115 wxRect
rectOrig(rect
? *rect
: wxRect(win
->GetSize()));
118 if ( !win
->IsShownOnScreen() )
120 // leave 'r' rectangle empty to indicate the window is not visible,
121 // see below (below "create the surface:") for how is this case handled
125 // compute painting rectangle after clipping if we're in PaintWindow
126 // code, otherwise paint on the entire window:
129 const wxRegion
& updateRegion
= win
->GetUpdateRegion();
130 if ( win
->GetTLW()->IsPainting() && !updateRegion
.IsEmpty() )
132 r
.Intersect(updateRegion
.AsRect());
133 wxCHECK_RET( !r
.IsEmpty(), "invalid painting rectangle" );
135 // parent TLW will flip the entire surface when painting is done
136 m_shouldFlip
= false;
140 // One of two things happened:
141 // (1) the TLW is not being painted by PaintWindow() now; or
142 // (2) we're drawing on some window other than the one that is
143 // currently painted on by PaintWindow()
144 // In either case, we need to flip the surface when we're done
145 // painting and we don't have to use updateRegion for clipping.
146 // OTOH, if the window is (partially) hidden by being
147 // out of its parent's area, we must clip the surface accordingly.
148 r
.Intersect(GetUncoveredWindowArea(win
));
149 m_shouldFlip
= true; // paint the results immediately
153 // create the surface:
156 // we're painting on invisible window: the changes won't have any
157 // effect, as the window will be repainted anyhow when it is shown,
158 // but we still need a valid DC so that e.g. text extents can be
159 // measured, so let's create a dummy surface that has the same
160 // format as the real one would have and let the code paint on it:
161 surface
= CreateDummySurface(win
, rect
);
163 // painting on hidden window has no effect on TLW's surface, don't
164 // waste time flipping the dummy surface:
165 m_shouldFlip
= false;
170 DFBRectangle dfbrect
= { r
.x
, r
.y
, r
.width
, r
.height
};
171 surface
= win
->GetDfbSurface()->GetSubSurface(&dfbrect
);
173 // if the DC was clipped thanks to rectPaint, we must adjust the
174 // origin accordingly; but we do *not* adjust for 'rect', because
175 // rect.GetPosition() has coordinates (0,0) in the DC:
176 origin
.x
= rectOrig
.x
- r
.x
;
177 origin
.y
= rectOrig
.y
- r
.y
;
179 // m_shouldFlip was set in the "if" block above this one
185 wxLogTrace(TRACE_PAINT
,
186 "%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]",
187 win
, win
->GetName().c_str(),
188 rectOrig
.x
, rectOrig
.y
, rectOrig
.GetRight(), rectOrig
.GetBottom(),
189 r
.x
, r
.y
, r
.GetRight(), r
.GetBottom(),
193 SetFont(win
->GetFont());
195 // offset coordinates to account for subsurface's origin coordinates:
196 SetDeviceOrigin(origin
.x
, origin
.y
);
199 wxWindowDCImpl::~wxWindowDCImpl()
201 wxIDirectFBSurfacePtr
surface(GetDirectFBSurface());
205 // if no painting was done on the DC, we don't have to flip the surface:
206 if ( !m_isBBoxValid
)
211 // paint overlays on top of the surface being drawn to by this DC
212 // before showing anything on the screen:
213 GetWindow()->PaintOverlays(m_winRect
);
215 DFBSurfaceCapabilities caps
= DSCAPS_NONE
;
216 surface
->GetCapabilities(&caps
);
217 if ( caps
& DSCAPS_DOUBLE
)
219 // FIXME: flip only modified parts of the surface
220 surface
->FlipToFront();
222 // else: the surface is not double-buffered and so cannot be flipped
224 // else: don't flip the surface, wxTLW will do it when it finishes
225 // painting of its invalidated areas
228 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
232 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
234 wxClientDCImpl::wxClientDCImpl(wxDC
*owner
, wxWindow
*win
)
235 : wxWindowDCImpl(owner
, win
)
237 wxCHECK_RET( win
, "invalid window" );
239 wxRect rect
= win
->GetClientRect();
240 InitForWin(win
, &rect
);
243 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------
247 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxWindowDCImpl
)