xref: /AOO41X/main/sc/source/core/tool/autoform.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 #define READ_OLDVERS
34 
35 #include "autoform.hxx"
36 
37 #include <sfx2/app.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <unotools/pathoptions.hxx>
40 #include <svl/itemset.hxx>
41 #include <tools/shl.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/outdev.hxx>
44 #include <svx/dialmgr.hxx>
45 #include <svx/dialogs.hrc>
46 #include <editeng/langitem.hxx>
47 #include <tools/urlobj.hxx>
48 #include <unotools/transliterationwrapper.hxx>
49 #include <tools/tenccvt.hxx>
50 
51 #include "globstr.hrc"
52 #include "document.hxx"
53 
54 //------------------------------------------------------------------------
55 
56 const sal_Char *linker_dummy = "";
57 
58 //	Standard-Name ist jetzt STR_STYLENAME_STANDARD (wie Vorlagen)
59 //static const sal_Char __FAR_DATA cStandardName[] = "Standard";
60 
61 static const sal_Char __FAR_DATA sAutoTblFmtName[] = "autotbl.fmt";
62 
63 // bis SO5PF
64 const sal_uInt16 AUTOFORMAT_ID_X		= 9501;
65 const sal_uInt16 AUTOFORMAT_ID_358		= 9601;
66 const sal_uInt16 AUTOFORMAT_DATA_ID_X	= 9502;
67 
68 // ab SO5
69 //! in nachfolgenden Versionen muss der Betrag dieser IDs groesser sein
70 const sal_uInt16 AUTOFORMAT_ID_504		= 9801;
71 const sal_uInt16 AUTOFORMAT_DATA_ID_504	= 9802;
72 
73 const sal_uInt16 AUTOFORMAT_ID_552		= 9901;
74 const sal_uInt16 AUTOFORMAT_DATA_ID_552	= 9902;
75 
76 // --- from 641 on: CJK and CTL font settings
77 const sal_uInt16 AUTOFORMAT_ID_641      = 10001;
78 const sal_uInt16 AUTOFORMAT_DATA_ID_641 = 10002;
79 
80 // --- from 680/dr14 on: diagonal frame lines
81 const sal_uInt16 AUTOFORMAT_ID_680DR14      = 10011;
82 const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14 = 10012;
83 
84 // --- from 680/dr25 on: #21549# store strings as UTF-8
85 const sal_uInt16 AUTOFORMAT_ID_680DR25      = 10021;
86 const sal_uInt16 AUTOFORMAT_DATA_ID_680DR25 = 10022;
87 
88 // --- from DEV300/overline2 on: #5991# overline support
89 const sal_uInt16 AUTOFORMAT_ID_300OVRLN      = 10031;
90 const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN = 10032;
91 
92 // aktuelle Version
93 const sal_uInt16 AUTOFORMAT_ID          = AUTOFORMAT_ID_300OVRLN;
94 const sal_uInt16 AUTOFORMAT_DATA_ID     = AUTOFORMAT_DATA_ID_300OVRLN;
95 
96 
97 #ifdef READ_OLDVERS
98 const sal_uInt16 AUTOFORMAT_OLD_ID_OLD	= 4201;
99 const sal_uInt16 AUTOFORMAT_OLD_DATA_ID	= 4202;
100 const sal_uInt16 AUTOFORMAT_OLD_ID_NEW 	= 4203;
101 #endif
102 
103 
104 //	Struct mit Versionsnummern der Items
105 
106 struct ScAfVersions
107 {
108 public:
109 	sal_uInt16 nFontVersion;
110 	sal_uInt16 nFontHeightVersion;
111 	sal_uInt16 nWeightVersion;
112 	sal_uInt16 nPostureVersion;
113 	sal_uInt16 nUnderlineVersion;
114 	sal_uInt16 nOverlineVersion;
115 	sal_uInt16 nCrossedOutVersion;
116 	sal_uInt16 nContourVersion;
117 	sal_uInt16 nShadowedVersion;
118 	sal_uInt16 nColorVersion;
119 	sal_uInt16 nBoxVersion;
120     sal_uInt16 nLineVersion;
121 	sal_uInt16 nBrushVersion;
122 
123 	sal_uInt16 nAdjustVersion;
124 
125 	sal_uInt16 nHorJustifyVersion;
126 	sal_uInt16 nVerJustifyVersion;
127 	sal_uInt16 nOrientationVersion;
128 	sal_uInt16 nMarginVersion;
129 	sal_uInt16 nBoolVersion;
130 	sal_uInt16 nInt32Version;
131 	sal_uInt16 nRotateModeVersion;
132 
133 	sal_uInt16 nNumFmtVersion;
134 
135 	ScAfVersions();
136 	void Load( SvStream& rStream, sal_uInt16 nVer );
137 	static void Write(SvStream& rStream);
138 };
139 
140 ScAfVersions::ScAfVersions() :
141 	nFontVersion(0),
142 	nFontHeightVersion(0),
143 	nWeightVersion(0),
144 	nPostureVersion(0),
145 	nUnderlineVersion(0),
146 	nOverlineVersion(0),
147 	nCrossedOutVersion(0),
148 	nContourVersion(0),
149 	nShadowedVersion(0),
150 	nColorVersion(0),
151 	nBoxVersion(0),
152     nLineVersion(0),
153 	nBrushVersion(0),
154 	nAdjustVersion(0),
155 	nHorJustifyVersion(0),
156 	nVerJustifyVersion(0),
157 	nOrientationVersion(0),
158 	nMarginVersion(0),
159 	nBoolVersion(0),
160 	nInt32Version(0),
161 	nRotateModeVersion(0),
162 	nNumFmtVersion(0)
163 {
164 }
165 
166 void ScAfVersions::Load( SvStream& rStream, sal_uInt16 nVer )
167 {
168 	rStream >> nFontVersion;
169 	rStream >> nFontHeightVersion;
170 	rStream >> nWeightVersion;
171 	rStream >> nPostureVersion;
172 	rStream >> nUnderlineVersion;
173     if ( nVer >= AUTOFORMAT_ID_300OVRLN )
174 		rStream >> nOverlineVersion;
175 	rStream >> nCrossedOutVersion;
176 	rStream >> nContourVersion;
177 	rStream >> nShadowedVersion;
178 	rStream >> nColorVersion;
179 	rStream >> nBoxVersion;
180     if ( nVer >= AUTOFORMAT_ID_680DR14 )
181         rStream >> nLineVersion;
182 	rStream >> nBrushVersion;
183 	rStream >> nAdjustVersion;
184 	rStream >> nHorJustifyVersion;
185 	rStream >> nVerJustifyVersion;
186 	rStream >> nOrientationVersion;
187 	rStream >> nMarginVersion;
188 	rStream >> nBoolVersion;
189 	if ( nVer >= AUTOFORMAT_ID_504 )
190 	{
191 		rStream >> nInt32Version;
192 		rStream >> nRotateModeVersion;
193 	}
194 	rStream >> nNumFmtVersion;
195 }
196 
197 void ScAfVersions::Write(SvStream& rStream)
198 {
199     rStream << SvxFontItem(ATTR_FONT).GetVersion(SOFFICE_FILEFORMAT_40);
200     rStream << SvxFontHeightItem(240, 100, ATTR_FONT_HEIGHT).GetVersion(SOFFICE_FILEFORMAT_40);
201     rStream << SvxWeightItem(WEIGHT_NORMAL, ATTR_FONT_WEIGHT).GetVersion(SOFFICE_FILEFORMAT_40);
202     rStream << SvxPostureItem(ITALIC_NONE, ATTR_FONT_POSTURE).GetVersion(SOFFICE_FILEFORMAT_40);
203     rStream << SvxUnderlineItem(UNDERLINE_NONE, ATTR_FONT_UNDERLINE).GetVersion(SOFFICE_FILEFORMAT_40);
204     rStream << SvxOverlineItem(UNDERLINE_NONE, ATTR_FONT_OVERLINE).GetVersion(SOFFICE_FILEFORMAT_40);
205     rStream << SvxCrossedOutItem(STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT).GetVersion(SOFFICE_FILEFORMAT_40);
206     rStream << SvxContourItem(sal_False, ATTR_FONT_CONTOUR).GetVersion(SOFFICE_FILEFORMAT_40);
207     rStream << SvxShadowedItem(sal_False, ATTR_FONT_SHADOWED).GetVersion(SOFFICE_FILEFORMAT_40);
208     rStream << SvxColorItem(ATTR_FONT_COLOR).GetVersion(SOFFICE_FILEFORMAT_40);
209     rStream << SvxBoxItem(ATTR_BORDER).GetVersion(SOFFICE_FILEFORMAT_40);
210     rStream << SvxLineItem(SID_FRAME_LINESTYLE).GetVersion(SOFFICE_FILEFORMAT_40);
211     rStream << SvxBrushItem(ATTR_BACKGROUND).GetVersion(SOFFICE_FILEFORMAT_40);
212 
213     rStream << SvxAdjustItem(SVX_ADJUST_LEFT, 0).GetVersion(SOFFICE_FILEFORMAT_40);
214 
215     rStream << SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY).GetVersion(SOFFICE_FILEFORMAT_40);
216     rStream << SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY).GetVersion(SOFFICE_FILEFORMAT_40);
217     rStream << SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0).GetVersion(SOFFICE_FILEFORMAT_40);
218     rStream << SvxMarginItem(ATTR_MARGIN).GetVersion(SOFFICE_FILEFORMAT_40);
219 	rStream << SfxBoolItem(ATTR_LINEBREAK).GetVersion(SOFFICE_FILEFORMAT_40);
220 	rStream << SfxInt32Item(ATTR_ROTATE_VALUE).GetVersion(SOFFICE_FILEFORMAT_40);
221 	rStream << SvxRotateModeItem(SVX_ROTATE_MODE_STANDARD,0).GetVersion(SOFFICE_FILEFORMAT_40);
222 
223 	rStream << (sal_uInt16)0;		// Num-Format
224 }
225 
226 //	---------------------------------------------------------------------------
227 
228 ScAutoFormatDataField::ScAutoFormatDataField() :
229     aFont( ATTR_FONT ),
230     aHeight( 240, 100, ATTR_FONT_HEIGHT ),
231     aWeight( WEIGHT_NORMAL, ATTR_FONT_WEIGHT ),
232     aPosture( ITALIC_NONE, ATTR_FONT_POSTURE ),
233 
234     aCJKFont( ATTR_CJK_FONT ),
235     aCJKHeight( 240, 100, ATTR_CJK_FONT_HEIGHT ),
236     aCJKWeight( WEIGHT_NORMAL, ATTR_CJK_FONT_WEIGHT ),
237     aCJKPosture( ITALIC_NONE, ATTR_CJK_FONT_POSTURE ),
238 
239     aCTLFont( ATTR_CTL_FONT ),
240     aCTLHeight( 240, 100, ATTR_CTL_FONT_HEIGHT ),
241     aCTLWeight( WEIGHT_NORMAL, ATTR_CTL_FONT_WEIGHT ),
242     aCTLPosture( ITALIC_NONE, ATTR_CTL_FONT_POSTURE ),
243 
244     aUnderline( UNDERLINE_NONE,ATTR_FONT_UNDERLINE ),
245     aOverline( UNDERLINE_NONE,ATTR_FONT_OVERLINE ),
246     aCrossedOut( STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ),
247     aContour( sal_False, ATTR_FONT_CONTOUR ),
248     aShadowed( sal_False, ATTR_FONT_SHADOWED ),
249     aColor( ATTR_FONT_COLOR ),
250     aBox( ATTR_BORDER ),
251     aTLBR( ATTR_BORDER_TLBR ),
252     aBLTR( ATTR_BORDER_BLTR ),
253     aBackground( ATTR_BACKGROUND ),
254     aAdjust( SVX_ADJUST_LEFT, 0 ),
255     aHorJustify( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ),
256     aVerJustify( SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY ),
257     aMargin( ATTR_MARGIN ),
258     aLinebreak( ATTR_LINEBREAK ),
259     aRotateAngle( ATTR_ROTATE_VALUE ),
260     aRotateMode( SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE )
261 {
262 }
263 
264 ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField& rCopy ) :
265     aFont( rCopy.aFont ),
266     aHeight( rCopy.aHeight ),
267     aWeight( rCopy.aWeight ),
268     aPosture( rCopy.aPosture ),
269     aCJKFont( rCopy.aCJKFont ),
270     aCJKHeight( rCopy.aCJKHeight ),
271     aCJKWeight( rCopy.aCJKWeight ),
272     aCJKPosture( rCopy.aCJKPosture ),
273     aCTLFont( rCopy.aCTLFont ),
274     aCTLHeight( rCopy.aCTLHeight ),
275     aCTLWeight( rCopy.aCTLWeight ),
276     aCTLPosture( rCopy.aCTLPosture ),
277     aUnderline( rCopy.aUnderline ),
278     aOverline( rCopy.aOverline ),
279     aCrossedOut( rCopy.aCrossedOut ),
280     aContour( rCopy.aContour ),
281     aShadowed( rCopy.aShadowed ),
282     aColor( rCopy.aColor ),
283     aBox( rCopy.aBox ),
284     aTLBR( rCopy.aTLBR ),
285     aBLTR( rCopy.aBLTR ),
286     aBackground( rCopy.aBackground ),
287     aAdjust( rCopy.aAdjust ),
288     aHorJustify( rCopy.aHorJustify ),
289     aVerJustify( rCopy.aVerJustify ),
290     aStacked( rCopy.aStacked ),
291     aMargin( rCopy.aMargin ),
292     aLinebreak( rCopy.aLinebreak ),
293     aRotateAngle( rCopy.aRotateAngle ),
294     aRotateMode( rCopy.aRotateMode ),
295     aNumFormat( rCopy.aNumFormat )
296 {
297 }
298 
299 ScAutoFormatDataField::~ScAutoFormatDataField()
300 {
301 }
302 
303 void ScAutoFormatDataField::SetAdjust( const SvxAdjustItem& rAdjust )
304 {
305     aAdjust.SetAdjust( rAdjust.GetAdjust() );
306     aAdjust.SetOneWord( rAdjust.GetOneWord() );
307     aAdjust.SetLastBlock( rAdjust.GetLastBlock() );
308 }
309 
310 #define READ( aItem, ItemType, nVers )      \
311     pNew = aItem.Create( rStream, nVers );  \
312     aItem = *(ItemType*)pNew;               \
313 	delete pNew;
314 
315 sal_Bool ScAutoFormatDataField::Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer )
316 {
317     SfxPoolItem* pNew;
318     SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0 );
319 
320     READ( aFont,        SvxFontItem,        rVersions.nFontVersion)
321     READ( aHeight,      SvxFontHeightItem,  rVersions.nFontHeightVersion)
322     READ( aWeight,      SvxWeightItem,      rVersions.nWeightVersion)
323     READ( aPosture,     SvxPostureItem,     rVersions.nPostureVersion)
324     // --- from 641 on: CJK and CTL font settings
325     if( AUTOFORMAT_DATA_ID_641 <= nVer )
326     {
327         READ( aCJKFont,     SvxFontItem,        rVersions.nFontVersion)
328         READ( aCJKHeight,   SvxFontHeightItem,  rVersions.nFontHeightVersion)
329         READ( aCJKWeight,   SvxWeightItem,      rVersions.nWeightVersion)
330         READ( aCJKPosture,  SvxPostureItem,     rVersions.nPostureVersion)
331         READ( aCTLFont,     SvxFontItem,        rVersions.nFontVersion)
332         READ( aCTLHeight,   SvxFontHeightItem,  rVersions.nFontHeightVersion)
333         READ( aCTLWeight,   SvxWeightItem,      rVersions.nWeightVersion)
334         READ( aCTLPosture,  SvxPostureItem,     rVersions.nPostureVersion)
335     }
336     READ( aUnderline,   SvxUnderlineItem,   rVersions.nUnderlineVersion)
337     if ( nVer >= AUTOFORMAT_DATA_ID_300OVRLN )
338     {
339 		READ( aOverline,    SvxOverlineItem,    rVersions.nOverlineVersion)
340     }
341     READ( aCrossedOut,  SvxCrossedOutItem,  rVersions.nCrossedOutVersion)
342     READ( aContour,     SvxContourItem,     rVersions.nContourVersion)
343     READ( aShadowed,    SvxShadowedItem,    rVersions.nShadowedVersion)
344     READ( aColor,       SvxColorItem,       rVersions.nColorVersion)
345     READ( aBox,         SvxBoxItem,         rVersions.nBoxVersion)
346 
347     // --- from 680/dr14 on: diagonal frame lines
348     if( AUTOFORMAT_DATA_ID_680DR14 <= nVer )
349     {
350         READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
351         READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
352     }
353 
354     READ( aBackground,  SvxBrushItem,       rVersions.nBrushVersion)
355 
356     pNew = aAdjust.Create( rStream, rVersions.nAdjustVersion );
357     SetAdjust( *(SvxAdjustItem*)pNew );
358     delete pNew;
359 
360     READ( aHorJustify,   SvxHorJustifyItem,  rVersions.nHorJustifyVersion)
361     READ( aVerJustify,   SvxVerJustifyItem,  rVersions.nVerJustifyVersion)
362     READ( aOrientation,  SvxOrientationItem, rVersions.nOrientationVersion)
363     READ( aMargin,       SvxMarginItem,      rVersions.nMarginVersion)
364 
365     pNew = aLinebreak.Create( rStream, rVersions.nBoolVersion );
366     SetLinebreak( *(SfxBoolItem*)pNew );
367     delete pNew;
368 
369     if ( nVer >= AUTOFORMAT_DATA_ID_504 )
370     {
371         pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
372         SetRotateAngle( *(SfxInt32Item*)pNew );
373         delete pNew;
374         pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
375         SetRotateMode( *(SvxRotateModeItem*)pNew );
376         delete pNew;
377     }
378 
379     if( 0 == rVersions.nNumFmtVersion )
380     {
381         // --- from 680/dr25 on: #21549# store strings as UTF-8
382         CharSet eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
383         aNumFormat.Load( rStream, eCharSet );
384     }
385 
386     //  adjust charset in font
387     CharSet eSysSet = gsl_getSystemTextEncoding();
388     CharSet eSrcSet = rStream.GetStreamCharSet();
389     if( eSrcSet != eSysSet && aFont.GetCharSet() == eSrcSet )
390         aFont.SetCharSet(eSysSet);
391 
392     aStacked.SetValue( aOrientation.IsStacked() );
393     aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
394 
395     return (rStream.GetError() == 0);
396 }
397 
398 #ifdef READ_OLDVERS
399 sal_Bool ScAutoFormatDataField::LoadOld( SvStream& rStream, const ScAfVersions& rVersions )
400 {
401     SfxPoolItem* pNew;
402     SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0 );
403 
404     aNumFormat.Load(rStream, rStream.GetStreamCharSet());
405 
406     READ( aFont,        SvxFontItem,        rVersions.nFontVersion)
407     READ( aHeight,      SvxFontHeightItem,  rVersions.nFontHeightVersion)
408     READ( aWeight,      SvxWeightItem,      rVersions.nWeightVersion)
409     READ( aPosture,     SvxPostureItem,     rVersions.nPostureVersion)
410     READ( aUnderline,   SvxUnderlineItem,   rVersions.nUnderlineVersion)
411     READ( aCrossedOut,  SvxCrossedOutItem,  rVersions.nCrossedOutVersion)
412     READ( aContour,     SvxContourItem,     rVersions.nContourVersion)
413     READ( aShadowed,    SvxShadowedItem,    rVersions.nShadowedVersion)
414     READ( aColor,       SvxColorItem,       rVersions.nColorVersion)
415     READ( aHorJustify,  SvxHorJustifyItem,  rVersions.nHorJustifyVersion)
416     READ( aVerJustify,  SvxVerJustifyItem,  rVersions.nVerJustifyVersion)
417     READ( aOrientation, SvxOrientationItem, rVersions.nOrientationVersion)
418     pNew = aLinebreak.Create( rStream, rVersions.nBoolVersion );
419     SetLinebreak( *(SfxBoolItem*)pNew );
420     delete pNew;
421     READ( aMargin,      SvxMarginItem,      rVersions.nMarginVersion)
422     READ( aBox,         SvxBoxItem,         rVersions.nBoxVersion)
423     READ( aBackground,  SvxBrushItem,       rVersions.nBrushVersion)
424 
425     aStacked.SetValue( aOrientation.IsStacked() );
426     aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
427 
428     return (rStream.GetError() == 0);
429 }
430 #endif
431 
432 sal_Bool ScAutoFormatDataField::Save( SvStream& rStream )
433 {
434     SvxOrientationItem aOrientation( aRotateAngle.GetValue(), aStacked.GetValue(), 0 );
435 
436     aFont.Store         ( rStream, aFont.GetVersion( SOFFICE_FILEFORMAT_40 ) );
437     aHeight.Store       ( rStream, aHeight.GetVersion( SOFFICE_FILEFORMAT_40 ) );
438     aWeight.Store       ( rStream, aWeight.GetVersion( SOFFICE_FILEFORMAT_40 ) );
439     aPosture.Store      ( rStream, aPosture.GetVersion( SOFFICE_FILEFORMAT_40 ) );
440     // --- from 641 on: CJK and CTL font settings
441     aCJKFont.Store      ( rStream, aCJKFont.GetVersion( SOFFICE_FILEFORMAT_40 ) );
442     aCJKHeight.Store    ( rStream, aCJKHeight.GetVersion( SOFFICE_FILEFORMAT_40 ) );
443     aCJKWeight.Store    ( rStream, aCJKWeight.GetVersion( SOFFICE_FILEFORMAT_40 ) );
444     aCJKPosture.Store   ( rStream, aCJKPosture.GetVersion( SOFFICE_FILEFORMAT_40 ) );
445     aCTLFont.Store      ( rStream, aCTLFont.GetVersion( SOFFICE_FILEFORMAT_40 ) );
446     aCTLHeight.Store    ( rStream, aCTLHeight.GetVersion( SOFFICE_FILEFORMAT_40 ) );
447     aCTLWeight.Store    ( rStream, aCTLWeight.GetVersion( SOFFICE_FILEFORMAT_40 ) );
448     aCTLPosture.Store   ( rStream, aCTLPosture.GetVersion( SOFFICE_FILEFORMAT_40 ) );
449 
450     aUnderline.Store    ( rStream, aUnderline.GetVersion( SOFFICE_FILEFORMAT_40 ) );
451     // --- from DEV300/overline2 on: overline support
452     aOverline.Store     ( rStream, aOverline.GetVersion( SOFFICE_FILEFORMAT_40 ) );
453     aCrossedOut.Store   ( rStream, aCrossedOut.GetVersion( SOFFICE_FILEFORMAT_40 ) );
454     aContour.Store      ( rStream, aContour.GetVersion( SOFFICE_FILEFORMAT_40 ) );
455     aShadowed.Store     ( rStream, aShadowed.GetVersion( SOFFICE_FILEFORMAT_40 ) );
456     aColor.Store        ( rStream, aColor.GetVersion( SOFFICE_FILEFORMAT_40 ) );
457     aBox.Store          ( rStream, aBox.GetVersion( SOFFICE_FILEFORMAT_40 ) );
458 
459     // --- from 680/dr14 on: diagonal frame lines
460     aTLBR.Store         ( rStream, aTLBR.GetVersion( SOFFICE_FILEFORMAT_40 ) );
461     aBLTR.Store         ( rStream, aBLTR.GetVersion( SOFFICE_FILEFORMAT_40 ) );
462 
463     aBackground.Store   ( rStream, aBackground.GetVersion( SOFFICE_FILEFORMAT_40 ) );
464 
465     aAdjust.Store       ( rStream, aAdjust.GetVersion( SOFFICE_FILEFORMAT_40 ) );
466 
467     aHorJustify.Store   ( rStream, aHorJustify.GetVersion( SOFFICE_FILEFORMAT_40 ) );
468     aVerJustify.Store   ( rStream, aVerJustify.GetVersion( SOFFICE_FILEFORMAT_40 ) );
469     aOrientation.Store  ( rStream, aOrientation.GetVersion( SOFFICE_FILEFORMAT_40 ) );
470     aMargin.Store       ( rStream, aMargin.GetVersion( SOFFICE_FILEFORMAT_40 ) );
471     aLinebreak.Store    ( rStream, aLinebreak.GetVersion( SOFFICE_FILEFORMAT_40 ) );
472     // Rotation ab SO5
473     aRotateAngle.Store  ( rStream, aRotateAngle.GetVersion( SOFFICE_FILEFORMAT_40 ) );
474     aRotateMode.Store   ( rStream, aRotateMode.GetVersion( SOFFICE_FILEFORMAT_40 ) );
475 
476     // --- from 680/dr25 on: #21549# store strings as UTF-8
477     aNumFormat.Save( rStream, RTL_TEXTENCODING_UTF8 );
478 
479     return (rStream.GetError() == 0);
480 }
481 
482 
483 //	---------------------------------------------------------------------------
484 
485 ScAutoFormatData::ScAutoFormatData()
486 {
487 	nStrResId = USHRT_MAX;
488 
489 	bIncludeValueFormat =
490 	bIncludeFont =
491 	bIncludeJustify =
492 	bIncludeFrame =
493 	bIncludeBackground =
494 	bIncludeWidthHeight = sal_True;
495 
496     ppDataField = new ScAutoFormatDataField*[ 16 ];
497     for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
498         ppDataField[ nIndex ] = new ScAutoFormatDataField;
499 }
500 
501 ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData& rData ) :
502         ScDataObject(),
503 		aName( rData.aName ),
504 		nStrResId( rData.nStrResId ),
505 		bIncludeFont( rData.bIncludeFont ),
506 		bIncludeJustify( rData.bIncludeJustify ),
507 		bIncludeFrame( rData.bIncludeFrame ),
508 		bIncludeBackground( rData.bIncludeBackground ),
509 		bIncludeValueFormat( rData.bIncludeValueFormat ),
510 		bIncludeWidthHeight( rData.bIncludeWidthHeight )
511 {
512     ppDataField = new ScAutoFormatDataField*[ 16 ];
513     for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
514         ppDataField[ nIndex ] = new ScAutoFormatDataField( rData.GetField( nIndex ) );
515 }
516 
517 ScAutoFormatData::~ScAutoFormatData()
518 {
519     for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
520         delete ppDataField[ nIndex ];
521     delete[] ppDataField;
522 }
523 
524 ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex )
525 {
526     DBG_ASSERT( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
527     DBG_ASSERT( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
528     return *ppDataField[ nIndex ];
529 }
530 
531 const ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex ) const
532 {
533     DBG_ASSERT( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
534     DBG_ASSERT( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
535     return *ppDataField[ nIndex ];
536 }
537 
538 const SfxPoolItem* ScAutoFormatData::GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const
539 {
540     const ScAutoFormatDataField& rField = GetField( nIndex );
541     switch( nWhich )
542 	{
543         case ATTR_FONT:             return &rField.GetFont();
544         case ATTR_FONT_HEIGHT:      return &rField.GetHeight();
545         case ATTR_FONT_WEIGHT:      return &rField.GetWeight();
546         case ATTR_FONT_POSTURE:     return &rField.GetPosture();
547         case ATTR_CJK_FONT:         return &rField.GetCJKFont();
548         case ATTR_CJK_FONT_HEIGHT:  return &rField.GetCJKHeight();
549         case ATTR_CJK_FONT_WEIGHT:  return &rField.GetCJKWeight();
550         case ATTR_CJK_FONT_POSTURE: return &rField.GetCJKPosture();
551         case ATTR_CTL_FONT:         return &rField.GetCTLFont();
552         case ATTR_CTL_FONT_HEIGHT:  return &rField.GetCTLHeight();
553         case ATTR_CTL_FONT_WEIGHT:  return &rField.GetCTLWeight();
554         case ATTR_CTL_FONT_POSTURE: return &rField.GetCTLPosture();
555         case ATTR_FONT_UNDERLINE:   return &rField.GetUnderline();
556         case ATTR_FONT_OVERLINE:    return &rField.GetOverline();
557         case ATTR_FONT_CROSSEDOUT:  return &rField.GetCrossedOut();
558         case ATTR_FONT_CONTOUR:     return &rField.GetContour();
559         case ATTR_FONT_SHADOWED:    return &rField.GetShadowed();
560         case ATTR_FONT_COLOR:       return &rField.GetColor();
561         case ATTR_BORDER:           return &rField.GetBox();
562         case ATTR_BORDER_TLBR:      return &rField.GetTLBR();
563         case ATTR_BORDER_BLTR:      return &rField.GetBLTR();
564         case ATTR_BACKGROUND:       return &rField.GetBackground();
565         case ATTR_HOR_JUSTIFY:      return &rField.GetHorJustify();
566         case ATTR_VER_JUSTIFY:      return &rField.GetVerJustify();
567         case ATTR_STACKED:          return &rField.GetStacked();
568         case ATTR_MARGIN:           return &rField.GetMargin();
569         case ATTR_LINEBREAK:        return &rField.GetLinebreak();
570         case ATTR_ROTATE_VALUE:     return &rField.GetRotateAngle();
571         case ATTR_ROTATE_MODE:      return &rField.GetRotateMode();
572 	}
573 	return NULL;
574 }
575 
576 void ScAutoFormatData::PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem )
577 {
578     ScAutoFormatDataField& rField = GetField( nIndex );
579     switch( rItem.Which() )
580 	{
581         case ATTR_FONT:             rField.SetFont( (const SvxFontItem&)rItem );              break;
582         case ATTR_FONT_HEIGHT:      rField.SetHeight( (const SvxFontHeightItem&)rItem );      break;
583         case ATTR_FONT_WEIGHT:      rField.SetWeight( (const SvxWeightItem&)rItem );          break;
584         case ATTR_FONT_POSTURE:     rField.SetPosture( (const SvxPostureItem&)rItem );        break;
585         case ATTR_CJK_FONT:         rField.SetCJKFont( (const SvxFontItem&)rItem );           break;
586         case ATTR_CJK_FONT_HEIGHT:  rField.SetCJKHeight( (const SvxFontHeightItem&)rItem );   break;
587         case ATTR_CJK_FONT_WEIGHT:  rField.SetCJKWeight( (const SvxWeightItem&)rItem );       break;
588         case ATTR_CJK_FONT_POSTURE: rField.SetCJKPosture( (const SvxPostureItem&)rItem );     break;
589         case ATTR_CTL_FONT:         rField.SetCTLFont( (const SvxFontItem&)rItem );           break;
590         case ATTR_CTL_FONT_HEIGHT:  rField.SetCTLHeight( (const SvxFontHeightItem&)rItem );   break;
591         case ATTR_CTL_FONT_WEIGHT:  rField.SetCTLWeight( (const SvxWeightItem&)rItem );       break;
592         case ATTR_CTL_FONT_POSTURE: rField.SetCTLPosture( (const SvxPostureItem&)rItem );     break;
593         case ATTR_FONT_UNDERLINE:   rField.SetUnderline( (const SvxUnderlineItem&)rItem );    break;
594         case ATTR_FONT_OVERLINE:    rField.SetOverline( (const SvxOverlineItem&)rItem );      break;
595         case ATTR_FONT_CROSSEDOUT:  rField.SetCrossedOut( (const SvxCrossedOutItem&)rItem );  break;
596         case ATTR_FONT_CONTOUR:     rField.SetContour( (const SvxContourItem&)rItem );        break;
597         case ATTR_FONT_SHADOWED:    rField.SetShadowed( (const SvxShadowedItem&)rItem );      break;
598         case ATTR_FONT_COLOR:       rField.SetColor( (const SvxColorItem&)rItem );            break;
599         case ATTR_BORDER:           rField.SetBox( (const SvxBoxItem&)rItem );                break;
600         case ATTR_BORDER_TLBR:      rField.SetTLBR( (const SvxLineItem&)rItem );              break;
601         case ATTR_BORDER_BLTR:      rField.SetBLTR( (const SvxLineItem&)rItem );              break;
602         case ATTR_BACKGROUND:       rField.SetBackground( (const SvxBrushItem&)rItem );       break;
603         case ATTR_HOR_JUSTIFY:      rField.SetHorJustify( (const SvxHorJustifyItem&)rItem );  break;
604         case ATTR_VER_JUSTIFY:      rField.SetVerJustify( (const SvxVerJustifyItem&)rItem );  break;
605         case ATTR_STACKED:          rField.SetStacked( (const SfxBoolItem&)rItem );           break;
606         case ATTR_MARGIN:           rField.SetMargin( (const SvxMarginItem&)rItem );          break;
607         case ATTR_LINEBREAK:        rField.SetLinebreak( (const SfxBoolItem&)rItem );         break;
608         case ATTR_ROTATE_VALUE:     rField.SetRotateAngle( (const SfxInt32Item&)rItem );      break;
609         case ATTR_ROTATE_MODE:      rField.SetRotateMode( (const SvxRotateModeItem&)rItem );  break;
610 	}
611 }
612 
613 void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich )
614 {
615     const SfxPoolItem* pItem = GetItem( nFromIndex, nWhich );
616     if( pItem )
617         PutItem( nToIndex, *pItem );
618 }
619 
620 const ScNumFormatAbbrev& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex ) const
621 {
622     return GetField( nIndex ).GetNumFormat();
623 }
624 
625 sal_Bool ScAutoFormatData::IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const
626 {
627 	sal_Bool bEqual = sal_True;
628     const ScAutoFormatDataField& rField1 = GetField( nIndex1 );
629     const ScAutoFormatDataField& rField2 = GetField( nIndex2 );
630 
631     if( bIncludeValueFormat )
632 	{
633         bEqual = bEqual
634             && (rField1.GetNumFormat()      == rField2.GetNumFormat());
635 	}
636     if( bIncludeFont )
637 	{
638         bEqual = bEqual
639             && (rField1.GetFont()           == rField2.GetFont())
640             && (rField1.GetHeight()         == rField2.GetHeight())
641             && (rField1.GetWeight()         == rField2.GetWeight())
642             && (rField1.GetPosture()        == rField2.GetPosture())
643             && (rField1.GetCJKFont()        == rField2.GetCJKFont())
644             && (rField1.GetCJKHeight()      == rField2.GetCJKHeight())
645             && (rField1.GetCJKWeight()      == rField2.GetCJKWeight())
646             && (rField1.GetCJKPosture()     == rField2.GetCJKPosture())
647             && (rField1.GetCTLFont()        == rField2.GetCTLFont())
648             && (rField1.GetCTLHeight()      == rField2.GetCTLHeight())
649             && (rField1.GetCTLWeight()      == rField2.GetCTLWeight())
650             && (rField1.GetCTLPosture()     == rField2.GetCTLPosture())
651             && (rField1.GetUnderline()      == rField2.GetUnderline())
652             && (rField1.GetOverline()       == rField2.GetOverline())
653             && (rField1.GetCrossedOut()     == rField2.GetCrossedOut())
654             && (rField1.GetContour()        == rField2.GetContour())
655             && (rField1.GetShadowed()       == rField2.GetShadowed())
656             && (rField1.GetColor()          == rField2.GetColor());
657 	}
658     if( bIncludeJustify )
659 	{
660         bEqual = bEqual
661             && (rField1.GetHorJustify()     == rField2.GetHorJustify())
662             && (rField1.GetVerJustify()     == rField2.GetVerJustify())
663             && (rField1.GetStacked()        == rField2.GetStacked())
664             && (rField1.GetLinebreak()      == rField2.GetLinebreak())
665             && (rField1.GetMargin()         == rField2.GetMargin())
666             && (rField1.GetRotateAngle()    == rField2.GetRotateAngle())
667             && (rField1.GetRotateMode()     == rField2.GetRotateMode());
668 	}
669     if( bIncludeFrame )
670     {
671         bEqual = bEqual
672             && (rField1.GetBox()            == rField2.GetBox())
673             && (rField1.GetTLBR()           == rField2.GetTLBR())
674             && (rField1.GetBLTR()           == rField2.GetBLTR());
675     }
676     if( bIncludeBackground )
677     {
678         bEqual = bEqual
679             && (rField1.GetBackground()     == rField2.GetBackground());
680     }
681 	return bEqual;
682 }
683 
684 void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const
685 {
686     const ScAutoFormatDataField& rField = GetField( nIndex );
687 
688     if( bIncludeValueFormat )
689     {
690         ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)rField.GetNumFormat();
691         SfxUInt32Item aValueFormat( ATTR_VALUE_FORMAT, 0 );
692         aValueFormat.SetValue( rNumFormat.GetFormatIndex( *rDoc.GetFormatTable() ) );
693         rItemSet.Put( aValueFormat );
694         rItemSet.Put( SvxLanguageItem( rNumFormat.GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
695     }
696     if( bIncludeFont )
697     {
698         rItemSet.Put( rField.GetFont() );
699         rItemSet.Put( rField.GetHeight() );
700         rItemSet.Put( rField.GetWeight() );
701         rItemSet.Put( rField.GetPosture() );
702         // #103065# do not insert empty CJK font
703         const SvxFontItem& rCJKFont = rField.GetCJKFont();
704         if( rCJKFont.GetStyleName().Len() )
705         {
706             rItemSet.Put( rCJKFont );
707             rItemSet.Put( rField.GetCJKHeight() );
708             rItemSet.Put( rField.GetCJKWeight() );
709             rItemSet.Put( rField.GetCJKPosture() );
710         }
711         else
712         {
713             rItemSet.Put( rField.GetHeight(), ATTR_CJK_FONT_HEIGHT );
714             rItemSet.Put( rField.GetWeight(), ATTR_CJK_FONT_WEIGHT );
715             rItemSet.Put( rField.GetPosture(), ATTR_CJK_FONT_POSTURE );
716         }
717         // #103065# do not insert empty CTL font
718         const SvxFontItem& rCTLFont = rField.GetCTLFont();
719         if( rCTLFont.GetStyleName().Len() )
720         {
721             rItemSet.Put( rCTLFont );
722             rItemSet.Put( rField.GetCTLHeight() );
723             rItemSet.Put( rField.GetCTLWeight() );
724             rItemSet.Put( rField.GetCTLPosture() );
725         }
726         else
727         {
728             rItemSet.Put( rField.GetHeight(), ATTR_CTL_FONT_HEIGHT );
729             rItemSet.Put( rField.GetWeight(), ATTR_CTL_FONT_WEIGHT );
730             rItemSet.Put( rField.GetPosture(), ATTR_CTL_FONT_POSTURE );
731         }
732         rItemSet.Put( rField.GetUnderline() );
733         rItemSet.Put( rField.GetOverline() );
734         rItemSet.Put( rField.GetCrossedOut() );
735         rItemSet.Put( rField.GetContour() );
736         rItemSet.Put( rField.GetShadowed() );
737         rItemSet.Put( rField.GetColor() );
738     }
739     if( bIncludeJustify )
740     {
741         rItemSet.Put( rField.GetHorJustify() );
742         rItemSet.Put( rField.GetVerJustify() );
743         rItemSet.Put( rField.GetStacked() );
744         rItemSet.Put( rField.GetLinebreak() );
745         rItemSet.Put( rField.GetMargin() );
746         rItemSet.Put( rField.GetRotateAngle() );
747         rItemSet.Put( rField.GetRotateMode() );
748     }
749     if( bIncludeFrame )
750     {
751         rItemSet.Put( rField.GetBox() );
752         rItemSet.Put( rField.GetTLBR() );
753         rItemSet.Put( rField.GetBLTR() );
754     }
755     if( bIncludeBackground )
756         rItemSet.Put( rField.GetBackground() );
757 }
758 
759 void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat )
760 {
761     ScAutoFormatDataField& rField = GetField( nIndex );
762 
763     rField.SetNumFormat     ( rNumFormat);
764     rField.SetFont          ( (const SvxFontItem&)          rItemSet.Get( ATTR_FONT ) );
765     rField.SetHeight        ( (const SvxFontHeightItem&)    rItemSet.Get( ATTR_FONT_HEIGHT ) );
766     rField.SetWeight        ( (const SvxWeightItem&)        rItemSet.Get( ATTR_FONT_WEIGHT ) );
767     rField.SetPosture       ( (const SvxPostureItem&)       rItemSet.Get( ATTR_FONT_POSTURE ) );
768     rField.SetCJKFont       ( (const SvxFontItem&)          rItemSet.Get( ATTR_CJK_FONT ) );
769     rField.SetCJKHeight     ( (const SvxFontHeightItem&)    rItemSet.Get( ATTR_CJK_FONT_HEIGHT ) );
770     rField.SetCJKWeight     ( (const SvxWeightItem&)        rItemSet.Get( ATTR_CJK_FONT_WEIGHT ) );
771     rField.SetCJKPosture    ( (const SvxPostureItem&)       rItemSet.Get( ATTR_CJK_FONT_POSTURE ) );
772     rField.SetCTLFont       ( (const SvxFontItem&)          rItemSet.Get( ATTR_CTL_FONT ) );
773     rField.SetCTLHeight     ( (const SvxFontHeightItem&)    rItemSet.Get( ATTR_CTL_FONT_HEIGHT ) );
774     rField.SetCTLWeight     ( (const SvxWeightItem&)        rItemSet.Get( ATTR_CTL_FONT_WEIGHT ) );
775     rField.SetCTLPosture    ( (const SvxPostureItem&)       rItemSet.Get( ATTR_CTL_FONT_POSTURE ) );
776     rField.SetUnderline     ( (const SvxUnderlineItem&)     rItemSet.Get( ATTR_FONT_UNDERLINE ) );
777     rField.SetOverline      ( (const SvxOverlineItem&)      rItemSet.Get( ATTR_FONT_OVERLINE ) );
778     rField.SetCrossedOut    ( (const SvxCrossedOutItem&)    rItemSet.Get( ATTR_FONT_CROSSEDOUT ) );
779     rField.SetContour       ( (const SvxContourItem&)       rItemSet.Get( ATTR_FONT_CONTOUR ) );
780     rField.SetShadowed      ( (const SvxShadowedItem&)      rItemSet.Get( ATTR_FONT_SHADOWED ) );
781     rField.SetColor         ( (const SvxColorItem&)         rItemSet.Get( ATTR_FONT_COLOR ) );
782     rField.SetTLBR          ( (const SvxLineItem&)          rItemSet.Get( ATTR_BORDER_TLBR ) );
783     rField.SetBLTR          ( (const SvxLineItem&)          rItemSet.Get( ATTR_BORDER_BLTR ) );
784     rField.SetHorJustify    ( (const SvxHorJustifyItem&)    rItemSet.Get( ATTR_HOR_JUSTIFY ) );
785     rField.SetVerJustify    ( (const SvxVerJustifyItem&)    rItemSet.Get( ATTR_VER_JUSTIFY ) );
786     rField.SetStacked       ( (const SfxBoolItem&)          rItemSet.Get( ATTR_STACKED ) );
787     rField.SetLinebreak     ( (const SfxBoolItem&)          rItemSet.Get( ATTR_LINEBREAK ) );
788     rField.SetMargin        ( (const SvxMarginItem&)        rItemSet.Get( ATTR_MARGIN ) );
789     rField.SetBackground    ( (const SvxBrushItem&)         rItemSet.Get( ATTR_BACKGROUND ) );
790     rField.SetRotateAngle   ( (const SfxInt32Item&)         rItemSet.Get( ATTR_ROTATE_VALUE ) );
791     rField.SetRotateMode    ( (const SvxRotateModeItem&)    rItemSet.Get( ATTR_ROTATE_MODE ) );
792 }
793 
794 sal_Bool ScAutoFormatData::Load( SvStream& rStream, const ScAfVersions& rVersions )
795 {
796 	sal_Bool    bRet = sal_True;
797     sal_uInt16  nVer = 0;
798     rStream >> nVer;
799 	bRet = 0 == rStream.GetError();
800     if( bRet && (nVer == AUTOFORMAT_DATA_ID_X ||
801             (AUTOFORMAT_DATA_ID_504 <= nVer && nVer <= AUTOFORMAT_DATA_ID)) )
802 	{
803         // --- from 680/dr25 on: #21549# store strings as UTF-8
804         CharSet eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
805         rStream.ReadByteString( aName, eCharSet );
806         if( AUTOFORMAT_DATA_ID_552 <= nVer )
807 		{
808 			rStream >> nStrResId;
809 			sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN + nStrResId;
810 			if( RID_SVXSTR_TBLAFMT_BEGIN <= nId &&
811 				nId < RID_SVXSTR_TBLAFMT_END )
812 			{
813 				aName = SVX_RESSTR( nId );
814 			}
815 			else
816 				nStrResId = USHRT_MAX;
817 		}
818 
819         sal_Bool b;
820 		rStream >> b; bIncludeFont = b;
821 		rStream >> b; bIncludeJustify = b;
822 		rStream >> b; bIncludeFrame = b;
823 		rStream >> b; bIncludeBackground = b;
824 		rStream >> b; bIncludeValueFormat = b;
825 		rStream >> b; bIncludeWidthHeight = b;
826 
827 		bRet = 0 == rStream.GetError();
828 		for( sal_uInt16 i = 0; bRet && i < 16; ++i )
829             bRet = GetField( i ).Load( rStream, rVersions, nVer );
830 	}
831 	else
832 		bRet = sal_False;
833 	return bRet;
834 }
835 
836 #ifdef READ_OLDVERS
837 sal_Bool ScAutoFormatData::LoadOld( SvStream& rStream, const ScAfVersions& rVersions )
838 {
839 	sal_Bool    bRet = sal_True;
840 	sal_uInt16  nVal = 0;
841 	rStream >> nVal;
842 	bRet = (rStream.GetError() == 0);
843 	if (bRet && (nVal == AUTOFORMAT_OLD_DATA_ID))
844 	{
845 		rStream.ReadByteString( aName, rStream.GetStreamCharSet() );
846 		sal_Bool b;
847 		rStream >> b; bIncludeFont = b;
848 		rStream >> b; bIncludeJustify = b;
849 		rStream >> b; bIncludeFrame = b;
850 		rStream >> b; bIncludeBackground = b;
851 		rStream >> b; bIncludeValueFormat = b;
852 		rStream >> b; bIncludeWidthHeight = b;
853 
854 		bRet = 0 == rStream.GetError();
855 		for (sal_uInt16 i=0; bRet && i < 16; i++)
856             bRet = GetField( i ).LoadOld( rStream, rVersions );
857 	}
858 	else
859 		bRet = sal_False;
860 	return bRet;
861 }
862 #endif
863 
864 sal_Bool ScAutoFormatData::Save(SvStream& rStream)
865 {
866 	sal_uInt16 nVal = AUTOFORMAT_DATA_ID;
867 	sal_Bool b;
868 	rStream << nVal;
869     // --- from 680/dr25 on: #21549# store strings as UTF-8
870     rStream.WriteByteString( aName, RTL_TEXTENCODING_UTF8 );
871 
872 #if 0
873 	//	This was an internal flag to allow creating AutoFormats with localized names
874 
875 	if ( USHRT_MAX == nStrResId )
876 	{
877 		String aIniVal( SFX_APP()->GetIniManager()->Get(
878 			SFX_GROUP_WORKINGSET_IMPL,
879 			String( RTL_CONSTASCII_USTRINGPARAM( "SaveTableAutoFmtNameId" ))));
880 		if( 0 != aIniVal.ToInt32() )
881 		{
882 			// check Name for ResId
883 			for( sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN;
884 						RID_SVXSTR_TBLAFMT_END > nId; ++nId )
885 			{
886 				String s( SVX_RES( nId ) );
887 				if( s == aName )
888 				{
889 					nStrResId = nId - RID_SVXSTR_TBLAFMT_BEGIN;
890 					break;
891 				}
892 			}
893 		}
894 	}
895 #endif
896 
897 	rStream << nStrResId;
898 	rStream << ( b = bIncludeFont );
899 	rStream << ( b = bIncludeJustify );
900 	rStream << ( b = bIncludeFrame );
901 	rStream << ( b = bIncludeBackground );
902 	rStream << ( b = bIncludeValueFormat );
903 	rStream << ( b = bIncludeWidthHeight );
904 
905     sal_Bool bRet = 0 == rStream.GetError();
906 	for (sal_uInt16 i = 0; bRet && (i < 16); i++)
907         bRet = GetField( i ).Save( rStream );
908 
909 	return bRet;
910 }
911 
912 //---------------------------------------------------------------------------------------
913 //---------------------------------------------------------------------------------------
914 
915 ScAutoFormat::ScAutoFormat(sal_uInt16 nLim, sal_uInt16 nDel, sal_Bool bDup):
916 	ScSortedCollection        (nLim, nDel, bDup),
917 	bSaveLater				(sal_False)
918 {
919     //  create default autoformat
920     ScAutoFormatData* pData = new ScAutoFormatData;
921 	String aName(ScGlobal::GetRscString(STR_STYLENAME_STANDARD));
922 	pData->SetName(aName);
923 
924     //  default font, default height
925     Font aStdFont = OutputDevice::GetDefaultFont(
926         DEFAULTFONT_LATIN_SPREADSHEET, LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE );
927     SvxFontItem aFontItem(
928         aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
929         aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_FONT );
930 
931     aStdFont = OutputDevice::GetDefaultFont(
932         DEFAULTFONT_CJK_SPREADSHEET, LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE );
933     SvxFontItem aCJKFontItem(
934         aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
935         aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CJK_FONT );
936 
937     aStdFont = OutputDevice::GetDefaultFont(
938         DEFAULTFONT_CTL_SPREADSHEET, LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE );
939     SvxFontItem aCTLFontItem(
940         aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
941         aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CTL_FONT );
942 
943     SvxFontHeightItem aHeight( 200, 100, ATTR_FONT_HEIGHT );      // 10 pt;
944 
945     //  black thin border
946 	Color aBlack( COL_BLACK );
947 	SvxBorderLine aLine( &aBlack, DEF_LINE_WIDTH_0 );
948     SvxBoxItem aBox( ATTR_BORDER );
949 	aBox.SetLine(&aLine, BOX_LINE_LEFT);
950 	aBox.SetLine(&aLine, BOX_LINE_TOP);
951 	aBox.SetLine(&aLine, BOX_LINE_RIGHT);
952 	aBox.SetLine(&aLine, BOX_LINE_BOTTOM);
953 
954 	Color aWhite(COL_WHITE);
955 	Color aBlue(COL_BLUE);
956     SvxColorItem aWhiteText( aWhite, ATTR_FONT_COLOR );
957     SvxColorItem aBlackText( aBlack, ATTR_FONT_COLOR );
958     SvxBrushItem aBlueBack( aBlue, ATTR_BACKGROUND );
959     SvxBrushItem aWhiteBack( aWhite, ATTR_BACKGROUND );
960     SvxBrushItem aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND );
961     SvxBrushItem aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND );
962 
963 	for (sal_uInt16 i=0; i<16; i++)
964 	{
965         pData->PutItem( i, aBox );
966         pData->PutItem( i, aFontItem );
967         pData->PutItem( i, aCJKFontItem );
968         pData->PutItem( i, aCTLFontItem );
969         aHeight.SetWhich( ATTR_FONT_HEIGHT );
970         pData->PutItem( i, aHeight );
971         aHeight.SetWhich( ATTR_CJK_FONT_HEIGHT );
972         pData->PutItem( i, aHeight );
973         aHeight.SetWhich( ATTR_CTL_FONT_HEIGHT );
974         pData->PutItem( i, aHeight );
975         if (i<4)                                    // top: white on blue
976 		{
977             pData->PutItem( i, aWhiteText );
978             pData->PutItem( i, aBlueBack );
979 		}
980         else if ( i%4 == 0 )                        // left: white on gray70
981 		{
982             pData->PutItem( i, aWhiteText );
983             pData->PutItem( i, aGray70Back );
984 		}
985         else if ( i%4 == 3 || i >= 12 )             // right and bottom: black on gray20
986 		{
987             pData->PutItem( i, aBlackText );
988             pData->PutItem( i, aGray20Back );
989 		}
990         else                                        // center: black on white
991 		{
992             pData->PutItem( i, aBlackText );
993             pData->PutItem( i, aWhiteBack );
994 		}
995 	}
996 
997 	Insert(pData);
998 }
999 
1000 ScAutoFormat::ScAutoFormat(const ScAutoFormat& rAutoFormat) :
1001 	ScSortedCollection (rAutoFormat),
1002 	bSaveLater		 (sal_False)
1003 {}
1004 
1005 ScAutoFormat::~ScAutoFormat()
1006 {
1007 	//	Bei Aenderungen per StarOne wird nicht sofort gespeichert, sondern zuerst nur
1008 	//	das SaveLater Flag gesetzt. Wenn das Flag noch gesetzt ist, jetzt speichern.
1009 
1010 	if (bSaveLater)
1011 		Save();
1012 }
1013 
1014 void ScAutoFormat::SetSaveLater( sal_Bool bSet )
1015 {
1016 	bSaveLater = bSet;
1017 }
1018 
1019 short ScAutoFormat::Compare(ScDataObject* pKey1, ScDataObject* pKey2) const
1020 {
1021 	String aStr1;
1022 	String aStr2;
1023 	((ScAutoFormatData*)pKey1)->GetName(aStr1);
1024 	((ScAutoFormatData*)pKey2)->GetName(aStr2);
1025 	String aStrStandard = ScGlobal::GetRscString(STR_STYLENAME_STANDARD);
1026     if ( ScGlobal::GetpTransliteration()->isEqual( aStr1, aStrStandard ) )
1027 		return -1;
1028     if ( ScGlobal::GetpTransliteration()->isEqual( aStr2, aStrStandard ) )
1029 		return 1;
1030     return (short) ScGlobal::GetpTransliteration()->compareString( aStr1, aStr2 );
1031 }
1032 
1033 sal_Bool ScAutoFormat::Load()
1034 {
1035 	sal_Bool bRet = sal_True;
1036 
1037 	INetURLObject aURL;
1038 	SvtPathOptions aPathOpt;
1039 	aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
1040 	aURL.setFinalSlash();
1041 	aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( sAutoTblFmtName ) ) );
1042 
1043 	SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_READ, sal_True );
1044 	SvStream* pStream = aMedium.GetInStream();
1045 	bRet = (pStream && pStream->GetError() == 0);
1046 	if (bRet)
1047 	{
1048 		SvStream& rStream = *pStream;
1049 		// Achtung hier muss ein allgemeiner Header gelesen werden
1050 		sal_uInt16 nVal = 0;
1051 		rStream >> nVal;
1052 		bRet = 0 == rStream.GetError();
1053 
1054 		ScAfVersions aVersions;
1055 
1056 		if (bRet)
1057 		{
1058 			if( nVal == AUTOFORMAT_ID_358 ||
1059 					(AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1060 			{
1061 				sal_uInt16 nFileVers = SOFFICE_FILEFORMAT_40;
1062 				sal_uInt8 nChrSet, nCnt;
1063 				long nPos = rStream.Tell();
1064 				rStream >> nCnt >> nChrSet;
1065 //				if( 4 <= nCnt )
1066 //					rStream >> nFileVers;
1067 				if( rStream.Tell() != sal_uLong(nPos + nCnt) )
1068 				{
1069 					DBG_ERRORFILE( "Der Header enthaelt mehr/neuere Daten" );
1070 					rStream.Seek( nPos + nCnt );
1071 				}
1072                 rStream.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet, nFileVers ) );
1073 				rStream.SetVersion( nFileVers );
1074 			}
1075 
1076 			if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X ||
1077 					(AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1078 			{
1079 				aVersions.Load( rStream, nVal );		// Item-Versionen
1080 
1081 				ScAutoFormatData* pData;
1082 				sal_uInt16 nAnz = 0;
1083 				rStream >> nAnz;
1084 				bRet = (rStream.GetError() == 0);
1085 				for (sal_uInt16 i=0; bRet && (i < nAnz); i++)
1086 				{
1087 					pData = new ScAutoFormatData();
1088 					bRet = pData->Load(rStream, aVersions);
1089 					Insert(pData);
1090 				}
1091 			}
1092 #ifdef READ_OLDVERS
1093 			else
1094 			{
1095 				if( AUTOFORMAT_OLD_ID_NEW == nVal )
1096 				{
1097 					// alte Version der Versions laden
1098 					rStream >> aVersions.nFontVersion;
1099 					rStream >> aVersions.nFontHeightVersion;
1100 					rStream >> aVersions.nWeightVersion;
1101 					rStream >> aVersions.nPostureVersion;
1102 					rStream >> aVersions.nUnderlineVersion;
1103 					rStream >> aVersions.nCrossedOutVersion;
1104 					rStream >> aVersions.nContourVersion;
1105 					rStream >> aVersions.nShadowedVersion;
1106 					rStream >> aVersions.nColorVersion;
1107 					rStream >> aVersions.nHorJustifyVersion;
1108 					rStream >> aVersions.nVerJustifyVersion;
1109 					rStream >> aVersions.nOrientationVersion;
1110 					rStream >> aVersions.nBoolVersion;
1111 					rStream >> aVersions.nMarginVersion;
1112 					rStream >> aVersions.nBoxVersion;
1113 					rStream >> aVersions.nBrushVersion;
1114 				}
1115 				if( AUTOFORMAT_OLD_ID_OLD == nVal ||
1116 					AUTOFORMAT_OLD_ID_NEW == nVal )
1117 				{
1118 					ScAutoFormatData* pData;
1119 					sal_uInt16 nAnz = 0;
1120 					rStream >> nAnz;
1121 					bRet = 0 == rStream.GetError();
1122 					for( sal_uInt16 i=0; bRet && (i < nAnz); ++i )
1123 					{
1124 						pData = new ScAutoFormatData();
1125 						bRet = pData->LoadOld( rStream, aVersions );
1126 						Insert( pData );
1127 					}
1128 				}
1129 				else
1130 					bRet = sal_False;
1131 			}
1132 #endif
1133 		}
1134 	}
1135 	bSaveLater = sal_False;
1136 	return bRet;
1137 }
1138 
1139 sal_Bool ScAutoFormat::Save()
1140 {
1141 	sal_Bool bRet = sal_True;
1142 
1143 	INetURLObject aURL;
1144 	SvtPathOptions aPathOpt;
1145 	aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
1146 	aURL.setFinalSlash();
1147 	aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( sAutoTblFmtName ) ) );
1148 
1149 	SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_WRITE, sal_True );
1150 	SvStream* pStream = aMedium.GetOutStream();
1151 	bRet = (pStream && pStream->GetError() == 0);
1152 	if (bRet)
1153 	{
1154 		SvStream& rStream = *pStream;
1155 		rStream.SetVersion( SOFFICE_FILEFORMAT_40 );
1156 
1157 		// Achtung hier muss ein allgemeiner Header gespeichert werden
1158 		sal_uInt16 nVal = AUTOFORMAT_ID;
1159 		rStream << nVal
1160 				<< (sal_uInt8)2 		// Anzahl von Zeichen des Headers incl. diesem
1161                 << (sal_uInt8)::GetSOStoreTextEncoding(
1162                     gsl_getSystemTextEncoding(), sal::static_int_cast<sal_uInt16>(rStream.GetVersion()) );
1163 //				<< (sal_uInt8)4 		// Anzahl von Zeichen des Headers incl. diesem
1164 //				<< (sal_uInt8)::GetStoreCharSet(::GetSystemCharSet())
1165 //				<< (UNIT16)SOFFICE_FILEFORMAT_NOW;
1166 		ScAfVersions::Write(rStream);			// Item-Versionen
1167 
1168 		bRet = (rStream.GetError() == 0);
1169 		//-----------------------------------------------------------
1170 		rStream << (sal_uInt16)(nCount - 1);
1171 		bRet = (rStream.GetError() == 0);
1172 		for (sal_uInt16 i=1; bRet && (i < nCount); i++)
1173 			bRet = ((ScAutoFormatData*)pItems[i])->Save(rStream);
1174 		rStream.Flush();
1175 
1176 		aMedium.Commit();
1177 	}
1178 	bSaveLater = sal_False;
1179 	return bRet;
1180 }
1181 
1182 sal_uInt16 ScAutoFormat::FindIndexPerName( const String& rName ) const
1183 {
1184 	String				aName;
1185 
1186 	for( sal_uInt16 i=0; i<nCount ; i++ )
1187 	{
1188 		ScAutoFormatData* pItem = (ScAutoFormatData*)pItems[i];
1189 		pItem->GetName( aName );
1190 
1191 		if( aName == rName )
1192 			return i;
1193 	}
1194 
1195 	return 0;
1196 }
1197 
1198 
1199 
1200 
1201