fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / shapes / backgroundshape.cxx
blob762c05c692b5662f1ec739737d793f3eae349d0d
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>
24 #include <com/sun/star/awt/Rectangle.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/awt/FontWeight.hpp>
28 #include <vcl/metaact.hxx>
29 #include <vcl/gdimtf.hxx>
31 #include <basegfx/numeric/ftools.hxx>
33 #include <boost/bind.hpp>
35 #include <cmath>
36 #include <algorithm>
37 #include <functional>
38 #include <limits>
40 #include "backgroundshape.hxx"
41 #include "slideshowexceptions.hxx"
42 #include "slideshowcontext.hxx"
43 #include "gdimtftools.hxx"
44 #include "shape.hxx"
45 #include "viewbackgroundshape.hxx"
48 using namespace ::com::sun::star;
51 namespace slideshow
53 namespace internal
55 /** Representation of a draw document's background shape.
57 This class implements the Shape interface for the
58 background shape. Since the background shape is neither
59 animatable nor attributable, those more specialized
60 derivations of the Shape interface are not implemented
61 here.
63 @attention this class is to be treated 'final', i.e. one
64 should not derive from it.
66 class BackgroundShape : public Shape
68 public:
69 /** Create the background shape.
71 This method creates a shape that handles the
72 peculiarities of the draw API regarding background
73 content.
75 BackgroundShape( const ::com::sun::star::uno::Reference<
76 ::com::sun::star::drawing::XDrawPage >& xDrawPage,
77 const ::com::sun::star::uno::Reference<
78 ::com::sun::star::drawing::XDrawPage >& xMasterPage,
79 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
81 virtual ::com::sun::star::uno::Reference<
82 ::com::sun::star::drawing::XShape > getXShape() const SAL_OVERRIDE;
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 // attribute methods
96 virtual ::basegfx::B2DRectangle getBounds() const SAL_OVERRIDE;
97 virtual ::basegfx::B2DRectangle getDomBounds() const SAL_OVERRIDE;
98 virtual ::basegfx::B2DRectangle getUpdateArea() const SAL_OVERRIDE;
99 virtual bool isVisible() const SAL_OVERRIDE;
100 virtual double getPriority() const SAL_OVERRIDE;
101 virtual bool isBackgroundDetached() const SAL_OVERRIDE;
104 // render methods
107 virtual bool update() const SAL_OVERRIDE;
108 virtual bool render() const SAL_OVERRIDE;
109 virtual bool isContentChanged() const SAL_OVERRIDE;
111 private:
112 /// The metafile actually representing the Shape
113 GDIMetaFileSharedPtr mpMtf;
115 // The attributes of this Shape
116 ::basegfx::B2DRectangle maBounds; // always needed for rendering
118 /// the list of active view shapes (one for each registered view layer)
119 typedef ::std::vector< ViewBackgroundShapeSharedPtr > ViewBackgroundShapeVector;
120 ViewBackgroundShapeVector maViewShapes;
127 BackgroundShape::BackgroundShape( const uno::Reference< drawing::XDrawPage >& xDrawPage,
128 const uno::Reference< drawing::XDrawPage >& xMasterPage,
129 const SlideShowContext& rContext ) :
130 mpMtf(),
131 maBounds(),
132 maViewShapes()
134 uno::Reference< beans::XPropertySet > xPropSet( xDrawPage,
135 uno::UNO_QUERY_THROW );
136 GDIMetaFileSharedPtr pMtf( new GDIMetaFile() );
138 // first try the page background (overrides
139 // masterpage background), then try masterpage
140 if( !getMetaFile( uno::Reference<lang::XComponent>(xDrawPage, uno::UNO_QUERY),
141 xDrawPage, *pMtf, MTF_LOAD_BACKGROUND_ONLY,
142 rContext.mxComponentContext ) &&
143 !getMetaFile( uno::Reference<lang::XComponent>(xMasterPage, uno::UNO_QUERY),
144 xDrawPage, *pMtf, MTF_LOAD_BACKGROUND_ONLY,
145 rContext.mxComponentContext ))
147 throw ShapeLoadFailedException();
150 // there is a special background shape, add it
151 // as the first one
154 sal_Int32 nDocWidth=0;
155 sal_Int32 nDocHeight=0;
156 xPropSet->getPropertyValue("Width") >>= nDocWidth;
157 xPropSet->getPropertyValue("Height") >>= nDocHeight;
159 mpMtf = pMtf;
160 maBounds = ::basegfx::B2DRectangle( 0,0,nDocWidth, nDocHeight );
163 uno::Reference< drawing::XShape > BackgroundShape::getXShape() const
165 // no real XShape representative
166 return uno::Reference< drawing::XShape >();
169 void BackgroundShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
170 bool bRedrawLayer )
172 // already added?
173 if( ::std::any_of( maViewShapes.begin(),
174 maViewShapes.end(),
175 ::boost::bind<bool>(
176 ::std::equal_to< ViewLayerSharedPtr >(),
177 ::boost::bind( &ViewBackgroundShape::getViewLayer,
178 _1 ),
179 ::boost::cref( rNewLayer ) ) ) )
181 // yes, nothing to do
182 return;
185 maViewShapes.push_back(
186 ViewBackgroundShapeSharedPtr(
187 new ViewBackgroundShape( rNewLayer,
188 maBounds ) ) );
190 // render the Shape on the newly added ViewLayer
191 if( bRedrawLayer )
192 maViewShapes.back()->render( mpMtf );
195 bool BackgroundShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
197 const ViewBackgroundShapeVector::iterator aEnd( maViewShapes.end() );
199 OSL_ENSURE( ::std::count_if(maViewShapes.begin(),
200 aEnd,
201 ::boost::bind<bool>(
202 ::std::equal_to< ViewLayerSharedPtr >(),
203 ::boost::bind( &ViewBackgroundShape::getViewLayer,
204 _1 ),
205 ::boost::cref( rLayer ) ) ) < 2,
206 "BackgroundShape::removeViewLayer(): Duplicate ViewLayer entries!" );
208 ViewBackgroundShapeVector::iterator aIter;
210 if( (aIter=::std::remove_if( maViewShapes.begin(),
211 aEnd,
212 ::boost::bind<bool>(
213 ::std::equal_to< ViewLayerSharedPtr >(),
214 ::boost::bind( &ViewBackgroundShape::getViewLayer,
215 _1 ),
216 ::boost::cref( rLayer ) ) )) == aEnd )
218 // view layer seemingly was not added, failed
219 return false;
222 // actually erase from container
223 maViewShapes.erase( aIter, aEnd );
225 return true;
228 bool BackgroundShape::clearAllViewLayers()
230 maViewShapes.clear();
231 return true;
234 ::basegfx::B2DRectangle BackgroundShape::getBounds() const
236 return maBounds;
239 ::basegfx::B2DRectangle BackgroundShape::getDomBounds() const
241 return maBounds;
244 ::basegfx::B2DRectangle BackgroundShape::getUpdateArea() const
246 // TODO(F1): Need to expand background, too, when
247 // antialiasing?
249 // no transformation etc. possible for background shape
250 return maBounds;
253 bool BackgroundShape::isVisible() const
255 return true;
258 double BackgroundShape::getPriority() const
260 return 0.0; // lowest prio, we're the background
263 bool BackgroundShape::update() const
265 return render();
268 bool BackgroundShape::render() const
270 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape::render()" );
271 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape: 0x" << std::hex << this );
273 // gcc again...
274 const ::basegfx::B2DRectangle& rCurrBounds( BackgroundShape::getBounds() );
276 if( rCurrBounds.getRange().equalZero() )
278 // zero-sized shapes are effectively invisible,
279 // thus, we save us the rendering...
280 return true;
283 // redraw all view shapes, by calling their render() method
284 if( ::std::count_if( maViewShapes.begin(),
285 maViewShapes.end(),
286 ::boost::bind( &ViewBackgroundShape::render,
288 ::boost::cref( mpMtf ) ) )
289 != static_cast<ViewBackgroundShapeVector::difference_type>(maViewShapes.size()) )
291 // at least one of the ViewBackgroundShape::render() calls did return
292 // false - update failed on at least one ViewLayer
293 return false;
296 return true;
299 bool BackgroundShape::isContentChanged() const
301 return false;
304 bool BackgroundShape::isBackgroundDetached() const
306 return false; // we're not animatable
311 ShapeSharedPtr createBackgroundShape(
312 const uno::Reference< drawing::XDrawPage >& xDrawPage,
313 const uno::Reference< drawing::XDrawPage >& xMasterPage,
314 const SlideShowContext& rContext )
316 return ShapeSharedPtr(
317 new BackgroundShape(
318 xDrawPage,
319 xMasterPage,
320 rContext ));
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */