merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / inc / xladdress.hxx
blobc4aff693a96456bc82c2550a06245b0c4e4bdd5a
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.hxx,v $
10 * $Revision: 1.6 $
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 #ifndef SC_XLADDRESS_HXX
32 #define SC_XLADDRESS_HXX
34 #include <vector>
35 #include "address.hxx"
37 class ScRangeList;
38 class XclImpStream;
39 class XclExpStream;
41 // ============================================================================
43 /** A 2D cell address struct with Excel column and row indexes. */
44 struct XclAddress
46 sal_uInt16 mnCol;
47 sal_uInt16 mnRow;
49 inline explicit XclAddress( ScAddress::Uninitialized ) {}
50 inline explicit XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
51 inline explicit XclAddress( sal_uInt16 nCol, sal_uInt16 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
53 inline void Set( sal_uInt16 nCol, sal_uInt16 nRow ) { mnCol = nCol; mnRow = nRow; }
55 void Read( XclImpStream& rStrm, bool bCol16Bit = true );
56 void Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
59 inline bool operator==( const XclAddress& rL, const XclAddress& rR )
61 return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow);
64 inline bool operator<( const XclAddress& rL, const XclAddress& rR )
66 return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow));
69 inline XclImpStream& operator>>( XclImpStream& rStrm, XclAddress& rXclPos )
71 rXclPos.Read( rStrm );
72 return rStrm;
75 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclAddress& rXclPos )
77 rXclPos.Write( rStrm );
78 return rStrm;
81 // ----------------------------------------------------------------------------
83 /** A 2D cell range address struct with Excel column and row indexes. */
84 struct XclRange
86 XclAddress maFirst;
87 XclAddress maLast;
89 inline explicit XclRange( ScAddress::Uninitialized e ) : maFirst( e ), maLast( e ) {}
90 inline explicit XclRange() {}
91 inline explicit XclRange( const XclAddress& rPos ) : maFirst( rPos ), maLast( rPos ) {}
92 inline explicit XclRange( const XclAddress& rFirst, const XclAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
93 inline explicit XclRange( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 ) :
94 maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {}
96 inline void Set( const XclAddress& rFirst, const XclAddress& rLast )
97 { maFirst = rFirst; maLast = rLast; }
98 inline void Set( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 )
99 { maFirst.Set( nCol1, nRow1 ); maLast.Set( nCol2, nRow2 ); }
101 inline sal_uInt16 GetColCount() const { return maLast.mnCol - maFirst.mnCol + 1; }
102 inline sal_uInt16 GetRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; }
103 bool Contains( const XclAddress& rPos ) const;
105 void Read( XclImpStream& rStrm, bool bCol16Bit = true );
106 void Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
109 inline bool operator==( const XclRange& rL, const XclRange& rR )
111 return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast);
114 inline bool operator<( const XclRange& rL, const XclRange& rR )
116 return (rL.maFirst < rR.maFirst) || ((rL.maFirst == rR.maFirst) && (rL.maLast < rR.maLast));
119 inline XclImpStream& operator>>( XclImpStream& rStrm, XclRange& rXclRange )
121 rXclRange.Read( rStrm );
122 return rStrm;
125 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRange& rXclRange )
127 rXclRange.Write( rStrm );
128 return rStrm;
131 // ----------------------------------------------------------------------------
133 /** A 2D cell range address list with Excel column and row indexes. */
134 class XclRangeList : public ::std::vector< XclRange >
136 public:
137 inline explicit XclRangeList() {}
139 XclRange GetEnclosingRange() const;
141 void Read( XclImpStream& rStrm, bool bCol16Bit = true );
142 void Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
143 void WriteSubList( XclExpStream& rStrm,
144 size_t nBegin, size_t nCount, bool bCol16Bit = true ) const;
147 inline XclImpStream& operator>>( XclImpStream& rStrm, XclRangeList& rXclRanges )
149 rXclRanges.Read( rStrm );
150 return rStrm;
153 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRangeList& rXclRanges )
155 rXclRanges.Write( rStrm );
156 return rStrm;
159 // ============================================================================
161 class XclTracer;
163 /** Base class for import/export address converters. */
164 class XclAddressConverterBase
166 public:
167 explicit XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos );
168 virtual ~XclAddressConverterBase();
170 /** Returns whether the "some columns have been cut" warning box should be shown. */
171 inline bool IsColTruncated() const { return mbColTrunc; }
172 /** Returns whether the "some rows have been cut" warning box should be shown. */
173 inline bool IsRowTruncated() const { return mbRowTrunc; }
174 /** Returns whether the "some sheets have been cut" warning box should be shown. */
175 inline bool IsTabTruncated() const { return mbTabTrunc; }
177 // ------------------------------------------------------------------------
179 /** Checks if the passed sheet index is valid.
180 @param nScTab The sheet index to check.
181 @param bWarn true = Sets the internal flag that produces a warning box
182 after loading/saving the file, if the sheet index is not valid.
183 @return true = Sheet index in nScTab is valid. */
184 bool CheckScTab( SCTAB nScTab, bool bWarn );
186 // ------------------------------------------------------------------------
187 protected:
188 XclTracer& mrTracer; /// Tracer for invalid addresses.
189 ScAddress maMaxPos; /// Default maximum position.
190 sal_uInt16 mnMaxCol; /// Maximum column index, as 16-bit value.
191 sal_uInt16 mnMaxRow; /// Maximum row index, as 16-bit value.
192 bool mbColTrunc; /// Flag for "columns truncated" warning box.
193 bool mbRowTrunc; /// Flag for "rows truncated" warning box.
194 bool mbTabTrunc; /// Flag for "tables truncated" warning box.
197 // ============================================================================
199 #endif