merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ppt / slidepersist.cxx
blobef040509ddf9235196d3d40cfd7104e238f5958e
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: slidepersist.cxx,v $
10 * $Revision: 1.7.6.1 $
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/helper/propertyset.hxx"
32 #include "oox/ppt/timenode.hxx"
33 #include "oox/ppt/pptshape.hxx"
34 #include "oox/ppt/slidepersist.hxx"
35 #include "oox/drawingml/fillproperties.hxx"
36 #include "oox/vml/vmldrawing.hxx"
37 #include "oox/core/namespaces.hxx"
38 #include "oox/core/xmlfilterbase.hxx"
39 #include "tokens.hxx"
41 #include <com/sun/star/style/XStyle.hpp>
42 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
43 #include <com/sun/star/container/XNamed.hpp>
44 #include <com/sun/star/beans/XMultiPropertySet.hpp>
45 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
47 using namespace ::com::sun::star;
48 using namespace ::oox::core;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::drawing;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::animations;
54 namespace oox { namespace ppt {
56 SlidePersist::SlidePersist( XmlFilterBase& rFilter, sal_Bool bMaster, sal_Bool bNotes,
57 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage,
58 oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
59 : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
60 , mxPage( rxPage )
61 , maShapesPtr( pShapesPtr )
62 , mnLayoutValueToken( 0 )
63 , mbMaster( bMaster )
64 , mbNotes ( bNotes )
65 , maDefaultTextStylePtr( pDefaultTextStyle )
66 , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
67 , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
68 , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
69 , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
71 if ( pDefaultTextStyle )
73 maTitleTextStylePtr->apply( *pDefaultTextStyle.get() );
74 maBodyTextStylePtr->apply( *pDefaultTextStyle.get() );
75 maNotesTextStylePtr->apply( *pDefaultTextStyle.get() );
76 maOtherTextStylePtr->apply( *pDefaultTextStyle.get() );
80 SlidePersist::~SlidePersist()
85 sal_Int16 SlidePersist::getLayoutFromValueToken()
87 sal_Int16 nLayout = 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
88 switch( mnLayoutValueToken )
90 case XML_blank: nLayout = 20; break;
91 case XML_chart: nLayout = 2; break;
92 case XML_chartAndTx: nLayout = 7; break;
93 case XML_clipArtAndTx: nLayout = 9; break;
94 case XML_clipArtAndVertTx: nLayout = 24; break;
95 case XML_fourObj: nLayout = 18; break;
96 case XML_obj: nLayout = 11; break;
97 case XML_objAndTx: nLayout = 13; break;
98 case XML_objOverTx: nLayout = 14; break;
99 case XML_tbl: nLayout = 8; break;
100 case XML_title: nLayout = 0; break;
101 case XML_titleOnly: nLayout = 19; break;
102 case XML_twoObj:
103 case XML_twoColTx: nLayout = 3; break;
104 case XML_twoObjAndTx: nLayout = 15; break;
105 case XML_twoObjOverTx: nLayout = 16; break;
106 case XML_tx: nLayout = 1; break;
107 case XML_txAndChart: nLayout = 4; break;
108 case XML_txAndClipArt: nLayout = 6; break;
109 case XML_txAndMedia: nLayout = 6; break;
110 case XML_txAndObj: nLayout = 10; break;
111 case XML_txAndTwoObj: nLayout = 12; break;
112 case XML_txOverObj: nLayout = 17; break;
113 case XML_vertTitleAndTx: nLayout = 22; break;
114 case XML_vertTitleAndTxOverChart: nLayout = 21; break;
115 case XML_vertTx: nLayout = 23; break;
117 case XML_twoTxTwoObj:
118 case XML_twoObjAndObj:
119 case XML_objTx:
120 case XML_picTx:
121 case XML_secHead:
122 case XML_objOnly:
123 case XML_objAndTwoObj:
124 case XML_mediaAndTx:
125 case XML_dgm:
126 case XML_cust:
127 default:
128 nLayout = 20;
130 return nLayout;
133 void SlidePersist::createXShapes( const XmlFilterBase& rFilterBase )
135 applyTextStyles( rFilterBase );
137 Reference< XShapes > xShapes( getPage(), UNO_QUERY );
139 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
140 std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
141 while( aShapesIter != rShapes.end() )
143 std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
144 std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
145 while( aChildIter != rChildren.end() )
147 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
148 if ( pPPTShape )
149 pPPTShape->addShape( rFilterBase, *this, getTheme(), xShapes, 0, &getShapeMap() );
150 else
151 (*aChildIter)->addShape( rFilterBase, getTheme(), xShapes, 0, &getShapeMap() );
153 aChildIter++;
157 Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
158 if( xNodeSupplier.is() )
160 Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
161 if( xNode.is() && !maTimeNodeList.empty() )
163 SlidePersistPtr pSlidePtr( shared_from_this() );
164 TimeNodePtr pNode(maTimeNodeList.front());
165 OSL_ENSURE( pNode, "pNode" );
167 pNode->setNode( rFilterBase, xNode, pSlidePtr );
172 void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
174 if ( mpBackgroundPropertiesPtr )
178 PropertyMap aPropMap;
179 static const rtl::OUString sBackground( RTL_CONSTASCII_USTRINGPARAM( "Background" ) );
180 uno::Reference< beans::XPropertySet > xPagePropSet( mxPage, uno::UNO_QUERY_THROW );
181 uno::Reference< beans::XPropertySet > xPropertySet( aPropMap.makePropertySet() );
182 PropertySet aPropSet( xPropertySet );
183 mpBackgroundPropertiesPtr->pushToPropSet( aPropSet, rFilterBase, rFilterBase.getModelObjectHelper() );
184 xPagePropSet->setPropertyValue( sBackground, Any( xPropertySet ) );
186 catch( Exception )
192 void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
193 oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
195 ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
196 if( pTextParagraphPropertiesPtr == NULL )
198 // no properties. return
199 return;
202 PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
204 PropertySet aPropSet( rxPropSet );
205 aPropSet.setProperties( rTextParagraphPropertyMap );
206 pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
209 void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
211 if ( mbMaster )
215 Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
216 Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
217 Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
219 if ( aXNameAccess.is() && aXNamed.is() )
221 oox::drawingml::TextListStylePtr pTextListStylePtr;
222 rtl::OUString aStyle;
223 rtl::OUString aFamily;
225 const rtl::OUString sOutline( RTL_CONSTASCII_USTRINGPARAM( "outline1" ) );
226 const rtl::OUString sTitle( RTL_CONSTASCII_USTRINGPARAM( "title" ) );
227 const rtl::OUString sStandard( RTL_CONSTASCII_USTRINGPARAM( "standard" ) );
228 const rtl::OUString sSubtitle( RTL_CONSTASCII_USTRINGPARAM( "subtitle" ) );
230 for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle)
232 switch( i )
234 case 0 : // title style
236 pTextListStylePtr = maTitleTextStylePtr;
237 aStyle = sTitle;
238 aFamily= aXNamed->getName();
239 break;
241 case 1 : // body style
243 pTextListStylePtr = maBodyTextStylePtr;
244 aStyle = sOutline;
245 aFamily= aXNamed->getName();
246 break;
248 case 3 : // notes style
250 pTextListStylePtr = maNotesTextStylePtr;
251 aStyle = sTitle;
252 aFamily= aXNamed->getName();
253 break;
255 case 4 : // standard style
257 pTextListStylePtr = maOtherTextStylePtr;
258 aStyle = sStandard;
259 aFamily = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) );
260 break;
262 case 5 : // subtitle
264 pTextListStylePtr = maBodyTextStylePtr;
265 aStyle = sSubtitle;
266 aFamily = aXNamed->getName();
267 break;
270 Reference< container::XNameAccess > xFamilies;
271 if ( aXNameAccess->hasByName( aFamily ) )
273 if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
275 if ( xFamilies->hasByName( aStyle ) )
277 Reference< style::XStyle > aXStyle;
278 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
280 Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
281 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
282 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
283 if ( i == 1 /* BodyStyle */ )
285 for ( int nLevel = 1; nLevel < 5; nLevel++ )
288 sal_Char pOutline[ 9 ] = "outline1";
289 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
290 rtl::OUString sOutlineStyle( rtl::OUString::createFromAscii( pOutline ) );
291 if ( xFamilies->hasByName( sOutlineStyle ) )
293 xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
294 if( aXStyle.is() )
295 xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW );
298 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
299 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
309 catch( Exception& )