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 #pragma once
21 
22 #include "global.hxx"
23 #include "attrib.hxx"
24 #include "patattr.hxx"
25 
26 #include <algorithm>
27 #include <memory>
28 
29 #include <svl/itemset.hxx>
30 
31 class ScDocument;
32 class ScEditDataArray;
33 class ScMarkArray;
34 class ScStyleSheet;
36 
37 class SfxItemPoolCache;
38 class SfxStyleSheetBase;
39 class SvxBoxItem;
40 class SvxBoxInfoItem;
41 
42 namespace editeng { class SvxBorderLine; }
43 
44 #define SC_LINE_EMPTY 0
45 #define SC_LINE_SET 1
46 #define SC_LINE_DONTCARE 2
47 
48 #define SC_ATTRARRAY_DELTA 4
49 
50 #define DEBUG_SC_TESTATTRARRAY 0
51 
53 {
60 
62  nBottom(SC_LINE_EMPTY),nHori(SC_LINE_EMPTY),nVert(SC_LINE_EMPTY) {}
63 };
64 
66 {
67  std::unique_ptr<SfxItemSet> pItemSet;
70 
72  sal_uInt64 mnPatternId;
73 
74  ScMergePatternState() : pOld1(nullptr), pOld2(nullptr),
75  mbValidPatternId(true), mnPatternId(0) {}
76 };
77 
78 // we store an array of these where the pattern applies to all rows up till nEndRow
80 {
83 };
84 
86 {
87 private:
91 
92  std::vector<ScAttrEntry> mvData;
93 
94 friend class ScDocument; // for FillInfo
95 friend class ScDocumentIterator;
96 friend class ScAttrIterator;
98 
99  bool ApplyFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
101  bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom );
102 
104  const ScPatternAttr* pPattern, ScEditDataArray* pDataArray );
105  void SetDefaultIfNotInit( SCSIZE nNeeded = 1 );
106  bool HasAttrib_Impl(const ScPatternAttr* pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const;
107 
108  ScAttrArray(const ScAttrArray&) = delete;
109  ScAttrArray& operator=(const ScAttrArray&) = delete;
110 
111 public:
112  ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument& rDoc, ScAttrArray* pNextColAttrArray );
113  ~ScAttrArray();
114 
115  ScDocument& GetDoc() { return rDocument; }
116  void SetTab(SCTAB nNewTab) { nTab = nNewTab; }
117  void SetCol(SCCOL nNewCol) { nCol = nNewCol; }
118 #if DEBUG_SC_TESTATTRARRAY
119  void TestData() const;
120 #endif
121  void Reset( const ScPatternAttr* pPattern);
122  bool Concat(SCSIZE nPos);
123 
124  const ScPatternAttr* GetPattern( SCROW nRow ) const;
125 
131  const ScPatternAttr* GetPatternRange( SCROW& rStartRow, SCROW& rEndRow, SCROW nRow ) const;
132 
133  void MergePatternArea( SCROW nStartRow, SCROW nEndRow, ScMergePatternState& rState, bool bDeep ) const;
134 
135  void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
136  SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight ) const;
137  void ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
138  SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight);
139 
140  void SetPattern( SCROW nRow, const ScPatternAttr* pPattern, bool bPutToPool = false )
141  { SetPatternAreaImpl(nRow, nRow, pPattern, bPutToPool, nullptr, /*bPassingOwnership*/false); }
142  const ScPatternAttr* SetPattern( SCROW nRow, std::unique_ptr<ScPatternAttr> pPattern, bool bPutToPool = false )
143  { return SetPatternAreaImpl(nRow, nRow, pPattern.release(), bPutToPool, nullptr, /*bPassingOwnership*/true); }
144  void SetPatternArea( SCROW nStartRow, SCROW nEndRow, std::unique_ptr<ScPatternAttr> pPattern,
145  bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr)
146  { SetPatternAreaImpl(nStartRow, nEndRow, pPattern.release(), bPutToPool, pDataArray, /*bPassingOwnership*/true); }
148  bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr)
149  { SetPatternAreaImpl(nStartRow, nEndRow, pPattern, bPutToPool, pDataArray, /*bPassingOwnership*/false); }
150  void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
152  ScEditDataArray* pDataArray = nullptr, bool* const pIsChanged = nullptr );
153  void SetAttrEntries(std::vector<ScAttrEntry> && vNewData);
155  const ::editeng::SvxBorderLine* pLine, bool bColorOnly );
156 
157  void AddCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
159  void RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
160 
161  void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich );
162  void ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement );
163 
165  SCROW GetNextUnprotected( SCROW nRow, bool bUp ) const;
166 
169  SCROW nRow, const ScStyleSheet* pSearchStyle, bool bUp,
170  const ScMarkArray* pMarkArray = nullptr) const;
171 
172  bool SearchStyleRange(
173  SCROW& rRow, SCROW& rEndRow, const ScStyleSheet* pSearchStyle, bool bUp,
174  const ScMarkArray* pMarkArray = nullptr) const;
175 
176  bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags );
177  bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags );
178 
179  bool Search( SCROW nRow, SCSIZE& nIndex ) const;
180 
181  bool HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) const;
182  bool IsMerged( SCROW nRow ) const;
183  bool ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
184  SCCOL& rPaintCol, SCROW& rPaintRow,
185  bool bRefresh );
187 
188  void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
189  bool IsStyleSheetUsed( const ScStyleSheet& rStyle ) const;
190 
192  const ScPatternAttr* pWantedPattern, bool bDefault );
193  void CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray );
194 
195  bool IsEmpty() const;
196 
197  bool GetFirstVisibleAttr( SCROW& rFirstRow ) const;
198  bool GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const;
200  bool IsVisibleEqual( const ScAttrArray& rOther,
201  SCROW nStartRow, SCROW nEndRow ) const;
202  bool IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const;
203 
204  bool TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
205  bool TestInsertRow( SCSIZE nSize ) const;
206  void InsertRow( SCROW nStartRow, SCSIZE nSize );
207  void DeleteRow( SCROW nStartRow, SCSIZE nSize );
208  void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex );
210  void MoveTo( SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray );
211  void CopyArea(
212  SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags = ScMF::NONE) const;
213 
215 
216  /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */
217  bool Reserve( SCSIZE nReserve );
218  SCSIZE Count() const { return mvData.size(); }
219  SCSIZE Count( SCROW nRow1, SCROW nRow2 ) const;
220 
221 private:
223  bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr,
224  bool bPassingPatternOwnership = false );
225 };
226 
227 // Iterator for attributes
228 
230 {
236 public:
237  inline ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr* pDefaultPattern );
238  inline const ScPatternAttr* Next( SCROW& rTop, SCROW& rBottom );
239  inline const ScPatternAttr* Resync( SCROW nRow, SCROW& rTop, SCROW& rBottom );
240  SCROW GetNextRow() const { return nRow; }
241 };
242 
243 inline ScAttrIterator::ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr* pDefaultPattern ) :
244  pArray( pNewArray ),
245  pDefPattern( pDefaultPattern ),
246  nRow( nStart ),
247  nEndRow( nEnd )
248 {
249  if ( pArray->Count() )
250  {
251  if ( nStart > 0 )
252  pArray->Search( nStart, nPos );
253  else
254  nPos = 0;
255  }
256  else
257  nPos = 0;
258 }
259 
260 inline const ScPatternAttr* ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom )
261 {
262  const ScPatternAttr* pRet;
263  if ( !pArray->Count() )
264  {
265  if ( !nPos )
266  {
267  ++nPos;
268  if ( nRow > MAXROW )
269  return nullptr;
270  rTop = nRow;
271  rBottom = std::min( nEndRow, MAXROW );
272  nRow = rBottom + 1;
273  return pDefPattern;
274  }
275  return nullptr;
276  }
277 
278  if ( nPos < pArray->Count() && nRow <= nEndRow )
279  {
280  rTop = nRow;
281  rBottom = std::min( pArray->mvData[nPos].nEndRow, nEndRow );
282  pRet = pArray->mvData[nPos].pPattern;
283  nRow = rBottom + 1;
284  ++nPos;
285  }
286  else
287  pRet = nullptr;
288  return pRet;
289 }
290 
291 inline const ScPatternAttr* ScAttrIterator::Resync( SCROW nRowP, SCROW& rTop, SCROW& rBottom )
292 {
293  nRow = nRowP;
294  if ( !pArray->Count() )
295  {
296  nPos = 0;
297  return Next( rTop, rBottom );
298  }
299  // Chances are high that the pattern changed on nRowP introduced a span
300  // starting right there. Assume that Next() was called so nPos already
301  // advanced. Another high chance is that the change extended a previous or
302  // next pattern. In all these cases we don't need to search.
303  if (3 <= nPos && nPos <= pArray->Count() && pArray->mvData[nPos-3].nEndRow < nRowP &&
304  nRowP <= pArray->mvData[nPos-2].nEndRow)
305  nPos -= 2;
306  else if (2 <= nPos && nPos <= pArray->Count() && pArray->mvData[nPos-2].nEndRow < nRowP &&
307  nRowP <= pArray->mvData[nPos-1].nEndRow)
308  --nPos;
309  else if (pArray->Count() > 0 && nRowP <= pArray->mvData[0].nEndRow)
310  nPos = 0;
311  else
312  pArray->Search( nRowP, nPos );
313  return Next( rTop, rBottom);
314 }
315 
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsVisibleEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2007
void DeleteRange(SCSIZE nStartIndex, SCSIZE nEndIndex)
Definition: attarray.cxx:2307
bool TestInsertRow(SCSIZE nSize) const
Definition: attarray.cxx:2192
bool RemoveFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1641
HasAttrFlags
Definition: global.hxx:192
sal_uInt8 nRight
Definition: attarray.hxx:55
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:2210
bool IsMerged(SCROW nRow) const
Definition: attarray.cxx:1424
sal_uInt8 nVert
Definition: attarray.hxx:59
long Long
bool Reserve(SCSIZE nReserve)
Definition: attarray.cxx:427
const ScPatternAttr * pDefPattern
Definition: attarray.hxx:232
bool HasAttrib(SCROW nRow1, SCROW nRow2, HasAttrFlags nMask) const
Definition: attarray.cxx:1399
std::unique_ptr< SfxItemSet > pItemSet
Definition: attarray.hxx:67
bool Concat(SCSIZE nPos)
Definition: attarray.cxx:154
sal_uInt8 nLeft
Definition: attarray.hxx:54
sal_uInt8 nBottom
Definition: attarray.hxx:57
ScAttrArray(const ScAttrArray &)=delete
void SetPatternAreaSafe(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pWantedPattern, bool bDefault)
Definition: attarray.cxx:1549
void SetDefaultIfNotInit(SCSIZE nNeeded=1)
Definition: attarray.cxx:109
SCTAB nTab
Definition: attarray.hxx:89
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:2259
bool IsStyleSheetUsed(const ScStyleSheet &rStyle) const
Definition: attarray.cxx:1842
bool HasVisibleAttrIn(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:1986
const ScPatternAttr * pPattern
Definition: attarray.hxx:82
const ScPatternAttr * Next(SCROW &rTop, SCROW &rBottom)
Definition: attarray.hxx:260
void DeleteHardAttr(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2329
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:44
This is a rather odd datastructure.
Definition: markarr.hxx:43
const SCROW MAXROW
Definition: address.hxx:68
bool SearchStyleRange(SCROW &rRow, SCROW &rEndRow, const ScStyleSheet *pSearchStyle, bool bUp, const ScMarkArray *pMarkArray=nullptr) const
Definition: attarray.cxx:2590
void CopyAreaSafe(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray)
Leave flags summarized with CopyArea.
Definition: attarray.cxx:2465
bool TestInsertCol(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2165
ScDocument & rDocument
Definition: attarray.hxx:90
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:92
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:142
void ApplyCacheArea(SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache *pCache, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: attarray.cxx:843
ScDocument & GetDoc()
Definition: attarray.hxx:115
const ScPatternAttr * Resync(SCROW nRow, SCROW &rTop, SCROW &rBottom)
Definition: attarray.hxx:291
sal_Int16 SCCOL
Definition: types.hxx:21
const ScAttrArray * pArray
Definition: attarray.hxx:231
Count
void ClearItems(SCROW nStartRow, SCROW nEndRow, const sal_uInt16 *pWhich)
Definition: attarray.cxx:1678
void CopyArea(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray, ScMF nStripFlags=ScMF::NONE) const
Copy between documents (Clipboard)
Definition: attarray.cxx:2393
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:140
sal_uInt64 mnPatternId
Definition: attarray.hxx:72
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:2518
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:2087
friend class ScDocumentIterator
Definition: attarray.hxx:95
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, std::unique_ptr< ScPatternAttr > pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:144
SCSIZE Count() const
Definition: attarray.hxx:218
bool IsEmpty() const
Definition: attarray.cxx:1876
ScAttrArray & operator=(const ScAttrArray &)=delete
void MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray &rAttrArray)
Move within a document.
Definition: attarray.cxx:2373
SCROW GetNextRow() const
Definition: attarray.hxx:240
bool GetFirstVisibleAttr(SCROW &rFirstRow) const
Definition: attarray.cxx:1889
const ScPatternAttr * pOld2
Definition: attarray.hxx:69
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:147
void ChangeIndent(SCROW nStartRow, SCROW nEndRow, bool bIncrement)
Definition: attarray.cxx:1708
sal_Int32 SCROW
Definition: types.hxx:17
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:243
ScMF
Definition: attrib.hxx:34
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:56
void DeleteArea(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2317
SCROW GetNextUnprotected(SCROW nRow, bool bUp) const
Including current, may return -1.
Definition: attarray.cxx:1770
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:1925
void Reset(const ScPatternAttr *pPattern)
Definition: attarray.cxx:121
void FindStyleSheet(const SfxStyleSheetBase *pStyleSheet, ScFlatBoolRowSegments &rUsedRows, bool bReset)
Definition: attarray.cxx:1807
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:68
#define SC_LINE_EMPTY
Definition: attarray.hxx:44
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:88
void RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:1494
void SetCol(SCCOL nNewCol)
Definition: attarray.hxx:117
bool ApplyFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1604
SCROW nEndRow
Definition: attarray.hxx:81
sal_uInt8 nHori
Definition: attarray.hxx:58
void SetTab(SCTAB nNewTab)
Definition: attarray.hxx:116
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: attarray.cxx:239
sal_Int16 SCTAB
Definition: types.hxx:22