xref: /AOO41X/main/sc/inc/attarray.hxx (revision 8f4c7c28c0e8f794fb1048a19304c40597e0d6b9)
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 
ScLineFlagsScLineFlags58     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 
ScMergePatternStateScMergePatternState68     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 
SetTab(SCTAB nNewTab)105     void    SetTab(SCTAB nNewTab)   { nTab = nNewTab; }
SetCol(SCCOL nNewCol)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     /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */
193     bool    Reserve( SCSIZE nCount );
Count() const194     SCSIZE  Count() const{ return nCount; }
195     SCSIZE  Count( SCROW nRw1, SCROW nRw2 );
196 };
197 
198 
199 //  ------------------------------------------------------------------------------
200 //                              Iterator fuer Attribute
201 //  ------------------------------------------------------------------------------
202 
203 class ScAttrIterator
204 {
205     const ScAttrArray*  pArray;
206     SCSIZE              nPos;
207     SCROW               nRow;
208     SCROW               nEndRow;
209 public:
210     inline              ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd );
211     inline const ScPatternAttr* Next( SCROW& rTop, SCROW& rBottom );
GetNextRow() const212     SCROW               GetNextRow() const { return nRow; }
213 };
214 
215 
ScAttrIterator(const ScAttrArray * pNewArray,SCROW nStart,SCROW nEnd)216 inline ScAttrIterator::ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd ) :
217     pArray( pNewArray ),
218     nRow( nStart ),
219     nEndRow( nEnd )
220 {
221     if ( nStart > 0 )
222         pArray->Search( nStart, nPos );
223     else
224         nPos = 0;
225 }
226 
Next(SCROW & rTop,SCROW & rBottom)227 inline const ScPatternAttr* ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom )
228 {
229     const ScPatternAttr* pRet;
230     if ( nPos < pArray->nCount && nRow <= nEndRow )
231     {
232         rTop = nRow;
233         rBottom = Min( pArray->pData[nPos].nRow, nEndRow );
234         pRet = pArray->pData[nPos].pPattern;
235         nRow = rBottom + 1;
236         ++nPos;
237     }
238     else
239         pRet = NULL;
240     return pRet;
241 }
242 
243 
244 
245 #endif
246 
247 
248