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_slideshow.hxx"
26 
27 // must be first
28 #include <canvas/debug.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <canvas/verbosetrace.hxx>
31 
32 #include <comphelper/anytostring.hxx>
33 #include <cppuhelper/exc_hlp.hxx>
34 
35 #include "externalshapebase.hxx"
36 #include "eventmultiplexer.hxx"
37 #include "vieweventhandler.hxx"
38 #include "intrinsicanimationeventhandler.hxx"
39 #include "tools.hxx"
40 
41 #include <boost/noncopyable.hpp>
42 
43 
44 using namespace ::com::sun::star;
45 
46 
47 namespace slideshow
48 {
49     namespace internal
50     {
51         class ExternalShapeBase::ExternalShapeBaseListener : public ViewEventHandler,
52                                                              public IntrinsicAnimationEventHandler,
53                                                              private boost::noncopyable
54         {
55         public:
ExternalShapeBaseListener(ExternalShapeBase & rBase)56             explicit ExternalShapeBaseListener( ExternalShapeBase& rBase ) :
57                 mrBase( rBase )
58             {}
59 
60 
61         private:
62             // ViewEventHandler
63             // -------------------------------------------------
64 
viewAdded(const UnoViewSharedPtr &)65             virtual void viewAdded( const UnoViewSharedPtr& ) {}
viewRemoved(const UnoViewSharedPtr &)66             virtual void viewRemoved( const UnoViewSharedPtr& ) {}
viewChanged(const UnoViewSharedPtr & rView)67             virtual void viewChanged( const UnoViewSharedPtr& rView )
68             {
69                 mrBase.implViewChanged(rView);
70             }
viewsChanged()71             virtual void viewsChanged()
72             {
73                 mrBase.implViewsChanged();
74             }
75 
76 
77             // IntrinsicAnimationEventHandler
78             // -------------------------------------------------
79 
enableAnimations()80             virtual bool enableAnimations()
81             {
82                 return mrBase.implStartIntrinsicAnimation();
83             }
disableAnimations()84             virtual bool disableAnimations()
85             {
86                 return mrBase.implEndIntrinsicAnimation();
87             }
88 
89             ExternalShapeBase& mrBase;
90         };
91 
92 
ExternalShapeBase(const uno::Reference<drawing::XShape> & xShape,double nPrio,const SlideShowContext & rContext)93         ExternalShapeBase::ExternalShapeBase( const uno::Reference< drawing::XShape >& 	xShape,
94                                               double									nPrio,
95                                               const SlideShowContext&                   rContext ) :
96             mxComponentContext( rContext.mxComponentContext ),
97             mxShape( xShape ),
98             mpListener( new ExternalShapeBaseListener(*this) ),
99             mpShapeManager( rContext.mpSubsettableShapeManager ),
100             mrEventMultiplexer( rContext.mrEventMultiplexer ),
101             mnPriority( nPrio ), // TODO(F1): When ZOrder someday becomes usable: make this ( getAPIShapePrio( xShape ) ),
102             maBounds( getAPIShapeBounds( xShape ) )
103         {
104             ENSURE_OR_THROW( mxShape.is(), "ExternalShapeBase::ExternalShapeBase(): Invalid XShape" );
105 
106             mpShapeManager->addIntrinsicAnimationHandler( mpListener );
107             mrEventMultiplexer.addViewHandler( mpListener );
108         }
109 
110 		// ---------------------------------------------------------------------
111 
~ExternalShapeBase()112         ExternalShapeBase::~ExternalShapeBase()
113         {
114             try
115             {
116                 mrEventMultiplexer.removeViewHandler( mpListener );
117                 mpShapeManager->removeIntrinsicAnimationHandler( mpListener );
118             }
119             catch (uno::Exception &)
120             {
121                 OSL_ENSURE( false, rtl::OUStringToOString(
122                                 comphelper::anyToString(
123                                     cppu::getCaughtException() ),
124                                 RTL_TEXTENCODING_UTF8 ).getStr() );
125             }
126         }
127 
128 		// ---------------------------------------------------------------------
129 
getXShape() const130         uno::Reference< drawing::XShape > ExternalShapeBase::getXShape() const
131         {
132             return mxShape;
133         }
134 
135 		// ---------------------------------------------------------------------
136 
play()137         void ExternalShapeBase::play()
138         {
139             implStartIntrinsicAnimation();
140         }
141 
142 		// ---------------------------------------------------------------------
143 
stop()144         void ExternalShapeBase::stop()
145         {
146             implEndIntrinsicAnimation();
147         }
148 
149 		// ---------------------------------------------------------------------
150 
pause()151         void ExternalShapeBase::pause()
152         {
153             implPauseIntrinsicAnimation();
154         }
155 
156 		// ---------------------------------------------------------------------
157 
isPlaying() const158         bool ExternalShapeBase::isPlaying() const
159         {
160             return implIsIntrinsicAnimationPlaying();
161         }
162 
163 		// ---------------------------------------------------------------------
164 
setMediaTime(double fTime)165         void ExternalShapeBase::setMediaTime(double fTime)
166         {
167             implSetIntrinsicAnimationTime(fTime);
168         }
169 
170 		// ---------------------------------------------------------------------
171 
update() const172         bool ExternalShapeBase::update() const
173         {
174 			return render();
175         }
176 
177 		// ---------------------------------------------------------------------
178 
render() const179         bool ExternalShapeBase::render() const
180         {
181             if( maBounds.getRange().equalZero() )
182             {
183                 // zero-sized shapes are effectively invisible,
184                 // thus, we save us the rendering...
185                 return true;
186             }
187 
188             return implRender( maBounds );
189         }
190 
191 		// ---------------------------------------------------------------------
192 
isContentChanged() const193         bool ExternalShapeBase::isContentChanged() const
194 		{
195 			return true;
196         }
197 
198 		// ---------------------------------------------------------------------
199 
getBounds() const200         ::basegfx::B2DRectangle ExternalShapeBase::getBounds() const
201         {
202         	return maBounds;
203         }
204 
205 		// ---------------------------------------------------------------------
206 
getDomBounds() const207         ::basegfx::B2DRectangle ExternalShapeBase::getDomBounds() const
208         {
209             return maBounds;
210         }
211 
212 		// ---------------------------------------------------------------------
213 
getUpdateArea() const214         ::basegfx::B2DRectangle ExternalShapeBase::getUpdateArea() const
215         {
216             return maBounds;
217         }
218 
219 		// ---------------------------------------------------------------------
220 
isVisible() const221         bool ExternalShapeBase::isVisible() const
222 		{
223 			return true;
224 		}
225 
226 		// ---------------------------------------------------------------------
227 
getPriority() const228         double ExternalShapeBase::getPriority() const
229         {
230             return mnPriority;
231         }
232 
233 		// ---------------------------------------------------------------------
234 
isBackgroundDetached() const235         bool ExternalShapeBase::isBackgroundDetached() const
236         {
237             // external shapes always have their own window/surface
238 			return true;
239         }
240 
241     }
242 }
243