LibreOffice Module sc (master)  1
table2.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <algorithm>
21 #include <memory>
22 #include <table.hxx>
23 #include <patattr.hxx>
24 #include <docpool.hxx>
25 #include <formulacell.hxx>
26 #include <document.hxx>
27 #include <drwlayer.hxx>
28 #include <olinetab.hxx>
29 #include <stlpool.hxx>
30 #include <attarray.hxx>
31 #include <markdata.hxx>
32 #include <dociter.hxx>
33 #include <conditio.hxx>
34 #include <chartlis.hxx>
35 #include <fillinfo.hxx>
36 #include <bcaslot.hxx>
37 #include <postit.hxx>
38 #include <sheetevents.hxx>
39 #include <segmenttree.hxx>
40 #include <dbdata.hxx>
41 #include <tokenarray.hxx>
42 #include <clipcontext.hxx>
43 #include <types.hxx>
44 #include <editutil.hxx>
45 #include <mtvcellfunc.hxx>
46 #include <refupdatecontext.hxx>
47 #include <scopetools.hxx>
48 #include <tabprotection.hxx>
49 #include <columnspanset.hxx>
50 #include <rowheightcontext.hxx>
51 #include <listenercontext.hxx>
52 #include <compressedarray.hxx>
53 #include <brdcst.hxx>
54 #include <refdata.hxx>
55 #include <docsh.hxx>
56 
57 #include <scitems.hxx>
58 #include <editeng/boxitem.hxx>
59 #include <editeng/editobj.hxx>
60 #include <o3tl/safeint.hxx>
61 #include <o3tl/unit_conversion.hxx>
62 #include <osl/diagnose.h>
63 #include <svl/poolcach.hxx>
64 #include <unotools/charclass.hxx>
65 #include <math.h>
66 
67 namespace {
68 
69 class ColumnRegroupFormulaCells
70 {
71  ScColContainer& mrCols;
72  std::vector<ScAddress>* mpGroupPos;
73 
74 public:
75  ColumnRegroupFormulaCells( ScColContainer& rCols, std::vector<ScAddress>* pGroupPos ) :
76  mrCols(rCols), mpGroupPos(pGroupPos) {}
77 
78  void operator() (SCCOL nCol)
79  {
80  mrCols[nCol].RegroupFormulaCells(mpGroupPos);
81  }
82 };
83 
84 }
85 
86 sal_uInt16 ScTable::GetTextWidth(SCCOL nCol, SCROW nRow) const
87 {
88  return aCol[nCol].GetTextWidth(nRow);
89 }
90 
91 bool ScTable::SetOutlineTable( const ScOutlineTable* pNewOutline )
92 {
93  sal_uInt16 nOldSizeX = 0;
94  sal_uInt16 nOldSizeY = 0;
95  sal_uInt16 nNewSizeX = 0;
96  sal_uInt16 nNewSizeY = 0;
97 
98  if (pOutlineTable)
99  {
100  nOldSizeX = pOutlineTable->GetColArray().GetDepth();
101  nOldSizeY = pOutlineTable->GetRowArray().GetDepth();
102  pOutlineTable.reset();
103  }
104 
105  if (pNewOutline)
106  {
107  pOutlineTable.reset(new ScOutlineTable( *pNewOutline ));
108  nNewSizeX = pOutlineTable->GetColArray().GetDepth();
109  nNewSizeY = pOutlineTable->GetRowArray().GetDepth();
110  }
111 
112  return ( nNewSizeX != nOldSizeX || nNewSizeY != nOldSizeY ); // changed size?
113 }
114 
116 {
117  if (!pOutlineTable)
118  pOutlineTable.reset(new ScOutlineTable);
119 }
120 
121 void ScTable::SetSheetEvents( std::unique_ptr<ScSheetEvents> pNew )
122 {
123  pSheetEvents = std::move(pNew);
124 
125  SetCalcNotification( false ); // discard notifications before the events were set
126 
127  SetStreamValid(false);
128 }
129 
131 {
132  bCalcNotification = bSet;
133 }
134 
135 bool ScTable::TestInsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize ) const
136 {
137  bool bTest = true;
138 
139  if ( nStartCol==0 && nEndCol==rDocument.MaxCol() && pOutlineTable )
140  bTest = pOutlineTable->TestInsertRow(nSize);
141 
142  for (SCCOL i=nStartCol; (i<=nEndCol) && bTest; i++)
143  bTest = CreateColumnIfNotExists(i).TestInsertRow(nStartRow, nSize);
144 
145  return bTest;
146 }
147 
148 void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize )
149 {
150  if (nStartCol==0 && nEndCol==rDocument.MaxCol())
151  {
152  if (mpRowHeights && pRowFlags)
153  {
154  mpRowHeights->insertSegment(nStartRow, nSize);
155  CRFlags nNewFlags = pRowFlags->Insert( nStartRow, nSize);
156  // only copy manual size flag, clear all others
157  if (nNewFlags != CRFlags::NONE && (nNewFlags != CRFlags::ManualSize))
158  pRowFlags->SetValue( nStartRow, nStartRow + nSize - 1,
159  nNewFlags & CRFlags::ManualSize);
160  }
161 
162  if (pOutlineTable)
163  pOutlineTable->InsertRow( nStartRow, nSize );
164 
165  mpFilteredRows->insertSegment(nStartRow, nSize);
166  mpHiddenRows->insertSegment(nStartRow, nSize);
167 
168  if (!maRowManualBreaks.empty())
169  {
170  // Copy all breaks up to nStartRow (non-inclusive).
171  ::std::set<SCROW>::iterator itr1 = maRowManualBreaks.lower_bound(nStartRow);
172  ::std::set<SCROW> aNewBreaks(maRowManualBreaks.begin(), itr1);
173 
174  // Copy all breaks from nStartRow (inclusive) to the last element,
175  // but add nSize to each value.
176  ::std::set<SCROW>::iterator itr2 = maRowManualBreaks.end();
177  for (; itr1 != itr2; ++itr1)
178  aNewBreaks.insert(static_cast<SCROW>(*itr1 + nSize));
179 
180  maRowManualBreaks.swap(aNewBreaks);
181  }
182  }
183 
184  for (SCCOL j=nStartCol; j<=nEndCol; j++)
185  aCol[j].InsertRow( nStartRow, nSize );
186 
187  mpCondFormatList->InsertRow(nTab, nStartCol, nEndCol, nStartRow, nSize);
188 
190 
191  // TODO: In the future we may want to check if the table has been
192  // really modified before setting the stream invalid.
193  SetStreamValid(false);
194 }
195 
197  const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize,
198  bool* pUndoOutline, std::vector<ScAddress>* pGroupPos )
199 {
200  if (nStartCol==0 && nEndCol==rDocument.MaxCol())
201  {
202  if (pRowFlags)
203  pRowFlags->Remove( nStartRow, nSize);
204 
205  if (mpRowHeights)
206  mpRowHeights->removeSegment(nStartRow, nStartRow+nSize);
207 
208  if (pOutlineTable)
209  if (pOutlineTable->DeleteRow( nStartRow, nSize ))
210  if (pUndoOutline)
211  *pUndoOutline = true;
212 
213  mpFilteredRows->removeSegment(nStartRow, nStartRow+nSize);
214  mpHiddenRows->removeSegment(nStartRow, nStartRow+nSize);
215 
216  if (!maRowManualBreaks.empty())
217  {
218  // Erase all manual breaks between nStartRow and nStartRow + nSize - 1 (inclusive).
219  std::set<SCROW>::iterator itr1 = maRowManualBreaks.lower_bound(nStartRow);
220  std::set<SCROW>::iterator itr2 = maRowManualBreaks.upper_bound(static_cast<SCROW>(nStartRow + nSize - 1));
221  maRowManualBreaks.erase(itr1, itr2);
222 
223  // Copy all breaks from the 1st element up to nStartRow to the new container.
224  itr1 = maRowManualBreaks.lower_bound(nStartRow);
225  ::std::set<SCROW> aNewBreaks(maRowManualBreaks.begin(), itr1);
226 
227  // Copy all breaks from nStartRow to the last element, but subtract each value by nSize.
228  itr2 = maRowManualBreaks.end();
229  for (; itr1 != itr2; ++itr1)
230  aNewBreaks.insert(static_cast<SCROW>(*itr1 - nSize));
231 
232  maRowManualBreaks.swap(aNewBreaks);
233  }
234  }
235 
236  { // scope for bulk broadcast
237  ScBulkBroadcast aBulkBroadcast( rDocument.GetBASM(), SfxHintId::ScDataChanged);
238  for (SCCOL j=nStartCol; j<=nEndCol; j++)
239  aCol[j].DeleteRow(nStartRow, nSize, pGroupPos);
240  }
241 
242  std::vector<SCCOL> aRegroupCols;
243  rRegroupCols.getColumns(nTab, aRegroupCols);
244  std::for_each(
245  aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol, pGroupPos));
246 
248 
249  // TODO: In the future we may want to check if the table has been
250  // really modified before setting the stream invalid.
251  SetStreamValid(false);
252 }
253 
254 bool ScTable::TestInsertCol( SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ) const
255 {
256  if ( nSize > o3tl::make_unsigned(rDocument.MaxCol()) )
257  return false;
258 
259  if ( nStartRow==0 && nEndRow==rDocument.MaxRow() && pOutlineTable
260  && ! pOutlineTable->TestInsertCol(nSize) )
261  return false;
262 
263  auto range = GetColumnsRange( rDocument.MaxCol() - static_cast<SCCOL>(nSize) + 1, rDocument.MaxCol() );
264  for (auto it = range.rbegin(); it != range.rend(); ++it )
265  if (! aCol[*it].TestInsertCol(nStartRow, nEndRow))
266  return false;
267 
268  return true;
269 }
270 
272  const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize )
273 {
274  if (nStartRow==0 && nEndRow==rDocument.MaxRow())
275  {
276  if (mpColWidth && mpColFlags)
277  {
278  mpColWidth->InsertPreservingSize(nStartCol, nSize, STD_COL_WIDTH);
279  // The inserted columns have the same widths as the columns, which were selected for insert.
280  for (SCSIZE i=0; i < std::min(rDocument.MaxCol()-nSize-nStartCol, nSize); ++i)
281  mpColWidth->SetValue(nStartCol + i, mpColWidth->GetValue(nStartCol+i+nSize));
282  mpColFlags->InsertPreservingSize(nStartCol, nSize, CRFlags::NONE);
283  }
284  if (pOutlineTable)
285  pOutlineTable->InsertCol( nStartCol, nSize );
286 
287  mpHiddenCols->insertSegment(nStartCol, static_cast<SCCOL>(nSize));
288  mpFilteredCols->insertSegment(nStartCol, static_cast<SCCOL>(nSize));
289 
290  if (!maColManualBreaks.empty())
291  {
292  // Copy all breaks up to nStartCol (non-inclusive).
293  ::std::set<SCCOL>::iterator itr1 = maColManualBreaks.lower_bound(nStartCol);
294  ::std::set<SCCOL> aNewBreaks(maColManualBreaks.begin(), itr1);
295 
296  // Copy all breaks from nStartCol (inclusive) to the last element,
297  // but add nSize to each value.
298  ::std::set<SCCOL>::iterator itr2 = maColManualBreaks.end();
299  for (; itr1 != itr2; ++itr1)
300  aNewBreaks.insert(static_cast<SCCOL>(*itr1 + nSize));
301 
302  maColManualBreaks.swap(aNewBreaks);
303  }
304  }
305 
306  if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
307  {
308  for (SCSIZE i=0; i < nSize; i++)
309  for (SCCOL nCol = aCol.size() - 1; nCol > nStartCol; nCol--)
310  aCol[nCol].SwapCol(aCol[nCol-1]);
311  }
312  else
313  {
314  for (SCSIZE i=0; static_cast<SCCOL>(i+nSize)+nStartCol < aCol.size(); i++)
315  aCol[aCol.size() - 1 - nSize - i].MoveTo(nStartRow, nEndRow, aCol[aCol.size() - 1 - i]);
316  }
317 
318  std::vector<SCCOL> aRegroupCols;
319  rRegroupCols.getColumns(nTab, aRegroupCols);
320  std::for_each(aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol, nullptr));
321 
322  if (nStartCol>0) // copy old attributes
323  {
324  sal_uInt16 nWhichArray[2];
325  nWhichArray[0] = ATTR_MERGE;
326  nWhichArray[1] = 0;
327 
329  for (SCSIZE i=0; i<nSize; i++)
330  {
331  aCol[nStartCol-1].CopyToColumn(aCxt, nStartRow, nEndRow, InsertDeleteFlags::ATTRIB,
332  false, aCol[nStartCol+i] );
333  aCol[nStartCol+i].RemoveFlags( nStartRow, nEndRow,
335  aCol[nStartCol+i].ClearItems( nStartRow, nEndRow, nWhichArray );
336  }
337  }
338 
339  mpCondFormatList->InsertCol(nTab, nStartRow, nEndRow, nStartCol, nSize);
340 
342 
343  // TODO: In the future we may want to check if the table has been
344  // really modified before setting the stream invalid.
345  SetStreamValid(false);
346 }
347 
349  const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE nSize, bool* pUndoOutline )
350 {
351  if (nStartRow==0 && nEndRow==rDocument.MaxRow())
352  {
353  if (mpColWidth && mpColFlags)
354  {
355  assert( nStartCol + nSize <= o3tl::make_unsigned(rDocument.MaxCol()+1) ); // moving 0 if ==rDocument.MaxCol()+1 is correct
356  mpColWidth->RemovePreservingSize(nStartCol, nSize, STD_COL_WIDTH);
357  mpColFlags->RemovePreservingSize(nStartCol, nSize, CRFlags::NONE);
358  }
359  if (pOutlineTable)
360  if (pOutlineTable->DeleteCol( nStartCol, nSize ))
361  if (pUndoOutline)
362  *pUndoOutline = true;
363 
364  SCCOL nRmSize = nStartCol + static_cast<SCCOL>(nSize);
365  mpHiddenCols->removeSegment(nStartCol, nRmSize);
366  mpFilteredCols->removeSegment(nStartCol, nRmSize);
367 
368  if (!maColManualBreaks.empty())
369  {
370  // Erase all manual breaks between nStartCol and nStartCol + nSize - 1 (inclusive).
371  std::set<SCCOL>::iterator itr1 = maColManualBreaks.lower_bound(nStartCol);
372  std::set<SCCOL>::iterator itr2 = maColManualBreaks.upper_bound(static_cast<SCCOL>(nStartCol + nSize - 1));
373  maColManualBreaks.erase(itr1, itr2);
374 
375  // Copy all breaks from the 1st element up to nStartCol to the new container.
376  itr1 = maColManualBreaks.lower_bound(nStartCol);
377  ::std::set<SCCOL> aNewBreaks(maColManualBreaks.begin(), itr1);
378 
379  // Copy all breaks from nStartCol to the last element, but subtract each value by nSize.
380  itr2 = maColManualBreaks.end();
381  for (; itr1 != itr2; ++itr1)
382  aNewBreaks.insert(static_cast<SCCOL>(*itr1 - nSize));
383 
384  maColManualBreaks.swap(aNewBreaks);
385  }
386  }
387 
388  for (SCSIZE i = 0; i < nSize; i++)
389  aCol[nStartCol + i].DeleteArea(nStartRow, nEndRow, InsertDeleteFlags::ALL, false);
390 
391  if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
392  {
393  for (SCSIZE i=0; i < nSize; i++)
394  for (SCCOL nCol = nStartCol; nCol < aCol.size() - 1; nCol++)
395  aCol[nCol].SwapCol(aCol[nCol+1]);
396  }
397  else
398  {
399  for (SCSIZE i=0; static_cast<SCCOL>(i+nSize)+nStartCol < aCol.size(); i++)
400  aCol[nStartCol + nSize + i].MoveTo(nStartRow, nEndRow, aCol[nStartCol + i]);
401  }
402 
403  std::vector<SCCOL> aRegroupCols;
404  rRegroupCols.getColumns(nTab, aRegroupCols);
405  std::for_each(aRegroupCols.begin(), aRegroupCols.end(), ColumnRegroupFormulaCells(aCol, nullptr));
406 
408 
409  // TODO: In the future we may want to check if the table has been
410  // really modified before setting the stream invalid.
411  SetStreamValid(false);
412 }
413 
415  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nDelFlag,
416  bool bBroadcast, sc::ColumnSpanSet* pBroadcastSpans )
417 {
418  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
419  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
420  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
421  {
422  { // scope for bulk broadcast
423  ScBulkBroadcast aBulkBroadcast( rDocument.GetBASM(), SfxHintId::ScDataChanged);
424  for (SCCOL i = nCol1; i <= nCol2; i++)
425  aCol[i].DeleteArea(nRow1, nRow2, nDelFlag, bBroadcast, pBroadcastSpans);
426  }
427 
428  // Do not set protected cell in a protected table
429 
430  if ( IsProtected() && (nDelFlag & InsertDeleteFlags::ATTRIB) )
431  {
432  ScPatternAttr aPattern(rDocument.GetPool());
433  aPattern.GetItemSet().Put( ScProtectionAttr( false ) );
434  ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern );
435  }
436 
437  if( nDelFlag & InsertDeleteFlags::ATTRIB )
438  mpCondFormatList->DeleteArea( nCol1, nRow1, nCol2, nRow2 );
439  }
440 
441  // TODO: In the future we may want to check if the table has been
442  // really modified before setting the stream invalid.
443  SetStreamValid(false);
444 }
445 
446 void ScTable::DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rMark, bool bBroadcast )
447 {
448  { // scope for bulk broadcast
449  ScBulkBroadcast aBulkBroadcast( rDocument.GetBASM(), SfxHintId::ScDataChanged);
450  for (SCCOL i=0; i < aCol.size(); i++)
451  aCol[i].DeleteSelection(nDelFlag, rMark, bBroadcast);
452  }
453 
454  ScRangeList aRangeList;
455  rMark.FillRangeListWithMarks(&aRangeList, false);
456 
457  for (size_t i = 0; i < aRangeList.size(); ++i)
458  {
459  const ScRange & rRange = aRangeList[i];
460 
461  if((nDelFlag & InsertDeleteFlags::ATTRIB) && rRange.aStart.Tab() == nTab)
462  mpCondFormatList->DeleteArea( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row() );
463  }
464 
465  // Do not set protected cell in a protected sheet
466 
467  if ( IsProtected() && (nDelFlag & InsertDeleteFlags::ATTRIB) )
468  {
469  ScDocumentPool* pPool = rDocument.GetPool();
470  SfxItemSet aSet( *pPool, svl::Items<ATTR_PATTERN_START, ATTR_PATTERN_END> );
471  aSet.Put( ScProtectionAttr( false ) );
472  SfxItemPoolCache aCache( pPool, &aSet );
473  ApplySelectionCache( &aCache, rMark );
474  }
475 
476  // TODO: In the future we may want to check if the table has been
477  // really modified before setting the stream invalid.
478  SetStreamValid(false);
479 }
480 
481 // pTable = Clipboard
483  sc::CopyToClipContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
484  ScTable* pTable )
485 {
486  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
487  return;
488 
489  // copy content
490  //local range names need to be copied first for formula cells
491  if (!pTable->mpRangeName && mpRangeName)
492  pTable->mpRangeName.reset( new ScRangeName(*mpRangeName) );
493 
494  nCol2 = ClampToAllocatedColumns(nCol2);
495 
496  for ( SCCOL i = nCol1; i <= nCol2; i++)
497  aCol[i].CopyToClip(rCxt, nRow1, nRow2, pTable->CreateColumnIfNotExists(i)); // notes are handled at column level
498 
499  // copy widths/heights, and only "hidden", "filtered" and "manual" flags
500  // also for all preceding columns/rows, to have valid positions for drawing objects
501 
502  if (mpColWidth && pTable->mpColWidth)
503  pTable->mpColWidth->CopyFrom(*mpColWidth, 0, nCol2);
504 
505  pTable->CopyColHidden(*this, 0, nCol2);
506  pTable->CopyColFiltered(*this, 0, nCol2);
507  if (pDBDataNoName)
508  pTable->SetAnonymousDBData(std::unique_ptr<ScDBData>(new ScDBData(*pDBDataNoName)));
509 
510  if (pRowFlags && pTable->pRowFlags && mpRowHeights && pTable->mpRowHeights)
511  {
512  pTable->pRowFlags->CopyFromAnded( *pRowFlags, 0, nRow2, CRFlags::ManualSize);
513  pTable->CopyRowHeight(*this, 0, nRow2, 0);
514  }
515 
516  pTable->CopyRowHidden(*this, 0, nRow2);
517  pTable->CopyRowFiltered(*this, 0, nRow2);
518 
519  // If necessary replace formulas with values
520 
521  if ( IsProtected() )
522  for (SCCOL i = nCol1; i <= nCol2; i++)
523  pTable->aCol[i].RemoveProtected(nRow1, nRow2);
524 
526 }
527 
529  sc::CopyToClipContext& rCxt, const ScRangeList& rRanges, ScTable* pTable )
530 {
531  for ( size_t i = 0, nListSize = rRanges.size(); i < nListSize; ++i )
532  {
533  const ScRange & r = rRanges[ i ];
534  CopyToClip( rCxt, r.aStart.Col(), r.aStart.Row(), r.aEnd.Col(), r.aEnd.Row(), pTable);
535  }
536 }
537 
539  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const SvNumberFormatterMergeMap& rMap, ScTable* pDestTab )
540 {
541  if (nCol1 > nCol2 || nRow1 > nRow2)
542  return;
543 
544  const SCCOL nFirstUnallocated = std::clamp<SCCOL>(GetAllocatedColumnsCount(), nCol1, nCol2 + 1);
545  if (nFirstUnallocated > nCol1)
546  pDestTab->CreateColumnIfNotExists(nFirstUnallocated - 1);
547 
548  for (SCCOL i = nCol1; i < nFirstUnallocated; ++i)
549  {
550  ScColumn& rSrcCol = aCol[i];
551  ScColumn& rDestCol = pDestTab->aCol[i];
552  rSrcCol.CopyStaticToDocument(nRow1, nRow2, rMap, rDestCol);
553  }
554 
555  // Maybe copy this table's default attrs to dest not limiting to already allocated in dest?
556  const SCCOL nLastInDest = std::min<SCCOL>(pDestTab->GetAllocatedColumnsCount() - 1, nCol2);
557  for (SCCOL i = nFirstUnallocated; i <= nLastInDest; ++i)
558  {
559  ScColumn& rDestCol = pDestTab->aCol[i];
560  rDestCol.maCellTextAttrs.set_empty(nRow1, nRow2);
561  rDestCol.maCells.set_empty(nRow1, nRow2);
562  for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
563  {
564  sal_uInt32 nNumFmt = aDefaultColAttrArray.GetPattern(nRow)->GetNumberFormat(
566  SvNumberFormatterMergeMap::const_iterator itNum = rMap.find(nNumFmt);
567  if (itNum != rMap.end())
568  nNumFmt = itNum->second;
569 
570  rDestCol.SetNumberFormat(nRow, nNumFmt);
571  }
572  rDestCol.CellStorageModified();
573  }
574 }
575 
576 void ScTable::CopyCellToDocument(SCCOL nSrcCol, SCROW nSrcRow, SCCOL nDestCol, SCROW nDestRow, ScTable& rDestTab )
577 {
578  if (!ValidColRow(nSrcCol, nSrcRow) || !ValidColRow(nDestCol, nDestRow))
579  return;
580 
581  if (nSrcCol >= GetAllocatedColumnsCount())
582  {
583  if (nDestCol < rDestTab.GetAllocatedColumnsCount())
584  {
585  ScColumn& rDestCol = rDestTab.aCol[nDestCol];
586  rDestCol.maCells.set_empty(nDestRow, nDestRow);
587  rDestCol.maCellTextAttrs.set_empty(nDestRow, nDestRow);
588  rDestCol.maCellNotes.set_empty(nDestRow, nDestRow);
589  rDestCol.CellStorageModified();
590  }
591  return;
592  }
593 
594  ScColumn& rSrcCol = aCol[nSrcCol];
595  ScColumn& rDestCol = rDestTab.CreateColumnIfNotExists(nDestCol);
596  rSrcCol.CopyCellToDocument(nSrcRow, nDestRow, rDestCol);
597 }
598 
599 namespace {
600 
601 bool CheckAndDeduplicateCondFormat(ScDocument& rDocument, ScConditionalFormat* pOldFormat, const ScConditionalFormat* pNewFormat, SCTAB nTab)
602 {
603  if (!pOldFormat)
604  return false;
605 
606  if (pOldFormat->EqualEntries(*pNewFormat, true))
607  {
608  const ScRangeList& rNewRangeList = pNewFormat->GetRange();
609  ScRangeList& rDstRangeList = pOldFormat->GetRangeList();
610  for (size_t i = 0; i < rNewRangeList.size(); ++i)
611  {
612  rDstRangeList.Join(rNewRangeList[i]);
613  }
614  rDocument.AddCondFormatData(rNewRangeList, nTab, pOldFormat->GetKey());
615  return true;
616  }
617 
618  return false;
619 }
620 
621 }
622 
623 void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
624  SCCOL nDx, SCROW nDy, const ScTable* pTable)
625 {
626  ScRange aOldRange( nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab);
627  ScRange aNewRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
628  bool bSameDoc = rDocument.GetStyleSheetPool() == pTable->rDocument.GetStyleSheetPool();
629 
630  for(const auto& rxCondFormat : *pTable->mpCondFormatList)
631  {
632  const ScRangeList& rCondFormatRange = rxCondFormat->GetRange();
633  if(!rCondFormatRange.Intersects( aOldRange ))
634  continue;
635 
636  ScRangeList aIntersectedRange = rCondFormatRange.GetIntersectedRange(aOldRange);
637  std::unique_ptr<ScConditionalFormat> pNewFormat = rxCondFormat->Clone(&rDocument);
638 
639  pNewFormat->SetRange(aIntersectedRange);
640  sc::RefUpdateContext aRefCxt(rDocument);
641  aRefCxt.meMode = URM_COPY;
642  aRefCxt.maRange = aNewRange;
643  aRefCxt.mnColDelta = nDx;
644  aRefCxt.mnRowDelta = nDy;
645  aRefCxt.mnTabDelta = nTab - pTable->nTab;
646  pNewFormat->UpdateReference(aRefCxt, true);
647 
648  if (bSameDoc && pTable->nTab == nTab && CheckAndDeduplicateCondFormat(rDocument, mpCondFormatList->GetFormat(rxCondFormat->GetKey()), pNewFormat.get(), nTab))
649  {
650  continue;
651  }
652  sal_uLong nMax = 0;
653  bool bDuplicate = false;
654  for(const auto& rxCond : *mpCondFormatList)
655  {
656  // Check if there is the same format in the destination
657  // If there is, then simply expand its range
658  if (CheckAndDeduplicateCondFormat(rDocument, rxCond.get(), pNewFormat.get(), nTab))
659  {
660  bDuplicate = true;
661  break;
662  }
663 
664  if (rxCond->GetKey() > nMax)
665  nMax = rxCond->GetKey();
666  }
667  // Do not add duplicate entries
668  if (bDuplicate)
669  {
670  continue;
671  }
672 
673  pNewFormat->SetKey(nMax + 1);
674  auto pNewFormatTmp = pNewFormat.get();
675  mpCondFormatList->InsertNew(std::move(pNewFormat));
676 
677  if(!bSameDoc)
678  {
679  for(size_t i = 0, n = pNewFormatTmp->size();
680  i < n; ++i)
681  {
682  OUString aStyleName;
683  const ScFormatEntry* pEntry = pNewFormatTmp->GetEntry(i);
684  if(pEntry->GetType() == ScFormatEntry::Type::Condition ||
686  aStyleName = static_cast<const ScCondFormatEntry*>(pEntry)->GetStyle();
687  else if(pEntry->GetType() == ScFormatEntry::Type::Date)
688  aStyleName = static_cast<const ScCondDateFormatEntry*>(pEntry)->GetStyleName();
689 
690  if(!aStyleName.isEmpty())
691  {
692  if(rDocument.GetStyleSheetPool()->Find(aStyleName, SfxStyleFamily::Para))
693  continue;
694 
695  rDocument.GetStyleSheetPool()->CopyStyleFrom(
696  pTable->rDocument.GetStyleSheetPool(), aStyleName, SfxStyleFamily::Para );
697  }
698  }
699  }
700 
701  rDocument.AddCondFormatData( pNewFormatTmp->GetRange(), nTab, pNewFormatTmp->GetKey() );
702  }
703 }
704 
706 {
707  if (!ValidCol(nCol))
708  return false;
709 
711  return true;
712 }
713 
714 // pTable is source
715 
717  sc::CopyFromClipContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
718  SCCOL nDx, SCROW nDy, ScTable* pTable )
719 {
720  if (nCol2 > rDocument.MaxCol())
721  nCol2 = rDocument.MaxCol();
722  if (nRow2 > rDocument.MaxRow())
723  nRow2 = rDocument.MaxRow();
724 
725  if (!(ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2)))
726  return;
727 
729  for ( SCCOL i = nCol1; i <= nCol2; i++)
730  {
731  pTable->CreateColumnIfNotExists(i - nDx);
732  aCol[i].CopyFromClip(rCxt, nRow1, nRow2, nDy, pTable->aCol[i - nDx]); // notes are handles at column level
733  }
734 
736  {
737  // make sure that there are no old references to the cond formats
738  sal_uInt16 nWhichArray[2];
739  nWhichArray[0] = ATTR_CONDITIONAL;
740  nWhichArray[1] = 0;
741  for ( SCCOL i = nCol1; i <= nCol2; ++i)
742  aCol[i].ClearItems(nRow1, nRow2, nWhichArray);
743  }
744 
746  return;
747 
748  if (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pTable->mpColWidth)
749  mpColWidth->CopyFrom(*pTable->mpColWidth, nCol1, nCol2, nCol1 - nDx);
750 
751  if (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pTable->mpRowHeights &&
752  pRowFlags && pTable->pRowFlags)
753  {
754  CopyRowHeight(*pTable, nRow1, nRow2, -nDy);
755  // Must copy CRFlags::ManualSize bit too, otherwise pRowHeight doesn't make sense
756  for (SCROW j=nRow1; j<=nRow2; j++)
757  {
758  if ( pTable->pRowFlags->GetValue(j-nDy) & CRFlags::ManualSize )
759  pRowFlags->OrValue( j, CRFlags::ManualSize);
760  else
761  pRowFlags->AndValue( j, ~CRFlags::ManualSize);
762  }
763  }
764 
765  // Do not set protected cell in a protected sheet
767  {
768  ScPatternAttr aPattern(rDocument.GetPool());
769  aPattern.GetItemSet().Put( ScProtectionAttr( false ) );
770  ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern );
771  }
772 
773  // create deep copies for conditional formatting
774  CopyConditionalFormat( nCol1, nRow1, nCol2, nRow2, nDx, nDy, pTable);
775 }
776 
778  sc::MixDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
779  ScPasteFunc nFunction, bool bSkipEmpty, const ScTable* pSrcTab )
780 {
781  for (SCCOL i=nCol1; i<=nCol2; i++)
782  aCol[i].MixData(rCxt, nRow1, nRow2, nFunction, bSkipEmpty, pSrcTab->aCol[i]);
783 }
784 
785 // Selection form this document
787  sc::MixDocContext& rCxt, const ScMarkData& rMark, ScPasteFunc nFunction,
788  bool bSkipEmpty, const ScTable* pSrcTab )
789 {
790  for (SCCOL i=0; i < aCol.size(); i++)
791  aCol[i].MixMarked(rCxt, rMark, nFunction, bSkipEmpty, pSrcTab->aCol[i]);
792 }
793 
794 namespace {
795 
796 class TransClipHandler
797 {
798  ScTable& mrClipTab;
799  const ScTable& mrSrcTab;
800  SCTAB mnSrcTab;
801  SCCOL mnCol1;
802  SCCOL mnSrcCol;
803  size_t mnTopRow;
804  size_t mnEndRow;
805  SCROW mnTransRow;
806  SCROW mnFilteredRows = 0;
807  SCROW mnRowDestOffset = 0;
808  bool mbAsLink;
809  bool mbWasCut;
810  bool mbIncludeFiltered;
812 
813  ScAddress getDestPos(size_t nRow) const
814  {
815  return ScAddress(static_cast<SCCOL>(mnCol1 + nRow - mnTopRow), mnTransRow,
816  mrClipTab.GetTab());
817  }
818 
819  ScFormulaCell* createRefCell(size_t nSrcRow, const ScAddress& rDestPos) const
820  {
821  ScAddress aSrcPos(mnSrcCol, nSrcRow, mnSrcTab);
822  ScSingleRefData aRef;
823  aRef.InitAddress(aSrcPos); // Absolute reference.
824  aRef.SetFlag3D(true);
825 
826  ScTokenArray aArr(mrClipTab.GetDoc());
827  aArr.AddSingleReference(aRef);
828  return new ScFormulaCell(mrClipTab.GetDoc(), rDestPos, aArr);
829  }
830 
831  void setLink(size_t nRow)
832  {
833  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
834  mrClipTab.SetFormulaCell(nTransCol, mnTransRow,
835  createRefCell(nRow, getDestPos(nRow)));
836  }
837 
838 public:
839  TransClipHandler(ScTable& rClipTab, const ScTable& rSrcTab, SCTAB nSrcTab, SCCOL nCol1,
840  SCCOL nSrcCol, size_t nTopRow, size_t nEndRow, SCROW nCombinedStartRow,
841  SCROW nRowDestOffset, bool bAsLink, bool bWasCut,
842  const InsertDeleteFlags& nFlags, const bool bIncludeFiltered,
843  std::vector<SCROW>& rFilteredRows)
844  : mrClipTab(rClipTab)
845  , mrSrcTab(rSrcTab)
846  , mnSrcTab(nSrcTab)
847  , mnCol1(nCol1)
848  , mnSrcCol(nSrcCol)
849  , mnTopRow(nTopRow)
850  , mnEndRow(nEndRow)
851  , mnTransRow(nSrcCol - nCol1 + nCombinedStartRow)
852  , mnRowDestOffset(nRowDestOffset)
853  , mbAsLink(bAsLink)
854  , mbWasCut(bWasCut)
855  , mbIncludeFiltered(bIncludeFiltered)
856  , mnFlags(nFlags)
857  {
858  // Create list of filtered rows.
859  if (!mbIncludeFiltered)
860  {
861  for (SCROW curRow = nTopRow; curRow <= static_cast<SCROW>(mnEndRow); ++curRow)
862  {
863  // maybe this loop could be optimized
864  bool bFiltered = mrSrcTab.RowFiltered(curRow, nullptr, nullptr);
865  if (bFiltered)
866  rFilteredRows.push_back(curRow);
867  }
868  }
869  }
870 
871  void operator() (size_t nRow, double fVal)
872  {
873  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
874  if (!mbIncludeFiltered && bFiltered)
875  {
876  mnFilteredRows++;
877  return;
878  }
879 
880  if (mbAsLink)
881  {
882  setLink(nRow);
883  return;
884  }
885 
886  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
887  mrClipTab.SetValue(nTransCol, mnTransRow, fVal);
888  }
889 
890  void operator() (size_t nRow, const svl::SharedString& rStr)
891  {
892  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
893  if (!mbIncludeFiltered && bFiltered)
894  {
895  mnFilteredRows++;
896  return;
897  }
898 
899  if (mbAsLink)
900  {
901  setLink(nRow);
902  return;
903  }
904 
905  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
906  mrClipTab.SetRawString(nTransCol, mnTransRow, rStr);
907  }
908 
909  void operator() (size_t nRow, const EditTextObject* p)
910  {
911  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
912  if (!mbIncludeFiltered && bFiltered)
913  {
914  mnFilteredRows++;
915  return;
916  }
917 
918  if (mbAsLink)
919  {
920  setLink(nRow);
921  return;
922  }
923 
924  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
925  mrClipTab.SetEditText(nTransCol, mnTransRow, ScEditUtil::Clone(*p, mrClipTab.GetDoc()));
926  }
927 
928  void operator() (size_t nRow, const ScFormulaCell* p)
929  {
930  bool bFiltered = mrSrcTab.RowFiltered(nRow, nullptr, nullptr);
931  if (!mbIncludeFiltered && bFiltered)
932  {
933  mnFilteredRows++;
934  return;
935  }
936 
937  if (mbAsLink)
938  {
939  setLink(nRow);
940  return;
941  }
942 
943  ScFormulaCell* pNew = new ScFormulaCell(*p, mrClipTab.GetDoc(),
944  getDestPos(nRow - mnFilteredRows + mnRowDestOffset),
946 
947  // rotate reference
948  // for Cut, the references are later adjusted through UpdateTranspose
949 
950  if (!mbWasCut)
951  pNew->TransposeReference();
952 
953  SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset;
954  mrClipTab.SetFormulaCell(nTransCol, mnTransRow, pNew);
955  }
956 
957  // empty cells
958  void operator()(const int /*type*/, size_t nRow, size_t nDataSize)
959  {
960  for (size_t curRow = nRow; curRow < nRow + nDataSize; ++curRow)
961  {
962  bool bFiltered = mrSrcTab.RowFiltered(curRow, nullptr, nullptr);
963  if (!mbIncludeFiltered && bFiltered)
964  {
965  mnFilteredRows++;
966  continue;
967  }
968 
969  if (mbAsLink && mnFlags == InsertDeleteFlags::ALL)
970  {
971  // with InsertDeleteFlags::ALL, also create links (formulas) for empty cells
972  setLink(nRow);
973  continue;
974  }
975  }
976  }
977 };
978 }
979 
980 void ScTable::TransposeClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
981  SCROW nCombinedStartRow, SCROW nRowDestOffset, ScTable* pTransClip,
982  InsertDeleteFlags nFlags, bool bAsLink, bool bIncludeFiltered)
983 {
984  bool bWasCut = rDocument.IsCutMode();
985 
986  for (SCCOL nCol=nCol1; nCol<=nCol2; nCol++)
987  {
988  std::vector<SCROW> aFilteredRows;
989 
990  TransClipHandler aFunc(*pTransClip, *this, nTab, nCol1, nCol, nRow1, nRow2,
991  nCombinedStartRow, nRowDestOffset, bAsLink, bWasCut, nFlags,
992  bIncludeFiltered, aFilteredRows);
993 
994  const sc::CellStoreType& rCells = aCol[nCol].maCells;
995 
996  // Loop through all rows by iterator and call aFunc operators
997  sc::ParseAll(rCells.begin(), rCells, nRow1, nRow2, aFunc,
998  aFunc);
999 
1000  // Attributes
1001  if (nFlags & InsertDeleteFlags::ATTRIB)
1002  TransposeColPatterns(pTransClip, nCol1, nCol, nRow1, nRow2, nCombinedStartRow,
1003  bIncludeFiltered, aFilteredRows, nRowDestOffset);
1004 
1005  // Cell Notes - fdo#68381 paste cell notes on Transpose
1006  if ((nFlags & InsertDeleteFlags::NOTE) && rDocument.HasColNotes(nCol, nTab))
1007  TransposeColNotes(pTransClip, nCol1, nCol, nRow1, nRow2, nCombinedStartRow,
1008  bIncludeFiltered, nRowDestOffset);
1009  }
1010 }
1011 
1012 static void lcl_SetTransposedPatternInRows(ScTable* pTransClip, SCROW nAttrRow1, SCROW nAttrRow2,
1013  SCCOL nCol1, SCROW nRow1, SCROW nCombinedStartRow, SCCOL nCol,
1014  const ScPatternAttr& rPatternAttr, bool bIncludeFiltered,
1015  const std::vector<SCROW>& rFilteredRows,
1016  SCROW nRowDestOffset)
1017 {
1018  for (SCROW nRow = nAttrRow1; nRow <= nAttrRow2; nRow++)
1019  {
1020  size_t nFilteredRowAdjustment = 0;
1021  if (!bIncludeFiltered)
1022  {
1023  // aFilteredRows is sorted thus lower_bound() can be used.
1024  // lower_bound() has a logarithmic complexity O(log(n))
1025  auto itRow1 = std::lower_bound(rFilteredRows.begin(), rFilteredRows.end(), nRow1);
1026  auto itRow = std::lower_bound(rFilteredRows.begin(), rFilteredRows.end(), nRow);
1027  bool bRefRowIsFiltered = itRow != rFilteredRows.end() && *itRow == nRow;
1028  if (bRefRowIsFiltered)
1029  continue;
1030 
1031  // How many filtered rows are between the formula cell and the reference?
1032  // distance() has a constant complexity O(1) for vectors
1033  nFilteredRowAdjustment = std::distance(itRow1, itRow);
1034  }
1035 
1036  pTransClip->SetPattern(
1037  static_cast<SCCOL>(nCol1 + nRow - nRow1 - nFilteredRowAdjustment + nRowDestOffset),
1038  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), rPatternAttr);
1039  }
1040 }
1041 
1042 void ScTable::TransposeColPatterns(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1,
1043  SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered,
1044  const std::vector<SCROW>& rFilteredRows, SCROW nRowDestOffset)
1045 {
1046  SCROW nAttrRow1 = {}; // spurious -Werror=maybe-uninitialized
1047  SCROW nAttrRow2 = {}; // spurious -Werror=maybe-uninitialized
1048  const ScPatternAttr* pPattern;
1049  std::unique_ptr<ScAttrIterator> pAttrIter(aCol[nCol].CreateAttrIterator( nRow1, nRow2 ));
1050  while ( (pPattern = pAttrIter->Next( nAttrRow1, nAttrRow2 )) != nullptr )
1051  {
1052  if ( !IsDefaultItem( pPattern ) )
1053  {
1054  const SfxItemSet& rSet = pPattern->GetItemSet();
1055  if ( rSet.GetItemState( ATTR_MERGE, false ) == SfxItemState::DEFAULT &&
1056  rSet.GetItemState( ATTR_MERGE_FLAG, false ) == SfxItemState::DEFAULT &&
1057  rSet.GetItemState( ATTR_BORDER, false ) == SfxItemState::DEFAULT )
1058  {
1059  // Set pattern in cells from nAttrRow1 to nAttrRow2
1060  // no borders or merge items involved - use pattern as-is
1061  lcl_SetTransposedPatternInRows(pTransClip, nAttrRow1, nAttrRow2, nCol1, nRow1,
1062  nCombinedStartRow, nCol, *pPattern,
1063  bIncludeFiltered, rFilteredRows, nRowDestOffset);
1064  }
1065  else
1066  {
1067  // transpose borders and merge values, remove merge flags (refreshed after pasting)
1068  ScPatternAttr aNewPattern( *pPattern );
1069  SfxItemSet& rNewSet = aNewPattern.GetItemSet();
1070 
1071  const SvxBoxItem& rOldBox = rSet.Get(ATTR_BORDER);
1072  if ( rOldBox.GetTop() || rOldBox.GetBottom() || rOldBox.GetLeft() || rOldBox.GetRight() )
1073  {
1074  SvxBoxItem aNew( ATTR_BORDER );
1075  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::TOP ), SvxBoxItemLine::LEFT );
1076  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
1077  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
1078  aNew.SetLine( rOldBox.GetLine( SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
1079  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::TOP ), SvxBoxItemLine::LEFT );
1080  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
1081  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
1082  aNew.SetDistance( rOldBox.GetDistance( SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
1083  rNewSet.Put( aNew );
1084  }
1085 
1086  const ScMergeAttr& rOldMerge = rSet.Get(ATTR_MERGE);
1087  if (rOldMerge.IsMerged())
1088  rNewSet.Put( ScMergeAttr( std::min(
1089  static_cast<SCCOL>(rOldMerge.GetRowMerge()),
1090  static_cast<SCCOL>(rDocument.MaxCol()+1 - (nAttrRow2-nRow1))),
1091  std::min(
1092  static_cast<SCROW>(rOldMerge.GetColMerge()),
1093  static_cast<SCROW>(rDocument.MaxRow()+1 - (nCol-nCol1)))));
1094  const ScMergeFlagAttr& rOldFlag = rSet.Get(ATTR_MERGE_FLAG);
1095  if (rOldFlag.IsOverlapped())
1096  {
1097  ScMF nNewFlags = rOldFlag.GetValue() & ~ScMF( ScMF::Hor | ScMF::Ver );
1098  if ( nNewFlags != ScMF::NONE )
1099  rNewSet.Put( ScMergeFlagAttr( nNewFlags ) );
1100  else
1101  rNewSet.ClearItem( ATTR_MERGE_FLAG );
1102  }
1103 
1104  // Set pattern in cells from nAttrRow1 to nAttrRow2
1105  lcl_SetTransposedPatternInRows(pTransClip, nAttrRow1, nAttrRow2, nCol1, nRow1,
1106  nCombinedStartRow, nCol, aNewPattern,
1107  bIncludeFiltered, rFilteredRows, nRowDestOffset);
1108  }
1109  }
1110  }
1111 }
1112 
1113 void ScTable::TransposeColNotes(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1,
1114  SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered,
1115  SCROW nRowDestOffset)
1116 {
1117  sc::CellNoteStoreType::const_iterator itBlk = aCol[nCol].maCellNotes.begin(), itBlkEnd = aCol[nCol].maCellNotes.end();
1118 
1119  // Locate the top row position.
1120  size_t nOffsetInBlock = 0;
1121  size_t nBlockStart = 0, nBlockEnd = 0, nRowPos = static_cast<size_t>(nRow1);
1122  for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd)
1123  {
1124  nBlockEnd = nBlockStart + itBlk->size;
1125  if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
1126  {
1127  // Found.
1128  nOffsetInBlock = nRowPos - nBlockStart;
1129  break;
1130  }
1131  }
1132 
1133  if (itBlk == itBlkEnd)
1134  // Specified range found
1135  return;
1136 
1137  nRowPos = static_cast<size_t>(nRow2); // End row position.
1138  SCCOL nFilteredRows = 0;
1139 
1140  // Keep processing until we hit the end row position.
1141  sc::cellnote_block::const_iterator itData, itDataEnd;
1142  for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd, nOffsetInBlock = 0)
1143  {
1144  nBlockEnd = nBlockStart + itBlk->size;
1145 
1146  if (itBlk->data)
1147  {
1148  itData = sc::cellnote_block::begin(*itBlk->data);
1149  std::advance(itData, nOffsetInBlock);
1150 
1151  // selected area is smaller than the iteration block
1152  if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
1153  {
1154  // This block contains the end row. Only process partially.
1155  size_t nOffsetEnd = nRowPos - nBlockStart + 1;
1156  itDataEnd = sc::cellnote_block::begin(*itBlk->data);
1157  std::advance(itDataEnd, nOffsetEnd);
1158  size_t curRow = nBlockStart + nOffsetInBlock;
1159  for (; itData != itDataEnd; ++itData, ++curRow)
1160  {
1161  bool bFiltered = this->RowFiltered(curRow, nullptr, nullptr);
1162  if (!bIncludeFiltered && bFiltered)
1163  {
1164  nFilteredRows++;
1165  continue;
1166  }
1167 
1168  ScAddress aDestPos(
1169  static_cast<SCCOL>(nCol1 + curRow - nRow1 - nFilteredRows + nRowDestOffset),
1170  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), pTransClip->nTab);
1171  pTransClip->rDocument.ReleaseNote(aDestPos);
1172  ScPostIt* pNote = *itData;
1173  if (pNote)
1174  {
1175  std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), pTransClip->rDocument, aDestPos, true );
1176  pTransClip->rDocument.SetNote(aDestPos, std::move(pClonedNote));
1177  }
1178  }
1179  break; // we reached the last valid block
1180  }
1181  else
1182  {
1183  itDataEnd = sc::cellnote_block::end(*itBlk->data);
1184  size_t curRow = nBlockStart + nOffsetInBlock;
1185  for (; itData != itDataEnd; ++itData, ++curRow)
1186  {
1187  bool bFiltered = this->RowFiltered(curRow, nullptr, nullptr);
1188  if (!bIncludeFiltered && bFiltered)
1189  {
1190  nFilteredRows++;
1191  continue;
1192  }
1193 
1194  ScAddress aDestPos(
1195  static_cast<SCCOL>(nCol1 + curRow - nRow1 - nFilteredRows + nRowDestOffset),
1196  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), pTransClip->nTab);
1197  pTransClip->rDocument.ReleaseNote(aDestPos);
1198  ScPostIt* pNote = *itData;
1199  if (pNote)
1200  {
1201  std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), pTransClip->rDocument, aDestPos, true );
1202  pTransClip->rDocument.SetNote(aDestPos, std::move(pClonedNote));
1203  }
1204  }
1205  }
1206  }
1207  else // remove dest notes for rows without notes
1208  {
1209  for (size_t curRow = nBlockStart + nOffsetInBlock;
1210  curRow <= nBlockEnd && curRow <= nRowPos; ++curRow)
1211  {
1212  bool bFiltered = this->RowFiltered(curRow, nullptr, nullptr);
1213  if (!bIncludeFiltered && bFiltered && curRow < nBlockEnd)
1214  {
1215  nFilteredRows++;
1216  continue;
1217  }
1218 
1219  ScAddress aDestPos(
1220  static_cast<SCCOL>(nCol1 + curRow - nRow1 - nFilteredRows + nRowDestOffset),
1221  static_cast<SCROW>(nCombinedStartRow + nCol - nCol1), pTransClip->nTab);
1222  pTransClip->rDocument.ReleaseNote(aDestPos);
1223  }
1224  }
1225  }
1226 }
1227 
1229 {
1230  if (!ValidCol(nCol))
1231  return nullptr;
1232 
1233  return &CreateColumnIfNotExists(nCol);
1234 }
1235 
1237 {
1238  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1239  return nullptr;
1240 
1241  return &aCol[nCol];
1242 }
1243 
1245 {
1246  std::shared_ptr<const sc::ColumnSet> pColSet = rCxt.getColumnSet();
1247  if (!pColSet)
1248  {
1249  for (SCCOL i=0; i < aCol.size(); i++)
1250  aCol[i].StartListeners(rCxt, bAll);
1251  }
1252  else if (pColSet->hasTab( nTab))
1253  {
1254  std::vector<SCCOL> aColumns;
1255  pColSet->getColumns( nTab, aColumns);
1256  for (auto i : aColumns)
1257  {
1258  if (0 <= i && i < aCol.size())
1259  aCol[i].StartListeners(rCxt, bAll);
1260  }
1261  }
1262 }
1263 
1265  sc::StartListeningContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1266 {
1267  nCol2 = ClampToAllocatedColumns(nCol2);
1268  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1269  aCol[nCol].AttachFormulaCells(rCxt, nRow1, nRow2);
1270 }
1271 
1273  sc::EndListeningContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1274 {
1275  nCol2 = ClampToAllocatedColumns(nCol2);
1276  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
1277  aCol[nCol].DetachFormulaCells(rCxt, nRow1, nRow2, nullptr);
1278 }
1279 
1281  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, sc::ColumnSpanSet& rBroadcastSpans )
1282 {
1283  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1284  if (nCol2 > rDocument.MaxCol()) nCol2 = rDocument.MaxCol();
1285  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
1286  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
1287  for (SCCOL i = nCol1; i <= nCol2; i++)
1288  aCol[i].SetDirtyFromClip(nRow1, nRow2, rBroadcastSpans);
1289 }
1290 
1293  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
1294 {
1295  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1296  if (nCol2 > rDocument.MaxCol()) nCol2 = rDocument.MaxCol();
1297  if (nRow2 > rDocument.MaxRow()) nRow2 = rDocument.MaxRow();
1298  if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
1299  for (SCCOL i = nCol1; i <= nCol2; i++)
1300  aCol[i].StartListeningFormulaCells(rStartCxt, rEndCxt, nRow1, nRow2);
1301 }
1302 
1304  sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1305  InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab, const ScMarkData* pMarkData,
1306  bool bAsLink, bool bColRowFlags, bool bGlobalNamesToLocal, bool bCopyCaptions )
1307 {
1308  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
1309  return;
1310 
1311  bool bIsUndoDoc = pDestTab->rDocument.IsUndo();
1312 
1313  if (bIsUndoDoc && (nFlags & InsertDeleteFlags::CONTENTS))
1314  {
1315  // Copying formulas may create sheet-local named expressions on the
1316  // destination sheet. Add existing to Undo first.
1317  pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( *GetRangeName())));
1318  }
1319 
1320  if (nFlags != InsertDeleteFlags::NONE)
1321  {
1322  InsertDeleteFlags nTempFlags( nFlags &
1324  // tdf#102364 - in some pathological cases CopyToTable() replacing cells with new cells
1325  // can lead to repetitive splitting and rejoining of the same formula group, which can get
1326  // quadratically expensive with large groups. So do the grouping just once at the end.
1327  sc::DelayFormulaGroupingSwitch delayGrouping( pDestTab->rDocument, true );
1328  for (SCCOL i = nCol1; i <= ClampToAllocatedColumns(nCol2); i++)
1329  aCol[i].CopyToColumn(rCxt, nRow1, nRow2, bIsUndoDoc ? nFlags : nTempFlags, bMarked,
1330  pDestTab->CreateColumnIfNotExists(i), pMarkData, bAsLink, bGlobalNamesToLocal);
1331  }
1332 
1333  if (!bColRowFlags) // Column widths/Row heights/Flags
1334  return;
1335 
1336  if(bIsUndoDoc && (nFlags & InsertDeleteFlags::ATTRIB))
1337  {
1338  pDestTab->mpCondFormatList.reset(new ScConditionalFormatList(pDestTab->rDocument, *mpCondFormatList));
1339  }
1340 
1341  if (pDBDataNoName)
1342  {
1343  std::unique_ptr<ScDBData> pNewDBData(new ScDBData(*pDBDataNoName));
1344  SCCOL aCol1, aCol2;
1345  SCROW aRow1, aRow2;
1346  SCTAB aTab;
1347  pNewDBData->GetArea(aTab, aCol1, aRow1, aCol2, aRow2);
1348  pNewDBData->MoveTo(pDestTab->nTab, aCol1, aRow1, aCol2, aRow2);
1349  pDestTab->SetAnonymousDBData(std::move(pNewDBData));
1350  }
1351  // Charts have to be adjusted when hide/show
1353 
1354  bool bFlagChange = false;
1355 
1356  bool bWidth = (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pDestTab->mpColWidth);
1357  bool bHeight = (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pDestTab->mpRowHeights);
1358 
1359  if (bWidth || bHeight)
1360  {
1361  if (bWidth)
1362  {
1363  auto destTabColWidthIt = pDestTab->mpColWidth->begin() + nCol1;
1364  auto thisTabColWidthIt = mpColWidth->begin() + nCol1;
1365  pDestTab->mpColWidth->CopyFrom(*mpColWidth, nCol1, nCol2);
1366  pDestTab->mpColFlags->CopyFrom(*mpColFlags, nCol1, nCol2);
1367  for (SCCOL i = nCol1; i <= nCol2; ++i)
1368  {
1369  bool bThisHidden = ColHidden(i);
1370  bool bHiddenChange = (pDestTab->ColHidden(i) != bThisHidden);
1371  bool bChange = bHiddenChange || (*destTabColWidthIt != *thisTabColWidthIt);
1372  pDestTab->SetColHidden(i, i, bThisHidden);
1373  //TODO: collect changes?
1374  if (bHiddenChange && pCharts)
1375  pCharts->SetRangeDirty(ScRange( i, 0, nTab, i, rDocument.MaxRow(), nTab ));
1376 
1377  if (bChange)
1378  bFlagChange = true;
1379 
1380  ++destTabColWidthIt;
1381  ++thisTabColWidthIt;
1382  }
1384  }
1385 
1386  if (bHeight)
1387  {
1388  bool bChange = pDestTab->GetRowHeight(nRow1, nRow2) != GetRowHeight(nRow1, nRow2);
1389 
1390  if (bChange)
1391  bFlagChange = true;
1392 
1393  pDestTab->CopyRowHeight(*this, nRow1, nRow2, 0);
1394  pDestTab->pRowFlags->CopyFrom(*pRowFlags, nRow1, nRow2);
1395 
1396  // Hidden flags.
1397  for (SCROW i = nRow1; i <= nRow2; ++i)
1398  {
1399  SCROW nLastRow;
1400  bool bHidden = RowHidden(i, nullptr, &nLastRow);
1401  if (nLastRow >= nRow2)
1402  // the last row shouldn't exceed the upper bound the caller specified.
1403  nLastRow = nRow2;
1404 
1405  bool bHiddenChanged = pDestTab->SetRowHidden(i, nLastRow, bHidden);
1406  if (bHiddenChanged && pCharts)
1407  // Hidden flags differ.
1408  pCharts->SetRangeDirty(ScRange(0, i, nTab, rDocument.MaxCol(), nLastRow, nTab));
1409 
1410  if (bHiddenChanged)
1411  bFlagChange = true;
1412 
1413  // Jump to the last row of the identical flag segment.
1414  i = nLastRow;
1415  }
1416 
1417  // Filtered flags.
1418  for (SCROW i = nRow1; i <= nRow2; ++i)
1419  {
1420  SCROW nLastRow;
1421  bool bFiltered = RowFiltered(i, nullptr, &nLastRow);
1422  if (nLastRow >= nRow2)
1423  // the last row shouldn't exceed the upper bound the caller specified.
1424  nLastRow = nRow2;
1425  pDestTab->SetRowFiltered(i, nLastRow, bFiltered);
1426  i = nLastRow;
1427  }
1429  }
1430  }
1431 
1432  if (bFlagChange)
1433  pDestTab->InvalidatePageBreaks();
1434 
1435  if(nFlags & InsertDeleteFlags::ATTRIB)
1436  {
1437  pDestTab->mpCondFormatList->DeleteArea(nCol1, nRow1, nCol2, nRow2);
1438  pDestTab->CopyConditionalFormat(nCol1, nRow1, nCol2, nRow2, 0, 0, this);
1439  }
1440 
1441  if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags
1442  pDestTab->SetOutlineTable( pOutlineTable.get() );
1443 
1444  if (!bIsUndoDoc && bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES)))
1445  {
1446  bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE;
1447  CopyCaptionsToTable( nCol1, nRow1, nCol2, nRow2, pDestTab, bCloneCaption);
1448  }
1449 }
1450 
1451 void ScTable::CopyCaptionsToTable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab,
1452  bool bCloneCaption )
1453 {
1454  if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
1455  return;
1456 
1457  nCol2 = ClampToAllocatedColumns(nCol2);
1458  for (SCCOL i = nCol1; i <= nCol2; i++)
1459  {
1460  aCol[i].CopyCellNotesToDocument(nRow1, nRow2, pDestTab->CreateColumnIfNotExists(i), bCloneCaption);
1461  pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2);
1462  }
1463 }
1464 
1466  sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1467  InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab )
1468 {
1469  if (!(ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2)))
1470  return;
1471 
1472  bool bWidth = (nRow1==0 && nRow2==rDocument.MaxRow() && mpColWidth && pDestTab->mpColWidth);
1473  bool bHeight = (nCol1==0 && nCol2==rDocument.MaxCol() && mpRowHeights && pDestTab->mpRowHeights);
1474 
1475  if ((nFlags & InsertDeleteFlags::CONTENTS) && mpRangeName)
1476  {
1477  // Undo sheet-local named expressions created during copying
1478  // formulas. If mpRangeName is not set then the Undo wasn't even
1479  // set to an empty ScRangeName map so don't "undo" that.
1480  pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( *GetRangeName())));
1481  if (!pDestTab->rDocument.IsClipOrUndo())
1482  {
1483  ScDocShell* pDocSh = static_cast<ScDocShell*>(pDestTab->rDocument.GetDocumentShell());
1484  if (pDocSh)
1485  pDocSh->SetAreasChangedNeedBroadcast();
1486  }
1487 
1488  }
1489 
1490  for ( SCCOL i = 0; i < aCol.size(); i++)
1491  {
1492  auto& rDestCol = pDestTab->CreateColumnIfNotExists(i);
1493  if ( i >= nCol1 && i <= nCol2 )
1494  aCol[i].UndoToColumn(rCxt, nRow1, nRow2, nFlags, bMarked, rDestCol);
1495  else
1496  aCol[i].CopyToColumn(rCxt, 0, rDocument.MaxRow(), InsertDeleteFlags::FORMULA, false, rDestCol);
1497  }
1498 
1499  if (nFlags & InsertDeleteFlags::ATTRIB)
1500  pDestTab->mpCondFormatList.reset(new ScConditionalFormatList(pDestTab->rDocument, *mpCondFormatList));
1501 
1502  if (!(bWidth||bHeight))
1503  return;
1504 
1505  if (bWidth)
1506  {
1507  pDestTab->mpColWidth->CopyFrom(*mpColWidth, nCol1, nCol2);
1509  }
1510  if (bHeight)
1511  {
1512  pDestTab->CopyRowHeight(*this, nRow1, nRow2, 0);
1514  }
1515 }
1516 
1517 void ScTable::CopyUpdated( const ScTable* pPosTab, ScTable* pDestTab ) const
1518 {
1519  pPosTab->CreateColumnIfNotExists(aCol.size()-1);
1520  pDestTab->CreateColumnIfNotExists(aCol.size()-1);
1521  for (SCCOL i=0; i < aCol.size(); i++)
1522  aCol[i].CopyUpdated( pPosTab->aCol[i], pDestTab->aCol[i] );
1523 }
1524 
1526 {
1527  bTableAreaValid = false;
1528 }
1529 
1531 {
1532  mbPageBreaksValid = false;
1533 }
1534 
1535 void ScTable::CopyScenarioTo( const ScTable* pDestTab ) const
1536 {
1537  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1538 
1539  for (SCCOL i=0; i < aCol.size(); i++)
1541 }
1542 
1543 void ScTable::CopyScenarioFrom( const ScTable* pSrcTab )
1544 {
1545  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1546 
1547  SCCOL nEndCol = pSrcTab->aCol.size();
1548  CreateColumnIfNotExists(nEndCol);
1549  for (SCCOL i=0; i < nEndCol; i++)
1550  aCol[i].CopyScenarioFrom( pSrcTab->aCol[i] );
1551 }
1552 
1553 void ScTable::MarkScenarioIn( ScMarkData& rDestMark, ScScenarioFlags nNeededBits ) const
1554 {
1555  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1556 
1557  if ( ( nScenarioFlags & nNeededBits ) != nNeededBits ) // Are all Bits set?
1558  return;
1559 
1560  for (SCCOL i=0; i < aCol.size(); i++)
1561  aCol[i].MarkScenarioIn( rDestMark );
1562 }
1563 
1564 bool ScTable::HasScenarioRange( const ScRange& rRange ) const
1565 {
1566  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1567 
1568  ScRange aTabRange = rRange;
1569  aTabRange.aStart.SetTab( nTab );
1570  aTabRange.aEnd.SetTab( nTab );
1571 
1572  const ScRangeList* pList = GetScenarioRanges();
1573 
1574  if (pList)
1575  {
1576  for ( size_t j = 0, n = pList->size(); j < n; j++ )
1577  {
1578  const ScRange & rR = (*pList)[j];
1579  if ( rR.Intersects( aTabRange ) )
1580  return true;
1581  }
1582  }
1583 
1584  return false;
1585 }
1586 
1588 {
1589  pScenarioRanges.reset();
1590 }
1591 
1593 {
1594  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1595 
1596  if (!pScenarioRanges)
1597  {
1598  const_cast<ScTable*>(this)->pScenarioRanges.reset(new ScRangeList);
1599  ScMarkData aMark(rDocument.GetSheetLimits());
1600  MarkScenarioIn( aMark, ScScenarioFlags::NONE ); // always
1601  aMark.FillRangeListWithMarks( pScenarioRanges.get(), false );
1602  }
1603  return pScenarioRanges.get();
1604 }
1605 
1606 bool ScTable::TestCopyScenarioTo( const ScTable* pDestTab ) const
1607 {
1608  OSL_ENSURE( bScenario, "bScenario == FALSE" );
1609 
1610  if (!pDestTab->IsProtected())
1611  return true;
1612 
1613  bool bOk = true;
1614  for (SCCOL i=0; i < aCol.size() && bOk; i++)
1615  bOk = aCol[i].TestCopyScenarioTo( pDestTab->aCol[i] );
1616  return bOk;
1617 }
1618 
1619 bool ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const OUString& rString,
1620  const ScSetStringParam * pParam )
1621 {
1622  if (!ValidColRow(nCol,nRow))
1623  {
1624  return false;
1625  }
1626 
1627  return CreateColumnIfNotExists(nCol).SetString(
1628  nRow, nTabP, rString, rDocument.GetAddressConvention(), pParam);
1629 }
1630 
1631 bool ScTable::SetEditText( SCCOL nCol, SCROW nRow, std::unique_ptr<EditTextObject> pEditText )
1632 {
1633  if (!ValidColRow(nCol, nRow))
1634  {
1635  return false;
1636  }
1637 
1638  CreateColumnIfNotExists(nCol).SetEditText(nRow, std::move(pEditText));
1639  return true;
1640 }
1641 
1642 void ScTable::SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
1643 {
1644  if (!ValidColRow(nCol, nRow))
1645  return;
1646 
1647  CreateColumnIfNotExists(nCol).SetEditText(nRow, rEditText, pEditPool);
1648 }
1649 
1650 SCROW ScTable::GetFirstEditTextRow( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
1651 {
1652  if (!ValidCol(nCol1) || !ValidCol(nCol2) || nCol2 < nCol1)
1653  return -1;
1654 
1655  if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow2 < nRow1)
1656  return -1;
1657 
1658  nCol2 = ClampToAllocatedColumns(nCol2);
1659  SCROW nFirst = rDocument.MaxRow()+1;
1660  for (SCCOL i = nCol1; i <= nCol2; ++i)
1661  {
1662  const ScColumn& rCol = aCol[i];
1663  SCROW nThisFirst = -1;
1664  if (const_cast<ScColumn&>(rCol).HasEditCells(nRow1, nRow2, nThisFirst))
1665  {
1666  if (nThisFirst == nRow1)
1667  return nRow1;
1668 
1669  if (nThisFirst < nFirst)
1670  nFirst = nThisFirst;
1671  }
1672  }
1673 
1674  return nFirst == (rDocument.MaxRow()+1) ? -1 : nFirst;
1675 }
1676 
1678 {
1679  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1680  return;
1681 
1682  aCol[nCol].Delete(nRow);
1683 }
1684 
1686  SCCOL nCol, SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
1687 {
1688  if (!ValidColRow(nCol, nRow))
1689  return;
1690 
1691  CreateColumnIfNotExists(nCol).SetFormula(nRow, rArray, eGram);
1692 }
1693 
1695  SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
1696 {
1697  if (!ValidColRow(nCol, nRow))
1698  return;
1699 
1700  CreateColumnIfNotExists(nCol).SetFormula(nRow, rFormula, eGram);
1701 }
1702 
1704 {
1705  if (!ValidColRow(nCol, nRow))
1706  {
1707  delete pCell;
1708  return nullptr;
1709  }
1710 
1712 }
1713 
1714 bool ScTable::SetFormulaCells( SCCOL nCol, SCROW nRow, std::vector<ScFormulaCell*>& rCells )
1715 {
1716  if (!ValidCol(nCol))
1717  return false;
1718 
1719  return CreateColumnIfNotExists(nCol).SetFormulaCells(nRow, rCells);
1720 }
1721 
1723 {
1724  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1725  return svl::SharedString();
1726 
1727  return aCol[nCol].GetSharedString(nRow);
1728 }
1729 
1730 void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
1731 {
1732  if (ValidColRow(nCol, nRow))
1733  CreateColumnIfNotExists(nCol).SetValue(nRow, rVal);
1734 }
1735 
1736 void ScTable::SetRawString( SCCOL nCol, SCROW nRow, const svl::SharedString& rStr )
1737 {
1738  if (ValidColRow(nCol, nRow))
1739  CreateColumnIfNotExists(nCol).SetRawString(nRow, rStr);
1740 }
1741 
1742 void ScTable::GetString( SCCOL nCol, SCROW nRow, OUString& rString, const ScInterpreterContext* pContext ) const
1743 {
1744  if (ValidColRow(nCol,nRow) && nCol < GetAllocatedColumnsCount())
1745  aCol[nCol].GetString( nRow, rString, pContext );
1746  else
1747  rString.clear();
1748 }
1749 
1750 double* ScTable::GetValueCell( SCCOL nCol, SCROW nRow )
1751 {
1752  if (!ValidColRow(nCol, nRow))
1753  return nullptr;
1754 
1755  return CreateColumnIfNotExists(nCol).GetValueCell(nRow);
1756 }
1757 
1758 void ScTable::GetInputString( SCCOL nCol, SCROW nRow, OUString& rString ) const
1759 {
1760  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1761  aCol[nCol].GetInputString( nRow, rString );
1762  else
1763  rString.clear();
1764 }
1765 
1766 double ScTable::GetValue( SCCOL nCol, SCROW nRow ) const
1767 {
1768  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1769  return aCol[nCol].GetValue( nRow );
1770  return 0.0;
1771 }
1772 
1774 {
1775  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1776  return nullptr;
1777 
1778  return aCol[nCol].GetEditText(nRow);
1779 }
1780 
1782 {
1783  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1784  return;
1785 
1786  return aCol[nCol].RemoveEditTextCharAttribs(nRow, rAttr);
1787 }
1788 
1789 void ScTable::GetFormula( SCCOL nCol, SCROW nRow, OUString& rFormula ) const
1790 {
1791  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1792  aCol[nCol].GetFormula( nRow, rFormula );
1793  else
1794  rFormula.clear();
1795 }
1796 
1798 {
1799  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1800  return nullptr;
1801 
1802  return aCol[nCol].GetFormulaCell(nRow);
1803 }
1804 
1806 {
1807  if (!ValidColRow(nCol, nRow))
1808  return nullptr;
1809  return CreateColumnIfNotExists(nCol).GetFormulaCell(nRow);
1810 }
1811 
1812 std::unique_ptr<ScPostIt> ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
1813 {
1814  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1815  return nullptr;
1816 
1817  return aCol[nCol].ReleaseNote(nRow);
1818 }
1819 
1820 size_t ScTable::GetNoteCount( SCCOL nCol ) const
1821 {
1822  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1823  return 0;
1824 
1825  return aCol[nCol].GetNoteCount();
1826 }
1827 
1828 SCROW ScTable::GetNotePosition( SCCOL nCol, size_t nIndex ) const
1829 {
1830  if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
1831  return -1;
1832 
1833  return aCol[nCol].GetNotePosition(nIndex);
1834 }
1835 
1837 {
1838  for (SCCOL i = 0; i < aCol.size(); ++i)
1840 }
1841 
1842 void ScTable::ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bPreserveData )
1843 {
1844  if (!ValidCol(nCol1) || !ValidCol(nCol2))
1845  return;
1846  if ( nCol2 >= aCol.size() ) nCol2 = aCol.size() - 1;
1847  for (SCCOL i = nCol1; i <= nCol2; ++i)
1848  aCol[i].ForgetNoteCaptions(nRow1, nRow2, bPreserveData);
1849 }
1850 
1851 void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
1852 {
1853  for (SCCOL nCol = 0; nCol < aCol.size(); ++nCol)
1854  aCol[nCol].GetAllNoteEntries(rNotes);
1855 }
1856 
1857 void ScTable::GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const
1858 {
1859  SCROW nStartRow = rRange.aStart.Row();
1860  SCROW nEndRow = rRange.aEnd.Row();
1861  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
1862  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1863  {
1864  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1865  }
1866 }
1867 
1868 CommentCaptionState ScTable::GetAllNoteCaptionsState(const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes )
1869 {
1870  SCROW nStartRow = rRange.aStart.Row();
1871  SCROW nEndRow = rRange.aEnd.Row();
1872  bool bIsFirstNoteShownState = true; // because of error: -Werror=maybe-uninitialized
1873  bool bFirstControl = true;
1874 
1875  ScTable* pTab = rDocument.FetchTable(nTab);
1876  assert(pTab);
1877  const SCCOL nEndCol = pTab->ClampToAllocatedColumns(rRange.aEnd.Col());
1878  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1879  {
1880  if (bFirstControl && rDocument.HasColNotes(nCol, nTab)) // detect status of first note caption
1881  {
1882  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1883  bIsFirstNoteShownState = rNotes.begin()->mpNote->IsCaptionShown();
1884  bFirstControl = false;
1885  }
1886 
1887  if (rDocument.HasColNotes(nCol, nTab))
1888  {
1889  aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
1890 
1891  bool bIsMixedState = std::any_of(rNotes.begin(), rNotes.end(), [bIsFirstNoteShownState](const sc::NoteEntry& rNote) {
1892  // compare the first note caption with others
1893  return bIsFirstNoteShownState != rNote.mpNote->IsCaptionShown(); });
1894  if (bIsMixedState)
1896  }
1897  }
1898  return bIsFirstNoteShownState ? CommentCaptionState::ALLSHOWN : CommentCaptionState::ALLHIDDEN;
1899 }
1900 
1902 {
1903  for (auto const & pCol : aCol)
1904  pCol->GetUnprotectedCells(0, rDocument.MaxRow(), rRangeList);
1905 }
1906 
1907 bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const
1908 {
1909  SCROW nStartRow = rRange.aStart.Row();
1910  SCROW nEndRow = rRange.aEnd.Row();
1911  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
1912  for (SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; ++nCol)
1913  {
1914  bool bContainsNote = !aCol[nCol].IsNotesEmptyBlock(nStartRow, nEndRow);
1915  if(bContainsNote)
1916  return true;
1917  }
1918 
1919  return false;
1920 }
1921 
1923 {
1924  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1925  return aCol[nCol].GetCellType( nRow );
1926  return CELLTYPE_NONE;
1927 }
1928 
1930 {
1931  if (!ValidColRow(nCol, nRow) || nCol >= GetAllocatedColumnsCount())
1932  return ScRefCellValue();
1933 
1934  return aCol[nCol].GetCellValue(nRow);
1935 }
1936 
1937 void ScTable::GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const
1938 {
1939  rCol = 0;
1940  rRow = rDocument.MaxRow()+1;
1941  while (rCol < (aCol.size() - 1) && aCol[rCol].IsEmptyData() )
1942  ++rCol;
1943  SCCOL nCol = rCol;
1944  while (nCol < aCol.size() && rRow > 0)
1945  {
1946  if (!aCol[nCol].IsEmptyData())
1947  rRow = ::std::min( rRow, aCol[nCol].GetFirstDataPos());
1948  ++nCol;
1949  }
1950 }
1951 
1952 void ScTable::GetLastDataPos(SCCOL& rCol, SCROW& rRow) const
1953 {
1954  rCol = aCol.size() - 1;
1955  rRow = 0;
1956  while (aCol[rCol].IsEmptyData() && (rCol > 0))
1957  rCol--;
1958  SCCOL nCol = rCol;
1959  while (nCol >= 0 && rRow < rDocument.MaxRow())
1960  rRow = ::std::max( rRow, aCol[nCol--].GetLastDataPos());
1961 }
1962 
1963 bool ScTable::HasData( SCCOL nCol, SCROW nRow ) const
1964 {
1965  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1966  return aCol[nCol].HasDataAt( nRow );
1967  else
1968  return false;
1969 }
1970 
1971 bool ScTable::HasStringData( SCCOL nCol, SCROW nRow ) const
1972 {
1973  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1974  return aCol[nCol].HasStringData( nRow );
1975  else
1976  return false;
1977 }
1978 
1979 bool ScTable::HasValueData( SCCOL nCol, SCROW nRow ) const
1980 {
1981  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
1982  return aCol[nCol].HasValueData( nRow );
1983  else
1984  return false;
1985 }
1986 
1987 bool ScTable::HasStringCells( SCCOL nStartCol, SCROW nStartRow,
1988  SCCOL nEndCol, SCROW nEndRow ) const
1989 {
1990  if (ValidCol(nEndCol))
1991  {
1992  nEndCol = ClampToAllocatedColumns(nEndCol);
1993  for (SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++)
1994  if (aCol[nCol].HasStringCells(nStartRow, nEndRow))
1995  return true;
1996  }
1997 
1998  return false;
1999 }
2000 
2002 {
2003  for (SCCOL i=0; i < aCol.size(); i++)
2004  aCol[i].SetDirtyVar();
2005 }
2006 
2008 {
2009  sc::AutoCalcSwitch aACSwitch(rDocument, false);
2010 
2011  for (SCCOL i = 0; i < aCol.size(); i++)
2013 }
2014 
2016 {
2017  sc::AutoCalcSwitch aACSwitch(rDocument, false);
2018 
2019  for (SCCOL i=0; i < aCol.size(); i++)
2020  aCol[i].SetAllFormulasDirty(rCxt);
2021 }
2022 
2024 {
2025  bool bOldAutoCalc = rDocument.GetAutoCalc();
2026  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
2027  SCCOL nCol2 = rRange.aEnd.Col();
2028  nCol2 = ClampToAllocatedColumns(nCol2);
2029  for (SCCOL i=rRange.aStart.Col(); i<=nCol2; i++)
2030  aCol[i].SetDirty(rRange.aStart.Row(), rRange.aEnd.Row(), eMode);
2031  rDocument.SetAutoCalc( bOldAutoCalc );
2032 }
2033 
2034 void ScTable::SetTableOpDirty( const ScRange& rRange )
2035 {
2036  bool bOldAutoCalc = rDocument.GetAutoCalc();
2037  rDocument.SetAutoCalc( false ); // no multiple recalculation
2038  const SCCOL nCol2 = ClampToAllocatedColumns(rRange.aEnd.Col());
2039  for (SCCOL i=rRange.aStart.Col(); i<=nCol2; i++)
2040  aCol[i].SetTableOpDirty( rRange );
2041  rDocument.SetAutoCalc( bOldAutoCalc );
2042 }
2043 
2045 {
2046  bool bOldAutoCalc = rDocument.GetAutoCalc();
2047  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
2048  for (SCCOL i=0; i < aCol.size(); i++)
2050  rDocument.SetAutoCalc( bOldAutoCalc );
2051 }
2052 
2054 {
2055  bool bOldAutoCalc = rDocument.GetAutoCalc();
2056  rDocument.SetAutoCalc( false ); // avoid multiple recalculations
2057  for (SCCOL i=0; i < aCol.size(); i++)
2059  rDocument.SetAutoCalc( bOldAutoCalc );
2060 }
2061 
2063 {
2064  sc::AutoCalcSwitch aSwitch(rDocument, false);
2065  for (SCCOL i = 0; i < aCol.size(); ++i)
2067 }
2068 
2069 bool ScTable::BroadcastBroadcasters( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScHint& rHint )
2070 {
2071  bool bBroadcasted = false;
2072  sc::AutoCalcSwitch aSwitch(rDocument, false);
2073  rHint.GetAddress().SetTab(nTab);
2074  nCol2 = ClampToAllocatedColumns(nCol2);
2075  for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
2076  bBroadcasted |= aCol[nCol].BroadcastBroadcasters( nRow1, nRow2, rHint);
2077  return bBroadcasted;
2078 }
2079 
2080 void ScTable::SetLoadingMedium(bool bLoading)
2081 {
2082  mpRowHeights->enableTreeSearch(!bLoading);
2083 }
2084 
2086 {
2087  for (SCCOL i=0; i < aCol.size(); i++)
2088  aCol[i].CalcAll();
2089 
2090  mpCondFormatList->CalcAll();
2091 }
2092 
2094 {
2095  for (SCCOL i = 0; i < aCol.size(); ++i)
2096  aCol[i].CompileAll(rCxt);
2097 
2098  if(mpCondFormatList)
2099  mpCondFormatList->CompileAll();
2100 }
2101 
2103 {
2104  if (mpRangeName)
2105  mpRangeName->CompileUnresolvedXML(rCxt);
2106 
2107  for (SCCOL i=0; i < aCol.size(); i++)
2108  {
2109  aCol[i].CompileXML(rCxt, rProgress);
2110  }
2111 
2112  if(mpCondFormatList)
2113  mpCondFormatList->CompileXML();
2114 }
2115 
2117 {
2118  bool bCompiled = false;
2119  for (SCCOL i = 0; i < aCol.size(); ++i)
2120  {
2121  if (aCol[i].CompileErrorCells(rCxt, nErrCode))
2122  bCompiled = true;
2123  }
2124 
2125  return bCompiled;
2126 }
2127 
2128 void ScTable::CalcAfterLoad( sc::CompileFormulaContext& rCxt, bool bStartListening )
2129 {
2130  for (SCCOL i = 0; i < aCol.size(); ++i)
2131  aCol[i].CalcAfterLoad(rCxt, bStartListening);
2132 }
2133 
2134 void ScTable::ResetChanged( const ScRange& rRange )
2135 {
2136  SCCOL nStartCol = rRange.aStart.Col();
2137  SCROW nStartRow = rRange.aStart.Row();
2138  SCCOL nEndCol = ClampToAllocatedColumns(rRange.aEnd.Col());
2139  SCROW nEndRow = rRange.aEnd.Row();
2140 
2141  for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
2142  aCol[nCol].ResetChanged(nStartRow, nEndRow);
2143 }
2144 
2145 // Attribute
2146 
2147 const SfxPoolItem* ScTable::GetAttr( SCCOL nCol, SCROW nRow, sal_uInt16 nWhich ) const
2148 {
2149  if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
2150  return &aCol[nCol].GetAttr( nRow, nWhich );
2151  else
2152  return nullptr;
2153 }
2154 
2155 sal_uInt32 ScTable::GetNumberFormat( const ScInterpreterContext& rContext, const ScAddress& rPos ) const
2156 {
2157  if (ValidColRow(rPos.Col(), rPos.Row()))
2158  {
2159  if (rPos.Col() < GetAllocatedColumnsCount())
2160  return aCol[rPos.Col()].GetNumberFormat(rContext, rPos.Row());
2161  return aDefaultColAttrArray.GetPattern(rPos.Row())
2162  ->GetNumberFormat(rContext.GetFormatTable());
2163  }
2164  return 0;
2165 }
2166 
2167 sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
2168 {
2169  if (ValidColRow(nCol,nRow))
2170  return CreateColumnIfNotExists(nCol).GetNumberFormat(rDocument.GetNonThreadedContext(), nRow);
2171  else
2172  return 0;
2173 }
2174 
2175 sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
2176 {
2177  if (!ValidCol(nCol) || !ValidRow(nStartRow) || !ValidRow(nEndRow))
2178  return 0;
2179 
2180  return CreateColumnIfNotExists(nCol).GetNumberFormat(nStartRow, nEndRow);
2181 }
2182 
2183 void ScTable::SetNumberFormat( SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat )
2184 {
2185  if (!ValidColRow(nCol, nRow))
2186  return;
2187 
2188  CreateColumnIfNotExists(nCol).SetNumberFormat(nRow, nNumberFormat);
2189 }
2190 
2191 const ScPatternAttr* ScTable::GetPattern( SCCOL nCol, SCROW nRow ) const
2192 {
2193  if (ValidColRow(nCol,nRow))
2194  return CreateColumnIfNotExists(nCol).GetPattern( nRow );
2195  else
2196  {
2197  OSL_FAIL("wrong column or row");
2198  return rDocument.GetDefPattern(); // for safety
2199  }
2200 }
2201 
2202 const ScPatternAttr* ScTable::GetMostUsedPattern( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
2203 {
2204  if ( ValidColRow( nCol, nStartRow ) && ValidRow( nEndRow ) && (nStartRow <= nEndRow)
2205  && nCol < GetAllocatedColumnsCount())
2206  return aCol[nCol].GetMostUsedPattern( nStartRow, nEndRow );
2207  else
2208  return nullptr;
2209 }
2210 
2211 bool ScTable::HasAttrib( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, HasAttrFlags nMask ) const
2212 {
2213  if ( nCol1 >= aCol.size() )
2214  return false;
2215  if ( nCol2 >= aCol.size() )
2216  nCol2 = aCol.size() - 1; // Rows above range, doesn't contains flags
2217 
2218  bool bFound = false;
2219  for (SCCOL i=nCol1; i<=nCol2 && !bFound; i++)
2220  bFound |= aCol[i].HasAttrib( nRow1, nRow2, nMask );
2221  return bFound;
2222 }
2223 
2224 bool ScTable::HasAttribSelection( const ScMarkData& rMark, HasAttrFlags nMask ) const
2225 {
2226  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2227 
2228  for (const sc::ColRowSpan & aSpan : aSpans)
2229  {
2230  for (SCCOLROW j = aSpan.mnStart; j <= aSpan.mnEnd; ++j)
2231  {
2232  if (aCol[j].HasAttribSelection(rMark, nMask))
2233  return true;
2234  }
2235  }
2236  return false;
2237 }
2238 
2239 bool ScTable::ExtendMerge( SCCOL nStartCol, SCROW nStartRow,
2240  SCCOL& rEndCol, SCROW& rEndRow,
2241  bool bRefresh )
2242 {
2243  if (!(ValidCol(nStartCol) && ValidCol(rEndCol)))
2244  {
2245  OSL_FAIL("ScTable::ExtendMerge: invalid column number");
2246  return false;
2247  }
2248  if ( nStartCol >= aCol.size() )
2249  {
2250  OSL_FAIL("ScTable::ExtendMerge: invalid nStartCol");
2251  return false;
2252  }
2253  bool bFound = false;
2254  SCCOL nOldEndX = std::min( rEndCol, static_cast<SCCOL>(aCol.size()-1) );
2255  SCROW nOldEndY = rEndRow;
2256  for (SCCOL i=nStartCol; i<=nOldEndX; i++)
2257  bFound |= aCol[i].ExtendMerge( i, nStartRow, nOldEndY, rEndCol, rEndRow, bRefresh );
2258  return bFound;
2259 }
2260 
2261 void ScTable::SetMergedCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
2262 {
2263  ScMergeAttr aAttr(nCol2-nCol1+1, nRow2-nRow1+1);
2264  ApplyAttr(nCol1, nRow1, aAttr);
2265 
2266  if (nCol1 < nCol2)
2267  ApplyFlags(nCol1+1, nRow1, nCol2, nRow2, ScMF::Hor);
2268 
2269  if (nRow1 < nRow2)
2270  ApplyFlags(nCol1, nRow1+1, nCol1, nRow2, ScMF::Ver);
2271 
2272  if (nCol1 < nCol2 && nRow1 < nRow2)
2273  ApplyFlags(nCol1+1, nRow1+1, nCol2, nRow2, ScMF::Hor | ScMF::Ver);
2274 }
2275 
2276 bool ScTable::IsBlockEmpty( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes ) const
2277 {
2278  if (!(ValidCol(nCol1) && ValidCol(nCol2)))
2279  {
2280  OSL_FAIL("ScTable::IsBlockEmpty: invalid column number");
2281  return false;
2282  }
2283  nCol2 = ClampToAllocatedColumns(nCol2);
2284  bool bEmpty = true;
2285  for (SCCOL i=nCol1; i<=nCol2 && bEmpty; i++)
2286  {
2287  bEmpty = aCol[i].IsEmptyBlock( nRow1, nRow2 );
2288  if (!bIgnoreNotes && bEmpty)
2289  {
2290  bEmpty = aCol[i].IsNotesEmptyBlock(nRow1, nRow2);
2291  }
2292  }
2293  return bEmpty;
2294 }
2295 
2296 SCSIZE ScTable::FillMaxRot( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2,
2297  SCCOL nCol, SCROW nAttrRow1, SCROW nAttrRow2, SCSIZE nArrY,
2298  const ScPatternAttr* pPattern, const SfxItemSet* pCondSet )
2299 {
2300  // Return value = new nArrY
2301 
2302  ScRotateDir nRotDir = pPattern->GetRotateDir( pCondSet );
2303  if ( nRotDir != ScRotateDir::NONE )
2304  {
2305  bool bHit = true;
2306  if ( nCol+1 < nX1 ) // column to the left
2307  bHit = ( nRotDir != ScRotateDir::Left );
2308  else if ( nCol > nX2+1 ) // column to the right
2309  bHit = ( nRotDir != ScRotateDir::Right ); // ScRotateDir::Standard may now also be extended to the left
2310 
2311  if ( bHit )
2312  {
2313  double nFactor = 0.0;
2314  if ( nCol > nX2+1 )
2315  {
2316  Degree100 nRotVal = pPattern->
2317  GetItem( ATTR_ROTATE_VALUE, pCondSet ).GetValue();
2318  double nRealOrient = nRotVal.get() * F_PI18000; // 1/100 degree
2319  double nCos = cos( nRealOrient );
2320  double nSin = sin( nRealOrient );
2321  //TODO: limit !!!
2322  //TODO: additional factor for varying PPT X/Y !!!
2323 
2324  // for ScRotateDir::Left this gives a negative value,
2325  // if the mode is considered
2326  nFactor = -fabs( nCos / nSin );
2327  }
2328 
2329  for ( SCROW nRow = nAttrRow1; nRow <= nAttrRow2; nRow++ )
2330  {
2331  if (!RowHidden(nRow))
2332  {
2333  bool bHitOne = true;
2334  if ( nCol > nX2+1 )
2335  {
2336  // Does the rotated cell extend into the visible range?
2337 
2338  SCCOL nTouchedCol = nCol;
2339  tools::Long nWidth = static_cast<tools::Long>(mpRowHeights->getValue(nRow) * nFactor);
2340  OSL_ENSURE(nWidth <= 0, "Wrong direction");
2341  while ( nWidth < 0 && nTouchedCol > 0 )
2342  {
2343  --nTouchedCol;
2344  nWidth += GetColWidth( nTouchedCol );
2345  }
2346  if ( nTouchedCol > nX2 )
2347  bHitOne = false;
2348  }
2349 
2350  if (bHitOne)
2351  {
2352  while ( nArrY<nArrCount && pRowInfo[nArrY].nRowNo < nRow )
2353  ++nArrY;
2354  if ( nArrY<nArrCount && pRowInfo[nArrY].nRowNo == nRow )
2355  pRowInfo[nArrY].nRotMaxCol = nCol;
2356  }
2357  }
2358  }
2359  }
2360  }
2361 
2362  return nArrY;
2363 }
2364 
2365 void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2 )
2366 {
2367  if ( !mpColWidth || !mpRowHeights || !mpColFlags || !pRowFlags )
2368  {
2369  OSL_FAIL( "Row/column info missing" );
2370  return;
2371  }
2372 
2373  // nRotMaxCol is initialized to SC_ROTMAX_NONE, nRowNo is already set
2374 
2375  SCROW nY1 = pRowInfo[0].nRowNo;
2376  SCROW nY2 = pRowInfo[nArrCount-1].nRowNo;
2377 
2378  for (SCCOL nCol : GetColumnsRange(0, rDocument.MaxCol()))
2379  {
2380  if (!ColHidden(nCol))
2381  {
2382  SCSIZE nArrY = 0;
2383  ScDocAttrIterator aIter( rDocument, nTab, nCol, nY1, nCol, nY2 );
2384  SCCOL nAttrCol;
2385  SCROW nAttrRow1, nAttrRow2;
2386  const ScPatternAttr* pPattern = aIter.GetNext( nAttrCol, nAttrRow1, nAttrRow2 );
2387  while ( pPattern )
2388  {
2389  const SfxPoolItem* pCondItem;
2390  if ( pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, &pCondItem )
2391  == SfxItemState::SET )
2392  {
2393  // Run through all formats, so that each cell does not have to be
2394  // handled individually
2395 
2396  const ScCondFormatIndexes& rCondFormatData = static_cast<const ScCondFormatItem*>(pCondItem)->GetCondFormatData();
2397  ScStyleSheetPool* pStylePool = rDocument.GetStyleSheetPool();
2398  if (mpCondFormatList && pStylePool && !rCondFormatData.empty())
2399  {
2400  for(const auto& rItem : rCondFormatData)
2401  {
2402  const ScConditionalFormat* pFormat = mpCondFormatList->GetFormat(rItem);
2403  if ( pFormat )
2404  {
2405  size_t nEntryCount = pFormat->size();
2406  for (size_t nEntry=0; nEntry<nEntryCount; nEntry++)
2407  {
2408  const ScFormatEntry* pEntry = pFormat->GetEntry(nEntry);
2409  if(pEntry->GetType() != ScFormatEntry::Type::Condition &&
2411  continue;
2412 
2413  OUString aStyleName = static_cast<const ScCondFormatEntry*>(pEntry)->GetStyle();
2414  if (!aStyleName.isEmpty())
2415  {
2416  SfxStyleSheetBase* pStyleSheet =
2417  pStylePool->Find( aStyleName, SfxStyleFamily::Para );
2418  if ( pStyleSheet )
2419  {
2420  FillMaxRot( pRowInfo, nArrCount, nX1, nX2,
2421  nCol, nAttrRow1, nAttrRow2,
2422  nArrY, pPattern, &pStyleSheet->GetItemSet() );
2423  // not changing nArrY
2424  }
2425  }
2426  }
2427  }
2428  }
2429  }
2430  }
2431 
2432  nArrY = FillMaxRot( pRowInfo, nArrCount, nX1, nX2,
2433  nCol, nAttrRow1, nAttrRow2,
2434  nArrY, pPattern, nullptr );
2435 
2436  pPattern = aIter.GetNext( nAttrCol, nAttrRow1, nAttrRow2 );
2437  }
2438  }
2439  }
2440 }
2441 
2442 bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2,
2443  bool bNoMatrixAtAll ) const
2444 {
2445  using namespace sc;
2446 
2447  if ( !IsColValid( nCol1 ) )
2448  return false;
2449 
2450  const SCCOL nMaxCol2 = std::min<SCCOL>( nCol2, aCol.size() - 1 );
2451 
2452  MatrixEdge nEdges = MatrixEdge::Nothing;
2453 
2454  if ( nCol1 == nMaxCol2 )
2455  { // left and right column
2457  nEdges = aCol[nCol1].GetBlockMatrixEdges( nRow1, nRow2, n, bNoMatrixAtAll );
2458  if ((nEdges != MatrixEdge::Nothing) && (((nEdges & n)!=n) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2459  return true; // left or right edge is missing or open
2460  }
2461  else
2462  { // left column
2463  nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Left, bNoMatrixAtAll);
2464  if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Left)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2465  return true; // left edge missing or open
2466  // right column
2467  nEdges = aCol[nMaxCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Right, bNoMatrixAtAll);
2468  if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Right)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
2469  return true; // right edge is missing or open
2470  }
2471 
2472  if (bNoMatrixAtAll)
2473  {
2474  for (SCCOL i=nCol1; i<=nMaxCol2; i++)
2475  {
2476  nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow2, MatrixEdge::Nothing, bNoMatrixAtAll);
2477  if (nEdges != MatrixEdge::Nothing
2478  && (nEdges != (MatrixEdge::Top | MatrixEdge::Left | MatrixEdge::Bottom | MatrixEdge::Right)))
2479  return true;
2480  }
2481  }
2482  else if ( nRow1 == nRow2 )
2483  { // Row on top and on bottom
2484  bool bOpen = false;
2485  const MatrixEdge n = MatrixEdge::Bottom | MatrixEdge::Top;
2486  for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
2487  {
2488  nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow1, n, bNoMatrixAtAll );
2489  if (nEdges != MatrixEdge::Nothing)
2490  {
2491  if ( (nEdges & n) != n )
2492  return true; // Top or bottom edge missing
2493  if (nEdges & MatrixEdge::Left)
2494  bOpen = true; // left edge open, continue
2495  else if ( !bOpen )
2496  return true; // Something exist that has not been opened
2497  if (nEdges & MatrixEdge::Right)
2498  bOpen = false; // Close right edge
2499  }
2500  }
2501  if ( bOpen )
2502  return true;
2503  }
2504  else
2505  {
2506  int j;
2507  MatrixEdge n;
2508  SCROW nR;
2509  // first top row, then bottom row
2510  for ( j=0, n = MatrixEdge::Top, nR=nRow1; j<2;
2511  j++, n = MatrixEdge::Bottom, nR=nRow2)
2512  {
2513  bool bOpen = false;
2514  for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
2515  {
2516  nEdges = aCol[i].GetBlockMatrixEdges( nR, nR, n, bNoMatrixAtAll );
2517  if ( nEdges != MatrixEdge::Nothing)
2518  {
2519  // in top row no top edge respectively
2520  // in bottom row no bottom edge
2521  if ( (nEdges & n) != n )
2522  return true;
2523  if (nEdges & MatrixEdge::Left)
2524  bOpen = true; // open left edge, continue
2525  else if ( !bOpen )
2526  return true; // Something exist that has not been opened
2527  if (nEdges & MatrixEdge::Right)
2528  bOpen = false; // Close right edge
2529  }
2530  }
2531  if ( bOpen )
2532  return true;
2533  }
2534  }
2535  return false;
2536 }
2537 
2539 {
2540  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2541 
2542  for (const sc::ColRowSpan & aSpan : aSpans)
2543  {
2544  SCCOL nEndCol = ClampToAllocatedColumns(aSpan.mnEnd);
2545  for ( SCCOLROW j=aSpan.mnStart; j<=nEndCol; j++ )
2546  {
2547  if ( aCol[j].HasSelectionMatrixFragment(rMark) )
2548  return true;
2549  }
2550  }
2551  return false;
2552 }
2553 
2554 bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2,
2555  SCROW nRow2, bool* pOnlyNotBecauseOfMatrix /* = NULL */,
2556  bool bNoMatrixAtAll ) const
2557 {
2558  if ( !ValidColRow( nCol2, nRow2 ) )
2559  {
2560  SAL_WARN("sc", "IsBlockEditable: invalid column or row " << nCol2 << " " << nRow2);
2561  if (pOnlyNotBecauseOfMatrix)
2562  *pOnlyNotBecauseOfMatrix = false;
2563  return false;
2564  }
2565  nCol1 = ClampToAllocatedColumns(nCol1);
2566  nCol2 = ClampToAllocatedColumns(nCol2);
2567 
2568  bool bIsEditable = true;
2569  if ( nLockCount )
2570  bIsEditable = false;
2571  else if ( IsProtected() && !rDocument.IsScenario(nTab) )
2572  {
2573  bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, HasAttrFlags::Protected );
2574  if (!bIsEditable)
2575  {
2576  // An enhanced protection permission may override the attribute.
2577  if (pTabProtection)
2578  bIsEditable = pTabProtection->isBlockEditable( ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab));
2579  }
2580  if (bIsEditable)
2581  {
2582  // If Sheet is protected and cells are not protected then
2583  // check the active scenario protect flag if this range is
2584  // on the active scenario range. Note the 'copy back' must also
2585  // be set to apply protection.
2586  sal_uInt16 nScenTab = nTab+1;
2587  while(rDocument.IsScenario(nScenTab))
2588  {
2589  ScRange aEditRange(nCol1, nRow1, nScenTab, nCol2, nRow2, nScenTab);
2590  if(rDocument.IsActiveScenario(nScenTab) && rDocument.HasScenarioRange(nScenTab, aEditRange))
2591  {
2592  ScScenarioFlags nFlags;
2593  rDocument.GetScenarioFlags(nScenTab,nFlags);
2594  bIsEditable = !((nFlags & ScScenarioFlags::Protected) && (nFlags & ScScenarioFlags::TwoWay));
2595  break;
2596  }
2597  nScenTab++;
2598  }
2599  }
2600  }
2601  else if (rDocument.IsScenario(nTab))
2602  {
2603  // Determine if the preceding sheet is protected
2604  SCTAB nActualTab = nTab;
2605  do
2606  {
2607  nActualTab--;
2608  }
2609  while(rDocument.IsScenario(nActualTab));
2610 
2611  if(rDocument.IsTabProtected(nActualTab))
2612  {
2613  ScRange aEditRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab);
2614  if(rDocument.HasScenarioRange(nTab, aEditRange))
2615  {
2616  ScScenarioFlags nFlags;
2617  rDocument.GetScenarioFlags(nTab,nFlags);
2618  bIsEditable = !(nFlags & ScScenarioFlags::Protected);
2619  }
2620  }
2621  }
2622  if ( bIsEditable )
2623  {
2624  if (HasBlockMatrixFragment( nCol1, nRow1, nCol2, nRow2, bNoMatrixAtAll))
2625  {
2626  bIsEditable = false;
2627  if ( pOnlyNotBecauseOfMatrix )
2628  *pOnlyNotBecauseOfMatrix = true;
2629  }
2630  else if ( pOnlyNotBecauseOfMatrix )
2631  *pOnlyNotBecauseOfMatrix = false;
2632  }
2633  else if ( pOnlyNotBecauseOfMatrix )
2634  *pOnlyNotBecauseOfMatrix = false;
2635  return bIsEditable;
2636 }
2637 
2639  bool* pOnlyNotBecauseOfMatrix /* = NULL */ ) const
2640 {
2641  bool bIsEditable = true;
2642  if ( nLockCount )
2643  bIsEditable = false;
2644  else if ( IsProtected() && !rDocument.IsScenario(nTab) )
2645  {
2646  ScRangeList aRanges;
2647  rMark.FillRangeListWithMarks( &aRanges, false );
2648  bIsEditable = !HasAttribSelection( rMark, HasAttrFlags::Protected );
2649  if (!bIsEditable)
2650  {
2651  // An enhanced protection permission may override the attribute.
2652  if (pTabProtection)
2653  bIsEditable = pTabProtection->isSelectionEditable( aRanges);
2654  }
2655  if (bIsEditable)
2656  {
2657  // If Sheet is protected and cells are not protected then
2658  // check the active scenario protect flag if this area is
2659  // in the active scenario range.
2660  SCTAB nScenTab = nTab+1;
2661  while(rDocument.IsScenario(nScenTab) && bIsEditable)
2662  {
2663  if(rDocument.IsActiveScenario(nScenTab))
2664  {
2665  for (size_t i=0, nRange = aRanges.size(); (i < nRange) && bIsEditable; i++ )
2666  {
2667  const ScRange & rRange = aRanges[ i ];
2668  if(rDocument.HasScenarioRange(nScenTab, rRange))
2669  {
2670  ScScenarioFlags nFlags;
2671  rDocument.GetScenarioFlags(nScenTab,nFlags);
2672  bIsEditable = !((nFlags & ScScenarioFlags::Protected) && (nFlags & ScScenarioFlags::TwoWay));
2673  }
2674  }
2675  }
2676  nScenTab++;
2677  }
2678  }
2679  }
2680  else if (rDocument.IsScenario(nTab))
2681  {
2682  // Determine if the preceding sheet is protected
2683  SCTAB nActualTab = nTab;
2684  do
2685  {
2686  nActualTab--;
2687  }
2688  while(rDocument.IsScenario(nActualTab));
2689 
2690  if(rDocument.IsTabProtected(nActualTab))
2691  {
2692  ScRangeList aRanges;
2693  rMark.FillRangeListWithMarks( &aRanges, false );
2694  for (size_t i = 0, nRange = aRanges.size(); (i < nRange) && bIsEditable; i++)
2695  {
2696  const ScRange & rRange = aRanges[ i ];
2697  if(rDocument.HasScenarioRange(nTab, rRange))
2698  {
2699  ScScenarioFlags nFlags;
2700  rDocument.GetScenarioFlags(nTab,nFlags);
2701  bIsEditable = !(nFlags & ScScenarioFlags::Protected);
2702  }
2703  }
2704  }
2705  }
2706  if ( bIsEditable )
2707  {
2708  if ( HasSelectionMatrixFragment( rMark ) )
2709  {
2710  bIsEditable = false;
2711  if ( pOnlyNotBecauseOfMatrix )
2712  *pOnlyNotBecauseOfMatrix = true;
2713  }
2714  else if ( pOnlyNotBecauseOfMatrix )
2715  *pOnlyNotBecauseOfMatrix = false;
2716  }
2717  else if ( pOnlyNotBecauseOfMatrix )
2718  *pOnlyNotBecauseOfMatrix = false;
2719  return bIsEditable;
2720 }
2721 
2723 {
2724  ++nLockCount;
2725 }
2726 
2728 {
2729  if (nLockCount)
2730  --nLockCount;
2731  else
2732  {
2733  OSL_FAIL("UnlockTable without LockTable");
2734  }
2735 }
2736 
2737 void ScTable::MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, bool bDeep ) const
2738 {
2739  std::vector<sc::ColRowSpan> aSpans = rMark.GetMarkedColSpans();
2740 
2741  for (const sc::ColRowSpan & rSpan : aSpans)
2742  {
2743  for (SCCOLROW i = rSpan.mnStart; i <= rSpan.mnEnd; ++i)
2744  {
2745  CreateColumnIfNotExists(i).MergeSelectionPattern( rState, rMark, bDeep );
2746  }
2747  }
2748 }
2749 
2751  SCCOL nCol2, SCROW nRow2, bool bDeep ) const
2752 {
2753  nCol2 = ClampToAllocatedColumns(nCol2);
2754  for (SCCOL i=nCol1; i<=nCol2; i++)
2755  aCol[i].MergePatternArea( rState, nRow1, nRow2, bDeep );
2756 }
2757 
2758 void ScTable::MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, ScLineFlags& rFlags,
2759  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const
2760 {
2761  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2762  {
2763  PutInOrder(nStartCol, nEndCol);
2764  PutInOrder(nStartRow, nEndRow);
2765  nEndCol = ClampToAllocatedColumns(nEndCol);
2766  for (SCCOL i=nStartCol; i<=nEndCol; i++)
2767  aCol[i].MergeBlockFrame( pLineOuter, pLineInner, rFlags,
2768  nStartRow, nEndRow, (i==nStartCol), nEndCol-i );
2769  }
2770 }
2771 
2772 void ScTable::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner,
2773  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
2774 {
2775  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2776  {
2777  PutInOrder(nStartCol, nEndCol);
2778  PutInOrder(nStartRow, nEndRow);
2779  nEndCol = ClampToAllocatedColumns(nEndCol);
2780  for (SCCOL i=nStartCol; i<=nEndCol; i++)
2781  aCol[i].ApplyBlockFrame(rLineOuter, pLineInner,
2782  nStartRow, nEndRow, (i==nStartCol), nEndCol-i);
2783  }
2784 }
2785 
2786 void ScTable::ApplyPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr )
2787 {
2788  if (ValidColRow(nCol,nRow))
2789  CreateColumnIfNotExists(nCol).ApplyPattern( nRow, rAttr );
2790 }
2791 
2792 void ScTable::ApplyPatternArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2793  const ScPatternAttr& rAttr, ScEditDataArray* pDataArray,
2794  bool* const pIsChanged )
2795 {
2796  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
2797  {
2798  PutInOrder(nStartCol, nEndCol);
2799  PutInOrder(nStartRow, nEndRow);
2800  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2801  CreateColumnIfNotExists(i).ApplyPatternArea(nStartRow, nEndRow, rAttr, pDataArray, pIsChanged);
2802  }
2803 }
2804 
2806  const ScPatternAttr& rPattern, SvNumFormatType nNewType )
2807 {
2808  SCCOL nEndCol = rRange.aEnd.Col();
2809  for ( SCCOL nCol = rRange.aStart.Col(); nCol <= nEndCol; nCol++ )
2810  {
2811  aCol[nCol].ApplyPatternIfNumberformatIncompatible( rRange, rPattern, nNewType );
2812  }
2813 }
2814 
2815 void ScTable::AddCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nIndex )
2816 {
2817  size_t n = rRangeList.size();
2818  for(size_t i = 0; i < n; ++i)
2819  {
2820  const ScRange & rRange = rRangeList[i];
2821  SCCOL nColStart = rRange.aStart.Col();
2822  SCCOL nColEnd = rRange.aEnd.Col();
2823  SCROW nRowStart = rRange.aStart.Row();
2824  SCROW nRowEnd = rRange.aEnd.Row();
2825  for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
2826  {
2827  CreateColumnIfNotExists(nCol).AddCondFormat(nRowStart, nRowEnd, nIndex);
2828  }
2829  }
2830 }
2831 
2832 void ScTable::RemoveCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nIndex )
2833 {
2834  size_t n = rRangeList.size();
2835  for(size_t i = 0; i < n; ++i)
2836  {
2837  const ScRange & rRange = rRangeList[i];
2838  SCCOL nColStart = rRange.aStart.Col();
2839  SCCOL nColEnd = ClampToAllocatedColumns(rRange.aEnd.Col());
2840  SCROW nRowStart = rRange.aStart.Row();
2841  SCROW nRowEnd = rRange.aEnd.Row();
2842  for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
2843  {
2844  aCol[nCol].RemoveCondFormat(nRowStart, nRowEnd, nIndex);
2845  }
2846  }
2847 }
2848 
2849 void ScTable::SetPatternAreaCondFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow,
2850  const ScPatternAttr& rAttr, const ScCondFormatIndexes& rCondFormatIndexes )
2851 {
2852  aCol[nCol].SetPatternArea( nStartRow, nEndRow, rAttr);
2853 
2854  for (const auto& rIndex : rCondFormatIndexes)
2855  {
2856  ScConditionalFormat* pCondFormat = mpCondFormatList->GetFormat(rIndex);
2857  if (pCondFormat)
2858  {
2859  ScRangeList aRange = pCondFormat->GetRange();
2860  aRange.Join( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab));
2861  pCondFormat->SetRange(aRange);
2862  }
2863  }
2864 }
2865 
2866 void ScTable::ApplyStyle( SCCOL nCol, SCROW nRow, const ScStyleSheet* rStyle )
2867 {
2868  if (ValidColRow(nCol,nRow))
2869  // If column not exists then we need to create it
2870  CreateColumnIfNotExists( nCol ).ApplyStyle( nRow, rStyle );
2871 }
2872 
2873 void ScTable::ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet& rStyle )
2874 {
2875  if (!(ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow)))
2876  return;
2877 
2878  PutInOrder(nStartCol, nEndCol);
2879  PutInOrder(nStartRow, nEndRow);
2880  if ( nEndCol == rDocument.MaxCol() )
2881  {
2882  if ( nStartCol < aCol.size() )
2883  {
2884  // If we would like set all columns to specific style, then change only default style for not existing columns
2885  nEndCol = aCol.size() - 1;
2886  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2887  aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
2888  aDefaultColAttrArray.ApplyStyleArea(nStartRow, nEndRow, rStyle );
2889  }
2890  else
2891  {
2892  CreateColumnIfNotExists( nStartCol - 1 );
2893  aDefaultColAttrArray.ApplyStyleArea(nStartRow, nEndRow, rStyle );
2894  }
2895  }
2896  else
2897  {
2898  CreateColumnIfNotExists( nEndCol );
2899  for (SCCOL i = nStartCol; i <= nEndCol; i++)
2900  aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
2901  }
2902 }
2903 
2904 void ScTable::ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark)
2905 {
2906  for (SCCOL i=0; i < aCol.size(); i++)
2907  aCol[i].ApplySelectionStyle( rStyle, rMark );
2908 }
2909 
2911  const ::editeng::SvxBorderLine* pLine, bool bColorOnly )
2912 {
2913  if ( bColorOnly && !pLine )
2914  return;
2915 
2916  for (SCCOL i=0; i < aCol.size(); i++)
2917  aCol[i].ApplySelectionLineStyle( rMark, pLine, bColorOnly );
2918 }
2919 
2920 const ScStyleSheet* ScTable::GetStyle( SCCOL nCol, SCROW nRow ) const
2921 {
2922  if ( !ValidColRow( nCol, nRow ) )
2923  return nullptr;
2924  if ( nCol < aCol.size() )
2925  return aCol[nCol].GetStyle( nRow );
2926  else
2927  return aDefaultColAttrArray.GetPattern( nRow )->GetStyleSheet();
2928 }
2929 
2930 const ScStyleSheet* ScTable::GetSelectionStyle( const ScMarkData& rMark, bool& rFound ) const
2931 {
2932  rFound = false;
2933 
2934  bool bEqual = true;
2935  bool bColFound;
2936 
2937  const ScStyleSheet* pStyle = nullptr;
2938  const ScStyleSheet* pNewStyle;
2939 
2940  for (SCCOL i=0; i < aCol.size() && bEqual; i++)
2941  if (rMark.HasMultiMarks(i))
2942  {
2943  pNewStyle = aCol[i].GetSelectionStyle( rMark, bColFound );
2944  if (bColFound)
2945  {
2946  rFound = true;
2947  if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
2948  bEqual = false;
2949  pStyle = pNewStyle;
2950  }
2951  }
2952 
2953  return bEqual ? pStyle : nullptr;
2954 }
2955 
2956 const ScStyleSheet* ScTable::GetAreaStyle( bool& rFound, SCCOL nCol1, SCROW nRow1,
2957  SCCOL nCol2, SCROW nRow2 ) const
2958 {
2959  rFound = false;
2960 
2961  bool bEqual = true;
2962  bool bColFound;
2963 
2964  const ScStyleSheet* pStyle = nullptr;
2965  const ScStyleSheet* pNewStyle;
2966  nCol2 = ClampToAllocatedColumns(nCol2);
2967  for (SCCOL i=nCol1; i<=nCol2 && bEqual; i++)
2968  {
2969  pNewStyle = aCol[i].GetAreaStyle(bColFound, nRow1, nRow2);
2970  if (bColFound)
2971  {
2972  rFound = true;
2973  if ( !pNewStyle || ( pStyle && pNewStyle != pStyle ) )
2974  bEqual = false;
2975  pStyle = pNewStyle;
2976  }
2977  }
2978 
2979  return bEqual ? pStyle : nullptr;
2980 }
2981 
2982 bool ScTable::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const
2983 {
2984  bool bIsUsed = false;
2985 
2986  for ( SCCOL i=0; i < aCol.size(); i++ )
2987  {
2988  if ( aCol[i].IsStyleSheetUsed( rStyle ) )
2989  {
2990  bIsUsed = true;
2991  }
2992  }
2993 
2994  return bIsUsed;
2995 }
2996 
2997 void ScTable::StyleSheetChanged( const SfxStyleSheetBase* pStyleSheet, bool bRemoved,
2998  OutputDevice* pDev,
2999  double nPPTX, double nPPTY,
3000  const Fraction& rZoomX, const Fraction& rZoomY )
3001 {
3002  ScFlatBoolRowSegments aUsedRows(rDocument.MaxRow());
3003  for (SCCOL i = 0; i < aCol.size(); ++i)
3004  aCol[i].FindStyleSheet(pStyleSheet, aUsedRows, bRemoved);
3005 
3006  sc::RowHeightContext aCxt(rDocument.MaxRow(), nPPTX, nPPTY, rZoomX, rZoomY, pDev);
3007  SCROW nRow = 0;
3008  while (nRow <= rDocument.MaxRow())
3009  {
3011  if (!aUsedRows.getRangeData(nRow, aData))
3012  // search failed!
3013  return;
3014 
3015  SCROW nEndRow = aData.mnRow2;
3016  if (aData.mbValue)
3017  SetOptimalHeight(aCxt, nRow, nEndRow, true);
3018 
3019  nRow = nEndRow + 1;
3020  }
3021 }
3022 
3023 bool ScTable::ApplyFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3024  ScMF nFlags )
3025 {
3026  bool bChanged = false;
3027  if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
3028  for (SCCOL i = nStartCol; i <= nEndCol; i++)
3029  bChanged |= CreateColumnIfNotExists(i).ApplyFlags(nStartRow, nEndRow, nFlags);
3030  return bChanged;
3031 }
3032 
3033 bool ScTable::RemoveFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3034  ScMF nFlags )
3035 {
3036  if (!ValidColRow(nStartCol, nStartRow) || !ValidColRow(nEndCol, nEndRow))
3037  return false;
3038  bool bChanged = false;
3039  nEndCol = ClampToAllocatedColumns(nEndCol);
3040  for (SCCOL i = nStartCol; i <= nEndCol; i++)
3041  bChanged |= aCol[i].RemoveFlags(nStartRow, nEndRow, nFlags);
3042  return bChanged;
3043 }
3044 
3045 void ScTable::SetPattern( const ScAddress& rPos, const ScPatternAttr& rAttr )
3046 {
3047  if (ValidColRow(rPos.Col(),rPos.Row()))
3048  aCol[rPos.Col()].SetPattern( rPos.Row(), rAttr );
3049 }
3050 
3051 const ScPatternAttr* ScTable::SetPattern( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPatternAttr> pAttr )
3052 {
3053  if (ValidColRow(nCol,nRow))
3054  return aCol[nCol].SetPattern( nRow, std::move(pAttr) );
3055  return nullptr;
3056 }
3057 
3058 void ScTable::SetPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr )
3059 {
3060  if (ValidColRow(nCol,nRow))
3061  aCol[nCol].SetPattern( nRow, rAttr );
3062 }
3063 
3064 void ScTable::ApplyAttr( SCCOL nCol, SCROW nRow, const SfxPoolItem& rAttr )
3065 {
3066  if (ValidColRow(nCol,nRow))
3067  CreateColumnIfNotExists(nCol).ApplyAttr( nRow, rAttr );
3068 }
3069 
3071  ScEditDataArray* pDataArray, bool* const pIsChanged )
3072 {
3073  for (SCCOL i=0; i < aCol.size(); i++)
3074  aCol[i].ApplySelectionCache( pCache, rMark, pDataArray, pIsChanged );
3075 }
3076 
3077 void ScTable::ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark )
3078 {
3079  for (SCCOL i=0; i < aCol.size(); i++)
3080  aCol[i].ChangeSelectionIndent( bIncrement, rMark );
3081 }
3082 
3083 void ScTable::ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark )
3084 {
3085  for (SCCOL i=0; i < aCol.size(); i++)
3086  aCol[i].ClearSelectionItems( pWhich, rMark );
3087 }
3088 
3089 // Column widths / Row heights
3090 
3091 void ScTable::SetColWidth( SCCOL nCol, sal_uInt16 nNewWidth )
3092 {
3093  if (ValidCol(nCol) && mpColWidth)
3094  {
3095  if (!nNewWidth)
3096  {
3097  nNewWidth = STD_COL_WIDTH;
3098  }
3099 
3100  if ( nNewWidth != mpColWidth->GetValue(nCol) )
3101  {
3102  mpColWidth->SetValue(nCol, nNewWidth);
3104  }
3105  }
3106  else
3107  {
3108  OSL_FAIL("Invalid column number or no widths");
3109  }
3110 }
3111 
3112 void ScTable::SetColWidthOnly( SCCOL nCol, sal_uInt16 nNewWidth )
3113 {
3114  if (!ValidCol(nCol) || !mpColWidth)
3115  return;
3116 
3117  if (!nNewWidth)
3118  nNewWidth = STD_COL_WIDTH;
3119 
3120  if (nNewWidth != mpColWidth->GetValue(nCol))
3121  mpColWidth->SetValue(nCol, nNewWidth);
3122 }
3123 
3124 void ScTable::SetRowHeight( SCROW nRow, sal_uInt16 nNewHeight )
3125 {
3126  if (ValidRow(nRow) && mpRowHeights)
3127  {
3128  if (!nNewHeight)
3129  {
3130  OSL_FAIL("SetRowHeight: Row height zero");
3131  nNewHeight = ScGlobal::nStdRowHeight;
3132  }
3133 
3134  sal_uInt16 nOldHeight = mpRowHeights->getValue(nRow);
3135  if ( nNewHeight != nOldHeight )
3136  {
3137  mpRowHeights->setValue(nRow, nRow, nNewHeight);
3139  }
3140  }
3141  else
3142  {
3143  OSL_FAIL("Invalid row number or no heights");
3144  }
3145 }
3146 
3147 namespace {
3148 
3153 bool lcl_pixelSizeChanged(
3154  ScFlatUInt16RowSegments& rRowHeights, SCROW nStartRow, SCROW nEndRow,
3155  sal_uInt16 nNewHeight, double nPPTY, bool bApi)
3156 {
3157  tools::Long nNewPix = static_cast<tools::Long>(nNewHeight * nPPTY);
3158 
3159  ScFlatUInt16RowSegments::ForwardIterator aFwdIter(rRowHeights);
3160  for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
3161  {
3162  sal_uInt16 nHeight;
3163  if (!aFwdIter.getValue(nRow, nHeight))
3164  break;
3165 
3166  if (nHeight != nNewHeight)
3167  {
3168  tools::Long nOldPix = static_cast<tools::Long>(nHeight * nPPTY);
3169 
3170  // Heuristic: Don't bother when handling interactive input, if changing just one row and
3171  // the height will shrink.
3172  bool bChanged = (nNewPix != nOldPix) && (bApi || nEndRow - nStartRow > 0 || nNewPix > nOldPix);
3173  if (bChanged)
3174  return true;
3175  }
3176 
3177  // Skip ahead to the last position of the current range.
3178  nRow = aFwdIter.getLastPos();
3179  }
3180  return false;
3181 }
3182 
3183 }
3184 
3185 bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight,
3186  double nPPTY, bool bApi )
3187 {
3188  bool bChanged = false;
3189  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3190  {
3191  if (!nNewHeight)
3192  {
3193  OSL_FAIL("SetRowHeight: Row height zero");
3194  nNewHeight = ScGlobal::nStdRowHeight;
3195  }
3196 
3197  bool bSingle = false; // true = process every row for its own
3198  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3199  if (pDrawLayer)
3200  if (pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ))
3201  bSingle = true;
3202 
3203  if (bSingle)
3204  {
3206  if (mpRowHeights->getRangeData(nStartRow, aData) &&
3207  nNewHeight == aData.mnValue && nEndRow <= aData.mnRow2)
3208  {
3209  bSingle = false; // no difference in this range
3210  }
3211  }
3212 
3213  // No idea why 20 is used here
3214  if (!bSingle || nEndRow - nStartRow < 20)
3215  {
3216  bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, nNewHeight, nPPTY, bApi);
3217  if (bChanged)
3218  mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
3219  }
3220  else
3221  {
3222  SCROW nMid = (nStartRow + nEndRow) / 2;
3223  // No idea why nPPTY is ignored in these recursive calls and instead 1.0 is used
3224  if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0, bApi))
3225  bChanged = true;
3226  if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0, bApi))
3227  bChanged = true;
3228  }
3229 
3230  if (bChanged)
3232  }
3233  else
3234  {
3235  OSL_FAIL("Invalid row number or no heights");
3236  }
3237 
3238  return bChanged;
3239 }
3240 
3241 void ScTable::SetRowHeightOnly( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight )
3242 {
3243  if (!ValidRow(nStartRow) || !ValidRow(nEndRow) || !mpRowHeights)
3244  return;
3245 
3246  if (!nNewHeight)
3247  nNewHeight = ScGlobal::nStdRowHeight;
3248 
3249  mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
3250 }
3251 
3252 void ScTable::SetManualHeight( SCROW nStartRow, SCROW nEndRow, bool bManual )
3253 {
3254  if (ValidRow(nStartRow) && ValidRow(nEndRow) && pRowFlags)
3255  {
3256  if (bManual)
3257  pRowFlags->OrValue( nStartRow, nEndRow, CRFlags::ManualSize);
3258  else
3259  pRowFlags->AndValue( nStartRow, nEndRow, ~CRFlags::ManualSize);
3260  }
3261  else
3262  {
3263  OSL_FAIL("Invalid row number or no column flags");
3264  }
3265 }
3266 
3267 sal_uInt16 ScTable::GetColWidth( SCCOL nCol, bool bHiddenAsZero ) const
3268 {
3269  OSL_ENSURE(ValidCol(nCol),"wrong column number");
3270 
3271  if (ValidCol(nCol) && mpColFlags && mpColWidth)
3272  {
3273  if (bHiddenAsZero && ColHidden(nCol))
3274  return 0;
3275  else
3276  return mpColWidth->GetValue(nCol);
3277  }
3278  else
3279  return sal_uInt16(STD_COL_WIDTH);
3280 }
3281 
3282 sal_uLong ScTable::GetColWidth( SCCOL nStartCol, SCCOL nEndCol ) const
3283 {
3284  if (!ValidCol(nStartCol) || !ValidCol(nEndCol) || nStartCol > nEndCol)
3285  return 0;
3286 
3287  sal_uLong nW = 0;
3288  bool bHidden = false;
3289  SCCOL nLastHiddenCol = -1;
3290  auto colWidthIt = mpColWidth->begin() + nStartCol;
3291  for (SCCOL nCol = nStartCol; nCol <= nEndCol; (++nCol <= nEndCol) ? ++colWidthIt : (void)false)
3292  {
3293  if (nCol > nLastHiddenCol)
3294  bHidden = ColHidden(nCol, nullptr, &nLastHiddenCol);
3295 
3296  if (bHidden)
3297  continue;
3298 
3299  nW += *colWidthIt;
3300  }
3301  return nW;
3302 }
3303 
3304 sal_uInt16 ScTable::GetOriginalWidth( SCCOL nCol ) const // always the set value
3305 {
3306  OSL_ENSURE(ValidCol(nCol),"wrong column number");
3307 
3308  if (ValidCol(nCol) && mpColWidth)
3309  return mpColWidth->GetValue(nCol);
3310  else
3311  return sal_uInt16(STD_COL_WIDTH);
3312 }
3313 
3314 sal_uInt16 ScTable::GetCommonWidth( SCCOL nEndCol ) const
3315 {
3316  // get the width that is used in the largest continuous column range (up to nEndCol)
3317 
3318  if ( !ValidCol(nEndCol) )
3319  {
3320  OSL_FAIL("wrong column");
3321  nEndCol = rDocument.MaxCol();
3322  }
3323 
3324  sal_uInt16 nMaxWidth = 0;
3325  sal_uInt16 nMaxCount = 0;
3326  SCCOL nRangeStart = 0;
3327  while ( nRangeStart <= nEndCol )
3328  {
3329  // skip hidden columns
3330  while ( nRangeStart <= nEndCol && ColHidden(nRangeStart) )
3331  ++nRangeStart;
3332  if ( nRangeStart <= nEndCol )
3333  {
3334  sal_uInt16 nThisCount = 0;
3335  auto colWidthIt = mpColWidth->begin() + nRangeStart;
3336  sal_uInt16 nThisWidth = *colWidthIt;
3337  SCCOL nRangeEnd = nRangeStart;
3338  while ( nRangeEnd <= nEndCol && *colWidthIt == nThisWidth )
3339  {
3340  ++nThisCount;
3341  ++nRangeEnd;
3342  ++colWidthIt;
3343 
3344  // skip hidden columns
3345  while ( nRangeEnd <= nEndCol && ColHidden(nRangeEnd) )
3346  {
3347  ++nRangeEnd;
3348  ++colWidthIt;
3349  }
3350  }
3351 
3352  if ( nThisCount > nMaxCount )
3353  {
3354  nMaxCount = nThisCount;
3355  nMaxWidth = nThisWidth;
3356  }
3357 
3358  nRangeStart = nRangeEnd; // next range
3359  }
3360  }
3361 
3362  return nMaxWidth;
3363 }
3364 
3365 sal_uInt16 ScTable::GetRowHeight( SCROW nRow, SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero ) const
3366 {
3367  SAL_WARN_IF(!ValidRow(nRow), "sc", "Invalid row number " << nRow);
3368 
3369  if (ValidRow(nRow) && mpRowHeights)
3370  {
3371  if (bHiddenAsZero && RowHidden( nRow, pStartRow, pEndRow))
3372  return 0;
3373  else
3374  {
3376  if (!mpRowHeights->getRangeData(nRow, aData))
3377  {
3378  if (pStartRow)
3379  *pStartRow = nRow;
3380  if (pEndRow)
3381  *pEndRow = nRow;
3382  // TODO: What should we return in case the search fails?
3383  return 0;
3384  }
3385 
3386  // If bHiddenAsZero, pStartRow and pEndRow were initialized to
3387  // boundaries of a non-hidden segment. Assume that the previous and
3388  // next segment are hidden then and limit the current height
3389  // segment.
3390  if (pStartRow)
3391  *pStartRow = (bHiddenAsZero ? std::max( *pStartRow, aData.mnRow1) : aData.mnRow1);
3392  if (pEndRow)
3393  *pEndRow = (bHiddenAsZero ? std::min( *pEndRow, aData.mnRow2) : aData.mnRow2);
3394  return aData.mnValue;
3395  }
3396  }
3397  else
3398  {
3399  if (pStartRow)
3400  *pStartRow = nRow;
3401  if (pEndRow)
3402  *pEndRow = nRow;
3403  return ScGlobal::nStdRowHeight;
3404  }
3405 }
3406 
3407 sal_uLong ScTable::GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero ) const
3408 {
3409  OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
3410 
3411  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3412  {
3413  sal_uLong nHeight = 0;
3414  SCROW nRow = nStartRow;
3415  while (nRow <= nEndRow)
3416  {
3417  SCROW nLastRow = -1;
3418  if (!( ( RowHidden(nRow, nullptr, &nLastRow) ) && bHiddenAsZero ) )
3419  {
3420  if (nLastRow > nEndRow)
3421  nLastRow = nEndRow;
3422  nHeight += mpRowHeights->getSumValue(nRow, nLastRow);
3423  }
3424  nRow = nLastRow + 1;
3425  }
3426  return nHeight;
3427  }
3428  else
3429  return (nEndRow - nStartRow + 1) * static_cast<sal_uLong>(ScGlobal::nStdRowHeight);
3430 }
3431 
3432 sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong* pnMaxHeight ) const
3433 {
3434  OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
3435 
3436  if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
3437  {
3438  sal_uLong nHeight = 0;
3439  SCROW nRow = nStartRow;
3440  while (nRow <= nEndRow)
3441  {
3442  SCROW nLastRow = -1;
3443  if (!RowHidden(nRow, nullptr, &nLastRow))
3444  {
3445  if (nLastRow > nEndRow)
3446  nLastRow = nEndRow;
3447 
3448  // #i117315# can't use getSumValue, because individual values must be rounded
3450  while (nRow <= nLastRow)
3451  {
3452  sal_uInt16 nRowVal;
3453  if (!aSegmentIter.getValue(nRow, nRowVal))
3454  return nHeight; // shouldn't happen
3455 
3456  SCROW nSegmentEnd = std::min( nLastRow, aSegmentIter.getLastPos() );
3457 
3458  // round-down a single height value, multiply resulting (pixel) values
3459  const sal_uLong nOneHeight = static_cast<sal_uLong>( nRowVal * fScale );
3460  // sometimes scaling results in zero height
3461  if (nOneHeight)
3462  {
3463  SCROW nRowsInSegment = nSegmentEnd + 1 - nRow;
3464  if (pnMaxHeight)
3465  {
3466  nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
3467  nHeight += nOneHeight * nRowsInSegment;
3468  if (nHeight > *pnMaxHeight)
3469  return nHeight;
3470  }
3471  else
3472  nHeight += nOneHeight * nRowsInSegment;
3473  }
3474 
3475  nRow = nSegmentEnd + 1;
3476  }
3477  }
3478  nRow = nLastRow + 1;
3479  }
3480  return nHeight;
3481  }
3482  else
3483  {
3484  const sal_uLong nOneHeight = static_cast<sal_uLong>(ScGlobal::nStdRowHeight * fScale);
3485  SCROW nRowsInSegment = nEndRow - nStartRow + 1;
3486  if (pnMaxHeight)
3487  {
3488  nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
3489  return nOneHeight * nRowsInSegment;
3490  }
3491  else
3492  return static_cast<sal_uLong>(nRowsInSegment * nOneHeight);
3493  }
3494 }
3495 
3496 sal_uInt16 ScTable::GetOriginalHeight( SCROW nRow ) const // non-0 even if hidden
3497 {
3498  OSL_ENSURE(ValidRow(nRow),"wrong row number");
3499 
3500  if (ValidRow(nRow) && mpRowHeights)
3501  return mpRowHeights->getValue(nRow);
3502  else
3503  return ScGlobal::nStdRowHeight;
3504 }
3505 
3506 // Column/Row -Flags
3507 
3509 {
3510  if (!ValidRow(nRow))
3511  return 0;
3512 
3513  SCROW nLastRow = -1;
3514  if (!RowHidden(nRow, nullptr, &nLastRow) || !ValidRow(nLastRow))
3515  return 0;
3516 
3517  return nLastRow - nRow + 1;
3518 }
3519 
3520 //TODO: combine ShowRows / DBShowRows
3521 
3522 void ScTable::ShowCol(SCCOL nCol, bool bShow)
3523 {
3524  if (ValidCol(nCol))
3525  {
3526  bool bWasVis = !ColHidden(nCol);
3527  if (bWasVis != bShow)
3528  {
3529  SetColHidden(nCol, nCol, !bShow);
3530 
3532  if ( pCharts )
3533  pCharts->SetRangeDirty(ScRange( nCol, 0, nTab, nCol, rDocument.MaxRow(), nTab ));
3534  }
3535  }
3536  else
3537  {
3538  OSL_FAIL("Invalid column number or no flags");
3539  }
3540 }
3541 
3542 void ScTable::ShowRow(SCROW nRow, bool bShow)
3543 {
3544  if (ValidRow(nRow) && pRowFlags)
3545  {
3546  bool bWasVis = !RowHidden(nRow);
3547  if (bWasVis != bShow)
3548  {
3549  SetRowHidden(nRow, nRow, !bShow);
3550  if (bShow)
3551  SetRowFiltered(nRow, nRow, false);
3553  if ( pCharts )
3554  pCharts->SetRangeDirty(ScRange( 0, nRow, nTab, rDocument.MaxCol(), nRow, nTab ));
3555 
3557  }
3558  }
3559  else
3560  {
3561  OSL_FAIL("Invalid row number or no flags");
3562  }
3563 }
3564 
3565 void ScTable::DBShowRow(SCROW nRow, bool bShow)
3566 {
3567  if (ValidRow(nRow) && pRowFlags)
3568  {
3569  // Always set filter flag; unchanged when Hidden
3570  bool bChanged = SetRowHidden(nRow, nRow, !bShow);
3571  SetRowFiltered(nRow, nRow, !bShow);
3572 
3573  if (bChanged)
3574  {
3576  if ( pCharts )
3577  pCharts->SetRangeDirty(ScRange( 0, nRow, nTab, rDocument.MaxCol(), nRow, nTab ));
3578 
3579  if (pOutlineTable)
3580  UpdateOutlineRow( nRow, nRow, bShow );
3581 
3583  }
3584  }
3585  else
3586  {
3587  OSL_FAIL("Invalid row number or no flags");
3588  }
3589 }
3590 
3591 void ScTable::DBShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
3592 {
3593  SCROW nStartRow = nRow1;
3594  while (nStartRow <= nRow2)
3595  {
3596  SCROW nEndRow = -1;
3597  bool bWasVis = !RowHiddenLeaf(nStartRow, nullptr, &nEndRow);
3598  if (nEndRow > nRow2)
3599  nEndRow = nRow2;
3600 
3601  bool bChanged = ( bWasVis != bShow );
3602 
3603  SetRowHidden(nStartRow, nEndRow, !bShow);
3604  SetRowFiltered(nStartRow, nEndRow, !bShow);
3605 
3606  if ( bChanged )
3607  {
3609  if ( pCharts )
3610  pCharts->SetRangeDirty(ScRange( 0, nStartRow, nTab, rDocument.MaxCol(), nEndRow, nTab ));
3611  }
3612 
3613  nStartRow = nEndRow + 1;
3614  }
3615 
3616  // #i12341# For Show/Hide rows, the outlines are updated separately from the outside.
3617  // For filtering, the changes aren't visible to the caller, so UpdateOutlineRow has
3618  // to be done here.
3619  if (pOutlineTable)
3620  UpdateOutlineRow( nRow1, nRow2, bShow );
3621 }
3622 
3623 void ScTable::ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
3624 {
3625  SCROW nStartRow = nRow1;
3626 
3627  // #i116164# if there are no drawing objects within the row range, a single HeightChanged call is enough
3628  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
3629  bool bHasObjects = pDrawLayer && pDrawLayer->HasObjectsInRows( nTab, nRow1, nRow2 );
3630 
3631  while (nStartRow <= nRow2)
3632  {
3633  SCROW nEndRow = -1;
3634  bool bWasVis = !RowHiddenLeaf(nStartRow, nullptr, &nEndRow);
3635  if (nEndRow > nRow2)
3636  nEndRow = nRow2;
3637 
3638  bool bChanged = ( bWasVis != bShow );
3639 
3640  SetRowHidden(nStartRow, nEndRow, !bShow);
3641  if (bShow)
3642  SetRowFiltered(nStartRow, nEndRow, false);
3643 
3644  if ( bChanged )
3645  {
3647  if ( pCharts )
3648  pCharts->SetRangeDirty(ScRange( 0, nStartRow, nTab, rDocument.MaxCol(), nEndRow, nTab ));
3649 
3651  }
3652 
3653  nStartRow = nEndRow + 1;
3654  }
3655 
3656  if ( !bHasObjects )
3657  {
3658  // #i116164# set the flags for the whole range at once
3659  SetRowHidden(nRow1, nRow2, !bShow);
3660  if (bShow)
3661  SetRowFiltered(nRow1, nRow2, false);
3662  }
3663 }
3664 
3665 bool ScTable::IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, SCROW nRowEnd) const
3666 {
3667  for (SCROW i = nRowStart; i <= nRowEnd; ++i)
3668  {
3669  if (RowHidden(i))
3670  return true;
3671  }
3672  for (SCCOL i = nColStart; i <= nColEnd; ++i)
3673  {
3674  if (ColHidden(i))
3675  return true;
3676  }
3677  return false;
3678 }
3679 
3680 bool ScTable::IsDataFiltered(const ScRange& rRange) const
3681 {
3682  return IsDataFiltered(rRange.aStart.Col(), rRange.aStart.Row(),
3683  rRange.aEnd.Col(), rRange.aEnd.Row());
3684 }
3685 
3686 void ScTable::SetRowFlags( SCROW nRow, CRFlags nNewFlags )
3687 {
3688  if (ValidRow(nRow) && pRowFlags)
3689  pRowFlags->SetValue( nRow, nNewFlags);
3690  else
3691  {
3692  OSL_FAIL("Invalid row number or no flags");
3693  }
3694 }
3695 
3696 void ScTable::SetRowFlags( SCROW nStartRow, SCROW nEndRow, CRFlags nNewFlags )
3697 {
3698  if (ValidRow(nStartRow) && ValidRow(nEndRow) && pRowFlags)
3699  pRowFlags->SetValue( nStartRow, nEndRow, nNewFlags);
3700  else
3701  {
3702  OSL_FAIL("Invalid row number(s) or no flags");
3703  }
3704 }
3705 
3707 {
3708  if (ValidCol(nCol) && mpColFlags)
3709  return mpColFlags->GetValue(nCol);
3710  else
3711  return CRFlags::NONE;
3712 }
3713 
3715 {
3716  if (ValidRow(nRow) && pRowFlags)
3717  return pRowFlags->GetValue(nRow);
3718  else
3719  return CRFlags::NONE;
3720 }
3721 
3723 {
3724  SCROW nLastFound = 0;
3725  if (pRowFlags)
3726  {
3727  SCROW nRow = pRowFlags->GetLastAnyBitAccess( CRFlags::All );
3728  if (ValidRow(nRow))
3729  nLastFound = nRow;
3730  }
3731 
3732  if (!maRowManualBreaks.empty())
3733  nLastFound = ::std::max(nLastFound, *maRowManualBreaks.rbegin());
3734 
3735  if (mpHiddenRows)
3736  {
3737  SCROW nRow = mpHiddenRows->findLastTrue();
3738  if (ValidRow(nRow))
3739  nLastFound = ::std::max(nLastFound, nRow);
3740  }
3741 
3742  if (mpFilteredRows)
3743  {
3744  SCROW nRow = mpFilteredRows->findLastTrue();
3745  if (ValidRow(nRow))
3746  nLastFound = ::std::max(nLastFound, nRow);
3747  }
3748 
3749  return nLastFound;
3750 }
3751 
3753 {
3754  if ( !mpColFlags )
3755  return 0;
3756 
3757  SCCOL nLastFound = 0;
3758  const auto nColSize = aCol.size();
3759  auto colWidthIt = mpColWidth->begin() + 1;
3760  for (SCCOL nCol = 1; nCol < nColSize; (++nCol < nColSize) ? ++colWidthIt : (void)false)
3761  if ((mpColFlags->GetValue(nCol) & CRFlags::All) || (*colWidthIt != STD_COL_WIDTH))
3762  nLastFound = nCol;
3763 
3764  return nLastFound;
3765 }
3766 
3768 {
3769  if ( !pRowFlags )
3770  return 0;
3771 
3772  SCROW nLastFlags = GetLastFlaggedRow();
3773 
3774  // Find the last row position where the height is NOT the standard row
3775  // height.
3776  // KOHEI: Test this to make sure it does what it's supposed to.
3777  SCROW nLastHeight = mpRowHeights->findLastTrue(ScGlobal::nStdRowHeight);
3778  if (!ValidRow(nLastHeight))
3779  nLastHeight = 0;
3780 
3781  return std::max( nLastFlags, nLastHeight);
3782 }
3783 
3784 bool ScTable::UpdateOutlineCol( SCCOL nStartCol, SCCOL nEndCol, bool bShow )
3785 {
3786  if (pOutlineTable && mpColFlags)
3787  {
3788  return pOutlineTable->GetColArray().ManualAction( nStartCol, nEndCol, bShow, *this, true );
3789  }
3790  else
3791  return false;
3792 }
3793 
3794 bool ScTable::UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, bool bShow )
3795 {
3796  if (pOutlineTable && pRowFlags)
3797  return pOutlineTable->GetRowArray().ManualAction( nStartRow, nEndRow, bShow, *this, false );
3798  else
3799  return false;
3800 }
3801 
3802 void ScTable::ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
3803 {
3804  // Column-wise expansion
3805 
3806  while (rX1 > 0 && ColHidden(rX1-1))
3807  --rX1;
3808 
3809  while (rX2 < rDocument.MaxCol() && ColHidden(rX2+1))
3810  ++rX2;
3811 
3812  // Row-wise expansion
3813 
3814  if (rY1 > 0)
3815  {
3817  if (mpHiddenRows->getRangeData(rY1-1, aData) && aData.mbValue)
3818  {
3819  SCROW nStartRow = aData.mnRow1;
3820  if (ValidRow(nStartRow))
3821  rY1 = nStartRow;
3822  }
3823  }
3824  if (rY2 < rDocument.MaxRow())
3825  {
3826  SCROW nEndRow = -1;
3827  if (RowHidden(rY2+1, nullptr, &nEndRow) && ValidRow(nEndRow))
3828  rY2 = nEndRow;
3829  }
3830 }
3831 
3832 void ScTable::StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
3833 {
3834  while ( rX2>rX1 && ColHidden(rX2) )
3835  --rX2;
3836  while ( rX2>rX1 && ColHidden(rX1) )
3837  ++rX1;
3838 
3839  if (rY1 < rY2)
3840  {
3842  if (mpHiddenRows->getRangeData(rY2, aData) && aData.mbValue)
3843  {
3844  SCROW nStartRow = aData.mnRow1;
3845  if (ValidRow(nStartRow) && nStartRow >= rY1)
3846  rY2 = nStartRow;
3847  }
3848  }
3849 
3850  if (rY1 < rY2)
3851  {
3852  SCROW nEndRow = -1;
3853  if (RowHidden(rY1, nullptr, &nEndRow) && ValidRow(nEndRow) && nEndRow <= rY2)
3854  rY1 = nEndRow;
3855  }
3856 }
3857 
3858 // Auto-Outline
3859 
3860 template< typename T >
3861 static short DiffSign( T a, T b )
3862 {
3863  return (a<b) ? -1 :
3864  (a>b) ? 1 : 0;
3865 }
3866 
3867 namespace {
3868 
3869 class OutlineArrayFinder
3870 {
3871  ScRange maRef;
3872  SCCOL mnCol;
3873  SCTAB mnTab;
3875  bool mbSizeChanged;
3876 
3877 public:
3878  OutlineArrayFinder(const ScRange& rRef, SCCOL nCol, SCTAB nTab, ScOutlineArray* pArray, bool bSizeChanged) :
3879  maRef(rRef), mnCol(nCol), mnTab(nTab), mpArray(pArray),
3880  mbSizeChanged(bSizeChanged) {}
3881 
3882  bool operator() (size_t nRow, const ScFormulaCell* pCell)
3883  {
3884  SCROW nRow2 = static_cast<SCROW>(nRow);
3885 
3886  if (!pCell->HasRefListExpressibleAsOneReference(maRef))
3887  return false;
3888 
3889  if (maRef.aStart.Row() != nRow2 || maRef.aEnd.Row() != nRow2 ||
3890  maRef.aStart.Tab() != mnTab || maRef.aEnd.Tab() != mnTab)
3891  return false;
3892 
3893  if (DiffSign(maRef.aStart.Col(), mnCol) != DiffSign(maRef.aEnd.Col(), mnCol))
3894  return false;
3895 
3896  return mpArray->Insert(maRef.aStart.Col(), maRef.aEnd.Col(), mbSizeChanged);
3897  }
3898 };
3899 
3900 }
3901 
3902 void ScTable::DoAutoOutline( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
3903 {
3904  typedef mdds::flat_segment_tree<SCROW, bool> UsedRowsType;
3905 
3906  bool bSizeChanged = false;
3907 
3908  SCCOL nCol;
3909  SCROW nRow;
3910  bool bFound;
3911  ScRange aRef;
3912 
3913  nEndCol = ClampToAllocatedColumns(nEndCol);
3914 
3916 
3917  // Rows
3918 
3919  UsedRowsType aUsed(0, rDocument.MaxRow()+1, false);
3920  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
3921  aCol[nCol].FindUsed(nStartRow, nEndRow, aUsed);
3922  aUsed.build_tree();
3923 
3924  ScOutlineArray& rRowArray = pOutlineTable->GetRowArray();
3925  for (nRow=nStartRow; nRow<=nEndRow; nRow++)
3926  {
3927  bool bUsed = false;
3928  SCROW nLastRow = nRow;
3929  aUsed.search_tree(nRow, bUsed, nullptr, &nLastRow);
3930  if (!bUsed)
3931  {
3932  nRow = nLastRow;
3933  continue;
3934  }
3935 
3936  bFound = false;
3937  for (nCol=nStartCol; nCol<=nEndCol && !bFound; nCol++)
3938  {
3939  ScRefCellValue aCell = aCol[nCol].GetCellValue(nRow);
3940 
3941  if (aCell.meType != CELLTYPE_FORMULA)
3942  continue;
3943 
3945  continue;
3946 
3947  if ( aRef.aStart.Col() == nCol && aRef.aEnd.Col() == nCol &&
3948  aRef.aStart.Tab() == nTab && aRef.aEnd.Tab() == nTab &&
3949  DiffSign( aRef.aStart.Row(), nRow ) ==
3950  DiffSign( aRef.aEnd.Row(), nRow ) )
3951  {
3952  if (rRowArray.Insert( aRef.aStart.Row(), aRef.aEnd.Row(), bSizeChanged ))
3953  {
3954  bFound = true;
3955  }
3956  }
3957  }
3958  }
3959 
3960  // Column
3961  ScOutlineArray& rColArray = pOutlineTable->GetColArray();
3962  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
3963  {
3964  if (aCol[nCol].IsEmptyData())
3965  continue;
3966 
3967  OutlineArrayFinder aFunc(aRef, nCol, nTab, &rColArray, bSizeChanged);
3968  sc::FindFormula(aCol[nCol].maCells, nStartRow, nEndRow, aFunc);
3969  }
3970 }
3971 
3972  // CopyData - for Query in other range
3973 
3974 void ScTable::CopyData( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
3975  SCCOL nDestCol, SCROW nDestRow, SCTAB nDestTab )
3976 {
3977  //TODO: if used for multiple rows, optimize after columns!
3978 
3979  ScAddress aSrc( nStartCol, nStartRow, nTab );
3980  ScAddress aDest( nDestCol, nDestRow, nDestTab );
3981  ScRange aRange( aSrc, aDest );
3982  bool bThisTab = ( nDestTab == nTab );
3983  SCROW nDestY = nDestRow;
3984  for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
3985  {
3986  aSrc.SetRow( nRow );
3987  aDest.SetRow( nDestY );
3988  SCCOL nDestX = nDestCol;
3989  for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
3990  {
3991  aSrc.SetCol( nCol );
3992  aDest.SetCol( nDestX );
3993  ScCellValue aCell;
3994  aCell.assign(rDocument, ScAddress(nCol, nRow, nTab));
3995 
3996  if (aCell.meType == CELLTYPE_FORMULA)
3997  {
3998  sc::RefUpdateContext aCxt(rDocument);
3999  aCxt.meMode = URM_COPY;
4000  aCxt.maRange = aRange;
4001  aCxt.mnColDelta = nDestCol - nStartCol;
4002  aCxt.mnRowDelta = nDestRow - nStartRow;
4003  aCxt.mnTabDelta = nDestTab - nTab;
4004  aCell.mpFormula->UpdateReference(aCxt);
4005  aCell.mpFormula->aPos = aDest;
4006  }
4007 
4008  if (bThisTab)
4009  {
4010  aCell.release(CreateColumnIfNotExists(nDestX), nDestY);
4011  SetPattern( nDestX, nDestY, *GetPattern( nCol, nRow ) );
4012  }
4013  else
4014  {
4015  aCell.release(rDocument, aDest);
4016  rDocument.SetPattern( aDest, *GetPattern( nCol, nRow ) );
4017  }
4018 
4019  ++nDestX;
4020  }
4021  ++nDestY;
4022  }
4023 }
4024 
4026 {
4027  ScRange aRef;
4028 
4029  if (pCell->HasOneReference(aRef))
4030  {
4031  if (aRef.aStart.Col()==aRef.aEnd.Col() && aRef.aStart.Tab()==aRef.aEnd.Tab())
4032  {
4033  SCROW nEndRow;
4034  if (!RowFiltered(aRef.aStart.Row(), nullptr, &nEndRow))
4035  // row not filtered.
4036  nEndRow = ::std::numeric_limits<SCROW>::max();
4037 
4038  if (!ValidRow(nEndRow) || nEndRow < aRef.aEnd.Row())
4039  return true; // at least partly visible
4040  return false; // completely invisible
4041  }
4042  }
4043 
4044  return true; // somehow different
4045 }
4046 
4047 void ScTable::GetUpperCellString(SCCOL nCol, SCROW nRow, OUString& rStr)
4048 {
4049  GetInputString(nCol, nRow, rStr);
4050  rStr = ScGlobal::getCharClassPtr()->uppercase(rStr.trim());
4051 }
4052 
4053 // Calculate the size of the sheet and set the size on DrawPage
4054 
4055 void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos,
4056  ScObjectHandling eObjectHandling)
4057 {
4058  ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
4059  if( pDrawLayer )
4060  {
4061  const sal_Int64 nMax = ::std::numeric_limits<tools::Long>::max();
4062  // #i113884# Avoid int32 overflow with possible negative results than can cause bad effects.
4063  // If the draw page size is smaller than all rows, only the bottom of the sheet is affected.
4064  tools::Long x = std::min(o3tl::convert(GetColOffset(rDocument.MaxCol() + 1),
4066  nMax);
4067  tools::Long y = std::min(o3tl::convert(GetRowOffset(rDocument.MaxRow() + 1),
4069  nMax);
4070 
4071  if ( IsLayoutRTL() ) // IsNegativePage
4072  x = -x;
4073 
4074  pDrawLayer->SetPageSize(static_cast<sal_uInt16>(nTab), Size(x, y), bUpdateNoteCaptionPos,
4075  eObjectHandling);
4076  }
4077 
4078  // #i102616# actions that modify the draw page size count as sheet modification
4079  // (exception: InitDrawLayer)
4080  if (bResetStreamValid)
4081  SetStreamValid(false);
4082 }
4083 
4084 void ScTable::SetRangeName(std::unique_ptr<ScRangeName> pNew)
4085 {
4086  mpRangeName = std::move(pNew);
4087 
4088  //fdo#39792: mark stream as invalid, otherwise new ScRangeName will not be written to file
4089  SetStreamValid(false);
4090 }
4091 
4093 {
4094  if (!mpRangeName)
4095  mpRangeName.reset(new ScRangeName);
4096  return mpRangeName.get();
4097 }
4098 
4099 sal_uLong ScTable::GetRowOffset( SCROW nRow, bool bHiddenAsZero ) const
4100 {
4101  sal_uLong n = 0;
4102  if ( mpHiddenRows && mpRowHeights )
4103  {
4104  if (nRow == 0)
4105  return 0;
4106  else if (nRow == 1)
4107  return GetRowHeight(0, nullptr, nullptr, bHiddenAsZero );
4108 
4109  n = GetTotalRowHeight(0, nRow-1, bHiddenAsZero);
4110 #if OSL_DEBUG_LEVEL > 0
4111  if (n == ::std::numeric_limits<tools::ULong>::max())
4112  OSL_FAIL("ScTable::GetRowOffset: row heights overflow");
4113 #endif
4114  }
4115  else
4116  {
4117  OSL_FAIL("GetRowOffset: Data missing");
4118  }
4119  return n;
4120 }
4121 
4123 {
4124  sal_uLong nSum = 0;
4125 
4127 
4128  ScFlatUInt16RowSegments::RangeData aRowHeightRange;
4129  aRowHeightRange.mnRow2 = -1;
4130  aRowHeightRange.mnValue = 0; // silence MSVC C4701
4131 
4132  for (SCROW nRow = 0; nRow <= rDocument.MaxRow(); ++nRow)
4133  {
4134  if (!mpHiddenRows->getRangeData(nRow, aData))
4135  // Failed to fetch the range data for whatever reason.
4136  break;
4137 
4138  if (aData.mbValue)
4139  {
4140  // This row is hidden. Skip ahead all hidden rows.
4141  nRow = aData.mnRow2;
4142  continue;
4143  }
4144 
4145  if (aRowHeightRange.mnRow2 < nRow)
4146  {
4147  if (!mpRowHeights->getRangeData(nRow, aRowHeightRange))
4148  // Failed to fetch the range data for whatever reason.
4149  break;
4150  }
4151 
4152  // find the last common row between hidden & height spans
4153  SCROW nLastCommon = std::min(aData.mnRow2, aRowHeightRange.mnRow2);
4154  assert (nLastCommon >= nRow);
4155  SCROW nCommon = nLastCommon - nRow + 1;
4156 
4157  // how much further to go ?
4158  sal_uLong nPixelsLeft = nHeight - nSum;
4159  sal_uLong nCommonPixels = static_cast<sal_uLong>(aRowHeightRange.mnValue) * nCommon;
4160 
4161  // are we in the zone ?
4162  if (nCommonPixels > nPixelsLeft)
4163  {
4164  nRow += (nPixelsLeft + aRowHeightRange.mnValue - 1) / aRowHeightRange.mnValue;
4165 
4166  // FIXME: finding this next row is far from elegant,
4167  // we have a single caller, which subtracts one as well(!?)
4168  if (nRow >= rDocument.MaxRow())
4169  return rDocument.MaxRow();
4170 
4171  if (!mpHiddenRows->getRangeData(nRow, aData))
4172  // Failed to fetch the range data for whatever reason.
4173  break;
4174 
4175  if (aData.mbValue)
4176  // These rows are hidden.
4177  nRow = aData.mnRow2 + 1;
4178 
4179  return nRow <= rDocument.MaxRow() ? nRow : rDocument.MaxRow();
4180  }
4181 
4182  // skip the range and keep hunting
4183  nSum += nCommonPixels;
4184  nRow = nLastCommon;
4185  }
4186  return -1;
4187 }
4188 
4189 sal_uLong ScTable::GetColOffset( SCCOL nCol, bool bHiddenAsZero ) const
4190 {
4191  sal_uLong n = 0;
4192  if ( mpColWidth )
4193  {
4194  auto colWidthIt = mpColWidth->begin();
4195  for (SCCOL i = 0; i < nCol; (++i < nCol) ? ++colWidthIt : (void)false)
4196  if (!( bHiddenAsZero && ColHidden(i) ))
4197  n += *colWidthIt;
4198  }
4199  else
4200  {
4201  OSL_FAIL("GetColumnOffset: Data missing");
4202  }
4203  return n;
4204 }
4205 
4206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
If set, cloned formula cells will start to listen to the document.
void FindMaxRotCol(RowInfo *pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCOL nX2)
Definition: table2.cxx:2365
void SetFormula(SCCOL nCol, SCROW nRow, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGram)
Definition: table2.cxx:1685
void SetMergedCells(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:2261
void CellStorageModified()
Called whenever the state of cell array gets modified i.e.
Definition: column2.cxx:1601
void ApplyStyle(SCROW nRow, const ScStyleSheet *rStyle)
Definition: column.cxx:560
void CalcAfterLoad(sc::CompileFormulaContext &rCxt, bool bStartListening)
Definition: table2.cxx:2128
void CopyUpdated(const ScTable *pPosTab, ScTable *pDestTab) const
Definition: table2.cxx:1517
svl::SharedString GetSharedString(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1722
constexpr double nPPTY
bool TestCopyScenarioTo(const ScTable *pDestTab) const
Definition: table2.cxx:1606
SCCOL GetColMerge() const
Definition: attrib.hxx:68
SCTAB nTab
Definition: table.hxx:204
SCROW mnRowDelta
Amount and direction of movement in the row direction.
const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:2191
bool SetRowHeightRange(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight, double nPPTY, bool bApi)
Definition: table2.cxx:3185
Temporarily switch on/off auto calculation mode.
Definition: scopetools.hxx:26
SCCOL GetLastChangedCol() const
Definition: table2.cxx:3752
bool Intersects(const ScRange &) const
Definition: rangelst.cxx:1082
CellType meType
Definition: cellvalue.hxx:37
ScRotateDir GetRotateDir(const SfxItemSet *pCondSet) const
Definition: patattr.cxx:1327
ScFormulaCell * SetFormulaCell(SCCOL nCol, SCROW nRow, ScFormulaCell *pCell)
Takes ownership of pCell.
Definition: table2.cxx:1703
void ApplyStyleArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: table2.cxx:2873
bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, HasAttrFlags nMask) const
Definition: table2.cxx:2211
bool HasScenarioRange(SCTAB nTab, const ScRange &rRange) const
Definition: documen3.cxx:864
ScAddress aStart
Definition: address.hxx:499
ScRotateDir
Definition: fillinfo.hxx:40
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1906
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
void UnlockTable()
Definition: table2.cxx:2727
bool HasBlockMatrixFragment(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2, bool bNoMatrixAtAll=false) const
Definition: table2.cxx:2442
void CompileAll(sc::CompileFormulaContext &rCxt)
Definition: table2.cxx:2093
Store parameters used in the ScDocument::SetString() method.
Definition: stringutil.hxx:34
void ForgetNoteCaptions(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bPreserveData)
Definition: table2.cxx:1842
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: table2.cxx:2015
void SetRowFlags(SCROW nRow, CRFlags nNewFlags)
Definition: table2.cxx:3686
bool IsBlockEmpty(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bIgnoreNotes) const
Definition: table2.cxx:2276
void MergeSelectionPattern(ScMergePatternState &rState, const ScMarkData &rMark, bool bDeep) const
Definition: column.cxx:335
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: column.cxx:370
void SetRowHeight(SCROW nRow, sal_uInt16 nNewHeight)
Definition: table2.cxx:3124
std::unique_ptr< ScFlatUInt16RowSegments > mpRowHeights
Definition: table.hxx:181
HasAttrFlags
Definition: global.hxx:192
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
void SetPatternAreaCondFormat(SCCOL nCol, SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rAttr, const ScCondFormatIndexes &rCondFormatIndexes)
Definition: table2.cxx:2849
Sheet / outlining (grouping) information.
SCROW Row() const
Definition: address.hxx:261
Simple container to keep track of sheet - column pair.
Definition: columnset.hxx:23
Single reference (one address) into the sheet.
Definition: refdata.hxx:29
ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2521
bool IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, SCROW nRowEnd) const
Definition: table2.cxx:3665
bool IsSelectionEditable(const ScMarkData &rMark, bool *pOnlyNotBecauseOfMatrix=nullptr) const
Definition: table2.cxx:2638
void SetRowHeightOnly(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight)
Set specified row height to specified ranges.
Definition: table2.cxx:3241
SCTAB GetTab() const
Definition: table.hxx:281
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:877
size_t GetNoteCount(SCCOL nCol) const
Definition: table2.cxx:1820
ScRangeList & GetRangeList()
Definition: conditio.hxx:561
void ApplyPattern(SCCOL nCol, SCROW nRow, const ScPatternAttr &rAttr)
Definition: table2.cxx:2786
ScColumn * FetchColumn(SCCOL nCol)
Definition: table2.cxx:1228
ScObjectHandling
Definition: drwlayer.hxx:89
std::unique_ptr< ScPostIt > ReleaseNote(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1812
ScScenarioFlags
Definition: global.hxx:235
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
void CopyData(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCCOL nDestCol, SCROW nDestRow, SCTAB nDestTab)
Definition: table2.cxx:3974
bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1558
void TransposeReference()
SCCOL size() const
ScMF GetValue() const
Definition: attrib.hxx:97
sal_uIntPtr sal_uLong
long Long
bool TestInsertRow(SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize) const
Definition: table2.cxx:135
Context for reference update during shifting, moving or copying of cell ranges.
void CopyRowFiltered(const ScTable &rTable, SCROW nStartRow, SCROW nEndRow)
Definition: table5.cxx:901
bool IsOverlapped() const
Definition: attrib.hxx:101
CellType GetCellType(const ScAddress &rPos) const
Definition: table.hxx:458
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
void SetCalcNotification(bool bSet)
Definition: table2.cxx:130
void SetEditText(SCROW nRow, std::unique_ptr< EditTextObject > pEditText)
Definition: column3.cxx:2217
sal_Int64 n
void GetString(SCCOL nCol, SCROW nRow, OUString &rString, const ScInterpreterContext *pContext=nullptr) const
Definition: table2.cxx:1742
bool IsUndo() const
Definition: document.hxx:1533
void DetachFormulaCells(sc::EndListeningContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1272
std::unique_ptr< ScFlatBoolColSegments > mpFilteredCols
Definition: table.hxx:187
const ScStyleSheet * GetSelectionStyle(const ScMarkData &rMark, bool &rFound) const
Definition: table2.cxx:2930
Rich-text attributes.
ScColumnVector::const_iterator end() const
bool HasScenarioRange(const ScRange &rRange) const
Definition: table2.cxx:1564
sal_Int32 mnCol
sal_uInt16 nLockCount
Definition: table.hxx:219
CommentCaptionState GetAllNoteCaptionsState(const ScRange &rRange, std::vector< sc::NoteEntry > &rNotes)
Definition: table2.cxx:1868
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:387
Store position data for column array storage.
const SfxItemSet & GetItemSet() const
sal_uInt16 GetDistance(SvxBoxItemLine nLine) const
bool mbPageBreaksValid
Definition: table.hxx:245
InsertDeleteFlags getInsertFlag() const
bool IsClipOrUndo() const
Definition: document.hxx:1532
void TransposeColPatterns(ScTable *pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1, SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered, const std::vector< SCROW > &rFilteredRows, SCROW nRowDestOffset)
Transpose clipboard patterns.
Definition: table2.cxx:1042
bool HasObjectsInRows(SCTAB nTab, SCROW nStartRow, SCROW nEndRow)
Definition: drwlayer.cxx:1474
void CopyStaticToDocument(SCROW nRow1, SCROW nRow2, const SvNumberFormatterMergeMap &rMap, ScColumn &rDestCol)
Definition: column.cxx:1062
bool CompileErrorCells(sc::CompileFormulaContext &rCxt, FormulaError nErrCode)
Definition: table2.cxx:2116
sal_uInt16 GetTextWidth(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:86
void GetFirstDataPos(SCCOL &rCol, SCROW &rRow) const
Definition: table2.cxx:1937
ScAddress aEnd
Definition: address.hxx:500
void SetManualHeight(SCROW nStartRow, SCROW nEndRow, bool bManual)
Definition: table2.cxx:3252
void SetColHidden(SCCOL nStartCol, SCCOL nEndCol, bool bHidden)
Definition: table5.cxx:638
void ApplyPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rPatAttr, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: column.cxx:516
virtual SfxItemSet & GetItemSet()
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
void CopyScenarioTo(const ScTable *pDestTab) const
Definition: table2.cxx:1535
void UndoToTable(sc::CopyToDocContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, InsertDeleteFlags nFlags, bool bMarked, ScTable *pDestTab)
Definition: table2.cxx:1465
void DeleteRow(const sc::ColumnSet &rRegroupCols, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize, bool *pUndoOutline, std::vector< ScAddress > *pGroupPos)
Definition: table2.cxx:196
sal_uInt16 GetOriginalHeight(SCROW nRow) const
Definition: table2.cxx:3496
void RemoveEditTextCharAttribs(SCCOL nCol, SCROW nRow, const ScPatternAttr &rAttr)
Definition: table2.cxx:1781
const editeng::SvxBorderLine * GetRight() const
mdds::multi_type_vector< CellFunc, CellStoreEvent > CellStoreType
const ScStyleSheet * GetStyle(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:2920
float x
void TransposeClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCROW nCombinedStartRow, SCROW nRowDestOffset, ScTable *pTransClip, InsertDeleteFlags nFlags, bool bAsLink, bool bIncludeFiltered)
Definition: table2.cxx:980
void MixData(sc::MixDocContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScPasteFunc nFunction, bool bSkipEmpty, const ScTable *pSrcTab)
Definition: table2.cxx:777
bool HasData(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1963
void SetDirtyAfterLoad()
Definition: table2.cxx:2044
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
void MergeBlockFrame(SvxBoxItem *pLineOuter, SvxBoxInfoItem *pLineInner, ScLineFlags &rFlags, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow) const
Definition: table2.cxx:2758
void ApplySelectionStyle(const ScStyleSheet &rStyle, const ScMarkData &rMark)
Definition: table2.cxx:2904
std::unique_ptr< ScRangeName > mpRangeName
Definition: table.hxx:226
SCROW nRowNo
Definition: fillinfo.hxx:181
SCROW GetRowForHeight(sal_uLong nHeight) const
Get the last row such that the height of row 0 to the end row is as high as possible without exceedin...
Definition: table2.cxx:4122
const ScAddress & GetAddress() const
Definition: brdcst.hxx:30
constexpr TypedWhichId< ScMergeAttr > ATTR_MERGE(144)
void ApplyAttr(SCCOL nCol, SCROW nRow, const SfxPoolItem &rAttr)
Definition: table2.cxx:3064
Internal use only (d&d undo): do not delete caption objects of cell notes.
void MarkScenarioIn(ScMarkData &rMark, ScScenarioFlags nNeededBits) const
Definition: table2.cxx:1553
bool UpdateReference(const sc::RefUpdateContext &rCxt, ScDocument *pUndoDoc=nullptr, const ScAddress *pUndoCellPos=nullptr)
bool ValidRow(SCROW nRow) const
Definition: table.hxx:331
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6087
void StartListeners(sc::StartListeningContext &rCxt, bool bAll)
Either start all formula cells as listeners unconditionally, or start those that are marked "needs li...
Definition: table2.cxx:1244
void SetStreamValid(bool bSet, bool bIgnoreLock=false)
Definition: table1.cxx:374
ScColumn & CreateColumnIfNotExists(const SCCOL nScCol) const
Definition: table.hxx:285
FuncFlags mnFlags
Information about all parameters.
void AttachFormulaCells(sc::StartListeningContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1264
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:35
constexpr TypedWhichId< ScRotateValueItem > ATTR_ROTATE_VALUE(135)
void ResetChanged(const ScRange &rRange)
Definition: table2.cxx:2134
ScFormulaCell * SetFormulaCell(SCROW nRow, ScFormulaCell *pCell, sc::StartListeningType eListenType=sc::SingleCellListening, bool bInheritNumFormatIfNeeded=true)
Takes ownership of pCell.
Definition: column3.cxx:2315
const ScRangeList & GetRange() const
Definition: conditio.hxx:559
sal_uLong GetColOffset(SCCOL nCol, bool bHiddenAsZero=true) const
Definition: table2.cxx:4189
static void lcl_SetTransposedPatternInRows(ScTable *pTransClip, SCROW nAttrRow1, SCROW nAttrRow2, SCCOL nCol1, SCROW nRow1, SCROW nCombinedStartRow, SCCOL nCol, const ScPatternAttr &rPatternAttr, bool bIncludeFiltered, const std::vector< SCROW > &rFilteredRows, SCROW nRowDestOffset)
Definition: table2.cxx:1012
#define STD_COL_WIDTH
Definition: global.hxx:94
void SetNumberFormat(SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat)
Definition: table2.cxx:2183
bool IsBlockEditable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool *pOnlyNotBecauseOfMatrix=nullptr, bool bNoMatrixAtAll=false) const
Definition: table2.cxx:2554
void InsertRow(SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize)
Definition: table2.cxx:148
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:42
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
void SetTableOpDirty(const ScRange &)
Definition: table2.cxx:2034
void SetAnonymousDBData(std::unique_ptr< ScDBData > pDBData)
Definition: table1.cxx:2373
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
Additional class containing cell annotation data.
Definition: postit.hxx:159
void SetColManualBreaks(const ::std::set< SCCOL > &rBreaks)
Definition: table5.cxx:329
void TransposeColNotes(ScTable *pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nRow1, SCROW nRow2, SCROW nCombinedStartRow, bool bIncludeFiltered, SCROW nRowDestOffset)
Transpose clipboard notes.
Definition: table2.cxx:1113
static short DiffSign(T a, T b)
Definition: table2.cxx:3861
void GetFormula(SCCOL nCol, SCROW nRow, OUString &rFormula) const
Definition: table2.cxx:1789
sal_uLong GetScaledRowHeight(SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong *pnMaxHeight=nullptr) const
Definition: table2.cxx:3432
bool UpdateOutlineCol(SCCOL nStartCol, SCCOL nEndCol, bool bShow)
Definition: table2.cxx:3784
void SetNumberFormat(SCROW nRow, sal_uInt32 nNumberFormat)
Definition: column2.cxx:3028
double * GetValueCell(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1750
sc::CellStoreType maCells
Definition: column.hxx:129
const std::shared_ptr< const ColumnSet > & getColumnSet() const
void SetColWidthOnly(SCCOL nCol, sal_uInt16 nNewWidth)
Definition: table2.cxx:3112
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:110
SCTAB Tab() const
Definition: address.hxx:270
void CopyToClip(sc::CopyToClipContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable *pTable)
Definition: table2.cxx:482
void StripHidden(SCCOL &rX1, SCROW &rY1, SCCOL &rX2, SCROW &rY2)
Definition: table2.cxx:3832
void SetRow(SCROW nRowP)
Definition: address.hxx:274
void release(ScDocument &rDoc, const ScAddress &rPos)
Set cell value at specified position in specified document.
Definition: cellvalue.cxx:432
void CopyColHidden(const ScTable &rTable, SCCOL nStartCol, SCCOL nEndCol)
Definition: table5.cxx:672
bool SetRowHidden(SCROW nStartRow, SCROW nEndRow, bool bHidden)
Definition: table5.cxx:588
void SetColWidth(SCCOL nCol, sal_uInt16 nNewWidth)
Definition: table2.cxx:3091
const editeng::SvxBorderLine * GetLine(SvxBoxItemLine nLine) const
bool HasValueData(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1979
bool SetFormulaCells(SCROW nRow, std::vector< ScFormulaCell * > &rCells)
Definition: column3.cxx:2353
sal_uInt32 GetNumberFormat(const ScInterpreterContext &rContext, SCROW nRow) const
Definition: column.cxx:421
ScColumnVector::const_iterator begin() const
void SetValue(SCCOL nCol, SCROW nRow, const double &rVal)
Definition: table2.cxx:1730
std::unique_ptr< ScOutlineTable > pOutlineTable
Definition: table.hxx:195
ScAddress aPos
void DoAutoOutline(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: table2.cxx:3902
void SetRangeName(std::unique_ptr< ScRangeName > pNew)
Definition: table2.cxx:4084
void SetPattern(const ScAddress &rPos, const ScPatternAttr &rAttr)
Definition: table2.cxx:3045
bool RemoveFlags(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags)
Definition: table2.cxx:3033
ScBroadcastAreaSlotMachine * GetBASM() const
Definition: document.hxx:2153
void SetRowManualBreaks(const ::std::set< SCROW > &rBreaks)
Definition: table5.cxx:322
void SetCol(SCCOL nColP)
Definition: address.hxx:278
size_t size() const
Definition: conditio.cxx:1767
sal_uInt16 GetOriginalWidth(SCCOL nCol) const
Definition: table2.cxx:3304
bool HasSelectionMatrixFragment(const ScMarkData &rMark) const
Definition: table2.cxx:2538
std::unique_ptr< ScBitMaskCompressedArray< SCCOL, CRFlags > > mpColFlags
Definition: table.hxx:183
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:953
bool IsLayoutRTL() const
Definition: table.hxx:340
float y
bool IsColValid(const SCCOL nScCol) const
Definition: table.hxx:318
constexpr OUStringLiteral aData
bool SetString(SCROW nRow, SCTAB nTab, const OUString &rString, formula::FormulaGrammar::AddressConvention eConv, const ScSetStringParam *pParam=nullptr)
Returns true if the cell format was set as well.
Definition: column3.cxx:2197
bool HasRefListExpressibleAsOneReference(ScRange &rRange) const
constexpr double nPPTX
bool SetOutlineTable(const ScOutlineTable *pNewOutline)
Definition: table2.cxx:91
static SC_DLLPUBLIC sal_uInt16 nStdRowHeight
Definition: global.hxx:583
sal_uInt32 GetKey() const
Definition: conditio.hxx:591
void SetRange(const ScRangeList &rRanges)
Definition: conditio.cxx:1741
std::unique_ptr< ScFlatBoolColSegments > mpHiddenCols
Definition: table.hxx:185
bool SetFormulaCells(SCCOL nCol, SCROW nRow, std::vector< ScFormulaCell * > &rCells)
Definition: table2.cxx:1714
const ScFormatEntry * GetEntry(sal_uInt16 nPos) const
Definition: conditio.cxx:1781
ScPasteFunc
Definition: global.hxx:188
void ShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
Definition: table2.cxx:3623
void ApplyStyle(SCCOL nCol, SCROW nRow, const ScStyleSheet *rStyle)
Definition: table2.cxx:2866
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1058
const editeng::SvxBorderLine * GetTop() const
void SetDrawPageSize(bool bResetStreamValid=true, bool bUpdateNoteCaptionPos=true, const ScObjectHandling eObjectHandling=ScObjectHandling::RecalcPosMode)
Definition: table2.cxx:4055
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
bool ColHidden(SCCOL nCol, SCCOL *pFirstCol=nullptr, SCCOL *pLastCol=nullptr) const
Definition: table5.cxx:571
bool IsProtected() const
Definition: table5.cxx:1088
SC_DLLPUBLIC void SetPattern(const ScAddress &, const ScPatternAttr &rAttr)
Definition: document.cxx:5075
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
UNDERLYING_TYPE get() const
void GetScenarioFlags(SCTAB nTab, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:479
bool ValidCol(SCCOL nCol) const
Definition: table.hxx:330
SCCOL nRotMaxCol
Definition: fillinfo.hxx:182
const ScFormulaCell * GetFormulaCell(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1797
ScDocument & GetDoc()
Definition: table.hxx:279
void InitBlockPosition(sc::ColumnBlockPosition &rBlockPos)
Definition: column3.cxx:1044
const editeng::SvxBorderLine * GetLeft() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
void SetDirtyVar()
Definition: table2.cxx:2001
void SetRawString(SCROW nRow, const OUString &rStr)
Definition: column3.cxx:2850
void AddCondFormatData(const ScRangeList &rRange, sal_uInt32 nIndex)
Definition: table2.cxx:2815
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
const ScRangeList * GetScenarioRanges() const
Definition: table2.cxx:1592
void CheckVectorizationState()
Definition: table2.cxx:2007
void SetFlag3D(bool bVal)
Definition: refdata.hxx:89
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
Definition: refdata.cxx:27
sal_Int16 SCCOL
Definition: types.hxx:21
sal_uInt16 GetColWidth(SCCOL nCol, bool bHiddenAsZero=true) const
Definition: table2.cxx:3267
InsertDeleteFlags
Definition: global.hxx:157
void InvalidateScenarioRanges()
Definition: table2.cxx:1587
void CopyCaptionsToTable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable *pDestTab, bool bCloneCaption)
Definition: table2.cxx:1451
std::unique_ptr< ScDBData > pDBDataNoName
Definition: table.hxx:225
SC_DLLPUBLIC void SetAutoCalc(bool bNewAutoCalc)
Definition: documen7.cxx:602
void CopyRowHidden(const ScTable &rTable, SCROW nStartRow, SCROW nEndRow)
Definition: table5.cxx:687
sc::CellTextAttrStoreType maCellTextAttrs
Definition: column.hxx:118
std::unique_ptr< ScPostIt > Clone(const ScAddress &rOwnPos, ScDocument &rDestDoc, const ScAddress &rDestPos, bool bCloneCaption) const
Clones this note and its caption object, if specified.
Definition: postit.cxx:877
CRFlags GetRowFlags(SCROW nRow) const
Definition: table2.cxx:3714
void SetEmptyCell(SCCOL nCol, SCROW nRow)
Definition: table2.cxx:1677
::std::map< sal_uInt32, sal_uInt32 > SvNumberFormatterMergeMap
const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, sal_uInt16 nWhich) const
Definition: table2.cxx:2147
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:873
SvNumberFormatter * GetFormatTable() const
const SvxPageUsage aArr[]
ScScenarioFlags nScenarioFlags
Definition: table.hxx:224
void ApplyStyleArea(SCROW nStartRow, SCROW nEndRow, const ScStyleSheet &rStyle)
Definition: attarray.cxx:626
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
void GetUnprotectedCells(ScRangeList &rRangeList) const
Definition: table2.cxx:1901
void ShowCol(SCCOL nCol, bool bShow)
Definition: table2.cxx:3522
bool HasAttribSelection(const ScMarkData &rMark, HasAttrFlags nMask) const
Definition: table2.cxx:2224
void CopyFromClip(sc::CopyFromClipContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCCOL nDx, SCROW nDy, ScTable *pTable)
Definition: table2.cxx:716
const EditTextObject * GetEditText(SCCOL nCol, SCROW nRow) const
Definition: table2.cxx:1773
void DBShowRows(SCROW nRow1, SCROW nRow2, bool bShow)
Definition: table2.cxx:3591
void GetNotesInRange(const ScRange &rRange, std::vector< sc::NoteEntry > &rNotes) const
Definition: table2.cxx:1857
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
bool TestInsertRow(SCROW nStartRow, SCSIZE nSize) const
Definition: column.cxx:837
size_t size() const
Definition: rangelst.hxx:89
std::unique_ptr< ScTableProtection > pTabProtection
Definition: table.hxx:178
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
void GetLastDataPos(SCCOL &rCol, SCROW &rRow) const
Definition: table2.cxx:1952
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
bool IsCutMode()
Definition: document.cxx:2039
CellStoreType::const_iterator ParseAll(const typename CellStoreType::const_iterator &itPos, const CellStoreType &rCells, SCROW nRow1, SCROW nRow2, FuncElem &rFuncElem, FuncElse &rFuncElse)
Definition: mtvcellfunc.hxx:83
void SetNote(const ScAddress &rPos, std::unique_ptr< ScPostIt > pNote)
Definition: document.cxx:6549
void SetRangeDirty(const ScRange &rRange)
Definition: chartlis.cxx:570
void CompileXML(sc::CompileFormulaContext &rCxt, ScProgress &rProgress)
Definition: table2.cxx:2102
SvNumFormatType
bool EqualEntries(const ScConditionalFormat &r, bool bIgnoreSrcPos=false) const
Definition: conditio.cxx:1722
bool bTableAreaValid
Definition: table.hxx:236
ScColContainer aCol
Definition: table.hxx:157
void SetRawString(SCCOL nCol, SCROW nRow, const svl::SharedString &rStr)
Definition: table2.cxx:1736
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1255
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1291
void LockTable()
Definition: table2.cxx:2722
void DBShowRow(SCROW nRow, bool bShow)
Definition: table2.cxx:3565
::std::set< SCROW > maRowManualBreaks
Definition: table.hxx:191
std::unique_ptr< ScConditionalFormatList > mpCondFormatList
Definition: table.hxx:228
double * GetValueCell(SCROW nRow)
Definition: column3.cxx:2948
void SetDistance(sal_uInt16 nNew, SvxBoxItemLine nLine)
void ApplySelectionLineStyle(const ScMarkData &rMark, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: table2.cxx:2910
void BroadcastRecalcOnRefMove()
Broadcast dirty formula cells that contain functions such as CELL(), COLUMN() or ROW() which may chan...
Definition: table2.cxx:2062
bool empty() const
CommentCaptionState
Definition: document.hxx:253
void ExtendHidden(SCCOL &rX1, SCROW &rY1, SCCOL &rX2, SCROW &rY2)
Definition: table2.cxx:3802
void SetAreasChangedNeedBroadcast()
Definition: docsh.hxx:384
bool ApplyFlags(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags)
Definition: table2.cxx:3023
ScRange maRange
Range of cells that are about to be moved for insert/delete/move modes.
void ApplyAttr(SCROW nRow, const SfxPoolItem &rAttr)
Definition: column.cxx:715