]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dcclient.cpp
fixed off by 2 error in HasPage() (patch 1562871)
[wxWidgets.git] / src / dfb / dcclient.cpp
CommitLineData
b3c86150
VS
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
20671963
VS
34#define TRACE_PAINT _T("paint")
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));
61 rp.Offset(-win->GetPosition());
62 rp.Offset(-parent->GetClientAreaOrigin());
63 r.Intersect(rp);
64
65 return r;
66}
67
68// creates a dummy surface that has the same format as the real window's
69// surface, but is not visible and so can be painted on even if the window
70// is hidden
71static
72wxIDirectFBSurfacePtr CreateDummySurface(wxWindow *win, const wxRect *rect)
73{
74 wxLogTrace(TRACE_PAINT, _T("%p ('%s'): creating dummy DC surface"),
75 win, win->GetName().c_str());
76 wxSize size(rect ? rect->GetSize() : win->GetSize());
7e2baeb4
VS
77 return win->GetDfbSurface()->CreateCompatible
78 (
79 size,
80 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
81 );
4dc9a81d
VS
82}
83
b3c86150
VS
84//-----------------------------------------------------------------------------
85// wxWindowDC
86//-----------------------------------------------------------------------------
87
88IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
89
90wxWindowDC::wxWindowDC(wxWindow *win)
b3c86150 91{
78d2c241 92 InitForWin(win, NULL);
b3c86150
VS
93}
94
78d2c241 95void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect)
b3c86150 96{
20671963 97 wxCHECK_RET( win, _T("invalid window") );
17dd5538 98
78d2c241 99 // obtain the surface used for painting:
20671963 100 wxPoint origin;
78d2c241 101 wxIDirectFBSurfacePtr surface;
2582bcdc 102
d18a7061
VS
103 wxRect rectOrig(rect ? *rect : wxRect(win->GetSize()));
104 wxRect r;
105
865a74c7 106 if ( !win->IsShownOnScreen() )
2582bcdc 107 {
d18a7061
VS
108 // leave 'r' rectangle empty to indicate the window is not visible,
109 // see below (below "create the surface:") for how is this case handled
2582bcdc 110 }
78d2c241
VS
111 else
112 {
20671963
VS
113 // compute painting rectangle after clipping if we're in PaintWindow
114 // code, otherwise paint on the entire window:
d18a7061 115 r = rectOrig;
20671963 116
4dc9a81d
VS
117 const wxRegion& updateRegion = win->GetUpdateRegion();
118 if ( win->GetTLW()->IsPainting() && !updateRegion.IsEmpty() )
119 {
120 r.Intersect(updateRegion.AsRect());
d18a7061
VS
121 wxCHECK_RET( !r.IsEmpty(), _T("invalid painting rectangle") );
122
4dc9a81d
VS
123 // parent TLW will flip the entire surface when painting is done
124 m_shouldFlip = false;
4dc9a81d
VS
125 }
126 else
127 {
128 // One of two things happened:
129 // (1) the TLW is not being painted by PaintWindow() now; or
130 // (2) we're drawing on some window other than the one that is
131 // currently painted on by PaintWindow()
132 // In either case, we need to flip the surface when we're done
133 // painting and we don't have to use updateRegion for clipping.
134 // OTOH, if the window is (partially) hidden by being
135 // out of its parent's area, we must clip the surface accordingly.
136 r.Intersect(GetUncoveredWindowArea(win));
d18a7061 137 m_shouldFlip = true; // paint the results immediately
4dc9a81d 138 }
d18a7061 139 }
20671963 140
d18a7061
VS
141 // create the surface:
142 if ( r.IsEmpty() )
143 {
144 // we're painting on invisible window: the changes won't have any
145 // effect, as the window will be repainted anyhow when it is shown,
146 // but we still need a valid DC so that e.g. text extents can be
147 // measured, so let's create a dummy surface that has the same
148 // format as the real one would have and let the code paint on it:
149 surface = CreateDummySurface(win, rect);
150
151 // painting on hidden window has no effect on TLW's surface, don't
152 // waste time flipping the dummy surface:
153 m_shouldFlip = false;
154 }
155 else
156 {
157 DFBRectangle dfbrect = { r.x, r.y, r.width, r.height };
158 surface = win->GetDfbSurface()->GetSubSurface(&dfbrect);
159
160 // if the DC was clipped thanks to rectPaint, we must adjust the
161 // origin accordingly; but we do *not* adjust for 'rect', because
20671963
VS
162 // rect.GetPosition() has coordinates (0,0) in the DC:
163 origin.x = rectOrig.x - r.x;
164 origin.y = rectOrig.y - r.y;
165
d18a7061 166 // m_shouldFlip was set in the "if" block above this one
78d2c241
VS
167 }
168
169 if ( !surface )
170 return;
171
d18a7061
VS
172 wxLogTrace(TRACE_PAINT,
173 _T("%p ('%s'): creating DC for area [%i,%i,%i,%i], clipped to [%i,%i,%i,%i], origin [%i,%i]"),
174 win, win->GetName().c_str(),
175 rectOrig.x, rectOrig.y, rectOrig.GetRight(), rectOrig.GetBottom(),
176 r.x, r.y, r.GetRight(), r.GetBottom(),
177 origin.x, origin.y);
178
78d2c241 179 Init(surface);
b3c86150 180 SetFont(win->GetFont());
78d2c241
VS
181
182 // offset coordinates to account for subsurface's origin coordinates:
20671963 183 SetDeviceOrigin(origin.x, origin.y);
b3c86150
VS
184}
185
20671963 186wxWindowDC::~wxWindowDC()
b3c86150 187{
20671963 188 wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
4dc9a81d 189 if ( !surface )
20671963
VS
190 return;
191
192 // if no painting was done on the DC, we don't have to flip the surface:
193 if ( !m_isBBoxValid )
194 return;
195
4dc9a81d 196 if ( m_shouldFlip )
20671963 197 {
7e2baeb4
VS
198 DFBSurfaceCapabilities caps = DSCAPS_NONE;
199 surface->GetCapabilities(&caps);
200 if ( caps & DSCAPS_DOUBLE )
201 {
202 // FIXME: flip only modified parts of the surface
203 surface->FlipToFront();
204 }
205 // else: the surface is not double-buffered and so cannot be flipped
20671963
VS
206 }
207 // else: don't flip the surface, wxTLW will do it when it finishes
208 // painting of its invalidated areas
b3c86150
VS
209}
210
211//-----------------------------------------------------------------------------
212// wxClientDC
213//-----------------------------------------------------------------------------
214
215IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
216
20671963 217wxClientDC::wxClientDC(wxWindow *win)
b3c86150 218{
20671963 219 wxCHECK_RET( win, _T("invalid window") );
17dd5538 220
20671963
VS
221 wxRect rect = win->GetClientRect();
222 InitForWin(win, &rect);
b3c86150
VS
223}
224
225//-----------------------------------------------------------------------------
226// wxPaintDC
227//-----------------------------------------------------------------------------
228
229IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)