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 .
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 <tools/shl.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/outdev.hxx>
29 #include <svx/dialmgr.hxx>
30 #include <svx/dialogs.hrc>
31 #include <editeng/langitem.hxx>
32 #include <tools/urlobj.hxx>
33 #include <unotools/transliterationwrapper.hxx>
34 #include <tools/tenccvt.hxx>
36 #include "globstr.hrc"
37 #include "document.hxx"
40 * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST
41 * be synchronized with Writer's SwTableAutoFmtTbl sw/source/core/doc/tblafmt.cxx
44 const sal_Char
*linker_dummy
= "";
46 static const sal_Char sAutoTblFmtName
[] = "autotbl.fmt";
49 const sal_uInt16 AUTOFORMAT_ID_X
= 9501;
50 const sal_uInt16 AUTOFORMAT_ID_358
= 9601;
51 const sal_uInt16 AUTOFORMAT_DATA_ID_X
= 9502;
54 // in following versions the value of the IDs must be higher
55 const sal_uInt16 AUTOFORMAT_ID_504
= 9801;
56 const sal_uInt16 AUTOFORMAT_DATA_ID_504
= 9802;
58 const sal_uInt16 AUTOFORMAT_DATA_ID_552
= 9902;
60 // --- from 641 on: CJK and CTL font settings
61 const sal_uInt16 AUTOFORMAT_DATA_ID_641
= 10002;
63 // --- from 680/dr14 on: diagonal frame lines
64 const sal_uInt16 AUTOFORMAT_ID_680DR14
= 10011;
65 const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14
= 10012;
67 // --- from 680/dr25 on: store strings as UTF-8
68 const sal_uInt16 AUTOFORMAT_ID_680DR25
= 10021;
70 // --- from DEV300/overline2 on: overline support
71 const sal_uInt16 AUTOFORMAT_ID_300OVRLN
= 10031;
72 const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN
= 10032;
74 // --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc)
75 const sal_uInt16 AUTOFORMAT_ID_31005
= 10041;
76 const sal_uInt16 AUTOFORMAT_DATA_ID_31005
= 10042;
79 const sal_uInt16 AUTOFORMAT_ID
= AUTOFORMAT_ID_31005
;
80 const sal_uInt16 AUTOFORMAT_DATA_ID
= AUTOFORMAT_DATA_ID_31005
;
84 /// Read an AutoFormatSwBlob from stream.
85 SvStream
& operator>>(SvStream
&stream
, AutoFormatSwBlob
&blob
)
89 sal_uInt64 endOfBlob
= 0;
92 const sal_uInt64 currentPosition
= stream
.Tell();
93 const sal_uInt64 blobSize
= endOfBlob
- currentPosition
;
94 // A zero-size indicates an empty blob. This happens when Calc creates a new autoformat,
95 // since it (naturally) doesn't have any writer-specific data to write.
98 blob
.pData
= new sal_uInt8
[blobSize
];
99 blob
.size
= static_cast<sal_Size
>(blobSize
);
100 stream
.Read(blob
.pData
, blob
.size
);
106 /// Write an AutoFormatSwBlob to stream.
107 SvStream
& operator<<(SvStream
&stream
, AutoFormatSwBlob
&blob
)
109 const sal_uInt64 endOfBlob
= stream
.Tell() + sizeof(sal_uInt64
) + blob
.size
;
112 stream
.Write(blob
.pData
, blob
.size
);
118 ScAfVersions::ScAfVersions() :
120 nFontHeightVersion(0),
123 nUnderlineVersion(0),
125 nCrossedOutVersion(0),
133 nHorJustifyVersion(0),
134 nVerJustifyVersion(0),
135 nOrientationVersion(0),
139 nRotateModeVersion(0),
144 void ScAfVersions::Load( SvStream
& rStream
, sal_uInt16 nVer
)
146 rStream
>> nFontVersion
;
147 rStream
>> nFontHeightVersion
;
148 rStream
>> nWeightVersion
;
149 rStream
>> nPostureVersion
;
150 rStream
>> nUnderlineVersion
;
151 if ( nVer
>= AUTOFORMAT_ID_300OVRLN
)
152 rStream
>> nOverlineVersion
;
153 rStream
>> nCrossedOutVersion
;
154 rStream
>> nContourVersion
;
155 rStream
>> nShadowedVersion
;
156 rStream
>> nColorVersion
;
157 rStream
>> nBoxVersion
;
158 if ( nVer
>= AUTOFORMAT_ID_680DR14
)
159 rStream
>> nLineVersion
;
160 rStream
>> nBrushVersion
;
161 rStream
>> nAdjustVersion
;
162 if (nVer
>= AUTOFORMAT_ID_31005
)
163 rStream
>> swVersions
;
164 rStream
>> nHorJustifyVersion
;
165 rStream
>> nVerJustifyVersion
;
166 rStream
>> nOrientationVersion
;
167 rStream
>> nMarginVersion
;
168 rStream
>> nBoolVersion
;
169 if ( nVer
>= AUTOFORMAT_ID_504
)
171 rStream
>> nInt32Version
;
172 rStream
>> nRotateModeVersion
;
174 rStream
>> nNumFmtVersion
;
177 void ScAfVersions::Write(SvStream
& rStream
, sal_uInt16 fileVersion
)
179 rStream
<< SvxFontItem(ATTR_FONT
).GetVersion(fileVersion
);
180 rStream
<< SvxFontHeightItem(240, 100, ATTR_FONT_HEIGHT
).GetVersion(fileVersion
);
181 rStream
<< SvxWeightItem(WEIGHT_NORMAL
, ATTR_FONT_WEIGHT
).GetVersion(fileVersion
);
182 rStream
<< SvxPostureItem(ITALIC_NONE
, ATTR_FONT_POSTURE
).GetVersion(fileVersion
);
183 rStream
<< SvxUnderlineItem(UNDERLINE_NONE
, ATTR_FONT_UNDERLINE
).GetVersion(fileVersion
);
184 rStream
<< SvxOverlineItem(UNDERLINE_NONE
, ATTR_FONT_OVERLINE
).GetVersion(fileVersion
);
185 rStream
<< SvxCrossedOutItem(STRIKEOUT_NONE
, ATTR_FONT_CROSSEDOUT
).GetVersion(fileVersion
);
186 rStream
<< SvxContourItem(false, ATTR_FONT_CONTOUR
).GetVersion(fileVersion
);
187 rStream
<< SvxShadowedItem(false, ATTR_FONT_SHADOWED
).GetVersion(fileVersion
);
188 rStream
<< SvxColorItem(ATTR_FONT_COLOR
).GetVersion(fileVersion
);
189 rStream
<< SvxBoxItem(ATTR_BORDER
).GetVersion(fileVersion
);
190 rStream
<< SvxLineItem(SID_FRAME_LINESTYLE
).GetVersion(fileVersion
);
191 rStream
<< SvxBrushItem(ATTR_BACKGROUND
).GetVersion(fileVersion
);
193 rStream
<< SvxAdjustItem(SVX_ADJUST_LEFT
, 0).GetVersion(fileVersion
);
194 if (fileVersion
>= SOFFICE_FILEFORMAT_50
)
195 rStream
<< swVersions
;
197 rStream
<< SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD
, ATTR_HOR_JUSTIFY
).GetVersion(fileVersion
);
198 rStream
<< SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD
, ATTR_VER_JUSTIFY
).GetVersion(fileVersion
);
199 rStream
<< SvxOrientationItem(SVX_ORIENTATION_STANDARD
, 0).GetVersion(fileVersion
);
200 rStream
<< SvxMarginItem(ATTR_MARGIN
).GetVersion(fileVersion
);
201 rStream
<< SfxBoolItem(ATTR_LINEBREAK
).GetVersion(fileVersion
);
202 rStream
<< SfxInt32Item(ATTR_ROTATE_VALUE
).GetVersion(fileVersion
);
203 rStream
<< SvxRotateModeItem(SVX_ROTATE_MODE_STANDARD
,0).GetVersion(fileVersion
);
205 rStream
<< (sal_uInt16
)0; // Num-Format
208 ScAutoFormatDataField::ScAutoFormatDataField() :
210 aHeight( 240, 100, ATTR_FONT_HEIGHT
),
211 aWeight( WEIGHT_NORMAL
, ATTR_FONT_WEIGHT
),
212 aPosture( ITALIC_NONE
, ATTR_FONT_POSTURE
),
214 aCJKFont( ATTR_CJK_FONT
),
215 aCJKHeight( 240, 100, ATTR_CJK_FONT_HEIGHT
),
216 aCJKWeight( WEIGHT_NORMAL
, ATTR_CJK_FONT_WEIGHT
),
217 aCJKPosture( ITALIC_NONE
, ATTR_CJK_FONT_POSTURE
),
219 aCTLFont( ATTR_CTL_FONT
),
220 aCTLHeight( 240, 100, ATTR_CTL_FONT_HEIGHT
),
221 aCTLWeight( WEIGHT_NORMAL
, ATTR_CTL_FONT_WEIGHT
),
222 aCTLPosture( ITALIC_NONE
, ATTR_CTL_FONT_POSTURE
),
224 aUnderline( UNDERLINE_NONE
,ATTR_FONT_UNDERLINE
),
225 aOverline( UNDERLINE_NONE
,ATTR_FONT_OVERLINE
),
226 aCrossedOut( STRIKEOUT_NONE
, ATTR_FONT_CROSSEDOUT
),
227 aContour( false, ATTR_FONT_CONTOUR
),
228 aShadowed( false, ATTR_FONT_SHADOWED
),
229 aColor( ATTR_FONT_COLOR
),
231 aTLBR( ATTR_BORDER_TLBR
),
232 aBLTR( ATTR_BORDER_BLTR
),
233 aBackground( ATTR_BACKGROUND
),
234 aAdjust( SVX_ADJUST_LEFT
, 0 ),
235 aHorJustify( SVX_HOR_JUSTIFY_STANDARD
, ATTR_HOR_JUSTIFY
),
236 aVerJustify( SVX_VER_JUSTIFY_STANDARD
, ATTR_VER_JUSTIFY
),
237 aMargin( ATTR_MARGIN
),
238 aLinebreak( ATTR_LINEBREAK
),
239 aRotateAngle( ATTR_ROTATE_VALUE
),
240 aRotateMode( SVX_ROTATE_MODE_STANDARD
, ATTR_ROTATE_MODE
)
244 ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField
& rCopy
) :
245 aFont( rCopy
.aFont
),
246 aHeight( rCopy
.aHeight
),
247 aWeight( rCopy
.aWeight
),
248 aPosture( rCopy
.aPosture
),
249 aCJKFont( rCopy
.aCJKFont
),
250 aCJKHeight( rCopy
.aCJKHeight
),
251 aCJKWeight( rCopy
.aCJKWeight
),
252 aCJKPosture( rCopy
.aCJKPosture
),
253 aCTLFont( rCopy
.aCTLFont
),
254 aCTLHeight( rCopy
.aCTLHeight
),
255 aCTLWeight( rCopy
.aCTLWeight
),
256 aCTLPosture( rCopy
.aCTLPosture
),
257 aUnderline( rCopy
.aUnderline
),
258 aOverline( rCopy
.aOverline
),
259 aCrossedOut( rCopy
.aCrossedOut
),
260 aContour( rCopy
.aContour
),
261 aShadowed( rCopy
.aShadowed
),
262 aColor( rCopy
.aColor
),
264 aTLBR( rCopy
.aTLBR
),
265 aBLTR( rCopy
.aBLTR
),
266 aBackground( rCopy
.aBackground
),
267 aAdjust( rCopy
.aAdjust
),
268 aHorJustify( rCopy
.aHorJustify
),
269 aVerJustify( rCopy
.aVerJustify
),
270 aStacked( rCopy
.aStacked
),
271 aMargin( rCopy
.aMargin
),
272 aLinebreak( rCopy
.aLinebreak
),
273 aRotateAngle( rCopy
.aRotateAngle
),
274 aRotateMode( rCopy
.aRotateMode
),
275 aNumFormat( rCopy
.aNumFormat
)
279 ScAutoFormatDataField::~ScAutoFormatDataField()
283 void ScAutoFormatDataField::SetAdjust( const SvxAdjustItem
& rAdjust
)
285 aAdjust
.SetAdjust( rAdjust
.GetAdjust() );
286 aAdjust
.SetOneWord( rAdjust
.GetOneWord() );
287 aAdjust
.SetLastBlock( rAdjust
.GetLastBlock() );
290 #define READ( aItem, ItemType, nVers ) \
291 pNew = aItem.Create( rStream, nVers ); \
292 aItem = *(ItemType*)pNew; \
295 sal_Bool
ScAutoFormatDataField::Load( SvStream
& rStream
, const ScAfVersions
& rVersions
, sal_uInt16 nVer
)
298 SvxOrientationItem
aOrientation( SVX_ORIENTATION_STANDARD
, 0 );
300 READ( aFont
, SvxFontItem
, rVersions
.nFontVersion
)
301 READ( aHeight
, SvxFontHeightItem
, rVersions
.nFontHeightVersion
)
302 READ( aWeight
, SvxWeightItem
, rVersions
.nWeightVersion
)
303 READ( aPosture
, SvxPostureItem
, rVersions
.nPostureVersion
)
304 // --- from 641 on: CJK and CTL font settings
305 if( AUTOFORMAT_DATA_ID_641
<= nVer
)
307 READ( aCJKFont
, SvxFontItem
, rVersions
.nFontVersion
)
308 READ( aCJKHeight
, SvxFontHeightItem
, rVersions
.nFontHeightVersion
)
309 READ( aCJKWeight
, SvxWeightItem
, rVersions
.nWeightVersion
)
310 READ( aCJKPosture
, SvxPostureItem
, rVersions
.nPostureVersion
)
311 READ( aCTLFont
, SvxFontItem
, rVersions
.nFontVersion
)
312 READ( aCTLHeight
, SvxFontHeightItem
, rVersions
.nFontHeightVersion
)
313 READ( aCTLWeight
, SvxWeightItem
, rVersions
.nWeightVersion
)
314 READ( aCTLPosture
, SvxPostureItem
, rVersions
.nPostureVersion
)
316 READ( aUnderline
, SvxUnderlineItem
, rVersions
.nUnderlineVersion
)
317 if ( nVer
>= AUTOFORMAT_DATA_ID_300OVRLN
)
319 READ( aOverline
, SvxOverlineItem
, rVersions
.nOverlineVersion
)
321 READ( aCrossedOut
, SvxCrossedOutItem
, rVersions
.nCrossedOutVersion
)
322 READ( aContour
, SvxContourItem
, rVersions
.nContourVersion
)
323 READ( aShadowed
, SvxShadowedItem
, rVersions
.nShadowedVersion
)
324 READ( aColor
, SvxColorItem
, rVersions
.nColorVersion
)
325 READ( aBox
, SvxBoxItem
, rVersions
.nBoxVersion
)
327 // --- from 680/dr14 on: diagonal frame lines
328 if( AUTOFORMAT_DATA_ID_680DR14
<= nVer
)
330 READ( aTLBR
, SvxLineItem
, rVersions
.nLineVersion
)
331 READ( aBLTR
, SvxLineItem
, rVersions
.nLineVersion
)
334 READ( aBackground
, SvxBrushItem
, rVersions
.nBrushVersion
)
336 pNew
= aAdjust
.Create( rStream
, rVersions
.nAdjustVersion
);
337 SetAdjust( *(SvxAdjustItem
*)pNew
);
340 if (nVer
>= AUTOFORMAT_DATA_ID_31005
)
341 rStream
>> m_swFields
;
343 READ( aHorJustify
, SvxHorJustifyItem
, rVersions
.nHorJustifyVersion
)
344 READ( aVerJustify
, SvxVerJustifyItem
, rVersions
.nVerJustifyVersion
)
345 READ( aOrientation
, SvxOrientationItem
, rVersions
.nOrientationVersion
)
346 READ( aMargin
, SvxMarginItem
, rVersions
.nMarginVersion
)
348 pNew
= aLinebreak
.Create( rStream
, rVersions
.nBoolVersion
);
349 SetLinebreak( *(SfxBoolItem
*)pNew
);
352 if ( nVer
>= AUTOFORMAT_DATA_ID_504
)
354 pNew
= aRotateAngle
.Create( rStream
, rVersions
.nInt32Version
);
355 SetRotateAngle( *(SfxInt32Item
*)pNew
);
357 pNew
= aRotateMode
.Create( rStream
, rVersions
.nRotateModeVersion
);
358 SetRotateMode( *(SvxRotateModeItem
*)pNew
);
362 if( 0 == rVersions
.nNumFmtVersion
)
364 // --- from 680/dr25 on: store strings as UTF-8
365 rtl_TextEncoding eCharSet
= (nVer
>= AUTOFORMAT_ID_680DR25
) ? RTL_TEXTENCODING_UTF8
: rStream
.GetStreamCharSet();
366 aNumFormat
.Load( rStream
, eCharSet
);
369 // adjust charset in font
370 rtl_TextEncoding eSysSet
= osl_getThreadTextEncoding();
371 rtl_TextEncoding eSrcSet
= rStream
.GetStreamCharSet();
372 if( eSrcSet
!= eSysSet
&& aFont
.GetCharSet() == eSrcSet
)
373 aFont
.SetCharSet(eSysSet
);
375 aStacked
.SetValue( aOrientation
.IsStacked() );
376 aRotateAngle
.SetValue( aOrientation
.GetRotation( aRotateAngle
.GetValue() ) );
378 return (rStream
.GetError() == 0);
381 sal_Bool
ScAutoFormatDataField::Save( SvStream
& rStream
, sal_uInt16 fileVersion
)
383 SvxOrientationItem
aOrientation( aRotateAngle
.GetValue(), aStacked
.GetValue(), 0 );
385 aFont
.Store ( rStream
, aFont
.GetVersion( fileVersion
) );
386 aHeight
.Store ( rStream
, aHeight
.GetVersion( fileVersion
) );
387 aWeight
.Store ( rStream
, aWeight
.GetVersion( fileVersion
) );
388 aPosture
.Store ( rStream
, aPosture
.GetVersion( fileVersion
) );
389 // --- from 641 on: CJK and CTL font settings
390 aCJKFont
.Store ( rStream
, aCJKFont
.GetVersion( fileVersion
) );
391 aCJKHeight
.Store ( rStream
, aCJKHeight
.GetVersion( fileVersion
) );
392 aCJKWeight
.Store ( rStream
, aCJKWeight
.GetVersion( fileVersion
) );
393 aCJKPosture
.Store ( rStream
, aCJKPosture
.GetVersion( fileVersion
) );
394 aCTLFont
.Store ( rStream
, aCTLFont
.GetVersion( fileVersion
) );
395 aCTLHeight
.Store ( rStream
, aCTLHeight
.GetVersion( fileVersion
) );
396 aCTLWeight
.Store ( rStream
, aCTLWeight
.GetVersion( fileVersion
) );
397 aCTLPosture
.Store ( rStream
, aCTLPosture
.GetVersion( fileVersion
) );
399 aUnderline
.Store ( rStream
, aUnderline
.GetVersion( fileVersion
) );
400 // --- from DEV300/overline2 on: overline support
401 aOverline
.Store ( rStream
, aOverline
.GetVersion( fileVersion
) );
402 aCrossedOut
.Store ( rStream
, aCrossedOut
.GetVersion( fileVersion
) );
403 aContour
.Store ( rStream
, aContour
.GetVersion( fileVersion
) );
404 aShadowed
.Store ( rStream
, aShadowed
.GetVersion( fileVersion
) );
405 aColor
.Store ( rStream
, aColor
.GetVersion( fileVersion
) );
406 aBox
.Store ( rStream
, aBox
.GetVersion( fileVersion
) );
408 // --- from 680/dr14 on: diagonal frame lines
409 aTLBR
.Store ( rStream
, aTLBR
.GetVersion( fileVersion
) );
410 aBLTR
.Store ( rStream
, aBLTR
.GetVersion( fileVersion
) );
412 aBackground
.Store ( rStream
, aBackground
.GetVersion( fileVersion
) );
414 aAdjust
.Store ( rStream
, aAdjust
.GetVersion( fileVersion
) );
415 if (fileVersion
>= SOFFICE_FILEFORMAT_50
)
416 rStream
<< m_swFields
;
418 aHorJustify
.Store ( rStream
, aHorJustify
.GetVersion( fileVersion
) );
419 aVerJustify
.Store ( rStream
, aVerJustify
.GetVersion( fileVersion
) );
420 aOrientation
.Store ( rStream
, aOrientation
.GetVersion( fileVersion
) );
421 aMargin
.Store ( rStream
, aMargin
.GetVersion( fileVersion
) );
422 aLinebreak
.Store ( rStream
, aLinebreak
.GetVersion( fileVersion
) );
424 aRotateAngle
.Store ( rStream
, aRotateAngle
.GetVersion( fileVersion
) );
425 aRotateMode
.Store ( rStream
, aRotateMode
.GetVersion( fileVersion
) );
427 // --- from 680/dr25 on: store strings as UTF-8
428 aNumFormat
.Save( rStream
, RTL_TEXTENCODING_UTF8
);
430 return (rStream
.GetError() == 0);
433 ScAutoFormatData::ScAutoFormatData()
435 nStrResId
= USHRT_MAX
;
437 bIncludeValueFormat
=
442 bIncludeWidthHeight
= true;
444 ppDataField
= new ScAutoFormatDataField
*[ 16 ];
445 for( sal_uInt16 nIndex
= 0; nIndex
< 16; ++nIndex
)
446 ppDataField
[ nIndex
] = new ScAutoFormatDataField
;
449 ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData
& rData
) :
450 aName( rData
.aName
),
451 nStrResId( rData
.nStrResId
),
452 bIncludeFont( rData
.bIncludeFont
),
453 bIncludeJustify( rData
.bIncludeJustify
),
454 bIncludeFrame( rData
.bIncludeFrame
),
455 bIncludeBackground( rData
.bIncludeBackground
),
456 bIncludeValueFormat( rData
.bIncludeValueFormat
),
457 bIncludeWidthHeight( rData
.bIncludeWidthHeight
)
459 ppDataField
= new ScAutoFormatDataField
*[ 16 ];
460 for( sal_uInt16 nIndex
= 0; nIndex
< 16; ++nIndex
)
461 ppDataField
[ nIndex
] = new ScAutoFormatDataField( rData
.GetField( nIndex
) );
464 ScAutoFormatData::~ScAutoFormatData()
466 for( sal_uInt16 nIndex
= 0; nIndex
< 16; ++nIndex
)
467 delete ppDataField
[ nIndex
];
468 delete[] ppDataField
;
471 ScAutoFormatDataField
& ScAutoFormatData::GetField( sal_uInt16 nIndex
)
473 OSL_ENSURE( nIndex
< 16, "ScAutoFormatData::GetField - illegal index" );
474 OSL_ENSURE( ppDataField
&& ppDataField
[ nIndex
], "ScAutoFormatData::GetField - no data" );
475 return *ppDataField
[ nIndex
];
478 const ScAutoFormatDataField
& ScAutoFormatData::GetField( sal_uInt16 nIndex
) const
480 OSL_ENSURE( nIndex
< 16, "ScAutoFormatData::GetField - illegal index" );
481 OSL_ENSURE( ppDataField
&& ppDataField
[ nIndex
], "ScAutoFormatData::GetField - no data" );
482 return *ppDataField
[ nIndex
];
485 const SfxPoolItem
* ScAutoFormatData::GetItem( sal_uInt16 nIndex
, sal_uInt16 nWhich
) const
487 const ScAutoFormatDataField
& rField
= GetField( nIndex
);
490 case ATTR_FONT
: return &rField
.GetFont();
491 case ATTR_FONT_HEIGHT
: return &rField
.GetHeight();
492 case ATTR_FONT_WEIGHT
: return &rField
.GetWeight();
493 case ATTR_FONT_POSTURE
: return &rField
.GetPosture();
494 case ATTR_CJK_FONT
: return &rField
.GetCJKFont();
495 case ATTR_CJK_FONT_HEIGHT
: return &rField
.GetCJKHeight();
496 case ATTR_CJK_FONT_WEIGHT
: return &rField
.GetCJKWeight();
497 case ATTR_CJK_FONT_POSTURE
: return &rField
.GetCJKPosture();
498 case ATTR_CTL_FONT
: return &rField
.GetCTLFont();
499 case ATTR_CTL_FONT_HEIGHT
: return &rField
.GetCTLHeight();
500 case ATTR_CTL_FONT_WEIGHT
: return &rField
.GetCTLWeight();
501 case ATTR_CTL_FONT_POSTURE
: return &rField
.GetCTLPosture();
502 case ATTR_FONT_UNDERLINE
: return &rField
.GetUnderline();
503 case ATTR_FONT_OVERLINE
: return &rField
.GetOverline();
504 case ATTR_FONT_CROSSEDOUT
: return &rField
.GetCrossedOut();
505 case ATTR_FONT_CONTOUR
: return &rField
.GetContour();
506 case ATTR_FONT_SHADOWED
: return &rField
.GetShadowed();
507 case ATTR_FONT_COLOR
: return &rField
.GetColor();
508 case ATTR_BORDER
: return &rField
.GetBox();
509 case ATTR_BORDER_TLBR
: return &rField
.GetTLBR();
510 case ATTR_BORDER_BLTR
: return &rField
.GetBLTR();
511 case ATTR_BACKGROUND
: return &rField
.GetBackground();
512 case ATTR_HOR_JUSTIFY
: return &rField
.GetHorJustify();
513 case ATTR_VER_JUSTIFY
: return &rField
.GetVerJustify();
514 case ATTR_STACKED
: return &rField
.GetStacked();
515 case ATTR_MARGIN
: return &rField
.GetMargin();
516 case ATTR_LINEBREAK
: return &rField
.GetLinebreak();
517 case ATTR_ROTATE_VALUE
: return &rField
.GetRotateAngle();
518 case ATTR_ROTATE_MODE
: return &rField
.GetRotateMode();
523 void ScAutoFormatData::PutItem( sal_uInt16 nIndex
, const SfxPoolItem
& rItem
)
525 ScAutoFormatDataField
& rField
= GetField( nIndex
);
526 switch( rItem
.Which() )
528 case ATTR_FONT
: rField
.SetFont( (const SvxFontItem
&)rItem
); break;
529 case ATTR_FONT_HEIGHT
: rField
.SetHeight( (const SvxFontHeightItem
&)rItem
); break;
530 case ATTR_FONT_WEIGHT
: rField
.SetWeight( (const SvxWeightItem
&)rItem
); break;
531 case ATTR_FONT_POSTURE
: rField
.SetPosture( (const SvxPostureItem
&)rItem
); break;
532 case ATTR_CJK_FONT
: rField
.SetCJKFont( (const SvxFontItem
&)rItem
); break;
533 case ATTR_CJK_FONT_HEIGHT
: rField
.SetCJKHeight( (const SvxFontHeightItem
&)rItem
); break;
534 case ATTR_CJK_FONT_WEIGHT
: rField
.SetCJKWeight( (const SvxWeightItem
&)rItem
); break;
535 case ATTR_CJK_FONT_POSTURE
: rField
.SetCJKPosture( (const SvxPostureItem
&)rItem
); break;
536 case ATTR_CTL_FONT
: rField
.SetCTLFont( (const SvxFontItem
&)rItem
); break;
537 case ATTR_CTL_FONT_HEIGHT
: rField
.SetCTLHeight( (const SvxFontHeightItem
&)rItem
); break;
538 case ATTR_CTL_FONT_WEIGHT
: rField
.SetCTLWeight( (const SvxWeightItem
&)rItem
); break;
539 case ATTR_CTL_FONT_POSTURE
: rField
.SetCTLPosture( (const SvxPostureItem
&)rItem
); break;
540 case ATTR_FONT_UNDERLINE
: rField
.SetUnderline( (const SvxUnderlineItem
&)rItem
); break;
541 case ATTR_FONT_OVERLINE
: rField
.SetOverline( (const SvxOverlineItem
&)rItem
); break;
542 case ATTR_FONT_CROSSEDOUT
: rField
.SetCrossedOut( (const SvxCrossedOutItem
&)rItem
); break;
543 case ATTR_FONT_CONTOUR
: rField
.SetContour( (const SvxContourItem
&)rItem
); break;
544 case ATTR_FONT_SHADOWED
: rField
.SetShadowed( (const SvxShadowedItem
&)rItem
); break;
545 case ATTR_FONT_COLOR
: rField
.SetColor( (const SvxColorItem
&)rItem
); break;
546 case ATTR_BORDER
: rField
.SetBox( (const SvxBoxItem
&)rItem
); break;
547 case ATTR_BORDER_TLBR
: rField
.SetTLBR( (const SvxLineItem
&)rItem
); break;
548 case ATTR_BORDER_BLTR
: rField
.SetBLTR( (const SvxLineItem
&)rItem
); break;
549 case ATTR_BACKGROUND
: rField
.SetBackground( (const SvxBrushItem
&)rItem
); break;
550 case ATTR_HOR_JUSTIFY
: rField
.SetHorJustify( (const SvxHorJustifyItem
&)rItem
); break;
551 case ATTR_VER_JUSTIFY
: rField
.SetVerJustify( (const SvxVerJustifyItem
&)rItem
); break;
552 case ATTR_STACKED
: rField
.SetStacked( (const SfxBoolItem
&)rItem
); break;
553 case ATTR_MARGIN
: rField
.SetMargin( (const SvxMarginItem
&)rItem
); break;
554 case ATTR_LINEBREAK
: rField
.SetLinebreak( (const SfxBoolItem
&)rItem
); break;
555 case ATTR_ROTATE_VALUE
: rField
.SetRotateAngle( (const SfxInt32Item
&)rItem
); break;
556 case ATTR_ROTATE_MODE
: rField
.SetRotateMode( (const SvxRotateModeItem
&)rItem
); break;
560 void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex
, sal_uInt16 nFromIndex
, sal_uInt16 nWhich
)
562 const SfxPoolItem
* pItem
= GetItem( nFromIndex
, nWhich
);
564 PutItem( nToIndex
, *pItem
);
567 const ScNumFormatAbbrev
& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex
) const
569 return GetField( nIndex
).GetNumFormat();
572 bool ScAutoFormatData::IsEqualData( sal_uInt16 nIndex1
, sal_uInt16 nIndex2
) const
575 const ScAutoFormatDataField
& rField1
= GetField( nIndex1
);
576 const ScAutoFormatDataField
& rField2
= GetField( nIndex2
);
578 if( bIncludeValueFormat
)
581 && (rField1
.GetNumFormat() == rField2
.GetNumFormat());
586 && (rField1
.GetFont() == rField2
.GetFont())
587 && (rField1
.GetHeight() == rField2
.GetHeight())
588 && (rField1
.GetWeight() == rField2
.GetWeight())
589 && (rField1
.GetPosture() == rField2
.GetPosture())
590 && (rField1
.GetCJKFont() == rField2
.GetCJKFont())
591 && (rField1
.GetCJKHeight() == rField2
.GetCJKHeight())
592 && (rField1
.GetCJKWeight() == rField2
.GetCJKWeight())
593 && (rField1
.GetCJKPosture() == rField2
.GetCJKPosture())
594 && (rField1
.GetCTLFont() == rField2
.GetCTLFont())
595 && (rField1
.GetCTLHeight() == rField2
.GetCTLHeight())
596 && (rField1
.GetCTLWeight() == rField2
.GetCTLWeight())
597 && (rField1
.GetCTLPosture() == rField2
.GetCTLPosture())
598 && (rField1
.GetUnderline() == rField2
.GetUnderline())
599 && (rField1
.GetOverline() == rField2
.GetOverline())
600 && (rField1
.GetCrossedOut() == rField2
.GetCrossedOut())
601 && (rField1
.GetContour() == rField2
.GetContour())
602 && (rField1
.GetShadowed() == rField2
.GetShadowed())
603 && (rField1
.GetColor() == rField2
.GetColor());
605 if( bIncludeJustify
)
608 && (rField1
.GetHorJustify() == rField2
.GetHorJustify())
609 && (rField1
.GetVerJustify() == rField2
.GetVerJustify())
610 && (rField1
.GetStacked() == rField2
.GetStacked())
611 && (rField1
.GetLinebreak() == rField2
.GetLinebreak())
612 && (rField1
.GetMargin() == rField2
.GetMargin())
613 && (rField1
.GetRotateAngle() == rField2
.GetRotateAngle())
614 && (rField1
.GetRotateMode() == rField2
.GetRotateMode());
619 && (rField1
.GetBox() == rField2
.GetBox())
620 && (rField1
.GetTLBR() == rField2
.GetTLBR())
621 && (rField1
.GetBLTR() == rField2
.GetBLTR());
623 if( bIncludeBackground
)
626 && (rField1
.GetBackground() == rField2
.GetBackground());
631 void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex
, SfxItemSet
& rItemSet
, ScDocument
& rDoc
) const
633 const ScAutoFormatDataField
& rField
= GetField( nIndex
);
635 if( bIncludeValueFormat
)
637 ScNumFormatAbbrev
& rNumFormat
= (ScNumFormatAbbrev
&)rField
.GetNumFormat();
638 SfxUInt32Item
aValueFormat( ATTR_VALUE_FORMAT
, 0 );
639 aValueFormat
.SetValue( rNumFormat
.GetFormatIndex( *rDoc
.GetFormatTable() ) );
640 rItemSet
.Put( aValueFormat
);
641 rItemSet
.Put( SvxLanguageItem( rNumFormat
.GetLanguage(), ATTR_LANGUAGE_FORMAT
) );
645 rItemSet
.Put( rField
.GetFont() );
646 rItemSet
.Put( rField
.GetHeight() );
647 rItemSet
.Put( rField
.GetWeight() );
648 rItemSet
.Put( rField
.GetPosture() );
649 // do not insert empty CJK font
650 const SvxFontItem
& rCJKFont
= rField
.GetCJKFont();
651 if (!rCJKFont
.GetStyleName().isEmpty())
653 rItemSet
.Put( rCJKFont
);
654 rItemSet
.Put( rField
.GetCJKHeight() );
655 rItemSet
.Put( rField
.GetCJKWeight() );
656 rItemSet
.Put( rField
.GetCJKPosture() );
660 rItemSet
.Put( rField
.GetHeight(), ATTR_CJK_FONT_HEIGHT
);
661 rItemSet
.Put( rField
.GetWeight(), ATTR_CJK_FONT_WEIGHT
);
662 rItemSet
.Put( rField
.GetPosture(), ATTR_CJK_FONT_POSTURE
);
664 // do not insert empty CTL font
665 const SvxFontItem
& rCTLFont
= rField
.GetCTLFont();
666 if (rCTLFont
.GetStyleName().isEmpty())
668 rItemSet
.Put( rCTLFont
);
669 rItemSet
.Put( rField
.GetCTLHeight() );
670 rItemSet
.Put( rField
.GetCTLWeight() );
671 rItemSet
.Put( rField
.GetCTLPosture() );
675 rItemSet
.Put( rField
.GetHeight(), ATTR_CTL_FONT_HEIGHT
);
676 rItemSet
.Put( rField
.GetWeight(), ATTR_CTL_FONT_WEIGHT
);
677 rItemSet
.Put( rField
.GetPosture(), ATTR_CTL_FONT_POSTURE
);
679 rItemSet
.Put( rField
.GetUnderline() );
680 rItemSet
.Put( rField
.GetOverline() );
681 rItemSet
.Put( rField
.GetCrossedOut() );
682 rItemSet
.Put( rField
.GetContour() );
683 rItemSet
.Put( rField
.GetShadowed() );
684 rItemSet
.Put( rField
.GetColor() );
686 if( bIncludeJustify
)
688 rItemSet
.Put( rField
.GetHorJustify() );
689 rItemSet
.Put( rField
.GetVerJustify() );
690 rItemSet
.Put( rField
.GetStacked() );
691 rItemSet
.Put( rField
.GetLinebreak() );
692 rItemSet
.Put( rField
.GetMargin() );
693 rItemSet
.Put( rField
.GetRotateAngle() );
694 rItemSet
.Put( rField
.GetRotateMode() );
698 rItemSet
.Put( rField
.GetBox() );
699 rItemSet
.Put( rField
.GetTLBR() );
700 rItemSet
.Put( rField
.GetBLTR() );
702 if( bIncludeBackground
)
703 rItemSet
.Put( rField
.GetBackground() );
706 void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex
, const SfxItemSet
& rItemSet
, const ScNumFormatAbbrev
& rNumFormat
)
708 ScAutoFormatDataField
& rField
= GetField( nIndex
);
710 rField
.SetNumFormat ( rNumFormat
);
711 rField
.SetFont ( (const SvxFontItem
&) rItemSet
.Get( ATTR_FONT
) );
712 rField
.SetHeight ( (const SvxFontHeightItem
&) rItemSet
.Get( ATTR_FONT_HEIGHT
) );
713 rField
.SetWeight ( (const SvxWeightItem
&) rItemSet
.Get( ATTR_FONT_WEIGHT
) );
714 rField
.SetPosture ( (const SvxPostureItem
&) rItemSet
.Get( ATTR_FONT_POSTURE
) );
715 rField
.SetCJKFont ( (const SvxFontItem
&) rItemSet
.Get( ATTR_CJK_FONT
) );
716 rField
.SetCJKHeight ( (const SvxFontHeightItem
&) rItemSet
.Get( ATTR_CJK_FONT_HEIGHT
) );
717 rField
.SetCJKWeight ( (const SvxWeightItem
&) rItemSet
.Get( ATTR_CJK_FONT_WEIGHT
) );
718 rField
.SetCJKPosture ( (const SvxPostureItem
&) rItemSet
.Get( ATTR_CJK_FONT_POSTURE
) );
719 rField
.SetCTLFont ( (const SvxFontItem
&) rItemSet
.Get( ATTR_CTL_FONT
) );
720 rField
.SetCTLHeight ( (const SvxFontHeightItem
&) rItemSet
.Get( ATTR_CTL_FONT_HEIGHT
) );
721 rField
.SetCTLWeight ( (const SvxWeightItem
&) rItemSet
.Get( ATTR_CTL_FONT_WEIGHT
) );
722 rField
.SetCTLPosture ( (const SvxPostureItem
&) rItemSet
.Get( ATTR_CTL_FONT_POSTURE
) );
723 rField
.SetUnderline ( (const SvxUnderlineItem
&) rItemSet
.Get( ATTR_FONT_UNDERLINE
) );
724 rField
.SetOverline ( (const SvxOverlineItem
&) rItemSet
.Get( ATTR_FONT_OVERLINE
) );
725 rField
.SetCrossedOut ( (const SvxCrossedOutItem
&) rItemSet
.Get( ATTR_FONT_CROSSEDOUT
) );
726 rField
.SetContour ( (const SvxContourItem
&) rItemSet
.Get( ATTR_FONT_CONTOUR
) );
727 rField
.SetShadowed ( (const SvxShadowedItem
&) rItemSet
.Get( ATTR_FONT_SHADOWED
) );
728 rField
.SetColor ( (const SvxColorItem
&) rItemSet
.Get( ATTR_FONT_COLOR
) );
729 rField
.SetTLBR ( (const SvxLineItem
&) rItemSet
.Get( ATTR_BORDER_TLBR
) );
730 rField
.SetBLTR ( (const SvxLineItem
&) rItemSet
.Get( ATTR_BORDER_BLTR
) );
731 rField
.SetHorJustify ( (const SvxHorJustifyItem
&) rItemSet
.Get( ATTR_HOR_JUSTIFY
) );
732 rField
.SetVerJustify ( (const SvxVerJustifyItem
&) rItemSet
.Get( ATTR_VER_JUSTIFY
) );
733 rField
.SetStacked ( (const SfxBoolItem
&) rItemSet
.Get( ATTR_STACKED
) );
734 rField
.SetLinebreak ( (const SfxBoolItem
&) rItemSet
.Get( ATTR_LINEBREAK
) );
735 rField
.SetMargin ( (const SvxMarginItem
&) rItemSet
.Get( ATTR_MARGIN
) );
736 rField
.SetBackground ( (const SvxBrushItem
&) rItemSet
.Get( ATTR_BACKGROUND
) );
737 rField
.SetRotateAngle ( (const SfxInt32Item
&) rItemSet
.Get( ATTR_ROTATE_VALUE
) );
738 rField
.SetRotateMode ( (const SvxRotateModeItem
&) rItemSet
.Get( ATTR_ROTATE_MODE
) );
741 bool ScAutoFormatData::Load( SvStream
& rStream
, const ScAfVersions
& rVersions
)
745 bool bRet
= 0 == rStream
.GetError();
746 if( bRet
&& (nVer
== AUTOFORMAT_DATA_ID_X
||
747 (AUTOFORMAT_DATA_ID_504
<= nVer
&& nVer
<= AUTOFORMAT_DATA_ID
)) )
749 // --- from 680/dr25 on: store strings as UTF-8
750 if (nVer
>= AUTOFORMAT_ID_680DR25
)
752 aName
= read_lenPrefixed_uInt8s_ToOUString
<sal_uInt16
>(rStream
,
753 RTL_TEXTENCODING_UTF8
);
756 aName
= rStream
.ReadUniOrByteString( rStream
.GetStreamCharSet() );
758 if( AUTOFORMAT_DATA_ID_552
<= nVer
)
760 rStream
>> nStrResId
;
761 sal_uInt16 nId
= RID_SVXSTR_TBLAFMT_BEGIN
+ nStrResId
;
762 if( RID_SVXSTR_TBLAFMT_BEGIN
<= nId
&&
763 nId
< RID_SVXSTR_TBLAFMT_END
)
765 aName
= SVX_RESSTR( nId
);
768 nStrResId
= USHRT_MAX
;
772 rStream
>> b
; bIncludeFont
= b
;
773 rStream
>> b
; bIncludeJustify
= b
;
774 rStream
>> b
; bIncludeFrame
= b
;
775 rStream
>> b
; bIncludeBackground
= b
;
776 rStream
>> b
; bIncludeValueFormat
= b
;
777 rStream
>> b
; bIncludeWidthHeight
= b
;
779 if (nVer
>= AUTOFORMAT_DATA_ID_31005
)
780 rStream
>> m_swFields
;
782 bRet
= 0 == rStream
.GetError();
783 for( sal_uInt16 i
= 0; bRet
&& i
< 16; ++i
)
784 bRet
= GetField( i
).Load( rStream
, rVersions
, nVer
);
791 bool ScAutoFormatData::Save(SvStream
& rStream
, sal_uInt16 fileVersion
)
793 sal_uInt16 nVal
= AUTOFORMAT_DATA_ID
;
796 // --- from 680/dr25 on: store strings as UTF-8
797 write_lenPrefixed_uInt8s_FromOUString
<sal_uInt16
>(rStream
, aName
, RTL_TEXTENCODING_UTF8
);
799 rStream
<< nStrResId
;
800 rStream
<< ( b
= bIncludeFont
);
801 rStream
<< ( b
= bIncludeJustify
);
802 rStream
<< ( b
= bIncludeFrame
);
803 rStream
<< ( b
= bIncludeBackground
);
804 rStream
<< ( b
= bIncludeValueFormat
);
805 rStream
<< ( b
= bIncludeWidthHeight
);
807 if (fileVersion
>= SOFFICE_FILEFORMAT_50
)
808 rStream
<< m_swFields
;
810 sal_Bool bRet
= 0 == rStream
.GetError();
811 for (sal_uInt16 i
= 0; bRet
&& (i
< 16); i
++)
812 bRet
= GetField( i
).Save( rStream
, fileVersion
);
817 ScAutoFormat::ScAutoFormat() :
820 // create default autoformat
821 ScAutoFormatData
* pData
= new ScAutoFormatData
;
822 OUString
aName(ScGlobal::GetRscString(STR_STYLENAME_STANDARD
));
823 pData
->SetName(aName
);
825 // default font, default height
826 Font aStdFont
= OutputDevice::GetDefaultFont(
827 DEFAULTFONT_LATIN_SPREADSHEET
, LANGUAGE_ENGLISH_US
, DEFAULTFONT_FLAGS_ONLYONE
);
828 SvxFontItem
aFontItem(
829 aStdFont
.GetFamily(), aStdFont
.GetName(), aStdFont
.GetStyleName(),
830 aStdFont
.GetPitch(), aStdFont
.GetCharSet(), ATTR_FONT
);
832 aStdFont
= OutputDevice::GetDefaultFont(
833 DEFAULTFONT_CJK_SPREADSHEET
, LANGUAGE_ENGLISH_US
, DEFAULTFONT_FLAGS_ONLYONE
);
834 SvxFontItem
aCJKFontItem(
835 aStdFont
.GetFamily(), aStdFont
.GetName(), aStdFont
.GetStyleName(),
836 aStdFont
.GetPitch(), aStdFont
.GetCharSet(), ATTR_CJK_FONT
);
838 aStdFont
= OutputDevice::GetDefaultFont(
839 DEFAULTFONT_CTL_SPREADSHEET
, LANGUAGE_ENGLISH_US
, DEFAULTFONT_FLAGS_ONLYONE
);
840 SvxFontItem
aCTLFontItem(
841 aStdFont
.GetFamily(), aStdFont
.GetName(), aStdFont
.GetStyleName(),
842 aStdFont
.GetPitch(), aStdFont
.GetCharSet(), ATTR_CTL_FONT
);
844 SvxFontHeightItem
aHeight( 200, 100, ATTR_FONT_HEIGHT
); // 10 pt;
847 Color
aBlack( COL_BLACK
);
848 ::editeng::SvxBorderLine
aLine( &aBlack
, DEF_LINE_WIDTH_0
);
849 SvxBoxItem
aBox( ATTR_BORDER
);
850 aBox
.SetLine(&aLine
, BOX_LINE_LEFT
);
851 aBox
.SetLine(&aLine
, BOX_LINE_TOP
);
852 aBox
.SetLine(&aLine
, BOX_LINE_RIGHT
);
853 aBox
.SetLine(&aLine
, BOX_LINE_BOTTOM
);
855 Color
aWhite(COL_WHITE
);
856 Color
aBlue(COL_BLUE
);
857 SvxColorItem
aWhiteText( aWhite
, ATTR_FONT_COLOR
);
858 SvxColorItem
aBlackText( aBlack
, ATTR_FONT_COLOR
);
859 SvxBrushItem
aBlueBack( aBlue
, ATTR_BACKGROUND
);
860 SvxBrushItem
aWhiteBack( aWhite
, ATTR_BACKGROUND
);
861 SvxBrushItem
aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND
);
862 SvxBrushItem
aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND
);
864 for (sal_uInt16 i
=0; i
<16; i
++)
866 pData
->PutItem( i
, aBox
);
867 pData
->PutItem( i
, aFontItem
);
868 pData
->PutItem( i
, aCJKFontItem
);
869 pData
->PutItem( i
, aCTLFontItem
);
870 aHeight
.SetWhich( ATTR_FONT_HEIGHT
);
871 pData
->PutItem( i
, aHeight
);
872 aHeight
.SetWhich( ATTR_CJK_FONT_HEIGHT
);
873 pData
->PutItem( i
, aHeight
);
874 aHeight
.SetWhich( ATTR_CTL_FONT_HEIGHT
);
875 pData
->PutItem( i
, aHeight
);
876 if (i
<4) // top: white on blue
878 pData
->PutItem( i
, aWhiteText
);
879 pData
->PutItem( i
, aBlueBack
);
881 else if ( i
%4 == 0 ) // left: white on gray70
883 pData
->PutItem( i
, aWhiteText
);
884 pData
->PutItem( i
, aGray70Back
);
886 else if ( i
%4 == 3 || i
>= 12 ) // right and bottom: black on gray20
888 pData
->PutItem( i
, aBlackText
);
889 pData
->PutItem( i
, aGray20Back
);
891 else // center: black on white
893 pData
->PutItem( i
, aBlackText
);
894 pData
->PutItem( i
, aWhiteBack
);
901 ScAutoFormat::ScAutoFormat(const ScAutoFormat
& r
) :
903 mbSaveLater(false) {}
905 ScAutoFormat::~ScAutoFormat()
907 // When modified via StarOne then only the SaveLater flag is set and no saving is done.
908 // If the flag is set then save now.
914 void ScAutoFormat::SetSaveLater( bool bSet
)
919 const ScAutoFormatData
* ScAutoFormat::findByIndex(size_t nIndex
) const
921 if (nIndex
>= maData
.size())
924 MapType::const_iterator it
= maData
.begin();
925 std::advance(it
, nIndex
);
929 ScAutoFormatData
* ScAutoFormat::findByIndex(size_t nIndex
)
931 if (nIndex
>= maData
.size())
934 MapType::iterator it
= maData
.begin();
935 std::advance(it
, nIndex
);
939 ScAutoFormat::const_iterator
ScAutoFormat::find(const ScAutoFormatData
* pData
) const
941 MapType::const_iterator it
= maData
.begin(), itEnd
= maData
.end();
942 for (; it
!= itEnd
; ++it
)
944 if (it
->second
== pData
)
950 ScAutoFormat::iterator
ScAutoFormat::find(const ScAutoFormatData
* pData
)
952 MapType::iterator it
= maData
.begin(), itEnd
= maData
.end();
953 for (; it
!= itEnd
; ++it
)
955 if (it
->second
== pData
)
961 ScAutoFormat::const_iterator
ScAutoFormat::find(const OUString
& rName
) const
963 return maData
.find(rName
);
966 ScAutoFormat::iterator
ScAutoFormat::find(const OUString
& rName
)
968 return maData
.find(rName
);
971 bool ScAutoFormat::insert(ScAutoFormatData
* pNew
)
973 OUString aName
= pNew
->GetName();
974 return maData
.insert(aName
, pNew
).second
;
977 void ScAutoFormat::erase(const iterator
& it
)
982 size_t ScAutoFormat::size() const
984 return maData
.size();
987 ScAutoFormat::const_iterator
ScAutoFormat::begin() const
989 return maData
.begin();
992 ScAutoFormat::const_iterator
ScAutoFormat::end() const
997 ScAutoFormat::iterator
ScAutoFormat::begin()
999 return maData
.begin();
1002 ScAutoFormat::iterator
ScAutoFormat::end()
1004 return maData
.end();
1007 bool ScAutoFormat::Load()
1010 SvtPathOptions aPathOpt
;
1011 aURL
.SetSmartURL( aPathOpt
.GetUserConfigPath() );
1012 aURL
.setFinalSlash();
1013 aURL
.Append( OUString( sAutoTblFmtName
) );
1015 SfxMedium
aMedium( aURL
.GetMainURL(INetURLObject::NO_DECODE
), STREAM_READ
);
1016 SvStream
* pStream
= aMedium
.GetInStream();
1017 bool bRet
= (pStream
&& pStream
->GetError() == 0);
1020 SvStream
& rStream
= *pStream
;
1021 // Attention: A common header has to be read
1022 sal_uInt16 nVal
= 0;
1024 bRet
= 0 == rStream
.GetError();
1028 if( nVal
== AUTOFORMAT_ID_358
||
1029 (AUTOFORMAT_ID_504
<= nVal
&& nVal
<= AUTOFORMAT_ID
) )
1031 sal_uInt16 nFileVers
= SOFFICE_FILEFORMAT_40
;
1032 sal_uInt8 nChrSet
, nCnt
;
1033 long nPos
= rStream
.Tell();
1034 rStream
>> nCnt
>> nChrSet
;
1035 if( rStream
.Tell() != sal_uLong(nPos
+ nCnt
) )
1037 OSL_FAIL( "header contains more/newer data" );
1038 rStream
.Seek( nPos
+ nCnt
);
1040 rStream
.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet
) );
1041 rStream
.SetVersion( nFileVers
);
1044 if( nVal
== AUTOFORMAT_ID_358
|| nVal
== AUTOFORMAT_ID_X
||
1045 (AUTOFORMAT_ID_504
<= nVal
&& nVal
<= AUTOFORMAT_ID
) )
1047 m_aVersions
.Load( rStream
, nVal
); // Item-Versionen
1049 ScAutoFormatData
* pData
;
1050 sal_uInt16 nAnz
= 0;
1052 bRet
= (rStream
.GetError() == 0);
1053 for (sal_uInt16 i
=0; bRet
&& (i
< nAnz
); i
++)
1055 pData
= new ScAutoFormatData();
1056 bRet
= pData
->Load(rStream
, m_aVersions
);
1064 mbSaveLater
= false;
1068 bool ScAutoFormat::Save()
1071 SvtPathOptions aPathOpt
;
1072 aURL
.SetSmartURL( aPathOpt
.GetUserConfigPath() );
1073 aURL
.setFinalSlash();
1074 aURL
.Append( OUString( sAutoTblFmtName
) );
1076 SfxMedium
aMedium( aURL
.GetMainURL(INetURLObject::NO_DECODE
), STREAM_WRITE
);
1077 SvStream
* pStream
= aMedium
.GetOutStream();
1078 bool bRet
= (pStream
&& pStream
->GetError() == 0);
1081 const sal_uInt16 fileVersion
= SOFFICE_FILEFORMAT_50
;
1082 SvStream
& rStream
= *pStream
;
1083 rStream
.SetVersion( fileVersion
);
1085 // Attention: A common header has to be saved
1086 sal_uInt16 nVal
= AUTOFORMAT_ID
;
1088 << (sal_uInt8
)2 // Number of chars of the header including this
1089 << (sal_uInt8
)::GetSOStoreTextEncoding(
1090 osl_getThreadTextEncoding() );
1091 m_aVersions
.Write(rStream
, fileVersion
);
1093 bRet
&= (rStream
.GetError() == 0);
1095 rStream
<< (sal_uInt16
)(maData
.size() - 1);
1096 bRet
&= (rStream
.GetError() == 0);
1097 MapType::iterator it
= maData
.begin(), itEnd
= maData
.end();
1100 for (++it
; bRet
&& it
!= itEnd
; ++it
) // Skip the first item.
1102 bRet
&= it
->second
->Save(rStream
, fileVersion
);
1110 mbSaveLater
= false;
1114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */