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 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
46 wxWindowDC::wxWindowDC(wxWindow
*win
)
48 InitForWin(win
, NULL
);
51 void wxWindowDC::InitForWin(wxWindow
*win
, const wxRect
*rect
)
55 wxCHECK_RET( win
, _T("invalid window") );
57 // obtain the surface used for painting:
59 wxIDirectFBSurfacePtr surface
;
61 if ( !win
->IsShownOnScreen() )
63 // we're painting on invisible window: the changes won't have any
64 // effect, as the window will be repainted anyhow when it is shown, but
65 // we still need a valid DC so that e.g. text extents can be measured,
66 // so let's create a dummy surface that has the same format as the real
67 // one would have and let the code paint on it:
68 wxLogTrace(TRACE_PAINT
, _T("%p ('%s'): creating dummy DC surface"),
69 win
, win
->GetName().c_str());
70 wxSize
size(rect
? rect
->GetSize() : win
->GetSize());
71 surface
= win
->GetDfbSurface()->CreateCompatible(size
);
75 wxRect
rectOrig(rect
? *rect
: wxRect(win
->GetSize()));
77 // compute painting rectangle after clipping if we're in PaintWindow
78 // code, otherwise paint on the entire window:
80 if ( win
->GetTLW()->IsPainting() )
81 r
.Intersect(win
->GetUpdateRegion().AsRect());
83 wxCHECK_RET( !r
.IsEmpty(), _T("invalid painting rectangle") );
85 // if the DC was clipped thanks to rectPaint, we must adjust the origin
86 // accordingly; but we do *not* adjust for 'rect', because
87 // rect.GetPosition() has coordinates (0,0) in the DC:
88 origin
.x
= rectOrig
.x
- r
.x
;
89 origin
.y
= rectOrig
.y
- r
.y
;
91 wxLogTrace(TRACE_PAINT
,
92 _T("%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]"),
93 win
, win
->GetName().c_str(),
94 rectOrig
.x
, rectOrig
.y
, rectOrig
.GetRight(), rectOrig
.GetBottom(),
95 r
.x
, r
.y
, r
.GetRight(), r
.GetBottom(),
98 DFBRectangle dfbrect
= { r
.x
, r
.y
, r
.width
, r
.height
};
99 surface
= win
->GetDfbSurface()->GetSubSurface(&dfbrect
);
106 SetFont(win
->GetFont());
108 // offset coordinates to account for subsurface's origin coordinates:
109 SetDeviceOrigin(origin
.x
, origin
.y
);
112 wxWindowDC::~wxWindowDC()
114 wxIDirectFBSurfacePtr
surface(GetDirectFBSurface());
115 if ( !surface
|| !m_win
)
118 // painting on hidden window has no effect on TLW's surface, don't
119 // waste time flipping the dummy surface:
120 if ( !m_win
->IsShownOnScreen() )
123 // if no painting was done on the DC, we don't have to flip the surface:
124 if ( !m_isBBoxValid
)
127 if ( !m_win
->GetTLW()->IsPainting() )
129 // FIXME: flip only modified parts of the surface
130 surface
->FlipToFront();
132 // else: don't flip the surface, wxTLW will do it when it finishes
133 // painting of its invalidated areas
136 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
140 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
142 wxClientDC::wxClientDC(wxWindow
*win
)
144 wxCHECK_RET( win
, _T("invalid window") );
146 wxRect rect
= win
->GetClientRect();
147 InitForWin(win
, &rect
);
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
154 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)