Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / undo / undoutil.cxx
blob4071e8574d937d2e9f9f114e7e380cffa485c000
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 "undoutil.hxx"
22 #include "docsh.hxx"
23 #include "tabvwsh.hxx"
24 #include "document.hxx"
25 #include "dbdata.hxx"
26 #include "globstr.hrc"
27 #include "globalnames.hxx"
28 #include "global.hxx"
29 #include "markdata.hxx"
31 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
32 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
33 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
35 if ( pDocShell->IsPaintLocked() )
36 return;
38 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
39 if (pViewShell)
41 SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
42 if ( nViewTab < nStartZ || nViewTab > nEndZ )
43 pViewShell->SetTabNo( nStartZ );
45 pViewShell->DoneBlockMode();
46 pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, false, false );
47 pViewShell->InitOwnBlockMode();
48 pViewShell->GetViewData()->GetMarkData().
49 SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
50 pViewShell->MarkDataChanged();
55 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
56 const ScAddress& rBlockStart,
57 const ScAddress& rBlockEnd )
59 MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
60 rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
64 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
65 const ScRange& rRange )
67 MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
68 rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab() );
73 ScDBData* ScUndoUtil::GetOldDBData( ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
74 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
76 ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
78 if (!pRet)
80 bool bWasTemp = false;
81 if ( pUndoData )
83 const OUString& aName = pUndoData->GetName();
84 if ( aName == STR_DB_LOCAL_NONAME )
85 bWasTemp = true;
87 OSL_ENSURE(bWasTemp, "Undo: didn't find database range");
88 (void)bWasTemp;
89 pRet = pDoc->GetAnonymousDBData(nTab);
90 if (!pRet)
92 pRet = new ScDBData( OUString(STR_DB_LOCAL_NONAME), nTab,
93 nCol1,nRow1, nCol2,nRow2, sal_True,
94 pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
95 pDoc->SetAnonymousDBData(nTab,pRet);
99 return pRet;
103 void ScUndoUtil::PaintMore( ScDocShell* pDocShell,
104 const ScRange& rRange )
106 SCCOL nCol1 = rRange.aStart.Col();
107 SCROW nRow1 = rRange.aStart.Row();
108 SCCOL nCol2 = rRange.aEnd.Col();
109 SCROW nRow2 = rRange.aEnd.Row();
110 if (nCol1 > 0) --nCol1;
111 if (nRow1 > 0) --nRow1;
112 if (nCol2<MAXCOL) ++nCol2;
113 if (nRow2<MAXROW) ++nRow2;
115 pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
116 nCol2,nRow2,rRange.aEnd.Tab(), PAINT_GRID );
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */