1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scfilt.hxx"
26
27
28
29 //------------------------------------------------------------------------
30
31 #include "scitems.hxx"
32 #include <svx/algitem.hxx>
33 #include <editeng/boxitem.hxx>
34 #include <editeng/brshitem.hxx>
35
36 #include "document.hxx"
37 #include "patattr.hxx"
38 #include "docpool.hxx"
39 #include "attrib.hxx"
40
41 #include "lotattr.hxx"
42 #include "lotfntbf.hxx"
43 #include "root.hxx"
44
45
46
LotusToScBorderLine(sal_uInt8 nLine,SvxBorderLine & aBL)47 void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, SvxBorderLine& aBL )
48 {
49 static const sal_uInt16 pPara[ 4 ][ 3 ] =
50 {
51 { 0,0,0 },
52 { DEF_LINE_WIDTH_1, 0, 0 },
53 { DEF_LINE_WIDTH_2, 0, 0 },
54 { DEF_LINE_WIDTH_1, DEF_LINE_WIDTH_1, DEF_LINE_WIDTH_1 }
55 };
56
57 nLine &= 0x03;
58
59 if( nLine )
60 {
61 aBL.SetOutWidth( pPara[ nLine ][ 0 ] );
62 aBL.SetInWidth( pPara[ nLine ][ 1 ] );
63 aBL.SetDistance( pPara[ nLine ][ 2 ] );
64 }
65 }
66
67
GetColorItem(const sal_uInt8 nLotIndex) const68 const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
69 {
70 DBG_ASSERT( nLotIndex > 0 && nLotIndex < 7,
71 "-LotAttrCache::GetColorItem(): caller hast to check index!" );
72
73 return *ppColorItems[ nLotIndex - 1 ];
74 }
75
76
GetColor(const sal_uInt8 nLotIndex) const77 const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
78 {
79 // Farbe <-> Index passt fuer Background, nicht aber fuer Fonts (0 <-> 7)!
80 DBG_ASSERT( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7, caller hast to check index!" );
81 return pColTab[ nLotIndex ];
82 }
83
84
LotAttrCache(void)85 LotAttrCache::LotAttrCache( void )
86 {
87 pDocPool = pLotusRoot->pDoc->GetPool();
88
89 pColTab = new Color [ 8 ];
90 pColTab[ 0 ] = Color( COL_WHITE );
91 pColTab[ 1 ] = Color( COL_LIGHTBLUE );
92 pColTab[ 2 ] = Color( COL_LIGHTGREEN );
93 pColTab[ 3 ] = Color( COL_LIGHTCYAN );
94 pColTab[ 4 ] = Color( COL_LIGHTRED );
95 pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
96 pColTab[ 6 ] = Color( COL_YELLOW );
97 pColTab[ 7 ] = Color( COL_BLACK );
98
99 ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR ); // 1
100 ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
101 ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
102 ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
103 ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
104 ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR ); // 6
105
106 pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
107 pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
108 }
109
110
~LotAttrCache()111 LotAttrCache::~LotAttrCache()
112 {
113 ENTRY* pAkt = ( ENTRY* ) List::First();
114
115 while( pAkt )
116 {
117 delete pAkt;
118 pAkt = ( ENTRY* ) List::Next();
119 }
120
121 for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
122 delete ppColorItems[ nCnt ];
123
124 delete pBlack;
125 delete pWhite;
126
127 delete[] pColTab;
128 }
129
130
GetPattAttr(const LotAttrWK3 & rAttr)131 const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
132 {
133 sal_uInt32 nRefHash;
134 ENTRY* pAkt = ( ENTRY* ) List::First();
135
136 MakeHash( rAttr, nRefHash );
137
138 while( pAkt )
139 {
140 if( *pAkt == nRefHash )
141 return *pAkt->pPattAttr;
142
143 pAkt = ( ENTRY* ) List::Next();
144 }
145
146 // neues PatternAttribute erzeugen
147 ScPatternAttr* pNewPatt = new ScPatternAttr( pDocPool );
148 SfxItemSet& rItemSet = pNewPatt->GetItemSet();
149 pAkt = new ENTRY( pNewPatt );
150
151 pAkt->nHash0 = nRefHash;
152
153 pLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
154
155 sal_uInt8 nLine = rAttr.nLineStyle;
156 if( nLine )
157 {
158 SvxBoxItem aBox( ATTR_BORDER );
159 SvxBorderLine aTop, aLeft, aBottom, aRight;
160
161 LotusToScBorderLine( nLine, aLeft );
162 nLine >>= 2;
163 LotusToScBorderLine( nLine, aRight );
164 nLine >>= 2;
165 LotusToScBorderLine( nLine, aTop );
166 nLine >>= 2;
167 LotusToScBorderLine( nLine, aBottom );
168
169 aBox.SetLine( &aTop, BOX_LINE_TOP );
170 aBox.SetLine( &aLeft, BOX_LINE_LEFT );
171 aBox.SetLine( &aBottom, BOX_LINE_BOTTOM );
172 aBox.SetLine( &aRight, BOX_LINE_RIGHT );
173
174 rItemSet.Put( aBox );
175 }
176
177 sal_uInt8 nFontCol = rAttr.nFontCol & 0x07;
178 if( nFontCol )
179 {
180 // nFontCol > 0
181 if( nFontCol < 7 )
182 rItemSet.Put( GetColorItem( nFontCol ) );
183 else
184 rItemSet.Put( *pWhite );
185 }
186
187 sal_uInt8 nBack = rAttr.nBack & 0x1F;
188 if( nBack )
189 rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
190
191 if( rAttr.nBack & 0x80 )
192 {
193 SvxHorJustifyItem aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
194 rItemSet.Put( aHorJustify );
195 }
196
197 List::Insert( pAkt, LIST_APPEND );
198
199 return *pNewPatt;
200 }
201
202
~LotAttrCol()203 LotAttrCol::~LotAttrCol()
204 {
205 Clear();
206 }
207
208
SetAttr(const SCROW nRow,const ScPatternAttr & rAttr)209 void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
210 {
211 // Actually with the current implementation of MAXROWCOUNT>=64k and nRow
212 // being read as sal_uInt16 there's no chance that nRow would be invalid..
213 DBG_ASSERT( ValidRow(nRow), "*LotAttrCol::SetAttr(): ... und rums?!" );
214
215 ENTRY* pAkt = ( ENTRY* ) List::Last();
216
217 if( pAkt )
218 {
219 if( ( pAkt->nLastRow == nRow - 1 ) && ( &rAttr == pAkt->pPattAttr ) )
220 pAkt->nLastRow = nRow;
221 else
222 {
223 pAkt = new ENTRY;
224
225 pAkt->pPattAttr = &rAttr;
226 pAkt->nFirstRow = pAkt->nLastRow = nRow;
227 List::Insert( pAkt, LIST_APPEND );
228 }
229 }
230 else
231 { // erster Eintrag
232 pAkt = new ENTRY;
233 pAkt->pPattAttr = &rAttr;
234 pAkt->nFirstRow = pAkt->nLastRow = nRow;
235 List::Insert( pAkt, LIST_APPEND );
236 }
237 }
238
239
Apply(const SCCOL nColNum,const SCTAB nTabNum,const sal_Bool)240 void LotAttrCol::Apply( const SCCOL nColNum, const SCTAB nTabNum, const sal_Bool /*bClear*/ )
241 {
242 ScDocument* pDoc = pLotusRoot->pDoc;
243 ENTRY* pAkt = ( ENTRY* ) List::First();
244
245 while( pAkt )
246 {
247 pDoc->ApplyPatternAreaTab( nColNum, pAkt->nFirstRow, nColNum, pAkt->nLastRow,
248 nTabNum, *pAkt->pPattAttr );
249
250 pAkt = ( ENTRY* ) List::Next();
251 }
252 }
253
254
Clear(void)255 void LotAttrCol::Clear( void )
256 {
257 ENTRY* pAkt = ( ENTRY* ) List::First();
258
259 while( pAkt )
260 {
261 delete pAkt;
262 pAkt = ( ENTRY* ) List::Next();
263 }
264 }
265
266
LotAttrTable(void)267 LotAttrTable::LotAttrTable( void )
268 {
269 }
270
271
~LotAttrTable()272 LotAttrTable::~LotAttrTable()
273 {
274 }
275
276
SetAttr(const SCCOL nColFirst,const SCCOL nColLast,const SCROW nRow,const LotAttrWK3 & rAttr)277 void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
278 const LotAttrWK3& rAttr )
279 {
280 // With the current implementation of MAXCOLCOUNT>=1024 and nColFirst and
281 // nColLast being calculated as sal_uInt8+sal_uInt8 there's no chance that
282 // they would be invalid.
283 const ScPatternAttr& rPattAttr = aAttrCache.GetPattAttr( rAttr );
284 SCCOL nColCnt;
285
286 for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
287 pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
288 }
289
290
Apply(const SCTAB nTabNum)291 void LotAttrTable::Apply( const SCTAB nTabNum )
292 {
293 SCCOL nColCnt;
294 for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
295 pCols[ nColCnt ].Apply( nColCnt, nTabNum ); // macht auch gleich ein Clear() am Ende
296 }
297
298
299
300
301