GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / vba / vbaname.cxx
blob903949a582639d051a3bd19146afc55d956c7582
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 .
19 #include <vbahelper/helperdecl.hxx>
21 #include <com/sun/star/table/XCellRange.hpp>
22 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
23 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
25 #include "vbaname.hxx"
26 #include "vbarange.hxx"
27 #include "vbaglobals.hxx"
28 #include <vector>
29 #include <rangenam.hxx>
30 #include <vcl/msgbox.hxx>
31 #include "tabvwsh.hxx"
32 #include "viewdata.hxx"
33 #include "nameuno.hxx"
34 #include "compiler.hxx"
35 #include "tokenarray.hxx"
37 #include <boost/scoped_ptr.hpp>
39 using namespace ::ooo::vba;
40 using namespace ::com::sun::star;
42 ScVbaName::ScVbaName(const css::uno::Reference< ov::XHelperInterface >& xParent,
43 const css::uno::Reference< css::uno::XComponentContext >& xContext,
44 const css::uno::Reference< css::sheet::XNamedRange >& xName,
45 const css::uno::Reference< css::sheet::XNamedRanges >& xNames,
46 const css::uno::Reference< css::frame::XModel >& xModel ):
47 NameImpl_BASE( xParent , xContext ),
48 mxModel( xModel ),
49 mxNamedRange( xName ),
50 mxNames( xNames )
54 ScVbaName::~ScVbaName()
58 css::uno::Reference< ov::excel::XWorksheet >
59 ScVbaName::getWorkSheet() throw (css::uno::RuntimeException)
61 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
62 return xApplication->getActiveSheet();
65 OUString
66 ScVbaName::getName() throw (css::uno::RuntimeException)
68 return mxNamedRange->getName();
71 void
72 ScVbaName::setName( const OUString & rName ) throw (css::uno::RuntimeException)
74 mxNamedRange->setName( rName );
77 OUString
78 ScVbaName::getNameLocal() throw (css::uno::RuntimeException)
80 return getName();
83 void
84 ScVbaName::setNameLocal( const OUString & rName ) throw (css::uno::RuntimeException)
86 setName( rName );
89 sal_Bool
90 ScVbaName::getVisible() throw (css::uno::RuntimeException)
92 return true;
95 void
96 ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException)
100 OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar, bool bPrependEquals )
102 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
103 OUString aContent;
104 if ( pNamedRange )
106 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
107 if (pData)
108 pData->GetSymbol( aContent, eGrammar );
110 if ( bPrependEquals )
112 if (aContent.indexOf('=') != 0)
113 aContent = "=" + aContent;
115 return aContent;
118 void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar, bool bRemoveEquals )
120 OUString sContent( rContent );
121 if ( bRemoveEquals )
123 if (sContent.startsWith("="))
124 sContent = sContent.copy(1);
126 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
128 // We should be able to do the below by just setting calling SetCode on pNamedRange
129 // right?
130 if ( pNamedRange && pNamedRange->pDocShell )
133 ScDocument* pDoc = pNamedRange->pDocShell->GetDocument();
134 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
135 if (pOldData)
137 // Shorter way of doing this ?
138 ScCompiler aComp( pDoc, pOldData->GetPos() );
139 aComp.SetGrammar( eGrammar );
140 boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(sContent));
141 pOldData->SetCode(*pArray);
146 OUString
147 ScVbaName::getValue() throw (css::uno::RuntimeException)
149 rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
151 return sResult;
154 void
155 ScVbaName::setValue( const OUString & rValue ) throw (css::uno::RuntimeException)
157 setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
160 OUString
161 ScVbaName::getRefersTo() throw (css::uno::RuntimeException)
163 return getValue();
166 void
167 ScVbaName::setRefersTo( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
169 setValue( rRefersTo );
172 OUString
173 ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException)
175 return getRefersTo();
178 void
179 ScVbaName::setRefersToLocal( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
181 setRefersTo( rRefersTo );
184 OUString
185 ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException)
187 rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
188 return sResult;
191 void
192 ScVbaName::setRefersToR1C1( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
194 setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
197 OUString
198 ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException)
200 return getRefersToR1C1();
203 void
204 ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
206 setRefersTo( rRefersTo );
209 css::uno::Reference< ov::excel::XRange >
210 ScVbaName::getRefersToRange() throw (css::uno::RuntimeException)
212 uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
213 mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
214 return xRange;
217 void
218 ScVbaName::setRefersToRange( const css::uno::Reference< ov::excel::XRange > /*rRange*/ ) throw (css::uno::RuntimeException)
222 void
223 ScVbaName::Delete() throw (css::uno::RuntimeException)
225 mxNames->removeByName( mxNamedRange->getName() );
228 OUString
229 ScVbaName::getServiceImplName()
231 return OUString( "ScVbaName" );
234 uno::Sequence< OUString >
235 ScVbaName::getServiceNames()
237 static uno::Sequence< OUString > aServiceNames;
238 if ( aServiceNames.getLength() == 0 )
240 aServiceNames.realloc( 1 );
241 aServiceNames[ 0 ] = "ooo.vba.excel.Name";
243 return aServiceNames;
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */