1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 #include "xladdress.hxx"
27 #include "xestream.hxx"
28 #include "xltracer.hxx"
29 #include "xistream.hxx"
30
31 // ============================================================================
32
Read(XclImpStream & rStrm,bool bCol16Bit)33 void XclAddress::Read( XclImpStream& rStrm, bool bCol16Bit )
34 {
35 rStrm >> mnRow;
36 if( bCol16Bit )
37 rStrm >> mnCol;
38 else
39 mnCol = rStrm.ReaduInt8();
40 }
41
Write(XclExpStream & rStrm,bool bCol16Bit) const42 void XclAddress::Write( XclExpStream& rStrm, bool bCol16Bit ) const
43 {
44 rStrm << mnRow;
45 if( bCol16Bit )
46 rStrm << mnCol;
47 else
48 rStrm << static_cast< sal_uInt8 >( mnCol );
49 }
50
51 // ----------------------------------------------------------------------------
52
Contains(const XclAddress & rPos) const53 bool XclRange::Contains( const XclAddress& rPos ) const
54 {
55 return (maFirst.mnCol <= rPos.mnCol) && (rPos.mnCol <= maLast.mnCol) &&
56 (maFirst.mnRow <= rPos.mnRow) && (rPos.mnRow <= maLast.mnRow);
57 }
58
Read(XclImpStream & rStrm,bool bCol16Bit)59 void XclRange::Read( XclImpStream& rStrm, bool bCol16Bit )
60 {
61 rStrm >> maFirst.mnRow >> maLast.mnRow;
62 if( bCol16Bit )
63 rStrm >> maFirst.mnCol >> maLast.mnCol;
64 else
65 {
66 maFirst.mnCol = rStrm.ReaduInt8();
67 maLast.mnCol = rStrm.ReaduInt8();
68 }
69 }
70
Write(XclExpStream & rStrm,bool bCol16Bit) const71 void XclRange::Write( XclExpStream& rStrm, bool bCol16Bit ) const
72 {
73 rStrm << maFirst.mnRow << maLast.mnRow;
74 if( bCol16Bit )
75 rStrm << maFirst.mnCol << maLast.mnCol;
76 else
77 rStrm << static_cast< sal_uInt8 >( maFirst.mnCol ) << static_cast< sal_uInt8 >( maLast.mnCol );
78 }
79
80 // ----------------------------------------------------------------------------
81
GetEnclosingRange() const82 XclRange XclRangeList::GetEnclosingRange() const
83 {
84 XclRange aXclRange;
85 if( !empty() )
86 {
87 const_iterator aIt = begin(), aEnd = end();
88 aXclRange = *aIt;
89 for( ++aIt; aIt != aEnd; ++aIt )
90 {
91 aXclRange.maFirst.mnCol = ::std::min( aXclRange.maFirst.mnCol, aIt->maFirst.mnCol );
92 aXclRange.maFirst.mnRow = ::std::min( aXclRange.maFirst.mnRow, aIt->maFirst.mnRow );
93 aXclRange.maLast.mnCol = ::std::max( aXclRange.maLast.mnCol, aIt->maLast.mnCol );
94 aXclRange.maLast.mnRow = ::std::max( aXclRange.maLast.mnRow, aIt->maLast.mnRow );
95 }
96 }
97 return aXclRange;
98 }
99
Read(XclImpStream & rStrm,bool bCol16Bit)100 void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit )
101 {
102 sal_uInt16 nCount;
103 rStrm >> nCount;
104 size_t nOldSize = size();
105 resize( nOldSize + nCount );
106 for( iterator aIt = begin() + nOldSize; rStrm.IsValid() && (nCount > 0); --nCount, ++aIt )
107 aIt->Read( rStrm, bCol16Bit );
108 }
109
Write(XclExpStream & rStrm,bool bCol16Bit) const110 void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit ) const
111 {
112 WriteSubList( rStrm, 0, size(), bCol16Bit );
113 }
114
WriteSubList(XclExpStream & rStrm,size_t nBegin,size_t nCount,bool bCol16Bit) const115 void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit ) const
116 {
117 DBG_ASSERT( nBegin <= size(), "XclRangeList::WriteSubList - invalid start position" );
118 size_t nEnd = ::std::min< size_t >( nBegin + nCount, size() );
119 sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
120 rStrm << nXclCount;
121 rStrm.SetSliceSize( bCol16Bit ? 8 : 6 );
122 for( const_iterator aIt = begin() + nBegin, aEnd = begin() + nEnd; aIt != aEnd; ++aIt )
123 aIt->Write( rStrm, bCol16Bit );
124 }
125
126 // ============================================================================
127
XclAddressConverterBase(XclTracer & rTracer,const ScAddress & rMaxPos)128 XclAddressConverterBase::XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos ) :
129 mrTracer( rTracer ),
130 maMaxPos( rMaxPos ),
131 mnMaxCol( static_cast< sal_uInt16 >( rMaxPos.Col() ) ),
132 mnMaxRow( static_cast< sal_uInt16 >( rMaxPos.Row() ) ),
133 mbColTrunc( false ),
134 mbRowTrunc( false ),
135 mbTabTrunc( false )
136 {
137 }
138
~XclAddressConverterBase()139 XclAddressConverterBase::~XclAddressConverterBase()
140 {
141 }
142
CheckScTab(SCTAB nScTab,bool bWarn)143 bool XclAddressConverterBase::CheckScTab( SCTAB nScTab, bool bWarn )
144 {
145 bool bValid = (0 <= nScTab) && (nScTab <= maMaxPos.Tab());
146 if( !bValid && bWarn )
147 {
148 mbTabTrunc |= (nScTab > maMaxPos.Tab()); // do not warn for deleted refs
149 mrTracer.TraceInvalidTab( nScTab, maMaxPos.Tab() );
150 }
151 return bValid;
152 }
153
154 // ============================================================================
155
156