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