1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_ATRARR_HXX 29 #define SC_ATRARR_HXX 30 31 #include "global.hxx" 32 #include "attrib.hxx" 33 34 class ScDocument; 35 class ScMarkArray; 36 class ScPatternAttr; 37 class ScStyleSheet; 38 class ScFlatBoolRowSegments; 39 40 class Rectangle; 41 class SfxItemPoolCache; 42 class SfxStyleSheetBase; 43 class SvxBorderLine; 44 class SvxBoxItem; 45 class SvxBoxInfoItem; 46 47 #define SC_LINE_EMPTY 0 48 #define SC_LINE_SET 1 49 #define SC_LINE_DONTCARE 2 50 51 #define SC_ATTRARRAY_DELTA 4 52 53 struct ScLineFlags 54 { 55 sal_uInt8 nLeft; 56 sal_uInt8 nRight; 57 sal_uInt8 nTop; 58 sal_uInt8 nBottom; 59 sal_uInt8 nHori; 60 sal_uInt8 nVert; 61 62 ScLineFlags() : nLeft(SC_LINE_EMPTY),nRight(SC_LINE_EMPTY),nTop(SC_LINE_EMPTY), 63 nBottom(SC_LINE_EMPTY),nHori(SC_LINE_EMPTY),nVert(SC_LINE_EMPTY) {} 64 }; 65 66 struct ScMergePatternState 67 { 68 SfxItemSet* pItemSet; // allocated in MergePatternArea, used for resulting ScPatternAttr 69 const ScPatternAttr* pOld1; // existing objects, temporary 70 const ScPatternAttr* pOld2; 71 72 ScMergePatternState() : pItemSet(NULL), pOld1(NULL), pOld2(NULL) {} 73 }; 74 75 struct ScAttrEntry 76 { 77 SCROW nRow; 78 const ScPatternAttr* pPattern; 79 }; 80 81 82 class ScAttrArray 83 { 84 private: 85 SCCOL nCol; 86 SCTAB nTab; 87 ScDocument* pDocument; 88 89 SCSIZE nCount; 90 SCSIZE nLimit; 91 ScAttrEntry* pData; 92 93 friend class ScDocument; // fuer FillInfo 94 friend class ScDocumentIterator; 95 friend class ScAttrIterator; 96 friend class ScHorizontalAttrIterator; 97 friend void lcl_IterGetNumberFormat( sal_uLong& nFormat, 98 const ScAttrArray*& rpArr, SCROW& nAttrEndRow, 99 const ScAttrArray* pNewArr, SCROW nRow, ScDocument* pDoc ); 100 101 sal_Bool ApplyFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner, 102 SCROW nStartRow, SCROW nEndRow, 103 sal_Bool bLeft, SCCOL nDistRight, sal_Bool bTop, SCROW nDistBottom ); 104 105 public: 106 ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc ); 107 ~ScAttrArray(); 108 109 void SetTab(SCTAB nNewTab) { nTab = nNewTab; } 110 void SetCol(SCCOL nNewCol) { nCol = nNewCol; } 111 #ifdef DBG_UTIL 112 void TestData() const; 113 #endif 114 void Reset( const ScPatternAttr* pPattern, sal_Bool bAlloc = sal_True ); 115 sal_Bool Concat(SCSIZE nPos); 116 117 const ScPatternAttr* GetPattern( SCROW nRow ) const; 118 const ScPatternAttr* GetPatternRange( SCROW& rStartRow, SCROW& rEndRow, SCROW nRow ) const; 119 void MergePatternArea( SCROW nStartRow, SCROW nEndRow, ScMergePatternState& rState, sal_Bool bDeep ) const; 120 121 void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags, 122 SCROW nStartRow, SCROW nEndRow, sal_Bool bLeft, SCCOL nDistRight ) const; 123 void ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner, 124 SCROW nStartRow, SCROW nEndRow, sal_Bool bLeft, SCCOL nDistRight ); 125 126 void SetPattern( SCROW nRow, const ScPatternAttr* pPattern, sal_Bool bPutToPool = sal_False ); 127 void SetPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr* pPattern, sal_Bool bPutToPool = sal_False); 128 void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, ScStyleSheet* pStyle ); 129 void ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache* pCache ); 130 void ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow, 131 const SvxBorderLine* pLine, sal_Bool bColorOnly ); 132 133 void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich ); 134 void ChangeIndent( SCROW nStartRow, SCROW nEndRow, sal_Bool bIncrement ); 135 136 /// Including current, may return -1 137 SCsROW GetNextUnprotected( SCsROW nRow, sal_Bool bUp ) const; 138 139 /// May return -1 if not found 140 SCsROW SearchStyle( SCsROW nRow, const ScStyleSheet* pSearchStyle, 141 sal_Bool bUp, ScMarkArray* pMarkArray = NULL ); 142 sal_Bool SearchStyleRange( SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle, 143 sal_Bool bUp, ScMarkArray* pMarkArray = NULL ); 144 145 sal_Bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags ); 146 sal_Bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags ); 147 148 sal_Bool Search( SCROW nRow, SCSIZE& nIndex ) const; 149 150 sal_Bool HasLines( SCROW nRow1, SCROW nRow2, Rectangle& rSizes, 151 sal_Bool bLeft, sal_Bool bRight ) const; 152 bool HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const; 153 sal_Bool ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow, 154 SCCOL& rPaintCol, SCROW& rPaintRow, 155 sal_Bool bRefresh, sal_Bool bAttrs ); 156 sal_Bool RemoveAreaMerge( SCROW nStartRow, SCROW nEndRow ); 157 158 void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset ); 159 sal_Bool IsStyleSheetUsed( const ScStyleSheet& rStyle, sal_Bool bGatherAllStyles ) const; 160 161 void DeleteAreaSafe(SCROW nStartRow, SCROW nEndRow); 162 void SetPatternAreaSafe( SCROW nStartRow, SCROW nEndRow, 163 const ScPatternAttr* pWantedPattern, sal_Bool bDefault ); 164 void CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray ); 165 166 sal_Bool IsEmpty() const; 167 168 //UNUSED2008-05 SCROW GetFirstEntryPos() const; 169 //UNUSED2008-05 SCROW GetLastEntryPos( sal_Bool bIncludeBottom ) const; 170 171 sal_Bool GetFirstVisibleAttr( SCROW& rFirstRow ) const; 172 sal_Bool GetLastVisibleAttr( 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