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
30
31#include <memory>
32#include <utility>
33
34using namespace ::ooo::vba;
35using namespace ::com::sun::star;
36
37ScVbaName::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 ))
46{
47}
48
50{
51}
52
53OUString
55{
56 return mxNamedRange->getName();
57}
58
59void
60ScVbaName::setName( const OUString & rName )
61{
62 mxNamedRange->setName( rName );
63}
64
65OUString
67{
68 return getName();
69}
70
71void
72ScVbaName::setNameLocal( const OUString & rName )
73{
74 setName( rName );
75}
76
79{
80 return true;
81}
82
83void
85{
86}
87
89{
90 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
91 OUString aContent;
92 if ( pNamedRange )
93 {
94 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
95 if (pData)
96 aContent = pData->GetSymbol( eGrammar );
97 }
98 if (aContent.indexOf('=') != 0)
99 aContent = "=" + aContent;
100 return aContent;
101}
102
103void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar )
104{
105 OUString sContent( rContent );
106 if (sContent.startsWith("="))
107 sContent = sContent.copy(1);
108 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
109
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;
114
115 ScDocument& rDoc = pNamedRange->pDocShell->GetDocument();
116 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
117 if (pOldData)
118 {
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);
123 }
124}
125
126OUString
128{
130
131 return sResult;
132}
133
134void
135ScVbaName::setValue( const OUString & rValue )
136{
138}
139
140OUString
142{
143 return getValue();
144}
145
146void
147ScVbaName::setRefersTo( const OUString & rRefersTo )
148{
149 setValue( rRefersTo );
150}
151
152OUString
154{
155 return getRefersTo();
156}
157
158void
159ScVbaName::setRefersToLocal( const OUString & rRefersTo )
160{
161 setRefersTo( rRefersTo );
162}
163
164OUString
166{
168 return sResult;
169}
170
171void
172ScVbaName::setRefersToR1C1( const OUString & rRefersTo )
173{
175}
176
177OUString
179{
180 return getRefersToR1C1();
181}
182
183void
184ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo )
185{
186 setRefersTo( rRefersTo );
187}
188
189css::uno::Reference< ov::excel::XRange >
191{
192 uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
194 return xRange;
195}
196
197void
199{
200 mxNames->removeByName( mxNamedRange->getName() );
201}
202
203OUString
205{
206 return "ScVbaName";
207}
208
209uno::Sequence< OUString >
211{
212 static uno::Sequence< OUString > const aServiceNames
213 {
214 "ooo.vba.excel.Name"
215 };
216 return aServiceNames;
217}
218
219/* 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:4691
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
ScDocShell * pDocShell
Definition: nameuno.hxx:54
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:135
css::uno::Reference< css::sheet::XNamedRange > mxNamedRange
Definition: vbaname.hxx:34
OUString getContent(const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:88
virtual void SAL_CALL setName(const OUString &rName) override
Definition: vbaname.cxx:60
void setContent(const OUString &sContent, const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:103
virtual void SAL_CALL setVisible(sal_Bool bVisible) override
Definition: vbaname.cxx:84
virtual sal_Bool SAL_CALL getVisible() override
Definition: vbaname.cxx:78
virtual OUString SAL_CALL getNameLocal() override
Definition: vbaname.cxx:66
virtual OUString getServiceImplName() override
Definition: vbaname.cxx:204
virtual OUString SAL_CALL getRefersToR1C1Local() override
Definition: vbaname.cxx:178
virtual OUString SAL_CALL getRefersToR1C1() override
Definition: vbaname.cxx:165
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getRefersToRange() override
Definition: vbaname.cxx:190
virtual void SAL_CALL setRefersTo(const OUString &rRefersTo) override
Definition: vbaname.cxx:147
virtual void SAL_CALL Delete() override
Definition: vbaname.cxx:198
virtual OUString SAL_CALL getRefersTo() override
Definition: vbaname.cxx:141
virtual void SAL_CALL setRefersToR1C1Local(const OUString &rRefersTo) override
Definition: vbaname.cxx:184
virtual OUString SAL_CALL getValue() override
Definition: vbaname.cxx:127
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbaname.cxx:210
virtual void SAL_CALL setRefersToLocal(const OUString &rRefersTo) override
Definition: vbaname.cxx:159
virtual ~ScVbaName() override
Definition: vbaname.cxx:49
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaname.hxx:33
virtual OUString SAL_CALL getName() override
Definition: vbaname.cxx:54
virtual void SAL_CALL setRefersToR1C1(const OUString &rRefersTo) override
Definition: vbaname.cxx:172
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:37
css::uno::Reference< css::sheet::XNamedRanges > mxNames
Definition: vbaname.hxx:35
virtual OUString SAL_CALL getRefersToLocal() override
Definition: vbaname.cxx:153
virtual void SAL_CALL setNameLocal(const OUString &rName) override
Definition: vbaname.cxx:72
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:1376
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