bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / docshell / olinefun.cxx
blobdae37214f2c05ccc863ffb1982d4e8f23147b481
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 "undodat.hxx"
27 #include "globstr.hrc"
28 #include "sc.hrc"
31 //========================================================================
33 static void lcl_InvalidateOutliner( SfxBindings* pBindings )
35 if ( pBindings )
37 pBindings->Invalidate( SID_OUTLINE_SHOW );
38 pBindings->Invalidate( SID_OUTLINE_HIDE );
39 pBindings->Invalidate( SID_OUTLINE_REMOVE );
41 pBindings->Invalidate( SID_STATUS_SUM ); // wegen ein-/ausblenden
42 pBindings->Invalidate( SID_ATTR_SIZE );
46 //------------------------------------------------------------------------
48 //! PaintWidthHeight zur DocShell verschieben?
50 static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab,
51 sal_Bool bColumns, SCCOLROW nStart, SCCOLROW nEnd )
53 ScDocument* pDoc = rDocShell.GetDocument();
55 sal_uInt16 nParts = PAINT_GRID;
56 SCCOL nStartCol = 0;
57 SCROW nStartRow = 0;
58 SCCOL nEndCol = MAXCOL; // fuer Test auf Merge
59 SCROW nEndRow = MAXROW;
60 if ( bColumns )
62 nParts |= PAINT_TOP;
63 nStartCol = static_cast<SCCOL>(nStart);
64 nEndCol = static_cast<SCCOL>(nEnd);
66 else
68 nParts |= PAINT_LEFT;
69 nStartRow = nStart;
70 nEndRow = nEnd;
72 if (pDoc->HasAttrib( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
73 HASATTR_MERGED | HASATTR_OVERLAPPED ))
75 nStartCol = 0;
76 nStartRow = 0;
78 rDocShell.PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts );
81 //------------------------------------------------------------------------
83 sal_Bool ScOutlineDocFunc::MakeOutline( const ScRange& rRange, sal_Bool bColumns, sal_Bool bRecord, sal_Bool bApi )
85 sal_Bool bSuccess = false;
86 SCCOL nStartCol = rRange.aStart.Col();
87 SCROW nStartRow = rRange.aStart.Row();
88 SCCOL nEndCol = rRange.aEnd.Col();
89 SCROW nEndRow = rRange.aEnd.Row();
90 SCTAB nTab = rRange.aStart.Tab();
92 ScDocument* pDoc = rDocShell.GetDocument();
93 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab, sal_True );
94 ScOutlineTable* pUndoTab = NULL;
96 if (bRecord && !pDoc->IsUndoEnabled())
97 bRecord = false;
99 if (bRecord)
100 pUndoTab = new ScOutlineTable( *pTable );
102 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
104 bool bRes;
105 bool bSize = false;
106 if ( bColumns )
107 bRes = pArray->Insert( nStartCol, nEndCol, bSize );
108 else
109 bRes = pArray->Insert( nStartRow, nEndRow, bSize );
111 if ( bRes )
113 if (bRecord)
115 rDocShell.GetUndoManager()->AddUndoAction(
116 new ScUndoMakeOutline( &rDocShell,
117 nStartCol,nStartRow,nTab,nEndCol,nEndRow,nTab,
118 pUndoTab, bColumns, sal_True ) );
121 if (pDoc->IsStreamValid(nTab))
122 pDoc->SetStreamValid(nTab, false);
124 sal_uInt16 nParts = 0; // Datenbereich nicht geaendert
125 if ( bColumns )
126 nParts |= PAINT_TOP;
127 else
128 nParts |= PAINT_LEFT;
129 if ( bSize )
130 nParts |= PAINT_SIZE;
132 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
133 rDocShell.SetDocumentModified();
134 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
135 bSuccess = sal_True;
137 else
139 if (!bApi)
140 rDocShell.ErrorMessage(STR_MSSG_MAKEOUTLINE_0); // "Gruppierung nicht moeglich"
141 delete pUndoTab;
144 return bSuccess;
147 sal_Bool ScOutlineDocFunc::RemoveOutline( const ScRange& rRange, sal_Bool bColumns, sal_Bool bRecord, sal_Bool bApi )
149 sal_Bool bDone = false;
151 SCCOL nStartCol = rRange.aStart.Col();
152 SCROW nStartRow = rRange.aStart.Row();
153 SCCOL nEndCol = rRange.aEnd.Col();
154 SCROW nEndRow = rRange.aEnd.Row();
155 SCTAB nTab = rRange.aStart.Tab();
157 ScDocument* pDoc = rDocShell.GetDocument();
159 if (bRecord && !pDoc->IsUndoEnabled())
160 bRecord = false;
161 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
162 if (pTable)
164 ScOutlineTable* pUndoTab = NULL;
165 if (bRecord)
166 pUndoTab = new ScOutlineTable( *pTable );
168 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
170 bool bRes;
171 bool bSize = false;
172 if ( bColumns )
173 bRes = pArray->Remove( nStartCol, nEndCol, bSize );
174 else
175 bRes = pArray->Remove( nStartRow, nEndRow, bSize );
177 if ( bRes )
179 if (bRecord)
181 rDocShell.GetUndoManager()->AddUndoAction(
182 new ScUndoMakeOutline( &rDocShell,
183 nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
184 pUndoTab, bColumns, false ) );
187 if (pDoc->IsStreamValid(nTab))
188 pDoc->SetStreamValid(nTab, false);
190 sal_uInt16 nParts = 0; // Datenbereich nicht geaendert
191 if ( bColumns )
192 nParts |= PAINT_TOP;
193 else
194 nParts |= PAINT_LEFT;
195 if ( bSize )
196 nParts |= PAINT_SIZE;
198 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, nParts );
199 rDocShell.SetDocumentModified();
200 bDone = sal_True;
201 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
203 // es wird nicht wieder eingeblendet -> kein UpdatePageBreaks
205 else
206 delete pUndoTab;
209 if (!bDone && !bApi)
210 rDocShell.ErrorMessage(STR_MSSG_REMOVEOUTLINE_0); // "Aufheben nicht moeglich"
212 return bDone;
215 sal_Bool ScOutlineDocFunc::RemoveAllOutlines( SCTAB nTab, sal_Bool bRecord, sal_Bool bApi )
217 sal_Bool bSuccess = false;
218 ScDocument* pDoc = rDocShell.GetDocument();
220 if (bRecord && !pDoc->IsUndoEnabled())
221 bRecord = false;
222 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
223 if (pTable)
225 if (bRecord)
227 SCCOLROW nCol1, nCol2, nRow1, nRow2;
228 pTable->GetColArray()->GetRange( nCol1, nCol2 );
229 pTable->GetRowArray()->GetRange( nRow1, nRow2 );
230 SCCOL nStartCol = static_cast<SCCOL>(nCol1);
231 SCROW nStartRow = nRow1;
232 SCCOL nEndCol = static_cast<SCCOL>(nCol2);
233 SCROW nEndRow = nRow2;
235 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
236 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
237 pDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, pUndoDoc );
238 pDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pUndoDoc );
240 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
242 rDocShell.GetUndoManager()->AddUndoAction(
243 new ScUndoRemoveAllOutlines( &rDocShell,
244 nStartCol, nStartRow, nTab,
245 nEndCol, nEndRow, nTab,
246 pUndoDoc, pUndoTab ) );
249 SelectLevel( nTab, sal_True, pTable->GetColArray()->GetDepth(), false, false, bApi );
250 SelectLevel( nTab, false, pTable->GetRowArray()->GetDepth(), false, false, bApi );
251 pDoc->SetOutlineTable( nTab, NULL );
253 pDoc->UpdatePageBreaks( nTab );
255 if (pDoc->IsStreamValid(nTab))
256 pDoc->SetStreamValid(nTab, false);
258 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab,
259 PAINT_GRID | PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
260 rDocShell.SetDocumentModified();
261 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
262 bSuccess = sal_True;
265 return bSuccess;
268 //------------------------------------------------------------------------
270 sal_Bool ScOutlineDocFunc::AutoOutline( const ScRange& rRange, sal_Bool bRecord, sal_Bool bApi )
272 SCCOL nStartCol = rRange.aStart.Col();
273 SCROW nStartRow = rRange.aStart.Row();
274 SCCOL nEndCol = rRange.aEnd.Col();
275 SCROW nEndRow = rRange.aEnd.Row();
276 SCTAB nTab = rRange.aStart.Tab();
278 ScDocument* pDoc = rDocShell.GetDocument();
280 if (bRecord && !pDoc->IsUndoEnabled())
281 bRecord = false;
282 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
284 ScDocument* pUndoDoc = NULL;
285 ScOutlineTable* pUndoTab = NULL;
287 if ( pTable )
289 if ( bRecord )
291 pUndoTab = new ScOutlineTable( *pTable );
293 SCCOLROW nCol1, nCol2, nRow1, nRow2;
294 pTable->GetColArray()->GetRange( nCol1, nCol2 );
295 pTable->GetRowArray()->GetRange( nRow1, nRow2 );
296 SCCOL nOutStartCol = static_cast<SCCOL>(nCol1);
297 SCROW nOutStartRow = nRow1;
298 SCCOL nOutEndCol = static_cast<SCCOL>(nCol2);
299 SCROW nOutEndRow = nRow2;
301 pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
302 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
303 pDoc->CopyToDocument( nOutStartCol, 0, nTab, nOutEndCol, MAXROW, nTab, IDF_NONE, false, pUndoDoc );
304 pDoc->CopyToDocument( 0, nOutStartRow, nTab, MAXCOL, nOutEndRow, nTab, IDF_NONE, false, pUndoDoc );
307 // einblenden
308 SelectLevel( nTab, sal_True, pTable->GetColArray()->GetDepth(), false, false, bApi );
309 SelectLevel( nTab, false, pTable->GetRowArray()->GetDepth(), false, false, bApi );
310 pDoc->SetOutlineTable( nTab, NULL );
313 pDoc->DoAutoOutline( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
315 if (bRecord)
317 rDocShell.GetUndoManager()->AddUndoAction(
318 new ScUndoAutoOutline( &rDocShell,
319 nStartCol, nStartRow, nTab,
320 nEndCol, nEndRow, nTab,
321 pUndoDoc, pUndoTab ) );
324 if (pDoc->IsStreamValid(nTab))
325 pDoc->SetStreamValid(nTab, false);
327 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_LEFT | PAINT_TOP | PAINT_SIZE );
328 rDocShell.SetDocumentModified();
329 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
331 return sal_True;
334 //------------------------------------------------------------------------
336 sal_Bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, sal_Bool bColumns, sal_uInt16 nLevel,
337 sal_Bool bRecord, sal_Bool bPaint, sal_Bool /* bApi */ )
339 ScDocument* pDoc = rDocShell.GetDocument();
341 if (bRecord && !pDoc->IsUndoEnabled())
342 bRecord = false;
343 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab ); // ist schon da
344 if (!pTable)
345 return false;
346 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
347 if (!pArray)
348 return false;
350 SCCOLROW nStart, nEnd;
351 pArray->GetRange( nStart, nEnd );
353 if ( bRecord )
355 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
356 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
357 if (bColumns)
359 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, false );
360 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
361 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false,
362 pUndoDoc );
364 else
366 pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
367 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pUndoDoc );
370 rDocShell.GetUndoManager()->AddUndoAction(
371 new ScUndoOutlineLevel( &rDocShell,
372 nStart, nEnd, nTab, //! start und end berechnen
373 pUndoDoc, pUndoTab,
374 bColumns, nLevel ) );
377 pDoc->InitializeNoteCaptions(nTab);
378 ScSubOutlineIterator aIter( pArray ); // alle Eintraege
379 ScOutlineEntry* pEntry;
380 while ((pEntry=aIter.GetNext()) != NULL)
382 sal_uInt16 nThisLevel = aIter.LastLevel();
383 sal_Bool bShow = (nThisLevel < nLevel);
384 if (bShow) // einblenden
386 pEntry->SetHidden( false );
387 pEntry->SetVisible( sal_True );
389 else if ( nThisLevel == nLevel ) // ausblenden
391 pEntry->SetHidden( sal_True );
392 pEntry->SetVisible( sal_True );
394 else // verdeckt
396 pEntry->SetVisible( false );
399 SCCOLROW nThisStart = pEntry->GetStart();
400 SCCOLROW nThisEnd = pEntry->GetEnd();
401 for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
403 if ( bColumns )
404 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, bShow );
405 else
407 // show several rows together, don't show filtered rows
408 SCROW nFilterEnd = i;
409 bool bFiltered = pDoc->RowFiltered( i, nTab, NULL, &nFilterEnd );
410 nFilterEnd = std::min( nThisEnd, nFilterEnd );
411 if ( !bShow || !bFiltered )
412 pDoc->ShowRows( i, nFilterEnd, nTab, bShow );
413 i = nFilterEnd;
418 pDoc->SetDrawPageSize(nTab);
419 pDoc->UpdatePageBreaks( nTab );
421 if (bPaint)
422 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
424 rDocShell.SetDocumentModified();
425 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
427 return sal_True;
430 //------------------------------------------------------------------------
432 sal_Bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, sal_Bool bRecord )
434 sal_Bool bDone = false;
436 SCCOL nStartCol = rRange.aStart.Col();
437 SCROW nStartRow = rRange.aStart.Row();
438 SCCOL nEndCol = rRange.aEnd.Col();
439 SCROW nEndRow = rRange.aEnd.Row();
440 SCTAB nTab = rRange.aStart.Tab();
442 ScDocument* pDoc = rDocShell.GetDocument();
444 if (bRecord && !pDoc->IsUndoEnabled())
445 bRecord = false;
446 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
448 if (pTable)
450 ScOutlineArray* pArray;
451 ScOutlineEntry* pEntry;
452 SCCOLROW nStart;
453 SCCOLROW nEnd;
454 SCCOLROW nMin;
455 SCCOLROW nMax;
456 SCCOLROW i;
458 if ( bRecord )
460 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
461 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
462 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
463 pDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, pUndoDoc );
464 pDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pUndoDoc );
466 rDocShell.GetUndoManager()->AddUndoAction(
467 new ScUndoOutlineBlock( &rDocShell,
468 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
469 pUndoDoc, pUndoTab, sal_True ) );
472 pDoc->InitializeNoteCaptions(nTab);
474 // Spalten
476 nMin=MAXCOL;
477 nMax=0;
478 pArray = pTable->GetColArray();
479 ScSubOutlineIterator aColIter( pArray );
480 while ((pEntry=aColIter.GetNext()) != NULL)
482 nStart = pEntry->GetStart();
483 nEnd = pEntry->GetEnd();
484 if ( nStart>=nStartCol && nEnd<=nEndCol )
486 pEntry->SetHidden( false );
487 pEntry->SetVisible( sal_True );
488 if (nStart<nMin) nMin=nStart;
489 if (nEnd>nMax) nMax=nEnd;
492 for ( i=nMin; i<=nMax; i++ )
493 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, sal_True );
495 // Zeilen
497 nMin=MAXROW;
498 nMax=0;
499 pArray = pTable->GetRowArray();
500 ScSubOutlineIterator aRowIter( pArray );
501 pDoc->InitializeNoteCaptions(nTab);
502 while ((pEntry=aRowIter.GetNext()) != NULL)
504 nStart = pEntry->GetStart();
505 nEnd = pEntry->GetEnd();
506 if ( nStart>=nStartRow && nEnd<=nEndRow )
508 pEntry->SetHidden( false );
509 pEntry->SetVisible( sal_True );
510 if (nStart<nMin) nMin=nStart;
511 if (nEnd>nMax) nMax=nEnd;
514 for ( i=nMin; i<=nMax; i++ )
516 // show several rows together, don't show filtered rows
517 SCROW nFilterEnd = i;
518 bool bFiltered = pDoc->RowFiltered( i, nTab, NULL, &nFilterEnd );
519 nFilterEnd = std::min( nMax, nFilterEnd );
520 if ( !bFiltered )
521 pDoc->ShowRows( i, nFilterEnd, nTab, sal_True );
522 i = nFilterEnd;
525 pDoc->SetDrawPageSize(nTab);
526 pDoc->UpdatePageBreaks( nTab );
528 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
529 rDocShell.SetDocumentModified();
530 bDone = sal_True;
532 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
535 return bDone;
538 sal_Bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, sal_Bool bRecord, sal_Bool bApi )
540 sal_Bool bDone = false;
542 SCCOL nStartCol = rRange.aStart.Col();
543 SCROW nStartRow = rRange.aStart.Row();
544 SCCOL nEndCol = rRange.aEnd.Col();
545 SCROW nEndRow = rRange.aEnd.Row();
546 SCTAB nTab = rRange.aStart.Tab();
548 ScDocument* pDoc = rDocShell.GetDocument();
550 if (bRecord && !pDoc->IsUndoEnabled())
551 bRecord = false;
552 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
554 if (pTable)
556 const ScOutlineEntry* pEntry;
557 size_t nColLevel;
558 size_t nRowLevel;
559 sal_uInt16 nCount;
560 SCCOLROW nStart;
561 SCCOLROW nEnd;
562 sal_uInt16 i;
564 SCCOLROW nEffStartCol = nStartCol;
565 SCCOLROW nEffEndCol = nEndCol;
566 ScOutlineArray* pColArray = pTable->GetColArray();
567 pColArray->FindTouchedLevel( nStartCol, nEndCol, nColLevel );
568 pColArray->ExtendBlock( nColLevel, nEffStartCol, nEffEndCol );
569 SCCOLROW nEffStartRow = nStartRow;
570 SCCOLROW nEffEndRow = nEndRow;
571 ScOutlineArray* pRowArray = pTable->GetRowArray();
572 pRowArray->FindTouchedLevel( nStartRow, nEndRow, nRowLevel );
573 pRowArray->ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow );
575 if ( bRecord )
577 ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
578 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
579 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
580 pDoc->CopyToDocument( static_cast<SCCOL>(nEffStartCol), 0, nTab,
581 static_cast<SCCOL>(nEffEndCol), MAXROW, nTab, IDF_NONE,
582 false, pUndoDoc );
583 pDoc->CopyToDocument( 0, nEffStartRow, nTab, MAXCOL, nEffEndRow, nTab, IDF_NONE, false, pUndoDoc );
585 rDocShell.GetUndoManager()->AddUndoAction(
586 new ScUndoOutlineBlock( &rDocShell,
587 nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
588 pUndoDoc, pUndoTab, false ) );
591 pDoc->InitializeNoteCaptions(nTab);
593 // Spalten
595 nCount = pColArray->GetCount(nColLevel);
596 for ( i=0; i<nCount; i++ )
598 pEntry = pColArray->GetEntry(nColLevel,i);
599 nStart = pEntry->GetStart();
600 nEnd = pEntry->GetEnd();
602 if ( static_cast<SCCOLROW>(nStartCol)<=nEnd && static_cast<SCCOLROW>(nEndCol)>=nStart )
603 HideOutline( nTab, sal_True, nColLevel, i, false, false, bApi );
606 // Zeilen
608 nCount = pRowArray->GetCount(nRowLevel);
609 for ( i=0; i<nCount; i++ )
611 pEntry = pRowArray->GetEntry(nRowLevel,i);
612 nStart = pEntry->GetStart();
613 nEnd = pEntry->GetEnd();
615 if ( nStartRow<=nEnd && nEndRow>=nStart )
616 HideOutline( nTab, false, nRowLevel, i, false, false, bApi );
619 pDoc->SetDrawPageSize(nTab);
620 pDoc->UpdatePageBreaks( nTab );
622 rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_LEFT | PAINT_TOP );
624 rDocShell.SetDocumentModified();
625 bDone = sal_True;
627 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
630 return bDone;
633 //------------------------------------------------------------------------
635 sal_Bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, sal_Bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
636 sal_Bool bRecord, sal_Bool bPaint, sal_Bool /* bApi */ )
638 ScDocument* pDoc = rDocShell.GetDocument();
639 if (bRecord && !pDoc->IsUndoEnabled())
640 bRecord = false;
642 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
643 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
644 ScOutlineEntry* pEntry = pArray->GetEntry( nLevel, nEntry );
645 SCCOLROW nStart = pEntry->GetStart();
646 SCCOLROW nEnd = pEntry->GetEnd();
648 if ( bRecord )
650 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
651 if (bColumns)
653 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, false );
654 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
655 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false,
656 pUndoDoc );
658 else
660 pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
661 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pUndoDoc );
664 rDocShell.GetUndoManager()->AddUndoAction(
665 new ScUndoDoOutline( &rDocShell,
666 nStart, nEnd, nTab, pUndoDoc, //! start und end berechnen
667 bColumns, nLevel, nEntry, sal_True ) );
670 pDoc->InitializeNoteCaptions(nTab);
671 pEntry->SetHidden(false);
672 SCCOLROW i;
673 for ( i = nStart; i <= nEnd; i++ )
675 if ( bColumns )
676 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, sal_True );
677 else
679 // show several rows together, don't show filtered rows
680 SCROW nFilterEnd = i;
681 bool bFiltered = pDoc->RowFiltered( i, nTab, NULL, &nFilterEnd );
682 nFilterEnd = std::min( nEnd, nFilterEnd );
683 if ( !bFiltered )
684 pDoc->ShowRows( i, nFilterEnd, nTab, sal_True );
685 i = nFilterEnd;
689 ScSubOutlineIterator aIter( pArray, nLevel, nEntry );
690 while ((pEntry=aIter.GetNext()) != NULL)
692 if ( pEntry->IsHidden() )
694 SCCOLROW nSubStart = pEntry->GetStart();
695 SCCOLROW nSubEnd = pEntry->GetEnd();
696 if ( bColumns )
697 for ( i = nSubStart; i <= nSubEnd; i++ )
698 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, false );
699 else
700 pDoc->ShowRows( nSubStart, nSubEnd, nTab, sal_False );
704 pArray->SetVisibleBelow( nLevel, nEntry, sal_True, sal_True );
706 pDoc->SetDrawPageSize(nTab);
707 pDoc->InvalidatePageBreaks(nTab);
708 pDoc->UpdatePageBreaks( nTab );
710 if (bPaint)
711 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
713 rDocShell.SetDocumentModified();
715 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
717 return sal_True; //! immer ???
720 sal_Bool ScOutlineDocFunc::HideOutline( SCTAB nTab, sal_Bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry,
721 sal_Bool bRecord, sal_Bool bPaint, sal_Bool /* bApi */ )
723 ScDocument* pDoc = rDocShell.GetDocument();
724 if (bRecord && !pDoc->IsUndoEnabled())
725 bRecord = false;
727 ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
728 ScOutlineArray* pArray = bColumns ? pTable->GetColArray() : pTable->GetRowArray();
729 ScOutlineEntry* pEntry = pArray->GetEntry( nLevel, nEntry );
730 SCCOLROW nStart = pEntry->GetStart();
731 SCCOLROW nEnd = pEntry->GetEnd();
733 if ( bRecord )
735 ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
736 if (bColumns)
738 pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, false );
739 pDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
740 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false,
741 pUndoDoc );
743 else
745 pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
746 pDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pUndoDoc );
749 rDocShell.GetUndoManager()->AddUndoAction(
750 new ScUndoDoOutline( &rDocShell,
751 nStart, nEnd, nTab, pUndoDoc,
752 bColumns, nLevel, nEntry, false ) );
755 pDoc->InitializeNoteCaptions(nTab);
756 pEntry->SetHidden(true);
757 SCCOLROW i;
758 if ( bColumns )
759 for ( i = nStart; i <= nEnd; i++ )
760 pDoc->ShowCol( static_cast<SCCOL>(i), nTab, sal_False );
761 else
762 pDoc->ShowRows( nStart, nEnd, nTab, sal_False );
764 pArray->SetVisibleBelow( nLevel, nEntry, false );
766 pDoc->SetDrawPageSize(nTab);
767 pDoc->InvalidatePageBreaks(nTab);
768 pDoc->UpdatePageBreaks( nTab );
770 if (bPaint)
771 lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
773 rDocShell.SetDocumentModified();
775 lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
777 return sal_True; //! immer ???
784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */