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  aContent = pData->GetSymbol( 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  return;
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 OUString
125 {
127 
128  return sResult;
129 }
130 
131 void
132 ScVbaName::setValue( const OUString & rValue )
133 {
135 }
136 
137 OUString
139 {
140  return getValue();
141 }
142 
143 void
144 ScVbaName::setRefersTo( const OUString & rRefersTo )
145 {
146  setValue( rRefersTo );
147 }
148 
149 OUString
151 {
152  return getRefersTo();
153 }
154 
155 void
156 ScVbaName::setRefersToLocal( const OUString & rRefersTo )
157 {
158  setRefersTo( rRefersTo );
159 }
160 
161 OUString
163 {
165  return sResult;
166 }
167 
168 void
169 ScVbaName::setRefersToR1C1( const OUString & rRefersTo )
170 {
172 }
173 
174 OUString
176 {
177  return getRefersToR1C1();
178 }
179 
180 void
181 ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo )
182 {
183  setRefersTo( rRefersTo );
184 }
185 
186 css::uno::Reference< ov::excel::XRange >
188 {
189  uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
191  return xRange;
192 }
193 
194 void
196 {
197  mxNames->removeByName( mxNamedRange->getName() );
198 }
199 
200 OUString
202 {
203  return "ScVbaName";
204 }
205 
206 uno::Sequence< OUString >
208 {
209  static uno::Sequence< OUString > const aServiceNames
210  {
211  "ooo.vba.excel.Name"
212  };
213  return aServiceNames;
214 }
215 
216 /* 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:207
virtual void SAL_CALL setRefersTo(const OUString &rRefersTo) override
Definition: vbaname.cxx:144
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:138
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
Definition: rangenam.cxx:606
SC_DLLPUBLIC OUString GetSymbol(const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: rangenam.cxx:243
std::unique_ptr< ContentProperties > pData
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getRefersToRange() override
Definition: vbaname.cxx:187
virtual OUString SAL_CALL getRefersToR1C1() override
Definition: vbaname.cxx:162
virtual void SAL_CALL setValue(const OUString &rValue) override
Definition: vbaname.cxx:132
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:34
css::uno::Reference< css::sheet::XNamedRanges > mxNames
Definition: vbaname.hxx:35
virtual ~ScVbaName() override
Definition: vbaname.cxx:46
virtual OUString getServiceImplName() override
Definition: vbaname.cxx:201
virtual void SAL_CALL setVisible(sal_Bool bVisible) override
Definition: vbaname.cxx:81
ScDocShell * pDocShell
Definition: nameuno.hxx:56
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
virtual sal_Bool SAL_CALL getVisible() override
Definition: vbaname.cxx:75
virtual OUString SAL_CALL getRefersToLocal() override
Definition: vbaname.cxx:150
virtual void SAL_CALL setRefersToLocal(const OUString &rRefersTo) override
Definition: vbaname.cxx:156
unsigned char sal_Bool
virtual OUString SAL_CALL getValue() override
Definition: vbaname.cxx:124
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:1363
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaname.hxx:33
void setContent(const OUString &sContent, const formula::FormulaGrammar::Grammar eGrammar)
Definition: vbaname.cxx:100
virtual void SAL_CALL Delete() override
Definition: vbaname.cxx:195
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:113
css::uno::Reference< css::uno::XComponentContext > mxContext
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
virtual OUString SAL_CALL getRefersToR1C1Local() override
Definition: vbaname.cxx:175
virtual void SAL_CALL setRefersToR1C1Local(const OUString &rRefersTo) override
Definition: vbaname.cxx:181
virtual void SAL_CALL setRefersToR1C1(const OUString &rRefersTo) override
Definition: vbaname.cxx:169