LibreOffice Module sc (master)  1
attarray.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SC_INC_ATTARRAY_HXX
21 #define INCLUDED_SC_INC_ATTARRAY_HXX
22 
23 #include "global.hxx"
24 #include "attrib.hxx"
25 #include "patattr.hxx"
26 
27 #include <algorithm>
28 #include <memory>
29 
30 #include <svl/itemset.hxx>
31 
32 class ScDocument;
33 class ScEditDataArray;
34 class ScMarkArray;
35 class ScStyleSheet;
37 
38 class SfxItemPoolCache;
39 class SfxStyleSheetBase;
40 class SvxBoxItem;
41 class SvxBoxInfoItem;
42 
43 namespace editeng { class SvxBorderLine; }
44 
45 #define SC_LINE_EMPTY 0
46 #define SC_LINE_SET 1
47 #define SC_LINE_DONTCARE 2
48 
49 #define SC_ATTRARRAY_DELTA 4
50 
51 #define DEBUG_SC_TESTATTRARRAY 0
52 
54 {
61 
63  nBottom(SC_LINE_EMPTY),nHori(SC_LINE_EMPTY),nVert(SC_LINE_EMPTY) {}
64 };
65 
67 {
68  std::unique_ptr<SfxItemSet> pItemSet;
71 
73  sal_uInt64 mnPatternId;
74 
75  ScMergePatternState() : pOld1(nullptr), pOld2(nullptr),
76  mbValidPatternId(true), mnPatternId(0) {}
77 };
78 
79 // we store an array of these where the pattern applies to all rows up till nEndRow
81 {
84 };
85 
87 {
88 private:
92 
93  std::vector<ScAttrEntry> mvData;
94 
95 friend class ScDocument; // for FillInfo
96 friend class ScDocumentIterator;
97 friend class ScAttrIterator;
99 
100  bool ApplyFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
102  bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom );
103 
105  const ScPatternAttr* pPattern, ScEditDataArray* pDataArray );
106  void SetDefaultIfNotInit( SCSIZE nNeeded = 1 );
107  bool HasAttrib_Impl(const ScPatternAttr* pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const;
108 
109  ScAttrArray(const ScAttrArray&) = delete;
110  ScAttrArray& operator=(const ScAttrArray&) = delete;
111 
112 public:
113  ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument& rDoc, ScAttrArray* pNextColAttrArray );
114  ~ScAttrArray();
115 
116  ScDocument& GetDoc() { return rDocument; }
117  void SetTab(SCTAB nNewTab) { nTab = nNewTab; }
118  void SetCol(SCCOL nNewCol) { nCol = nNewCol; }
119 #if DEBUG_SC_TESTATTRARRAY
120  void TestData() const;
121 #endif
122  void Reset( const ScPatternAttr* pPattern);
123  bool Concat(SCSIZE nPos);
124 
125  const ScPatternAttr* GetPattern( SCROW nRow ) const;
126 
132  const ScPatternAttr* GetPatternRange( SCROW& rStartRow, SCROW& rEndRow, SCROW nRow ) const;
133 
134  void MergePatternArea( SCROW nStartRow, SCROW nEndRow, ScMergePatternState& rState, bool bDeep ) const;
135 
136  void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
137  SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight ) const;
138  void ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
139  SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight);
140 
141  void SetPattern( SCROW nRow, const ScPatternAttr* pPattern, bool bPutToPool = false )
142  { SetPatternAreaImpl(nRow, nRow, pPattern, bPutToPool, nullptr, /*bPassingOwnership*/false); }
143  const ScPatternAttr* SetPattern( SCROW nRow, std::unique_ptr<ScPatternAttr> pPattern, bool bPutToPool = false )
144  { return SetPatternAreaImpl(nRow, nRow, pPattern.release(), bPutToPool, nullptr, /*bPassingOwnership*/true); }
145  void SetPatternArea( SCROW nStartRow, SCROW nEndRow, std::unique_ptr<ScPatternAttr> pPattern,
146  bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr)
147  { SetPatternAreaImpl(nStartRow, nEndRow, pPattern.release(), bPutToPool, pDataArray, /*bPassingOwnership*/true); }
149  bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr)
150  { SetPatternAreaImpl(nStartRow, nEndRow, pPattern, bPutToPool, pDataArray, /*bPassingOwnership*/false); }
151  void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
153  ScEditDataArray* pDataArray = nullptr, bool* const pIsChanged = nullptr );
154  void SetAttrEntries(std::vector<ScAttrEntry> && vNewData);
156  const ::editeng::SvxBorderLine* pLine, bool bColorOnly );
157 
158  void AddCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
160  void RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
161 
162  void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich );
163  void ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement );
164 
166  SCROW GetNextUnprotected( SCROW nRow, bool bUp ) const;
167 
170  SCROW nRow, const ScStyleSheet* pSearchStyle, bool bUp,
171  const ScMarkArray* pMarkArray = nullptr) const;
172 
173  bool SearchStyleRange(
174  SCROW& rRow, SCROW& rEndRow, const ScStyleSheet* pSearchStyle, bool bUp,
175  const ScMarkArray* pMarkArray = nullptr) const;
176 
177  bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags );
178  bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags );
179 
180  bool Search( SCROW nRow, SCSIZE& nIndex ) const;
181 
182  bool HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) const;
183  bool IsMerged( SCROW nRow ) const;
184  bool ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
185  SCCOL& rPaintCol, SCROW& rPaintRow,
186  bool bRefresh );
188 
189  void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
190  bool IsStyleSheetUsed( const ScStyleSheet& rStyle ) const;
191 
193  const ScPatternAttr* pWantedPattern, bool bDefault );
194  void CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray );
195 
196  bool IsEmpty() const;
197 
198  bool GetFirstVisibleAttr( SCROW& rFirstRow ) const;
199  bool GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const;
201  bool IsVisibleEqual( const ScAttrArray& rOther,
202  SCROW nStartRow, SCROW nEndRow ) const;
203  bool IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const;
204 
205  bool TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
206  bool TestInsertRow( SCSIZE nSize ) const;
207  void InsertRow( SCROW nStartRow, SCSIZE nSize );
208  void DeleteRow( SCROW nStartRow, SCSIZE nSize );
209  void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex );
211  void MoveTo( SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray );
212  void CopyArea(
213  SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags = ScMF::NONE) const;
214 
216 
217  /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */
218  bool Reserve( SCSIZE nReserve );
219  SCSIZE Count() const { return mvData.size(); }
220  SCSIZE Count( SCROW nRow1, SCROW nRow2 ) const;
221 
222 private:
224  bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr,
225  bool bPassingPatternOwnership = false );
226 };
227 
228 // Iterator for attributes
229 
231 {
237 public:
238  inline ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr* pDefaultPattern );
239  inline const ScPatternAttr* Next( SCROW& rTop, SCROW& rBottom );
240  inline const ScPatternAttr* Resync( SCROW nRow, SCROW& rTop, SCROW& rBottom );
241  SCROW GetNextRow() const { return nRow; }
242 };
243 
244 inline ScAttrIterator::ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr* pDefaultPattern ) :
245  pArray( pNewArray ),
246  pDefPattern( pDefaultPattern ),
247  nRow( nStart ),
248  nEndRow( nEnd )
249 {
250  if ( pArray->Count() )
251  {
252  if ( nStart > 0 )
253  pArray->Search( nStart, nPos );
254  else
255  nPos = 0;
256  }
257  else
258  nPos = 0;
259 }
260 
261 inline const ScPatternAttr* ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom )
262 {
263  const ScPatternAttr* pRet;
264  if ( !pArray->Count() )
265  {
266  if ( !nPos )
267  {
268  ++nPos;
269  if ( nRow > MAXROW )
270  return nullptr;
271  rTop = nRow;
272  rBottom = std::min( nEndRow, MAXROW );
273  nRow = rBottom + 1;
274  return pDefPattern;
275  }
276  return nullptr;
277  }
278 
279  if ( nPos < pArray->Count() && nRow <= nEndRow )
280  {
281  rTop = nRow;
282  rBottom = std::min( pArray->mvData[nPos].nEndRow, nEndRow );
283  pRet = pArray->mvData[nPos].pPattern;
284  nRow = rBottom + 1;
285  ++nPos;
286  }
287  else
288  pRet = nullptr;
289  return pRet;
290 }
291 
292 inline const ScPatternAttr* ScAttrIterator::Resync( SCROW nRowP, SCROW& rTop, SCROW& rBottom )
293 {
294  nRow = nRowP;
295  if ( !pArray->Count() )
296  {
297  nPos = 0;
298  return Next( rTop, rBottom );
299  }
300  // Chances are high that the pattern changed on nRowP introduced a span
301  // starting right there. Assume that Next() was called so nPos already
302  // advanced. Another high chance is that the change extended a previous or
303  // next pattern. In all these cases we don't need to search.
304  if (3 <= nPos && nPos <= pArray->Count() && pArray->mvData[nPos-3].nEndRow < nRowP &&
305  nRowP <= pArray->mvData[nPos-2].nEndRow)
306  nPos -= 2;
307  else if (2 <= nPos && nPos <= pArray->Count() && pArray->mvData[nPos-2].nEndRow < nRowP &&
308  nRowP <= pArray->mvData[nPos-1].nEndRow)
309  --nPos;
310  else if (pArray->Count() > 0 && nRowP <= pArray->mvData[0].nEndRow)
311  nPos = 0;
312  else
313  pArray->Search( nRowP, nPos );
314  return Next( rTop, rBottom);
315 }
316 
317 #endif
318 
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsVisibleEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2005
void DeleteRange(SCSIZE nStartIndex, SCSIZE nEndIndex)
Definition: attarray.cxx:2305
bool TestInsertRow(SCSIZE nSize) const
Definition: attarray.cxx:2190
bool RemoveFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1642
HasAttrFlags
Definition: global.hxx:194
sal_uInt8 nRight
Definition: attarray.hxx:56
TestDataElements TestData
bool ExtendMerge(SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow, SCCOL &rPaintCol, SCROW &rPaintRow, bool bRefresh)
Area around any given summaries expand and adapt any MergeFlag (bRefresh)
Definition: attarray.cxx:1441
void InsertRow(SCROW nStartRow, SCSIZE nSize)
Definition: attarray.cxx:2208
bool IsMerged(SCROW nRow) const
Definition: attarray.cxx:1424
sal_uInt8 nVert
Definition: attarray.hxx:60
long Long
bool Reserve(SCSIZE nReserve)
Definition: attarray.cxx:427
const ScPatternAttr * pDefPattern
Definition: attarray.hxx:233
bool HasAttrib(SCROW nRow1, SCROW nRow2, HasAttrFlags nMask) const
Definition: attarray.cxx:1399
std::unique_ptr< SfxItemSet > pItemSet
Definition: attarray.hxx:68
bool Concat(SCSIZE nPos)
Definition: attarray.cxx:154
sal_uInt8 nLeft
Definition: attarray.hxx:55
sal_uInt8 nBottom
Definition: attarray.hxx:58
ScAttrArray(const ScAttrArray &)=delete
void SetPatternAreaSafe(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pWantedPattern, bool bDefault)
Definition: attarray.cxx:1550
void SetDefaultIfNotInit(SCSIZE nNeeded=1)
Definition: attarray.cxx:109
SCTAB nTab
Definition: attarray.hxx:90
void ApplyBlockFrame(const SvxBoxItem &rLineOuter, const SvxBoxInfoItem *pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight)
Definition: attarray.cxx:1232
void SetAttrEntries(std::vector< ScAttrEntry > &&vNewData)
Definition: attarray.cxx:926
void DeleteRow(SCROW nStartRow, SCSIZE nSize)
Definition: attarray.cxx:2257
bool IsStyleSheetUsed(const ScStyleSheet &rStyle) const
Definition: attarray.cxx:1844
bool HasVisibleAttrIn(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:1984
const ScPatternAttr * pPattern
Definition: attarray.hxx:83
const ScPatternAttr * Next(SCROW &rTop, SCROW &rBottom)
Definition: attarray.hxx:261
void DeleteHardAttr(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2327
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:45
This is a rather odd datastructure.
Definition: markarr.hxx:44
const SCROW MAXROW
Definition: address.hxx:69
bool SearchStyleRange(SCROW &rRow, SCROW &rEndRow, const ScStyleSheet *pSearchStyle, bool bUp, const ScMarkArray *pMarkArray=nullptr) const
Definition: attarray.cxx:2588
void CopyAreaSafe(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray)
Leave flags summarized with CopyArea.
Definition: attarray.cxx:2463
bool TestInsertCol(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2163
ScDocument & rDocument
Definition: attarray.hxx:91
bool Search(SCROW nRow, SCSIZE &nIndex) const
Definition: attarray.cxx:194
std::vector< std::unique_ptr< SvLinkSource_Entry_Impl > > mvData
std::vector< ScAttrEntry > mvData
Definition: attarray.hxx:93
void MergePatternArea(SCROW nStartRow, SCROW nEndRow, ScMergePatternState &rState, bool bDeep) const
Definition: attarray.cxx:971
const ScPatternAttr * SetPattern(SCROW nRow, std::unique_ptr< ScPatternAttr > pPattern, bool bPutToPool=false)
Definition: attarray.hxx:143
void ApplyCacheArea(SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache *pCache, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: attarray.cxx:843
ScDocument & GetDoc()
Definition: attarray.hxx:116
const ScPatternAttr * Resync(SCROW nRow, SCROW &rTop, SCROW &rBottom)
Definition: attarray.hxx:292
sal_Int16 SCCOL
Definition: types.hxx:22
const ScAttrArray * pArray
Definition: attarray.hxx:232
Count
void ClearItems(SCROW nStartRow, SCROW nEndRow, const sal_uInt16 *pWhich)
Definition: attarray.cxx:1679
void CopyArea(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray, ScMF nStripFlags=ScMF::NONE) const
Copy between documents (Clipboard)
Definition: attarray.cxx:2391
void ApplyStyleArea(SCROW nStartRow, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: attarray.cxx:626
void SetPattern(SCROW nRow, const ScPatternAttr *pPattern, bool bPutToPool=false)
Definition: attarray.hxx:141
sal_uInt64 mnPatternId
Definition: attarray.hxx:73
bool HasAttrib_Impl(const ScPatternAttr *pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const
Definition: attarray.cxx:1274
SCROW SearchStyle(SCROW nRow, const ScStyleSheet *pSearchStyle, bool bUp, const ScMarkArray *pMarkArray=nullptr) const
May return -1 if not found.
Definition: attarray.cxx:2516
void RemoveCellCharAttribs(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, ScEditDataArray *pDataArray)
Definition: attarray.cxx:397
bool IsAllEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2085
friend class ScDocumentIterator
Definition: attarray.hxx:96
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, std::unique_ptr< ScPatternAttr > pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:145
SCSIZE Count() const
Definition: attarray.hxx:219
bool IsEmpty() const
Definition: attarray.cxx:1878
ScAttrArray & operator=(const ScAttrArray &)=delete
void MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray &rAttrArray)
Move within a document.
Definition: attarray.cxx:2371
SCROW GetNextRow() const
Definition: attarray.hxx:241
bool GetFirstVisibleAttr(SCROW &rFirstRow) const
Definition: attarray.cxx:1891
const ScPatternAttr * pOld2
Definition: attarray.hxx:70
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:148
void ChangeIndent(SCROW nStartRow, SCROW nEndRow, bool bIncrement)
Definition: attarray.cxx:1709
sal_Int32 SCROW
Definition: types.hxx:18
const ScPatternAttr * SetPatternAreaImpl(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr, bool bPassingPatternOwnership=false)
Definition: attarray.cxx:454
ScAttrIterator(const ScAttrArray *pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr *pDefaultPattern)
Definition: attarray.hxx:244
ScMF
Definition: attrib.hxx:35
unsigned char sal_uInt8
void MergeBlockFrame(SvxBoxItem *pLineOuter, SvxBoxInfoItem *pLineInner, ScLineFlags &rFlags, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight) const
Definition: attarray.cxx:1121
sal_uInt8 nTop
Definition: attarray.hxx:57
void DeleteArea(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2315
SCROW GetNextUnprotected(SCROW nRow, bool bUp) const
Including current, may return -1.
Definition: attarray.cxx:1771
void ApplyLineStyleArea(SCROW nStartRow, SCROW nEndRow, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: attarray.cxx:720
bool GetLastVisibleAttr(SCROW &rLastRow, SCROW nLastData) const
Definition: attarray.cxx:1927
void Reset(const ScPatternAttr *pPattern)
Definition: attarray.cxx:121
void FindStyleSheet(const SfxStyleSheetBase *pStyleSheet, ScFlatBoolRowSegments &rUsedRows, bool bReset)
Definition: attarray.cxx:1808
void RemoveCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex)
if nIndex == 0, remove all conditional format data
Definition: attarray.cxx:338
const ScPatternAttr * pOld1
existing objects, temporary
Definition: attarray.hxx:69
#define SC_LINE_EMPTY
Definition: attarray.hxx:45
const ScPatternAttr * GetPatternRange(SCROW &rStartRow, SCROW &rEndRow, SCROW nRow) const
Returns if you search for attributes at nRow the range from rStartRow to rEndRow where that attribute...
Definition: attarray.cxx:254
bool ApplyFrame(const SvxBoxItem *pLineOuter, const SvxBoxInfoItem *pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom)
Definition: attarray.cxx:1163
void AddCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex)
Definition: attarray.cxx:278
SCCOL nCol
Definition: attarray.hxx:89
void RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:1494
void SetCol(SCCOL nNewCol)
Definition: attarray.hxx:118
bool ApplyFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1605
SCROW nEndRow
Definition: attarray.hxx:82
sal_uInt8 nHori
Definition: attarray.hxx:59
void SetTab(SCTAB nNewTab)
Definition: attarray.hxx:117
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: attarray.cxx:239
sal_Int16 SCTAB
Definition: types.hxx:23