1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_CONVUNO_HXX
21 #define SC_CONVUNO_HXX
24 #include <i18npool/lang.h>
25 #include <com/sun/star/table/CellAddress.hpp>
26 #include <com/sun/star/table/CellRangeAddress.hpp>
27 #include <com/sun/star/lang/Locale.hpp>
29 #include "address.hxx"
35 static LanguageType
GetLanguage( const com::sun::star::lang::Locale
& rLocale
);
36 static void FillLocale( com::sun::star::lang::Locale
& rLocale
, LanguageType eLang
);
38 // CellAddress -> ScAddress
39 static inline void FillScAddress(
40 ScAddress
& rScAddress
,
41 const ::com::sun::star::table::CellAddress
& rApiAddress
);
42 // ScAddress -> CellAddress
43 static inline void FillApiAddress(
44 ::com::sun::star::table::CellAddress
& rApiAddress
,
45 const ScAddress
& rScAddress
);
46 // CellRangeAddress -> ScRange
47 static inline void FillScRange(
49 const ::com::sun::star::table::CellRangeAddress
& rApiRange
);
50 // ScRange -> CellRangeAddress
51 static inline void FillApiRange(
52 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
53 const ScRange
& rScRange
);
54 // CellAddress -> CellRangeAddress
55 static inline void FillApiRange(
56 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
57 const ::com::sun::star::table::CellAddress
& rApiAddress
);
58 // CellRangeAddress-Start -> CellAddress
59 static inline void FillApiStartAddress(
60 ::com::sun::star::table::CellAddress
& rApiAddress
,
61 const ::com::sun::star::table::CellRangeAddress
& rApiRange
);
62 // CellRangeAddress-End -> CellAddress
63 static inline void FillApiEndAddress(
64 ::com::sun::star::table::CellAddress
& rApiAddress
,
65 const ::com::sun::star::table::CellRangeAddress
& rApiRange
);
67 /** Returns true, if the passed ranges have at least one common cell. */
68 static inline bool Intersects(
69 const ::com::sun::star::table::CellRangeAddress
& rApiARange1
,
70 const ::com::sun::star::table::CellRangeAddress
& rApiARange2
);
71 /** Returns true, if the passed address rApiInner is inside the passed range rApiOuter. */
72 static inline bool Contains(
73 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
74 const ::com::sun::star::table::CellAddress
& rApiInner
);
75 /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */
76 static inline bool Contains(
77 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
78 const ::com::sun::star::table::CellRangeAddress
& rApiInner
);
82 inline void ScUnoConversion::FillScAddress(
83 ScAddress
& rScAddress
,
84 const ::com::sun::star::table::CellAddress
& rApiAddress
)
86 rScAddress
.Set( (SCCOL
)rApiAddress
.Column
, (SCROW
)rApiAddress
.Row
, (SCTAB
)rApiAddress
.Sheet
);
89 inline void ScUnoConversion::FillApiAddress(
90 ::com::sun::star::table::CellAddress
& rApiAddress
,
91 const ScAddress
& rScAddress
)
93 rApiAddress
.Column
= rScAddress
.Col();
94 rApiAddress
.Row
= rScAddress
.Row();
95 rApiAddress
.Sheet
= rScAddress
.Tab();
98 inline void ScUnoConversion::FillScRange(
100 const ::com::sun::star::table::CellRangeAddress
& rApiRange
)
102 rScRange
.aStart
.Set( (SCCOL
)rApiRange
.StartColumn
, (SCROW
)rApiRange
.StartRow
, (SCTAB
)rApiRange
.Sheet
);
103 rScRange
.aEnd
.Set( (SCCOL
)rApiRange
.EndColumn
, (SCROW
)rApiRange
.EndRow
, (SCTAB
)rApiRange
.Sheet
);
106 inline void ScUnoConversion::FillApiRange(
107 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
108 const ScRange
& rScRange
)
110 rApiRange
.StartColumn
= rScRange
.aStart
.Col();
111 rApiRange
.StartRow
= rScRange
.aStart
.Row();
112 rApiRange
.Sheet
= rScRange
.aStart
.Tab();
113 rApiRange
.EndColumn
= rScRange
.aEnd
.Col();
114 rApiRange
.EndRow
= rScRange
.aEnd
.Row();
117 inline void ScUnoConversion::FillApiRange(
118 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
119 const ::com::sun::star::table::CellAddress
& rApiAddress
)
121 rApiRange
.StartColumn
= rApiRange
.EndColumn
= rApiAddress
.Column
;
122 rApiRange
.StartRow
= rApiRange
.EndRow
= rApiAddress
.Row
;
123 rApiRange
.Sheet
= rApiAddress
.Sheet
;
126 inline void ScUnoConversion::FillApiStartAddress(
127 ::com::sun::star::table::CellAddress
& rApiAddress
,
128 const ::com::sun::star::table::CellRangeAddress
& rApiRange
)
130 rApiAddress
.Column
= rApiRange
.StartColumn
;
131 rApiAddress
.Row
= rApiRange
.StartRow
;
132 rApiAddress
.Sheet
= rApiRange
.Sheet
;
135 inline void ScUnoConversion::FillApiEndAddress(
136 ::com::sun::star::table::CellAddress
& rApiAddress
,
137 const ::com::sun::star::table::CellRangeAddress
& rApiRange
)
139 rApiAddress
.Column
= rApiRange
.EndColumn
;
140 rApiAddress
.Row
= rApiRange
.EndRow
;
141 rApiAddress
.Sheet
= rApiRange
.Sheet
;
144 inline bool ScUnoConversion::Intersects(
145 const ::com::sun::star::table::CellRangeAddress
& rApiRange1
,
146 const ::com::sun::star::table::CellRangeAddress
& rApiRange2
)
148 return (rApiRange1
.Sheet
== rApiRange2
.Sheet
) &&
149 (::std::max( rApiRange1
.StartColumn
, rApiRange2
.StartColumn
) <= ::std::min( rApiRange1
.EndColumn
, rApiRange2
.EndColumn
)) &&
150 (::std::max( rApiRange1
.StartRow
, rApiRange2
.StartRow
) <= ::std::min( rApiRange1
.EndRow
, rApiRange2
.EndRow
));
153 inline bool ScUnoConversion::Contains(
154 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
155 const ::com::sun::star::table::CellAddress
& rApiInner
)
157 return (rApiOuter
.Sheet
== rApiInner
.Sheet
) &&
158 (rApiOuter
.StartColumn
<= rApiInner
.Column
) && (rApiInner
.Column
<= rApiOuter
.EndColumn
) &&
159 (rApiOuter
.StartRow
<= rApiInner
.Row
) && (rApiInner
.Row
<= rApiOuter
.EndRow
);
162 inline bool ScUnoConversion::Contains(
163 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
164 const ::com::sun::star::table::CellRangeAddress
& rApiInner
)
166 return (rApiOuter
.Sheet
== rApiInner
.Sheet
) &&
167 (rApiOuter
.StartColumn
<= rApiInner
.StartColumn
) && (rApiInner
.EndColumn
<= rApiOuter
.EndColumn
) &&
168 (rApiOuter
.StartRow
<= rApiInner
.StartRow
) && (rApiInner
.EndRow
<= rApiOuter
.EndRow
);
171 //___________________________________________________________________
173 inline sal_Bool
operator==(
174 const ::com::sun::star::table::CellAddress
& rApiAddress1
,
175 const ::com::sun::star::table::CellAddress
& rApiAddress2
)
178 (rApiAddress1
.Column
== rApiAddress2
.Column
) &&
179 (rApiAddress1
.Row
== rApiAddress2
.Row
) &&
180 (rApiAddress1
.Sheet
== rApiAddress2
.Sheet
);
183 inline sal_Bool
operator!=(
184 const ::com::sun::star::table::CellAddress
& rApiAddress1
,
185 const ::com::sun::star::table::CellAddress
& rApiAddress2
)
187 return !(rApiAddress1
== rApiAddress2
);
190 inline sal_Bool
operator==(
191 const ::com::sun::star::table::CellRangeAddress
& rApiRange1
,
192 const ::com::sun::star::table::CellRangeAddress
& rApiRange2
)
195 (rApiRange1
.StartColumn
== rApiRange2
.StartColumn
) &&
196 (rApiRange1
.StartRow
== rApiRange2
.StartRow
) &&
197 (rApiRange1
.EndColumn
== rApiRange2
.EndColumn
) &&
198 (rApiRange1
.EndRow
== rApiRange2
.EndRow
) &&
199 (rApiRange1
.Sheet
== rApiRange2
.Sheet
);
202 inline sal_Bool
operator!=(
203 const ::com::sun::star::table::CellRangeAddress
& rApiRange1
,
204 const ::com::sun::star::table::CellRangeAddress
& rApiRange2
)
206 return !(rApiRange1
== rApiRange2
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */