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
->GetRect());
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(size
);
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
86 wxWindowDC::wxWindowDC(wxWindow
*win
)
88 InitForWin(win
, NULL
);
91 void wxWindowDC::InitForWin(wxWindow
*win
, const wxRect
*rect
)
93 wxCHECK_RET( win
, _T("invalid window") );
95 // obtain the surface used for painting:
97 wxIDirectFBSurfacePtr surface
;
99 if ( !win
->IsShownOnScreen() )
101 // we're painting on invisible window: the changes won't have any
102 // effect, as the window will be repainted anyhow when it is shown, but
103 // we still need a valid DC so that e.g. text extents can be measured,
104 // so let's create a dummy surface that has the same format as the real
105 // one would have and let the code paint on it:
106 surface
= CreateDummySurface(win
, rect
);
108 // painting on hidden window has no effect on TLW's surface, don't
109 // waste time flipping the dummy surface:
110 m_shouldFlip
= false;
114 wxRect
rectOrig(rect
? *rect
: wxRect(win
->GetSize()));
116 // compute painting rectangle after clipping if we're in PaintWindow
117 // code, otherwise paint on the entire window:
120 const wxRegion
& updateRegion
= win
->GetUpdateRegion();
121 if ( win
->GetTLW()->IsPainting() && !updateRegion
.IsEmpty() )
123 r
.Intersect(updateRegion
.AsRect());
124 // parent TLW will flip the entire surface when painting is done
125 m_shouldFlip
= false;
127 wxCHECK_RET( !r
.IsEmpty(), _T("invalid painting rectangle") );
131 // One of two things happened:
132 // (1) the TLW is not being painted by PaintWindow() now; or
133 // (2) we're drawing on some window other than the one that is
134 // currently painted on by PaintWindow()
135 // In either case, we need to flip the surface when we're done
136 // painting and we don't have to use updateRegion for clipping.
137 // OTOH, if the window is (partially) hidden by being
138 // out of its parent's area, we must clip the surface accordingly.
139 r
.Intersect(GetUncoveredWindowArea(win
));
142 // the window is fully hidden, we can't paint on it, so create
143 // a dummy surface as above
144 surface
= CreateDummySurface(win
, &rectOrig
);
145 m_shouldFlip
= false;
149 DFBRectangle dfbrect
= { r
.x
, r
.y
, r
.width
, r
.height
};
150 surface
= win
->GetDfbSurface()->GetSubSurface(&dfbrect
);
152 // paint the results immediately
157 // if the DC was clipped thanks to rectPaint, we must adjust the origin
158 // accordingly; but we do *not* adjust for 'rect', because
159 // rect.GetPosition() has coordinates (0,0) in the DC:
160 origin
.x
= rectOrig
.x
- r
.x
;
161 origin
.y
= rectOrig
.y
- r
.y
;
163 wxLogTrace(TRACE_PAINT
,
164 _T("%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]"),
165 win
, win
->GetName().c_str(),
166 rectOrig
.x
, rectOrig
.y
, rectOrig
.GetRight(), rectOrig
.GetBottom(),
167 r
.x
, r
.y
, r
.GetRight(), r
.GetBottom(),
175 SetFont(win
->GetFont());
177 // offset coordinates to account for subsurface's origin coordinates:
178 SetDeviceOrigin(origin
.x
, origin
.y
);
181 wxWindowDC::~wxWindowDC()
183 wxIDirectFBSurfacePtr
surface(GetDirectFBSurface());
187 // if no painting was done on the DC, we don't have to flip the surface:
188 if ( !m_isBBoxValid
)
193 // FIXME: flip only modified parts of the surface
194 surface
->FlipToFront();
196 // else: don't flip the surface, wxTLW will do it when it finishes
197 // painting of its invalidated areas
200 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
206 wxClientDC::wxClientDC(wxWindow
*win
)
208 wxCHECK_RET( win
, _T("invalid window") );
210 wxRect rect
= win
->GetClientRect();
211 InitForWin(win
, &rect
);
214 //-----------------------------------------------------------------------------
216 //-----------------------------------------------------------------------------
218 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)