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