]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dcclient.cpp
include errno.h to fix buildbot compilation
[wxWidgets.git] / src / dfb / dcclient.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/dcclient.cpp
4a624f6e 3// Purpose: wxWindowDCImpl, wxClientDCImpl and wxPaintDC
b3c86150
VS
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
b3c86150
VS
26#ifndef WX_PRECOMP
27 #include "wx/window.h"
23205be8 28 #include "wx/nonownedwnd.h"
b3c86150
VS
29#endif
30
4a624f6e 31#include "wx/dfb/dcclient.h"
b3c86150
VS
32#include "wx/dfb/private.h"
33
a5001e93 34#define TRACE_PAINT "paint"
20671963 35
b3c86150
VS
36// ===========================================================================
37// implementation
38// ===========================================================================
39
4dc9a81d
VS
40//-----------------------------------------------------------------------------
41// helpers
42//-----------------------------------------------------------------------------
43
44// Returns subrect of the window that is not outside of its parent's
45// boundaries ("hidden behind its borders"), recursively:
46static wxRect GetUncoveredWindowArea(wxWindow *win)
47{
399754a6 48 wxRect r(win->GetSize());
4dc9a81d
VS
49
50 if ( win->IsTopLevel() )
51 return r;
52
53 wxWindow *parent = win->GetParent();
54 if ( !parent )
55 return r;
56
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
59 // parent's area:
60 wxRect rp(GetUncoveredWindowArea(parent));
c04c7a3d
VS
61
62 // normal windows cannot extend out of its parent's client area:
63 if ( !win->CanBeOutsideClientArea() )
64 rp.Intersect(parent->GetClientRect());
65
4dc9a81d
VS
66 rp.Offset(-win->GetPosition());
67 rp.Offset(-parent->GetClientAreaOrigin());
68 r.Intersect(rp);
69
70 return r;
71}
72
73// creates a dummy surface that has the same format as the real window's
74// surface, but is not visible and so can be painted on even if the window
75// is hidden
76static
77wxIDirectFBSurfacePtr CreateDummySurface(wxWindow *win, const wxRect *rect)
78{
a5001e93 79 wxLogTrace(TRACE_PAINT, "%p ('%s'): creating dummy DC surface",
4dc9a81d
VS
80 win, win->GetName().c_str());
81 wxSize size(rect ? rect->GetSize() : win->GetSize());
643de214
VZ
82
83 // we can't create a surface of 0 size but the size of the window may be 0,
84 // so ensure that we have at least a single pixel to draw on
85 size.IncTo(wxSize(1, 1));
86
7e2baeb4
VS
87 return win->GetDfbSurface()->CreateCompatible
88 (
89 size,
90 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
91 );
4dc9a81d
VS
92}
93
b3c86150 94//-----------------------------------------------------------------------------
4a624f6e 95// wxWindowDCImpl
b3c86150
VS
96//-----------------------------------------------------------------------------
97
4a624f6e 98IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxDFBDCImpl)
b3c86150 99
4a624f6e
VZ
100wxWindowDCImpl::wxWindowDCImpl(wxDC *owner, wxWindow *win)
101 : wxDFBDCImpl(owner)
b3c86150 102{
78d2c241 103 InitForWin(win, NULL);
b3c86150
VS
104}
105
4a624f6e 106void wxWindowDCImpl::InitForWin(wxWindow *win, const wxRect *rect)
b3c86150 107{
a5001e93 108 wxCHECK_RET( win, "invalid window" );
17dd5538 109
9d646d31 110 m_window = win;
30c841c8 111
78d2c241 112 // obtain the surface used for painting:
20671963 113 wxPoint origin;
78d2c241 114 wxIDirectFBSurfacePtr surface;
2582bcdc 115
d18a7061
VS
116 wxRect rectOrig(rect ? *rect : wxRect(win->GetSize()));
117 wxRect r;
118
865a74c7 119 if ( !win->IsShownOnScreen() )
2582bcdc 120 {
d18a7061
VS
121 // leave 'r' rectangle empty to indicate the window is not visible,
122 // see below (below "create the surface:") for how is this case handled
2582bcdc 123 }
78d2c241
VS
124 else
125 {
20671963
VS
126 // compute painting rectangle after clipping if we're in PaintWindow
127 // code, otherwise paint on the entire window:
d18a7061 128 r = rectOrig;
20671963 129
4dc9a81d
VS
130 const wxRegion& updateRegion = win->GetUpdateRegion();
131 if ( win->GetTLW()->IsPainting() && !updateRegion.IsEmpty() )
132 {
133 r.Intersect(updateRegion.AsRect());
a5001e93 134 wxCHECK_RET( !r.IsEmpty(), "invalid painting rectangle" );
d18a7061 135
4dc9a81d
VS
136 // parent TLW will flip the entire surface when painting is done
137 m_shouldFlip = false;
4dc9a81d
VS
138 }
139 else
140 {
141 // One of two things happened:
142 // (1) the TLW is not being painted by PaintWindow() now; or
143 // (2) we're drawing on some window other than the one that is
144 // currently painted on by PaintWindow()
145 // In either case, we need to flip the surface when we're done
146 // painting and we don't have to use updateRegion for clipping.
147 // OTOH, if the window is (partially) hidden by being
148 // out of its parent's area, we must clip the surface accordingly.
149 r.Intersect(GetUncoveredWindowArea(win));
d18a7061 150 m_shouldFlip = true; // paint the results immediately
4dc9a81d 151 }
d18a7061 152 }
20671963 153
d18a7061
VS
154 // create the surface:
155 if ( r.IsEmpty() )
156 {
157 // we're painting on invisible window: the changes won't have any
158 // effect, as the window will be repainted anyhow when it is shown,
159 // but we still need a valid DC so that e.g. text extents can be
160 // measured, so let's create a dummy surface that has the same
161 // format as the real one would have and let the code paint on it:
162 surface = CreateDummySurface(win, rect);
163
164 // painting on hidden window has no effect on TLW's surface, don't
165 // waste time flipping the dummy surface:
166 m_shouldFlip = false;
167 }
168 else
169 {
30c841c8 170 m_winRect = r;
d18a7061
VS
171 DFBRectangle dfbrect = { r.x, r.y, r.width, r.height };
172 surface = win->GetDfbSurface()->GetSubSurface(&dfbrect);
173
174 // if the DC was clipped thanks to rectPaint, we must adjust the
175 // origin accordingly; but we do *not* adjust for 'rect', because
20671963
VS
176 // rect.GetPosition() has coordinates (0,0) in the DC:
177 origin.x = rectOrig.x - r.x;
178 origin.y = rectOrig.y - r.y;
179
d18a7061 180 // m_shouldFlip was set in the "if" block above this one
78d2c241
VS
181 }
182
183 if ( !surface )
184 return;
185
d18a7061 186 wxLogTrace(TRACE_PAINT,
a5001e93 187 "%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]",
d18a7061
VS
188 win, win->GetName().c_str(),
189 rectOrig.x, rectOrig.y, rectOrig.GetRight(), rectOrig.GetBottom(),
190 r.x, r.y, r.GetRight(), r.GetBottom(),
191 origin.x, origin.y);
192
c16db850 193 DFBInit(surface);
b3c86150 194 SetFont(win->GetFont());
78d2c241
VS
195
196 // offset coordinates to account for subsurface's origin coordinates:
20671963 197 SetDeviceOrigin(origin.x, origin.y);
b3c86150
VS
198}
199
4a624f6e 200wxWindowDCImpl::~wxWindowDCImpl()
b3c86150 201{
20671963 202 wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
4dc9a81d 203 if ( !surface )
20671963
VS
204 return;
205
206 // if no painting was done on the DC, we don't have to flip the surface:
207 if ( !m_isBBoxValid )
208 return;
209
4dc9a81d 210 if ( m_shouldFlip )
20671963 211 {
30c841c8
VS
212 // paint overlays on top of the surface being drawn to by this DC
213 // before showing anything on the screen:
9d646d31 214 GetWindow()->PaintOverlays(m_winRect);
30c841c8 215
7e2baeb4
VS
216 DFBSurfaceCapabilities caps = DSCAPS_NONE;
217 surface->GetCapabilities(&caps);
218 if ( caps & DSCAPS_DOUBLE )
219 {
220 // FIXME: flip only modified parts of the surface
221 surface->FlipToFront();
222 }
223 // else: the surface is not double-buffered and so cannot be flipped
20671963
VS
224 }
225 // else: don't flip the surface, wxTLW will do it when it finishes
226 // painting of its invalidated areas
b3c86150
VS
227}
228
229//-----------------------------------------------------------------------------
4a624f6e 230// wxClientDCImpl
b3c86150
VS
231//-----------------------------------------------------------------------------
232
4a624f6e 233IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl)
b3c86150 234
4a624f6e
VZ
235wxClientDCImpl::wxClientDCImpl(wxDC *owner, wxWindow *win)
236 : wxWindowDCImpl(owner, win)
b3c86150 237{
a5001e93 238 wxCHECK_RET( win, "invalid window" );
17dd5538 239
20671963
VS
240 wxRect rect = win->GetClientRect();
241 InitForWin(win, &rect);
b3c86150
VS
242}
243
244//-----------------------------------------------------------------------------
245// wxPaintDC
246//-----------------------------------------------------------------------------
247
4a624f6e 248IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl)