1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*38d50f7bSAndrew Rist * distributed with this work for additional information
6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at
10*38d50f7bSAndrew Rist *
11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist *
13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the
17*38d50f7bSAndrew Rist * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist * under the License.
19*38d50f7bSAndrew Rist *
20*38d50f7bSAndrew Rist *************************************************************/
21*38d50f7bSAndrew Rist
22*38d50f7bSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef SC_CONVUNO_HXX
25cdf0e10cSrcweir #define SC_CONVUNO_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir #include <i18npool/lang.h>
29cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp>
30cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
32cdf0e10cSrcweir #include "global.hxx"
33cdf0e10cSrcweir #include "address.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweir class ScUnoConversion
37cdf0e10cSrcweir {
38cdf0e10cSrcweir public:
39cdf0e10cSrcweir static LanguageType GetLanguage( const com::sun::star::lang::Locale& rLocale );
40cdf0e10cSrcweir static void FillLocale( com::sun::star::lang::Locale& rLocale, LanguageType eLang );
41cdf0e10cSrcweir
42cdf0e10cSrcweir // CellAddress -> ScAddress
43cdf0e10cSrcweir static inline void FillScAddress(
44cdf0e10cSrcweir ScAddress& rScAddress,
45cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress );
46cdf0e10cSrcweir // ScAddress -> CellAddress
47cdf0e10cSrcweir static inline void FillApiAddress(
48cdf0e10cSrcweir ::com::sun::star::table::CellAddress& rApiAddress,
49cdf0e10cSrcweir const ScAddress& rScAddress );
50cdf0e10cSrcweir // CellRangeAddress -> ScRange
51cdf0e10cSrcweir static inline void FillScRange(
52cdf0e10cSrcweir ScRange& rScRange,
53cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange );
54cdf0e10cSrcweir // ScRange -> CellRangeAddress
55cdf0e10cSrcweir static inline void FillApiRange(
56cdf0e10cSrcweir ::com::sun::star::table::CellRangeAddress& rApiRange,
57cdf0e10cSrcweir const ScRange& rScRange );
58cdf0e10cSrcweir // CellAddress -> CellRangeAddress
59cdf0e10cSrcweir static inline void FillApiRange(
60cdf0e10cSrcweir ::com::sun::star::table::CellRangeAddress& rApiRange,
61cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress );
62cdf0e10cSrcweir // CellRangeAddress-Start -> CellAddress
63cdf0e10cSrcweir static inline void FillApiStartAddress(
64cdf0e10cSrcweir ::com::sun::star::table::CellAddress& rApiAddress,
65cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange );
66cdf0e10cSrcweir // CellRangeAddress-End -> CellAddress
67cdf0e10cSrcweir static inline void FillApiEndAddress(
68cdf0e10cSrcweir ::com::sun::star::table::CellAddress& rApiAddress,
69cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange );
70cdf0e10cSrcweir
71cdf0e10cSrcweir /** Returns true, if the passed ranges have at least one common cell. */
72cdf0e10cSrcweir static inline bool Intersects(
73cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiARange1,
74cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiARange2 );
75cdf0e10cSrcweir /** Returns true, if the passed address rApiInner is inside the passed range rApiOuter. */
76cdf0e10cSrcweir static inline bool Contains(
77cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiOuter,
78cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiInner );
79cdf0e10cSrcweir /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */
80cdf0e10cSrcweir static inline bool Contains(
81cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiOuter,
82cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiInner );
83cdf0e10cSrcweir };
84cdf0e10cSrcweir
85cdf0e10cSrcweir
FillScAddress(ScAddress & rScAddress,const::com::sun::star::table::CellAddress & rApiAddress)86cdf0e10cSrcweir inline void ScUnoConversion::FillScAddress(
87cdf0e10cSrcweir ScAddress& rScAddress,
88cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir rScAddress.Set( (SCCOL)rApiAddress.Column, (SCROW)rApiAddress.Row, (SCTAB)rApiAddress.Sheet );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
FillApiAddress(::com::sun::star::table::CellAddress & rApiAddress,const ScAddress & rScAddress)93cdf0e10cSrcweir inline void ScUnoConversion::FillApiAddress(
94cdf0e10cSrcweir ::com::sun::star::table::CellAddress& rApiAddress,
95cdf0e10cSrcweir const ScAddress& rScAddress )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir rApiAddress.Column = rScAddress.Col();
98cdf0e10cSrcweir rApiAddress.Row = rScAddress.Row();
99cdf0e10cSrcweir rApiAddress.Sheet = rScAddress.Tab();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
FillScRange(ScRange & rScRange,const::com::sun::star::table::CellRangeAddress & rApiRange)102cdf0e10cSrcweir inline void ScUnoConversion::FillScRange(
103cdf0e10cSrcweir ScRange& rScRange,
104cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir rScRange.aStart.Set( (SCCOL)rApiRange.StartColumn, (SCROW)rApiRange.StartRow, (SCTAB)rApiRange.Sheet );
107cdf0e10cSrcweir rScRange.aEnd.Set( (SCCOL)rApiRange.EndColumn, (SCROW)rApiRange.EndRow, (SCTAB)rApiRange.Sheet );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
FillApiRange(::com::sun::star::table::CellRangeAddress & rApiRange,const ScRange & rScRange)110cdf0e10cSrcweir inline void ScUnoConversion::FillApiRange(
111cdf0e10cSrcweir ::com::sun::star::table::CellRangeAddress& rApiRange,
112cdf0e10cSrcweir const ScRange& rScRange )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir rApiRange.StartColumn = rScRange.aStart.Col();
115cdf0e10cSrcweir rApiRange.StartRow = rScRange.aStart.Row();
116cdf0e10cSrcweir rApiRange.Sheet = rScRange.aStart.Tab();
117cdf0e10cSrcweir rApiRange.EndColumn = rScRange.aEnd.Col();
118cdf0e10cSrcweir rApiRange.EndRow = rScRange.aEnd.Row();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
FillApiRange(::com::sun::star::table::CellRangeAddress & rApiRange,const::com::sun::star::table::CellAddress & rApiAddress)121cdf0e10cSrcweir inline void ScUnoConversion::FillApiRange(
122cdf0e10cSrcweir ::com::sun::star::table::CellRangeAddress& rApiRange,
123cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir rApiRange.StartColumn = rApiRange.EndColumn = rApiAddress.Column;
126cdf0e10cSrcweir rApiRange.StartRow = rApiRange.EndRow = rApiAddress.Row;
127cdf0e10cSrcweir rApiRange.Sheet = rApiAddress.Sheet;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
FillApiStartAddress(::com::sun::star::table::CellAddress & rApiAddress,const::com::sun::star::table::CellRangeAddress & rApiRange)130cdf0e10cSrcweir inline void ScUnoConversion::FillApiStartAddress(
131cdf0e10cSrcweir ::com::sun::star::table::CellAddress& rApiAddress,
132cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir rApiAddress.Column = rApiRange.StartColumn;
135cdf0e10cSrcweir rApiAddress.Row = rApiRange.StartRow;
136cdf0e10cSrcweir rApiAddress.Sheet = rApiRange.Sheet;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
FillApiEndAddress(::com::sun::star::table::CellAddress & rApiAddress,const::com::sun::star::table::CellRangeAddress & rApiRange)139cdf0e10cSrcweir inline void ScUnoConversion::FillApiEndAddress(
140cdf0e10cSrcweir ::com::sun::star::table::CellAddress& rApiAddress,
141cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir rApiAddress.Column = rApiRange.EndColumn;
144cdf0e10cSrcweir rApiAddress.Row = rApiRange.EndRow;
145cdf0e10cSrcweir rApiAddress.Sheet = rApiRange.Sheet;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
Intersects(const::com::sun::star::table::CellRangeAddress & rApiRange1,const::com::sun::star::table::CellRangeAddress & rApiRange2)148cdf0e10cSrcweir inline bool ScUnoConversion::Intersects(
149cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange1,
150cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir return (rApiRange1.Sheet == rApiRange2.Sheet) &&
153cdf0e10cSrcweir (::std::max( rApiRange1.StartColumn, rApiRange2.StartColumn ) <= ::std::min( rApiRange1.EndColumn, rApiRange2.EndColumn )) &&
154cdf0e10cSrcweir (::std::max( rApiRange1.StartRow, rApiRange2.StartRow ) <= ::std::min( rApiRange1.EndRow, rApiRange2.EndRow ));
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
Contains(const::com::sun::star::table::CellRangeAddress & rApiOuter,const::com::sun::star::table::CellAddress & rApiInner)157cdf0e10cSrcweir inline bool ScUnoConversion::Contains(
158cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiOuter,
159cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiInner )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir return (rApiOuter.Sheet == rApiInner.Sheet) &&
162cdf0e10cSrcweir (rApiOuter.StartColumn <= rApiInner.Column) && (rApiInner.Column <= rApiOuter.EndColumn) &&
163cdf0e10cSrcweir (rApiOuter.StartRow <= rApiInner.Row) && (rApiInner.Row <= rApiOuter.EndRow);
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
Contains(const::com::sun::star::table::CellRangeAddress & rApiOuter,const::com::sun::star::table::CellRangeAddress & rApiInner)166cdf0e10cSrcweir inline bool ScUnoConversion::Contains(
167cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiOuter,
168cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiInner )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir return (rApiOuter.Sheet == rApiInner.Sheet) &&
171cdf0e10cSrcweir (rApiOuter.StartColumn <= rApiInner.StartColumn) && (rApiInner.EndColumn <= rApiOuter.EndColumn) &&
172cdf0e10cSrcweir (rApiOuter.StartRow <= rApiInner.StartRow) && (rApiInner.EndRow <= rApiOuter.EndRow);
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
175cdf0e10cSrcweir //___________________________________________________________________
176cdf0e10cSrcweir
operator ==(const::com::sun::star::table::CellAddress & rApiAddress1,const::com::sun::star::table::CellAddress & rApiAddress2)177cdf0e10cSrcweir inline sal_Bool operator==(
178cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress1,
179cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress2 )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir return
182cdf0e10cSrcweir (rApiAddress1.Column == rApiAddress2.Column) &&
183cdf0e10cSrcweir (rApiAddress1.Row == rApiAddress2.Row) &&
184cdf0e10cSrcweir (rApiAddress1.Sheet == rApiAddress2.Sheet);
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
operator !=(const::com::sun::star::table::CellAddress & rApiAddress1,const::com::sun::star::table::CellAddress & rApiAddress2)187cdf0e10cSrcweir inline sal_Bool operator!=(
188cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress1,
189cdf0e10cSrcweir const ::com::sun::star::table::CellAddress& rApiAddress2 )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir return !(rApiAddress1 == rApiAddress2);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
operator ==(const::com::sun::star::table::CellRangeAddress & rApiRange1,const::com::sun::star::table::CellRangeAddress & rApiRange2)194cdf0e10cSrcweir inline sal_Bool operator==(
195cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange1,
196cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir return
199cdf0e10cSrcweir (rApiRange1.StartColumn == rApiRange2.StartColumn) &&
200cdf0e10cSrcweir (rApiRange1.StartRow == rApiRange2.StartRow) &&
201cdf0e10cSrcweir (rApiRange1.EndColumn == rApiRange2.EndColumn) &&
202cdf0e10cSrcweir (rApiRange1.EndRow == rApiRange2.EndRow) &&
203cdf0e10cSrcweir (rApiRange1.Sheet == rApiRange2.Sheet);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
operator !=(const::com::sun::star::table::CellRangeAddress & rApiRange1,const::com::sun::star::table::CellRangeAddress & rApiRange2)206cdf0e10cSrcweir inline sal_Bool operator!=(
207cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange1,
208cdf0e10cSrcweir const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir return !(rApiRange1 == rApiRange2);
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir #endif
214cdf0e10cSrcweir
215