1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/dcclient.cpp
3 // Purpose: wxWindowDC, wxClientDC and wxPaintDC
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/dcclient.h"
29 #include "wx/window.h"
32 #include "wx/dfb/private.h"
34 #define TRACE_PAINT _T("paint")
36 // ===========================================================================
38 // ===========================================================================
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
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
)
48 wxRect
r(win
->GetSize());
50 if ( win
->IsTopLevel() )
53 wxWindow
*parent
= win
->GetParent();
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
60 wxRect
rp(GetUncoveredWindowArea(parent
));
61 rp
.Offset(-win
->GetPosition());
62 rp
.Offset(-parent
->GetClientAreaOrigin());
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
72 wxIDirectFBSurfacePtr
CreateDummySurface(wxWindow
*win
, const wxRect
*rect
)
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
80 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
90 wxWindowDC::wxWindowDC(wxWindow
*win
)
92 InitForWin(win
, NULL
);
95 void wxWindowDC::InitForWin(wxWindow
*win
, const wxRect
*rect
)
97 wxCHECK_RET( win
, _T("invalid window") );
101 // obtain the surface used for painting:
103 wxIDirectFBSurfacePtr surface
;
105 wxRect
rectOrig(rect
? *rect
: wxRect(win
->GetSize()));
108 if ( !win
->IsShownOnScreen() )
110 // leave 'r' rectangle empty to indicate the window is not visible,
111 // see below (below "create the surface:") for how is this case handled
115 // compute painting rectangle after clipping if we're in PaintWindow
116 // code, otherwise paint on the entire window:
119 const wxRegion
& updateRegion
= win
->GetUpdateRegion();
120 if ( win
->GetTLW()->IsPainting() && !updateRegion
.IsEmpty() )
122 r
.Intersect(updateRegion
.AsRect());
123 wxCHECK_RET( !r
.IsEmpty(), _T("invalid painting rectangle") );
125 // parent TLW will flip the entire surface when painting is done
126 m_shouldFlip
= false;
130 // One of two things happened:
131 // (1) the TLW is not being painted by PaintWindow() now; or
132 // (2) we're drawing on some window other than the one that is
133 // currently painted on by PaintWindow()
134 // In either case, we need to flip the surface when we're done
135 // painting and we don't have to use updateRegion for clipping.
136 // OTOH, if the window is (partially) hidden by being
137 // out of its parent's area, we must clip the surface accordingly.
138 r
.Intersect(GetUncoveredWindowArea(win
));
139 m_shouldFlip
= true; // paint the results immediately
143 // create the surface:
146 // we're painting on invisible window: the changes won't have any
147 // effect, as the window will be repainted anyhow when it is shown,
148 // but we still need a valid DC so that e.g. text extents can be
149 // measured, so let's create a dummy surface that has the same
150 // format as the real one would have and let the code paint on it:
151 surface
= CreateDummySurface(win
, rect
);
153 // painting on hidden window has no effect on TLW's surface, don't
154 // waste time flipping the dummy surface:
155 m_shouldFlip
= false;
160 DFBRectangle dfbrect
= { r
.x
, r
.y
, r
.width
, r
.height
};
161 surface
= win
->GetDfbSurface()->GetSubSurface(&dfbrect
);
163 // if the DC was clipped thanks to rectPaint, we must adjust the
164 // origin accordingly; but we do *not* adjust for 'rect', because
165 // rect.GetPosition() has coordinates (0,0) in the DC:
166 origin
.x
= rectOrig
.x
- r
.x
;
167 origin
.y
= rectOrig
.y
- r
.y
;
169 // m_shouldFlip was set in the "if" block above this one
175 wxLogTrace(TRACE_PAINT
,
176 _T("%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]"),
177 win
, win
->GetName().c_str(),
178 rectOrig
.x
, rectOrig
.y
, rectOrig
.GetRight(), rectOrig
.GetBottom(),
179 r
.x
, r
.y
, r
.GetRight(), r
.GetBottom(),
183 SetFont(win
->GetFont());
185 // offset coordinates to account for subsurface's origin coordinates:
186 SetDeviceOrigin(origin
.x
, origin
.y
);
189 wxWindowDC::~wxWindowDC()
191 wxIDirectFBSurfacePtr
surface(GetDirectFBSurface());
195 // if no painting was done on the DC, we don't have to flip the surface:
196 if ( !m_isBBoxValid
)
201 // paint overlays on top of the surface being drawn to by this DC
202 // before showing anything on the screen:
203 m_win
->PaintOverlays(m_winRect
);
205 DFBSurfaceCapabilities caps
= DSCAPS_NONE
;
206 surface
->GetCapabilities(&caps
);
207 if ( caps
& DSCAPS_DOUBLE
)
209 // FIXME: flip only modified parts of the surface
210 surface
->FlipToFront();
212 // else: the surface is not double-buffered and so cannot be flipped
214 // else: don't flip the surface, wxTLW will do it when it finishes
215 // painting of its invalidated areas
218 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
222 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
224 wxClientDC::wxClientDC(wxWindow
*win
)
226 wxCHECK_RET( win
, _T("invalid window") );
228 wxRect rect
= win
->GetClientRect();
229 InitForWin(win
, &rect
);
232 //-----------------------------------------------------------------------------
234 //-----------------------------------------------------------------------------
236 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)