xref: /aoo41x/main/sc/source/ui/undo/undoutil.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // System - Includes -----------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "undoutil.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "docsh.hxx"
40*cdf0e10cSrcweir #include "tabvwsh.hxx"
41*cdf0e10cSrcweir #include "document.hxx"
42*cdf0e10cSrcweir #include "dbcolect.hxx"
43*cdf0e10cSrcweir #include "globstr.hrc"
44*cdf0e10cSrcweir #include "global.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
47*cdf0e10cSrcweir 								SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
48*cdf0e10cSrcweir 								SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     if ( pDocShell->IsPaintLocked() )
51*cdf0e10cSrcweir         return;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
54*cdf0e10cSrcweir 	if (pViewShell)
55*cdf0e10cSrcweir 	{
56*cdf0e10cSrcweir 		SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
57*cdf0e10cSrcweir 		if ( nViewTab < nStartZ || nViewTab > nEndZ )
58*cdf0e10cSrcweir 			pViewShell->SetTabNo( nStartZ );
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 		pViewShell->DoneBlockMode();
61*cdf0e10cSrcweir 		pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, sal_False, sal_False );
62*cdf0e10cSrcweir 		pViewShell->InitOwnBlockMode();
63*cdf0e10cSrcweir 		pViewShell->GetViewData()->GetMarkData().
64*cdf0e10cSrcweir 				SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
65*cdf0e10cSrcweir         pViewShell->MarkDataChanged();
66*cdf0e10cSrcweir 	}
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
71*cdf0e10cSrcweir 								const ScAddress& rBlockStart,
72*cdf0e10cSrcweir 								const ScAddress& rBlockEnd )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
75*cdf0e10cSrcweir 								rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
80*cdf0e10cSrcweir 								const ScRange& rRange )
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
83*cdf0e10cSrcweir 								rRange.aEnd.Col(),   rRange.aEnd.Row(),   rRange.aEnd.Tab()   );
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir ScDBData* ScUndoUtil::GetOldDBData( ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
89*cdf0e10cSrcweir 									SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	if (!pRet)
94*cdf0e10cSrcweir 	{
95*cdf0e10cSrcweir 		sal_Bool bWasTemp = sal_False;
96*cdf0e10cSrcweir 		if ( pUndoData )
97*cdf0e10cSrcweir 		{
98*cdf0e10cSrcweir 			String aName;
99*cdf0e10cSrcweir 			pUndoData->GetName( aName );
100*cdf0e10cSrcweir 			if ( aName == ScGlobal::GetRscString( STR_DB_NONAME ) )
101*cdf0e10cSrcweir 				bWasTemp = sal_True;
102*cdf0e10cSrcweir 		}
103*cdf0e10cSrcweir         DBG_ASSERT(bWasTemp, "Undo: didn't find database range");
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 		sal_uInt16 nIndex;
106*cdf0e10cSrcweir 		ScDBCollection* pColl = pDoc->GetDBCollection();
107*cdf0e10cSrcweir 		if (pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nIndex ))
108*cdf0e10cSrcweir 			pRet = (*pColl)[nIndex];
109*cdf0e10cSrcweir 		else
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			pRet = new ScDBData( ScGlobal::GetRscString( STR_DB_NONAME ), nTab,
112*cdf0e10cSrcweir 								nCol1,nRow1, nCol2,nRow2, sal_True,
113*cdf0e10cSrcweir 								pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
114*cdf0e10cSrcweir 			pColl->Insert( pRet );
115*cdf0e10cSrcweir 		}
116*cdf0e10cSrcweir 	}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	return pRet;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void ScUndoUtil::PaintMore( ScDocShell* pDocShell,
123*cdf0e10cSrcweir 								const ScRange& rRange )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	SCCOL nCol1 = rRange.aStart.Col();
126*cdf0e10cSrcweir 	SCROW nRow1 = rRange.aStart.Row();
127*cdf0e10cSrcweir 	SCCOL nCol2 = rRange.aEnd.Col();
128*cdf0e10cSrcweir 	SCROW nRow2 = rRange.aEnd.Row();
129*cdf0e10cSrcweir 	if (nCol1 > 0) --nCol1;
130*cdf0e10cSrcweir 	if (nRow1 > 0) --nRow1;
131*cdf0e10cSrcweir 	if (nCol2<MAXCOL) ++nCol2;
132*cdf0e10cSrcweir 	if (nRow2<MAXROW) ++nRow2;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
135*cdf0e10cSrcweir 						  nCol2,nRow2,rRange.aEnd.Tab(), PAINT_GRID );
136*cdf0e10cSrcweir }
137