Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "refupdat.hxx"
30 : : #include "document.hxx"
31 : : #include "compiler.hxx"
32 : : #include "bigrange.hxx"
33 : : #include "chgtrack.hxx"
34 : :
35 : : //------------------------------------------------------------------------
36 : :
37 : : template< typename R, typename S, typename U >
38 : 2970 : bool lcl_MoveStart( R& rRef, U nStart, S nDelta, U nMask )
39 : : {
40 : 2970 : bool bCut = false;
41 [ + + ][ + + ]: 2970 : if ( rRef >= nStart )
42 : 2871 : rRef = sal::static_int_cast<R>( rRef + nDelta );
43 [ + + ][ + + ]: 99 : else if ( nDelta < 0 && rRef >= nStart + nDelta )
[ + + ][ + + ]
44 : 3 : rRef = nStart + nDelta; //! begrenzen ???
45 [ - + ][ + + ]: 2970 : if ( rRef < 0 )
46 : : {
47 : 80 : rRef = 0;
48 : 80 : bCut = true;
49 : : }
50 [ - + ][ + + ]: 2890 : else if ( rRef > nMask )
51 : : {
52 : 7 : rRef = nMask;
53 : 7 : bCut = true;
54 : : }
55 : 2970 : return bCut;
56 : : }
57 : :
58 : : template< typename R, typename S, typename U >
59 : 2970 : bool lcl_MoveEnd( R& rRef, U nStart, S nDelta, U nMask )
60 : : {
61 : 2970 : bool bCut = false;
62 [ + + ][ + + ]: 2970 : if ( rRef >= nStart )
63 : 2901 : rRef = sal::static_int_cast<R>( rRef + nDelta );
64 [ + + ][ + + ]: 69 : else if ( nDelta < 0 && rRef >= nStart + nDelta )
[ - + ][ # # ]
65 : 3 : rRef = nStart + nDelta - 1; //! begrenzen ???
66 [ - + ][ + + ]: 2970 : if ( rRef < 0 )
67 : : {
68 : 80 : rRef = 0;
69 : 80 : bCut = true;
70 : : }
71 [ + + ][ + + ]: 2890 : else if ( rRef > nMask )
72 : : {
73 : 16 : rRef = nMask;
74 : 16 : bCut = true;
75 : : }
76 : 2970 : return bCut;
77 : : }
78 : :
79 : : template< typename R, typename S, typename U >
80 : 24 : bool lcl_MoveReorder( R& rRef, U nStart, U nEnd, S nDelta )
81 : : {
82 [ + + ][ + - ]: 24 : if ( rRef >= nStart && rRef <= nEnd )
83 : : {
84 : 12 : rRef = sal::static_int_cast<R>( rRef + nDelta );
85 : 12 : return true;
86 : : }
87 : :
88 [ - + ]: 12 : if ( nDelta > 0 ) // nach hinten schieben
89 : : {
90 [ # # ][ # # ]: 0 : if ( rRef >= nStart && rRef <= nEnd + nDelta )
91 : : {
92 [ # # ]: 0 : if ( rRef <= nEnd )
93 : 0 : rRef = sal::static_int_cast<R>( rRef + nDelta ); // in the moved range
94 : : else
95 : 0 : rRef -= nEnd - nStart + 1; // nachruecken
96 : 0 : return true;
97 : : }
98 : : }
99 : : else // nach vorne schieben
100 : : {
101 [ + - ][ + - ]: 12 : if ( rRef >= nStart + nDelta && rRef <= nEnd )
102 : : {
103 [ - + ]: 12 : if ( rRef >= nStart )
104 : 0 : rRef = sal::static_int_cast<R>( rRef + nDelta ); // in the moved range
105 : : else
106 : 12 : rRef += nEnd - nStart + 1; // nachruecken
107 : 12 : return true;
108 : : }
109 : : }
110 : :
111 : 24 : return false;
112 : : }
113 : :
114 : : template< typename R, typename S, typename U >
115 : 0 : bool lcl_MoveItCut( R& rRef, S nDelta, U nMask )
116 : : {
117 : 0 : bool bCut = false;
118 : 0 : rRef = sal::static_int_cast<R>( rRef + nDelta );
119 [ # # # # ]: 0 : if ( rRef < 0 )
120 : : {
121 : 0 : rRef = 0;
122 : 0 : bCut = true;
123 : : }
124 [ # # ][ # # ]: 0 : else if ( rRef > nMask )
125 : : {
126 : 0 : rRef = nMask;
127 : 0 : bCut = true;
128 : : }
129 : 0 : return bCut;
130 : : }
131 : :
132 : : template< typename R, typename S, typename U >
133 : 208 : void lcl_MoveItWrap( R& rRef, S nDelta, U nMask )
134 : : {
135 : 208 : rRef = sal::static_int_cast<R>( rRef + nDelta );
136 [ - + - + ]: 208 : if ( rRef < 0 )
137 : 0 : rRef += nMask+1;
138 [ - + ][ - + ]: 208 : else if ( rRef > nMask )
139 : 0 : rRef -= nMask+1;
140 : 208 : }
141 : :
142 : : template< typename R, typename S, typename U >
143 : 18 : bool lcl_MoveRefPart( R& rRef1Val, bool& rRef1Del, bool bDo1,
144 : : R& rRef2Val, bool& rRef2Del, bool bDo2,
145 : : U nStart, U nEnd, S nDelta, U nMask )
146 : : {
147 [ + - ][ # # ]: 18 : if ( nDelta )
148 : : {
149 : : bool bDel, bCut1, bCut2;
150 : 18 : bDel = bCut1 = bCut2 = false;
151 : : S n;
152 [ + - ][ + - ]: 18 : if (bDo1 && bDo2)
[ # # ][ # # ]
153 : : {
154 [ + + ][ # # ]: 18 : if ( nDelta < 0 )
155 : : {
156 : 6 : n = nStart + nDelta;
157 [ + + ][ - + ]: 6 : if ( n <= rRef1Val && rRef1Val < nStart
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
158 : : && n <= rRef2Val && rRef2Val < nStart )
159 : 0 : bDel = true;
160 : : }
161 : : else
162 : : {
163 : 12 : n = nEnd + nDelta;
164 [ - + ][ # # ]: 12 : if ( nEnd < rRef1Val && rRef1Val <= n
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
165 : : && nEnd < rRef2Val && rRef2Val <= n )
166 : 0 : bDel = true;
167 : : }
168 : : }
169 [ - + ][ # # ]: 18 : if ( bDel )
170 : : { // move deleted along
171 : 0 : rRef1Val = sal::static_int_cast<R>( rRef1Val + nDelta );
172 : 0 : rRef2Val = sal::static_int_cast<R>( rRef2Val + nDelta );
173 : : }
174 : : else
175 : : {
176 [ + - ][ # # ]: 18 : if (bDo1)
177 : : {
178 [ - + ][ # # ]: 18 : if ( rRef1Del )
179 : 0 : rRef1Val = sal::static_int_cast<R>( rRef1Val + nDelta );
180 : : else
181 : 18 : bCut1 = lcl_MoveStart( rRef1Val, nStart, nDelta, nMask );
182 : : }
183 [ + - ][ # # ]: 18 : if (bDo2)
184 : : {
185 [ - + ][ # # ]: 18 : if ( rRef2Del )
186 : 0 : rRef2Val = sal::static_int_cast<R>( rRef2Val + nDelta );
187 : : else
188 : 18 : bCut2 = lcl_MoveEnd( rRef2Val, nStart, nDelta, nMask );
189 : : }
190 : : }
191 [ + - ][ - + ]: 18 : if ( bDel || (bCut1 && bCut2) )
[ # # ][ # # ]
[ # # ][ # # ]
192 : 0 : rRef1Del = rRef2Del = true;
193 [ + - ][ + - ]: 18 : return bDel || bCut1 || bCut2 || rRef1Del || rRef2Del;
[ + - ][ + - ]
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
194 : : }
195 : : else
196 : 18 : return false;
197 : : }
198 : :
199 : : template< typename R, typename S, typename U >
200 : 114 : bool IsExpand( R n1, R n2, U nStart, S nD )
201 : : { //! vor normalem Move...
202 : : return
203 : : nD > 0 // Insert
204 : : && n1 < n2 // mindestens zwei Cols/Rows/Tabs in Ref
205 : : && (
206 : : (nStart <= n1 && n1 < nStart + nD) // n1 innerhalb des Insert
207 : : || (n2 + 1 == nStart) // n2 direkt vor Insert
208 [ + - ][ + + ]: 114 : ); // n1 < nStart <= n2 wird sowieso expanded!
[ + - ][ - + ]
[ # # ][ + - ]
[ + + ][ + + ]
[ - + ][ - + ]
209 : : }
210 : :
211 : :
212 : : template< typename R, typename S, typename U >
213 : 3 : void Expand( R& n1, R& n2, U nStart, S nD )
214 : : { //! nach normalem Move..., nur wenn IsExpand vorher true war!
215 : : //! erst das Ende
216 [ - + ][ - + ]: 3 : if ( n2 + 1 == nStart )
217 : : { // am Ende
218 : 0 : n2 = sal::static_int_cast<R>( n2 + nD );
219 : 3 : return;
220 : : }
221 : : // am Anfang
222 : 3 : n1 = sal::static_int_cast<R>( n1 - nD );
223 : : }
224 : :
225 : :
226 : 0 : bool lcl_IsWrapBig( sal_Int32 nRef, sal_Int32 nDelta )
227 : : {
228 [ # # ][ # # ]: 0 : if ( nRef > 0 && nDelta > 0 )
229 : 0 : return nRef + nDelta <= 0;
230 [ # # ][ # # ]: 0 : else if ( nRef < 0 && nDelta < 0 )
231 : 0 : return nRef + nDelta >= 0;
232 : 0 : return false;
233 : : }
234 : :
235 : :
236 : 0 : bool lcl_MoveBig( sal_Int32& rRef, sal_Int32 nStart, sal_Int32 nDelta )
237 : : {
238 : 0 : bool bCut = false;
239 [ # # ]: 0 : if ( rRef >= nStart )
240 : : {
241 [ # # ]: 0 : if ( nDelta > 0 )
242 : 0 : bCut = lcl_IsWrapBig( rRef, nDelta );
243 [ # # ]: 0 : if ( bCut )
244 : 0 : rRef = nInt32Max;
245 : : else
246 : 0 : rRef += nDelta;
247 : : }
248 : 0 : return bCut;
249 : : }
250 : :
251 : 0 : bool lcl_MoveItCutBig( sal_Int32& rRef, sal_Int32 nDelta )
252 : : {
253 : 0 : bool bCut = lcl_IsWrapBig( rRef, nDelta );
254 : 0 : rRef += nDelta;
255 : 0 : return bCut;
256 : : }
257 : :
258 : :
259 : 3029 : ScRefUpdateRes ScRefUpdate::Update( ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
260 : : SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
261 : : SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
262 : : SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
263 : : SCCOL& theCol1, SCROW& theRow1, SCTAB& theTab1,
264 : : SCCOL& theCol2, SCROW& theRow2, SCTAB& theTab2 )
265 : : {
266 : 3029 : ScRefUpdateRes eRet = UR_NOTHING;
267 : :
268 : 3029 : SCCOL oldCol1 = theCol1;
269 : 3029 : SCROW oldRow1 = theRow1;
270 : 3029 : SCTAB oldTab1 = theTab1;
271 : 3029 : SCCOL oldCol2 = theCol2;
272 : 3029 : SCROW oldRow2 = theRow2;
273 : 3029 : SCTAB oldTab2 = theTab2;
274 : :
275 : : bool bCut1, bCut2;
276 : :
277 [ + + ]: 3029 : if (eUpdateRefMode == URM_INSDEL)
278 : : {
279 : 3017 : bool bExpand = pDoc->IsExpandRefs();
280 [ + - ][ + - ]: 3017 : if ( nDx && (theRow1 >= nRow1) && (theRow2 <= nRow2) &&
[ + - ][ + - ]
[ + + ]
281 : : (theTab1 >= nTab1) && (theTab2 <= nTab2) )
282 : : {
283 [ + + ][ + + ]: 114 : bool bExp = (bExpand && IsExpand( theCol1, theCol2, nCol1, nDx ));
284 : 114 : bCut1 = lcl_MoveStart( theCol1, nCol1, nDx, MAXCOL );
285 : 114 : bCut2 = lcl_MoveEnd( theCol2, nCol1, nDx, MAXCOL );
286 [ - + ]: 114 : if ( theCol2 < theCol1 )
287 : : {
288 : 0 : eRet = UR_INVALID;
289 : 0 : theCol2 = theCol1;
290 : : }
291 [ + + ][ + + ]: 114 : else if ( bCut1 || bCut2 )
292 : 10 : eRet = UR_UPDATED;
293 [ + + ]: 114 : if ( bExp )
294 : : {
295 : 2 : Expand( theCol1, theCol2, nCol1, nDx );
296 : 2 : eRet = UR_UPDATED;
297 : : }
298 : : }
299 [ + + ][ + - ]: 3017 : if ( nDy && (theCol1 >= nCol1) && (theCol2 <= nCol2) &&
[ + - ][ + - ]
[ + - ]
300 : : (theTab1 >= nTab1) && (theTab2 <= nTab2) )
301 : : {
302 [ + + ][ + + ]: 92 : bool bExp = (bExpand && IsExpand( theRow1, theRow2, nRow1, nDy ));
303 : 92 : bCut1 = lcl_MoveStart( theRow1, nRow1, nDy, MAXROW );
304 : 92 : bCut2 = lcl_MoveEnd( theRow2, nRow1, nDy, MAXROW );
305 [ - + ]: 92 : if ( theRow2 < theRow1 )
306 : : {
307 : 0 : eRet = UR_INVALID;
308 : 0 : theRow2 = theRow1;
309 : : }
310 [ + - ][ + + ]: 92 : else if ( bCut1 || bCut2 )
311 : 6 : eRet = UR_UPDATED;
312 [ + + ]: 92 : if ( bExp )
313 : : {
314 : 1 : Expand( theRow1, theRow2, nRow1, nDy );
315 : 1 : eRet = UR_UPDATED;
316 : : }
317 : : }
318 [ + + ][ + + ]: 3017 : if ( nDz && (theCol1 >= nCol1) && (theCol2 <= nCol2) &&
[ + - ][ + - ]
[ + - ]
319 : : (theRow1 >= nRow1) && (theRow2 <= nRow2) )
320 : : {
321 : 2746 : SCsTAB nMaxTab = pDoc->GetTableCount() - 1;
322 : 2746 : nMaxTab = sal::static_int_cast<SCsTAB>(nMaxTab + nDz); // adjust to new count
323 [ # # ][ - + ]: 2746 : bool bExp = (bExpand && IsExpand( theTab1, theTab2, nTab1, nDz ));
324 : 2746 : bCut1 = lcl_MoveStart( theTab1, nTab1, nDz, static_cast<SCTAB>(nMaxTab) );
325 : 2746 : bCut2 = lcl_MoveEnd( theTab2, nTab1, nDz, static_cast<SCTAB>(nMaxTab) );
326 [ - + ]: 2746 : if ( theTab2 < theTab1 )
327 : : {
328 : 0 : eRet = UR_INVALID;
329 : 0 : theTab2 = theTab1;
330 : : }
331 [ + + ][ - + ]: 2746 : else if ( bCut1 || bCut2 )
332 : 80 : eRet = UR_UPDATED;
333 [ - + ]: 2746 : if ( bExp )
334 : : {
335 : 0 : Expand( theTab1, theTab2, nTab1, nDz );
336 : 0 : eRet = UR_UPDATED;
337 : : }
338 : : }
339 : : }
340 [ - + ]: 12 : else if (eUpdateRefMode == URM_MOVE)
341 : : {
342 [ # # ][ # # ]: 0 : if ((theCol1 >= nCol1-nDx) && (theRow1 >= nRow1-nDy) && (theTab1 >= nTab1-nDz) &&
[ # # ][ # # ]
[ # # ][ # # ]
343 : : (theCol2 <= nCol2-nDx) && (theRow2 <= nRow2-nDy) && (theTab2 <= nTab2-nDz))
344 : : {
345 [ # # ]: 0 : if ( nDx )
346 : : {
347 : 0 : bCut1 = lcl_MoveItCut( theCol1, nDx, MAXCOL );
348 : 0 : bCut2 = lcl_MoveItCut( theCol2, nDx, MAXCOL );
349 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
350 : 0 : eRet = UR_UPDATED;
351 : : }
352 [ # # ]: 0 : if ( nDy )
353 : : {
354 : 0 : bCut1 = lcl_MoveItCut( theRow1, nDy, MAXROW );
355 : 0 : bCut2 = lcl_MoveItCut( theRow2, nDy, MAXROW );
356 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
357 : 0 : eRet = UR_UPDATED;
358 : : }
359 [ # # ]: 0 : if ( nDz )
360 : : {
361 : 0 : SCsTAB nMaxTab = (SCsTAB) pDoc->GetTableCount() - 1;
362 : 0 : bCut1 = lcl_MoveItCut( theTab1, nDz, static_cast<SCTAB>(nMaxTab) );
363 : 0 : bCut2 = lcl_MoveItCut( theTab2, nDz, static_cast<SCTAB>(nMaxTab) );
364 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
365 : 0 : eRet = UR_UPDATED;
366 : : }
367 : : }
368 : : }
369 [ + - ]: 12 : else if (eUpdateRefMode == URM_REORDER)
370 : : {
371 : : // bisher nur fuer nDz (MoveTab)
372 : : OSL_ENSURE ( !nDx && !nDy, "URM_REORDER fuer x und y noch nicht implementiert" );
373 : :
374 [ + - ][ + - ]: 12 : if ( nDz && (theCol1 >= nCol1) && (theCol2 <= nCol2) &&
[ + - ][ + - ]
[ + - ]
375 : : (theRow1 >= nRow1) && (theRow2 <= nRow2) )
376 : : {
377 : 12 : bCut1 = lcl_MoveReorder( theTab1, nTab1, nTab2, nDz );
378 : 12 : bCut2 = lcl_MoveReorder( theTab2, nTab1, nTab2, nDz );
379 [ # # ][ - + ]: 12 : if ( bCut1 || bCut2 )
380 : 12 : eRet = UR_UPDATED;
381 : : }
382 : : }
383 : :
384 [ + + ]: 3029 : if ( eRet == UR_NOTHING )
385 : : {
386 [ + + ][ + + ]: 2921 : if (oldCol1 != theCol1
[ + + ][ + + ]
[ + + ][ - + ]
387 : : || oldRow1 != theRow1
388 : : || oldTab1 != theTab1
389 : : || oldCol2 != theCol2
390 : : || oldRow2 != theRow2
391 : : || oldTab2 != theTab2
392 : : )
393 : 2799 : eRet = UR_UPDATED;
394 : : }
395 : 3029 : return eRet;
396 : : }
397 : :
398 : :
399 : : // simples UpdateReference fuer ScBigRange (ScChangeAction/ScChangeTrack)
400 : : // Referenzen koennen auch ausserhalb des Dokuments liegen!
401 : : // Ganze Spalten/Zeilen (nInt32Min..nInt32Max) bleiben immer solche!
402 : 0 : ScRefUpdateRes ScRefUpdate::Update( UpdateRefMode eUpdateRefMode,
403 : : const ScBigRange& rWhere, sal_Int32 nDx, sal_Int32 nDy, sal_Int32 nDz,
404 : : ScBigRange& rWhat )
405 : : {
406 : 0 : ScRefUpdateRes eRet = UR_NOTHING;
407 : 0 : const ScBigRange aOldRange( rWhat );
408 : :
409 : : sal_Int32 nCol1, nRow1, nTab1, nCol2, nRow2, nTab2;
410 : : sal_Int32 theCol1, theRow1, theTab1, theCol2, theRow2, theTab2;
411 : 0 : rWhere.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
412 : 0 : rWhat.GetVars( theCol1, theRow1, theTab1, theCol2, theRow2, theTab2 );
413 : :
414 : : bool bCut1, bCut2;
415 : :
416 [ # # ]: 0 : if (eUpdateRefMode == URM_INSDEL)
417 : : {
418 [ # # ][ # # ]: 0 : if ( nDx && (theRow1 >= nRow1) && (theRow2 <= nRow2) &&
[ # # ][ # # ]
[ # # ][ # # ]
419 : : (theTab1 >= nTab1) && (theTab2 <= nTab2) &&
420 [ # # ]: 0 : !(theCol1 == nInt32Min && theCol2 == nInt32Max) )
421 : : {
422 : 0 : bCut1 = lcl_MoveBig( theCol1, nCol1, nDx );
423 : 0 : bCut2 = lcl_MoveBig( theCol2, nCol1, nDx );
424 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
425 : 0 : eRet = UR_UPDATED;
426 : 0 : rWhat.aStart.SetCol( theCol1 );
427 : 0 : rWhat.aEnd.SetCol( theCol2 );
428 : : }
429 [ # # ][ # # ]: 0 : if ( nDy && (theCol1 >= nCol1) && (theCol2 <= nCol2) &&
[ # # ][ # # ]
[ # # ][ # # ]
430 : : (theTab1 >= nTab1) && (theTab2 <= nTab2) &&
431 [ # # ]: 0 : !(theRow1 == nInt32Min && theRow2 == nInt32Max) )
432 : : {
433 : 0 : bCut1 = lcl_MoveBig( theRow1, nRow1, nDy );
434 : 0 : bCut2 = lcl_MoveBig( theRow2, nRow1, nDy );
435 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
436 : 0 : eRet = UR_UPDATED;
437 : 0 : rWhat.aStart.SetRow( theRow1 );
438 : 0 : rWhat.aEnd.SetRow( theRow2 );
439 : : }
440 [ # # ][ # # ]: 0 : if ( nDz && (theCol1 >= nCol1) && (theCol2 <= nCol2) &&
[ # # ][ # # ]
[ # # ][ # # ]
441 : : (theRow1 >= nRow1) && (theRow2 <= nRow2) &&
442 [ # # ]: 0 : !(theTab1 == nInt32Min && theTab2 == nInt32Max) )
443 : : {
444 : 0 : bCut1 = lcl_MoveBig( theTab1, nTab1, nDz );
445 : 0 : bCut2 = lcl_MoveBig( theTab2, nTab1, nDz );
446 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
447 : 0 : eRet = UR_UPDATED;
448 : 0 : rWhat.aStart.SetTab( theTab1 );
449 : 0 : rWhat.aEnd.SetTab( theTab2 );
450 : : }
451 : : }
452 [ # # ]: 0 : else if (eUpdateRefMode == URM_MOVE)
453 : : {
454 [ # # ]: 0 : if ( rWhere.In( rWhat ) )
455 : : {
456 [ # # ][ # # ]: 0 : if ( nDx && !(theCol1 == nInt32Min && theCol2 == nInt32Max) )
[ # # ]
457 : : {
458 : 0 : bCut1 = lcl_MoveItCutBig( theCol1, nDx );
459 : 0 : bCut2 = lcl_MoveItCutBig( theCol2, nDx );
460 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
461 : 0 : eRet = UR_UPDATED;
462 : 0 : rWhat.aStart.SetCol( theCol1 );
463 : 0 : rWhat.aEnd.SetCol( theCol2 );
464 : : }
465 [ # # ][ # # ]: 0 : if ( nDy && !(theRow1 == nInt32Min && theRow2 == nInt32Max) )
[ # # ]
466 : : {
467 : 0 : bCut1 = lcl_MoveItCutBig( theRow1, nDy );
468 : 0 : bCut2 = lcl_MoveItCutBig( theRow2, nDy );
469 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
470 : 0 : eRet = UR_UPDATED;
471 : 0 : rWhat.aStart.SetRow( theRow1 );
472 : 0 : rWhat.aEnd.SetRow( theRow2 );
473 : : }
474 [ # # ][ # # ]: 0 : if ( nDz && !(theTab1 == nInt32Min && theTab2 == nInt32Max) )
[ # # ]
475 : : {
476 : 0 : bCut1 = lcl_MoveItCutBig( theTab1, nDz );
477 : 0 : bCut2 = lcl_MoveItCutBig( theTab2, nDz );
478 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
479 : 0 : eRet = UR_UPDATED;
480 : 0 : rWhat.aStart.SetTab( theTab1 );
481 : 0 : rWhat.aEnd.SetTab( theTab2 );
482 : : }
483 : : }
484 : : }
485 : :
486 [ # # ][ # # ]: 0 : if ( eRet == UR_NOTHING && rWhat != aOldRange )
[ # # ]
487 : 0 : eRet = UR_UPDATED;
488 : :
489 : 0 : return eRet;
490 : : }
491 : :
492 : :
493 : 21 : ScRefUpdateRes ScRefUpdate::Update( ScDocument* pDoc, UpdateRefMode eMode,
494 : : const ScAddress& rPos, const ScRange& r,
495 : : SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
496 : : ScComplexRefData& rRef, WhatType eWhat )
497 : : {
498 : 21 : ScRefUpdateRes eRet = UR_NOTHING;
499 : :
500 : 21 : SCCOL nCol1 = r.aStart.Col();
501 : 21 : SCROW nRow1 = r.aStart.Row();
502 : 21 : SCTAB nTab1 = r.aStart.Tab();
503 : 21 : SCCOL nCol2 = r.aEnd.Col();
504 : 21 : SCROW nRow2 = r.aEnd.Row();
505 : 21 : SCTAB nTab2 = r.aEnd.Tab();
506 : :
507 [ + + ]: 21 : if( eMode == URM_INSDEL )
508 : : {
509 : 18 : bool bExpand = pDoc->IsExpandRefs();
510 : :
511 : 18 : const ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
512 : : bool bInDeleteUndo =
513 [ - + ]: 18 : ( pChangeTrack ? pChangeTrack->IsInDeleteUndo() : false );
514 : :
515 : 18 : SCCOL oldCol1 = rRef.Ref1.nCol;
516 : 18 : SCROW oldRow1 = rRef.Ref1.nRow;
517 : 18 : SCTAB oldTab1 = rRef.Ref1.nTab;
518 : 18 : SCCOL oldCol2 = rRef.Ref2.nCol;
519 : 18 : SCROW oldRow2 = rRef.Ref2.nRow;
520 : 18 : SCTAB oldTab2 = rRef.Ref2.nTab;
521 : :
522 : 18 : bool bRef1ColDel = rRef.Ref1.IsColDeleted();
523 : 18 : bool bRef2ColDel = rRef.Ref2.IsColDeleted();
524 : 18 : bool bRef1RowDel = rRef.Ref1.IsRowDeleted();
525 : 18 : bool bRef2RowDel = rRef.Ref2.IsRowDeleted();
526 : 18 : bool bRef1TabDel = rRef.Ref1.IsTabDeleted();
527 : 18 : bool bRef2TabDel = rRef.Ref2.IsTabDeleted();
528 : :
529 [ # # ][ # # ]: 18 : if( nDx &&
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ - + ]
530 : : ((rRef.Ref1.nRow >= nRow1
531 : : && rRef.Ref2.nRow <= nRow2) || (bRef1RowDel || bRef2RowDel))
532 : : &&
533 : : ((rRef.Ref1.nTab >= nTab1
534 : : && rRef.Ref2.nTab <= nTab2) || (bRef1TabDel || bRef2TabDel))
535 : : )
536 : : {
537 : 0 : bool bExp = (bExpand && !bInDeleteUndo && IsExpand( rRef.Ref1.nCol,
538 [ # # ][ # # ]: 0 : rRef.Ref2.nCol, nCol1, nDx ));
[ # # ]
539 : : bool bDo1 = (eWhat == ScRefUpdate::ALL || (eWhat ==
540 [ # # ][ # # ]: 0 : ScRefUpdate::ABSOLUTE && !rRef.Ref1.IsColRel()));
[ # # ]
541 : : bool bDo2 = (eWhat == ScRefUpdate::ALL || (eWhat ==
542 [ # # ][ # # ]: 0 : ScRefUpdate::ABSOLUTE && !rRef.Ref2.IsColRel()));
[ # # ]
543 [ # # ]: 0 : if ( lcl_MoveRefPart( rRef.Ref1.nCol, bRef1ColDel, bDo1,
544 : : rRef.Ref2.nCol, bRef2ColDel, bDo2,
545 : 0 : nCol1, nCol2, nDx, MAXCOL ) )
546 : : {
547 : 0 : eRet = UR_UPDATED;
548 [ # # ][ # # ]: 0 : if ( bInDeleteUndo && (bRef1ColDel || bRef2ColDel) )
[ # # ]
549 : : {
550 [ # # ][ # # ]: 0 : if ( bRef1ColDel && nCol1 <= rRef.Ref1.nCol &&
[ # # ]
551 : : rRef.Ref1.nCol <= nCol1 + nDx )
552 : 0 : rRef.Ref1.SetColDeleted( false );
553 [ # # ][ # # ]: 0 : if ( bRef2ColDel && nCol1 <= rRef.Ref2.nCol &&
[ # # ]
554 : : rRef.Ref2.nCol <= nCol1 + nDx )
555 : 0 : rRef.Ref2.SetColDeleted( false );
556 : : }
557 : : else
558 : : {
559 [ # # ]: 0 : if ( bRef1ColDel )
560 : 0 : rRef.Ref1.SetColDeleted( true );
561 [ # # ]: 0 : if ( bRef2ColDel )
562 : 0 : rRef.Ref2.SetColDeleted( true );
563 : : }
564 : : }
565 [ # # ]: 0 : if ( bExp )
566 : : {
567 : 0 : Expand( rRef.Ref1.nCol, rRef.Ref2.nCol, nCol1, nDx );
568 : 0 : eRet = UR_UPDATED;
569 : : }
570 : : }
571 [ + - ][ + - ]: 18 : if( nDy &&
[ - + ][ # # ]
[ # # ][ + - ]
[ - + ][ # # ]
[ # # ]
572 : : ((rRef.Ref1.nCol >= nCol1
573 : : && rRef.Ref2.nCol <= nCol2) || (bRef1ColDel || bRef2ColDel))
574 : : &&
575 : : ((rRef.Ref1.nTab >= nTab1
576 : : && rRef.Ref2.nTab <= nTab2) || (bRef1TabDel || bRef2TabDel))
577 : : )
578 : : {
579 : 0 : bool bExp = (bExpand && !bInDeleteUndo && IsExpand( rRef.Ref1.nRow,
580 [ - + ][ # # ]: 18 : rRef.Ref2.nRow, nRow1, nDy ));
[ # # ]
581 : : bool bDo1 = (eWhat == ScRefUpdate::ALL || (eWhat ==
582 [ - + ][ # # ]: 18 : ScRefUpdate::ABSOLUTE && !rRef.Ref1.IsRowRel()));
[ # # ]
583 : : bool bDo2 = (eWhat == ScRefUpdate::ALL || (eWhat ==
584 [ - + ][ # # ]: 18 : ScRefUpdate::ABSOLUTE && !rRef.Ref2.IsRowRel()));
[ # # ]
585 [ - + ]: 18 : if ( lcl_MoveRefPart( rRef.Ref1.nRow, bRef1RowDel, bDo1,
586 : : rRef.Ref2.nRow, bRef2RowDel, bDo2,
587 : 18 : nRow1, nRow2, nDy, MAXROW ) )
588 : : {
589 : 0 : eRet = UR_UPDATED;
590 [ # # ][ # # ]: 0 : if ( bInDeleteUndo && (bRef1RowDel || bRef2RowDel) )
[ # # ]
591 : : {
592 [ # # ][ # # ]: 0 : if ( bRef1RowDel && nRow1 <= rRef.Ref1.nRow &&
[ # # ]
593 : : rRef.Ref1.nRow <= nRow1 + nDy )
594 : 0 : rRef.Ref1.SetRowDeleted( false );
595 [ # # ][ # # ]: 0 : if ( bRef2RowDel && nRow1 <= rRef.Ref2.nRow &&
[ # # ]
596 : : rRef.Ref2.nRow <= nRow1 + nDy )
597 : 0 : rRef.Ref2.SetRowDeleted( false );
598 : : }
599 : : else
600 : : {
601 [ # # ]: 0 : if ( bRef1RowDel )
602 : 0 : rRef.Ref1.SetRowDeleted( true );
603 [ # # ]: 0 : if ( bRef2RowDel )
604 : 0 : rRef.Ref2.SetRowDeleted( true );
605 : : }
606 : : }
607 [ - + ]: 18 : if ( bExp )
608 : : {
609 : 0 : Expand( rRef.Ref1.nRow, rRef.Ref2.nRow, nRow1, nDy );
610 : 0 : eRet = UR_UPDATED;
611 : : }
612 : : }
613 [ - + ][ # # ]: 18 : if( nDz &&
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
614 : : ((rRef.Ref1.nCol >= nCol1
615 : : && rRef.Ref2.nCol <= nCol2) || (bRef1ColDel || bRef2ColDel))
616 : : &&
617 : : ((rRef.Ref1.nRow >= nRow1
618 : : && rRef.Ref2.nRow <= nRow2) || (bRef1RowDel || bRef2RowDel))
619 : : )
620 : : {
621 : 0 : bool bExp = (bExpand && !bInDeleteUndo && IsExpand( rRef.Ref1.nTab,
622 [ # # ][ # # ]: 0 : rRef.Ref2.nTab, nTab1, nDz ));
[ # # ]
623 [ # # ]: 0 : SCTAB nMaxTab = pDoc->GetTableCount() - 1;
624 : : bool bDo1 = (eWhat == ScRefUpdate::ALL || (eWhat ==
625 [ # # ][ # # ]: 0 : ScRefUpdate::ABSOLUTE && !rRef.Ref1.IsTabRel()));
[ # # ]
626 : : bool bDo2 = (eWhat == ScRefUpdate::ALL || (eWhat ==
627 [ # # ][ # # ]: 0 : ScRefUpdate::ABSOLUTE && !rRef.Ref2.IsTabRel()));
[ # # ]
628 [ # # ]: 0 : if ( lcl_MoveRefPart( rRef.Ref1.nTab, bRef1TabDel, bDo1,
629 : : rRef.Ref2.nTab, bRef2TabDel, bDo2,
630 : 0 : nTab1, nTab2, nDz, nMaxTab ) )
631 : : {
632 : 0 : eRet = UR_UPDATED;
633 [ # # ][ # # ]: 0 : if ( bInDeleteUndo && (bRef1TabDel || bRef2TabDel) )
[ # # ]
634 : : {
635 [ # # ][ # # ]: 0 : if ( bRef1TabDel && nTab1 <= rRef.Ref1.nTab &&
[ # # ]
636 : : rRef.Ref1.nTab <= nTab1 + nDz )
637 : 0 : rRef.Ref1.SetTabDeleted( false );
638 [ # # ][ # # ]: 0 : if ( bRef2TabDel && nTab1 <= rRef.Ref2.nTab &&
[ # # ]
639 : : rRef.Ref2.nTab <= nTab1 + nDz )
640 : 0 : rRef.Ref2.SetTabDeleted( false );
641 : : }
642 : : else
643 : : {
644 [ # # ]: 0 : if ( bRef1TabDel )
645 : 0 : rRef.Ref1.SetTabDeleted( true );
646 [ # # ]: 0 : if ( bRef2TabDel )
647 : 0 : rRef.Ref2.SetTabDeleted( true );
648 : : }
649 : : }
650 [ # # ]: 0 : if ( bExp )
651 : : {
652 : 0 : Expand( rRef.Ref1.nTab, rRef.Ref2.nTab, nTab1, nDz );
653 : 0 : eRet = UR_UPDATED;
654 : : }
655 : : }
656 [ + - ]: 18 : if ( eRet == UR_NOTHING )
657 : : {
658 [ + - ][ + + ]: 18 : if (oldCol1 != rRef.Ref1.nCol
[ + - ][ + - ]
[ + + ][ - + ]
659 : : || oldRow1 != rRef.Ref1.nRow
660 : : || oldTab1 != rRef.Ref1.nTab
661 : : || oldCol2 != rRef.Ref2.nCol
662 : : || oldRow2 != rRef.Ref2.nRow
663 : : || oldTab2 != rRef.Ref2.nTab
664 : : )
665 : 9 : eRet = UR_UPDATED;
666 : : }
667 [ + - ]: 18 : if (eWhat != ScRefUpdate::ABSOLUTE)
668 [ + - ]: 18 : rRef.CalcRelFromAbs( rPos );
669 : : }
670 : : else
671 : : {
672 [ - + ]: 3 : if( eMode == URM_MOVE )
673 : : {
674 [ # # ][ # # ]: 0 : if ( rRef.Ref1.nCol >= nCol1-nDx
[ # # ][ # # ]
[ # # ][ # # ]
675 : : && rRef.Ref1.nRow >= nRow1-nDy
676 : : && rRef.Ref1.nTab >= nTab1-nDz
677 : : && rRef.Ref2.nCol <= nCol2-nDx
678 : : && rRef.Ref2.nRow <= nRow2-nDy
679 : : && rRef.Ref2.nTab <= nTab2-nDz )
680 : : {
681 : 0 : eRet = Move( pDoc, rPos, nDx, nDy, nDz, rRef, false, true ); // immer verschieben
682 : : }
683 [ # # ][ # # ]: 0 : else if ( nDz && r.In( rPos ) )
[ # # ]
684 : : {
685 : 0 : rRef.Ref1.SetFlag3D( true );
686 : 0 : rRef.Ref2.SetFlag3D( true );
687 : 0 : eRet = UR_UPDATED;
688 [ # # ]: 0 : if (eWhat != ScRefUpdate::ABSOLUTE)
689 : 0 : rRef.CalcRelFromAbs( rPos );
690 : : }
691 [ # # ]: 0 : else if (eWhat != ScRefUpdate::ABSOLUTE)
692 : 0 : rRef.CalcRelFromAbs( rPos );
693 : : }
694 [ + - ][ - + ]: 3 : else if( eMode == URM_COPY && r.In( rPos ) )
[ - + ]
695 : 0 : eRet = Move( pDoc, rPos, nDx, nDy, nDz, rRef, false, false ); // nur relative
696 : : // sollte nicht mehr verwendet werden muessen
697 [ - + ]: 3 : else if (eWhat != ScRefUpdate::ABSOLUTE)
698 : 0 : rRef.CalcRelFromAbs( rPos );
699 : : }
700 : 21 : return eRet;
701 : : }
702 : :
703 : :
704 : 0 : ScRefUpdateRes ScRefUpdate::Move( ScDocument* pDoc, const ScAddress& rPos,
705 : : SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
706 : : ScComplexRefData& rRef, bool bWrap, bool bAbsolute )
707 : : {
708 : 0 : ScRefUpdateRes eRet = UR_NOTHING;
709 : :
710 : 0 : SCCOL oldCol1 = rRef.Ref1.nCol;
711 : 0 : SCROW oldRow1 = rRef.Ref1.nRow;
712 : 0 : SCTAB oldTab1 = rRef.Ref1.nTab;
713 : 0 : SCCOL oldCol2 = rRef.Ref2.nCol;
714 : 0 : SCROW oldRow2 = rRef.Ref2.nRow;
715 : 0 : SCTAB oldTab2 = rRef.Ref2.nTab;
716 : :
717 : : bool bCut1, bCut2;
718 [ # # ]: 0 : if ( nDx )
719 : : {
720 : 0 : bCut1 = bCut2 = false;
721 [ # # ][ # # ]: 0 : if( bAbsolute || rRef.Ref1.IsColRel() )
[ # # ]
722 : : {
723 [ # # ]: 0 : if( bWrap )
724 : 0 : lcl_MoveItWrap( rRef.Ref1.nCol, nDx, MAXCOL );
725 : : else
726 : 0 : bCut1 = lcl_MoveItCut( rRef.Ref1.nCol, nDx, MAXCOL );
727 : : }
728 [ # # ][ # # ]: 0 : if( bAbsolute || rRef.Ref2.IsColRel() )
[ # # ]
729 : : {
730 [ # # ]: 0 : if( bWrap )
731 : 0 : lcl_MoveItWrap( rRef.Ref2.nCol, nDx, MAXCOL );
732 : : else
733 : 0 : bCut2 = lcl_MoveItCut( rRef.Ref2.nCol, nDx, MAXCOL );
734 : : }
735 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
736 : 0 : eRet = UR_UPDATED;
737 [ # # ][ # # ]: 0 : if ( bCut1 && bCut2 )
738 : : {
739 : 0 : rRef.Ref1.SetColDeleted( true );
740 : 0 : rRef.Ref2.SetColDeleted( true );
741 : : }
742 : : }
743 [ # # ]: 0 : if ( nDy )
744 : : {
745 : 0 : bCut1 = bCut2 = false;
746 [ # # ][ # # ]: 0 : if( bAbsolute || rRef.Ref1.IsRowRel() )
[ # # ]
747 : : {
748 [ # # ]: 0 : if( bWrap )
749 : 0 : lcl_MoveItWrap( rRef.Ref1.nRow, nDy, MAXROW );
750 : : else
751 : 0 : bCut1 = lcl_MoveItCut( rRef.Ref1.nRow, nDy, MAXROW );
752 : : }
753 [ # # ][ # # ]: 0 : if( bAbsolute || rRef.Ref2.IsRowRel() )
[ # # ]
754 : : {
755 [ # # ]: 0 : if( bWrap )
756 : 0 : lcl_MoveItWrap( rRef.Ref2.nRow, nDy, MAXROW );
757 : : else
758 : 0 : bCut2 = lcl_MoveItCut( rRef.Ref2.nRow, nDy, MAXROW );
759 : : }
760 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
761 : 0 : eRet = UR_UPDATED;
762 [ # # ][ # # ]: 0 : if ( bCut1 && bCut2 )
763 : : {
764 : 0 : rRef.Ref1.SetRowDeleted( true );
765 : 0 : rRef.Ref2.SetRowDeleted( true );
766 : : }
767 : : }
768 [ # # ]: 0 : if ( nDz )
769 : : {
770 : 0 : bCut1 = bCut2 = false;
771 : 0 : SCsTAB nMaxTab = (SCsTAB) pDoc->GetTableCount() - 1;
772 [ # # ][ # # ]: 0 : if( bAbsolute || rRef.Ref1.IsTabRel() )
[ # # ]
773 : : {
774 [ # # ]: 0 : if( bWrap )
775 : 0 : lcl_MoveItWrap( rRef.Ref1.nTab, nDz, static_cast<SCTAB>(nMaxTab) );
776 : : else
777 : 0 : bCut1 = lcl_MoveItCut( rRef.Ref1.nTab, nDz, static_cast<SCTAB>(nMaxTab) );
778 : 0 : rRef.Ref1.SetFlag3D( rPos.Tab() != rRef.Ref1.nTab );
779 : : }
780 [ # # ][ # # ]: 0 : if( bAbsolute || rRef.Ref2.IsTabRel() )
[ # # ]
781 : : {
782 [ # # ]: 0 : if( bWrap )
783 : 0 : lcl_MoveItWrap( rRef.Ref2.nTab, nDz, static_cast<SCTAB>(nMaxTab) );
784 : : else
785 : 0 : bCut2 = lcl_MoveItCut( rRef.Ref2.nTab, nDz, static_cast<SCTAB>(nMaxTab) );
786 : 0 : rRef.Ref2.SetFlag3D( rPos.Tab() != rRef.Ref2.nTab );
787 : : }
788 [ # # ][ # # ]: 0 : if ( bCut1 || bCut2 )
789 : 0 : eRet = UR_UPDATED;
790 [ # # ][ # # ]: 0 : if ( bCut1 && bCut2 )
791 : : {
792 : 0 : rRef.Ref1.SetTabDeleted( true );
793 : 0 : rRef.Ref2.SetTabDeleted( true );
794 : : }
795 : : }
796 : :
797 [ # # ]: 0 : if ( eRet == UR_NOTHING )
798 : : {
799 [ # # ][ # # ]: 0 : if (oldCol1 != rRef.Ref1.nCol
[ # # ][ # # ]
[ # # ][ # # ]
800 : : || oldRow1 != rRef.Ref1.nRow
801 : : || oldTab1 != rRef.Ref1.nTab
802 : : || oldCol2 != rRef.Ref2.nCol
803 : : || oldRow2 != rRef.Ref2.nRow
804 : : || oldTab2 != rRef.Ref2.nTab
805 : : )
806 : 0 : eRet = UR_UPDATED;
807 : : }
808 [ # # ][ # # ]: 0 : if ( bWrap && eRet != UR_NOTHING )
809 : 0 : rRef.PutInOrder();
810 : 0 : rRef.CalcRelFromAbs( rPos );
811 : 0 : return eRet;
812 : : }
813 : :
814 : 233 : void ScRefUpdate::MoveRelWrap( ScDocument* pDoc, const ScAddress& rPos,
815 : : SCCOL nMaxCol, SCROW nMaxRow, ScComplexRefData& rRef )
816 : : {
817 [ + + ]: 233 : if( rRef.Ref1.IsColRel() )
818 : : {
819 : 34 : rRef.Ref1.nCol = rRef.Ref1.nRelCol + rPos.Col();
820 : 34 : lcl_MoveItWrap( rRef.Ref1.nCol, static_cast<SCsCOL>(0), nMaxCol );
821 : : }
822 [ + + ]: 233 : if( rRef.Ref2.IsColRel() )
823 : : {
824 : 34 : rRef.Ref2.nCol = rRef.Ref2.nRelCol + rPos.Col();
825 : 34 : lcl_MoveItWrap( rRef.Ref2.nCol, static_cast<SCsCOL>(0), nMaxCol );
826 : : }
827 [ + + ]: 233 : if( rRef.Ref1.IsRowRel() )
828 : : {
829 : 34 : rRef.Ref1.nRow = rRef.Ref1.nRelRow + rPos.Row();
830 : 34 : lcl_MoveItWrap( rRef.Ref1.nRow, static_cast<SCsROW>(0), nMaxRow );
831 : : }
832 [ + + ]: 233 : if( rRef.Ref2.IsRowRel() )
833 : : {
834 : 34 : rRef.Ref2.nRow = rRef.Ref2.nRelRow + rPos.Row();
835 : 34 : lcl_MoveItWrap( rRef.Ref2.nRow, static_cast<SCsROW>(0), nMaxRow );
836 : : }
837 : 233 : SCsTAB nMaxTab = (SCsTAB) pDoc->GetTableCount() - 1;
838 [ + + ]: 233 : if( rRef.Ref1.IsTabRel() )
839 : : {
840 : 36 : rRef.Ref1.nTab = rRef.Ref1.nRelTab + rPos.Tab();
841 : 36 : lcl_MoveItWrap( rRef.Ref1.nTab, static_cast<SCsTAB>(0), static_cast<SCTAB>(nMaxTab) );
842 : : }
843 [ + + ]: 233 : if( rRef.Ref2.IsTabRel() )
844 : : {
845 : 36 : rRef.Ref2.nTab = rRef.Ref2.nRelTab + rPos.Tab();
846 : 36 : lcl_MoveItWrap( rRef.Ref2.nTab, static_cast<SCsTAB>(0), static_cast<SCTAB>(nMaxTab) );
847 : : }
848 : 233 : rRef.PutInOrder();
849 : 233 : rRef.CalcRelFromAbs( rPos );
850 : 233 : }
851 : :
852 : : //------------------------------------------------------------------
853 : :
854 : 0 : void ScRefUpdate::DoTranspose( SCsCOL& rCol, SCsROW& rRow, SCsTAB& rTab,
855 : : ScDocument* pDoc, const ScRange& rSource, const ScAddress& rDest )
856 : : {
857 : 0 : SCsTAB nDz = ((SCsTAB)rDest.Tab())-(SCsTAB)rSource.aStart.Tab();
858 [ # # ]: 0 : if (nDz)
859 : : {
860 : 0 : SCsTAB nNewTab = rTab+nDz;
861 : 0 : SCsTAB nCount = pDoc->GetTableCount();
862 [ # # ]: 0 : while (nNewTab<0) nNewTab = sal::static_int_cast<SCsTAB>( nNewTab + nCount );
863 [ # # ]: 0 : while (nNewTab>=nCount) nNewTab = sal::static_int_cast<SCsTAB>( nNewTab - nCount );
864 : 0 : rTab = nNewTab;
865 : : }
866 : : OSL_ENSURE( rCol>=rSource.aStart.Col() && rRow>=rSource.aStart.Row(),
867 : : "UpdateTranspose: Pos. falsch" );
868 : :
869 : 0 : SCsCOL nRelX = rCol - (SCsCOL)rSource.aStart.Col();
870 : 0 : SCsROW nRelY = rRow - (SCsROW)rSource.aStart.Row();
871 : :
872 : 0 : rCol = static_cast<SCsCOL>(static_cast<SCsCOLROW>(rDest.Col()) +
873 : 0 : static_cast<SCsCOLROW>(nRelY));
874 : 0 : rRow = static_cast<SCsROW>(static_cast<SCsCOLROW>(rDest.Row()) +
875 : 0 : static_cast<SCsCOLROW>(nRelX));
876 : 0 : }
877 : :
878 : :
879 : 0 : ScRefUpdateRes ScRefUpdate::UpdateTranspose( ScDocument* pDoc,
880 : : const ScRange& rSource, const ScAddress& rDest,
881 : : ScComplexRefData& rRef )
882 : : {
883 : 0 : ScRefUpdateRes eRet = UR_NOTHING;
884 [ # # ][ # # : 0 : if ( rRef.Ref1.nCol >= rSource.aStart.Col() && rRef.Ref2.nCol <= rSource.aEnd.Col() &&
# # # # #
# # # ]
[ # # ]
885 : 0 : rRef.Ref1.nRow >= rSource.aStart.Row() && rRef.Ref2.nRow <= rSource.aEnd.Row() &&
886 : 0 : rRef.Ref1.nTab >= rSource.aStart.Tab() && rRef.Ref2.nTab <= rSource.aEnd.Tab() )
887 : : {
888 : 0 : DoTranspose( rRef.Ref1.nCol, rRef.Ref1.nRow, rRef.Ref1.nTab, pDoc, rSource, rDest );
889 : 0 : DoTranspose( rRef.Ref2.nCol, rRef.Ref2.nRow, rRef.Ref2.nTab, pDoc, rSource, rDest );
890 : 0 : eRet = UR_UPDATED;
891 : : }
892 : 0 : return eRet;
893 : : }
894 : :
895 : : //------------------------------------------------------------------
896 : :
897 : : // UpdateGrow - erweitert Referenzen, die genau auf den Bereich zeigen
898 : : // kommt ohne Dokument aus
899 : :
900 : :
901 : 0 : ScRefUpdateRes ScRefUpdate::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY,
902 : : ScComplexRefData& rRef )
903 : : {
904 : 0 : ScRefUpdateRes eRet = UR_NOTHING;
905 : :
906 : : // in Y-Richtung darf die Ref auch eine Zeile weiter unten anfangen,
907 : : // falls ein Bereich Spaltenkoepfe enthaelt
908 : :
909 : : bool bUpdateX = ( nGrowX &&
910 : 0 : rRef.Ref1.nCol == rArea.aStart.Col() && rRef.Ref2.nCol == rArea.aEnd.Col() &&
911 : 0 : rRef.Ref1.nRow >= rArea.aStart.Row() && rRef.Ref2.nRow <= rArea.aEnd.Row() &&
912 [ # # # # : 0 : rRef.Ref1.nTab >= rArea.aStart.Tab() && rRef.Ref2.nTab <= rArea.aEnd.Tab() );
# # # # #
# ][ # # ]
[ # # ]
913 : : bool bUpdateY = ( nGrowY &&
914 : 0 : rRef.Ref1.nCol >= rArea.aStart.Col() && rRef.Ref2.nCol <= rArea.aEnd.Col() &&
915 : 0 : ( rRef.Ref1.nRow == rArea.aStart.Row() || rRef.Ref1.nRow == rArea.aStart.Row()+1 ) &&
916 : 0 : rRef.Ref2.nRow == rArea.aEnd.Row() &&
917 [ # # # # : 0 : rRef.Ref1.nTab >= rArea.aStart.Tab() && rRef.Ref2.nTab <= rArea.aEnd.Tab() );
# # # # #
# # # ]
[ # # ][ # # ]
918 : :
919 [ # # ]: 0 : if ( bUpdateX )
920 : : {
921 : 0 : rRef.Ref2.nCol = sal::static_int_cast<SCsCOL>( rRef.Ref2.nCol + nGrowX );
922 : 0 : eRet = UR_UPDATED;
923 : : }
924 [ # # ]: 0 : if ( bUpdateY )
925 : : {
926 : 0 : rRef.Ref2.nRow = sal::static_int_cast<SCsROW>( rRef.Ref2.nRow + nGrowY );
927 : 0 : eRet = UR_UPDATED;
928 : : }
929 : :
930 : 0 : return eRet;
931 : : }
932 : :
933 : :
934 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|