xref: /aoo41x/main/sc/inc/attarray.hxx (revision 8f4c7c28)
138d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
338d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
438d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
538d50f7bSAndrew Rist  * distributed with this work for additional information
638d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
738d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
838d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
938d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
1038d50f7bSAndrew Rist  *
1138d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1238d50f7bSAndrew Rist  *
1338d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1438d50f7bSAndrew Rist  * software distributed under the License is distributed on an
1538d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1638d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
1738d50f7bSAndrew Rist  * specific language governing permissions and limitations
1838d50f7bSAndrew Rist  * under the License.
1938d50f7bSAndrew Rist  *
2038d50f7bSAndrew Rist  *************************************************************/
2138d50f7bSAndrew Rist 
2238d50f7bSAndrew 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 
ScLineFlagsScLineFlags58cdf0e10cSrcweir 	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 
ScMergePatternStateScMergePatternState68cdf0e10cSrcweir     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 
SetTab(SCTAB nNewTab)105cdf0e10cSrcweir 	void	SetTab(SCTAB nNewTab)	{ nTab = nNewTab; }
SetCol(SCCOL nNewCol)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;
169557cb412SWang Lei 	/*
170557cb412SWang Lei 	Get the last cell's row number , which have visual atribute or visual data in attribute list
171557cb412SWang Lei 	*/
172557cb412SWang Lei 	sal_Bool    GetLastAttr( SCROW& rLastRow, SCROW nLastData ) const;
173cdf0e10cSrcweir 	sal_Bool	HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
174cdf0e10cSrcweir 	sal_Bool	IsVisibleEqual( const ScAttrArray& rOther,
175cdf0e10cSrcweir 							SCROW nStartRow, SCROW nEndRow ) const;
176cdf0e10cSrcweir 	sal_Bool	IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	sal_Bool	TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
179cdf0e10cSrcweir 	sal_Bool	TestInsertRow( SCSIZE nSize ) const;
180cdf0e10cSrcweir 	void	InsertRow( SCROW nStartRow, SCSIZE nSize );
181cdf0e10cSrcweir 	void	DeleteRow( SCROW nStartRow, SCSIZE nSize );
182cdf0e10cSrcweir 	void	DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex );
183cdf0e10cSrcweir 	void	DeleteArea( SCROW nStartRow, SCROW nEndRow );
184cdf0e10cSrcweir 	void	MoveTo( SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray );
185cdf0e10cSrcweir 	void	CopyArea( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray,
186cdf0e10cSrcweir 						sal_Int16 nStripFlags = 0 );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	void	DeleteHardAttr( SCROW nStartRow, SCROW nEndRow );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //UNUSED2008-05  void    ConvertFontsAfterLoad();     // old binary file format
191*8f4c7c28SSteve Yin 
192*8f4c7c28SSteve Yin     /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */
193*8f4c7c28SSteve Yin     bool    Reserve( SCSIZE nCount );
Count() const194*8f4c7c28SSteve Yin     SCSIZE  Count() const{ return nCount; }
195*8f4c7c28SSteve Yin     SCSIZE  Count( SCROW nRw1, SCROW nRw2 );
196cdf0e10cSrcweir };
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //	------------------------------------------------------------------------------
200cdf0e10cSrcweir //								Iterator fuer Attribute
201cdf0e10cSrcweir //	------------------------------------------------------------------------------
202cdf0e10cSrcweir 
203cdf0e10cSrcweir class ScAttrIterator
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	const ScAttrArray*	pArray;
206cdf0e10cSrcweir 	SCSIZE				nPos;
207cdf0e10cSrcweir 	SCROW				nRow;
208cdf0e10cSrcweir 	SCROW				nEndRow;
209cdf0e10cSrcweir public:
210cdf0e10cSrcweir 	inline				ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd );
211cdf0e10cSrcweir 	inline const ScPatternAttr*	Next( SCROW& rTop, SCROW& rBottom );
GetNextRow() const212cdf0e10cSrcweir 	SCROW				GetNextRow() const { return nRow; }
213cdf0e10cSrcweir };
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
ScAttrIterator(const ScAttrArray * pNewArray,SCROW nStart,SCROW nEnd)216cdf0e10cSrcweir inline ScAttrIterator::ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd ) :
217cdf0e10cSrcweir 	pArray( pNewArray ),
218cdf0e10cSrcweir 	nRow( nStart ),
219cdf0e10cSrcweir 	nEndRow( nEnd )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir 	if ( nStart > 0 )
222cdf0e10cSrcweir 		pArray->Search( nStart, nPos );
223cdf0e10cSrcweir 	else
224cdf0e10cSrcweir 		nPos = 0;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
Next(SCROW & rTop,SCROW & rBottom)227cdf0e10cSrcweir inline const ScPatternAttr*	ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	const ScPatternAttr* pRet;
230cdf0e10cSrcweir 	if ( nPos < pArray->nCount && nRow <= nEndRow )
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir 		rTop = nRow;
233cdf0e10cSrcweir 		rBottom = Min( pArray->pData[nPos].nRow, nEndRow );
234cdf0e10cSrcweir 		pRet = pArray->pData[nPos].pPattern;
235cdf0e10cSrcweir 		nRow = rBottom + 1;
236cdf0e10cSrcweir 		++nPos;
237cdf0e10cSrcweir 	}
238cdf0e10cSrcweir 	else
239cdf0e10cSrcweir 		pRet = NULL;
240cdf0e10cSrcweir 	return pRet;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir #endif
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 
248