LibreOffice Module slideshow (master) 1
appletshape.cxx
Go to the documentation of this file.
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#include "appletshape.hxx"
22#include "externalshapebase.hxx"
23#include "viewappletshape.hxx"
24#include <tools.hxx>
25
26#include <o3tl/safeint.hxx>
27#include <osl/diagnose.h>
28
29#include <algorithm>
30#include <utility>
31
32
33using namespace ::com::sun::star;
34
35
36namespace slideshow::internal
37{
38 namespace {
39
46 class AppletShape : public ExternalShapeBase
47 {
48 public:
69 AppletShape( const css::uno::Reference< css::drawing::XShape >& xShape,
70 double nPrio,
71 OUString aServiceName,
72 const char** pPropCopyTable,
73 std::size_t nNumPropEntries,
74 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
75
76 private:
77
78 // View layer methods
79
80
81 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
82 bool bRedrawLayer ) override;
83 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) override;
84 virtual void clearAllViewLayers() override;
85
86
87 // ExternalShapeBase methods
88
89
90 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const override;
91 virtual void implViewChanged( const UnoViewSharedPtr& rView ) override;
92 virtual void implViewsChanged() override;
93 virtual bool implStartIntrinsicAnimation() override;
94 virtual bool implEndIntrinsicAnimation() override;
95 virtual void implPauseIntrinsicAnimation() override;
96 virtual bool implIsIntrinsicAnimationPlaying() const override;
97 virtual void implSetIntrinsicAnimationTime(double) override;
98
99 const OUString maServiceName;
100 const char** mpPropCopyTable;
101 const std::size_t mnNumPropEntries;
102
104 typedef ::std::vector< ViewAppletShapeSharedPtr > ViewAppletShapeVector;
105 ViewAppletShapeVector maViewAppletShapes;
107 };
108
109 }
110
111 AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
112 double nPrio,
113 OUString aServiceName,
114 const char** pPropCopyTable,
115 std::size_t nNumPropEntries,
116 const SlideShowContext& rContext ) :
117 ExternalShapeBase( xShape, nPrio, rContext ),
118 maServiceName(std::move( aServiceName )),
119 mpPropCopyTable( pPropCopyTable ),
120 mnNumPropEntries( nNumPropEntries ),
122 mbIsPlaying(false)
123 {
124 }
125
126
127 void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
128 {
129 const ::basegfx::B2DRectangle& rBounds = getBounds();
130 // determine ViewAppletShape that needs update
131 for( const auto& pViewAppletShape : maViewAppletShapes )
132 {
133 if( pViewAppletShape->getViewLayer()->isOnView( rView ) )
134 pViewAppletShape->resize( rBounds );
135 }
136 }
137
138
139 void AppletShape::implViewsChanged()
140 {
141 // resize all ViewShapes
142 const ::basegfx::B2DRectangle& rBounds = getBounds();
143 for( const auto& pViewAppletShape : maViewAppletShapes )
144 pViewAppletShape->resize( rBounds );
145 }
146
147
148 void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
149 bool bRedrawLayer )
150 {
151 try
152 {
153 maViewAppletShapes.push_back(
154 std::make_shared<ViewAppletShape>( rNewLayer,
155 getXShape(),
159 mxComponentContext ));
160
161 // push new size to view shape
162 maViewAppletShapes.back()->resize( getBounds() );
163
164 // render the Shape on the newly added ViewLayer
165 if( bRedrawLayer )
166 maViewAppletShapes.back()->render( getBounds() );
167 }
168 catch(uno::Exception&)
169 {
170 // ignore failed shapes - slideshow should run with
171 // the remaining content
172 }
173 }
174
175
176 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
177 {
178 const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
179
180 OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
181 aEnd,
182 [&rLayer]
183 ( const ViewAppletShapeSharedPtr& pShape )
184 { return rLayer == pShape->getViewLayer(); } ) < 2,
185 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
186
187 ViewAppletShapeVector::iterator aIter;
188
189 if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
190 aEnd,
191 [&rLayer]
192 ( const ViewAppletShapeSharedPtr& pShape )
193 { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
194 {
195 // view layer seemingly was not added, failed
196 return false;
197 }
198
199 // actually erase from container
200 maViewAppletShapes.erase( aIter, aEnd );
201
202 return true;
203 }
204
205
206 void AppletShape::clearAllViewLayers()
207 {
208 maViewAppletShapes.clear();
209 }
210
211
212 bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
213 {
214 // redraw all view shapes, by calling their update() method
215 if( o3tl::make_unsigned(::std::count_if( maViewAppletShapes.begin(),
216 maViewAppletShapes.end(),
217 [&rCurrBounds]
218 ( const ViewAppletShapeSharedPtr& pShape )
219 { return pShape->render( rCurrBounds ); } ))
220 != maViewAppletShapes.size() )
221 {
222 // at least one of the ViewShape::update() calls did return
223 // false - update failed on at least one ViewLayer
224 return false;
225 }
226
227 return true;
228 }
229
230
231 bool AppletShape::implStartIntrinsicAnimation()
232 {
233 const ::basegfx::B2DRectangle& rBounds = getBounds();
234 for( const auto& pViewAppletShape : maViewAppletShapes )
235 pViewAppletShape->startApplet( rBounds );
236
237 mbIsPlaying = true;
238
239 return true;
240 }
241
242
243 bool AppletShape::implEndIntrinsicAnimation()
244 {
245 for( const auto& pViewAppletShape : maViewAppletShapes )
246 pViewAppletShape->endApplet();
247
248 mbIsPlaying = false;
249
250 return true;
251 }
252
253
254 void AppletShape::implPauseIntrinsicAnimation()
255 {
256 // TODO(F1): any way of temporarily disabling/deactivating
257 // applets?
258 }
259
260
261 bool AppletShape::implIsIntrinsicAnimationPlaying() const
262 {
263 return mbIsPlaying;
264 }
265
266
267 void AppletShape::implSetIntrinsicAnimationTime(double)
268 {
269 // No way of doing this, or?
270 }
271
272 std::shared_ptr<Shape> createAppletShape(
274 double nPrio,
275 const OUString& rServiceName,
276 const char** pPropCopyTable,
277 std::size_t nNumPropEntries,
278 const SlideShowContext& rContext )
279 {
280 return std::make_shared<AppletShape>(xShape,
281 nPrio,
282 rServiceName,
283 pPropCopyTable,
284 nNumPropEntries,
285 rContext);
286 }
287}
288
289/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const std::size_t mnNumPropEntries
const OUString maServiceName
Definition: appletshape.cxx:99
bool mbIsPlaying
const char ** mpPropCopyTable
ViewAppletShapeVector maViewAppletShapes
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
::std::shared_ptr< ViewAppletShape > ViewAppletShapeSharedPtr
std::shared_ptr< ViewLayer > ViewLayerSharedPtr
Definition: viewlayer.hxx:168
std::shared_ptr< Shape > createAppletShape(const uno::Reference< drawing::XShape > &xShape, double nPrio, const OUString &rServiceName, const char **pPropCopyTable, std::size_t nNumPropEntries, const SlideShowContext &rContext)
std::shared_ptr< UnoView > UnoViewSharedPtr
Common arguments for slideshow objects.