Line data Source code
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 : #include <vbahelper/helperdecl.hxx>
20 :
21 : #include <com/sun/star/table/XCellRange.hpp>
22 : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
23 : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
24 :
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"
36 :
37 : #include <boost/scoped_ptr.hpp>
38 :
39 : using namespace ::ooo::vba;
40 : using namespace ::com::sun::star;
41 :
42 12 : 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 12 : mxNames( xNames )
51 : {
52 12 : }
53 :
54 24 : ScVbaName::~ScVbaName()
55 : {
56 24 : }
57 :
58 : OUString
59 3 : ScVbaName::getName() throw (css::uno::RuntimeException, std::exception)
60 : {
61 3 : return mxNamedRange->getName();
62 : }
63 :
64 : void
65 0 : ScVbaName::setName( const OUString & rName ) throw (css::uno::RuntimeException, std::exception)
66 : {
67 0 : mxNamedRange->setName( rName );
68 0 : }
69 :
70 : OUString
71 0 : ScVbaName::getNameLocal() throw (css::uno::RuntimeException, std::exception)
72 : {
73 0 : return getName();
74 : }
75 :
76 : void
77 0 : ScVbaName::setNameLocal( const OUString & rName ) throw (css::uno::RuntimeException, std::exception)
78 : {
79 0 : setName( rName );
80 0 : }
81 :
82 : sal_Bool
83 0 : ScVbaName::getVisible() throw (css::uno::RuntimeException, std::exception)
84 : {
85 0 : return true;
86 : }
87 :
88 : void
89 0 : ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException, std::exception)
90 : {
91 0 : }
92 :
93 7 : OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar, bool bPrependEquals )
94 : {
95 7 : ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
96 7 : OUString aContent;
97 7 : if ( pNamedRange )
98 : {
99 7 : ScRangeData* pData = pNamedRange->GetRangeData_Impl();
100 7 : if (pData)
101 7 : pData->GetSymbol( aContent, eGrammar );
102 : }
103 7 : if ( bPrependEquals )
104 : {
105 7 : if (aContent.indexOf('=') != 0)
106 7 : aContent = "=" + aContent;
107 : }
108 7 : return aContent;
109 : }
110 :
111 1 : void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar, bool bRemoveEquals )
112 : {
113 1 : OUString sContent( rContent );
114 1 : if ( bRemoveEquals )
115 : {
116 1 : if (sContent.startsWith("="))
117 1 : sContent = sContent.copy(1);
118 : }
119 1 : ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
120 :
121 : // We should be able to do the below by just setting calling SetCode on pNamedRange
122 : // right?
123 1 : if ( pNamedRange && pNamedRange->pDocShell )
124 : {
125 :
126 1 : ScDocument& rDoc = pNamedRange->pDocShell->GetDocument();
127 1 : ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
128 1 : if (pOldData)
129 : {
130 : // Shorter way of doing this ?
131 1 : ScCompiler aComp( &rDoc, pOldData->GetPos() );
132 1 : aComp.SetGrammar( eGrammar );
133 2 : boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(sContent));
134 2 : pOldData->SetCode(*pArray);
135 : }
136 1 : }
137 1 : }
138 :
139 : OUString
140 4 : ScVbaName::getValue() throw (css::uno::RuntimeException, std::exception)
141 : {
142 4 : rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
143 :
144 4 : return sResult;
145 : }
146 :
147 : void
148 0 : ScVbaName::setValue( const OUString & rValue ) throw (css::uno::RuntimeException, std::exception)
149 : {
150 0 : setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
151 0 : }
152 :
153 : OUString
154 4 : ScVbaName::getRefersTo() throw (css::uno::RuntimeException, std::exception)
155 : {
156 4 : return getValue();
157 : }
158 :
159 : void
160 0 : ScVbaName::setRefersTo( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
161 : {
162 0 : setValue( rRefersTo );
163 0 : }
164 :
165 : OUString
166 0 : ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException, std::exception)
167 : {
168 0 : return getRefersTo();
169 : }
170 :
171 : void
172 0 : ScVbaName::setRefersToLocal( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
173 : {
174 0 : setRefersTo( rRefersTo );
175 0 : }
176 :
177 : OUString
178 3 : ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException, std::exception)
179 : {
180 3 : rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
181 3 : return sResult;
182 : }
183 :
184 : void
185 1 : ScVbaName::setRefersToR1C1( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
186 : {
187 1 : setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
188 1 : }
189 :
190 : OUString
191 0 : ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException, std::exception)
192 : {
193 0 : return getRefersToR1C1();
194 : }
195 :
196 : void
197 0 : ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo ) throw (css::uno::RuntimeException, std::exception)
198 : {
199 0 : setRefersTo( rRefersTo );
200 0 : }
201 :
202 : css::uno::Reference< ov::excel::XRange >
203 3 : ScVbaName::getRefersToRange() throw (css::uno::RuntimeException, std::exception)
204 : {
205 : uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
206 3 : mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
207 3 : return xRange;
208 : }
209 :
210 : void
211 5 : ScVbaName::Delete() throw (css::uno::RuntimeException, std::exception)
212 : {
213 5 : mxNames->removeByName( mxNamedRange->getName() );
214 5 : }
215 :
216 : OUString
217 0 : ScVbaName::getServiceImplName()
218 : {
219 0 : return OUString( "ScVbaName" );
220 : }
221 :
222 : uno::Sequence< OUString >
223 0 : ScVbaName::getServiceNames()
224 : {
225 0 : static uno::Sequence< OUString > aServiceNames;
226 0 : if ( aServiceNames.getLength() == 0 )
227 : {
228 0 : aServiceNames.realloc( 1 );
229 0 : aServiceNames[ 0 ] = "ooo.vba.excel.Name";
230 : }
231 0 : return aServiceNames;
232 9 : }
233 :
234 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|