Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "xladdress.hxx"
21 : #include "xestream.hxx"
22 : #include "xltracer.hxx"
23 : #include "xistream.hxx"
24 :
25 : // ============================================================================
26 :
27 42710 : void XclAddress::Read( XclImpStream& rStrm, bool bCol16Bit )
28 : {
29 42710 : mnRow = rStrm.ReaduInt16();
30 42710 : if( bCol16Bit )
31 42710 : rStrm >> mnCol;
32 : else
33 0 : mnCol = rStrm.ReaduInt8();
34 42710 : }
35 :
36 0 : void XclAddress::Write( XclExpStream& rStrm, bool bCol16Bit ) const
37 : {
38 0 : rStrm << static_cast<sal_uInt16> (mnRow);
39 0 : if( bCol16Bit )
40 0 : rStrm << mnCol;
41 : else
42 0 : rStrm << static_cast< sal_uInt8 >( mnCol );
43 0 : }
44 :
45 : // ----------------------------------------------------------------------------
46 :
47 0 : bool XclRange::Contains( const XclAddress& rPos ) const
48 : {
49 : return (maFirst.mnCol <= rPos.mnCol) && (rPos.mnCol <= maLast.mnCol) &&
50 0 : (maFirst.mnRow <= rPos.mnRow) && (rPos.mnRow <= maLast.mnRow);
51 : }
52 :
53 1074 : void XclRange::Read( XclImpStream& rStrm, bool bCol16Bit )
54 : {
55 1074 : maFirst.mnRow = rStrm.ReaduInt16();
56 1074 : maLast.mnRow = rStrm.ReaduInt16();
57 :
58 1074 : if( bCol16Bit )
59 886 : rStrm >> maFirst.mnCol >> maLast.mnCol;
60 : else
61 : {
62 188 : maFirst.mnCol = rStrm.ReaduInt8();
63 188 : maLast.mnCol = rStrm.ReaduInt8();
64 : }
65 1074 : }
66 :
67 0 : void XclRange::Write( XclExpStream& rStrm, bool bCol16Bit ) const
68 : {
69 0 : rStrm << static_cast<sal_uInt16>(maFirst.mnRow) << static_cast<sal_uInt16>(maLast.mnRow);
70 0 : if( bCol16Bit )
71 0 : rStrm << maFirst.mnCol << maLast.mnCol;
72 : else
73 0 : rStrm << static_cast< sal_uInt8 >( maFirst.mnCol ) << static_cast< sal_uInt8 >( maLast.mnCol );
74 0 : }
75 :
76 : // ----------------------------------------------------------------------------
77 :
78 0 : XclRange XclRangeList::GetEnclosingRange() const
79 : {
80 0 : XclRange aXclRange;
81 0 : if( !empty() )
82 : {
83 0 : const_iterator aIt = begin(), aEnd = end();
84 0 : aXclRange = *aIt;
85 0 : for( ++aIt; aIt != aEnd; ++aIt )
86 : {
87 0 : aXclRange.maFirst.mnCol = ::std::min( aXclRange.maFirst.mnCol, aIt->maFirst.mnCol );
88 0 : aXclRange.maFirst.mnRow = ::std::min( aXclRange.maFirst.mnRow, aIt->maFirst.mnRow );
89 0 : aXclRange.maLast.mnCol = ::std::max( aXclRange.maLast.mnCol, aIt->maLast.mnCol );
90 0 : aXclRange.maLast.mnRow = ::std::max( aXclRange.maLast.mnRow, aIt->maLast.mnRow );
91 : }
92 : }
93 0 : return aXclRange;
94 : }
95 :
96 194 : void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit )
97 : {
98 : sal_uInt16 nCount;
99 194 : rStrm >> nCount;
100 194 : size_t nOldSize = size();
101 194 : resize( nOldSize + nCount );
102 388 : for( iterator aIt = begin() + nOldSize; rStrm.IsValid() && (nCount > 0); --nCount, ++aIt )
103 194 : aIt->Read( rStrm, bCol16Bit );
104 194 : }
105 :
106 0 : void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit ) const
107 : {
108 0 : WriteSubList( rStrm, 0, size(), bCol16Bit );
109 0 : }
110 :
111 0 : void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit ) const
112 : {
113 : OSL_ENSURE( nBegin <= size(), "XclRangeList::WriteSubList - invalid start position" );
114 0 : size_t nEnd = ::std::min< size_t >( nBegin + nCount, size() );
115 0 : sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
116 0 : rStrm << nXclCount;
117 0 : rStrm.SetSliceSize( bCol16Bit ? 8 : 6 );
118 0 : for( const_iterator aIt = begin() + nBegin, aEnd = begin() + nEnd; aIt != aEnd; ++aIt )
119 0 : aIt->Write( rStrm, bCol16Bit );
120 0 : }
121 :
122 : // ============================================================================
123 :
124 46 : XclAddressConverterBase::XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos ) :
125 : mrTracer( rTracer ),
126 : maMaxPos( rMaxPos ),
127 46 : mnMaxCol( static_cast< sal_uInt16 >( rMaxPos.Col() ) ),
128 46 : mnMaxRow( static_cast< sal_uInt16 >( rMaxPos.Row() ) ),
129 : mbColTrunc( false ),
130 : mbRowTrunc( false ),
131 138 : mbTabTrunc( false )
132 : {
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" );
135 46 : }
136 :
137 46 : XclAddressConverterBase::~XclAddressConverterBase()
138 : {
139 46 : }
140 :
141 0 : bool XclAddressConverterBase::CheckScTab( SCTAB nScTab, bool bWarn )
142 : {
143 0 : bool bValid = (0 <= nScTab) && (nScTab <= maMaxPos.Tab());
144 0 : if( !bValid && bWarn )
145 : {
146 0 : mbTabTrunc |= (nScTab > maMaxPos.Tab()); // do not warn for deleted refs
147 0 : mrTracer.TraceInvalidTab( nScTab, maMaxPos.Tab() );
148 : }
149 0 : return bValid;
150 24 : }
151 :
152 : // ============================================================================
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|