bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / ximpbody.cxx
blobc1f8f0824faa785412693f9cc2aac884cc6ffdc8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ximpbody.hxx"
21 #include <xmloff/prstylei.hxx>
22 #include "ximpnote.hxx"
23 #include <com/sun/star/drawing/XDrawPage.hpp>
24 #include <com/sun/star/drawing/XDrawPages.hpp>
25 #include <com/sun/star/container/XNamed.hpp>
26 #include <com/sun/star/presentation/XPresentationPage.hpp>
27 #include "ximpstyl.hxx"
28 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
32 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include <xmloff/xmlprmap.hxx>
35 #include <xmloff/families.hxx>
36 #include "ximpshow.hxx"
37 #include "PropertySetMerger.hxx"
38 #include "animationimport.hxx"
39 #include <tools/debug.hxx>
41 using namespace ::com::sun::star;
43 SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
44 sal_uInt16 nPrfx, const OUString& rLocalName,
45 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
46 uno::Reference< drawing::XShapes >& rShapes)
47 : SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
48 , mbHadSMILNodes( false )
50 bool bHaveXmlId( false );
51 OUString sXmlId;
53 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
55 for(sal_Int16 i=0; i < nAttrCount; i++)
57 OUString sAttrName = xAttrList->getNameByIndex( i );
58 OUString aLocalName;
59 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
60 OUString sValue = xAttrList->getValueByIndex( i );
61 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
63 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
65 case XML_TOK_DRAWPAGE_NAME:
67 maName = sValue;
68 break;
70 case XML_TOK_DRAWPAGE_STYLE_NAME:
72 maStyleName = sValue;
73 break;
75 case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
77 maMasterPageName = sValue;
78 break;
80 case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
82 maPageLayoutName = sValue;
83 break;
85 case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
87 maUseHeaderDeclName = sValue;
88 break;
90 case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
92 maUseFooterDeclName = sValue;
93 break;
95 case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
97 maUseDateTimeDeclName = sValue;
98 break;
100 case XML_TOK_DRAWPAGE_DRAWID:
102 if (!bHaveXmlId) { sXmlId = sValue; }
104 break;
105 case XML_TOK_DRAWPAGE_XMLID:
107 sXmlId = sValue;
108 bHaveXmlId = true;
110 break;
111 case XML_TOK_DRAWPAGE_HREF:
113 maHREF = sValue;
114 break;
119 if (!sXmlId.isEmpty())
121 uno::Reference< uno::XInterface > const xRef( rShapes.get() );
122 GetImport().getInterfaceToIdentifierMapper().registerReference(
123 sXmlId, xRef );
125 GetImport().GetShapeImport()->startPage( rShapes );
127 uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
129 // set PageName?
130 if(!maName.isEmpty())
132 if(xShapeDrawPage.is())
134 uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
135 if(xNamed.is())
136 xNamed->setName(maName);
140 // set MasterPage?
141 if(!maMasterPageName.isEmpty())
143 // #85906# Code for setting masterpage needs complete rework
144 // since GetSdImport().GetMasterStylesContext() gives always ZERO
145 // because of content/style file split. Now the nechanism is to
146 // compare the wanted masterpage-name with the existing masterpages
147 // which were loaded and created in the styles section loading.
148 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
149 uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
150 uno::Reference< drawing::XDrawPage > xMasterPage;
152 if(xDrawPage.is() && xMasterPages.is())
154 bool bDone(false);
155 OUString sDisplayName( rImport.GetStyleDisplayName(
156 XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
158 for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
160 uno::Any aAny(xMasterPages->getByIndex(a));
161 aAny >>= xMasterPage;
163 if(xMasterPage.is())
165 uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
166 if(xMasterNamed.is())
168 OUString sMasterPageName = xMasterNamed->getName();
170 if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
172 xDrawPage->setMasterPage(xMasterPage);
173 bDone = true;
179 DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
183 SetStyle( maStyleName );
185 if( !maHREF.isEmpty() )
187 uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
188 if( xProps.is() )
190 sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
191 if( nIndex != -1 )
193 OUString aFileName( maHREF.copy( 0, nIndex ) );
194 OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
196 maHREF = GetImport().GetAbsoluteReference( aFileName );
197 maHREF += OUString(static_cast<sal_Unicode>('#'));
198 maHREF += aBookmarkName;
201 xProps->setPropertyValue("BookmarkURL", uno::makeAny( maHREF ) );
205 SetLayout();
207 DeleteAllShapes();
210 SdXMLDrawPageContext::~SdXMLDrawPageContext()
214 SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
215 const OUString& rLocalName,
216 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
218 SvXMLImportContext *pContext = 0L;
219 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
221 // some special objects inside draw:page context
222 switch(rTokenMap.Get(nPrefix, rLocalName))
224 case XML_TOK_DRAWPAGE_NOTES:
226 if( GetSdImport().IsImpress() )
228 // get notes page
229 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
230 if(xPresPage.is())
232 uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
233 if(xNotesDrawPage.is())
235 uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
236 if(xNewShapes.is())
238 // presentation:notes inside draw:page context
239 pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
244 break;
246 case XML_TOK_DRAWPAGE_PAR:
247 case XML_TOK_DRAWPAGE_SEQ:
249 if( GetSdImport().IsImpress() )
251 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
252 if(xNodeSupplier.is())
254 pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
255 mbHadSMILNodes = true;
258 break;
262 // call parent when no own context was created
263 if(!pContext)
264 pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
266 return pContext;
269 void SdXMLDrawPageContext::EndElement()
271 SdXMLGenericPageContext::EndElement();
272 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
274 if( mbHadSMILNodes )
276 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
277 uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
278 if(xNodeSupplier.is())
279 xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
283 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
284 sal_uInt16 nPrfx, const OUString& rLocalName )
285 : SvXMLImportContext( rImport, nPrfx, rLocalName )
289 SdXMLBodyContext::~SdXMLBodyContext()
293 SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
294 sal_uInt16 nPrefix,
295 const OUString& rLocalName,
296 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
298 SvXMLImportContext *pContext = 0L;
299 const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
301 switch(rTokenMap.Get(nPrefix, rLocalName))
303 case XML_TOK_BODY_HEADER_DECL:
304 case XML_TOK_BODY_FOOTER_DECL:
305 case XML_TOK_BODY_DATE_TIME_DECL:
307 pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
308 break;
310 case XML_TOK_BODY_PAGE:
312 // only read the first page in preview mode
313 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
315 // import this page
316 uno::Reference< drawing::XDrawPage > xNewDrawPage;
317 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
319 if( !xDrawPages.is() )
320 break;
322 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
324 // new page, create and insert
325 xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
327 else
329 // existing page, use it
330 uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
331 aAny >>= xNewDrawPage;
334 // increment global import page counter
335 GetSdImport().IncrementNewPageCount();
337 if(xNewDrawPage.is())
339 uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
340 if(xNewShapes.is())
342 // draw:page inside office:body context
343 pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
344 xNewShapes);
348 break;
350 case XML_TOK_BODY_SETTINGS:
352 pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
356 // call parent when no own context was created
357 if(!pContext)
358 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
360 return pContext;
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */