Update ooo320-m1
[ooovba.git] / sc / source / filter / excel / xladdress.cxx
blob290a7dc5227767311463cb460aa750d67e41f827
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xladdress.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "xladdress.hxx"
34 #include "xestream.hxx"
35 #include "xltracer.hxx"
36 #include "xistream.hxx"
38 // ============================================================================
40 void XclAddress::Read( XclImpStream& rStrm, bool bCol16Bit )
42 rStrm >> mnRow;
43 if( bCol16Bit )
44 rStrm >> mnCol;
45 else
46 mnCol = rStrm.ReaduInt8();
49 void XclAddress::Write( XclExpStream& rStrm, bool bCol16Bit ) const
51 rStrm << mnRow;
52 if( bCol16Bit )
53 rStrm << mnCol;
54 else
55 rStrm << static_cast< sal_uInt8 >( mnCol );
58 // ----------------------------------------------------------------------------
60 bool XclRange::Contains( const XclAddress& rPos ) const
62 return (maFirst.mnCol <= rPos.mnCol) && (rPos.mnCol <= maLast.mnCol) &&
63 (maFirst.mnRow <= rPos.mnRow) && (rPos.mnRow <= maLast.mnRow);
66 void XclRange::Read( XclImpStream& rStrm, bool bCol16Bit )
68 rStrm >> maFirst.mnRow >> maLast.mnRow;
69 if( bCol16Bit )
70 rStrm >> maFirst.mnCol >> maLast.mnCol;
71 else
73 maFirst.mnCol = rStrm.ReaduInt8();
74 maLast.mnCol = rStrm.ReaduInt8();
78 void XclRange::Write( XclExpStream& rStrm, bool bCol16Bit ) const
80 rStrm << maFirst.mnRow << maLast.mnRow;
81 if( bCol16Bit )
82 rStrm << maFirst.mnCol << maLast.mnCol;
83 else
84 rStrm << static_cast< sal_uInt8 >( maFirst.mnCol ) << static_cast< sal_uInt8 >( maLast.mnCol );
87 // ----------------------------------------------------------------------------
89 XclRange XclRangeList::GetEnclosingRange() const
91 XclRange aXclRange;
92 if( !empty() )
94 const_iterator aIt = begin(), aEnd = end();
95 aXclRange = *aIt;
96 for( ++aIt; aIt != aEnd; ++aIt )
98 aXclRange.maFirst.mnCol = ::std::min( aXclRange.maFirst.mnCol, aIt->maFirst.mnCol );
99 aXclRange.maFirst.mnRow = ::std::min( aXclRange.maFirst.mnRow, aIt->maFirst.mnRow );
100 aXclRange.maLast.mnCol = ::std::max( aXclRange.maLast.mnCol, aIt->maLast.mnCol );
101 aXclRange.maLast.mnRow = ::std::max( aXclRange.maLast.mnRow, aIt->maLast.mnRow );
104 return aXclRange;
107 void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit )
109 sal_uInt16 nCount;
110 rStrm >> nCount;
111 size_t nOldSize = size();
112 resize( nOldSize + nCount );
113 for( iterator aIt = begin() + nOldSize; rStrm.IsValid() && (nCount > 0); --nCount, ++aIt )
114 aIt->Read( rStrm, bCol16Bit );
117 void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit ) const
119 WriteSubList( rStrm, 0, size(), bCol16Bit );
122 void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit ) const
124 DBG_ASSERT( nBegin <= size(), "XclRangeList::WriteSubList - invalid start position" );
125 size_t nEnd = ::std::min< size_t >( nBegin + nCount, size() );
126 sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
127 rStrm << nXclCount;
128 rStrm.SetSliceSize( bCol16Bit ? 8 : 6 );
129 for( const_iterator aIt = begin() + nBegin, aEnd = begin() + nEnd; aIt != aEnd; ++aIt )
130 aIt->Write( rStrm, bCol16Bit );
133 // ============================================================================
135 XclAddressConverterBase::XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos ) :
136 mrTracer( rTracer ),
137 maMaxPos( rMaxPos ),
138 mnMaxCol( static_cast< sal_uInt16 >( rMaxPos.Col() ) ),
139 mnMaxRow( static_cast< sal_uInt16 >( rMaxPos.Row() ) ),
140 mbColTrunc( false ),
141 mbRowTrunc( false ),
142 mbTabTrunc( false )
144 DBG_ASSERT( static_cast< size_t >( rMaxPos.Col() ) <= SAL_MAX_UINT16, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
145 DBG_ASSERT( static_cast< size_t >( rMaxPos.Row() ) <= SAL_MAX_UINT16, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
148 XclAddressConverterBase::~XclAddressConverterBase()
152 bool XclAddressConverterBase::CheckScTab( SCTAB nScTab, bool bWarn )
154 bool bValid = (0 <= nScTab) && (nScTab <= maMaxPos.Tab());
155 if( !bValid && bWarn )
157 mbTabTrunc |= (nScTab > maMaxPos.Tab()); // do not warn for deleted refs
158 mrTracer.TraceInvalidTab( nScTab, maMaxPos.Tab() );
160 return bValid;
163 // ============================================================================