Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_INC_CONVUNO_HXX
21 : #define INCLUDED_SC_INC_CONVUNO_HXX
22 :
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 "global.hxx"
29 : #include "address.hxx"
30 :
31 : class ScUnoConversion
32 : {
33 : public:
34 : static LanguageType GetLanguage( const com::sun::star::lang::Locale& rLocale );
35 : static void FillLocale( com::sun::star::lang::Locale& rLocale, LanguageType eLang );
36 :
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(
47 : ScRange& rScRange,
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 );
65 :
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 );
78 : };
79 :
80 8157 : inline void ScUnoConversion::FillScAddress(
81 : ScAddress& rScAddress,
82 : const ::com::sun::star::table::CellAddress& rApiAddress )
83 : {
84 8157 : rScAddress.Set( (SCCOL)rApiAddress.Column, (SCROW)rApiAddress.Row, (SCTAB)rApiAddress.Sheet );
85 8157 : }
86 :
87 121 : inline void ScUnoConversion::FillApiAddress(
88 : ::com::sun::star::table::CellAddress& rApiAddress,
89 : const ScAddress& rScAddress )
90 : {
91 121 : rApiAddress.Column = rScAddress.Col();
92 121 : rApiAddress.Row = rScAddress.Row();
93 121 : rApiAddress.Sheet = rScAddress.Tab();
94 121 : }
95 :
96 1140 : inline void ScUnoConversion::FillScRange(
97 : ScRange& rScRange,
98 : const ::com::sun::star::table::CellRangeAddress& rApiRange )
99 : {
100 1140 : rScRange.aStart.Set( (SCCOL)rApiRange.StartColumn, (SCROW)rApiRange.StartRow, (SCTAB)rApiRange.Sheet );
101 1140 : rScRange.aEnd.Set( (SCCOL)rApiRange.EndColumn, (SCROW)rApiRange.EndRow, (SCTAB)rApiRange.Sheet );
102 1140 : }
103 :
104 9639 : inline void ScUnoConversion::FillApiRange(
105 : ::com::sun::star::table::CellRangeAddress& rApiRange,
106 : const ScRange& rScRange )
107 : {
108 9639 : rApiRange.StartColumn = rScRange.aStart.Col();
109 9639 : rApiRange.StartRow = rScRange.aStart.Row();
110 9639 : rApiRange.Sheet = rScRange.aStart.Tab();
111 9639 : rApiRange.EndColumn = rScRange.aEnd.Col();
112 9639 : rApiRange.EndRow = rScRange.aEnd.Row();
113 9639 : }
114 :
115 : inline void ScUnoConversion::FillApiRange(
116 : ::com::sun::star::table::CellRangeAddress& rApiRange,
117 : const ::com::sun::star::table::CellAddress& rApiAddress )
118 : {
119 : rApiRange.StartColumn = rApiRange.EndColumn = rApiAddress.Column;
120 : rApiRange.StartRow = rApiRange.EndRow = rApiAddress.Row;
121 : rApiRange.Sheet = rApiAddress.Sheet;
122 : }
123 :
124 0 : inline void ScUnoConversion::FillApiStartAddress(
125 : ::com::sun::star::table::CellAddress& rApiAddress,
126 : const ::com::sun::star::table::CellRangeAddress& rApiRange )
127 : {
128 0 : rApiAddress.Column = rApiRange.StartColumn;
129 0 : rApiAddress.Row = rApiRange.StartRow;
130 0 : rApiAddress.Sheet = rApiRange.Sheet;
131 0 : }
132 :
133 : inline void ScUnoConversion::FillApiEndAddress(
134 : ::com::sun::star::table::CellAddress& rApiAddress,
135 : const ::com::sun::star::table::CellRangeAddress& rApiRange )
136 : {
137 : rApiAddress.Column = rApiRange.EndColumn;
138 : rApiAddress.Row = rApiRange.EndRow;
139 : rApiAddress.Sheet = rApiRange.Sheet;
140 : }
141 :
142 0 : inline bool ScUnoConversion::Intersects(
143 : const ::com::sun::star::table::CellRangeAddress& rApiRange1,
144 : const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
145 : {
146 0 : return (rApiRange1.Sheet == rApiRange2.Sheet) &&
147 0 : (::std::max( rApiRange1.StartColumn, rApiRange2.StartColumn ) <= ::std::min( rApiRange1.EndColumn, rApiRange2.EndColumn )) &&
148 0 : (::std::max( rApiRange1.StartRow, rApiRange2.StartRow ) <= ::std::min( rApiRange1.EndRow, rApiRange2.EndRow ));
149 : }
150 :
151 : inline bool ScUnoConversion::Contains(
152 : const ::com::sun::star::table::CellRangeAddress& rApiOuter,
153 : const ::com::sun::star::table::CellAddress& rApiInner )
154 : {
155 : return (rApiOuter.Sheet == rApiInner.Sheet) &&
156 : (rApiOuter.StartColumn <= rApiInner.Column) && (rApiInner.Column <= rApiOuter.EndColumn) &&
157 : (rApiOuter.StartRow <= rApiInner.Row) && (rApiInner.Row <= rApiOuter.EndRow);
158 : }
159 :
160 16 : inline bool ScUnoConversion::Contains(
161 : const ::com::sun::star::table::CellRangeAddress& rApiOuter,
162 : const ::com::sun::star::table::CellRangeAddress& rApiInner )
163 : {
164 32 : return (rApiOuter.Sheet == rApiInner.Sheet) &&
165 46 : (rApiOuter.StartColumn <= rApiInner.StartColumn) && (rApiInner.EndColumn <= rApiOuter.EndColumn) &&
166 44 : (rApiOuter.StartRow <= rApiInner.StartRow) && (rApiInner.EndRow <= rApiOuter.EndRow);
167 : }
168 :
169 0 : inline bool operator==(
170 : const ::com::sun::star::table::CellAddress& rApiAddress1,
171 : const ::com::sun::star::table::CellAddress& rApiAddress2 )
172 : {
173 : return
174 0 : (rApiAddress1.Column == rApiAddress2.Column) &&
175 0 : (rApiAddress1.Row == rApiAddress2.Row) &&
176 0 : (rApiAddress1.Sheet == rApiAddress2.Sheet);
177 : }
178 :
179 : inline bool operator!=(
180 : const ::com::sun::star::table::CellAddress& rApiAddress1,
181 : const ::com::sun::star::table::CellAddress& rApiAddress2 )
182 : {
183 : return !(rApiAddress1 == rApiAddress2);
184 : }
185 :
186 205 : inline bool operator==(
187 : const ::com::sun::star::table::CellRangeAddress& rApiRange1,
188 : const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
189 : {
190 : return
191 410 : (rApiRange1.StartColumn == rApiRange2.StartColumn) &&
192 410 : (rApiRange1.StartRow == rApiRange2.StartRow) &&
193 410 : (rApiRange1.EndColumn == rApiRange2.EndColumn) &&
194 615 : (rApiRange1.EndRow == rApiRange2.EndRow) &&
195 410 : (rApiRange1.Sheet == rApiRange2.Sheet);
196 : }
197 :
198 205 : inline bool operator!=(
199 : const ::com::sun::star::table::CellRangeAddress& rApiRange1,
200 : const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
201 : {
202 205 : return !(rApiRange1 == rApiRange2);
203 : }
204 :
205 : #endif
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|