1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // System - Includes -----------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "undoutil.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "docsh.hxx"
36cdf0e10cSrcweir #include "tabvwsh.hxx"
37cdf0e10cSrcweir #include "document.hxx"
38cdf0e10cSrcweir #include "dbcolect.hxx"
39cdf0e10cSrcweir #include "globstr.hrc"
40cdf0e10cSrcweir #include "global.hxx"
41cdf0e10cSrcweir
MarkSimpleBlock(ScDocShell * pDocShell,SCCOL nStartX,SCROW nStartY,SCTAB nStartZ,SCCOL nEndX,SCROW nEndY,SCTAB nEndZ)42cdf0e10cSrcweir void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
43cdf0e10cSrcweir SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
44cdf0e10cSrcweir SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir if ( pDocShell->IsPaintLocked() )
47cdf0e10cSrcweir return;
48cdf0e10cSrcweir
49cdf0e10cSrcweir ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
50cdf0e10cSrcweir if (pViewShell)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
53cdf0e10cSrcweir if ( nViewTab < nStartZ || nViewTab > nEndZ )
54cdf0e10cSrcweir pViewShell->SetTabNo( nStartZ );
55cdf0e10cSrcweir
56cdf0e10cSrcweir pViewShell->DoneBlockMode();
57cdf0e10cSrcweir pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, sal_False, sal_False );
58cdf0e10cSrcweir pViewShell->InitOwnBlockMode();
59cdf0e10cSrcweir pViewShell->GetViewData()->GetMarkData().
60cdf0e10cSrcweir SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
61cdf0e10cSrcweir pViewShell->MarkDataChanged();
62cdf0e10cSrcweir }
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
65cdf0e10cSrcweir
MarkSimpleBlock(ScDocShell * pDocShell,const ScAddress & rBlockStart,const ScAddress & rBlockEnd)66cdf0e10cSrcweir void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
67cdf0e10cSrcweir const ScAddress& rBlockStart,
68cdf0e10cSrcweir const ScAddress& rBlockEnd )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
71cdf0e10cSrcweir rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir
MarkSimpleBlock(ScDocShell * pDocShell,const ScRange & rRange)75cdf0e10cSrcweir void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
76cdf0e10cSrcweir const ScRange& rRange )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
79cdf0e10cSrcweir rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab() );
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir
83cdf0e10cSrcweir
GetOldDBData(ScDBData * pUndoData,ScDocument * pDoc,SCTAB nTab,SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2)84cdf0e10cSrcweir ScDBData* ScUndoUtil::GetOldDBData( ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
85*22407013SOliver-Rainer Wittmann SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
86cdf0e10cSrcweir {
87*22407013SOliver-Rainer Wittmann ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
88*22407013SOliver-Rainer Wittmann
89*22407013SOliver-Rainer Wittmann if (!pRet)
90*22407013SOliver-Rainer Wittmann {
91*22407013SOliver-Rainer Wittmann bool bWasInternalUnnamed = false;
92*22407013SOliver-Rainer Wittmann bool bWasInternalForAutoFilter = false;
93*22407013SOliver-Rainer Wittmann if ( pUndoData )
94*22407013SOliver-Rainer Wittmann {
95*22407013SOliver-Rainer Wittmann String aName;
96*22407013SOliver-Rainer Wittmann pUndoData->GetName( aName );
97*22407013SOliver-Rainer Wittmann if ( pUndoData->IsInternalUnnamed() )
98*22407013SOliver-Rainer Wittmann {
99*22407013SOliver-Rainer Wittmann bWasInternalUnnamed = true;
100*22407013SOliver-Rainer Wittmann }
101*22407013SOliver-Rainer Wittmann else if (pUndoData->IsInternalForAutoFilter())
102*22407013SOliver-Rainer Wittmann {
103*22407013SOliver-Rainer Wittmann bWasInternalForAutoFilter = true;
104*22407013SOliver-Rainer Wittmann }
105*22407013SOliver-Rainer Wittmann }
106*22407013SOliver-Rainer Wittmann DBG_ASSERT( bWasInternalUnnamed || bWasInternalForAutoFilter, "Undo: didn't find database range");
107*22407013SOliver-Rainer Wittmann
108*22407013SOliver-Rainer Wittmann sal_uInt16 nIndex;
109*22407013SOliver-Rainer Wittmann ScDBCollection* pColl = pDoc->GetDBCollection();
110*22407013SOliver-Rainer Wittmann if ( bWasInternalUnnamed
111*22407013SOliver-Rainer Wittmann && pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nIndex ))
112*22407013SOliver-Rainer Wittmann {
113*22407013SOliver-Rainer Wittmann pRet = (*pColl)[nIndex];
114*22407013SOliver-Rainer Wittmann }
115*22407013SOliver-Rainer Wittmann else
116*22407013SOliver-Rainer Wittmann {
117*22407013SOliver-Rainer Wittmann String aNewNamed = bWasInternalForAutoFilter
118*22407013SOliver-Rainer Wittmann ? pColl->GetNewDefaultDBName()
119*22407013SOliver-Rainer Wittmann : ScGlobal::GetRscString( STR_DB_NONAME );
120*22407013SOliver-Rainer Wittmann pRet = new ScDBData(
121*22407013SOliver-Rainer Wittmann aNewNamed, nTab, nCol1,nRow1, nCol2,nRow2, sal_True,
122*22407013SOliver-Rainer Wittmann pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
123*22407013SOliver-Rainer Wittmann pColl->Insert( pRet );
124*22407013SOliver-Rainer Wittmann }
125*22407013SOliver-Rainer Wittmann }
126*22407013SOliver-Rainer Wittmann
127*22407013SOliver-Rainer Wittmann return pRet;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir
PaintMore(ScDocShell * pDocShell,const ScRange & rRange)131cdf0e10cSrcweir void ScUndoUtil::PaintMore( ScDocShell* pDocShell,
132cdf0e10cSrcweir const ScRange& rRange )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir SCCOL nCol1 = rRange.aStart.Col();
135cdf0e10cSrcweir SCROW nRow1 = rRange.aStart.Row();
136cdf0e10cSrcweir SCCOL nCol2 = rRange.aEnd.Col();
137cdf0e10cSrcweir SCROW nRow2 = rRange.aEnd.Row();
138cdf0e10cSrcweir if (nCol1 > 0) --nCol1;
139cdf0e10cSrcweir if (nRow1 > 0) --nRow1;
140cdf0e10cSrcweir if (nCol2<MAXCOL) ++nCol2;
141cdf0e10cSrcweir if (nRow2<MAXROW) ++nRow2;
142cdf0e10cSrcweir
143cdf0e10cSrcweir pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
144cdf0e10cSrcweir nCol2,nRow2,rRange.aEnd.Tab(), PAINT_GRID );
145cdf0e10cSrcweir }
146