1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
61 case XML_ELEMENT(DRAW
, XML_STYLE_NAME
):
66 case XML_ELEMENT(DRAW
, XML_MASTER_PAGE_NAME
):
68 sMasterPageName
= sValue
;
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
;
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
;
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
;
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
;
99 case XML_ELEMENT(DRAW
, XML_ID
):
101 if (!bHaveXmlId
) { sXmlId
= sValue
; }
104 case XML_ELEMENT(XML
, XML_ID
):
110 case XML_ELEMENT(XLINK
, XML_HREF
):
118 if (!sXmlId
.isEmpty())
120 uno::Reference
< uno::XInterface
> const xRef( rShapes
.get() );
121 GetImport().getInterfaceToIdentifierMapper().registerReference(
124 GetImport().GetShapeImport()->startPage( rShapes
);
126 uno::Reference
< drawing::XDrawPage
> xShapeDrawPage(rShapes
, uno::UNO_QUERY
);
129 if(!sContextName
.isEmpty())
131 if(xShapeDrawPage
.is())
133 uno::Reference
< container::XNamed
> xNamed(xShapeDrawPage
, uno::UNO_QUERY
);
135 xNamed
->setName(sContextName
);
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())
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
;
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
);
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
);
189 sal_Int32 nIndex
= sHREF
.lastIndexOf( '#' );
192 OUString
aFileName( sHREF
.copy( 0, nIndex
) );
193 OUString
aBookmarkName( sHREF
.copy( nIndex
+1 ) );
195 sHREF
= GetImport().GetAbsoluteReference( aFileName
) + "#"
199 xProps
->setPropertyValue("BookmarkURL", uno::makeAny( sHREF
) );
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
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() )
225 uno::Reference
< presentation::XPresentationPage
> xPresPage(GetLocalShapesContext(), uno::UNO_QUERY
);
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
);
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
);
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());
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(
289 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
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() )
305 uno::Reference
< drawing::XDrawPage
> xNewDrawPage
;
306 uno::Reference
< drawing::XDrawPages
> xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY
);
308 if( !xDrawPages
.is() )
311 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages
->getCount())
313 // new page, create and insert
314 xNewDrawPage
= xDrawPages
->insertNewByIndex(xDrawPages
->getCount());
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
);
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
);
342 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */