LCOV - code coverage report
Current view: top level - sc/source/filter/lotus - lotattr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 116 0.9 %
Date: 2012-08-25 Functions: 2 14 14.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 202 1.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                 :            : 
      30                 :            : #include "lotattr.hxx"
      31                 :            : 
      32                 :            : #include <boost/bind.hpp>
      33                 :            : 
      34                 :            : #include <editeng/boxitem.hxx>
      35                 :            : #include <editeng/brshitem.hxx>
      36                 :            : #include <editeng/justifyitem.hxx>
      37                 :            : #include <svx/algitem.hxx>
      38                 :            : 
      39                 :            : #include "attrib.hxx"
      40                 :            : #include "docpool.hxx"
      41                 :            : #include "document.hxx"
      42                 :            : #include "lotfntbf.hxx"
      43                 :            : #include "patattr.hxx"
      44                 :            : #include "root.hxx"
      45                 :            : #include "scitems.hxx"
      46                 :            : 
      47                 :            : 
      48                 :            : using namespace ::com::sun::star;
      49                 :            : 
      50                 :            : 
      51                 :          0 : LotAttrCache::ENTRY::ENTRY (ScPatternAttr* p)
      52                 :          0 :     : pPattAttr(p)
      53                 :            : {
      54                 :          0 : }
      55                 :            : 
      56                 :          0 : LotAttrCache::ENTRY::~ENTRY ()
      57                 :            : {
      58         [ #  # ]:          0 :     delete pPattAttr;
      59                 :          0 : }
      60                 :            : 
      61                 :          0 : LotAttrCache::LotAttrCache ()
      62                 :            : {
      63         [ #  # ]:          0 :     pDocPool = pLotusRoot->pDoc->GetPool();
      64                 :            : 
      65 [ #  # ][ #  # ]:          0 :     pColTab = new Color [ 8 ];
      66                 :          0 :     pColTab[ 0 ] = Color( COL_WHITE );
      67                 :          0 :     pColTab[ 1 ] = Color( COL_LIGHTBLUE );
      68                 :          0 :     pColTab[ 2 ] = Color( COL_LIGHTGREEN );
      69                 :          0 :     pColTab[ 3 ] = Color( COL_LIGHTCYAN );
      70                 :          0 :     pColTab[ 4 ] = Color( COL_LIGHTRED );
      71                 :          0 :     pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
      72                 :          0 :     pColTab[ 6 ] = Color( COL_YELLOW );
      73                 :          0 :     pColTab[ 7 ] = Color( COL_BLACK );
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 :     ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR );     // 1
      76 [ #  # ][ #  # ]:          0 :     ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
      77 [ #  # ][ #  # ]:          0 :     ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
      78 [ #  # ][ #  # ]:          0 :     ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
      79 [ #  # ][ #  # ]:          0 :     ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
      80 [ #  # ][ #  # ]:          0 :     ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR );     // 6
      81                 :            : 
      82 [ #  # ][ #  # ]:          0 :     pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
      83 [ #  # ][ #  # ]:          0 :     pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
      84                 :          0 : }
      85                 :            : 
      86                 :            : 
      87                 :          0 : LotAttrCache::~LotAttrCache()
      88                 :            : {
      89         [ #  # ]:          0 :     for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
      90 [ #  # ][ #  # ]:          0 :         delete ppColorItems[ nCnt ];
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 :     delete pBlack;
      93 [ #  # ][ #  # ]:          0 :     delete pWhite;
      94                 :            : 
      95         [ #  # ]:          0 :     delete[] pColTab;
      96                 :          0 : }
      97                 :            : 
      98                 :            : 
      99                 :          0 : const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
     100                 :            : {
     101                 :            :     sal_uInt32  nRefHash;
     102                 :          0 :     MakeHash( rAttr, nRefHash );
     103                 :            : 
     104                 :            :     boost::ptr_vector<ENTRY>::const_iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
     105 [ #  # ][ #  # ]:          0 :                                                                  boost::bind(&ENTRY::nHash0,_1) == nRefHash);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     106                 :            : 
     107 [ #  # ][ #  # ]:          0 :     if (iter != aEntries.end())
                 [ #  # ]
     108         [ #  # ]:          0 :         return *(iter->pPattAttr);
     109                 :            : 
     110                 :            :     // neues PatternAttribute erzeugen
     111 [ #  # ][ #  # ]:          0 :     ScPatternAttr*  pNewPatt = new ScPatternAttr(pDocPool);
     112                 :            : 
     113                 :          0 :     SfxItemSet&     rItemSet = pNewPatt->GetItemSet();
     114         [ #  # ]:          0 :     ENTRY *pAkt = new ENTRY( pNewPatt );
     115                 :            : 
     116                 :          0 :     pAkt->nHash0 = nRefHash;
     117                 :            : 
     118         [ #  # ]:          0 :     pLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
     119                 :            : 
     120                 :          0 :     sal_uInt8 nLine = rAttr.nLineStyle;
     121         [ #  # ]:          0 :     if( nLine )
     122                 :            :     {
     123         [ #  # ]:          0 :         SvxBoxItem      aBox( ATTR_BORDER );
     124 [ #  # ][ #  # ]:          0 :         ::editeng::SvxBorderLine    aTop, aLeft, aBottom, aRight;
         [ #  # ][ #  # ]
     125                 :            : 
     126         [ #  # ]:          0 :         LotusToScBorderLine( nLine, aLeft );
     127                 :          0 :         nLine >>= 2;
     128         [ #  # ]:          0 :         LotusToScBorderLine( nLine, aRight );
     129                 :          0 :         nLine >>= 2;
     130         [ #  # ]:          0 :         LotusToScBorderLine( nLine, aTop );
     131                 :          0 :         nLine >>= 2;
     132         [ #  # ]:          0 :         LotusToScBorderLine( nLine, aBottom );
     133                 :            : 
     134         [ #  # ]:          0 :         aBox.SetLine( &aTop, BOX_LINE_TOP );
     135         [ #  # ]:          0 :         aBox.SetLine( &aLeft, BOX_LINE_LEFT );
     136         [ #  # ]:          0 :         aBox.SetLine( &aBottom, BOX_LINE_BOTTOM );
     137         [ #  # ]:          0 :         aBox.SetLine( &aRight, BOX_LINE_RIGHT );
     138                 :            : 
     139 [ #  # ][ #  # ]:          0 :         rItemSet.Put( aBox );
     140                 :            :     }
     141                 :            : 
     142                 :          0 :     sal_uInt8               nFontCol = rAttr.nFontCol & 0x07;
     143         [ #  # ]:          0 :     if( nFontCol )
     144                 :            :     {
     145                 :            :         // nFontCol > 0
     146         [ #  # ]:          0 :         if( nFontCol < 7 )
     147         [ #  # ]:          0 :             rItemSet.Put( GetColorItem( nFontCol ) );
     148                 :            :         else
     149         [ #  # ]:          0 :             rItemSet.Put( *pWhite );
     150                 :            :     }
     151                 :            : 
     152                 :          0 :     sal_uInt8 nBack = rAttr.nBack & 0x1F;
     153         [ #  # ]:          0 :     if( nBack )
     154 [ #  # ][ #  # ]:          0 :         rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
                 [ #  # ]
     155                 :            : 
     156         [ #  # ]:          0 :     if( rAttr.nBack & 0x80 )
     157                 :            :     {
     158         [ #  # ]:          0 :         SvxHorJustifyItem   aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
     159 [ #  # ][ #  # ]:          0 :         rItemSet.Put( aHorJustify );
     160                 :            :     }
     161                 :            : 
     162         [ #  # ]:          0 :     aEntries.push_back(pAkt);
     163                 :            : 
     164                 :          0 :     return *pNewPatt;
     165                 :            : }
     166                 :            : 
     167                 :            : 
     168                 :          0 : void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, ::editeng::SvxBorderLine& aBL )
     169                 :            : {
     170                 :          0 :     nLine &= 0x03;
     171                 :            : 
     172   [ #  #  #  # ]:          0 :     switch ( nLine )
     173                 :            :     {
     174                 :            :         default:
     175                 :          0 :         case 0: aBL.SetBorderLineStyle(table::BorderLineStyle::NONE); break;
     176                 :          0 :         case 1: aBL.SetWidth( DEF_LINE_WIDTH_1 ); break;
     177                 :          0 :         case 2: aBL.SetWidth( DEF_LINE_WIDTH_2 ); break;
     178                 :            :         case 3:
     179                 :            :         {
     180                 :          0 :             aBL.SetBorderLineStyle(table::BorderLineStyle::DOUBLE);
     181                 :          0 :             aBL.SetWidth( DEF_LINE_WIDTH_1 );
     182                 :            :         }
     183                 :          0 :         break;
     184                 :            :     }
     185                 :          0 : }
     186                 :            : 
     187                 :          0 : const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
     188                 :            : {
     189                 :            :     OSL_ENSURE( nLotIndex > 0 && nLotIndex < 7,
     190                 :            :                 "-LotAttrCache::GetColorItem(): caller hast to check index!" );
     191                 :            : 
     192                 :          0 :     return *ppColorItems[ nLotIndex - 1 ];
     193                 :            : }
     194                 :            : 
     195                 :          0 : const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
     196                 :            : {
     197                 :            :     // Farbe <-> Index passt fuer Background, nicht aber fuer Fonts (0 <-> 7)!
     198                 :            :         OSL_ENSURE( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7, caller hast to check index!" );
     199                 :            : 
     200                 :          0 :     return pColTab[ nLotIndex ];
     201                 :            : }
     202                 :            : 
     203                 :          0 : void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
     204                 :            : {
     205                 :            :     // Actually with the current implementation of MAXROWCOUNT>=64k and nRow
     206                 :            :     // being read as sal_uInt16 there's no chance that nRow would be invalid..
     207                 :            :     OSL_ENSURE( ValidRow(nRow), "*LotAttrCol::SetAttr(): ... und rums?!" );
     208                 :            : 
     209         [ #  # ]:          0 :     boost::ptr_vector<ENTRY>::reverse_iterator iterLast = aEntries.rbegin();
     210                 :            : 
     211 [ #  # ][ #  # ]:          0 :     if(iterLast != aEntries.rend())
                 [ #  # ]
     212                 :            :     {
     213 [ #  # ][ #  # ]:          0 :         if( ( iterLast->nLastRow == nRow - 1 ) && ( &rAttr == iterLast->pPattAttr ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     214         [ #  # ]:          0 :             iterLast->nLastRow = nRow;
     215                 :            :         else
     216                 :            :         {
     217         [ #  # ]:          0 :             ENTRY *pAkt = new ENTRY;
     218                 :            : 
     219                 :          0 :             pAkt->pPattAttr = &rAttr;
     220                 :          0 :             pAkt->nFirstRow = pAkt->nLastRow = nRow;
     221                 :            : 
     222         [ #  # ]:          0 :             aEntries.push_back(pAkt);
     223                 :            :         }
     224                 :            :     }
     225                 :            :     else
     226                 :            :     {   // erster Eintrag
     227         [ #  # ]:          0 :         ENTRY *pAkt = new ENTRY;
     228                 :          0 :         pAkt->pPattAttr = &rAttr;
     229                 :          0 :         pAkt->nFirstRow = pAkt->nLastRow = nRow;
     230                 :            : 
     231         [ #  # ]:          0 :         aEntries.push_back(pAkt);
     232                 :            :     }
     233                 :          0 : }
     234                 :            : 
     235                 :            : 
     236                 :          0 : void LotAttrCol::Apply( const SCCOL nColNum, const SCTAB nTabNum )
     237                 :            : {
     238                 :          0 :     ScDocument*     pDoc = pLotusRoot->pDoc;
     239                 :            : 
     240         [ #  # ]:          0 :     boost::ptr_vector<ENTRY>::iterator iter;
     241 [ #  # ][ #  # ]:          0 :     for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     242                 :            :     {
     243 [ #  # ][ #  # ]:          0 :         pDoc->ApplyPatternAreaTab(nColNum,iter->nFirstRow,nColNum,iter->nLastRow,
     244 [ #  # ][ #  # ]:          0 :                                   nTabNum, *(iter->pPattAttr));
     245                 :            :     }
     246                 :          0 : }
     247                 :            : 
     248                 :          0 : void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
     249                 :            :                             const LotAttrWK3& rAttr )
     250                 :            : {
     251                 :            :     // With the current implementation of MAXCOLCOUNT>=1024 and nColFirst and
     252                 :            :     // nColLast being calculated as sal_uInt8+sal_uInt8 there's no chance that
     253                 :            :     // they would be invalid.
     254                 :          0 :     const ScPatternAttr &rPattAttr = aAttrCache.GetPattAttr( rAttr );
     255                 :            :     SCCOL nColCnt;
     256                 :            : 
     257         [ #  # ]:          0 :     for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
     258                 :          0 :         pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
     259                 :          0 : }
     260                 :            : 
     261                 :            : 
     262                 :          0 : void LotAttrTable::Apply( const SCTAB nTabNum )
     263                 :            : {
     264                 :            :     SCCOL nColCnt;
     265         [ #  # ]:          0 :     for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
     266                 :          0 :         pCols[ nColCnt ].Apply( nColCnt, nTabNum );     // macht auch gleich ein Clear() am Ende
     267 [ +  - ][ +  - ]:         24 : }
     268                 :            : 
     269                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10