1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lotattr.cxx,v $
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"
48 #include "lotattr.hxx"
49 #include "lotfntbf.hxx"
54 void LotAttrCache::LotusToScBorderLine( UINT8 nLine
, SvxBorderLine
& aBL
)
56 static const UINT16 pPara
[ 4 ][ 3 ] =
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
}
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();
125 pAkt
= ( ENTRY
* ) List::Next();
128 for( UINT16 nCnt
= 0 ; nCnt
< 6 ; nCnt
++ )
129 delete ppColorItems
[ nCnt
];
138 const ScPatternAttr
& LotAttrCache::GetPattAttr( const LotAttrWK3
& rAttr
)
141 ENTRY
* pAkt
= ( ENTRY
* ) List::First();
143 MakeHash( rAttr
, nRefHash
);
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
;
165 SvxBoxItem
aBox( ATTR_BORDER
);
166 SvxBorderLine aTop
, aLeft
, aBottom
, aRight
;
168 LotusToScBorderLine( nLine
, aLeft
);
170 LotusToScBorderLine( nLine
, aRight
);
172 LotusToScBorderLine( nLine
, aTop
);
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;
189 rItemSet
.Put( GetColorItem( nFontCol
) );
191 rItemSet
.Put( *pWhite
);
194 UINT8 nBack
= rAttr
.nBack
& 0x1F;
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
);
210 LotAttrCol::~LotAttrCol()
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();
224 if( ( pAkt
->nLastRow
== nRow
- 1 ) && ( &rAttr
== pAkt
->pPattAttr
) )
225 pAkt
->nLastRow
= nRow
;
230 pAkt
->pPattAttr
= &rAttr
;
231 pAkt
->nFirstRow
= pAkt
->nLastRow
= nRow
;
232 List::Insert( pAkt
, LIST_APPEND
);
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();
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();
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
);
288 for( nColCnt
= nColFirst
; nColCnt
<= nColLast
; nColCnt
++ )
289 pCols
[ nColCnt
].SetAttr( nRow
, rPattAttr
);
293 void LotAttrTable::Apply( const SCTAB nTabNum
)
296 for( nColCnt
= 0 ; nColCnt
<= MAXCOL
; nColCnt
++ )
297 pCols
[ nColCnt
].Apply( nColCnt
, nTabNum
); // macht auch gleich ein Clear() am Ende