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