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 : #include "lotattr.hxx"
21 :
22 : #include <boost/bind.hpp>
23 :
24 : #include <editeng/boxitem.hxx>
25 : #include <editeng/brushitem.hxx>
26 : #include <editeng/justifyitem.hxx>
27 : #include <svx/algitem.hxx>
28 :
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"
36 :
37 : using namespace ::com::sun::star;
38 :
39 0 : LotAttrCache::ENTRY::ENTRY (ScPatternAttr* p)
40 : : pPattAttr(p)
41 0 : , nHash0(0)
42 : {
43 0 : }
44 :
45 0 : LotAttrCache::ENTRY::~ENTRY ()
46 : {
47 0 : delete pPattAttr;
48 0 : }
49 :
50 4 : LotAttrCache::LotAttrCache (LOTUS_ROOT* pLotRoot)
51 4 : : mpLotusRoot(pLotRoot)
52 : {
53 4 : pDocPool = mpLotusRoot->pDoc->GetPool();
54 :
55 4 : pColTab = new Color [ 8 ];
56 4 : pColTab[ 0 ] = Color( COL_WHITE );
57 4 : pColTab[ 1 ] = Color( COL_LIGHTBLUE );
58 4 : pColTab[ 2 ] = Color( COL_LIGHTGREEN );
59 4 : pColTab[ 3 ] = Color( COL_LIGHTCYAN );
60 4 : pColTab[ 4 ] = Color( COL_LIGHTRED );
61 4 : pColTab[ 5 ] = Color( COL_LIGHTMAGENTA );
62 4 : pColTab[ 6 ] = Color( COL_YELLOW );
63 4 : pColTab[ 7 ] = Color( COL_BLACK );
64 :
65 4 : ppColorItems[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR ); // 1
66 4 : ppColorItems[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR );
67 4 : ppColorItems[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR );
68 4 : ppColorItems[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR );
69 4 : ppColorItems[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR );
70 4 : ppColorItems[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR ); // 6
71 :
72 4 : pBlack = new SvxColorItem( Color( COL_BLACK ), ATTR_FONT_COLOR );
73 4 : pWhite = new SvxColorItem( Color( COL_WHITE ), ATTR_FONT_COLOR );
74 4 : }
75 :
76 8 : LotAttrCache::~LotAttrCache()
77 : {
78 28 : for( sal_uInt16 nCnt = 0 ; nCnt < 6 ; nCnt++ )
79 24 : delete ppColorItems[ nCnt ];
80 :
81 4 : delete pBlack;
82 4 : delete pWhite;
83 :
84 4 : delete[] pColTab;
85 4 : }
86 :
87 0 : const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr )
88 : {
89 : sal_uInt32 nRefHash;
90 0 : MakeHash( rAttr, nRefHash );
91 :
92 : boost::ptr_vector<ENTRY>::const_iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
93 0 : boost::bind(&ENTRY::nHash0,_1) == nRefHash);
94 :
95 0 : if (iter != aEntries.end())
96 0 : return *(iter->pPattAttr);
97 :
98 : // generate new Pattern Attribute
99 0 : ScPatternAttr* pNewPatt = new ScPatternAttr(pDocPool);
100 :
101 0 : SfxItemSet& rItemSet = pNewPatt->GetItemSet();
102 0 : ENTRY *pAkt = new ENTRY( pNewPatt );
103 :
104 0 : pAkt->nHash0 = nRefHash;
105 :
106 0 : mpLotusRoot->pFontBuff->Fill( rAttr.nFont, rItemSet );
107 :
108 0 : sal_uInt8 nLine = rAttr.nLineStyle;
109 0 : if( nLine )
110 : {
111 0 : SvxBoxItem aBox( ATTR_BORDER );
112 0 : ::editeng::SvxBorderLine aTop, aLeft, aBottom, aRight;
113 :
114 0 : LotusToScBorderLine( nLine, aLeft );
115 0 : nLine >>= 2;
116 0 : LotusToScBorderLine( nLine, aRight );
117 0 : nLine >>= 2;
118 0 : LotusToScBorderLine( nLine, aTop );
119 0 : nLine >>= 2;
120 0 : LotusToScBorderLine( nLine, aBottom );
121 :
122 0 : aBox.SetLine( &aTop, SvxBoxItemLine::TOP );
123 0 : aBox.SetLine( &aLeft, SvxBoxItemLine::LEFT );
124 0 : aBox.SetLine( &aBottom, SvxBoxItemLine::BOTTOM );
125 0 : aBox.SetLine( &aRight, SvxBoxItemLine::RIGHT );
126 :
127 0 : rItemSet.Put( aBox );
128 : }
129 :
130 0 : sal_uInt8 nFontCol = rAttr.nFontCol & 0x07;
131 0 : if( nFontCol )
132 : {
133 : // nFontCol > 0
134 0 : if( nFontCol < 7 )
135 0 : rItemSet.Put( GetColorItem( nFontCol ) );
136 : else
137 0 : rItemSet.Put( *pWhite );
138 : }
139 :
140 0 : sal_uInt8 nBack = rAttr.nBack & 0x1F;
141 0 : if( nBack )
142 0 : rItemSet.Put( SvxBrushItem( GetColor( nBack & 0x07 ), ATTR_BACKGROUND ) );
143 :
144 0 : if( rAttr.nBack & 0x80 )
145 : {
146 0 : SvxHorJustifyItem aHorJustify(SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
147 0 : rItemSet.Put( aHorJustify );
148 : }
149 :
150 0 : aEntries.push_back(pAkt);
151 :
152 0 : return *pNewPatt;
153 : }
154 :
155 0 : void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine, ::editeng::SvxBorderLine& aBL )
156 : {
157 0 : nLine &= 0x03;
158 :
159 0 : switch ( nLine )
160 : {
161 0 : case 0: aBL.SetBorderLineStyle(table::BorderLineStyle::NONE); break;
162 0 : case 1: aBL.SetWidth( DEF_LINE_WIDTH_1 ); break;
163 0 : case 2: aBL.SetWidth( DEF_LINE_WIDTH_2 ); break;
164 : case 3:
165 : {
166 0 : aBL.SetBorderLineStyle(table::BorderLineStyle::DOUBLE_THIN);
167 0 : aBL.SetWidth( DEF_LINE_WIDTH_1 );
168 : }
169 0 : break;
170 : }
171 0 : }
172 :
173 0 : const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
174 : {
175 : OSL_ENSURE( nLotIndex > 0 && nLotIndex < 7,
176 : "-LotAttrCache::GetColorItem(): caller hast to check index!" );
177 :
178 0 : return *ppColorItems[ nLotIndex - 1 ];
179 : }
180 :
181 24 : const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
182 : {
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!" );
185 :
186 24 : return pColTab[ nLotIndex ];
187 : }
188 :
189 0 : void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
190 : {
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?!" );
194 :
195 0 : boost::ptr_vector<ENTRY>::reverse_iterator iterLast = aEntries.rbegin();
196 :
197 0 : if(iterLast != aEntries.rend())
198 : {
199 0 : if( ( iterLast->nLastRow == nRow - 1 ) && ( &rAttr == iterLast->pPattAttr ) )
200 0 : iterLast->nLastRow = nRow;
201 : else
202 : {
203 0 : ENTRY *pAkt = new ENTRY;
204 :
205 0 : pAkt->pPattAttr = &rAttr;
206 0 : pAkt->nFirstRow = pAkt->nLastRow = nRow;
207 :
208 0 : aEntries.push_back(pAkt);
209 : }
210 : }
211 : else
212 : { // first entry
213 0 : ENTRY *pAkt = new ENTRY;
214 0 : pAkt->pPattAttr = &rAttr;
215 0 : pAkt->nFirstRow = pAkt->nLastRow = nRow;
216 :
217 0 : aEntries.push_back(pAkt);
218 : }
219 0 : }
220 :
221 0 : void LotAttrCol::Apply(LOTUS_ROOT* pLotusRoot, const SCCOL nColNum, const SCTAB nTabNum)
222 : {
223 0 : ScDocument* pDoc = pLotusRoot->pDoc;
224 :
225 0 : boost::ptr_vector<ENTRY>::iterator iter;
226 0 : for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
227 : {
228 0 : pDoc->ApplyPatternAreaTab(nColNum,iter->nFirstRow,nColNum,iter->nLastRow,
229 0 : nTabNum, *(iter->pPattAttr));
230 : }
231 0 : }
232 :
233 4 : LotAttrTable::LotAttrTable(LOTUS_ROOT* pLotRoot):
234 4 : aAttrCache(pLotRoot)
235 : {
236 4 : }
237 :
238 0 : void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
239 : const LotAttrWK3& rAttr )
240 : {
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 0 : const ScPatternAttr &rPattAttr = aAttrCache.GetPattAttr( rAttr );
245 : SCCOL nColCnt;
246 :
247 0 : for( nColCnt = nColFirst ; nColCnt <= nColLast ; nColCnt++ )
248 0 : pCols[ nColCnt ].SetAttr( nRow, rPattAttr );
249 0 : }
250 :
251 0 : void LotAttrTable::Apply(LOTUS_ROOT* pLotusRoot, const SCTAB nTabNum)
252 : {
253 : SCCOL nColCnt;
254 0 : for( nColCnt = 0 ; nColCnt <= MAXCOL ; nColCnt++ )
255 0 : pCols[ nColCnt ].Apply(pLotusRoot, nColCnt, nTabNum); // does a Clear() at end
256 30 : }
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|