LCOV - code coverage report
Current view: top level - sc/source/core/tool - autoform.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 446 622 71.7 %
Date: 2015-06-13 12:38:46 Functions: 36 46 78.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "autoform.hxx"
      21             : 
      22             : #include <sfx2/app.hxx>
      23             : #include <sfx2/docfile.hxx>
      24             : #include <unotools/pathoptions.hxx>
      25             : #include <svl/itemset.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <vcl/outdev.hxx>
      28             : #include <svx/dialmgr.hxx>
      29             : #include <svx/dialogs.hrc>
      30             : #include <editeng/langitem.hxx>
      31             : #include <tools/urlobj.hxx>
      32             : #include <unotools/transliterationwrapper.hxx>
      33             : #include <tools/tenccvt.hxx>
      34             : 
      35             : #include "globstr.hrc"
      36             : #include "document.hxx"
      37             : 
      38             : /*
      39             :  * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST
      40             :  * be synchronized with Writer's SwTableAutoFmtTbl sw/source/core/doc/tblafmt.cxx
      41             :  */
      42             : 
      43             : const sal_Char *linker_dummy = "";
      44             : 
      45             : static const sal_Char sAutoTblFmtName[] = "autotbl.fmt";
      46             : 
      47             : // till SO5PF
      48             : const sal_uInt16 AUTOFORMAT_ID_X        = 9501;
      49             : const sal_uInt16 AUTOFORMAT_ID_358      = 9601;
      50             : const sal_uInt16 AUTOFORMAT_DATA_ID_X   = 9502;
      51             : 
      52             : // from SO5 on
      53             : // in following versions the value of the IDs must be higher
      54             : const sal_uInt16 AUTOFORMAT_ID_504      = 9801;
      55             : const sal_uInt16 AUTOFORMAT_DATA_ID_504 = 9802;
      56             : 
      57             : const sal_uInt16 AUTOFORMAT_DATA_ID_552 = 9902;
      58             : 
      59             : // --- from 641 on: CJK and CTL font settings
      60             : const sal_uInt16 AUTOFORMAT_DATA_ID_641 = 10002;
      61             : 
      62             : // --- from 680/dr14 on: diagonal frame lines
      63             : const sal_uInt16 AUTOFORMAT_ID_680DR14      = 10011;
      64             : const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14 = 10012;
      65             : 
      66             : // --- from 680/dr25 on: store strings as UTF-8
      67             : const sal_uInt16 AUTOFORMAT_ID_680DR25      = 10021;
      68             : 
      69             : // --- from DEV300/overline2 on: overline support
      70             : const sal_uInt16 AUTOFORMAT_ID_300OVRLN      = 10031;
      71             : const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN = 10032;
      72             : 
      73             : // --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc)
      74             : const sal_uInt16 AUTOFORMAT_ID_31005      = 10041;
      75             : const sal_uInt16 AUTOFORMAT_DATA_ID_31005 = 10042;
      76             : 
      77             : // current version
      78             : const sal_uInt16 AUTOFORMAT_ID          = AUTOFORMAT_ID_31005;
      79             : const sal_uInt16 AUTOFORMAT_DATA_ID     = AUTOFORMAT_DATA_ID_31005;
      80             : 
      81             : namespace
      82             : {
      83             :     /// Read an AutoFormatSwBlob from stream.
      84           0 :     SvStream& operator>>(SvStream &stream, AutoFormatSwBlob &blob)
      85             :     {
      86           0 :         blob.Reset();
      87             : 
      88           0 :         sal_uInt64 endOfBlob = 0;
      89           0 :         stream.ReadUInt64( endOfBlob );
      90             : 
      91           0 :         const sal_uInt64 currentPosition = stream.Tell();
      92           0 :         const sal_uInt64 blobSize = endOfBlob - currentPosition;
      93             :         // A zero-size indicates an empty blob. This happens when Calc creates a new autoformat,
      94             :         // since it (naturally) doesn't have any writer-specific data to write.
      95           0 :         if (blobSize)
      96             :         {
      97           0 :             blob.pData = new sal_uInt8[blobSize];
      98           0 :             blob.size = static_cast<sal_Size>(blobSize);
      99           0 :             stream.Read(blob.pData, blob.size);
     100             :         }
     101             : 
     102           0 :         return stream;
     103             :     }
     104             : 
     105             :     /// Write an AutoFormatSwBlob to stream.
     106         563 :     SvStream& WriteAutoFormatSwBlob(SvStream &stream, AutoFormatSwBlob &blob)
     107             :     {
     108         563 :         const sal_uInt64 endOfBlob = stream.Tell() + sizeof(sal_uInt64) + blob.size;
     109         563 :         stream.WriteUInt64( endOfBlob );
     110         563 :         if (blob.size)
     111           0 :             stream.Write(blob.pData, blob.size);
     112             : 
     113         563 :         return stream;
     114             :     }
     115             : }
     116             : 
     117           2 : ScAfVersions::ScAfVersions() :
     118             :     nFontVersion(0),
     119             :     nFontHeightVersion(0),
     120             :     nWeightVersion(0),
     121             :     nPostureVersion(0),
     122             :     nUnderlineVersion(0),
     123             :     nOverlineVersion(0),
     124             :     nCrossedOutVersion(0),
     125             :     nContourVersion(0),
     126             :     nShadowedVersion(0),
     127             :     nColorVersion(0),
     128             :     nBoxVersion(0),
     129             :     nLineVersion(0),
     130             :     nBrushVersion(0),
     131             :     nAdjustVersion(0),
     132             :     nHorJustifyVersion(0),
     133             :     nVerJustifyVersion(0),
     134             :     nOrientationVersion(0),
     135             :     nMarginVersion(0),
     136             :     nBoolVersion(0),
     137             :     nInt32Version(0),
     138             :     nRotateModeVersion(0),
     139           2 :     nNumFmtVersion(0)
     140             : {
     141           2 : }
     142             : 
     143           2 : void ScAfVersions::Load( SvStream& rStream, sal_uInt16 nVer )
     144             : {
     145           2 :     rStream.ReadUInt16( nFontVersion );
     146           2 :     rStream.ReadUInt16( nFontHeightVersion );
     147           2 :     rStream.ReadUInt16( nWeightVersion );
     148           2 :     rStream.ReadUInt16( nPostureVersion );
     149           2 :     rStream.ReadUInt16( nUnderlineVersion );
     150           2 :     if ( nVer >= AUTOFORMAT_ID_300OVRLN )
     151           0 :         rStream.ReadUInt16( nOverlineVersion );
     152           2 :     rStream.ReadUInt16( nCrossedOutVersion );
     153           2 :     rStream.ReadUInt16( nContourVersion );
     154           2 :     rStream.ReadUInt16( nShadowedVersion );
     155           2 :     rStream.ReadUInt16( nColorVersion );
     156           2 :     rStream.ReadUInt16( nBoxVersion );
     157           2 :     if ( nVer >= AUTOFORMAT_ID_680DR14 )
     158           2 :         rStream.ReadUInt16( nLineVersion );
     159           2 :     rStream.ReadUInt16( nBrushVersion );
     160           2 :     rStream.ReadUInt16( nAdjustVersion );
     161           2 :     if (nVer >= AUTOFORMAT_ID_31005)
     162           0 :         rStream >> swVersions;
     163           2 :     rStream.ReadUInt16( nHorJustifyVersion );
     164           2 :     rStream.ReadUInt16( nVerJustifyVersion );
     165           2 :     rStream.ReadUInt16( nOrientationVersion );
     166           2 :     rStream.ReadUInt16( nMarginVersion );
     167           2 :     rStream.ReadUInt16( nBoolVersion );
     168           2 :     if ( nVer >= AUTOFORMAT_ID_504 )
     169             :     {
     170           2 :         rStream.ReadUInt16( nInt32Version );
     171           2 :         rStream.ReadUInt16( nRotateModeVersion );
     172             :     }
     173           2 :     rStream.ReadUInt16( nNumFmtVersion );
     174           2 : }
     175             : 
     176           2 : void ScAfVersions::Write(SvStream& rStream, sal_uInt16 fileVersion)
     177             : {
     178           2 :     rStream.WriteUInt16( SvxFontItem(ATTR_FONT).GetVersion(fileVersion) );
     179           2 :     rStream.WriteUInt16( SvxFontHeightItem(240, 100, ATTR_FONT_HEIGHT).GetVersion(fileVersion) );
     180           2 :     rStream.WriteUInt16( SvxWeightItem(WEIGHT_NORMAL, ATTR_FONT_WEIGHT).GetVersion(fileVersion) );
     181           2 :     rStream.WriteUInt16( SvxPostureItem(ITALIC_NONE, ATTR_FONT_POSTURE).GetVersion(fileVersion) );
     182           2 :     rStream.WriteUInt16( SvxUnderlineItem(UNDERLINE_NONE, ATTR_FONT_UNDERLINE).GetVersion(fileVersion) );
     183           2 :     rStream.WriteUInt16( SvxOverlineItem(UNDERLINE_NONE, ATTR_FONT_OVERLINE).GetVersion(fileVersion) );
     184           2 :     rStream.WriteUInt16( SvxCrossedOutItem(STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT).GetVersion(fileVersion) );
     185           2 :     rStream.WriteUInt16( SvxContourItem(false, ATTR_FONT_CONTOUR).GetVersion(fileVersion) );
     186           2 :     rStream.WriteUInt16( SvxShadowedItem(false, ATTR_FONT_SHADOWED).GetVersion(fileVersion) );
     187           2 :     rStream.WriteUInt16( SvxColorItem(ATTR_FONT_COLOR).GetVersion(fileVersion) );
     188           2 :     rStream.WriteUInt16( SvxBoxItem(ATTR_BORDER).GetVersion(fileVersion) );
     189           2 :     rStream.WriteUInt16( SvxLineItem(SID_FRAME_LINESTYLE).GetVersion(fileVersion) );
     190           2 :     rStream.WriteUInt16( SvxBrushItem(ATTR_BACKGROUND).GetVersion(fileVersion) );
     191             : 
     192           2 :     rStream.WriteUInt16( SvxAdjustItem(SVX_ADJUST_LEFT, 0).GetVersion(fileVersion) );
     193           2 :     if (fileVersion >= SOFFICE_FILEFORMAT_50)
     194           2 :         WriteAutoFormatSwBlob( rStream, swVersions );
     195             : 
     196           2 :     rStream.WriteUInt16( SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY).GetVersion(fileVersion) );
     197           2 :     rStream.WriteUInt16( SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY).GetVersion(fileVersion) );
     198           2 :     rStream.WriteUInt16( SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0).GetVersion(fileVersion) );
     199           2 :     rStream.WriteUInt16( SvxMarginItem(ATTR_MARGIN).GetVersion(fileVersion) );
     200           2 :     rStream.WriteUInt16( SfxBoolItem(ATTR_LINEBREAK).GetVersion(fileVersion) );
     201           2 :     rStream.WriteUInt16( SfxInt32Item(ATTR_ROTATE_VALUE).GetVersion(fileVersion) );
     202           2 :     rStream.WriteUInt16( SvxRotateModeItem(SVX_ROTATE_MODE_STANDARD,0).GetVersion(fileVersion) );
     203             : 
     204           2 :     rStream.WriteUInt16( 0 );       // Num-Format
     205           2 : }
     206             : 
     207         560 : ScAutoFormatDataField::ScAutoFormatDataField() :
     208             :     aFont( ATTR_FONT ),
     209             :     aHeight( 240, 100, ATTR_FONT_HEIGHT ),
     210             :     aWeight( WEIGHT_NORMAL, ATTR_FONT_WEIGHT ),
     211             :     aPosture( ITALIC_NONE, ATTR_FONT_POSTURE ),
     212             : 
     213             :     aCJKFont( ATTR_CJK_FONT ),
     214             :     aCJKHeight( 240, 100, ATTR_CJK_FONT_HEIGHT ),
     215             :     aCJKWeight( WEIGHT_NORMAL, ATTR_CJK_FONT_WEIGHT ),
     216             :     aCJKPosture( ITALIC_NONE, ATTR_CJK_FONT_POSTURE ),
     217             : 
     218             :     aCTLFont( ATTR_CTL_FONT ),
     219             :     aCTLHeight( 240, 100, ATTR_CTL_FONT_HEIGHT ),
     220             :     aCTLWeight( WEIGHT_NORMAL, ATTR_CTL_FONT_WEIGHT ),
     221             :     aCTLPosture( ITALIC_NONE, ATTR_CTL_FONT_POSTURE ),
     222             : 
     223             :     aUnderline( UNDERLINE_NONE,ATTR_FONT_UNDERLINE ),
     224             :     aOverline( UNDERLINE_NONE,ATTR_FONT_OVERLINE ),
     225             :     aCrossedOut( STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ),
     226             :     aContour( false, ATTR_FONT_CONTOUR ),
     227             :     aShadowed( false, ATTR_FONT_SHADOWED ),
     228             :     aColor( ATTR_FONT_COLOR ),
     229             :     aBox( ATTR_BORDER ),
     230             :     aTLBR( ATTR_BORDER_TLBR ),
     231             :     aBLTR( ATTR_BORDER_BLTR ),
     232             :     aBackground( ATTR_BACKGROUND ),
     233             :     aAdjust( SVX_ADJUST_LEFT, 0 ),
     234             :     aHorJustify( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ),
     235             :     aVerJustify( SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY ),
     236             :     aMargin( ATTR_MARGIN ),
     237             :     aLinebreak( ATTR_LINEBREAK ),
     238             :     aRotateAngle( ATTR_ROTATE_VALUE ),
     239         560 :     aRotateMode( SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE )
     240             : {
     241         560 : }
     242             : 
     243          32 : ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField& rCopy ) :
     244             :     aFont( rCopy.aFont ),
     245             :     aHeight( rCopy.aHeight ),
     246             :     aWeight( rCopy.aWeight ),
     247             :     aPosture( rCopy.aPosture ),
     248             :     aCJKFont( rCopy.aCJKFont ),
     249             :     aCJKHeight( rCopy.aCJKHeight ),
     250             :     aCJKWeight( rCopy.aCJKWeight ),
     251             :     aCJKPosture( rCopy.aCJKPosture ),
     252             :     aCTLFont( rCopy.aCTLFont ),
     253             :     aCTLHeight( rCopy.aCTLHeight ),
     254             :     aCTLWeight( rCopy.aCTLWeight ),
     255             :     aCTLPosture( rCopy.aCTLPosture ),
     256             :     aUnderline( rCopy.aUnderline ),
     257             :     aOverline( rCopy.aOverline ),
     258             :     aCrossedOut( rCopy.aCrossedOut ),
     259             :     aContour( rCopy.aContour ),
     260             :     aShadowed( rCopy.aShadowed ),
     261             :     aColor( rCopy.aColor ),
     262             :     aBox( rCopy.aBox ),
     263             :     aTLBR( rCopy.aTLBR ),
     264             :     aBLTR( rCopy.aBLTR ),
     265             :     aBackground( rCopy.aBackground ),
     266             :     aAdjust( rCopy.aAdjust ),
     267             :     aHorJustify( rCopy.aHorJustify ),
     268             :     aVerJustify( rCopy.aVerJustify ),
     269             :     aStacked( rCopy.aStacked ),
     270             :     aMargin( rCopy.aMargin ),
     271             :     aLinebreak( rCopy.aLinebreak ),
     272             :     aRotateAngle( rCopy.aRotateAngle ),
     273             :     aRotateMode( rCopy.aRotateMode ),
     274          32 :     aNumFormat( rCopy.aNumFormat )
     275             : {
     276          32 : }
     277             : 
     278         592 : ScAutoFormatDataField::~ScAutoFormatDataField()
     279             : {
     280         592 : }
     281             : 
     282         512 : void ScAutoFormatDataField::SetAdjust( const SvxAdjustItem& rAdjust )
     283             : {
     284         512 :     aAdjust.SetAdjust( rAdjust.GetAdjust() );
     285         512 :     aAdjust.SetOneWord( rAdjust.GetOneWord() );
     286         512 :     aAdjust.SetLastBlock( rAdjust.GetLastBlock() );
     287         512 : }
     288             : 
     289             : #define READ( aItem, ItemType, nVers )      \
     290             :     pNew = aItem.Create( rStream, nVers );  \
     291             :     aItem = *static_cast<ItemType*>(pNew);  \
     292             :     delete pNew;
     293             : 
     294         512 : bool ScAutoFormatDataField::Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer )
     295             : {
     296             :     SfxPoolItem* pNew;
     297         512 :     SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0 );
     298             : 
     299         512 :     READ( aFont,        SvxFontItem,        rVersions.nFontVersion)
     300         512 :     READ( aHeight,      SvxFontHeightItem,  rVersions.nFontHeightVersion)
     301         512 :     READ( aWeight,      SvxWeightItem,      rVersions.nWeightVersion)
     302         512 :     READ( aPosture,     SvxPostureItem,     rVersions.nPostureVersion)
     303             :     // --- from 641 on: CJK and CTL font settings
     304         512 :     if( AUTOFORMAT_DATA_ID_641 <= nVer )
     305             :     {
     306         512 :         READ( aCJKFont,     SvxFontItem,        rVersions.nFontVersion)
     307         512 :         READ( aCJKHeight,   SvxFontHeightItem,  rVersions.nFontHeightVersion)
     308         512 :         READ( aCJKWeight,   SvxWeightItem,      rVersions.nWeightVersion)
     309         512 :         READ( aCJKPosture,  SvxPostureItem,     rVersions.nPostureVersion)
     310         512 :         READ( aCTLFont,     SvxFontItem,        rVersions.nFontVersion)
     311         512 :         READ( aCTLHeight,   SvxFontHeightItem,  rVersions.nFontHeightVersion)
     312         512 :         READ( aCTLWeight,   SvxWeightItem,      rVersions.nWeightVersion)
     313         512 :         READ( aCTLPosture,  SvxPostureItem,     rVersions.nPostureVersion)
     314             :     }
     315         512 :     READ( aUnderline,   SvxUnderlineItem,   rVersions.nUnderlineVersion)
     316         512 :     if ( nVer >= AUTOFORMAT_DATA_ID_300OVRLN )
     317             :     {
     318           0 :         READ( aOverline,    SvxOverlineItem,    rVersions.nOverlineVersion)
     319             :     }
     320         512 :     READ( aCrossedOut,  SvxCrossedOutItem,  rVersions.nCrossedOutVersion)
     321         512 :     READ( aContour,     SvxContourItem,     rVersions.nContourVersion)
     322         512 :     READ( aShadowed,    SvxShadowedItem,    rVersions.nShadowedVersion)
     323         512 :     READ( aColor,       SvxColorItem,       rVersions.nColorVersion)
     324         512 :     READ( aBox,         SvxBoxItem,         rVersions.nBoxVersion)
     325             : 
     326             :     // --- from 680/dr14 on: diagonal frame lines
     327         512 :     if( AUTOFORMAT_DATA_ID_680DR14 <= nVer )
     328             :     {
     329         512 :         READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
     330         512 :         READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
     331             :     }
     332             : 
     333         512 :     READ( aBackground,  SvxBrushItem,       rVersions.nBrushVersion)
     334             : 
     335         512 :     pNew = aAdjust.Create( rStream, rVersions.nAdjustVersion );
     336         512 :     SetAdjust( *static_cast<SvxAdjustItem*>(pNew) );
     337         512 :     delete pNew;
     338             : 
     339         512 :     if (nVer >= AUTOFORMAT_DATA_ID_31005)
     340           0 :         rStream >> m_swFields;
     341             : 
     342         512 :     READ( aHorJustify,   SvxHorJustifyItem,  rVersions.nHorJustifyVersion)
     343         512 :     READ( aVerJustify,   SvxVerJustifyItem,  rVersions.nVerJustifyVersion)
     344         512 :     READ( aOrientation,  SvxOrientationItem, rVersions.nOrientationVersion)
     345         512 :     READ( aMargin,       SvxMarginItem,      rVersions.nMarginVersion)
     346             : 
     347         512 :     pNew = aLinebreak.Create( rStream, rVersions.nBoolVersion );
     348         512 :     SetLinebreak( *static_cast<SfxBoolItem*>(pNew) );
     349         512 :     delete pNew;
     350             : 
     351         512 :     if ( nVer >= AUTOFORMAT_DATA_ID_504 )
     352             :     {
     353         512 :         pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
     354         512 :         SetRotateAngle( *static_cast<SfxInt32Item*>(pNew) );
     355         512 :         delete pNew;
     356         512 :         pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
     357         512 :         SetRotateMode( *static_cast<SvxRotateModeItem*>(pNew) );
     358         512 :         delete pNew;
     359             :     }
     360             : 
     361         512 :     if( 0 == rVersions.nNumFmtVersion )
     362             :     {
     363             :         // --- from 680/dr25 on: store strings as UTF-8
     364         512 :         rtl_TextEncoding eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
     365         512 :         aNumFormat.Load( rStream, eCharSet );
     366             :     }
     367             : 
     368             :     //  adjust charset in font
     369         512 :     rtl_TextEncoding eSysSet = osl_getThreadTextEncoding();
     370         512 :     rtl_TextEncoding eSrcSet = rStream.GetStreamCharSet();
     371         512 :     if( eSrcSet != eSysSet && aFont.GetCharSet() == eSrcSet )
     372         512 :         aFont.SetCharSet(eSysSet);
     373             : 
     374         512 :     aStacked.SetValue( aOrientation.IsStacked() );
     375         512 :     aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
     376             : 
     377         512 :     return (rStream.GetError() == 0);
     378             : }
     379             : 
     380         528 : bool ScAutoFormatDataField::Save( SvStream& rStream, sal_uInt16 fileVersion )
     381             : {
     382         528 :     SvxOrientationItem aOrientation( aRotateAngle.GetValue(), aStacked.GetValue(), 0 );
     383             : 
     384         528 :     aFont.Store         ( rStream, aFont.GetVersion( fileVersion ) );
     385         528 :     aHeight.Store       ( rStream, aHeight.GetVersion( fileVersion ) );
     386         528 :     aWeight.Store       ( rStream, aWeight.GetVersion( fileVersion ) );
     387         528 :     aPosture.Store      ( rStream, aPosture.GetVersion( fileVersion ) );
     388             :     // --- from 641 on: CJK and CTL font settings
     389         528 :     aCJKFont.Store      ( rStream, aCJKFont.GetVersion( fileVersion ) );
     390         528 :     aCJKHeight.Store    ( rStream, aCJKHeight.GetVersion( fileVersion ) );
     391         528 :     aCJKWeight.Store    ( rStream, aCJKWeight.GetVersion( fileVersion ) );
     392         528 :     aCJKPosture.Store   ( rStream, aCJKPosture.GetVersion( fileVersion ) );
     393         528 :     aCTLFont.Store      ( rStream, aCTLFont.GetVersion( fileVersion ) );
     394         528 :     aCTLHeight.Store    ( rStream, aCTLHeight.GetVersion( fileVersion ) );
     395         528 :     aCTLWeight.Store    ( rStream, aCTLWeight.GetVersion( fileVersion ) );
     396         528 :     aCTLPosture.Store   ( rStream, aCTLPosture.GetVersion( fileVersion ) );
     397             : 
     398         528 :     aUnderline.Store    ( rStream, aUnderline.GetVersion( fileVersion ) );
     399             :     // --- from DEV300/overline2 on: overline support
     400         528 :     aOverline.Store     ( rStream, aOverline.GetVersion( fileVersion ) );
     401         528 :     aCrossedOut.Store   ( rStream, aCrossedOut.GetVersion( fileVersion ) );
     402         528 :     aContour.Store      ( rStream, aContour.GetVersion( fileVersion ) );
     403         528 :     aShadowed.Store     ( rStream, aShadowed.GetVersion( fileVersion ) );
     404         528 :     aColor.Store        ( rStream, aColor.GetVersion( fileVersion ) );
     405         528 :     aBox.Store          ( rStream, aBox.GetVersion( fileVersion ) );
     406             : 
     407             :     // --- from 680/dr14 on: diagonal frame lines
     408         528 :     aTLBR.Store         ( rStream, aTLBR.GetVersion( fileVersion ) );
     409         528 :     aBLTR.Store         ( rStream, aBLTR.GetVersion( fileVersion ) );
     410             : 
     411         528 :     aBackground.Store   ( rStream, aBackground.GetVersion( fileVersion ) );
     412             : 
     413         528 :     aAdjust.Store       ( rStream, aAdjust.GetVersion( fileVersion ) );
     414         528 :     if (fileVersion >= SOFFICE_FILEFORMAT_50)
     415         528 :         WriteAutoFormatSwBlob( rStream, m_swFields );
     416             : 
     417         528 :     aHorJustify.Store   ( rStream, aHorJustify.GetVersion( fileVersion ) );
     418         528 :     aVerJustify.Store   ( rStream, aVerJustify.GetVersion( fileVersion ) );
     419         528 :     aOrientation.Store  ( rStream, aOrientation.GetVersion( fileVersion ) );
     420         528 :     aMargin.Store       ( rStream, aMargin.GetVersion( fileVersion ) );
     421         528 :     aLinebreak.Store    ( rStream, aLinebreak.GetVersion( fileVersion ) );
     422             :     // Rotation ab SO5
     423         528 :     aRotateAngle.Store  ( rStream, aRotateAngle.GetVersion( fileVersion ) );
     424         528 :     aRotateMode.Store   ( rStream, aRotateMode.GetVersion( fileVersion ) );
     425             : 
     426             :     // --- from 680/dr25 on: store strings as UTF-8
     427         528 :     aNumFormat.Save( rStream, RTL_TEXTENCODING_UTF8 );
     428             : 
     429         528 :     return (rStream.GetError() == 0);
     430             : }
     431             : 
     432          35 : ScAutoFormatData::ScAutoFormatData()
     433             : {
     434          35 :     nStrResId = USHRT_MAX;
     435             : 
     436             :     bIncludeValueFormat =
     437             :     bIncludeFont =
     438             :     bIncludeJustify =
     439             :     bIncludeFrame =
     440             :     bIncludeBackground =
     441          35 :     bIncludeWidthHeight = true;
     442             : 
     443          35 :     ppDataField = new ScAutoFormatDataField*[ 16 ];
     444         595 :     for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
     445         560 :         ppDataField[ nIndex ] = new ScAutoFormatDataField;
     446          35 : }
     447             : 
     448           2 : ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData& rData ) :
     449             :         aName( rData.aName ),
     450             :         nStrResId( rData.nStrResId ),
     451             :         bIncludeFont( rData.bIncludeFont ),
     452             :         bIncludeJustify( rData.bIncludeJustify ),
     453             :         bIncludeFrame( rData.bIncludeFrame ),
     454             :         bIncludeBackground( rData.bIncludeBackground ),
     455             :         bIncludeValueFormat( rData.bIncludeValueFormat ),
     456           2 :         bIncludeWidthHeight( rData.bIncludeWidthHeight )
     457             : {
     458           2 :     ppDataField = new ScAutoFormatDataField*[ 16 ];
     459          34 :     for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
     460          32 :         ppDataField[ nIndex ] = new ScAutoFormatDataField( rData.GetField( nIndex ) );
     461           2 : }
     462             : 
     463          74 : ScAutoFormatData::~ScAutoFormatData()
     464             : {
     465         629 :     for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
     466         592 :         delete ppDataField[ nIndex ];
     467          37 :     delete[] ppDataField;
     468          37 : }
     469             : 
     470        1416 : ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex )
     471             : {
     472             :     OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
     473             :     OSL_ENSURE( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
     474        1416 :     return *ppDataField[ nIndex ];
     475             : }
     476             : 
     477         338 : const ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex ) const
     478             : {
     479             :     OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
     480             :     OSL_ENSURE( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
     481         338 :     return *ppDataField[ nIndex ];
     482             : }
     483             : 
     484         306 : const SfxPoolItem* ScAutoFormatData::GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const
     485             : {
     486         306 :     const ScAutoFormatDataField& rField = GetField( nIndex );
     487         306 :     switch( nWhich )
     488             :     {
     489          42 :         case ATTR_FONT:             return &rField.GetFont();
     490           7 :         case ATTR_FONT_HEIGHT:      return &rField.GetHeight();
     491           7 :         case ATTR_FONT_WEIGHT:      return &rField.GetWeight();
     492           7 :         case ATTR_FONT_POSTURE:     return &rField.GetPosture();
     493          35 :         case ATTR_CJK_FONT:         return &rField.GetCJKFont();
     494           7 :         case ATTR_CJK_FONT_HEIGHT:  return &rField.GetCJKHeight();
     495           7 :         case ATTR_CJK_FONT_WEIGHT:  return &rField.GetCJKWeight();
     496           7 :         case ATTR_CJK_FONT_POSTURE: return &rField.GetCJKPosture();
     497          35 :         case ATTR_CTL_FONT:         return &rField.GetCTLFont();
     498           7 :         case ATTR_CTL_FONT_HEIGHT:  return &rField.GetCTLHeight();
     499           7 :         case ATTR_CTL_FONT_WEIGHT:  return &rField.GetCTLWeight();
     500           7 :         case ATTR_CTL_FONT_POSTURE: return &rField.GetCTLPosture();
     501           7 :         case ATTR_FONT_UNDERLINE:   return &rField.GetUnderline();
     502           7 :         case ATTR_FONT_OVERLINE:    return &rField.GetOverline();
     503           7 :         case ATTR_FONT_CROSSEDOUT:  return &rField.GetCrossedOut();
     504           7 :         case ATTR_FONT_CONTOUR:     return &rField.GetContour();
     505           7 :         case ATTR_FONT_SHADOWED:    return &rField.GetShadowed();
     506           7 :         case ATTR_FONT_COLOR:       return &rField.GetColor();
     507           6 :         case ATTR_BORDER:           return &rField.GetBox();
     508           0 :         case ATTR_BORDER_TLBR:      return &rField.GetTLBR();
     509           0 :         case ATTR_BORDER_BLTR:      return &rField.GetBLTR();
     510          14 :         case ATTR_BACKGROUND:       return &rField.GetBackground();
     511           7 :         case ATTR_HOR_JUSTIFY:      return &rField.GetHorJustify();
     512           3 :         case ATTR_VER_JUSTIFY:      return &rField.GetVerJustify();
     513           7 :         case ATTR_STACKED:          return &rField.GetStacked();
     514          28 :         case ATTR_MARGIN:           return &rField.GetMargin();
     515           7 :         case ATTR_LINEBREAK:        return &rField.GetLinebreak();
     516          12 :         case ATTR_ROTATE_VALUE:     return &rField.GetRotateAngle();
     517           3 :         case ATTR_ROTATE_MODE:      return &rField.GetRotateMode();
     518             :     }
     519           2 :     return NULL;
     520             : }
     521             : 
     522         376 : void ScAutoFormatData::PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem )
     523             : {
     524         376 :     ScAutoFormatDataField& rField = GetField( nIndex );
     525         376 :     switch( rItem.Which() )
     526             :     {
     527          44 :         case ATTR_FONT:             rField.SetFont( static_cast<const SvxFontItem&>(rItem) );              break;
     528          34 :         case ATTR_FONT_HEIGHT:      rField.SetHeight( static_cast<const SvxFontHeightItem&>(rItem) );      break;
     529           2 :         case ATTR_FONT_WEIGHT:      rField.SetWeight( static_cast<const SvxWeightItem&>(rItem) );          break;
     530           2 :         case ATTR_FONT_POSTURE:     rField.SetPosture( static_cast<const SvxPostureItem&>(rItem) );        break;
     531          42 :         case ATTR_CJK_FONT:         rField.SetCJKFont( static_cast<const SvxFontItem&>(rItem) );           break;
     532          34 :         case ATTR_CJK_FONT_HEIGHT:  rField.SetCJKHeight( static_cast<const SvxFontHeightItem&>(rItem) );   break;
     533           2 :         case ATTR_CJK_FONT_WEIGHT:  rField.SetCJKWeight( static_cast<const SvxWeightItem&>(rItem) );       break;
     534           2 :         case ATTR_CJK_FONT_POSTURE: rField.SetCJKPosture( static_cast<const SvxPostureItem&>(rItem) );     break;
     535          42 :         case ATTR_CTL_FONT:         rField.SetCTLFont( static_cast<const SvxFontItem&>(rItem) );           break;
     536          34 :         case ATTR_CTL_FONT_HEIGHT:  rField.SetCTLHeight( static_cast<const SvxFontHeightItem&>(rItem) );   break;
     537           2 :         case ATTR_CTL_FONT_WEIGHT:  rField.SetCTLWeight( static_cast<const SvxWeightItem&>(rItem) );       break;
     538           2 :         case ATTR_CTL_FONT_POSTURE: rField.SetCTLPosture( static_cast<const SvxPostureItem&>(rItem) );     break;
     539           2 :         case ATTR_FONT_UNDERLINE:   rField.SetUnderline( static_cast<const SvxUnderlineItem&>(rItem) );    break;
     540           2 :         case ATTR_FONT_OVERLINE:    rField.SetOverline( static_cast<const SvxOverlineItem&>(rItem) );      break;
     541           2 :         case ATTR_FONT_CROSSEDOUT:  rField.SetCrossedOut( static_cast<const SvxCrossedOutItem&>(rItem) );  break;
     542           2 :         case ATTR_FONT_CONTOUR:     rField.SetContour( static_cast<const SvxContourItem&>(rItem) );        break;
     543           2 :         case ATTR_FONT_SHADOWED:    rField.SetShadowed( static_cast<const SvxShadowedItem&>(rItem) );      break;
     544          34 :         case ATTR_FONT_COLOR:       rField.SetColor( static_cast<const SvxColorItem&>(rItem) );            break;
     545          34 :         case ATTR_BORDER:           rField.SetBox( static_cast<const SvxBoxItem&>(rItem) );                break;
     546           0 :         case ATTR_BORDER_TLBR:      rField.SetTLBR( static_cast<const SvxLineItem&>(rItem) );              break;
     547           0 :         case ATTR_BORDER_BLTR:      rField.SetBLTR( static_cast<const SvxLineItem&>(rItem) );              break;
     548          36 :         case ATTR_BACKGROUND:       rField.SetBackground( static_cast<const SvxBrushItem&>(rItem) );       break;
     549           2 :         case ATTR_HOR_JUSTIFY:      rField.SetHorJustify( static_cast<const SvxHorJustifyItem&>(rItem) );  break;
     550           1 :         case ATTR_VER_JUSTIFY:      rField.SetVerJustify( static_cast<const SvxVerJustifyItem&>(rItem) );  break;
     551           2 :         case ATTR_STACKED:          rField.SetStacked( static_cast<const SfxBoolItem&>(rItem) );           break;
     552           8 :         case ATTR_MARGIN:           rField.SetMargin( static_cast<const SvxMarginItem&>(rItem) );          break;
     553           2 :         case ATTR_LINEBREAK:        rField.SetLinebreak( static_cast<const SfxBoolItem&>(rItem) );         break;
     554           4 :         case ATTR_ROTATE_VALUE:     rField.SetRotateAngle( static_cast<const SfxInt32Item&>(rItem) );      break;
     555           1 :         case ATTR_ROTATE_MODE:      rField.SetRotateMode( static_cast<const SvxRotateModeItem&>(rItem) );  break;
     556             :     }
     557         376 : }
     558             : 
     559           0 : void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich )
     560             : {
     561           0 :     const SfxPoolItem* pItem = GetItem( nFromIndex, nWhich );
     562           0 :     if( pItem )
     563           0 :         PutItem( nToIndex, *pItem );
     564           0 : }
     565             : 
     566           0 : const ScNumFormatAbbrev& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex ) const
     567             : {
     568           0 :     return GetField( nIndex ).GetNumFormat();
     569             : }
     570             : 
     571           0 : bool ScAutoFormatData::IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const
     572             : {
     573           0 :     bool bEqual = true;
     574           0 :     const ScAutoFormatDataField& rField1 = GetField( nIndex1 );
     575           0 :     const ScAutoFormatDataField& rField2 = GetField( nIndex2 );
     576             : 
     577           0 :     if( bIncludeValueFormat )
     578             :     {
     579             :         bEqual = bEqual
     580           0 :             && (rField1.GetNumFormat()      == rField2.GetNumFormat());
     581             :     }
     582           0 :     if( bIncludeFont )
     583             :     {
     584             :         bEqual = bEqual
     585           0 :             && (rField1.GetFont()           == rField2.GetFont())
     586           0 :             && (rField1.GetHeight()         == rField2.GetHeight())
     587           0 :             && (rField1.GetWeight()         == rField2.GetWeight())
     588           0 :             && (rField1.GetPosture()        == rField2.GetPosture())
     589           0 :             && (rField1.GetCJKFont()        == rField2.GetCJKFont())
     590           0 :             && (rField1.GetCJKHeight()      == rField2.GetCJKHeight())
     591           0 :             && (rField1.GetCJKWeight()      == rField2.GetCJKWeight())
     592           0 :             && (rField1.GetCJKPosture()     == rField2.GetCJKPosture())
     593           0 :             && (rField1.GetCTLFont()        == rField2.GetCTLFont())
     594           0 :             && (rField1.GetCTLHeight()      == rField2.GetCTLHeight())
     595           0 :             && (rField1.GetCTLWeight()      == rField2.GetCTLWeight())
     596           0 :             && (rField1.GetCTLPosture()     == rField2.GetCTLPosture())
     597           0 :             && (rField1.GetUnderline()      == rField2.GetUnderline())
     598           0 :             && (rField1.GetOverline()       == rField2.GetOverline())
     599           0 :             && (rField1.GetCrossedOut()     == rField2.GetCrossedOut())
     600           0 :             && (rField1.GetContour()        == rField2.GetContour())
     601           0 :             && (rField1.GetShadowed()       == rField2.GetShadowed())
     602           0 :             && (rField1.GetColor()          == rField2.GetColor());
     603             :     }
     604           0 :     if( bIncludeJustify )
     605             :     {
     606             :         bEqual = bEqual
     607           0 :             && (rField1.GetHorJustify()     == rField2.GetHorJustify())
     608           0 :             && (rField1.GetVerJustify()     == rField2.GetVerJustify())
     609           0 :             && (rField1.GetStacked()        == rField2.GetStacked())
     610           0 :             && (rField1.GetLinebreak()      == rField2.GetLinebreak())
     611           0 :             && (rField1.GetMargin()         == rField2.GetMargin())
     612           0 :             && (rField1.GetRotateAngle()    == rField2.GetRotateAngle())
     613           0 :             && (rField1.GetRotateMode()     == rField2.GetRotateMode());
     614             :     }
     615           0 :     if( bIncludeFrame )
     616             :     {
     617             :         bEqual = bEqual
     618           0 :             && (rField1.GetBox()            == rField2.GetBox())
     619           0 :             && (rField1.GetTLBR()           == rField2.GetTLBR())
     620           0 :             && (rField1.GetBLTR()           == rField2.GetBLTR());
     621             :     }
     622           0 :     if( bIncludeBackground )
     623             :     {
     624             :         bEqual = bEqual
     625           0 :             && (rField1.GetBackground()     == rField2.GetBackground());
     626             :     }
     627           0 :     return bEqual;
     628             : }
     629             : 
     630           0 : void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const
     631             : {
     632           0 :     const ScAutoFormatDataField& rField = GetField( nIndex );
     633             : 
     634           0 :     if( bIncludeValueFormat )
     635             :     {
     636           0 :         ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)rField.GetNumFormat();
     637           0 :         SfxUInt32Item aValueFormat( ATTR_VALUE_FORMAT, 0 );
     638           0 :         aValueFormat.SetValue( rNumFormat.GetFormatIndex( *rDoc.GetFormatTable() ) );
     639           0 :         rItemSet.Put( aValueFormat );
     640           0 :         rItemSet.Put( SvxLanguageItem( rNumFormat.GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
     641             :     }
     642           0 :     if( bIncludeFont )
     643             :     {
     644           0 :         rItemSet.Put( rField.GetFont() );
     645           0 :         rItemSet.Put( rField.GetHeight() );
     646           0 :         rItemSet.Put( rField.GetWeight() );
     647           0 :         rItemSet.Put( rField.GetPosture() );
     648             :         // do not insert empty CJK font
     649           0 :         const SvxFontItem& rCJKFont = rField.GetCJKFont();
     650           0 :         if (!rCJKFont.GetStyleName().isEmpty())
     651             :         {
     652           0 :             rItemSet.Put( rCJKFont );
     653           0 :             rItemSet.Put( rField.GetCJKHeight() );
     654           0 :             rItemSet.Put( rField.GetCJKWeight() );
     655           0 :             rItemSet.Put( rField.GetCJKPosture() );
     656             :         }
     657             :         else
     658             :         {
     659           0 :             rItemSet.Put( rField.GetHeight(), ATTR_CJK_FONT_HEIGHT );
     660           0 :             rItemSet.Put( rField.GetWeight(), ATTR_CJK_FONT_WEIGHT );
     661           0 :             rItemSet.Put( rField.GetPosture(), ATTR_CJK_FONT_POSTURE );
     662             :         }
     663             :         // do not insert empty CTL font
     664           0 :         const SvxFontItem& rCTLFont = rField.GetCTLFont();
     665           0 :         if (!rCTLFont.GetStyleName().isEmpty())
     666             :         {
     667           0 :             rItemSet.Put( rCTLFont );
     668           0 :             rItemSet.Put( rField.GetCTLHeight() );
     669           0 :             rItemSet.Put( rField.GetCTLWeight() );
     670           0 :             rItemSet.Put( rField.GetCTLPosture() );
     671             :         }
     672             :         else
     673             :         {
     674           0 :             rItemSet.Put( rField.GetHeight(), ATTR_CTL_FONT_HEIGHT );
     675           0 :             rItemSet.Put( rField.GetWeight(), ATTR_CTL_FONT_WEIGHT );
     676           0 :             rItemSet.Put( rField.GetPosture(), ATTR_CTL_FONT_POSTURE );
     677             :         }
     678           0 :         rItemSet.Put( rField.GetUnderline() );
     679           0 :         rItemSet.Put( rField.GetOverline() );
     680           0 :         rItemSet.Put( rField.GetCrossedOut() );
     681           0 :         rItemSet.Put( rField.GetContour() );
     682           0 :         rItemSet.Put( rField.GetShadowed() );
     683           0 :         rItemSet.Put( rField.GetColor() );
     684             :     }
     685           0 :     if( bIncludeJustify )
     686             :     {
     687           0 :         rItemSet.Put( rField.GetHorJustify() );
     688           0 :         rItemSet.Put( rField.GetVerJustify() );
     689           0 :         rItemSet.Put( rField.GetStacked() );
     690           0 :         rItemSet.Put( rField.GetLinebreak() );
     691           0 :         rItemSet.Put( rField.GetMargin() );
     692           0 :         rItemSet.Put( rField.GetRotateAngle() );
     693           0 :         rItemSet.Put( rField.GetRotateMode() );
     694             :     }
     695           0 :     if( bIncludeFrame )
     696             :     {
     697           0 :         rItemSet.Put( rField.GetBox() );
     698           0 :         rItemSet.Put( rField.GetTLBR() );
     699           0 :         rItemSet.Put( rField.GetBLTR() );
     700             :     }
     701           0 :     if( bIncludeBackground )
     702           0 :         rItemSet.Put( rField.GetBackground() );
     703           0 : }
     704             : 
     705           0 : void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat )
     706             : {
     707           0 :     ScAutoFormatDataField& rField = GetField( nIndex );
     708             : 
     709           0 :     rField.SetNumFormat     ( rNumFormat);
     710           0 :     rField.SetFont          ( static_cast<const SvxFontItem&>          (rItemSet.Get( ATTR_FONT )) );
     711           0 :     rField.SetHeight        ( static_cast<const SvxFontHeightItem&>    (rItemSet.Get( ATTR_FONT_HEIGHT )) );
     712           0 :     rField.SetWeight        ( static_cast<const SvxWeightItem&>        (rItemSet.Get( ATTR_FONT_WEIGHT )) );
     713           0 :     rField.SetPosture       ( static_cast<const SvxPostureItem&>       (rItemSet.Get( ATTR_FONT_POSTURE )) );
     714           0 :     rField.SetCJKFont       ( static_cast<const SvxFontItem&>          (rItemSet.Get( ATTR_CJK_FONT )) );
     715           0 :     rField.SetCJKHeight     ( static_cast<const SvxFontHeightItem&>    (rItemSet.Get( ATTR_CJK_FONT_HEIGHT )) );
     716           0 :     rField.SetCJKWeight     ( static_cast<const SvxWeightItem&>        (rItemSet.Get( ATTR_CJK_FONT_WEIGHT )) );
     717           0 :     rField.SetCJKPosture    ( static_cast<const SvxPostureItem&>       (rItemSet.Get( ATTR_CJK_FONT_POSTURE )) );
     718           0 :     rField.SetCTLFont       ( static_cast<const SvxFontItem&>          (rItemSet.Get( ATTR_CTL_FONT )) );
     719           0 :     rField.SetCTLHeight     ( static_cast<const SvxFontHeightItem&>    (rItemSet.Get( ATTR_CTL_FONT_HEIGHT )) );
     720           0 :     rField.SetCTLWeight     ( static_cast<const SvxWeightItem&>        (rItemSet.Get( ATTR_CTL_FONT_WEIGHT )) );
     721           0 :     rField.SetCTLPosture    ( static_cast<const SvxPostureItem&>       (rItemSet.Get( ATTR_CTL_FONT_POSTURE )) );
     722           0 :     rField.SetUnderline     ( static_cast<const SvxUnderlineItem&>     (rItemSet.Get( ATTR_FONT_UNDERLINE )) );
     723           0 :     rField.SetOverline      ( static_cast<const SvxOverlineItem&>      (rItemSet.Get( ATTR_FONT_OVERLINE )) );
     724           0 :     rField.SetCrossedOut    ( static_cast<const SvxCrossedOutItem&>    (rItemSet.Get( ATTR_FONT_CROSSEDOUT )) );
     725           0 :     rField.SetContour       ( static_cast<const SvxContourItem&>       (rItemSet.Get( ATTR_FONT_CONTOUR )) );
     726           0 :     rField.SetShadowed      ( static_cast<const SvxShadowedItem&>      (rItemSet.Get( ATTR_FONT_SHADOWED )) );
     727           0 :     rField.SetColor         ( static_cast<const SvxColorItem&>         (rItemSet.Get( ATTR_FONT_COLOR )) );
     728           0 :     rField.SetTLBR          ( static_cast<const SvxLineItem&>          (rItemSet.Get( ATTR_BORDER_TLBR )) );
     729           0 :     rField.SetBLTR          ( static_cast<const SvxLineItem&>          (rItemSet.Get( ATTR_BORDER_BLTR )) );
     730           0 :     rField.SetHorJustify    ( static_cast<const SvxHorJustifyItem&>    (rItemSet.Get( ATTR_HOR_JUSTIFY )) );
     731           0 :     rField.SetVerJustify    ( static_cast<const SvxVerJustifyItem&>    (rItemSet.Get( ATTR_VER_JUSTIFY )) );
     732           0 :     rField.SetStacked       ( static_cast<const SfxBoolItem&>          (rItemSet.Get( ATTR_STACKED )) );
     733           0 :     rField.SetLinebreak     ( static_cast<const SfxBoolItem&>          (rItemSet.Get( ATTR_LINEBREAK )) );
     734           0 :     rField.SetMargin        ( static_cast<const SvxMarginItem&>        (rItemSet.Get( ATTR_MARGIN )) );
     735           0 :     rField.SetBackground    ( static_cast<const SvxBrushItem&>         (rItemSet.Get( ATTR_BACKGROUND )) );
     736           0 :     rField.SetRotateAngle   ( static_cast<const SfxInt32Item&>         (rItemSet.Get( ATTR_ROTATE_VALUE )) );
     737           0 :     rField.SetRotateMode    ( static_cast<const SvxRotateModeItem&>    (rItemSet.Get( ATTR_ROTATE_MODE )) );
     738           0 : }
     739             : 
     740          32 : bool ScAutoFormatData::Load( SvStream& rStream, const ScAfVersions& rVersions )
     741             : {
     742          32 :     sal_uInt16  nVer = 0;
     743          32 :     rStream.ReadUInt16( nVer );
     744          32 :     bool bRet = 0 == rStream.GetError();
     745          64 :     if( bRet && (nVer == AUTOFORMAT_DATA_ID_X ||
     746          64 :             (AUTOFORMAT_DATA_ID_504 <= nVer && nVer <= AUTOFORMAT_DATA_ID)) )
     747             :     {
     748             :         // --- from 680/dr25 on: store strings as UTF-8
     749          32 :         if (nVer >= AUTOFORMAT_ID_680DR25)
     750             :         {
     751          64 :             aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rStream,
     752          32 :                 RTL_TEXTENCODING_UTF8);
     753             :         }
     754             :         else
     755           0 :             aName = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
     756             : 
     757          32 :         if( AUTOFORMAT_DATA_ID_552 <= nVer )
     758             :         {
     759          32 :             rStream.ReadUInt16( nStrResId );
     760          32 :             sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN + nStrResId;
     761          32 :             if( RID_SVXSTR_TBLAFMT_BEGIN <= nId &&
     762             :                 nId < RID_SVXSTR_TBLAFMT_END )
     763             :             {
     764          32 :                 aName = SVX_RESSTR( nId );
     765             :             }
     766             :             else
     767           0 :                 nStrResId = USHRT_MAX;
     768             :         }
     769             : 
     770             :         bool b;
     771          32 :         rStream.ReadCharAsBool( b ); bIncludeFont = b;
     772          32 :         rStream.ReadCharAsBool( b ); bIncludeJustify = b;
     773          32 :         rStream.ReadCharAsBool( b ); bIncludeFrame = b;
     774          32 :         rStream.ReadCharAsBool( b ); bIncludeBackground = b;
     775          32 :         rStream.ReadCharAsBool( b ); bIncludeValueFormat = b;
     776          32 :         rStream.ReadCharAsBool( b ); bIncludeWidthHeight = b;
     777             : 
     778          32 :         if (nVer >= AUTOFORMAT_DATA_ID_31005)
     779           0 :             rStream >> m_swFields;
     780             : 
     781          32 :         bRet = 0 == rStream.GetError();
     782         544 :         for( sal_uInt16 i = 0; bRet && i < 16; ++i )
     783         544 :             bRet = GetField( i ).Load( rStream, rVersions, nVer );
     784             :     }
     785             :     else
     786           0 :         bRet = false;
     787          32 :     return bRet;
     788             : }
     789             : 
     790          33 : bool ScAutoFormatData::Save(SvStream& rStream, sal_uInt16 fileVersion)
     791             : {
     792          33 :     sal_uInt16 nVal = AUTOFORMAT_DATA_ID;
     793          33 :     rStream.WriteUInt16( nVal );
     794             :     // --- from 680/dr25 on: store strings as UTF-8
     795          33 :     write_uInt16_lenPrefixed_uInt8s_FromOUString(rStream, aName, RTL_TEXTENCODING_UTF8);
     796             : 
     797          33 :     rStream.WriteUInt16( nStrResId );
     798          33 :     rStream.WriteBool( bIncludeFont );
     799          33 :     rStream.WriteBool( bIncludeJustify );
     800          33 :     rStream.WriteBool( bIncludeFrame );
     801          33 :     rStream.WriteBool( bIncludeBackground );
     802          33 :     rStream.WriteBool( bIncludeValueFormat );
     803          33 :     rStream.WriteBool( bIncludeWidthHeight );
     804             : 
     805          33 :     if (fileVersion >= SOFFICE_FILEFORMAT_50)
     806          33 :         WriteAutoFormatSwBlob( rStream, m_swFields );
     807             : 
     808          33 :     bool bRet = 0 == rStream.GetError();
     809         561 :     for (sal_uInt16 i = 0; bRet && (i < 16); i++)
     810         528 :         bRet = GetField( i ).Save( rStream, fileVersion );
     811             : 
     812          33 :     return bRet;
     813             : }
     814             : 
     815           2 : ScAutoFormat::ScAutoFormat() :
     816           2 :     mbSaveLater(false)
     817             : {
     818             :     //  create default autoformat
     819           2 :     ScAutoFormatData* pData = new ScAutoFormatData;
     820           2 :     OUString aName(ScGlobal::GetRscString(STR_STYLENAME_STANDARD));
     821           2 :     pData->SetName(aName);
     822             : 
     823             :     //  default font, default height
     824             :     vcl::Font aStdFont = OutputDevice::GetDefaultFont(
     825           4 :         DefaultFontType::LATIN_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne );
     826             :     SvxFontItem aFontItem(
     827           2 :         aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
     828           6 :         aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_FONT );
     829             : 
     830           4 :     aStdFont = OutputDevice::GetDefaultFont(
     831           2 :         DefaultFontType::CJK_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne );
     832             :     SvxFontItem aCJKFontItem(
     833           2 :         aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
     834           6 :         aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CJK_FONT );
     835             : 
     836           4 :     aStdFont = OutputDevice::GetDefaultFont(
     837           2 :         DefaultFontType::CTL_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne );
     838             :     SvxFontItem aCTLFontItem(
     839           2 :         aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
     840           6 :         aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CTL_FONT );
     841             : 
     842           4 :     SvxFontHeightItem aHeight( 200, 100, ATTR_FONT_HEIGHT );      // 10 pt;
     843             : 
     844             :     //  black thin border
     845           2 :     Color aBlack( COL_BLACK );
     846           2 :     ::editeng::SvxBorderLine aLine( &aBlack, DEF_LINE_WIDTH_0 );
     847           4 :     SvxBoxItem aBox( ATTR_BORDER );
     848           2 :     aBox.SetLine(&aLine, SvxBoxItemLine::LEFT);
     849           2 :     aBox.SetLine(&aLine, SvxBoxItemLine::TOP);
     850           2 :     aBox.SetLine(&aLine, SvxBoxItemLine::RIGHT);
     851           2 :     aBox.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
     852             : 
     853           2 :     Color aWhite(COL_WHITE);
     854           2 :     Color aBlue(COL_BLUE);
     855           4 :     SvxColorItem aWhiteText( aWhite, ATTR_FONT_COLOR );
     856           4 :     SvxColorItem aBlackText( aBlack, ATTR_FONT_COLOR );
     857           4 :     SvxBrushItem aBlueBack( aBlue, ATTR_BACKGROUND );
     858           4 :     SvxBrushItem aWhiteBack( aWhite, ATTR_BACKGROUND );
     859           4 :     SvxBrushItem aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND );
     860           4 :     SvxBrushItem aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND );
     861             : 
     862          34 :     for (sal_uInt16 i=0; i<16; i++)
     863             :     {
     864          32 :         pData->PutItem( i, aBox );
     865          32 :         pData->PutItem( i, aFontItem );
     866          32 :         pData->PutItem( i, aCJKFontItem );
     867          32 :         pData->PutItem( i, aCTLFontItem );
     868          32 :         aHeight.SetWhich( ATTR_FONT_HEIGHT );
     869          32 :         pData->PutItem( i, aHeight );
     870          32 :         aHeight.SetWhich( ATTR_CJK_FONT_HEIGHT );
     871          32 :         pData->PutItem( i, aHeight );
     872          32 :         aHeight.SetWhich( ATTR_CTL_FONT_HEIGHT );
     873          32 :         pData->PutItem( i, aHeight );
     874          32 :         if (i<4)                                    // top: white on blue
     875             :         {
     876           8 :             pData->PutItem( i, aWhiteText );
     877           8 :             pData->PutItem( i, aBlueBack );
     878             :         }
     879          24 :         else if ( i%4 == 0 )                        // left: white on gray70
     880             :         {
     881           6 :             pData->PutItem( i, aWhiteText );
     882           6 :             pData->PutItem( i, aGray70Back );
     883             :         }
     884          18 :         else if ( i%4 == 3 || i >= 12 )             // right and bottom: black on gray20
     885             :         {
     886          10 :             pData->PutItem( i, aBlackText );
     887          10 :             pData->PutItem( i, aGray20Back );
     888             :         }
     889             :         else                                        // center: black on white
     890             :         {
     891           8 :             pData->PutItem( i, aBlackText );
     892           8 :             pData->PutItem( i, aWhiteBack );
     893             :         }
     894             :     }
     895             : 
     896           4 :     insert(pData);
     897           2 : }
     898             : 
     899           0 : ScAutoFormat::ScAutoFormat(const ScAutoFormat& r) :
     900             :     maData(r.maData),
     901           0 :     mbSaveLater(false) {}
     902             : 
     903           4 : ScAutoFormat::~ScAutoFormat()
     904             : {
     905             :     //  When modified via StarOne then only the SaveLater flag is set and no saving is done.
     906             :     //  If the flag is set then save now.
     907             : 
     908           2 :     if (mbSaveLater)
     909           0 :         Save();
     910           2 : }
     911             : 
     912         106 : void ScAutoFormat::SetSaveLater( bool bSet )
     913             : {
     914         106 :     mbSaveLater = bSet;
     915         106 : }
     916             : 
     917           0 : const ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex) const
     918             : {
     919           0 :     if (nIndex >= maData.size())
     920           0 :         return NULL;
     921             : 
     922           0 :     MapType::const_iterator it = maData.begin();
     923           0 :     std::advance(it, nIndex);
     924           0 :     return it->second;
     925             : }
     926             : 
     927         368 : ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex)
     928             : {
     929         368 :     if (nIndex >= maData.size())
     930           0 :         return NULL;
     931             : 
     932         368 :     MapType::iterator it = maData.begin();
     933         368 :     std::advance(it, nIndex);
     934         368 :     return it->second;
     935             : }
     936             : 
     937           0 : ScAutoFormat::const_iterator ScAutoFormat::find(const ScAutoFormatData* pData) const
     938             : {
     939           0 :     MapType::const_iterator it = maData.begin(), itEnd = maData.end();
     940           0 :     for (; it != itEnd; ++it)
     941             :     {
     942           0 :         if (it->second == pData)
     943           0 :             return it;
     944             :     }
     945           0 :     return itEnd;
     946             : }
     947             : 
     948           2 : ScAutoFormat::iterator ScAutoFormat::find(const ScAutoFormatData* pData)
     949             : {
     950           2 :     MapType::iterator it = maData.begin(), itEnd = maData.end();
     951          34 :     for (; it != itEnd; ++it)
     952             :     {
     953          34 :         if (it->second == pData)
     954           2 :             return it;
     955             :     }
     956           0 :     return itEnd;
     957             : }
     958             : 
     959           0 : ScAutoFormat::const_iterator ScAutoFormat::find(const OUString& rName) const
     960             : {
     961           0 :     return maData.find(rName);
     962             : }
     963             : 
     964           2 : ScAutoFormat::iterator ScAutoFormat::find(const OUString& rName)
     965             : {
     966           2 :     return maData.find(rName);
     967             : }
     968             : 
     969          37 : bool ScAutoFormat::insert(ScAutoFormatData* pNew)
     970             : {
     971          37 :     OUString aName = pNew->GetName();
     972          37 :     return maData.insert(aName, pNew).second;
     973             : }
     974             : 
     975           3 : void ScAutoFormat::erase(const iterator& it)
     976             : {
     977           3 :     maData.erase(it);
     978           3 : }
     979             : 
     980         422 : size_t ScAutoFormat::size() const
     981             : {
     982         422 :     return maData.size();
     983             : }
     984             : 
     985          11 : ScAutoFormat::const_iterator ScAutoFormat::begin() const
     986             : {
     987          11 :     return maData.begin();
     988             : }
     989             : 
     990          11 : ScAutoFormat::const_iterator ScAutoFormat::end() const
     991             : {
     992          11 :     return maData.end();
     993             : }
     994             : 
     995           8 : ScAutoFormat::iterator ScAutoFormat::begin()
     996             : {
     997           8 :     return maData.begin();
     998             : }
     999             : 
    1000           6 : ScAutoFormat::iterator ScAutoFormat::end()
    1001             : {
    1002           6 :     return maData.end();
    1003             : }
    1004             : 
    1005           2 : bool ScAutoFormat::Load()
    1006             : {
    1007           2 :     INetURLObject aURL;
    1008           4 :     SvtPathOptions aPathOpt;
    1009           2 :     aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
    1010           2 :     aURL.setFinalSlash();
    1011           2 :     aURL.Append( OUString( sAutoTblFmtName ) );
    1012             : 
    1013           4 :     SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), StreamMode::READ );
    1014           2 :     SvStream* pStream = aMedium.GetInStream();
    1015           2 :     bool bRet = (pStream && pStream->GetError() == 0);
    1016           2 :     if (bRet)
    1017             :     {
    1018           2 :         SvStream& rStream = *pStream;
    1019             :         // Attention: A common header has to be read
    1020           2 :         sal_uInt16 nVal = 0;
    1021           2 :         rStream.ReadUInt16( nVal );
    1022           2 :         bRet = 0 == rStream.GetError();
    1023             : 
    1024           2 :         if (bRet)
    1025             :         {
    1026           4 :             if( nVal == AUTOFORMAT_ID_358 ||
    1027           4 :                     (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
    1028             :             {
    1029           2 :                 sal_uInt16 nFileVers = SOFFICE_FILEFORMAT_40;
    1030             :                 sal_uInt8 nChrSet, nCnt;
    1031           2 :                 long nPos = rStream.Tell();
    1032           2 :                 rStream.ReadUChar( nCnt ).ReadUChar( nChrSet );
    1033           2 :                 if( rStream.Tell() != sal_uLong(nPos + nCnt) )
    1034             :                 {
    1035             :                     OSL_FAIL( "header contains more/newer data" );
    1036           0 :                     rStream.Seek( nPos + nCnt );
    1037             :                 }
    1038           2 :                 rStream.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet ) );
    1039           2 :                 rStream.SetVersion( nFileVers );
    1040             :             }
    1041             : 
    1042           4 :             if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X ||
    1043           4 :                     (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
    1044             :             {
    1045           2 :                 m_aVersions.Load( rStream, nVal );        // Item-Versionen
    1046             : 
    1047             :                 ScAutoFormatData* pData;
    1048           2 :                 sal_uInt16 nAnz = 0;
    1049           2 :                 rStream.ReadUInt16( nAnz );
    1050           2 :                 bRet = (rStream.GetError() == 0);
    1051          34 :                 for (sal_uInt16 i=0; bRet && (i < nAnz); i++)
    1052             :                 {
    1053          32 :                     pData = new ScAutoFormatData();
    1054          32 :                     bRet = pData->Load(rStream, m_aVersions);
    1055          32 :                     insert(pData);
    1056           2 :                 }
    1057             :             }
    1058             :             else
    1059           0 :                 bRet = false;
    1060             :         }
    1061             :     }
    1062           2 :     mbSaveLater = false;
    1063           4 :     return bRet;
    1064             : }
    1065             : 
    1066           2 : bool ScAutoFormat::Save()
    1067             : {
    1068           2 :     INetURLObject aURL;
    1069           4 :     SvtPathOptions aPathOpt;
    1070           2 :     aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
    1071           2 :     aURL.setFinalSlash();
    1072           2 :     aURL.Append(sAutoTblFmtName);
    1073             : 
    1074           4 :     SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), StreamMode::WRITE );
    1075           2 :     SvStream* pStream = aMedium.GetOutStream();
    1076           2 :     bool bRet = (pStream && pStream->GetError() == 0);
    1077           2 :     if (bRet)
    1078             :     {
    1079           2 :         const sal_uInt16 fileVersion = SOFFICE_FILEFORMAT_50;
    1080           2 :         SvStream& rStream = *pStream;
    1081           2 :         rStream.SetVersion( fileVersion );
    1082             : 
    1083             :         // Attention: A common header has to be saved
    1084           2 :         sal_uInt16 nVal = AUTOFORMAT_ID;
    1085           2 :         rStream.WriteUInt16( nVal )
    1086           2 :                .WriteUChar( 2 )         // Number of chars of the header including this
    1087             :                .WriteUChar( ::GetSOStoreTextEncoding(
    1088           4 :                     osl_getThreadTextEncoding() ) );
    1089           2 :         m_aVersions.Write(rStream, fileVersion);
    1090             : 
    1091           2 :         bRet &= (rStream.GetError() == 0);
    1092             : 
    1093           2 :         rStream.WriteUInt16( maData.size() - 1 );
    1094           2 :         bRet &= (rStream.GetError() == 0);
    1095           2 :         MapType::iterator it = maData.begin(), itEnd = maData.end();
    1096           2 :         if (it != itEnd)
    1097             :         {
    1098          35 :             for (++it; bRet && it != itEnd; ++it) // Skip the first item.
    1099             :             {
    1100          33 :                 bRet &= it->second->Save(rStream, fileVersion);
    1101             :             }
    1102             :         }
    1103             : 
    1104           2 :         rStream.Flush();
    1105             : 
    1106           2 :         aMedium.Commit();
    1107             :     }
    1108           2 :     mbSaveLater = false;
    1109           4 :     return bRet;
    1110         156 : }
    1111             : 
    1112             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11