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 .
21 #include <canvas/canvastools.hxx>
23 #include "appletshape.hxx"
24 #include "externalshapebase.hxx"
25 #include <vieweventhandler.hxx>
26 #include "viewappletshape.hxx"
32 using namespace ::com::sun::star
;
39 /** Represents an applet shape.
41 This implementation offers support for applet shapes (both
42 Java applets, and Netscape plugins). Such shapes need
45 class AppletShape
: public ExternalShapeBase
48 /** Create a shape for the given XShape for a applet object
51 The XShape to represent.
54 Externally-determined shape priority (used e.g. for
55 paint ordering). This number _must be_ unique!
58 Service name to use, when creating the actual viewer
62 Table of plain ASCII property names, to copy from
65 @param nNumPropEntries
66 Number of property table entries (in pPropCopyTable)
68 AppletShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
,
70 const OUString
& rServiceName
,
71 const char** pPropCopyTable
,
72 std::size_t nNumPropEntries
,
73 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
80 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
81 bool bRedrawLayer
) override
;
82 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
) override
;
83 virtual void clearAllViewLayers() override
;
86 // ExternalShapeBase methods
89 virtual bool implRender( const ::basegfx::B2DRange
& rCurrBounds
) const override
;
90 virtual void implViewChanged( const UnoViewSharedPtr
& rView
) override
;
91 virtual void implViewsChanged() override
;
92 virtual bool implStartIntrinsicAnimation() override
;
93 virtual bool implEndIntrinsicAnimation() override
;
94 virtual void implPauseIntrinsicAnimation() override
;
95 virtual bool implIsIntrinsicAnimationPlaying() const override
;
96 virtual void implSetIntrinsicAnimationTime(double) override
;
98 const OUString maServiceName
;
99 const char** mpPropCopyTable
;
100 const std::size_t mnNumPropEntries
;
102 /// the list of active view shapes (one for each registered view layer)
103 typedef ::std::vector
< ViewAppletShapeSharedPtr
> ViewAppletShapeVector
;
104 ViewAppletShapeVector maViewAppletShapes
;
108 AppletShape::AppletShape( const uno::Reference
< drawing::XShape
>& xShape
,
110 const OUString
& rServiceName
,
111 const char** pPropCopyTable
,
112 std::size_t nNumPropEntries
,
113 const SlideShowContext
& rContext
) :
114 ExternalShapeBase( xShape
, nPrio
, rContext
),
115 maServiceName( rServiceName
),
116 mpPropCopyTable( pPropCopyTable
),
117 mnNumPropEntries( nNumPropEntries
),
118 maViewAppletShapes(),
124 void AppletShape::implViewChanged( const UnoViewSharedPtr
& rView
)
126 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
127 // determine ViewAppletShape that needs update
128 for( const auto& pViewAppletShape
: maViewAppletShapes
)
130 if( pViewAppletShape
->getViewLayer()->isOnView( rView
) )
131 pViewAppletShape
->resize( rBounds
);
136 void AppletShape::implViewsChanged()
138 // resize all ViewShapes
139 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
140 for( const auto& pViewAppletShape
: maViewAppletShapes
)
141 pViewAppletShape
->resize( rBounds
);
145 void AppletShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
150 maViewAppletShapes
.push_back(
151 std::make_shared
<ViewAppletShape
>( rNewLayer
,
156 mxComponentContext
));
158 // push new size to view shape
159 maViewAppletShapes
.back()->resize( getBounds() );
161 // render the Shape on the newly added ViewLayer
163 maViewAppletShapes
.back()->render( getBounds() );
165 catch(uno::Exception
&)
167 // ignore failed shapes - slideshow should run with
168 // the remaining content
173 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
175 const ViewAppletShapeVector::iterator
aEnd( maViewAppletShapes
.end() );
177 OSL_ENSURE( ::std::count_if(maViewAppletShapes
.begin(),
180 ( const ViewAppletShapeSharedPtr
& pShape
)
181 { return rLayer
== pShape
->getViewLayer(); } ) < 2,
182 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
184 ViewAppletShapeVector::iterator aIter
;
186 if( (aIter
=::std::remove_if( maViewAppletShapes
.begin(),
189 ( const ViewAppletShapeSharedPtr
& pShape
)
190 { return rLayer
== pShape
->getViewLayer(); } ) ) == aEnd
)
192 // view layer seemingly was not added, failed
196 // actually erase from container
197 maViewAppletShapes
.erase( aIter
, aEnd
);
203 void AppletShape::clearAllViewLayers()
205 maViewAppletShapes
.clear();
209 bool AppletShape::implRender( const ::basegfx::B2DRange
& rCurrBounds
) const
211 // redraw all view shapes, by calling their update() method
212 if( ::std::count_if( maViewAppletShapes
.begin(),
213 maViewAppletShapes
.end(),
215 ( const ViewAppletShapeSharedPtr
& pShape
)
216 { return pShape
->render( rCurrBounds
); } )
217 != static_cast<ViewAppletShapeVector::difference_type
>(maViewAppletShapes
.size()) )
219 // at least one of the ViewShape::update() calls did return
220 // false - update failed on at least one ViewLayer
228 bool AppletShape::implStartIntrinsicAnimation()
230 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
231 for( const auto& pViewAppletShape
: maViewAppletShapes
)
232 pViewAppletShape
->startApplet( rBounds
);
240 bool AppletShape::implEndIntrinsicAnimation()
242 for( const auto& pViewAppletShape
: maViewAppletShapes
)
243 pViewAppletShape
->endApplet();
251 void AppletShape::implPauseIntrinsicAnimation()
253 // TODO(F1): any way of temporarily disabling/deactivating
258 bool AppletShape::implIsIntrinsicAnimationPlaying() const
264 void AppletShape::implSetIntrinsicAnimationTime(double)
266 // No way of doing this, or?
269 std::shared_ptr
<Shape
> createAppletShape(
270 const uno::Reference
< drawing::XShape
>& xShape
,
272 const OUString
& rServiceName
,
273 const char** pPropCopyTable
,
274 std::size_t nNumPropEntries
,
275 const SlideShowContext
& rContext
)
277 std::shared_ptr
< AppletShape
> pAppletShape(
278 new AppletShape(xShape
,
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */