merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / ximpbody.cxx
blob71aa82da490a44c7ce106b62ce095487f5c44b47
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ximpbody.cxx,v $
10 * $Revision: 1.36 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "ximpbody.hxx"
34 #include <xmloff/prstylei.hxx>
35 #include "ximpnote.hxx"
36 #include <com/sun/star/drawing/XDrawPage.hpp>
37 #include <com/sun/star/drawing/XDrawPages.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 #include <com/sun/star/presentation/XPresentationPage.hpp>
40 #include "ximpstyl.hxx"
41 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
45 #include "unointerfacetouniqueidentifiermapper.hxx"
46 #include <xmloff/xmluconv.hxx>
47 #include <xmloff/xmlprmap.hxx>
48 #include <xmloff/families.hxx>
49 #include "ximpshow.hxx"
50 #include "PropertySetMerger.hxx"
51 #include "animationimport.hxx"
52 #include <tools/string.hxx>
54 using ::rtl::OUString;
55 using ::rtl::OUStringBuffer;
57 using namespace ::com::sun::star;
59 //////////////////////////////////////////////////////////////////////////////
61 SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
62 USHORT nPrfx, const OUString& rLocalName,
63 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
64 uno::Reference< drawing::XShapes >& rShapes)
65 : SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
66 , mbHadSMILNodes( false )
68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
70 for(sal_Int16 i=0; i < nAttrCount; i++)
72 OUString sAttrName = xAttrList->getNameByIndex( i );
73 OUString aLocalName;
74 USHORT nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
75 OUString sValue = xAttrList->getValueByIndex( i );
76 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
78 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
80 case XML_TOK_DRAWPAGE_NAME:
82 maName = sValue;
83 break;
85 case XML_TOK_DRAWPAGE_STYLE_NAME:
87 maStyleName = sValue;
88 break;
90 case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
92 maMasterPageName = sValue;
93 break;
95 case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
97 maPageLayoutName = sValue;
98 break;
100 case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
102 maUseHeaderDeclName = sValue;
103 break;
105 case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
107 maUseFooterDeclName = sValue;
108 break;
110 case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
112 maUseDateTimeDeclName = sValue;
113 break;
116 case XML_TOK_DRAWPAGE_ID:
118 uno::Reference< uno::XInterface > xRef( rShapes.get() );
119 GetImport().getInterfaceToIdentifierMapper().registerReference( sValue, xRef );
120 break;
122 case XML_TOK_DRAWPAGE_HREF:
124 maHREF = sValue;
125 break;
130 GetImport().GetShapeImport()->startPage( rShapes );
132 uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
134 // set PageName?
135 if(maName.getLength())
137 if(xShapeDrawPage.is())
139 uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
140 if(xNamed.is())
141 xNamed->setName(maName);
145 // set MasterPage?
146 if(maMasterPageName.getLength())
148 // #85906# Code for setting masterpage needs complete rework
149 // since GetSdImport().GetMasterStylesContext() gives always ZERO
150 // because of content/style file split. Now the nechanism is to
151 // compare the wanted masterpage-name with the existing masterpages
152 // which were loaded and created in the styles section loading.
153 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
154 uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
155 uno::Reference< drawing::XDrawPage > xMasterPage;
157 if(xDrawPage.is() && xMasterPages.is())
159 sal_Bool bDone(FALSE);
160 OUString sDisplayName( rImport.GetStyleDisplayName(
161 XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
163 for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
165 uno::Any aAny(xMasterPages->getByIndex(a));
166 aAny >>= xMasterPage;
168 if(xMasterPage.is())
170 uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
171 if(xMasterNamed.is())
173 OUString sMasterPageName = xMasterNamed->getName();
175 if(sMasterPageName.getLength() &&
176 sMasterPageName.equals(sDisplayName))
178 xDrawPage->setMasterPage(xMasterPage);
179 bDone = TRUE;
185 DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
189 SetStyle( maStyleName );
191 if( maHREF.getLength() )
193 uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
194 if( xProps.is() )
196 sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
197 if( nIndex != -1 )
199 OUString aFileName( maHREF.copy( 0, nIndex ) );
200 OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
202 maHREF = GetImport().GetAbsoluteReference( aFileName );
203 maHREF += String( (sal_Unicode)'#' );
204 maHREF += aBookmarkName;
207 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BookmarkURL" ) ), uno::makeAny( maHREF ) );
211 SetLayout();
213 DeleteAllShapes();
216 //////////////////////////////////////////////////////////////////////////////
218 SdXMLDrawPageContext::~SdXMLDrawPageContext()
222 //////////////////////////////////////////////////////////////////////////////
224 SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( USHORT nPrefix,
225 const OUString& rLocalName,
226 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
228 SvXMLImportContext *pContext = 0L;
229 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
231 // some special objects inside draw:page context
232 switch(rTokenMap.Get(nPrefix, rLocalName))
234 case XML_TOK_DRAWPAGE_NOTES:
236 if( GetSdImport().IsImpress() )
238 // get notes page
239 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
240 if(xPresPage.is())
242 uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
243 if(xNotesDrawPage.is())
245 uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
246 if(xNewShapes.is())
248 // presentation:notes inside draw:page context
249 pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
254 break;
256 case XML_TOK_DRAWPAGE_PAR:
257 case XML_TOK_DRAWPAGE_SEQ:
259 if( GetSdImport().IsImpress() )
261 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
262 if(xNodeSupplier.is())
264 pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
265 mbHadSMILNodes = true;
268 break;
272 // call parent when no own context was created
273 if(!pContext)
274 pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
276 return pContext;
279 void SdXMLDrawPageContext::EndElement()
281 SdXMLGenericPageContext::EndElement();
282 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
284 if( mbHadSMILNodes )
286 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
287 uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
288 if(xNodeSupplier.is())
289 xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
293 //////////////////////////////////////////////////////////////////////////////
294 //////////////////////////////////////////////////////////////////////////////
296 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
297 USHORT nPrfx, const OUString& rLocalName )
298 : SvXMLImportContext( rImport, nPrfx, rLocalName )
302 //////////////////////////////////////////////////////////////////////////////
304 SdXMLBodyContext::~SdXMLBodyContext()
308 //////////////////////////////////////////////////////////////////////////////
310 SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
311 USHORT nPrefix,
312 const OUString& rLocalName,
313 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
315 SvXMLImportContext *pContext = 0L;
316 const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
318 switch(rTokenMap.Get(nPrefix, rLocalName))
320 case XML_TOK_BODY_HEADER_DECL:
321 case XML_TOK_BODY_FOOTER_DECL:
322 case XML_TOK_BODY_DATE_TIME_DECL:
324 pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
325 break;
327 case XML_TOK_BODY_PAGE:
329 // only read the first page in preview mode
330 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
332 // import this page
333 uno::Reference< drawing::XDrawPage > xNewDrawPage;
334 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
336 if( !xDrawPages.is() )
337 break;
339 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
341 // new page, create and insert
342 xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
344 else
346 // existing page, use it
347 uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
348 aAny >>= xNewDrawPage;
351 // increment global import page counter
352 GetSdImport().IncrementNewPageCount();
354 if(xNewDrawPage.is())
356 uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
357 if(xNewShapes.is())
359 // draw:page inside office:body context
360 pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
361 xNewShapes);
365 break;
367 case XML_TOK_BODY_SETTINGS:
369 pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
373 // call parent when no own context was created
374 if(!pContext)
375 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
377 return pContext;