1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xladdress.cxx,v $
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
)
46 mnCol
= rStrm
.ReaduInt8();
49 void XclAddress::Write( XclExpStream
& rStrm
, bool bCol16Bit
) const
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
;
70 rStrm
>> maFirst
.mnCol
>> maLast
.mnCol
;
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
;
82 rStrm
<< maFirst
.mnCol
<< maLast
.mnCol
;
84 rStrm
<< static_cast< sal_uInt8
>( maFirst
.mnCol
) << static_cast< sal_uInt8
>( maLast
.mnCol
);
87 // ----------------------------------------------------------------------------
89 XclRange
XclRangeList::GetEnclosingRange() const
94 const_iterator aIt
= begin(), aEnd
= end();
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
);
107 void XclRangeList::Read( XclImpStream
& rStrm
, bool bCol16Bit
)
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
);
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
) :
138 mnMaxCol( static_cast< sal_uInt16
>( rMaxPos
.Col() ) ),
139 mnMaxRow( static_cast< sal_uInt16
>( rMaxPos
.Row() ) ),
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() );
163 // ============================================================================