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