1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <canvas/canvastools.hxx>
26 #include <boost/shared_ptr.hpp>
28 #include "appletshape.hxx"
29 #include "externalshapebase.hxx"
30 #include "vieweventhandler.hxx"
31 #include "viewappletshape.hxx"
34 #include <boost/bind.hpp>
38 using namespace ::com::sun::star
;
45 /** Represents an applet shape.
47 This implementation offers support for applet shapes (both
48 Java applets, and Netscape plugins). Such shapes need
51 class AppletShape
: public ExternalShapeBase
54 /** Create a shape for the given XShape for a applet object
57 The XShape to represent.
60 Externally-determined shape priority (used e.g. for
61 paint ordering). This number _must be_ unique!
64 Service name to use, when creating the actual viewer
68 Table of plain ASCII property names, to copy from
71 @param nNumPropEntries
72 Number of property table entries (in pPropCopyTable)
74 AppletShape( const ::com::sun::star::uno::Reference
<
75 ::com::sun::star::drawing::XShape
>& xShape
,
77 const OUString
& rServiceName
,
78 const char** pPropCopyTable
,
79 sal_Size nNumPropEntries
,
80 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
87 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
88 bool bRedrawLayer
) SAL_OVERRIDE
;
89 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
) SAL_OVERRIDE
;
90 virtual bool clearAllViewLayers() SAL_OVERRIDE
;
93 // ExternalShapeBase methods
96 virtual bool implRender( const ::basegfx::B2DRange
& rCurrBounds
) const SAL_OVERRIDE
;
97 virtual void implViewChanged( const UnoViewSharedPtr
& rView
) SAL_OVERRIDE
;
98 virtual void implViewsChanged() SAL_OVERRIDE
;
99 virtual bool implStartIntrinsicAnimation() SAL_OVERRIDE
;
100 virtual bool implEndIntrinsicAnimation() SAL_OVERRIDE
;
101 virtual bool implPauseIntrinsicAnimation() SAL_OVERRIDE
;
102 virtual bool implIsIntrinsicAnimationPlaying() const SAL_OVERRIDE
;
103 virtual void implSetIntrinsicAnimationTime(double) SAL_OVERRIDE
;
105 const OUString maServiceName
;
106 const char** mpPropCopyTable
;
107 const sal_Size mnNumPropEntries
;
109 /// the list of active view shapes (one for each registered view layer)
110 typedef ::std::vector
< ViewAppletShapeSharedPtr
> ViewAppletShapeVector
;
111 ViewAppletShapeVector maViewAppletShapes
;
115 AppletShape::AppletShape( const uno::Reference
< drawing::XShape
>& xShape
,
117 const OUString
& rServiceName
,
118 const char** pPropCopyTable
,
119 sal_Size nNumPropEntries
,
120 const SlideShowContext
& rContext
) :
121 ExternalShapeBase( xShape
, nPrio
, rContext
),
122 maServiceName( rServiceName
),
123 mpPropCopyTable( pPropCopyTable
),
124 mnNumPropEntries( nNumPropEntries
),
125 maViewAppletShapes(),
132 void AppletShape::implViewChanged( const UnoViewSharedPtr
& rView
)
134 // determine ViewAppletShape that needs update
135 ViewAppletShapeVector::const_iterator
aIter(maViewAppletShapes
.begin());
136 ViewAppletShapeVector::const_iterator
const aEnd (maViewAppletShapes
.end());
137 while( aIter
!= aEnd
)
139 if( (*aIter
)->getViewLayer()->isOnView(rView
) )
140 (*aIter
)->resize(getBounds());
148 void AppletShape::implViewsChanged()
150 // resize all ViewShapes
151 ::std::for_each( maViewAppletShapes
.begin(),
152 maViewAppletShapes
.end(),
154 &ViewAppletShape::resize
,
156 AppletShape::getBounds()) );
161 void AppletShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
166 maViewAppletShapes
.push_back(
167 ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer
,
172 mxComponentContext
)));
174 // push new size to view shape
175 maViewAppletShapes
.back()->resize( getBounds() );
177 // render the Shape on the newly added ViewLayer
179 maViewAppletShapes
.back()->render( getBounds() );
181 catch(uno::Exception
&)
183 // ignore failed shapes - slideshow should run with
184 // the remaining content
190 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
192 const ViewAppletShapeVector::iterator
aEnd( maViewAppletShapes
.end() );
194 OSL_ENSURE( ::std::count_if(maViewAppletShapes
.begin(),
197 ::std::equal_to
< ViewLayerSharedPtr
>(),
198 ::boost::bind( &ViewAppletShape::getViewLayer
, _1
),
199 ::boost::cref( rLayer
) ) ) < 2,
200 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
202 ViewAppletShapeVector::iterator aIter
;
204 if( (aIter
=::std::remove_if( maViewAppletShapes
.begin(),
207 ::std::equal_to
< ViewLayerSharedPtr
>(),
208 ::boost::bind( &ViewAppletShape::getViewLayer
,
210 ::boost::cref( rLayer
) ) )) == aEnd
)
212 // view layer seemingly was not added, failed
216 // actually erase from container
217 maViewAppletShapes
.erase( aIter
, aEnd
);
224 bool AppletShape::clearAllViewLayers()
226 maViewAppletShapes
.clear();
232 bool AppletShape::implRender( const ::basegfx::B2DRange
& rCurrBounds
) const
234 // redraw all view shapes, by calling their update() method
235 if( ::std::count_if( maViewAppletShapes
.begin(),
236 maViewAppletShapes
.end(),
238 ::boost::mem_fn( &ViewAppletShape::render
),
240 ::boost::cref( rCurrBounds
) ) )
241 != static_cast<ViewAppletShapeVector::difference_type
>(maViewAppletShapes
.size()) )
243 // at least one of the ViewShape::update() calls did return
244 // false - update failed on at least one ViewLayer
253 bool AppletShape::implStartIntrinsicAnimation()
255 ::std::for_each( maViewAppletShapes
.begin(),
256 maViewAppletShapes
.end(),
257 ::boost::bind( &ViewAppletShape::startApplet
,
267 bool AppletShape::implEndIntrinsicAnimation()
269 ::std::for_each( maViewAppletShapes
.begin(),
270 maViewAppletShapes
.end(),
271 ::boost::mem_fn( &ViewAppletShape::endApplet
) );
280 bool AppletShape::implPauseIntrinsicAnimation()
282 // TODO(F1): any way of temporarily disabling/deactivating
289 bool AppletShape::implIsIntrinsicAnimationPlaying() const
296 void AppletShape::implSetIntrinsicAnimationTime(double)
298 // No way of doing this, or?
301 boost::shared_ptr
<Shape
> createAppletShape(
302 const uno::Reference
< drawing::XShape
>& xShape
,
304 const OUString
& rServiceName
,
305 const char** pPropCopyTable
,
306 sal_Size nNumPropEntries
,
307 const SlideShowContext
& rContext
)
309 boost::shared_ptr
< AppletShape
> pAppletShape(
310 new AppletShape(xShape
,
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */