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: pptshape.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 #include "oox/ppt/pptshape.hxx"
32 #include "oox/core/namespaces.hxx"
33 #include "oox/core/xmlfilterbase.hxx"
34 #include "oox/drawingml/textbody.hxx"
37 #include <com/sun/star/container/XNamed.hpp>
38 #include <com/sun/star/beans/XMultiPropertySet.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
41 #include <com/sun/star/text/XText.hpp>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include "oox/ppt/slidepersist.hxx"
46 using namespace ::oox::core
;
47 using namespace ::oox::drawingml
;
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::awt
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::frame
;
53 using namespace ::com::sun::star::text
;
54 using namespace ::com::sun::star::drawing
;
56 namespace oox
{ namespace ppt
{
58 PPTShape::PPTShape( const oox::ppt::ShapeLocation eShapeLocation
, const sal_Char
* pServiceName
)
59 : Shape( pServiceName
)
60 , meShapeLocation( eShapeLocation
)
61 , mbReferenced( sal_False
)
69 void PPTShape::addShape(
70 const oox::core::XmlFilterBase
& rFilterBase
,
71 const SlidePersist
& rSlidePersist
,
72 const oox::drawingml::ThemePtr
& rxTheme
,
73 const Reference
< XShapes
>& rxShapes
,
74 const awt::Rectangle
* pShapeRect
,
75 ::oox::drawingml::ShapeIdMap
* pShapeMap
)
77 // only placeholder from layout are being inserted
78 if ( mnSubType
&& ( meShapeLocation
== Master
) )
82 rtl::OUString
sServiceName( msServiceName
);
83 if( sServiceName
.getLength() )
85 oox::drawingml::TextListStylePtr aMasterTextListStyle
;
86 Reference
< lang::XMultiServiceFactory
> xServiceFact( rFilterBase
.getModel(), UNO_QUERY_THROW
);
87 sal_Bool bClearText
= sal_False
;
89 if ( sServiceName
!= OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) )
96 const rtl::OUString
sTitleShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.TitleTextShape" ) );
97 sServiceName
= sTitleShapeService
;
98 aMasterTextListStyle
= rSlidePersist
.getMasterPersist().get() ? rSlidePersist
.getMasterPersist()->getTitleTextStyle() : rSlidePersist
.getTitleTextStyle();
103 const rtl::OUString
sTitleShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.SubtitleShape" ) );
104 sServiceName
= sTitleShapeService
;
105 aMasterTextListStyle
= rSlidePersist
.getMasterPersist().get() ? rSlidePersist
.getMasterPersist()->getTitleTextStyle() : rSlidePersist
.getTitleTextStyle();
109 const rtl::OUString
sOutlinerShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.OutlinerShape" ) );
110 sServiceName
= sOutlinerShapeService
;
111 aMasterTextListStyle
= rSlidePersist
.getMasterPersist().get() ? rSlidePersist
.getMasterPersist()->getBodyTextStyle() : rSlidePersist
.getBodyTextStyle();
116 const rtl::OUString
sNotesShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.NotesShape" ) );
117 const rtl::OUString
sOutlinerShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.OutlinerShape" ) );
118 if ( rSlidePersist
.isNotesPage() )
120 sServiceName
= sNotesShapeService
;
121 aMasterTextListStyle
= rSlidePersist
.getMasterPersist().get() ? rSlidePersist
.getMasterPersist()->getNotesTextStyle() : rSlidePersist
.getNotesTextStyle();
125 sServiceName
= sOutlinerShapeService
;
126 aMasterTextListStyle
= rSlidePersist
.getMasterPersist().get() ? rSlidePersist
.getMasterPersist()->getBodyTextStyle() : rSlidePersist
.getBodyTextStyle();
132 const rtl::OUString
sDateTimeShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.DateTimeShape" ) );
133 sServiceName
= sDateTimeShapeService
;
134 bClearText
= sal_True
;
139 const rtl::OUString
sHeaderShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.HeaderShape" ) );
140 sServiceName
= sHeaderShapeService
;
141 bClearText
= sal_True
;
146 const rtl::OUString
sFooterShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.FooterShape" ) );
147 sServiceName
= sFooterShapeService
;
148 bClearText
= sal_True
;
153 const rtl::OUString
sSlideNumberShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.SlideNumberShape" ) );
154 sServiceName
= sSlideNumberShapeService
;
155 bClearText
= sal_True
;
160 const rtl::OUString
sPageShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PageShape" ) );
161 sServiceName
= sPageShapeService
;
170 // use placeholder index if possible
171 if( mnSubType
&& getIndex() && rSlidePersist
.getMasterPersist().get() ) {
172 oox::drawingml::ShapePtr pPlaceholder
= PPTShape::findPlaceholderByIndex( getIndex(), rSlidePersist
.getMasterPersist()->getShapes()->getChildren() );
173 if( pPlaceholder
.get() && pPlaceholder
->getTextBody() ) {
174 TextListStylePtr
pNewTextListStyle (new TextListStyle());
176 pNewTextListStyle
->apply( pPlaceholder
->getTextBody()->getTextListStyle() );
177 aMasterTextListStyle
= pNewTextListStyle
;
181 // use style from master slide for placeholders only, otherwise use slide's style, which might be the default style from presentation
182 if ( !aMasterTextListStyle
.get() )
183 aMasterTextListStyle
= ( mnSubType
&& rSlidePersist
.getMasterPersist().get() ) ? rSlidePersist
.getMasterPersist()->getOtherTextStyle() : rSlidePersist
.getOtherTextStyle();
185 if( aMasterTextListStyle
.get() && getTextBody().get() ) {
186 TextListStylePtr
aCombinedTextListStyle (new TextListStyle());
188 aCombinedTextListStyle
->apply( *aMasterTextListStyle
.get() );
190 if( mpPlaceholder
.get() && mpPlaceholder
->getTextBody().get() )
191 aCombinedTextListStyle
->apply( mpPlaceholder
->getTextBody()->getTextListStyle() );
192 aCombinedTextListStyle
->apply( getTextBody()->getTextListStyle() );
194 setMasterTextListStyle( aCombinedTextListStyle
);
196 setMasterTextListStyle( aMasterTextListStyle
);
198 Reference
< XShape
> xShape( createAndInsert( rFilterBase
, sServiceName
, rxTheme
, rxShapes
, pShapeRect
, bClearText
) );
199 if ( !rSlidePersist
.isMasterPage() && rSlidePersist
.getPage().is() && ( (sal_Int32
)mnSubType
== XML_title
) )
203 rtl::OUString aTitleText
;
204 Reference
< XTextRange
> xText( xShape
, UNO_QUERY_THROW
);
205 aTitleText
= xText
->getString();
206 if ( aTitleText
.getLength() && ( aTitleText
.getLength() < 64 ) ) // just a magic value, but we don't want to set slide names which are too long
208 Reference
< container::XNamed
> xName( rSlidePersist
.getPage(), UNO_QUERY_THROW
);
209 xName
->setName( aTitleText
);
212 catch( uno::Exception
& )
216 if( pShapeMap
&& msId
.getLength() )
218 (*pShapeMap
)[ msId
] = shared_from_this();
221 // if this is a group shape, we have to add also each child shape
222 Reference
< XShapes
> xShapes( xShape
, UNO_QUERY
);
224 addChildren( rFilterBase
, *this, rxTheme
, xShapes
, pShapeRect
? *pShapeRect
: awt::Rectangle( maPosition
.X
, maPosition
.Y
, maSize
.Width
, maSize
.Height
), pShapeMap
);
227 catch( const Exception
& )
232 void PPTShape::applyShapeReference( const oox::drawingml::Shape
& rReferencedShape
)
234 Shape::applyShapeReference( rReferencedShape
);
237 oox::drawingml::ShapePtr
PPTShape::findPlaceholder( const sal_Int32 nMasterPlaceholder
, std::vector
< oox::drawingml::ShapePtr
>& rShapes
)
239 oox::drawingml::ShapePtr aShapePtr
;
240 std::vector
< oox::drawingml::ShapePtr
>::reverse_iterator
aRevIter( rShapes
.rbegin() );
241 while( aRevIter
!= rShapes
.rend() )
243 if ( (*aRevIter
)->getSubType() == nMasterPlaceholder
)
245 aShapePtr
= *aRevIter
;
248 std::vector
< oox::drawingml::ShapePtr
>& rChildren
= (*aRevIter
)->getChildren();
249 aShapePtr
= findPlaceholder( nMasterPlaceholder
, rChildren
);
250 if ( aShapePtr
.get() )
257 oox::drawingml::ShapePtr
PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx
, std::vector
< oox::drawingml::ShapePtr
>& rShapes
)
259 oox::drawingml::ShapePtr aShapePtr
;
260 std::vector
< oox::drawingml::ShapePtr
>::reverse_iterator
aRevIter( rShapes
.rbegin() );
261 while( aRevIter
!= rShapes
.rend() )
263 if ( (*aRevIter
)->getIndex() == nIdx
)
265 aShapePtr
= *aRevIter
;
268 std::vector
< oox::drawingml::ShapePtr
>& rChildren
= (*aRevIter
)->getChildren();
269 aShapePtr
= findPlaceholderByIndex( nIdx
, rChildren
);
270 if ( aShapePtr
.get() )
277 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
278 oox::drawingml::ShapePtr
PPTShape::findPlaceholder( sal_Int32 nFirstPlaceholder
, sal_Int32 nSecondPlaceholder
, std::vector
< oox::drawingml::ShapePtr
>& rShapes
)
280 oox::drawingml::ShapePtr pPlaceholder
= findPlaceholder( nFirstPlaceholder
, rShapes
);
281 return !nSecondPlaceholder
|| pPlaceholder
.get() ? pPlaceholder
: findPlaceholder( nSecondPlaceholder
, rShapes
);