Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / convuno.hxx
blob14cf2728c411197b8da6ecb91893a54aa727b0b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <algorithm>
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>
28 #include "address.hxx"
30 class ScUnoConversion
32 public:
33 static LanguageType GetLanguage( const css::lang::Locale& rLocale );
34 static void FillLocale( css::lang::Locale& rLocale, LanguageType eLang );
36 // CellAddress -> ScAddress
37 static inline void FillScAddress(
38 ScAddress& rScAddress,
39 const css::table::CellAddress& rApiAddress );
40 // ScAddress -> CellAddress
41 static inline void FillApiAddress(
42 css::table::CellAddress& rApiAddress,
43 const ScAddress& rScAddress );
44 // CellRangeAddress -> ScRange
45 static inline void FillScRange(
46 ScRange& rScRange,
47 const css::table::CellRangeAddress& rApiRange );
48 // ScRange -> CellRangeAddress
49 static inline void FillApiRange(
50 css::table::CellRangeAddress& rApiRange,
51 const ScRange& rScRange );
53 /** Returns true, if the passed ranges have at least one common cell. */
54 static inline bool Intersects(
55 const css::table::CellRangeAddress& rApiARange1,
56 const css::table::CellRangeAddress& rApiARange2 );
57 /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */
58 static inline bool Contains(
59 const css::table::CellRangeAddress& rApiOuter,
60 const css::table::CellRangeAddress& rApiInner );
63 inline void ScUnoConversion::FillScAddress(
64 ScAddress& rScAddress,
65 const css::table::CellAddress& rApiAddress )
67 rScAddress.Set( static_cast<SCCOL>(rApiAddress.Column), static_cast<SCROW>(rApiAddress.Row), static_cast<SCTAB>(rApiAddress.Sheet) );
70 inline void ScUnoConversion::FillApiAddress(
71 css::table::CellAddress& rApiAddress,
72 const ScAddress& rScAddress )
74 rApiAddress.Column = rScAddress.Col();
75 rApiAddress.Row = rScAddress.Row();
76 rApiAddress.Sheet = rScAddress.Tab();
79 inline void ScUnoConversion::FillScRange(
80 ScRange& rScRange,
81 const css::table::CellRangeAddress& rApiRange )
83 rScRange.aStart.Set( static_cast<SCCOL>(rApiRange.StartColumn), static_cast<SCROW>(rApiRange.StartRow), static_cast<SCTAB>(rApiRange.Sheet) );
84 rScRange.aEnd.Set( static_cast<SCCOL>(rApiRange.EndColumn), static_cast<SCROW>(rApiRange.EndRow), static_cast<SCTAB>(rApiRange.Sheet) );
87 inline void ScUnoConversion::FillApiRange(
88 css::table::CellRangeAddress& rApiRange,
89 const ScRange& rScRange )
91 rApiRange.StartColumn = rScRange.aStart.Col();
92 rApiRange.StartRow = rScRange.aStart.Row();
93 rApiRange.Sheet = rScRange.aStart.Tab();
94 rApiRange.EndColumn = rScRange.aEnd.Col();
95 rApiRange.EndRow = rScRange.aEnd.Row();
98 inline bool ScUnoConversion::Intersects(
99 const css::table::CellRangeAddress& rApiRange1,
100 const css::table::CellRangeAddress& rApiRange2 )
102 return (rApiRange1.Sheet == rApiRange2.Sheet) &&
103 (::std::max( rApiRange1.StartColumn, rApiRange2.StartColumn ) <= ::std::min( rApiRange1.EndColumn, rApiRange2.EndColumn )) &&
104 (::std::max( rApiRange1.StartRow, rApiRange2.StartRow ) <= ::std::min( rApiRange1.EndRow, rApiRange2.EndRow ));
107 inline bool ScUnoConversion::Contains(
108 const css::table::CellRangeAddress& rApiOuter,
109 const css::table::CellRangeAddress& rApiInner )
111 return (rApiOuter.Sheet == rApiInner.Sheet) &&
112 (rApiOuter.StartColumn <= rApiInner.StartColumn) && (rApiInner.EndColumn <= rApiOuter.EndColumn) &&
113 (rApiOuter.StartRow <= rApiInner.StartRow) && (rApiInner.EndRow <= rApiOuter.EndRow);
116 #endif
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */