1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <editeng/borderline.hxx>
24 #include <editeng/boxitem.hxx>
25 #include <editeng/brushitem.hxx>
26 #include <editeng/colritem.hxx>
27 #include <editeng/justifyitem.hxx>
28 #include <sal/log.hxx>
30 #include <docpool.hxx>
31 #include <document.hxx>
32 #include <lotfntbf.hxx>
33 #include <patattr.hxx>
35 #include <scitems.hxx>
37 using namespace ::com::sun::star
;
39 LotAttrCache::ENTRY::ENTRY (std::unique_ptr
<ScPatternAttr
> p
)
40 : pPattAttr(std::move(p
))
45 LotAttrCache::ENTRY::~ENTRY ()
49 LotAttrCache::LotAttrCache (LOTUS_ROOT
* pLotRoot
)
50 : mpLotusRoot(pLotRoot
)
52 pDocPool
= mpLotusRoot
->pDoc
->GetPool();
54 pColTab
.reset( new Color
[ 8 ] );
55 pColTab
[ 0 ] = COL_WHITE
;
56 pColTab
[ 1 ] = COL_LIGHTBLUE
;
57 pColTab
[ 2 ] = COL_LIGHTGREEN
;
58 pColTab
[ 3 ] = COL_LIGHTCYAN
;
59 pColTab
[ 4 ] = COL_LIGHTRED
;
60 pColTab
[ 5 ] = COL_LIGHTMAGENTA
;
61 pColTab
[ 6 ] = COL_YELLOW
;
62 pColTab
[ 7 ] = COL_BLACK
;
64 ppColorItems
[ 0 ].reset( new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR
) ); // 1
65 ppColorItems
[ 1 ].reset( new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR
) );
66 ppColorItems
[ 2 ].reset( new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR
) );
67 ppColorItems
[ 3 ].reset( new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR
) );
68 ppColorItems
[ 4 ].reset( new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR
) );
69 ppColorItems
[ 5 ].reset( new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR
) ); // 6
71 pWhite
.reset( new SvxColorItem( COL_WHITE
, ATTR_FONT_COLOR
) );
74 LotAttrCache::~LotAttrCache()
78 const ScPatternAttr
& LotAttrCache::GetPattAttr( const LotAttrWK3
& rAttr
)
81 MakeHash( rAttr
, nRefHash
);
83 std::vector
< std::unique_ptr
<ENTRY
> >::const_iterator iter
84 = std::find_if(aEntries
.begin(),aEntries
.end(),
85 [nRefHash
] (const std::unique_ptr
<ENTRY
>& rEntry
) { return rEntry
->nHash0
== nRefHash
; } );
87 if (iter
!= aEntries
.end())
88 return *((*iter
)->pPattAttr
);
90 // generate new Pattern Attribute
91 ScPatternAttr
* pNewPatt
= new ScPatternAttr(pDocPool
);
93 SfxItemSet
& rItemSet
= pNewPatt
->GetItemSet();
94 ENTRY
*pCurrent
= new ENTRY( std::unique_ptr
<ScPatternAttr
>(pNewPatt
) );
96 pCurrent
->nHash0
= nRefHash
;
98 mpLotusRoot
->maFontBuff
.Fill( rAttr
.nFont
, rItemSet
);
100 sal_uInt8 nLine
= rAttr
.nLineStyle
;
103 SvxBoxItem
aBox( ATTR_BORDER
);
104 ::editeng::SvxBorderLine aTop
, aLeft
, aBottom
, aRight
;
106 LotusToScBorderLine( nLine
, aLeft
);
108 LotusToScBorderLine( nLine
, aRight
);
110 LotusToScBorderLine( nLine
, aTop
);
112 LotusToScBorderLine( nLine
, aBottom
);
114 aBox
.SetLine( &aTop
, SvxBoxItemLine::TOP
);
115 aBox
.SetLine( &aLeft
, SvxBoxItemLine::LEFT
);
116 aBox
.SetLine( &aBottom
, SvxBoxItemLine::BOTTOM
);
117 aBox
.SetLine( &aRight
, SvxBoxItemLine::RIGHT
);
119 rItemSet
.Put( aBox
);
122 sal_uInt8 nFontCol
= rAttr
.nFontCol
& 0x07;
127 rItemSet
.Put( GetColorItem( nFontCol
) );
129 rItemSet
.Put( *pWhite
);
132 sal_uInt8 nBack
= rAttr
.nBack
& 0x1F;
134 rItemSet
.Put( SvxBrushItem( GetColor( nBack
& 0x07 ), ATTR_BACKGROUND
) );
136 if( rAttr
.nBack
& 0x80 )
138 SvxHorJustifyItem
aHorJustify(SvxCellHorJustify::Center
, ATTR_HOR_JUSTIFY
);
139 rItemSet
.Put( aHorJustify
);
142 aEntries
.push_back(std::unique_ptr
<ENTRY
>(pCurrent
));
147 void LotAttrCache::LotusToScBorderLine( sal_uInt8 nLine
, ::editeng::SvxBorderLine
& aBL
)
153 case 0: aBL
.SetBorderLineStyle(SvxBorderLineStyle::NONE
); break;
154 case 1: aBL
.SetWidth( DEF_LINE_WIDTH_1
); break;
155 case 2: aBL
.SetWidth( DEF_LINE_WIDTH_2
); break;
158 aBL
.SetBorderLineStyle(SvxBorderLineStyle::DOUBLE_THIN
);
159 aBL
.SetWidth( DEF_LINE_WIDTH_1
);
165 const SvxColorItem
& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex
) const
167 // *LotAttrCache::GetColorItem(): caller has to check index!
168 assert( nLotIndex
> 0 && nLotIndex
< 7 );
170 return *ppColorItems
[ nLotIndex
- 1 ];
173 const Color
& LotAttrCache::GetColor( const sal_uInt8 nLotIndex
) const
175 // color <-> index fits background, but not for fonts (0 <-> 7)!
176 // *LotAttrCache::GetColor(): Index > 7, caller hast to check index!"
177 assert( nLotIndex
< 8 );
179 return pColTab
[ nLotIndex
];
182 void LotAttrCol::SetAttr( const SCROW nRow
, const ScPatternAttr
& rAttr
)
184 // Actually with the current implementation of MAXROWCOUNT>=64k and nRow
185 // being read as sal_uInt16 there's no chance that nRow would be invalid...
186 SAL_WARN_IF( !ValidRow(nRow
), "sc.filter", "*LotAttrCol::SetAttr(): ... and failed?!" );
188 std::vector
<std::unique_ptr
<ENTRY
> >::reverse_iterator iterLast
= aEntries
.rbegin();
190 if(iterLast
!= aEntries
.rend())
192 if( ( (*iterLast
)->nLastRow
== nRow
- 1 ) && ( &rAttr
== (*iterLast
)->pPattAttr
) )
193 (*iterLast
)->nLastRow
= nRow
;
196 ENTRY
*pCurrent
= new ENTRY
;
198 pCurrent
->pPattAttr
= &rAttr
;
199 pCurrent
->nFirstRow
= pCurrent
->nLastRow
= nRow
;
201 aEntries
.push_back(std::unique_ptr
<ENTRY
>(pCurrent
));
206 ENTRY
*pCurrent
= new ENTRY
;
207 pCurrent
->pPattAttr
= &rAttr
;
208 pCurrent
->nFirstRow
= pCurrent
->nLastRow
= nRow
;
210 aEntries
.push_back(std::unique_ptr
<ENTRY
>(pCurrent
));
214 void LotAttrCol::Apply(LOTUS_ROOT
* pLotusRoot
, const SCCOL nColNum
, const SCTAB nTabNum
)
216 ScDocument
* pDoc
= pLotusRoot
->pDoc
;
218 for (const auto& rxEntry
: aEntries
)
220 pDoc
->ApplyPatternAreaTab(nColNum
, rxEntry
->nFirstRow
, nColNum
, rxEntry
->nLastRow
,
221 nTabNum
, *(rxEntry
->pPattAttr
));
225 LotAttrTable::LotAttrTable(LOTUS_ROOT
* pLotRoot
):
230 void LotAttrTable::SetAttr( const SCCOL nColFirst
, const SCCOL nColLast
, const SCROW nRow
,
231 const LotAttrWK3
& rAttr
)
233 // With the current implementation of MAXCOLCOUNT>=1024 and nColFirst and
234 // nColLast being calculated as sal_uInt8+sal_uInt8 there's no chance that
235 // they would be invalid.
236 const ScPatternAttr
&rPattAttr
= aAttrCache
.GetPattAttr( rAttr
);
239 for( nColCnt
= nColFirst
; nColCnt
<= nColLast
; nColCnt
++ )
240 pCols
[ nColCnt
].SetAttr( nRow
, rPattAttr
);
243 void LotAttrTable::Apply(LOTUS_ROOT
* pLotusRoot
, const SCTAB nTabNum
)
246 for( nColCnt
= 0 ; nColCnt
<= aAttrCache
.mpLotusRoot
->pDoc
->MaxCol() ; nColCnt
++ )
247 pCols
[ nColCnt
].Apply(pLotusRoot
, nColCnt
, nTabNum
); // does a Clear() at end
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */