xref: /aoo41x/main/sc/inc/attarray.hxx (revision 38d50f7b)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38d50f7bSAndrew Rist  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19*38d50f7bSAndrew Rist  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_ATRARR_HXX
25cdf0e10cSrcweir #define SC_ATRARR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "global.hxx"
28cdf0e10cSrcweir #include "attrib.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir class ScDocument;
31cdf0e10cSrcweir class ScMarkArray;
32cdf0e10cSrcweir class ScPatternAttr;
33cdf0e10cSrcweir class ScStyleSheet;
34cdf0e10cSrcweir class ScFlatBoolRowSegments;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir class Rectangle;
37cdf0e10cSrcweir class SfxItemPoolCache;
38cdf0e10cSrcweir class SfxStyleSheetBase;
39cdf0e10cSrcweir class SvxBorderLine;
40cdf0e10cSrcweir class SvxBoxItem;
41cdf0e10cSrcweir class SvxBoxInfoItem;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #define SC_LINE_EMPTY			0
44cdf0e10cSrcweir #define SC_LINE_SET				1
45cdf0e10cSrcweir #define SC_LINE_DONTCARE		2
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define SC_ATTRARRAY_DELTA      4
48cdf0e10cSrcweir 
49cdf0e10cSrcweir struct ScLineFlags
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	sal_uInt8	nLeft;
52cdf0e10cSrcweir 	sal_uInt8	nRight;
53cdf0e10cSrcweir 	sal_uInt8	nTop;
54cdf0e10cSrcweir 	sal_uInt8	nBottom;
55cdf0e10cSrcweir 	sal_uInt8	nHori;
56cdf0e10cSrcweir 	sal_uInt8	nVert;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	ScLineFlags() : nLeft(SC_LINE_EMPTY),nRight(SC_LINE_EMPTY),nTop(SC_LINE_EMPTY),
59cdf0e10cSrcweir 					nBottom(SC_LINE_EMPTY),nHori(SC_LINE_EMPTY),nVert(SC_LINE_EMPTY) {}
60cdf0e10cSrcweir };
61cdf0e10cSrcweir 
62cdf0e10cSrcweir struct ScMergePatternState
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     SfxItemSet* pItemSet;           // allocated in MergePatternArea, used for resulting ScPatternAttr
65cdf0e10cSrcweir     const ScPatternAttr* pOld1;     // existing objects, temporary
66cdf0e10cSrcweir     const ScPatternAttr* pOld2;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     ScMergePatternState() : pItemSet(NULL), pOld1(NULL), pOld2(NULL) {}
69cdf0e10cSrcweir };
70cdf0e10cSrcweir 
71cdf0e10cSrcweir struct ScAttrEntry
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	SCROW					nRow;
74cdf0e10cSrcweir 	const ScPatternAttr*	pPattern;
75cdf0e10cSrcweir };
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir class ScAttrArray
79cdf0e10cSrcweir {
80cdf0e10cSrcweir private:
81cdf0e10cSrcweir 	SCCOL			nCol;
82cdf0e10cSrcweir 	SCTAB			nTab;
83cdf0e10cSrcweir 	ScDocument*		pDocument;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	SCSIZE			nCount;
86cdf0e10cSrcweir     SCSIZE          nLimit;
87cdf0e10cSrcweir 	ScAttrEntry*	pData;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir friend class ScDocument;				// fuer FillInfo
90cdf0e10cSrcweir friend class ScDocumentIterator;
91cdf0e10cSrcweir friend class ScAttrIterator;
92cdf0e10cSrcweir friend class ScHorizontalAttrIterator;
93cdf0e10cSrcweir friend void lcl_IterGetNumberFormat( sal_uLong& nFormat,
94cdf0e10cSrcweir 		const ScAttrArray*& rpArr, SCROW& nAttrEndRow,
95cdf0e10cSrcweir 		const ScAttrArray* pNewArr, SCROW nRow, ScDocument* pDoc );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	sal_Bool	ApplyFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
98cdf0e10cSrcweir 							SCROW nStartRow, SCROW nEndRow,
99cdf0e10cSrcweir 							sal_Bool bLeft, SCCOL nDistRight, sal_Bool bTop, SCROW nDistBottom );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir public:
102cdf0e10cSrcweir 			ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc );
103cdf0e10cSrcweir 			~ScAttrArray();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	void	SetTab(SCTAB nNewTab)	{ nTab = nNewTab; }
106cdf0e10cSrcweir 	void	SetCol(SCCOL nNewCol)	{ nCol = nNewCol; }
107cdf0e10cSrcweir #ifdef DBG_UTIL
108cdf0e10cSrcweir 	void	TestData() const;
109cdf0e10cSrcweir #endif
110cdf0e10cSrcweir 	void	Reset( const ScPatternAttr* pPattern, sal_Bool bAlloc = sal_True );
111cdf0e10cSrcweir 	sal_Bool	Concat(SCSIZE nPos);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	const ScPatternAttr* GetPattern( SCROW nRow ) const;
114cdf0e10cSrcweir 	const ScPatternAttr* GetPatternRange( SCROW& rStartRow, SCROW& rEndRow, SCROW nRow ) const;
115cdf0e10cSrcweir 	void	MergePatternArea( SCROW nStartRow, SCROW nEndRow, ScMergePatternState& rState, sal_Bool bDeep ) const;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	void	MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
118cdf0e10cSrcweir 							SCROW nStartRow, SCROW nEndRow, sal_Bool bLeft, SCCOL nDistRight ) const;
119cdf0e10cSrcweir 	void	ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
120cdf0e10cSrcweir 							SCROW nStartRow, SCROW nEndRow, sal_Bool bLeft, SCCOL nDistRight );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	void	SetPattern( SCROW nRow, const ScPatternAttr* pPattern, sal_Bool bPutToPool = sal_False );
123cdf0e10cSrcweir 	void	SetPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr* pPattern, sal_Bool bPutToPool = sal_False);
124cdf0e10cSrcweir 	void	ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, ScStyleSheet* pStyle );
125cdf0e10cSrcweir 	void	ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache* pCache );
126cdf0e10cSrcweir 	void	ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow,
127cdf0e10cSrcweir 								const SvxBorderLine* pLine, sal_Bool bColorOnly );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	void	ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich );
130cdf0e10cSrcweir 	void	ChangeIndent( SCROW nStartRow, SCROW nEndRow, sal_Bool bIncrement );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             /// Including current, may return -1
133cdf0e10cSrcweir 	SCsROW	GetNextUnprotected( SCsROW nRow, sal_Bool bUp ) const;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             /// May return -1 if not found
136cdf0e10cSrcweir 	SCsROW	SearchStyle( SCsROW nRow, const ScStyleSheet* pSearchStyle,
137cdf0e10cSrcweir 							sal_Bool bUp, ScMarkArray* pMarkArray = NULL );
138cdf0e10cSrcweir 	sal_Bool	SearchStyleRange( SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle,
139cdf0e10cSrcweir 							sal_Bool bUp, ScMarkArray* pMarkArray = NULL );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 	sal_Bool	ApplyFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags );
142cdf0e10cSrcweir 	sal_Bool	RemoveFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	sal_Bool 	Search( SCROW nRow, SCSIZE& nIndex ) const;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	sal_Bool	HasLines( SCROW nRow1, SCROW nRow2, Rectangle& rSizes,
147cdf0e10cSrcweir 						sal_Bool bLeft, sal_Bool bRight ) const;
148cdf0e10cSrcweir     bool    HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const;
149cdf0e10cSrcweir 	sal_Bool	ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
150cdf0e10cSrcweir 								SCCOL& rPaintCol, SCROW& rPaintRow,
151cdf0e10cSrcweir 								sal_Bool bRefresh, sal_Bool bAttrs );
152cdf0e10cSrcweir 	sal_Bool	RemoveAreaMerge( SCROW nStartRow, SCROW nEndRow );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	void	FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
155cdf0e10cSrcweir 	sal_Bool	IsStyleSheetUsed( const ScStyleSheet& rStyle, sal_Bool bGatherAllStyles ) const;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	void	DeleteAreaSafe(SCROW nStartRow, SCROW nEndRow);
158cdf0e10cSrcweir 	void	SetPatternAreaSafe( SCROW nStartRow, SCROW nEndRow,
159cdf0e10cSrcweir 									const ScPatternAttr* pWantedPattern, sal_Bool bDefault );
160cdf0e10cSrcweir 	void	CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	sal_Bool	IsEmpty() const;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir //UNUSED2008-05  SCROW	GetFirstEntryPos() const;
165cdf0e10cSrcweir //UNUSED2008-05  SCROW	GetLastEntryPos( sal_Bool bIncludeBottom ) const;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     sal_Bool    GetFirstVisibleAttr( SCROW& rFirstRow ) const;
168cdf0e10cSrcweir     sal_Bool    GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const;
169cdf0e10cSrcweir 	sal_Bool	HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
170cdf0e10cSrcweir 	sal_Bool	IsVisibleEqual( const ScAttrArray& rOther,
171cdf0e10cSrcweir 							SCROW nStartRow, SCROW nEndRow ) const;
172cdf0e10cSrcweir 	sal_Bool	IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	sal_Bool	TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
175cdf0e10cSrcweir 	sal_Bool	TestInsertRow( SCSIZE nSize ) const;
176cdf0e10cSrcweir 	void	InsertRow( SCROW nStartRow, SCSIZE nSize );
177cdf0e10cSrcweir 	void	DeleteRow( SCROW nStartRow, SCSIZE nSize );
178cdf0e10cSrcweir 	void	DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex );
179cdf0e10cSrcweir 	void	DeleteArea( SCROW nStartRow, SCROW nEndRow );
180cdf0e10cSrcweir 	void	MoveTo( SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray );
181cdf0e10cSrcweir 	void	CopyArea( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray,
182cdf0e10cSrcweir 						sal_Int16 nStripFlags = 0 );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	void	DeleteHardAttr( SCROW nStartRow, SCROW nEndRow );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir //UNUSED2008-05  void    ConvertFontsAfterLoad();     // old binary file format
187cdf0e10cSrcweir };
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //	------------------------------------------------------------------------------
191cdf0e10cSrcweir //								Iterator fuer Attribute
192cdf0e10cSrcweir //	------------------------------------------------------------------------------
193cdf0e10cSrcweir 
194cdf0e10cSrcweir class ScAttrIterator
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	const ScAttrArray*	pArray;
197cdf0e10cSrcweir 	SCSIZE				nPos;
198cdf0e10cSrcweir 	SCROW				nRow;
199cdf0e10cSrcweir 	SCROW				nEndRow;
200cdf0e10cSrcweir public:
201cdf0e10cSrcweir 	inline				ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd );
202cdf0e10cSrcweir 	inline const ScPatternAttr*	Next( SCROW& rTop, SCROW& rBottom );
203cdf0e10cSrcweir 	SCROW				GetNextRow() const { return nRow; }
204cdf0e10cSrcweir };
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir inline ScAttrIterator::ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd ) :
208cdf0e10cSrcweir 	pArray( pNewArray ),
209cdf0e10cSrcweir 	nRow( nStart ),
210cdf0e10cSrcweir 	nEndRow( nEnd )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	if ( nStart > 0 )
213cdf0e10cSrcweir 		pArray->Search( nStart, nPos );
214cdf0e10cSrcweir 	else
215cdf0e10cSrcweir 		nPos = 0;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir inline const ScPatternAttr*	ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	const ScPatternAttr* pRet;
221cdf0e10cSrcweir 	if ( nPos < pArray->nCount && nRow <= nEndRow )
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		rTop = nRow;
224cdf0e10cSrcweir 		rBottom = Min( pArray->pData[nPos].nRow, nEndRow );
225cdf0e10cSrcweir 		pRet = pArray->pData[nPos].pPattern;
226cdf0e10cSrcweir 		nRow = rBottom + 1;
227cdf0e10cSrcweir 		++nPos;
228cdf0e10cSrcweir 	}
229cdf0e10cSrcweir 	else
230cdf0e10cSrcweir 		pRet = NULL;
231cdf0e10cSrcweir 	return pRet;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
236cdf0e10cSrcweir #endif
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 
239