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 : ::std::for_each( maViewAppletShapes.begin(),
152 : maViewAppletShapes.end(),
153 : ::boost::bind(
154 : &ViewAppletShape::resize,
155 : _1,
156 0 : AppletShape::getBounds()) );
157 0 : }
158 :
159 :
160 :
161 0 : void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
162 : bool bRedrawLayer )
163 : {
164 : try
165 : {
166 : maViewAppletShapes.push_back(
167 : ViewAppletShapeSharedPtr( new ViewAppletShape( rNewLayer,
168 0 : getXShape(),
169 : maServiceName,
170 : mpPropCopyTable,
171 : mnNumPropEntries,
172 0 : mxComponentContext )));
173 :
174 : // push new size to view shape
175 0 : maViewAppletShapes.back()->resize( getBounds() );
176 :
177 : // render the Shape on the newly added ViewLayer
178 0 : if( bRedrawLayer )
179 0 : maViewAppletShapes.back()->render( getBounds() );
180 : }
181 0 : catch(uno::Exception&)
182 : {
183 : // ignore failed shapes - slideshow should run with
184 : // the remaining content
185 : }
186 0 : }
187 :
188 :
189 :
190 0 : bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
191 : {
192 0 : const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
193 :
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!" );
201 :
202 0 : ViewAppletShapeVector::iterator aIter;
203 :
204 0 : 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 0 : ::boost::cref( rLayer ) ) )) == aEnd )
211 : {
212 : // view layer seemingly was not added, failed
213 0 : return false;
214 : }
215 :
216 : // actually erase from container
217 0 : maViewAppletShapes.erase( aIter, aEnd );
218 :
219 0 : return true;
220 : }
221 :
222 :
223 :
224 0 : bool AppletShape::clearAllViewLayers()
225 : {
226 0 : maViewAppletShapes.clear();
227 0 : return true;
228 : }
229 :
230 :
231 :
232 0 : bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
233 : {
234 : // redraw all view shapes, by calling their update() method
235 0 : if( ::std::count_if( maViewAppletShapes.begin(),
236 : maViewAppletShapes.end(),
237 : ::boost::bind<bool>(
238 : ::boost::mem_fn( &ViewAppletShape::render ),
239 : _1,
240 0 : ::boost::cref( rCurrBounds ) ) )
241 0 : != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
242 : {
243 : // at least one of the ViewShape::update() calls did return
244 : // false - update failed on at least one ViewLayer
245 0 : return false;
246 : }
247 :
248 0 : return true;
249 : }
250 :
251 :
252 :
253 0 : bool AppletShape::implStartIntrinsicAnimation()
254 : {
255 : ::std::for_each( maViewAppletShapes.begin(),
256 : maViewAppletShapes.end(),
257 : ::boost::bind( &ViewAppletShape::startApplet,
258 : _1,
259 0 : getBounds()) );
260 0 : mbIsPlaying = true;
261 :
262 0 : return true;
263 : }
264 :
265 :
266 :
267 0 : bool AppletShape::implEndIntrinsicAnimation()
268 : {
269 : ::std::for_each( maViewAppletShapes.begin(),
270 : maViewAppletShapes.end(),
271 0 : ::boost::mem_fn( &ViewAppletShape::endApplet ) );
272 :
273 0 : mbIsPlaying = false;
274 :
275 0 : return true;
276 : }
277 :
278 :
279 :
280 0 : bool AppletShape::implPauseIntrinsicAnimation()
281 : {
282 : // TODO(F1): any way of temporarily disabling/deactivating
283 : // applets?
284 0 : return true;
285 : }
286 :
287 :
288 :
289 0 : bool AppletShape::implIsIntrinsicAnimationPlaying() const
290 : {
291 0 : return mbIsPlaying;
292 : }
293 :
294 :
295 :
296 0 : void AppletShape::implSetIntrinsicAnimationTime(double)
297 : {
298 : // No way of doing this, or?
299 0 : }
300 :
301 0 : 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 )
308 : {
309 : boost::shared_ptr< AppletShape > pAppletShape(
310 : new AppletShape(xShape,
311 : nPrio,
312 : rServiceName,
313 : pPropCopyTable,
314 : nNumPropEntries,
315 0 : rContext) );
316 :
317 0 : return pAppletShape;
318 : }
319 : }
320 3 : }
321 :
322 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|