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