LibreOffice Module sc (master) 1
vbaname.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 "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>
28
29#include <memory>
30#include <utility>
31
32using namespace ::ooo::vba;
33using namespace ::com::sun::star;
34
35ScVbaName::ScVbaName(const css::uno::Reference< ov::XHelperInterface >& xParent,
36 const css::uno::Reference< css::uno::XComponentContext >& xContext,
37 css::uno::Reference< css::sheet::XNamedRange > xName,
38 css::uno::Reference< css::sheet::XNamedRanges > xNames,
39 css::uno::Reference< css::frame::XModel > xModel ):
40 NameImpl_BASE( xParent , xContext ),
41 mxModel(std::move( xModel )),
42 mxNamedRange(std::move( xName )),
43 mxNames(std::move( xNames ))
44{
45}
46
48{
49}
50
51OUString
53{
54 return mxNamedRange->getName();
55}
56
57void
58ScVbaName::setName( const OUString & rName )
59{
60 mxNamedRange->setName( rName );
61}
62
63OUString
65{
66 return getName();
67}
68
69void
70ScVbaName::setNameLocal( const OUString & rName )
71{
72 setName( rName );
73}
74
77{
78 return true;
79}
80
81void
83{
84}
85
87{
88 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
89 OUString aContent;
90 if ( pNamedRange )
91 {
92 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
93 if (pData)
94 aContent = pData->GetSymbol( eGrammar );
95 }
96 if (aContent.indexOf('=') != 0)
97 aContent = "=" + aContent;
98 return aContent;
99}
100
101void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar )
102{
103 OUString sContent( rContent );
104 if (sContent.startsWith("="))
105 sContent = sContent.copy(1);
106 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
107
108 // We should be able to do the below by just setting calling SetCode on pNamedRange
109 // right?
110 if ( !(pNamedRange && pNamedRange->pDocShell) )
111 return;
112
113 ScDocument& rDoc = pNamedRange->pDocShell->GetDocument();
114 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
115 if (pOldData)
116 {
117 // Shorter way of doing this ?
118 ScCompiler aComp( rDoc, pOldData->GetPos(), eGrammar );
119 std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(sContent));
120 pOldData->SetCode(*pArray);
121 }
122}
123
124OUString
126{
128
129 return sResult;
130}
131
132void
133ScVbaName::setValue( const OUString & rValue )
134{
136}
137
138OUString
140{
141 return getValue();
142}
143
144void
145ScVbaName::setRefersTo( const OUString & rRefersTo )
146{
147 setValue( rRefersTo );
148}
149
150OUString
152{
153 return getRefersTo();
154}
155
156void
157ScVbaName::setRefersToLocal( const OUString & rRefersTo )
158{
159 setRefersTo( rRefersTo );
160}
161
162OUString
164{
166 return sResult;
167}
168
169void
170ScVbaName::setRefersToR1C1( const OUString & rRefersTo )
171{
173}
174
175OUString
177{
178 return getRefersToR1C1();
179}
180
181void
182ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo )
183{
184 setRefersTo( rRefersTo );
185}
186
187css::uno::Reference< ov::excel::XRange >
189{
190 uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
192 return xRange;
193}
194
195void
197{
198 mxNames->removeByName( mxNamedRange->getName() );
199}
200
201OUString
203{
204 return "ScVbaName";
205}
206
207uno::Sequence< OUString >
209{
210 static uno::Sequence< OUString > const aServiceNames
211 {
212 "ooo.vba.excel.Name"
213 };
214 return aServiceNames;
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
Definition: compiler.cxx:4687
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
ScDocShell * pDocShell
Definition: nameuno.hxx:56
ScRangeData * GetRangeData_Impl()
Definition: nameuno.cxx:112
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
Definition: rangenam.cxx:621
const ScAddress & GetPos() const
Definition: rangenam.hxx:113
virtual void SAL_CALL setValue(const OUString &rValue) override
Definition: vbaname.cxx:133
css::uno::Reference< css::sheet::XNamedRange > mxNamedRange
Definition: vbaname.hxx:34
OUString getContent(const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:86
virtual void SAL_CALL setName(const OUString &rName) override
Definition: vbaname.cxx:58
void setContent(const OUString &sContent, const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:101
virtual void SAL_CALL setVisible(sal_Bool bVisible) override
Definition: vbaname.cxx:82
virtual sal_Bool SAL_CALL getVisible() override
Definition: vbaname.cxx:76
virtual OUString SAL_CALL getNameLocal() override
Definition: vbaname.cxx:64
virtual OUString getServiceImplName() override
Definition: vbaname.cxx:202
virtual OUString SAL_CALL getRefersToR1C1Local() override
Definition: vbaname.cxx:176
virtual OUString SAL_CALL getRefersToR1C1() override
Definition: vbaname.cxx:163
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getRefersToRange() override
Definition: vbaname.cxx:188
virtual void SAL_CALL setRefersTo(const OUString &rRefersTo) override
Definition: vbaname.cxx:145
virtual void SAL_CALL Delete() override
Definition: vbaname.cxx:196
virtual OUString SAL_CALL getRefersTo() override
Definition: vbaname.cxx:139
virtual void SAL_CALL setRefersToR1C1Local(const OUString &rRefersTo) override
Definition: vbaname.cxx:182
virtual OUString SAL_CALL getValue() override
Definition: vbaname.cxx:125
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbaname.cxx:208
virtual void SAL_CALL setRefersToLocal(const OUString &rRefersTo) override
Definition: vbaname.cxx:157
virtual ~ScVbaName() override
Definition: vbaname.cxx:47
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaname.hxx:33
virtual OUString SAL_CALL getName() override
Definition: vbaname.cxx:52
virtual void SAL_CALL setRefersToR1C1(const OUString &rRefersTo) override
Definition: vbaname.cxx:170
ScVbaName(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::sheet::XNamedRange > xName, css::uno::Reference< css::sheet::XNamedRanges > xNames, css::uno::Reference< css::frame::XModel > xModel)
Definition: vbaname.cxx:35
css::uno::Reference< css::sheet::XNamedRanges > mxNames
Definition: vbaname.hxx:35
virtual OUString SAL_CALL getRefersToLocal() override
Definition: vbaname.cxx:151
virtual void SAL_CALL setNameLocal(const OUString &rName) override
Definition: vbaname.cxx:70
static css::uno::Reference< ov::excel::XRange > getRangeObjectForName(const css::uno::Reference< css::uno::XComponentContext > &xContext, const OUString &sRangeName, ScDocShell *pDocSh, formula::FormulaGrammar::AddressConvention eConv)
Definition: vbarange.cxx:1374
Sequence< OUString > aServiceNames
std::unique_ptr< sal_Int32[]> pData
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
Reference< XModel > xModel
unsigned char sal_Bool