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 .
21 #include <autoform.hxx>
23 #include <sal/log.hxx>
24 #include <sfx2/docfile.hxx>
25 #include <unotools/pathoptions.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/itemset.hxx>
28 #include <vcl/outdev.hxx>
29 #include <svx/algitem.hxx>
30 #include <svx/dialmgr.hxx>
31 #include <svx/rotmodit.hxx>
32 #include <svx/strings.hrc>
33 #include <editeng/adjustitem.hxx>
34 #include <editeng/borderline.hxx>
35 #include <editeng/boxitem.hxx>
36 #include <editeng/brushitem.hxx>
37 #include <editeng/colritem.hxx>
38 #include <editeng/contouritem.hxx>
39 #include <editeng/crossedoutitem.hxx>
40 #include <editeng/fhgtitem.hxx>
41 #include <editeng/fontitem.hxx>
42 #include <editeng/justifyitem.hxx>
43 #include <editeng/langitem.hxx>
44 #include <editeng/lineitem.hxx>
45 #include <editeng/postitem.hxx>
46 #include <editeng/shdditem.hxx>
47 #include <editeng/udlnitem.hxx>
48 #include <editeng/wghtitem.hxx>
49 #include <tools/urlobj.hxx>
50 #include <comphelper/fileformat.h>
51 #include <unotools/collatorwrapper.hxx>
52 #include <unotools/transliterationwrapper.hxx>
53 #include <tools/tenccvt.hxx>
54 #include <osl/diagnose.h>
55 #include <osl/thread.hxx>
58 #include <globstr.hrc>
59 #include <scitems.hxx>
60 #include <scresid.hxx>
61 #include <document.hxx>
64 * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST
65 * be synchronized with Writer's SwTableAutoFmtTbl sw/source/core/doc/tblafmt.cxx
68 constexpr OUString sAutoTblFmtName
= u
"autotbl.fmt"_ustr
;
71 const sal_uInt16 AUTOFORMAT_ID_X
= 9501;
72 const sal_uInt16 AUTOFORMAT_ID_358
= 9601;
73 const sal_uInt16 AUTOFORMAT_DATA_ID_X
= 9502;
76 // in following versions the value of the IDs must be higher
77 const sal_uInt16 AUTOFORMAT_ID_504
= 9801;
78 const sal_uInt16 AUTOFORMAT_DATA_ID_504
= 9802;
80 const sal_uInt16 AUTOFORMAT_DATA_ID_552
= 9902;
82 // --- from 680/dr25 on: store strings as UTF-8
83 const sal_uInt16 AUTOFORMAT_ID_680DR25
= 10021;
85 // --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc)
86 const sal_uInt16 AUTOFORMAT_ID_31005
= 10041;
87 const sal_uInt16 AUTOFORMAT_DATA_ID_31005
= 10042;
90 const sal_uInt16 AUTOFORMAT_ID
= AUTOFORMAT_ID_31005
;
91 const sal_uInt16 AUTOFORMAT_DATA_ID
= AUTOFORMAT_DATA_ID_31005
;
95 /// Read an AutoFormatSwBlob from stream.
96 SvStream
& operator>>(SvStream
&stream
, AutoFormatSwBlob
&blob
)
100 sal_uInt64 endOfBlob
= 0;
101 stream
.ReadUInt64( endOfBlob
);
103 const sal_uInt64 currentPosition
= stream
.Tell();
104 const sal_uInt64 blobSize
= endOfBlob
- currentPosition
;
105 // A zero-size indicates an empty blob. This happens when Calc creates a new autoformat,
106 // since it (naturally) doesn't have any writer-specific data to write.
109 blob
.pData
.reset(new sal_uInt8
[blobSize
]);
110 blob
.size
= static_cast<std::size_t>(blobSize
);
111 stream
.ReadBytes(blob
.pData
.get(), blob
.size
);
117 /// Write an AutoFormatSwBlob to stream.
118 SvStream
& WriteAutoFormatSwBlob(SvStream
&stream
, const AutoFormatSwBlob
&blob
)
120 const sal_uInt64 endOfBlob
= stream
.Tell() + sizeof(sal_uInt64
) + blob
.size
;
121 stream
.WriteUInt64( endOfBlob
);
123 stream
.WriteBytes(blob
.pData
.get(), blob
.size
);
129 ScAfVersions::ScAfVersions()
133 void ScAfVersions::Load( SvStream
& rStream
, sal_uInt16 nVer
)
135 LoadBlockA(rStream
, nVer
);
136 if (nVer
>= AUTOFORMAT_ID_31005
)
138 rStream
>> swVersions
;
140 LoadBlockB(rStream
, nVer
);
143 void ScAfVersions::Write(SvStream
& rStream
, sal_uInt16 fileVersion
)
145 AutoFormatVersions::WriteBlockA(rStream
, fileVersion
);
147 if (fileVersion
>= SOFFICE_FILEFORMAT_50
)
149 WriteAutoFormatSwBlob( rStream
, swVersions
);
152 AutoFormatVersions::WriteBlockB(rStream
, fileVersion
);
155 ScAutoFormatDataField::ScAutoFormatDataField()
157 // need to set default instances for base class AutoFormatBase here
158 // due to resource defines (e.g. ATTR_FONT) which are not available
159 // in svx and different in the different usages of derivations
160 m_aFont
= std::make_unique
<SvxFontItem
>(ATTR_FONT
);
161 m_aHeight
= std::make_unique
<SvxFontHeightItem
>(240, 100, ATTR_FONT_HEIGHT
);
162 m_aWeight
= std::make_unique
<SvxWeightItem
>(WEIGHT_NORMAL
, ATTR_FONT_WEIGHT
);
163 m_aPosture
= std::make_unique
<SvxPostureItem
>(ITALIC_NONE
, ATTR_FONT_POSTURE
);
164 m_aCJKFont
= std::make_unique
<SvxFontItem
>(ATTR_CJK_FONT
);
165 m_aCJKHeight
= std::make_unique
<SvxFontHeightItem
>(240, 100, ATTR_CJK_FONT_HEIGHT
);
166 m_aCJKWeight
= std::make_unique
<SvxWeightItem
>(WEIGHT_NORMAL
, ATTR_CJK_FONT_WEIGHT
);
167 m_aCJKPosture
= std::make_unique
<SvxPostureItem
>(ITALIC_NONE
, ATTR_CJK_FONT_POSTURE
);
168 m_aCTLFont
= std::make_unique
<SvxFontItem
>(ATTR_CTL_FONT
);
169 m_aCTLHeight
= std::make_unique
<SvxFontHeightItem
>(240, 100, ATTR_CTL_FONT_HEIGHT
);
170 m_aCTLWeight
= std::make_unique
<SvxWeightItem
>(WEIGHT_NORMAL
, ATTR_CTL_FONT_WEIGHT
);
171 m_aCTLPosture
= std::make_unique
<SvxPostureItem
>(ITALIC_NONE
, ATTR_CTL_FONT_POSTURE
);
172 m_aUnderline
= std::make_unique
<SvxUnderlineItem
>(LINESTYLE_NONE
,ATTR_FONT_UNDERLINE
);
173 m_aOverline
= std::make_unique
<SvxOverlineItem
>(LINESTYLE_NONE
,ATTR_FONT_OVERLINE
);
174 m_aCrossedOut
= std::make_unique
<SvxCrossedOutItem
>(STRIKEOUT_NONE
, ATTR_FONT_CROSSEDOUT
);
175 m_aContour
= std::make_unique
<SvxContourItem
>(false, ATTR_FONT_CONTOUR
);
176 m_aShadowed
= std::make_unique
<SvxShadowedItem
>(false, ATTR_FONT_SHADOWED
);
177 m_aColor
= std::make_unique
<SvxColorItem
>(ATTR_FONT_COLOR
);
178 m_aBox
= std::make_unique
<SvxBoxItem
>(ATTR_BORDER
);
179 m_aTLBR
= std::make_unique
<SvxLineItem
>(ATTR_BORDER_TLBR
);
180 m_aBLTR
= std::make_unique
<SvxLineItem
>(ATTR_BORDER_BLTR
);
181 m_aBackground
= std::make_unique
<SvxBrushItem
>(ATTR_BACKGROUND
);
182 m_aAdjust
= std::make_unique
<SvxAdjustItem
>(SvxAdjust::Left
, 0);
183 m_aHorJustify
= std::make_unique
<SvxHorJustifyItem
>(SvxCellHorJustify::Standard
, ATTR_HOR_JUSTIFY
);
184 m_aVerJustify
= std::make_unique
<SvxVerJustifyItem
>(SvxCellVerJustify::Standard
, ATTR_VER_JUSTIFY
);
185 m_aStacked
= std::make_unique
<ScVerticalStackCell
>();
186 m_aMargin
= std::make_unique
<SvxMarginItem
>(ATTR_MARGIN
);
187 m_aLinebreak
= std::make_unique
<ScLineBreakCell
>();
188 m_aRotateAngle
= std::make_unique
<ScRotateValueItem
>(0_deg100
);
189 m_aRotateMode
= std::make_unique
<SvxRotateModeItem
>(SVX_ROTATE_MODE_STANDARD
, ATTR_ROTATE_MODE
);
192 ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField
& rCopy
)
193 : AutoFormatBase(rCopy
),
194 // m_swFields was not copied in original, needed?
195 aNumFormat( rCopy
.aNumFormat
)
199 ScAutoFormatDataField::~ScAutoFormatDataField()
203 bool ScAutoFormatDataField::Load( SvStream
& rStream
, const ScAfVersions
& rVersions
, sal_uInt16 nVer
)
205 LoadBlockA( rStream
, rVersions
, nVer
);
207 if (nVer
>= AUTOFORMAT_DATA_ID_31005
)
209 rStream
>> m_swFields
;
212 LoadBlockB( rStream
, rVersions
, nVer
);
214 if( 0 == rVersions
.nNumFormatVersion
)
216 // --- from 680/dr25 on: store strings as UTF-8
217 rtl_TextEncoding eCharSet
= (nVer
>= AUTOFORMAT_ID_680DR25
) ? RTL_TEXTENCODING_UTF8
: rStream
.GetStreamCharSet();
218 aNumFormat
.Load( rStream
, eCharSet
);
221 // adjust charset in font
222 rtl_TextEncoding eSysSet
= osl_getThreadTextEncoding();
223 rtl_TextEncoding eSrcSet
= rStream
.GetStreamCharSet();
224 if( eSrcSet
!= eSysSet
&& m_aFont
->GetCharSet() == eSrcSet
)
225 m_aFont
->SetCharSet(eSysSet
);
227 return (rStream
.GetError() == ERRCODE_NONE
);
230 bool ScAutoFormatDataField::Save( SvStream
& rStream
, sal_uInt16 fileVersion
)
232 SaveBlockA( rStream
, fileVersion
);
234 if (fileVersion
>= SOFFICE_FILEFORMAT_50
)
236 WriteAutoFormatSwBlob( rStream
, m_swFields
);
239 SaveBlockB( rStream
, fileVersion
);
241 // --- from 680/dr25 on: store strings as UTF-8
242 aNumFormat
.Save( rStream
, RTL_TEXTENCODING_UTF8
);
244 return (rStream
.GetError() == ERRCODE_NONE
);
247 ScAutoFormatData::ScAutoFormatData()
249 nStrResId
= USHRT_MAX
;
251 bIncludeValueFormat
=
256 bIncludeWidthHeight
= true;
258 for( sal_uInt16 nIndex
= 0; nIndex
< 16; ++nIndex
)
259 ppDataField
[ nIndex
].reset( new ScAutoFormatDataField
);
262 ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData
& rData
) :
263 aName( rData
.aName
),
264 nStrResId( rData
.nStrResId
),
265 bIncludeFont( rData
.bIncludeFont
),
266 bIncludeJustify( rData
.bIncludeJustify
),
267 bIncludeFrame( rData
.bIncludeFrame
),
268 bIncludeBackground( rData
.bIncludeBackground
),
269 bIncludeValueFormat( rData
.bIncludeValueFormat
),
270 bIncludeWidthHeight( rData
.bIncludeWidthHeight
)
272 for( sal_uInt16 nIndex
= 0; nIndex
< 16; ++nIndex
)
273 ppDataField
[ nIndex
].reset( new ScAutoFormatDataField( rData
.GetField( nIndex
) ) );
276 ScAutoFormatData::~ScAutoFormatData()
280 ScAutoFormatDataField
& ScAutoFormatData::GetField( sal_uInt16 nIndex
)
282 OSL_ENSURE( nIndex
< 16, "ScAutoFormatData::GetField - illegal index" );
283 OSL_ENSURE( ppDataField
[ nIndex
], "ScAutoFormatData::GetField - no data" );
284 return *ppDataField
[ nIndex
];
287 const ScAutoFormatDataField
& ScAutoFormatData::GetField( sal_uInt16 nIndex
) const
289 OSL_ENSURE( nIndex
< 16, "ScAutoFormatData::GetField - illegal index" );
290 OSL_ENSURE( ppDataField
[ nIndex
], "ScAutoFormatData::GetField - no data" );
291 return *ppDataField
[ nIndex
];
294 const SfxPoolItem
* ScAutoFormatData::GetItem( sal_uInt16 nIndex
, sal_uInt16 nWhich
) const
296 const ScAutoFormatDataField
& rField
= GetField( nIndex
);
299 case ATTR_FONT
: return &rField
.GetFont();
300 case ATTR_FONT_HEIGHT
: return &rField
.GetHeight();
301 case ATTR_FONT_WEIGHT
: return &rField
.GetWeight();
302 case ATTR_FONT_POSTURE
: return &rField
.GetPosture();
303 case ATTR_CJK_FONT
: return &rField
.GetCJKFont();
304 case ATTR_CJK_FONT_HEIGHT
: return &rField
.GetCJKHeight();
305 case ATTR_CJK_FONT_WEIGHT
: return &rField
.GetCJKWeight();
306 case ATTR_CJK_FONT_POSTURE
: return &rField
.GetCJKPosture();
307 case ATTR_CTL_FONT
: return &rField
.GetCTLFont();
308 case ATTR_CTL_FONT_HEIGHT
: return &rField
.GetCTLHeight();
309 case ATTR_CTL_FONT_WEIGHT
: return &rField
.GetCTLWeight();
310 case ATTR_CTL_FONT_POSTURE
: return &rField
.GetCTLPosture();
311 case ATTR_FONT_UNDERLINE
: return &rField
.GetUnderline();
312 case ATTR_FONT_OVERLINE
: return &rField
.GetOverline();
313 case ATTR_FONT_CROSSEDOUT
: return &rField
.GetCrossedOut();
314 case ATTR_FONT_CONTOUR
: return &rField
.GetContour();
315 case ATTR_FONT_SHADOWED
: return &rField
.GetShadowed();
316 case ATTR_FONT_COLOR
: return &rField
.GetColor();
317 case ATTR_BORDER
: return &rField
.GetBox();
318 case ATTR_BORDER_TLBR
: return &rField
.GetTLBR();
319 case ATTR_BORDER_BLTR
: return &rField
.GetBLTR();
320 case ATTR_BACKGROUND
: return &rField
.GetBackground();
321 case ATTR_HOR_JUSTIFY
: return &rField
.GetHorJustify();
322 case ATTR_VER_JUSTIFY
: return &rField
.GetVerJustify();
323 case ATTR_STACKED
: return &rField
.GetStacked();
324 case ATTR_MARGIN
: return &rField
.GetMargin();
325 case ATTR_LINEBREAK
: return &rField
.GetLinebreak();
326 case ATTR_ROTATE_VALUE
: return &rField
.GetRotateAngle();
327 case ATTR_ROTATE_MODE
: return &rField
.GetRotateMode();
332 void ScAutoFormatData::PutItem( sal_uInt16 nIndex
, const SfxPoolItem
& rItem
)
334 ScAutoFormatDataField
& rField
= GetField( nIndex
);
335 switch( rItem
.Which() )
337 case ATTR_FONT
: rField
.SetFont( rItem
.StaticWhichCast(ATTR_FONT
) ); break;
338 case ATTR_FONT_HEIGHT
: rField
.SetHeight( rItem
.StaticWhichCast(ATTR_FONT_HEIGHT
) ); break;
339 case ATTR_FONT_WEIGHT
: rField
.SetWeight( rItem
.StaticWhichCast(ATTR_FONT_WEIGHT
) ); break;
340 case ATTR_FONT_POSTURE
: rField
.SetPosture( rItem
.StaticWhichCast(ATTR_FONT_POSTURE
) ); break;
341 case ATTR_CJK_FONT
: rField
.SetCJKFont( rItem
.StaticWhichCast(ATTR_CJK_FONT
) ); break;
342 case ATTR_CJK_FONT_HEIGHT
: rField
.SetCJKHeight( rItem
.StaticWhichCast(ATTR_CJK_FONT_HEIGHT
) ); break;
343 case ATTR_CJK_FONT_WEIGHT
: rField
.SetCJKWeight( rItem
.StaticWhichCast(ATTR_CJK_FONT_WEIGHT
) ); break;
344 case ATTR_CJK_FONT_POSTURE
: rField
.SetCJKPosture( rItem
.StaticWhichCast(ATTR_CJK_FONT_POSTURE
) ); break;
345 case ATTR_CTL_FONT
: rField
.SetCTLFont( rItem
.StaticWhichCast(ATTR_CTL_FONT
) ); break;
346 case ATTR_CTL_FONT_HEIGHT
: rField
.SetCTLHeight( rItem
.StaticWhichCast(ATTR_CTL_FONT_HEIGHT
) ); break;
347 case ATTR_CTL_FONT_WEIGHT
: rField
.SetCTLWeight( rItem
.StaticWhichCast(ATTR_CTL_FONT_WEIGHT
) ); break;
348 case ATTR_CTL_FONT_POSTURE
: rField
.SetCTLPosture( rItem
.StaticWhichCast(ATTR_CTL_FONT_POSTURE
) ); break;
349 case ATTR_FONT_UNDERLINE
: rField
.SetUnderline( rItem
.StaticWhichCast(ATTR_FONT_UNDERLINE
) ); break;
350 case ATTR_FONT_OVERLINE
: rField
.SetOverline( rItem
.StaticWhichCast(ATTR_FONT_OVERLINE
) ); break;
351 case ATTR_FONT_CROSSEDOUT
: rField
.SetCrossedOut( rItem
.StaticWhichCast(ATTR_FONT_CROSSEDOUT
) ); break;
352 case ATTR_FONT_CONTOUR
: rField
.SetContour( rItem
.StaticWhichCast(ATTR_FONT_CONTOUR
) ); break;
353 case ATTR_FONT_SHADOWED
: rField
.SetShadowed( rItem
.StaticWhichCast(ATTR_FONT_SHADOWED
) ); break;
354 case ATTR_FONT_COLOR
: rField
.SetColor( rItem
.StaticWhichCast(ATTR_FONT_COLOR
) ); break;
355 case ATTR_BORDER
: rField
.SetBox( rItem
.StaticWhichCast(ATTR_BORDER
) ); break;
356 case ATTR_BORDER_TLBR
: rField
.SetTLBR( rItem
.StaticWhichCast(ATTR_BORDER_TLBR
) ); break;
357 case ATTR_BORDER_BLTR
: rField
.SetBLTR( rItem
.StaticWhichCast(ATTR_BORDER_BLTR
) ); break;
358 case ATTR_BACKGROUND
: rField
.SetBackground( rItem
.StaticWhichCast(ATTR_BACKGROUND
) ); break;
359 case ATTR_HOR_JUSTIFY
: rField
.SetHorJustify( rItem
.StaticWhichCast(ATTR_HOR_JUSTIFY
) ); break;
360 case ATTR_VER_JUSTIFY
: rField
.SetVerJustify( rItem
.StaticWhichCast(ATTR_VER_JUSTIFY
) ); break;
361 case ATTR_STACKED
: rField
.SetStacked( rItem
.StaticWhichCast(ATTR_STACKED
) ); break;
362 case ATTR_MARGIN
: rField
.SetMargin( rItem
.StaticWhichCast(ATTR_MARGIN
) ); break;
363 case ATTR_LINEBREAK
: rField
.SetLinebreak( rItem
.StaticWhichCast(ATTR_LINEBREAK
) ); break;
364 case ATTR_ROTATE_VALUE
: rField
.SetRotateAngle( rItem
.StaticWhichCast(ATTR_ROTATE_VALUE
) ); break;
365 case ATTR_ROTATE_MODE
: rField
.SetRotateMode( rItem
.StaticWhichCast(ATTR_ROTATE_MODE
) ); break;
369 void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex
, sal_uInt16 nFromIndex
, sal_uInt16 nWhich
)
371 const SfxPoolItem
* pItem
= GetItem( nFromIndex
, nWhich
);
373 PutItem( nToIndex
, *pItem
);
376 const ScNumFormatAbbrev
& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex
) const
378 return GetField( nIndex
).GetNumFormat();
381 bool ScAutoFormatData::HasSameData( sal_uInt16 nIndex1
, sal_uInt16 nIndex2
) const
384 const ScAutoFormatDataField
& rField1
= GetField( nIndex1
);
385 const ScAutoFormatDataField
& rField2
= GetField( nIndex2
);
387 if( bIncludeValueFormat
)
390 && (rField1
.GetNumFormat() == rField2
.GetNumFormat());
395 && (rField1
.GetFont() == rField2
.GetFont())
396 && (rField1
.GetHeight() == rField2
.GetHeight())
397 && (rField1
.GetWeight() == rField2
.GetWeight())
398 && (rField1
.GetPosture() == rField2
.GetPosture())
399 && (rField1
.GetCJKFont() == rField2
.GetCJKFont())
400 && (rField1
.GetCJKHeight() == rField2
.GetCJKHeight())
401 && (rField1
.GetCJKWeight() == rField2
.GetCJKWeight())
402 && (rField1
.GetCJKPosture() == rField2
.GetCJKPosture())
403 && (rField1
.GetCTLFont() == rField2
.GetCTLFont())
404 && (rField1
.GetCTLHeight() == rField2
.GetCTLHeight())
405 && (rField1
.GetCTLWeight() == rField2
.GetCTLWeight())
406 && (rField1
.GetCTLPosture() == rField2
.GetCTLPosture())
407 && (rField1
.GetUnderline() == rField2
.GetUnderline())
408 && (rField1
.GetOverline() == rField2
.GetOverline())
409 && (rField1
.GetCrossedOut() == rField2
.GetCrossedOut())
410 && (rField1
.GetContour() == rField2
.GetContour())
411 && (rField1
.GetShadowed() == rField2
.GetShadowed())
412 && (rField1
.GetColor() == rField2
.GetColor());
414 if( bIncludeJustify
)
417 && (rField1
.GetHorJustify() == rField2
.GetHorJustify())
418 && (rField1
.GetVerJustify() == rField2
.GetVerJustify())
419 && (rField1
.GetStacked() == rField2
.GetStacked())
420 && (rField1
.GetLinebreak() == rField2
.GetLinebreak())
421 && (rField1
.GetMargin() == rField2
.GetMargin())
422 && (rField1
.GetRotateAngle() == rField2
.GetRotateAngle())
423 && (rField1
.GetRotateMode() == rField2
.GetRotateMode());
428 && (rField1
.GetBox() == rField2
.GetBox())
429 && (rField1
.GetTLBR() == rField2
.GetTLBR())
430 && (rField1
.GetBLTR() == rField2
.GetBLTR());
432 if( bIncludeBackground
)
435 && (rField1
.GetBackground() == rField2
.GetBackground());
440 void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex
, SfxItemSet
& rItemSet
, const ScDocument
& rDoc
) const
442 const ScAutoFormatDataField
& rField
= GetField( nIndex
);
444 if( bIncludeValueFormat
)
446 ScNumFormatAbbrev
& rNumFormat
= const_cast<ScNumFormatAbbrev
&>(rField
.GetNumFormat());
447 SfxUInt32Item
aValueFormat( ATTR_VALUE_FORMAT
, 0 );
448 aValueFormat
.SetValue( rNumFormat
.GetFormatIndex( *rDoc
.GetFormatTable() ) );
449 rItemSet
.Put( aValueFormat
);
450 rItemSet
.Put( SvxLanguageItem( rNumFormat
.GetLanguage(), ATTR_LANGUAGE_FORMAT
) );
454 rItemSet
.Put( rField
.GetFont() );
455 rItemSet
.Put( rField
.GetHeight() );
456 rItemSet
.Put( rField
.GetWeight() );
457 rItemSet
.Put( rField
.GetPosture() );
458 // do not insert empty CJK font
459 const SvxFontItem
& rCJKFont
= rField
.GetCJKFont();
460 if (!rCJKFont
.GetStyleName().isEmpty())
462 rItemSet
.Put( rCJKFont
);
463 rItemSet
.Put( rField
.GetCJKHeight() );
464 rItemSet
.Put( rField
.GetCJKWeight() );
465 rItemSet
.Put( rField
.GetCJKPosture() );
469 SvxFontHeightItem
aFontHeightItem(rField
.GetHeight());
470 aFontHeightItem
.SetWhich(ATTR_CJK_FONT_HEIGHT
);
471 rItemSet
.Put( aFontHeightItem
);
472 SvxWeightItem
aWeightItem(rField
.GetWeight());
473 aWeightItem
.SetWhich(ATTR_CJK_FONT_WEIGHT
);
474 rItemSet
.Put( aWeightItem
);
475 SvxPostureItem
aPostureItem(rField
.GetPosture());
476 aPostureItem
.SetWhich(ATTR_CJK_FONT_POSTURE
);
477 rItemSet
.Put( aPostureItem
);
479 // do not insert empty CTL font
480 const SvxFontItem
& rCTLFont
= rField
.GetCTLFont();
481 if (!rCTLFont
.GetStyleName().isEmpty())
483 rItemSet
.Put( rCTLFont
);
484 rItemSet
.Put( rField
.GetCTLHeight() );
485 rItemSet
.Put( rField
.GetCTLWeight() );
486 rItemSet
.Put( rField
.GetCTLPosture() );
490 SvxFontHeightItem
aFontHeightItem(rField
.GetHeight());
491 aFontHeightItem
.SetWhich(ATTR_CTL_FONT_HEIGHT
);
492 rItemSet
.Put( aFontHeightItem
);
493 SvxWeightItem
aWeightItem(rField
.GetWeight());
494 aWeightItem
.SetWhich(ATTR_CTL_FONT_WEIGHT
);
495 rItemSet
.Put( aWeightItem
);
496 SvxPostureItem
aPostureItem(rField
.GetPosture());
497 aPostureItem
.SetWhich(ATTR_CTL_FONT_POSTURE
);
498 rItemSet
.Put( aPostureItem
);
500 rItemSet
.Put( rField
.GetUnderline() );
501 rItemSet
.Put( rField
.GetOverline() );
502 rItemSet
.Put( rField
.GetCrossedOut() );
503 rItemSet
.Put( rField
.GetContour() );
504 rItemSet
.Put( rField
.GetShadowed() );
505 rItemSet
.Put( rField
.GetColor() );
507 if( bIncludeJustify
)
509 rItemSet
.Put( rField
.GetHorJustify() );
510 rItemSet
.Put( rField
.GetVerJustify() );
511 rItemSet
.Put( rField
.GetStacked() );
512 rItemSet
.Put( rField
.GetLinebreak() );
513 rItemSet
.Put( rField
.GetMargin() );
514 rItemSet
.Put( rField
.GetRotateAngle() );
515 rItemSet
.Put( rField
.GetRotateMode() );
519 rItemSet
.Put( rField
.GetBox() );
520 rItemSet
.Put( rField
.GetTLBR() );
521 rItemSet
.Put( rField
.GetBLTR() );
523 if( bIncludeBackground
)
524 rItemSet
.Put( rField
.GetBackground() );
527 void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex
, const SfxItemSet
& rItemSet
, const ScNumFormatAbbrev
& rNumFormat
)
529 ScAutoFormatDataField
& rField
= GetField( nIndex
);
531 rField
.SetNumFormat ( rNumFormat
);
532 rField
.SetFont ( rItemSet
.Get( ATTR_FONT
) );
533 rField
.SetHeight ( rItemSet
.Get( ATTR_FONT_HEIGHT
) );
534 rField
.SetWeight ( rItemSet
.Get( ATTR_FONT_WEIGHT
) );
535 rField
.SetPosture ( rItemSet
.Get( ATTR_FONT_POSTURE
) );
536 rField
.SetCJKFont ( rItemSet
.Get( ATTR_CJK_FONT
) );
537 rField
.SetCJKHeight ( rItemSet
.Get( ATTR_CJK_FONT_HEIGHT
) );
538 rField
.SetCJKWeight ( rItemSet
.Get( ATTR_CJK_FONT_WEIGHT
) );
539 rField
.SetCJKPosture ( rItemSet
.Get( ATTR_CJK_FONT_POSTURE
) );
540 rField
.SetCTLFont ( rItemSet
.Get( ATTR_CTL_FONT
) );
541 rField
.SetCTLHeight ( rItemSet
.Get( ATTR_CTL_FONT_HEIGHT
) );
542 rField
.SetCTLWeight ( rItemSet
.Get( ATTR_CTL_FONT_WEIGHT
) );
543 rField
.SetCTLPosture ( rItemSet
.Get( ATTR_CTL_FONT_POSTURE
) );
544 rField
.SetUnderline ( rItemSet
.Get( ATTR_FONT_UNDERLINE
) );
545 rField
.SetOverline ( rItemSet
.Get( ATTR_FONT_OVERLINE
) );
546 rField
.SetCrossedOut ( rItemSet
.Get( ATTR_FONT_CROSSEDOUT
) );
547 rField
.SetContour ( rItemSet
.Get( ATTR_FONT_CONTOUR
) );
548 rField
.SetShadowed ( rItemSet
.Get( ATTR_FONT_SHADOWED
) );
549 rField
.SetColor ( rItemSet
.Get( ATTR_FONT_COLOR
) );
550 rField
.SetTLBR ( rItemSet
.Get( ATTR_BORDER_TLBR
) );
551 rField
.SetBLTR ( rItemSet
.Get( ATTR_BORDER_BLTR
) );
552 rField
.SetHorJustify ( rItemSet
.Get( ATTR_HOR_JUSTIFY
) );
553 rField
.SetVerJustify ( rItemSet
.Get( ATTR_VER_JUSTIFY
) );
554 rField
.SetStacked ( rItemSet
.Get( ATTR_STACKED
) );
555 rField
.SetLinebreak ( rItemSet
.Get( ATTR_LINEBREAK
) );
556 rField
.SetMargin ( rItemSet
.Get( ATTR_MARGIN
) );
557 rField
.SetBackground ( rItemSet
.Get( ATTR_BACKGROUND
) );
558 rField
.SetRotateAngle ( rItemSet
.Get( ATTR_ROTATE_VALUE
) );
559 rField
.SetRotateMode ( rItemSet
.Get( ATTR_ROTATE_MODE
) );
562 const TranslateId RID_SVXSTR_TBLAFMT
[] =
564 RID_SVXSTR_TBLAFMT_3D
,
565 RID_SVXSTR_TBLAFMT_BLACK1
,
566 RID_SVXSTR_TBLAFMT_BLACK2
,
567 RID_SVXSTR_TBLAFMT_BLUE
,
568 RID_SVXSTR_TBLAFMT_BROWN
,
569 RID_SVXSTR_TBLAFMT_CURRENCY
,
570 RID_SVXSTR_TBLAFMT_CURRENCY_3D
,
571 RID_SVXSTR_TBLAFMT_CURRENCY_GRAY
,
572 RID_SVXSTR_TBLAFMT_CURRENCY_LAVENDER
,
573 RID_SVXSTR_TBLAFMT_CURRENCY_TURQUOISE
,
574 RID_SVXSTR_TBLAFMT_GRAY
,
575 RID_SVXSTR_TBLAFMT_GREEN
,
576 RID_SVXSTR_TBLAFMT_LAVENDER
,
577 RID_SVXSTR_TBLAFMT_RED
,
578 RID_SVXSTR_TBLAFMT_TURQUOISE
,
579 RID_SVXSTR_TBLAFMT_YELLOW
,
580 RID_SVXSTR_TBLAFMT_LO6_ACADEMIC
,
581 RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_BLUE
,
582 RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_GREEN
,
583 RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_RED
,
584 RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_YELLOW
,
585 RID_SVXSTR_TBLAFMT_LO6_ELEGANT
,
586 RID_SVXSTR_TBLAFMT_LO6_FINANCIAL
,
587 RID_SVXSTR_TBLAFMT_LO6_SIMPLE_GRID_COLUMNS
,
588 RID_SVXSTR_TBLAFMT_LO6_SIMPLE_GRID_ROWS
,
589 RID_SVXSTR_TBLAFMT_LO6_SIMPLE_LIST_SHADED
592 bool ScAutoFormatData::Load( SvStream
& rStream
, const ScAfVersions
& rVersions
)
595 rStream
.ReadUInt16( nVer
);
596 bool bRet
= ERRCODE_NONE
== rStream
.GetError();
597 if( bRet
&& (nVer
== AUTOFORMAT_DATA_ID_X
||
598 (AUTOFORMAT_DATA_ID_504
<= nVer
&& nVer
<= AUTOFORMAT_DATA_ID
)) )
600 // --- from 680/dr25 on: store strings as UTF-8
601 if (nVer
>= AUTOFORMAT_ID_680DR25
)
603 aName
= read_uInt16_lenPrefixed_uInt8s_ToOUString(rStream
,
604 RTL_TEXTENCODING_UTF8
);
607 aName
= rStream
.ReadUniOrByteString( rStream
.GetStreamCharSet() );
609 if( AUTOFORMAT_DATA_ID_552
<= nVer
)
611 rStream
.ReadUInt16( nStrResId
);
612 if (nStrResId
< SAL_N_ELEMENTS(RID_SVXSTR_TBLAFMT
))
613 aName
= SvxResId(RID_SVXSTR_TBLAFMT
[nStrResId
]);
615 nStrResId
= USHRT_MAX
;
619 rStream
.ReadCharAsBool( b
); bIncludeFont
= b
;
620 rStream
.ReadCharAsBool( b
); bIncludeJustify
= b
;
621 rStream
.ReadCharAsBool( b
); bIncludeFrame
= b
;
622 rStream
.ReadCharAsBool( b
); bIncludeBackground
= b
;
623 rStream
.ReadCharAsBool( b
); bIncludeValueFormat
= b
;
624 rStream
.ReadCharAsBool( b
); bIncludeWidthHeight
= b
;
626 if (nVer
>= AUTOFORMAT_DATA_ID_31005
)
627 rStream
>> m_swFields
;
629 bRet
= ERRCODE_NONE
== rStream
.GetError();
630 for( sal_uInt16 i
= 0; bRet
&& i
< 16; ++i
)
631 bRet
= GetField( i
).Load( rStream
, rVersions
, nVer
);
638 bool ScAutoFormatData::Save(SvStream
& rStream
, sal_uInt16 fileVersion
)
640 rStream
.WriteUInt16( AUTOFORMAT_DATA_ID
);
641 // --- from 680/dr25 on: store strings as UTF-8
642 write_uInt16_lenPrefixed_uInt8s_FromOUString(rStream
, aName
, RTL_TEXTENCODING_UTF8
);
644 rStream
.WriteUInt16( nStrResId
);
645 rStream
.WriteBool( bIncludeFont
);
646 rStream
.WriteBool( bIncludeJustify
);
647 rStream
.WriteBool( bIncludeFrame
);
648 rStream
.WriteBool( bIncludeBackground
);
649 rStream
.WriteBool( bIncludeValueFormat
);
650 rStream
.WriteBool( bIncludeWidthHeight
);
652 if (fileVersion
>= SOFFICE_FILEFORMAT_50
)
653 WriteAutoFormatSwBlob( rStream
, m_swFields
);
655 bool bRet
= ERRCODE_NONE
== rStream
.GetError();
656 for (sal_uInt16 i
= 0; bRet
&& (i
< 16); i
++)
657 bRet
= GetField( i
).Save( rStream
, fileVersion
);
662 ScAutoFormat::ScAutoFormat() :
665 // create default autoformat
666 std::unique_ptr
<ScAutoFormatData
> pData(new ScAutoFormatData
);
667 OUString
aName(ScResId(STR_STYLENAME_STANDARD
));
668 pData
->SetName(aName
);
670 // default font, default height
671 vcl::Font aStdFont
= OutputDevice::GetDefaultFont(
672 DefaultFontType::LATIN_SPREADSHEET
, LANGUAGE_ENGLISH_US
, GetDefaultFontFlags::OnlyOne
);
673 SvxFontItem
aFontItem(
674 aStdFont
.GetFamilyType(), aStdFont
.GetFamilyName(), aStdFont
.GetStyleName(),
675 aStdFont
.GetPitch(), aStdFont
.GetCharSet(), ATTR_FONT
);
677 aStdFont
= OutputDevice::GetDefaultFont(
678 DefaultFontType::CJK_SPREADSHEET
, LANGUAGE_ENGLISH_US
, GetDefaultFontFlags::OnlyOne
);
679 SvxFontItem
aCJKFontItem(
680 aStdFont
.GetFamilyType(), aStdFont
.GetFamilyName(), aStdFont
.GetStyleName(),
681 aStdFont
.GetPitch(), aStdFont
.GetCharSet(), ATTR_CJK_FONT
);
683 aStdFont
= OutputDevice::GetDefaultFont(
684 DefaultFontType::CTL_SPREADSHEET
, LANGUAGE_ENGLISH_US
, GetDefaultFontFlags::OnlyOne
);
685 SvxFontItem
aCTLFontItem(
686 aStdFont
.GetFamilyType(), aStdFont
.GetFamilyName(), aStdFont
.GetStyleName(),
687 aStdFont
.GetPitch(), aStdFont
.GetCharSet(), ATTR_CTL_FONT
);
689 SvxFontHeightItem
aHeight( 200, 100, ATTR_FONT_HEIGHT
); // 10 pt;
692 Color
aBlack( COL_BLACK
);
693 ::editeng::SvxBorderLine
aLine( &aBlack
, SvxBorderLineWidth::VeryThin
);
694 SvxBoxItem
aBox( ATTR_BORDER
);
695 aBox
.SetLine(&aLine
, SvxBoxItemLine::LEFT
);
696 aBox
.SetLine(&aLine
, SvxBoxItemLine::TOP
);
697 aBox
.SetLine(&aLine
, SvxBoxItemLine::RIGHT
);
698 aBox
.SetLine(&aLine
, SvxBoxItemLine::BOTTOM
);
700 Color
aWhite(COL_WHITE
);
701 SvxColorItem
aWhiteText( aWhite
, ATTR_FONT_COLOR
);
702 SvxColorItem
aBlackText( aBlack
, ATTR_FONT_COLOR
);
703 SvxBrushItem
aBlueBack( COL_BLUE
, ATTR_BACKGROUND
);
704 SvxBrushItem
aWhiteBack( aWhite
, ATTR_BACKGROUND
);
705 SvxBrushItem
aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND
);
706 SvxBrushItem
aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND
);
708 for (sal_uInt16 i
=0; i
<16; i
++)
710 pData
->PutItem( i
, aBox
);
711 pData
->PutItem( i
, aFontItem
);
712 pData
->PutItem( i
, aCJKFontItem
);
713 pData
->PutItem( i
, aCTLFontItem
);
714 aHeight
.SetWhich( ATTR_FONT_HEIGHT
);
715 pData
->PutItem( i
, aHeight
);
716 aHeight
.SetWhich( ATTR_CJK_FONT_HEIGHT
);
717 pData
->PutItem( i
, aHeight
);
718 aHeight
.SetWhich( ATTR_CTL_FONT_HEIGHT
);
719 pData
->PutItem( i
, aHeight
);
720 if (i
<4) // top: white on blue
722 pData
->PutItem( i
, aWhiteText
);
723 pData
->PutItem( i
, aBlueBack
);
725 else if ( i
%4 == 0 ) // left: white on gray70
727 pData
->PutItem( i
, aWhiteText
);
728 pData
->PutItem( i
, aGray70Back
);
730 else if ( i
%4 == 3 || i
>= 12 ) // right and bottom: black on gray20
732 pData
->PutItem( i
, aBlackText
);
733 pData
->PutItem( i
, aGray20Back
);
735 else // center: black on white
737 pData
->PutItem( i
, aBlackText
);
738 pData
->PutItem( i
, aWhiteBack
);
742 insert(std::move(pData
));
745 bool DefaultFirstEntry::operator() (const OUString
& left
, const OUString
& right
) const
747 OUString
aStrStandard(ScResId(STR_STYLENAME_STANDARD
));
748 if (ScGlobal::GetTransliteration().isEqual( left
, right
) )
750 if ( ScGlobal::GetTransliteration().isEqual( left
, aStrStandard
) )
752 if ( ScGlobal::GetTransliteration().isEqual( right
, aStrStandard
) )
754 return ScGlobal::GetCollator().compareString( left
, right
) < 0;
757 void ScAutoFormat::SetSaveLater( bool bSet
)
762 const ScAutoFormatData
* ScAutoFormat::findByIndex(size_t nIndex
) const
764 if (nIndex
>= m_Data
.size())
767 MapType::const_iterator it
= m_Data
.begin();
768 std::advance(it
, nIndex
);
769 return it
->second
.get();
772 ScAutoFormatData
* ScAutoFormat::findByIndex(size_t nIndex
)
774 if (nIndex
>= m_Data
.size())
777 MapType::iterator it
= m_Data
.begin();
778 std::advance(it
, nIndex
);
779 return it
->second
.get();
782 ScAutoFormat::iterator
ScAutoFormat::find(const OUString
& rName
)
784 return m_Data
.find(rName
);
787 ScAutoFormat::iterator
ScAutoFormat::insert(std::unique_ptr
<ScAutoFormatData
> pNew
)
789 OUString aName
= pNew
->GetName();
790 return m_Data
.insert(std::make_pair(aName
, std::move(pNew
))).first
;
793 void ScAutoFormat::erase(const iterator
& it
)
798 size_t ScAutoFormat::size() const
800 return m_Data
.size();
803 ScAutoFormat::const_iterator
ScAutoFormat::begin() const
805 return m_Data
.begin();
808 ScAutoFormat::const_iterator
ScAutoFormat::end() const
813 ScAutoFormat::iterator
ScAutoFormat::begin()
815 return m_Data
.begin();
818 ScAutoFormat::iterator
ScAutoFormat::end()
823 void ScAutoFormat::Load()
826 SvtPathOptions aPathOpt
;
827 aURL
.SetSmartURL( aPathOpt
.GetUserConfigPath() );
828 aURL
.setFinalSlash();
829 aURL
.Append( sAutoTblFmtName
);
831 SfxMedium
aMedium( aURL
.GetMainURL(INetURLObject::DecodeMechanism::NONE
), StreamMode::READ
);
832 SvStream
* pStream
= aMedium
.GetInStream();
833 bool bRet
= (pStream
&& pStream
->GetError() == ERRCODE_NONE
);
836 SvStream
& rStream
= *pStream
;
837 // Attention: A common header has to be read
839 rStream
.ReadUInt16( nVal
);
840 bRet
= ERRCODE_NONE
== rStream
.GetError();
844 if( nVal
== AUTOFORMAT_ID_358
||
845 (AUTOFORMAT_ID_504
<= nVal
&& nVal
<= AUTOFORMAT_ID
) )
847 sal_uInt8 nChrSet
, nCnt
;
848 sal_uInt64 nPos
= rStream
.Tell();
849 rStream
.ReadUChar( nCnt
).ReadUChar( nChrSet
);
850 if( rStream
.Tell() != sal_uLong(nPos
+ nCnt
) )
852 OSL_FAIL( "header contains more/newer data" );
853 rStream
.Seek( nPos
+ nCnt
);
855 rStream
.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet
) );
856 rStream
.SetVersion( SOFFICE_FILEFORMAT_40
);
859 if( nVal
== AUTOFORMAT_ID_358
|| nVal
== AUTOFORMAT_ID_X
||
860 (AUTOFORMAT_ID_504
<= nVal
&& nVal
<= AUTOFORMAT_ID
) )
862 m_aVersions
.Load( rStream
, nVal
); // item versions
865 rStream
.ReadUInt16( nCnt
);
866 bRet
= (rStream
.GetError() == ERRCODE_NONE
);
868 // there has to at least be a sal_uInt16 header
869 const size_t nMaxRecords
= rStream
.remainingSize() / sizeof(sal_uInt16
);
870 if (nCnt
> nMaxRecords
)
872 SAL_WARN("sc", "Parsing error: " << nMaxRecords
<<
873 " max possible entries, but " << nCnt
<< " claimed, truncating");
877 for (sal_uInt16 i
=0; bRet
&& (i
< nCnt
); i
++)
879 std::unique_ptr
<ScAutoFormatData
> pData(new ScAutoFormatData());
880 bRet
= pData
->Load(rStream
, m_aVersions
);
881 insert(std::move(pData
));
889 bool ScAutoFormat::Save()
892 SvtPathOptions aPathOpt
;
893 aURL
.SetSmartURL( aPathOpt
.GetUserConfigPath() );
894 aURL
.setFinalSlash();
895 aURL
.Append(sAutoTblFmtName
);
897 SfxMedium
aMedium( aURL
.GetMainURL(INetURLObject::DecodeMechanism::NONE
), StreamMode::WRITE
);
898 SvStream
* pStream
= aMedium
.GetOutStream();
899 bool bRet
= (pStream
&& pStream
->GetError() == ERRCODE_NONE
);
902 const sal_uInt16 fileVersion
= SOFFICE_FILEFORMAT_50
;
903 SvStream
& rStream
= *pStream
;
904 rStream
.SetVersion( fileVersion
);
906 // Attention: A common header has to be saved
907 rStream
.WriteUInt16( AUTOFORMAT_ID
)
908 .WriteUChar( 2 ) // Number of chars of the header including this
909 .WriteUChar( ::GetSOStoreTextEncoding(
910 osl_getThreadTextEncoding() ) );
911 m_aVersions
.Write(rStream
, fileVersion
);
913 bRet
&= (rStream
.GetError() == ERRCODE_NONE
);
915 rStream
.WriteUInt16( m_Data
.size() - 1 );
916 bRet
&= (rStream
.GetError() == ERRCODE_NONE
);
917 MapType::iterator it
= m_Data
.begin(), itEnd
= m_Data
.end();
920 for (++it
; bRet
&& it
!= itEnd
; ++it
) // Skip the first item.
922 bRet
&= it
->second
->Save(rStream
, fileVersion
);
926 rStream
.FlushBuffer();
934 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */