1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
40 #include "backgroundshape.hxx"
41 #include "slideshowexceptions.hxx"
42 #include "slideshowcontext.hxx"
43 #include "gdimtftools.hxx"
45 #include "viewbackgroundshape.hxx"
48 using namespace ::com::sun::star
;
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
63 @attention this class is to be treated 'final', i.e. one
64 should not derive from it.
66 class BackgroundShape
: public Shape
69 /** Create the background shape.
71 This method creates a shape that handles the
72 peculiarities of the draw API regarding background
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
;
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
;
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
;
107 virtual bool update() const SAL_OVERRIDE
;
108 virtual bool render() const SAL_OVERRIDE
;
109 virtual bool isContentChanged() const SAL_OVERRIDE
;
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
) :
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
154 sal_Int32 nDocWidth
=0;
155 sal_Int32 nDocHeight
=0;
156 xPropSet
->getPropertyValue("Width") >>= nDocWidth
;
157 xPropSet
->getPropertyValue("Height") >>= nDocHeight
;
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
,
173 if( ::std::any_of( maViewShapes
.begin(),
176 ::std::equal_to
< ViewLayerSharedPtr
>(),
177 ::boost::bind( &ViewBackgroundShape::getViewLayer
,
179 ::boost::cref( rNewLayer
) ) ) )
181 // yes, nothing to do
185 maViewShapes
.push_back(
186 ViewBackgroundShapeSharedPtr(
187 new ViewBackgroundShape( rNewLayer
,
190 // render the Shape on the newly added ViewLayer
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(),
202 ::std::equal_to
< ViewLayerSharedPtr
>(),
203 ::boost::bind( &ViewBackgroundShape::getViewLayer
,
205 ::boost::cref( rLayer
) ) ) < 2,
206 "BackgroundShape::removeViewLayer(): Duplicate ViewLayer entries!" );
208 ViewBackgroundShapeVector::iterator aIter
;
210 if( (aIter
=::std::remove_if( maViewShapes
.begin(),
213 ::std::equal_to
< ViewLayerSharedPtr
>(),
214 ::boost::bind( &ViewBackgroundShape::getViewLayer
,
216 ::boost::cref( rLayer
) ) )) == aEnd
)
218 // view layer seemingly was not added, failed
222 // actually erase from container
223 maViewShapes
.erase( aIter
, aEnd
);
228 bool BackgroundShape::clearAllViewLayers()
230 maViewShapes
.clear();
234 ::basegfx::B2DRectangle
BackgroundShape::getBounds() const
239 ::basegfx::B2DRectangle
BackgroundShape::getDomBounds() const
244 ::basegfx::B2DRectangle
BackgroundShape::getUpdateArea() const
246 // TODO(F1): Need to expand background, too, when
249 // no transformation etc. possible for background shape
253 bool BackgroundShape::isVisible() const
258 double BackgroundShape::getPriority() const
260 return 0.0; // lowest prio, we're the background
263 bool BackgroundShape::update() const
268 bool BackgroundShape::render() const
270 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape::render()" );
271 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape: 0x" << std::hex
<< this );
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...
283 // redraw all view shapes, by calling their render() method
284 if( ::std::count_if( maViewShapes
.begin(),
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
299 bool BackgroundShape::isContentChanged() const
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(
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */