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 #include "excelvbahelper.hxx"
21 #include "vbaname.hxx"
22 #include "vbarange.hxx"
24 #include <rangenam.hxx>
25 #include <nameuno.hxx>
26 #include <compiler.hxx>
27 #include <tokenarray.hxx>
29 #include <comphelper/servicehelper.hxx>
34 using namespace ::ooo::vba
;
35 using namespace ::com::sun::star
;
37 ScVbaName::ScVbaName(const css::uno::Reference
< ov::XHelperInterface
>& xParent
,
38 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
39 css::uno::Reference
< css::sheet::XNamedRange
> xName
,
40 css::uno::Reference
< css::sheet::XNamedRanges
> xNames
,
41 css::uno::Reference
< css::frame::XModel
> xModel
):
42 NameImpl_BASE( xParent
, xContext
),
43 mxModel(std::move( xModel
)),
44 mxNamedRange(std::move( xName
)),
45 mxNames(std::move( xNames
))
49 ScVbaName::~ScVbaName()
56 return mxNamedRange
->getName();
60 ScVbaName::setName( const OUString
& rName
)
62 mxNamedRange
->setName( rName
);
66 ScVbaName::getNameLocal()
72 ScVbaName::setNameLocal( const OUString
& rName
)
78 ScVbaName::getVisible()
84 ScVbaName::setVisible( sal_Bool
/*bVisible*/ )
88 OUString
ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar
)
90 ScNamedRangeObj
* pNamedRange
= dynamic_cast< ScNamedRangeObj
* >( mxNamedRange
.get() );
94 ScRangeData
* pData
= pNamedRange
->GetRangeData_Impl();
96 aContent
= pData
->GetSymbol( eGrammar
);
98 if (aContent
.indexOf('=') != 0)
99 aContent
= "=" + aContent
;
103 void ScVbaName::setContent( const OUString
& rContent
, const formula::FormulaGrammar::Grammar eGrammar
)
105 OUString
sContent( rContent
);
106 if (sContent
.startsWith("="))
107 sContent
= sContent
.copy(1);
108 ScNamedRangeObj
* pNamedRange
= dynamic_cast< ScNamedRangeObj
* >( mxNamedRange
.get() );
110 // We should be able to do the below by just setting calling SetCode on pNamedRange
112 if ( !(pNamedRange
&& pNamedRange
->pDocShell
) )
115 ScDocument
& rDoc
= pNamedRange
->pDocShell
->GetDocument();
116 ScRangeData
* pOldData
= pNamedRange
->GetRangeData_Impl();
119 // Shorter way of doing this ?
120 ScCompiler
aComp( rDoc
, pOldData
->GetPos(), eGrammar
);
121 std::unique_ptr
<ScTokenArray
> pArray(aComp
.CompileString(sContent
));
122 pOldData
->SetCode(*pArray
);
127 ScVbaName::getValue()
129 OUString sResult
= getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1
);
135 ScVbaName::setValue( const OUString
& rValue
)
137 setContent( rValue
, formula::FormulaGrammar::GRAM_NATIVE_XL_A1
);
141 ScVbaName::getRefersTo()
147 ScVbaName::setRefersTo( const OUString
& rRefersTo
)
149 setValue( rRefersTo
);
153 ScVbaName::getRefersToLocal()
155 return getRefersTo();
159 ScVbaName::setRefersToLocal( const OUString
& rRefersTo
)
161 setRefersTo( rRefersTo
);
165 ScVbaName::getRefersToR1C1()
167 OUString sResult
= getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1
);
172 ScVbaName::setRefersToR1C1( const OUString
& rRefersTo
)
174 setContent( rRefersTo
, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1
);
178 ScVbaName::getRefersToR1C1Local()
180 return getRefersToR1C1();
184 ScVbaName::setRefersToR1C1Local( const OUString
& rRefersTo
)
186 setRefersTo( rRefersTo
);
189 css::uno::Reference
< ov::excel::XRange
>
190 ScVbaName::getRefersToRange()
192 uno::Reference
< ov::excel::XRange
> xRange
= ScVbaRange::getRangeObjectForName(
193 mxContext
, mxNamedRange
->getName(), excel::getDocShell( mxModel
), formula::FormulaGrammar::CONV_XL_R1C1
);
200 mxNames
->removeByName( mxNamedRange
->getName() );
204 ScVbaName::getServiceImplName()
206 return u
"ScVbaName"_ustr
;
209 uno::Sequence
< OUString
>
210 ScVbaName::getServiceNames()
212 static uno::Sequence
< OUString
> const aServiceNames
214 u
"ooo.vba.excel.Name"_ustr
216 return aServiceNames
;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */