1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "xladdress.hxx"
21 #include "xestream.hxx"
22 #include "xltracer.hxx"
23 #include "xistream.hxx"
25 // ============================================================================
27 void XclAddress::Read( XclImpStream
& rStrm
, bool bCol16Bit
)
29 mnRow
= rStrm
.ReaduInt16();
33 mnCol
= rStrm
.ReaduInt8();
36 void XclAddress::Write( XclExpStream
& rStrm
, bool bCol16Bit
) const
38 rStrm
<< static_cast<sal_uInt16
> (mnRow
);
42 rStrm
<< static_cast< sal_uInt8
>( mnCol
);
45 // ----------------------------------------------------------------------------
47 bool XclRange::Contains( const XclAddress
& rPos
) const
49 return (maFirst
.mnCol
<= rPos
.mnCol
) && (rPos
.mnCol
<= maLast
.mnCol
) &&
50 (maFirst
.mnRow
<= rPos
.mnRow
) && (rPos
.mnRow
<= maLast
.mnRow
);
53 void XclRange::Read( XclImpStream
& rStrm
, bool bCol16Bit
)
55 maFirst
.mnRow
= rStrm
.ReaduInt16();
56 maLast
.mnRow
= rStrm
.ReaduInt16();
59 rStrm
>> maFirst
.mnCol
>> maLast
.mnCol
;
62 maFirst
.mnCol
= rStrm
.ReaduInt8();
63 maLast
.mnCol
= rStrm
.ReaduInt8();
67 void XclRange::Write( XclExpStream
& rStrm
, bool bCol16Bit
) const
69 rStrm
<< static_cast<sal_uInt16
>(maFirst
.mnRow
) << static_cast<sal_uInt16
>(maLast
.mnRow
);
71 rStrm
<< maFirst
.mnCol
<< maLast
.mnCol
;
73 rStrm
<< static_cast< sal_uInt8
>( maFirst
.mnCol
) << static_cast< sal_uInt8
>( maLast
.mnCol
);
76 // ----------------------------------------------------------------------------
78 XclRange
XclRangeList::GetEnclosingRange() const
83 const_iterator aIt
= begin(), aEnd
= end();
85 for( ++aIt
; aIt
!= aEnd
; ++aIt
)
87 aXclRange
.maFirst
.mnCol
= ::std::min( aXclRange
.maFirst
.mnCol
, aIt
->maFirst
.mnCol
);
88 aXclRange
.maFirst
.mnRow
= ::std::min( aXclRange
.maFirst
.mnRow
, aIt
->maFirst
.mnRow
);
89 aXclRange
.maLast
.mnCol
= ::std::max( aXclRange
.maLast
.mnCol
, aIt
->maLast
.mnCol
);
90 aXclRange
.maLast
.mnRow
= ::std::max( aXclRange
.maLast
.mnRow
, aIt
->maLast
.mnRow
);
96 void XclRangeList::Read( XclImpStream
& rStrm
, bool bCol16Bit
)
100 size_t nOldSize
= size();
101 resize( nOldSize
+ nCount
);
102 for( iterator aIt
= begin() + nOldSize
; rStrm
.IsValid() && (nCount
> 0); --nCount
, ++aIt
)
103 aIt
->Read( rStrm
, bCol16Bit
);
106 void XclRangeList::Write( XclExpStream
& rStrm
, bool bCol16Bit
) const
108 WriteSubList( rStrm
, 0, size(), bCol16Bit
);
111 void XclRangeList::WriteSubList( XclExpStream
& rStrm
, size_t nBegin
, size_t nCount
, bool bCol16Bit
) const
113 OSL_ENSURE( nBegin
<= size(), "XclRangeList::WriteSubList - invalid start position" );
114 size_t nEnd
= ::std::min
< size_t >( nBegin
+ nCount
, size() );
115 sal_uInt16 nXclCount
= ulimit_cast
< sal_uInt16
>( nEnd
- nBegin
);
117 rStrm
.SetSliceSize( bCol16Bit
? 8 : 6 );
118 for( const_iterator aIt
= begin() + nBegin
, aEnd
= begin() + nEnd
; aIt
!= aEnd
; ++aIt
)
119 aIt
->Write( rStrm
, bCol16Bit
);
122 // ============================================================================
124 XclAddressConverterBase::XclAddressConverterBase( XclTracer
& rTracer
, const ScAddress
& rMaxPos
) :
127 mnMaxCol( static_cast< sal_uInt16
>( rMaxPos
.Col() ) ),
128 mnMaxRow( static_cast< sal_uInt16
>( rMaxPos
.Row() ) ),
133 OSL_ENSURE( static_cast< size_t >( rMaxPos
.Col() ) <= SAL_MAX_UINT16
, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
134 OSL_ENSURE( static_cast< size_t >( rMaxPos
.Row() ) <= SAL_MAX_UINT32
, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
137 XclAddressConverterBase::~XclAddressConverterBase()
141 bool XclAddressConverterBase::CheckScTab( SCTAB nScTab
, bool bWarn
)
143 bool bValid
= (0 <= nScTab
) && (nScTab
<= maMaxPos
.Tab());
144 if( !bValid
&& bWarn
)
146 mbTabTrunc
|= (nScTab
> maMaxPos
.Tab()); // do not warn for deleted refs
147 mrTracer
.TraceInvalidTab( nScTab
, maMaxPos
.Tab() );
152 // ============================================================================
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */