merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / undo / undoutil.cxx
blob63401a03b49666797b066cd4aff94148b1b0bcb9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undoutil.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes -----------------------------------------------------
38 // INCLUDE ---------------------------------------------------------------
40 #include "undoutil.hxx"
42 #include "docsh.hxx"
43 #include "tabvwsh.hxx"
44 #include "document.hxx"
45 #include "dbcolect.hxx"
46 #include "globstr.hrc"
47 #include "global.hxx"
49 void ScUndoUtil::MarkSimpleBlock( ScDocShell* /* pDocShell */,
50 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
51 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
53 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
54 if (pViewShell)
56 SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
57 if ( nViewTab < nStartZ || nViewTab > nEndZ )
58 pViewShell->SetTabNo( nStartZ );
60 pViewShell->DoneBlockMode();
61 pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, FALSE, FALSE );
62 pViewShell->InitOwnBlockMode();
63 pViewShell->GetViewData()->GetMarkData().
64 SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
65 pViewShell->MarkDataChanged();
70 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
71 const ScAddress& rBlockStart,
72 const ScAddress& rBlockEnd )
74 MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
75 rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
79 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
80 const ScRange& rRange )
82 MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
83 rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab() );
88 ScDBData* ScUndoUtil::GetOldDBData( ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
89 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
91 ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
93 if (!pRet)
95 BOOL bWasTemp = FALSE;
96 if ( pUndoData )
98 String aName;
99 pUndoData->GetName( aName );
100 if ( aName == ScGlobal::GetRscString( STR_DB_NONAME ) )
101 bWasTemp = TRUE;
103 DBG_ASSERT(bWasTemp, "Undo: didn't find database range");
105 USHORT nIndex;
106 ScDBCollection* pColl = pDoc->GetDBCollection();
107 if (pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nIndex ))
108 pRet = (*pColl)[nIndex];
109 else
111 pRet = new ScDBData( ScGlobal::GetRscString( STR_DB_NONAME ), nTab,
112 nCol1,nRow1, nCol2,nRow2, TRUE,
113 pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
114 pColl->Insert( pRet );
118 return pRet;
122 void ScUndoUtil::PaintMore( ScDocShell* pDocShell,
123 const ScRange& rRange )
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;
134 pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
135 nCol2,nRow2,rRange.aEnd.Tab(), PAINT_GRID );