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/script/browse/BrowseNodeTypes.hpp>
26 #include <vcl/svapp.hxx>
27 #include <basic/sbstar.hxx>
28 #include <basic/sbmeth.hxx>
29 #include <basic/sbmod.hxx>
31 #include <util/MiscUtils.hxx>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::comphelper
;
38 using namespace ::com::sun::star::script
;
39 using namespace ::sf_misc
;
41 #define BASPROV_PROPERTY_ID_URI 1
42 #define BASPROV_PROPERTY_ID_EDITABLE 2
44 #define BASPROV_PROPERTY_URI "URI"
45 #define BASPROV_PROPERTY_EDITABLE "Editable"
47 #define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
54 // BasicMethodNodeImpl
57 BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference
< XComponentContext
>& rxContext
,
58 const OUString
& sScriptingContext
, SbMethod
* pMethod
, bool isAppScript
)
59 : ::scripting_helper::OBroadcastHelperHolder( m_aMutex
)
60 ,OPropertyContainer( GetBroadcastHelper() )
61 ,m_xContext( rxContext
)
62 ,m_sScriptingContext( sScriptingContext
)
64 ,m_bIsAppScript( isAppScript
)
69 SbModule
* pModule
= m_pMethod
->GetModule();
72 StarBASIC
* pBasic
= static_cast< StarBASIC
* >( pModule
->GetParent() );
75 m_sURI
= "vnd.sun.star.script:";
76 m_sURI
+= pBasic
->GetName();
78 m_sURI
+= pModule
->GetName();
80 m_sURI
+= m_pMethod
->GetName();
81 m_sURI
+= "?language=Basic&location=";
83 m_sURI
+= "application";
90 registerProperty( BASPROV_PROPERTY_URI
, BASPROV_PROPERTY_ID_URI
, BASPROV_DEFAULT_ATTRIBS(), &m_sURI
, cppu::UnoType
<decltype(m_sURI
)>::get() );
91 registerProperty( BASPROV_PROPERTY_EDITABLE
, BASPROV_PROPERTY_ID_EDITABLE
, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable
, cppu::UnoType
<decltype(m_bEditable
)>::get() );
95 BasicMethodNodeImpl::~BasicMethodNodeImpl()
103 IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl
, BasicMethodNodeImpl_BASE
, OPropertyContainer
)
109 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl
, BasicMethodNodeImpl_BASE
, OPropertyContainer
)
115 OUString
BasicMethodNodeImpl::getName( )
117 SolarMutexGuard aGuard
;
119 OUString sMethodName
;
121 sMethodName
= m_pMethod
->GetName();
127 Sequence
< Reference
< browse::XBrowseNode
> > BasicMethodNodeImpl::getChildNodes( )
129 return Sequence
< Reference
< browse::XBrowseNode
> >();
133 sal_Bool
BasicMethodNodeImpl::hasChildNodes( )
139 sal_Int16
BasicMethodNodeImpl::getType( )
141 return browse::BrowseNodeTypes::SCRIPT
;
145 // OPropertySetHelper
148 ::cppu::IPropertyArrayHelper
& BasicMethodNodeImpl::getInfoHelper( )
150 return *getArrayHelper();
154 // OPropertyArrayUsageHelper
157 ::cppu::IPropertyArrayHelper
* BasicMethodNodeImpl::createArrayHelper( ) const
159 Sequence
< Property
> aProps
;
160 describeProperties( aProps
);
161 return new ::cppu::OPropertyArrayHelper( aProps
);
168 Reference
< XPropertySetInfo
> BasicMethodNodeImpl::getPropertySetInfo( )
170 Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
178 Reference
< XIntrospectionAccess
> BasicMethodNodeImpl::getIntrospection( )
180 return Reference
< XIntrospectionAccess
>();
184 Any
BasicMethodNodeImpl::invoke( const OUString
& aFunctionName
, const Sequence
< Any
>&,
185 Sequence
< sal_Int16
>&, Sequence
< Any
>& )
187 if ( aFunctionName
!= BASPROV_PROPERTY_EDITABLE
)
189 throw IllegalArgumentException(
190 "BasicMethodNodeImpl::invoke: function name not supported!",
191 Reference
< XInterface
>(), 1 );
194 OUString sDocURL
, sLibName
, sModName
;
195 sal_uInt16 nLine1
= 0;
197 if ( !m_bIsAppScript
)
199 Reference
< frame::XModel
> xModel
= MiscUtils::tDocUrlToModel( m_sScriptingContext
);
203 sDocURL
= xModel
->getURL();
204 if ( sDocURL
.isEmpty() )
206 Sequence
< PropertyValue
> aProps
= xModel
->getArgs();
207 // TODO: according to MBA the property 'Title' may change in future
208 const PropertyValue
* pProp
= std::find_if(aProps
.begin(), aProps
.end(),
209 [](const PropertyValue
& rProp
) { return rProp
.Name
== "Title"; });
210 if (pProp
!= aProps
.end())
211 pProp
->Value
>>= sDocURL
;
219 m_pMethod
->GetLineRange( nLine1
, nLine2
);
220 SbModule
* pModule
= m_pMethod
->GetModule();
223 sModName
= pModule
->GetName();
224 StarBASIC
* pBasic
= static_cast< StarBASIC
* >( pModule
->GetParent() );
226 sLibName
= pBasic
->GetName();
230 if ( m_xContext
.is() )
232 Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create( m_xContext
);
234 Reference
< frame::XDispatchProvider
> xProv( xDesktop
->getCurrentFrame(), UNO_QUERY
);
238 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create( m_xContext
) );
240 Sequence
< PropertyValue
> aArgs(7);
241 aArgs
[0].Name
= "Document";
242 aArgs
[0].Value
<<= sDocURL
;
243 aArgs
[1].Name
= "LibName";
244 aArgs
[1].Value
<<= sLibName
;
245 aArgs
[2].Name
= "Name";
246 aArgs
[2].Value
<<= sModName
;
247 aArgs
[3].Name
= "Type";
248 aArgs
[3].Value
<<= OUString("Module");
249 aArgs
[4].Name
= "Line";
250 aArgs
[4].Value
<<= static_cast< sal_uInt32
>( nLine1
);
251 xHelper
->executeDispatch( xProv
, ".uno:BasicIDEAppear", OUString(), 0, aArgs
);
260 void BasicMethodNodeImpl::setValue( const OUString
&, const Any
& )
262 throw UnknownPropertyException(
263 "BasicMethodNodeImpl::setValue: property name is unknown!" );
267 Any
BasicMethodNodeImpl::getValue( const OUString
& )
269 throw UnknownPropertyException(
270 "BasicMethodNodeImpl::getValue: property name is unknown!" );
274 sal_Bool
BasicMethodNodeImpl::hasMethod( const OUString
& aName
)
276 bool bReturn
= false;
277 if ( aName
== BASPROV_PROPERTY_EDITABLE
)
284 sal_Bool
BasicMethodNodeImpl::hasProperty( const OUString
& )
290 } // namespace basprov
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */