LCOV - code coverage report
Current view: top level - sc/inc - autoform.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 87 92.0 %
Date: 2012-08-25 Functions: 72 79 91.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SC_AUTOFORM_HXX
      30                 :            : #define SC_AUTOFORM_HXX
      31                 :            : 
      32                 :            : /*************************************************************************
      33                 :            : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      34                 :            : 
      35                 :            : 
      36                 :            :     Die akt. Struktur der Autoformatierung darf nicht mehr veraendert werden.
      37                 :            :     Diese wird durch unterschiedlichen Code vom StartWriter und vom StarCalc
      38                 :            :     eingelesen/geschrieben.
      39                 :            :     Sollte sich doch mal eine Aenderung nicht vermeiden lassen, dann auf
      40                 :            :     jedenfall in beiden Applikationen aendern.
      41                 :            : 
      42                 :            :     The structure of table auto formatting should not changed. It is used
      43                 :            :     by different code of Writer and Calc. If a change is necessary, the
      44                 :            :     source code of both applications must be changed!
      45                 :            : 
      46                 :            : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      47                 :            : **************************************************************************/
      48                 :            : 
      49                 :            : #include "scitems.hxx"
      50                 :            : #include <editeng/adjitem.hxx>
      51                 :            : #include <svx/algitem.hxx>
      52                 :            : #include <editeng/boxitem.hxx>
      53                 :            : #include <editeng/brshitem.hxx>
      54                 :            : #include <editeng/cntritem.hxx>
      55                 :            : #include <editeng/colritem.hxx>
      56                 :            : #include <editeng/crsditem.hxx>
      57                 :            : #include <editeng/fhgtitem.hxx>
      58                 :            : #include <editeng/fontitem.hxx>
      59                 :            : #include <editeng/postitem.hxx>
      60                 :            : #include <editeng/shdditem.hxx>
      61                 :            : #include <editeng/udlnitem.hxx>
      62                 :            : #include <editeng/wghtitem.hxx>
      63                 :            : #include <editeng/justifyitem.hxx>
      64                 :            : #include <svx/rotmodit.hxx>
      65                 :            : #include <svl/intitem.hxx>
      66                 :            : #include <editeng/bolnitem.hxx>
      67                 :            : #include "scdllapi.h"
      68                 :            : #include "global.hxx"
      69                 :            : #include "zforauto.hxx"
      70                 :            : 
      71                 :            : #include <boost/ptr_container/ptr_map.hpp>
      72                 :            : 
      73                 :            : /**
      74                 :            : A binary blob of writer-specific data. This data typically consists of types that are
      75                 :            : unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
      76                 :            : 
      77                 :            : @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
      78                 :            : logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
      79                 :            : That logic was preserved. From _31005 onward, writer-specific data should be handled by
      80                 :            : blobs to avoid needlessly complicating the Calc logic.
      81                 :            : */
      82                 :            : struct AutoFormatSwBlob : ::boost::noncopyable
      83                 :            : {
      84                 :            :     sal_uInt8 *pData;
      85                 :            :     sal_Size size;
      86                 :            : 
      87                 :        341 :     AutoFormatSwBlob() : pData(0), size(0)
      88                 :            :     {
      89                 :        341 :     }
      90                 :            : 
      91                 :        341 :     ~AutoFormatSwBlob()
      92                 :        341 :     {
      93                 :        341 :         Reset();
      94                 :        341 :     }
      95                 :            : 
      96                 :        341 :     void Reset()
      97                 :            :     {
      98         [ -  + ]:        341 :         delete[] pData;
      99                 :        341 :         pData = 0;
     100                 :        341 :         size = 0;
     101                 :        341 :     }
     102                 :            : };
     103                 :            : 
     104                 :            : /// Struct with version numbers of the Items
     105                 :          1 : struct ScAfVersions
     106                 :            : {
     107                 :            : public:
     108                 :            :     sal_uInt16 nFontVersion;
     109                 :            :     sal_uInt16 nFontHeightVersion;
     110                 :            :     sal_uInt16 nWeightVersion;
     111                 :            :     sal_uInt16 nPostureVersion;
     112                 :            :     sal_uInt16 nUnderlineVersion;
     113                 :            :     sal_uInt16 nOverlineVersion;
     114                 :            :     sal_uInt16 nCrossedOutVersion;
     115                 :            :     sal_uInt16 nContourVersion;
     116                 :            :     sal_uInt16 nShadowedVersion;
     117                 :            :     sal_uInt16 nColorVersion;
     118                 :            :     sal_uInt16 nBoxVersion;
     119                 :            :     sal_uInt16 nLineVersion;
     120                 :            :     sal_uInt16 nBrushVersion;
     121                 :            : 
     122                 :            :     sal_uInt16 nAdjustVersion;
     123                 :            :     AutoFormatSwBlob swVersions;
     124                 :            : 
     125                 :            :     sal_uInt16 nHorJustifyVersion;
     126                 :            :     sal_uInt16 nVerJustifyVersion;
     127                 :            :     sal_uInt16 nOrientationVersion;
     128                 :            :     sal_uInt16 nMarginVersion;
     129                 :            :     sal_uInt16 nBoolVersion;
     130                 :            :     sal_uInt16 nInt32Version;
     131                 :            :     sal_uInt16 nRotateModeVersion;
     132                 :            : 
     133                 :            :     sal_uInt16 nNumFmtVersion;
     134                 :            : 
     135                 :            :     ScAfVersions();
     136                 :            :     void Load( SvStream& rStream, sal_uInt16 nVer );
     137                 :            :     void Write(SvStream& rStream, sal_uInt16 fileVersion);
     138                 :            : };
     139                 :            : 
     140                 :            : /// Contains all items for one cell of a table autoformat.
     141                 :            : class ScAutoFormatDataField
     142                 :            : {
     143                 :            : private:
     144                 :            :     SvxFontItem                 aFont;
     145                 :            :     SvxFontHeightItem           aHeight;
     146                 :            :     SvxWeightItem               aWeight;
     147                 :            :     SvxPostureItem              aPosture;
     148                 :            : 
     149                 :            :     SvxFontItem                 aCJKFont;
     150                 :            :     SvxFontHeightItem           aCJKHeight;
     151                 :            :     SvxWeightItem               aCJKWeight;
     152                 :            :     SvxPostureItem              aCJKPosture;
     153                 :            : 
     154                 :            :     SvxFontItem                 aCTLFont;
     155                 :            :     SvxFontHeightItem           aCTLHeight;
     156                 :            :     SvxWeightItem               aCTLWeight;
     157                 :            :     SvxPostureItem              aCTLPosture;
     158                 :            : 
     159                 :            :     SvxUnderlineItem            aUnderline;
     160                 :            :     SvxOverlineItem             aOverline;
     161                 :            :     SvxCrossedOutItem           aCrossedOut;
     162                 :            :     SvxContourItem              aContour;
     163                 :            :     SvxShadowedItem             aShadowed;
     164                 :            :     SvxColorItem                aColor;
     165                 :            :     SvxBoxItem                  aBox;
     166                 :            :     SvxLineItem                 aTLBR;
     167                 :            :     SvxLineItem                 aBLTR;
     168                 :            :     SvxBrushItem                aBackground;
     169                 :            : 
     170                 :            :     // Writer specific
     171                 :            :     SvxAdjustItem               aAdjust;
     172                 :            :     AutoFormatSwBlob            m_swFields;
     173                 :            : 
     174                 :            :     // Calc specific
     175                 :            :     SvxHorJustifyItem           aHorJustify;
     176                 :            :     SvxVerJustifyItem           aVerJustify;
     177                 :            :     SfxBoolItem                 aStacked;
     178                 :            :     SvxMarginItem               aMargin;
     179                 :            :     SfxBoolItem                 aLinebreak;
     180                 :            :     // from SO5, 504k on, rotated text
     181                 :            :     SfxInt32Item                aRotateAngle;
     182                 :            :     SvxRotateModeItem           aRotateMode;
     183                 :            : 
     184                 :            :     // number format
     185                 :            :     ScNumFormatAbbrev           aNumFormat;
     186                 :            : 
     187                 :            : public:
     188                 :            :                                 ScAutoFormatDataField();
     189                 :            :                                 ScAutoFormatDataField( const ScAutoFormatDataField& rCopy );
     190                 :            :                                 ~ScAutoFormatDataField();
     191                 :            : 
     192                 :          0 :     const ScNumFormatAbbrev&    GetNumFormat() const    { return aNumFormat; }
     193                 :         42 :     const SvxFontItem&          GetFont() const         { return aFont; }
     194                 :          7 :     const SvxFontHeightItem&    GetHeight() const       { return aHeight; }
     195                 :          7 :     const SvxWeightItem&        GetWeight() const       { return aWeight; }
     196                 :          7 :     const SvxPostureItem&       GetPosture() const      { return aPosture; }
     197                 :         35 :     const SvxFontItem&          GetCJKFont() const      { return aCJKFont; }
     198                 :          7 :     const SvxFontHeightItem&    GetCJKHeight() const    { return aCJKHeight; }
     199                 :          7 :     const SvxWeightItem&        GetCJKWeight() const    { return aCJKWeight; }
     200                 :          7 :     const SvxPostureItem&       GetCJKPosture() const   { return aCJKPosture; }
     201                 :         35 :     const SvxFontItem&          GetCTLFont() const      { return aCTLFont; }
     202                 :          7 :     const SvxFontHeightItem&    GetCTLHeight() const    { return aCTLHeight; }
     203                 :          7 :     const SvxWeightItem&        GetCTLWeight() const    { return aCTLWeight; }
     204                 :          7 :     const SvxPostureItem&       GetCTLPosture() const   { return aCTLPosture; }
     205                 :          7 :     const SvxUnderlineItem&     GetUnderline() const    { return aUnderline; }
     206                 :          7 :     const SvxOverlineItem&      GetOverline() const     { return aOverline; }
     207                 :          7 :     const SvxCrossedOutItem&    GetCrossedOut() const   { return aCrossedOut; }
     208                 :          7 :     const SvxContourItem&       GetContour() const      { return aContour; }
     209                 :          7 :     const SvxShadowedItem&      GetShadowed() const     { return aShadowed; }
     210                 :          7 :     const SvxColorItem&         GetColor() const        { return aColor; }
     211                 :          7 :     const SvxHorJustifyItem&    GetHorJustify() const   { return aHorJustify; }
     212                 :          3 :     const SvxVerJustifyItem&    GetVerJustify() const   { return aVerJustify; }
     213                 :          7 :     const SfxBoolItem&          GetStacked() const      { return aStacked; }
     214                 :          7 :     const SfxBoolItem&          GetLinebreak() const    { return aLinebreak; }
     215                 :         28 :     const SvxMarginItem&        GetMargin() const       { return aMargin; }
     216                 :          6 :     const SvxBoxItem&           GetBox() const          { return aBox; }
     217                 :          0 :     const SvxLineItem&          GetTLBR() const         { return aTLBR; }
     218                 :          0 :     const SvxLineItem&          GetBLTR() const         { return aBLTR; }
     219                 :         14 :     const SvxBrushItem&         GetBackground() const   { return aBackground; }
     220                 :            :     const SvxAdjustItem&        GetAdjust() const       { return aAdjust; }
     221                 :         12 :     const SfxInt32Item&         GetRotateAngle() const  { return aRotateAngle; }
     222                 :          3 :     const SvxRotateModeItem&    GetRotateMode() const   { return aRotateMode; }
     223                 :            : 
     224                 :          0 :     void    SetNumFormat( const ScNumFormatAbbrev& rNumFormat )     { aNumFormat = rNumFormat; }
     225                 :         28 :     void    SetFont( const SvxFontItem& rFont )                     { aFont = rFont; }
     226                 :         18 :     void    SetHeight( const SvxFontHeightItem& rHeight )           { aHeight = rHeight; }
     227                 :          2 :     void    SetWeight( const SvxWeightItem& rWeight )               { aWeight = rWeight; }
     228                 :          2 :     void    SetPosture( const SvxPostureItem& rPosture )            { aPosture = rPosture; }
     229                 :         26 :     void    SetCJKFont( const SvxFontItem& rCJKFont )               { aCJKFont = rCJKFont; }
     230                 :         18 :     void    SetCJKHeight( const SvxFontHeightItem& rCJKHeight )     { aCJKHeight = rCJKHeight; }
     231                 :          2 :     void    SetCJKWeight( const SvxWeightItem& rCJKWeight )         { aCJKWeight = rCJKWeight; }
     232                 :          2 :     void    SetCJKPosture( const SvxPostureItem& rCJKPosture )      { aCJKPosture = rCJKPosture; }
     233                 :         26 :     void    SetCTLFont( const SvxFontItem& rCTLFont )               { aCTLFont = rCTLFont; }
     234                 :         18 :     void    SetCTLHeight( const SvxFontHeightItem& rCTLHeight )     { aCTLHeight = rCTLHeight; }
     235                 :          2 :     void    SetCTLWeight( const SvxWeightItem& rCTLWeight )         { aCTLWeight = rCTLWeight; }
     236                 :          2 :     void    SetCTLPosture( const SvxPostureItem& rCTLPosture )      { aCTLPosture = rCTLPosture; }
     237                 :          2 :     void    SetUnderline( const SvxUnderlineItem& rUnderline )      { aUnderline = rUnderline; }
     238                 :          2 :     void    SetOverline( const SvxOverlineItem& rOverline )         { aOverline = rOverline; }
     239                 :          2 :     void    SetCrossedOut( const SvxCrossedOutItem& rCrossedOut )   { aCrossedOut = rCrossedOut; }
     240                 :          2 :     void    SetContour( const SvxContourItem& rContour )            { aContour = rContour; }
     241                 :          2 :     void    SetShadowed( const SvxShadowedItem& rShadowed )         { aShadowed = rShadowed; }
     242                 :         18 :     void    SetColor( const SvxColorItem& rColor )                  { aColor = rColor; }
     243                 :          2 :     void    SetHorJustify( const SvxHorJustifyItem& rHorJustify )   { aHorJustify = rHorJustify; }
     244                 :          1 :     void    SetVerJustify( const SvxVerJustifyItem& rVerJustify )   { aVerJustify = rVerJustify; }
     245                 :          2 :     void    SetStacked( const SfxBoolItem& rStacked )               { aStacked.SetValue( rStacked.GetValue() ); }
     246                 :        258 :     void    SetLinebreak( const SfxBoolItem& rLinebreak )           { aLinebreak.SetValue( rLinebreak.GetValue() ); }
     247                 :          8 :     void    SetMargin( const SvxMarginItem& rMargin )               { aMargin = rMargin; }
     248                 :         18 :     void    SetBox( const SvxBoxItem& rBox )                        { aBox = rBox; }
     249                 :          0 :     void    SetTLBR( const SvxLineItem& rTLBR )                     { aTLBR = rTLBR; }
     250                 :          0 :     void    SetBLTR( const SvxLineItem& rBLTR )                     { aBLTR = rBLTR; }
     251                 :         20 :     void    SetBackground( const SvxBrushItem& rBackground )        { aBackground = rBackground; }
     252                 :            :     void    SetAdjust( const SvxAdjustItem& rAdjust );
     253                 :        260 :     void    SetRotateAngle( const SfxInt32Item& rRotateAngle )      { aRotateAngle.SetValue( rRotateAngle.GetValue() ); }
     254                 :        257 :     void    SetRotateMode( const SvxRotateModeItem& rRotateMode )   { aRotateMode.SetValue( rRotateMode.GetValue() ); }
     255                 :            : 
     256                 :            :     sal_Bool                        Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer );
     257                 :            :     sal_Bool                        Save( SvStream& rStream, sal_uInt16 fileVersion );
     258                 :            : };
     259                 :            : 
     260                 :            : 
     261                 :            : class SC_DLLPUBLIC ScAutoFormatData
     262                 :            : {
     263                 :            : private:
     264                 :            :     rtl::OUString               aName;
     265                 :            :     sal_uInt16                  nStrResId;
     266                 :            :     // common flags of Calc and Writer
     267                 :            :     bool                        bIncludeFont : 1;
     268                 :            :     bool                        bIncludeJustify : 1;
     269                 :            :     bool                        bIncludeFrame : 1;
     270                 :            :     bool                        bIncludeBackground : 1;
     271                 :            : 
     272                 :            :     // Calc specific flags
     273                 :            :     bool                        bIncludeValueFormat : 1;
     274                 :            :     bool                        bIncludeWidthHeight : 1;
     275                 :            : 
     276                 :            :     // Writer-specific data
     277                 :            :     AutoFormatSwBlob m_swFields;
     278                 :            : 
     279                 :            :     ScAutoFormatDataField**     ppDataField;
     280                 :            : 
     281                 :            :     SC_DLLPRIVATE ScAutoFormatDataField&       GetField( sal_uInt16 nIndex );
     282                 :            :     SC_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
     283                 :            : 
     284                 :            : public:
     285                 :            :     ScAutoFormatData();
     286                 :            :     ScAutoFormatData( const ScAutoFormatData& rData );
     287                 :            :     ~ScAutoFormatData();
     288                 :            : 
     289                 :          4 :     void            SetName( const rtl::OUString& rName )              { aName = rName; nStrResId = USHRT_MAX; }
     290                 :        250 :     const rtl::OUString& GetName() const { return aName; }
     291                 :            : 
     292                 :          7 :     bool            GetIncludeValueFormat() const               { return bIncludeValueFormat; }
     293                 :          7 :     bool            GetIncludeFont() const                      { return bIncludeFont; }
     294                 :          7 :     bool            GetIncludeJustify() const                   { return bIncludeJustify; }
     295                 :          7 :     bool            GetIncludeFrame() const                     { return bIncludeFrame; }
     296                 :          7 :     bool            GetIncludeBackground() const                { return bIncludeBackground; }
     297                 :          7 :     bool            GetIncludeWidthHeight() const               { return bIncludeWidthHeight; }
     298                 :            : 
     299                 :          3 :     void            SetIncludeValueFormat( bool bValueFormat )  { bIncludeValueFormat = bValueFormat; }
     300                 :          3 :     void            SetIncludeFont( bool bFont )                { bIncludeFont = bFont; }
     301                 :          3 :     void            SetIncludeJustify( bool bJustify )          { bIncludeJustify = bJustify; }
     302                 :          3 :     void            SetIncludeFrame( bool bFrame )              { bIncludeFrame = bFrame; }
     303                 :          3 :     void            SetIncludeBackground( bool bBackground )    { bIncludeBackground = bBackground; }
     304                 :          3 :     void            SetIncludeWidthHeight( bool bWidthHeight )  { bIncludeWidthHeight = bWidthHeight; }
     305                 :            : 
     306                 :            :     const SfxPoolItem*          GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const;
     307                 :            :     void                        PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem );
     308                 :            :     void                        CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich );
     309                 :            : 
     310                 :            :     const ScNumFormatAbbrev&    GetNumFormat( sal_uInt16 nIndex ) const;
     311                 :            : 
     312                 :            :     bool                        IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const;
     313                 :            : 
     314                 :            :     void                        FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const;
     315                 :            :     void                        GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat );
     316                 :            : 
     317                 :            :     bool                        Load( SvStream& rStream, const ScAfVersions& rVersions );
     318                 :            :     bool                        Save( SvStream& rStream, sal_uInt16 fileVersion );
     319                 :            : };
     320                 :            : 
     321                 :            : class SC_DLLPUBLIC ScAutoFormat
     322                 :            : {
     323                 :            :     typedef boost::ptr_map<rtl::OUString, ScAutoFormatData> MapType;
     324                 :            :     MapType maData;
     325                 :            :     bool mbSaveLater;
     326                 :            :     ScAfVersions m_aVersions;
     327                 :            : 
     328                 :            : public:
     329                 :            :     typedef MapType::const_iterator const_iterator;
     330                 :            :     typedef MapType::iterator iterator;
     331                 :            : 
     332                 :            :     ScAutoFormat();
     333                 :            :     ScAutoFormat(const ScAutoFormat& r);
     334                 :            :     ~ScAutoFormat();
     335                 :            :     bool Load();
     336                 :            :     bool Save();
     337                 :            : 
     338                 :            :     void SetSaveLater( bool bSet );
     339                 :          0 :     bool IsSaveLater() const { return mbSaveLater; }
     340                 :            : 
     341                 :            :     const ScAutoFormatData* findByIndex(size_t nIndex) const;
     342                 :            :     ScAutoFormatData* findByIndex(size_t nIndex);
     343                 :            :     const_iterator find(const ScAutoFormatData* pData) const;
     344                 :            :     iterator find(const ScAutoFormatData* pData);
     345                 :            :     const_iterator find(const rtl::OUString& rName) const;
     346                 :            :     iterator find(const rtl::OUString& rName);
     347                 :            : 
     348                 :            :     bool insert(ScAutoFormatData* pNew);
     349                 :            :     void erase(const iterator& it);
     350                 :            : 
     351                 :            :     size_t size() const;
     352                 :            :     const_iterator begin() const;
     353                 :            :     const_iterator end() const;
     354                 :            :     iterator begin();
     355                 :            :     iterator end();
     356                 :            : };
     357                 :            : 
     358                 :            : 
     359                 :            : #endif
     360                 :            : 
     361                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10