LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/lotus - lotattr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 120 28.3 %
Date: 2012-12-27 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/brshitem.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           0 :     : pPattAttr(p)
      44             : {
      45           0 : }
      46             : 
      47           0 : LotAttrCache::ENTRY::~ENTRY ()
      48             : {
      49           0 :     delete pPattAttr;
      50           0 : }
      51             : 
      52           1 : LotAttrCache::LotAttrCache (LOTUS_ROOT* pLotRoot):
      53           1 :     mpLotusRoot(pLotRoot)
      54             : {
      55           1 :     pDocPool = mpLotusRoot->pDoc->GetPool();
      56             : 
      57           1 :     pColTab = new Color [ 8 ];
      58           1 :     pColTab[ 0 ] = Color( COL_WHITE );
      59           1 :     pColTab[ 1 ] = Color( COL_LIGHTBLUE );
      60           1 :     pColTab[ 2 ] = Color( COL_LIGHTGREEN );
      61           1 :     pColTab[ 3 ] = Color( COL_LIGHTCYAN );
      62           1 :     pColTab[ 4 ] = Color( COL_LIGHTRED );
      63           1 :     pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
      64           1 :     pColTab[ 6 ] = Color( COL_YELLOW );
      65           1 :     pColTab[ 7 ] = Color( COL_BLACK );
      66             : 
      67           1 :     ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR );     // 1
      68           1 :     ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
      69           1 :     ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
      70           1 :     ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
      71           1 :     ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
      72           1 :     ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR );     // 6
      73             : 
      74           1 :     pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
      75           1 :     pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
      76           1 : }
      77             : 
      78             : 
      79           2 : LotAttrCache::~LotAttrCache()
      80             : {
      81           7 :     for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
      82           6 :         delete ppColorItems[ nCnt ];
      83             : 
      84           1 :     delete pBlack;
      85           1 :     delete pWhite;
      86             : 
      87           1 :     delete[] pColTab;
      88           1 : }
      89             : 
      90             : 
      91           0 : const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
      92             : {
      93             :     sal_uInt32  nRefHash;
      94           0 :     MakeHash( rAttr, nRefHash );
      95             : 
      96             :     boost::ptr_vector<ENTRY>::const_iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
      97           0 :                                                                  boost::bind(&ENTRY::nHash0,_1) == nRefHash);
      98             : 
      99           0 :     if (iter != aEntries.end())
     100           0 :         return *(iter->pPattAttr);
     101             : 
     102             :     // neues PatternAttribute erzeugen
     103           0 :     ScPatternAttr*  pNewPatt = new ScPatternAttr(pDocPool);
     104             : 
     105           0 :     SfxItemSet&     rItemSet = pNewPatt->GetItemSet();
     106           0 :     ENTRY *pAkt = new ENTRY( pNewPatt );
     107             : 
     108           0 :     pAkt->nHash0 = nRefHash;
     109             : 
     110           0 :     mpLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
     111             : 
     112           0 :     sal_uInt8 nLine = rAttr.nLineStyle;
     113           0 :     if( nLine )
     114             :     {
     115           0 :         SvxBoxItem      aBox( ATTR_BORDER );
     116           0 :         ::editeng::SvxBorderLine    aTop, aLeft, aBottom, aRight;
     117             : 
     118           0 :         LotusToScBorderLine( nLine, aLeft );
     119           0 :         nLine >>= 2;
     120           0 :         LotusToScBorderLine( nLine, aRight );
     121           0 :         nLine >>= 2;
     122           0 :         LotusToScBorderLine( nLine, aTop );
     123           0 :         nLine >>= 2;
     124           0 :         LotusToScBorderLine( nLine, aBottom );
     125             : 
     126           0 :         aBox.SetLine( &aTop, BOX_LINE_TOP );
     127           0 :         aBox.SetLine( &aLeft, BOX_LINE_LEFT );
     128           0 :         aBox.SetLine( &aBottom, BOX_LINE_BOTTOM );
     129           0 :         aBox.SetLine( &aRight, BOX_LINE_RIGHT );
     130             : 
     131           0 :         rItemSet.Put( aBox );
     132             :     }
     133             : 
     134           0 :     sal_uInt8               nFontCol = rAttr.nFontCol & 0x07;
     135           0 :     if( nFontCol )
     136             :     {
     137             :         // nFontCol > 0
     138           0 :         if( nFontCol < 7 )
     139           0 :             rItemSet.Put( GetColorItem( nFontCol ) );
     140             :         else
     141           0 :             rItemSet.Put( *pWhite );
     142             :     }
     143             : 
     144           0 :     sal_uInt8 nBack = rAttr.nBack & 0x1F;
     145           0 :     if( nBack )
     146           0 :         rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
     147             : 
     148           0 :     if( rAttr.nBack & 0x80 )
     149             :     {
     150           0 :         SvxHorJustifyItem   aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
     151           0 :         rItemSet.Put( aHorJustify );
     152             :     }
     153             : 
     154           0 :     aEntries.push_back(pAkt);
     155             : 
     156           0 :     return *pNewPatt;
     157             : }
     158             : 
     159             : 
     160           0 : void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, ::editeng::SvxBorderLine& aBL )
     161             : {
     162           0 :     nLine &= 0x03;
     163             : 
     164           0 :     switch ( nLine )
     165             :     {
     166             :         default:
     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);
     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           9 : }
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10