]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/dcclient.cpp
rebaked after listctrl/imagelist and wxUniv changes
[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 #define TRACE_PAINT _T("paint")
35
36 // ===========================================================================
37 // implementation
38 // ===========================================================================
39
40 //-----------------------------------------------------------------------------
41 // wxWindowDC
42 //-----------------------------------------------------------------------------
43
44 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
45
46 wxWindowDC::wxWindowDC(wxWindow *win)
47 {
48 InitForWin(win, NULL);
49 }
50
51 void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect)
52 {
53 m_win = win;
54
55 wxCHECK_RET( win, _T("invalid window") );
56
57 // obtain the surface used for painting:
58 wxPoint origin;
59 wxIDirectFBSurfacePtr surface;
60
61 if ( !win->IsShownOnScreen() )
62 {
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);
72 }
73 else
74 {
75 wxRect rectOrig(rect ? *rect : wxRect(win->GetSize()));
76
77 // compute painting rectangle after clipping if we're in PaintWindow
78 // code, otherwise paint on the entire window:
79 wxRect r(rectOrig);
80 if ( win->GetTLW()->IsPainting() )
81 r.Intersect(win->GetUpdateRegion().AsRect());
82
83 wxCHECK_RET( !r.IsEmpty(), _T("invalid painting rectangle") );
84
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;
90
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(),
96 origin.x, origin.y);
97
98 DFBRectangle dfbrect = { r.x, r.y, r.width, r.height };
99 surface = win->GetDfbSurface()->GetSubSurface(&dfbrect);
100 }
101
102 if ( !surface )
103 return;
104
105 Init(surface);
106 SetFont(win->GetFont());
107
108 // offset coordinates to account for subsurface's origin coordinates:
109 SetDeviceOrigin(origin.x, origin.y);
110 }
111
112 wxWindowDC::~wxWindowDC()
113 {
114 wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
115 if ( !surface || !m_win )
116 return;
117
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() )
121 return;
122
123 // if no painting was done on the DC, we don't have to flip the surface:
124 if ( !m_isBBoxValid )
125 return;
126
127 if ( !m_win->GetTLW()->IsPainting() )
128 {
129 // FIXME: flip only modified parts of the surface
130 surface->FlipToFront();
131 }
132 // else: don't flip the surface, wxTLW will do it when it finishes
133 // painting of its invalidated areas
134 }
135
136 //-----------------------------------------------------------------------------
137 // wxClientDC
138 //-----------------------------------------------------------------------------
139
140 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
141
142 wxClientDC::wxClientDC(wxWindow *win)
143 {
144 wxCHECK_RET( win, _T("invalid window") );
145
146 wxRect rect = win->GetClientRect();
147 InitForWin(win, &rect);
148 }
149
150 //-----------------------------------------------------------------------------
151 // wxPaintDC
152 //-----------------------------------------------------------------------------
153
154 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)