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