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: pptshapecontext.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 <com/sun/star/xml/sax/FastToken.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/beans/XMultiPropertySet.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/container/XNamed.hpp>
37 #include "oox/ppt/pptshape.hxx"
38 #include "oox/ppt/pptshapecontext.hxx"
39 #include "oox/ppt/pptshapepropertiescontext.hxx"
40 #include "oox/ppt/slidepersist.hxx"
41 #include "oox/drawingml/shapestylecontext.hxx"
42 #include "oox/core/namespaces.hxx"
43 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
44 #include "oox/drawingml/lineproperties.hxx"
45 #include "oox/drawingml/drawingmltypes.hxx"
46 #include "oox/drawingml/customshapegeometry.hxx"
47 #include "oox/drawingml/textbodycontext.hxx"
49 #include "properties.hxx"
52 using namespace oox::core
;
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::drawing
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::text
;
58 using namespace ::com::sun::star::xml::sax
;
60 namespace oox
{ namespace ppt
{
63 PPTShapeContext::PPTShapeContext( ContextHandler
& rParent
, const SlidePersistPtr pSlidePersistPtr
, oox::drawingml::ShapePtr pMasterShapePtr
, oox::drawingml::ShapePtr pShapePtr
)
64 : oox::drawingml::ShapeContext( rParent
, pMasterShapePtr
, pShapePtr
)
65 , mpSlidePersistPtr( pSlidePersistPtr
)
69 Reference
< XFastContextHandler
> PPTShapeContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
71 Reference
< XFastContextHandler
> xRet
;
73 switch( aElementToken
)
75 // nvSpPr CT_ShapeNonVisual begin
76 // case NMSP_PPT|XML_drElemPr:
78 case NMSP_PPT
|XML_cNvPr
:
79 mpShapePtr
->setId( xAttribs
->getOptionalValue( XML_id
) );
80 mpShapePtr
->setName( xAttribs
->getOptionalValue( XML_name
) );
84 sal_Int32
nSubType( xAttribs
->getOptionalValueToken( XML_type
, XML_obj
) );
85 mpShapePtr
->setSubType( nSubType
);
86 OUString
sIdx( xAttribs
->getOptionalValue( XML_idx
) );
87 sal_Bool bHasIdx
= sIdx
.getLength() > 0;
88 sal_Int32 nIdx
= sIdx
.toInt32();
89 mpShapePtr
->setIndex( nIdx
);
91 if ( nSubType
|| bHasIdx
)
93 PPTShape
* pPPTShapePtr
= dynamic_cast< PPTShape
* >( mpShapePtr
.get() );
96 oox::ppt::ShapeLocation eShapeLocation
= pPPTShapePtr
->getShapeLocation();
97 oox::drawingml::ShapePtr pPlaceholder
;
99 if ( bHasIdx
&& eShapeLocation
== Slide
)
101 // TODO: use id to shape map
102 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
103 if ( pMasterPersist
.get() )
104 pPlaceholder
= PPTShape::findPlaceholderByIndex( nIdx
, pMasterPersist
->getShapes()->getChildren() );
106 if ( !pPlaceholder
.get() && ( ( eShapeLocation
== Slide
) || ( eShapeLocation
== Layout
) ) )
108 // inheriting properties from placeholder objects by cloning shape
110 sal_Int32 nFirstPlaceholder
= 0;
111 sal_Int32 nSecondPlaceholder
= 0;
114 case XML_ctrTitle
: // slide/layout
115 nFirstPlaceholder
= XML_ctrTitle
;
116 nSecondPlaceholder
= XML_title
;
118 case XML_subTitle
: // slide/layout
119 nFirstPlaceholder
= XML_subTitle
;
120 nSecondPlaceholder
= XML_title
;
122 case XML_obj
: // slide/layout
123 nFirstPlaceholder
= XML_body
;
125 case XML_dt
: // slide/layout/master/notes/notesmaster/handoutmaster
126 case XML_sldNum
: // slide/layout/master/notes/notesmaster/handoutmaster
127 case XML_ftr
: // slide/layout/master/notes/notesmaster/handoutmaster
128 case XML_hdr
: // notes/notesmaster/handoutmaster
129 case XML_body
: // slide/layout/master/notes/notesmaster
130 case XML_title
: // slide/layout/master/
131 case XML_chart
: // slide/layout
132 case XML_tbl
: // slide/layout
133 case XML_clipArt
: // slide/layout
134 case XML_dgm
: // slide/layout
135 case XML_media
: // slide/layout
136 case XML_sldImg
: // notes/notesmaster
137 case XML_pic
: // slide/layout
138 nFirstPlaceholder
= nSubType
;
142 if ( nFirstPlaceholder
)
144 if ( eShapeLocation
== Layout
) // for layout objects the referenced object can be found within the same shape tree
145 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
, mpSlidePersistPtr
->getShapes()->getChildren() );
146 else if ( eShapeLocation
== Slide
) // normal slide shapes have to search within the corresponding master tree for referenced objects
148 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
149 if ( pMasterPersist
.get() )
150 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
, pMasterPersist
->getShapes()->getChildren() );
154 if ( pPlaceholder
.get() )
156 mpShapePtr
->applyShapeReference( *pPlaceholder
.get() );
157 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( pPlaceholder
.get() );
159 pPPTShape
->setReferenced( sal_True
);
160 pPPTShapePtr
->setPlaceholder( pPlaceholder
);
166 // nvSpPr CT_ShapeNonVisual end
168 case NMSP_PPT
|XML_spPr
:
169 xRet
= new PPTShapePropertiesContext( *this, *mpShapePtr
);
172 case NMSP_PPT
|XML_style
:
173 xRet
= new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr
);
176 case NMSP_PPT
|XML_txBody
:
178 oox::drawingml::TextBodyPtr
xTextBody( new oox::drawingml::TextBody
);
179 xTextBody
->getTextProperties().maPropertyMap
[ PROP_FontIndependentLineSpacing
] <<= static_cast< sal_Bool
>( sal_True
);
180 mpShapePtr
->setTextBody( xTextBody
);
181 xRet
= new oox::drawingml::TextBodyContext( *this, *xTextBody
);