fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbaname.cxx
blob6230344de2927753d4ed31ec96bc7083c144b592
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 OUString
59 ScVbaName::getName() throw (css::uno::RuntimeException, std::exception)
61 return mxNamedRange->getName();
64 void
65 ScVbaName::setName( const OUString & rName ) throw (css::uno::RuntimeException, std::exception)
67 mxNamedRange->setName( rName );
70 OUString
71 ScVbaName::getNameLocal() throw (css::uno::RuntimeException, std::exception)
73 return getName();
76 void
77 ScVbaName::setNameLocal( const OUString & rName ) throw (css::uno::RuntimeException, std::exception)
79 setName( rName );
82 sal_Bool
83 ScVbaName::getVisible() throw (css::uno::RuntimeException, std::exception)
85 return true;
88 void
89 ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException, std::exception)
93 OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar, bool bPrependEquals )
95 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
96 OUString aContent;
97 if ( pNamedRange )
99 ScRangeData* pData = pNamedRange->GetRangeData_Impl();
100 if (pData)
101 pData->GetSymbol( aContent, eGrammar );
103 if ( bPrependEquals )
105 if (aContent.indexOf('=') != 0)
106 aContent = "=" + aContent;
108 return aContent;
111 void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar, bool bRemoveEquals )
113 OUString sContent( rContent );
114 if ( bRemoveEquals )
116 if (sContent.startsWith("="))
117 sContent = sContent.copy(1);
119 ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
121 // We should be able to do the below by just setting calling SetCode on pNamedRange
122 // right?
123 if ( pNamedRange && pNamedRange->pDocShell )
126 ScDocument& rDoc = pNamedRange->pDocShell->GetDocument();
127 ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
128 if (pOldData)
130 // Shorter way of doing this ?
131 ScCompiler aComp( &rDoc, pOldData->GetPos() );
132 aComp.SetGrammar( eGrammar );
133 boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(sContent));
134 pOldData->SetCode(*pArray);
139 OUString
140 ScVbaName::getValue() throw (css::uno::RuntimeException, std::exception)
142 rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
144 return sResult;
147 void
148 ScVbaName::setValue( const OUString & rValue ) throw (css::uno::RuntimeException, std::exception)
150 setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
153 OUString
154 ScVbaName::getRefersTo() throw (css::uno::RuntimeException, std::exception)
156 return getValue();
159 void
160 ScVbaName::setRefersTo( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
162 setValue( rRefersTo );
165 OUString
166 ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException, std::exception)
168 return getRefersTo();
171 void
172 ScVbaName::setRefersToLocal( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
174 setRefersTo( rRefersTo );
177 OUString
178 ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException, std::exception)
180 rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
181 return sResult;
184 void
185 ScVbaName::setRefersToR1C1( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
187 setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
190 OUString
191 ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException, std::exception)
193 return getRefersToR1C1();
196 void
197 ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
199 setRefersTo( rRefersTo );
202 css::uno::Reference< ov::excel::XRange >
203 ScVbaName::getRefersToRange() throw (css::uno::RuntimeException, std::exception)
205 uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
206 mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
207 return xRange;
210 void
211 ScVbaName::Delete() throw (css::uno::RuntimeException, std::exception)
213 mxNames->removeByName( mxNamedRange->getName() );
216 OUString
217 ScVbaName::getServiceImplName()
219 return OUString( "ScVbaName" );
222 uno::Sequence< OUString >
223 ScVbaName::getServiceNames()
225 static uno::Sequence< OUString > aServiceNames;
226 if ( aServiceNames.getLength() == 0 )
228 aServiceNames.realloc( 1 );
229 aServiceNames[ 0 ] = "ooo.vba.excel.Name";
231 return aServiceNames;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */