1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SC_XLADDRESS_HXX
29 #define SC_XLADDRESS_HXX
32 #include "address.hxx"
38 // ============================================================================
40 /** A 2D cell address struct with Excel column and row indexes. */
46 inline explicit XclAddress( ScAddress::Uninitialized
) {}
47 inline explicit XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
48 inline explicit XclAddress( sal_uInt16 nCol
, sal_uInt16 nRow
) : mnCol( nCol
), mnRow( nRow
) {}
50 inline void Set( sal_uInt16 nCol
, sal_uInt16 nRow
) { mnCol
= nCol
; mnRow
= nRow
; }
52 void Read( XclImpStream
& rStrm
, bool bCol16Bit
= true );
53 void Write( XclExpStream
& rStrm
, bool bCol16Bit
= true ) const;
56 inline bool operator==( const XclAddress
& rL
, const XclAddress
& rR
)
58 return (rL
.mnCol
== rR
.mnCol
) && (rL
.mnRow
== rR
.mnRow
);
61 inline bool operator<( const XclAddress
& rL
, const XclAddress
& rR
)
63 return (rL
.mnCol
< rR
.mnCol
) || ((rL
.mnCol
== rR
.mnCol
) && (rL
.mnRow
< rR
.mnRow
));
66 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclAddress
& rXclPos
)
68 rXclPos
.Read( rStrm
);
72 inline XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclAddress
& rXclPos
)
74 rXclPos
.Write( rStrm
);
78 // ----------------------------------------------------------------------------
80 /** A 2D cell range address struct with Excel column and row indexes. */
86 inline explicit XclRange( ScAddress::Uninitialized e
) : maFirst( e
), maLast( e
) {}
87 inline explicit XclRange() {}
88 inline explicit XclRange( const XclAddress
& rPos
) : maFirst( rPos
), maLast( rPos
) {}
89 inline explicit XclRange( const XclAddress
& rFirst
, const XclAddress
& rLast
) : maFirst( rFirst
), maLast( rLast
) {}
90 inline explicit XclRange( sal_uInt16 nCol1
, sal_uInt16 nRow1
, sal_uInt16 nCol2
, sal_uInt16 nRow2
) :
91 maFirst( nCol1
, nRow1
), maLast( nCol2
, nRow2
) {}
93 inline void Set( const XclAddress
& rFirst
, const XclAddress
& rLast
)
94 { maFirst
= rFirst
; maLast
= rLast
; }
95 inline void Set( sal_uInt16 nCol1
, sal_uInt16 nRow1
, sal_uInt16 nCol2
, sal_uInt16 nRow2
)
96 { maFirst
.Set( nCol1
, nRow1
); maLast
.Set( nCol2
, nRow2
); }
98 inline sal_uInt16
GetColCount() const { return maLast
.mnCol
- maFirst
.mnCol
+ 1; }
99 inline sal_uInt16
GetRowCount() const { return maLast
.mnRow
- maFirst
.mnRow
+ 1; }
100 bool Contains( const XclAddress
& rPos
) const;
102 void Read( XclImpStream
& rStrm
, bool bCol16Bit
= true );
103 void Write( XclExpStream
& rStrm
, bool bCol16Bit
= true ) const;
106 inline bool operator==( const XclRange
& rL
, const XclRange
& rR
)
108 return (rL
.maFirst
== rR
.maFirst
) && (rL
.maLast
== rR
.maLast
);
111 inline bool operator<( const XclRange
& rL
, const XclRange
& rR
)
113 return (rL
.maFirst
< rR
.maFirst
) || ((rL
.maFirst
== rR
.maFirst
) && (rL
.maLast
< rR
.maLast
));
116 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclRange
& rXclRange
)
118 rXclRange
.Read( rStrm
);
122 inline XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclRange
& rXclRange
)
124 rXclRange
.Write( rStrm
);
128 // ----------------------------------------------------------------------------
130 /** A 2D cell range address list with Excel column and row indexes. */
131 class XclRangeList
: public ::std::vector
< XclRange
>
134 inline explicit XclRangeList() {}
136 XclRange
GetEnclosingRange() const;
138 void Read( XclImpStream
& rStrm
, bool bCol16Bit
= true );
139 void Write( XclExpStream
& rStrm
, bool bCol16Bit
= true ) const;
140 void WriteSubList( XclExpStream
& rStrm
,
141 size_t nBegin
, size_t nCount
, bool bCol16Bit
= true ) const;
144 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclRangeList
& rXclRanges
)
146 rXclRanges
.Read( rStrm
);
150 inline XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclRangeList
& rXclRanges
)
152 rXclRanges
.Write( rStrm
);
156 // ============================================================================
160 /** Base class for import/export address converters. */
161 class XclAddressConverterBase
164 explicit XclAddressConverterBase( XclTracer
& rTracer
, const ScAddress
& rMaxPos
);
165 virtual ~XclAddressConverterBase();
167 /** Returns whether the "some columns have been cut" warning box should be shown. */
168 inline bool IsColTruncated() const { return mbColTrunc
; }
169 /** Returns whether the "some rows have been cut" warning box should be shown. */
170 inline bool IsRowTruncated() const { return mbRowTrunc
; }
171 /** Returns whether the "some sheets have been cut" warning box should be shown. */
172 inline bool IsTabTruncated() const { return mbTabTrunc
; }
174 // ------------------------------------------------------------------------
176 /** Checks if the passed sheet index is valid.
177 @param nScTab The sheet index to check.
178 @param bWarn true = Sets the internal flag that produces a warning box
179 after loading/saving the file, if the sheet index is not valid.
180 @return true = Sheet index in nScTab is valid. */
181 bool CheckScTab( SCTAB nScTab
, bool bWarn
);
183 // ------------------------------------------------------------------------
185 XclTracer
& mrTracer
; /// Tracer for invalid addresses.
186 ScAddress maMaxPos
; /// Default maximum position.
187 sal_uInt16 mnMaxCol
; /// Maximum column index, as 16-bit value.
188 sal_uInt16 mnMaxRow
; /// Maximum row index, as 16-bit value.
189 bool mbColTrunc
; /// Flag for "columns truncated" warning box.
190 bool mbRowTrunc
; /// Flag for "rows truncated" warning box.
191 bool mbTabTrunc
; /// Flag for "tables truncated" warning box.
194 // ============================================================================