tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / docshell / olinefun.cxx
blob3b15989c3664486d1de98b7c8afe36a88662101c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/bindings.hxx>
22 #include <olinefun.hxx>
24 #include <docsh.hxx>
25 #include <olinetab.hxx>
26 #include <tabvwsh.hxx>
27 #include <undodat.hxx>
28 #include <globstr.hrc>
29 #include <sc.hrc>
31 #include <comphelper/lok.hxx>
34 static void lcl_InvalidateOutliner( SfxBindings* pBindings )
36 if ( pBindings )
38 pBindings->Invalidate( SID_OUTLINE_SHOW );
39 pBindings->Invalidate( SID_OUTLINE_HIDE );
40 pBindings->Invalidate( SID_OUTLINE_REMOVE );
42 pBindings->Invalidate( SID_STATUS_SUM ); // because of enabling/disabling
43 pBindings->Invalidate( SID_ATTR_SIZE );
47 //! Move PaintWidthHeight to DocShell ?
49 static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab,
50 bool bColumns, SCCOLROW nStart, SCCOLROW nEnd )
52 ScDocument& rDoc = rDocShell.GetDocument();
54 PaintPartFlags nParts = PaintPartFlags::Grid;
55 SCCOL nStartCol = 0;
56 SCROW nStartRow = 0;
57 SCCOL nEndCol = rDoc.MaxCol(); // for testing if merged
58 SCROW nEndRow = rDoc.MaxRow();
59 if ( bColumns )
61 nParts |= PaintPartFlags::Top;
62 nStartCol = static_cast<SCCOL>(nStart);
63 nEndCol = static_cast<SCCOL>(nEnd);
65 else
67 nParts |= PaintPartFlags::Left;
68 nStartRow = nStart;
69 nEndRow = nEnd;
71 if (rDoc.HasAttrib( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
72 HasAttrFlags::Merged | HasAttrFlags::Overlapped ))
74 nStartCol = 0;
75 nStartRow = 0;
77 rDocShell.PostPaint( nStartCol,nStartRow,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab, nParts );
80 void ScOutlineDocFunc::MakeOutline( const ScRange& rRange, bool bColumns, bool bRecord, bool bApi )
82 SCCOL nStartCol = rRange.aStart.Col();
83 SCROW nStartRow = rRange.aStart.Row();
84 SCCOL nEndCol = rRange.aEnd.Col();
85 SCROW nEndRow = rRange.aEnd.Row();
86 SCTAB nTab = rRange.aStart.Tab();
88 ScDocument& rDoc = rDocShell.GetDocument();
89 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab, true );
90 std::unique_ptr<ScOutlineTable> pUndoTab;
92 if (bRecord && !rDoc.IsUndoEnabled())
93 bRecord = false;
95 if (bRecord)
96 pUndoTab.reset(new ScOutlineTable( *pTable ));
98 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
100 bool bRes;
101 bool bSize = false;
102 if ( bColumns )
103 bRes = rArray.Insert( nStartCol, nEndCol, bSize );
104 else
105 bRes = rArray.Insert( nStartRow, nEndRow, bSize );
107 if ( bRes )
109 if (bRecord)
111 rDocShell.GetUndoManager()->AddUndoAction(
112 std::make_unique<ScUndoMakeOutline>( &rDocShell,
113 nStartCol,nStartRow,nTab,nEndCol,nEndRow,nTab,
114 std::move(pUndoTab), bColumns, true ) );
117 rDoc.SetStreamValid(nTab, false);
119 PaintPartFlags nParts = PaintPartFlags::NONE; // Data range hasn't been changed
120 if ( bColumns )
121 nParts |= PaintPartFlags::Top;
122 else
123 nParts |= PaintPartFlags::Left;
124 if ( bSize )
125 nParts |= PaintPartFlags::Size;
127 rDocShell.PostPaint( 0,0,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab, nParts );
128 rDocShell.SetDocumentModified();
129 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
131 else
133 if (!bApi)
134 rDocShell.ErrorMessage(STR_MSSG_MAKEOUTLINE_0); // "Grouping not possible"
138 void ScOutlineDocFunc::RemoveOutline( const ScRange& rRange, bool bColumns, bool bRecord, bool bApi )
140 bool bDone = false;
142 SCCOL nStartCol = rRange.aStart.Col();
143 SCROW nStartRow = rRange.aStart.Row();
144 SCCOL nEndCol = rRange.aEnd.Col();
145 SCROW nEndRow = rRange.aEnd.Row();
146 SCTAB nTab = rRange.aStart.Tab();
148 ScDocument& rDoc = rDocShell.GetDocument();
150 if (bRecord && !rDoc.IsUndoEnabled())
151 bRecord = false;
152 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
153 if (pTable)
155 std::unique_ptr<ScOutlineTable> pUndoTab;
156 if (bRecord)
157 pUndoTab.reset(new ScOutlineTable( *pTable ));
159 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
161 bool bRes;
162 bool bSize = false;
163 if ( bColumns )
164 bRes = rArray.Remove( nStartCol, nEndCol, bSize );
165 else
166 bRes = rArray.Remove( nStartRow, nEndRow, bSize );
168 if ( bRes )
170 if (bRecord)
172 rDocShell.GetUndoManager()->AddUndoAction(
173 std::make_unique<ScUndoMakeOutline>( &rDocShell,
174 nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
175 std::move(pUndoTab), bColumns, false ) );
178 rDoc.SetStreamValid(nTab, false);
180 PaintPartFlags nParts = PaintPartFlags::NONE; // Data range hasn't been changed
181 if ( bColumns )
182 nParts |= PaintPartFlags::Top;
183 else
184 nParts |= PaintPartFlags::Left;
185 if ( bSize )
186 nParts |= PaintPartFlags::Size;
188 rDocShell.PostPaint( 0,0,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab, nParts );
189 rDocShell.SetDocumentModified();
190 bDone = true;
191 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
193 // we are not enabling again -> no UpdatePageBreaks
197 if (!bDone && !bApi)
198 rDocShell.ErrorMessage(STR_MSSG_REMOVEOUTLINE_0); // "Ungrouping not possible"
201 bool ScOutlineDocFunc::RemoveAllOutlines( SCTAB nTab, bool bRecord )
203 bool bSuccess = false;
204 ScDocument& rDoc = rDocShell.GetDocument();
206 if (bRecord && !rDoc.IsUndoEnabled())
207 bRecord = false;
208 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
209 if (pTable)
211 if (bRecord)
213 SCCOLROW nCol1, nCol2, nRow1, nRow2;
214 pTable->GetColArray().GetRange( nCol1, nCol2 );
215 pTable->GetRowArray().GetRange( nRow1, nRow2 );
216 SCCOL nStartCol = static_cast<SCCOL>(nCol1);
217 SCROW nStartRow = nRow1;
218 SCCOL nEndCol = static_cast<SCCOL>(nCol2);
219 SCROW nEndRow = nRow2;
221 ScDocumentUniquePtr pUndoDoc(new ScDocument( SCDOCMODE_UNDO ));
222 pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
223 rDoc.CopyToDocument(nStartCol, 0, nTab, nEndCol, rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
224 rDoc.CopyToDocument(0, nStartRow, nTab, rDoc.MaxCol(), nEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
226 std::unique_ptr<ScOutlineTable> pUndoTab(new ScOutlineTable( *pTable ));
228 rDocShell.GetUndoManager()->AddUndoAction(
229 std::make_unique<ScUndoRemoveAllOutlines>( &rDocShell,
230 nStartCol, nStartRow, nTab,
231 nEndCol, nEndRow, nTab,
232 std::move(pUndoDoc), std::move(pUndoTab) ) );
235 SelectLevel( nTab, true, pTable->GetColArray().GetDepth(), false, false );
236 SelectLevel( nTab, false, pTable->GetRowArray().GetDepth(), false, false );
237 rDoc.SetOutlineTable( nTab, nullptr );
239 rDoc.UpdatePageBreaks( nTab );
241 rDoc.SetStreamValid(nTab, false);
243 rDocShell.PostPaint( 0,0,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab,
244 PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top | PaintPartFlags::Size );
245 rDocShell.SetDocumentModified();
246 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
247 bSuccess = true;
250 return bSuccess;
253 void ScOutlineDocFunc::AutoOutline( const ScRange& rRange, bool bRecord )
255 SCCOL nStartCol = rRange.aStart.Col();
256 SCROW nStartRow = rRange.aStart.Row();
257 SCCOL nEndCol = rRange.aEnd.Col();
258 SCROW nEndRow = rRange.aEnd.Row();
259 SCTAB nTab = rRange.aStart.Tab();
261 ScDocument& rDoc = rDocShell.GetDocument();
263 if (bRecord && !rDoc.IsUndoEnabled())
264 bRecord = false;
265 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
267 ScDocumentUniquePtr pUndoDoc;
268 std::unique_ptr<ScOutlineTable> pUndoTab;
270 if ( pTable )
272 if ( bRecord )
274 pUndoTab.reset(new ScOutlineTable( *pTable ));
276 SCCOLROW nCol1, nCol2, nRow1, nRow2;
277 pTable->GetColArray().GetRange( nCol1, nCol2 );
278 pTable->GetRowArray().GetRange( nRow1, nRow2 );
279 SCCOL nOutStartCol = static_cast<SCCOL>(nCol1);
280 SCROW nOutStartRow = nRow1;
281 SCCOL nOutEndCol = static_cast<SCCOL>(nCol2);
282 SCROW nOutEndRow = nRow2;
284 pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
285 pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
286 rDoc.CopyToDocument(nOutStartCol, 0, nTab, nOutEndCol, rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
287 rDoc.CopyToDocument(0, nOutStartRow, nTab, rDoc.MaxCol(), nOutEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
290 // enable
291 SelectLevel( nTab, true, pTable->GetColArray().GetDepth(), false, false );
292 SelectLevel( nTab, false, pTable->GetRowArray().GetDepth(), false, false );
293 rDoc.SetOutlineTable( nTab, nullptr );
296 rDoc.DoAutoOutline( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
298 if (bRecord)
300 rDocShell.GetUndoManager()->AddUndoAction(
301 std::make_unique<ScUndoAutoOutline>( &rDocShell,
302 nStartCol, nStartRow, nTab,
303 nEndCol, nEndRow, nTab,
304 std::move(pUndoDoc), std::move(pUndoTab) ) );
307 rDoc.SetStreamValid(nTab, false);
309 rDocShell.PostPaint( 0,0,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab, PaintPartFlags::Left | PaintPartFlags::Top | PaintPartFlags::Size );
310 rDocShell.SetDocumentModified();
311 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
314 bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel,
315 bool bRecord, bool bPaint )
317 ScDocument& rDoc = rDocShell.GetDocument();
318 ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
320 if (bRecord && !rDoc.IsUndoEnabled())
321 bRecord = false;
322 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab ); // already there
323 if (!pTable)
324 return false;
325 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
327 SCCOLROW nStart, nEnd;
328 rArray.GetRange( nStart, nEnd );
330 // TODO undo can mess things up when another view is editing a cell in the range of group entry
331 // this is a temporarily workaround
332 if (!comphelper::LibreOfficeKit::isActive() && bRecord )
334 std::unique_ptr<ScOutlineTable> pUndoTab(new ScOutlineTable( *pTable ));
335 ScDocumentUniquePtr pUndoDoc(new ScDocument( SCDOCMODE_UNDO ));
336 if (bColumns)
338 pUndoDoc->InitUndo( rDoc, nTab, nTab, true );
339 rDoc.CopyToDocument(static_cast<SCCOL>(nStart), 0, nTab,
340 static_cast<SCCOL>(nEnd), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false,
341 *pUndoDoc);
343 else
345 pUndoDoc->InitUndo( rDoc, nTab, nTab, false, true );
346 rDoc.CopyToDocument(0, nStart, nTab, rDoc.MaxCol(), nEnd, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
349 rDocShell.GetUndoManager()->AddUndoAction(
350 std::make_unique<ScUndoOutlineLevel>( &rDocShell,
351 nStart, nEnd, nTab, //! calculate start and end
352 std::move(pUndoDoc), std::move(pUndoTab),
353 bColumns, nLevel ) );
356 ScSubOutlineIterator aIter( &rArray ); // all entries
357 ScOutlineEntry* pEntry;
358 while ((pEntry=aIter.GetNext()) != nullptr)
360 SCCOLROW nThisStart = pEntry->GetStart();
361 SCCOLROW nThisEnd = pEntry->GetEnd();
363 sal_uInt16 nThisLevel = aIter.LastLevel();
364 bool bShow = (nThisLevel < nLevel);
366 if (!bShow && pViewSh && ScTabViewShell::isAnyEditViewInRange(pViewSh, bColumns, nThisStart, nThisEnd))
367 continue;
369 if (bShow) // enable
371 pEntry->SetHidden( false );
372 pEntry->SetVisible( true );
374 else if ( nThisLevel == nLevel ) // disable
376 pEntry->SetHidden( true );
377 pEntry->SetVisible( true );
379 else // hidden below
381 if (comphelper::LibreOfficeKit::isActive() && nThisLevel > 0)
383 pEntry->SetHidden( true );
384 const ScOutlineEntry* pParentEntry = rArray.GetEntryByPos(nThisLevel - 1, nThisStart);
385 if (pParentEntry && pParentEntry->IsHidden())
386 pEntry->SetVisible( false );
388 else
390 pEntry->SetVisible( false );
394 for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
396 if ( bColumns )
397 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, bShow );
398 else
400 // show several rows together, don't show filtered rows
401 SCROW nFilterEnd = i;
402 bool bFiltered = rDoc.RowFiltered( i, nTab, nullptr, &nFilterEnd );
403 nFilterEnd = std::min( nThisEnd, nFilterEnd );
404 if ( !bShow || !bFiltered )
405 rDoc.ShowRows( i, nFilterEnd, nTab, bShow );
406 i = nFilterEnd;
411 rDoc.SetDrawPageSize(nTab);
412 rDoc.UpdatePageBreaks( nTab );
414 if ( pViewSh )
415 pViewSh->OnLOKShowHideColRow(bColumns, nStart - 1);
417 if (bPaint)
418 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
420 rDocShell.SetDocumentModified();
421 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
423 return true;
426 bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord )
428 bool bDone = false;
430 SCCOL nStartCol = rRange.aStart.Col();
431 SCROW nStartRow = rRange.aStart.Row();
432 SCCOL nEndCol = rRange.aEnd.Col();
433 SCROW nEndRow = rRange.aEnd.Row();
434 SCTAB nTab = rRange.aStart.Tab();
436 ScDocument& rDoc = rDocShell.GetDocument();
438 if (bRecord && !rDoc.IsUndoEnabled())
439 bRecord = false;
440 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
442 if (pTable)
444 ScOutlineEntry* pEntry;
445 SCCOLROW nStart;
446 SCCOLROW nEnd;
447 SCCOLROW nMin;
448 SCCOLROW nMax;
449 SCCOLROW i;
451 // TODO undo can mess things up when another view is editing a cell in the range of group entry
452 // this is a temporarily workaround
453 if ( !comphelper::LibreOfficeKit::isActive() && bRecord )
455 std::unique_ptr<ScOutlineTable> pUndoTab(new ScOutlineTable( *pTable ));
456 ScDocumentUniquePtr pUndoDoc(new ScDocument( SCDOCMODE_UNDO ));
457 pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
458 rDoc.CopyToDocument(nStartCol, 0, nTab, nEndCol, rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
459 rDoc.CopyToDocument(0, nStartRow, nTab, rDoc.MaxCol(), nEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
461 rDocShell.GetUndoManager()->AddUndoAction(
462 std::make_unique<ScUndoOutlineBlock>( &rDocShell,
463 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
464 std::move(pUndoDoc), std::move(pUndoTab), true ) );
467 // Columns
469 nMin=rDoc.MaxCol();
470 nMax=0;
471 ScOutlineArray& rColArray = pTable->GetColArray();
472 ScSubOutlineIterator aColIter( &rColArray );
473 while ((pEntry=aColIter.GetNext()) != nullptr)
475 nStart = pEntry->GetStart();
476 nEnd = pEntry->GetEnd();
477 if ( nStart>=nStartCol && nEnd<=nEndCol )
479 pEntry->SetHidden( false );
480 pEntry->SetVisible( true );
481 if (nStart<nMin) nMin=nStart;
482 if (nEnd>nMax) nMax=nEnd;
485 const SCCOLROW nMinStartCol = nMin;
486 for ( i=nMin; i<=nMax; i++ )
487 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, true );
489 // Rows
491 nMin=rDoc.MaxRow();
492 nMax=0;
493 ScOutlineArray& rRowArray = pTable->GetRowArray();
494 ScSubOutlineIterator aRowIter( &rRowArray );
495 while ((pEntry=aRowIter.GetNext()) != nullptr)
497 nStart = pEntry->GetStart();
498 nEnd = pEntry->GetEnd();
499 if ( nStart>=nStartRow && nEnd<=nEndRow )
501 pEntry->SetHidden( false );
502 pEntry->SetVisible( true );
503 if (nStart<nMin) nMin=nStart;
504 if (nEnd>nMax) nMax=nEnd;
507 const SCCOLROW nMinStartRow = nMin;
508 for ( i=nMin; i<=nMax; i++ )
510 // show several rows together, don't show filtered rows
511 SCROW nFilterEnd = i;
512 bool bFiltered = rDoc.RowFiltered( i, nTab, nullptr, &nFilterEnd );
513 nFilterEnd = std::min( nMax, nFilterEnd );
514 if ( !bFiltered )
515 rDoc.ShowRows( i, nFilterEnd, nTab, true );
516 i = nFilterEnd;
520 rDoc.SetDrawPageSize(nTab);
521 rDoc.UpdatePageBreaks( nTab );
523 ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
524 if ( pViewSh )
526 pViewSh->OnLOKShowHideColRow(/*columns: */ true, nMinStartCol - 1);
527 pViewSh->OnLOKShowHideColRow(/*columns: */ false, nMinStartRow - 1);
530 rDocShell.PostPaint( 0,0,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab, PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top );
531 rDocShell.SetDocumentModified();
532 bDone = true;
534 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
537 return bDone;
540 bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, bool bRecord )
542 bool bDone = false;
544 SCCOL nStartCol = rRange.aStart.Col();
545 SCROW nStartRow = rRange.aStart.Row();
546 SCCOL nEndCol = rRange.aEnd.Col();
547 SCROW nEndRow = rRange.aEnd.Row();
548 SCTAB nTab = rRange.aStart.Tab();
550 ScDocument& rDoc = rDocShell.GetDocument();
552 if (bRecord && !rDoc.IsUndoEnabled())
553 bRecord = false;
554 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
556 if (pTable)
558 const ScOutlineEntry* pEntry;
559 size_t nColLevel;
560 size_t nRowLevel;
561 sal_uInt16 nCount;
562 SCCOLROW nStart;
563 SCCOLROW nEnd;
564 sal_uInt16 i;
566 SCCOLROW nEffStartCol = nStartCol;
567 SCCOLROW nEffEndCol = nEndCol;
568 ScOutlineArray& rColArray = pTable->GetColArray();
569 rColArray.FindTouchedLevel( nStartCol, nEndCol, nColLevel );
570 rColArray.ExtendBlock( nColLevel, nEffStartCol, nEffEndCol );
571 SCCOLROW nEffStartRow = nStartRow;
572 SCCOLROW nEffEndRow = nEndRow;
573 ScOutlineArray& rRowArray = pTable->GetRowArray();
574 rRowArray.FindTouchedLevel( nStartRow, nEndRow, nRowLevel );
575 rRowArray.ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow );
577 // TODO undo can mess things up when another view is editing a cell in the range of group entry
578 // this is a temporarily workaround
579 if ( !comphelper::LibreOfficeKit::isActive() && bRecord )
581 std::unique_ptr<ScOutlineTable> pUndoTab(new ScOutlineTable( *pTable ));
582 ScDocumentUniquePtr pUndoDoc(new ScDocument( SCDOCMODE_UNDO ));
583 pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
584 rDoc.CopyToDocument(static_cast<SCCOL>(nEffStartCol), 0, nTab,
585 static_cast<SCCOL>(nEffEndCol), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE,
586 false, *pUndoDoc);
587 rDoc.CopyToDocument(0, nEffStartRow, nTab, rDoc.MaxCol(), nEffEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
589 rDocShell.GetUndoManager()->AddUndoAction(
590 std::make_unique<ScUndoOutlineBlock>( &rDocShell,
591 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
592 std::move(pUndoDoc), std::move(pUndoTab), false ) );
595 // Columns
597 nCount = rColArray.GetCount(nColLevel);
598 for ( i=0; i<nCount; i++ )
600 pEntry = rColArray.GetEntry(nColLevel,i);
601 nStart = pEntry->GetStart();
602 nEnd = pEntry->GetEnd();
604 if ( static_cast<SCCOLROW>(nStartCol)<=nEnd && static_cast<SCCOLROW>(nEndCol)>=nStart )
605 HideOutline( nTab, true, nColLevel, i, false, false );
608 // Rows
610 nCount = rRowArray.GetCount(nRowLevel);
611 for ( i=0; i<nCount; i++ )
613 pEntry = rRowArray.GetEntry(nRowLevel,i);
614 nStart = pEntry->GetStart();
615 nEnd = pEntry->GetEnd();
617 if ( nStartRow<=nEnd && nEndRow>=nStart )
618 HideOutline( nTab, false, nRowLevel, i, false, false );
621 rDoc.SetDrawPageSize(nTab);
622 rDoc.UpdatePageBreaks( nTab );
624 rDocShell.PostPaint( 0,0,nTab, rDoc.MaxCol(),rDoc.MaxRow(),nTab, PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top );
626 rDocShell.SetDocumentModified();
627 bDone = true;
629 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
632 return bDone;
635 void ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
636 bool bRecord, bool bPaint )
638 ScDocument& rDoc = rDocShell.GetDocument();
639 if (bRecord && !rDoc.IsUndoEnabled())
640 bRecord = false;
642 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
643 if (!pTable)
644 return;
646 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
647 ScOutlineEntry* pEntry = rArray.GetEntry( nLevel, nEntry );
648 SCCOLROW nStart = pEntry->GetStart();
649 SCCOLROW nEnd = pEntry->GetEnd();
651 // TODO undo can mess things up when another view is editing a cell in the range of group entry
652 // this is a temporarily workaround
653 if ( !comphelper::LibreOfficeKit::isActive() && bRecord )
655 ScDocumentUniquePtr pUndoDoc(new ScDocument( SCDOCMODE_UNDO ));
656 if (bColumns)
658 pUndoDoc->InitUndo( rDoc, nTab, nTab, true );
659 rDoc.CopyToDocument(static_cast<SCCOL>(nStart), 0, nTab,
660 static_cast<SCCOL>(nEnd), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false,
661 *pUndoDoc);
663 else
665 pUndoDoc->InitUndo( rDoc, nTab, nTab, false, true );
666 rDoc.CopyToDocument(0, nStart, nTab, rDoc.MaxCol(), nEnd, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
669 rDocShell.GetUndoManager()->AddUndoAction(
670 std::make_unique<ScUndoDoOutline>( &rDocShell,
671 nStart, nEnd, nTab, std::move(pUndoDoc), //! calc start and end
672 bColumns, nLevel, nEntry, true ) );
675 pEntry->SetHidden(false);
676 SCCOLROW i;
677 for ( i = nStart; i <= nEnd; i++ )
679 if ( bColumns )
680 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, true );
681 else
683 // show several rows together, don't show filtered rows
684 SCROW nFilterEnd = i;
685 bool bFiltered = rDoc.RowFiltered( i, nTab, nullptr, &nFilterEnd );
686 nFilterEnd = std::min( nEnd, nFilterEnd );
687 if ( !bFiltered )
688 rDoc.ShowRows( i, nFilterEnd, nTab, true );
689 i = nFilterEnd;
693 ScSubOutlineIterator aIter( &rArray, nLevel, nEntry );
694 while ((pEntry=aIter.GetNext()) != nullptr)
696 if ( pEntry->IsHidden() )
698 SCCOLROW nSubStart = pEntry->GetStart();
699 SCCOLROW nSubEnd = pEntry->GetEnd();
700 if ( bColumns )
701 for ( i = nSubStart; i <= nSubEnd; i++ )
702 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, false );
703 else
704 rDoc.ShowRows( nSubStart, nSubEnd, nTab, false );
708 rArray.SetVisibleBelow( nLevel, nEntry, true, true );
710 rDoc.SetDrawPageSize(nTab);
711 rDoc.InvalidatePageBreaks(nTab);
712 rDoc.UpdatePageBreaks( nTab );
714 ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
715 if ( pViewSh )
716 pViewSh->OnLOKShowHideColRow(bColumns, nStart - 1);
718 if (bPaint)
719 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
721 rDocShell.SetDocumentModified();
723 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
726 bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
727 bool bRecord, bool bPaint )
729 ScDocument& rDoc = rDocShell.GetDocument();
730 if (bRecord && !rDoc.IsUndoEnabled())
731 bRecord = false;
733 ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
734 if (!pTable)
735 return false;
736 ScOutlineArray& rArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
737 ScOutlineEntry* pEntry = rArray.GetEntry( nLevel, nEntry );
738 SCCOLROW nStart = pEntry->GetStart();
739 SCCOLROW nEnd = pEntry->GetEnd();
741 ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
742 if (pViewSh && ScTabViewShell::isAnyEditViewInRange(pViewSh, bColumns, nStart, nEnd))
743 return false;
745 // TODO undo can mess things up when another view is editing a cell in the range of group entry
746 // this is a temporarily workaround
747 if ( !comphelper::LibreOfficeKit::isActive() && bRecord )
749 ScDocumentUniquePtr pUndoDoc(new ScDocument( SCDOCMODE_UNDO ));
750 if (bColumns)
752 pUndoDoc->InitUndo( rDoc, nTab, nTab, true );
753 rDoc.CopyToDocument(static_cast<SCCOL>(nStart), 0, nTab,
754 static_cast<SCCOL>(nEnd), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false,
755 *pUndoDoc);
757 else
759 pUndoDoc->InitUndo( rDoc, nTab, nTab, false, true );
760 rDoc.CopyToDocument(0, nStart, nTab, rDoc.MaxCol(), nEnd, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc);
763 rDocShell.GetUndoManager()->AddUndoAction(
764 std::make_unique<ScUndoDoOutline>( &rDocShell,
765 nStart, nEnd, nTab, std::move(pUndoDoc),
766 bColumns, nLevel, nEntry, false ) );
769 pEntry->SetHidden(true);
770 SCCOLROW i;
771 if ( bColumns )
772 for ( i = nStart; i <= nEnd; i++ )
773 rDoc.ShowCol( static_cast<SCCOL>(i), nTab, false );
774 else
775 rDoc.ShowRows( nStart, nEnd, nTab, false );
777 rArray.SetVisibleBelow( nLevel, nEntry, false );
779 rDoc.SetDrawPageSize(nTab);
780 rDoc.InvalidatePageBreaks(nTab);
781 rDoc.UpdatePageBreaks( nTab );
783 if ( pViewSh )
784 pViewSh->OnLOKShowHideColRow(bColumns, nStart - 1);
786 if (bPaint)
787 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
789 rDocShell.SetDocumentModified();
791 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
794 return true; //! always ???
797 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */