verify that we're not painting on hidden window (which is not implemented)
[wxWidgets.git] / src / dfb / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/dcclient.cpp
3 // Purpose: wxWindowDC, wxClientDC and wxPaintDC
4 // Author: Vaclav Slavik
5 // Created: 2006-08-10
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ===========================================================================
12 // declarations
13 // ===========================================================================
14
15 // ---------------------------------------------------------------------------
16 // headers
17 // ---------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #include "wx/dcclient.h"
27
28 #ifndef WX_PRECOMP
29 #include "wx/window.h"
30 #endif
31
32 #include "wx/dfb/private.h"
33
34 // ===========================================================================
35 // implementation
36 // ===========================================================================
37
38 //-----------------------------------------------------------------------------
39 // wxWindowDC
40 //-----------------------------------------------------------------------------
41
42 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
43
44 wxWindowDC::wxWindowDC(wxWindow *win)
45 : wxDC(win ? win->GetDfbSurface() : NULL)
46 {
47 InitForWin(win);
48 }
49
50 void wxWindowDC::InitForWin(wxWindow *win)
51 {
52 wxCHECK_RET( win, _T("invalid window") );
53
54 // FIXME: this should be made to work: we need to detect that the window
55 // is not visible and in that case, a) ignore any drawing actions
56 // and b) provide dummy surface that can still be used to get
57 // information (e.g. text extents):
58 wxWindow *w = win;
59 for ( wxWindow *w = win; w; w = w->GetParent() )
60 {
61 // painting on hidden TLW when non-TLW windows are shown is OK,
62 // DirectFB manages that:
63 if ( w->IsTopLevel() )
64 break;
65
66 wxASSERT_MSG( w->IsShown(),
67 _T("painting on hidden window not implemented yet") );
68 }
69
70
71 SetFont(win->GetFont());
72 }
73
74 //-----------------------------------------------------------------------------
75 // base class for wxClientDC and wxPaintDC
76 //-----------------------------------------------------------------------------
77
78 wxClientDCBase::wxClientDCBase(wxWindow *win)
79 {
80 wxCHECK_RET( win, _T("invalid window") );
81
82 wxRect rect = win->GetClientRect();
83 DFBRectangle dfbrect = { rect.x, rect.y, rect.width, rect.height };
84
85 wxIDirectFBSurfacePtr subsurf(
86 win->GetDfbSurface()->GetSubSurface(&dfbrect));
87 if ( !subsurf )
88 return;
89
90 Init(subsurf);
91 InitForWin(win);
92
93 // offset coordinates to account for subsurface's origin coordinates:
94 SetDeviceOrigin(rect.x, rect.y);
95 }
96
97 //-----------------------------------------------------------------------------
98 // wxClientDC
99 //-----------------------------------------------------------------------------
100
101 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
102
103 wxClientDC::~wxClientDC()
104 {
105 // flip to surface so that the changes become visible
106 wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
107
108 // FIXME: do this only if the surface was modified (as opposed to e.g.
109 // used only to obtain text metrics)
110 if ( surface )
111 surface->Flip(NULL, DSFLIP_NONE);
112 }
113
114 //-----------------------------------------------------------------------------
115 // wxPaintDC
116 //-----------------------------------------------------------------------------
117
118 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
119
120 #warning "wxPaintDC ctor must respect m_updateRegion"
121
122 wxPaintDC::~wxPaintDC()
123 {
124 // NB: do *not* flip the surface: wxPaintDC is used with EVT_PAINT and the
125 // surface will be flipped for the entire TLW once all children are
126 // repainted
127 }