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>
31 using namespace ::ooo::vba
;
32 using namespace ::com::sun::star
;
34 ScVbaName::ScVbaName(const css::uno::Reference
< ov::XHelperInterface
>& xParent
,
35 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
36 const css::uno::Reference
< css::sheet::XNamedRange
>& xName
,
37 const css::uno::Reference
< css::sheet::XNamedRanges
>& xNames
,
38 const css::uno::Reference
< css::frame::XModel
>& xModel
):
39 NameImpl_BASE( xParent
, xContext
),
41 mxNamedRange( xName
),
46 ScVbaName::~ScVbaName()
53 return mxNamedRange
->getName();
57 ScVbaName::setName( const OUString
& rName
)
59 mxNamedRange
->setName( rName
);
63 ScVbaName::getNameLocal()
69 ScVbaName::setNameLocal( const OUString
& rName
)
75 ScVbaName::getVisible()
81 ScVbaName::setVisible( sal_Bool
/*bVisible*/ )
85 OUString
ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar
)
87 ScNamedRangeObj
* pNamedRange
= dynamic_cast< ScNamedRangeObj
* >( mxNamedRange
.get() );
91 ScRangeData
* pData
= pNamedRange
->GetRangeData_Impl();
93 pData
->GetSymbol( aContent
, eGrammar
);
95 if (aContent
.indexOf('=') != 0)
96 aContent
= "=" + aContent
;
100 void ScVbaName::setContent( const OUString
& rContent
, const formula::FormulaGrammar::Grammar eGrammar
)
102 OUString
sContent( rContent
);
103 if (sContent
.startsWith("="))
104 sContent
= sContent
.copy(1);
105 ScNamedRangeObj
* pNamedRange
= dynamic_cast< ScNamedRangeObj
* >( mxNamedRange
.get() );
107 // We should be able to do the below by just setting calling SetCode on pNamedRange
109 if ( !(pNamedRange
&& pNamedRange
->pDocShell
) )
112 ScDocument
& rDoc
= pNamedRange
->pDocShell
->GetDocument();
113 ScRangeData
* pOldData
= pNamedRange
->GetRangeData_Impl();
116 // Shorter way of doing this ?
117 ScCompiler
aComp( rDoc
, pOldData
->GetPos(), eGrammar
);
118 std::unique_ptr
<ScTokenArray
> pArray(aComp
.CompileString(sContent
));
119 pOldData
->SetCode(*pArray
);
124 ScVbaName::getValue()
126 OUString sResult
= getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1
);
132 ScVbaName::setValue( const OUString
& rValue
)
134 setContent( rValue
, formula::FormulaGrammar::GRAM_NATIVE_XL_A1
);
138 ScVbaName::getRefersTo()
144 ScVbaName::setRefersTo( const OUString
& rRefersTo
)
146 setValue( rRefersTo
);
150 ScVbaName::getRefersToLocal()
152 return getRefersTo();
156 ScVbaName::setRefersToLocal( const OUString
& rRefersTo
)
158 setRefersTo( rRefersTo
);
162 ScVbaName::getRefersToR1C1()
164 OUString sResult
= getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1
);
169 ScVbaName::setRefersToR1C1( const OUString
& rRefersTo
)
171 setContent( rRefersTo
, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1
);
175 ScVbaName::getRefersToR1C1Local()
177 return getRefersToR1C1();
181 ScVbaName::setRefersToR1C1Local( const OUString
& rRefersTo
)
183 setRefersTo( rRefersTo
);
186 css::uno::Reference
< ov::excel::XRange
>
187 ScVbaName::getRefersToRange()
189 uno::Reference
< ov::excel::XRange
> xRange
= ScVbaRange::getRangeObjectForName(
190 mxContext
, mxNamedRange
->getName(), excel::getDocShell( mxModel
), formula::FormulaGrammar::CONV_XL_R1C1
);
197 mxNames
->removeByName( mxNamedRange
->getName() );
201 ScVbaName::getServiceImplName()
206 uno::Sequence
< OUString
>
207 ScVbaName::getServiceNames()
209 static uno::Sequence
< OUString
> const aServiceNames
213 return aServiceNames
;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */