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 : #ifndef SC_XLADDRESS_HXX
21 : #define SC_XLADDRESS_HXX
22 :
23 : #include <vector>
24 : #include "address.hxx"
25 :
26 : class XclImpStream;
27 : class XclExpStream;
28 :
29 : // ============================================================================
30 :
31 : /** A 2D cell address struct with Excel column and row indexes. */
32 : struct XclAddress
33 : {
34 : sal_uInt16 mnCol;
35 : sal_uInt32 mnRow;
36 :
37 226 : inline explicit XclAddress( ScAddress::Uninitialized ) {}
38 22626 : inline explicit XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
39 544 : inline explicit XclAddress( sal_uInt16 nCol, sal_uInt32 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
40 :
41 232 : inline void Set( sal_uInt16 nCol, sal_uInt32 nRow ) { mnCol = nCol; mnRow = nRow; }
42 :
43 : void Read( XclImpStream& rStrm, bool bCol16Bit = true );
44 : void Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
45 : };
46 :
47 : inline bool operator==( const XclAddress& rL, const XclAddress& rR )
48 : {
49 : return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow);
50 : }
51 :
52 : inline bool operator<( const XclAddress& rL, const XclAddress& rR )
53 : {
54 : return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow));
55 : }
56 :
57 21340 : inline XclImpStream& operator>>( XclImpStream& rStrm, XclAddress& rXclPos )
58 : {
59 21340 : rXclPos.Read( rStrm );
60 21340 : return rStrm;
61 : }
62 :
63 0 : inline XclExpStream& operator<<( XclExpStream& rStrm, const XclAddress& rXclPos )
64 : {
65 0 : rXclPos.Write( rStrm );
66 0 : return rStrm;
67 : }
68 :
69 : // ----------------------------------------------------------------------------
70 :
71 : /** A 2D cell range address struct with Excel column and row indexes. */
72 : struct XclRange
73 : {
74 : XclAddress maFirst;
75 : XclAddress maLast;
76 :
77 92 : inline explicit XclRange( ScAddress::Uninitialized e ) : maFirst( e ), maLast( e ) {}
78 687 : inline explicit XclRange() {}
79 1 : inline explicit XclRange( const XclAddress& rPos ) : maFirst( rPos ), maLast( rPos ) {}
80 : inline explicit XclRange( const XclAddress& rFirst, const XclAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
81 1 : inline explicit XclRange( sal_uInt16 nCol1, sal_uInt32 nRow1, sal_uInt16 nCol2, sal_uInt32 nRow2 ) :
82 1 : maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {}
83 :
84 : inline void Set( const XclAddress& rFirst, const XclAddress& rLast )
85 : { maFirst = rFirst; maLast = rLast; }
86 0 : inline void Set( sal_uInt16 nCol1, sal_uInt32 nRow1, sal_uInt16 nCol2, sal_uInt32 nRow2 )
87 0 : { maFirst.Set( nCol1, nRow1 ); maLast.Set( nCol2, nRow2 ); }
88 :
89 64 : inline sal_uInt16 GetColCount() const { return maLast.mnCol - maFirst.mnCol + 1; }
90 1 : inline sal_uInt32 GetRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; }
91 : bool Contains( const XclAddress& rPos ) const;
92 :
93 : void Read( XclImpStream& rStrm, bool bCol16Bit = true );
94 : void Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
95 : };
96 :
97 : inline bool operator==( const XclRange& rL, const XclRange& rR )
98 : {
99 : return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast);
100 : }
101 :
102 : inline bool operator<( const XclRange& rL, const XclRange& rR )
103 : {
104 : return (rL.maFirst < rR.maFirst) || ((rL.maFirst == rR.maFirst) && (rL.maLast < rR.maLast));
105 : }
106 :
107 439 : inline XclImpStream& operator>>( XclImpStream& rStrm, XclRange& rXclRange )
108 : {
109 439 : rXclRange.Read( rStrm );
110 439 : return rStrm;
111 : }
112 :
113 0 : inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRange& rXclRange )
114 : {
115 0 : rXclRange.Write( rStrm );
116 0 : return rStrm;
117 : }
118 :
119 : // ----------------------------------------------------------------------------
120 :
121 : /** A 2D cell range address list with Excel column and row indexes. */
122 100 : class XclRangeList : public ::std::vector< XclRange >
123 : {
124 : public:
125 100 : inline explicit XclRangeList() {}
126 :
127 : XclRange GetEnclosingRange() const;
128 :
129 : void Read( XclImpStream& rStrm, bool bCol16Bit = true );
130 : void Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
131 : void WriteSubList( XclExpStream& rStrm,
132 : size_t nBegin, size_t nCount, bool bCol16Bit = true ) const;
133 : };
134 :
135 4 : inline XclImpStream& operator>>( XclImpStream& rStrm, XclRangeList& rXclRanges )
136 : {
137 4 : rXclRanges.Read( rStrm );
138 4 : return rStrm;
139 : }
140 :
141 0 : inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRangeList& rXclRanges )
142 : {
143 0 : rXclRanges.Write( rStrm );
144 0 : return rStrm;
145 : }
146 :
147 : // ============================================================================
148 :
149 : class XclTracer;
150 :
151 : /** Base class for import/export address converters. */
152 : class XclAddressConverterBase
153 : {
154 : public:
155 : explicit XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos );
156 : virtual ~XclAddressConverterBase();
157 :
158 : /** Returns whether the "some columns have been cut" warning box should be shown. */
159 20 : inline bool IsColTruncated() const { return mbColTrunc; }
160 : /** Returns whether the "some rows have been cut" warning box should be shown. */
161 20 : inline bool IsRowTruncated() const { return mbRowTrunc; }
162 : /** Returns whether the "some sheets have been cut" warning box should be shown. */
163 20 : inline bool IsTabTruncated() const { return mbTabTrunc; }
164 :
165 : // ------------------------------------------------------------------------
166 :
167 : /** Checks if the passed sheet index is valid.
168 : @param nScTab The sheet index to check.
169 : @param bWarn true = Sets the internal flag that produces a warning box
170 : after loading/saving the file, if the sheet index is not valid.
171 : @return true = Sheet index in nScTab is valid. */
172 : bool CheckScTab( SCTAB nScTab, bool bWarn );
173 :
174 : // ------------------------------------------------------------------------
175 : protected:
176 : XclTracer& mrTracer; /// Tracer for invalid addresses.
177 : ScAddress maMaxPos; /// Default maximum position.
178 : sal_uInt16 mnMaxCol; /// Maximum column index, as 16-bit value.
179 : sal_uInt32 mnMaxRow; /// Maximum row index.
180 : bool mbColTrunc; /// Flag for "columns truncated" warning box.
181 : bool mbRowTrunc; /// Flag for "rows truncated" warning box.
182 : bool mbTabTrunc; /// Flag for "tables truncated" warning box.
183 : };
184 :
185 : // ============================================================================
186 :
187 : #endif
188 :
189 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|