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
);
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
< beans::XPropertySet
> xPropSet(xMasterPage
, uno::UNO_QUERY_THROW
);
167 OUString
aPropName("SlideLayout");
168 uno::Reference
< beans::XPropertySetInfo
> xInfo(xPropSet
->getPropertySetInfo());
169 if (xInfo
.is() && xInfo
->hasPropertyByName(aPropName
))
171 sal_Int32 nType
= -1;
172 uno::Reference
< container::XNameAccess
> xPageLayouts(GetSdImport().getPageLayouts());
173 if (xPageLayouts
.is())
175 if (xPageLayouts
->hasByName(maPageLayoutName
))
176 xPageLayouts
->getByName(maPageLayoutName
) >>= nType
;
179 xPropSet
->setPropertyValue(aPropName
, uno::Any(static_cast<sal_Int16
>(nType
)));
183 uno::Reference
< container::XNamed
> xMasterNamed(xMasterPage
, uno::UNO_QUERY
);
184 if(xMasterNamed
.is())
186 OUString sLoopMasterPageName
= xMasterNamed
->getName();
188 if(!sLoopMasterPageName
.isEmpty() && sLoopMasterPageName
== sDisplayName
)
190 xDrawPage
->setMasterPage(xMasterPage
);
197 SAL_WARN_IF( !bDone
, "xmloff", "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a master slide!" );
201 SetStyle( sStyleName
);
203 if( !sHREF
.isEmpty() )
205 uno::Reference
< beans::XPropertySet
> xProps( xShapeDrawPage
, uno::UNO_QUERY
);
208 sal_Int32 nIndex
= sHREF
.lastIndexOf( '#' );
211 OUString
aFileName( sHREF
.copy( 0, nIndex
) );
212 std::u16string_view
aBookmarkName( sHREF
.subView( nIndex
+1 ) );
214 sHREF
= GetImport().GetAbsoluteReference( aFileName
) + "#"
218 xProps
->setPropertyValue("BookmarkURL", uno::Any( sHREF
) );
227 SdXMLDrawPageContext::~SdXMLDrawPageContext()
231 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SdXMLDrawPageContext::createFastChildContext(sal_Int32 nElement
,
232 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
234 // some special objects inside draw:page context
237 case XML_ELEMENT(PRESENTATION
, XML_NOTES
):
238 case XML_ELEMENT(PRESENTATION_SO52
, XML_NOTES
):
239 case XML_ELEMENT(PRESENTATION_OOO
, XML_NOTES
):
241 if( GetSdImport().IsImpress() )
244 uno::Reference
< presentation::XPresentationPage
> xPresPage(GetLocalShapesContext(), uno::UNO_QUERY
);
247 uno::Reference
< drawing::XDrawPage
> xNotesDrawPage
= xPresPage
->getNotesPage();
248 if(xNotesDrawPage
.is())
250 // presentation:notes inside draw:page context
251 return new SdXMLNotesContext( GetSdImport(), xAttrList
, xNotesDrawPage
);
257 case XML_ELEMENT(ANIMATION
, XML_PAR
):
258 case XML_ELEMENT(ANIMATION_OOO
, XML_PAR
):
259 case XML_ELEMENT(ANIMATION
, XML_SEQ
):
260 case XML_ELEMENT(ANIMATION_OOO
, XML_SEQ
):
262 if( GetSdImport().IsImpress() )
264 uno::Reference
< animations::XAnimationNodeSupplier
> xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY
);
265 if(xNodeSupplier
.is())
267 mbHadSMILNodes
= true;
268 return new xmloff::AnimationNodeContext( xNodeSupplier
->getAnimationNode(), GetSdImport(), nElement
, xAttrList
);
273 case XML_ELEMENT(DRAW
, XML_LAYER_SET
):
275 return new SdXMLLayerSetContext( GetSdImport() );
279 // call parent when no own context was created
280 return SdXMLGenericPageContext::createFastChildContext(nElement
, xAttrList
);
283 void SdXMLDrawPageContext::endFastElement(sal_Int32 nElement
)
285 SdXMLGenericPageContext::endFastElement(nElement
);
286 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
290 uno::Reference
< animations::XAnimationNodeSupplier
> xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY
);
291 uno::Reference
< beans::XPropertySet
> xPageProps( GetLocalShapesContext(), uno::UNO_QUERY
);
292 if(xNodeSupplier
.is())
293 xmloff::AnimationNodeContext::postProcessRootNode( xNodeSupplier
->getAnimationNode(), xPageProps
);
297 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport
& rImport
)
298 : SvXMLImportContext( rImport
)
302 SdXMLBodyContext::~SdXMLBodyContext()
306 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SdXMLBodyContext::createFastChildContext(
308 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
312 case XML_ELEMENT(PRESENTATION
, XML_SETTINGS
):
313 case XML_ELEMENT(PRESENTATION_SO52
, XML_SETTINGS
):
314 case XML_ELEMENT(PRESENTATION_OOO
, XML_SETTINGS
):
316 return new SdXMLShowsContext( GetSdImport(), xAttrList
);
318 case XML_ELEMENT(DRAW
, XML_PAGE
):
320 // only read the first page in preview mode
321 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
324 uno::Reference
< drawing::XDrawPage
> xNewDrawPage
;
325 uno::Reference
< drawing::XDrawPages
> xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY
);
327 if( !xDrawPages
.is() )
330 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages
->getCount())
332 // new page, create and insert
333 xNewDrawPage
= xDrawPages
->insertNewByIndex(xDrawPages
->getCount());
337 // existing page, use it
338 uno::Any
aAny(xDrawPages
->getByIndex(GetSdImport().GetNewPageCount()));
339 aAny
>>= xNewDrawPage
;
342 // increment global import page counter
343 GetSdImport().IncrementNewPageCount();
345 if(xNewDrawPage
.is())
347 // draw:page inside office:body context
348 return new SdXMLDrawPageContext(GetSdImport(), xAttrList
, xNewDrawPage
);
353 case XML_ELEMENT(PRESENTATION
, XML_HEADER_DECL
):
354 case XML_ELEMENT(PRESENTATION
, XML_FOOTER_DECL
):
355 case XML_ELEMENT(PRESENTATION
, XML_DATE_TIME_DECL
):
357 return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList
);
360 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */