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 123 : 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 123 : , mbHadSMILNodes( false )
49 : {
50 123 : bool bHaveXmlId( false );
51 123 : OUString sXmlId;
52 :
53 123 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
54 :
55 550 : for(sal_Int16 i=0; i < nAttrCount; i++)
56 : {
57 427 : OUString sAttrName = xAttrList->getNameByIndex( i );
58 854 : OUString aLocalName;
59 427 : sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
60 854 : OUString sValue = xAttrList->getValueByIndex( i );
61 427 : const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
62 :
63 427 : switch(rAttrTokenMap.Get(nPrefix, aLocalName))
64 : {
65 : case XML_TOK_DRAWPAGE_NAME:
66 : {
67 121 : maName = sValue;
68 121 : break;
69 : }
70 : case XML_TOK_DRAWPAGE_STYLE_NAME:
71 : {
72 121 : maStyleName = sValue;
73 121 : break;
74 : }
75 : case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
76 : {
77 123 : maMasterPageName = sValue;
78 123 : break;
79 : }
80 : case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
81 : {
82 62 : maPageLayoutName = sValue;
83 62 : 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 427 : }
118 :
119 123 : 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 123 : GetImport().GetShapeImport()->startPage( rShapes );
126 :
127 123 : uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
128 :
129 : // set PageName?
130 123 : if(!maName.isEmpty())
131 : {
132 121 : if(xShapeDrawPage.is())
133 : {
134 121 : uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
135 121 : if(xNamed.is())
136 121 : xNamed->setName(maName);
137 : }
138 : }
139 :
140 : // set MasterPage?
141 123 : 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 123 : uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
149 246 : uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
150 246 : uno::Reference< drawing::XDrawPage > xMasterPage;
151 :
152 123 : if(xDrawPage.is() && xMasterPages.is())
153 : {
154 123 : bool bDone(false);
155 : OUString sDisplayName( rImport.GetStyleDisplayName(
156 123 : XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
157 :
158 256 : for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
159 : {
160 133 : uno::Any aAny(xMasterPages->getByIndex(a));
161 133 : aAny >>= xMasterPage;
162 :
163 133 : if(xMasterPage.is())
164 : {
165 133 : uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
166 133 : if(xMasterNamed.is())
167 : {
168 133 : OUString sMasterPageName = xMasterNamed->getName();
169 :
170 133 : if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
171 : {
172 123 : xDrawPage->setMasterPage(xMasterPage);
173 123 : bDone = true;
174 133 : }
175 133 : }
176 : }
177 133 : }
178 :
179 123 : DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
180 123 : }
181 : }
182 :
183 123 : SetStyle( maStyleName );
184 :
185 123 : 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 123 : SetLayout();
206 :
207 123 : DeleteAllShapes();
208 123 : }
209 :
210 246 : SdXMLDrawPageContext::~SdXMLDrawPageContext()
211 : {
212 246 : }
213 :
214 986 : 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 986 : SvXMLImportContext *pContext = 0L;
219 986 : const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
220 :
221 : // some special objects inside draw:page context
222 986 : switch(rTokenMap.Get(nPrefix, rLocalName))
223 : {
224 : case XML_TOK_DRAWPAGE_NOTES:
225 : {
226 73 : if( GetSdImport().IsImpress() )
227 : {
228 : // get notes page
229 73 : uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
230 73 : if(xPresPage.is())
231 : {
232 73 : uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
233 73 : if(xNotesDrawPage.is())
234 : {
235 73 : uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
236 73 : if(xNewShapes.is())
237 : {
238 : // presentation:notes inside draw:page context
239 73 : pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
240 73 : }
241 73 : }
242 73 : }
243 : }
244 73 : break;
245 : }
246 : case XML_TOK_DRAWPAGE_PAR:
247 : case XML_TOK_DRAWPAGE_SEQ:
248 : {
249 1 : if( GetSdImport().IsImpress() )
250 : {
251 1 : uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
252 1 : if(xNodeSupplier.is())
253 : {
254 1 : pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
255 1 : mbHadSMILNodes = true;
256 1 : }
257 : }
258 1 : break;
259 : }
260 : }
261 :
262 : // call parent when no own context was created
263 986 : if(!pContext)
264 912 : pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
265 :
266 986 : return pContext;
267 : }
268 :
269 123 : void SdXMLDrawPageContext::EndElement()
270 : {
271 123 : SdXMLGenericPageContext::EndElement();
272 123 : GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
273 :
274 123 : if( mbHadSMILNodes )
275 : {
276 1 : uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
277 2 : uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
278 1 : if(xNodeSupplier.is())
279 2 : xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
280 : }
281 123 : }
282 :
283 89 : SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
284 : sal_uInt16 nPrfx, const OUString& rLocalName )
285 89 : : SvXMLImportContext( rImport, nPrfx, rLocalName )
286 : {
287 89 : }
288 :
289 178 : SdXMLBodyContext::~SdXMLBodyContext()
290 : {
291 178 : }
292 :
293 165 : SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
294 : sal_uInt16 nPrefix,
295 : const OUString& rLocalName,
296 : const uno::Reference< xml::sax::XAttributeList>& xAttrList )
297 : {
298 165 : SvXMLImportContext *pContext = 0L;
299 165 : const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
300 :
301 165 : 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 123 : if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
314 : {
315 : // import this page
316 123 : uno::Reference< drawing::XDrawPage > xNewDrawPage;
317 246 : uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
318 :
319 123 : if( !xDrawPages.is() )
320 0 : break;
321 :
322 123 : if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
323 : {
324 : // new page, create and insert
325 35 : xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
326 : }
327 : else
328 : {
329 : // existing page, use it
330 88 : uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
331 88 : aAny >>= xNewDrawPage;
332 : }
333 :
334 : // increment global import page counter
335 123 : GetSdImport().IncrementNewPageCount();
336 :
337 123 : if(xNewDrawPage.is())
338 : {
339 123 : uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
340 123 : if(xNewShapes.is())
341 : {
342 : // draw:page inside office:body context
343 : pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
344 123 : xNewShapes);
345 123 : }
346 123 : }
347 : }
348 123 : break;
349 : }
350 : case XML_TOK_BODY_SETTINGS:
351 : {
352 42 : pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
353 : }
354 : }
355 :
356 : // call parent when no own context was created
357 165 : if(!pContext)
358 0 : pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
359 :
360 165 : return pContext;
361 : }
362 :
363 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|