xref: /trunk/main/slideshow/source/engine/shapes/appletshape.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
170f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
370f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
470f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
570f497fbSAndrew Rist  * distributed with this work for additional information
670f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
770f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
870f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
970f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1170f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1370f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1470f497fbSAndrew Rist  * software distributed under the License is distributed on an
1570f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1670f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
1770f497fbSAndrew Rist  * specific language governing permissions and limitations
1870f497fbSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2070f497fbSAndrew Rist  *************************************************************/
2170f497fbSAndrew Rist 
2270f497fbSAndrew 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
157*a72d41dcSDamjan Jovanovic             ::basegfx::B2DRectangle aBounds = AppletShape::getBounds();
158cdf0e10cSrcweir             ::std::for_each( maViewAppletShapes.begin(),
159cdf0e10cSrcweir                              maViewAppletShapes.end(),
160cdf0e10cSrcweir                              ::boost::bind(
161cdf0e10cSrcweir                                  &ViewAppletShape::resize,
162cdf0e10cSrcweir                                  _1,
163*a72d41dcSDamjan Jovanovic                                  ::boost::cref( aBounds ) ) );
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         // ---------------------------------------------------------------------
167cdf0e10cSrcweir 
addViewLayer(const ViewLayerSharedPtr & rNewLayer,bool bRedrawLayer)168cdf0e10cSrcweir         void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
169cdf0e10cSrcweir                                         bool                      bRedrawLayer )
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir             try
172cdf0e10cSrcweir             {
173cdf0e10cSrcweir                 maViewAppletShapes.push_back(
174cdf0e10cSrcweir                     ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer,
175cdf0e10cSrcweir                                                                    getXShape(),
176cdf0e10cSrcweir                                                                    maServiceName,
177cdf0e10cSrcweir                                                                    mpPropCopyTable,
178cdf0e10cSrcweir                                                                    mnNumPropEntries,
179cdf0e10cSrcweir                                                                    mxComponentContext )));
180cdf0e10cSrcweir 
181cdf0e10cSrcweir                 // push new size to view shape
182cdf0e10cSrcweir                 maViewAppletShapes.back()->resize( getBounds() );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir                 // render the Shape on the newly added ViewLayer
185cdf0e10cSrcweir                 if( bRedrawLayer )
186cdf0e10cSrcweir                     maViewAppletShapes.back()->render( getBounds() );
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir             catch(uno::Exception&)
189cdf0e10cSrcweir             {
190cdf0e10cSrcweir                 // ignore failed shapes - slideshow should run with
191cdf0e10cSrcweir                 // the remaining content
192cdf0e10cSrcweir             }
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         // ---------------------------------------------------------------------
196cdf0e10cSrcweir 
removeViewLayer(const ViewLayerSharedPtr & rLayer)197cdf0e10cSrcweir         bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir             const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir             OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
202cdf0e10cSrcweir                                         aEnd,
203cdf0e10cSrcweir                                         ::boost::bind<bool>(
204cdf0e10cSrcweir                                             ::std::equal_to< ViewLayerSharedPtr >(),
205cdf0e10cSrcweir                                             ::boost::bind( &ViewAppletShape::getViewLayer, _1 ),
206cdf0e10cSrcweir                                             ::boost::cref( rLayer ) ) ) < 2,
207cdf0e10cSrcweir                         "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
208cdf0e10cSrcweir 
209cdf0e10cSrcweir             ViewAppletShapeVector::iterator aIter;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir             if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
212cdf0e10cSrcweir                                          aEnd,
213cdf0e10cSrcweir                                          ::boost::bind<bool>(
214cdf0e10cSrcweir                                              ::std::equal_to< ViewLayerSharedPtr >(),
215cdf0e10cSrcweir                                              ::boost::bind( &ViewAppletShape::getViewLayer,
216cdf0e10cSrcweir                                                             _1 ),
217cdf0e10cSrcweir                                              ::boost::cref( rLayer ) ) )) == aEnd )
218cdf0e10cSrcweir             {
219cdf0e10cSrcweir                 // view layer seemingly was not added, failed
220cdf0e10cSrcweir                 return false;
221cdf0e10cSrcweir             }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir             // actually erase from container
224cdf0e10cSrcweir             maViewAppletShapes.erase( aIter, aEnd );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir             return true;
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         // ---------------------------------------------------------------------
230cdf0e10cSrcweir 
clearAllViewLayers()231cdf0e10cSrcweir         bool AppletShape::clearAllViewLayers()
232cdf0e10cSrcweir         {
233cdf0e10cSrcweir             maViewAppletShapes.clear();
234cdf0e10cSrcweir             return true;
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         // ---------------------------------------------------------------------
238cdf0e10cSrcweir 
implRender(const::basegfx::B2DRange & rCurrBounds) const239cdf0e10cSrcweir         bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
240cdf0e10cSrcweir         {
241cdf0e10cSrcweir             // redraw all view shapes, by calling their update() method
242cdf0e10cSrcweir             if( ::std::count_if( maViewAppletShapes.begin(),
243cdf0e10cSrcweir                                  maViewAppletShapes.end(),
244cdf0e10cSrcweir                                  ::boost::bind<bool>(
245cdf0e10cSrcweir                                      ::boost::mem_fn( &ViewAppletShape::render ),
246cdf0e10cSrcweir                                      _1,
247cdf0e10cSrcweir                                      ::boost::cref( rCurrBounds ) ) )
248cdf0e10cSrcweir                 != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
249cdf0e10cSrcweir             {
250cdf0e10cSrcweir                 // at least one of the ViewShape::update() calls did return
251cdf0e10cSrcweir                 // false - update failed on at least one ViewLayer
252cdf0e10cSrcweir                 return false;
253cdf0e10cSrcweir             }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir             return true;
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         // ---------------------------------------------------------------------
259cdf0e10cSrcweir 
implStartIntrinsicAnimation()260cdf0e10cSrcweir         bool AppletShape::implStartIntrinsicAnimation()
261cdf0e10cSrcweir         {
262*a72d41dcSDamjan Jovanovic             ::basegfx::B2DRectangle aBounds = getBounds();
263cdf0e10cSrcweir             ::std::for_each( maViewAppletShapes.begin(),
264cdf0e10cSrcweir                              maViewAppletShapes.end(),
265cdf0e10cSrcweir                              ::boost::bind( &ViewAppletShape::startApplet,
266cdf0e10cSrcweir                                             _1,
267*a72d41dcSDamjan Jovanovic                                             ::boost::cref( aBounds )));
268cdf0e10cSrcweir             mbIsPlaying = true;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir             return true;
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         // ---------------------------------------------------------------------
274cdf0e10cSrcweir 
implEndIntrinsicAnimation()275cdf0e10cSrcweir         bool AppletShape::implEndIntrinsicAnimation()
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir             ::std::for_each( maViewAppletShapes.begin(),
278cdf0e10cSrcweir                              maViewAppletShapes.end(),
279cdf0e10cSrcweir                              ::boost::mem_fn( &ViewAppletShape::endApplet ) );
280cdf0e10cSrcweir 
281cdf0e10cSrcweir             mbIsPlaying = false;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir             return true;
284cdf0e10cSrcweir         }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         // ---------------------------------------------------------------------
287cdf0e10cSrcweir 
implPauseIntrinsicAnimation()288cdf0e10cSrcweir         bool AppletShape::implPauseIntrinsicAnimation()
289cdf0e10cSrcweir         {
290cdf0e10cSrcweir             // TODO(F1): any way of temporarily disabling/deactivating
291cdf0e10cSrcweir             // applets?
292cdf0e10cSrcweir             return true;
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir         // ---------------------------------------------------------------------
296cdf0e10cSrcweir 
implIsIntrinsicAnimationPlaying() const297cdf0e10cSrcweir         bool AppletShape::implIsIntrinsicAnimationPlaying() const
298cdf0e10cSrcweir         {
299cdf0e10cSrcweir             return mbIsPlaying;
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         // ---------------------------------------------------------------------
303cdf0e10cSrcweir 
implSetIntrinsicAnimationTime(double)304cdf0e10cSrcweir         void AppletShape::implSetIntrinsicAnimationTime(double)
305cdf0e10cSrcweir         {
306cdf0e10cSrcweir             // No way of doing this, or?
307cdf0e10cSrcweir         }
308cdf0e10cSrcweir 
createAppletShape(const uno::Reference<drawing::XShape> & xShape,double nPrio,const::rtl::OUString & rServiceName,const char ** pPropCopyTable,sal_Size nNumPropEntries,const SlideShowContext & rContext)309cdf0e10cSrcweir         boost::shared_ptr<Shape> createAppletShape(
310cdf0e10cSrcweir             const uno::Reference< drawing::XShape >& xShape,
311cdf0e10cSrcweir             double                                   nPrio,
312cdf0e10cSrcweir             const ::rtl::OUString&                   rServiceName,
313cdf0e10cSrcweir             const char**                             pPropCopyTable,
314cdf0e10cSrcweir             sal_Size                                 nNumPropEntries,
315cdf0e10cSrcweir             const SlideShowContext&                  rContext )
316cdf0e10cSrcweir         {
317cdf0e10cSrcweir             boost::shared_ptr< AppletShape > pAppletShape(
318cdf0e10cSrcweir                 new AppletShape(xShape,
319cdf0e10cSrcweir                                 nPrio,
320cdf0e10cSrcweir                                 rServiceName,
321cdf0e10cSrcweir                                 pPropCopyTable,
322cdf0e10cSrcweir                                 nNumPropEntries,
323cdf0e10cSrcweir                                 rContext) );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir             return pAppletShape;
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir }
329