1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: refdata.cxx,v $
* $Revision: 1.7.32.2 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
#include "refdata.hxx"
void SingleRefData::CalcRelFromAbs( const ScAddress& rPos )
{
nRelCol = nCol - rPos.Col();
nRelRow = nRow - rPos.Row();
nRelTab = nTab - rPos.Tab();
}
void SingleRefData::SmartRelAbs( const ScAddress& rPos )
{
if ( Flags.bColRel )
nCol = nRelCol + rPos.Col();
else
nRelCol = nCol - rPos.Col();
if ( Flags.bRowRel )
nRow = nRelRow + rPos.Row();
else
nRelRow = nRow - rPos.Row();
if ( Flags.bTabRel )
nTab = nRelTab + rPos.Tab();
else
nRelTab = nTab - rPos.Tab();
}
void SingleRefData::CalcAbsIfRel( const ScAddress& rPos )
{
if ( Flags.bColRel )
{
nCol = nRelCol + rPos.Col();
if ( !VALIDCOL( nCol ) )
Flags.bColDeleted = TRUE;
}
if ( Flags.bRowRel )
{
nRow = nRelRow + rPos.Row();
if ( !VALIDROW( nRow ) )
Flags.bRowDeleted = TRUE;
}
if ( Flags.bTabRel )
{
nTab = nRelTab + rPos.Tab();
if ( !VALIDTAB( nTab ) )
Flags.bTabDeleted = TRUE;
}
}
//UNUSED2008-05 void SingleRefData::OldBoolsToNewFlags( const OldSingleRefBools& rBools )
//UNUSED2008-05 {
//UNUSED2008-05 switch ( rBools.bRelCol )
//UNUSED2008-05 {
//UNUSED2008-05 case SR_DELETED :
//UNUSED2008-05 Flags.bColRel = TRUE; // der war verlorengegangen
//UNUSED2008-05 Flags.bColDeleted = TRUE;
//UNUSED2008-05 break;
//UNUSED2008-05 case SR_ABSOLUTE :
//UNUSED2008-05 Flags.bColRel = FALSE;
//UNUSED2008-05 Flags.bColDeleted = FALSE;
//UNUSED2008-05 break;
//UNUSED2008-05 case SR_RELABS :
//UNUSED2008-05 case SR_RELATIVE :
//UNUSED2008-05 default:
//UNUSED2008-05 Flags.bColRel = TRUE;
//UNUSED2008-05 Flags.bColDeleted = FALSE;
//UNUSED2008-05 }
//UNUSED2008-05 switch ( rBools.bRelRow )
//UNUSED2008-05 {
//UNUSED2008-05 case SR_DELETED :
//UNUSED2008-05 Flags.bRowRel = TRUE; // der war verlorengegangen
//UNUSED2008-05 Flags.bRowDeleted = TRUE;
//UNUSED2008-05 break;
//UNUSED2008-05 case SR_ABSOLUTE :
//UNUSED2008-05 Flags.bRowRel = FALSE;
//UNUSED2008-05 Flags.bRowDeleted = FALSE;
//UNUSED2008-05 break;
//UNUSED2008-05 case SR_RELABS :
//UNUSED2008-05 case SR_RELATIVE :
//UNUSED2008-05 default:
//UNUSED2008-05 Flags.bRowRel = TRUE;
//UNUSED2008-05 Flags.bRowDeleted = FALSE;
//UNUSED2008-05 }
//UNUSED2008-05 switch ( rBools.bRelTab )
//UNUSED2008-05 {
//UNUSED2008-05 case SR_DELETED :
//UNUSED2008-05 Flags.bTabRel = TRUE; // der war verlorengegangen
//UNUSED2008-05 Flags.bTabDeleted = TRUE;
//UNUSED2008-05 break;
//UNUSED2008-05 case SR_ABSOLUTE :
//UNUSED2008-05 Flags.bTabRel = FALSE;
//UNUSED2008-05 Flags.bTabDeleted = FALSE;
//UNUSED2008-05 break;
//UNUSED2008-05 case SR_RELABS :
//UNUSED2008-05 case SR_RELATIVE :
//UNUSED2008-05 default:
//UNUSED2008-05 Flags.bTabRel = TRUE;
//UNUSED2008-05 Flags.bTabDeleted = FALSE;
//UNUSED2008-05 }
//UNUSED2008-05 Flags.bFlag3D = (rBools.bOldFlag3D & SRF_3D ? TRUE : FALSE);
//UNUSED2008-05 Flags.bRelName = (rBools.bOldFlag3D & SRF_RELNAME ? TRUE : FALSE);
//UNUSED2008-05 if ( !Flags.bFlag3D )
//UNUSED2008-05 Flags.bTabRel = TRUE; // ist bei einigen aelteren Dokumenten nicht gesetzt
//UNUSED2008-05 }
//UNUSED2008-05
//UNUSED2008-05
//UNUSED2008-05 /*
//UNUSED2008-05 bis Release 3.1 sah Store so aus
//UNUSED2008-05
//UNUSED2008-05 BYTE n = ( ( r.bOldFlag3D & 0x03 ) << 6 ) // RelName, 3D
//UNUSED2008-05 | ( ( r.bRelTab & 0x03 ) << 4 ) // Relative, RelAbs
//UNUSED2008-05 | ( ( r.bRelRow & 0x03 ) << 2 )
//UNUSED2008-05 | ( r.bRelCol & 0x03 );
//UNUSED2008-05
//UNUSED2008-05 bis Release 3.1 sah Load so aus
//UNUSED2008-05
//UNUSED2008-05 r.bRelCol = ( n & 0x03 );
//UNUSED2008-05 r.bRelRow = ( ( n >> 2 ) & 0x03 );
//UNUSED2008-05 r.bRelTab = ( ( n >> 4 ) & 0x03 );
//UNUSED2008-05 r.bOldFlag3D = ( ( n >> 6 ) & 0x03 );
//UNUSED2008-05
//UNUSED2008-05 bRelCol == SR_DELETED war identisch mit bRelCol == (SR_RELATIVE | SR_RELABS)
//UNUSED2008-05 leider..
//UNUSED2008-05 3.1 liest Zukunft: Deleted wird nicht unbedingt erkannt, nur wenn auch Relativ.
//UNUSED2008-05 Aber immer noch nCol > MAXCOL und gut sollte sein..
//UNUSED2008-05 */
//UNUSED2008-05
//UNUSED2008-05 BYTE SingleRefData::CreateStoreByteFromFlags() const
//UNUSED2008-05 {
//UNUSED2008-05 return (BYTE)(
//UNUSED2008-05 ( (Flags.bRelName & 0x01) << 7 )
//UNUSED2008-05 | ( (Flags.bFlag3D & 0x01) << 6 )
//UNUSED2008-05 | ( (Flags.bTabDeleted & 0x01) << 5 )
//UNUSED2008-05 | ( (Flags.bTabRel & 0x01) << 4 )
//UNUSED2008-05 | ( (Flags.bRowDeleted & 0x01) << 3 )
//UNUSED2008-05 | ( (Flags.bRowRel & 0x01) << 2 )
//UNUSED2008-05 | ( (Flags.bColDeleted & 0x01) << 1 )
//UNUSED2008-05 | (Flags.bColRel & 0x01)
//UNUSED2008-05 );
//UNUSED2008-05 }
//UNUSED2008-05
//UNUSED2008-05
//UNUSED2008-05 void SingleRefData::CreateFlagsFromLoadByte( BYTE n )
//UNUSED2008-05 {
//UNUSED2008-05 Flags.bColRel = (n & 0x01 );
//UNUSED2008-05 Flags.bColDeleted = ( (n >> 1) & 0x01 );
//UNUSED2008-05 Flags.bRowRel = ( (n >> 2) & 0x01 );
//UNUSED2008-05 Flags.bRowDeleted = ( (n >> 3) & 0x01 );
//UNUSED2008-05 Flags.bTabRel = ( (n >> 4) & 0x01 );
//UNUSED2008-05 Flags.bTabDeleted = ( (n >> 5) & 0x01 );
//UNUSED2008-05 Flags.bFlag3D = ( (n >> 6) & 0x01 );
//UNUSED2008-05 Flags.bRelName = ( (n >> 7) & 0x01 );
//UNUSED2008-05 }
BOOL SingleRefData::operator==( const SingleRefData& r ) const
{
return bFlags == r.bFlags &&
(Flags.bColRel ? nRelCol == r.nRelCol : nCol == r.nCol) &&
(Flags.bRowRel ? nRelRow == r.nRelRow : nRow == r.nRow) &&
(Flags.bTabRel ? nRelTab == r.nRelTab : nTab == r.nTab);
}
bool SingleRefData::operator!=( const SingleRefData& r ) const
{
return !operator==(r);
}
static void lcl_putInOrder( SingleRefData & rRef1, SingleRefData & rRef2 )
{
SCCOL nCol1, nCol2;
SCROW nRow1, nRow2;
SCTAB nTab1, nTab2;
BOOL bTmp;
BYTE nRelState1, nRelState2;
if ( rRef1.Flags.bRelName )
nRelState1 =
((rRef1.Flags.bTabRel & 0x01) << 2)
| ((rRef1.Flags.bRowRel & 0x01) << 1)
| ((rRef1.Flags.bColRel & 0x01));
else
nRelState1 = 0;
if ( rRef2.Flags.bRelName )
nRelState2 =
((rRef2.Flags.bTabRel & 0x01) << 2)
| ((rRef2.Flags.bRowRel & 0x01) << 1)
| ((rRef2.Flags.bColRel & 0x01));
else
nRelState2 = 0;
if ( (nCol1 = rRef1.nCol) > (nCol2 = rRef2.nCol) )
{
rRef1.nCol = nCol2;
rRef2.nCol = nCol1;
nCol1 = rRef1.nRelCol;
rRef1.nRelCol = rRef2.nRelCol;
rRef2.nRelCol = nCol1;
if ( rRef1.Flags.bRelName && rRef1.Flags.bColRel )
nRelState2 |= 1;
else
nRelState2 &= ~1;
if ( rRef2.Flags.bRelName && rRef2.Flags.bColRel )
nRelState1 |= 1;
else
nRelState1 &= ~1;
bTmp = rRef1.Flags.bColRel;
rRef1.Flags.bColRel = rRef2.Flags.bColRel;
rRef2.Flags.bColRel = bTmp;
bTmp = rRef1.Flags.bColDeleted;
rRef1.Flags.bColDeleted = rRef2.Flags.bColDeleted;
rRef2.Flags.bColDeleted = bTmp;
}
if ( (nRow1 = rRef1.nRow) > (nRow2 = rRef2.nRow) )
{
rRef1.nRow = nRow2;
rRef2.nRow = nRow1;
nRow1 = rRef1.nRelRow;
rRef1.nRelRow = rRef2.nRelRow;
rRef2.nRelRow = nRow1;
if ( rRef1.Flags.bRelName && rRef1.Flags.bRowRel )
nRelState2 |= 2;
else
nRelState2 &= ~2;
if ( rRef2.Flags.bRelName && rRef2.Flags.bRowRel )
nRelState1 |= 2;
else
nRelState1 &= ~2;
bTmp = rRef1.Flags.bRowRel;
rRef1.Flags.bRowRel = rRef2.Flags.bRowRel;
rRef2.Flags.bRowRel = bTmp;
bTmp = rRef1.Flags.bRowDeleted;
rRef1.Flags.bRowDeleted = rRef2.Flags.bRowDeleted;
rRef2.Flags.bRowDeleted = bTmp;
}
if ( (nTab1 = rRef1.nTab) > (nTab2 = rRef2.nTab) )
{
rRef1.nTab = nTab2;
rRef2.nTab = nTab1;
nTab1 = rRef1.nRelTab;
rRef1.nRelTab = rRef2.nRelTab;
rRef2.nRelTab = nTab1;
if ( rRef1.Flags.bRelName && rRef1.Flags.bTabRel )
nRelState2 |= 4;
else
nRelState2 &= ~4;
if ( rRef2.Flags.bRelName && rRef2.Flags.bTabRel )
nRelState1 |= 4;
else
nRelState1 &= ~4;
bTmp = rRef1.Flags.bTabRel;
rRef1.Flags.bTabRel = rRef2.Flags.bTabRel;
rRef2.Flags.bTabRel = bTmp;
bTmp = rRef1.Flags.bTabDeleted;
rRef1.Flags.bTabDeleted = rRef2.Flags.bTabDeleted;
rRef2.Flags.bTabDeleted = bTmp;
}
rRef1.Flags.bRelName = ( nRelState1 ? TRUE : FALSE );
rRef2.Flags.bRelName = ( nRelState2 ? TRUE : FALSE );
}
void ComplRefData::PutInOrder()
{
lcl_putInOrder( Ref1, Ref2);
}
static void lcl_adjustInOrder( SingleRefData & rRef1, SingleRefData & rRef2, bool bFirstLeader )
{
// a1:a2:a3, bFirstLeader: rRef1==a1==r1, rRef2==a3==r2
// else: rRef1==a3==r2, rRef2==a2==r1
SingleRefData& r1 = (bFirstLeader ? rRef1 : rRef2);
SingleRefData& r2 = (bFirstLeader ? rRef2 : rRef1);
if (r1.Flags.bFlag3D && !r2.Flags.bFlag3D)
{
// [$]Sheet1.A5:A6 on Sheet2 do still refer only Sheet1.
r2.nTab = r1.nTab;
r2.nRelTab = r1.nRelTab;
r2.Flags.bTabRel = r1.Flags.bTabRel;
}
lcl_putInOrder( rRef1, rRef2);
}
ComplRefData& ComplRefData::Extend( const SingleRefData & rRef, const ScAddress & rPos )
{
CalcAbsIfRel( rPos);
SingleRefData aRef = rRef;
aRef.CalcAbsIfRel( rPos);
bool bInherit3D = Ref1.IsFlag3D() && !Ref2.IsFlag3D();
bool bInherit3Dtemp = bInherit3D && !rRef.IsFlag3D();
if (aRef.nCol < Ref1.nCol || aRef.nRow < Ref1.nRow || aRef.nTab < Ref1.nTab)
{
lcl_adjustInOrder( Ref1, aRef, true);
aRef = rRef;
aRef.CalcAbsIfRel( rPos);
}
if (aRef.nCol > Ref2.nCol || aRef.nRow > Ref2.nRow || aRef.nTab > Ref2.nTab)
{
if (bInherit3D)
Ref2.SetFlag3D( true);
lcl_adjustInOrder( aRef, Ref2, false);
if (bInherit3Dtemp)
Ref2.SetFlag3D( false);
aRef = rRef;
aRef.CalcAbsIfRel( rPos);
}
// In Ref2 use absolute/relative addressing from non-extended parts if
// equal and therefor not adjusted.
// A$5:A5 => A$5:A$5:A5 => A$5:A5, and not A$5:A$5
// A$6:$A5 => A$6:A$6:$A5 => A5:$A$6
if (Ref2.nCol == aRef.nCol)
Ref2.SetColRel( aRef.IsColRel());
if (Ref2.nRow == aRef.nRow)
Ref2.SetRowRel( aRef.IsRowRel());
// $Sheet1.$A$5:$A$6 => $Sheet1.$A$5:$A$5:$A$6 => $Sheet1.$A$5:$A$6, and
// not $Sheet1.$A$5:Sheet1.$A$6 (with invisible second 3D, but relative).
if (Ref2.nTab == aRef.nTab)
Ref2.SetTabRel( bInherit3Dtemp ? Ref1.IsTabRel() : aRef.IsTabRel());
Ref2.CalcRelFromAbs( rPos);
// Force 3D if necessary. References to other sheets always.
if (Ref1.nTab != rPos.Tab())
Ref1.SetFlag3D( true);
// In the second part only if different sheet thus not inherited.
if (Ref2.nTab != Ref1.nTab)
Ref2.SetFlag3D( true);
// Merge Flag3D to Ref2 in case there was nothing to inherit and/or range
// wasn't extended as in A5:A5:Sheet1.A5 if on Sheet1.
if (rRef.IsFlag3D())
Ref2.SetFlag3D( true);
return *this;
}
ComplRefData& ComplRefData::Extend( const ComplRefData & rRef, const ScAddress & rPos )
{
return Extend( rRef.Ref1, rPos).Extend( rRef.Ref2, rPos);
}
|