xref: /trunk/main/oox/source/ppt/slidepersist.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/ppt/timenode.hxx"
29*cdf0e10cSrcweir #include "oox/ppt/pptshape.hxx"
30*cdf0e10cSrcweir #include "oox/ppt/slidepersist.hxx"
31*cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx"
32*cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx"
33*cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
34*cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx"
35*cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace ::com::sun::star;
44*cdf0e10cSrcweir using namespace ::oox::core;
45*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
47*cdf0e10cSrcweir using namespace ::com::sun::star::container;
48*cdf0e10cSrcweir using namespace ::com::sun::star::animations;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace oox { namespace ppt {
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir SlidePersist::SlidePersist( XmlFilterBase& rFilter, sal_Bool bMaster, sal_Bool bNotes,
53*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage,
54*cdf0e10cSrcweir         oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
55*cdf0e10cSrcweir : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
56*cdf0e10cSrcweir , mxPage( rxPage )
57*cdf0e10cSrcweir , maShapesPtr( pShapesPtr )
58*cdf0e10cSrcweir , mnLayoutValueToken( 0 )
59*cdf0e10cSrcweir , mbMaster( bMaster )
60*cdf0e10cSrcweir , mbNotes ( bNotes )
61*cdf0e10cSrcweir , maDefaultTextStylePtr( pDefaultTextStyle )
62*cdf0e10cSrcweir , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
63*cdf0e10cSrcweir , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
64*cdf0e10cSrcweir , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
65*cdf0e10cSrcweir , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     if ( pDefaultTextStyle )
68*cdf0e10cSrcweir     {
69*cdf0e10cSrcweir     /*
70*cdf0e10cSrcweir         maTitleTextStylePtr->apply( *pDefaultTextStyle.get() );
71*cdf0e10cSrcweir         maBodyTextStylePtr->apply( *pDefaultTextStyle.get() );
72*cdf0e10cSrcweir         maNotesTextStylePtr->apply( *pDefaultTextStyle.get() );
73*cdf0e10cSrcweir     */
74*cdf0e10cSrcweir         maOtherTextStylePtr->apply( *pDefaultTextStyle.get() );
75*cdf0e10cSrcweir     }
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir SlidePersist::~SlidePersist()
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir sal_Int16 SlidePersist::getLayoutFromValueToken()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     sal_Int16 nLayout = 20;     // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
86*cdf0e10cSrcweir     switch( mnLayoutValueToken )
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         case XML_blank:             nLayout = 20; break;
89*cdf0e10cSrcweir         case XML_chart:             nLayout =  2; break;
90*cdf0e10cSrcweir         case XML_chartAndTx:        nLayout =  7; break;
91*cdf0e10cSrcweir         case XML_clipArtAndTx:      nLayout =  9; break;
92*cdf0e10cSrcweir         case XML_clipArtAndVertTx:  nLayout = 24; break;
93*cdf0e10cSrcweir         case XML_fourObj:           nLayout = 18; break;
94*cdf0e10cSrcweir         case XML_obj:               nLayout = 11; break;
95*cdf0e10cSrcweir         case XML_objAndTx:          nLayout = 13; break;
96*cdf0e10cSrcweir         case XML_objOverTx:         nLayout = 14; break;
97*cdf0e10cSrcweir         case XML_tbl:               nLayout =  8; break;
98*cdf0e10cSrcweir         case XML_title:             nLayout =  0; break;
99*cdf0e10cSrcweir         case XML_titleOnly:         nLayout = 19; break;
100*cdf0e10cSrcweir         case XML_twoObj:
101*cdf0e10cSrcweir         case XML_twoColTx:          nLayout =  3; break;
102*cdf0e10cSrcweir         case XML_twoObjAndTx:       nLayout = 15; break;
103*cdf0e10cSrcweir         case XML_twoObjOverTx:      nLayout = 16; break;
104*cdf0e10cSrcweir         case XML_tx:                nLayout =  1; break;
105*cdf0e10cSrcweir         case XML_txAndChart:        nLayout =  4; break;
106*cdf0e10cSrcweir         case XML_txAndClipArt:      nLayout =  6; break;
107*cdf0e10cSrcweir         case XML_txAndMedia:        nLayout =  6; break;
108*cdf0e10cSrcweir         case XML_txAndObj:          nLayout = 10; break;
109*cdf0e10cSrcweir         case XML_txAndTwoObj:       nLayout = 12; break;
110*cdf0e10cSrcweir         case XML_txOverObj:         nLayout = 17; break;
111*cdf0e10cSrcweir         case XML_vertTitleAndTx:    nLayout = 22; break;
112*cdf0e10cSrcweir         case XML_vertTitleAndTxOverChart: nLayout = 21; break;
113*cdf0e10cSrcweir         case XML_vertTx:            nLayout = 23; break;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         case XML_twoTxTwoObj:
116*cdf0e10cSrcweir         case XML_twoObjAndObj:
117*cdf0e10cSrcweir         case XML_objTx:
118*cdf0e10cSrcweir         case XML_picTx:
119*cdf0e10cSrcweir         case XML_secHead:
120*cdf0e10cSrcweir         case XML_objOnly:
121*cdf0e10cSrcweir         case XML_objAndTwoObj:
122*cdf0e10cSrcweir         case XML_mediaAndTx:
123*cdf0e10cSrcweir         case XML_dgm:
124*cdf0e10cSrcweir         case XML_cust:
125*cdf0e10cSrcweir         default:
126*cdf0e10cSrcweir             nLayout = 20;
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     return nLayout;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     applyTextStyles( rFilterBase );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     Reference< XShapes > xShapes( getPage(), UNO_QUERY );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
138*cdf0e10cSrcweir     std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
139*cdf0e10cSrcweir     while( aShapesIter != rShapes.end() )
140*cdf0e10cSrcweir     {
141*cdf0e10cSrcweir         std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
142*cdf0e10cSrcweir         std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
143*cdf0e10cSrcweir         while( aChildIter != rChildren.end() )
144*cdf0e10cSrcweir         {
145*cdf0e10cSrcweir             PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
146*cdf0e10cSrcweir             if ( pPPTShape )
147*cdf0e10cSrcweir                 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, 0, &getShapeMap() );
148*cdf0e10cSrcweir             else
149*cdf0e10cSrcweir                 (*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, 0, &getShapeMap() );
150*cdf0e10cSrcweir             aChildIter++;
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
155*cdf0e10cSrcweir     if( xNodeSupplier.is() )
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
158*cdf0e10cSrcweir         if( xNode.is() && !maTimeNodeList.empty() )
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir             SlidePersistPtr pSlidePtr( shared_from_this() );
161*cdf0e10cSrcweir             TimeNodePtr pNode(maTimeNodeList.front());
162*cdf0e10cSrcweir             OSL_ENSURE( pNode, "pNode" );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir             pNode->setNode( rFilterBase, xNode, pSlidePtr );
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir     }
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     if ( mpBackgroundPropertiesPtr )
172*cdf0e10cSrcweir     {
173*cdf0e10cSrcweir         sal_Int32 nPhClr = maBackgroundColor.isUsed() ?
174*cdf0e10cSrcweir             maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         ::oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
177*cdf0e10cSrcweir         mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
178*cdf0e10cSrcweir         PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
179*cdf0e10cSrcweir     }
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
183*cdf0e10cSrcweir     oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
186*cdf0e10cSrcweir     if( pTextParagraphPropertiesPtr == NULL )
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         // no properties. return
189*cdf0e10cSrcweir         return;
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     PropertySet aPropSet( rxPropSet );
195*cdf0e10cSrcweir     aPropSet.setProperties( rTextParagraphPropertyMap );
196*cdf0e10cSrcweir     pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     if ( mbMaster )
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir         try
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
206*cdf0e10cSrcweir             Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
207*cdf0e10cSrcweir             Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir             if ( aXNameAccess.is() && aXNamed.is() )
210*cdf0e10cSrcweir             {
211*cdf0e10cSrcweir                 oox::drawingml::TextListStylePtr pTextListStylePtr;
212*cdf0e10cSrcweir                 rtl::OUString aStyle;
213*cdf0e10cSrcweir                 rtl::OUString aFamily;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir                 const rtl::OUString sOutline( RTL_CONSTASCII_USTRINGPARAM( "outline1" ) );
216*cdf0e10cSrcweir                 const rtl::OUString sTitle( RTL_CONSTASCII_USTRINGPARAM( "title" ) );
217*cdf0e10cSrcweir                 const rtl::OUString sStandard( RTL_CONSTASCII_USTRINGPARAM( "standard" ) );
218*cdf0e10cSrcweir                 const rtl::OUString sSubtitle( RTL_CONSTASCII_USTRINGPARAM( "subtitle" ) );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir                 for( int i = 0; i < 4; i++ )    // todo: aggregation of bodystyle (subtitle)
221*cdf0e10cSrcweir                 {
222*cdf0e10cSrcweir                     switch( i )
223*cdf0e10cSrcweir                     {
224*cdf0e10cSrcweir                         case 0 :    // title style
225*cdf0e10cSrcweir                         {
226*cdf0e10cSrcweir                             pTextListStylePtr = maTitleTextStylePtr;
227*cdf0e10cSrcweir                             aStyle = sTitle;
228*cdf0e10cSrcweir                             aFamily= aXNamed->getName();
229*cdf0e10cSrcweir                             break;
230*cdf0e10cSrcweir                         }
231*cdf0e10cSrcweir                         case 1 :    // body style
232*cdf0e10cSrcweir                         {
233*cdf0e10cSrcweir                             pTextListStylePtr = maBodyTextStylePtr;
234*cdf0e10cSrcweir                             aStyle = sOutline;
235*cdf0e10cSrcweir                             aFamily= aXNamed->getName();
236*cdf0e10cSrcweir                             break;
237*cdf0e10cSrcweir                         }
238*cdf0e10cSrcweir                         case 3 :    // notes style
239*cdf0e10cSrcweir                         {
240*cdf0e10cSrcweir                             pTextListStylePtr = maNotesTextStylePtr;
241*cdf0e10cSrcweir                             aStyle = sTitle;
242*cdf0e10cSrcweir                             aFamily= aXNamed->getName();
243*cdf0e10cSrcweir                             break;
244*cdf0e10cSrcweir                         }
245*cdf0e10cSrcweir                         case 4 :    // standard style
246*cdf0e10cSrcweir                         {
247*cdf0e10cSrcweir                             pTextListStylePtr = maOtherTextStylePtr;
248*cdf0e10cSrcweir                             aStyle = sStandard;
249*cdf0e10cSrcweir                             aFamily = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) );
250*cdf0e10cSrcweir                             break;
251*cdf0e10cSrcweir                         }
252*cdf0e10cSrcweir                         case 5 :    // subtitle
253*cdf0e10cSrcweir                         {
254*cdf0e10cSrcweir                             pTextListStylePtr = maBodyTextStylePtr;
255*cdf0e10cSrcweir                             aStyle = sSubtitle;
256*cdf0e10cSrcweir                             aFamily = aXNamed->getName();
257*cdf0e10cSrcweir                             break;
258*cdf0e10cSrcweir                         }
259*cdf0e10cSrcweir                     }
260*cdf0e10cSrcweir                     Reference< container::XNameAccess > xFamilies;
261*cdf0e10cSrcweir                     if ( aXNameAccess->hasByName( aFamily ) )
262*cdf0e10cSrcweir                     {
263*cdf0e10cSrcweir                         if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
264*cdf0e10cSrcweir                         {
265*cdf0e10cSrcweir                             if ( xFamilies->hasByName( aStyle ) )
266*cdf0e10cSrcweir                             {
267*cdf0e10cSrcweir                                 Reference< style::XStyle > aXStyle;
268*cdf0e10cSrcweir                                 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
269*cdf0e10cSrcweir                                 {
270*cdf0e10cSrcweir                                     Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
271*cdf0e10cSrcweir                                     setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
272*cdf0e10cSrcweir                                     setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
273*cdf0e10cSrcweir                                     if ( i == 1 /* BodyStyle */ )
274*cdf0e10cSrcweir                                     {
275*cdf0e10cSrcweir                                         for ( int nLevel = 1; nLevel < 5; nLevel++ )
276*cdf0e10cSrcweir                                         {
277*cdf0e10cSrcweir                                             {
278*cdf0e10cSrcweir                                                 sal_Char pOutline[ 9 ] = "outline1";
279*cdf0e10cSrcweir                                                 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
280*cdf0e10cSrcweir                                                 rtl::OUString sOutlineStyle( rtl::OUString::createFromAscii( pOutline ) );
281*cdf0e10cSrcweir                                                 if ( xFamilies->hasByName( sOutlineStyle ) )
282*cdf0e10cSrcweir                                                 {
283*cdf0e10cSrcweir                                                     xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
284*cdf0e10cSrcweir                                                     if( aXStyle.is() )
285*cdf0e10cSrcweir                                                         xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW );
286*cdf0e10cSrcweir                                                 }
287*cdf0e10cSrcweir                                             }
288*cdf0e10cSrcweir                                             setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
289*cdf0e10cSrcweir                                             setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
290*cdf0e10cSrcweir                                         }
291*cdf0e10cSrcweir                                     }
292*cdf0e10cSrcweir                                 }
293*cdf0e10cSrcweir                             }
294*cdf0e10cSrcweir                         }
295*cdf0e10cSrcweir                     }
296*cdf0e10cSrcweir                 }
297*cdf0e10cSrcweir             }
298*cdf0e10cSrcweir         }
299*cdf0e10cSrcweir         catch( Exception& )
300*cdf0e10cSrcweir         {
301*cdf0e10cSrcweir         }
302*cdf0e10cSrcweir     }
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir } }
306*cdf0e10cSrcweir 
307