LCOV - code coverage report
Current view: top level - sc/source/filter/lotus - lotattr.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 120 28.3 %
Date: 2014-04-11 Functions: 6 15 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "lotattr.hxx"
      22             : 
      23             : #include <boost/bind.hpp>
      24             : 
      25             : #include <editeng/boxitem.hxx>
      26             : #include <editeng/brushitem.hxx>
      27             : #include <editeng/justifyitem.hxx>
      28             : #include <svx/algitem.hxx>
      29             : 
      30             : #include "attrib.hxx"
      31             : #include "docpool.hxx"
      32             : #include "document.hxx"
      33             : #include "lotfntbf.hxx"
      34             : #include "patattr.hxx"
      35             : #include "root.hxx"
      36             : #include "scitems.hxx"
      37             : 
      38             : 
      39             : using namespace ::com::sun::star;
      40             : 
      41             : 
      42           0 : LotAttrCache::ENTRY::ENTRY (ScPatternAttr* p)
      43             :     : pPattAttr(p)
      44           0 :     , nHash0(0)
      45             : {
      46           0 : }
      47             : 
      48           0 : LotAttrCache::ENTRY::~ENTRY ()
      49             : {
      50           0 :     delete pPattAttr;
      51           0 : }
      52             : 
      53           1 : LotAttrCache::LotAttrCache (LOTUS_ROOT* pLotRoot):
      54           1 :     mpLotusRoot(pLotRoot)
      55             : {
      56           1 :     pDocPool = mpLotusRoot->pDoc->GetPool();
      57             : 
      58           1 :     pColTab = new Color [ 8 ];
      59           1 :     pColTab[ 0 ] = Color( COL_WHITE );
      60           1 :     pColTab[ 1 ] = Color( COL_LIGHTBLUE );
      61           1 :     pColTab[ 2 ] = Color( COL_LIGHTGREEN );
      62           1 :     pColTab[ 3 ] = Color( COL_LIGHTCYAN );
      63           1 :     pColTab[ 4 ] = Color( COL_LIGHTRED );
      64           1 :     pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
      65           1 :     pColTab[ 6 ] = Color( COL_YELLOW );
      66           1 :     pColTab[ 7 ] = Color( COL_BLACK );
      67             : 
      68           1 :     ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR );     // 1
      69           1 :     ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
      70           1 :     ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
      71           1 :     ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
      72           1 :     ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
      73           1 :     ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR );     // 6
      74             : 
      75           1 :     pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
      76           1 :     pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
      77           1 : }
      78             : 
      79             : 
      80           2 : LotAttrCache::~LotAttrCache()
      81             : {
      82           7 :     for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
      83           6 :         delete ppColorItems[ nCnt ];
      84             : 
      85           1 :     delete pBlack;
      86           1 :     delete pWhite;
      87             : 
      88           1 :     delete[] pColTab;
      89           1 : }
      90             : 
      91             : 
      92           0 : const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
      93             : {
      94             :     sal_uInt32  nRefHash;
      95           0 :     MakeHash( rAttr, nRefHash );
      96             : 
      97             :     boost::ptr_vector<ENTRY>::const_iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
      98           0 :                                                                  boost::bind(&ENTRY::nHash0,_1) == nRefHash);
      99             : 
     100           0 :     if (iter != aEntries.end())
     101           0 :         return *(iter->pPattAttr);
     102             : 
     103             :     // neues PatternAttribute erzeugen
     104           0 :     ScPatternAttr*  pNewPatt = new ScPatternAttr(pDocPool);
     105             : 
     106           0 :     SfxItemSet&     rItemSet = pNewPatt->GetItemSet();
     107           0 :     ENTRY *pAkt = new ENTRY( pNewPatt );
     108             : 
     109           0 :     pAkt->nHash0 = nRefHash;
     110             : 
     111           0 :     mpLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
     112             : 
     113           0 :     sal_uInt8 nLine = rAttr.nLineStyle;
     114           0 :     if( nLine )
     115             :     {
     116           0 :         SvxBoxItem      aBox( ATTR_BORDER );
     117           0 :         ::editeng::SvxBorderLine    aTop, aLeft, aBottom, aRight;
     118             : 
     119           0 :         LotusToScBorderLine( nLine, aLeft );
     120           0 :         nLine >>= 2;
     121           0 :         LotusToScBorderLine( nLine, aRight );
     122           0 :         nLine >>= 2;
     123           0 :         LotusToScBorderLine( nLine, aTop );
     124           0 :         nLine >>= 2;
     125           0 :         LotusToScBorderLine( nLine, aBottom );
     126             : 
     127           0 :         aBox.SetLine( &aTop, BOX_LINE_TOP );
     128           0 :         aBox.SetLine( &aLeft, BOX_LINE_LEFT );
     129           0 :         aBox.SetLine( &aBottom, BOX_LINE_BOTTOM );
     130           0 :         aBox.SetLine( &aRight, BOX_LINE_RIGHT );
     131             : 
     132           0 :         rItemSet.Put( aBox );
     133             :     }
     134             : 
     135           0 :     sal_uInt8               nFontCol = rAttr.nFontCol & 0x07;
     136           0 :     if( nFontCol )
     137             :     {
     138             :         // nFontCol > 0
     139           0 :         if( nFontCol < 7 )
     140           0 :             rItemSet.Put( GetColorItem( nFontCol ) );
     141             :         else
     142           0 :             rItemSet.Put( *pWhite );
     143             :     }
     144             : 
     145           0 :     sal_uInt8 nBack = rAttr.nBack & 0x1F;
     146           0 :     if( nBack )
     147           0 :         rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
     148             : 
     149           0 :     if( rAttr.nBack & 0x80 )
     150             :     {
     151           0 :         SvxHorJustifyItem   aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
     152           0 :         rItemSet.Put( aHorJustify );
     153             :     }
     154             : 
     155           0 :     aEntries.push_back(pAkt);
     156             : 
     157           0 :     return *pNewPatt;
     158             : }
     159             : 
     160             : 
     161           0 : void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, ::editeng::SvxBorderLine& aBL )
     162             : {
     163           0 :     nLine &= 0x03;
     164             : 
     165           0 :     switch ( nLine )
     166             :     {
     167           0 :         case 0: aBL.SetBorderLineStyle(table::BorderLineStyle::NONE); break;
     168           0 :         case 1: aBL.SetWidth( DEF_LINE_WIDTH_1 ); break;
     169           0 :         case 2: aBL.SetWidth( DEF_LINE_WIDTH_2 ); break;
     170             :         case 3:
     171             :         {
     172           0 :             aBL.SetBorderLineStyle(table::BorderLineStyle::DOUBLE_THIN);
     173           0 :             aBL.SetWidth( DEF_LINE_WIDTH_1 );
     174             :         }
     175           0 :         break;
     176             :     }
     177           0 : }
     178             : 
     179           0 : const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
     180             : {
     181             :     OSL_ENSURE( nLotIndex > 0 && nLotIndex < 7,
     182             :                 "-LotAttrCache::GetColorItem(): caller hast to check index!" );
     183             : 
     184           0 :     return *ppColorItems[ nLotIndex - 1 ];
     185             : }
     186             : 
     187           6 : const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
     188             : {
     189             :     // Farbe <-> Index passt fuer Background, nicht aber fuer Fonts (0 <-> 7)!
     190             :         OSL_ENSURE( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7, caller hast to check index!" );
     191             : 
     192           6 :     return pColTab[ nLotIndex ];
     193             : }
     194             : 
     195           0 : void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
     196             : {
     197             :     // Actually with the current implementation of MAXROWCOUNT>=64k and nRow
     198             :     // being read as sal_uInt16 there's no chance that nRow would be invalid..
     199             :     OSL_ENSURE( ValidRow(nRow), "*LotAttrCol::SetAttr(): ... und rums?!" );
     200             : 
     201           0 :     boost::ptr_vector<ENTRY>::reverse_iterator iterLast = aEntries.rbegin();
     202             : 
     203           0 :     if(iterLast != aEntries.rend())
     204             :     {
     205           0 :         if( ( iterLast->nLastRow == nRow - 1 ) && ( &rAttr == iterLast->pPattAttr ) )
     206           0 :             iterLast->nLastRow = nRow;
     207             :         else
     208             :         {
     209           0 :             ENTRY *pAkt = new ENTRY;
     210             : 
     211           0 :             pAkt->pPattAttr = &rAttr;
     212           0 :             pAkt->nFirstRow = pAkt->nLastRow = nRow;
     213             : 
     214           0 :             aEntries.push_back(pAkt);
     215             :         }
     216             :     }
     217             :     else
     218             :     {   // erster Eintrag
     219           0 :         ENTRY *pAkt = new ENTRY;
     220           0 :         pAkt->pPattAttr = &rAttr;
     221           0 :         pAkt->nFirstRow = pAkt->nLastRow = nRow;
     222             : 
     223           0 :         aEntries.push_back(pAkt);
     224             :     }
     225           0 : }
     226             : 
     227             : 
     228           0 : void LotAttrCol::Apply( const SCCOL nColNum, const SCTAB nTabNum )
     229             : {
     230           0 :     ScDocument*     pDoc = pLotusRoot->pDoc;
     231             : 
     232           0 :     boost::ptr_vector<ENTRY>::iterator iter;
     233           0 :     for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
     234             :     {
     235           0 :         pDoc->ApplyPatternAreaTab(nColNum,iter->nFirstRow,nColNum,iter->nLastRow,
     236           0 :                                   nTabNum, *(iter->pPattAttr));
     237             :     }
     238           0 : }
     239             : 
     240           1 : LotAttrTable::LotAttrTable(LOTUS_ROOT* pLotRoot):
     241           1 :     aAttrCache(pLotRoot)
     242             : {
     243           1 : }
     244             : 
     245           0 : void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
     246             :                             const LotAttrWK3& rAttr )
     247             : {
     248             :     // With the current implementation of MAXCOLCOUNT>=1024 and nColFirst and
     249             :     // nColLast being calculated as sal_uInt8+sal_uInt8 there's no chance that
     250             :     // they would be invalid.
     251           0 :     const ScPatternAttr &rPattAttr = aAttrCache.GetPattAttr( rAttr );
     252             :     SCCOL nColCnt;
     253             : 
     254           0 :     for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
     255           0 :         pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
     256           0 : }
     257             : 
     258             : 
     259           0 : void LotAttrTable::Apply( const SCTAB nTabNum )
     260             : {
     261             :     SCCOL nColCnt;
     262           0 :     for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
     263           0 :         pCols[ nColCnt ].Apply( nColCnt, nTabNum );     // macht auch gleich ein Clear() am Ende
     264          18 : }
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10