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