nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / draw / ximpbody.cxx
blob1fb5568281999860058f08b73cbbc535220e3b6f
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/xmlnamespace.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/families.hxx>
34 #include "ximpshow.hxx"
35 #include "layerimp.hxx"
36 #include <animationimport.hxx>
37 #include <sal/log.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::xmloff::token;
42 SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
43 const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
44 uno::Reference< drawing::XShapes > const & rShapes)
45 : SdXMLGenericPageContext( rImport, xAttrList, rShapes )
46 , mbHadSMILNodes( false )
48 bool bHaveXmlId( false );
49 OUString sXmlId, sStyleName, sContextName, sMasterPageName, sHREF;
51 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
53 OUString sValue = aIter.toString();
54 switch(aIter.getToken())
56 case XML_ELEMENT(DRAW, XML_NAME):
58 sContextName = sValue;
59 break;
61 case XML_ELEMENT(DRAW, XML_STYLE_NAME):
63 sStyleName = sValue;
64 break;
66 case XML_ELEMENT(DRAW, XML_MASTER_PAGE_NAME):
68 sMasterPageName = sValue;
69 break;
71 case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
72 case XML_ELEMENT(PRESENTATION_SO52, XML_PRESENTATION_PAGE_LAYOUT_NAME):
73 case XML_ELEMENT(PRESENTATION_OOO, XML_PRESENTATION_PAGE_LAYOUT_NAME):
75 maPageLayoutName = sValue;
76 break;
78 case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
79 case XML_ELEMENT(PRESENTATION_SO52, XML_USE_HEADER_NAME):
80 case XML_ELEMENT(PRESENTATION_OOO, XML_USE_HEADER_NAME):
82 maUseHeaderDeclName = sValue;
83 break;
85 case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
86 case XML_ELEMENT(PRESENTATION_SO52, XML_USE_FOOTER_NAME):
87 case XML_ELEMENT(PRESENTATION_OOO, XML_USE_FOOTER_NAME):
89 maUseFooterDeclName = sValue;
90 break;
92 case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
93 case XML_ELEMENT(PRESENTATION_SO52, XML_USE_DATE_TIME_NAME):
94 case XML_ELEMENT(PRESENTATION_OOO, XML_USE_DATE_TIME_NAME):
96 maUseDateTimeDeclName = sValue;
97 break;
99 case XML_ELEMENT(DRAW, XML_ID):
101 if (!bHaveXmlId) { sXmlId = sValue; }
103 break;
104 case XML_ELEMENT(XML, XML_ID):
106 sXmlId = sValue;
107 bHaveXmlId = true;
109 break;
110 case XML_ELEMENT(XLINK, XML_HREF):
112 sHREF = sValue;
113 break;
118 if (!sXmlId.isEmpty())
120 uno::Reference< uno::XInterface > const xRef( rShapes.get() );
121 GetImport().getInterfaceToIdentifierMapper().registerReference(
122 sXmlId, xRef );
124 GetImport().GetShapeImport()->startPage( rShapes );
126 uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
128 // set PageName?
129 if(!sContextName.isEmpty())
131 if(xShapeDrawPage.is())
133 uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
134 if(xNamed.is())
135 xNamed->setName(sContextName);
139 // set MasterPage?
140 if(!sMasterPageName.isEmpty())
142 // #85906# Code for setting masterpage needs complete rework
143 // since GetSdImport().GetMasterStylesContext() gives always ZERO
144 // because of content/style file split. Now the mechanism is to
145 // compare the wanted masterpage-name with the existing masterpages
146 // which were loaded and created in the styles section loading.
147 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
148 uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
149 uno::Reference< drawing::XDrawPage > xMasterPage;
151 if(xDrawPage.is() && xMasterPages.is())
153 bool bDone(false);
154 OUString sDisplayName( rImport.GetStyleDisplayName(
155 XmlStyleFamily::MASTER_PAGE, sMasterPageName ) );
157 for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
159 uno::Any aAny(xMasterPages->getByIndex(a));
160 aAny >>= xMasterPage;
162 if(xMasterPage.is())
164 uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
165 if(xMasterNamed.is())
167 OUString sLoopMasterPageName = xMasterNamed->getName();
169 if(!sLoopMasterPageName.isEmpty() && sLoopMasterPageName == sDisplayName)
171 xDrawPage->setMasterPage(xMasterPage);
172 bDone = true;
178 SAL_WARN_IF( !bDone, "xmloff", "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a master slide!" );
182 SetStyle( sStyleName );
184 if( !sHREF.isEmpty() )
186 uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
187 if( xProps.is() )
189 sal_Int32 nIndex = sHREF.lastIndexOf( '#' );
190 if( nIndex != -1 )
192 OUString aFileName( sHREF.copy( 0, nIndex ) );
193 OUString aBookmarkName( sHREF.copy( nIndex+1 ) );
195 sHREF = GetImport().GetAbsoluteReference( aFileName ) + "#"
196 + aBookmarkName;
199 xProps->setPropertyValue("BookmarkURL", uno::makeAny( sHREF ) );
203 SetLayout();
205 DeleteAllShapes();
208 SdXMLDrawPageContext::~SdXMLDrawPageContext()
212 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawPageContext::createFastChildContext(sal_Int32 nElement,
213 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
215 // some special objects inside draw:page context
216 switch(nElement)
218 case XML_ELEMENT(PRESENTATION, XML_NOTES):
219 case XML_ELEMENT(PRESENTATION_SO52, XML_NOTES):
220 case XML_ELEMENT(PRESENTATION_OOO, XML_NOTES):
222 if( GetSdImport().IsImpress() )
224 // get notes page
225 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
226 if(xPresPage.is())
228 uno::Reference< drawing::XDrawPage > xNotesDrawPage = xPresPage->getNotesPage();
229 if(xNotesDrawPage.is())
231 // presentation:notes inside draw:page context
232 return new SdXMLNotesContext( GetSdImport(), xAttrList, xNotesDrawPage);
236 break;
238 case XML_ELEMENT(ANIMATION, XML_PAR):
239 case XML_ELEMENT(ANIMATION_OOO, XML_PAR):
240 case XML_ELEMENT(ANIMATION, XML_SEQ):
241 case XML_ELEMENT(ANIMATION_OOO, XML_SEQ):
243 if( GetSdImport().IsImpress() )
245 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
246 if(xNodeSupplier.is())
248 mbHadSMILNodes = true;
249 return new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nElement, xAttrList );
252 break;
254 case XML_ELEMENT(DRAW, XML_LAYER_SET):
256 return new SdXMLLayerSetContext( GetSdImport() );
260 // call parent when no own context was created
261 return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList);
264 void SdXMLDrawPageContext::endFastElement(sal_Int32 nElement)
266 SdXMLGenericPageContext::endFastElement(nElement);
267 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
269 if( mbHadSMILNodes )
271 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
272 uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
273 if(xNodeSupplier.is())
274 xmloff::AnimationNodeContext::postProcessRootNode( xNodeSupplier->getAnimationNode(), xPageProps );
278 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport )
279 : SvXMLImportContext( rImport )
283 SdXMLBodyContext::~SdXMLBodyContext()
287 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLBodyContext::createFastChildContext(
288 sal_Int32 nElement,
289 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
291 switch (nElement)
293 case XML_ELEMENT(PRESENTATION, XML_SETTINGS):
294 case XML_ELEMENT(PRESENTATION_SO52, XML_SETTINGS):
295 case XML_ELEMENT(PRESENTATION_OOO, XML_SETTINGS):
297 return new SdXMLShowsContext( GetSdImport(), xAttrList );
299 case XML_ELEMENT(DRAW, XML_PAGE):
301 // only read the first page in preview mode
302 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
304 // import this page
305 uno::Reference< drawing::XDrawPage > xNewDrawPage;
306 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
308 if( !xDrawPages.is() )
309 break;
311 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
313 // new page, create and insert
314 xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
316 else
318 // existing page, use it
319 uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
320 aAny >>= xNewDrawPage;
323 // increment global import page counter
324 GetSdImport().IncrementNewPageCount();
326 if(xNewDrawPage.is())
328 // draw:page inside office:body context
329 return new SdXMLDrawPageContext(GetSdImport(), xAttrList, xNewDrawPage);
332 break;
334 case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL):
335 case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL):
336 case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL):
338 return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList );
339 break;
341 default:
342 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
344 return nullptr;
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */