merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ppt / pptgraphicshapecontext.cxx
blob97e104cf91dd68a89f6342296cf90a6aa206ed50
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 $
10 * $Revision: 1.6 $
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/pptgraphicshapecontext.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"
48 #include "tokens.hxx"
50 using rtl::OUString;
51 using namespace oox::core;
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::drawing;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::text;
57 using namespace ::com::sun::star::xml::sax;
59 namespace oox { namespace ppt {
61 // CT_Shape
62 PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
63 : oox::drawingml::GraphicShapeContext( rParent, pMasterShapePtr, pShapePtr )
64 , mpSlidePersistPtr( pSlidePersistPtr )
68 static oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
70 oox::drawingml::ShapePtr aShapePtr;
71 std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
72 while( aRevIter != rShapes.rend() )
74 if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
76 aShapePtr = *aRevIter;
77 break;
79 std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
80 aShapePtr = findPlaceholder( nMasterPlaceholder, rChildren );
81 if ( aShapePtr.get() )
82 break;
83 aRevIter++;
85 return aShapePtr;
88 static oox::drawingml::ShapePtr findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes )
90 oox::drawingml::ShapePtr aShapePtr;
91 std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
92 while( aRevIter != rShapes.rend() )
94 if ( (*aRevIter)->getIndex() == nIdx )
96 aShapePtr = *aRevIter;
97 break;
99 std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
100 aShapePtr = findPlaceholderByIndex( nIdx, rChildren );
101 if ( aShapePtr.get() )
102 break;
103 aRevIter++;
105 return aShapePtr;
108 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
109 static oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
111 oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, rShapes );
112 return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, rShapes );
115 Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
117 Reference< XFastContextHandler > xRet;
119 switch( aElementToken )
121 // nvSpPr CT_ShapeNonVisual begin
122 // case NMSP_PPT|XML_drElemPr:
123 // break;
124 case NMSP_PPT|XML_cNvPr:
125 mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
126 mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
127 break;
128 case NMSP_PPT|XML_ph:
130 sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
131 mpShapePtr->setSubType( nSubType );
132 OUString sIdx( xAttribs->getOptionalValue( XML_idx ) );
133 sal_Bool bHasIdx = sIdx.getLength() > 0;
134 sal_Int32 nIdx = sIdx.toInt32();
135 mpShapePtr->setIndex( nIdx );
137 if ( nSubType || bHasIdx )
139 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
140 if ( pPPTShapePtr )
142 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
143 oox::drawingml::ShapePtr pPlaceholder;
145 if ( bHasIdx && eShapeLocation == Slide )
147 // TODO: use id to shape map
148 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
149 if ( pMasterPersist.get() )
150 pPlaceholder = findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
152 if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
154 // inheriting properties from placeholder objects by cloning shape
156 sal_Int32 nFirstPlaceholder = 0;
157 sal_Int32 nSecondPlaceholder = 0;
158 switch( nSubType )
160 case XML_ctrTitle : // slide/layout
161 nFirstPlaceholder = XML_ctrTitle;
162 nSecondPlaceholder = XML_title;
163 break;
164 case XML_subTitle : // slide/layout
165 nFirstPlaceholder = XML_subTitle;
166 nSecondPlaceholder = XML_title;
167 break;
168 case XML_obj : // slide/layout
169 nFirstPlaceholder = XML_body;
170 break;
171 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
172 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
173 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
174 case XML_hdr : // notes/notesmaster/handoutmaster
175 case XML_body : // slide/layout/master/notes/notesmaster
176 case XML_title : // slide/layout/master/
177 case XML_chart : // slide/layout
178 case XML_tbl : // slide/layout
179 case XML_clipArt : // slide/layout
180 case XML_dgm : // slide/layout
181 case XML_media : // slide/layout
182 case XML_sldImg : // notes/notesmaster
183 case XML_pic : // slide/layout
184 nFirstPlaceholder = nSubType;
185 default:
186 break;
188 if ( nFirstPlaceholder )
190 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
191 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, mpSlidePersistPtr->getShapes()->getChildren() );
192 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
194 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
195 if ( pMasterPersist.get() )
196 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pMasterPersist->getShapes()->getChildren() );
200 if ( pPlaceholder.get() )
202 mpShapePtr->applyShapeReference( *pPlaceholder.get() );
203 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
204 if ( pPPTShape )
205 pPPTShape->setReferenced( sal_True );
206 pPPTShapePtr->setPlaceholder( pPlaceholder );
210 break;
212 // nvSpPr CT_ShapeNonVisual end
214 case NMSP_PPT|XML_spPr:
215 xRet = new PPTShapePropertiesContext( *this, *mpShapePtr );
216 break;
218 case NMSP_PPT|XML_style:
219 xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
220 break;
222 case NMSP_PPT|XML_txBody:
224 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
225 mpShapePtr->setTextBody( xTextBody );
226 xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
227 break;
231 if( !xRet.is() )
232 xRet.set( GraphicShapeContext::createFastChildContext( aElementToken, xAttribs ) );
234 return xRet;