1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26 
27 #include "PresenterSprite.hxx"
28 
29 #include <com/sun/star/lang/XComponent.hpp>
30 #include <com/sun/star/rendering/CompositeOperation.hpp>
31 #include <com/sun/star/rendering/RenderState.hpp>
32 #include <com/sun/star/rendering/ViewState.hpp>
33 
34 using namespace ::com::sun::star;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::UNO_QUERY;
37 
38 namespace sdext { namespace presenter {
39 
PresenterSprite(void)40 PresenterSprite::PresenterSprite (void)
41     : mxSpriteFactory(),
42       mxSprite(),
43       maSize(0,0),
44       maLocation(0,0),
45       maTransform(1,0,0, 0,1,0),
46       mbIsVisible(false),
47       mnPriority(0),
48       mnAlpha(1.0)
49 {
50 }
51 
52 
53 
54 
~PresenterSprite(void)55 PresenterSprite::~PresenterSprite (void)
56 {
57     if (mxSprite.is())
58     {
59         mxSprite->hide();
60         Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
61         if (xComponent.is())
62             xComponent->dispose();
63         mxSprite = NULL;
64     }
65 }
66 
67 
68 
69 
SetFactory(const::css::uno::Reference<css::rendering::XSpriteCanvas> & rxSpriteFactory)70 void PresenterSprite::SetFactory (
71     const ::css::uno::Reference<css::rendering::XSpriteCanvas>& rxSpriteFactory)
72 {
73     if (mxSpriteFactory != rxSpriteFactory)
74     {
75         DisposeSprite();
76         mxSpriteFactory = rxSpriteFactory;
77         if (mbIsVisible)
78             PresenterSprite();
79     }
80 }
81 
82 
83 
84 
GetCanvas(void)85 ::css::uno::Reference<css::rendering::XCanvas> PresenterSprite::GetCanvas (void)
86 {
87     ProvideSprite();
88     if (mxSprite.is())
89         return mxSprite->getContentCanvas();
90     else
91         return NULL;
92 }
93 
94 
95 
96 
Show(void)97 void PresenterSprite::Show (void)
98 {
99     mbIsVisible = true;
100     if (mxSprite.is())
101         mxSprite->show();
102     else
103         ProvideSprite();
104 }
105 
106 
107 
108 
Hide(void)109 void PresenterSprite::Hide (void)
110 {
111     mbIsVisible = false;
112     if (mxSprite.is())
113         mxSprite->hide();
114 }
115 
116 
117 
118 
IsVisible(void) const119 bool PresenterSprite::IsVisible (void) const
120 {
121     return mbIsVisible;
122 }
123 
124 
125 
126 
SetPriority(const double nPriority)127 void PresenterSprite::SetPriority (const double nPriority)
128 {
129     mnPriority = nPriority;
130     if (mxSprite.is())
131         mxSprite->setPriority(mnPriority);
132 }
133 
134 
135 
136 
GetPriority(void) const137 double PresenterSprite::GetPriority (void) const
138 {
139     return mnPriority;
140 }
141 
142 
143 
144 
Resize(const css::geometry::RealSize2D & rSize)145 void PresenterSprite::Resize (const css::geometry::RealSize2D& rSize)
146 {
147     maSize = rSize;
148     if (mxSprite.is())
149         DisposeSprite();
150     if (mbIsVisible)
151         ProvideSprite();
152 }
153 
154 
155 
156 
GetSize(void) const157 css::geometry::RealSize2D PresenterSprite::GetSize (void) const
158 {
159     return maSize;
160 }
161 
162 
163 
164 
MoveTo(const css::geometry::RealPoint2D & rLocation)165 void PresenterSprite::MoveTo (const css::geometry::RealPoint2D& rLocation)
166 {
167     maLocation = rLocation;
168     if (mxSprite.is())
169         mxSprite->move(
170             maLocation,
171             rendering::ViewState(
172                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
173                 NULL),
174             rendering::RenderState(
175                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
176                 NULL,
177                 uno::Sequence<double>(4),
178                 rendering::CompositeOperation::SOURCE)
179             );
180 }
181 
182 
183 
184 
GetLocation(void) const185 css::geometry::RealPoint2D PresenterSprite::GetLocation (void) const
186 {
187     return maLocation;
188 }
189 
190 
191 
192 
Transform(const css::geometry::AffineMatrix2D & rTransform)193 void PresenterSprite::Transform (const css::geometry::AffineMatrix2D& rTransform)
194 {
195     maTransform = rTransform;
196     if (mxSprite.is())
197         mxSprite->transform(maTransform);
198 }
199 
200 
201 
202 
GetTransform(void) const203 css::geometry::AffineMatrix2D PresenterSprite::GetTransform (void) const
204 {
205     return maTransform;
206 }
207 
208 
209 
210 
SetAlpha(const double nAlpha)211 void PresenterSprite::SetAlpha (const double nAlpha)
212 {
213     mnAlpha = nAlpha;
214     if (mxSprite.is())
215         mxSprite->setAlpha(mnAlpha);
216 }
217 
218 
219 
220 
GetAlpha(void) const221 double PresenterSprite::GetAlpha (void) const
222 {
223     return mnAlpha;
224 }
225 
226 
227 
228 
Update(void)229 void PresenterSprite::Update (void)
230 {
231     if (mxSpriteFactory.is())
232         mxSpriteFactory->updateScreen(sal_False);
233 }
234 
235 
236 
237 
ProvideSprite(void)238 void PresenterSprite::ProvideSprite (void)
239 {
240     if ( ! mxSprite.is()
241         && mxSpriteFactory.is()
242         && maSize.Width>0
243         && maSize.Height>0)
244     {
245         mxSprite = mxSpriteFactory->createCustomSprite(maSize);
246         if (mxSprite.is())
247         {
248             mxSprite->transform(maTransform);
249             mxSprite->move(maLocation,
250                 rendering::ViewState(
251                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
252                 NULL),
253             rendering::RenderState(
254                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
255                 NULL,
256                 uno::Sequence<double>(4),
257                 rendering::CompositeOperation::SOURCE)
258                 );
259             mxSprite->setAlpha(mnAlpha);
260             mxSprite->setPriority(mnPriority);
261             if (mbIsVisible)
262                 mxSprite->show();
263         }
264     }
265 }
266 
267 
268 
269 
DisposeSprite(void)270 void PresenterSprite::DisposeSprite (void)
271 {
272     if (mxSprite.is())
273     {
274         mxSprite->hide();
275         Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
276         if (xComponent.is())
277             xComponent->dispose();
278         mxSprite = NULL;
279     }
280 }
281 
282 
283 
284 
285 } } //end of namespace sdext::presenter
286