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
379
380
381
382
383
384
|
/* -*- 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 <com/sun/star/container/XIndexReplace.hpp>
#include "impastpl.hxx"
#include <xmloff/xmlaustp.hxx>
#include <xmloff/families.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlexp.hxx>
#include <xmloff/xmlprhdl.hxx>
#include <xmloff/xmlprmap.hxx>
#include <xmloff/XMLTextListAutoStylePool.hxx>
#include <PageMasterStyleMap.hxx>
#include <osl/diagnose.h>
using namespace ::std;
using namespace ::com::sun::star;
using namespace ::xmloff::token;
namespace
{
void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
const XMLPropertyState& _rProperty )
{
assert(_rxMapper.is());
// obtain the data style name
OUString sDataStyleName;
_rProperty.maValue >>= sDataStyleName;
assert(!sDataStyleName.isEmpty() && "xmloff::lcl_exportDataStyle: invalid property value for the data style name!");
// add the attribute
_rExport.AddAttribute(
_rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
_rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
sDataStyleName );
}
}
void SvXMLAutoStylePoolP::exportStyleAttributes(
SvXMLAttributeList&,
XmlStyleFamily nFamily,
const vector< XMLPropertyState >& rProperties,
const SvXMLExportPropertyMapper& rPropExp,
const SvXMLUnitConverter&,
const SvXMLNamespaceMap&
) const
{
if ( XmlStyleFamily::CONTROL_ID == nFamily )
{ // it's a control-related style
const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
for (const auto& rProp : rProperties)
{
if ( ( rProp.mnIndex > -1 )
&& ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( rProp.mnIndex ) )
)
{ // it's the data-style for a grid column
lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
}
}
}
if( (XmlStyleFamily::SD_GRAPHICS_ID == nFamily) || (XmlStyleFamily::SD_PRESENTATION_ID == nFamily) )
{ // it's a graphics style
const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
assert(aPropertyMapper.is());
bool bFoundControlShapeDataStyle = false;
bool bFoundNumberingRulesName = false;
for (const auto& rProp : rProperties)
{
if (rProp.mnIndex > -1)
{ // it's a valid property
switch( aPropertyMapper->GetEntryContextId(rProp.mnIndex) )
{
case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
{ // it's the control shape data style property
if (bFoundControlShapeDataStyle)
{
OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
// already added the attribute for the first occurrence
break;
}
lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
// check if there is another property with the special context id we're handling here
bFoundControlShapeDataStyle = true;
break;
}
case CTF_SD_NUMBERINGRULES_NAME:
{
if (bFoundNumberingRulesName)
{
OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
// already added the attribute for the first occurrence
break;
}
uno::Reference< container::XIndexReplace > xNumRule;
rProp.maValue >>= xNumRule;
if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
{
const OUString sName(const_cast<XMLTextListAutoStylePool*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
}
bFoundNumberingRulesName = true;
break;
}
}
}
}
}
if( nFamily == XmlStyleFamily::PAGE_MASTER )
{
for( const auto& rProp : rProperties )
{
if (rProp.mnIndex > -1)
{
const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
sal_Int32 nIndex = rProp.mnIndex;
sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
switch( nContextID )
{
case CTF_PM_PAGEUSAGE:
{
OUString sValue;
const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
if( pPropHdl &&
pPropHdl->exportXML( sValue, rProp.maValue,
GetExport().GetMM100UnitConverter() ) &&
( ! IsXMLToken( sValue, XML_ALL ) ) )
{
GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
}
}
break;
}
}
}
}
}
void SvXMLAutoStylePoolP::exportStyleContent(
const css::uno::Reference< css::xml::sax::XDocumentHandler > &,
XmlStyleFamily nFamily,
const vector< XMLPropertyState >& rProperties,
const SvXMLExportPropertyMapper& rPropExp,
const SvXMLUnitConverter&,
const SvXMLNamespaceMap&
) const
{
if( nFamily != XmlStyleFamily::PAGE_MASTER )
return;
sal_Int32 nHeaderStartIndex(-1);
sal_Int32 nHeaderEndIndex(-1);
sal_Int32 nFooterStartIndex(-1);
sal_Int32 nFooterEndIndex(-1);
bool bHeaderStartIndex(false);
bool bHeaderEndIndex(false);
bool bFooterStartIndex(false);
bool bFooterEndIndex(false);
const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
sal_Int32 nIndex(0);
while(nIndex < aPropMapper->GetEntryCount())
{
switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
{
case CTF_PM_HEADERFLAG:
{
if (!bHeaderStartIndex)
{
nHeaderStartIndex = nIndex;
bHeaderStartIndex = true;
}
if (bFooterStartIndex && !bFooterEndIndex)
{
nFooterEndIndex = nIndex;
bFooterEndIndex = true;
}
}
break;
case CTF_PM_FOOTERFLAG:
{
if (!bFooterStartIndex)
{
nFooterStartIndex = nIndex;
bFooterStartIndex = true;
}
if (bHeaderStartIndex && !bHeaderEndIndex)
{
nHeaderEndIndex = nIndex;
bHeaderEndIndex = true;
}
}
break;
}
nIndex++;
}
if (!bHeaderEndIndex)
nHeaderEndIndex = nIndex;
if (!bFooterEndIndex)
nFooterEndIndex = nIndex;
// export header style element
{
SvXMLElementExport aElem(
GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
true, true );
rPropExp.exportXML(
GetExport(), rProperties,
nHeaderStartIndex, nHeaderEndIndex, SvXmlExportFlags::IGN_WS);
}
// export footer style
{
SvXMLElementExport aElem(
GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
true, true );
rPropExp.exportXML(
GetExport(), rProperties,
nFooterStartIndex, nFooterEndIndex, SvXmlExportFlags::IGN_WS);
}
}
SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
: pImpl( new SvXMLAutoStylePoolP_Impl( rExport ) )
{
}
SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
{
}
SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
{
return pImpl->GetExport();
}
// TODO: remove this
void SvXMLAutoStylePoolP::AddFamily(
XmlStyleFamily nFamily,
const OUString& rStrName,
SvXMLExportPropertyMapper* pMapper,
const OUString& aStrPrefix )
{
rtl::Reference <SvXMLExportPropertyMapper> xTmp = pMapper;
AddFamily( nFamily, rStrName, xTmp, aStrPrefix );
}
void SvXMLAutoStylePoolP::AddFamily(
XmlStyleFamily nFamily,
const OUString& rStrName,
const rtl::Reference < SvXMLExportPropertyMapper > & rMapper,
const OUString& rStrPrefix,
bool bAsFamily )
{
pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
}
void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
XmlStyleFamily nFamily,
const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
{
pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
}
void SvXMLAutoStylePoolP::RegisterName( XmlStyleFamily nFamily,
const OUString& rName )
{
pImpl->RegisterName( nFamily, rName );
}
void SvXMLAutoStylePoolP::RegisterDefinedName( XmlStyleFamily nFamily,
const OUString& rName )
{
pImpl->RegisterDefinedName( nFamily, rName );
}
void SvXMLAutoStylePoolP::GetRegisteredNames(
uno::Sequence<sal_Int32>& rFamilies,
uno::Sequence<OUString>& rNames )
{
pImpl->GetRegisteredNames( rFamilies, rNames );
}
void SvXMLAutoStylePoolP::RegisterNames(
uno::Sequence<sal_Int32> const & aFamilies,
uno::Sequence<OUString> const & aNames )
{
assert(aFamilies.getLength() == aNames.getLength());
// iterate over sequence(s) and call RegisterName(..) for each pair
const sal_Int32* pFamilies = aFamilies.getConstArray();
const OUString* pNames = aNames.getConstArray();
sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
for( sal_Int32 n = 0; n < nCount; n++ )
RegisterName( static_cast<XmlStyleFamily>(pFamilies[n]), pNames[n] );
}
OUString SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily,
const vector< XMLPropertyState >& rProperties )
{
OUString sName;
pImpl->Add(sName, nFamily, "", rProperties );
return sName;
}
OUString SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily,
const OUString& rParent,
const vector< XMLPropertyState >& rProperties, bool bDontSeek )
{
OUString sName;
pImpl->Add(sName, nFamily, rParent, rProperties, bDontSeek);
return sName;
}
bool SvXMLAutoStylePoolP::Add(OUString& rName, XmlStyleFamily nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
{
return pImpl->Add(rName, nFamily, rParent, rProperties);
}
bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, XmlStyleFamily nFamily, const OUString& rParent,
const ::std::vector< XMLPropertyState >& rProperties )
{
return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
}
OUString SvXMLAutoStylePoolP::Find( XmlStyleFamily nFamily,
const OUString& rParent,
const vector< XMLPropertyState >& rProperties ) const
{
return pImpl->Find( nFamily, rParent, rProperties );
}
void SvXMLAutoStylePoolP::exportXML( XmlStyleFamily nFamily ) const
{
pImpl->exportXML( nFamily, this );
}
void SvXMLAutoStylePoolP::ClearEntries()
{
pImpl->ClearEntries();
}
std::vector<xmloff::AutoStyleEntry> SvXMLAutoStylePoolP::GetAutoStyleEntries() const
{
return pImpl->GetAutoStyleEntries();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|