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 "document.hxx"
25#include "patattr.hxx"
26
27#include <algorithm>
28#include <memory>
29#include <optional>
30
31#include <svl/itemset.hxx>
32
33class ScDocument;
34class ScEditDataArray;
35class ScMarkArray;
36class ScStyleSheet;
38
41class SvxBoxItem;
42class SvxBoxInfoItem;
43
44namespace editeng { class SvxBorderLine; }
45
46#define SC_LINE_EMPTY 0
47#define SC_LINE_SET 1
48#define SC_LINE_DONTCARE 2
49
50#define SC_ATTRARRAY_DELTA 4
51
52#define DEBUG_SC_TESTATTRARRAY 0
53
55{
62
65};
66
68{
69 std::optional<SfxItemSet> pItemSet;
72
74 sal_uInt64 mnPatternId;
75
76 ScMergePatternState() : pOld1(nullptr), pOld2(nullptr),
77 mbValidPatternId(true), mnPatternId(0) {}
78};
79
80// we store an array of these where the pattern applies to all rows up till nEndRow
82{
85 bool operator==( const ScAttrEntry& other ) const
86 {
87 return nEndRow == other.nEndRow && pPattern == other.pPattern;
88 }
89};
90
92{
93private:
97
98 std::vector<ScAttrEntry> mvData;
99
100friend class ScDocument; // for FillInfo
102friend class ScAttrIterator;
104
105 bool ApplyFrame( const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
107 bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom );
108
110 const ScPatternAttr* pPattern, ScEditDataArray* pDataArray );
111 void SetDefaultIfNotInit( SCSIZE nNeeded = 1 );
112 bool HasAttrib_Impl(const ScPatternAttr* pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const;
113
114 ScAttrArray(const ScAttrArray&) = delete;
116
117public:
118 ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument& rDoc, ScAttrArray* pNextColAttrArray );
119 ~ScAttrArray();
120
122 const ScDocument& GetDoc() const { return rDocument; }
123 void SetTab(SCTAB nNewTab) { nTab = nNewTab; }
124 void SetCol(SCCOL nNewCol) { nCol = nNewCol; }
125#if DEBUG_SC_TESTATTRARRAY
126 void TestData() const;
127#endif
128 void Reset( const ScPatternAttr* pPattern);
129 bool Concat(SCSIZE nPos);
130
131 const ScPatternAttr* GetPattern( SCROW nRow ) const;
132
138 const ScPatternAttr* GetPatternRange( SCROW& rStartRow, SCROW& rEndRow, SCROW nRow ) const;
139
140 void MergePatternArea( SCROW nStartRow, SCROW nEndRow, ScMergePatternState& rState, bool bDeep ) const;
141
142 void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
143 SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight ) const;
144 void ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
145 SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight);
146
147 void SetPattern( SCROW nRow, const ScPatternAttr* pPattern, bool bPutToPool = false )
148 { SetPatternAreaImpl(nRow, nRow, pPattern, bPutToPool, nullptr, /*bPassingOwnership*/false); }
149 const ScPatternAttr* SetPattern( SCROW nRow, std::unique_ptr<ScPatternAttr> pPattern, bool bPutToPool = false )
150 { return SetPatternAreaImpl(nRow, nRow, pPattern.release(), bPutToPool, nullptr, /*bPassingOwnership*/true); }
151 void SetPatternArea( SCROW nStartRow, SCROW nEndRow, std::unique_ptr<ScPatternAttr> pPattern,
152 bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr)
153 { SetPatternAreaImpl(nStartRow, nEndRow, pPattern.release(), bPutToPool, pDataArray, /*bPassingOwnership*/true); }
155 bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr)
156 { SetPatternAreaImpl(nStartRow, nEndRow, pPattern, bPutToPool, pDataArray, /*bPassingOwnership*/false); }
157 void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
159 ScEditDataArray* pDataArray = nullptr, bool* const pIsChanged = nullptr );
160 void SetAttrEntries(std::vector<ScAttrEntry> && vNewData);
162 const ::editeng::SvxBorderLine* pLine, bool bColorOnly );
163
164 void AddCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
166 void RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
167
168 void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich );
169 void ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement );
170
172 SCROW GetNextUnprotected( SCROW nRow, bool bUp ) const;
173
176 SCROW nRow, const ScStyleSheet* pSearchStyle, bool bUp,
177 const ScMarkArray* pMarkArray = nullptr) const;
178
179 bool SearchStyleRange(
180 SCROW& rRow, SCROW& rEndRow, const ScStyleSheet* pSearchStyle, bool bUp,
181 const ScMarkArray* pMarkArray = nullptr) const;
182
183 bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags );
184 bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags );
185
186 bool Search( SCROW nRow, SCSIZE& nIndex ) const;
187
188 bool HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) const;
189 bool HasAttrib( SCROW nRow, HasAttrFlags nMask, SCROW* nStartRow = nullptr, SCROW* nEndRow = nullptr ) const;
190 bool IsMerged( SCROW nRow ) const;
191 bool ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
192 SCCOL& rPaintCol, SCROW& rPaintRow,
193 bool bRefresh );
195
196 void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
197 bool IsStyleSheetUsed( const ScStyleSheet& rStyle ) const;
198
200 const ScPatternAttr* pWantedPattern, bool bDefault );
202
203 bool IsEmpty() const;
204
205 bool GetFirstVisibleAttr( SCROW& rFirstRow ) const;
206 bool GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const;
208 bool IsVisibleEqual( const ScAttrArray& rOther,
209 SCROW nStartRow, SCROW nEndRow ) const;
210 bool IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const;
211
213 bool TestInsertRow( SCSIZE nSize ) const;
214 void InsertRow( SCROW nStartRow, SCSIZE nSize );
215 void DeleteRow( SCROW nStartRow, SCSIZE nSize );
216 void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex );
218 void MoveTo( SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray );
219 void CopyArea(
220 SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags = ScMF::NONE) const;
221
223
224 /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */
225 bool Reserve( SCSIZE nReserve );
226 SCSIZE Count() const { return mvData.size(); }
227 SCSIZE Count( SCROW nRow1, SCROW nRow2 ) const;
228
229private:
231 bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr,
232 bool bPassingPatternOwnership = false );
233};
234
235// Iterator for attributes
236
238{
244public:
245 inline ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr* pDefaultPattern );
246 inline const ScPatternAttr* Next( SCROW& rTop, SCROW& rBottom );
247 inline const ScPatternAttr* Resync( SCROW nRow, SCROW& rTop, SCROW& rBottom );
248 SCROW GetNextRow() const { return nRow; }
249};
250
251inline ScAttrIterator::ScAttrIterator( const ScAttrArray* pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr* pDefaultPattern ) :
252 pArray( pNewArray ),
253 pDefPattern( pDefaultPattern ),
254 nRow( nStart ),
255 nEndRow( nEnd )
256{
257 if ( pArray->Count() )
258 {
259 if ( nStart > 0 )
260 pArray->Search( nStart, nPos );
261 else
262 nPos = 0;
263 }
264 else
265 nPos = 0;
266}
267
268inline const ScPatternAttr* ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom )
269{
270 const ScPatternAttr* pRet;
271 if ( !pArray->Count() )
272 {
273 if ( !nPos )
274 {
275 ++nPos;
276 if ( nRow > pArray->GetDoc().MaxRow())
277 return nullptr;
278 rTop = nRow;
279 rBottom = std::min( nEndRow, pArray->GetDoc().MaxRow());
280 nRow = rBottom + 1;
281 return pDefPattern;
282 }
283 return nullptr;
284 }
285
286 if ( nPos < pArray->Count() && nRow <= nEndRow )
287 {
288 rTop = nRow;
289 rBottom = std::min( pArray->mvData[nPos].nEndRow, nEndRow );
290 pRet = pArray->mvData[nPos].pPattern;
291 nRow = rBottom + 1;
292 ++nPos;
293 }
294 else
295 pRet = nullptr;
296 return pRet;
297}
298
299inline const ScPatternAttr* ScAttrIterator::Resync( SCROW nRowP, SCROW& rTop, SCROW& rBottom )
300{
301 nRow = nRowP;
302 if ( !pArray->Count() )
303 {
304 nPos = 0;
305 return Next( rTop, rBottom );
306 }
307 // Chances are high that the pattern changed on nRowP introduced a span
308 // starting right there. Assume that Next() was called so nPos already
309 // advanced. Another high chance is that the change extended a previous or
310 // next pattern. In all these cases we don't need to search.
311 if (3 <= nPos && nPos <= pArray->Count() && pArray->mvData[nPos-3].nEndRow < nRowP &&
312 nRowP <= pArray->mvData[nPos-2].nEndRow)
313 nPos -= 2;
314 else if (2 <= nPos && nPos <= pArray->Count() && pArray->mvData[nPos-2].nEndRow < nRowP &&
315 nRowP <= pArray->mvData[nPos-1].nEndRow)
316 --nPos;
317 else if (pArray->Count() > 0 && nRowP <= pArray->mvData[0].nEndRow)
318 nPos = 0;
319 else
320 pArray->Search( nRowP, nPos );
321 return Next( rTop, rBottom);
322}
323
324/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
#define SC_LINE_EMPTY
Definition: attarray.hxx:46
ScMF
Definition: attrib.hxx:34
const ScDocument & GetDoc() const
Definition: attarray.hxx:122
bool Concat(SCSIZE nPos)
Definition: attarray.cxx:154
bool RemoveFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1659
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:154
SCROW GetNextUnprotected(SCROW nRow, bool bUp) const
Including current, may return -1.
Definition: attarray.cxx:1790
void ClearItems(SCROW nStartRow, SCROW nEndRow, const sal_uInt16 *pWhich)
Definition: attarray.cxx:1696
const ScPatternAttr * SetPattern(SCROW nRow, std::unique_ptr< ScPatternAttr > pPattern, bool bPutToPool=false)
Definition: attarray.hxx:149
ScAttrArray(const ScAttrArray &)=delete
void SetAttrEntries(std::vector< ScAttrEntry > &&vNewData)
Definition: attarray.cxx:919
void FindStyleSheet(const SfxStyleSheetBase *pStyleSheet, ScFlatBoolRowSegments &rUsedRows, bool bReset)
Definition: attarray.cxx:1827
void DeleteArea(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2333
ScDocument & GetDoc()
Definition: attarray.hxx:121
bool Search(SCROW nRow, SCSIZE &nIndex) const
Definition: attarray.cxx:194
void DeleteHardAttr(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2345
void SetPattern(SCROW nRow, const ScPatternAttr *pPattern, bool bPutToPool=false)
Definition: attarray.hxx:147
bool ApplyFrame(const SvxBoxItem &rLineOuter, const SvxBoxInfoItem *pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom)
Definition: attarray.cxx:1165
ScDocument & rDocument
Definition: attarray.hxx:96
bool IsEmpty() const
Definition: attarray.cxx:1896
bool Reserve(SCSIZE nReserve)
Definition: attarray.cxx:423
bool HasVisibleAttrIn(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2002
bool IsVisibleEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2023
SCCOL nCol
Definition: attarray.hxx:94
void RemoveCellCharAttribs(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, ScEditDataArray *pDataArray)
Definition: attarray.cxx:393
bool IsMerged(SCROW nRow) const
Definition: attarray.cxx:1442
bool ApplyFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1622
void ApplyCacheArea(SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache *pCache, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: attarray.cxx:836
void Reset(const ScPatternAttr *pPattern)
Definition: attarray.cxx:121
void SetTab(SCTAB nNewTab)
Definition: attarray.hxx:123
SCROW SearchStyle(SCROW nRow, const ScStyleSheet *pSearchStyle, bool bUp, const ScMarkArray *pMarkArray=nullptr) const
May return -1 if not found.
Definition: attarray.cxx:2534
void ChangeIndent(SCROW nStartRow, SCROW nEndRow, bool bIncrement)
Definition: attarray.cxx:1726
void SetDefaultIfNotInit(SCSIZE nNeeded=1)
Definition: attarray.cxx:109
void DeleteRow(SCROW nStartRow, SCSIZE nSize)
Definition: attarray.cxx:2275
SCSIZE Count() const
Definition: attarray.hxx:226
void MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray &rAttrArray)
Move within a document.
Definition: attarray.cxx:2389
void RemoveCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex)
if nIndex == 0, remove all conditional format data
Definition: attarray.cxx:336
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: attarray.cxx:239
ScAttrArray & operator=(const ScAttrArray &)=delete
void DeleteRange(SCSIZE nStartIndex, SCSIZE nEndIndex)
Definition: attarray.cxx:2323
void ApplyLineStyleArea(SCROW nStartRow, SCROW nEndRow, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: attarray.cxx:716
SCTAB nTab
Definition: attarray.hxx:95
void MergePatternArea(SCROW nStartRow, SCROW nEndRow, ScMergePatternState &rState, bool bDeep) const
Definition: attarray.cxx:973
bool GetFirstVisibleAttr(SCROW &rFirstRow) const
Definition: attarray.cxx:1909
void MergeBlockFrame(SvxBoxItem *pLineOuter, SvxBoxInfoItem *pLineInner, ScLineFlags &rFlags, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight) const
Definition: attarray.cxx:1123
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:1459
const ScPatternAttr * SetPatternAreaImpl(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr, bool bPassingPatternOwnership=false)
Definition: attarray.cxx:450
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, std::unique_ptr< ScPatternAttr > pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:151
bool IsAllEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2103
bool TestInsertRow(SCSIZE nSize) const
Definition: attarray.cxx:2208
bool IsStyleSheetUsed(const ScStyleSheet &rStyle) const
Definition: attarray.cxx:1862
bool HasAttrib_Impl(const ScPatternAttr *pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const
Definition: attarray.cxx:1273
void CopyAreaSafe(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray)
Leave flags summarized with CopyArea.
Definition: attarray.cxx:2481
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
void ApplyStyleArea(SCROW nStartRow, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: attarray.cxx:622
bool SearchStyleRange(SCROW &rRow, SCROW &rEndRow, const ScStyleSheet *pSearchStyle, bool bUp, const ScMarkArray *pMarkArray=nullptr) const
Definition: attarray.cxx:2606
void CopyArea(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray, ScMF nStripFlags=ScMF::NONE) const
Copy between documents (Clipboard)
Definition: attarray.cxx:2409
bool HasAttrib(SCROW nRow1, SCROW nRow2, HasAttrFlags nMask) const
Definition: attarray.cxx:1396
bool GetLastVisibleAttr(SCROW &rLastRow, SCROW nLastData) const
Definition: attarray.cxx:1945
friend class ScDocumentIterator
Definition: attarray.hxx:101
void ApplyBlockFrame(const SvxBoxItem &rLineOuter, const SvxBoxInfoItem *pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight)
Definition: attarray.cxx:1234
bool TestInsertCol(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2181
void SetCol(SCCOL nNewCol)
Definition: attarray.hxx:124
void InsertRow(SCROW nStartRow, SCSIZE nSize)
Definition: attarray.cxx:2226
void SetPatternAreaSafe(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pWantedPattern, bool bDefault)
Definition: attarray.cxx:1567
std::vector< ScAttrEntry > mvData
Definition: attarray.hxx:98
void AddCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex)
Definition: attarray.cxx:278
void RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:1512
ScAttrIterator(const ScAttrArray *pNewArray, SCROW nStart, SCROW nEnd, const ScPatternAttr *pDefaultPattern)
Definition: attarray.hxx:251
const ScAttrArray * pArray
Definition: attarray.hxx:239
SCROW GetNextRow() const
Definition: attarray.hxx:248
const ScPatternAttr * Next(SCROW &rTop, SCROW &rBottom)
Definition: attarray.hxx:268
const ScPatternAttr * pDefPattern
Definition: attarray.hxx:240
const ScPatternAttr * Resync(SCROW nRow, SCROW &rTop, SCROW &rBottom)
Definition: attarray.hxx:299
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:892
This is a rather odd datastructure.
Definition: markarr.hxx:44
HasAttrFlags
Definition: global.hxx:183
std::vector< std::unique_ptr< SvLinkSource_Entry_Impl > > mvData
Count
TestDataElements TestData
long Long
SCROW nEndRow
Definition: attarray.hxx:83
bool operator==(const ScAttrEntry &other) const
Definition: attarray.hxx:85
const ScPatternAttr * pPattern
Definition: attarray.hxx:84
sal_uInt8 nHori
Definition: attarray.hxx:60
sal_uInt8 nVert
Definition: attarray.hxx:61
sal_uInt8 nLeft
Definition: attarray.hxx:56
sal_uInt8 nBottom
Definition: attarray.hxx:59
sal_uInt8 nRight
Definition: attarray.hxx:57
sal_uInt8 nTop
Definition: attarray.hxx:58
const ScPatternAttr * pOld2
Definition: attarray.hxx:71
std::optional< SfxItemSet > pItemSet
Definition: attarray.hxx:69
const ScPatternAttr * pOld1
existing objects, temporary
Definition: attarray.hxx:70
sal_uInt64 mnPatternId
Definition: attarray.hxx:74
unsigned char sal_uInt8
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17