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 .
21 #include <com/sun/star/awt/Rectangle.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/awt/FontWeight.hpp>
25 #include <vcl/metaact.hxx>
26 #include <vcl/gdimtf.hxx>
28 #include <basegfx/numeric/ftools.hxx>
29 #include <sal/log.hxx>
36 #include "backgroundshape.hxx"
37 #include <slideshowexceptions.hxx>
38 #include <slideshowcontext.hxx>
39 #include "gdimtftools.hxx"
41 #include "viewbackgroundshape.hxx"
44 using namespace ::com::sun::star
;
51 /** Representation of a draw document's background shape.
53 This class implements the Shape interface for the
54 background shape. Since the background shape is neither
55 animatable nor attributable, those more specialized
56 derivations of the Shape interface are not implemented
59 @attention this class is to be treated 'final', i.e. one
60 should not derive from it.
62 class BackgroundShape
: public Shape
65 /** Create the background shape.
67 This method creates a shape that handles the
68 peculiarities of the draw API regarding background
71 BackgroundShape( const css::uno::Reference
< css::drawing::XDrawPage
>& xDrawPage
,
72 const css::uno::Reference
< css::drawing::XDrawPage
>& xMasterPage
,
73 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
75 virtual css::uno::Reference
<
76 css::drawing::XShape
> getXShape() const override
;
81 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
82 bool bRedrawLayer
) override
;
83 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
) override
;
84 virtual void clearAllViewLayers() override
;
90 virtual ::basegfx::B2DRectangle
getBounds() const override
;
91 virtual ::basegfx::B2DRectangle
getDomBounds() const override
;
92 virtual ::basegfx::B2DRectangle
getUpdateArea() const override
;
93 virtual bool isVisible() const override
;
94 virtual double getPriority() const override
;
95 virtual bool isBackgroundDetached() const override
;
101 virtual bool update() const override
;
102 virtual bool render() const override
;
103 virtual bool isContentChanged() const override
;
106 /// The metafile actually representing the Shape
107 GDIMetaFileSharedPtr mpMtf
;
109 // The attributes of this Shape
110 ::basegfx::B2DRectangle maBounds
; // always needed for rendering
112 /// the list of active view shapes (one for each registered view layer)
113 typedef ::std::vector
< ViewBackgroundShapeSharedPtr
> ViewBackgroundShapeVector
;
114 ViewBackgroundShapeVector maViewShapes
;
118 BackgroundShape::BackgroundShape( const uno::Reference
< drawing::XDrawPage
>& xDrawPage
,
119 const uno::Reference
< drawing::XDrawPage
>& xMasterPage
,
120 const SlideShowContext
& rContext
) :
125 uno::Reference
< beans::XPropertySet
> xPropSet( xDrawPage
,
126 uno::UNO_QUERY_THROW
);
127 // first try the page background (overrides
128 // masterpage background), then try masterpage
129 GDIMetaFileSharedPtr xMtf
= getMetaFile(uno::Reference
<lang::XComponent
>(xDrawPage
, uno::UNO_QUERY
),
130 xDrawPage
, MTF_LOAD_BACKGROUND_ONLY
,
131 rContext
.mxComponentContext
);
135 xMtf
= getMetaFile( uno::Reference
<lang::XComponent
>(xMasterPage
, uno::UNO_QUERY
),
136 xDrawPage
, MTF_LOAD_BACKGROUND_ONLY
,
137 rContext
.mxComponentContext
);
142 throw ShapeLoadFailedException();
145 // there is a special background shape, add it
148 sal_Int32 nDocWidth
=0;
149 sal_Int32 nDocHeight
=0;
150 xPropSet
->getPropertyValue("Width") >>= nDocWidth
;
151 xPropSet
->getPropertyValue("Height") >>= nDocHeight
;
154 maBounds
= ::basegfx::B2DRectangle( 0,0,nDocWidth
, nDocHeight
);
157 uno::Reference
< drawing::XShape
> BackgroundShape::getXShape() const
159 // no real XShape representative
160 return uno::Reference
< drawing::XShape
>();
163 void BackgroundShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
167 if( ::std::any_of( maViewShapes
.begin(),
169 [&rNewLayer
]( const ViewBackgroundShapeSharedPtr
& pBgShape
)
170 { return pBgShape
->getViewLayer() == rNewLayer
; } ) )
172 // yes, nothing to do
176 maViewShapes
.push_back(
177 std::make_shared
<ViewBackgroundShape
>(
178 rNewLayer
, maBounds
) );
180 // render the Shape on the newly added ViewLayer
182 maViewShapes
.back()->render( mpMtf
);
185 bool BackgroundShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
187 const ViewBackgroundShapeVector::iterator
aEnd( maViewShapes
.end() );
189 OSL_ENSURE( ::std::count_if(maViewShapes
.begin(),
191 [&rLayer
]( const ViewBackgroundShapeSharedPtr
& pBgShape
)
192 { return pBgShape
->getViewLayer() == rLayer
; } ) < 2,
193 "BackgroundShape::removeViewLayer(): Duplicate ViewLayer entries!" );
195 ViewBackgroundShapeVector::iterator aIter
;
197 if( (aIter
=::std::remove_if( maViewShapes
.begin(),
199 [&rLayer
]( const ViewBackgroundShapeSharedPtr
& pBgShape
)
200 { return pBgShape
->getViewLayer() == rLayer
; } )) == aEnd
)
202 // view layer seemingly was not added, failed
206 // actually erase from container
207 maViewShapes
.erase( aIter
, aEnd
);
212 void BackgroundShape::clearAllViewLayers()
214 maViewShapes
.clear();
217 ::basegfx::B2DRectangle
BackgroundShape::getBounds() const
222 ::basegfx::B2DRectangle
BackgroundShape::getDomBounds() const
227 ::basegfx::B2DRectangle
BackgroundShape::getUpdateArea() const
229 // TODO(F1): Need to expand background, too, when
232 // no transformation etc. possible for background shape
236 bool BackgroundShape::isVisible() const
241 double BackgroundShape::getPriority() const
243 return 0.0; // lowest prio, we're the background
246 bool BackgroundShape::update() const
251 bool BackgroundShape::render() const
253 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape::render()" );
254 SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape: 0x" << std::hex
<< this );
257 const ::basegfx::B2DRectangle
& rCurrBounds( BackgroundShape::getBounds() );
259 if( rCurrBounds
.getRange().equalZero() )
261 // zero-sized shapes are effectively invisible,
262 // thus, we save us the rendering...
266 // redraw all view shapes, by calling their render() method
267 if( ::std::count_if( maViewShapes
.begin(),
269 [this]( const ViewBackgroundShapeSharedPtr
& pBgShape
)
270 { return pBgShape
->render( this->mpMtf
); } )
271 != static_cast<ViewBackgroundShapeVector::difference_type
>(maViewShapes
.size()) )
273 // at least one of the ViewBackgroundShape::render() calls did return
274 // false - update failed on at least one ViewLayer
281 bool BackgroundShape::isContentChanged() const
286 bool BackgroundShape::isBackgroundDetached() const
288 return false; // we're not animatable
292 ShapeSharedPtr
createBackgroundShape(
293 const uno::Reference
< drawing::XDrawPage
>& xDrawPage
,
294 const uno::Reference
< drawing::XDrawPage
>& xMasterPage
,
295 const SlideShowContext
& rContext
)
297 return ShapeSharedPtr(
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */