LibreOffice Module sc (master) 1
addruno.cxx
Go to the documentation of this file.
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#include <com/sun/star/table/CellAddress.hpp>
21#include <com/sun/star/table/CellRangeAddress.hpp>
23
24#include <svl/itemprop.hxx>
25#include <vcl/svapp.hxx>
26
27#include <docsh.hxx>
28#include <unonames.hxx>
29#include <miscuno.hxx>
30#include <convuno.hxx>
31#include <addruno.hxx>
32
33using namespace com::sun::star;
34
36 pDocShell( pDocSh ),
37 nRefSheet( 0 ),
38 bIsRange( _bIsRange )
39{
41}
42
44{
46
47 if (pDocShell)
49}
50
52{
53 if ( rHint.GetId() == SfxHintId::Dying )
54 {
55 pDocShell = nullptr; // invalid
56 }
57}
58
60{
61 if (!pDocShell)
62 return false;
63
65 bool bSuccess = false;
66 if ( bIsRange )
67 {
68 ScRefFlags nResult = aRange.ParseAny( rUIString, rDoc, eConv );
69 if ( nResult & ScRefFlags::VALID )
70 {
71 if ( ( nResult & ScRefFlags::TAB_3D ) == ScRefFlags::ZERO )
72 aRange.aStart.SetTab( static_cast<SCTAB>(nRefSheet) );
73 if ( ( nResult & ScRefFlags::TAB2_3D ) == ScRefFlags::ZERO )
75 // different sheets are not supported in CellRangeAddress
76 if ( aRange.aStart.Tab() == aRange.aEnd.Tab() )
77 bSuccess = true;
78 }
79 }
80 else
81 {
82 ScRefFlags nResult = aRange.aStart.Parse( rUIString, rDoc, eConv );
83 if ( nResult & ScRefFlags::VALID )
84 {
85 if ( ( nResult & ScRefFlags::TAB_3D ) == ScRefFlags::ZERO )
86 aRange.aStart.SetTab( static_cast<SCTAB>(nRefSheet) );
87 bSuccess = true;
88 }
89 }
90 return bSuccess;
91}
92
93// XPropertySet
94
95uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAddressConversionObj::getPropertySetInfo()
96{
97 SolarMutexGuard aGuard;
98
99 if ( bIsRange )
100 {
101 static const SfxItemPropertyMapEntry aPropertyMap[] =
102 {
109 };
110 static uno::Reference<beans::XPropertySetInfo> aRef(new SfxItemPropertySetInfo( aPropertyMap ));
111 return aRef;
112 }
113 else
114 {
115 static const SfxItemPropertyMapEntry aPropertyMap[] =
116 {
123 };
124 static uno::Reference<beans::XPropertySetInfo> aRef(new SfxItemPropertySetInfo( aPropertyMap ));
125 return aRef;
126 }
127}
128
129void SAL_CALL ScAddressConversionObj::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
130{
131 if ( !pDocShell )
132 throw uno::RuntimeException();
133
134 bool bSuccess = false;
135 if ( aPropertyName == SC_UNONAME_ADDRESS )
136 {
137 // read the cell/range address from API struct
138 if ( bIsRange )
139 {
140 table::CellRangeAddress aRangeAddress;
141 if ( aValue >>= aRangeAddress )
142 {
143 ScUnoConversion::FillScRange( aRange, aRangeAddress );
144 bSuccess = true;
145 }
146 }
147 else
148 {
149 table::CellAddress aCellAddress;
150 if ( aValue >>= aCellAddress )
151 {
153 bSuccess = true;
154 }
155 }
156 }
157 else if ( aPropertyName == SC_UNONAME_REFSHEET )
158 {
159 // set the reference sheet
160 sal_Int32 nIntVal = 0;
161 if ( aValue >>= nIntVal )
162 {
163 nRefSheet = nIntVal;
164 bSuccess = true;
165 }
166 }
167 else if ( aPropertyName == SC_UNONAME_UIREPR )
168 {
169 // parse the UI representation string
170 OUString sRepresentation;
171 if (aValue >>= sRepresentation)
172 {
173 bSuccess = ParseUIString( sRepresentation );
174 }
175 }
176 else if ( aPropertyName == SC_UNONAME_PERSREPR || aPropertyName == SC_UNONAME_XLA1REPR )
177 {
180
181 // parse the file format string
182 OUString sRepresentation;
183 if (aValue >>= sRepresentation)
184 {
185 OUString aUIString(sRepresentation);
186
187 // cell or range: strip a single "." at the start
188 if ( aUIString[0]== '.' )
189 aUIString = aUIString.copy( 1 );
190
191 if ( bIsRange )
192 {
193 // range: also strip a "." after the last colon
194 sal_Int32 nColon = aUIString.lastIndexOf( ':' );
195 if ( nColon >= 0 && nColon < aUIString.getLength() - 1 &&
196 aUIString[nColon+1] == '.' )
197 aUIString = aUIString.replaceAt( nColon+1, 1, u"" );
198 }
199
200 // parse the rest like a UI string
201 bSuccess = ParseUIString( aUIString, eConv );
202 }
203 }
204 else
205 throw beans::UnknownPropertyException(aPropertyName);
206
207 if ( !bSuccess )
208 throw lang::IllegalArgumentException();
209}
210
211uno::Any SAL_CALL ScAddressConversionObj::getPropertyValue( const OUString& aPropertyName )
212{
213 if ( !pDocShell )
214 throw uno::RuntimeException();
215
217 uno::Any aRet;
218
219 if ( aPropertyName == SC_UNONAME_ADDRESS )
220 {
221 if ( bIsRange )
222 {
223 table::CellRangeAddress aRangeAddress;
224 ScUnoConversion::FillApiRange( aRangeAddress, aRange );
225 aRet <<= aRangeAddress;
226 }
227 else
228 {
229 table::CellAddress aCellAddress;
231 aRet <<= aCellAddress;
232 }
233 }
234 else if ( aPropertyName == SC_UNONAME_REFSHEET )
235 {
236 aRet <<= nRefSheet;
237 }
238 else if ( aPropertyName == SC_UNONAME_UIREPR )
239 {
240 // generate UI representation string - include sheet only if different from ref sheet
241 OUString aFormatStr;
243 if ( aRange.aStart.Tab() != nRefSheet )
244 nFlags |= ScRefFlags::TAB_3D;
245 if ( bIsRange )
246 aFormatStr = aRange.Format(rDoc, nFlags);
247 else
248 aFormatStr = aRange.aStart.Format(nFlags, &rDoc);
249 aRet <<= aFormatStr;
250 }
251 else if ( aPropertyName == SC_UNONAME_PERSREPR || aPropertyName == SC_UNONAME_XLA1REPR )
252 {
255
256 // generate file format string - always include sheet
257 OUString aFormatStr(aRange.aStart.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc, eConv));
258 if ( bIsRange )
259 {
260 // manually concatenate range so both parts always have the sheet name
261 aFormatStr += ":";
264 nFlags |= ScRefFlags::TAB_3D;
265 OUString aSecond(aRange.aEnd.Format(nFlags, &rDoc, eConv));
266 aFormatStr += aSecond ;
267 }
268 aRet <<= aFormatStr;
269 }
270 else
271 throw beans::UnknownPropertyException(aPropertyName);
272
273 return aRet;
274}
275
277
278// lang::XServiceInfo
279
280OUString SAL_CALL ScAddressConversionObj::getImplementationName()
281{
282 return "ScAddressConversionObj";
283}
284
285sal_Bool SAL_CALL ScAddressConversionObj::supportsService( const OUString& rServiceName )
286{
287 return cppu::supportsService(this, rServiceName);
288}
289
290uno::Sequence<OUString> SAL_CALL ScAddressConversionObj::getSupportedServiceNames()
291{
292 if (bIsRange)
294 else
296}
297
298/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefFlags
Definition: address.hxx:158
virtual ~ScAddressConversionObj() override
Definition: addruno.cxx:43
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: addruno.cxx:95
ScDocShell * pDocShell
Definition: addruno.hxx:36
bool ParseUIString(const OUString &rUIString, ::formula::FormulaGrammar::AddressConvention eConv=::formula::FormulaGrammar::CONV_OOO)
Definition: addruno.cxx:59
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: addruno.cxx:129
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: addruno.cxx:211
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: addruno.cxx:285
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: addruno.cxx:290
ScAddressConversionObj(ScDocShell *pDocSh, bool bIsRange)
Definition: addruno.cxx:35
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: addruno.cxx:51
SCTAB Tab() const
Definition: address.hxx:283
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1537
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2170
ScAddress aEnd
Definition: address.hxx:498
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1733
ScAddress aStart
Definition: address.hxx:497
static void FillScAddress(ScAddress &rScAddress, const css::table::CellAddress &rApiAddress)
Definition: convuno.hxx:63
static void FillScRange(ScRange &rScRange, const css::table::CellRangeAddress &rApiRange)
Definition: convuno.hxx:79
static void FillApiAddress(css::table::CellAddress &rApiAddress, const ScAddress &rScAddress)
Definition: convuno.hxx:70
static void FillApiRange(css::table::CellRangeAddress &rApiRange, const ScRange &rScRange)
Definition: convuno.hxx:87
SfxHintId GetId() const
css::uno::Type const & get()
float u
#define SC_IMPL_DUMMY_PROPERTY_LISTENER(ClassName)
Definition: miscuno.hxx:72
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool
sal_Int16 SCTAB
Definition: types.hxx:22
constexpr OUStringLiteral SC_UNONAME_PERSREPR
Definition: unonames.hxx:675
constexpr OUStringLiteral SC_SERVICENAME_RANGEADDRESS
Definition: unonames.hxx:29
constexpr OUStringLiteral SC_SERVICENAME_CELLADDRESS
Definition: unonames.hxx:28
constexpr OUStringLiteral SC_UNONAME_REFSHEET
Definition: unonames.hxx:677
constexpr OUStringLiteral SC_UNONAME_UIREPR
Definition: unonames.hxx:674
constexpr OUStringLiteral SC_UNONAME_XLA1REPR
Definition: unonames.hxx:676
constexpr OUStringLiteral SC_UNONAME_ADDRESS
Definition: unonames.hxx:673