update dev300-m58
[ooovba.git] / sc / source / filter / lotus / lotattr.cxx
blob3ec3277cc0003dd487a312f4c4fb007be1d29a9e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lotattr.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/algitem.hxx>
40 #include <svx/boxitem.hxx>
41 #include <svx/brshitem.hxx>
43 #include "document.hxx"
44 #include "patattr.hxx"
45 #include "docpool.hxx"
46 #include "attrib.hxx"
48 #include "lotattr.hxx"
49 #include "lotfntbf.hxx"
50 #include "root.hxx"
54 void LotAttrCache::LotusToScBorderLine( UINT8 nLine, SvxBorderLine& aBL )
56 static const UINT16 pPara[ 4 ][ 3 ] =
58 { 0,0,0 },
59 { DEF_LINE_WIDTH_1, 0, 0 },
60 { DEF_LINE_WIDTH_2, 0, 0 },
61 { DEF_LINE_WIDTH_1, DEF_LINE_WIDTH_1, DEF_LINE_WIDTH_1 }
64 nLine &= 0x03;
66 if( nLine )
68 aBL.SetOutWidth( pPara[ nLine ][ 0 ] );
69 aBL.SetInWidth( pPara[ nLine ][ 1 ] );
70 aBL.SetDistance( pPara[ nLine ][ 2 ] );
75 const SvxColorItem& LotAttrCache::GetColorItem( const UINT8 nLotIndex ) const
77 DBG_ASSERT( nLotIndex > 0 && nLotIndex < 7,
78 "-LotAttrCache::GetColorItem(): so nicht!" );
80 return *ppColorItems[ nLotIndex - 1 ];
84 const Color& LotAttrCache::GetColor( const UINT8 nLotIndex ) const
86 // Farbe <-> Index passt fuer Background, nicht aber fuer Fonts (0 <-> 7)!
87 DBG_ASSERT( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7!" );
88 return pColTab[ nLotIndex ];
92 LotAttrCache::LotAttrCache( void )
94 pDocPool = pLotusRoot->pDoc->GetPool();
96 pColTab = new Color [ 8 ];
97 pColTab[ 0 ] = Color( COL_WHITE );
98 pColTab[ 1 ] = Color( COL_LIGHTBLUE );
99 pColTab[ 2 ] = Color( COL_LIGHTGREEN );
100 pColTab[ 3 ] = Color( COL_LIGHTCYAN );
101 pColTab[ 4 ] = Color( COL_LIGHTRED );
102 pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
103 pColTab[ 6 ] = Color( COL_YELLOW );
104 pColTab[ 7 ] = Color( COL_BLACK );
106 ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR ); // 1
107 ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
108 ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
109 ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
110 ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
111 ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR ); // 6
113 pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
114 pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
118 LotAttrCache::~LotAttrCache()
120 ENTRY* pAkt = ( ENTRY* ) List::First();
122 while( pAkt )
124 delete pAkt;
125 pAkt = ( ENTRY* ) List::Next();
128 for( UINT16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
129 delete ppColorItems[ nCnt ];
131 delete pBlack;
132 delete pWhite;
134 delete[] pColTab;
138 const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
140 UINT32 nRefHash;
141 ENTRY* pAkt = ( ENTRY* ) List::First();
143 MakeHash( rAttr, nRefHash );
145 while( pAkt )
147 if( *pAkt == nRefHash )
148 return *pAkt->pPattAttr;
150 pAkt = ( ENTRY* ) List::Next();
153 // neues PatternAttribute erzeugen
154 ScPatternAttr* pNewPatt = new ScPatternAttr( pDocPool );
155 SfxItemSet& rItemSet = pNewPatt->GetItemSet();
156 pAkt = new ENTRY( pNewPatt );
158 pAkt->nHash0 = nRefHash;
160 pLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
162 UINT8 nLine = rAttr.nLineStyle;
163 if( nLine )
165 SvxBoxItem aBox( ATTR_BORDER );
166 SvxBorderLine aTop, aLeft, aBottom, aRight;
168 LotusToScBorderLine( nLine, aLeft );
169 nLine >>= 2;
170 LotusToScBorderLine( nLine, aRight );
171 nLine >>= 2;
172 LotusToScBorderLine( nLine, aTop );
173 nLine >>= 2;
174 LotusToScBorderLine( nLine, aBottom );
176 aBox.SetLine( &aTop, BOX_LINE_TOP );
177 aBox.SetLine( &aLeft, BOX_LINE_LEFT );
178 aBox.SetLine( &aBottom, BOX_LINE_BOTTOM );
179 aBox.SetLine( &aRight, BOX_LINE_RIGHT );
181 rItemSet.Put( aBox );
184 UINT8 nFontCol = rAttr.nFontCol & 0x07;
185 if( nFontCol )
187 // nFontCol > 0
188 if( nFontCol < 7 )
189 rItemSet.Put( GetColorItem( nFontCol ) );
190 else
191 rItemSet.Put( *pWhite );
194 UINT8 nBack = rAttr.nBack & 0x1F;
195 if( nBack )
196 rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
198 if( rAttr.nBack & 0x80 )
200 SvxHorJustifyItem aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
201 rItemSet.Put( aHorJustify );
204 List::Insert( pAkt, LIST_APPEND );
206 return *pNewPatt;
210 LotAttrCol::~LotAttrCol()
212 Clear();
216 void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
218 DBG_ASSERT( ValidRow(nRow), "*LotAttrCol::SetAttr(): ... und rums?!" );
220 ENTRY* pAkt = ( ENTRY* ) List::Last();
222 if( pAkt )
224 if( ( pAkt->nLastRow == nRow - 1 ) && ( &rAttr == pAkt->pPattAttr ) )
225 pAkt->nLastRow = nRow;
226 else
228 pAkt = new ENTRY;
230 pAkt->pPattAttr = &rAttr;
231 pAkt->nFirstRow = pAkt->nLastRow = nRow;
232 List::Insert( pAkt, LIST_APPEND );
235 else
236 { // erster Eintrag
237 pAkt = new ENTRY;
238 pAkt->pPattAttr = &rAttr;
239 pAkt->nFirstRow = pAkt->nLastRow = nRow;
240 List::Insert( pAkt, LIST_APPEND );
245 void LotAttrCol::Apply( const SCCOL nColNum, const SCTAB nTabNum, const BOOL /*bClear*/ )
247 ScDocument* pDoc = pLotusRoot->pDoc;
248 ENTRY* pAkt = ( ENTRY* ) List::First();
250 while( pAkt )
252 pDoc->ApplyPatternAreaTab( nColNum, pAkt->nFirstRow, nColNum, pAkt->nLastRow,
253 nTabNum, *pAkt->pPattAttr );
255 pAkt = ( ENTRY* ) List::Next();
260 void LotAttrCol::Clear( void )
262 ENTRY* pAkt = ( ENTRY* ) List::First();
264 while( pAkt )
266 delete pAkt;
267 pAkt = ( ENTRY* ) List::Next();
272 LotAttrTable::LotAttrTable( void )
277 LotAttrTable::~LotAttrTable()
282 void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
283 const LotAttrWK3& rAttr )
285 const ScPatternAttr& rPattAttr = aAttrCache.GetPattAttr( rAttr );
286 SCCOL nColCnt;
288 for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
289 pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
293 void LotAttrTable::Apply( const SCTAB nTabNum )
295 SCCOL nColCnt;
296 for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
297 pCols[ nColCnt ].Apply( nColCnt, nTabNum ); // macht auch gleich ein Clear() am Ende