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