xref: /aoo41x/main/sc/source/core/tool/detdata.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 
32 
33 // INCLUDE ---------------------------------------------------------------
34 
35 #include <tools/debug.hxx>
36 
37 #include "detdata.hxx"
38 #include "refupdat.hxx"
39 #include "rechead.hxx"
40 
41 //------------------------------------------------------------------------
42 
43 SV_IMPL_PTRARR( ScDetOpArr_Impl, ScDetOpDataPtr );
44 
45 //------------------------------------------------------------------------
46 
47 ScDetOpList::ScDetOpList(const ScDetOpList& rList) :
48     ScDetOpArr_Impl(),
49 	bHasAddError( sal_False )
50 {
51 	sal_uInt16 nCount = rList.Count();
52 
53 	for (sal_uInt16 i=0; i<nCount; i++)
54 		Append( new ScDetOpData(*rList[i]) );
55 }
56 
57 void ScDetOpList::DeleteOnTab( SCTAB nTab )
58 {
59     sal_uInt16 nPos = 0;
60     while ( nPos < Count() )
61     {
62         // look for operations on the deleted sheet
63 
64         if ( (*this)[nPos]->GetPos().Tab() == nTab )
65             Remove(nPos);
66         else
67             ++nPos;
68     }
69 }
70 
71 void ScDetOpList::UpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
72 								const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
73 {
74 	sal_uInt16 nCount = Count();
75 	for (sal_uInt16 i=0; i<nCount; i++)
76 	{
77 		ScAddress aPos = (*this)[i]->GetPos();
78 		SCCOL nCol1 = aPos.Col();
79 		SCROW nRow1 = aPos.Row();
80 		SCTAB nTab1 = aPos.Tab();
81 		SCCOL nCol2 = nCol1;
82 		SCROW nRow2 = nRow1;
83 		SCTAB nTab2 = nTab1;
84 
85 		ScRefUpdateRes eRes =
86 			ScRefUpdate::Update( pDoc, eUpdateRefMode,
87 				rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
88 				rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, nDz,
89 				nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
90 		if ( eRes != UR_NOTHING )
91 			(*this)[i]->SetPos( ScAddress( nCol1, nRow1, nTab1 ) );
92 	}
93 }
94 
95 void ScDetOpList::Append( ScDetOpData* pDetOpData )
96 {
97     if ( pDetOpData->GetOperation() == SCDETOP_ADDERROR )
98 		bHasAddError = sal_True;
99 
100     Insert( pDetOpData, Count() );
101 }
102 
103 
104 sal_Bool ScDetOpList::operator==( const ScDetOpList& r ) const
105 {
106 	// fuer Ref-Undo
107 
108 	sal_uInt16 nCount = Count();
109 	sal_Bool bEqual = ( nCount == r.Count() );
110 	for (sal_uInt16 i=0; i<nCount && bEqual; i++)		// Reihenfolge muss auch gleich sein
111 		if ( !(*(*this)[i] == *r[i]) )				// Eintraege unterschiedlich ?
112 			bEqual = sal_False;
113 
114 	return bEqual;
115 }
116 
117 
118 
119