update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / source / core / tool / autoform.cxx
blob795eb19b4827d1a19648c57af857acdecc9494bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "autoform.hxx"
22 #include <sfx2/app.hxx>
23 #include <sfx2/docfile.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <svl/itemset.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/outdev.hxx>
28 #include <svx/dialmgr.hxx>
29 #include <svx/dialogs.hrc>
30 #include <editeng/langitem.hxx>
31 #include <tools/urlobj.hxx>
32 #include <unotools/transliterationwrapper.hxx>
33 #include <tools/tenccvt.hxx>
35 #include "globstr.hrc"
36 #include "document.hxx"
39 * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST
40 * be synchronized with Writer's SwTableAutoFmtTbl sw/source/core/doc/tblafmt.cxx
43 const sal_Char *linker_dummy = "";
45 static const sal_Char sAutoTblFmtName[] = "autotbl.fmt";
47 // till SO5PF
48 const sal_uInt16 AUTOFORMAT_ID_X = 9501;
49 const sal_uInt16 AUTOFORMAT_ID_358 = 9601;
50 const sal_uInt16 AUTOFORMAT_DATA_ID_X = 9502;
52 // from SO5 on
53 // in following versions the value of the IDs must be higher
54 const sal_uInt16 AUTOFORMAT_ID_504 = 9801;
55 const sal_uInt16 AUTOFORMAT_DATA_ID_504 = 9802;
57 const sal_uInt16 AUTOFORMAT_DATA_ID_552 = 9902;
59 // --- from 641 on: CJK and CTL font settings
60 const sal_uInt16 AUTOFORMAT_DATA_ID_641 = 10002;
62 // --- from 680/dr14 on: diagonal frame lines
63 const sal_uInt16 AUTOFORMAT_ID_680DR14 = 10011;
64 const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14 = 10012;
66 // --- from 680/dr25 on: store strings as UTF-8
67 const sal_uInt16 AUTOFORMAT_ID_680DR25 = 10021;
69 // --- from DEV300/overline2 on: overline support
70 const sal_uInt16 AUTOFORMAT_ID_300OVRLN = 10031;
71 const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN = 10032;
73 // --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc)
74 const sal_uInt16 AUTOFORMAT_ID_31005 = 10041;
75 const sal_uInt16 AUTOFORMAT_DATA_ID_31005 = 10042;
77 // current version
78 const sal_uInt16 AUTOFORMAT_ID = AUTOFORMAT_ID_31005;
79 const sal_uInt16 AUTOFORMAT_DATA_ID = AUTOFORMAT_DATA_ID_31005;
81 namespace
83 /// Read an AutoFormatSwBlob from stream.
84 SvStream& operator>>(SvStream &stream, AutoFormatSwBlob &blob)
86 blob.Reset();
88 sal_uInt64 endOfBlob = 0;
89 stream.ReadUInt64( endOfBlob );
91 const sal_uInt64 currentPosition = stream.Tell();
92 const sal_uInt64 blobSize = endOfBlob - currentPosition;
93 // A zero-size indicates an empty blob. This happens when Calc creates a new autoformat,
94 // since it (naturally) doesn't have any writer-specific data to write.
95 if (blobSize)
97 blob.pData = new sal_uInt8[blobSize];
98 blob.size = static_cast<sal_Size>(blobSize);
99 stream.Read(blob.pData, blob.size);
102 return stream;
105 /// Write an AutoFormatSwBlob to stream.
106 SvStream& WriteAutoFormatSwBlob(SvStream &stream, AutoFormatSwBlob &blob)
108 const sal_uInt64 endOfBlob = stream.Tell() + sizeof(sal_uInt64) + blob.size;
109 stream.WriteUInt64( endOfBlob );
110 if (blob.size)
111 stream.Write(blob.pData, blob.size);
113 return stream;
117 ScAfVersions::ScAfVersions() :
118 nFontVersion(0),
119 nFontHeightVersion(0),
120 nWeightVersion(0),
121 nPostureVersion(0),
122 nUnderlineVersion(0),
123 nOverlineVersion(0),
124 nCrossedOutVersion(0),
125 nContourVersion(0),
126 nShadowedVersion(0),
127 nColorVersion(0),
128 nBoxVersion(0),
129 nLineVersion(0),
130 nBrushVersion(0),
131 nAdjustVersion(0),
132 nHorJustifyVersion(0),
133 nVerJustifyVersion(0),
134 nOrientationVersion(0),
135 nMarginVersion(0),
136 nBoolVersion(0),
137 nInt32Version(0),
138 nRotateModeVersion(0),
139 nNumFmtVersion(0)
143 void ScAfVersions::Load( SvStream& rStream, sal_uInt16 nVer )
145 rStream.ReadUInt16( nFontVersion );
146 rStream.ReadUInt16( nFontHeightVersion );
147 rStream.ReadUInt16( nWeightVersion );
148 rStream.ReadUInt16( nPostureVersion );
149 rStream.ReadUInt16( nUnderlineVersion );
150 if ( nVer >= AUTOFORMAT_ID_300OVRLN )
151 rStream.ReadUInt16( nOverlineVersion );
152 rStream.ReadUInt16( nCrossedOutVersion );
153 rStream.ReadUInt16( nContourVersion );
154 rStream.ReadUInt16( nShadowedVersion );
155 rStream.ReadUInt16( nColorVersion );
156 rStream.ReadUInt16( nBoxVersion );
157 if ( nVer >= AUTOFORMAT_ID_680DR14 )
158 rStream.ReadUInt16( nLineVersion );
159 rStream.ReadUInt16( nBrushVersion );
160 rStream.ReadUInt16( nAdjustVersion );
161 if (nVer >= AUTOFORMAT_ID_31005)
162 rStream >> swVersions;
163 rStream.ReadUInt16( nHorJustifyVersion );
164 rStream.ReadUInt16( nVerJustifyVersion );
165 rStream.ReadUInt16( nOrientationVersion );
166 rStream.ReadUInt16( nMarginVersion );
167 rStream.ReadUInt16( nBoolVersion );
168 if ( nVer >= AUTOFORMAT_ID_504 )
170 rStream.ReadUInt16( nInt32Version );
171 rStream.ReadUInt16( nRotateModeVersion );
173 rStream.ReadUInt16( nNumFmtVersion );
176 void ScAfVersions::Write(SvStream& rStream, sal_uInt16 fileVersion)
178 rStream.WriteUInt16( SvxFontItem(ATTR_FONT).GetVersion(fileVersion) );
179 rStream.WriteUInt16( SvxFontHeightItem(240, 100, ATTR_FONT_HEIGHT).GetVersion(fileVersion) );
180 rStream.WriteUInt16( SvxWeightItem(WEIGHT_NORMAL, ATTR_FONT_WEIGHT).GetVersion(fileVersion) );
181 rStream.WriteUInt16( SvxPostureItem(ITALIC_NONE, ATTR_FONT_POSTURE).GetVersion(fileVersion) );
182 rStream.WriteUInt16( SvxUnderlineItem(UNDERLINE_NONE, ATTR_FONT_UNDERLINE).GetVersion(fileVersion) );
183 rStream.WriteUInt16( SvxOverlineItem(UNDERLINE_NONE, ATTR_FONT_OVERLINE).GetVersion(fileVersion) );
184 rStream.WriteUInt16( SvxCrossedOutItem(STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT).GetVersion(fileVersion) );
185 rStream.WriteUInt16( SvxContourItem(false, ATTR_FONT_CONTOUR).GetVersion(fileVersion) );
186 rStream.WriteUInt16( SvxShadowedItem(false, ATTR_FONT_SHADOWED).GetVersion(fileVersion) );
187 rStream.WriteUInt16( SvxColorItem(ATTR_FONT_COLOR).GetVersion(fileVersion) );
188 rStream.WriteUInt16( SvxBoxItem(ATTR_BORDER).GetVersion(fileVersion) );
189 rStream.WriteUInt16( SvxLineItem(SID_FRAME_LINESTYLE).GetVersion(fileVersion) );
190 rStream.WriteUInt16( SvxBrushItem(ATTR_BACKGROUND).GetVersion(fileVersion) );
192 rStream.WriteUInt16( SvxAdjustItem(SVX_ADJUST_LEFT, 0).GetVersion(fileVersion) );
193 if (fileVersion >= SOFFICE_FILEFORMAT_50)
194 WriteAutoFormatSwBlob( rStream, swVersions );
196 rStream.WriteUInt16( SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY).GetVersion(fileVersion) );
197 rStream.WriteUInt16( SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY).GetVersion(fileVersion) );
198 rStream.WriteUInt16( SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0).GetVersion(fileVersion) );
199 rStream.WriteUInt16( SvxMarginItem(ATTR_MARGIN).GetVersion(fileVersion) );
200 rStream.WriteUInt16( SfxBoolItem(ATTR_LINEBREAK).GetVersion(fileVersion) );
201 rStream.WriteUInt16( SfxInt32Item(ATTR_ROTATE_VALUE).GetVersion(fileVersion) );
202 rStream.WriteUInt16( SvxRotateModeItem(SVX_ROTATE_MODE_STANDARD,0).GetVersion(fileVersion) );
204 rStream.WriteUInt16( 0 ); // Num-Format
207 ScAutoFormatDataField::ScAutoFormatDataField() :
208 aFont( ATTR_FONT ),
209 aHeight( 240, 100, ATTR_FONT_HEIGHT ),
210 aWeight( WEIGHT_NORMAL, ATTR_FONT_WEIGHT ),
211 aPosture( ITALIC_NONE, ATTR_FONT_POSTURE ),
213 aCJKFont( ATTR_CJK_FONT ),
214 aCJKHeight( 240, 100, ATTR_CJK_FONT_HEIGHT ),
215 aCJKWeight( WEIGHT_NORMAL, ATTR_CJK_FONT_WEIGHT ),
216 aCJKPosture( ITALIC_NONE, ATTR_CJK_FONT_POSTURE ),
218 aCTLFont( ATTR_CTL_FONT ),
219 aCTLHeight( 240, 100, ATTR_CTL_FONT_HEIGHT ),
220 aCTLWeight( WEIGHT_NORMAL, ATTR_CTL_FONT_WEIGHT ),
221 aCTLPosture( ITALIC_NONE, ATTR_CTL_FONT_POSTURE ),
223 aUnderline( UNDERLINE_NONE,ATTR_FONT_UNDERLINE ),
224 aOverline( UNDERLINE_NONE,ATTR_FONT_OVERLINE ),
225 aCrossedOut( STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ),
226 aContour( false, ATTR_FONT_CONTOUR ),
227 aShadowed( false, ATTR_FONT_SHADOWED ),
228 aColor( ATTR_FONT_COLOR ),
229 aBox( ATTR_BORDER ),
230 aTLBR( ATTR_BORDER_TLBR ),
231 aBLTR( ATTR_BORDER_BLTR ),
232 aBackground( ATTR_BACKGROUND ),
233 aAdjust( SVX_ADJUST_LEFT, 0 ),
234 aHorJustify( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ),
235 aVerJustify( SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY ),
236 aMargin( ATTR_MARGIN ),
237 aLinebreak( ATTR_LINEBREAK ),
238 aRotateAngle( ATTR_ROTATE_VALUE ),
239 aRotateMode( SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE )
243 ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField& rCopy ) :
244 aFont( rCopy.aFont ),
245 aHeight( rCopy.aHeight ),
246 aWeight( rCopy.aWeight ),
247 aPosture( rCopy.aPosture ),
248 aCJKFont( rCopy.aCJKFont ),
249 aCJKHeight( rCopy.aCJKHeight ),
250 aCJKWeight( rCopy.aCJKWeight ),
251 aCJKPosture( rCopy.aCJKPosture ),
252 aCTLFont( rCopy.aCTLFont ),
253 aCTLHeight( rCopy.aCTLHeight ),
254 aCTLWeight( rCopy.aCTLWeight ),
255 aCTLPosture( rCopy.aCTLPosture ),
256 aUnderline( rCopy.aUnderline ),
257 aOverline( rCopy.aOverline ),
258 aCrossedOut( rCopy.aCrossedOut ),
259 aContour( rCopy.aContour ),
260 aShadowed( rCopy.aShadowed ),
261 aColor( rCopy.aColor ),
262 aBox( rCopy.aBox ),
263 aTLBR( rCopy.aTLBR ),
264 aBLTR( rCopy.aBLTR ),
265 aBackground( rCopy.aBackground ),
266 aAdjust( rCopy.aAdjust ),
267 aHorJustify( rCopy.aHorJustify ),
268 aVerJustify( rCopy.aVerJustify ),
269 aStacked( rCopy.aStacked ),
270 aMargin( rCopy.aMargin ),
271 aLinebreak( rCopy.aLinebreak ),
272 aRotateAngle( rCopy.aRotateAngle ),
273 aRotateMode( rCopy.aRotateMode ),
274 aNumFormat( rCopy.aNumFormat )
278 ScAutoFormatDataField::~ScAutoFormatDataField()
282 void ScAutoFormatDataField::SetAdjust( const SvxAdjustItem& rAdjust )
284 aAdjust.SetAdjust( rAdjust.GetAdjust() );
285 aAdjust.SetOneWord( rAdjust.GetOneWord() );
286 aAdjust.SetLastBlock( rAdjust.GetLastBlock() );
289 #define READ( aItem, ItemType, nVers ) \
290 pNew = aItem.Create( rStream, nVers ); \
291 aItem = *static_cast<ItemType*>(pNew); \
292 delete pNew;
294 bool ScAutoFormatDataField::Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer )
296 SfxPoolItem* pNew;
297 SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0 );
299 READ( aFont, SvxFontItem, rVersions.nFontVersion)
300 READ( aHeight, SvxFontHeightItem, rVersions.nFontHeightVersion)
301 READ( aWeight, SvxWeightItem, rVersions.nWeightVersion)
302 READ( aPosture, SvxPostureItem, rVersions.nPostureVersion)
303 // --- from 641 on: CJK and CTL font settings
304 if( AUTOFORMAT_DATA_ID_641 <= nVer )
306 READ( aCJKFont, SvxFontItem, rVersions.nFontVersion)
307 READ( aCJKHeight, SvxFontHeightItem, rVersions.nFontHeightVersion)
308 READ( aCJKWeight, SvxWeightItem, rVersions.nWeightVersion)
309 READ( aCJKPosture, SvxPostureItem, rVersions.nPostureVersion)
310 READ( aCTLFont, SvxFontItem, rVersions.nFontVersion)
311 READ( aCTLHeight, SvxFontHeightItem, rVersions.nFontHeightVersion)
312 READ( aCTLWeight, SvxWeightItem, rVersions.nWeightVersion)
313 READ( aCTLPosture, SvxPostureItem, rVersions.nPostureVersion)
315 READ( aUnderline, SvxUnderlineItem, rVersions.nUnderlineVersion)
316 if ( nVer >= AUTOFORMAT_DATA_ID_300OVRLN )
318 READ( aOverline, SvxOverlineItem, rVersions.nOverlineVersion)
320 READ( aCrossedOut, SvxCrossedOutItem, rVersions.nCrossedOutVersion)
321 READ( aContour, SvxContourItem, rVersions.nContourVersion)
322 READ( aShadowed, SvxShadowedItem, rVersions.nShadowedVersion)
323 READ( aColor, SvxColorItem, rVersions.nColorVersion)
324 READ( aBox, SvxBoxItem, rVersions.nBoxVersion)
326 // --- from 680/dr14 on: diagonal frame lines
327 if( AUTOFORMAT_DATA_ID_680DR14 <= nVer )
329 READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
330 READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
333 READ( aBackground, SvxBrushItem, rVersions.nBrushVersion)
335 pNew = aAdjust.Create( rStream, rVersions.nAdjustVersion );
336 SetAdjust( *static_cast<SvxAdjustItem*>(pNew) );
337 delete pNew;
339 if (nVer >= AUTOFORMAT_DATA_ID_31005)
340 rStream >> m_swFields;
342 READ( aHorJustify, SvxHorJustifyItem, rVersions.nHorJustifyVersion)
343 READ( aVerJustify, SvxVerJustifyItem, rVersions.nVerJustifyVersion)
344 READ( aOrientation, SvxOrientationItem, rVersions.nOrientationVersion)
345 READ( aMargin, SvxMarginItem, rVersions.nMarginVersion)
347 pNew = aLinebreak.Create( rStream, rVersions.nBoolVersion );
348 SetLinebreak( *static_cast<SfxBoolItem*>(pNew) );
349 delete pNew;
351 if ( nVer >= AUTOFORMAT_DATA_ID_504 )
353 pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
354 SetRotateAngle( *static_cast<SfxInt32Item*>(pNew) );
355 delete pNew;
356 pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
357 SetRotateMode( *static_cast<SvxRotateModeItem*>(pNew) );
358 delete pNew;
361 if( 0 == rVersions.nNumFmtVersion )
363 // --- from 680/dr25 on: store strings as UTF-8
364 rtl_TextEncoding eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
365 aNumFormat.Load( rStream, eCharSet );
368 // adjust charset in font
369 rtl_TextEncoding eSysSet = osl_getThreadTextEncoding();
370 rtl_TextEncoding eSrcSet = rStream.GetStreamCharSet();
371 if( eSrcSet != eSysSet && aFont.GetCharSet() == eSrcSet )
372 aFont.SetCharSet(eSysSet);
374 aStacked.SetValue( aOrientation.IsStacked() );
375 aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
377 return (rStream.GetError() == 0);
380 bool ScAutoFormatDataField::Save( SvStream& rStream, sal_uInt16 fileVersion )
382 SvxOrientationItem aOrientation( aRotateAngle.GetValue(), aStacked.GetValue(), 0 );
384 aFont.Store ( rStream, aFont.GetVersion( fileVersion ) );
385 aHeight.Store ( rStream, aHeight.GetVersion( fileVersion ) );
386 aWeight.Store ( rStream, aWeight.GetVersion( fileVersion ) );
387 aPosture.Store ( rStream, aPosture.GetVersion( fileVersion ) );
388 // --- from 641 on: CJK and CTL font settings
389 aCJKFont.Store ( rStream, aCJKFont.GetVersion( fileVersion ) );
390 aCJKHeight.Store ( rStream, aCJKHeight.GetVersion( fileVersion ) );
391 aCJKWeight.Store ( rStream, aCJKWeight.GetVersion( fileVersion ) );
392 aCJKPosture.Store ( rStream, aCJKPosture.GetVersion( fileVersion ) );
393 aCTLFont.Store ( rStream, aCTLFont.GetVersion( fileVersion ) );
394 aCTLHeight.Store ( rStream, aCTLHeight.GetVersion( fileVersion ) );
395 aCTLWeight.Store ( rStream, aCTLWeight.GetVersion( fileVersion ) );
396 aCTLPosture.Store ( rStream, aCTLPosture.GetVersion( fileVersion ) );
398 aUnderline.Store ( rStream, aUnderline.GetVersion( fileVersion ) );
399 // --- from DEV300/overline2 on: overline support
400 aOverline.Store ( rStream, aOverline.GetVersion( fileVersion ) );
401 aCrossedOut.Store ( rStream, aCrossedOut.GetVersion( fileVersion ) );
402 aContour.Store ( rStream, aContour.GetVersion( fileVersion ) );
403 aShadowed.Store ( rStream, aShadowed.GetVersion( fileVersion ) );
404 aColor.Store ( rStream, aColor.GetVersion( fileVersion ) );
405 aBox.Store ( rStream, aBox.GetVersion( fileVersion ) );
407 // --- from 680/dr14 on: diagonal frame lines
408 aTLBR.Store ( rStream, aTLBR.GetVersion( fileVersion ) );
409 aBLTR.Store ( rStream, aBLTR.GetVersion( fileVersion ) );
411 aBackground.Store ( rStream, aBackground.GetVersion( fileVersion ) );
413 aAdjust.Store ( rStream, aAdjust.GetVersion( fileVersion ) );
414 if (fileVersion >= SOFFICE_FILEFORMAT_50)
415 WriteAutoFormatSwBlob( rStream, m_swFields );
417 aHorJustify.Store ( rStream, aHorJustify.GetVersion( fileVersion ) );
418 aVerJustify.Store ( rStream, aVerJustify.GetVersion( fileVersion ) );
419 aOrientation.Store ( rStream, aOrientation.GetVersion( fileVersion ) );
420 aMargin.Store ( rStream, aMargin.GetVersion( fileVersion ) );
421 aLinebreak.Store ( rStream, aLinebreak.GetVersion( fileVersion ) );
422 // Rotation ab SO5
423 aRotateAngle.Store ( rStream, aRotateAngle.GetVersion( fileVersion ) );
424 aRotateMode.Store ( rStream, aRotateMode.GetVersion( fileVersion ) );
426 // --- from 680/dr25 on: store strings as UTF-8
427 aNumFormat.Save( rStream, RTL_TEXTENCODING_UTF8 );
429 return (rStream.GetError() == 0);
432 ScAutoFormatData::ScAutoFormatData()
434 nStrResId = USHRT_MAX;
436 bIncludeValueFormat =
437 bIncludeFont =
438 bIncludeJustify =
439 bIncludeFrame =
440 bIncludeBackground =
441 bIncludeWidthHeight = true;
443 ppDataField = new ScAutoFormatDataField*[ 16 ];
444 for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
445 ppDataField[ nIndex ] = new ScAutoFormatDataField;
448 ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData& rData ) :
449 aName( rData.aName ),
450 nStrResId( rData.nStrResId ),
451 bIncludeFont( rData.bIncludeFont ),
452 bIncludeJustify( rData.bIncludeJustify ),
453 bIncludeFrame( rData.bIncludeFrame ),
454 bIncludeBackground( rData.bIncludeBackground ),
455 bIncludeValueFormat( rData.bIncludeValueFormat ),
456 bIncludeWidthHeight( rData.bIncludeWidthHeight )
458 ppDataField = new ScAutoFormatDataField*[ 16 ];
459 for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
460 ppDataField[ nIndex ] = new ScAutoFormatDataField( rData.GetField( nIndex ) );
463 ScAutoFormatData::~ScAutoFormatData()
465 for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
466 delete ppDataField[ nIndex ];
467 delete[] ppDataField;
470 ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex )
472 OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
473 OSL_ENSURE( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
474 return *ppDataField[ nIndex ];
477 const ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex ) const
479 OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
480 OSL_ENSURE( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
481 return *ppDataField[ nIndex ];
484 const SfxPoolItem* ScAutoFormatData::GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const
486 const ScAutoFormatDataField& rField = GetField( nIndex );
487 switch( nWhich )
489 case ATTR_FONT: return &rField.GetFont();
490 case ATTR_FONT_HEIGHT: return &rField.GetHeight();
491 case ATTR_FONT_WEIGHT: return &rField.GetWeight();
492 case ATTR_FONT_POSTURE: return &rField.GetPosture();
493 case ATTR_CJK_FONT: return &rField.GetCJKFont();
494 case ATTR_CJK_FONT_HEIGHT: return &rField.GetCJKHeight();
495 case ATTR_CJK_FONT_WEIGHT: return &rField.GetCJKWeight();
496 case ATTR_CJK_FONT_POSTURE: return &rField.GetCJKPosture();
497 case ATTR_CTL_FONT: return &rField.GetCTLFont();
498 case ATTR_CTL_FONT_HEIGHT: return &rField.GetCTLHeight();
499 case ATTR_CTL_FONT_WEIGHT: return &rField.GetCTLWeight();
500 case ATTR_CTL_FONT_POSTURE: return &rField.GetCTLPosture();
501 case ATTR_FONT_UNDERLINE: return &rField.GetUnderline();
502 case ATTR_FONT_OVERLINE: return &rField.GetOverline();
503 case ATTR_FONT_CROSSEDOUT: return &rField.GetCrossedOut();
504 case ATTR_FONT_CONTOUR: return &rField.GetContour();
505 case ATTR_FONT_SHADOWED: return &rField.GetShadowed();
506 case ATTR_FONT_COLOR: return &rField.GetColor();
507 case ATTR_BORDER: return &rField.GetBox();
508 case ATTR_BORDER_TLBR: return &rField.GetTLBR();
509 case ATTR_BORDER_BLTR: return &rField.GetBLTR();
510 case ATTR_BACKGROUND: return &rField.GetBackground();
511 case ATTR_HOR_JUSTIFY: return &rField.GetHorJustify();
512 case ATTR_VER_JUSTIFY: return &rField.GetVerJustify();
513 case ATTR_STACKED: return &rField.GetStacked();
514 case ATTR_MARGIN: return &rField.GetMargin();
515 case ATTR_LINEBREAK: return &rField.GetLinebreak();
516 case ATTR_ROTATE_VALUE: return &rField.GetRotateAngle();
517 case ATTR_ROTATE_MODE: return &rField.GetRotateMode();
519 return NULL;
522 void ScAutoFormatData::PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem )
524 ScAutoFormatDataField& rField = GetField( nIndex );
525 switch( rItem.Which() )
527 case ATTR_FONT: rField.SetFont( static_cast<const SvxFontItem&>(rItem) ); break;
528 case ATTR_FONT_HEIGHT: rField.SetHeight( static_cast<const SvxFontHeightItem&>(rItem) ); break;
529 case ATTR_FONT_WEIGHT: rField.SetWeight( static_cast<const SvxWeightItem&>(rItem) ); break;
530 case ATTR_FONT_POSTURE: rField.SetPosture( static_cast<const SvxPostureItem&>(rItem) ); break;
531 case ATTR_CJK_FONT: rField.SetCJKFont( static_cast<const SvxFontItem&>(rItem) ); break;
532 case ATTR_CJK_FONT_HEIGHT: rField.SetCJKHeight( static_cast<const SvxFontHeightItem&>(rItem) ); break;
533 case ATTR_CJK_FONT_WEIGHT: rField.SetCJKWeight( static_cast<const SvxWeightItem&>(rItem) ); break;
534 case ATTR_CJK_FONT_POSTURE: rField.SetCJKPosture( static_cast<const SvxPostureItem&>(rItem) ); break;
535 case ATTR_CTL_FONT: rField.SetCTLFont( static_cast<const SvxFontItem&>(rItem) ); break;
536 case ATTR_CTL_FONT_HEIGHT: rField.SetCTLHeight( static_cast<const SvxFontHeightItem&>(rItem) ); break;
537 case ATTR_CTL_FONT_WEIGHT: rField.SetCTLWeight( static_cast<const SvxWeightItem&>(rItem) ); break;
538 case ATTR_CTL_FONT_POSTURE: rField.SetCTLPosture( static_cast<const SvxPostureItem&>(rItem) ); break;
539 case ATTR_FONT_UNDERLINE: rField.SetUnderline( static_cast<const SvxUnderlineItem&>(rItem) ); break;
540 case ATTR_FONT_OVERLINE: rField.SetOverline( static_cast<const SvxOverlineItem&>(rItem) ); break;
541 case ATTR_FONT_CROSSEDOUT: rField.SetCrossedOut( static_cast<const SvxCrossedOutItem&>(rItem) ); break;
542 case ATTR_FONT_CONTOUR: rField.SetContour( static_cast<const SvxContourItem&>(rItem) ); break;
543 case ATTR_FONT_SHADOWED: rField.SetShadowed( static_cast<const SvxShadowedItem&>(rItem) ); break;
544 case ATTR_FONT_COLOR: rField.SetColor( static_cast<const SvxColorItem&>(rItem) ); break;
545 case ATTR_BORDER: rField.SetBox( static_cast<const SvxBoxItem&>(rItem) ); break;
546 case ATTR_BORDER_TLBR: rField.SetTLBR( static_cast<const SvxLineItem&>(rItem) ); break;
547 case ATTR_BORDER_BLTR: rField.SetBLTR( static_cast<const SvxLineItem&>(rItem) ); break;
548 case ATTR_BACKGROUND: rField.SetBackground( static_cast<const SvxBrushItem&>(rItem) ); break;
549 case ATTR_HOR_JUSTIFY: rField.SetHorJustify( static_cast<const SvxHorJustifyItem&>(rItem) ); break;
550 case ATTR_VER_JUSTIFY: rField.SetVerJustify( static_cast<const SvxVerJustifyItem&>(rItem) ); break;
551 case ATTR_STACKED: rField.SetStacked( static_cast<const SfxBoolItem&>(rItem) ); break;
552 case ATTR_MARGIN: rField.SetMargin( static_cast<const SvxMarginItem&>(rItem) ); break;
553 case ATTR_LINEBREAK: rField.SetLinebreak( static_cast<const SfxBoolItem&>(rItem) ); break;
554 case ATTR_ROTATE_VALUE: rField.SetRotateAngle( static_cast<const SfxInt32Item&>(rItem) ); break;
555 case ATTR_ROTATE_MODE: rField.SetRotateMode( static_cast<const SvxRotateModeItem&>(rItem) ); break;
559 void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich )
561 const SfxPoolItem* pItem = GetItem( nFromIndex, nWhich );
562 if( pItem )
563 PutItem( nToIndex, *pItem );
566 const ScNumFormatAbbrev& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex ) const
568 return GetField( nIndex ).GetNumFormat();
571 bool ScAutoFormatData::IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const
573 bool bEqual = true;
574 const ScAutoFormatDataField& rField1 = GetField( nIndex1 );
575 const ScAutoFormatDataField& rField2 = GetField( nIndex2 );
577 if( bIncludeValueFormat )
579 bEqual = bEqual
580 && (rField1.GetNumFormat() == rField2.GetNumFormat());
582 if( bIncludeFont )
584 bEqual = bEqual
585 && (rField1.GetFont() == rField2.GetFont())
586 && (rField1.GetHeight() == rField2.GetHeight())
587 && (rField1.GetWeight() == rField2.GetWeight())
588 && (rField1.GetPosture() == rField2.GetPosture())
589 && (rField1.GetCJKFont() == rField2.GetCJKFont())
590 && (rField1.GetCJKHeight() == rField2.GetCJKHeight())
591 && (rField1.GetCJKWeight() == rField2.GetCJKWeight())
592 && (rField1.GetCJKPosture() == rField2.GetCJKPosture())
593 && (rField1.GetCTLFont() == rField2.GetCTLFont())
594 && (rField1.GetCTLHeight() == rField2.GetCTLHeight())
595 && (rField1.GetCTLWeight() == rField2.GetCTLWeight())
596 && (rField1.GetCTLPosture() == rField2.GetCTLPosture())
597 && (rField1.GetUnderline() == rField2.GetUnderline())
598 && (rField1.GetOverline() == rField2.GetOverline())
599 && (rField1.GetCrossedOut() == rField2.GetCrossedOut())
600 && (rField1.GetContour() == rField2.GetContour())
601 && (rField1.GetShadowed() == rField2.GetShadowed())
602 && (rField1.GetColor() == rField2.GetColor());
604 if( bIncludeJustify )
606 bEqual = bEqual
607 && (rField1.GetHorJustify() == rField2.GetHorJustify())
608 && (rField1.GetVerJustify() == rField2.GetVerJustify())
609 && (rField1.GetStacked() == rField2.GetStacked())
610 && (rField1.GetLinebreak() == rField2.GetLinebreak())
611 && (rField1.GetMargin() == rField2.GetMargin())
612 && (rField1.GetRotateAngle() == rField2.GetRotateAngle())
613 && (rField1.GetRotateMode() == rField2.GetRotateMode());
615 if( bIncludeFrame )
617 bEqual = bEqual
618 && (rField1.GetBox() == rField2.GetBox())
619 && (rField1.GetTLBR() == rField2.GetTLBR())
620 && (rField1.GetBLTR() == rField2.GetBLTR());
622 if( bIncludeBackground )
624 bEqual = bEqual
625 && (rField1.GetBackground() == rField2.GetBackground());
627 return bEqual;
630 void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const
632 const ScAutoFormatDataField& rField = GetField( nIndex );
634 if( bIncludeValueFormat )
636 ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)rField.GetNumFormat();
637 SfxUInt32Item aValueFormat( ATTR_VALUE_FORMAT, 0 );
638 aValueFormat.SetValue( rNumFormat.GetFormatIndex( *rDoc.GetFormatTable() ) );
639 rItemSet.Put( aValueFormat );
640 rItemSet.Put( SvxLanguageItem( rNumFormat.GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
642 if( bIncludeFont )
644 rItemSet.Put( rField.GetFont() );
645 rItemSet.Put( rField.GetHeight() );
646 rItemSet.Put( rField.GetWeight() );
647 rItemSet.Put( rField.GetPosture() );
648 // do not insert empty CJK font
649 const SvxFontItem& rCJKFont = rField.GetCJKFont();
650 if (!rCJKFont.GetStyleName().isEmpty())
652 rItemSet.Put( rCJKFont );
653 rItemSet.Put( rField.GetCJKHeight() );
654 rItemSet.Put( rField.GetCJKWeight() );
655 rItemSet.Put( rField.GetCJKPosture() );
657 else
659 rItemSet.Put( rField.GetHeight(), ATTR_CJK_FONT_HEIGHT );
660 rItemSet.Put( rField.GetWeight(), ATTR_CJK_FONT_WEIGHT );
661 rItemSet.Put( rField.GetPosture(), ATTR_CJK_FONT_POSTURE );
663 // do not insert empty CTL font
664 const SvxFontItem& rCTLFont = rField.GetCTLFont();
665 if (!rCTLFont.GetStyleName().isEmpty())
667 rItemSet.Put( rCTLFont );
668 rItemSet.Put( rField.GetCTLHeight() );
669 rItemSet.Put( rField.GetCTLWeight() );
670 rItemSet.Put( rField.GetCTLPosture() );
672 else
674 rItemSet.Put( rField.GetHeight(), ATTR_CTL_FONT_HEIGHT );
675 rItemSet.Put( rField.GetWeight(), ATTR_CTL_FONT_WEIGHT );
676 rItemSet.Put( rField.GetPosture(), ATTR_CTL_FONT_POSTURE );
678 rItemSet.Put( rField.GetUnderline() );
679 rItemSet.Put( rField.GetOverline() );
680 rItemSet.Put( rField.GetCrossedOut() );
681 rItemSet.Put( rField.GetContour() );
682 rItemSet.Put( rField.GetShadowed() );
683 rItemSet.Put( rField.GetColor() );
685 if( bIncludeJustify )
687 rItemSet.Put( rField.GetHorJustify() );
688 rItemSet.Put( rField.GetVerJustify() );
689 rItemSet.Put( rField.GetStacked() );
690 rItemSet.Put( rField.GetLinebreak() );
691 rItemSet.Put( rField.GetMargin() );
692 rItemSet.Put( rField.GetRotateAngle() );
693 rItemSet.Put( rField.GetRotateMode() );
695 if( bIncludeFrame )
697 rItemSet.Put( rField.GetBox() );
698 rItemSet.Put( rField.GetTLBR() );
699 rItemSet.Put( rField.GetBLTR() );
701 if( bIncludeBackground )
702 rItemSet.Put( rField.GetBackground() );
705 void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat )
707 ScAutoFormatDataField& rField = GetField( nIndex );
709 rField.SetNumFormat ( rNumFormat);
710 rField.SetFont ( static_cast<const SvxFontItem&> (rItemSet.Get( ATTR_FONT )) );
711 rField.SetHeight ( static_cast<const SvxFontHeightItem&> (rItemSet.Get( ATTR_FONT_HEIGHT )) );
712 rField.SetWeight ( static_cast<const SvxWeightItem&> (rItemSet.Get( ATTR_FONT_WEIGHT )) );
713 rField.SetPosture ( static_cast<const SvxPostureItem&> (rItemSet.Get( ATTR_FONT_POSTURE )) );
714 rField.SetCJKFont ( static_cast<const SvxFontItem&> (rItemSet.Get( ATTR_CJK_FONT )) );
715 rField.SetCJKHeight ( static_cast<const SvxFontHeightItem&> (rItemSet.Get( ATTR_CJK_FONT_HEIGHT )) );
716 rField.SetCJKWeight ( static_cast<const SvxWeightItem&> (rItemSet.Get( ATTR_CJK_FONT_WEIGHT )) );
717 rField.SetCJKPosture ( static_cast<const SvxPostureItem&> (rItemSet.Get( ATTR_CJK_FONT_POSTURE )) );
718 rField.SetCTLFont ( static_cast<const SvxFontItem&> (rItemSet.Get( ATTR_CTL_FONT )) );
719 rField.SetCTLHeight ( static_cast<const SvxFontHeightItem&> (rItemSet.Get( ATTR_CTL_FONT_HEIGHT )) );
720 rField.SetCTLWeight ( static_cast<const SvxWeightItem&> (rItemSet.Get( ATTR_CTL_FONT_WEIGHT )) );
721 rField.SetCTLPosture ( static_cast<const SvxPostureItem&> (rItemSet.Get( ATTR_CTL_FONT_POSTURE )) );
722 rField.SetUnderline ( static_cast<const SvxUnderlineItem&> (rItemSet.Get( ATTR_FONT_UNDERLINE )) );
723 rField.SetOverline ( static_cast<const SvxOverlineItem&> (rItemSet.Get( ATTR_FONT_OVERLINE )) );
724 rField.SetCrossedOut ( static_cast<const SvxCrossedOutItem&> (rItemSet.Get( ATTR_FONT_CROSSEDOUT )) );
725 rField.SetContour ( static_cast<const SvxContourItem&> (rItemSet.Get( ATTR_FONT_CONTOUR )) );
726 rField.SetShadowed ( static_cast<const SvxShadowedItem&> (rItemSet.Get( ATTR_FONT_SHADOWED )) );
727 rField.SetColor ( static_cast<const SvxColorItem&> (rItemSet.Get( ATTR_FONT_COLOR )) );
728 rField.SetTLBR ( static_cast<const SvxLineItem&> (rItemSet.Get( ATTR_BORDER_TLBR )) );
729 rField.SetBLTR ( static_cast<const SvxLineItem&> (rItemSet.Get( ATTR_BORDER_BLTR )) );
730 rField.SetHorJustify ( static_cast<const SvxHorJustifyItem&> (rItemSet.Get( ATTR_HOR_JUSTIFY )) );
731 rField.SetVerJustify ( static_cast<const SvxVerJustifyItem&> (rItemSet.Get( ATTR_VER_JUSTIFY )) );
732 rField.SetStacked ( static_cast<const SfxBoolItem&> (rItemSet.Get( ATTR_STACKED )) );
733 rField.SetLinebreak ( static_cast<const SfxBoolItem&> (rItemSet.Get( ATTR_LINEBREAK )) );
734 rField.SetMargin ( static_cast<const SvxMarginItem&> (rItemSet.Get( ATTR_MARGIN )) );
735 rField.SetBackground ( static_cast<const SvxBrushItem&> (rItemSet.Get( ATTR_BACKGROUND )) );
736 rField.SetRotateAngle ( static_cast<const SfxInt32Item&> (rItemSet.Get( ATTR_ROTATE_VALUE )) );
737 rField.SetRotateMode ( static_cast<const SvxRotateModeItem&> (rItemSet.Get( ATTR_ROTATE_MODE )) );
740 bool ScAutoFormatData::Load( SvStream& rStream, const ScAfVersions& rVersions )
742 sal_uInt16 nVer = 0;
743 rStream.ReadUInt16( nVer );
744 bool bRet = 0 == rStream.GetError();
745 if( bRet && (nVer == AUTOFORMAT_DATA_ID_X ||
746 (AUTOFORMAT_DATA_ID_504 <= nVer && nVer <= AUTOFORMAT_DATA_ID)) )
748 // --- from 680/dr25 on: store strings as UTF-8
749 if (nVer >= AUTOFORMAT_ID_680DR25)
751 aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rStream,
752 RTL_TEXTENCODING_UTF8);
754 else
755 aName = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
757 if( AUTOFORMAT_DATA_ID_552 <= nVer )
759 rStream.ReadUInt16( nStrResId );
760 sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN + nStrResId;
761 if( RID_SVXSTR_TBLAFMT_BEGIN <= nId &&
762 nId < RID_SVXSTR_TBLAFMT_END )
764 aName = SVX_RESSTR( nId );
766 else
767 nStrResId = USHRT_MAX;
770 bool b;
771 rStream.ReadCharAsBool( b ); bIncludeFont = b;
772 rStream.ReadCharAsBool( b ); bIncludeJustify = b;
773 rStream.ReadCharAsBool( b ); bIncludeFrame = b;
774 rStream.ReadCharAsBool( b ); bIncludeBackground = b;
775 rStream.ReadCharAsBool( b ); bIncludeValueFormat = b;
776 rStream.ReadCharAsBool( b ); bIncludeWidthHeight = b;
778 if (nVer >= AUTOFORMAT_DATA_ID_31005)
779 rStream >> m_swFields;
781 bRet = 0 == rStream.GetError();
782 for( sal_uInt16 i = 0; bRet && i < 16; ++i )
783 bRet = GetField( i ).Load( rStream, rVersions, nVer );
785 else
786 bRet = false;
787 return bRet;
790 bool ScAutoFormatData::Save(SvStream& rStream, sal_uInt16 fileVersion)
792 sal_uInt16 nVal = AUTOFORMAT_DATA_ID;
793 rStream.WriteUInt16( nVal );
794 // --- from 680/dr25 on: store strings as UTF-8
795 write_uInt16_lenPrefixed_uInt8s_FromOUString(rStream, aName, RTL_TEXTENCODING_UTF8);
797 rStream.WriteUInt16( nStrResId );
798 rStream.WriteBool( bIncludeFont );
799 rStream.WriteBool( bIncludeJustify );
800 rStream.WriteBool( bIncludeFrame );
801 rStream.WriteBool( bIncludeBackground );
802 rStream.WriteBool( bIncludeValueFormat );
803 rStream.WriteBool( bIncludeWidthHeight );
805 if (fileVersion >= SOFFICE_FILEFORMAT_50)
806 WriteAutoFormatSwBlob( rStream, m_swFields );
808 bool bRet = 0 == rStream.GetError();
809 for (sal_uInt16 i = 0; bRet && (i < 16); i++)
810 bRet = GetField( i ).Save( rStream, fileVersion );
812 return bRet;
815 ScAutoFormat::ScAutoFormat() :
816 mbSaveLater(false)
818 // create default autoformat
819 ScAutoFormatData* pData = new ScAutoFormatData;
820 OUString aName(ScGlobal::GetRscString(STR_STYLENAME_STANDARD));
821 pData->SetName(aName);
823 // default font, default height
824 vcl::Font aStdFont = OutputDevice::GetDefaultFont(
825 DefaultFontType::LATIN_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne );
826 SvxFontItem aFontItem(
827 aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
828 aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_FONT );
830 aStdFont = OutputDevice::GetDefaultFont(
831 DefaultFontType::CJK_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne );
832 SvxFontItem aCJKFontItem(
833 aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
834 aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CJK_FONT );
836 aStdFont = OutputDevice::GetDefaultFont(
837 DefaultFontType::CTL_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne );
838 SvxFontItem aCTLFontItem(
839 aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
840 aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CTL_FONT );
842 SvxFontHeightItem aHeight( 200, 100, ATTR_FONT_HEIGHT ); // 10 pt;
844 // black thin border
845 Color aBlack( COL_BLACK );
846 ::editeng::SvxBorderLine aLine( &aBlack, DEF_LINE_WIDTH_0 );
847 SvxBoxItem aBox( ATTR_BORDER );
848 aBox.SetLine(&aLine, SvxBoxItemLine::LEFT);
849 aBox.SetLine(&aLine, SvxBoxItemLine::TOP);
850 aBox.SetLine(&aLine, SvxBoxItemLine::RIGHT);
851 aBox.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
853 Color aWhite(COL_WHITE);
854 Color aBlue(COL_BLUE);
855 SvxColorItem aWhiteText( aWhite, ATTR_FONT_COLOR );
856 SvxColorItem aBlackText( aBlack, ATTR_FONT_COLOR );
857 SvxBrushItem aBlueBack( aBlue, ATTR_BACKGROUND );
858 SvxBrushItem aWhiteBack( aWhite, ATTR_BACKGROUND );
859 SvxBrushItem aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND );
860 SvxBrushItem aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND );
862 for (sal_uInt16 i=0; i<16; i++)
864 pData->PutItem( i, aBox );
865 pData->PutItem( i, aFontItem );
866 pData->PutItem( i, aCJKFontItem );
867 pData->PutItem( i, aCTLFontItem );
868 aHeight.SetWhich( ATTR_FONT_HEIGHT );
869 pData->PutItem( i, aHeight );
870 aHeight.SetWhich( ATTR_CJK_FONT_HEIGHT );
871 pData->PutItem( i, aHeight );
872 aHeight.SetWhich( ATTR_CTL_FONT_HEIGHT );
873 pData->PutItem( i, aHeight );
874 if (i<4) // top: white on blue
876 pData->PutItem( i, aWhiteText );
877 pData->PutItem( i, aBlueBack );
879 else if ( i%4 == 0 ) // left: white on gray70
881 pData->PutItem( i, aWhiteText );
882 pData->PutItem( i, aGray70Back );
884 else if ( i%4 == 3 || i >= 12 ) // right and bottom: black on gray20
886 pData->PutItem( i, aBlackText );
887 pData->PutItem( i, aGray20Back );
889 else // center: black on white
891 pData->PutItem( i, aBlackText );
892 pData->PutItem( i, aWhiteBack );
896 insert(pData);
899 bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) const
901 OUString aStrStandard(ScGlobal::GetRscString(STR_STYLENAME_STANDARD));
902 if ( ScGlobal::GetpTransliteration()->isEqual( left, aStrStandard ) )
903 return true;
904 if ( ScGlobal::GetpTransliteration()->isEqual( right, aStrStandard ) )
905 return false;
906 return ScGlobal::GetCollator()->compareString( left, right) < 0;
909 ScAutoFormat::ScAutoFormat(const ScAutoFormat& r) :
910 maData(r.maData),
911 mbSaveLater(false) {}
913 ScAutoFormat::~ScAutoFormat()
915 // When modified via StarOne then only the SaveLater flag is set and no saving is done.
916 // If the flag is set then save now.
918 if (mbSaveLater)
919 Save();
922 void ScAutoFormat::SetSaveLater( bool bSet )
924 mbSaveLater = bSet;
927 const ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex) const
929 if (nIndex >= maData.size())
930 return NULL;
932 MapType::const_iterator it = maData.begin();
933 std::advance(it, nIndex);
934 return it->second;
937 ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex)
939 if (nIndex >= maData.size())
940 return NULL;
942 MapType::iterator it = maData.begin();
943 std::advance(it, nIndex);
944 return it->second;
947 ScAutoFormat::const_iterator ScAutoFormat::find(const ScAutoFormatData* pData) const
949 MapType::const_iterator it = maData.begin(), itEnd = maData.end();
950 for (; it != itEnd; ++it)
952 if (it->second == pData)
953 return it;
955 return itEnd;
958 ScAutoFormat::iterator ScAutoFormat::find(const ScAutoFormatData* pData)
960 MapType::iterator it = maData.begin(), itEnd = maData.end();
961 for (; it != itEnd; ++it)
963 if (it->second == pData)
964 return it;
966 return itEnd;
969 ScAutoFormat::const_iterator ScAutoFormat::find(const OUString& rName) const
971 return maData.find(rName);
974 ScAutoFormat::iterator ScAutoFormat::find(const OUString& rName)
976 return maData.find(rName);
979 bool ScAutoFormat::insert(ScAutoFormatData* pNew)
981 OUString aName = pNew->GetName();
982 return maData.insert(aName, pNew).second;
985 void ScAutoFormat::erase(const iterator& it)
987 maData.erase(it);
990 size_t ScAutoFormat::size() const
992 return maData.size();
995 ScAutoFormat::const_iterator ScAutoFormat::begin() const
997 return maData.begin();
1000 ScAutoFormat::const_iterator ScAutoFormat::end() const
1002 return maData.end();
1005 ScAutoFormat::iterator ScAutoFormat::begin()
1007 return maData.begin();
1010 ScAutoFormat::iterator ScAutoFormat::end()
1012 return maData.end();
1015 bool ScAutoFormat::Load()
1017 INetURLObject aURL;
1018 SvtPathOptions aPathOpt;
1019 aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
1020 aURL.setFinalSlash();
1021 aURL.Append( OUString( sAutoTblFmtName ) );
1023 SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), StreamMode::READ );
1024 SvStream* pStream = aMedium.GetInStream();
1025 bool bRet = (pStream && pStream->GetError() == 0);
1026 if (bRet)
1028 SvStream& rStream = *pStream;
1029 // Attention: A common header has to be read
1030 sal_uInt16 nVal = 0;
1031 rStream.ReadUInt16( nVal );
1032 bRet = 0 == rStream.GetError();
1034 if (bRet)
1036 if( nVal == AUTOFORMAT_ID_358 ||
1037 (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1039 sal_uInt16 nFileVers = SOFFICE_FILEFORMAT_40;
1040 sal_uInt8 nChrSet, nCnt;
1041 long nPos = rStream.Tell();
1042 rStream.ReadUChar( nCnt ).ReadUChar( nChrSet );
1043 if( rStream.Tell() != sal_uLong(nPos + nCnt) )
1045 OSL_FAIL( "header contains more/newer data" );
1046 rStream.Seek( nPos + nCnt );
1048 rStream.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet ) );
1049 rStream.SetVersion( nFileVers );
1052 if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X ||
1053 (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1055 m_aVersions.Load( rStream, nVal ); // Item-Versionen
1057 ScAutoFormatData* pData;
1058 sal_uInt16 nAnz = 0;
1059 rStream.ReadUInt16( nAnz );
1060 bRet = (rStream.GetError() == 0);
1061 for (sal_uInt16 i=0; bRet && (i < nAnz); i++)
1063 pData = new ScAutoFormatData();
1064 bRet = pData->Load(rStream, m_aVersions);
1065 insert(pData);
1068 else
1069 bRet = false;
1072 mbSaveLater = false;
1073 return bRet;
1076 bool ScAutoFormat::Save()
1078 INetURLObject aURL;
1079 SvtPathOptions aPathOpt;
1080 aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
1081 aURL.setFinalSlash();
1082 aURL.Append(sAutoTblFmtName);
1084 SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), StreamMode::WRITE );
1085 SvStream* pStream = aMedium.GetOutStream();
1086 bool bRet = (pStream && pStream->GetError() == 0);
1087 if (bRet)
1089 const sal_uInt16 fileVersion = SOFFICE_FILEFORMAT_50;
1090 SvStream& rStream = *pStream;
1091 rStream.SetVersion( fileVersion );
1093 // Attention: A common header has to be saved
1094 sal_uInt16 nVal = AUTOFORMAT_ID;
1095 rStream.WriteUInt16( nVal )
1096 .WriteUChar( 2 ) // Number of chars of the header including this
1097 .WriteUChar( ::GetSOStoreTextEncoding(
1098 osl_getThreadTextEncoding() ) );
1099 m_aVersions.Write(rStream, fileVersion);
1101 bRet &= (rStream.GetError() == 0);
1103 rStream.WriteUInt16( maData.size() - 1 );
1104 bRet &= (rStream.GetError() == 0);
1105 MapType::iterator it = maData.begin(), itEnd = maData.end();
1106 if (it != itEnd)
1108 for (++it; bRet && it != itEnd; ++it) // Skip the first item.
1110 bRet &= it->second->Save(rStream, fileVersion);
1114 rStream.Flush();
1116 aMedium.Commit();
1118 mbSaveLater = false;
1119 return bRet;
1122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */