]> git.saurik.com Git - wxWidgets.git/blob - src/common/overlaycmn.cpp
add wxUSE_DATAVIEWCTRL check to fix a hundred compilation errors
[wxWidgets.git] / src / common / overlaycmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/overlaycmn.cpp
3 // Purpose: common wxOverlay code
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2006-10-20
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/overlay.h"
28 #include "wx/private/overlay.h"
29 #include "wx/dcclient.h"
30 #include "wx/dcmemory.h"
31
32 // ============================================================================
33 // implementation
34 // ============================================================================
35
36 // ----------------------------------------------------------------------------
37 // wxOverlay
38 // ----------------------------------------------------------------------------
39
40 wxOverlay::wxOverlay()
41 {
42 m_impl = new wxOverlayImpl();
43 m_inDrawing = false;
44 }
45
46 wxOverlay::~wxOverlay()
47 {
48 delete m_impl;
49 }
50
51 bool wxOverlay::IsOk()
52 {
53 return m_impl->IsOk();
54 }
55
56 void wxOverlay::Init( wxWindowDC* dc, int x , int y , int width , int height )
57 {
58 m_impl->Init(dc, x, y, width, height);
59 }
60
61 void wxOverlay::BeginDrawing( wxWindowDC* dc)
62 {
63 m_impl->BeginDrawing(dc);
64 m_inDrawing = true ;
65 }
66
67 void wxOverlay::EndDrawing( wxWindowDC* dc)
68 {
69 m_impl->EndDrawing(dc);
70 m_inDrawing = false ;
71 }
72
73 void wxOverlay::Clear( wxWindowDC* dc)
74 {
75 m_impl->Clear(dc);
76 }
77
78 void wxOverlay::Reset()
79 {
80 wxASSERT_MSG(m_inDrawing==false,wxT("cannot reset overlay during drawing"));
81 m_impl->Reset();
82 }
83
84
85 // ----------------------------------------------------------------------------
86 // wxDCOverlay
87 // ----------------------------------------------------------------------------
88
89 wxDCOverlay::wxDCOverlay(wxOverlay &overlay, wxWindowDC *dc, int x , int y , int width , int height) :
90 m_overlay(overlay)
91 {
92 Init(dc, x, y, width, height);
93 }
94
95 wxDCOverlay::wxDCOverlay(wxOverlay &overlay, wxWindowDC *dc) :
96 m_overlay(overlay)
97 {
98 int width;
99 int height;
100 dc->GetSize(&width,&height);
101 Init(dc, 0, 0, width, height);
102 }
103
104 wxDCOverlay::~wxDCOverlay()
105 {
106 m_overlay.EndDrawing(m_dc);
107 }
108
109 void wxDCOverlay::Init(wxWindowDC *dc, int x , int y , int width , int height )
110 {
111 m_dc = dc ;
112 if ( !m_overlay.IsOk() )
113 {
114 m_overlay.Init(dc,x,y,width,height);
115 }
116 m_overlay.BeginDrawing(dc);
117 }
118
119 void wxDCOverlay::Clear()
120 {
121 m_overlay.Clear(m_dc);
122 }
123
124 // ----------------------------------------------------------------------------
125 // generic implementation of wxOverlayImpl
126 // ----------------------------------------------------------------------------
127
128 #ifndef wxHAS_NATIVE_OVERLAY
129
130 wxOverlayImpl::wxOverlayImpl()
131 {
132 #if defined(__WXGTK__) || defined(__WXMSW__)
133 m_window = NULL ;
134 #endif
135 m_x = m_y = m_width = m_height = 0 ;
136 }
137
138 wxOverlayImpl::~wxOverlayImpl()
139 {
140 }
141
142 bool wxOverlayImpl::IsOk()
143 {
144 return m_bmpSaved.Ok() ;
145 }
146
147 void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height )
148 {
149 #if defined(__WXGTK20__)
150 #if wxUSE_NEW_DC
151 wxImplDC *impl = dc->GetImpl();
152 wxGTKWindowImplDC *gtk_impl = wxDynamicCast( impl, wxGTKWindowImplDC );
153 if (gtk_impl)
154 m_window = gtk_impl->m_owningWindow;
155 #else
156 m_window = dc->m_owningWindow;
157 #endif
158 #elif defined(__WXGTK__)
159 m_window = dc->m_owner;
160 #elif defined(__WXMSW__)
161 m_window = dc->GetWindow();
162 #endif
163 wxMemoryDC dcMem ;
164 m_bmpSaved.Create( width, height );
165 dcMem.SelectObject( m_bmpSaved );
166 m_x = x ;
167 m_y = y ;
168 m_width = width ;
169 m_height = height ;
170 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
171 wxPoint pt = dc->GetDeviceOrigin();
172 x += pt.x;
173 y += pt.y;
174 #endif // broken wxGTK wxDC::Blit
175 dcMem.Blit(0, 0, m_width, m_height,
176 dc, x, y);
177 dcMem.SelectObject( wxNullBitmap );
178 }
179
180 void wxOverlayImpl::Clear(wxWindowDC* dc)
181 {
182 wxMemoryDC dcMem ;
183 dcMem.SelectObject( m_bmpSaved );
184 dc->Blit( m_x, m_y, m_width, m_height , &dcMem , 0 , 0 );
185 dcMem.SelectObject( wxNullBitmap );
186 }
187
188 void wxOverlayImpl::Reset()
189 {
190 m_bmpSaved = wxBitmap();
191 }
192
193 void wxOverlayImpl::BeginDrawing(wxWindowDC* WXUNUSED(dc))
194 {
195 }
196
197 void wxOverlayImpl::EndDrawing(wxWindowDC* WXUNUSED(dc))
198 {
199 }
200
201 #endif // !wxHAS_NATIVE_OVERLAY
202
203