1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backgroundshape.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
35 #include <canvas/debug.hxx>
37 #include <com/sun/star/awt/Rectangle.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/awt/FontWeight.hpp>
40 #include <rtl/logfile.hxx>
42 #include <vcl/metaact.hxx>
43 #include <vcl/gdimtf.hxx>
45 #include <basegfx/numeric/ftools.hxx>
47 #include <boost/bind.hpp>
49 #include <cmath> // for trigonometry and fabs
54 #include "backgroundshape.hxx"
55 #include "slideshowexceptions.hxx"
56 #include "slideshowcontext.hxx"
57 #include "gdimtftools.hxx"
59 #include "viewbackgroundshape.hxx"
62 using namespace ::com::sun::star
;
69 /** Representation of a draw document's background shape.
71 This class implements the Shape interface for the
72 background shape. Since the background shape is neither
73 animatable nor attributable, those more specialized
74 derivations of the Shape interface are not implemented
77 @attention this class is to be treated 'final', i.e. one
78 should not derive from it.
80 class BackgroundShape
: public Shape
83 /** Create the background shape.
85 This method creates a shape that handles the
86 peculiarities of the draw API regarding background
89 BackgroundShape( const ::com::sun::star::uno::Reference
<
90 ::com::sun::star::drawing::XDrawPage
>& xDrawPage
,
91 const ::com::sun::star::uno::Reference
<
92 ::com::sun::star::drawing::XDrawPage
>& xMasterPage
,
93 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
95 virtual ::com::sun::star::uno::Reference
<
96 ::com::sun::star::drawing::XShape
> getXShape() const;
99 //------------------------------------------------------------------
101 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
103 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
);
104 virtual bool clearAllViewLayers();
108 //------------------------------------------------------------------
110 virtual ::basegfx::B2DRectangle
getBounds() const;
111 virtual ::basegfx::B2DRectangle
getDomBounds() const;
112 virtual ::basegfx::B2DRectangle
getUpdateArea() const;
113 virtual bool isVisible() const;
114 virtual double getPriority() const;
115 virtual bool isBackgroundDetached() const;
119 //------------------------------------------------------------------
121 virtual bool update() const;
122 virtual bool render() const;
123 virtual bool isContentChanged() const;
126 /// The metafile actually representing the Shape
127 GDIMetaFileSharedPtr mpMtf
;
129 // The attributes of this Shape
130 ::basegfx::B2DRectangle maBounds
; // always needed for rendering
132 /// the list of active view shapes (one for each registered view layer)
133 typedef ::std::vector
< ViewBackgroundShapeSharedPtr
> ViewBackgroundShapeVector
;
134 ViewBackgroundShapeVector maViewShapes
;
138 ////////////////////////////////////////////////////////////////////////////////
141 BackgroundShape::BackgroundShape( const uno::Reference
< drawing::XDrawPage
>& xDrawPage
,
142 const uno::Reference
< drawing::XDrawPage
>& xMasterPage
,
143 const SlideShowContext
& rContext
) :
148 uno::Reference
< beans::XPropertySet
> xPropSet( xDrawPage
,
149 uno::UNO_QUERY_THROW
);
150 GDIMetaFileSharedPtr
pMtf( new GDIMetaFile() );
152 // first try the page background (overrides
153 // masterpage background), then try masterpage
154 if( !getMetaFile( uno::Reference
<lang::XComponent
>(xDrawPage
, uno::UNO_QUERY
),
155 xDrawPage
, *pMtf
, MTF_LOAD_BACKGROUND_ONLY
,
156 rContext
.mxComponentContext
) &&
157 !getMetaFile( uno::Reference
<lang::XComponent
>(xMasterPage
, uno::UNO_QUERY
),
158 xDrawPage
, *pMtf
, MTF_LOAD_BACKGROUND_ONLY
,
159 rContext
.mxComponentContext
))
161 throw ShapeLoadFailedException();
164 // there is a special background shape, add it
166 // ---------------------------------------------------
168 sal_Int32 nDocWidth
=0;
169 sal_Int32 nDocHeight
=0;
170 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= nDocWidth
;
171 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= nDocHeight
;
174 maBounds
= ::basegfx::B2DRectangle( 0,0,nDocWidth
, nDocHeight
);
177 uno::Reference
< drawing::XShape
> BackgroundShape::getXShape() const
179 // no real XShape representative
180 return uno::Reference
< drawing::XShape
>();
183 void BackgroundShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
186 ViewBackgroundShapeVector::iterator
aEnd( maViewShapes
.end() );
189 if( ::std::find_if( maViewShapes
.begin(),
192 ::std::equal_to
< ViewLayerSharedPtr
>(),
193 ::boost::bind( &ViewBackgroundShape::getViewLayer
,
195 ::boost::cref( rNewLayer
) ) ) != aEnd
)
197 // yes, nothing to do
201 maViewShapes
.push_back(
202 ViewBackgroundShapeSharedPtr(
203 new ViewBackgroundShape( rNewLayer
,
206 // render the Shape on the newly added ViewLayer
208 maViewShapes
.back()->render( mpMtf
);
211 bool BackgroundShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
213 const ViewBackgroundShapeVector::iterator
aEnd( maViewShapes
.end() );
215 OSL_ENSURE( ::std::count_if(maViewShapes
.begin(),
218 ::std::equal_to
< ViewLayerSharedPtr
>(),
219 ::boost::bind( &ViewBackgroundShape::getViewLayer
,
221 ::boost::cref( rLayer
) ) ) < 2,
222 "BackgroundShape::removeViewLayer(): Duplicate ViewLayer entries!" );
224 ViewBackgroundShapeVector::iterator aIter
;
226 if( (aIter
=::std::remove_if( maViewShapes
.begin(),
229 ::std::equal_to
< ViewLayerSharedPtr
>(),
230 ::boost::bind( &ViewBackgroundShape::getViewLayer
,
232 ::boost::cref( rLayer
) ) )) == aEnd
)
234 // view layer seemingly was not added, failed
238 // actually erase from container
239 maViewShapes
.erase( aIter
, aEnd
);
244 bool BackgroundShape::clearAllViewLayers()
246 maViewShapes
.clear();
250 ::basegfx::B2DRectangle
BackgroundShape::getBounds() const
255 ::basegfx::B2DRectangle
BackgroundShape::getDomBounds() const
260 ::basegfx::B2DRectangle
BackgroundShape::getUpdateArea() const
262 // TODO(F1): Need to expand background, too, when
265 // no transformation etc. possible for background shape
269 bool BackgroundShape::isVisible() const
274 double BackgroundShape::getPriority() const
276 return 0.0; // lowest prio, we're the background
279 bool BackgroundShape::update() const
284 bool BackgroundShape::render() const
286 RTL_LOGFILE_CONTEXT( aLog
, "::presentation::internal::BackgroundShape::render()" );
287 RTL_LOGFILE_CONTEXT_TRACE1( aLog
, "::presentation::internal::BackgroundShape: 0x%X", this );
290 const ::basegfx::B2DRectangle
& rCurrBounds( BackgroundShape::getBounds() );
292 if( rCurrBounds
.getRange().equalZero() )
294 // zero-sized shapes are effectively invisible,
295 // thus, we save us the rendering...
299 // redraw all view shapes, by calling their render() method
300 if( ::std::count_if( maViewShapes
.begin(),
302 ::boost::bind( &ViewBackgroundShape::render
,
304 ::boost::cref( mpMtf
) ) )
305 != static_cast<ViewBackgroundShapeVector::difference_type
>(maViewShapes
.size()) )
307 // at least one of the ViewBackgroundShape::render() calls did return
308 // false - update failed on at least one ViewLayer
315 bool BackgroundShape::isContentChanged() const
320 bool BackgroundShape::isBackgroundDetached() const
322 return false; // we're not animatable
325 //////////////////////////////////////////////////////////
327 ShapeSharedPtr
createBackgroundShape(
328 const uno::Reference
< drawing::XDrawPage
>& xDrawPage
,
329 const uno::Reference
< drawing::XDrawPage
>& xMasterPage
,
330 const SlideShowContext
& rContext
)
332 return ShapeSharedPtr(