LibreOffice Module sc (master)  1
attarray.cxx
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 #include <attarray.hxx>
21 #include <scitems.hxx>
22 #include <editeng/borderline.hxx>
23 #include <editeng/boxitem.hxx>
24 #include <editeng/lineitem.hxx>
25 #include <editeng/shaditem.hxx>
26 #include <editeng/editobj.hxx>
27 #include <editeng/justifyitem.hxx>
28 #include <osl/diagnose.h>
29 #include <svl/poolcach.hxx>
30 #include <sfx2/objsh.hxx>
31 
32 #include <global.hxx>
33 #include <document.hxx>
34 #include <docpool.hxx>
35 #include <patattr.hxx>
36 #include <stlsheet.hxx>
37 #include <stlpool.hxx>
38 #include <markarr.hxx>
39 #include <globstr.hrc>
40 #include <scresid.hxx>
41 #include <segmenttree.hxx>
42 #include <editdataarray.hxx>
43 #include <cellvalue.hxx>
44 #include <editutil.hxx>
45 #include <mtvelements.hxx>
46 #include <memory>
47 
48 using ::editeng::SvxBorderLine;
49 
50 ScAttrArray::ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument& rDoc, ScAttrArray* pDefaultColAttrArray ) :
51  nCol( nNewCol ),
52  nTab( nNewTab ),
53  rDocument( rDoc )
54 {
55  if ( nCol == -1 || !pDefaultColAttrArray || pDefaultColAttrArray->mvData.empty() )
56  return;
57 
58  ScAddress aAdrStart( nCol, 0, nTab );
59  ScAddress aAdrEnd( nCol, 0, nTab );
60  mvData.resize( pDefaultColAttrArray->mvData.size() );
61  for ( size_t nIdx = 0; nIdx < pDefaultColAttrArray->mvData.size(); ++nIdx )
62  {
63  mvData[nIdx].nEndRow = pDefaultColAttrArray->mvData[nIdx].nEndRow;
64  ScPatternAttr aNewPattern( *(pDefaultColAttrArray->mvData[nIdx].pPattern) );
65  mvData[nIdx].pPattern = &rDocument.GetPool()->Put( aNewPattern );
66  bool bNumFormatChanged = false;
67  if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
68  mvData[nIdx].pPattern->GetItemSet(), rDocument.GetDefPattern()->GetItemSet() ) )
69  {
70  aAdrStart.SetRow( nIdx ? mvData[nIdx-1].nEndRow+1 : 0 );
71  aAdrEnd.SetRow( mvData[nIdx].nEndRow );
72  rDocument.InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
73  }
74  }
75 }
76 
78 {
79 #if DEBUG_SC_TESTATTRARRAY
80  TestData();
81 #endif
82 
83  ScDocumentPool* pDocPool = rDocument.GetPool();
84  for (auto const & rEntry : mvData)
85  pDocPool->Remove(*rEntry.pPattern);
86 }
87 
88 #if DEBUG_SC_TESTATTRARRAY
89 void ScAttrArray::TestData() const
90 {
91 
92  sal_uInt16 nErr = 0;
93  SCSIZE nPos;
94  for (nPos=0; nPos<nCount; nPos++)
95  {
96  if (nPos > 0)
97  if (mvData[nPos].pPattern == mvData[nPos-1].pPattern || mvData[nPos].nRow <= mvData[nPos-1].nRow)
98  ++nErr;
99  if (mvData[nPos].pPattern->Which() != ATTR_PATTERN)
100  ++nErr;
101  }
102  if ( nPos && mvData[nPos-1].nRow != rDocument.MaxRow() )
103  ++nErr;
104 
105  SAL_WARN_IF( nErr, "sc", nErr << " errors in attribute array, column " << nCol );
106 }
107 #endif
108 
110 {
111  if ( !mvData.empty() )
112  return;
113 
114  SCSIZE nNewLimit = std::max<SCSIZE>( SC_ATTRARRAY_DELTA, nNeeded );
115  mvData.reserve( nNewLimit );
116  mvData.emplace_back();
117  mvData[0].nEndRow = rDocument.MaxRow();
118  mvData[0].pPattern = rDocument.GetDefPattern(); // no put
119 }
120 
121 void ScAttrArray::Reset( const ScPatternAttr* pPattern )
122 {
123  ScDocumentPool* pDocPool = rDocument.GetPool();
124  ScAddress aAdrStart( nCol, 0, nTab );
125  ScAddress aAdrEnd ( nCol, 0, nTab );
126 
127  for (SCSIZE i=0; i<mvData.size(); i++)
128  {
129  // ensure that attributing changes text width of cell
130  const ScPatternAttr* pOldPattern = mvData[i].pPattern;
131  if ( nCol != -1 )
132  {
133  bool bNumFormatChanged;
134  if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
135  pPattern->GetItemSet(), pOldPattern->GetItemSet() ) )
136  {
137  aAdrStart.SetRow( i ? mvData[i-1].nEndRow+1 : 0 );
138  aAdrEnd .SetRow( mvData[i].nEndRow );
139  rDocument.InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
140  }
141  }
142  pDocPool->Remove(*pOldPattern);
143  }
144  mvData.resize(0);
145 
146  rDocument.SetStreamValid(nTab, false);
147 
148  mvData.resize(1);
149  const ScPatternAttr* pNewPattern = &pDocPool->Put(*pPattern);
150  mvData[0].nEndRow = rDocument.MaxRow();
151  mvData[0].pPattern = pNewPattern;
152 }
153 
155 {
156  bool bRet = false;
157  if (nPos < mvData.size())
158  {
159  if (nPos > 0)
160  {
161  if (mvData[nPos - 1].pPattern == mvData[nPos].pPattern)
162  {
163  mvData[nPos - 1].nEndRow = mvData[nPos].nEndRow;
164  rDocument.GetPool()->Remove(*mvData[nPos].pPattern);
165  mvData.erase(mvData.begin() + nPos);
166  nPos--;
167  bRet = true;
168  }
169  }
170  if (nPos + 1 < mvData.size())
171  {
172  if (mvData[nPos + 1].pPattern == mvData[nPos].pPattern)
173  {
174  mvData[nPos].nEndRow = mvData[nPos + 1].nEndRow;
175  rDocument.GetPool()->Remove(*mvData[nPos].pPattern);
176  mvData.erase(mvData.begin() + nPos + 1);
177  bRet = true;
178  }
179  }
180  }
181  return bRet;
182 }
183 
184 /*
185  * nCount is the number of runs of different attribute combinations;
186  * no attribute in a column => nCount==1, one attribute somewhere => nCount == 3
187  * (ie. one run with no attribute + one attribute + another run with no attribute)
188  * so a range of identical attributes is only one entry in ScAttrArray.
189  *
190  * Iterative implementation of Binary Search
191  * The same implementation was used inside ScMarkArray::Search().
192  */
193 
194 bool ScAttrArray::Search( SCROW nRow, SCSIZE& nIndex ) const
195 {
196 /* auto it = std::lower_bound(mvData.begin(), mvData.end(), nRow,
197  [] (const ScAttrEntry &r1, SCROW nRow)
198  { return r1.nEndRow < nRow; } );
199  if (it != mvData.end())
200  nIndex = it - mvData.begin();
201  return it != mvData.end(); */
202 
203  if (mvData.size() == 1)
204  {
205  nIndex = 0;
206  return true;
207  }
208 
209  tools::Long nHi = static_cast<tools::Long>(mvData.size()) - 1;
210  tools::Long i = 0;
211  tools::Long nLo = 0;
212 
213  while ( nLo <= nHi )
214  {
215  i = (nLo + nHi) / 2;
216 
217  if (mvData[i].nEndRow < nRow)
218  {
219  // If [nRow] greater, ignore left half
220  nLo = i + 1;
221  }
222  else if ((i > 0) && (mvData[i - 1].nEndRow >= nRow))
223  {
224  // If [nRow] is smaller, ignore right half
225  nHi = i - 1;
226  }
227  else
228  {
229  // found
230  nIndex=static_cast<SCSIZE>(i);
231  return true;
232  }
233  }
234 
235  nIndex=0;
236  return false;
237 }
238 
240 {
241  if ( mvData.empty() )
242  {
243  if ( !rDocument.ValidRow(nRow) )
244  return nullptr;
245  return rDocument.GetDefPattern();
246  }
247  SCSIZE i;
248  if (Search( nRow, i ))
249  return mvData[i].pPattern;
250  else
251  return nullptr;
252 }
253 
255  SCROW& rEndRow, SCROW nRow ) const
256 {
257  if ( mvData.empty() )
258  {
259  if ( !rDocument.ValidRow( nRow ) )
260  return nullptr;
261  rStartRow = 0;
262  rEndRow = rDocument.MaxRow();
263  return rDocument.GetDefPattern();
264  }
265  SCSIZE nIndex;
266  if ( Search( nRow, nIndex ) )
267  {
268  if ( nIndex > 0 )
269  rStartRow = mvData[nIndex-1].nEndRow + 1;
270  else
271  rStartRow = 0;
272  rEndRow = mvData[nIndex].nEndRow;
273  return mvData[nIndex].pPattern;
274  }
275  return nullptr;
276 }
277 
278 void ScAttrArray::AddCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex )
279 {
280  if(!rDocument.ValidRow(nStartRow) || !rDocument.ValidRow(nEndRow))
281  return;
282 
283  if(nEndRow < nStartRow)
284  return;
285 
286  SCROW nTempStartRow = nStartRow;
287  SCROW nTempEndRow = nEndRow;
288 
289  do
290  {
291  const ScPatternAttr* pPattern = GetPattern(nTempStartRow);
292 
293  std::unique_ptr<ScPatternAttr> pNewPattern;
294  if(pPattern)
295  {
296  pNewPattern.reset( new ScPatternAttr(*pPattern) );
297  SCROW nPatternStartRow;
298  SCROW nPatternEndRow;
299  GetPatternRange( nPatternStartRow, nPatternEndRow, nTempStartRow );
300 
301  nTempEndRow = std::min<SCROW>( nPatternEndRow, nEndRow );
302  const SfxPoolItem* pItem = nullptr;
303  pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, &pItem );
304  if(pItem)
305  {
306  ScCondFormatIndexes const & rCondFormatData = static_cast<const ScCondFormatItem*>(pItem)->GetCondFormatData();
307  if (rCondFormatData.find(nIndex) == rCondFormatData.end())
308  {
309  ScCondFormatIndexes aNewCondFormatData;
310  aNewCondFormatData.reserve(rCondFormatData.size()+1);
311  aNewCondFormatData = rCondFormatData;
312  aNewCondFormatData.insert(nIndex);
313  ScCondFormatItem aItem( std::move(aNewCondFormatData) );
314  pNewPattern->GetItemSet().Put( aItem );
315  }
316  }
317  else
318  {
319  ScCondFormatItem aItem(nIndex);
320  pNewPattern->GetItemSet().Put( aItem );
321  }
322  }
323  else
324  {
325  pNewPattern.reset( new ScPatternAttr( rDocument.GetPool() ) );
326  ScCondFormatItem aItem(nIndex);
327  pNewPattern->GetItemSet().Put( aItem );
328  nTempEndRow = nEndRow;
329  }
330 
331  SetPatternArea( nTempStartRow, nTempEndRow, std::move(pNewPattern), true );
332  nTempStartRow = nTempEndRow + 1;
333  }
334  while(nTempEndRow < nEndRow);
335 
336 }
337 
338 void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex )
339 {
340  if(!rDocument.ValidRow(nStartRow) || !rDocument.ValidRow(nEndRow))
341  return;
342 
343  if(nEndRow < nStartRow)
344  return;
345 
346  SCROW nTempStartRow = nStartRow;
347  SCROW nTempEndRow = nEndRow;
348 
349  do
350  {
351  const ScPatternAttr* pPattern = GetPattern(nTempStartRow);
352 
353  if(pPattern)
354  {
355  SCROW nPatternStartRow;
356  SCROW nPatternEndRow;
357  GetPatternRange( nPatternStartRow, nPatternEndRow, nTempStartRow );
358 
359  nTempEndRow = std::min<SCROW>( nPatternEndRow, nEndRow );
360  const SfxPoolItem* pItem = nullptr;
361  pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, &pItem );
362  if(pItem)
363  {
364  auto pPatternAttr = std::make_unique<ScPatternAttr>( *pPattern );
365  if (nIndex == 0)
366  {
367  ScCondFormatItem aItem;
368  pPatternAttr->GetItemSet().Put( aItem );
369  SetPatternArea( nTempStartRow, nTempEndRow, std::move(pPatternAttr), true );
370  }
371  else
372  {
373  ScCondFormatIndexes const & rCondFormatData = static_cast<const ScCondFormatItem*>(pItem)->GetCondFormatData();
374  auto itr = rCondFormatData.find(nIndex);
375  if(itr != rCondFormatData.end())
376  {
377  ScCondFormatIndexes aNewCondFormatData(rCondFormatData);
378  aNewCondFormatData.erase_at(std::distance(rCondFormatData.begin(), itr));
379  ScCondFormatItem aItem( std::move(aNewCondFormatData) );
380  pPatternAttr->GetItemSet().Put( aItem );
381  SetPatternArea( nTempStartRow, nTempEndRow, std::move(pPatternAttr), true );
382  }
383  }
384  }
385  }
386  else
387  {
388  return;
389  }
390 
391  nTempStartRow = nTempEndRow + 1;
392  }
393  while(nTempEndRow < nEndRow);
394 
395 }
396 
398  const ScPatternAttr* pPattern, ScEditDataArray* pDataArray )
399 {
400  assert( nCol != -1 );
401  // cache mdds position, this doesn't modify the mdds container, just EditTextObject's
402  sc::ColumnBlockPosition blockPos;
404  for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
405  {
406  ScAddress aPos(nCol, nRow, nTab);
407  ScRefCellValue aCell(rDocument, aPos, blockPos);
408  if (aCell.meType != CELLTYPE_EDIT || !aCell.mpEditText)
409  continue;
410 
411  std::unique_ptr<EditTextObject> pOldData;
412  if (pDataArray)
413  pOldData = aCell.mpEditText->Clone();
414 
415  // Direct modification of cell content - something to watch out for if
416  // we decide to share edit text instances in the future.
417  ScEditUtil::RemoveCharAttribs(const_cast<EditTextObject&>(*aCell.mpEditText), *pPattern);
418 
419  if (pDataArray)
420  {
421  std::unique_ptr<EditTextObject> pNewData = aCell.mpEditText->Clone();
422  pDataArray->AddItem(nTab, nCol, nRow, std::move(pOldData), std::move(pNewData));
423  }
424  }
425 }
426 
427 bool ScAttrArray::Reserve( SCSIZE nReserve )
428 {
429  if ( mvData.empty() && nReserve )
430  {
431  try {
432  mvData.reserve(nReserve);
433  mvData.emplace_back();
434  mvData[0].nEndRow = rDocument.MaxRow();
435  mvData[0].pPattern = rDocument.GetDefPattern(); // no put
436  return true;
437  } catch (std::bad_alloc const &) {
438  return false;
439  }
440  }
441  else if ( mvData.capacity() < nReserve )
442  {
443  try {
444  mvData.reserve(nReserve);
445  return true;
446  } catch (std::bad_alloc const &) {
447  return false;
448  }
449  }
450  else
451  return false;
452 }
453 
454 const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr* pPattern,
455  bool bPutToPool, ScEditDataArray* pDataArray, bool bPassingOwnership )
456 {
457  if (rDocument.ValidRow(nStartRow) && rDocument.ValidRow(nEndRow))
458  {
459  if (bPutToPool)
460  {
461  if (bPassingOwnership)
462  pPattern = &rDocument.GetPool()->Put(std::unique_ptr<ScPatternAttr>(const_cast<ScPatternAttr*>(pPattern)));
463  else
464  pPattern = &rDocument.GetPool()->Put(*pPattern);
465  }
466  if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
467  Reset(pPattern);
468  else
469  {
470  SCSIZE nNeeded = mvData.size() + 2;
471  SetDefaultIfNotInit( nNeeded );
472 
473  ScAddress aAdrStart( nCol, 0, nTab );
474  ScAddress aAdrEnd ( nCol, 0, nTab );
475 
476  SCSIZE ni = 0; // number of entries in beginning
477  SCSIZE nx = 0; // track position
478  SCROW ns = 0; // start row of track position
479  if ( nStartRow > 0 )
480  {
481  // skip beginning
482  SCSIZE nIndex;
483  Search( nStartRow, nIndex );
484  ni = nIndex;
485 
486  if ( ni > 0 )
487  {
488  nx = ni;
489  ns = mvData[ni-1].nEndRow+1;
490  }
491  }
492 
493  // ensure that attributing changes text width of cell
494  // otherwise, conditional formats need to be reset or deleted
495  bool bIsLoading = !rDocument.GetDocumentShell() || rDocument.GetDocumentShell()->IsLoading();
496  while ( ns <= nEndRow )
497  {
498  if ( nCol != -1 && !bIsLoading )
499  {
500  const SfxItemSet& rNewSet = pPattern->GetItemSet();
501  const SfxItemSet& rOldSet = mvData[nx].pPattern->GetItemSet();
502  bool bNumFormatChanged;
503  if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
504  rNewSet, rOldSet ) )
505  {
506  aAdrStart.SetRow( std::max(nStartRow,ns) );
507  aAdrEnd .SetRow( std::min(nEndRow,mvData[nx].nEndRow) );
508  rDocument.InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
509  }
510  }
511  ns = mvData[nx].nEndRow + 1;
512  nx++;
513  }
514 
515  // continue modifying data array
516 
517  SCSIZE nInsert; // insert position (MAXROWCOUNT := no insert)
518  bool bCombined = false;
519  bool bSplit = false;
520  if ( nStartRow > 0 )
521  {
522  nInsert = rDocument.MaxRow() + 1;
523  if ( mvData[ni].pPattern != pPattern )
524  {
525  if ( ni == 0 || (mvData[ni-1].nEndRow < nStartRow - 1) )
526  { // may be a split or a simple insert or just a shrink,
527  // row adjustment is done further down
528  if ( mvData[ni].nEndRow > nEndRow )
529  bSplit = true;
530  ni++;
531  nInsert = ni;
532  }
533  else if (mvData[ni - 1].nEndRow == nStartRow - 1)
534  nInsert = ni;
535  }
536  if ( ni > 0 && mvData[ni-1].pPattern == pPattern )
537  { // combine
538  mvData[ni-1].nEndRow = nEndRow;
539  nInsert = rDocument.MaxRow() + 1;
540  bCombined = true;
541  }
542  }
543  else
544  nInsert = 0;
545 
546  SCSIZE nj = ni; // stop position of range to replace
547  while ( nj < mvData.size() && mvData[nj].nEndRow <= nEndRow )
548  nj++;
549  if ( !bSplit )
550  {
551  if ( nj < mvData.size() && mvData[nj].pPattern == pPattern )
552  { // combine
553  if ( ni > 0 )
554  {
555  if ( mvData[ni-1].pPattern == pPattern )
556  { // adjacent entries
557  mvData[ni-1].nEndRow = mvData[nj].nEndRow;
558  nj++;
559  }
560  else if ( ni == nInsert )
561  mvData[ni-1].nEndRow = nStartRow - 1; // shrink
562  }
563  nInsert = rDocument.MaxRow() + 1;
564  bCombined = true;
565  }
566  else if ( ni > 0 && ni == nInsert )
567  mvData[ni-1].nEndRow = nStartRow - 1; // shrink
568  }
569  ScDocumentPool* pDocPool = rDocument.GetPool();
570  if ( bSplit )
571  { // duplicate split entry in pool
572  pDocPool->Put( *mvData[ni-1].pPattern );
573  }
574  if ( ni < nj )
575  { // remove middle entries
576  for ( SCSIZE nk=ni; nk<nj; nk++)
577  { // remove entries from pool
578  pDocPool->Remove( *mvData[nk].pPattern );
579  }
580  if ( !bCombined )
581  { // replace one entry
582  mvData[ni].nEndRow = nEndRow;
583  mvData[ni].pPattern = pPattern;
584  ni++;
585  nInsert = rDocument.MaxRow() + 1;
586  }
587  if ( ni < nj )
588  { // remove entries
589  mvData.erase( mvData.begin() + ni, mvData.begin() + nj);
590  }
591  }
592 
593  if ( nInsert < sal::static_int_cast<SCSIZE>(rDocument.MaxRow() + 1) )
594  { // insert or append new entry
595  if ( nInsert <= mvData.size() )
596  {
597  if ( !bSplit )
598  mvData.emplace(mvData.begin() + nInsert);
599  else
600  {
601  mvData.insert(mvData.begin() + nInsert, 2, ScAttrEntry());
602  mvData[nInsert+1] = mvData[nInsert-1];
603  }
604  }
605  if ( nInsert )
606  mvData[nInsert-1].nEndRow = nStartRow - 1;
607  mvData[nInsert].nEndRow = nEndRow;
608  mvData[nInsert].pPattern = pPattern;
609 
610  // Remove character attributes from these cells if the pattern
611  // is applied during normal session.
612  if (pDataArray && nCol != -1)
613  RemoveCellCharAttribs(nStartRow, nEndRow, pPattern, pDataArray);
614  }
615 
616  rDocument.SetStreamValid(nTab, false);
617  }
618  }
619 
620 #if DEBUG_SC_TESTATTRARRAY
621  TestData();
622 #endif
623  return pPattern;
624 }
625 
626 void ScAttrArray::ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle )
627 {
628  if (!(rDocument.ValidRow(nStartRow) && rDocument.ValidRow(nEndRow)))
629  return;
630 
632  SCSIZE nPos;
633  SCROW nStart=0;
634  if (!Search( nStartRow, nPos ))
635  {
636  OSL_FAIL("Search Failure");
637  return;
638  }
639 
640  ScAddress aAdrStart( nCol, 0, nTab );
641  ScAddress aAdrEnd ( nCol, 0, nTab );
642 
643  do
644  {
645  const ScPatternAttr* pOldPattern = mvData[nPos].pPattern;
646  std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr(*pOldPattern));
647  pNewPattern->SetStyleSheet(const_cast<ScStyleSheet*>(&rStyle));
648  SCROW nY1 = nStart;
649  SCROW nY2 = mvData[nPos].nEndRow;
650  nStart = mvData[nPos].nEndRow + 1;
651 
652  if ( *pNewPattern == *pOldPattern )
653  {
654  // keep the original pattern (might be default)
655  // pNewPattern is deleted below
656  nPos++;
657  }
658  else if ( nY1 < nStartRow || nY2 > nEndRow )
659  {
660  if (nY1 < nStartRow) nY1=nStartRow;
661  if (nY2 > nEndRow) nY2=nEndRow;
662  SetPatternArea( nY1, nY2, std::move(pNewPattern), true );
663  Search( nStart, nPos );
664  }
665  else
666  {
667  if ( nCol != -1 )
668  {
669  // ensure attributing changes text width of cell; otherwise
670  // there aren't (yet) template format changes
671  const SfxItemSet& rNewSet = pNewPattern->GetItemSet();
672  const SfxItemSet& rOldSet = pOldPattern->GetItemSet();
673 
674  bool bNumFormatChanged;
675  if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
676  rNewSet, rOldSet ) )
677  {
678  aAdrStart.SetRow( nPos ? mvData[nPos-1].nEndRow+1 : 0 );
679  aAdrEnd .SetRow( mvData[nPos].nEndRow );
680  rDocument.InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
681  }
682  }
683 
684  rDocument.GetPool()->Remove(*mvData[nPos].pPattern);
685  mvData[nPos].pPattern = &rDocument.GetPool()->Put(*pNewPattern);
686  if (Concat(nPos))
687  Search(nStart, nPos);
688  else
689  nPos++;
690  }
691  }
692  while ((nStart <= nEndRow) && (nPos < mvData.size()));
693 
694  rDocument.SetStreamValid(nTab, false);
695 
696 #if DEBUG_SC_TESTATTRARRAY
697  TestData();
698 #endif
699 }
700 
701  // const cast, otherwise it will be too inefficient/complicated
702 static void SetLineColor(SvxBorderLine const * dest, Color c)
703 {
704  if (dest)
705  {
706  const_cast<SvxBorderLine*>(dest)->SetColor(c);
707  }
708 }
709 
710 static void SetLine(const SvxBorderLine* dest, const SvxBorderLine* src)
711 {
712  if (dest)
713  {
714  SvxBorderLine* pCast = const_cast<SvxBorderLine*>(dest);
715  pCast->SetBorderLineStyle( src->GetBorderLineStyle() );
716  pCast->SetWidth( src->GetWidth() );
717  }
718 }
719 
720 void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow,
721  const SvxBorderLine* pLine, bool bColorOnly )
722 {
723  if ( bColorOnly && !pLine )
724  return;
725 
726  if (!(rDocument.ValidRow(nStartRow) && rDocument.ValidRow(nEndRow)))
727  return;
728 
729  SCSIZE nPos;
730  SCROW nStart=0;
732  if (!Search( nStartRow, nPos ))
733  {
734  OSL_FAIL("Search failure");
735  return;
736  }
737 
738  do
739  {
740  const ScPatternAttr* pOldPattern = mvData[nPos].pPattern;
741  const SfxItemSet& rOldSet = pOldPattern->GetItemSet();
742  const SfxPoolItem* pBoxItem = nullptr;
743  SfxItemState eState = rOldSet.GetItemState( ATTR_BORDER, true, &pBoxItem );
744  const SfxPoolItem* pTLBRItem = nullptr;
745  SfxItemState eTLBRState = rOldSet.GetItemState( ATTR_BORDER_TLBR, true, &pTLBRItem );
746  const SfxPoolItem* pBLTRItem = nullptr;
747  SfxItemState eBLTRState = rOldSet.GetItemState( ATTR_BORDER_BLTR, true, &pBLTRItem );
748 
749  if ( (SfxItemState::SET == eState) || (SfxItemState::SET == eTLBRState) || (SfxItemState::SET == eBLTRState) )
750  {
751  std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr(*pOldPattern));
752  SfxItemSet& rNewSet = pNewPattern->GetItemSet();
753  SCROW nY1 = nStart;
754  SCROW nY2 = mvData[nPos].nEndRow;
755 
756  std::unique_ptr<SvxBoxItem> pNewBoxItem( pBoxItem ? static_cast<SvxBoxItem*>(pBoxItem->Clone()) : nullptr);
757  std::unique_ptr<SvxLineItem> pNewTLBRItem( pTLBRItem ? static_cast<SvxLineItem*>(pTLBRItem->Clone()) : nullptr);
758  std::unique_ptr<SvxLineItem> pNewBLTRItem(pBLTRItem ? static_cast<SvxLineItem*>(pBLTRItem->Clone()) : nullptr);
759 
760  // fetch line and update attributes with parameters
761 
762  if ( !pLine )
763  {
764  if( pNewBoxItem )
765  {
766  if ( pNewBoxItem->GetTop() ) pNewBoxItem->SetLine( nullptr, SvxBoxItemLine::TOP );
767  if ( pNewBoxItem->GetBottom() ) pNewBoxItem->SetLine( nullptr, SvxBoxItemLine::BOTTOM );
768  if ( pNewBoxItem->GetLeft() ) pNewBoxItem->SetLine( nullptr, SvxBoxItemLine::LEFT );
769  if ( pNewBoxItem->GetRight() ) pNewBoxItem->SetLine( nullptr, SvxBoxItemLine::RIGHT );
770  }
771  if( pNewTLBRItem && pNewTLBRItem->GetLine() )
772  pNewTLBRItem->SetLine( nullptr );
773  if( pNewBLTRItem && pNewBLTRItem->GetLine() )
774  pNewBLTRItem->SetLine( nullptr );
775  }
776  else
777  {
778  if ( bColorOnly )
779  {
780  Color aColor( pLine->GetColor() );
781  if( pNewBoxItem )
782  {
783  SetLineColor( pNewBoxItem->GetTop(), aColor );
784  SetLineColor( pNewBoxItem->GetBottom(), aColor );
785  SetLineColor( pNewBoxItem->GetLeft(), aColor );
786  SetLineColor( pNewBoxItem->GetRight(), aColor );
787  }
788  if( pNewTLBRItem )
789  SetLineColor( pNewTLBRItem->GetLine(), aColor );
790  if( pNewBLTRItem )
791  SetLineColor( pNewBLTRItem->GetLine(), aColor );
792  }
793  else
794  {
795  if( pNewBoxItem )
796  {
797  SetLine( pNewBoxItem->GetTop(), pLine );
798  SetLine( pNewBoxItem->GetBottom(), pLine );
799  SetLine( pNewBoxItem->GetLeft(), pLine );
800  SetLine( pNewBoxItem->GetRight(), pLine );
801  }
802  if( pNewTLBRItem )
803  SetLine( pNewTLBRItem->GetLine(), pLine );
804  if( pNewBLTRItem )
805  SetLine( pNewBLTRItem->GetLine(), pLine );
806  }
807  }
808  if( pNewBoxItem ) rNewSet.Put( *pNewBoxItem );
809  if( pNewTLBRItem ) rNewSet.Put( *pNewTLBRItem );
810  if( pNewBLTRItem ) rNewSet.Put( *pNewBLTRItem );
811 
812  nStart = mvData[nPos].nEndRow + 1;
813 
814  if ( nY1 < nStartRow || nY2 > nEndRow )
815  {
816  if (nY1 < nStartRow) nY1=nStartRow;
817  if (nY2 > nEndRow) nY2=nEndRow;
818  SetPatternArea( nY1, nY2, std::move(pNewPattern), true );
819  Search( nStart, nPos );
820  }
821  else
822  {
823  // remove from pool ?
824  rDocument.GetPool()->Remove(*mvData[nPos].pPattern);
825  mvData[nPos].pPattern =
826  &rDocument.GetPool()->Put(std::move(pNewPattern));
827 
828  if (Concat(nPos))
829  Search(nStart, nPos);
830  else
831  nPos++;
832  }
833  }
834  else
835  {
836  nStart = mvData[nPos].nEndRow + 1;
837  nPos++;
838  }
839  }
840  while ((nStart <= nEndRow) && (nPos < mvData.size()));
841 }
842 
843 void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache* pCache, ScEditDataArray* pDataArray, bool* const pIsChanged )
844 {
845 #if DEBUG_SC_TESTATTRARRAY
846  TestData();
847 #endif
848 
849  if (!(rDocument.ValidRow(nStartRow) && rDocument.ValidRow(nEndRow)))
850  return;
851 
852  SCSIZE nPos;
853  SCROW nStart=0;
855  if (!Search( nStartRow, nPos ))
856  {
857  OSL_FAIL("Search Failure");
858  return;
859  }
860 
861  ScAddress aAdrStart( nCol, 0, nTab );
862  ScAddress aAdrEnd ( nCol, 0, nTab );
863 
864  do
865  {
866  const ScPatternAttr* pOldPattern = mvData[nPos].pPattern;
867  const ScPatternAttr* pNewPattern = static_cast<const ScPatternAttr*>( &pCache->ApplyTo( *pOldPattern ) );
868  if (pNewPattern != pOldPattern)
869  {
870  SCROW nY1 = nStart;
871  SCROW nY2 = mvData[nPos].nEndRow;
872  nStart = mvData[nPos].nEndRow + 1;
873 
874  if(pIsChanged)
875  *pIsChanged = true;
876 
877  if ( nY1 < nStartRow || nY2 > nEndRow )
878  {
879  if (nY1 < nStartRow) nY1=nStartRow;
880  if (nY2 > nEndRow) nY2=nEndRow;
881  SetPatternArea( nY1, nY2, pNewPattern, false, pDataArray );
882  Search( nStart, nPos );
883  }
884  else
885  {
886  if ( nCol != -1 )
887  {
888  // ensure attributing changes text-width of cell
889 
890  const SfxItemSet& rNewSet = pNewPattern->GetItemSet();
891  const SfxItemSet& rOldSet = pOldPattern->GetItemSet();
892 
893  bool bNumFormatChanged;
894  if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
895  rNewSet, rOldSet ) )
896  {
897  aAdrStart.SetRow( nPos ? mvData[nPos-1].nEndRow+1 : 0 );
898  aAdrEnd .SetRow( mvData[nPos].nEndRow );
899  rDocument.InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
900  }
901  }
902 
903  rDocument.GetPool()->Remove(*mvData[nPos].pPattern);
904  mvData[nPos].pPattern = pNewPattern;
905  if (Concat(nPos))
906  Search(nStart, nPos);
907  else
908  ++nPos;
909  }
910  }
911  else
912  {
913  nStart = mvData[nPos].nEndRow + 1;
914  ++nPos;
915  }
916  }
917  while (nStart <= nEndRow);
918 
919  rDocument.SetStreamValid(nTab, false);
920 
921 #if DEBUG_SC_TESTATTRARRAY
922  TestData();
923 #endif
924 }
925 
926 void ScAttrArray::SetAttrEntries(std::vector<ScAttrEntry> && vNewData)
927 {
928  ScDocumentPool* pDocPool = rDocument.GetPool();
929  for (auto const & rEntry : mvData)
930  pDocPool->Remove(*rEntry.pPattern);
931 
932  mvData = std::move(vNewData);
933 }
934 
935 static void lcl_MergeDeep( SfxItemSet& rMergeSet, const SfxItemSet& rSource )
936 {
937  const SfxPoolItem* pNewItem;
938  const SfxPoolItem* pOldItem;
939  for (sal_uInt16 nId=ATTR_PATTERN_START; nId<=ATTR_PATTERN_END; nId++)
940  {
941  // pMergeSet has no parent
942  SfxItemState eOldState = rMergeSet.GetItemState( nId, false, &pOldItem );
943 
944  if ( eOldState == SfxItemState::DEFAULT )
945  {
946  SfxItemState eNewState = rSource.GetItemState( nId, true, &pNewItem );
947  if ( eNewState == SfxItemState::SET )
948  {
949  if ( *pNewItem != rMergeSet.GetPool()->GetDefaultItem(nId) )
950  rMergeSet.InvalidateItem( nId );
951  }
952  }
953  else if ( eOldState == SfxItemState::SET ) // Item set
954  {
955  SfxItemState eNewState = rSource.GetItemState( nId, true, &pNewItem );
956  if ( eNewState == SfxItemState::SET )
957  {
958  if ( pNewItem != pOldItem ) // Both pulled
959  rMergeSet.InvalidateItem( nId );
960  }
961  else // Default
962  {
963  if ( *pOldItem != rSource.GetPool()->GetDefaultItem(nId) )
964  rMergeSet.InvalidateItem( nId );
965  }
966  }
967  // Dontcare remains Dontcare
968  }
969 }
970 
971 void ScAttrArray::MergePatternArea( SCROW nStartRow, SCROW nEndRow,
972  ScMergePatternState& rState, bool bDeep ) const
973 {
974  if (!(rDocument.ValidRow(nStartRow) && rDocument.ValidRow(nEndRow)))
975  return;
976 
977  SCSIZE nPos = 0;
978  SCROW nStart=0;
979  if ( !mvData.empty() && !Search( nStartRow, nPos ) )
980  {
981  OSL_FAIL("Search failure");
982  return;
983  }
984 
985  do
986  {
987  // similar patterns must not be repeated
988  const ScPatternAttr* pPattern = nullptr;
989  if ( !mvData.empty() )
990  pPattern = mvData[nPos].pPattern;
991  else
992  pPattern = rDocument.GetDefPattern();
993  if ( pPattern != rState.pOld1 && pPattern != rState.pOld2 )
994  {
995  const SfxItemSet& rThisSet = pPattern->GetItemSet();
996  if (rState.pItemSet)
997  {
998  rState.mbValidPatternId = false;
999  if (bDeep)
1000  lcl_MergeDeep( *rState.pItemSet, rThisSet );
1001  else
1002  rState.pItemSet->MergeValues( rThisSet );
1003  }
1004  else
1005  {
1006  // first pattern - copied from parent
1007  rState.pItemSet.emplace( *rThisSet.GetPool(), rThisSet.GetRanges() );
1008  rState.pItemSet->Set( rThisSet, bDeep );
1009  rState.mnPatternId = pPattern->GetKey();
1010  }
1011 
1012  rState.pOld2 = rState.pOld1;
1013  rState.pOld1 = pPattern;
1014  }
1015 
1016  if ( !mvData.empty() )
1017  nStart = mvData[nPos].nEndRow + 1;
1018  else
1019  nStart = rDocument.MaxRow() + 1;
1020  ++nPos;
1021  }
1022  while (nStart <= nEndRow);
1023 }
1024 
1025 // assemble border
1026 
1027 static bool lcl_TestAttr( const SvxBorderLine* pOldLine, const SvxBorderLine* pNewLine,
1028  sal_uInt8& rModified, const SvxBorderLine*& rpNew )
1029 {
1030  if (rModified == SC_LINE_DONTCARE)
1031  return false; // don't go again
1032 
1033  if (rModified == SC_LINE_EMPTY)
1034  {
1035  rModified = SC_LINE_SET;
1036  rpNew = pNewLine;
1037  return true; // initial value
1038  }
1039 
1040  if (pOldLine == pNewLine)
1041  {
1042  rpNew = pOldLine;
1043  return false;
1044  }
1045 
1046  if (pOldLine && pNewLine)
1047  if (*pOldLine == *pNewLine)
1048  {
1049  rpNew = pOldLine;
1050  return false;
1051  }
1052 
1053  rModified = SC_LINE_DONTCARE;
1054  rpNew = nullptr;
1055  return true; // another line -> don't care
1056 }
1057 
1058 static void lcl_MergeToFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner,
1059  ScLineFlags& rFlags, const ScPatternAttr* pPattern,
1060  bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom )
1061 {
1062  // right/bottom border set when connected together
1063  const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE);
1064  if ( rMerge.GetColMerge() == nDistRight + 1 )
1065  nDistRight = 0;
1066  if ( rMerge.GetRowMerge() == nDistBottom + 1 )
1067  nDistBottom = 0;
1068 
1069  const SvxBoxItem* pCellFrame = &pPattern->GetItemSet().Get( ATTR_BORDER );
1070  const SvxBorderLine* pLeftAttr = pCellFrame->GetLeft();
1071  const SvxBorderLine* pRightAttr = pCellFrame->GetRight();
1072  const SvxBorderLine* pTopAttr = pCellFrame->GetTop();
1073  const SvxBorderLine* pBottomAttr = pCellFrame->GetBottom();
1074  const SvxBorderLine* pNew;
1075 
1076  if (bTop)
1077  {
1078  if (lcl_TestAttr( pLineOuter->GetTop(), pTopAttr, rFlags.nTop, pNew ))
1079  pLineOuter->SetLine( pNew, SvxBoxItemLine::TOP );
1080  }
1081  else
1082  {
1083  if (lcl_TestAttr( pLineInner->GetHori(), pTopAttr, rFlags.nHori, pNew ))
1084  pLineInner->SetLine( pNew, SvxBoxInfoItemLine::HORI );
1085  }
1086 
1087  if (nDistBottom == 0)
1088  {
1089  if (lcl_TestAttr( pLineOuter->GetBottom(), pBottomAttr, rFlags.nBottom, pNew ))
1090  pLineOuter->SetLine( pNew, SvxBoxItemLine::BOTTOM );
1091  }
1092  else
1093  {
1094  if (lcl_TestAttr( pLineInner->GetHori(), pBottomAttr, rFlags.nHori, pNew ))
1095  pLineInner->SetLine( pNew, SvxBoxInfoItemLine::HORI );
1096  }
1097 
1098  if (bLeft)
1099  {
1100  if (lcl_TestAttr( pLineOuter->GetLeft(), pLeftAttr, rFlags.nLeft, pNew ))
1101  pLineOuter->SetLine( pNew, SvxBoxItemLine::LEFT );
1102  }
1103  else
1104  {
1105  if (lcl_TestAttr( pLineInner->GetVert(), pLeftAttr, rFlags.nVert, pNew ))
1106  pLineInner->SetLine( pNew, SvxBoxInfoItemLine::VERT );
1107  }
1108 
1109  if (nDistRight == 0)
1110  {
1111  if (lcl_TestAttr( pLineOuter->GetRight(), pRightAttr, rFlags.nRight, pNew ))
1112  pLineOuter->SetLine( pNew, SvxBoxItemLine::RIGHT );
1113  }
1114  else
1115  {
1116  if (lcl_TestAttr( pLineInner->GetVert(), pRightAttr, rFlags.nVert, pNew ))
1117  pLineInner->SetLine( pNew, SvxBoxInfoItemLine::VERT );
1118  }
1119 }
1120 
1122  ScLineFlags& rFlags,
1123  SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight ) const
1124 {
1125  const ScPatternAttr* pPattern;
1126 
1127  if (nStartRow == nEndRow)
1128  {
1129  pPattern = GetPattern( nStartRow );
1130  lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, pPattern, bLeft, nDistRight, true, 0 );
1131  }
1132  else if ( !mvData.empty() ) // non-default pattern
1133  {
1134  pPattern = GetPattern( nStartRow );
1135  lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, pPattern, bLeft, nDistRight, true,
1136  nEndRow-nStartRow );
1137 
1138  SCSIZE nStartIndex;
1139  SCSIZE nEndIndex;
1140  Search( nStartRow+1, nStartIndex );
1141  Search( nEndRow-1, nEndIndex );
1142  for (SCSIZE i=nStartIndex; i<=nEndIndex; i++)
1143  {
1144  pPattern = mvData[i].pPattern;
1145  lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, pPattern, bLeft, nDistRight, false,
1146  nEndRow - std::min( mvData[i].nEndRow, static_cast<SCROW>(nEndRow-1) ) );
1147  // nDistBottom here always > 0
1148  }
1149 
1150  pPattern = GetPattern( nEndRow );
1151  lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, pPattern, bLeft, nDistRight, false, 0 );
1152  }
1153  else
1154  {
1155  lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, rDocument.GetDefPattern(), bLeft, nDistRight, true, 0 );
1156  }
1157 }
1158 
1159 // apply border
1160 
1161 // ApplyFrame - on an entry into the array
1162 
1163 bool ScAttrArray::ApplyFrame( const SvxBoxItem* pBoxItem,
1164  const SvxBoxInfoItem* pBoxInfoItem,
1165  SCROW nStartRow, SCROW nEndRow,
1166  bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom )
1167 {
1168  OSL_ENSURE( pBoxItem && pBoxInfoItem, "Missing line attributes!" );
1169 
1170  const ScPatternAttr* pPattern = GetPattern( nStartRow );
1171  const SvxBoxItem* pOldFrame = &pPattern->GetItemSet().Get( ATTR_BORDER );
1172 
1173  // right/bottom border set when connected together
1174  const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE);
1175  if ( rMerge.GetColMerge() == nDistRight + 1 )
1176  nDistRight = 0;
1177  if ( rMerge.GetRowMerge() == nDistBottom + 1 )
1178  nDistBottom = 0;
1179 
1180  SvxBoxItem aNewFrame( *pOldFrame );
1181  bool bRTL=rDocument.IsLayoutRTL(nTab);
1182  // fdo#37464 check if the sheet are RTL then replace right <=> left
1183  if (bRTL)
1184  {
1185  if( bLeft && nDistRight==0)
1186  {
1187  if ( pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::LEFT) )
1188  aNewFrame.SetLine( pBoxItem->GetLeft(), SvxBoxItemLine::RIGHT );
1189  if ( pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::RIGHT) )
1190  aNewFrame.SetLine( pBoxItem->GetRight(), SvxBoxItemLine::LEFT );
1191  }
1192  else
1193  {
1194  if ( (nDistRight==0) ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::LEFT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) )
1195  aNewFrame.SetLine( (nDistRight==0) ? pBoxItem->GetLeft() : pBoxInfoItem->GetVert(),
1196  SvxBoxItemLine::RIGHT );
1197  if ( bLeft ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::RIGHT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) )
1198  aNewFrame.SetLine( bLeft ? pBoxItem->GetRight() : pBoxInfoItem->GetVert(),
1199  SvxBoxItemLine::LEFT );
1200  }
1201  }
1202  else
1203  {
1204  if ( bLeft ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::LEFT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) )
1205  aNewFrame.SetLine( bLeft ? pBoxItem->GetLeft() : pBoxInfoItem->GetVert(),
1206  SvxBoxItemLine::LEFT );
1207  if ( (nDistRight==0) ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::RIGHT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) )
1208  aNewFrame.SetLine( (nDistRight==0) ? pBoxItem->GetRight() : pBoxInfoItem->GetVert(),
1209  SvxBoxItemLine::RIGHT );
1210  }
1211  if ( bTop ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::TOP) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::HORI) )
1212  aNewFrame.SetLine( bTop ? pBoxItem->GetTop() : pBoxInfoItem->GetHori(),
1213  SvxBoxItemLine::TOP );
1214  if ( (nDistBottom==0) ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::BOTTOM) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::HORI) )
1215  aNewFrame.SetLine( (nDistBottom==0) ? pBoxItem->GetBottom() : pBoxInfoItem->GetHori(),
1216  SvxBoxItemLine::BOTTOM );
1217 
1218  if (aNewFrame == *pOldFrame)
1219  {
1220  // nothing to do
1221  return false;
1222  }
1223  else
1224  {
1225  SfxItemPoolCache aCache( rDocument.GetPool(), &aNewFrame );
1226  ApplyCacheArea( nStartRow, nEndRow, &aCache );
1227 
1228  return true;
1229  }
1230 }
1231 
1232 void ScAttrArray::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
1233  SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight)
1234 {
1235  if (nStartRow == nEndRow)
1236  ApplyFrame(&rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0);
1237  else if ( !mvData.empty() )
1238  {
1239  ApplyFrame(&rLineOuter, pLineInner, nStartRow, nStartRow, bLeft, nDistRight,
1240  true, nEndRow-nStartRow);
1241 
1242  if ( nEndRow > nStartRow+1 ) // inner part available?
1243  {
1244  SCSIZE nStartIndex;
1245  SCSIZE nEndIndex;
1246  Search( nStartRow+1, nStartIndex );
1247  Search( nEndRow-1, nEndIndex );
1248  SCROW nTmpStart = nStartRow+1;
1249  SCROW nTmpEnd;
1250  for (SCSIZE i=nStartIndex; i<=nEndIndex;)
1251  {
1252  nTmpEnd = std::min( static_cast<SCROW>(nEndRow-1), mvData[i].nEndRow );
1253  bool bChanged = ApplyFrame(&rLineOuter, pLineInner, nTmpStart, nTmpEnd,
1254  bLeft, nDistRight, false, nEndRow - nTmpEnd);
1255  nTmpStart = nTmpEnd+1;
1256  if (bChanged)
1257  {
1258  Search(nTmpStart, i);
1259  Search(nEndRow-1, nEndIndex);
1260  }
1261  else
1262  i++;
1263  }
1264  }
1265 
1266  ApplyFrame(&rLineOuter, pLineInner, nEndRow, nEndRow, bLeft, nDistRight, false, 0);
1267  }
1268  else
1269  {
1270  ApplyFrame(&rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0);
1271  }
1272 }
1273 
1274 bool ScAttrArray::HasAttrib_Impl(const ScPatternAttr* pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const
1275 {
1276  bool bFound = false;
1277  if ( nMask & HasAttrFlags::Merged )
1278  {
1279  const ScMergeAttr* pMerge = &pPattern->GetItem( ATTR_MERGE );
1280  if ( pMerge->GetColMerge() > 1 || pMerge->GetRowMerge() > 1 )
1281  bFound = true;
1282  }
1284  {
1285  const ScMergeFlagAttr* pMergeFlag = &pPattern->GetItem( ATTR_MERGE_FLAG );
1286  if ( (nMask & HasAttrFlags::Overlapped) && pMergeFlag->IsOverlapped() )
1287  bFound = true;
1288  if ( (nMask & HasAttrFlags::NotOverlapped) && !pMergeFlag->IsOverlapped() )
1289  bFound = true;
1290  if ( (nMask & HasAttrFlags::AutoFilter) && pMergeFlag->HasAutoFilter() )
1291  bFound = true;
1292  }
1293  if ( nMask & HasAttrFlags::Lines )
1294  {
1295  const SvxBoxItem* pBox = &pPattern->GetItem( ATTR_BORDER );
1296  if ( pBox->GetLeft() || pBox->GetRight() || pBox->GetTop() || pBox->GetBottom() )
1297  bFound = true;
1298  }
1299  if ( nMask & HasAttrFlags::Shadow )
1300  {
1301  const SvxShadowItem* pShadow = &pPattern->GetItem( ATTR_SHADOW );
1302  if ( pShadow->GetLocation() != SvxShadowLocation::NONE )
1303  bFound = true;
1304  }
1305  if ( nMask & HasAttrFlags::Conditional )
1306  {
1307  bool bContainsCondFormat = pPattern->GetItem( ATTR_CONDITIONAL ).GetCondFormatData().empty();
1308  if ( bContainsCondFormat )
1309  bFound = true;
1310  }
1311  if ( nMask & HasAttrFlags::Protected )
1312  {
1313  const ScProtectionAttr* pProtect = &pPattern->GetItem( ATTR_PROTECTION );
1314  bool bFoundTemp = false;
1315  if ( pProtect->GetProtection() || pProtect->GetHideCell() )
1316  bFoundTemp = true;
1317 
1318  bool bContainsCondFormat = !mvData.empty() &&
1319  !pPattern->GetItem( ATTR_CONDITIONAL ).GetCondFormatData().empty();
1320  if ( bContainsCondFormat && nCol != -1 ) // rDocument.GetCondResult() is valid only for real columns.
1321  {
1322  SCROW nRowStartCond = std::max<SCROW>( nRow1, i ? mvData[i-1].nEndRow + 1: 0 );
1323  SCROW nRowEndCond = std::min<SCROW>( nRow2, mvData[i].nEndRow );
1324  bool bFoundCond = false;
1325  for(SCROW nRowCond = nRowStartCond; nRowCond <= nRowEndCond && !bFoundCond; ++nRowCond)
1326  {
1327  const SfxItemSet* pSet = rDocument.GetCondResult( nCol, nRowCond, nTab );
1328 
1329  const SfxPoolItem* pItem;
1330  if( pSet && pSet->GetItemState( ATTR_PROTECTION, true, &pItem ) == SfxItemState::SET )
1331  {
1332  const ScProtectionAttr* pCondProtect = static_cast<const ScProtectionAttr*>(pItem);
1333  if( pCondProtect->GetProtection() || pCondProtect->GetHideCell() )
1334  bFoundCond = true;
1335  else
1336  break;
1337  }
1338  else
1339  {
1340  // well it is not true that we found one
1341  // but existing one + cell where conditional
1342  // formatting does not remove it
1343  // => we should use the existing protection setting
1344  bFoundCond = bFoundTemp;
1345  }
1346  }
1347  bFoundTemp = bFoundCond;
1348  }
1349 
1350  if(bFoundTemp)
1351  bFound = true;
1352  }
1353  if ( nMask & HasAttrFlags::Rotate )
1354  {
1355  const ScRotateValueItem* pRotate = &pPattern->GetItem( ATTR_ROTATE_VALUE );
1356  // 90 or 270 degrees is former SvxOrientationItem - only look for other values
1357  // (see ScPatternAttr::GetCellOrientation)
1358  Degree100 nAngle = pRotate->GetValue();
1359  if ( nAngle && nAngle != 9000_deg100 && nAngle != 27000_deg100 )
1360  bFound = true;
1361  }
1362  if ( nMask & HasAttrFlags::NeedHeight )
1363  {
1364  if (pPattern->GetCellOrientation() != SvxCellOrientation::Standard)
1365  bFound = true;
1366  else if (pPattern->GetItem( ATTR_LINEBREAK ).GetValue())
1367  bFound = true;
1368  else if (pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue() == SvxCellHorJustify::Block)
1369  bFound = true;
1370 
1371  else if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty())
1372  bFound = true;
1373  else if (pPattern->GetItem( ATTR_ROTATE_VALUE ).GetValue())
1374  bFound = true;
1375  }
1377  {
1378  const SvxShadowItem* pShadow = &pPattern->GetItem( ATTR_SHADOW );
1379  SvxShadowLocation eLoc = pShadow->GetLocation();
1380  if ( nMask & HasAttrFlags::ShadowRight )
1381  if ( eLoc == SvxShadowLocation::TopRight || eLoc == SvxShadowLocation::BottomRight )
1382  bFound = true;
1383  if ( nMask & HasAttrFlags::ShadowDown )
1384  if ( eLoc == SvxShadowLocation::BottomLeft || eLoc == SvxShadowLocation::BottomRight )
1385  bFound = true;
1386  }
1387  if ( nMask & HasAttrFlags::RightOrCenter )
1388  {
1389  // called only if the sheet is LTR, so physical=logical alignment can be assumed
1390  SvxCellHorJustify eHorJust = pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue();
1391  if ( eHorJust == SvxCellHorJustify::Right || eHorJust == SvxCellHorJustify::Center )
1392  bFound = true;
1393  }
1394 
1395  return bFound;
1396 }
1397 
1398 // Test if field contains specific attribute
1399 bool ScAttrArray::HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) const
1400 {
1401  if (mvData.empty())
1402  {
1403  return HasAttrib_Impl(rDocument.GetDefPattern(), nMask, 0, rDocument.MaxRow(), 0);
1404  }
1405 
1406  SCSIZE nStartIndex;
1407  SCSIZE nEndIndex;
1408  Search( nRow1, nStartIndex );
1409  if (nRow1 != nRow2)
1410  Search( nRow2, nEndIndex );
1411  else
1412  nEndIndex = nStartIndex;
1413  bool bFound = false;
1414 
1415  for (SCSIZE i=nStartIndex; i<=nEndIndex && !bFound; i++)
1416  {
1417  const ScPatternAttr* pPattern = mvData[i].pPattern;
1418  bFound = HasAttrib_Impl(pPattern, nMask, nRow1, nRow2, i);
1419  }
1420 
1421  return bFound;
1422 }
1423 
1424 bool ScAttrArray::IsMerged( SCROW nRow ) const
1425 {
1426  if ( !mvData.empty() )
1427  {
1428  SCSIZE nIndex;
1429  Search(nRow, nIndex);
1430  const ScMergeAttr& rItem = mvData[nIndex].pPattern->GetItem(ATTR_MERGE);
1431 
1432  return rItem.IsMerged();
1433  }
1434 
1435  return rDocument.GetDefPattern()->GetItem(ATTR_MERGE).IsMerged();
1436 }
1437 
1441 bool ScAttrArray::ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
1442  SCCOL& rPaintCol, SCROW& rPaintRow,
1443  bool bRefresh )
1444 {
1445  assert( nCol != -1 );
1447  const ScPatternAttr* pPattern;
1448  const ScMergeAttr* pItem;
1449  SCSIZE nStartIndex;
1450  SCSIZE nEndIndex;
1451  Search( nStartRow, nStartIndex );
1452  Search( nEndRow, nEndIndex );
1453  bool bFound = false;
1454 
1455  for (SCSIZE i=nStartIndex; i<=nEndIndex; i++)
1456  {
1457  pPattern = mvData[i].pPattern;
1458  pItem = &pPattern->GetItem( ATTR_MERGE );
1459  SCCOL nCountX = pItem->GetColMerge();
1460  SCROW nCountY = pItem->GetRowMerge();
1461  if (nCountX>1 || nCountY>1)
1462  {
1463  SCROW nThisRow = (i>0) ? mvData[i-1].nEndRow+1 : 0;
1464  SCCOL nMergeEndCol = nThisCol + nCountX - 1;
1465  SCROW nMergeEndRow = nThisRow + nCountY - 1;
1466  if (nMergeEndCol > rPaintCol && nMergeEndCol <= rDocument.MaxCol())
1467  rPaintCol = nMergeEndCol;
1468  if (nMergeEndRow > rPaintRow && nMergeEndRow <= rDocument.MaxRow())
1469  rPaintRow = nMergeEndRow;
1470  bFound = true;
1471 
1472  if (bRefresh)
1473  {
1474  if ( nMergeEndCol > nThisCol )
1475  rDocument.ApplyFlagsTab( nThisCol+1, nThisRow, nMergeEndCol, mvData[i].nEndRow,
1476  nTab, ScMF::Hor );
1477  if ( nMergeEndRow > nThisRow )
1478  rDocument.ApplyFlagsTab( nThisCol, nThisRow+1, nThisCol, nMergeEndRow,
1479  nTab, ScMF::Ver );
1480  if ( nMergeEndCol > nThisCol && nMergeEndRow > nThisRow )
1481  rDocument.ApplyFlagsTab( nThisCol+1, nThisRow+1, nMergeEndCol, nMergeEndRow,
1482  nTab, ScMF::Hor | ScMF::Ver );
1483 
1484  Search( nThisRow, i ); // Data changed
1485  Search( nStartRow, nStartIndex );
1486  Search( nEndRow, nEndIndex );
1487  }
1488  }
1489  }
1490 
1491  return bFound;
1492 }
1493 
1494 void ScAttrArray::RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow)
1495 {
1496  assert( nCol != -1 );
1498  const ScPatternAttr* pPattern;
1499  const ScMergeAttr* pItem;
1500  SCSIZE nIndex;
1501 
1502  Search( nStartRow, nIndex );
1503  SCROW nThisStart = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
1504  if (nThisStart < nStartRow)
1505  nThisStart = nStartRow;
1506 
1507  while ( nThisStart <= nEndRow )
1508  {
1509  SCROW nThisEnd = mvData[nIndex].nEndRow;
1510  if (nThisEnd > nEndRow)
1511  nThisEnd = nEndRow;
1512 
1513  pPattern = mvData[nIndex].pPattern;
1514  pItem = &pPattern->GetItem( ATTR_MERGE );
1515  SCCOL nCountX = pItem->GetColMerge();
1516  SCROW nCountY = pItem->GetRowMerge();
1517  if (nCountX>1 || nCountY>1)
1518  {
1519  const ScMergeAttr* pAttr = &rDocument.GetPool()->GetDefaultItem( ATTR_MERGE );
1521 
1522  OSL_ENSURE( nCountY==1 || nThisStart==nThisEnd, "What's up?" );
1523 
1524  SCCOL nThisCol = nCol;
1525  SCCOL nMergeEndCol = nThisCol + nCountX - 1;
1526  SCROW nMergeEndRow = nThisEnd + nCountY - 1;
1527 
1528  // ApplyAttr for areas
1529  for (SCROW nThisRow = nThisStart; nThisRow <= nThisEnd; nThisRow++)
1530  rDocument.ApplyAttr( nThisCol, nThisRow, nTab, *pAttr );
1531 
1532  ScPatternAttr aNewPattern( rDocument.GetPool() );
1533  SfxItemSet* pSet = &aNewPattern.GetItemSet();
1534  pSet->Put( *pFlagAttr );
1535  rDocument.ApplyPatternAreaTab( nThisCol, nThisStart, nMergeEndCol, nMergeEndRow,
1536  nTab, aNewPattern );
1537 
1538  Search( nThisEnd, nIndex ); // data changed
1539  }
1540 
1541  ++nIndex;
1542  if ( nIndex < mvData.size() )
1543  nThisStart = mvData[nIndex-1].nEndRow+1;
1544  else
1545  nThisStart = rDocument.MaxRow()+1; // End
1546  }
1547 }
1548 
1550  const ScPatternAttr* pWantedPattern, bool bDefault )
1551 {
1553  const ScPatternAttr* pOldPattern;
1554  const ScMergeFlagAttr* pItem;
1555 
1556  SCSIZE nIndex;
1557  SCROW nRow;
1558  SCROW nThisRow;
1559  bool bFirstUse = true;
1560 
1561  Search( nStartRow, nIndex );
1562  nThisRow = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
1563  while ( nThisRow <= nEndRow )
1564  {
1565  pOldPattern = mvData[nIndex].pPattern;
1566  if (pOldPattern != pWantedPattern) // FIXME: else-branch?
1567  {
1568  if (nThisRow < nStartRow) nThisRow = nStartRow;
1569  nRow = mvData[nIndex].nEndRow;
1570  SCROW nAttrRow = std::min( nRow, nEndRow );
1571  pItem = &pOldPattern->GetItem( ATTR_MERGE_FLAG );
1572 
1573  if (pItem->IsOverlapped() || pItem->HasAutoFilter())
1574  {
1575  // default-constructing a ScPatternAttr for DeleteArea doesn't work
1576  // because it would have no cell style information.
1577  // Instead, the document's GetDefPattern is copied. Since it is passed as
1578  // pWantedPattern, no special treatment of default is needed here anymore.
1579  std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr( *pWantedPattern ));
1580  pNewPattern->GetItemSet().Put( *pItem );
1581  SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true );
1582  }
1583  else
1584  {
1585  if ( !bDefault )
1586  {
1587  if (bFirstUse)
1588  bFirstUse = false;
1589  else
1590  // it's in the pool
1591  rDocument.GetPool()->Put( *pWantedPattern );
1592  }
1593  SetPatternArea( nThisRow, nAttrRow, pWantedPattern );
1594  }
1595 
1596  Search( nThisRow, nIndex ); // data changed
1597  }
1598 
1599  ++nIndex;
1600  nThisRow = mvData[nIndex-1].nEndRow+1;
1601  }
1602 }
1603 
1604 bool ScAttrArray::ApplyFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags )
1605 {
1607  const ScPatternAttr* pOldPattern;
1608 
1609  ScMF nOldValue;
1610  SCSIZE nIndex;
1611  SCROW nRow;
1612  SCROW nThisRow;
1613  bool bChanged = false;
1614 
1615  Search( nStartRow, nIndex );
1616  nThisRow = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
1617  if (nThisRow < nStartRow) nThisRow = nStartRow;
1618 
1619  while ( nThisRow <= nEndRow )
1620  {
1621  pOldPattern = mvData[nIndex].pPattern;
1622  nOldValue = pOldPattern->GetItem( ATTR_MERGE_FLAG ).GetValue();
1623  if ( (nOldValue | nFlags) != nOldValue )
1624  {
1625  nRow = mvData[nIndex].nEndRow;
1626  SCROW nAttrRow = std::min( nRow, nEndRow );
1627  auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern);
1628  pNewPattern->GetItemSet().Put( ScMergeFlagAttr( nOldValue | nFlags ) );
1629  SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true );
1630  Search( nThisRow, nIndex ); // data changed
1631  bChanged = true;
1632  }
1633 
1634  ++nIndex;
1635  nThisRow = mvData[nIndex-1].nEndRow+1;
1636  }
1637 
1638  return bChanged;
1639 }
1640 
1641 bool ScAttrArray::RemoveFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags )
1642 {
1644  const ScPatternAttr* pOldPattern;
1645 
1646  ScMF nOldValue;
1647  SCSIZE nIndex;
1648  SCROW nRow;
1649  SCROW nThisRow;
1650  bool bChanged = false;
1651 
1652  Search( nStartRow, nIndex );
1653  nThisRow = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
1654  if (nThisRow < nStartRow) nThisRow = nStartRow;
1655 
1656  while ( nThisRow <= nEndRow )
1657  {
1658  pOldPattern = mvData[nIndex].pPattern;
1659  nOldValue = pOldPattern->GetItem( ATTR_MERGE_FLAG ).GetValue();
1660  if ( (nOldValue & ~nFlags) != nOldValue )
1661  {
1662  nRow = mvData[nIndex].nEndRow;
1663  SCROW nAttrRow = std::min( nRow, nEndRow );
1664  auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern);
1665  pNewPattern->GetItemSet().Put( ScMergeFlagAttr( nOldValue & ~nFlags ) );
1666  SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true );
1667  Search( nThisRow, nIndex ); // data changed
1668  bChanged = true;
1669  }
1670 
1671  ++nIndex;
1672  nThisRow = mvData[nIndex-1].nEndRow+1;
1673  }
1674 
1675  return bChanged;
1676 }
1677 
1678 void ScAttrArray::ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich )
1679 {
1681  SCSIZE nIndex;
1682  SCROW nRow;
1683  SCROW nThisRow;
1684 
1685  Search( nStartRow, nIndex );
1686  nThisRow = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
1687  if (nThisRow < nStartRow) nThisRow = nStartRow;
1688 
1689  while ( nThisRow <= nEndRow )
1690  {
1691  const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern;
1692  if ( pOldPattern->HasItemsSet( pWhich ) )
1693  {
1694  auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern);
1695  pNewPattern->ClearItems( pWhich );
1696 
1697  nRow = mvData[nIndex].nEndRow;
1698  SCROW nAttrRow = std::min( nRow, nEndRow );
1699  SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true );
1700  Search( nThisRow, nIndex ); // data changed
1701  }
1702 
1703  ++nIndex;
1704  nThisRow = mvData[nIndex-1].nEndRow+1;
1705  }
1706 }
1707 
1708 void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement )
1709 {
1711  SCSIZE nIndex;
1712  Search( nStartRow, nIndex );
1713  SCROW nThisStart = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
1714  if (nThisStart < nStartRow) nThisStart = nStartRow;
1715 
1716  while ( nThisStart <= nEndRow )
1717  {
1718  const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern;
1719  const SfxItemSet& rOldSet = pOldPattern->GetItemSet();
1720  const SfxPoolItem* pItem;
1721 
1722  bool bNeedJust = ( rOldSet.GetItemState( ATTR_HOR_JUSTIFY, false, &pItem ) != SfxItemState::SET
1723  || (static_cast<const SvxHorJustifyItem*>(pItem)->GetValue() != SvxCellHorJustify::Left &&
1724  static_cast<const SvxHorJustifyItem*>(pItem)->GetValue() != SvxCellHorJustify::Right ));
1725  sal_uInt16 nOldValue = rOldSet.Get( ATTR_INDENT ).GetValue();
1726  sal_uInt16 nNewValue = nOldValue;
1727  // To keep Increment indent from running outside the cell1659
1728  tools::Long nColWidth = static_cast<tools::Long>(rDocument.GetColWidth(nCol,nTab));
1729  if ( bIncrement )
1730  {
1731  if ( nNewValue < nColWidth-SC_INDENT_STEP )
1732  {
1733  nNewValue += SC_INDENT_STEP;
1734  if ( nNewValue > nColWidth-SC_INDENT_STEP ) nNewValue = nColWidth-SC_INDENT_STEP;
1735  }
1736  }
1737  else
1738  {
1739  if ( nNewValue > 0 )
1740  {
1741  if ( nNewValue > SC_INDENT_STEP )
1742  nNewValue -= SC_INDENT_STEP;
1743  else
1744  nNewValue = 0;
1745  }
1746  }
1747 
1748  if ( bNeedJust || nNewValue != nOldValue )
1749  {
1750  SCROW nThisEnd = mvData[nIndex].nEndRow;
1751  SCROW nAttrRow = std::min( nThisEnd, nEndRow );
1752  auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern);
1753  pNewPattern->GetItemSet().Put( ScIndentItem( nNewValue ) );
1754  if ( bNeedJust )
1755  pNewPattern->GetItemSet().Put(
1756  SvxHorJustifyItem( SvxCellHorJustify::Left, ATTR_HOR_JUSTIFY ) );
1757  SetPatternArea( nThisStart, nAttrRow, std::move(pNewPattern), true );
1758 
1759  nThisStart = nThisEnd + 1;
1760  Search( nThisStart, nIndex ); // data changed
1761  }
1762  else
1763  {
1764  nThisStart = mvData[nIndex].nEndRow + 1;
1765  ++nIndex;
1766  }
1767  }
1768 }
1769 
1771 {
1772  tools::Long nRet = nRow;
1773  if (rDocument.ValidRow(nRow))
1774  {
1775  if ( mvData.empty() )
1776  {
1777  if ( bUp )
1778  return -1;
1779  else
1780  return rDocument.MaxRow()+1;
1781  }
1782 
1783  SCSIZE nIndex;
1784  Search(nRow, nIndex);
1785  while (mvData[nIndex].pPattern->
1786  GetItem(ATTR_PROTECTION).GetProtection())
1787  {
1788  if (bUp)
1789  {
1790  if (nIndex==0)
1791  return -1; // not found
1792  --nIndex;
1793  nRet = mvData[nIndex].nEndRow;
1794  }
1795  else
1796  {
1797  nRet = mvData[nIndex].nEndRow+1;
1798  ++nIndex;
1799  if (nIndex >= mvData.size())
1800  return rDocument.MaxRow()+1; // not found
1801  }
1802  }
1803  }
1804  return nRet;
1805 }
1806 
1807 void ScAttrArray::FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset )
1808 {
1810  SCROW nStart = 0;
1811  SCSIZE nPos = 0;
1812  while (nPos < mvData.size())
1813  {
1814  SCROW nEnd = mvData[nPos].nEndRow;
1815  if (mvData[nPos].pPattern->GetStyleSheet() == pStyleSheet)
1816  {
1817  rUsedRows.setTrue(nStart, nEnd);
1818 
1819  if (bReset)
1820  {
1821  ScPatternAttr aNewPattern(*mvData[nPos].pPattern);
1822  rDocument.GetPool()->Remove(*mvData[nPos].pPattern);
1823  aNewPattern.SetStyleSheet( static_cast<ScStyleSheet*>(
1825  Find( ScResId(STR_STYLENAME_STANDARD),
1826  SfxStyleFamily::Para,
1827  SfxStyleSearchBits::Auto | SfxStyleSearchBits::ScStandard ) ) );
1828  mvData[nPos].pPattern = &rDocument.GetPool()->Put(aNewPattern);
1829 
1830  if (Concat(nPos))
1831  {
1832  Search(nStart, nPos);
1833  --nPos; // because ++ at end
1834  }
1835  }
1836  }
1837  nStart = nEnd + 1;
1838  ++nPos;
1839  }
1840 }
1841 
1842 bool ScAttrArray::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const
1843 {
1844  if ( mvData.empty() )
1845  {
1846  const ScStyleSheet* pStyle = rDocument.GetDefPattern()->GetStyleSheet();
1847  if ( pStyle )
1848  {
1850  if ( pStyle == &rStyle )
1851  return true;
1852  }
1853  return false;
1854  }
1855 
1856  bool bIsUsed = false;
1857  SCSIZE nPos = 0;
1858 
1859  while ( nPos < mvData.size() )
1860  {
1861  const ScStyleSheet* pStyle = mvData[nPos].pPattern->GetStyleSheet();
1862  if ( pStyle )
1863  {
1865  if ( pStyle == &rStyle )
1866  {
1867  bIsUsed = true;
1868  }
1869  }
1870  nPos++;
1871  }
1872 
1873  return bIsUsed;
1874 }
1875 
1877 {
1878  if ( mvData.empty() )
1879  return true;
1880 
1881  if (mvData.size() == 1)
1882  {
1883  return mvData[0].pPattern == rDocument.GetDefPattern();
1884  }
1885  else
1886  return false;
1887 }
1888 
1889 bool ScAttrArray::GetFirstVisibleAttr( SCROW& rFirstRow ) const
1890 {
1891  if ( mvData.empty() )
1892  return false;
1893 
1894  bool bFound = false;
1895  SCSIZE nStart = 0;
1896 
1897  // Skip first entry if more than 1 row.
1898  // Entries at the end are not skipped, GetFirstVisibleAttr may be larger than GetLastVisibleAttr.
1899 
1900  SCSIZE nVisStart = 1;
1901  while ( nVisStart < mvData.size() && mvData[nVisStart].pPattern->IsVisibleEqual(*mvData[nVisStart-1].pPattern) )
1902  ++nVisStart;
1903  if ( nVisStart >= mvData.size() || mvData[nVisStart-1].nEndRow > 0 ) // more than 1 row?
1904  nStart = nVisStart;
1905 
1906  while ( nStart < mvData.size() && !bFound )
1907  {
1908  if ( mvData[nStart].pPattern->IsVisible() )
1909  {
1910  rFirstRow = nStart ? ( mvData[nStart-1].nEndRow + 1 ) : 0;
1911  bFound = true;
1912  }
1913  else
1914  ++nStart;
1915  }
1916 
1917  return bFound;
1918 }
1919 
1920 // size (rows) of a range of attributes after cell content where the search is stopped
1921 // (more than a default page size, 2*42 because it's as good as any number)
1922 
1924 
1925 bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const
1926 {
1927  if ( mvData.empty() )
1928  {
1929  rLastRow = nLastData;
1930  return false;
1931  }
1932 
1933  // #i30830# changed behavior:
1934  // ignore all attributes starting with the first run of SC_VISATTR_STOP equal rows
1935  // below the last content cell
1936 
1937  if ( nLastData == rDocument.MaxRow() )
1938  {
1939  rLastRow = rDocument.MaxRow(); // can't look for attributes below rDocument.MaxRow()
1940  return true;
1941  }
1942 
1943  // Quick check: last data row in or immediately preceding a run that is the
1944  // last attribution down to the end, e.g. default style or column style.
1945  SCSIZE nPos = mvData.size() - 1;
1946  SCROW nStartRow = (nPos ? mvData[nPos-1].nEndRow + 1 : 0);
1947  if (nStartRow <= nLastData + 1)
1948  {
1949  // Ignore here a few rows if data happens to end within
1950  // SC_VISATTR_STOP rows before rDocument.MaxRow().
1951  rLastRow = nLastData;
1952  return false;
1953  }
1954 
1955  // Find a run below last data row.
1956  bool bFound = false;
1957  Search( nLastData, nPos );
1958  while ( nPos < mvData.size() )
1959  {
1960  // find range of visually equal formats
1961  SCSIZE nEndPos = nPos;
1962  while ( nEndPos < mvData.size()-1 &&
1963  mvData[nEndPos].pPattern->IsVisibleEqual( *mvData[nEndPos+1].pPattern))
1964  ++nEndPos;
1965  SCROW nAttrStartRow = ( nPos > 0 ) ? ( mvData[nPos-1].nEndRow + 1 ) : 0;
1966  if ( nAttrStartRow <= nLastData )
1967  nAttrStartRow = nLastData + 1;
1968  SCROW nAttrSize = mvData[nEndPos].nEndRow + 1 - nAttrStartRow;
1969  if ( nAttrSize >= SC_VISATTR_STOP )
1970  break; // while, ignore this range and below
1971  else if ( mvData[nEndPos].pPattern->IsVisible() )
1972  {
1973  rLastRow = mvData[nEndPos].nEndRow;
1974  bFound = true;
1975  }
1976  nPos = nEndPos + 1;
1977  }
1978 
1979  return bFound;
1980 }
1981 
1982 bool ScAttrArray::HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const
1983 {
1984  if ( mvData.empty() )
1985  return rDocument.GetDefPattern()->IsVisible();
1986 
1987  SCSIZE nIndex;
1988  Search( nStartRow, nIndex );
1989  SCROW nThisStart = nStartRow;
1990  bool bFound = false;
1991  while ( nIndex < mvData.size() && nThisStart <= nEndRow && !bFound )
1992  {
1993  if ( mvData[nIndex].pPattern->IsVisible() )
1994  bFound = true;
1995 
1996  nThisStart = mvData[nIndex].nEndRow + 1;
1997  ++nIndex;
1998  }
1999 
2000  return bFound;
2001 }
2002 
2004  SCROW nStartRow, SCROW nEndRow ) const
2005 {
2006  if ( mvData.empty() && rOther.mvData.empty() )
2007  {
2008  const ScPatternAttr* pDefPattern1 = rDocument.GetDefPattern();
2009  const ScPatternAttr* pDefPattern2 = rOther.rDocument.GetDefPattern();
2010  return ( pDefPattern1 == pDefPattern2 || pDefPattern1->IsVisibleEqual( *pDefPattern2 ) );
2011  }
2012 
2013  {
2014  const ScAttrArray* pNonDefault = nullptr;
2015  const ScPatternAttr* pDefPattern = nullptr;
2016  bool bDefNonDefCase = false;
2017  if ( mvData.empty() && !rOther.mvData.empty() )
2018  {
2019  pNonDefault = &rOther;
2020  pDefPattern = rDocument.GetDefPattern();
2021  bDefNonDefCase = true;
2022  }
2023  else if ( !mvData.empty() && rOther.mvData.empty() )
2024  {
2025  pNonDefault = this;
2026  pDefPattern = rOther.rDocument.GetDefPattern();
2027  bDefNonDefCase = true;
2028  }
2029 
2030  if ( bDefNonDefCase )
2031  {
2032  bool bEqual = true;
2033  SCSIZE nPos = 0;
2034  if ( nStartRow > 0 )
2035  pNonDefault->Search( nStartRow, nPos );
2036 
2037  while ( nPos < pNonDefault->Count() && bEqual )
2038  {
2039  const ScPatternAttr* pNonDefPattern = pNonDefault->mvData[nPos].pPattern;
2040  bEqual = ( pNonDefPattern == pDefPattern ||
2041  pNonDefPattern->IsVisibleEqual( *pDefPattern ) );
2042 
2043  if ( pNonDefault->mvData[nPos].nEndRow >= nEndRow ) break;
2044  ++nPos;
2045  }
2046  return bEqual;
2047  }
2048  }
2049 
2050  bool bEqual = true;
2051  SCSIZE nThisPos = 0;
2052  SCSIZE nOtherPos = 0;
2053  if ( nStartRow > 0 )
2054  {
2055  Search( nStartRow, nThisPos );
2056  rOther.Search( nStartRow, nOtherPos );
2057  }
2058 
2059  while ( nThisPos<mvData.size() && nOtherPos<rOther.Count() && bEqual )
2060  {
2061  SCROW nThisRow = mvData[nThisPos].nEndRow;
2062  SCROW nOtherRow = rOther.mvData[nOtherPos].nEndRow;
2063  const ScPatternAttr* pThisPattern = mvData[nThisPos].pPattern;
2064  const ScPatternAttr* pOtherPattern = rOther.mvData[nOtherPos].pPattern;
2065  bEqual = ( pThisPattern == pOtherPattern ||
2066  pThisPattern->IsVisibleEqual(*pOtherPattern) );
2067 
2068  if ( nThisRow >= nOtherRow )
2069  {
2070  if ( nOtherRow >= nEndRow ) break;
2071  ++nOtherPos;
2072  }
2073  if ( nThisRow <= nOtherRow )
2074  {
2075  if ( nThisRow >= nEndRow ) break;
2076  ++nThisPos;
2077  }
2078  }
2079 
2080  return bEqual;
2081 }
2082 
2083 bool ScAttrArray::IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const
2084 {
2085  // summarised with IsVisibleEqual
2086  if ( mvData.empty() && rOther.mvData.empty() )
2087  {
2088  const ScPatternAttr* pDefPattern1 = rDocument.GetDefPattern();
2089  const ScPatternAttr* pDefPattern2 = rOther.rDocument.GetDefPattern();
2090  return ( pDefPattern1 == pDefPattern2 );
2091  }
2092 
2093  {
2094  const ScAttrArray* pNonDefault = nullptr;
2095  const ScPatternAttr* pDefPattern = nullptr;
2096  bool bDefNonDefCase = false;
2097  if ( mvData.empty() && !rOther.mvData.empty() )
2098  {
2099  pNonDefault = &rOther;
2100  pDefPattern = rDocument.GetDefPattern();
2101  bDefNonDefCase = true;
2102  }
2103  else if ( !mvData.empty() && rOther.mvData.empty() )
2104  {
2105  pNonDefault = this;
2106  pDefPattern = rOther.rDocument.GetDefPattern();
2107  bDefNonDefCase = true;
2108  }
2109 
2110  if ( bDefNonDefCase )
2111  {
2112  bool bEqual = true;
2113  SCSIZE nPos = 0;
2114  if ( nStartRow > 0 )
2115  pNonDefault->Search( nStartRow, nPos );
2116 
2117  while ( nPos < pNonDefault->Count() && bEqual )
2118  {
2119  const ScPatternAttr* pNonDefPattern = pNonDefault->mvData[nPos].pPattern;
2120  bEqual = ( pNonDefPattern == pDefPattern );
2121 
2122  if ( pNonDefault->mvData[nPos].nEndRow >= nEndRow ) break;
2123  ++nPos;
2124  }
2125  return bEqual;
2126  }
2127  }
2128 
2129  bool bEqual = true;
2130  SCSIZE nThisPos = 0;
2131  SCSIZE nOtherPos = 0;
2132  if ( nStartRow > 0 )
2133  {
2134  Search( nStartRow, nThisPos );
2135  rOther.Search( nStartRow, nOtherPos );
2136  }
2137 
2138  while ( nThisPos<mvData.size() && nOtherPos<rOther.Count() && bEqual )
2139  {
2140  SCROW nThisRow = mvData[nThisPos].nEndRow;
2141  SCROW nOtherRow = rOther.mvData[nOtherPos].nEndRow;
2142  const ScPatternAttr* pThisPattern = mvData[nThisPos].pPattern;
2143  const ScPatternAttr* pOtherPattern = rOther.mvData[nOtherPos].pPattern;
2144  bEqual = ( pThisPattern == pOtherPattern );
2145 
2146  if ( nThisRow >= nOtherRow )
2147  {
2148  if ( nOtherRow >= nEndRow ) break;
2149  ++nOtherPos;
2150  }
2151  if ( nThisRow <= nOtherRow )
2152  {
2153  if ( nThisRow >= nEndRow ) break;
2154  ++nThisPos;
2155  }
2156  }
2157 
2158  return bEqual;
2159 }
2160 
2161 bool ScAttrArray::TestInsertCol( SCROW nStartRow, SCROW nEndRow) const
2162 {
2163  // Horizontal aggregate are not allowed to be moved out; if whole summary,
2164  // here is not recognized
2165 
2166  bool bTest = true;
2167  if (!IsEmpty())
2168  {
2169  SCSIZE nIndex = 0;
2170  if ( nStartRow > 0 )
2171  Search( nStartRow, nIndex );
2172 
2173  for ( ; nIndex < mvData.size(); nIndex++ )
2174  {
2175  if ( mvData[nIndex].pPattern->
2176  GetItem(ATTR_MERGE_FLAG).IsHorOverlapped() )
2177  {
2178  bTest = false; // may not be pushed out
2179  break;
2180  }
2181  if ( mvData[nIndex].nEndRow >= nEndRow ) // end of range
2182  break;
2183  }
2184  }
2185  return bTest;
2186 }
2187 
2189 {
2190  // if 1st row pushed out is vertically overlapped, summary would be broken
2191 
2192  // rDocument.MaxRow() + 1 - nSize = 1st row pushed out
2193 
2194  if ( mvData.empty() )
2195  return !rDocument.GetDefPattern()->
2196  GetItem(ATTR_MERGE_FLAG).IsVerOverlapped();
2197 
2198  SCSIZE nFirstLost = mvData.size()-1;
2199  while ( nFirstLost && mvData[nFirstLost-1].nEndRow >= sal::static_int_cast<SCROW>(rDocument.MaxRow() + 1 - nSize) )
2200  --nFirstLost;
2201 
2202  return !mvData[nFirstLost].pPattern->
2203  GetItem(ATTR_MERGE_FLAG).IsVerOverlapped();
2204 }
2205 
2206 void ScAttrArray::InsertRow( SCROW nStartRow, SCSIZE nSize )
2207 {
2209 
2210  SCROW nSearch = nStartRow > 0 ? nStartRow - 1 : 0; // expand predecessor
2211  SCSIZE nIndex;
2212  Search( nSearch, nIndex );
2213 
2214  // set ScMergeAttr may not be extended (so behind delete again)
2215 
2216  bool bDoMerge = mvData[nIndex].pPattern->GetItem(ATTR_MERGE).IsMerged();
2217 
2218  assert( !bDoMerge || nCol != -1 );
2219 
2220  SCSIZE nRemove = 0;
2221  SCSIZE i;
2222  for (i = nIndex; i < mvData.size()-1; i++)
2223  {
2224  SCROW nNew = mvData[i].nEndRow + nSize;
2225  if ( nNew >= rDocument.MaxRow() ) // at end?
2226  {
2227  nNew = rDocument.MaxRow();
2228  if (!nRemove)
2229  nRemove = i+1; // remove the following?
2230  }
2231  mvData[i].nEndRow = nNew;
2232  }
2233 
2234  // Remove entries at end ?
2235 
2236  if (nRemove && nRemove < mvData.size())
2237  DeleteRange( nRemove, mvData.size()-1 );
2238 
2239  if (bDoMerge) // extensively repair (again) ScMergeAttr
2240  {
2241  // ApplyAttr for areas
2242 
2244  for (SCSIZE nAdd=0; nAdd<nSize; nAdd++)
2245  rDocument.ApplyAttr( nCol, nStartRow+nAdd, nTab, rDef );
2246 
2247  // reply inserts in this area not summarized
2248  }
2249 
2250  // Don't duplicate the merge flags in the inserted row.
2251  // #i108488# ScMF::Scenario has to be allowed.
2252  RemoveFlags( nStartRow, nStartRow+nSize-1, ScMF::Hor | ScMF::Ver | ScMF::Auto | ScMF::Button );
2253 }
2254 
2255 void ScAttrArray::DeleteRow( SCROW nStartRow, SCSIZE nSize )
2256 {
2258  bool bFirst=true;
2259  SCSIZE nStartIndex = 0;
2260  SCSIZE nEndIndex = 0;
2261  SCSIZE i;
2262 
2263  for ( i = 0; i < mvData.size()-1; i++)
2264  if (mvData[i].nEndRow >= nStartRow && mvData[i].nEndRow <= sal::static_int_cast<SCROW>(nStartRow+nSize-1))
2265  {
2266  if (bFirst)
2267  {
2268  nStartIndex = i;
2269  bFirst = false;
2270  }
2271  nEndIndex = i;
2272  }
2273  if (!bFirst)
2274  {
2275  SCROW nStart;
2276  if (nStartIndex==0)
2277  nStart = 0;
2278  else
2279  nStart = mvData[nStartIndex-1].nEndRow + 1;
2280 
2281  if (nStart < nStartRow)
2282  {
2283  mvData[nStartIndex].nEndRow = nStartRow - 1;
2284  ++nStartIndex;
2285  }
2286  if (nEndIndex >= nStartIndex)
2287  {
2288  DeleteRange( nStartIndex, nEndIndex );
2289  if (nStartIndex > 0)
2290  if ( mvData[nStartIndex-1].pPattern == mvData[nStartIndex].pPattern )
2291  DeleteRange( nStartIndex-1, nStartIndex-1 );
2292  }
2293  }
2294  for (i = 0; i < mvData.size()-1; i++)
2295  if (mvData[i].nEndRow >= nStartRow)
2296  mvData[i].nEndRow -= nSize;
2297 
2298  // Below does not follow the pattern to detect pressure ranges;
2299  // instead, only remove merge flags.
2301 }
2302 
2303 void ScAttrArray::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex )
2304 {
2306  ScDocumentPool* pDocPool = rDocument.GetPool();
2307  for (SCSIZE i = nStartIndex; i <= nEndIndex; i++)
2308  pDocPool->Remove(*mvData[i].pPattern);
2309 
2310  mvData.erase(mvData.begin() + nStartIndex, mvData.begin() + nEndIndex + 1);
2311 }
2312 
2313 void ScAttrArray::DeleteArea(SCROW nStartRow, SCROW nEndRow)
2314 {
2316  if ( nCol != -1 )
2317  RemoveAreaMerge( nStartRow, nEndRow ); // remove from combined flags
2318 
2319  if ( !HasAttrib( nStartRow, nEndRow, HasAttrFlags::Overlapped | HasAttrFlags::AutoFilter) )
2320  SetPatternArea( nStartRow, nEndRow, rDocument.GetDefPattern() );
2321  else
2322  SetPatternAreaSafe( nStartRow, nEndRow, rDocument.GetDefPattern(), true ); // leave merge flags
2323 }
2324 
2325 void ScAttrArray::DeleteHardAttr(SCROW nStartRow, SCROW nEndRow)
2326 {
2328  const ScPatternAttr* pDefPattern = rDocument.GetDefPattern();
2329 
2330  SCSIZE nIndex;
2331  SCROW nRow;
2332  SCROW nThisRow;
2333 
2334  Search( nStartRow, nIndex );
2335  nThisRow = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0;
2336  if (nThisRow < nStartRow) nThisRow = nStartRow;
2337 
2338  while ( nThisRow <= nEndRow )
2339  {
2340  const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern;
2341 
2342  if ( pOldPattern->GetItemSet().Count() ) // hard attributes ?
2343  {
2344  nRow = mvData[nIndex].nEndRow;
2345  SCROW nAttrRow = std::min( nRow, nEndRow );
2346 
2347  auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern);
2348  SfxItemSet& rSet = pNewPattern->GetItemSet();
2349  for (sal_uInt16 nId = ATTR_PATTERN_START; nId <= ATTR_PATTERN_END; nId++)
2350  if (nId != ATTR_MERGE && nId != ATTR_MERGE_FLAG)
2351  rSet.ClearItem(nId);
2352 
2353  if ( *pNewPattern == *pDefPattern )
2354  SetPatternArea( nThisRow, nAttrRow, pDefPattern );
2355  else
2356  SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true );
2357 
2358  Search( nThisRow, nIndex ); // data changed
2359  }
2360 
2361  ++nIndex;
2362  nThisRow = mvData[nIndex-1].nEndRow+1;
2363  }
2364 }
2365 
2369 void ScAttrArray::MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray)
2370 {
2372  SCROW nStart = nStartRow;
2373  for (SCSIZE i = 0; i < mvData.size(); i++)
2374  {
2375  if ((mvData[i].nEndRow >= nStartRow) && (i == 0 || mvData[i-1].nEndRow < nEndRow))
2376  {
2377  // copy (bPutToPool=TRUE)
2378  rAttrArray.SetPatternArea( nStart, std::min( mvData[i].nEndRow, nEndRow ),
2379  mvData[i].pPattern, true );
2380  }
2381  nStart = std::max( nStart, mvData[i].nEndRow + 1 );
2382  }
2383  DeleteArea(nStartRow, nEndRow);
2384 }
2385 
2390  SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags) const
2391 {
2392  nStartRow -= nDy; // Source
2393  nEndRow -= nDy;
2394 
2395  SCROW nDestStart = std::max(static_cast<tools::Long>(static_cast<tools::Long>(nStartRow) + nDy), tools::Long(0));
2396  SCROW nDestEnd = std::min(static_cast<tools::Long>(static_cast<tools::Long>(nEndRow) + nDy), tools::Long(rDocument.MaxRow()));
2397 
2398  ScDocumentPool* pSourceDocPool = rDocument.GetPool();
2399  ScDocumentPool* pDestDocPool = rAttrArray.rDocument.GetPool();
2400  bool bSamePool = (pSourceDocPool==pDestDocPool);
2401 
2402  if ( mvData.empty() )
2403  {
2404  const ScPatternAttr* pNewPattern = &pDestDocPool->GetDefaultItem( ATTR_PATTERN );
2405  rAttrArray.SetPatternArea(nDestStart, nDestEnd, pNewPattern);
2406  return;
2407  }
2408 
2409  for (SCSIZE i = 0; (i < mvData.size()) && (nDestStart <= nDestEnd); i++)
2410  {
2411  if (mvData[i].nEndRow >= nStartRow)
2412  {
2413  const ScPatternAttr* pOldPattern = mvData[i].pPattern;
2414  const ScPatternAttr* pNewPattern;
2415 
2416  if (IsDefaultItem( pOldPattern ))
2417  {
2418  // default: nothing changed
2419 
2420  pNewPattern = &pDestDocPool->GetDefaultItem( ATTR_PATTERN );
2421  }
2422  else if ( nStripFlags != ScMF::NONE )
2423  {
2424  ScPatternAttr aTmpPattern( *pOldPattern );
2425  ScMF nNewFlags = ScMF::NONE;
2426  if ( nStripFlags != ScMF::All )
2427  nNewFlags = aTmpPattern.GetItem(ATTR_MERGE_FLAG).GetValue() & ~nStripFlags;
2428 
2429  if ( nNewFlags != ScMF::NONE )
2430  aTmpPattern.GetItemSet().Put( ScMergeFlagAttr( nNewFlags ) );
2431  else
2432  aTmpPattern.GetItemSet().ClearItem( ATTR_MERGE_FLAG );
2433 
2434  if (bSamePool)
2435  pNewPattern = &pDestDocPool->Put(aTmpPattern);
2436  else
2437  pNewPattern = aTmpPattern.PutInPool( &rAttrArray.rDocument, &rDocument );
2438  }
2439  else
2440  {
2441  if (bSamePool)
2442  pNewPattern = &pDestDocPool->Put(*pOldPattern);
2443  else
2444  pNewPattern = pOldPattern->PutInPool( &rAttrArray.rDocument, &rDocument );
2445  }
2446 
2447  rAttrArray.SetPatternArea(nDestStart,
2448  std::min(static_cast<SCROW>(mvData[i].nEndRow + nDy), nDestEnd), pNewPattern);
2449  }
2450 
2451  // when pasting from clipboard and skipping filtered rows, the adjusted
2452  // end position can be negative
2453  nDestStart = std::max(static_cast<tools::Long>(nDestStart), static_cast<tools::Long>(mvData[i].nEndRow + nDy + 1));
2454  }
2455 }
2456 
2461 void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray )
2462 {
2463  nStartRow -= nDy; // Source
2464  nEndRow -= nDy;
2465 
2466  SCROW nDestStart = std::max(static_cast<tools::Long>(static_cast<tools::Long>(nStartRow) + nDy), tools::Long(0));
2467  SCROW nDestEnd = std::min(static_cast<tools::Long>(static_cast<tools::Long>(nEndRow) + nDy), tools::Long(rDocument.MaxRow()));
2468 
2469  if ( !rAttrArray.HasAttrib( nDestStart, nDestEnd, HasAttrFlags::Overlapped ) )
2470  {
2471  CopyArea( nStartRow+nDy, nEndRow+nDy, nDy, rAttrArray );
2472  return;
2473  }
2474 
2475  ScDocumentPool* pSourceDocPool = rDocument.GetPool();
2476  ScDocumentPool* pDestDocPool = rAttrArray.rDocument.GetPool();
2477  bool bSamePool = (pSourceDocPool==pDestDocPool);
2478 
2479  if ( mvData.empty() )
2480  {
2481  const ScPatternAttr* pNewPattern;
2482  if (bSamePool)
2483  pNewPattern = &pDestDocPool->Put(*rDocument.GetDefPattern());
2484  else
2485  pNewPattern = rDocument.GetDefPattern()->PutInPool( &rAttrArray.rDocument, &rDocument );
2486 
2487  rAttrArray.SetPatternAreaSafe(nDestStart, nDestEnd, pNewPattern, false);
2488  return;
2489  }
2490 
2491 
2492  for (SCSIZE i = 0; (i < mvData.size()) && (nDestStart <= nDestEnd); i++)
2493  {
2494  if (mvData[i].nEndRow >= nStartRow)
2495  {
2496  const ScPatternAttr* pOldPattern = mvData[i].pPattern;
2497  const ScPatternAttr* pNewPattern;
2498 
2499  if (bSamePool)
2500  pNewPattern = &pDestDocPool->Put(*pOldPattern);
2501  else
2502  pNewPattern = pOldPattern->PutInPool( &rAttrArray.rDocument, &rDocument );
2503 
2504  rAttrArray.SetPatternAreaSafe(nDestStart,
2505  std::min(static_cast<SCROW>(mvData[i].nEndRow + nDy), nDestEnd), pNewPattern, false);
2506  }
2507 
2508  // when pasting from clipboard and skipping filtered rows, the adjusted
2509  // end position can be negative
2510  nDestStart = std::max(static_cast<tools::Long>(nDestStart), static_cast<tools::Long>(mvData[i].nEndRow + nDy + 1));
2511  }
2512 }
2513 
2515  SCROW nRow, const ScStyleSheet* pSearchStyle, bool bUp,
2516  const ScMarkArray* pMarkArray) const
2517 {
2518  bool bFound = false;
2519 
2520  if (pMarkArray)
2521  {
2522  nRow = pMarkArray->GetNextMarked( nRow, bUp );
2523  if (!rDocument.ValidRow(nRow))
2524  return nRow;
2525  }
2526 
2527  if ( mvData.empty() )
2528  {
2529  if (rDocument.GetDefPattern()->GetStyleSheet() == pSearchStyle)
2530  return nRow;
2531 
2532  nRow = bUp ? -1 : rDocument.MaxRow() + 1;
2533  return nRow;
2534  }
2535 
2536  SCSIZE nIndex;
2537  Search(nRow, nIndex);
2538  const ScPatternAttr* pPattern = mvData[nIndex].pPattern;
2539 
2540  while (nIndex < mvData.size() && !bFound)
2541  {
2542  if (pPattern->GetStyleSheet() == pSearchStyle)
2543  {
2544  if (pMarkArray)
2545  {
2546  nRow = pMarkArray->GetNextMarked( nRow, bUp );
2547  SCROW nStart = nIndex ? mvData[nIndex-1].nEndRow+1 : 0;
2548  if (nRow >= nStart && nRow <= mvData[nIndex].nEndRow)
2549  bFound = true;
2550  }
2551  else
2552  bFound = true;
2553  }
2554 
2555  if (!bFound)
2556  {
2557  if (bUp)
2558  {
2559  if (nIndex==0)
2560  {
2561  nIndex = mvData.size();
2562  nRow = -1;
2563  }
2564  else
2565  {
2566  --nIndex;
2567  nRow = mvData[nIndex].nEndRow;
2568  pPattern = mvData[nIndex].pPattern;
2569  }
2570  }
2571  else
2572  {
2573  nRow = mvData[nIndex].nEndRow+1;
2574  ++nIndex;
2575  if (nIndex<mvData.size())
2576  pPattern = mvData[nIndex].pPattern;
2577  }
2578  }
2579  }
2580 
2581  OSL_ENSURE( bFound || !rDocument.ValidRow(nRow), "Internal failure in ScAttrArray::SearchStyle" );
2582 
2583  return nRow;
2584 }
2585 
2587  SCROW& rRow, SCROW& rEndRow, const ScStyleSheet* pSearchStyle, bool bUp,
2588  const ScMarkArray* pMarkArray) const
2589 {
2590  SCROW nStartRow = SearchStyle( rRow, pSearchStyle, bUp, pMarkArray );
2591  if (rDocument.ValidRow(nStartRow))
2592  {
2593  if ( mvData.empty() )
2594  {
2595  rRow = nStartRow;
2596  if (bUp)
2597  {
2598  rEndRow = 0;
2599  if (pMarkArray)
2600  {
2601  SCROW nMarkEnd = pMarkArray->GetMarkEnd( nStartRow, true );
2602  if (nMarkEnd>rEndRow)
2603  rEndRow = nMarkEnd;
2604  }
2605  }
2606  else
2607  {
2608  rEndRow = rDocument.MaxRow();
2609  if (pMarkArray)
2610  {
2611  SCROW nMarkEnd = pMarkArray->GetMarkEnd( nStartRow, false );
2612  if (nMarkEnd<rEndRow)
2613  rEndRow = nMarkEnd;
2614  }
2615  }
2616 
2617  return true;
2618  }
2619 
2620  SCSIZE nIndex;
2621  Search(nStartRow,nIndex);
2622 
2623  rRow = nStartRow;
2624  if (bUp)
2625  {
2626  if (nIndex>0)
2627  rEndRow = mvData[nIndex-1].nEndRow + 1;
2628  else
2629  rEndRow = 0;
2630  if (pMarkArray)
2631  {
2632  SCROW nMarkEnd = pMarkArray->GetMarkEnd( nStartRow, true );
2633  if (nMarkEnd>rEndRow)
2634  rEndRow = nMarkEnd;
2635  }
2636  }
2637  else
2638  {
2639  rEndRow = mvData[nIndex].nEndRow;
2640  if (pMarkArray)
2641  {
2642  SCROW nMarkEnd = pMarkArray->GetMarkEnd( nStartRow, false );
2643  if (nMarkEnd<rEndRow)
2644  rEndRow = nMarkEnd;
2645  }
2646  }
2647 
2648  return true;
2649  }
2650  else
2651  return false;
2652 }
2653 
2654 SCSIZE ScAttrArray::Count( SCROW nStartRow, SCROW nEndRow ) const
2655 {
2656  if ( mvData.empty() )
2657  return 1;
2658 
2659  SCSIZE nIndex1, nIndex2;
2660 
2661  if( !Search( nStartRow, nIndex1 ) )
2662  return 0;
2663 
2664  if( !Search( nEndRow, nIndex2 ) )
2665  nIndex2 = mvData.size() - 1;
2666 
2667  return nIndex2 - nIndex1 + 1;
2668 }
2669 
2670 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsVisibleEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2003
void DeleteRange(SCSIZE nStartIndex, SCSIZE nEndIndex)
Definition: attarray.cxx:2303
static void lcl_MergeToFrame(SvxBoxItem *pLineOuter, SvxBoxInfoItem *pLineInner, ScLineFlags &rFlags, const ScPatternAttr *pPattern, bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom)
Definition: attarray.cxx:1058
SCCOL GetColMerge() const
Definition: attrib.hxx:68
SvxCellHorJustify
bool TestInsertRow(SCSIZE nSize) const
Definition: attarray.cxx:2188
sal_uInt64 GetKey() const
Definition: patattr.cxx:1362
sal_Int32 nIndex
constexpr TypedWhichId< ScPatternAttr > ATTR_PATTERN(156)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
bool RemoveFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1641
HasAttrFlags
Definition: global.hxx:193
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
tuple ns
constexpr sal_uInt16 ATTR_PATTERN_START(100)
std::string GetValue
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
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void InsertRow(SCROW nStartRow, SCSIZE nSize)
Definition: attarray.cxx:2206
bool IsMerged(SCROW nRow) const
Definition: attarray.cxx:1424
sal_uInt8 nVert
Definition: attarray.hxx:60
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
static void SetLine(const SvxBorderLine *dest, const SvxBorderLine *src)
Definition: attarray.cxx:710
long Long
bool Reserve(SCSIZE nReserve)
Definition: attarray.cxx:427
const editeng::SvxBorderLine * GetVert() const
bool IsOverlapped() const
Definition: attrib.hxx:101
SC_DLLPUBLIC bool ApplyFlagsTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, ScMF nFlags)
Definition: document.cxx:5038
SC_DLLPUBLIC bool InitColumnBlockPosition(sc::ColumnBlockPosition &rBlockPos, SCTAB nTab, SCCOL nCol)
Definition: document.cxx:2627
bool HasAttrib(SCROW nRow1, SCROW nRow2, HasAttrFlags nMask) const
Definition: attarray.cxx:1399
const WhichRangesContainer & GetRanges() const
bool Concat(SCSIZE nPos)
Definition: attarray.cxx:154
void InvalidateItem(sal_uInt16 nWhich)
sal_uInt8 nLeft
Definition: attarray.hxx:55
Store position data for column array storage.
sal_Int16 nId
const SfxItemSet & GetItemSet() const
bool HasItemsSet(const sal_uInt16 *pWhich) const
Definition: patattr.cxx:955
void erase_at(size_t index)
const_iterator find(const Value &x) const
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
void SetUsage(ScStyleSheet::Usage eUse) const
Definition: stlsheet.hxx:52
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
sal_uInt8 nBottom
Definition: attarray.hxx:58
ScAttrArray(const ScAttrArray &)=delete
void Remove(const SfxPoolItem &)
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
Definition: document.cxx:4788
const editeng::SvxBorderLine * GetRight() const
void SetPatternAreaSafe(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pWantedPattern, bool bDefault)
Definition: attarray.cxx:1549
void SetDefaultIfNotInit(SCSIZE nNeeded=1)
Definition: attarray.cxx:109
constexpr TypedWhichId< ScMergeAttr > ATTR_MERGE(144)
SCTAB nTab
Definition: attarray.hxx:90
const SfxSetItem & ApplyTo(const SfxSetItem &rSetItem)
void ApplyBlockFrame(const SvxBoxItem &rLineOuter, const SvxBoxInfoItem *pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight)
Definition: attarray.cxx:1232
constexpr TypedWhichId< ScIndentItem > ATTR_INDENT(131)
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6087
void SetAttrEntries(std::vector< ScAttrEntry > &&vNewData)
Definition: attarray.cxx:926
void DeleteRow(SCROW nStartRow, SCSIZE nSize)
Definition: attarray.cxx:2255
constexpr TypedWhichId< ScRotateValueItem > ATTR_ROTATE_VALUE(135)
bool IsStyleSheetUsed(const ScStyleSheet &rStyle) const
Definition: attarray.cxx:1842
bool HasVisibleAttrIn(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:1982
SvxShadowLocation GetLocation() const
const EditTextObject * mpEditText
Definition: cellvalue.hxx:109
void DeleteHardAttr(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2325
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
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
constexpr TypedWhichId< SvxShadowItem > ATTR_SHADOW(152)
This is a rather odd datastructure.
Definition: markarr.hxx:43
bool setTrue(SCROW nRow1, SCROW nRow2)
int nCount
void reserve(size_type amount)
bool SearchStyleRange(SCROW &rRow, SCROW &rEndRow, const ScStyleSheet *pSearchStyle, bool bUp, const ScMarkArray *pMarkArray=nullptr) const
Definition: attarray.cxx:2586
void CopyAreaSafe(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray)
Leave flags summarized with CopyArea.
Definition: attarray.cxx:2461
bool IsVisible() const
Definition: patattr.cxx:1104
void SetRow(SCROW nRowP)
Definition: address.hxx:274
bool TestInsertCol(SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2161
ScDocument & rDocument
Definition: attarray.hxx:91
bool Search(SCROW nRow, SCSIZE &nIndex) const
Definition: attarray.cxx:194
size_type size() const
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:70
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_TLBR(141)
std::vector< ScAttrEntry > mvData
Definition: attarray.hxx:93
bool GetHideCell() const
Definition: attrib.hxx:147
const editeng::SvxBorderLine * GetHori() const
void MergePatternArea(SCROW nStartRow, SCROW nEndRow, ScMergePatternState &rState, bool bDeep) const
Definition: attarray.cxx:971
const editeng::SvxBorderLine * GetTop() const
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const editeng::SvxBorderLine * GetLeft() const
void ApplyCacheArea(SCROW nStartRow, SCROW nEndRow, SfxItemPoolCache *pCache, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: attarray.cxx:843
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
sal_Int16 SCCOL
Definition: types.hxx:21
const SCROW SC_VISATTR_STOP
Definition: attarray.cxx:1923
static bool lcl_TestAttr(const SvxBorderLine *pOldLine, const SvxBorderLine *pNewLine, sal_uInt8 &rModified, const SvxBorderLine *&rpNew)
Definition: attarray.cxx:1027
void ClearItems(SCROW nStartRow, SCROW nEndRow, const sal_uInt16 *pWhich)
Definition: attarray.cxx:1678
#define SC_LINE_DONTCARE
Definition: attarray.hxx:47
void CopyArea(SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray &rAttrArray, ScMF nStripFlags=ScMF::NONE) const
Copy between documents (Clipboard)
Definition: attarray.cxx:2389
sal_uInt16 Count() const
autofilter arrow
void ApplyStyleArea(SCROW nStartRow, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: attarray.cxx:626
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxInfoItemLine nLine)
sal_uInt64 mnPatternId
Definition: attarray.hxx:73
SCROW GetMarkEnd(SCROW nRow, bool bUp) const
Definition: markarr.cxx:313
SC_DLLPUBLIC void ApplyPatternAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScPatternAttr &rAttr)
Definition: document.cxx:4817
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:2514
void RemoveCellCharAttribs(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr *pPattern, ScEditDataArray *pDataArray)
Definition: attarray.cxx:397
const_iterator end() const
bool IsAllEqual(const ScAttrArray &rOther, SCROW nStartRow, SCROW nEndRow) const
Definition: attarray.cxx:2083
void SetPatternArea(SCROW nStartRow, SCROW nEndRow, std::unique_ptr< ScPatternAttr > pPattern, bool bPutToPool=false, ScEditDataArray *pDataArray=nullptr)
Definition: attarray.hxx:145
SC_DLLPUBLIC const SfxItemSet * GetCondResult(SCCOL nCol, SCROW nRow, SCTAB nTab, ScRefCellValue *pCell=nullptr) const
Definition: documen4.cxx:799
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
static SvxCellOrientation GetCellOrientation(const SfxItemSet &rItemSet, const SfxItemSet *pCondSet)
Definition: patattr.cxx:157
SCSIZE Count() const
Definition: attarray.hxx:219
SfxItemPool * GetPool() const
#define SC_INDENT_STEP
Definition: global.hxx:234
void SetStyleSheet(ScStyleSheet *pNewStyle, bool bClearDirectFormat=true)
Definition: patattr.cxx:1169
bool IsEmpty() const
Definition: attarray.cxx:1876
void MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray &rAttrArray)
Move within a document.
Definition: attarray.cxx:2369
bool IsValid(SvxBoxInfoItemValidFlags nValid) const
const_iterator begin() const
bool IsMerged() const
Definition: attrib.hxx:71
bool GetFirstVisibleAttr(SCROW &rFirstRow) const
Definition: attarray.cxx:1889
const ScPatternAttr * pOld2
Definition: attarray.hxx:70
#define SC_LINE_SET
Definition: attarray.hxx:46
void InvalidateTextWidth(std::u16string_view rStyleName)
Definition: documen8.cxx:297
CellType meType
Definition: cellvalue.hxx:105
void ChangeIndent(SCROW nStartRow, SCROW nEndRow, bool bIncrement)
Definition: attarray.cxx:1708
static void SetLineColor(SvxBorderLine const *dest, Color c)
Definition: attarray.cxx:702
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
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
bool ValidRow(SCROW nRow) const
Definition: document.hxx:875
ScMF
Definition: attrib.hxx:34
void SetStreamValid(SCTAB nTab, bool bSet, bool bIgnoreLock=false)
Definition: document.cxx:925
SfxItemState
#define SC_ATTRARRAY_DELTA
Definition: attarray.hxx:49
double nx
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define SAL_WARN_IF(condition, area, stream)
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
ScPatternAttr * PutInPool(ScDocument *pDestDoc, ScDocument *pSrcDoc) const
Definition: patattr.cxx:1031
bool GetProtection() const
Definition: attrib.hxx:143
sal_uInt8 nTop
Definition: attarray.hxx:57
void DeleteArea(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:2313
virtual std::unique_ptr< EditTextObject > Clone() const =0
static bool CheckWidthInvalidate(bool &bNumFormatChanged, const SfxItemSet &rNewAttrs, const SfxItemSet &rOldAttrs)
Definition: global.cxx:180
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
Degree100 GetValue() const
constexpr TypedWhichId< ScCondFormatItem > ATTR_CONDITIONAL(154)
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
Definition: document.cxx:6082
constexpr sal_uInt16 ATTR_PATTERN_END(155)
SCROW GetNextUnprotected(SCROW nRow, bool bUp) const
Including current, may return -1.
Definition: attarray.cxx:1770
static void RemoveCharAttribs(EditTextObject &rEditText, const ScPatternAttr &rAttr)
Definition: editutil.cxx:149
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6092
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:986
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
bool IsVisibleEqual(const ScPatternAttr &rOther) const
Definition: patattr.cxx:1150
const ScPatternAttr * pOld1
existing objects, temporary
Definition: attarray.hxx:69
void RemoveCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex)
if nIndex == 0, remove all conditional format data
Definition: attarray.cxx:338
#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
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1057
void AddItem(SCTAB nTab, SCCOL nCol, SCROW nRow, std::unique_ptr< EditTextObject > pOldData, std::unique_ptr< EditTextObject > pNewData)
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
SCROW GetRowMerge() const
Definition: attrib.hxx:69
void RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow)
Definition: attarray.cxx:1494
bool HasAutoFilter() const
Definition: attrib.hxx:103
std::pair< const_iterator, bool > insert(Value &&x)
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4151
bool ApplyFlags(SCROW nStartRow, SCROW nEndRow, ScMF nFlags)
Definition: attarray.cxx:1604
std::optional< SfxItemSet > pItemSet
Definition: attarray.hxx:68
bool IsLoading() const
static void lcl_MergeDeep(SfxItemSet &rMergeSet, const SfxItemSet &rSource)
Definition: attarray.cxx:935
SCROW GetNextMarked(SCROW nRow, bool bUp) const
Including current row, may return -1 if bUp and not found.
Definition: markarr.cxx:290
const editeng::SvxBorderLine * GetBottom() const
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_BLTR(142)
sal_uInt8 nHori
Definition: attarray.hxx:59
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: attarray.cxx:239
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22
dp table output
bool IsDefaultItem(const SfxPoolItem *pItem)
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
SvxShadowLocation