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>
27 #include <comphelper/propertyvalue.hxx>
29 #include <vcl/svapp.hxx>
30 #include <basic/sbstar.hxx>
31 #include <basic/sbmeth.hxx>
32 #include <basic/sbmod.hxx>
34 #include <util/MiscUtils.hxx>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::beans
;
40 using namespace ::comphelper
;
41 using namespace ::com::sun::star::script
;
42 using namespace ::sf_misc
;
44 #define BASPROV_PROPERTY_ID_URI 1
45 #define BASPROV_PROPERTY_ID_EDITABLE 2
47 constexpr OUStringLiteral BASPROV_PROPERTY_URI
= u
"URI";
48 constexpr OUString BASPROV_PROPERTY_EDITABLE
= u
"Editable"_ustr
;
50 #define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
57 // BasicMethodNodeImpl
60 BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference
< XComponentContext
>& rxContext
,
61 OUString sScriptingContext
, SbMethod
* pMethod
, bool isAppScript
)
63 m_xContext( rxContext
)
64 ,m_sScriptingContext(std::move( sScriptingContext
))
66 ,m_bIsAppScript( isAppScript
)
71 SbModule
* pModule
= m_pMethod
->GetModule();
74 StarBASIC
* pBasic
= static_cast< StarBASIC
* >( pModule
->GetParent() );
77 m_sURI
= "vnd.sun.star.script:";
78 m_sURI
+= pBasic
->GetName();
80 m_sURI
+= pModule
->GetName();
82 m_sURI
+= m_pMethod
->GetName();
83 m_sURI
+= "?language=Basic&location=";
85 m_sURI
+= "application";
92 registerProperty( BASPROV_PROPERTY_URI
, BASPROV_PROPERTY_ID_URI
, BASPROV_DEFAULT_ATTRIBS(), &m_sURI
, cppu::UnoType
<decltype(m_sURI
)>::get() );
93 registerProperty( BASPROV_PROPERTY_EDITABLE
, BASPROV_PROPERTY_ID_EDITABLE
, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable
, cppu::UnoType
<decltype(m_bEditable
)>::get() );
97 BasicMethodNodeImpl::~BasicMethodNodeImpl()
105 IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl
, BasicMethodNodeImpl_BASE
, comphelper::OPropertyContainer2
)
111 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl
, BasicMethodNodeImpl_BASE
, comphelper::OPropertyContainer2
)
117 OUString
BasicMethodNodeImpl::getName( )
119 SolarMutexGuard aGuard
;
121 OUString sMethodName
;
123 sMethodName
= m_pMethod
->GetName();
129 Sequence
< Reference
< browse::XBrowseNode
> > BasicMethodNodeImpl::getChildNodes( )
131 return Sequence
< Reference
< browse::XBrowseNode
> >();
135 sal_Bool
BasicMethodNodeImpl::hasChildNodes( )
141 sal_Int16
BasicMethodNodeImpl::getType( )
143 return browse::BrowseNodeTypes::SCRIPT
;
147 // OPropertySetHelper
150 ::cppu::IPropertyArrayHelper
& BasicMethodNodeImpl::getInfoHelper( )
152 return *getArrayHelper();
156 // OPropertyArrayUsageHelper
159 ::cppu::IPropertyArrayHelper
* BasicMethodNodeImpl::createArrayHelper( ) const
161 Sequence
< Property
> aProps
;
162 describeProperties( aProps
);
163 return new ::cppu::OPropertyArrayHelper( aProps
);
170 Reference
< XPropertySetInfo
> BasicMethodNodeImpl::getPropertySetInfo( )
172 Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
180 Reference
< XIntrospectionAccess
> BasicMethodNodeImpl::getIntrospection( )
182 return Reference
< XIntrospectionAccess
>();
186 Any
BasicMethodNodeImpl::invoke( const OUString
& aFunctionName
, const Sequence
< Any
>&,
187 Sequence
< sal_Int16
>&, Sequence
< Any
>& )
189 if ( aFunctionName
!= BASPROV_PROPERTY_EDITABLE
)
191 throw IllegalArgumentException(
192 u
"BasicMethodNodeImpl::invoke: function name not supported!"_ustr
,
193 Reference
< XInterface
>(), 1 );
196 OUString sDocURL
, sLibName
, sModName
;
197 sal_uInt16 nLine1
= 0;
199 if ( !m_bIsAppScript
)
201 Reference
< frame::XModel
> xModel
= MiscUtils::tDocUrlToModel( m_sScriptingContext
);
205 sDocURL
= xModel
->getURL();
206 if ( sDocURL
.isEmpty() )
208 const Sequence
< PropertyValue
> aProps
= xModel
->getArgs();
209 // TODO: according to MBA the property 'Title' may change in future
210 const PropertyValue
* pProp
= std::find_if(aProps
.begin(), aProps
.end(),
211 [](const PropertyValue
& rProp
) { return rProp
.Name
== "Title"; });
212 if (pProp
!= aProps
.end())
213 pProp
->Value
>>= sDocURL
;
221 m_pMethod
->GetLineRange( nLine1
, nLine2
);
222 SbModule
* pModule
= m_pMethod
->GetModule();
225 sModName
= pModule
->GetName();
226 StarBASIC
* pBasic
= static_cast< StarBASIC
* >( pModule
->GetParent() );
228 sLibName
= pBasic
->GetName();
232 if ( m_xContext
.is() )
234 Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create( m_xContext
);
236 Reference
< frame::XDispatchProvider
> xProv( xDesktop
->getCurrentFrame(), UNO_QUERY
);
240 Reference
< frame::XDispatchHelper
> xHelper( frame::DispatchHelper::create( m_xContext
) );
242 Sequence
< PropertyValue
> aArgs
{
243 comphelper::makePropertyValue(u
"Document"_ustr
, sDocURL
),
244 comphelper::makePropertyValue(u
"LibName"_ustr
, sLibName
),
245 comphelper::makePropertyValue(u
"Name"_ustr
, sModName
),
246 comphelper::makePropertyValue(u
"Type"_ustr
, u
"Module"_ustr
),
247 comphelper::makePropertyValue(u
"Line"_ustr
, static_cast< sal_uInt32
>( nLine1
))
249 xHelper
->executeDispatch( xProv
, u
".uno:BasicIDEAppear"_ustr
, OUString(), 0, aArgs
);
258 void BasicMethodNodeImpl::setValue( const OUString
&, const Any
& )
260 throw UnknownPropertyException(
261 u
"BasicMethodNodeImpl::setValue: property name is unknown!"_ustr
);
265 Any
BasicMethodNodeImpl::getValue( const OUString
& )
267 throw UnknownPropertyException(
268 u
"BasicMethodNodeImpl::getValue: property name is unknown!"_ustr
);
272 sal_Bool
BasicMethodNodeImpl::hasMethod( const OUString
& aName
)
274 bool bReturn
= false;
275 if ( aName
== BASPROV_PROPERTY_EDITABLE
)
282 sal_Bool
BasicMethodNodeImpl::hasProperty( const OUString
& )
288 } // namespace basprov
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */