]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dcclient.cpp
rebaked after listctrl/imagelist and wxUniv changes
[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
40//-----------------------------------------------------------------------------
41// wxWindowDC
42//-----------------------------------------------------------------------------
43
44IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
45
46wxWindowDC::wxWindowDC(wxWindow *win)
b3c86150 47{
78d2c241 48 InitForWin(win, NULL);
b3c86150
VS
49}
50
78d2c241 51void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect)
b3c86150 52{
20671963 53 m_win = win;
b3c86150 54
20671963 55 wxCHECK_RET( win, _T("invalid window") );
17dd5538 56
78d2c241 57 // obtain the surface used for painting:
20671963 58 wxPoint origin;
78d2c241 59 wxIDirectFBSurfacePtr surface;
2582bcdc 60
865a74c7 61 if ( !win->IsShownOnScreen() )
2582bcdc
VS
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:
20671963
VS
68 wxLogTrace(TRACE_PAINT, _T("%p ('%s'): creating dummy DC surface"),
69 win, win->GetName().c_str());
2582bcdc 70 wxSize size(rect ? rect->GetSize() : win->GetSize());
a5b31f4e 71 surface = win->GetDfbSurface()->CreateCompatible(size);
2582bcdc 72 }
78d2c241
VS
73 else
74 {
20671963
VS
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 };
78d2c241
VS
99 surface = win->GetDfbSurface()->GetSubSurface(&dfbrect);
100 }
101
102 if ( !surface )
103 return;
104
105 Init(surface);
b3c86150 106 SetFont(win->GetFont());
78d2c241
VS
107
108 // offset coordinates to account for subsurface's origin coordinates:
20671963 109 SetDeviceOrigin(origin.x, origin.y);
b3c86150
VS
110}
111
20671963 112wxWindowDC::~wxWindowDC()
b3c86150 113{
20671963
VS
114 wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
115 if ( !surface || !m_win )
116 return;
b3c86150 117
20671963
VS
118 // painting on hidden window has no effect on TLW's surface, don't
119 // waste time flipping the dummy surface:
865a74c7 120 if ( !m_win->IsShownOnScreen() )
20671963
VS
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
b3c86150
VS
134}
135
136//-----------------------------------------------------------------------------
137// wxClientDC
138//-----------------------------------------------------------------------------
139
140IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
141
20671963 142wxClientDC::wxClientDC(wxWindow *win)
b3c86150 143{
20671963 144 wxCHECK_RET( win, _T("invalid window") );
17dd5538 145
20671963
VS
146 wxRect rect = win->GetClientRect();
147 InitForWin(win, &rect);
b3c86150
VS
148}
149
150//-----------------------------------------------------------------------------
151// wxPaintDC
152//-----------------------------------------------------------------------------
153
154IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)