xref: /aoo42x/main/sw/source/core/doc/tblafmt.cxx (revision 7114c7e9)
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_sw.hxx"
26 
27 
28 #include <tools/resid.hxx>
29 #include <tools/stream.hxx>
30 #include <tools/shl.hxx>
31 #include <vcl/svapp.hxx>
32 #include <sfx2/docfile.hxx>
33 #include <svl/urihelper.hxx>
34 #include <svl/zforlist.hxx>
35 #include <svl/zformat.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <sfx2/app.hxx>
38 #include <svx/dialmgr.hxx>
39 #ifndef _SVX_DIALOGS_HRC
40 #include <svx/dialogs.hrc>
41 #endif
42 
43 #define READ_OLDVERS		// erstmal noch alte Versionen lesen
44 #include <swtypes.hxx>
45 #include <doc.hxx>
46 #include <poolfmt.hxx>
47 #include <tblafmt.hxx>
48 #include <cellatr.hxx>
49 #include <SwStyleNameMapper.hxx>
50 
51 // bis SO5PF
52 const sal_uInt16 AUTOFORMAT_ID_X		= 9501;
53 const sal_uInt16 AUTOFORMAT_ID_358		= 9601;
54 const sal_uInt16 AUTOFORMAT_DATA_ID_X	= 9502;
55 
56 // ab SO5
57 //! in nachfolgenden Versionen muss der Betrag dieser IDs groesser sein
58 const sal_uInt16 AUTOFORMAT_ID_504		= 9801;
59 const sal_uInt16 AUTOFORMAT_DATA_ID_504	= 9802;
60 
61 const sal_uInt16 AUTOFORMAT_ID_552		= 9901;
62 const sal_uInt16 AUTOFORMAT_DATA_ID_552	= 9902;
63 
64 // --- from 641 on: CJK and CTL font settings
65 const sal_uInt16 AUTOFORMAT_ID_641      = 10001;
66 const sal_uInt16 AUTOFORMAT_DATA_ID_641 = 10002;
67 
68 // --- from 680/dr14 on: diagonal frame lines
69 const sal_uInt16 AUTOFORMAT_ID_680DR14      = 10011;
70 const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14 = 10012;
71 
72 // --- from 680/dr25 on: #21549# store strings as UTF-8
73 const sal_uInt16 AUTOFORMAT_ID_680DR25      = 10021;
74 const sal_uInt16 AUTOFORMAT_DATA_ID_680DR25 = 10022;
75 
76 // --- from DEV300/overline2 on: #5991# overline
77 const sal_uInt16 AUTOFORMAT_ID_300OVRLN      = 10031;
78 const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN = 10032;
79 
80 // current version
81 const sal_uInt16 AUTOFORMAT_ID          = AUTOFORMAT_ID_300OVRLN;
82 const sal_uInt16 AUTOFORMAT_DATA_ID     = AUTOFORMAT_DATA_ID_300OVRLN;
83 
84 
85 #ifdef READ_OLDVERS
86 const sal_uInt16 AUTOFORMAT_OLD_ID		= 8201;
87 const sal_uInt16 AUTOFORMAT_OLD_ID1		= 8301;
88 const sal_uInt16 AUTOFORMAT_OLD_DATA_ID	= 8202;
89 #endif
90 
91 
92 SwBoxAutoFmt* SwTableAutoFmt::pDfltBoxAutoFmt = 0;
93 
94 #define sAutoTblFmtName "autotbl.fmt"
95 
96 // SwTable Auto-Format-Tabelle
97 SV_IMPL_PTRARR( _SwTableAutoFmtTbl, SwTableAutoFmt* )
98 
99 
100 //	Struct mit Versionsnummern der Items
101 
102 struct SwAfVersions
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 	SwAfVersions();
132 	void Load( SvStream& rStream, sal_uInt16 nVer );
133 };
134 
SwAfVersions()135 SwAfVersions::SwAfVersions() :
136 	nFontVersion(0),
137 	nFontHeightVersion(0),
138 	nWeightVersion(0),
139 	nPostureVersion(0),
140 	nUnderlineVersion(0),
141 	nOverlineVersion(0),
142 	nCrossedOutVersion(0),
143 	nContourVersion(0),
144 	nShadowedVersion(0),
145 	nColorVersion(0),
146 	nBoxVersion(0),
147 	nLineVersion(0),
148 	nBrushVersion(0),
149 	nAdjustVersion(0),
150 	nHorJustifyVersion(0),
151 	nVerJustifyVersion(0),
152 	nOrientationVersion(0),
153 	nMarginVersion(0),
154 	nBoolVersion(0),
155 	nInt32Version(0),
156 	nRotateModeVersion(0),
157 	nNumFmtVersion(0)
158 {
159 }
160 
Load(SvStream & rStream,sal_uInt16 nVer)161 void SwAfVersions::Load( SvStream& rStream, sal_uInt16 nVer )
162 {
163 	rStream >> nFontVersion;
164 	rStream >> nFontHeightVersion;
165 	rStream >> nWeightVersion;
166 	rStream >> nPostureVersion;
167 	rStream >> nUnderlineVersion;
168 	if ( nVer >= AUTOFORMAT_ID_300OVRLN )
169 		rStream >> nOverlineVersion;
170 	rStream >> nCrossedOutVersion;
171 	rStream >> nContourVersion;
172 	rStream >> nShadowedVersion;
173 	rStream >> nColorVersion;
174 	rStream >> nBoxVersion;
175 	if ( nVer >= AUTOFORMAT_ID_680DR14 )
176 		rStream >> nLineVersion;
177 	rStream >> nBrushVersion;
178 	rStream >> nAdjustVersion;
179 	rStream >> nHorJustifyVersion;
180 	rStream >> nVerJustifyVersion;
181 	rStream >> nOrientationVersion;
182 	rStream >> nMarginVersion;
183 	rStream >> nBoolVersion;
184 	if ( nVer >= AUTOFORMAT_ID_504 )
185 	{
186 		rStream >> nInt32Version;
187 		rStream >> nRotateModeVersion;
188 	}
189 	rStream >> nNumFmtVersion;
190 }
191 
192 //	---------------------------------------------------------------------------
193 
SwBoxAutoFmt()194 SwBoxAutoFmt::SwBoxAutoFmt()
195 	: aFont( *(SvxFontItem*)GetDfltAttr( RES_CHRATR_FONT ) ),
196 	aHeight( 240, 100, RES_CHRATR_FONTSIZE ),
197 	aWeight( WEIGHT_NORMAL, RES_CHRATR_WEIGHT ),
198 	aPosture( ITALIC_NONE, RES_CHRATR_POSTURE ),
199 
200 	aCJKFont( *(SvxFontItem*)GetDfltAttr( RES_CHRATR_CJK_FONT ) ),
201 	aCJKHeight( 240, 100, RES_CHRATR_CJK_FONTSIZE ),
202 	aCJKWeight( WEIGHT_NORMAL, RES_CHRATR_CJK_WEIGHT ),
203 	aCJKPosture( ITALIC_NONE, RES_CHRATR_CJK_POSTURE ),
204 
205 	aCTLFont( *(SvxFontItem*)GetDfltAttr( RES_CHRATR_CTL_FONT ) ),
206 	aCTLHeight( 240, 100, RES_CHRATR_CTL_FONTSIZE ),
207 	aCTLWeight( WEIGHT_NORMAL, RES_CHRATR_CTL_WEIGHT ),
208 	aCTLPosture( ITALIC_NONE, RES_CHRATR_CTL_POSTURE ),
209 
210 	aUnderline( UNDERLINE_NONE, RES_CHRATR_UNDERLINE ),
211 	aOverline( UNDERLINE_NONE, RES_CHRATR_OVERLINE ),
212 	aCrossedOut( STRIKEOUT_NONE, RES_CHRATR_CROSSEDOUT ),
213 	aContour( sal_False, RES_CHRATR_CONTOUR ),
214 	aShadowed( sal_False, RES_CHRATR_SHADOWED ),
215 	aColor( RES_CHRATR_COLOR ),
216 	aBox( RES_BOX ),
217 	aTLBR( 0 ),
218 	aBLTR( 0 ),
219 	aBackground( RES_BACKGROUND ),
220 	aAdjust( SVX_ADJUST_LEFT, RES_PARATR_ADJUST ),
221 	aHorJustify( SVX_HOR_JUSTIFY_STANDARD, 0),
222 	aVerJustify( SVX_VER_JUSTIFY_STANDARD, 0),
223 	aStacked( 0 ),
224 	aMargin( 0 ),
225 	aLinebreak( 0 ),
226 	aRotateAngle( 0 ),
227 
228 // FIXME - add attribute IDs for the diagonal line items
229 //    aTLBR( RES_... ),
230 //    aBLTR( RES_... ),
231 	aRotateMode( SVX_ROTATE_MODE_STANDARD, 0 )
232 {
233 	eSysLanguage = eNumFmtLanguage = static_cast<LanguageType>(::GetAppLanguage());
234 	aBox.SetDistance( 55 );
235 }
236 
237 
SwBoxAutoFmt(const SwBoxAutoFmt & rNew)238 SwBoxAutoFmt::SwBoxAutoFmt( const SwBoxAutoFmt& rNew )
239 	: aFont( rNew.aFont ),
240 	aHeight( rNew.aHeight ),
241 	aWeight( rNew.aWeight ),
242 	aPosture( rNew.aPosture ),
243 	aCJKFont( rNew.aCJKFont ),
244 	aCJKHeight( rNew.aCJKHeight ),
245 	aCJKWeight( rNew.aCJKWeight ),
246 	aCJKPosture( rNew.aCJKPosture ),
247 	aCTLFont( rNew.aCTLFont ),
248 	aCTLHeight( rNew.aCTLHeight ),
249 	aCTLWeight( rNew.aCTLWeight ),
250 	aCTLPosture( rNew.aCTLPosture ),
251 	aUnderline( rNew.aUnderline ),
252 	aOverline( rNew.aOverline ),
253 	aCrossedOut( rNew.aCrossedOut ),
254 	aContour( rNew.aContour ),
255 	aShadowed( rNew.aShadowed ),
256 	aColor( rNew.aColor ),
257 	aBox( rNew.aBox ),
258 	aTLBR( rNew.aTLBR ),
259 	aBLTR( rNew.aBLTR ),
260 	aBackground( rNew.aBackground ),
261 	aAdjust( rNew.aAdjust ),
262 	aHorJustify( rNew.aHorJustify ),
263 	aVerJustify( rNew.aVerJustify ),
264 	aStacked( rNew.aStacked ),
265 	aMargin( rNew.aMargin ),
266 	aLinebreak( rNew.aLinebreak ),
267 	aRotateAngle( rNew.aRotateAngle ),
268 	aRotateMode( rNew.aRotateMode ),
269 	sNumFmtString( rNew.sNumFmtString ),
270 	eSysLanguage( rNew.eSysLanguage ),
271 	eNumFmtLanguage( rNew.eNumFmtLanguage )
272 {
273 }
274 
275 
~SwBoxAutoFmt()276 SwBoxAutoFmt::~SwBoxAutoFmt()
277 {
278 }
279 
operator =(const SwBoxAutoFmt & rNew)280 SwBoxAutoFmt& SwBoxAutoFmt::operator=( const SwBoxAutoFmt& rNew )
281 {
282 	aFont = rNew.aFont;
283 	aHeight = rNew.aHeight;
284 	aWeight = rNew.aWeight;
285 	aPosture = rNew.aPosture;
286 	aCJKFont = rNew.aCJKFont;
287 	aCJKHeight = rNew.aCJKHeight;
288 	aCJKWeight = rNew.aCJKWeight;
289 	aCJKPosture = rNew.aCJKPosture;
290 	aCTLFont = rNew.aCTLFont;
291 	aCTLHeight = rNew.aCTLHeight;
292 	aCTLWeight = rNew.aCTLWeight;
293 	aCTLPosture = rNew.aCTLPosture;
294 	aUnderline = rNew.aUnderline;
295 	aOverline = rNew.aOverline;
296 	aCrossedOut = rNew.aCrossedOut;
297 	aContour = rNew.aContour;
298 	aShadowed = rNew.aShadowed;
299 	aColor = rNew.aColor;
300 	SetAdjust( rNew.aAdjust );
301 	aBox = rNew.aBox;
302 	aTLBR = rNew.aTLBR;
303 	aBLTR = rNew.aBLTR;
304 	aBackground = rNew.aBackground;
305 
306 	aHorJustify = rNew.aHorJustify;
307 	aVerJustify = rNew.aVerJustify;
308 	aStacked.SetValue( rNew.aStacked.GetValue() );
309 	aMargin = rNew.aMargin;
310 	aLinebreak.SetValue( rNew.aLinebreak.GetValue() );
311 	aRotateAngle.SetValue( rNew.aRotateAngle.GetValue() );
312 	aRotateMode.SetValue( rNew.aRotateMode.GetValue() );
313 
314 	sNumFmtString = rNew.sNumFmtString;
315 	eSysLanguage = rNew.eSysLanguage;
316 	eNumFmtLanguage = rNew.eNumFmtLanguage;
317 
318 	return *this;
319 }
320 
321 
322 #define READ( aItem, aItemType, nVers )\
323 	pNew = aItem.Create(rStream, nVers ); \
324 	aItem = *(aItemType*)pNew; \
325 	delete pNew;
326 
Load(SvStream & rStream,const SwAfVersions & rVersions,sal_uInt16 nVer)327 sal_Bool SwBoxAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer )
328 {
329 	SfxPoolItem* pNew;
330     SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0);
331 
332     READ( aFont,        SvxFontItem            , rVersions.nFontVersion)
333 
334 	if( rStream.GetStreamCharSet() == aFont.GetCharSet() )
335         aFont.SetCharSet(::gsl_getSystemTextEncoding());
336 
337     READ( aHeight,      SvxFontHeightItem  , rVersions.nFontHeightVersion)
338     READ( aWeight,      SvxWeightItem      , rVersions.nWeightVersion)
339     READ( aPosture,     SvxPostureItem     , rVersions.nPostureVersion)
340     // --- from 641 on: CJK and CTL font settings
341     if( AUTOFORMAT_DATA_ID_641 <= nVer )
342     {
343         READ( aCJKFont,                        SvxFontItem         , rVersions.nFontVersion)
344         READ( aCJKHeight,       SvxFontHeightItem   , rVersions.nFontHeightVersion)
345         READ( aCJKWeight,     SvxWeightItem       , rVersions.nWeightVersion)
346         READ( aCJKPosture,   SvxPostureItem      , rVersions.nPostureVersion)
347         READ( aCTLFont,                        SvxFontItem         , rVersions.nFontVersion)
348         READ( aCTLHeight,        SvxFontHeightItem   , rVersions.nFontHeightVersion)
349         READ( aCTLWeight,       SvxWeightItem       , rVersions.nWeightVersion)
350         READ( aCTLPosture,   SvxPostureItem      , rVersions.nPostureVersion)
351     }
352     READ( aUnderline,   SvxUnderlineItem   , rVersions.nUnderlineVersion)
353     if( nVer >= AUTOFORMAT_DATA_ID_300OVRLN )
354     {
355         READ( aOverline,       SvxOverlineItem     , rVersions.nOverlineVersion)
356     }
357     READ( aCrossedOut,  SvxCrossedOutItem  , rVersions.nCrossedOutVersion)
358     READ( aContour,     SvxContourItem     , rVersions.nContourVersion)
359     READ( aShadowed,    SvxShadowedItem       , rVersions.nShadowedVersion)
360     READ( aColor,       SvxColorItem       , rVersions.nColorVersion)
361 
362     READ( aBox,         SvxBoxItem         , rVersions.nBoxVersion)
363 
364     // --- from 680/dr14 on: diagonal frame lines
365     if( nVer >= AUTOFORMAT_DATA_ID_680DR14 )
366     {
367         READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
368         READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
369     }
370 
371 	READ( aBackground,  SvxBrushItem		, rVersions.nBrushVersion)
372 
373 	pNew = aAdjust.Create(rStream, rVersions.nAdjustVersion );
374 	SetAdjust( *(SvxAdjustItem*)pNew );
375 	delete pNew;
376 
377     READ( aHorJustify,  SvxHorJustifyItem , rVersions.nHorJustifyVersion)
378     READ( aVerJustify,  SvxVerJustifyItem   , rVersions.nVerJustifyVersion)
379     READ( aOrientation, SvxOrientationItem  , rVersions.nOrientationVersion)
380     READ( aMargin, SvxMarginItem       , rVersions.nMarginVersion)
381 
382 	pNew = aLinebreak.Create(rStream, rVersions.nBoolVersion );
383 	aLinebreak.SetValue( ((SfxBoolItem*)pNew)->GetValue() );
384 	delete pNew;
385 
386 	if ( nVer >= AUTOFORMAT_DATA_ID_504 )
387 	{
388 		pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
389 		aRotateAngle.SetValue( ((SfxInt32Item*)pNew)->GetValue() );
390 		delete pNew;
391 		pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
392 		aRotateMode.SetValue( ((SvxRotateModeItem*)pNew)->GetValue() );
393 		delete pNew;
394 	}
395 
396 	if( 0 == rVersions.nNumFmtVersion )
397 	{
398 		sal_uInt16 eSys, eLge;
399         // --- from 680/dr25 on: #21549# store strings as UTF-8
400         CharSet eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
401         rStream.ReadByteString( sNumFmtString, eCharSet )
402 				>> eSys >> eLge;
403 		eSysLanguage = (LanguageType) eSys;
404 		eNumFmtLanguage = (LanguageType) eLge;
405 		if ( eSysLanguage == LANGUAGE_SYSTEM )		// von alten Versionen (Calc)
406 			eSysLanguage = static_cast<LanguageType>(::GetAppLanguage());
407 	}
408 
409     aStacked.SetValue( aOrientation.IsStacked() );
410     aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
411 
412 	return 0 == rStream.GetError();
413 }
414 
415 #ifdef READ_OLDVERS
416 
LoadOld(SvStream & rStream,sal_uInt16 aLoadVer[])417 sal_Bool SwBoxAutoFmt::LoadOld( SvStream& rStream, sal_uInt16 aLoadVer[] )
418 {
419 	SfxPoolItem* pNew;
420 	READ( aFont,        SvxFontItem			, 0)
421 
422 	if( rStream.GetStreamCharSet() == aFont.GetCharSet() )
423         aFont.SetCharSet(::gsl_getSystemTextEncoding());
424 
425 	READ( aHeight,      SvxFontHeightItem	, 1)
426 	READ( aWeight,      SvxWeightItem		, 2)
427 	READ( aPosture,     SvxPostureItem	    , 3)
428 	READ( aUnderline,   SvxUnderlineItem	, 4)
429 	READ( aCrossedOut,  SvxCrossedOutItem	, 5)
430 	READ( aContour,     SvxContourItem	    , 6)
431 	READ( aShadowed,    SvxShadowedItem	    , 7)
432 	READ( aColor,       SvxColorItem		, 8)
433 
434 	pNew = aAdjust.Create(rStream, aLoadVer[ 9 ] );
435 	SetAdjust( *(SvxAdjustItem*)pNew );
436 	delete pNew;
437 
438 	READ( aBox,         SvxBoxItem		    , 10)
439 	READ( aBackground,  SvxBrushItem		, 11)
440 
441 	return 0 == rStream.GetError();
442 }
443 
444 #endif
445 
446 
Save(SvStream & rStream) const447 sal_Bool SwBoxAutoFmt::Save( SvStream& rStream ) const
448 {
449     SvxOrientationItem aOrientation( aRotateAngle.GetValue(), aStacked.GetValue(), 0 );
450 
451 	aFont.Store( rStream, aFont.GetVersion(SOFFICE_FILEFORMAT_40)  );
452 	aHeight.Store( rStream, aHeight.GetVersion(SOFFICE_FILEFORMAT_40) );
453 	aWeight.Store( rStream, aWeight.GetVersion(SOFFICE_FILEFORMAT_40) );
454 	aPosture.Store( rStream, aPosture.GetVersion(SOFFICE_FILEFORMAT_40) );
455     aCJKFont.Store( rStream, aCJKFont.GetVersion(SOFFICE_FILEFORMAT_40)  );
456     aCJKHeight.Store( rStream, aCJKHeight.GetVersion(SOFFICE_FILEFORMAT_40) );
457     aCJKWeight.Store( rStream, aCJKWeight.GetVersion(SOFFICE_FILEFORMAT_40) );
458     aCJKPosture.Store( rStream, aCJKPosture.GetVersion(SOFFICE_FILEFORMAT_40) );
459     aCTLFont.Store( rStream, aCTLFont.GetVersion(SOFFICE_FILEFORMAT_40)  );
460     aCTLHeight.Store( rStream, aCTLHeight.GetVersion(SOFFICE_FILEFORMAT_40) );
461     aCTLWeight.Store( rStream, aCTLWeight.GetVersion(SOFFICE_FILEFORMAT_40) );
462     aCTLPosture.Store( rStream, aCTLPosture.GetVersion(SOFFICE_FILEFORMAT_40) );
463 	aUnderline.Store( rStream, aUnderline.GetVersion(SOFFICE_FILEFORMAT_40) );
464 	aOverline.Store( rStream, aOverline.GetVersion(SOFFICE_FILEFORMAT_40) );
465 	aCrossedOut.Store( rStream, aCrossedOut.GetVersion(SOFFICE_FILEFORMAT_40) );
466 	aContour.Store( rStream, aContour.GetVersion(SOFFICE_FILEFORMAT_40) );
467 	aShadowed.Store( rStream, aShadowed.GetVersion(SOFFICE_FILEFORMAT_40) );
468 	aColor.Store( rStream, aColor.GetVersion(SOFFICE_FILEFORMAT_40) );
469 	aBox.Store( rStream, aBox.GetVersion(SOFFICE_FILEFORMAT_40) );
470     aTLBR.Store( rStream, aTLBR.GetVersion(SOFFICE_FILEFORMAT_40) );
471     aBLTR.Store( rStream, aBLTR.GetVersion(SOFFICE_FILEFORMAT_40) );
472 	aBackground.Store( rStream, aBackground.GetVersion(SOFFICE_FILEFORMAT_40) );
473 
474 	aAdjust.Store( rStream, aAdjust.GetVersion(SOFFICE_FILEFORMAT_40) );
475 
476 	aHorJustify.Store( rStream, aHorJustify.GetVersion(SOFFICE_FILEFORMAT_40) );
477 	aVerJustify.Store( rStream, aVerJustify.GetVersion(SOFFICE_FILEFORMAT_40) );
478 	aOrientation.Store( rStream, aOrientation.GetVersion(SOFFICE_FILEFORMAT_40) );
479 	aMargin.Store( rStream, aMargin.GetVersion(SOFFICE_FILEFORMAT_40) );
480 	aLinebreak.Store( rStream, aLinebreak.GetVersion(SOFFICE_FILEFORMAT_40) );
481 	// Calc Rotation ab SO5
482 	aRotateAngle.Store( rStream, aRotateAngle.GetVersion(SOFFICE_FILEFORMAT_40) );
483 	aRotateMode.Store( rStream, aRotateMode.GetVersion(SOFFICE_FILEFORMAT_40) );
484 
485     // --- from 680/dr25 on: #21549# store strings as UTF-8
486     rStream.WriteByteString( sNumFmtString, RTL_TEXTENCODING_UTF8 )
487 		<< (sal_uInt16)eSysLanguage << (sal_uInt16)eNumFmtLanguage;
488 
489 	return 0 == rStream.GetError();
490 }
491 
492 
SaveVersionNo(SvStream & rStream) const493 sal_Bool SwBoxAutoFmt::SaveVersionNo( SvStream& rStream ) const
494 {
495 	rStream << aFont.GetVersion( SOFFICE_FILEFORMAT_40 );
496 	rStream << aHeight.GetVersion( SOFFICE_FILEFORMAT_40 );
497 	rStream << aWeight.GetVersion( SOFFICE_FILEFORMAT_40 );
498 	rStream << aPosture.GetVersion( SOFFICE_FILEFORMAT_40 );
499 	rStream << aUnderline.GetVersion( SOFFICE_FILEFORMAT_40 );
500 	rStream << aOverline.GetVersion( SOFFICE_FILEFORMAT_40 );
501 	rStream << aCrossedOut.GetVersion( SOFFICE_FILEFORMAT_40 );
502 	rStream << aContour.GetVersion( SOFFICE_FILEFORMAT_40 );
503 	rStream << aShadowed.GetVersion( SOFFICE_FILEFORMAT_40 );
504 	rStream << aColor.GetVersion( SOFFICE_FILEFORMAT_40 );
505 	rStream << aBox.GetVersion( SOFFICE_FILEFORMAT_40 );
506     rStream << aTLBR.GetVersion( SOFFICE_FILEFORMAT_40 );
507 	rStream << aBackground.GetVersion( SOFFICE_FILEFORMAT_40 );
508 
509 	rStream << aAdjust.GetVersion( SOFFICE_FILEFORMAT_40 );
510 
511 	rStream << aHorJustify.GetVersion( SOFFICE_FILEFORMAT_40 );
512 	rStream << aVerJustify.GetVersion( SOFFICE_FILEFORMAT_40 );
513     rStream << SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0).GetVersion( SOFFICE_FILEFORMAT_40 );
514 	rStream << aMargin.GetVersion( SOFFICE_FILEFORMAT_40 );
515 	rStream << aLinebreak.GetVersion( SOFFICE_FILEFORMAT_40 );
516 	rStream << aRotateAngle.GetVersion( SOFFICE_FILEFORMAT_40 );
517 	rStream << aRotateMode.GetVersion( SOFFICE_FILEFORMAT_40 );
518 
519 	rStream << (sal_uInt16)0;		// NumberFormat
520 
521 	return 0 == rStream.GetError();
522 }
523 
524 
SwTableAutoFmt(const String & rName)525 SwTableAutoFmt::SwTableAutoFmt( const String& rName )
526 	: aName( rName ), nStrResId( USHRT_MAX )
527 {
528 	bInclFont = sal_True;
529 	bInclJustify = sal_True;
530 	bInclFrame = sal_True;
531 	bInclBackground = sal_True;
532 	bInclValueFormat = sal_True;
533 	bInclWidthHeight = sal_True;
534 
535 	memset( aBoxAutoFmt, 0, sizeof( aBoxAutoFmt ) );
536 }
537 
538 
SwTableAutoFmt(const SwTableAutoFmt & rNew)539 SwTableAutoFmt::SwTableAutoFmt( const SwTableAutoFmt& rNew )
540 {
541 	for( sal_uInt8 n = 0; n < 16; ++n )
542 		aBoxAutoFmt[ n ] = 0;
543 	*this = rNew;
544 }
545 
operator =(const SwTableAutoFmt & rNew)546 SwTableAutoFmt& SwTableAutoFmt::operator=( const SwTableAutoFmt& rNew )
547 {
548 	for( sal_uInt8 n = 0; n < 16; ++n )
549 	{
550 		if( aBoxAutoFmt[ n ] )
551 			delete aBoxAutoFmt[ n ];
552 
553 		SwBoxAutoFmt* pFmt = rNew.aBoxAutoFmt[ n ];
554 		if( pFmt )		// ist gesetzt -> kopieren
555 			aBoxAutoFmt[ n ] = new SwBoxAutoFmt( *pFmt );
556 		else			// sonst default
557 			aBoxAutoFmt[ n ] = 0;
558 	}
559 
560 	aName = rNew.aName;
561 	nStrResId = rNew.nStrResId;
562 	bInclFont = rNew.bInclFont;
563 	bInclJustify = rNew.bInclJustify;
564 	bInclFrame = rNew.bInclFrame;
565 	bInclBackground = rNew.bInclBackground;
566 	bInclValueFormat = rNew.bInclValueFormat;
567 	bInclWidthHeight = rNew.bInclWidthHeight;
568 
569 	return *this;
570 }
571 
572 
~SwTableAutoFmt()573 SwTableAutoFmt::~SwTableAutoFmt()
574 {
575 	SwBoxAutoFmt** ppFmt = aBoxAutoFmt;
576 	for( sal_uInt8 n = 0; n < 16; ++n, ++ppFmt )
577 		if( *ppFmt )
578 			delete *ppFmt;
579 }
580 
581 
SetBoxFmt(const SwBoxAutoFmt & rNew,sal_uInt8 nPos)582 void SwTableAutoFmt::SetBoxFmt( const SwBoxAutoFmt& rNew, sal_uInt8 nPos )
583 {
584 	ASSERT( nPos < 16, "falscher Bereich" );
585 
586 	SwBoxAutoFmt* pFmt = aBoxAutoFmt[ nPos ];
587 	if( pFmt )		// ist gesetzt -> kopieren
588 		*aBoxAutoFmt[ nPos ] = rNew;
589 	else			// sonst neu setzen
590 		aBoxAutoFmt[ nPos ] = new SwBoxAutoFmt( rNew );
591 }
592 
593 
GetBoxFmt(sal_uInt8 nPos) const594 const SwBoxAutoFmt& SwTableAutoFmt::GetBoxFmt( sal_uInt8 nPos ) const
595 {
596 	ASSERT( nPos < 16, "falscher Bereich" );
597 
598 	SwBoxAutoFmt* pFmt = aBoxAutoFmt[ nPos ];
599 	if( pFmt )		// ist gesetzt -> kopieren
600 		return *pFmt;
601 	else			// sonst den default returnen
602 	{
603 		// falls noch nicht vorhanden:
604 		if( !pDfltBoxAutoFmt )
605 			pDfltBoxAutoFmt = new SwBoxAutoFmt;
606 		return *pDfltBoxAutoFmt;
607 	}
608 }
609 
610 
611 
UpdateFromSet(sal_uInt8 nPos,const SfxItemSet & rSet,UpdateFlags eFlags,SvNumberFormatter * pNFmtr)612 SwBoxAutoFmt& SwTableAutoFmt::UpdateFromSet( sal_uInt8 nPos,
613 											const SfxItemSet& rSet,
614 											UpdateFlags eFlags,
615 											SvNumberFormatter* pNFmtr )
616 {
617 	ASSERT( nPos < 16, "falscher Bereich" );
618 
619 	SwBoxAutoFmt* pFmt = aBoxAutoFmt[ nPos ];
620 	if( !pFmt )		// ist gesetzt -> kopieren
621 	{
622 		pFmt = new SwBoxAutoFmt;
623 		aBoxAutoFmt[ nPos ] = pFmt;
624 	}
625 
626 	if( UPDATE_CHAR & eFlags )
627 	{
628 		pFmt->SetFont( (SvxFontItem&)rSet.Get( RES_CHRATR_FONT ) );
629 		pFmt->SetHeight( (SvxFontHeightItem&)rSet.Get( RES_CHRATR_FONTSIZE ) );
630 		pFmt->SetWeight( (SvxWeightItem&)rSet.Get( RES_CHRATR_WEIGHT ) );
631 		pFmt->SetPosture( (SvxPostureItem&)rSet.Get( RES_CHRATR_POSTURE ) );
632         pFmt->SetCJKFont( (SvxFontItem&)rSet.Get( RES_CHRATR_CJK_FONT ) );
633         pFmt->SetCJKHeight( (SvxFontHeightItem&)rSet.Get( RES_CHRATR_CJK_FONTSIZE ) );
634         pFmt->SetCJKWeight( (SvxWeightItem&)rSet.Get( RES_CHRATR_CJK_WEIGHT ) );
635         pFmt->SetCJKPosture( (SvxPostureItem&)rSet.Get( RES_CHRATR_CJK_POSTURE ) );
636         pFmt->SetCTLFont( (SvxFontItem&)rSet.Get( RES_CHRATR_CTL_FONT ) );
637         pFmt->SetCTLHeight( (SvxFontHeightItem&)rSet.Get( RES_CHRATR_CTL_FONTSIZE ) );
638         pFmt->SetCTLWeight( (SvxWeightItem&)rSet.Get( RES_CHRATR_CTL_WEIGHT ) );
639         pFmt->SetCTLPosture( (SvxPostureItem&)rSet.Get( RES_CHRATR_CTL_POSTURE ) );
640 		pFmt->SetUnderline( (SvxUnderlineItem&)rSet.Get( RES_CHRATR_UNDERLINE ) );
641 		pFmt->SetOverline( (SvxOverlineItem&)rSet.Get( RES_CHRATR_OVERLINE ) );
642 		pFmt->SetCrossedOut( (SvxCrossedOutItem&)rSet.Get( RES_CHRATR_CROSSEDOUT ) );
643 		pFmt->SetContour( (SvxContourItem&)rSet.Get( RES_CHRATR_CONTOUR ) );
644 		pFmt->SetShadowed( (SvxShadowedItem&)rSet.Get( RES_CHRATR_SHADOWED ) );
645 		pFmt->SetColor( (SvxColorItem&)rSet.Get( RES_CHRATR_COLOR ) );
646 		pFmt->SetAdjust( (SvxAdjustItem&)rSet.Get( RES_PARATR_ADJUST ) );
647 	}
648 	if( UPDATE_BOX & eFlags )
649 	{
650 		pFmt->SetBox( (SvxBoxItem&)rSet.Get( RES_BOX ) );
651 // FIXME - add attribute IDs for the diagonal line items
652 //        pFmt->SetTLBR( (SvxLineItem&)rSet.Get( RES_... ) );
653 //        pFmt->SetBLTR( (SvxLineItem&)rSet.Get( RES_... ) );
654 		pFmt->SetBackground( (SvxBrushItem&)rSet.Get( RES_BACKGROUND ) );
655 
656 		const SwTblBoxNumFormat* pNumFmtItem;
657 		const SvNumberformat* pNumFormat = 0;
658 		if( SFX_ITEM_SET == rSet.GetItemState( RES_BOXATR_FORMAT, sal_True,
659 			(const SfxPoolItem**)&pNumFmtItem ) && pNFmtr &&
660 			0 != (pNumFormat = pNFmtr->GetEntry( pNumFmtItem->GetValue() )) )
661 			pFmt->SetValueFormat( ((SvNumberformat*)pNumFormat)->GetFormatstring(),
662 									pNumFormat->GetLanguage(),
663 									static_cast<LanguageType>(::GetAppLanguage()));
664 		else
665 		{
666 			// defaulten
667 			pFmt->SetValueFormat( aEmptyStr, LANGUAGE_SYSTEM,
668 								  static_cast<LanguageType>(::GetAppLanguage() ));
669 		}
670 	}
671 	// den Rest koennen wir nicht, Calc spezifisch
672 
673 	return *pFmt;
674 }
675 
676 
UpdateToSet(sal_uInt8 nPos,SfxItemSet & rSet,UpdateFlags eFlags,SvNumberFormatter * pNFmtr) const677 void SwTableAutoFmt::UpdateToSet( sal_uInt8 nPos, SfxItemSet& rSet,
678 				UpdateFlags eFlags, SvNumberFormatter* pNFmtr ) const
679 {
680 	const SwBoxAutoFmt& rChg = GetBoxFmt( nPos );
681 
682 	if( UPDATE_CHAR & eFlags )
683 	{
684 		if( IsFont() )
685 		{
686 			rSet.Put( rChg.GetFont() );
687 			rSet.Put( rChg.GetHeight() );
688 			rSet.Put( rChg.GetWeight() );
689 			rSet.Put( rChg.GetPosture() );
690             // #103065# do not insert empty CJK font
691             const SvxFontItem& rCJKFont = rChg.GetCJKFont();
692             if( rCJKFont.GetStyleName().Len() )
693             {
694                 rSet.Put( rChg.GetCJKFont() );
695                 rSet.Put( rChg.GetCJKHeight() );
696                 rSet.Put( rChg.GetCJKWeight() );
697                 rSet.Put( rChg.GetCJKPosture() );
698             }
699             else
700             {
701                 rSet.Put( rChg.GetHeight(), RES_CHRATR_CJK_FONTSIZE );
702                 rSet.Put( rChg.GetWeight(), RES_CHRATR_CJK_WEIGHT );
703                 rSet.Put( rChg.GetPosture(), RES_CHRATR_CJK_POSTURE );
704             }
705             // #103065# do not insert empty CTL font
706             const SvxFontItem& rCTLFont = rChg.GetCTLFont();
707             if( rCTLFont.GetStyleName().Len() )
708             {
709                 rSet.Put( rChg.GetCTLFont() );
710                 rSet.Put( rChg.GetCTLHeight() );
711                 rSet.Put( rChg.GetCTLWeight() );
712                 rSet.Put( rChg.GetCTLPosture() );
713             }
714             else
715             {
716                 rSet.Put( rChg.GetHeight(), RES_CHRATR_CTL_FONTSIZE );
717                 rSet.Put( rChg.GetWeight(), RES_CHRATR_CTL_WEIGHT );
718                 rSet.Put( rChg.GetPosture(), RES_CHRATR_CTL_POSTURE );
719             }
720 			rSet.Put( rChg.GetUnderline() );
721 			rSet.Put( rChg.GetOverline() );
722 			rSet.Put( rChg.GetCrossedOut() );
723 			rSet.Put( rChg.GetContour() );
724 			rSet.Put( rChg.GetShadowed() );
725 			rSet.Put( rChg.GetColor() );
726 		}
727 		if( IsJustify() )
728 			rSet.Put( rChg.GetAdjust() );
729 	}
730 
731 	if( UPDATE_BOX & eFlags )
732 	{
733 		if( IsFrame() )
734         {
735 			rSet.Put( rChg.GetBox() );
736 // FIXME - uncomment the lines to put the diagonal line items
737 //            rSet.Put( rChg.GetTLBR() );
738 //            rSet.Put( rChg.GetBLTR() );
739         }
740 		if( IsBackground() )
741 			rSet.Put( rChg.GetBackground() );
742 
743 		if( IsValueFormat() && pNFmtr )
744 		{
745 			String sFmt; LanguageType eLng, eSys;
746 			rChg.GetValueFormat( sFmt, eLng, eSys );
747 			if( sFmt.Len() )
748 			{
749                 short nType;
750                 sal_Bool bNew;
751                 xub_StrLen nCheckPos;
752                 sal_uInt32 nKey = pNFmtr->GetIndexPuttingAndConverting( sFmt, eLng,
753                         eSys, nType, bNew, nCheckPos);
754 				rSet.Put( SwTblBoxNumFormat( nKey ));
755 			}
756 			else
757 				rSet.ClearItem( RES_BOXATR_FORMAT );
758 		}
759 	}
760 
761 	// den Rest koennen wir nicht, Calc spezifisch
762 }
763 
764 
Load(SvStream & rStream,const SwAfVersions & rVersions)765 sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions )
766 {
767 	sal_Bool	bRet = sal_True;
768 	sal_uInt16	nVal = 0;
769 	rStream >> nVal;
770 	bRet = 0 == rStream.GetError();
771 
772 	if( bRet && (nVal == AUTOFORMAT_DATA_ID_X ||
773 			(AUTOFORMAT_DATA_ID_504 <= nVal && nVal <= AUTOFORMAT_DATA_ID)) )
774 	{
775 		sal_Bool b;
776         // --- from 680/dr25 on: #21549# store strings as UTF-8
777         CharSet eCharSet = (nVal >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
778         rStream.ReadByteString( aName, eCharSet );
779 		if( AUTOFORMAT_DATA_ID_552 <= nVal )
780 		{
781 			rStream >> nStrResId;
782 			sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN + nStrResId;
783 			if( RID_SVXSTR_TBLAFMT_BEGIN <= nId &&
784 				nId < RID_SVXSTR_TBLAFMT_END )
785 			{
786 				aName = SVX_RESSTR( nId );
787 			}
788 			else
789 				nStrResId = USHRT_MAX;
790 		}
791 		rStream >> b; bInclFont = b;
792 		rStream >> b; bInclJustify = b;
793 		rStream >> b; bInclFrame = b;
794 		rStream >> b; bInclBackground = b;
795 		rStream >> b; bInclValueFormat = b;
796 		rStream >> b; bInclWidthHeight = b;
797 
798 		bRet = 0 == rStream.GetError();
799 
800 		for( sal_uInt8 i = 0; i < 16; ++i )
801 		{
802 			SwBoxAutoFmt* pFmt = new SwBoxAutoFmt;
803 			bRet = pFmt->Load( rStream, rVersions, nVal );
804 			if( bRet )
805 				aBoxAutoFmt[ i ] = pFmt;
806 			else
807 			{
808 				delete pFmt;
809 				break;
810 			}
811 		}
812 	}
813 	return bRet;
814 }
815 
816 #ifdef READ_OLDVERS
817 
LoadOld(SvStream & rStream,sal_uInt16 aLoadVer[])818 sal_Bool SwTableAutoFmt::LoadOld( SvStream& rStream, sal_uInt16 aLoadVer[] )
819 {
820 	sal_Bool	bRet = sal_True;
821 	sal_uInt16	nVal = 0;
822 	rStream >> nVal;
823 	bRet = 0 == rStream.GetError();
824 
825 	if( bRet && ( AUTOFORMAT_OLD_DATA_ID == nVal ))
826 	{
827 		sal_Bool b;
828 		rStream.ReadByteString( aName, rStream.GetStreamCharSet() );
829 		rStream >> b; bInclFont = b;
830 		rStream >> b; bInclJustify = b;
831 		rStream >> b; bInclFrame = b;
832 		rStream >> b; bInclBackground = b;
833 		bRet = (rStream.GetError() == 0);
834 
835 		for( int i = 0; i < 16; i++)
836 		{
837 			SwBoxAutoFmt* pFmt = new SwBoxAutoFmt;
838 			bRet = pFmt->LoadOld( rStream, aLoadVer );
839 			if( bRet )
840 				aBoxAutoFmt[ i ] = pFmt;
841 			else
842 			{
843 				delete pFmt;
844 				break;
845 			}
846 		}
847 	}
848 	return bRet;
849 }
850 #endif
851 
852 
Save(SvStream & rStream) const853 sal_Bool SwTableAutoFmt::Save( SvStream& rStream ) const
854 {
855 	sal_uInt16 nVal = AUTOFORMAT_DATA_ID;
856 	sal_Bool b;
857 	rStream << nVal;
858     // --- from 680/dr25 on: #21549# store strings as UTF-8
859     rStream.WriteByteString( aName, RTL_TEXTENCODING_UTF8 );
860 	rStream << nStrResId;
861 	rStream << ( b = bInclFont );
862 	rStream << ( b = bInclJustify );
863 	rStream << ( b = bInclFrame );
864 	rStream << ( b = bInclBackground );
865 	rStream << ( b = bInclValueFormat );
866 	rStream << ( b = bInclWidthHeight );
867 
868 	sal_Bool bRet = 0 == rStream.GetError();
869 
870 	for( int i = 0; bRet && i < 16; ++i )
871 	{
872 		SwBoxAutoFmt* pFmt = aBoxAutoFmt[ i ];
873 		if( !pFmt )		// nicht gesetzt -> default schreiben
874 		{
875 			// falls noch nicht vorhanden:
876 			if( !pDfltBoxAutoFmt )
877 				pDfltBoxAutoFmt = new SwBoxAutoFmt;
878 			pFmt = pDfltBoxAutoFmt;
879 		}
880 		bRet = pFmt->Save( rStream );
881 	}
882 	return bRet;
883 }
884 
885 
SwTableAutoFmtTbl()886 SwTableAutoFmtTbl::SwTableAutoFmtTbl()
887 {
888 	String sNm;
889 	SwTableAutoFmt* pNew = new SwTableAutoFmt(
890 							SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm ) );
891 
892 	SwBoxAutoFmt aNew;
893 
894 	sal_uInt8 i;
895 
896 	Color aColor( COL_BLUE );
897     SvxBrushItem aBrushItem( aColor, RES_BACKGROUND );
898 	aNew.SetBackground( aBrushItem );
899     aNew.SetColor( SvxColorItem(Color( COL_WHITE ), RES_CHRATR_COLOR) );
900 
901 	for( i = 0; i < 4; ++i )
902 		pNew->SetBoxFmt( aNew, i );
903 
904 	// 70% Grau
905 	aBrushItem.SetColor( RGB_COLORDATA( 0x4d, 0x4d, 0x4d ) );
906 	aNew.SetBackground( aBrushItem );
907 	for( i = 4; i <= 12; i += 4 )
908 		pNew->SetBoxFmt( aNew, i );
909 
910 	// 20% Grau
911 	aBrushItem.SetColor( RGB_COLORDATA( 0xcc, 0xcc, 0xcc ) );
912 	aNew.SetBackground( aBrushItem );
913 	aColor.SetColor( COL_BLACK );
914     aNew.SetColor( SvxColorItem( aColor, RES_CHRATR_COLOR) );
915 	for( i = 7; i <= 15; i += 4 )
916 		pNew->SetBoxFmt( aNew, i );
917 	for( i = 13; i <= 14; ++i )
918 		pNew->SetBoxFmt( aNew, i );
919 
920 	aBrushItem.SetColor( Color( COL_WHITE ) );
921 	aNew.SetBackground( aBrushItem );
922 	for( i = 5; i <= 6; ++i )
923 		pNew->SetBoxFmt( aNew, i );
924 	for( i = 9; i <= 10; ++i )
925 		pNew->SetBoxFmt( aNew, i );
926 
927 
928     SvxBoxItem aBox( RES_BOX );
929 	aBox.SetDistance( 55 );
930 	SvxBorderLine aLn( &aColor, DEF_LINE_WIDTH_0 );
931 	aBox.SetLine( &aLn, BOX_LINE_LEFT );
932 	aBox.SetLine( &aLn, BOX_LINE_BOTTOM );
933 
934 	for( i = 0; i <= 15; ++i )
935 	{
936 		aBox.SetLine( i <= 3 ? &aLn : 0, BOX_LINE_TOP );
937 		aBox.SetLine( (3 == ( i & 3 )) ? &aLn : 0, BOX_LINE_RIGHT );
938 		((SwBoxAutoFmt&)pNew->GetBoxFmt( i )).SetBox( aBox );
939 	}
940 
941 	Insert( pNew, Count() );
942 }
943 
Load()944 sal_Bool SwTableAutoFmtTbl::Load()
945 {
946 	sal_Bool bRet = sal_False;
947 	String sNm( String::CreateFromAscii(
948 				RTL_CONSTASCII_STRINGPARAM( sAutoTblFmtName )));
949 	SvtPathOptions aOpt;
950 	if( aOpt.SearchFile( sNm, SvtPathOptions::PATH_USERCONFIG ))
951 	{
952 		SfxMedium aStream( sNm, STREAM_STD_READ, sal_True );
953 		bRet = Load( *aStream.GetInStream() );
954 	}
955 	else
956 		bRet = sal_False;
957 	return bRet;
958 }
959 
Save() const960 sal_Bool SwTableAutoFmtTbl::Save() const
961 {
962 	SvtPathOptions aPathOpt;
963     String sNm( aPathOpt.GetUserConfigPath() );
964 	sNm += INET_PATH_TOKEN;
965 	sNm.AppendAscii( RTL_CONSTASCII_STRINGPARAM( sAutoTblFmtName ));
966 	SfxMedium aStream(sNm, STREAM_STD_WRITE, sal_True );
967 	return Save( *aStream.GetOutStream() ) && aStream.Commit();
968 }
969 
Load(SvStream & rStream)970 sal_Bool SwTableAutoFmtTbl::Load( SvStream& rStream )
971 {
972 	sal_Bool bRet = 0 == rStream.GetError();
973 	if (bRet)
974 	{
975 		// Achtung hier muss ein allgemeiner Header gelesen werden
976 		sal_uInt16 nVal = 0;
977 		rStream >> nVal;
978 		bRet = 0 == rStream.GetError();
979 
980 		if( bRet )
981 		{
982 			SwAfVersions aVersions;
983 
984 			if( nVal == AUTOFORMAT_ID_358 ||
985 					(AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
986 			{
987 				sal_uInt16 nFileVers = SOFFICE_FILEFORMAT_40;
988 				sal_uInt8 nChrSet, nCnt;
989 				long nPos = rStream.Tell();
990 				rStream >> nCnt >> nChrSet;
991 //				if( 4 <= nCnt )
992 //					rStream >> nFileVers;
993 				if( rStream.Tell() != sal_uLong(nPos + nCnt) )
994 				{
995 					ASSERT( sal_False, "The header contains more / newer data" );
996 					rStream.Seek( nPos + nCnt );
997 				}
998 				rStream.SetStreamCharSet( (CharSet)nChrSet );
999 				rStream.SetVersion( nFileVers );
1000 			}
1001 
1002 			if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X ||
1003 					(AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1004 			{
1005 				aVersions.Load( rStream, nVal );		// Item-Versionen
1006 
1007 				SwTableAutoFmt* pNew;
1008 				sal_uInt16 nAnz = 0;
1009 				rStream >> nAnz;
1010 
1011 				bRet = 0 == rStream.GetError();
1012 
1013 				for( sal_uInt16 i = 0; i < nAnz; ++i )
1014 				{
1015 					pNew = new SwTableAutoFmt( aEmptyStr );
1016 					bRet = pNew->Load( rStream, aVersions );
1017 					if( bRet )
1018 					{
1019 						Insert( pNew, Count() );
1020 					}
1021 					else
1022 					{
1023 						delete pNew;
1024 						break;
1025 					}
1026 				}
1027 			}
1028 #ifdef READ_OLDVERS
1029 			else if( AUTOFORMAT_OLD_ID == nVal || AUTOFORMAT_OLD_ID1 == nVal )
1030 			{
1031 				SwTableAutoFmt* pNew;
1032 				sal_uInt16 nAnz = 0;
1033 				rStream >> nAnz;
1034 
1035 				sal_uInt16 aArr[ 12 ];
1036 				memset( aArr, 0, 12 * sizeof( sal_uInt16 ) );
1037 				if( AUTOFORMAT_OLD_ID1 == nVal )
1038 					for( sal_uInt16 n = 0; n < 12; ++n )
1039 						rStream >> aArr[ n ];
1040 
1041 				bRet = 0 == rStream.GetError();
1042 
1043 				for( sal_uInt16 i = 0; i < nAnz; ++i )
1044 				{
1045 					pNew = new SwTableAutoFmt( aEmptyStr );
1046 					bRet = pNew->LoadOld( rStream, aArr );
1047 					if( bRet )
1048 					{
1049 						Insert( pNew, Count() );
1050 					}
1051 					else
1052 					{
1053 						delete pNew;
1054 						break;
1055 					}
1056 				}
1057 			}
1058 #endif
1059 		}
1060 	}
1061 	return bRet;
1062 }
1063 
1064 
Save(SvStream & rStream) const1065 sal_Bool SwTableAutoFmtTbl::Save( SvStream& rStream ) const
1066 {
1067 	sal_Bool bRet = 0 == rStream.GetError();
1068 	if (bRet)
1069 	{
1070 		rStream.SetVersion( SOFFICE_FILEFORMAT_40 );
1071 
1072 		// Achtung hier muss ein allgemeiner Header gespeichert werden
1073 		sal_uInt16 nVal = AUTOFORMAT_ID;
1074 		rStream << nVal
1075 				<< (sal_uInt8)2 		// Anzahl von Zeichen des Headers incl. diesem
1076 				<< (sal_uInt8)GetStoreCharSet( ::gsl_getSystemTextEncoding() );
1077 //				<< (sal_uInt8)4 		// Anzahl von Zeichen des Headers incl. diesem
1078 //				<< (sal_uInt8)::GetSystemCharSet()
1079 //				<< (UNIT16)SOFFICE_FILEFORMAT_NOW;
1080 		bRet = 0 == rStream.GetError();
1081 
1082 		//-----------------------------------------------------------
1083 		// die VersionsNummer fuer alle Attribute schreiben
1084 		(*this)[ 0 ]->GetBoxFmt( 0 ).SaveVersionNo( rStream );
1085 
1086 		rStream << (sal_uInt16)(Count() - 1);
1087 		bRet = 0 == rStream.GetError();
1088 
1089 		for( sal_uInt16 i = 1; bRet && i < Count(); ++i )
1090 		{
1091 			SwTableAutoFmt* pFmt = (*this)[ i ];
1092 			bRet = pFmt->Save( rStream );
1093 		}
1094 	}
1095 	rStream.Flush();
1096 	return bRet;
1097 }
1098