fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / shapes / appletshape.cxx
blobc4aa406ab3e13ee47abb29bf0269c03e2e3f7668
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 // must be first
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"
32 #include "tools.hxx"
34 #include <boost/bind.hpp>
35 #include <algorithm>
38 using namespace ::com::sun::star;
41 namespace slideshow
43 namespace internal
45 /** Represents an applet shape.
47 This implementation offers support for applet shapes (both
48 Java applets, and Netscape plugins). Such shapes need
49 special treatment.
51 class AppletShape : public ExternalShapeBase
53 public:
54 /** Create a shape for the given XShape for a applet object
56 @param xShape
57 The XShape to represent.
59 @param nPrio
60 Externally-determined shape priority (used e.g. for
61 paint ordering). This number _must be_ unique!
63 @param rServiceName
64 Service name to use, when creating the actual viewer
65 component
67 @param pPropCopyTable
68 Table of plain ASCII property names, to copy from
69 xShape to applet.
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,
76 double nPrio,
77 const OUString& rServiceName,
78 const char** pPropCopyTable,
79 sal_Size nNumPropEntries,
80 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
82 private:
84 // View layer methods
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;
112 bool mbIsPlaying;
115 AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
116 double nPrio,
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(),
126 mbIsPlaying(false)
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());
142 ++aIter;
148 void AppletShape::implViewsChanged()
150 // resize all ViewShapes
151 ::std::for_each( maViewAppletShapes.begin(),
152 maViewAppletShapes.end(),
153 ::boost::bind(
154 &ViewAppletShape::resize,
156 AppletShape::getBounds()) );
161 void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
162 bool bRedrawLayer )
166 maViewAppletShapes.push_back(
167 ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer,
168 getXShape(),
169 maServiceName,
170 mpPropCopyTable,
171 mnNumPropEntries,
172 mxComponentContext )));
174 // push new size to view shape
175 maViewAppletShapes.back()->resize( getBounds() );
177 // render the Shape on the newly added ViewLayer
178 if( bRedrawLayer )
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(),
195 aEnd,
196 ::boost::bind<bool>(
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(),
205 aEnd,
206 ::boost::bind<bool>(
207 ::std::equal_to< ViewLayerSharedPtr >(),
208 ::boost::bind( &ViewAppletShape::getViewLayer,
209 _1 ),
210 ::boost::cref( rLayer ) ) )) == aEnd )
212 // view layer seemingly was not added, failed
213 return false;
216 // actually erase from container
217 maViewAppletShapes.erase( aIter, aEnd );
219 return true;
224 bool AppletShape::clearAllViewLayers()
226 maViewAppletShapes.clear();
227 return true;
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(),
237 ::boost::bind<bool>(
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
245 return false;
248 return true;
253 bool AppletShape::implStartIntrinsicAnimation()
255 ::std::for_each( maViewAppletShapes.begin(),
256 maViewAppletShapes.end(),
257 ::boost::bind( &ViewAppletShape::startApplet,
259 getBounds()) );
260 mbIsPlaying = true;
262 return true;
267 bool AppletShape::implEndIntrinsicAnimation()
269 ::std::for_each( maViewAppletShapes.begin(),
270 maViewAppletShapes.end(),
271 ::boost::mem_fn( &ViewAppletShape::endApplet ) );
273 mbIsPlaying = false;
275 return true;
280 bool AppletShape::implPauseIntrinsicAnimation()
282 // TODO(F1): any way of temporarily disabling/deactivating
283 // applets?
284 return true;
289 bool AppletShape::implIsIntrinsicAnimationPlaying() const
291 return mbIsPlaying;
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,
303 double nPrio,
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,
311 nPrio,
312 rServiceName,
313 pPropCopyTable,
314 nNumPropEntries,
315 rContext) );
317 return pAppletShape;
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */