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 <canvas/verbosetrace.hxx>
30 #include <canvas/canvastools.hxx>
31 
32 #include <boost/shared_ptr.hpp>
33 
34 #include "appletshape.hxx"
35 #include "externalshapebase.hxx"
36 #include "vieweventhandler.hxx"
37 #include "viewappletshape.hxx"
38 #include "tools.hxx"
39 
40 #include <boost/bind.hpp>
41 #include <algorithm>
42 
43 
44 using namespace ::com::sun::star;
45 
46 
47 namespace slideshow
48 {
49     namespace internal
50     {
51         /** Represents an applet shape.
52 
53             This implementation offers support for applet shapes (both
54             Java applets, and Netscape plugins). Such shapes need
55             special treatment.
56          */
57         class AppletShape : public ExternalShapeBase
58         {
59         public:
60             /** Create a shape for the given XShape for a applet object
61 
62             	@param xShape
63                 The XShape to represent.
64 
65                 @param nPrio
66                 Externally-determined shape priority (used e.g. for
67                 paint ordering). This number _must be_ unique!
68 
69                 @param rServiceName
70                 Service name to use, when creating the actual viewer
71                 component
72 
73                 @param pPropCopyTable
74                 Table of plain ASCII property names, to copy from
75                 xShape to applet.
76 
77                 @param nNumPropEntries
78                 Number of property table entries (in pPropCopyTable)
79              */
80             AppletShape( const ::com::sun::star::uno::Reference<
81                        		::com::sun::star::drawing::XShape >&	xShape,
82                          double										nPrio,
83                          const ::rtl::OUString&                     rServiceName,
84                          const char**                               pPropCopyTable,
85                          sal_Size                                   nNumPropEntries,
86                          const SlideShowContext&                    rContext ); // throw ShapeLoadFailedException;
87 
88         private:
89 
90             // View layer methods
91             //------------------------------------------------------------------
92 
93             virtual void addViewLayer( const ViewLayerSharedPtr& 	rNewLayer,
94                                        bool							bRedrawLayer );
95             virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer );
96             virtual bool clearAllViewLayers();
97 
98 
99             // ExternalShapeBase methods
100             //------------------------------------------------------------------
101 
102             virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const;
103             virtual void implViewChanged( const UnoViewSharedPtr& rView );
104             virtual void implViewsChanged();
105             virtual bool implStartIntrinsicAnimation();
106             virtual bool implEndIntrinsicAnimation();
107             virtual bool implPauseIntrinsicAnimation();
108             virtual bool implIsIntrinsicAnimationPlaying() const;
109             virtual void implSetIntrinsicAnimationTime(double);
110 
111             const ::rtl::OUString                           maServiceName;
112             const char**                                    mpPropCopyTable;
113             const sal_Size                                  mnNumPropEntries;
114 
115             /// the list of active view shapes (one for each registered view layer)
116             typedef ::std::vector< ViewAppletShapeSharedPtr > ViewAppletShapeVector;
117             ViewAppletShapeVector                           maViewAppletShapes;
118             bool                                             mbIsPlaying;
119         };
120 
AppletShape(const uno::Reference<drawing::XShape> & xShape,double nPrio,const::rtl::OUString & rServiceName,const char ** pPropCopyTable,sal_Size nNumPropEntries,const SlideShowContext & rContext)121         AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
122                                   double                                   nPrio,
123                                   const ::rtl::OUString&                   rServiceName,
124                                   const char**                             pPropCopyTable,
125                                   sal_Size                                 nNumPropEntries,
126                                   const SlideShowContext&                  rContext ) :
127             ExternalShapeBase( xShape, nPrio, rContext ),
128             maServiceName( rServiceName ),
129             mpPropCopyTable( pPropCopyTable ),
130             mnNumPropEntries( nNumPropEntries ),
131             maViewAppletShapes(),
132             mbIsPlaying(false)
133         {
134         }
135 
136 		// ---------------------------------------------------------------------
137 
implViewChanged(const UnoViewSharedPtr & rView)138         void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
139         {
140             // determine ViewAppletShape that needs update
141             ViewAppletShapeVector::const_iterator       aIter(maViewAppletShapes.begin());
142             ViewAppletShapeVector::const_iterator const aEnd (maViewAppletShapes.end());
143             while( aIter != aEnd )
144             {
145                 if( (*aIter)->getViewLayer()->isOnView(rView) )
146                     (*aIter)->resize(getBounds());
147 
148                 ++aIter;
149             }
150         }
151 
152 		// ---------------------------------------------------------------------
153 
implViewsChanged()154         void AppletShape::implViewsChanged()
155         {
156             // resize all ViewShapes
157             ::basegfx::B2DRectangle aBounds = AppletShape::getBounds();
158             ::std::for_each( maViewAppletShapes.begin(),
159                              maViewAppletShapes.end(),
160                              ::boost::bind(
161                                  &ViewAppletShape::resize,
162                                  _1,
163                                  ::boost::cref( aBounds ) ) );
164         }
165 
166 		// ---------------------------------------------------------------------
167 
addViewLayer(const ViewLayerSharedPtr & rNewLayer,bool bRedrawLayer)168         void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
169                                         bool                      bRedrawLayer )
170         {
171             try
172             {
173                 maViewAppletShapes.push_back(
174                     ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer,
175                                                                    getXShape(),
176                                                                    maServiceName,
177                                                                    mpPropCopyTable,
178                                                                    mnNumPropEntries,
179                                                                    mxComponentContext )));
180 
181                 // push new size to view shape
182                 maViewAppletShapes.back()->resize( getBounds() );
183 
184                 // render the Shape on the newly added ViewLayer
185                 if( bRedrawLayer )
186                     maViewAppletShapes.back()->render( getBounds() );
187             }
188             catch(uno::Exception&)
189             {
190                 // ignore failed shapes - slideshow should run with
191                 // the remaining content
192             }
193         }
194 
195 		// ---------------------------------------------------------------------
196 
removeViewLayer(const ViewLayerSharedPtr & rLayer)197         bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
198         {
199             const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
200 
201             OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
202                                         aEnd,
203                                         ::boost::bind<bool>(
204                                             ::std::equal_to< ViewLayerSharedPtr >(),
205                                             ::boost::bind( &ViewAppletShape::getViewLayer, _1 ),
206                                             ::boost::cref( rLayer ) ) ) < 2,
207                         "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
208 
209             ViewAppletShapeVector::iterator aIter;
210 
211             if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
212                                          aEnd,
213                                          ::boost::bind<bool>(
214                                              ::std::equal_to< ViewLayerSharedPtr >(),
215                                              ::boost::bind( &ViewAppletShape::getViewLayer,
216                                                             _1 ),
217                                              ::boost::cref( rLayer ) ) )) == aEnd )
218             {
219                 // view layer seemingly was not added, failed
220                 return false;
221             }
222 
223             // actually erase from container
224             maViewAppletShapes.erase( aIter, aEnd );
225 
226             return true;
227         }
228 
229 		// ---------------------------------------------------------------------
230 
clearAllViewLayers()231         bool AppletShape::clearAllViewLayers()
232         {
233             maViewAppletShapes.clear();
234             return true;
235         }
236 
237 		// ---------------------------------------------------------------------
238 
implRender(const::basegfx::B2DRange & rCurrBounds) const239         bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
240         {
241             // redraw all view shapes, by calling their update() method
242             if( ::std::count_if( maViewAppletShapes.begin(),
243                                  maViewAppletShapes.end(),
244                                  ::boost::bind<bool>(
245                                      ::boost::mem_fn( &ViewAppletShape::render ),
246                                      _1,
247                                      ::boost::cref( rCurrBounds ) ) )
248                 != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
249             {
250                 // at least one of the ViewShape::update() calls did return
251                 // false - update failed on at least one ViewLayer
252                 return false;
253             }
254 
255             return true;
256         }
257 
258 		// ---------------------------------------------------------------------
259 
implStartIntrinsicAnimation()260         bool AppletShape::implStartIntrinsicAnimation()
261         {
262             ::basegfx::B2DRectangle aBounds = getBounds();
263             ::std::for_each( maViewAppletShapes.begin(),
264                              maViewAppletShapes.end(),
265                              ::boost::bind( &ViewAppletShape::startApplet,
266                                             _1,
267                                             ::boost::cref( aBounds )));
268             mbIsPlaying = true;
269 
270             return true;
271         }
272 
273 		// ---------------------------------------------------------------------
274 
implEndIntrinsicAnimation()275         bool AppletShape::implEndIntrinsicAnimation()
276         {
277             ::std::for_each( maViewAppletShapes.begin(),
278                              maViewAppletShapes.end(),
279                              ::boost::mem_fn( &ViewAppletShape::endApplet ) );
280 
281             mbIsPlaying = false;
282 
283             return true;
284         }
285 
286 		// ---------------------------------------------------------------------
287 
implPauseIntrinsicAnimation()288         bool AppletShape::implPauseIntrinsicAnimation()
289         {
290             // TODO(F1): any way of temporarily disabling/deactivating
291             // applets?
292             return true;
293         }
294 
295 		// ---------------------------------------------------------------------
296 
implIsIntrinsicAnimationPlaying() const297         bool AppletShape::implIsIntrinsicAnimationPlaying() const
298         {
299             return mbIsPlaying;
300         }
301 
302 		// ---------------------------------------------------------------------
303 
implSetIntrinsicAnimationTime(double)304         void AppletShape::implSetIntrinsicAnimationTime(double)
305         {
306             // No way of doing this, or?
307         }
308 
createAppletShape(const uno::Reference<drawing::XShape> & xShape,double nPrio,const::rtl::OUString & rServiceName,const char ** pPropCopyTable,sal_Size nNumPropEntries,const SlideShowContext & rContext)309         boost::shared_ptr<Shape> createAppletShape(
310             const uno::Reference< drawing::XShape >& xShape,
311             double                                   nPrio,
312             const ::rtl::OUString&                   rServiceName,
313             const char**                             pPropCopyTable,
314             sal_Size                                 nNumPropEntries,
315             const SlideShowContext&                  rContext )
316         {
317             boost::shared_ptr< AppletShape > pAppletShape(
318                 new AppletShape(xShape,
319                                 nPrio,
320                                 rServiceName,
321                                 pPropCopyTable,
322                                 nNumPropEntries,
323                                 rContext) );
324 
325             return pAppletShape;
326         }
327     }
328 }
329