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 SC_CONVUNO_HXX
21 : #define SC_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 :
32 : class ScUnoConversion
33 : {
34 : public:
35 : static LanguageType GetLanguage( const com::sun::star::lang::Locale& rLocale );
36 : static void FillLocale( com::sun::star::lang::Locale& rLocale, LanguageType eLang );
37 :
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(
48 : ScRange& rScRange,
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 );
66 :
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 );
79 : };
80 :
81 :
82 1400 : inline void ScUnoConversion::FillScAddress(
83 : ScAddress& rScAddress,
84 : const ::com::sun::star::table::CellAddress& rApiAddress )
85 : {
86 1400 : rScAddress.Set( (SCCOL)rApiAddress.Column, (SCROW)rApiAddress.Row, (SCTAB)rApiAddress.Sheet );
87 1400 : }
88 :
89 107 : inline void ScUnoConversion::FillApiAddress(
90 : ::com::sun::star::table::CellAddress& rApiAddress,
91 : const ScAddress& rScAddress )
92 : {
93 107 : rApiAddress.Column = rScAddress.Col();
94 107 : rApiAddress.Row = rScAddress.Row();
95 107 : rApiAddress.Sheet = rScAddress.Tab();
96 107 : }
97 :
98 946 : inline void ScUnoConversion::FillScRange(
99 : ScRange& rScRange,
100 : const ::com::sun::star::table::CellRangeAddress& rApiRange )
101 : {
102 946 : rScRange.aStart.Set( (SCCOL)rApiRange.StartColumn, (SCROW)rApiRange.StartRow, (SCTAB)rApiRange.Sheet );
103 946 : rScRange.aEnd.Set( (SCCOL)rApiRange.EndColumn, (SCROW)rApiRange.EndRow, (SCTAB)rApiRange.Sheet );
104 946 : }
105 :
106 5984 : inline void ScUnoConversion::FillApiRange(
107 : ::com::sun::star::table::CellRangeAddress& rApiRange,
108 : const ScRange& rScRange )
109 : {
110 5984 : rApiRange.StartColumn = rScRange.aStart.Col();
111 5984 : rApiRange.StartRow = rScRange.aStart.Row();
112 5984 : rApiRange.Sheet = rScRange.aStart.Tab();
113 5984 : rApiRange.EndColumn = rScRange.aEnd.Col();
114 5984 : rApiRange.EndRow = rScRange.aEnd.Row();
115 5984 : }
116 :
117 : inline void ScUnoConversion::FillApiRange(
118 : ::com::sun::star::table::CellRangeAddress& rApiRange,
119 : const ::com::sun::star::table::CellAddress& rApiAddress )
120 : {
121 : rApiRange.StartColumn = rApiRange.EndColumn = rApiAddress.Column;
122 : rApiRange.StartRow = rApiRange.EndRow = rApiAddress.Row;
123 : rApiRange.Sheet = rApiAddress.Sheet;
124 : }
125 :
126 0 : inline void ScUnoConversion::FillApiStartAddress(
127 : ::com::sun::star::table::CellAddress& rApiAddress,
128 : const ::com::sun::star::table::CellRangeAddress& rApiRange )
129 : {
130 0 : rApiAddress.Column = rApiRange.StartColumn;
131 0 : rApiAddress.Row = rApiRange.StartRow;
132 0 : rApiAddress.Sheet = rApiRange.Sheet;
133 0 : }
134 :
135 : inline void ScUnoConversion::FillApiEndAddress(
136 : ::com::sun::star::table::CellAddress& rApiAddress,
137 : const ::com::sun::star::table::CellRangeAddress& rApiRange )
138 : {
139 : rApiAddress.Column = rApiRange.EndColumn;
140 : rApiAddress.Row = rApiRange.EndRow;
141 : rApiAddress.Sheet = rApiRange.Sheet;
142 : }
143 :
144 0 : inline bool ScUnoConversion::Intersects(
145 : const ::com::sun::star::table::CellRangeAddress& rApiRange1,
146 : const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
147 : {
148 0 : return (rApiRange1.Sheet == rApiRange2.Sheet) &&
149 0 : (::std::max( rApiRange1.StartColumn, rApiRange2.StartColumn ) <= ::std::min( rApiRange1.EndColumn, rApiRange2.EndColumn )) &&
150 0 : (::std::max( rApiRange1.StartRow, rApiRange2.StartRow ) <= ::std::min( rApiRange1.EndRow, rApiRange2.EndRow ));
151 : }
152 :
153 : inline bool ScUnoConversion::Contains(
154 : const ::com::sun::star::table::CellRangeAddress& rApiOuter,
155 : const ::com::sun::star::table::CellAddress& rApiInner )
156 : {
157 : return (rApiOuter.Sheet == rApiInner.Sheet) &&
158 : (rApiOuter.StartColumn <= rApiInner.Column) && (rApiInner.Column <= rApiOuter.EndColumn) &&
159 : (rApiOuter.StartRow <= rApiInner.Row) && (rApiInner.Row <= rApiOuter.EndRow);
160 : }
161 :
162 16 : inline bool ScUnoConversion::Contains(
163 : const ::com::sun::star::table::CellRangeAddress& rApiOuter,
164 : const ::com::sun::star::table::CellRangeAddress& rApiInner )
165 : {
166 32 : return (rApiOuter.Sheet == rApiInner.Sheet) &&
167 46 : (rApiOuter.StartColumn <= rApiInner.StartColumn) && (rApiInner.EndColumn <= rApiOuter.EndColumn) &&
168 44 : (rApiOuter.StartRow <= rApiInner.StartRow) && (rApiInner.EndRow <= rApiOuter.EndRow);
169 : }
170 :
171 : //___________________________________________________________________
172 :
173 0 : inline sal_Bool operator==(
174 : const ::com::sun::star::table::CellAddress& rApiAddress1,
175 : const ::com::sun::star::table::CellAddress& rApiAddress2 )
176 : {
177 : return
178 0 : (rApiAddress1.Column == rApiAddress2.Column) &&
179 0 : (rApiAddress1.Row == rApiAddress2.Row) &&
180 0 : (rApiAddress1.Sheet == rApiAddress2.Sheet);
181 : }
182 :
183 : inline sal_Bool operator!=(
184 : const ::com::sun::star::table::CellAddress& rApiAddress1,
185 : const ::com::sun::star::table::CellAddress& rApiAddress2 )
186 : {
187 : return !(rApiAddress1 == rApiAddress2);
188 : }
189 :
190 61 : inline sal_Bool operator==(
191 : const ::com::sun::star::table::CellRangeAddress& rApiRange1,
192 : const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
193 : {
194 : return
195 122 : (rApiRange1.StartColumn == rApiRange2.StartColumn) &&
196 122 : (rApiRange1.StartRow == rApiRange2.StartRow) &&
197 122 : (rApiRange1.EndColumn == rApiRange2.EndColumn) &&
198 183 : (rApiRange1.EndRow == rApiRange2.EndRow) &&
199 122 : (rApiRange1.Sheet == rApiRange2.Sheet);
200 : }
201 :
202 61 : inline sal_Bool operator!=(
203 : const ::com::sun::star::table::CellRangeAddress& rApiRange1,
204 : const ::com::sun::star::table::CellRangeAddress& rApiRange2 )
205 : {
206 61 : return !(rApiRange1 == rApiRange2);
207 : }
208 :
209 : #endif
210 :
211 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|