update dev300-m58
[ooovba.git] / sdext / source / presenter / PresenterSprite.cxx
blob8d419a7fcb2d3f8eb50299f229ae3bd4b1a81da6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterSprite.cxx,v $
11 * $Revision: 1.6 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterSprite.hxx"
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/rendering/CompositeOperation.hpp>
39 #include <com/sun/star/rendering/RenderState.hpp>
40 #include <com/sun/star/rendering/ViewState.hpp>
42 using namespace ::com::sun::star;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::UNO_QUERY;
46 namespace sdext { namespace presenter {
48 PresenterSprite::PresenterSprite (void)
49 : mxSpriteFactory(),
50 mxSprite(),
51 maSize(0,0),
52 maLocation(0,0),
53 maTransform(1,0,0, 0,1,0),
54 mbIsVisible(false),
55 mnPriority(0),
56 mnAlpha(1.0)
63 PresenterSprite::~PresenterSprite (void)
65 if (mxSprite.is())
67 mxSprite->hide();
68 Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
69 if (xComponent.is())
70 xComponent->dispose();
71 mxSprite = NULL;
78 void PresenterSprite::SetFactory (
79 const ::css::uno::Reference<css::rendering::XSpriteCanvas>& rxSpriteFactory)
81 if (mxSpriteFactory != rxSpriteFactory)
83 DisposeSprite();
84 mxSpriteFactory = rxSpriteFactory;
85 if (mbIsVisible)
86 PresenterSprite();
93 ::css::uno::Reference<css::rendering::XCanvas> PresenterSprite::GetCanvas (void)
95 ProvideSprite();
96 if (mxSprite.is())
97 return mxSprite->getContentCanvas();
98 else
99 return NULL;
105 void PresenterSprite::Show (void)
107 mbIsVisible = true;
108 if (mxSprite.is())
109 mxSprite->show();
110 else
111 ProvideSprite();
117 void PresenterSprite::Hide (void)
119 mbIsVisible = false;
120 if (mxSprite.is())
121 mxSprite->hide();
127 bool PresenterSprite::IsVisible (void) const
129 return mbIsVisible;
135 void PresenterSprite::SetPriority (const double nPriority)
137 mnPriority = nPriority;
138 if (mxSprite.is())
139 mxSprite->setPriority(mnPriority);
145 double PresenterSprite::GetPriority (void) const
147 return mnPriority;
153 void PresenterSprite::Resize (const css::geometry::RealSize2D& rSize)
155 maSize = rSize;
156 if (mxSprite.is())
157 DisposeSprite();
158 if (mbIsVisible)
159 ProvideSprite();
165 css::geometry::RealSize2D PresenterSprite::GetSize (void) const
167 return maSize;
173 void PresenterSprite::MoveTo (const css::geometry::RealPoint2D& rLocation)
175 maLocation = rLocation;
176 if (mxSprite.is())
177 mxSprite->move(
178 maLocation,
179 rendering::ViewState(
180 geometry::AffineMatrix2D(1,0,0, 0,1,0),
181 NULL),
182 rendering::RenderState(
183 geometry::AffineMatrix2D(1,0,0, 0,1,0),
184 NULL,
185 uno::Sequence<double>(4),
186 rendering::CompositeOperation::SOURCE)
193 css::geometry::RealPoint2D PresenterSprite::GetLocation (void) const
195 return maLocation;
201 void PresenterSprite::Transform (const css::geometry::AffineMatrix2D& rTransform)
203 maTransform = rTransform;
204 if (mxSprite.is())
205 mxSprite->transform(maTransform);
211 css::geometry::AffineMatrix2D PresenterSprite::GetTransform (void) const
213 return maTransform;
219 void PresenterSprite::SetAlpha (const double nAlpha)
221 mnAlpha = nAlpha;
222 if (mxSprite.is())
223 mxSprite->setAlpha(mnAlpha);
229 double PresenterSprite::GetAlpha (void) const
231 return mnAlpha;
237 void PresenterSprite::Update (void)
239 if (mxSpriteFactory.is())
240 mxSpriteFactory->updateScreen(sal_False);
246 void PresenterSprite::ProvideSprite (void)
248 if ( ! mxSprite.is()
249 && mxSpriteFactory.is()
250 && maSize.Width>0
251 && maSize.Height>0)
253 mxSprite = mxSpriteFactory->createCustomSprite(maSize);
254 if (mxSprite.is())
256 mxSprite->transform(maTransform);
257 mxSprite->move(maLocation,
258 rendering::ViewState(
259 geometry::AffineMatrix2D(1,0,0, 0,1,0),
260 NULL),
261 rendering::RenderState(
262 geometry::AffineMatrix2D(1,0,0, 0,1,0),
263 NULL,
264 uno::Sequence<double>(4),
265 rendering::CompositeOperation::SOURCE)
267 mxSprite->setAlpha(mnAlpha);
268 mxSprite->setPriority(mnPriority);
269 if (mbIsVisible)
270 mxSprite->show();
278 void PresenterSprite::DisposeSprite (void)
280 if (mxSprite.is())
282 mxSprite->hide();
283 Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
284 if (xComponent.is())
285 xComponent->dispose();
286 mxSprite = NULL;
293 } } //end of namespace sdext::presenter