LibreOffice Module slideshow (master) 1
backgroundshape.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 <com/sun/star/beans/XPropertySet.hpp>
22
23#include <sal/log.hxx>
24#include <o3tl/safeint.hxx>
25#include <osl/diagnose.h>
26
27#include <algorithm>
28
29#include "backgroundshape.hxx"
31#include <slideshowcontext.hxx>
32#include "gdimtftools.hxx"
33#include <shape.hxx>
35
36
37using namespace ::com::sun::star;
38
39
40namespace slideshow::internal
41{
42 namespace {
43
55 class BackgroundShape : public Shape
56 {
57 public:
64 BackgroundShape( const css::uno::Reference< css::drawing::XDrawPage >& xDrawPage,
65 const css::uno::Reference< css::drawing::XDrawPage >& xMasterPage,
66 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
67
68 virtual css::uno::Reference<
69 css::drawing::XShape > getXShape() const override;
70
71 // View layer methods
72
73
74 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
75 bool bRedrawLayer ) override;
76 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) override;
77 virtual void clearAllViewLayers() override;
78
79
80 // attribute methods
81
82
83 virtual ::basegfx::B2DRectangle getBounds() const override;
84 virtual ::basegfx::B2DRectangle getDomBounds() const override;
85 virtual ::basegfx::B2DRectangle getUpdateArea() const override;
86 virtual bool isVisible() const override;
87 virtual double getPriority() const override;
88 virtual bool isForeground() const override { return false; }
89 virtual bool isBackgroundDetached() const override;
90
91
92 // render methods
93
94
95 virtual bool update() const override;
96 virtual bool render() const override;
97 virtual bool isContentChanged() const override;
98
99 private:
102
103 // The attributes of this Shape
104 ::basegfx::B2DRectangle maBounds; // always needed for rendering
105
107 typedef ::std::vector< ViewBackgroundShapeSharedPtr > ViewBackgroundShapeVector;
108 ViewBackgroundShapeVector maViewShapes;
109 };
110
111 }
112
113 BackgroundShape::BackgroundShape( const uno::Reference< drawing::XDrawPage >& xDrawPage,
114 const uno::Reference< drawing::XDrawPage >& xMasterPage,
115 const SlideShowContext& rContext ) :
116 mpMtf(),
117 maBounds(),
119 {
120 uno::Reference< beans::XPropertySet > xPropSet( xDrawPage,
121 uno::UNO_QUERY_THROW );
122 // first try the page background (overrides
123 // masterpage background), then try masterpage
124 GDIMetaFileSharedPtr xMtf = getMetaFile(uno::Reference<lang::XComponent>(xDrawPage, uno::UNO_QUERY),
125 xDrawPage, MTF_LOAD_BACKGROUND_ONLY,
126 rContext.mxComponentContext);
127
128 if (!xMtf)
129 {
130 xMtf = getMetaFile( uno::Reference<lang::XComponent>(xMasterPage, uno::UNO_QUERY),
131 xDrawPage, MTF_LOAD_BACKGROUND_ONLY,
132 rContext.mxComponentContext );
133 }
134
135 if (!xMtf)
136 {
137 throw ShapeLoadFailedException();
138 }
139
140 // there is a special background shape, add it
141 // as the first one
142
143 sal_Int32 nDocWidth=0;
144 sal_Int32 nDocHeight=0;
145 xPropSet->getPropertyValue("Width") >>= nDocWidth;
146 xPropSet->getPropertyValue("Height") >>= nDocHeight;
147
148 mpMtf = xMtf;
149 maBounds = ::basegfx::B2DRectangle( 0,0,nDocWidth, nDocHeight );
150 }
151
152 uno::Reference< drawing::XShape > BackgroundShape::getXShape() const
153 {
154 // no real XShape representative
155 return uno::Reference< drawing::XShape >();
156 }
157
158 void BackgroundShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
159 bool bRedrawLayer )
160 {
161 // already added?
162 if( ::std::any_of( maViewShapes.begin(),
163 maViewShapes.end(),
164 [&rNewLayer]( const ViewBackgroundShapeSharedPtr& pBgShape )
165 { return pBgShape->getViewLayer() == rNewLayer; } ) )
166 {
167 // yes, nothing to do
168 return;
169 }
170
171 maViewShapes.push_back(
172 std::make_shared<ViewBackgroundShape>(
173 rNewLayer, maBounds ) );
174
175 // render the Shape on the newly added ViewLayer
176 if( bRedrawLayer )
177 maViewShapes.back()->render( mpMtf );
178 }
179
180 bool BackgroundShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
181 {
182 const ViewBackgroundShapeVector::iterator aEnd( maViewShapes.end() );
183
184 OSL_ENSURE( ::std::count_if(maViewShapes.begin(),
185 aEnd,
186 [&rLayer]( const ViewBackgroundShapeSharedPtr& pBgShape )
187 { return pBgShape->getViewLayer() == rLayer; } ) < 2,
188 "BackgroundShape::removeViewLayer(): Duplicate ViewLayer entries!" );
189
190 ViewBackgroundShapeVector::iterator aIter;
191
192 if( (aIter=::std::remove_if( maViewShapes.begin(),
193 aEnd,
194 [&rLayer]( const ViewBackgroundShapeSharedPtr& pBgShape )
195 { return pBgShape->getViewLayer() == rLayer; } )) == aEnd )
196 {
197 // view layer seemingly was not added, failed
198 return false;
199 }
200
201 // actually erase from container
202 maViewShapes.erase( aIter, aEnd );
203
204 return true;
205 }
206
207 void BackgroundShape::clearAllViewLayers()
208 {
209 maViewShapes.clear();
210 }
211
212 ::basegfx::B2DRectangle BackgroundShape::getBounds() const
213 {
214 return maBounds;
215 }
216
217 ::basegfx::B2DRectangle BackgroundShape::getDomBounds() const
218 {
219 return maBounds;
220 }
221
222 ::basegfx::B2DRectangle BackgroundShape::getUpdateArea() const
223 {
224 // TODO(F1): Need to expand background, too, when
225 // antialiasing?
226
227 // no transformation etc. possible for background shape
228 return maBounds;
229 }
230
231 bool BackgroundShape::isVisible() const
232 {
233 return true;
234 }
235
236 double BackgroundShape::getPriority() const
237 {
238 return 0.0; // lowest prio, we're the background
239 }
240
241 bool BackgroundShape::update() const
242 {
243 return render();
244 }
245
246 bool BackgroundShape::render() const
247 {
248 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape::render()" );
249 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape: 0x" << std::hex << this );
250
251 // gcc again...
252 const ::basegfx::B2DRectangle& rCurrBounds( BackgroundShape::getBounds() );
253
254 if( rCurrBounds.getRange().equalZero() )
255 {
256 // zero-sized shapes are effectively invisible,
257 // thus, we save us the rendering...
258 return true;
259 }
260
261 // redraw all view shapes, by calling their render() method
262 if( o3tl::make_unsigned(::std::count_if( maViewShapes.begin(),
263 maViewShapes.end(),
264 [this]( const ViewBackgroundShapeSharedPtr& pBgShape )
265 { return pBgShape->render( this->mpMtf ); } ))
266 != maViewShapes.size() )
267 {
268 // at least one of the ViewBackgroundShape::render() calls did return
269 // false - update failed on at least one ViewLayer
270 return false;
271 }
272
273 return true;
274 }
275
276 bool BackgroundShape::isContentChanged() const
277 {
278 return false;
279 }
280
281 bool BackgroundShape::isBackgroundDetached() const
282 {
283 return false; // we're not animatable
284 }
285
286
289 const uno::Reference< drawing::XDrawPage >& xMasterPage,
290 const SlideShowContext& rContext )
291 {
292 return std::make_shared<BackgroundShape>(
293 xDrawPage,
294 xMasterPage,
295 rContext );
296 }
297}
298
299/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GDIMetaFileSharedPtr mpMtf
The metafile actually representing the Shape.
::basegfx::B2DRectangle maBounds
ViewBackgroundShapeVector maViewShapes
::std::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr
#define SAL_INFO(area, stream)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
@ MTF_LOAD_BACKGROUND_ONLY
retrieve a meta file for the page background only
Definition: gdimtftools.hxx:52
std::shared_ptr< ViewLayer > ViewLayerSharedPtr
Definition: viewlayer.hxx:168
ShapeSharedPtr createBackgroundShape(const uno::Reference< drawing::XDrawPage > &xDrawPage, const uno::Reference< drawing::XDrawPage > &xMasterPage, const SlideShowContext &rContext)
::std::shared_ptr< ViewBackgroundShape > ViewBackgroundShapeSharedPtr
GDIMetaFileSharedPtr getMetaFile(const uno::Reference< lang::XComponent > &xSource, const uno::Reference< drawing::XDrawPage > &xContainingPage, int mtfLoadFlags, const uno::Reference< uno::XComponentContext > &rxContext)
::std::shared_ptr< Shape > ShapeSharedPtr
Common arguments for slideshow objects.
Shape
bool update()