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/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 );
53 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
55 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
57 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
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
:
70 case XML_TOK_DRAWPAGE_STYLE_NAME
:
75 case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME
:
77 maMasterPageName
= sValue
;
80 case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME
:
82 maPageLayoutName
= sValue
;
85 case XML_TOK_DRAWPAGE_USE_HEADER_NAME
:
87 maUseHeaderDeclName
= sValue
;
90 case XML_TOK_DRAWPAGE_USE_FOOTER_NAME
:
92 maUseFooterDeclName
= sValue
;
95 case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME
:
97 maUseDateTimeDeclName
= sValue
;
100 case XML_TOK_DRAWPAGE_DRAWID
:
102 if (!bHaveXmlId
) { sXmlId
= sValue
; }
105 case XML_TOK_DRAWPAGE_XMLID
:
111 case XML_TOK_DRAWPAGE_HREF
:
119 if (!sXmlId
.isEmpty())
121 uno::Reference
< uno::XInterface
> const xRef( rShapes
.get() );
122 GetImport().getInterfaceToIdentifierMapper().registerReference(
125 GetImport().GetShapeImport()->startPage( rShapes
);
127 uno::Reference
< drawing::XDrawPage
> xShapeDrawPage(rShapes
, uno::UNO_QUERY
);
130 if(!maName
.isEmpty())
132 if(xShapeDrawPage
.is())
134 uno::Reference
< container::XNamed
> xNamed(xShapeDrawPage
, uno::UNO_QUERY
);
136 xNamed
->setName(maName
);
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())
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
;
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
);
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
);
190 sal_Int32 nIndex
= maHREF
.lastIndexOf( (sal_Unicode
)'#' );
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
) );
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() )
229 uno::Reference
< presentation::XPresentationPage
> xPresPage(GetLocalShapesContext(), uno::UNO_QUERY
);
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
);
238 // presentation:notes inside draw:page context
239 pContext
= new SdXMLNotesContext( GetSdImport(), nPrefix
, rLocalName
, xAttrList
, xNewShapes
);
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;
262 // call parent when no own context was created
264 pContext
= SdXMLGenericPageContext::CreateChildContext(nPrefix
, rLocalName
, xAttrList
);
269 void SdXMLDrawPageContext::EndElement()
271 SdXMLGenericPageContext::EndElement();
272 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
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(
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
);
310 case XML_TOK_BODY_PAGE
:
312 // only read the first page in preview mode
313 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
316 uno::Reference
< drawing::XDrawPage
> xNewDrawPage
;
317 uno::Reference
< drawing::XDrawPages
> xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY
);
319 if( !xDrawPages
.is() )
322 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages
->getCount())
324 // new page, create and insert
325 xNewDrawPage
= xDrawPages
->insertNewByIndex(xDrawPages
->getCount());
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
);
342 // draw:page inside office:body context
343 pContext
= new SdXMLDrawPageContext(GetSdImport(), nPrefix
, rLocalName
, xAttrList
,
350 case XML_TOK_BODY_SETTINGS
:
352 pContext
= new SdXMLShowsContext( GetSdImport(), nPrefix
, rLocalName
, xAttrList
);
356 // call parent when no own context was created
358 pContext
= SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
, xAttrList
);
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */