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