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

Generated by: LCOV version 1.11