Update ooo320-m1
[ooovba.git] / slideshow / source / engine / shapes / appletshape.cxx
blobfb85d3a42abcf8de0090f2befef33c94212c2bbc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appletshape.cxx,v $
10 * $Revision: 1.3.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
37 #include <canvas/canvastools.hxx>
39 #include <boost/shared_ptr.hpp>
41 #include "appletshape.hxx"
42 #include "externalshapebase.hxx"
43 #include "vieweventhandler.hxx"
44 #include "viewappletshape.hxx"
45 #include "tools.hxx"
47 #include <boost/bind.hpp>
48 #include <algorithm>
51 using namespace ::com::sun::star;
54 namespace slideshow
56 namespace internal
58 /** Represents an applet shape.
60 This implementation offers support for applet shapes (both
61 Java applets, and Netscape plugins). Such shapes need
62 special treatment.
64 class AppletShape : public ExternalShapeBase
66 public:
67 /** Create a shape for the given XShape for a applet object
69 @param xShape
70 The XShape to represent.
72 @param nPrio
73 Externally-determined shape priority (used e.g. for
74 paint ordering). This number _must be_ unique!
76 @param rServiceName
77 Service name to use, when creating the actual viewer
78 component
80 @param pPropCopyTable
81 Table of plain ASCII property names, to copy from
82 xShape to applet.
84 @param nNumPropEntries
85 Number of property table entries (in pPropCopyTable)
87 AppletShape( const ::com::sun::star::uno::Reference<
88 ::com::sun::star::drawing::XShape >& xShape,
89 double nPrio,
90 const ::rtl::OUString& rServiceName,
91 const char** pPropCopyTable,
92 sal_Size nNumPropEntries,
93 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
95 private:
97 // View layer methods
98 //------------------------------------------------------------------
100 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
101 bool bRedrawLayer );
102 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer );
103 virtual bool clearAllViewLayers();
106 // ExternalShapeBase methods
107 //------------------------------------------------------------------
109 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const;
110 virtual void implViewChanged( const UnoViewSharedPtr& rView );
111 virtual void implViewsChanged();
112 virtual bool implStartIntrinsicAnimation();
113 virtual bool implEndIntrinsicAnimation();
114 virtual bool implPauseIntrinsicAnimation();
115 virtual bool implIsIntrinsicAnimationPlaying() const;
116 virtual void implSetIntrinsicAnimationTime(double);
118 const ::rtl::OUString maServiceName;
119 const char** mpPropCopyTable;
120 const sal_Size mnNumPropEntries;
122 /// the list of active view shapes (one for each registered view layer)
123 typedef ::std::vector< ViewAppletShapeSharedPtr > ViewAppletShapeVector;
124 ViewAppletShapeVector maViewAppletShapes;
125 bool mbIsPlaying;
128 AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
129 double nPrio,
130 const ::rtl::OUString& rServiceName,
131 const char** pPropCopyTable,
132 sal_Size nNumPropEntries,
133 const SlideShowContext& rContext ) :
134 ExternalShapeBase( xShape, nPrio, rContext ),
135 maServiceName( rServiceName ),
136 mpPropCopyTable( pPropCopyTable ),
137 mnNumPropEntries( nNumPropEntries ),
138 maViewAppletShapes(),
139 mbIsPlaying(false)
143 // ---------------------------------------------------------------------
145 void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
147 // determine ViewAppletShape that needs update
148 ViewAppletShapeVector::const_iterator aIter(maViewAppletShapes.begin());
149 ViewAppletShapeVector::const_iterator const aEnd (maViewAppletShapes.end());
150 while( aIter != aEnd )
152 if( (*aIter)->getViewLayer()->isOnView(rView) )
153 (*aIter)->resize(getBounds());
155 ++aIter;
159 // ---------------------------------------------------------------------
161 void AppletShape::implViewsChanged()
163 // resize all ViewShapes
164 ::std::for_each( maViewAppletShapes.begin(),
165 maViewAppletShapes.end(),
166 ::boost::bind(
167 &ViewAppletShape::resize,
169 ::boost::cref( AppletShape::getBounds())) );
172 // ---------------------------------------------------------------------
174 void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
175 bool bRedrawLayer )
179 maViewAppletShapes.push_back(
180 ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer,
181 getXShape(),
182 maServiceName,
183 mpPropCopyTable,
184 mnNumPropEntries,
185 mxComponentContext )));
187 // push new size to view shape
188 maViewAppletShapes.back()->resize( getBounds() );
190 // render the Shape on the newly added ViewLayer
191 if( bRedrawLayer )
192 maViewAppletShapes.back()->render( getBounds() );
194 catch(uno::Exception&)
196 // ignore failed shapes - slideshow should run with
197 // the remaining content
201 // ---------------------------------------------------------------------
203 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
205 const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
207 OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
208 aEnd,
209 ::boost::bind<bool>(
210 ::std::equal_to< ViewLayerSharedPtr >(),
211 ::boost::bind( &ViewAppletShape::getViewLayer, _1 ),
212 ::boost::cref( rLayer ) ) ) < 2,
213 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
215 ViewAppletShapeVector::iterator aIter;
217 if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
218 aEnd,
219 ::boost::bind<bool>(
220 ::std::equal_to< ViewLayerSharedPtr >(),
221 ::boost::bind( &ViewAppletShape::getViewLayer,
222 _1 ),
223 ::boost::cref( rLayer ) ) )) == aEnd )
225 // view layer seemingly was not added, failed
226 return false;
229 // actually erase from container
230 maViewAppletShapes.erase( aIter, aEnd );
232 return true;
235 // ---------------------------------------------------------------------
237 bool AppletShape::clearAllViewLayers()
239 maViewAppletShapes.clear();
240 return true;
243 // ---------------------------------------------------------------------
245 bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
247 // redraw all view shapes, by calling their update() method
248 if( ::std::count_if( maViewAppletShapes.begin(),
249 maViewAppletShapes.end(),
250 ::boost::bind<bool>(
251 ::boost::mem_fn( &ViewAppletShape::render ),
253 ::boost::cref( rCurrBounds ) ) )
254 != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
256 // at least one of the ViewShape::update() calls did return
257 // false - update failed on at least one ViewLayer
258 return false;
261 return true;
264 // ---------------------------------------------------------------------
266 bool AppletShape::implStartIntrinsicAnimation()
268 ::std::for_each( maViewAppletShapes.begin(),
269 maViewAppletShapes.end(),
270 ::boost::bind( &ViewAppletShape::startApplet,
272 ::boost::cref( getBounds() )));
273 mbIsPlaying = true;
275 return true;
278 // ---------------------------------------------------------------------
280 bool AppletShape::implEndIntrinsicAnimation()
282 ::std::for_each( maViewAppletShapes.begin(),
283 maViewAppletShapes.end(),
284 ::boost::mem_fn( &ViewAppletShape::endApplet ) );
286 mbIsPlaying = false;
288 return true;
291 // ---------------------------------------------------------------------
293 bool AppletShape::implPauseIntrinsicAnimation()
295 // TODO(F1): any way of temporarily disabling/deactivating
296 // applets?
297 return true;
300 // ---------------------------------------------------------------------
302 bool AppletShape::implIsIntrinsicAnimationPlaying() const
304 return mbIsPlaying;
307 // ---------------------------------------------------------------------
309 void AppletShape::implSetIntrinsicAnimationTime(double)
311 // No way of doing this, or?
314 boost::shared_ptr<Shape> createAppletShape(
315 const uno::Reference< drawing::XShape >& xShape,
316 double nPrio,
317 const ::rtl::OUString& rServiceName,
318 const char** pPropCopyTable,
319 sal_Size nNumPropEntries,
320 const SlideShowContext& rContext )
322 boost::shared_ptr< AppletShape > pAppletShape(
323 new AppletShape(xShape,
324 nPrio,
325 rServiceName,
326 pPropCopyTable,
327 nNumPropEntries,
328 rContext) );
330 return pAppletShape;