fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / lotus / lotattr.cxx
blob9444d9cba035301fd6bd0f9f39da05a268b31ab3
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 .
20 #include "lotattr.hxx"
22 #include <boost/bind.hpp>
24 #include <editeng/boxitem.hxx>
25 #include <editeng/brushitem.hxx>
26 #include <editeng/justifyitem.hxx>
27 #include <svx/algitem.hxx>
29 #include "attrib.hxx"
30 #include "docpool.hxx"
31 #include "document.hxx"
32 #include "lotfntbf.hxx"
33 #include "patattr.hxx"
34 #include "root.hxx"
35 #include "scitems.hxx"
37 using namespace ::com::sun::star;
39 LotAttrCache::ENTRY::ENTRY (ScPatternAttr* p)
40 : pPattAttr(p)
41 , nHash0(0)
45 LotAttrCache::ENTRY::~ENTRY ()
47 delete pPattAttr;
50 LotAttrCache::LotAttrCache (LOTUS_ROOT* pLotRoot)
51 : mpLotusRoot(pLotRoot)
53 pDocPool = mpLotusRoot->pDoc->GetPool();
55 pColTab = new Color [ 8 ];
56 pColTab[ 0 ] = Color( COL_WHITE );
57 pColTab[ 1 ] = Color( COL_LIGHTBLUE );
58 pColTab[ 2 ] = Color( COL_LIGHTGREEN );
59 pColTab[ 3 ] = Color( COL_LIGHTCYAN );
60 pColTab[ 4 ] = Color( COL_LIGHTRED );
61 pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
62 pColTab[ 6 ] = Color( COL_YELLOW );
63 pColTab[ 7 ] = Color( COL_BLACK );
65 ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR ); // 1
66 ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
67 ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
68 ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
69 ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
70 ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR ); // 6
72 pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
73 pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
76 LotAttrCache::~LotAttrCache()
78 for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
79 delete ppColorItems[ nCnt ];
81 delete pBlack;
82 delete pWhite;
84 delete[] pColTab;
87 const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
89 sal_uInt32 nRefHash;
90 MakeHash( rAttr, nRefHash );
92 boost::ptr_vector<ENTRY>::const_iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
93 boost::bind(&ENTRY::nHash0,_1) == nRefHash);
95 if (iter != aEntries.end())
96 return *(iter->pPattAttr);
98 // generate new Pattern Attribute
99 ScPatternAttr* pNewPatt = new ScPatternAttr(pDocPool);
101 SfxItemSet& rItemSet = pNewPatt->GetItemSet();
102 ENTRY *pAkt = new ENTRY( pNewPatt );
104 pAkt->nHash0 = nRefHash;
106 mpLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
108 sal_uInt8 nLine = rAttr.nLineStyle;
109 if( nLine )
111 SvxBoxItem aBox( ATTR_BORDER );
112 ::editeng::SvxBorderLine aTop, aLeft, aBottom, aRight;
114 LotusToScBorderLine( nLine, aLeft );
115 nLine >>= 2;
116 LotusToScBorderLine( nLine, aRight );
117 nLine >>= 2;
118 LotusToScBorderLine( nLine, aTop );
119 nLine >>= 2;
120 LotusToScBorderLine( nLine, aBottom );
122 aBox.SetLine( &aTop, SvxBoxItemLine::TOP );
123 aBox.SetLine( &aLeft, SvxBoxItemLine::LEFT );
124 aBox.SetLine( &aBottom, SvxBoxItemLine::BOTTOM );
125 aBox.SetLine( &aRight, SvxBoxItemLine::RIGHT );
127 rItemSet.Put( aBox );
130 sal_uInt8 nFontCol = rAttr.nFontCol & 0x07;
131 if( nFontCol )
133 // nFontCol > 0
134 if( nFontCol < 7 )
135 rItemSet.Put( GetColorItem( nFontCol ) );
136 else
137 rItemSet.Put( *pWhite );
140 sal_uInt8 nBack = rAttr.nBack & 0x1F;
141 if( nBack )
142 rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
144 if( rAttr.nBack & 0x80 )
146 SvxHorJustifyItem aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
147 rItemSet.Put( aHorJustify );
150 aEntries.push_back(pAkt);
152 return *pNewPatt;
155 void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, ::editeng::SvxBorderLine& aBL )
157 nLine &= 0x03;
159 switch ( nLine )
161 case 0: aBL.SetBorderLineStyle(table::BorderLineStyle::NONE); break;
162 case 1: aBL.SetWidth( DEF_LINE_WIDTH_1 ); break;
163 case 2: aBL.SetWidth( DEF_LINE_WIDTH_2 ); break;
164 case 3:
166 aBL.SetBorderLineStyle(table::BorderLineStyle::DOUBLE_THIN);
167 aBL.SetWidth( DEF_LINE_WIDTH_1 );
169 break;
173 const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
175 OSL_ENSURE( nLotIndex > 0 && nLotIndex < 7,
176 "-LotAttrCache::GetColorItem(): caller hast to check index!" );
178 return *ppColorItems[ nLotIndex - 1 ];
181 const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
183 // color <-> index fits background, but not for fonts (0 <-> 7)!
184 OSL_ENSURE( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7, caller hast to check index!" );
186 return pColTab[ nLotIndex ];
189 void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
191 // Actually with the current implementation of MAXROWCOUNT>=64k and nRow
192 // being read as sal_uInt16 there's no chance that nRow would be invalid..
193 OSL_ENSURE( ValidRow(nRow), "*LotAttrCol::SetAttr(): ... und rums?!" );
195 boost::ptr_vector<ENTRY>::reverse_iterator iterLast = aEntries.rbegin();
197 if(iterLast != aEntries.rend())
199 if( ( iterLast->nLastRow == nRow - 1 ) && ( &rAttr == iterLast->pPattAttr ) )
200 iterLast->nLastRow = nRow;
201 else
203 ENTRY *pAkt = new ENTRY;
205 pAkt->pPattAttr = &rAttr;
206 pAkt->nFirstRow = pAkt->nLastRow = nRow;
208 aEntries.push_back(pAkt);
211 else
212 { // first entry
213 ENTRY *pAkt = new ENTRY;
214 pAkt->pPattAttr = &rAttr;
215 pAkt->nFirstRow = pAkt->nLastRow = nRow;
217 aEntries.push_back(pAkt);
221 void LotAttrCol::Apply(LOTUS_ROOT* pLotusRoot, const SCCOL nColNum, const SCTAB nTabNum)
223 ScDocument* pDoc = pLotusRoot->pDoc;
225 boost::ptr_vector<ENTRY>::iterator iter;
226 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
228 pDoc->ApplyPatternAreaTab(nColNum,iter->nFirstRow,nColNum,iter->nLastRow,
229 nTabNum, *(iter->pPattAttr));
233 LotAttrTable::LotAttrTable(LOTUS_ROOT* pLotRoot):
234 aAttrCache(pLotRoot)
238 void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
239 const LotAttrWK3& rAttr )
241 // With the current implementation of MAXCOLCOUNT>=1024 and nColFirst and
242 // nColLast being calculated as sal_uInt8+sal_uInt8 there's no chance that
243 // they would be invalid.
244 const ScPatternAttr &rPattAttr = aAttrCache.GetPattAttr( rAttr );
245 SCCOL nColCnt;
247 for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
248 pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
251 void LotAttrTable::Apply(LOTUS_ROOT* pLotusRoot, const SCTAB nTabNum)
253 SCCOL nColCnt;
254 for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
255 pCols[ nColCnt ].Apply(pLotusRoot, nColCnt, nTabNum); // does a Clear() at end
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */