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 INCLUDED_SC_INC_CONVUNO_HXX
21 #define INCLUDED_SC_INC_CONVUNO_HXX
24 #include <i18nlangtag/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"
34 static LanguageType
GetLanguage( const com::sun::star::lang::Locale
& rLocale
);
35 static void FillLocale( com::sun::star::lang::Locale
& rLocale
, LanguageType eLang
);
37 // CellAddress -> ScAddress
38 static inline void FillScAddress(
39 ScAddress
& rScAddress
,
40 const ::com::sun::star::table::CellAddress
& rApiAddress
);
41 // ScAddress -> CellAddress
42 static inline void FillApiAddress(
43 ::com::sun::star::table::CellAddress
& rApiAddress
,
44 const ScAddress
& rScAddress
);
45 // CellRangeAddress -> ScRange
46 static inline void FillScRange(
48 const ::com::sun::star::table::CellRangeAddress
& rApiRange
);
49 // ScRange -> CellRangeAddress
50 static inline void FillApiRange(
51 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
52 const ScRange
& rScRange
);
53 // CellAddress -> CellRangeAddress
54 static inline void FillApiRange(
55 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
56 const ::com::sun::star::table::CellAddress
& rApiAddress
);
57 // CellRangeAddress-Start -> CellAddress
58 static inline void FillApiStartAddress(
59 ::com::sun::star::table::CellAddress
& rApiAddress
,
60 const ::com::sun::star::table::CellRangeAddress
& rApiRange
);
61 // CellRangeAddress-End -> CellAddress
62 static inline void FillApiEndAddress(
63 ::com::sun::star::table::CellAddress
& rApiAddress
,
64 const ::com::sun::star::table::CellRangeAddress
& rApiRange
);
66 /** Returns true, if the passed ranges have at least one common cell. */
67 static inline bool Intersects(
68 const ::com::sun::star::table::CellRangeAddress
& rApiARange1
,
69 const ::com::sun::star::table::CellRangeAddress
& rApiARange2
);
70 /** Returns true, if the passed address rApiInner is inside the passed range rApiOuter. */
71 static inline bool Contains(
72 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
73 const ::com::sun::star::table::CellAddress
& rApiInner
);
74 /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */
75 static inline bool Contains(
76 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
77 const ::com::sun::star::table::CellRangeAddress
& rApiInner
);
80 inline void ScUnoConversion::FillScAddress(
81 ScAddress
& rScAddress
,
82 const ::com::sun::star::table::CellAddress
& rApiAddress
)
84 rScAddress
.Set( (SCCOL
)rApiAddress
.Column
, (SCROW
)rApiAddress
.Row
, (SCTAB
)rApiAddress
.Sheet
);
87 inline void ScUnoConversion::FillApiAddress(
88 ::com::sun::star::table::CellAddress
& rApiAddress
,
89 const ScAddress
& rScAddress
)
91 rApiAddress
.Column
= rScAddress
.Col();
92 rApiAddress
.Row
= rScAddress
.Row();
93 rApiAddress
.Sheet
= rScAddress
.Tab();
96 inline void ScUnoConversion::FillScRange(
98 const ::com::sun::star::table::CellRangeAddress
& rApiRange
)
100 rScRange
.aStart
.Set( (SCCOL
)rApiRange
.StartColumn
, (SCROW
)rApiRange
.StartRow
, (SCTAB
)rApiRange
.Sheet
);
101 rScRange
.aEnd
.Set( (SCCOL
)rApiRange
.EndColumn
, (SCROW
)rApiRange
.EndRow
, (SCTAB
)rApiRange
.Sheet
);
104 inline void ScUnoConversion::FillApiRange(
105 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
106 const ScRange
& rScRange
)
108 rApiRange
.StartColumn
= rScRange
.aStart
.Col();
109 rApiRange
.StartRow
= rScRange
.aStart
.Row();
110 rApiRange
.Sheet
= rScRange
.aStart
.Tab();
111 rApiRange
.EndColumn
= rScRange
.aEnd
.Col();
112 rApiRange
.EndRow
= rScRange
.aEnd
.Row();
115 inline void ScUnoConversion::FillApiRange(
116 ::com::sun::star::table::CellRangeAddress
& rApiRange
,
117 const ::com::sun::star::table::CellAddress
& rApiAddress
)
119 rApiRange
.StartColumn
= rApiRange
.EndColumn
= rApiAddress
.Column
;
120 rApiRange
.StartRow
= rApiRange
.EndRow
= rApiAddress
.Row
;
121 rApiRange
.Sheet
= rApiAddress
.Sheet
;
124 inline void ScUnoConversion::FillApiStartAddress(
125 ::com::sun::star::table::CellAddress
& rApiAddress
,
126 const ::com::sun::star::table::CellRangeAddress
& rApiRange
)
128 rApiAddress
.Column
= rApiRange
.StartColumn
;
129 rApiAddress
.Row
= rApiRange
.StartRow
;
130 rApiAddress
.Sheet
= rApiRange
.Sheet
;
133 inline void ScUnoConversion::FillApiEndAddress(
134 ::com::sun::star::table::CellAddress
& rApiAddress
,
135 const ::com::sun::star::table::CellRangeAddress
& rApiRange
)
137 rApiAddress
.Column
= rApiRange
.EndColumn
;
138 rApiAddress
.Row
= rApiRange
.EndRow
;
139 rApiAddress
.Sheet
= rApiRange
.Sheet
;
142 inline bool ScUnoConversion::Intersects(
143 const ::com::sun::star::table::CellRangeAddress
& rApiRange1
,
144 const ::com::sun::star::table::CellRangeAddress
& rApiRange2
)
146 return (rApiRange1
.Sheet
== rApiRange2
.Sheet
) &&
147 (::std::max( rApiRange1
.StartColumn
, rApiRange2
.StartColumn
) <= ::std::min( rApiRange1
.EndColumn
, rApiRange2
.EndColumn
)) &&
148 (::std::max( rApiRange1
.StartRow
, rApiRange2
.StartRow
) <= ::std::min( rApiRange1
.EndRow
, rApiRange2
.EndRow
));
151 inline bool ScUnoConversion::Contains(
152 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
153 const ::com::sun::star::table::CellAddress
& rApiInner
)
155 return (rApiOuter
.Sheet
== rApiInner
.Sheet
) &&
156 (rApiOuter
.StartColumn
<= rApiInner
.Column
) && (rApiInner
.Column
<= rApiOuter
.EndColumn
) &&
157 (rApiOuter
.StartRow
<= rApiInner
.Row
) && (rApiInner
.Row
<= rApiOuter
.EndRow
);
160 inline bool ScUnoConversion::Contains(
161 const ::com::sun::star::table::CellRangeAddress
& rApiOuter
,
162 const ::com::sun::star::table::CellRangeAddress
& rApiInner
)
164 return (rApiOuter
.Sheet
== rApiInner
.Sheet
) &&
165 (rApiOuter
.StartColumn
<= rApiInner
.StartColumn
) && (rApiInner
.EndColumn
<= rApiOuter
.EndColumn
) &&
166 (rApiOuter
.StartRow
<= rApiInner
.StartRow
) && (rApiInner
.EndRow
<= rApiOuter
.EndRow
);
169 inline bool operator==(
170 const ::com::sun::star::table::CellAddress
& rApiAddress1
,
171 const ::com::sun::star::table::CellAddress
& rApiAddress2
)
174 (rApiAddress1
.Column
== rApiAddress2
.Column
) &&
175 (rApiAddress1
.Row
== rApiAddress2
.Row
) &&
176 (rApiAddress1
.Sheet
== rApiAddress2
.Sheet
);
179 inline bool operator!=(
180 const ::com::sun::star::table::CellAddress
& rApiAddress1
,
181 const ::com::sun::star::table::CellAddress
& rApiAddress2
)
183 return !(rApiAddress1
== rApiAddress2
);
186 inline bool operator==(
187 const ::com::sun::star::table::CellRangeAddress
& rApiRange1
,
188 const ::com::sun::star::table::CellRangeAddress
& rApiRange2
)
191 (rApiRange1
.StartColumn
== rApiRange2
.StartColumn
) &&
192 (rApiRange1
.StartRow
== rApiRange2
.StartRow
) &&
193 (rApiRange1
.EndColumn
== rApiRange2
.EndColumn
) &&
194 (rApiRange1
.EndRow
== rApiRange2
.EndRow
) &&
195 (rApiRange1
.Sheet
== rApiRange2
.Sheet
);
198 inline bool operator!=(
199 const ::com::sun::star::table::CellRangeAddress
& rApiRange1
,
200 const ::com::sun::star::table::CellRangeAddress
& rApiRange2
)
202 return !(rApiRange1
== rApiRange2
);
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */