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 css::lang::Locale
& rLocale
);
35 static void FillLocale( css::lang::Locale
& rLocale
, LanguageType eLang
);
37 // CellAddress -> ScAddress
38 static inline void FillScAddress(
39 ScAddress
& rScAddress
,
40 const css::table::CellAddress
& rApiAddress
);
41 // ScAddress -> CellAddress
42 static inline void FillApiAddress(
43 css::table::CellAddress
& rApiAddress
,
44 const ScAddress
& rScAddress
);
45 // CellRangeAddress -> ScRange
46 static inline void FillScRange(
48 const css::table::CellRangeAddress
& rApiRange
);
49 // ScRange -> CellRangeAddress
50 static inline void FillApiRange(
51 css::table::CellRangeAddress
& rApiRange
,
52 const ScRange
& rScRange
);
53 // CellRangeAddress-Start -> CellAddress
54 static inline void FillApiStartAddress(
55 css::table::CellAddress
& rApiAddress
,
56 const css::table::CellRangeAddress
& rApiRange
);
58 /** Returns true, if the passed ranges have at least one common cell. */
59 static inline bool Intersects(
60 const css::table::CellRangeAddress
& rApiARange1
,
61 const css::table::CellRangeAddress
& rApiARange2
);
62 /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */
63 static inline bool Contains(
64 const css::table::CellRangeAddress
& rApiOuter
,
65 const css::table::CellRangeAddress
& rApiInner
);
68 inline void ScUnoConversion::FillScAddress(
69 ScAddress
& rScAddress
,
70 const css::table::CellAddress
& rApiAddress
)
72 rScAddress
.Set( (SCCOL
)rApiAddress
.Column
, (SCROW
)rApiAddress
.Row
, (SCTAB
)rApiAddress
.Sheet
);
75 inline void ScUnoConversion::FillApiAddress(
76 css::table::CellAddress
& rApiAddress
,
77 const ScAddress
& rScAddress
)
79 rApiAddress
.Column
= rScAddress
.Col();
80 rApiAddress
.Row
= rScAddress
.Row();
81 rApiAddress
.Sheet
= rScAddress
.Tab();
84 inline void ScUnoConversion::FillScRange(
86 const css::table::CellRangeAddress
& rApiRange
)
88 rScRange
.aStart
.Set( (SCCOL
)rApiRange
.StartColumn
, (SCROW
)rApiRange
.StartRow
, (SCTAB
)rApiRange
.Sheet
);
89 rScRange
.aEnd
.Set( (SCCOL
)rApiRange
.EndColumn
, (SCROW
)rApiRange
.EndRow
, (SCTAB
)rApiRange
.Sheet
);
92 inline void ScUnoConversion::FillApiRange(
93 css::table::CellRangeAddress
& rApiRange
,
94 const ScRange
& rScRange
)
96 rApiRange
.StartColumn
= rScRange
.aStart
.Col();
97 rApiRange
.StartRow
= rScRange
.aStart
.Row();
98 rApiRange
.Sheet
= rScRange
.aStart
.Tab();
99 rApiRange
.EndColumn
= rScRange
.aEnd
.Col();
100 rApiRange
.EndRow
= rScRange
.aEnd
.Row();
103 inline void ScUnoConversion::FillApiStartAddress(
104 css::table::CellAddress
& rApiAddress
,
105 const css::table::CellRangeAddress
& rApiRange
)
107 rApiAddress
.Column
= rApiRange
.StartColumn
;
108 rApiAddress
.Row
= rApiRange
.StartRow
;
109 rApiAddress
.Sheet
= rApiRange
.Sheet
;
112 inline bool ScUnoConversion::Intersects(
113 const css::table::CellRangeAddress
& rApiRange1
,
114 const css::table::CellRangeAddress
& rApiRange2
)
116 return (rApiRange1
.Sheet
== rApiRange2
.Sheet
) &&
117 (::std::max( rApiRange1
.StartColumn
, rApiRange2
.StartColumn
) <= ::std::min( rApiRange1
.EndColumn
, rApiRange2
.EndColumn
)) &&
118 (::std::max( rApiRange1
.StartRow
, rApiRange2
.StartRow
) <= ::std::min( rApiRange1
.EndRow
, rApiRange2
.EndRow
));
121 inline bool ScUnoConversion::Contains(
122 const css::table::CellRangeAddress
& rApiOuter
,
123 const css::table::CellRangeAddress
& rApiInner
)
125 return (rApiOuter
.Sheet
== rApiInner
.Sheet
) &&
126 (rApiOuter
.StartColumn
<= rApiInner
.StartColumn
) && (rApiInner
.EndColumn
<= rApiOuter
.EndColumn
) &&
127 (rApiOuter
.StartRow
<= rApiInner
.StartRow
) && (rApiInner
.EndRow
<= rApiOuter
.EndRow
);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */