1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <osl/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <basic/sbstar.hxx>
30 #include <basic/sbmeth.hxx>
31 #include <basic/sbmod.hxx>
33 #include <util/MiscUtils.hxx>
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::comphelper
;
40 using namespace ::com::sun::star::script
;
41 using namespace ::sf_misc
;
43 #define BASPROV_PROPERTY_ID_URI 1
44 #define BASPROV_PROPERTY_ID_EDITABLE 2
46 #define BASPROV_PROPERTY_URI OUString( "URI" )
47 #define BASPROV_PROPERTY_EDITABLE "Editable"
49 #define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
58 // BasicMethodNodeImpl
61 BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference
< XComponentContext
>& rxContext
,
62 const OUString
& sScriptingContext
, SbMethod
* pMethod
, bool isAppScript
)
63 : ::scripting_helper::OBroadcastHelperHolder( m_aMutex
)
64 ,OPropertyContainer( GetBroadcastHelper() )
65 ,m_xContext( rxContext
)
66 ,m_sScriptingContext( sScriptingContext
)
68 ,m_bIsAppScript( isAppScript
)
73 SbModule
* pModule
= m_pMethod
->GetModule();
76 StarBASIC
* pBasic
= static_cast< StarBASIC
* >( pModule
->GetParent() );
79 m_sURI
= "vnd.sun.star.script:";
80 m_sURI
+= pBasic
->GetName();
82 m_sURI
+= pModule
->GetName();
84 m_sURI
+= m_pMethod
->GetName();
85 m_sURI
+= "?language=Basic&location=";
87 m_sURI
+= "application";
94 registerProperty( BASPROV_PROPERTY_URI
, BASPROV_PROPERTY_ID_URI
, BASPROV_DEFAULT_ATTRIBS(), &m_sURI
, cppu::UnoType
<decltype(m_sURI
)>::get() );
95 registerProperty( BASPROV_PROPERTY_EDITABLE
, BASPROV_PROPERTY_ID_EDITABLE
, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable
, cppu::UnoType
<decltype(m_bEditable
)>::get() );
100 BasicMethodNodeImpl::~BasicMethodNodeImpl()
108 IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl
, BasicMethodNodeImpl_BASE
, OPropertyContainer
)
114 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl
, BasicMethodNodeImpl_BASE
, OPropertyContainer
)
120 OUString
BasicMethodNodeImpl::getName( ) throw (RuntimeException
, std::exception
)
122 SolarMutexGuard aGuard
;
124 OUString sMethodName
;
126 sMethodName
= m_pMethod
->GetName();
133 Sequence
< Reference
< browse::XBrowseNode
> > BasicMethodNodeImpl::getChildNodes( ) throw (RuntimeException
, std::exception
)
135 SolarMutexGuard aGuard
;
137 return Sequence
< Reference
< browse::XBrowseNode
> >();
142 sal_Bool
BasicMethodNodeImpl::hasChildNodes( ) throw (RuntimeException
, std::exception
)
144 SolarMutexGuard aGuard
;
151 sal_Int16
BasicMethodNodeImpl::getType( ) throw (RuntimeException
, std::exception
)
153 SolarMutexGuard aGuard
;
155 return browse::BrowseNodeTypes::SCRIPT
;
159 // OPropertySetHelper
162 ::cppu::IPropertyArrayHelper
& BasicMethodNodeImpl::getInfoHelper( )
164 return *getArrayHelper();
168 // OPropertyArrayUsageHelper
171 ::cppu::IPropertyArrayHelper
* BasicMethodNodeImpl::createArrayHelper( ) const
173 Sequence
< Property
> aProps
;
174 describeProperties( aProps
);
175 return new ::cppu::OPropertyArrayHelper( aProps
);
182 Reference
< XPropertySetInfo
> BasicMethodNodeImpl::getPropertySetInfo( ) throw (RuntimeException
, std::exception
)
184 Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
192 Reference
< XIntrospectionAccess
> BasicMethodNodeImpl::getIntrospection( ) throw (RuntimeException
, std::exception
)
194 return Reference
< XIntrospectionAccess
>();
199 Any
BasicMethodNodeImpl::invoke( const OUString
& aFunctionName
, const Sequence
< Any
>& aParams
,
200 Sequence
< sal_Int16
>& aOutParamIndex
, Sequence
< Any
>& aOutParam
)
201 throw (IllegalArgumentException
, script::CannotConvertException
,
202 reflection::InvocationTargetException
, RuntimeException
, std::exception
)
205 (void)aOutParamIndex
;
208 if ( aFunctionName
== BASPROV_PROPERTY_EDITABLE
)
210 OUString sDocURL
, sLibName
, sModName
;
211 sal_uInt16 nLine1
= 0, nLine2
;
213 if ( !m_bIsAppScript
)
215 Reference
< frame::XModel
> xModel
= MiscUtils::tDocUrlToModel( m_sScriptingContext
);
219 sDocURL
= xModel
->getURL();
220 if ( sDocURL
.isEmpty() )
222 Sequence
< PropertyValue
> aProps
= xModel
->getArgs();
223 sal_Int32 nProps
= aProps
.getLength();
224 const PropertyValue
* pProps
= aProps
.getConstArray();
225 for ( sal_Int32 i
= 0; i
< nProps
; ++i
)
227 // TODO: according to MBA the property 'Title' may change in future
228 if ( pProps
[i
].Name
== "Title" )
230 pProps
[i
].Value
>>= sDocURL
;
240 m_pMethod
->GetLineRange( nLine1
, nLine2
);
241 SbModule
* pModule
= m_pMethod
->GetModule();
244 sModName
= pModule
->GetName();
245 StarBASIC
* pBasic
= static_cast< StarBASIC
* >( pModule
->GetParent() );
247 sLibName
= pBasic
->GetName();
251 if ( m_xContext
.is() )
253 Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create( m_xContext
);
255 Reference
< frame::XDispatchProvider
> xProv( xDesktop
->getCurrentFrame(), UNO_QUERY
);
259 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create( m_xContext
) );
261 Sequence
< PropertyValue
> aArgs(7);
262 aArgs
[0].Name
= "Document";
263 aArgs
[0].Value
<<= sDocURL
;
264 aArgs
[1].Name
= "LibName";
265 aArgs
[1].Value
<<= sLibName
;
266 aArgs
[2].Name
= "Name";
267 aArgs
[2].Value
<<= sModName
;
268 aArgs
[3].Name
= "Type";
269 aArgs
[3].Value
<<= OUString("Module");
270 aArgs
[4].Name
= "Line";
271 aArgs
[4].Value
<<= static_cast< sal_uInt32
>( nLine1
);
272 xHelper
->executeDispatch( xProv
, OUString(".uno:BasicIDEAppear"), OUString(), 0, aArgs
);
278 throw IllegalArgumentException(
279 "BasicMethodNodeImpl::invoke: function name not supported!",
280 Reference
< XInterface
>(), 1 );
288 void BasicMethodNodeImpl::setValue( const OUString
& aPropertyName
, const Any
& aValue
)
289 throw (UnknownPropertyException
, script::CannotConvertException
,
290 reflection::InvocationTargetException
, RuntimeException
, std::exception
)
295 throw UnknownPropertyException(
296 "BasicMethodNodeImpl::setValue: property name is unknown!" );
301 Any
BasicMethodNodeImpl::getValue( const OUString
& aPropertyName
) throw (UnknownPropertyException
, RuntimeException
, std::exception
)
305 throw UnknownPropertyException(
306 "BasicMethodNodeImpl::getValue: property name is unknown!" );
311 sal_Bool
BasicMethodNodeImpl::hasMethod( const OUString
& aName
) throw (RuntimeException
, std::exception
)
313 bool bReturn
= false;
314 if ( aName
== BASPROV_PROPERTY_EDITABLE
)
322 sal_Bool
BasicMethodNodeImpl::hasProperty( const OUString
& aName
) throw (RuntimeException
, std::exception
)
332 } // namespace basprov
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */