xref: /aoo42x/main/sc/inc/convuno.hxx (revision 38d50f7b)
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_CONVUNO_HXX
25 #define SC_CONVUNO_HXX
26 
27 #include <algorithm>
28 #include <i18npool/lang.h>
29 #include <com/sun/star/table/CellAddress.hpp>
30 #include <com/sun/star/table/CellRangeAddress.hpp>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include "global.hxx"
33 #include "address.hxx"
34 
35 
36 class ScUnoConversion
37 {
38 public:
39 	static LanguageType GetLanguage( const com::sun::star::lang::Locale& rLocale );
40 	static void FillLocale( com::sun::star::lang::Locale& rLocale, LanguageType eLang );
41 
42 	// CellAddress -> ScAddress
43 	static inline void	FillScAddress(
44 							ScAddress& rScAddress,
45 							const ::com::sun::star::table::CellAddress& rApiAddress );
46 	// ScAddress -> CellAddress
47 	static inline void	FillApiAddress(
48 							::com::sun::star::table::CellAddress& rApiAddress,
49 							const ScAddress& rScAddress );
50 	// CellRangeAddress -> ScRange
51 	static inline void	FillScRange(
52 							ScRange& rScRange,
53 							const ::com::sun::star::table::CellRangeAddress& rApiRange );
54 	// ScRange -> CellRangeAddress
55 	static inline void	FillApiRange(
56 							::com::sun::star::table::CellRangeAddress& rApiRange,
57 							const ScRange& rScRange );
58 	// CellAddress -> CellRangeAddress
59 	static inline void	FillApiRange(
60 							::com::sun::star::table::CellRangeAddress& rApiRange,
61 							const ::com::sun::star::table::CellAddress& rApiAddress );
62 	// CellRangeAddress-Start -> CellAddress
63 	static inline void	FillApiStartAddress(
64 							::com::sun::star::table::CellAddress& rApiAddress,
65 							const ::com::sun::star::table::CellRangeAddress& rApiRange );
66 	// CellRangeAddress-End -> CellAddress
67 	static inline void	FillApiEndAddress(
68 							::com::sun::star::table::CellAddress& rApiAddress,
69 							const ::com::sun::star::table::CellRangeAddress& rApiRange );
70 
71     /** Returns true, if the passed ranges have at least one common cell. */
72     static inline bool  Intersects(
73 							const ::com::sun::star::table::CellRangeAddress& rApiARange1,
74 							const ::com::sun::star::table::CellRangeAddress& rApiARange2 );
75     /** Returns true, if the passed address rApiInner is inside the passed range rApiOuter. */
76     static inline bool  Contains(
77                             const ::com::sun::star::table::CellRangeAddress& rApiOuter,
78                             const ::com::sun::star::table::CellAddress& rApiInner );
79     /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */
80     static inline bool  Contains(
81                             const ::com::sun::star::table::CellRangeAddress& rApiOuter,
82                             const ::com::sun::star::table::CellRangeAddress& rApiInner );
83 };
84 
85 
FillScAddress(ScAddress & rScAddress,const::com::sun::star::table::CellAddress & rApiAddress)86 inline void	ScUnoConversion::FillScAddress(
87 		ScAddress& rScAddress,
88 		const ::com::sun::star::table::CellAddress& rApiAddress )
89 {
90 	rScAddress.Set( (SCCOL)rApiAddress.Column, (SCROW)rApiAddress.Row, (SCTAB)rApiAddress.Sheet );
91 }
92 
FillApiAddress(::com::sun::star::table::CellAddress & rApiAddress,const ScAddress & rScAddress)93 inline void	ScUnoConversion::FillApiAddress(
94 		::com::sun::star::table::CellAddress& rApiAddress,
95 		const ScAddress& rScAddress )
96 {
97 	rApiAddress.Column = rScAddress.Col();
98 	rApiAddress.Row = rScAddress.Row();
99 	rApiAddress.Sheet = rScAddress.Tab();
100 }
101 
FillScRange(ScRange & rScRange,const::com::sun::star::table::CellRangeAddress & rApiRange)102 inline void	ScUnoConversion::FillScRange(
103 		ScRange& rScRange,
104 		const ::com::sun::star::table::CellRangeAddress& rApiRange )
105 {
106 	rScRange.aStart.Set( (SCCOL)rApiRange.StartColumn, (SCROW)rApiRange.StartRow, (SCTAB)rApiRange.Sheet );
107 	rScRange.aEnd.Set( (SCCOL)rApiRange.EndColumn, (SCROW)rApiRange.EndRow, (SCTAB)rApiRange.Sheet );
108 }
109 
FillApiRange(::com::sun::star::table::CellRangeAddress & rApiRange,const ScRange & rScRange)110 inline void	ScUnoConversion::FillApiRange(
111 		::com::sun::star::table::CellRangeAddress& rApiRange,
112 		const ScRange& rScRange )
113 {
114 	rApiRange.StartColumn = rScRange.aStart.Col();
115 	rApiRange.StartRow = rScRange.aStart.Row();
116 	rApiRange.Sheet = rScRange.aStart.Tab();
117 	rApiRange.EndColumn = rScRange.aEnd.Col();
118 	rApiRange.EndRow = rScRange.aEnd.Row();
119 }
120 
FillApiRange(::com::sun::star::table::CellRangeAddress & rApiRange,const::com::sun::star::table::CellAddress & rApiAddress)121 inline void	ScUnoConversion::FillApiRange(
122 		::com::sun::star::table::CellRangeAddress& rApiRange,
123 		const ::com::sun::star::table::CellAddress& rApiAddress )
124 {
125 	rApiRange.StartColumn = rApiRange.EndColumn = rApiAddress.Column;
126 	rApiRange.StartRow = rApiRange.EndRow = rApiAddress.Row;
127 	rApiRange.Sheet = rApiAddress.Sheet;
128 }
129 
FillApiStartAddress(::com::sun::star::table::CellAddress & rApiAddress,const::com::sun::star::table::CellRangeAddress & rApiRange)130 inline void	ScUnoConversion::FillApiStartAddress(
131 		::com::sun::star::table::CellAddress& rApiAddress,
132 		const ::com::sun::star::table::CellRangeAddress& rApiRange )
133 {
134 	rApiAddress.Column = rApiRange.StartColumn;
135 	rApiAddress.Row = rApiRange.StartRow;
136 	rApiAddress.Sheet = rApiRange.Sheet;
137 }
138 
FillApiEndAddress(::com::sun::star::table::CellAddress & rApiAddress,const::com::sun::star::table::CellRangeAddress & rApiRange)139 inline void	ScUnoConversion::FillApiEndAddress(
140 		::com::sun::star::table::CellAddress& rApiAddress,
141 		const ::com::sun::star::table::CellRangeAddress& rApiRange )
142 {
143 	rApiAddress.Column = rApiRange.EndColumn;
144 	rApiAddress.Row = rApiRange.EndRow;
145 	rApiAddress.Sheet = rApiRange.Sheet;
146 }
147 
Intersects(const::com::sun::star::table::CellRangeAddress & rApiRange1,const::com::sun::star::table::CellRangeAddress & rApiRange2)148 inline bool ScUnoConversion::Intersects(
149         const ::com::sun::star::table::CellRangeAddress& rApiRange1,
150         const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
151 {
152     return (rApiRange1.Sheet == rApiRange2.Sheet) &&
153         (::std::max( rApiRange1.StartColumn, rApiRange2.StartColumn ) <= ::std::min( rApiRange1.EndColumn, rApiRange2.EndColumn )) &&
154         (::std::max( rApiRange1.StartRow, rApiRange2.StartRow ) <= ::std::min( rApiRange1.EndRow, rApiRange2.EndRow ));
155 }
156 
Contains(const::com::sun::star::table::CellRangeAddress & rApiOuter,const::com::sun::star::table::CellAddress & rApiInner)157 inline bool ScUnoConversion::Contains(
158         const ::com::sun::star::table::CellRangeAddress& rApiOuter,
159         const ::com::sun::star::table::CellAddress& rApiInner )
160 {
161     return (rApiOuter.Sheet == rApiInner.Sheet) &&
162         (rApiOuter.StartColumn <= rApiInner.Column) && (rApiInner.Column <= rApiOuter.EndColumn) &&
163         (rApiOuter.StartRow <= rApiInner.Row) && (rApiInner.Row <= rApiOuter.EndRow);
164 }
165 
Contains(const::com::sun::star::table::CellRangeAddress & rApiOuter,const::com::sun::star::table::CellRangeAddress & rApiInner)166 inline bool ScUnoConversion::Contains(
167         const ::com::sun::star::table::CellRangeAddress& rApiOuter,
168         const ::com::sun::star::table::CellRangeAddress& rApiInner )
169 {
170     return (rApiOuter.Sheet == rApiInner.Sheet) &&
171         (rApiOuter.StartColumn <= rApiInner.StartColumn) && (rApiInner.EndColumn <= rApiOuter.EndColumn) &&
172         (rApiOuter.StartRow <= rApiInner.StartRow) && (rApiInner.EndRow <= rApiOuter.EndRow);
173 }
174 
175 //___________________________________________________________________
176 
operator ==(const::com::sun::star::table::CellAddress & rApiAddress1,const::com::sun::star::table::CellAddress & rApiAddress2)177 inline sal_Bool operator==(
178 		const ::com::sun::star::table::CellAddress& rApiAddress1,
179 		const ::com::sun::star::table::CellAddress& rApiAddress2 )
180 {
181 	return
182 		(rApiAddress1.Column == rApiAddress2.Column) &&
183 		(rApiAddress1.Row == rApiAddress2.Row) &&
184 		(rApiAddress1.Sheet == rApiAddress2.Sheet);
185 }
186 
operator !=(const::com::sun::star::table::CellAddress & rApiAddress1,const::com::sun::star::table::CellAddress & rApiAddress2)187 inline sal_Bool operator!=(
188 		const ::com::sun::star::table::CellAddress& rApiAddress1,
189 		const ::com::sun::star::table::CellAddress& rApiAddress2 )
190 {
191 	return !(rApiAddress1 == rApiAddress2);
192 }
193 
operator ==(const::com::sun::star::table::CellRangeAddress & rApiRange1,const::com::sun::star::table::CellRangeAddress & rApiRange2)194 inline sal_Bool operator==(
195 		const ::com::sun::star::table::CellRangeAddress& rApiRange1,
196 		const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
197 {
198 	return
199 		(rApiRange1.StartColumn == rApiRange2.StartColumn) &&
200 		(rApiRange1.StartRow == rApiRange2.StartRow) &&
201 		(rApiRange1.EndColumn == rApiRange2.EndColumn) &&
202 		(rApiRange1.EndRow == rApiRange2.EndRow) &&
203 		(rApiRange1.Sheet == rApiRange2.Sheet);
204 }
205 
operator !=(const::com::sun::star::table::CellRangeAddress & rApiRange1,const::com::sun::star::table::CellRangeAddress & rApiRange2)206 inline sal_Bool operator!=(
207 		const ::com::sun::star::table::CellRangeAddress& rApiRange1,
208 		const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
209 {
210 	return !(rApiRange1 == rApiRange2);
211 }
212 
213 #endif
214 
215