1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "PresenterSprite.hxx"
32 
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/rendering/CompositeOperation.hpp>
35 #include <com/sun/star/rendering/RenderState.hpp>
36 #include <com/sun/star/rendering/ViewState.hpp>
37 
38 using namespace ::com::sun::star;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::UNO_QUERY;
41 
42 namespace sdext { namespace presenter {
43 
44 PresenterSprite::PresenterSprite (void)
45     : mxSpriteFactory(),
46       mxSprite(),
47       maSize(0,0),
48       maLocation(0,0),
49       maTransform(1,0,0, 0,1,0),
50       mbIsVisible(false),
51       mnPriority(0),
52       mnAlpha(1.0)
53 {
54 }
55 
56 
57 
58 
59 PresenterSprite::~PresenterSprite (void)
60 {
61     if (mxSprite.is())
62     {
63         mxSprite->hide();
64         Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
65         if (xComponent.is())
66             xComponent->dispose();
67         mxSprite = NULL;
68     }
69 }
70 
71 
72 
73 
74 void PresenterSprite::SetFactory (
75     const ::css::uno::Reference<css::rendering::XSpriteCanvas>& rxSpriteFactory)
76 {
77     if (mxSpriteFactory != rxSpriteFactory)
78     {
79         DisposeSprite();
80         mxSpriteFactory = rxSpriteFactory;
81         if (mbIsVisible)
82             PresenterSprite();
83     }
84 }
85 
86 
87 
88 
89 ::css::uno::Reference<css::rendering::XCanvas> PresenterSprite::GetCanvas (void)
90 {
91     ProvideSprite();
92     if (mxSprite.is())
93         return mxSprite->getContentCanvas();
94     else
95         return NULL;
96 }
97 
98 
99 
100 
101 void PresenterSprite::Show (void)
102 {
103     mbIsVisible = true;
104     if (mxSprite.is())
105         mxSprite->show();
106     else
107         ProvideSprite();
108 }
109 
110 
111 
112 
113 void PresenterSprite::Hide (void)
114 {
115     mbIsVisible = false;
116     if (mxSprite.is())
117         mxSprite->hide();
118 }
119 
120 
121 
122 
123 bool PresenterSprite::IsVisible (void) const
124 {
125     return mbIsVisible;
126 }
127 
128 
129 
130 
131 void PresenterSprite::SetPriority (const double nPriority)
132 {
133     mnPriority = nPriority;
134     if (mxSprite.is())
135         mxSprite->setPriority(mnPriority);
136 }
137 
138 
139 
140 
141 double PresenterSprite::GetPriority (void) const
142 {
143     return mnPriority;
144 }
145 
146 
147 
148 
149 void PresenterSprite::Resize (const css::geometry::RealSize2D& rSize)
150 {
151     maSize = rSize;
152     if (mxSprite.is())
153         DisposeSprite();
154     if (mbIsVisible)
155         ProvideSprite();
156 }
157 
158 
159 
160 
161 css::geometry::RealSize2D PresenterSprite::GetSize (void) const
162 {
163     return maSize;
164 }
165 
166 
167 
168 
169 void PresenterSprite::MoveTo (const css::geometry::RealPoint2D& rLocation)
170 {
171     maLocation = rLocation;
172     if (mxSprite.is())
173         mxSprite->move(
174             maLocation,
175             rendering::ViewState(
176                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
177                 NULL),
178             rendering::RenderState(
179                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
180                 NULL,
181                 uno::Sequence<double>(4),
182                 rendering::CompositeOperation::SOURCE)
183             );
184 }
185 
186 
187 
188 
189 css::geometry::RealPoint2D PresenterSprite::GetLocation (void) const
190 {
191     return maLocation;
192 }
193 
194 
195 
196 
197 void PresenterSprite::Transform (const css::geometry::AffineMatrix2D& rTransform)
198 {
199     maTransform = rTransform;
200     if (mxSprite.is())
201         mxSprite->transform(maTransform);
202 }
203 
204 
205 
206 
207 css::geometry::AffineMatrix2D PresenterSprite::GetTransform (void) const
208 {
209     return maTransform;
210 }
211 
212 
213 
214 
215 void PresenterSprite::SetAlpha (const double nAlpha)
216 {
217     mnAlpha = nAlpha;
218     if (mxSprite.is())
219         mxSprite->setAlpha(mnAlpha);
220 }
221 
222 
223 
224 
225 double PresenterSprite::GetAlpha (void) const
226 {
227     return mnAlpha;
228 }
229 
230 
231 
232 
233 void PresenterSprite::Update (void)
234 {
235     if (mxSpriteFactory.is())
236         mxSpriteFactory->updateScreen(sal_False);
237 }
238 
239 
240 
241 
242 void PresenterSprite::ProvideSprite (void)
243 {
244     if ( ! mxSprite.is()
245         && mxSpriteFactory.is()
246         && maSize.Width>0
247         && maSize.Height>0)
248     {
249         mxSprite = mxSpriteFactory->createCustomSprite(maSize);
250         if (mxSprite.is())
251         {
252             mxSprite->transform(maTransform);
253             mxSprite->move(maLocation,
254                 rendering::ViewState(
255                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
256                 NULL),
257             rendering::RenderState(
258                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
259                 NULL,
260                 uno::Sequence<double>(4),
261                 rendering::CompositeOperation::SOURCE)
262                 );
263             mxSprite->setAlpha(mnAlpha);
264             mxSprite->setPriority(mnPriority);
265             if (mbIsVisible)
266                 mxSprite->show();
267         }
268     }
269 }
270 
271 
272 
273 
274 void PresenterSprite::DisposeSprite (void)
275 {
276     if (mxSprite.is())
277     {
278         mxSprite->hide();
279         Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
280         if (xComponent.is())
281             xComponent->dispose();
282         mxSprite = NULL;
283     }
284 }
285 
286 
287 
288 
289 } } //end of namespace sdext::presenter
290