Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
31 :
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>
40 :
41 : using namespace ::com::sun::star;
42 :
43 150 : 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 150 : , mbHadSMILNodes( false )
49 : {
50 150 : bool bHaveXmlId( false );
51 150 : OUString sXmlId;
52 :
53 150 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
54 :
55 648 : for(sal_Int16 i=0; i < nAttrCount; i++)
56 : {
57 498 : OUString sAttrName = xAttrList->getNameByIndex( i );
58 996 : OUString aLocalName;
59 498 : sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
60 996 : OUString sValue = xAttrList->getValueByIndex( i );
61 498 : const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
62 :
63 498 : switch(rAttrTokenMap.Get(nPrefix, aLocalName))
64 : {
65 : case XML_TOK_DRAWPAGE_NAME:
66 : {
67 150 : maName = sValue;
68 150 : break;
69 : }
70 : case XML_TOK_DRAWPAGE_STYLE_NAME:
71 : {
72 150 : maStyleName = sValue;
73 150 : break;
74 : }
75 : case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
76 : {
77 150 : maMasterPageName = sValue;
78 150 : break;
79 : }
80 : case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
81 : {
82 48 : maPageLayoutName = sValue;
83 48 : break;
84 : }
85 : case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
86 : {
87 0 : maUseHeaderDeclName = sValue;
88 0 : break;
89 : }
90 : case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
91 : {
92 0 : maUseFooterDeclName = sValue;
93 0 : break;
94 : }
95 : case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
96 : {
97 0 : maUseDateTimeDeclName = sValue;
98 0 : break;
99 : }
100 : case XML_TOK_DRAWPAGE_DRAWID:
101 : {
102 0 : if (!bHaveXmlId) { sXmlId = sValue; }
103 : }
104 0 : break;
105 : case XML_TOK_DRAWPAGE_XMLID:
106 : {
107 0 : sXmlId = sValue;
108 0 : bHaveXmlId = true;
109 : }
110 0 : break;
111 : case XML_TOK_DRAWPAGE_HREF:
112 : {
113 0 : maHREF = sValue;
114 0 : break;
115 : }
116 : }
117 498 : }
118 :
119 150 : if (!sXmlId.isEmpty())
120 : {
121 0 : uno::Reference< uno::XInterface > const xRef( rShapes.get() );
122 0 : GetImport().getInterfaceToIdentifierMapper().registerReference(
123 0 : sXmlId, xRef );
124 : }
125 150 : GetImport().GetShapeImport()->startPage( rShapes );
126 :
127 150 : uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
128 :
129 : // set PageName?
130 150 : if(!maName.isEmpty())
131 : {
132 150 : if(xShapeDrawPage.is())
133 : {
134 150 : uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
135 150 : if(xNamed.is())
136 150 : xNamed->setName(maName);
137 : }
138 : }
139 :
140 : // set MasterPage?
141 150 : if(!maMasterPageName.isEmpty())
142 : {
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 150 : uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
149 300 : uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
150 300 : uno::Reference< drawing::XDrawPage > xMasterPage;
151 :
152 150 : if(xDrawPage.is() && xMasterPages.is())
153 : {
154 150 : bool bDone(false);
155 : OUString sDisplayName( rImport.GetStyleDisplayName(
156 150 : XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
157 :
158 302 : for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
159 : {
160 152 : uno::Any aAny(xMasterPages->getByIndex(a));
161 152 : aAny >>= xMasterPage;
162 :
163 152 : if(xMasterPage.is())
164 : {
165 152 : uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
166 152 : if(xMasterNamed.is())
167 : {
168 152 : OUString sMasterPageName = xMasterNamed->getName();
169 :
170 152 : if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
171 : {
172 150 : xDrawPage->setMasterPage(xMasterPage);
173 150 : bDone = true;
174 152 : }
175 152 : }
176 : }
177 152 : }
178 :
179 150 : DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
180 150 : }
181 : }
182 :
183 150 : SetStyle( maStyleName );
184 :
185 150 : if( !maHREF.isEmpty() )
186 : {
187 0 : uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
188 0 : if( xProps.is() )
189 : {
190 0 : sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
191 0 : if( nIndex != -1 )
192 : {
193 0 : OUString aFileName( maHREF.copy( 0, nIndex ) );
194 0 : OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
195 :
196 0 : maHREF = GetImport().GetAbsoluteReference( aFileName );
197 0 : maHREF += OUString(static_cast<sal_Unicode>('#'));
198 0 : maHREF += aBookmarkName;
199 : }
200 :
201 0 : xProps->setPropertyValue("BookmarkURL", uno::makeAny( maHREF ) );
202 0 : }
203 : }
204 :
205 150 : SetLayout();
206 :
207 150 : DeleteAllShapes();
208 150 : }
209 :
210 300 : SdXMLDrawPageContext::~SdXMLDrawPageContext()
211 : {
212 300 : }
213 :
214 1594 : SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
215 : const OUString& rLocalName,
216 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
217 : {
218 1594 : SvXMLImportContext *pContext = 0L;
219 1594 : const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
220 :
221 : // some special objects inside draw:page context
222 1594 : switch(rTokenMap.Get(nPrefix, rLocalName))
223 : {
224 : case XML_TOK_DRAWPAGE_NOTES:
225 : {
226 66 : if( GetSdImport().IsImpress() )
227 : {
228 : // get notes page
229 66 : uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
230 66 : if(xPresPage.is())
231 : {
232 66 : uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
233 66 : if(xNotesDrawPage.is())
234 : {
235 66 : uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
236 66 : if(xNewShapes.is())
237 : {
238 : // presentation:notes inside draw:page context
239 66 : pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
240 66 : }
241 66 : }
242 66 : }
243 : }
244 66 : break;
245 : }
246 : case XML_TOK_DRAWPAGE_PAR:
247 : case XML_TOK_DRAWPAGE_SEQ:
248 : {
249 2 : if( GetSdImport().IsImpress() )
250 : {
251 2 : uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
252 2 : if(xNodeSupplier.is())
253 : {
254 2 : pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
255 2 : mbHadSMILNodes = true;
256 2 : }
257 : }
258 2 : break;
259 : }
260 : }
261 :
262 : // call parent when no own context was created
263 1594 : if(!pContext)
264 1526 : pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
265 :
266 1594 : return pContext;
267 : }
268 :
269 150 : void SdXMLDrawPageContext::EndElement()
270 : {
271 150 : SdXMLGenericPageContext::EndElement();
272 150 : GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
273 :
274 150 : if( mbHadSMILNodes )
275 : {
276 2 : uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
277 4 : uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
278 2 : if(xNodeSupplier.is())
279 4 : xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
280 : }
281 150 : }
282 :
283 114 : SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
284 : sal_uInt16 nPrfx, const OUString& rLocalName )
285 114 : : SvXMLImportContext( rImport, nPrfx, rLocalName )
286 : {
287 114 : }
288 :
289 228 : SdXMLBodyContext::~SdXMLBodyContext()
290 : {
291 228 : }
292 :
293 182 : SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
294 : sal_uInt16 nPrefix,
295 : const OUString& rLocalName,
296 : const uno::Reference< xml::sax::XAttributeList>& xAttrList )
297 : {
298 182 : SvXMLImportContext *pContext = 0L;
299 182 : const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
300 :
301 182 : switch(rTokenMap.Get(nPrefix, rLocalName))
302 : {
303 : case XML_TOK_BODY_HEADER_DECL:
304 : case XML_TOK_BODY_FOOTER_DECL:
305 : case XML_TOK_BODY_DATE_TIME_DECL:
306 : {
307 0 : pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
308 0 : break;
309 : }
310 : case XML_TOK_BODY_PAGE:
311 : {
312 : // only read the first page in preview mode
313 150 : if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
314 : {
315 : // import this page
316 150 : uno::Reference< drawing::XDrawPage > xNewDrawPage;
317 300 : uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
318 :
319 150 : if( !xDrawPages.is() )
320 0 : break;
321 :
322 150 : if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
323 : {
324 : // new page, create and insert
325 38 : xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
326 : }
327 : else
328 : {
329 : // existing page, use it
330 112 : uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
331 112 : aAny >>= xNewDrawPage;
332 : }
333 :
334 : // increment global import page counter
335 150 : GetSdImport().IncrementNewPageCount();
336 :
337 150 : if(xNewDrawPage.is())
338 : {
339 150 : uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
340 150 : if(xNewShapes.is())
341 : {
342 : // draw:page inside office:body context
343 : pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
344 150 : xNewShapes);
345 150 : }
346 150 : }
347 : }
348 150 : break;
349 : }
350 : case XML_TOK_BODY_SETTINGS:
351 : {
352 32 : pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
353 : }
354 : }
355 :
356 : // call parent when no own context was created
357 182 : if(!pContext)
358 0 : pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
359 :
360 182 : return pContext;
361 : }
362 :
363 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|