]> git.saurik.com Git - wxWidgets.git/blob - src/common/overlaycmn.cpp
Minor header cleaning.
[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(__WXGTK__)
150 m_window = dc->m_owner;
151 #else
152 #if defined (__WXMSW__)
153 m_window = dc->GetWindow();
154 #endif // __WXMSW__
155
156 #endif
157 wxMemoryDC dcMem ;
158 m_bmpSaved.Create( width, height );
159 dcMem.SelectObject( m_bmpSaved );
160 m_x = x ;
161 m_y = y ;
162 m_width = width ;
163 m_height = height ;
164 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
165 wxPoint pt = dc->GetDeviceOrigin();
166 x += pt.x;
167 y += pt.y;
168 #endif // broken wxGTK wxDC::Blit
169 dcMem.Blit(0, 0, m_width, m_height,
170 dc, x, y);
171 dcMem.SelectObject( wxNullBitmap );
172 }
173
174 void wxOverlayImpl::Clear(wxWindowDC* dc)
175 {
176 wxMemoryDC dcMem ;
177 dcMem.SelectObject( m_bmpSaved );
178 dc->Blit( m_x, m_y, m_width, m_height , &dcMem , 0 , 0 );
179 dcMem.SelectObject( wxNullBitmap );
180 }
181
182 void wxOverlayImpl::Reset()
183 {
184 m_bmpSaved = wxBitmap();
185 }
186
187 void wxOverlayImpl::BeginDrawing(wxWindowDC* WXUNUSED(dc))
188 {
189 }
190
191 void wxOverlayImpl::EndDrawing(wxWindowDC* WXUNUSED(dc))
192 {
193 }
194
195 #endif // !wxHAS_NATIVE_OVERLAY
196
197