Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : // must be first
22 : #include <canvas/debug.hxx>
23 : #include <canvas/verbosetrace.hxx>
24 : #include <canvas/canvastools.hxx>
25 :
26 : #include <boost/shared_ptr.hpp>
27 :
28 : #include "appletshape.hxx"
29 : #include "externalshapebase.hxx"
30 : #include "vieweventhandler.hxx"
31 : #include "viewappletshape.hxx"
32 : #include "tools.hxx"
33 :
34 : #include <boost/bind.hpp>
35 : #include <algorithm>
36 :
37 :
38 : using namespace ::com::sun::star;
39 :
40 :
41 : namespace slideshow
42 : {
43 : namespace internal
44 : {
45 : /** Represents an applet shape.
46 :
47 : This implementation offers support for applet shapes (both
48 : Java applets, and Netscape plugins). Such shapes need
49 : special treatment.
50 : */
51 0 : class AppletShape : public ExternalShapeBase
52 : {
53 : public:
54 : /** Create a shape for the given XShape for a applet object
55 :
56 : @param xShape
57 : The XShape to represent.
58 :
59 : @param nPrio
60 : Externally-determined shape priority (used e.g. for
61 : paint ordering). This number _must be_ unique!
62 :
63 : @param rServiceName
64 : Service name to use, when creating the actual viewer
65 : component
66 :
67 : @param pPropCopyTable
68 : Table of plain ASCII property names, to copy from
69 : xShape to applet.
70 :
71 : @param nNumPropEntries
72 : Number of property table entries (in pPropCopyTable)
73 : */
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;
81 :
82 : private:
83 :
84 : // View layer methods
85 :
86 :
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;
91 :
92 :
93 : // ExternalShapeBase methods
94 :
95 :
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;
104 :
105 : const OUString maServiceName;
106 : const char** mpPropCopyTable;
107 : const sal_Size mnNumPropEntries;
108 :
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;
113 : };
114 :
115 0 : 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 0 : mbIsPlaying(false)
127 : {
128 0 : }
129 :
130 :
131 :
132 0 : void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
133 : {
134 : // determine ViewAppletShape that needs update
135 0 : ViewAppletShapeVector::const_iterator aIter(maViewAppletShapes.begin());
136 0 : ViewAppletShapeVector::const_iterator const aEnd (maViewAppletShapes.end());
137 0 : while( aIter != aEnd )
138 : {
139 0 : if( (*aIter)->getViewLayer()->isOnView(rView) )
140 0 : (*aIter)->resize(getBounds());
141 :
142 0 : ++aIter;
143 : }
144 0 : }
145 :
146 :
147 :
148 0 : void AppletShape::implViewsChanged()
149 : {
150 : // resize all ViewShapes
151 0 : ::basegfx::B2DRectangle bounds( AppletShape::getBounds() );
152 : ::std::for_each( maViewAppletShapes.begin(),
153 : maViewAppletShapes.end(),
154 : ::boost::bind(
155 : &ViewAppletShape::resize,
156 : _1,
157 0 : ::boost::cref( bounds )) );
158 0 : }
159 :
160 :
161 :
162 0 : void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
163 : bool bRedrawLayer )
164 : {
165 : try
166 : {
167 : maViewAppletShapes.push_back(
168 : ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer,
169 0 : getXShape(),
170 : maServiceName,
171 : mpPropCopyTable,
172 : mnNumPropEntries,
173 0 : mxComponentContext )));
174 :
175 : // push new size to view shape
176 0 : maViewAppletShapes.back()->resize( getBounds() );
177 :
178 : // render the Shape on the newly added ViewLayer
179 0 : if( bRedrawLayer )
180 0 : maViewAppletShapes.back()->render( getBounds() );
181 : }
182 0 : catch(uno::Exception&)
183 : {
184 : // ignore failed shapes - slideshow should run with
185 : // the remaining content
186 : }
187 0 : }
188 :
189 :
190 :
191 0 : bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
192 : {
193 0 : const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
194 :
195 : OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
196 : aEnd,
197 : ::boost::bind<bool>(
198 : ::std::equal_to< ViewLayerSharedPtr >(),
199 : ::boost::bind( &ViewAppletShape::getViewLayer, _1 ),
200 : ::boost::cref( rLayer ) ) ) < 2,
201 : "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
202 :
203 0 : ViewAppletShapeVector::iterator aIter;
204 :
205 0 : if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
206 : aEnd,
207 : ::boost::bind<bool>(
208 : ::std::equal_to< ViewLayerSharedPtr >(),
209 : ::boost::bind( &ViewAppletShape::getViewLayer,
210 : _1 ),
211 0 : ::boost::cref( rLayer ) ) )) == aEnd )
212 : {
213 : // view layer seemingly was not added, failed
214 0 : return false;
215 : }
216 :
217 : // actually erase from container
218 0 : maViewAppletShapes.erase( aIter, aEnd );
219 :
220 0 : return true;
221 : }
222 :
223 :
224 :
225 0 : bool AppletShape::clearAllViewLayers()
226 : {
227 0 : maViewAppletShapes.clear();
228 0 : return true;
229 : }
230 :
231 :
232 :
233 0 : bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
234 : {
235 : // redraw all view shapes, by calling their update() method
236 0 : if( ::std::count_if( maViewAppletShapes.begin(),
237 : maViewAppletShapes.end(),
238 : ::boost::bind<bool>(
239 : ::boost::mem_fn( &ViewAppletShape::render ),
240 : _1,
241 0 : ::boost::cref( rCurrBounds ) ) )
242 0 : != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
243 : {
244 : // at least one of the ViewShape::update() calls did return
245 : // false - update failed on at least one ViewLayer
246 0 : return false;
247 : }
248 :
249 0 : return true;
250 : }
251 :
252 :
253 :
254 0 : bool AppletShape::implStartIntrinsicAnimation()
255 : {
256 0 : ::basegfx::B2DRectangle bounds( getBounds() );
257 : ::std::for_each( maViewAppletShapes.begin(),
258 : maViewAppletShapes.end(),
259 : ::boost::bind( &ViewAppletShape::startApplet,
260 : _1,
261 0 : ::boost::cref( bounds )));
262 0 : mbIsPlaying = true;
263 :
264 0 : return true;
265 : }
266 :
267 :
268 :
269 0 : bool AppletShape::implEndIntrinsicAnimation()
270 : {
271 : ::std::for_each( maViewAppletShapes.begin(),
272 : maViewAppletShapes.end(),
273 0 : ::boost::mem_fn( &ViewAppletShape::endApplet ) );
274 :
275 0 : mbIsPlaying = false;
276 :
277 0 : return true;
278 : }
279 :
280 :
281 :
282 0 : bool AppletShape::implPauseIntrinsicAnimation()
283 : {
284 : // TODO(F1): any way of temporarily disabling/deactivating
285 : // applets?
286 0 : return true;
287 : }
288 :
289 :
290 :
291 0 : bool AppletShape::implIsIntrinsicAnimationPlaying() const
292 : {
293 0 : return mbIsPlaying;
294 : }
295 :
296 :
297 :
298 0 : void AppletShape::implSetIntrinsicAnimationTime(double)
299 : {
300 : // No way of doing this, or?
301 0 : }
302 :
303 0 : boost::shared_ptr<Shape> createAppletShape(
304 : const uno::Reference< drawing::XShape >& xShape,
305 : double nPrio,
306 : const OUString& rServiceName,
307 : const char** pPropCopyTable,
308 : sal_Size nNumPropEntries,
309 : const SlideShowContext& rContext )
310 : {
311 : boost::shared_ptr< AppletShape > pAppletShape(
312 : new AppletShape(xShape,
313 : nPrio,
314 : rServiceName,
315 : pPropCopyTable,
316 : nNumPropEntries,
317 0 : rContext) );
318 :
319 0 : return pAppletShape;
320 : }
321 : }
322 6 : }
323 :
324 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|