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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XLADDRESS_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XLADDRESS_HXX
24 #include "address.hxx"
29 /** A 2D cell address struct with Excel column and row indexes. */
35 inline explicit XclAddress( ScAddress::Uninitialized
) {}
36 inline explicit XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
37 inline explicit XclAddress( sal_uInt16 nCol
, sal_uInt32 nRow
) : mnCol( nCol
), mnRow( nRow
) {}
39 inline void Set( sal_uInt16 nCol
, sal_uInt32 nRow
) { mnCol
= nCol
; mnRow
= nRow
; }
41 void Read( XclImpStream
& rStrm
, bool bCol16Bit
= true );
42 void Write( XclExpStream
& rStrm
, bool bCol16Bit
= true ) const;
45 inline bool operator==( const XclAddress
& rL
, const XclAddress
& rR
)
47 return (rL
.mnCol
== rR
.mnCol
) && (rL
.mnRow
== rR
.mnRow
);
50 inline bool operator<( const XclAddress
& rL
, const XclAddress
& rR
)
52 return (rL
.mnCol
< rR
.mnCol
) || ((rL
.mnCol
== rR
.mnCol
) && (rL
.mnRow
< rR
.mnRow
));
55 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclAddress
& rXclPos
)
57 rXclPos
.Read( rStrm
);
61 inline XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclAddress
& rXclPos
)
63 rXclPos
.Write( rStrm
);
67 /** A 2D cell range address struct with Excel column and row indexes. */
73 inline explicit XclRange( ScAddress::Uninitialized e
) : maFirst( e
), maLast( e
) {}
74 inline explicit XclRange() {}
75 inline explicit XclRange( const XclAddress
& rPos
) : maFirst( rPos
), maLast( rPos
) {}
76 inline explicit XclRange( const XclAddress
& rFirst
, const XclAddress
& rLast
) : maFirst( rFirst
), maLast( rLast
) {}
77 inline explicit XclRange( sal_uInt16 nCol1
, sal_uInt32 nRow1
, sal_uInt16 nCol2
, sal_uInt32 nRow2
) :
78 maFirst( nCol1
, nRow1
), maLast( nCol2
, nRow2
) {}
80 inline void Set( const XclAddress
& rFirst
, const XclAddress
& rLast
)
81 { maFirst
= rFirst
; maLast
= rLast
; }
82 inline void Set( sal_uInt16 nCol1
, sal_uInt32 nRow1
, sal_uInt16 nCol2
, sal_uInt32 nRow2
)
83 { maFirst
.Set( nCol1
, nRow1
); maLast
.Set( nCol2
, nRow2
); }
85 inline sal_uInt16
GetColCount() const { return maLast
.mnCol
- maFirst
.mnCol
+ 1; }
86 inline sal_uInt32
GetRowCount() const { return maLast
.mnRow
- maFirst
.mnRow
+ 1; }
87 bool Contains( const XclAddress
& rPos
) const;
89 void Read( XclImpStream
& rStrm
, bool bCol16Bit
= true );
90 void Write( XclExpStream
& rStrm
, bool bCol16Bit
= true ) const;
93 inline bool operator==( const XclRange
& rL
, const XclRange
& rR
)
95 return (rL
.maFirst
== rR
.maFirst
) && (rL
.maLast
== rR
.maLast
);
98 inline bool operator<( const XclRange
& rL
, const XclRange
& rR
)
100 return (rL
.maFirst
< rR
.maFirst
) || ((rL
.maFirst
== rR
.maFirst
) && (rL
.maLast
< rR
.maLast
));
103 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclRange
& rXclRange
)
105 rXclRange
.Read( rStrm
);
109 inline XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclRange
& rXclRange
)
111 rXclRange
.Write( rStrm
);
115 typedef ::std::vector
< XclRange
> XclRangeVector
;
117 /** A 2D cell range address list with Excel column and row indexes. */
121 XclRangeVector mRanges
;
124 inline explicit XclRangeList() : mRanges() {}
126 size_t size() const { return mRanges
.size(); }
127 bool empty() const { return mRanges
.empty(); }
128 XclRangeVector::const_iterator
begin() const { return mRanges
.begin(); }
129 XclRangeVector::const_iterator
end() const { return mRanges
.end(); }
130 void clear() { mRanges
.clear(); }
131 void push_back(const XclRange
&rRange
) { mRanges
.push_back(rRange
); }
133 XclRange
GetEnclosingRange() const;
135 void Read( XclImpStream
& rStrm
, bool bCol16Bit
= true, sal_uInt16 nCountInStream
= 0 );
136 void Write( XclExpStream
& rStrm
, bool bCol16Bit
= true, sal_uInt16 nCountInStream
= 0 ) const;
137 void WriteSubList( XclExpStream
& rStrm
,
138 size_t nBegin
, size_t nCount
, bool bCol16Bit
= true, sal_uInt16 nCountInStream
= 0 ) const;
141 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclRangeList
& rXclRanges
)
143 rXclRanges
.Read( rStrm
);
147 inline XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclRangeList
& rXclRanges
)
149 rXclRanges
.Write( rStrm
);
155 /** Base class for import/export address converters. */
156 class XclAddressConverterBase
159 explicit XclAddressConverterBase( XclTracer
& rTracer
, const ScAddress
& rMaxPos
);
160 virtual ~XclAddressConverterBase();
162 /** Returns whether the "some columns have been cut" warning box should be shown. */
163 inline bool IsColTruncated() const { return mbColTrunc
; }
164 /** Returns whether the "some rows have been cut" warning box should be shown. */
165 inline bool IsRowTruncated() const { return mbRowTrunc
; }
166 /** Returns whether the "some sheets have been cut" warning box should be shown. */
167 inline bool IsTabTruncated() const { return mbTabTrunc
; }
169 /** Checks if the passed sheet index is valid.
170 @param nScTab The sheet index to check.
171 @param bWarn true = Sets the internal flag that produces a warning box
172 after loading/saving the file, if the sheet index is not valid.
173 @return true = Sheet index in nScTab is valid. */
174 bool CheckScTab( SCTAB nScTab
, bool bWarn
);
177 XclTracer
& mrTracer
; /// Tracer for invalid addresses.
178 ScAddress maMaxPos
; /// Default maximum position.
179 sal_uInt16 mnMaxCol
; /// Maximum column index, as 16-bit value.
180 sal_uInt32 mnMaxRow
; /// Maximum row index.
181 bool mbColTrunc
; /// Flag for "columns truncated" warning box.
182 bool mbRowTrunc
; /// Flag for "rows truncated" warning box.
183 bool mbTabTrunc
; /// Flag for "tables truncated" warning box.
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */