1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
33 //------------------------------------------------------------------------
35 #include "scitems.hxx"
36 #include <svx/algitem.hxx>
37 #include <editeng/boxitem.hxx>
38 #include <editeng/brshitem.hxx>
40 #include "document.hxx"
41 #include "patattr.hxx"
42 #include "docpool.hxx"
45 #include "lotattr.hxx"
46 #include "lotfntbf.hxx"
51 void LotAttrCache::LotusToScBorderLine( UINT8 nLine
, SvxBorderLine
& aBL
)
53 static const UINT16 pPara
[ 4 ][ 3 ] =
56 { DEF_LINE_WIDTH_1
, 0, 0 },
57 { DEF_LINE_WIDTH_2
, 0, 0 },
58 { DEF_LINE_WIDTH_1
, DEF_LINE_WIDTH_1
, DEF_LINE_WIDTH_1
}
65 aBL
.SetOutWidth( pPara
[ nLine
][ 0 ] );
66 aBL
.SetInWidth( pPara
[ nLine
][ 1 ] );
67 aBL
.SetDistance( pPara
[ nLine
][ 2 ] );
72 const SvxColorItem
& LotAttrCache::GetColorItem( const UINT8 nLotIndex
) const
74 DBG_ASSERT( nLotIndex
> 0 && nLotIndex
< 7,
75 "-LotAttrCache::GetColorItem(): so nicht!" );
77 return *ppColorItems
[ nLotIndex
- 1 ];
81 const Color
& LotAttrCache::GetColor( const UINT8 nLotIndex
) const
83 // Farbe <-> Index passt fuer Background, nicht aber fuer Fonts (0 <-> 7)!
84 DBG_ASSERT( nLotIndex
< 8, "*LotAttrCache::GetColor(): Index > 7!" );
85 return pColTab
[ nLotIndex
];
89 LotAttrCache::LotAttrCache( void )
91 pDocPool
= pLotusRoot
->pDoc
->GetPool();
93 pColTab
= new Color
[ 8 ];
94 pColTab
[ 0 ] = Color( COL_WHITE
);
95 pColTab
[ 1 ] = Color( COL_LIGHTBLUE
);
96 pColTab
[ 2 ] = Color( COL_LIGHTGREEN
);
97 pColTab
[ 3 ] = Color( COL_LIGHTCYAN
);
98 pColTab
[ 4 ] = Color( COL_LIGHTRED
);
99 pColTab
[ 5 ] = Color( COL_LIGHTMAGENTA
);
100 pColTab
[ 6 ] = Color( COL_YELLOW
);
101 pColTab
[ 7 ] = Color( COL_BLACK
);
103 ppColorItems
[ 0 ] = new SvxColorItem( GetColor( 1 ), ATTR_FONT_COLOR
); // 1
104 ppColorItems
[ 1 ] = new SvxColorItem( GetColor( 2 ), ATTR_FONT_COLOR
);
105 ppColorItems
[ 2 ] = new SvxColorItem( GetColor( 3 ), ATTR_FONT_COLOR
);
106 ppColorItems
[ 3 ] = new SvxColorItem( GetColor( 4 ), ATTR_FONT_COLOR
);
107 ppColorItems
[ 4 ] = new SvxColorItem( GetColor( 5 ), ATTR_FONT_COLOR
);
108 ppColorItems
[ 5 ] = new SvxColorItem( GetColor( 6 ), ATTR_FONT_COLOR
); // 6
110 pBlack
= new SvxColorItem( Color( COL_BLACK
), ATTR_FONT_COLOR
);
111 pWhite
= new SvxColorItem( Color( COL_WHITE
), ATTR_FONT_COLOR
);
115 LotAttrCache::~LotAttrCache()
117 ENTRY
* pAkt
= ( ENTRY
* ) List::First();
122 pAkt
= ( ENTRY
* ) List::Next();
125 for( UINT16 nCnt
= 0 ; nCnt
< 6 ; nCnt
++ )
126 delete ppColorItems
[ nCnt
];
135 const ScPatternAttr
& LotAttrCache::GetPattAttr( const LotAttrWK3
& rAttr
)
138 ENTRY
* pAkt
= ( ENTRY
* ) List::First();
140 MakeHash( rAttr
, nRefHash
);
144 if( *pAkt
== nRefHash
)
145 return *pAkt
->pPattAttr
;
147 pAkt
= ( ENTRY
* ) List::Next();
150 // neues PatternAttribute erzeugen
151 ScPatternAttr
* pNewPatt
= new ScPatternAttr( pDocPool
);
152 SfxItemSet
& rItemSet
= pNewPatt
->GetItemSet();
153 pAkt
= new ENTRY( pNewPatt
);
155 pAkt
->nHash0
= nRefHash
;
157 pLotusRoot
->pFontBuff
->Fill( rAttr
.nFont
, rItemSet
);
159 UINT8 nLine
= rAttr
.nLineStyle
;
162 SvxBoxItem
aBox( ATTR_BORDER
);
163 SvxBorderLine aTop
, aLeft
, aBottom
, aRight
;
165 LotusToScBorderLine( nLine
, aLeft
);
167 LotusToScBorderLine( nLine
, aRight
);
169 LotusToScBorderLine( nLine
, aTop
);
171 LotusToScBorderLine( nLine
, aBottom
);
173 aBox
.SetLine( &aTop
, BOX_LINE_TOP
);
174 aBox
.SetLine( &aLeft
, BOX_LINE_LEFT
);
175 aBox
.SetLine( &aBottom
, BOX_LINE_BOTTOM
);
176 aBox
.SetLine( &aRight
, BOX_LINE_RIGHT
);
178 rItemSet
.Put( aBox
);
181 UINT8 nFontCol
= rAttr
.nFontCol
& 0x07;
186 rItemSet
.Put( GetColorItem( nFontCol
) );
188 rItemSet
.Put( *pWhite
);
191 UINT8 nBack
= rAttr
.nBack
& 0x1F;
193 rItemSet
.Put( SvxBrushItem( GetColor( nBack
& 0x07 ), ATTR_BACKGROUND
) );
195 if( rAttr
.nBack
& 0x80 )
197 SvxHorJustifyItem
aHorJustify(SVX_HOR_JUSTIFY_CENTER
, ATTR_HOR_JUSTIFY
);
198 rItemSet
.Put( aHorJustify
);
201 List::Insert( pAkt
, LIST_APPEND
);
207 LotAttrCol::~LotAttrCol()
213 void LotAttrCol::SetAttr( const SCROW nRow
, const ScPatternAttr
& rAttr
)
215 DBG_ASSERT( ValidRow(nRow
), "*LotAttrCol::SetAttr(): ... und rums?!" );
217 ENTRY
* pAkt
= ( ENTRY
* ) List::Last();
221 if( ( pAkt
->nLastRow
== nRow
- 1 ) && ( &rAttr
== pAkt
->pPattAttr
) )
222 pAkt
->nLastRow
= nRow
;
227 pAkt
->pPattAttr
= &rAttr
;
228 pAkt
->nFirstRow
= pAkt
->nLastRow
= nRow
;
229 List::Insert( pAkt
, LIST_APPEND
);
235 pAkt
->pPattAttr
= &rAttr
;
236 pAkt
->nFirstRow
= pAkt
->nLastRow
= nRow
;
237 List::Insert( pAkt
, LIST_APPEND
);
242 void LotAttrCol::Apply( const SCCOL nColNum
, const SCTAB nTabNum
, const BOOL
/*bClear*/ )
244 ScDocument
* pDoc
= pLotusRoot
->pDoc
;
245 ENTRY
* pAkt
= ( ENTRY
* ) List::First();
249 pDoc
->ApplyPatternAreaTab( nColNum
, pAkt
->nFirstRow
, nColNum
, pAkt
->nLastRow
,
250 nTabNum
, *pAkt
->pPattAttr
);
252 pAkt
= ( ENTRY
* ) List::Next();
257 void LotAttrCol::Clear( void )
259 ENTRY
* pAkt
= ( ENTRY
* ) List::First();
264 pAkt
= ( ENTRY
* ) List::Next();
269 LotAttrTable::LotAttrTable( void )
274 LotAttrTable::~LotAttrTable()
279 void LotAttrTable::SetAttr( const SCCOL nColFirst
, const SCCOL nColLast
, const SCROW nRow
,
280 const LotAttrWK3
& rAttr
)
282 const ScPatternAttr
& rPattAttr
= aAttrCache
.GetPattAttr( rAttr
);
285 for( nColCnt
= nColFirst
; nColCnt
<= nColLast
; nColCnt
++ )
286 pCols
[ nColCnt
].SetAttr( nRow
, rPattAttr
);
290 void LotAttrTable::Apply( const SCTAB nTabNum
)
293 for( nColCnt
= 0 ; nColCnt
<= MAXCOL
; nColCnt
++ )
294 pCols
[ nColCnt
].Apply( nColCnt
, nTabNum
); // macht auch gleich ein Clear() am Ende