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 // ===========================================================================
36 // ===========================================================================
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
44 wxWindowDC::wxWindowDC(wxWindow
*win
)
46 InitForWin(win
, NULL
);
49 void wxWindowDC::InitForWin(wxWindow
*win
, const wxRect
*rect
)
51 wxCHECK_RET( win
, _T("invalid window") );
53 // check if the rectangle covers full window and so is not needed:
54 if ( rect
&& *rect
== wxRect(win
->GetSize()) )
57 // obtain the surface used for painting:
58 wxIDirectFBSurfacePtr surface
;
60 if ( !win
->IsVisible() )
62 // we're painting on invisible window: the changes won't have any
63 // effect, as the window will be repainted anyhow when it is shown, but
64 // we still need a valid DC so that e.g. text extents can be measured,
65 // so let's create a dummy surface that has the same format as the real
66 // one would have and let the code paint on it:
67 wxSize
size(rect
? rect
->GetSize() : win
->GetSize());
68 surface
= wxDfbCreateCompatibleSurface(win
->GetDfbSurface(), size
);
72 wxCHECK_RET( win
->GetSize().x
> 0 && win
->GetSize().y
> 0,
73 _T("window has invalid size") );
75 surface
= win
->GetDfbSurface();
79 wxCHECK_RET( !rect
|| !rect
->IsEmpty(), _T("invalid rectangle") );
81 DFBRectangle dfbrect
= { rect
->x
, rect
->y
, rect
->width
, rect
->height
};
82 surface
= win
->GetDfbSurface()->GetSubSurface(&dfbrect
);
89 SetFont(win
->GetFont());
91 // offset coordinates to account for subsurface's origin coordinates:
93 SetDeviceOrigin(rect
->x
, rect
->y
);
96 //-----------------------------------------------------------------------------
97 // base class for wxClientDC and wxPaintDC
98 //-----------------------------------------------------------------------------
100 wxClientDCBase::wxClientDCBase(wxWindow
*win
)
102 wxCHECK_RET( win
, _T("invalid window") );
104 wxRect rect
= win
->GetClientRect();
105 InitForWin(win
, &rect
);
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
114 wxClientDC::~wxClientDC()
116 // flip to surface so that the changes become visible
117 wxIDirectFBSurfacePtr
surface(GetDirectFBSurface());
119 // FIXME: do this only if the surface was modified (as opposed to e.g.
120 // used only to obtain text metrics)
122 surface
->Flip(NULL
, DSFLIP_NONE
);
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
129 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
131 #warning "wxPaintDC ctor must respect m_updateRegion"
133 wxPaintDC::~wxPaintDC()
135 // NB: do *not* flip the surface: wxPaintDC is used with EVT_PAINT and the
136 // surface will be flipped for the entire TLW once all children are