1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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"
47 #include <boost/bind.hpp>
51 using namespace ::com::sun::star
;
58 /** Represents an applet shape.
60 This implementation offers support for applet shapes (both
61 Java applets, and Netscape plugins). Such shapes need
64 class AppletShape
: public ExternalShapeBase
67 /** Create a shape for the given XShape for a applet object
70 The XShape to represent.
73 Externally-determined shape priority (used e.g. for
74 paint ordering). This number _must be_ unique!
77 Service name to use, when creating the actual viewer
81 Table of plain ASCII property names, to copy from
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
,
90 const ::rtl::OUString
& rServiceName
,
91 const char** pPropCopyTable
,
92 sal_Size nNumPropEntries
,
93 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
98 //------------------------------------------------------------------
100 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
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
;
128 AppletShape::AppletShape( const uno::Reference
< drawing::XShape
>& xShape
,
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(),
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());
159 // ---------------------------------------------------------------------
161 void AppletShape::implViewsChanged()
163 // resize all ViewShapes
164 ::std::for_each( maViewAppletShapes
.begin(),
165 maViewAppletShapes
.end(),
167 &ViewAppletShape::resize
,
169 ::boost::cref( AppletShape::getBounds())) );
172 // ---------------------------------------------------------------------
174 void AppletShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
179 maViewAppletShapes
.push_back(
180 ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer
,
185 mxComponentContext
)));
187 // push new size to view shape
188 maViewAppletShapes
.back()->resize( getBounds() );
190 // render the Shape on the newly added ViewLayer
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(),
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(),
220 ::std::equal_to
< ViewLayerSharedPtr
>(),
221 ::boost::bind( &ViewAppletShape::getViewLayer
,
223 ::boost::cref( rLayer
) ) )) == aEnd
)
225 // view layer seemingly was not added, failed
229 // actually erase from container
230 maViewAppletShapes
.erase( aIter
, aEnd
);
235 // ---------------------------------------------------------------------
237 bool AppletShape::clearAllViewLayers()
239 maViewAppletShapes
.clear();
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(),
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
264 // ---------------------------------------------------------------------
266 bool AppletShape::implStartIntrinsicAnimation()
268 ::std::for_each( maViewAppletShapes
.begin(),
269 maViewAppletShapes
.end(),
270 ::boost::bind( &ViewAppletShape::startApplet
,
272 ::boost::cref( getBounds() )));
278 // ---------------------------------------------------------------------
280 bool AppletShape::implEndIntrinsicAnimation()
282 ::std::for_each( maViewAppletShapes
.begin(),
283 maViewAppletShapes
.end(),
284 ::boost::mem_fn( &ViewAppletShape::endApplet
) );
291 // ---------------------------------------------------------------------
293 bool AppletShape::implPauseIntrinsicAnimation()
295 // TODO(F1): any way of temporarily disabling/deactivating
300 // ---------------------------------------------------------------------
302 bool AppletShape::implIsIntrinsicAnimationPlaying() const
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
,
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
,