xref: /aoo4110/main/sc/source/filter/inc/xladdress.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_XLADDRESS_HXX
25 #define SC_XLADDRESS_HXX
26 
27 #include <vector>
28 #include "address.hxx"
29 
30 class ScRangeList;
31 class XclImpStream;
32 class XclExpStream;
33 
34 // ============================================================================
35 
36 /** A 2D cell address struct with Excel column and row indexes. */
37 struct XclAddress
38 {
39     sal_uInt16          mnCol;
40     sal_uInt16          mnRow;
41 
XclAddressXclAddress42     inline explicit     XclAddress( ScAddress::Uninitialized ) {}
XclAddressXclAddress43     inline explicit     XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
XclAddressXclAddress44     inline explicit     XclAddress( sal_uInt16 nCol, sal_uInt16 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
45 
SetXclAddress46     inline void         Set( sal_uInt16 nCol, sal_uInt16 nRow ) { mnCol = nCol; mnRow = nRow; }
47 
48     void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
49     void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
50 };
51 
operator ==(const XclAddress & rL,const XclAddress & rR)52 inline bool operator==( const XclAddress& rL, const XclAddress& rR )
53 {
54     return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow);
55 }
56 
operator <(const XclAddress & rL,const XclAddress & rR)57 inline bool operator<( const XclAddress& rL, const XclAddress& rR )
58 {
59     return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow));
60 }
61 
operator >>(XclImpStream & rStrm,XclAddress & rXclPos)62 inline XclImpStream& operator>>( XclImpStream& rStrm, XclAddress& rXclPos )
63 {
64     rXclPos.Read( rStrm );
65     return rStrm;
66 }
67 
operator <<(XclExpStream & rStrm,const XclAddress & rXclPos)68 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclAddress& rXclPos )
69 {
70     rXclPos.Write( rStrm );
71     return rStrm;
72 }
73 
74 // ----------------------------------------------------------------------------
75 
76 /** A 2D cell range address struct with Excel column and row indexes. */
77 struct XclRange
78 {
79     XclAddress          maFirst;
80     XclAddress          maLast;
81 
XclRangeXclRange82     inline explicit     XclRange( ScAddress::Uninitialized e ) : maFirst( e ), maLast( e ) {}
XclRangeXclRange83     inline explicit     XclRange() {}
XclRangeXclRange84     inline explicit     XclRange( const XclAddress& rPos ) : maFirst( rPos ), maLast( rPos ) {}
XclRangeXclRange85     inline explicit     XclRange( const XclAddress& rFirst, const XclAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
XclRangeXclRange86     inline explicit     XclRange( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 ) :
87                             maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {}
88 
SetXclRange89     inline void         Set( const XclAddress& rFirst, const XclAddress& rLast )
90                             { maFirst = rFirst; maLast = rLast; }
SetXclRange91     inline void         Set( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 )
92                             { maFirst.Set( nCol1, nRow1 ); maLast.Set( nCol2, nRow2 ); }
93 
GetColCountXclRange94     inline sal_uInt16   GetColCount() const { return maLast.mnCol - maFirst.mnCol + 1; }
GetRowCountXclRange95     inline sal_uInt16   GetRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; }
96     bool                Contains( const XclAddress& rPos ) const;
97 
98     void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
99     void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
100 };
101 
operator ==(const XclRange & rL,const XclRange & rR)102 inline bool operator==( const XclRange& rL, const XclRange& rR )
103 {
104     return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast);
105 }
106 
operator <(const XclRange & rL,const XclRange & rR)107 inline bool operator<( const XclRange& rL, const XclRange& rR )
108 {
109     return (rL.maFirst < rR.maFirst) || ((rL.maFirst == rR.maFirst) && (rL.maLast < rR.maLast));
110 }
111 
operator >>(XclImpStream & rStrm,XclRange & rXclRange)112 inline XclImpStream& operator>>( XclImpStream& rStrm, XclRange& rXclRange )
113 {
114     rXclRange.Read( rStrm );
115     return rStrm;
116 }
117 
operator <<(XclExpStream & rStrm,const XclRange & rXclRange)118 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRange& rXclRange )
119 {
120     rXclRange.Write( rStrm );
121     return rStrm;
122 }
123 
124 // ----------------------------------------------------------------------------
125 
126 /** A 2D cell range address list with Excel column and row indexes. */
127 class XclRangeList : public ::std::vector< XclRange >
128 {
129 public:
XclRangeList()130     inline explicit     XclRangeList() {}
131 
132     XclRange            GetEnclosingRange() const;
133 
134     void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
135     void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
136     void                WriteSubList( XclExpStream& rStrm,
137                             size_t nBegin, size_t nCount, bool bCol16Bit = true ) const;
138 };
139 
operator >>(XclImpStream & rStrm,XclRangeList & rXclRanges)140 inline XclImpStream& operator>>( XclImpStream& rStrm, XclRangeList& rXclRanges )
141 {
142     rXclRanges.Read( rStrm );
143     return rStrm;
144 }
145 
operator <<(XclExpStream & rStrm,const XclRangeList & rXclRanges)146 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRangeList& rXclRanges )
147 {
148     rXclRanges.Write( rStrm );
149     return rStrm;
150 }
151 
152 // ============================================================================
153 
154 class XclTracer;
155 
156 /** Base class for import/export address converters. */
157 class XclAddressConverterBase
158 {
159 public:
160     explicit            XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos );
161     virtual             ~XclAddressConverterBase();
162 
163     /** Returns whether the "some columns have been cut" warning box should be shown. */
IsColTruncated() const164     inline bool         IsColTruncated() const { return mbColTrunc; }
165     /** Returns whether the "some rows have been cut" warning box should be shown. */
IsRowTruncated() const166     inline bool         IsRowTruncated() const { return mbRowTrunc; }
167     /** Returns whether the "some sheets have been cut" warning box should be shown. */
IsTabTruncated() const168     inline bool         IsTabTruncated() const { return mbTabTrunc; }
169 
170     // ------------------------------------------------------------------------
171 
172     /** Checks if the passed sheet index is valid.
173         @param nScTab  The sheet index to check.
174         @param bWarn  true = Sets the internal flag that produces a warning box
175             after loading/saving the file, if the sheet index is not valid.
176         @return  true = Sheet index in nScTab is valid. */
177     bool                CheckScTab( SCTAB nScTab, bool bWarn );
178 
179     // ------------------------------------------------------------------------
180 protected:
181     XclTracer&          mrTracer;       /// Tracer for invalid addresses.
182     ScAddress           maMaxPos;       /// Default maximum position.
183     sal_uInt16          mnMaxCol;       /// Maximum column index, as 16-bit value.
184     sal_uInt16          mnMaxRow;       /// Maximum row index, as 16-bit value.
185     bool                mbColTrunc;     /// Flag for "columns truncated" warning box.
186     bool                mbRowTrunc;     /// Flag for "rows truncated" warning box.
187     bool                mbTabTrunc;     /// Flag for "tables truncated" warning box.
188 };
189 
190 // ============================================================================
191 
192 #endif
193 
194