fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / source / ui / vba / vbaname.cxx
blob9721b73ed5d2b952d32610aa9e611e166fa0034f
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 using namespace ::ooo::vba;
38 using namespace ::com::sun::star;
40 ScVbaName::ScVbaName(const css::uno::Reference< ov::XHelperInterface >& xParent,
41 const css::uno::Reference< css::uno::XComponentContext >& xContext,
42 const css::uno::Reference< css::sheet::XNamedRange >& xName,
43 const css::uno::Reference< css::sheet::XNamedRanges >& xNames,
44 const css::uno::Reference< css::frame::XModel >& xModel ):
45 NameImpl_BASE( xParent , xContext ),
46 mxModel( xModel ),
47 mxNamedRange( xName ),
48 mxNames( xNames )
52 ScVbaName::~ScVbaName()
56 css::uno::Reference< ov::excel::XWorksheet >
57 ScVbaName::getWorkSheet() throw (css::uno::RuntimeException)
59 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
60 return xApplication->getActiveSheet();
63 OUString
64 ScVbaName::getName() throw (css::uno::RuntimeException)
66 return mxNamedRange->getName();
69 void
70 ScVbaName::setName( const OUString & rName ) throw (css::uno::RuntimeException)
72 mxNamedRange->setName( rName );
75 OUString
76 ScVbaName::getNameLocal() throw (css::uno::RuntimeException)
78 return getName();
81 void
82 ScVbaName::setNameLocal( const OUString & rName ) throw (css::uno::RuntimeException)
84 setName( rName );
87 sal_Bool
88 ScVbaName::getVisible() throw (css::uno::RuntimeException)
90 return true;
93 void
94 ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException)
98 OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar, bool bPrependEquals )
100 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
101 OUString aContent;
102 if ( pNamedRange )
104 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
105 if (pData)
106 pData->GetSymbol( aContent, eGrammar );
108 if ( bPrependEquals )
110 if (aContent.indexOf('=') != 0)
111 aContent = OUString::createFromAscii("=") + aContent;
113 return aContent;
116 void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar, bool bRemoveEquals )
118 OUString sContent( rContent );
119 if ( bRemoveEquals )
121 if (sContent.indexOf('=') == 0)
122 sContent = sContent.copy(1);
124 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
126 // We should be able to do the below by just setting calling SetCode on pNamedRange
127 // right?
128 if ( pNamedRange && pNamedRange->pDocShell )
131 ScDocument* pDoc = pNamedRange->pDocShell->GetDocument();
132 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
133 if (pOldData)
135 // Shorter way of doing this ?
136 ScCompiler aComp( pDoc, pOldData->GetPos() );
137 aComp.SetGrammar( eGrammar );
138 ScTokenArray aArray(*aComp.CompileString( sContent ) );
139 pOldData->SetCode( aArray );
144 OUString
145 ScVbaName::getValue() throw (css::uno::RuntimeException)
147 rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
149 return sResult;
152 void
153 ScVbaName::setValue( const OUString & rValue ) throw (css::uno::RuntimeException)
155 setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
158 OUString
159 ScVbaName::getRefersTo() throw (css::uno::RuntimeException)
161 return getValue();
164 void
165 ScVbaName::setRefersTo( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
167 setValue( rRefersTo );
170 OUString
171 ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException)
173 return getRefersTo();
176 void
177 ScVbaName::setRefersToLocal( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
179 setRefersTo( rRefersTo );
182 OUString
183 ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException)
185 rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
186 return sResult;
189 void
190 ScVbaName::setRefersToR1C1( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
192 setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
195 OUString
196 ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException)
198 return getRefersToR1C1();
201 void
202 ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
204 setRefersTo( rRefersTo );
207 css::uno::Reference< ov::excel::XRange >
208 ScVbaName::getRefersToRange() throw (css::uno::RuntimeException)
210 uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
211 mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
212 return xRange;
215 void
216 ScVbaName::setRefersToRange( const css::uno::Reference< ov::excel::XRange > /*rRange*/ ) throw (css::uno::RuntimeException)
220 void
221 ScVbaName::Delete() throw (css::uno::RuntimeException)
223 mxNames->removeByName( mxNamedRange->getName() );
226 OUString
227 ScVbaName::getServiceImplName()
229 return OUString( "ScVbaName" );
232 uno::Sequence< OUString >
233 ScVbaName::getServiceNames()
235 static uno::Sequence< OUString > aServiceNames;
236 if ( aServiceNames.getLength() == 0 )
238 aServiceNames.realloc( 1 );
239 aServiceNames[ 0 ] = OUString( "ooo.vba.excel.Name" );
241 return aServiceNames;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */