LCOV - code coverage report
Current view: top level - sw/inc - tblafmt.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 67 0.0 %
Date: 2012-08-25 Functions: 0 61 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 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                 :            : #ifndef SW_TBLAFMT_HXX
      29                 :            : #define SW_TBLAFMT_HXX
      30                 :            : /*************************************************************************
      31                 :            : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      32                 :            : 
      33                 :            :     The structure of table auto formatting should not be changed. It is used
      34                 :            :     by different code of Writer and Calc. If a change is necessary, the
      35                 :            :     source code of both applications must be changed!
      36                 :            : 
      37                 :            : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      38                 :            : **************************************************************************/
      39                 :            : 
      40                 :            : #include <boost/scoped_ptr.hpp>
      41                 :            : 
      42                 :            : #include "hintids.hxx"          // _Always_ before the solar-items!
      43                 :            : #include <svx/algitem.hxx>
      44                 :            : #include <editeng/fontitem.hxx>
      45                 :            : #include <editeng/fhgtitem.hxx>
      46                 :            : #include <editeng/wghtitem.hxx>
      47                 :            : #include <editeng/postitem.hxx>
      48                 :            : #include <editeng/udlnitem.hxx>
      49                 :            : #include <editeng/crsditem.hxx>
      50                 :            : #include <editeng/cntritem.hxx>
      51                 :            : #include <editeng/shdditem.hxx>
      52                 :            : #include <editeng/colritem.hxx>
      53                 :            : #include <editeng/boxitem.hxx>
      54                 :            : #include <editeng/brshitem.hxx>
      55                 :            : #include <editeng/adjitem.hxx>
      56                 :            : #include <editeng/justifyitem.hxx>
      57                 :            : #include <editeng/brkitem.hxx>
      58                 :            : #include <editeng/keepitem.hxx>
      59                 :            : #include <editeng/frmdiritem.hxx>
      60                 :            : #include <editeng/shaditem.hxx>
      61                 :            : #include <svx/rotmodit.hxx>
      62                 :            : #include <svl/intitem.hxx>
      63                 :            : #include <editeng/bolnitem.hxx>
      64                 :            : #include <fmtpdsc.hxx>
      65                 :            : #include <fmtlsplt.hxx>
      66                 :            : #include <fmtrowsplt.hxx>
      67                 :            : #include <fmtornt.hxx>
      68                 :            : #include "swdllapi.h"
      69                 :            : 
      70                 :            : struct SwAfVersions;
      71                 :            : 
      72                 :            : class SvNumberFormatter;
      73                 :            : 
      74                 :            : class SwBoxAutoFmt
      75                 :            : {
      76                 :            :     // common attributes of Calc and Writer
      77                 :            :     // --- from 641 on: CJK and CTL font settings
      78                 :            :     SvxFontItem         aFont;
      79                 :            :     SvxFontHeightItem   aHeight;
      80                 :            :     SvxWeightItem       aWeight;
      81                 :            :     SvxPostureItem      aPosture;
      82                 :            : 
      83                 :            :     SvxFontItem         aCJKFont;
      84                 :            :     SvxFontHeightItem   aCJKHeight;
      85                 :            :     SvxWeightItem       aCJKWeight;
      86                 :            :     SvxPostureItem      aCJKPosture;
      87                 :            : 
      88                 :            :     SvxFontItem         aCTLFont;
      89                 :            :     SvxFontHeightItem   aCTLHeight;
      90                 :            :     SvxWeightItem       aCTLWeight;
      91                 :            :     SvxPostureItem      aCTLPosture;
      92                 :            : 
      93                 :            :     SvxUnderlineItem    aUnderline;
      94                 :            :     SvxOverlineItem     aOverline;
      95                 :            :     SvxCrossedOutItem   aCrossedOut;
      96                 :            :     SvxContourItem      aContour;
      97                 :            :     SvxShadowedItem     aShadowed;
      98                 :            :     SvxColorItem        aColor;
      99                 :            :     SvxBoxItem          aBox;
     100                 :            :     SvxLineItem         aTLBR;
     101                 :            :     SvxLineItem         aBLTR;
     102                 :            :     SvxBrushItem        aBackground;
     103                 :            : 
     104                 :            :     // Writer specific
     105                 :            :     SvxAdjustItem       aAdjust;
     106                 :            :     SvxFrameDirectionItem m_aTextOrientation;
     107                 :            :     SwFmtVertOrient m_aVerticalAlignment;
     108                 :            : 
     109                 :            :     // Calc specific
     110                 :            :     SvxHorJustifyItem   aHorJustify;
     111                 :            :     SvxVerJustifyItem   aVerJustify;
     112                 :            :     SfxBoolItem         aStacked;
     113                 :            :     SvxMarginItem       aMargin;
     114                 :            :     SfxBoolItem         aLinebreak;
     115                 :            :     SfxInt32Item        aRotateAngle;
     116                 :            :     SvxRotateModeItem   aRotateMode;
     117                 :            : 
     118                 :            :     // number format
     119                 :            :     String              sNumFmtString;
     120                 :            :     LanguageType        eSysLanguage, eNumFmtLanguage;
     121                 :            : 
     122                 :            : public:
     123                 :            :     SwBoxAutoFmt();
     124                 :            :     SwBoxAutoFmt( const SwBoxAutoFmt& rNew );
     125                 :            :     ~SwBoxAutoFmt();
     126                 :            : 
     127                 :            :     int operator==( const SwBoxAutoFmt& rCmp ) const;
     128                 :            :     SwBoxAutoFmt& operator=( const SwBoxAutoFmt& rNew );
     129                 :            : 
     130                 :            :     // The get-methods.
     131                 :          0 :     const SvxFontItem       &GetFont() const        { return aFont; }
     132                 :          0 :     const SvxFontHeightItem &GetHeight() const      { return aHeight; }
     133                 :          0 :     const SvxWeightItem     &GetWeight() const      { return aWeight; }
     134                 :          0 :     const SvxPostureItem    &GetPosture() const     { return aPosture; }
     135                 :          0 :     const SvxFontItem       &GetCJKFont() const     { return aCJKFont; }
     136                 :          0 :     const SvxFontHeightItem &GetCJKHeight() const   { return aCJKHeight; }
     137                 :          0 :     const SvxWeightItem     &GetCJKWeight() const   { return aCJKWeight; }
     138                 :          0 :     const SvxPostureItem    &GetCJKPosture() const  { return aCJKPosture; }
     139                 :          0 :     const SvxFontItem       &GetCTLFont() const     { return aCTLFont; }
     140                 :          0 :     const SvxFontHeightItem &GetCTLHeight() const   { return aCTLHeight; }
     141                 :          0 :     const SvxWeightItem     &GetCTLWeight() const   { return aCTLWeight; }
     142                 :          0 :     const SvxPostureItem    &GetCTLPosture() const  { return aCTLPosture; }
     143                 :          0 :     const SvxUnderlineItem  &GetUnderline() const   { return aUnderline; }
     144                 :          0 :     const SvxOverlineItem   &GetOverline() const    { return aOverline; }
     145                 :          0 :     const SvxCrossedOutItem &GetCrossedOut() const  { return aCrossedOut; }
     146                 :          0 :     const SvxContourItem    &GetContour() const     { return aContour; }
     147                 :          0 :     const SvxShadowedItem   &GetShadowed() const    { return aShadowed; }
     148                 :          0 :     const SvxColorItem      &GetColor() const       { return aColor; }
     149                 :          0 :     const SvxAdjustItem     &GetAdjust() const      { return aAdjust; }
     150                 :          0 :     const SvxFrameDirectionItem& GetTextOrientation() const { return m_aTextOrientation; }
     151                 :          0 :     const SwFmtVertOrient& GetVerticalAlignment() const { return m_aVerticalAlignment; }
     152                 :          0 :     const SvxBoxItem        &GetBox() const         { return aBox; }
     153                 :            :     const SvxLineItem       &GetTLBR() const        { return aTLBR; }
     154                 :            :     const SvxLineItem       &GetBLTR() const        { return aBLTR; }
     155                 :          0 :     const SvxBrushItem      &GetBackground() const  { return aBackground; }
     156                 :          0 :     void GetValueFormat( String& rFmt, LanguageType& rLng, LanguageType& rSys ) const
     157                 :          0 :         { rFmt = sNumFmtString; rLng = eNumFmtLanguage; rSys = eSysLanguage; }
     158                 :            : 
     159                 :            :     // The set-methods.
     160                 :          0 :     void SetFont( const SvxFontItem& rNew )             { aFont = rNew; }
     161                 :          0 :     void SetHeight( const SvxFontHeightItem& rNew )     { aHeight = rNew; }
     162                 :          0 :     void SetWeight( const SvxWeightItem& rNew )         { aWeight = rNew; }
     163                 :          0 :     void SetPosture( const SvxPostureItem& rNew )       { aPosture = rNew; }
     164                 :          0 :     void SetCJKFont( const SvxFontItem& rNew )          { aCJKFont = rNew; }
     165                 :          0 :     void SetCJKHeight( const SvxFontHeightItem& rNew )  { aCJKHeight = rNew; }
     166                 :          0 :     void SetCJKWeight( const SvxWeightItem& rNew )      { aCJKWeight = rNew; }
     167                 :          0 :     void SetCJKPosture( const SvxPostureItem& rNew )    { aCJKPosture = rNew; }
     168                 :          0 :     void SetCTLFont( const SvxFontItem& rNew )          { aCTLFont = rNew; }
     169                 :          0 :     void SetCTLHeight( const SvxFontHeightItem& rNew )  { aCTLHeight = rNew; }
     170                 :          0 :     void SetCTLWeight( const SvxWeightItem& rNew )      { aCTLWeight = rNew; }
     171                 :          0 :     void SetCTLPosture( const SvxPostureItem& rNew )    { aCTLPosture = rNew; }
     172                 :          0 :     void SetUnderline( const SvxUnderlineItem& rNew )   { aUnderline = rNew; }
     173                 :          0 :     void SetOverline( const SvxOverlineItem& rNew )     { aOverline = rNew; }
     174                 :          0 :     void SetCrossedOut( const SvxCrossedOutItem& rNew ) { aCrossedOut = rNew; }
     175                 :          0 :     void SetContour( const SvxContourItem& rNew )       { aContour = rNew; }
     176                 :          0 :     void SetShadowed( const SvxShadowedItem& rNew )     { aShadowed = rNew; }
     177                 :          0 :     void SetColor( const SvxColorItem& rNew )           { aColor = rNew; }
     178                 :          0 :     void SetAdjust( const SvxAdjustItem& rNew )
     179                 :            :         {
     180                 :          0 :             aAdjust.SetAdjust( rNew.GetAdjust() );
     181                 :          0 :             aAdjust.SetOneWord( rNew.GetOneWord() );
     182                 :          0 :             aAdjust.SetLastBlock( rNew.GetLastBlock() );
     183                 :          0 :         }
     184                 :          0 :     void SetTextOrientation(const SvxFrameDirectionItem& rNew) { m_aTextOrientation = rNew; }
     185                 :          0 :     void SetVerticalAlignment(const SwFmtVertOrient& rNew) { m_aVerticalAlignment = rNew; }
     186                 :          0 :     void SetBox( const SvxBoxItem& rNew )               { aBox = rNew; }
     187                 :          0 :     void SetBackground( const SvxBrushItem& rNew )      { aBackground = rNew; }
     188                 :          0 :     void SetValueFormat( const String& rFmt, LanguageType eLng, LanguageType eSys )
     189                 :          0 :         { sNumFmtString = rFmt; eNumFmtLanguage = eLng; eSysLanguage = eSys; }
     190                 :            : 
     191                 :            :     sal_Bool Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer );
     192                 :            :     sal_Bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
     193                 :            :     sal_Bool SaveVersionNo( SvStream& rStream, sal_uInt16 fileVersion ) const;
     194                 :            : };
     195                 :            : 
     196                 :            : /*
     197                 :            : @remarks
     198                 :            : A table has a number of lines. These lines seem to correspond with rows, except in the case of
     199                 :            : rows spanning more than one line. Each line contains a number of boxes/cells.
     200                 :            : 
     201                 :            : AutoFormat properties are retrieved and stored in a grid of 16 table boxes. A sampling approach
     202                 :            : is used to read the data. 4 lines are picked, and 4 boxes are picked from each.
     203                 :            : 
     204                 :            : The line picking and box picking algorithms are similar. We start at the first line/box, and pick
     205                 :            : lines/boxes one by one for a maximum of 3. The 4th line/box is the last line/box in the current
     206                 :            : table/line. If we hit the end of lines/boxes, the last line/box encountered is picked several times.
     207                 :            : 
     208                 :            : For example, in a 2x3 table, the 4 lines will be [0, 1, 1, 1]. In each line, the boxes will be
     209                 :            : [0, 1, 2, 2]. In a 6x5 table, the 4 lines will be [0, 1, 2, 4] and the boxes per line will be
     210                 :            : [0, 1, 2, 5].
     211                 :            : 
     212                 :            : As you can see, property extraction/application is lossless for tables that are 4x4 or smaller
     213                 :            : (and in fact has a bit of redundnacy). For larger tables, we lose any individual cell formatting
     214                 :            : for the range [(3,rows - 1) -> (3, cols - 1)]. That formatting is replaced by formatting from
     215                 :            : the saved cells:
     216                 :            : 
     217                 :            :             0            1            2           3           4           5
     218                 :            :         +-----------------------------------------------------------------------+
     219                 :            :      0  |   Saved   |  Saved    |  Saved    |           |           |  Saved    |
     220                 :            :         +-----------------------------------------------------------------------+
     221                 :            :      1  |   Saved   |  Saved    |  Saved    |           |           |  Saved    |
     222                 :            :         +-----------------------------------------------------------------------+
     223                 :            :      2  |   Saved   |  Saved    |  Saved    |           |           |  Saved    |
     224                 :            :         +-----------------------------------------------------------------------+
     225                 :            :      3  |           |           |           |           |           |           |
     226                 :            :         +-----------------------------------------------------------------------+
     227                 :            :      4  |           |           |           |           |           |           |
     228                 :            :         +-----------------------------------------------------------------------+
     229                 :            :      5  |   Saved   |  Saved    |  Saved    |           |           |  Saved    |
     230                 :            :         +-----------+-----------+-----------+-----------+-----------+-----------+
     231                 :            : 
     232                 :            : The properties saved are divided into three categories:
     233                 :            :     1. Character properties: Font, font size, weight, etc.
     234                 :            :     2. Box properties: Box, cell background
     235                 :            :     3. Table properties: Properties that are set in the Table->Table Properties dialog.
     236                 :            : 
     237                 :            : Character and box properties are stored per cell (and are lossy for tables larger than 4x4). Table
     238                 :            : properties are stored per-table, and are lossless.
     239                 :            : */
     240                 :            : class SW_DLLPUBLIC SwTableAutoFmt
     241                 :            : {
     242                 :            :     friend void _FinitCore();       // To destroy dflt. pointer.
     243                 :            :     static SwBoxAutoFmt* pDfltBoxAutoFmt;
     244                 :            : 
     245                 :            :     String aName;
     246                 :            :     sal_uInt16 nStrResId;
     247                 :            : 
     248                 :            :     // Common flags of Calc and Writer.
     249                 :            :     sal_Bool bInclFont : 1;
     250                 :            :     sal_Bool bInclJustify : 1;
     251                 :            :     sal_Bool bInclFrame : 1;
     252                 :            :     sal_Bool bInclBackground : 1;
     253                 :            :     sal_Bool bInclValueFormat : 1;
     254                 :            : 
     255                 :            :     // Calc specific flags.
     256                 :            :     sal_Bool bInclWidthHeight : 1;
     257                 :            : 
     258                 :            :     SwBoxAutoFmt* aBoxAutoFmt[ 16 ];
     259                 :            : 
     260                 :            :     // Writer-specific options
     261                 :            :     SvxFmtBreakItem m_aBreak;
     262                 :            :     SwFmtPageDesc m_aPageDesc;
     263                 :            :     SvxFmtKeepItem m_aKeepWithNextPara;
     264                 :            :     sal_uInt16 m_aRepeatHeading;
     265                 :            :     sal_Bool m_bLayoutSplit;
     266                 :            :     sal_Bool m_bRowSplit;
     267                 :            :     sal_Bool m_bCollapsingBorders;
     268                 :            :     SvxShadowItem m_aShadow;
     269                 :            : 
     270                 :            : public:
     271                 :            :     SwTableAutoFmt( const String& rName );
     272                 :            :     SwTableAutoFmt( const SwTableAutoFmt& rNew );
     273                 :            :     ~SwTableAutoFmt();
     274                 :            : 
     275                 :            :     SwTableAutoFmt& operator=( const SwTableAutoFmt& rNew );
     276                 :            : 
     277                 :            :     void SetBoxFmt( const SwBoxAutoFmt& rNew, sal_uInt8 nPos );
     278                 :            :     const SwBoxAutoFmt& GetBoxFmt( sal_uInt8 nPos ) const;
     279                 :            : 
     280                 :          0 :     void SetName( const String& rNew ) { aName = rNew; nStrResId = USHRT_MAX; }
     281                 :          0 :     const String& GetName() const { return aName; }
     282                 :            : 
     283                 :            :     enum UpdateFlags { UPDATE_CHAR = 1, UPDATE_BOX = 2, UPDATE_ALL = 3 };
     284                 :            :     void UpdateFromSet( sal_uInt8 nPos, const SfxItemSet& rSet,
     285                 :            :                                 UpdateFlags eFlags, SvNumberFormatter* );
     286                 :            :     void UpdateToSet( sal_uInt8 nPos, SfxItemSet& rSet, UpdateFlags eFlags,
     287                 :            :                         SvNumberFormatter* ) const ;
     288                 :            : 
     289                 :            :     void RestoreTableProperties(SwTable &table) const;
     290                 :            :     void StoreTableProperties(const SwTable &table);
     291                 :            : 
     292                 :          0 :     sal_Bool IsFont() const         { return bInclFont; }
     293                 :          0 :     sal_Bool IsJustify() const      { return bInclJustify; }
     294                 :          0 :     sal_Bool IsFrame() const        { return bInclFrame; }
     295                 :          0 :     sal_Bool IsBackground() const   { return bInclBackground; }
     296                 :          0 :     sal_Bool IsValueFormat() const  { return bInclValueFormat; }
     297                 :            : 
     298                 :          0 :     void SetFont( const sal_Bool bNew )         { bInclFont = bNew; }
     299                 :          0 :     void SetJustify( const  sal_Bool bNew )     { bInclJustify = bNew; }
     300                 :          0 :     void SetFrame( const sal_Bool bNew )        { bInclFrame = bNew; }
     301                 :          0 :     void SetBackground( const sal_Bool bNew )   { bInclBackground = bNew; }
     302                 :          0 :     void SetValueFormat( const sal_Bool bNew )  { bInclValueFormat = bNew; }
     303                 :          0 :     void SetWidthHeight( const sal_Bool bNew )  { bInclWidthHeight = bNew; }
     304                 :            : 
     305                 :            :     sal_Bool Load( SvStream& rStream, const SwAfVersions& );
     306                 :            :     sal_Bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
     307                 :            : };
     308                 :            : 
     309                 :            : class SW_DLLPUBLIC SwTableAutoFmtTbl
     310                 :            : {
     311                 :            :     struct Impl;
     312                 :            :     ::boost::scoped_ptr<Impl> m_pImpl;
     313                 :            : 
     314                 :            :     SW_DLLPRIVATE sal_Bool Load( SvStream& rStream );
     315                 :            :     SW_DLLPRIVATE sal_Bool Save( SvStream& rStream ) const;
     316                 :            : 
     317                 :            : public:
     318                 :            :     explicit SwTableAutoFmtTbl();
     319                 :            :     ~SwTableAutoFmtTbl();
     320                 :            : 
     321                 :            :     size_t size() const;
     322                 :            :     SwTableAutoFmt const& operator[](size_t i) const;
     323                 :            :     SwTableAutoFmt      & operator[](size_t i);
     324                 :            :     void InsertAutoFmt(size_t i, SwTableAutoFmt * pFmt);
     325                 :            :     void EraseAutoFmt(size_t i);
     326                 :            :     void MoveAutoFmt(size_t target, size_t source);
     327                 :            : 
     328                 :            :     sal_Bool Load();
     329                 :            :     sal_Bool Save() const;
     330                 :            : };
     331                 :            : 
     332                 :            : #endif
     333                 :            : 
     334                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10