nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / ui / vba / vbaname.cxx
blob5f923da844dd07211167fe84c0ca05118e091d65
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include <docsh.hxx>
24 #include <rangenam.hxx>
25 #include <nameuno.hxx>
26 #include <compiler.hxx>
27 #include <tokenarray.hxx>
29 #include <memory>
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 ),
40 mxModel( xModel ),
41 mxNamedRange( xName ),
42 mxNames( xNames )
46 ScVbaName::~ScVbaName()
50 OUString
51 ScVbaName::getName()
53 return mxNamedRange->getName();
56 void
57 ScVbaName::setName( const OUString & rName )
59 mxNamedRange->setName( rName );
62 OUString
63 ScVbaName::getNameLocal()
65 return getName();
68 void
69 ScVbaName::setNameLocal( const OUString & rName )
71 setName( rName );
74 sal_Bool
75 ScVbaName::getVisible()
77 return true;
80 void
81 ScVbaName::setVisible( sal_Bool /*bVisible*/ )
85 OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar )
87 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
88 OUString aContent;
89 if ( pNamedRange )
91 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
92 if (pData)
93 pData->GetSymbol( aContent, eGrammar );
95 if (aContent.indexOf('=') != 0)
96 aContent = "=" + aContent;
97 return 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
108 // right?
109 if ( !(pNamedRange && pNamedRange->pDocShell) )
110 return;
112 ScDocument& rDoc = pNamedRange->pDocShell->GetDocument();
113 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
114 if (pOldData)
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);
123 OUString
124 ScVbaName::getValue()
126 OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
128 return sResult;
131 void
132 ScVbaName::setValue( const OUString & rValue )
134 setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
137 OUString
138 ScVbaName::getRefersTo()
140 return getValue();
143 void
144 ScVbaName::setRefersTo( const OUString & rRefersTo )
146 setValue( rRefersTo );
149 OUString
150 ScVbaName::getRefersToLocal()
152 return getRefersTo();
155 void
156 ScVbaName::setRefersToLocal( const OUString & rRefersTo )
158 setRefersTo( rRefersTo );
161 OUString
162 ScVbaName::getRefersToR1C1()
164 OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
165 return sResult;
168 void
169 ScVbaName::setRefersToR1C1( const OUString & rRefersTo )
171 setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
174 OUString
175 ScVbaName::getRefersToR1C1Local()
177 return getRefersToR1C1();
180 void
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 );
191 return xRange;
194 void
195 ScVbaName::Delete()
197 mxNames->removeByName( mxNamedRange->getName() );
200 OUString
201 ScVbaName::getServiceImplName()
203 return "ScVbaName";
206 uno::Sequence< OUString >
207 ScVbaName::getServiceNames()
209 static uno::Sequence< OUString > const aServiceNames
211 "ooo.vba.excel.Name"
213 return aServiceNames;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */