bump product version to 6.3.0.0.beta1
[LibreOffice.git] / scripting / source / basprov / basmethnode.cxx
bloba0104f260950d9a41f06af08eab1e0c04fc00fb5
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 .
20 #include "basmethnode.hxx"
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <com/sun/star/frame/DispatchHelper.hpp>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/frame/XDispatchProvider.hpp>
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
27 #include <vcl/svapp.hxx>
28 #include <basic/sbstar.hxx>
29 #include <basic/sbmeth.hxx>
30 #include <basic/sbmod.hxx>
32 #include <util/MiscUtils.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::comphelper;
39 using namespace ::com::sun::star::script;
40 using namespace ::sf_misc;
42 #define BASPROV_PROPERTY_ID_URI 1
43 #define BASPROV_PROPERTY_ID_EDITABLE 2
45 #define BASPROV_PROPERTY_URI "URI"
46 #define BASPROV_PROPERTY_EDITABLE "Editable"
48 #define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
51 namespace basprov
55 // BasicMethodNodeImpl
58 BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference< XComponentContext >& rxContext,
59 const OUString& sScriptingContext, SbMethod* pMethod, bool isAppScript )
60 : ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
61 ,OPropertyContainer( GetBroadcastHelper() )
62 ,m_xContext( rxContext )
63 ,m_sScriptingContext( sScriptingContext )
64 ,m_pMethod( pMethod )
65 ,m_bIsAppScript( isAppScript )
66 ,m_bEditable( true )
68 if ( m_pMethod )
70 SbModule* pModule = m_pMethod->GetModule();
71 if ( pModule )
73 StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
74 if ( pBasic )
76 m_sURI = "vnd.sun.star.script:";
77 m_sURI += pBasic->GetName();
78 m_sURI += ".";
79 m_sURI += pModule->GetName();
80 m_sURI += ".";
81 m_sURI += m_pMethod->GetName();
82 m_sURI += "?language=Basic&location=";
83 if ( m_bIsAppScript )
84 m_sURI += "application";
85 else
86 m_sURI += "document";
91 registerProperty( BASPROV_PROPERTY_URI, BASPROV_PROPERTY_ID_URI, BASPROV_DEFAULT_ATTRIBS(), &m_sURI, cppu::UnoType<decltype(m_sURI)>::get() );
92 registerProperty( BASPROV_PROPERTY_EDITABLE, BASPROV_PROPERTY_ID_EDITABLE, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable, cppu::UnoType<decltype(m_bEditable)>::get() );
96 BasicMethodNodeImpl::~BasicMethodNodeImpl()
101 // XInterface
104 IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
107 // XTypeProvider
110 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
113 // XBrowseNode
116 OUString BasicMethodNodeImpl::getName( )
118 SolarMutexGuard aGuard;
120 OUString sMethodName;
121 if ( m_pMethod )
122 sMethodName = m_pMethod->GetName();
124 return sMethodName;
128 Sequence< Reference< browse::XBrowseNode > > BasicMethodNodeImpl::getChildNodes( )
130 return Sequence< Reference< browse::XBrowseNode > >();
134 sal_Bool BasicMethodNodeImpl::hasChildNodes( )
136 return false;
140 sal_Int16 BasicMethodNodeImpl::getType( )
142 return browse::BrowseNodeTypes::SCRIPT;
146 // OPropertySetHelper
149 ::cppu::IPropertyArrayHelper& BasicMethodNodeImpl::getInfoHelper( )
151 return *getArrayHelper();
155 // OPropertyArrayUsageHelper
158 ::cppu::IPropertyArrayHelper* BasicMethodNodeImpl::createArrayHelper( ) const
160 Sequence< Property > aProps;
161 describeProperties( aProps );
162 return new ::cppu::OPropertyArrayHelper( aProps );
166 // XPropertySet
169 Reference< XPropertySetInfo > BasicMethodNodeImpl::getPropertySetInfo( )
171 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
172 return xInfo;
176 // XInvocation
179 Reference< XIntrospectionAccess > BasicMethodNodeImpl::getIntrospection( )
181 return Reference< XIntrospectionAccess >();
185 Any BasicMethodNodeImpl::invoke( const OUString& aFunctionName, const Sequence< Any >&,
186 Sequence< sal_Int16 >&, Sequence< Any >& )
188 if ( aFunctionName != BASPROV_PROPERTY_EDITABLE )
190 throw IllegalArgumentException(
191 "BasicMethodNodeImpl::invoke: function name not supported!",
192 Reference< XInterface >(), 1 );
195 OUString sDocURL, sLibName, sModName;
196 sal_uInt16 nLine1 = 0, nLine2;
198 if ( !m_bIsAppScript )
200 Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext );
202 if ( xModel.is() )
204 sDocURL = xModel->getURL();
205 if ( sDocURL.isEmpty() )
207 Sequence < PropertyValue > aProps = xModel->getArgs();
208 sal_Int32 nProps = aProps.getLength();
209 const PropertyValue* pProps = aProps.getConstArray();
210 for ( sal_Int32 i = 0; i < nProps; ++i )
212 // TODO: according to MBA the property 'Title' may change in future
213 if ( pProps[i].Name == "Title" )
215 pProps[i].Value >>= sDocURL;
216 break;
223 if ( m_pMethod )
225 m_pMethod->GetLineRange( nLine1, nLine2 );
226 SbModule* pModule = m_pMethod->GetModule();
227 if ( pModule )
229 sModName = pModule->GetName();
230 StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
231 if ( pBasic )
232 sLibName = pBasic->GetName();
236 if ( m_xContext.is() )
238 Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
240 Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY );
242 if ( xProv.is() )
244 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create( m_xContext ) );
246 Sequence < PropertyValue > aArgs(7);
247 aArgs[0].Name = "Document";
248 aArgs[0].Value <<= sDocURL;
249 aArgs[1].Name = "LibName";
250 aArgs[1].Value <<= sLibName;
251 aArgs[2].Name = "Name";
252 aArgs[2].Value <<= sModName;
253 aArgs[3].Name = "Type";
254 aArgs[3].Value <<= OUString("Module");
255 aArgs[4].Name = "Line";
256 aArgs[4].Value <<= static_cast< sal_uInt32 >( nLine1 );
257 xHelper->executeDispatch( xProv, ".uno:BasicIDEAppear", OUString(), 0, aArgs );
262 return Any();
266 void BasicMethodNodeImpl::setValue( const OUString&, const Any& )
268 throw UnknownPropertyException(
269 "BasicMethodNodeImpl::setValue: property name is unknown!" );
273 Any BasicMethodNodeImpl::getValue( const OUString& )
275 throw UnknownPropertyException(
276 "BasicMethodNodeImpl::getValue: property name is unknown!" );
280 sal_Bool BasicMethodNodeImpl::hasMethod( const OUString& aName )
282 bool bReturn = false;
283 if ( aName == BASPROV_PROPERTY_EDITABLE )
284 bReturn = true;
286 return bReturn;
290 sal_Bool BasicMethodNodeImpl::hasProperty( const OUString& )
292 return false;
296 } // namespace basprov
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */