tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbaname.cxx
blob8eb3357e746cc331b72a0573a3fbd2c2354dea0f
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 <comphelper/servicehelper.hxx>
31 #include <memory>
32 #include <utility>
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()
53 OUString
54 ScVbaName::getName()
56 return mxNamedRange->getName();
59 void
60 ScVbaName::setName( const OUString & rName )
62 mxNamedRange->setName( rName );
65 OUString
66 ScVbaName::getNameLocal()
68 return getName();
71 void
72 ScVbaName::setNameLocal( const OUString & rName )
74 setName( rName );
77 sal_Bool
78 ScVbaName::getVisible()
80 return true;
83 void
84 ScVbaName::setVisible( sal_Bool /*bVisible*/ )
88 OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar )
90 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
91 OUString aContent;
92 if ( pNamedRange )
94 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
95 if (pData)
96 aContent = pData->GetSymbol( eGrammar );
98 if (aContent.indexOf('=') != 0)
99 aContent = "=" + aContent;
100 return 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
111 // right?
112 if ( !(pNamedRange && pNamedRange->pDocShell) )
113 return;
115 ScDocument& rDoc = pNamedRange->pDocShell->GetDocument();
116 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
117 if (pOldData)
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);
126 OUString
127 ScVbaName::getValue()
129 OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
131 return sResult;
134 void
135 ScVbaName::setValue( const OUString & rValue )
137 setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
140 OUString
141 ScVbaName::getRefersTo()
143 return getValue();
146 void
147 ScVbaName::setRefersTo( const OUString & rRefersTo )
149 setValue( rRefersTo );
152 OUString
153 ScVbaName::getRefersToLocal()
155 return getRefersTo();
158 void
159 ScVbaName::setRefersToLocal( const OUString & rRefersTo )
161 setRefersTo( rRefersTo );
164 OUString
165 ScVbaName::getRefersToR1C1()
167 OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
168 return sResult;
171 void
172 ScVbaName::setRefersToR1C1( const OUString & rRefersTo )
174 setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
177 OUString
178 ScVbaName::getRefersToR1C1Local()
180 return getRefersToR1C1();
183 void
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 );
194 return xRange;
197 void
198 ScVbaName::Delete()
200 mxNames->removeByName( mxNamedRange->getName() );
203 OUString
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: */