1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "ximpbody.hxx"
#include <xmloff/prstylei.hxx>
#include "ximpnote.hxx"
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/drawing/XDrawPages.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/presentation/XPresentationPage.hpp>
#include "ximpstyl.hxx"
#include <com/sun/star/drawing/XMasterPageTarget.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/xmlprmap.hxx>
#include <xmloff/families.hxx>
#include "ximpshow.hxx"
#include "PropertySetMerger.hxx"
#include "animationimport.hxx"
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using namespace ::com::sun::star;
//////////////////////////////////////////////////////////////////////////////
SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLocalName,
const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes >& rShapes)
: SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
, mbHadSMILNodes( false )
{
bool bHaveXmlId( false );
OUString sXmlId;
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for(sal_Int16 i=0; i < nAttrCount; i++)
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
OUString sValue = xAttrList->getValueByIndex( i );
const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
switch(rAttrTokenMap.Get(nPrefix, aLocalName))
{
case XML_TOK_DRAWPAGE_NAME:
{
maName = sValue;
break;
}
case XML_TOK_DRAWPAGE_STYLE_NAME:
{
maStyleName = sValue;
break;
}
case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
{
maMasterPageName = sValue;
break;
}
case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
{
maPageLayoutName = sValue;
break;
}
case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
{
maUseHeaderDeclName = sValue;
break;
}
case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
{
maUseFooterDeclName = sValue;
break;
}
case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
{
maUseDateTimeDeclName = sValue;
break;
}
case XML_TOK_DRAWPAGE_DRAWID:
{
if (!bHaveXmlId) { sXmlId = sValue; }
}
break;
case XML_TOK_DRAWPAGE_XMLID:
{
sXmlId = sValue;
bHaveXmlId = true;
}
break;
case XML_TOK_DRAWPAGE_HREF:
{
maHREF = sValue;
break;
}
}
}
if (!sXmlId.isEmpty())
{
uno::Reference< uno::XInterface > const xRef( rShapes.get() );
GetImport().getInterfaceToIdentifierMapper().registerReference(
sXmlId, xRef );
}
GetImport().GetShapeImport()->startPage( rShapes );
uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
// set PageName?
if(!maName.isEmpty())
{
if(xShapeDrawPage.is())
{
uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
if(xNamed.is())
xNamed->setName(maName);
}
}
// set MasterPage?
if(!maMasterPageName.isEmpty())
{
// #85906# Code for setting masterpage needs complete rework
// since GetSdImport().GetMasterStylesContext() gives always ZERO
// because of content/style file split. Now the nechanism is to
// compare the wanted masterpage-name with the existing masterpages
// which were loaded and created in the styles section loading.
uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
uno::Reference< drawing::XDrawPage > xMasterPage;
if(xDrawPage.is() && xMasterPages.is())
{
sal_Bool bDone(sal_False);
OUString sDisplayName( rImport.GetStyleDisplayName(
XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
{
uno::Any aAny(xMasterPages->getByIndex(a));
aAny >>= xMasterPage;
if(xMasterPage.is())
{
uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
if(xMasterNamed.is())
{
OUString sMasterPageName = xMasterNamed->getName();
if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
{
xDrawPage->setMasterPage(xMasterPage);
bDone = sal_True;
}
}
}
}
DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
}
}
SetStyle( maStyleName );
if( !maHREF.isEmpty() )
{
uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
if( xProps.is() )
{
sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
if( nIndex != -1 )
{
OUString aFileName( maHREF.copy( 0, nIndex ) );
OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
maHREF = GetImport().GetAbsoluteReference( aFileName );
maHREF += OUString(static_cast<sal_Unicode>('#'));
maHREF += aBookmarkName;
}
xProps->setPropertyValue( OUString( "BookmarkURL" ), uno::makeAny( maHREF ) );
}
}
SetLayout();
DeleteAllShapes();
}
//////////////////////////////////////////////////////////////////////////////
SdXMLDrawPageContext::~SdXMLDrawPageContext()
{
}
//////////////////////////////////////////////////////////////////////////////
SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
{
SvXMLImportContext *pContext = 0L;
const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
// some special objects inside draw:page context
switch(rTokenMap.Get(nPrefix, rLocalName))
{
case XML_TOK_DRAWPAGE_NOTES:
{
if( GetSdImport().IsImpress() )
{
// get notes page
uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
if(xPresPage.is())
{
uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
if(xNotesDrawPage.is())
{
uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
if(xNewShapes.is())
{
// presentation:notes inside draw:page context
pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
}
}
}
}
break;
}
case XML_TOK_DRAWPAGE_PAR:
case XML_TOK_DRAWPAGE_SEQ:
{
if( GetSdImport().IsImpress() )
{
uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
if(xNodeSupplier.is())
{
pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
mbHadSMILNodes = true;
}
}
break;
}
}
// call parent when no own context was created
if(!pContext)
pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
return pContext;
}
void SdXMLDrawPageContext::EndElement()
{
SdXMLGenericPageContext::EndElement();
GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
if( mbHadSMILNodes )
{
uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
if(xNodeSupplier.is())
xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLocalName )
: SvXMLImportContext( rImport, nPrfx, rLocalName )
{
}
//////////////////////////////////////////////////////////////////////////////
SdXMLBodyContext::~SdXMLBodyContext()
{
}
//////////////////////////////////////////////////////////////////////////////
SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList>& xAttrList )
{
SvXMLImportContext *pContext = 0L;
const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
switch(rTokenMap.Get(nPrefix, rLocalName))
{
case XML_TOK_BODY_HEADER_DECL:
case XML_TOK_BODY_FOOTER_DECL:
case XML_TOK_BODY_DATE_TIME_DECL:
{
pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
break;
}
case XML_TOK_BODY_PAGE:
{
// only read the first page in preview mode
if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
{
// import this page
uno::Reference< drawing::XDrawPage > xNewDrawPage;
uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
if( !xDrawPages.is() )
break;
if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
{
// new page, create and insert
xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
}
else
{
// existing page, use it
uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
aAny >>= xNewDrawPage;
}
// increment global import page counter
GetSdImport().IncrementNewPageCount();
if(xNewDrawPage.is())
{
uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
if(xNewShapes.is())
{
// draw:page inside office:body context
pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
xNewShapes);
}
}
}
break;
}
case XML_TOK_BODY_SETTINGS:
{
pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
}
}
// call parent when no own context was created
if(!pContext)
pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
return pContext;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|