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"
40 using ::rtl::OUString
;
41 using ::rtl::OUStringBuffer
;
43 using namespace ::com::sun::star
;
45 //////////////////////////////////////////////////////////////////////////////
47 SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport
& rImport
,
48 sal_uInt16 nPrfx
, const OUString
& rLocalName
,
49 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
50 uno::Reference
< drawing::XShapes
>& rShapes
)
51 : SdXMLGenericPageContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
)
52 , mbHadSMILNodes( false )
54 bool bHaveXmlId( false );
57 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
59 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
61 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
63 sal_uInt16 nPrefix
= GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
64 OUString sValue
= xAttrList
->getValueByIndex( i
);
65 const SvXMLTokenMap
& rAttrTokenMap
= GetSdImport().GetDrawPageAttrTokenMap();
67 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
69 case XML_TOK_DRAWPAGE_NAME
:
74 case XML_TOK_DRAWPAGE_STYLE_NAME
:
79 case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME
:
81 maMasterPageName
= sValue
;
84 case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME
:
86 maPageLayoutName
= sValue
;
89 case XML_TOK_DRAWPAGE_USE_HEADER_NAME
:
91 maUseHeaderDeclName
= sValue
;
94 case XML_TOK_DRAWPAGE_USE_FOOTER_NAME
:
96 maUseFooterDeclName
= sValue
;
99 case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME
:
101 maUseDateTimeDeclName
= sValue
;
104 case XML_TOK_DRAWPAGE_DRAWID
:
106 if (!bHaveXmlId
) { sXmlId
= sValue
; }
109 case XML_TOK_DRAWPAGE_XMLID
:
115 case XML_TOK_DRAWPAGE_HREF
:
123 if (!sXmlId
.isEmpty())
125 uno::Reference
< uno::XInterface
> const xRef( rShapes
.get() );
126 GetImport().getInterfaceToIdentifierMapper().registerReference(
129 GetImport().GetShapeImport()->startPage( rShapes
);
131 uno::Reference
< drawing::XDrawPage
> xShapeDrawPage(rShapes
, uno::UNO_QUERY
);
134 if(!maName
.isEmpty())
136 if(xShapeDrawPage
.is())
138 uno::Reference
< container::XNamed
> xNamed(xShapeDrawPage
, uno::UNO_QUERY
);
140 xNamed
->setName(maName
);
145 if(!maMasterPageName
.isEmpty())
147 // #85906# Code for setting masterpage needs complete rework
148 // since GetSdImport().GetMasterStylesContext() gives always ZERO
149 // because of content/style file split. Now the nechanism is to
150 // compare the wanted masterpage-name with the existing masterpages
151 // which were loaded and created in the styles section loading.
152 uno::Reference
< drawing::XDrawPages
> xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY
);
153 uno::Reference
< drawing::XMasterPageTarget
> xDrawPage(rShapes
, uno::UNO_QUERY
);
154 uno::Reference
< drawing::XDrawPage
> xMasterPage
;
156 if(xDrawPage
.is() && xMasterPages
.is())
158 sal_Bool
bDone(sal_False
);
159 OUString
sDisplayName( rImport
.GetStyleDisplayName(
160 XML_STYLE_FAMILY_MASTER_PAGE
, maMasterPageName
) );
162 for(sal_Int32 a
= 0; !bDone
&& a
< xMasterPages
->getCount(); a
++)
164 uno::Any
aAny(xMasterPages
->getByIndex(a
));
165 aAny
>>= xMasterPage
;
169 uno::Reference
< container::XNamed
> xMasterNamed(xMasterPage
, uno::UNO_QUERY
);
170 if(xMasterNamed
.is())
172 OUString sMasterPageName
= xMasterNamed
->getName();
174 if(!sMasterPageName
.isEmpty() && sMasterPageName
.equals(sDisplayName
))
176 xDrawPage
->setMasterPage(xMasterPage
);
183 DBG_ASSERT( bDone
, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
187 SetStyle( maStyleName
);
189 if( !maHREF
.isEmpty() )
191 uno::Reference
< beans::XPropertySet
> xProps( xShapeDrawPage
, uno::UNO_QUERY
);
194 sal_Int32 nIndex
= maHREF
.lastIndexOf( (sal_Unicode
)'#' );
197 OUString
aFileName( maHREF
.copy( 0, nIndex
) );
198 OUString
aBookmarkName( maHREF
.copy( nIndex
+1 ) );
200 maHREF
= GetImport().GetAbsoluteReference( aFileName
);
201 maHREF
+= OUString(static_cast<sal_Unicode
>('#'));
202 maHREF
+= aBookmarkName
;
205 xProps
->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BookmarkURL" ) ), uno::makeAny( maHREF
) );
214 //////////////////////////////////////////////////////////////////////////////
216 SdXMLDrawPageContext::~SdXMLDrawPageContext()
220 //////////////////////////////////////////////////////////////////////////////
222 SvXMLImportContext
*SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix
,
223 const OUString
& rLocalName
,
224 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
226 SvXMLImportContext
*pContext
= 0L;
227 const SvXMLTokenMap
& rTokenMap
= GetSdImport().GetDrawPageElemTokenMap();
229 // some special objects inside draw:page context
230 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
232 case XML_TOK_DRAWPAGE_NOTES
:
234 if( GetSdImport().IsImpress() )
237 uno::Reference
< presentation::XPresentationPage
> xPresPage(GetLocalShapesContext(), uno::UNO_QUERY
);
240 uno::Reference
< drawing::XDrawPage
> xNotesDrawPage(xPresPage
->getNotesPage(), uno::UNO_QUERY
);
241 if(xNotesDrawPage
.is())
243 uno::Reference
< drawing::XShapes
> xNewShapes(xNotesDrawPage
, uno::UNO_QUERY
);
246 // presentation:notes inside draw:page context
247 pContext
= new SdXMLNotesContext( GetSdImport(), nPrefix
, rLocalName
, xAttrList
, xNewShapes
);
254 case XML_TOK_DRAWPAGE_PAR
:
255 case XML_TOK_DRAWPAGE_SEQ
:
257 if( GetSdImport().IsImpress() )
259 uno::Reference
< animations::XAnimationNodeSupplier
> xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY
);
260 if(xNodeSupplier
.is())
262 pContext
= new xmloff::AnimationNodeContext( xNodeSupplier
->getAnimationNode(), GetSdImport(), nPrefix
, rLocalName
, xAttrList
);
263 mbHadSMILNodes
= true;
270 // call parent when no own context was created
272 pContext
= SdXMLGenericPageContext::CreateChildContext(nPrefix
, rLocalName
, xAttrList
);
277 void SdXMLDrawPageContext::EndElement()
279 SdXMLGenericPageContext::EndElement();
280 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
284 uno::Reference
< animations::XAnimationNodeSupplier
> xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY
);
285 uno::Reference
< beans::XPropertySet
> xPageProps( GetLocalShapesContext(), uno::UNO_QUERY
);
286 if(xNodeSupplier
.is())
287 xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier
->getAnimationNode(), xPageProps
);
291 //////////////////////////////////////////////////////////////////////////////
292 //////////////////////////////////////////////////////////////////////////////
294 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport
& rImport
,
295 sal_uInt16 nPrfx
, const OUString
& rLocalName
)
296 : SvXMLImportContext( rImport
, nPrfx
, rLocalName
)
300 //////////////////////////////////////////////////////////////////////////////
302 SdXMLBodyContext::~SdXMLBodyContext()
306 //////////////////////////////////////////////////////////////////////////////
308 SvXMLImportContext
*SdXMLBodyContext::CreateChildContext(
310 const OUString
& rLocalName
,
311 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
313 SvXMLImportContext
*pContext
= 0L;
314 const SvXMLTokenMap
& rTokenMap
= GetSdImport().GetBodyElemTokenMap();
316 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
318 case XML_TOK_BODY_HEADER_DECL
:
319 case XML_TOK_BODY_FOOTER_DECL
:
320 case XML_TOK_BODY_DATE_TIME_DECL
:
322 pContext
= new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
325 case XML_TOK_BODY_PAGE
:
327 // only read the first page in preview mode
328 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
331 uno::Reference
< drawing::XDrawPage
> xNewDrawPage
;
332 uno::Reference
< drawing::XDrawPages
> xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY
);
334 if( !xDrawPages
.is() )
337 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages
->getCount())
339 // new page, create and insert
340 xNewDrawPage
= xDrawPages
->insertNewByIndex(xDrawPages
->getCount());
344 // existing page, use it
345 uno::Any
aAny(xDrawPages
->getByIndex(GetSdImport().GetNewPageCount()));
346 aAny
>>= xNewDrawPage
;
349 // increment global import page counter
350 GetSdImport().IncrementNewPageCount();
352 if(xNewDrawPage
.is())
354 uno::Reference
< drawing::XShapes
> xNewShapes(xNewDrawPage
, uno::UNO_QUERY
);
357 // draw:page inside office:body context
358 pContext
= new SdXMLDrawPageContext(GetSdImport(), nPrefix
, rLocalName
, xAttrList
,
365 case XML_TOK_BODY_SETTINGS
:
367 pContext
= new SdXMLShowsContext( GetSdImport(), nPrefix
, rLocalName
, xAttrList
);
371 // call parent when no own context was created
373 pContext
= SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
, xAttrList
);
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */