1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <olinetab.hxx>
26 #include <tabvwsh.hxx>
27 #include <undodat.hxx>
28 #include <globstr.hrc>
31 #include <comphelper/lok.hxx>
34 static void lcl_InvalidateOutliner( SfxBindings
* 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
;
57 SCCOL nEndCol
= rDoc
.MaxCol(); // for testing if merged
58 SCROW nEndRow
= rDoc
.MaxRow();
61 nParts
|= PaintPartFlags::Top
;
62 nStartCol
= static_cast<SCCOL
>(nStart
);
63 nEndCol
= static_cast<SCCOL
>(nEnd
);
67 nParts
|= PaintPartFlags::Left
;
71 if (rDoc
.HasAttrib( nStartCol
,nStartRow
,nTab
, nEndCol
,nEndRow
,nTab
,
72 HasAttrFlags::Merged
| HasAttrFlags::Overlapped
))
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())
96 pUndoTab
.reset(new ScOutlineTable( *pTable
));
98 ScOutlineArray
& rArray
= bColumns
? pTable
->GetColArray() : pTable
->GetRowArray();
103 bRes
= rArray
.Insert( nStartCol
, nEndCol
, bSize
);
105 bRes
= rArray
.Insert( nStartRow
, nEndRow
, bSize
);
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
121 nParts
|= PaintPartFlags::Top
;
123 nParts
|= PaintPartFlags::Left
;
125 nParts
|= PaintPartFlags::Size
;
127 rDocShell
.PostPaint( 0,0,nTab
, rDoc
.MaxCol(),rDoc
.MaxRow(),nTab
, nParts
);
128 rDocShell
.SetDocumentModified();
129 lcl_InvalidateOutliner( rDocShell
.GetViewBindings() );
134 rDocShell
.ErrorMessage(STR_MSSG_MAKEOUTLINE_0
); // "Grouping not possible"
138 void ScOutlineDocFunc::RemoveOutline( const ScRange
& rRange
, bool bColumns
, bool bRecord
, bool bApi
)
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())
152 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
155 std::unique_ptr
<ScOutlineTable
> pUndoTab
;
157 pUndoTab
.reset(new ScOutlineTable( *pTable
));
159 ScOutlineArray
& rArray
= bColumns
? pTable
->GetColArray() : pTable
->GetRowArray();
164 bRes
= rArray
.Remove( nStartCol
, nEndCol
, bSize
);
166 bRes
= rArray
.Remove( nStartRow
, nEndRow
, bSize
);
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
182 nParts
|= PaintPartFlags::Top
;
184 nParts
|= PaintPartFlags::Left
;
186 nParts
|= PaintPartFlags::Size
;
188 rDocShell
.PostPaint( 0,0,nTab
, rDoc
.MaxCol(),rDoc
.MaxRow(),nTab
, nParts
);
189 rDocShell
.SetDocumentModified();
191 lcl_InvalidateOutliner( rDocShell
.GetViewBindings() );
193 // we are not enabling again -> no UpdatePageBreaks
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())
208 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
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() );
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())
265 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
267 ScDocumentUniquePtr pUndoDoc
;
268 std::unique_ptr
<ScOutlineTable
> pUndoTab
;
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
);
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
);
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())
322 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
); // already there
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
));
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,
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
))
371 pEntry
->SetHidden( false );
372 pEntry
->SetVisible( true );
374 else if ( nThisLevel
== nLevel
) // disable
376 pEntry
->SetHidden( true );
377 pEntry
->SetVisible( true );
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 );
390 pEntry
->SetVisible( false );
394 for (SCCOLROW i
=nThisStart
; i
<=nThisEnd
; i
++)
397 rDoc
.ShowCol( static_cast<SCCOL
>(i
), nTab
, bShow
);
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
);
411 rDoc
.SetDrawPageSize(nTab
);
412 rDoc
.UpdatePageBreaks( nTab
);
415 pViewSh
->OnLOKShowHideColRow(bColumns
, nStart
- 1);
418 lcl_PaintWidthHeight( rDocShell
, nTab
, bColumns
, nStart
, nEnd
);
420 rDocShell
.SetDocumentModified();
421 lcl_InvalidateOutliner( rDocShell
.GetViewBindings() );
426 bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange
& rRange
, bool bRecord
)
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())
440 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
444 ScOutlineEntry
* pEntry
;
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 ) );
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 );
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
);
515 rDoc
.ShowRows( i
, nFilterEnd
, nTab
, true );
520 rDoc
.SetDrawPageSize(nTab
);
521 rDoc
.UpdatePageBreaks( nTab
);
523 ScTabViewShell
* pViewSh
= rDocShell
.GetBestViewShell();
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();
534 lcl_InvalidateOutliner( rDocShell
.GetViewBindings() );
540 bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange
& rRange
, bool bRecord
)
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())
554 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
558 const ScOutlineEntry
* pEntry
;
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
,
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 ) );
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 );
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();
629 lcl_InvalidateOutliner( rDocShell
.GetViewBindings() );
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())
642 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
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
));
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,
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);
677 for ( i
= nStart
; i
<= nEnd
; i
++ )
680 rDoc
.ShowCol( static_cast<SCCOL
>(i
), nTab
, true );
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
);
688 rDoc
.ShowRows( i
, nFilterEnd
, nTab
, true );
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();
701 for ( i
= nSubStart
; i
<= nSubEnd
; i
++ )
702 rDoc
.ShowCol( static_cast<SCCOL
>(i
), nTab
, false );
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();
716 pViewSh
->OnLOKShowHideColRow(bColumns
, nStart
- 1);
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())
733 ScOutlineTable
* pTable
= rDoc
.GetOutlineTable( nTab
);
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
))
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
));
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,
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);
772 for ( i
= nStart
; i
<= nEnd
; i
++ )
773 rDoc
.ShowCol( static_cast<SCCOL
>(i
), nTab
, false );
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
);
784 pViewSh
->OnLOKShowHideColRow(bColumns
, nStart
- 1);
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: */