Bump version to 4.3-4
[LibreOffice.git] / sc / source / filter / lotus / lotattr.cxx
blobe78209bf7cbe0514c82d02928d5632d5073e3e7b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "lotattr.hxx"
23 #include <boost/bind.hpp>
25 #include <editeng/boxitem.hxx>
26 #include <editeng/brushitem.hxx>
27 #include <editeng/justifyitem.hxx>
28 #include <svx/algitem.hxx>
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"
39 using namespace ::com::sun::star;
42 LotAttrCache::ENTRY::ENTRY (ScPatternAttr* p)
43 : pPattAttr(p)
44 , nHash0(0)
48 LotAttrCache::ENTRY::~ENTRY ()
50 delete pPattAttr;
53 LotAttrCache::LotAttrCache (LOTUS_ROOT* pLotRoot):
54 mpLotusRoot(pLotRoot)
56 pDocPool = mpLotusRoot->pDoc->GetPool();
58 pColTab = new Color [ 8 ];
59 pColTab[ 0 ] = Color( COL_WHITE );
60 pColTab[ 1 ] = Color( COL_LIGHTBLUE );
61 pColTab[ 2 ] = Color( COL_LIGHTGREEN );
62 pColTab[ 3 ] = Color( COL_LIGHTCYAN );
63 pColTab[ 4 ] = Color( COL_LIGHTRED );
64 pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
65 pColTab[ 6 ] = Color( COL_YELLOW );
66 pColTab[ 7 ] = Color( COL_BLACK );
68 ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR ); // 1
69 ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
70 ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
71 ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
72 ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
73 ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR ); // 6
75 pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
76 pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
80 LotAttrCache::~LotAttrCache()
82 for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
83 delete ppColorItems[ nCnt ];
85 delete pBlack;
86 delete pWhite;
88 delete[] pColTab;
92 const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
94 sal_uInt32 nRefHash;
95 MakeHash( rAttr, nRefHash );
97 boost::ptr_vector<ENTRY>::const_iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
98 boost::bind(&ENTRY::nHash0,_1) == nRefHash);
100 if (iter != aEntries.end())
101 return *(iter->pPattAttr);
103 // neues PatternAttribute erzeugen
104 ScPatternAttr* pNewPatt = new ScPatternAttr(pDocPool);
106 SfxItemSet& rItemSet = pNewPatt->GetItemSet();
107 ENTRY *pAkt = new ENTRY( pNewPatt );
109 pAkt->nHash0 = nRefHash;
111 mpLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
113 sal_uInt8 nLine = rAttr.nLineStyle;
114 if( nLine )
116 SvxBoxItem aBox( ATTR_BORDER );
117 ::editeng::SvxBorderLine aTop, aLeft, aBottom, aRight;
119 LotusToScBorderLine( nLine, aLeft );
120 nLine >>= 2;
121 LotusToScBorderLine( nLine, aRight );
122 nLine >>= 2;
123 LotusToScBorderLine( nLine, aTop );
124 nLine >>= 2;
125 LotusToScBorderLine( nLine, aBottom );
127 aBox.SetLine( &aTop, BOX_LINE_TOP );
128 aBox.SetLine( &aLeft, BOX_LINE_LEFT );
129 aBox.SetLine( &aBottom, BOX_LINE_BOTTOM );
130 aBox.SetLine( &aRight, BOX_LINE_RIGHT );
132 rItemSet.Put( aBox );
135 sal_uInt8 nFontCol = rAttr.nFontCol & 0x07;
136 if( nFontCol )
138 // nFontCol > 0
139 if( nFontCol < 7 )
140 rItemSet.Put( GetColorItem( nFontCol ) );
141 else
142 rItemSet.Put( *pWhite );
145 sal_uInt8 nBack = rAttr.nBack & 0x1F;
146 if( nBack )
147 rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
149 if( rAttr.nBack & 0x80 )
151 SvxHorJustifyItem aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
152 rItemSet.Put( aHorJustify );
155 aEntries.push_back(pAkt);
157 return *pNewPatt;
161 void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, ::editeng::SvxBorderLine& aBL )
163 nLine &= 0x03;
165 switch ( nLine )
167 case 0: aBL.SetBorderLineStyle(table::BorderLineStyle::NONE); break;
168 case 1: aBL.SetWidth( DEF_LINE_WIDTH_1 ); break;
169 case 2: aBL.SetWidth( DEF_LINE_WIDTH_2 ); break;
170 case 3:
172 aBL.SetBorderLineStyle(table::BorderLineStyle::DOUBLE_THIN);
173 aBL.SetWidth( DEF_LINE_WIDTH_1 );
175 break;
179 const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
181 OSL_ENSURE( nLotIndex > 0 && nLotIndex < 7,
182 "-LotAttrCache::GetColorItem(): caller hast to check index!" );
184 return *ppColorItems[ nLotIndex - 1 ];
187 const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
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!" );
192 return pColTab[ nLotIndex ];
195 void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
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?!" );
201 boost::ptr_vector<ENTRY>::reverse_iterator iterLast = aEntries.rbegin();
203 if(iterLast != aEntries.rend())
205 if( ( iterLast->nLastRow == nRow - 1 ) && ( &rAttr == iterLast->pPattAttr ) )
206 iterLast->nLastRow = nRow;
207 else
209 ENTRY *pAkt = new ENTRY;
211 pAkt->pPattAttr = &rAttr;
212 pAkt->nFirstRow = pAkt->nLastRow = nRow;
214 aEntries.push_back(pAkt);
217 else
218 { // erster Eintrag
219 ENTRY *pAkt = new ENTRY;
220 pAkt->pPattAttr = &rAttr;
221 pAkt->nFirstRow = pAkt->nLastRow = nRow;
223 aEntries.push_back(pAkt);
228 void LotAttrCol::Apply( const SCCOL nColNum, const SCTAB nTabNum )
230 ScDocument* pDoc = pLotusRoot->pDoc;
232 boost::ptr_vector<ENTRY>::iterator iter;
233 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
235 pDoc->ApplyPatternAreaTab(nColNum,iter->nFirstRow,nColNum,iter->nLastRow,
236 nTabNum, *(iter->pPattAttr));
240 LotAttrTable::LotAttrTable(LOTUS_ROOT* pLotRoot):
241 aAttrCache(pLotRoot)
245 void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
246 const LotAttrWK3& rAttr )
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 const ScPatternAttr &rPattAttr = aAttrCache.GetPattAttr( rAttr );
252 SCCOL nColCnt;
254 for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
255 pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
259 void LotAttrTable::Apply( const SCTAB nTabNum )
261 SCCOL nColCnt;
262 for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
263 pCols[ nColCnt ].Apply( nColCnt, nTabNum ); // macht auch gleich ein Clear() am Ende
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */