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