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