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

Generated by: LCOV version 1.10