1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // must be first
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <tools/diagnose_ex.h>
30cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
33cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "externalshapebase.hxx"
36cdf0e10cSrcweir #include "eventmultiplexer.hxx"
37cdf0e10cSrcweir #include "vieweventhandler.hxx"
38cdf0e10cSrcweir #include "intrinsicanimationeventhandler.hxx"
39cdf0e10cSrcweir #include "tools.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <boost/noncopyable.hpp>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace slideshow
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     namespace internal
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         class ExternalShapeBase::ExternalShapeBaseListener : public ViewEventHandler,
52cdf0e10cSrcweir                                                              public IntrinsicAnimationEventHandler,
53cdf0e10cSrcweir                                                              private boost::noncopyable
54cdf0e10cSrcweir         {
55cdf0e10cSrcweir         public:
ExternalShapeBaseListener(ExternalShapeBase & rBase)56cdf0e10cSrcweir             explicit ExternalShapeBaseListener( ExternalShapeBase& rBase ) :
57cdf0e10cSrcweir                 mrBase( rBase )
58cdf0e10cSrcweir             {}
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         private:
62cdf0e10cSrcweir             // ViewEventHandler
63cdf0e10cSrcweir             // -------------------------------------------------
64cdf0e10cSrcweir 
viewAdded(const UnoViewSharedPtr &)65cdf0e10cSrcweir             virtual void viewAdded( const UnoViewSharedPtr& ) {}
viewRemoved(const UnoViewSharedPtr &)66cdf0e10cSrcweir             virtual void viewRemoved( const UnoViewSharedPtr& ) {}
viewChanged(const UnoViewSharedPtr & rView)67cdf0e10cSrcweir             virtual void viewChanged( const UnoViewSharedPtr& rView )
68cdf0e10cSrcweir             {
69cdf0e10cSrcweir                 mrBase.implViewChanged(rView);
70cdf0e10cSrcweir             }
viewsChanged()71cdf0e10cSrcweir             virtual void viewsChanged()
72cdf0e10cSrcweir             {
73cdf0e10cSrcweir                 mrBase.implViewsChanged();
74cdf0e10cSrcweir             }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             // IntrinsicAnimationEventHandler
78cdf0e10cSrcweir             // -------------------------------------------------
79cdf0e10cSrcweir 
enableAnimations()80cdf0e10cSrcweir             virtual bool enableAnimations()
81cdf0e10cSrcweir             {
82cdf0e10cSrcweir                 return mrBase.implStartIntrinsicAnimation();
83cdf0e10cSrcweir             }
disableAnimations()84cdf0e10cSrcweir             virtual bool disableAnimations()
85cdf0e10cSrcweir             {
86cdf0e10cSrcweir                 return mrBase.implEndIntrinsicAnimation();
87cdf0e10cSrcweir             }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             ExternalShapeBase& mrBase;
90cdf0e10cSrcweir         };
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
ExternalShapeBase(const uno::Reference<drawing::XShape> & xShape,double nPrio,const SlideShowContext & rContext)93cdf0e10cSrcweir         ExternalShapeBase::ExternalShapeBase( const uno::Reference< drawing::XShape >& 	xShape,
94cdf0e10cSrcweir                                               double									nPrio,
95cdf0e10cSrcweir                                               const SlideShowContext&                   rContext ) :
96cdf0e10cSrcweir             mxComponentContext( rContext.mxComponentContext ),
97cdf0e10cSrcweir             mxShape( xShape ),
98cdf0e10cSrcweir             mpListener( new ExternalShapeBaseListener(*this) ),
99cdf0e10cSrcweir             mpShapeManager( rContext.mpSubsettableShapeManager ),
100cdf0e10cSrcweir             mrEventMultiplexer( rContext.mrEventMultiplexer ),
101cdf0e10cSrcweir             mnPriority( nPrio ), // TODO(F1): When ZOrder someday becomes usable: make this ( getAPIShapePrio( xShape ) ),
102cdf0e10cSrcweir             maBounds( getAPIShapeBounds( xShape ) )
103cdf0e10cSrcweir         {
104cdf0e10cSrcweir             ENSURE_OR_THROW( mxShape.is(), "ExternalShapeBase::ExternalShapeBase(): Invalid XShape" );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir             mpShapeManager->addIntrinsicAnimationHandler( mpListener );
107cdf0e10cSrcweir             mrEventMultiplexer.addViewHandler( mpListener );
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		// ---------------------------------------------------------------------
111cdf0e10cSrcweir 
~ExternalShapeBase()112cdf0e10cSrcweir         ExternalShapeBase::~ExternalShapeBase()
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             try
115cdf0e10cSrcweir             {
116cdf0e10cSrcweir                 mrEventMultiplexer.removeViewHandler( mpListener );
117cdf0e10cSrcweir                 mpShapeManager->removeIntrinsicAnimationHandler( mpListener );
118cdf0e10cSrcweir             }
119cdf0e10cSrcweir             catch (uno::Exception &)
120cdf0e10cSrcweir             {
121cdf0e10cSrcweir                 OSL_ENSURE( false, rtl::OUStringToOString(
122cdf0e10cSrcweir                                 comphelper::anyToString(
123cdf0e10cSrcweir                                     cppu::getCaughtException() ),
124cdf0e10cSrcweir                                 RTL_TEXTENCODING_UTF8 ).getStr() );
125cdf0e10cSrcweir             }
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		// ---------------------------------------------------------------------
129cdf0e10cSrcweir 
getXShape() const130cdf0e10cSrcweir         uno::Reference< drawing::XShape > ExternalShapeBase::getXShape() const
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             return mxShape;
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		// ---------------------------------------------------------------------
136cdf0e10cSrcweir 
play()137cdf0e10cSrcweir         void ExternalShapeBase::play()
138cdf0e10cSrcweir         {
139cdf0e10cSrcweir             implStartIntrinsicAnimation();
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		// ---------------------------------------------------------------------
143cdf0e10cSrcweir 
stop()144cdf0e10cSrcweir         void ExternalShapeBase::stop()
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             implEndIntrinsicAnimation();
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 		// ---------------------------------------------------------------------
150cdf0e10cSrcweir 
pause()151cdf0e10cSrcweir         void ExternalShapeBase::pause()
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             implPauseIntrinsicAnimation();
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		// ---------------------------------------------------------------------
157cdf0e10cSrcweir 
isPlaying() const158cdf0e10cSrcweir         bool ExternalShapeBase::isPlaying() const
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             return implIsIntrinsicAnimationPlaying();
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		// ---------------------------------------------------------------------
164cdf0e10cSrcweir 
setMediaTime(double fTime)165cdf0e10cSrcweir         void ExternalShapeBase::setMediaTime(double fTime)
166cdf0e10cSrcweir         {
167cdf0e10cSrcweir             implSetIntrinsicAnimationTime(fTime);
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		// ---------------------------------------------------------------------
171cdf0e10cSrcweir 
update() const172cdf0e10cSrcweir         bool ExternalShapeBase::update() const
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir 			return render();
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		// ---------------------------------------------------------------------
178cdf0e10cSrcweir 
render() const179cdf0e10cSrcweir         bool ExternalShapeBase::render() const
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             if( maBounds.getRange().equalZero() )
182cdf0e10cSrcweir             {
183cdf0e10cSrcweir                 // zero-sized shapes are effectively invisible,
184cdf0e10cSrcweir                 // thus, we save us the rendering...
185cdf0e10cSrcweir                 return true;
186cdf0e10cSrcweir             }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             return implRender( maBounds );
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		// ---------------------------------------------------------------------
192cdf0e10cSrcweir 
isContentChanged() const193cdf0e10cSrcweir         bool ExternalShapeBase::isContentChanged() const
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			return true;
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		// ---------------------------------------------------------------------
199cdf0e10cSrcweir 
getBounds() const200cdf0e10cSrcweir         ::basegfx::B2DRectangle ExternalShapeBase::getBounds() const
201cdf0e10cSrcweir         {
202cdf0e10cSrcweir         	return maBounds;
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 		// ---------------------------------------------------------------------
206cdf0e10cSrcweir 
getDomBounds() const207cdf0e10cSrcweir         ::basegfx::B2DRectangle ExternalShapeBase::getDomBounds() const
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir             return maBounds;
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 		// ---------------------------------------------------------------------
213cdf0e10cSrcweir 
getUpdateArea() const214cdf0e10cSrcweir         ::basegfx::B2DRectangle ExternalShapeBase::getUpdateArea() const
215cdf0e10cSrcweir         {
216cdf0e10cSrcweir             return maBounds;
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 		// ---------------------------------------------------------------------
220cdf0e10cSrcweir 
isVisible() const221cdf0e10cSrcweir         bool ExternalShapeBase::isVisible() const
222cdf0e10cSrcweir 		{
223cdf0e10cSrcweir 			return true;
224cdf0e10cSrcweir 		}
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 		// ---------------------------------------------------------------------
227cdf0e10cSrcweir 
getPriority() const228cdf0e10cSrcweir         double ExternalShapeBase::getPriority() const
229cdf0e10cSrcweir         {
230cdf0e10cSrcweir             return mnPriority;
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 		// ---------------------------------------------------------------------
234cdf0e10cSrcweir 
isBackgroundDetached() const235cdf0e10cSrcweir         bool ExternalShapeBase::isBackgroundDetached() const
236cdf0e10cSrcweir         {
237cdf0e10cSrcweir             // external shapes always have their own window/surface
238cdf0e10cSrcweir 			return true;
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir }
243