LibreOffice Module scripting (master) 1
basmethnode.cxx
Go to the documentation of this file.
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
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
28#include <utility>
29#include <vcl/svapp.hxx>
30#include <basic/sbstar.hxx>
31#include <basic/sbmeth.hxx>
32#include <basic/sbmod.hxx>
33
34#include <util/MiscUtils.hxx>
35
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::lang;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::beans;
40using namespace ::comphelper;
41using namespace ::com::sun::star::script;
42using namespace ::sf_misc;
43
44#define BASPROV_PROPERTY_ID_URI 1
45#define BASPROV_PROPERTY_ID_EDITABLE 2
46
47constexpr OUStringLiteral BASPROV_PROPERTY_URI = u"URI";
48constexpr OUStringLiteral BASPROV_PROPERTY_EDITABLE = u"Editable";
49
50#define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
51
52
53namespace basprov
54{
55
56
57 // BasicMethodNodeImpl
58
59
60 BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference< XComponentContext >& rxContext,
61 OUString sScriptingContext, SbMethod* pMethod, bool isAppScript )
62 : ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
63 ,OPropertyContainer( GetBroadcastHelper() )
64 ,m_xContext( rxContext )
65 ,m_sScriptingContext(std::move( sScriptingContext ))
66 ,m_pMethod( pMethod )
67 ,m_bIsAppScript( isAppScript )
68 ,m_bEditable( true )
69 {
70 if ( m_pMethod )
71 {
72 SbModule* pModule = m_pMethod->GetModule();
73 if ( pModule )
74 {
75 StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
76 if ( pBasic )
77 {
78 m_sURI = "vnd.sun.star.script:";
79 m_sURI += pBasic->GetName();
80 m_sURI += ".";
81 m_sURI += pModule->GetName();
82 m_sURI += ".";
84 m_sURI += "?language=Basic&location=";
85 if ( m_bIsAppScript )
86 m_sURI += "application";
87 else
88 m_sURI += "document";
89 }
90 }
91 }
92
95 }
96
97
99 {
100 }
101
102
103 // XInterface
104
105
107
108
109 // XTypeProvider
110
111
113
114
115 // XBrowseNode
116
117
118 OUString BasicMethodNodeImpl::getName( )
119 {
120 SolarMutexGuard aGuard;
121
122 OUString sMethodName;
123 if ( m_pMethod )
124 sMethodName = m_pMethod->GetName();
125
126 return sMethodName;
127 }
128
129
130 Sequence< Reference< browse::XBrowseNode > > BasicMethodNodeImpl::getChildNodes( )
131 {
132 return Sequence< Reference< browse::XBrowseNode > >();
133 }
134
135
137 {
138 return false;
139 }
140
141
143 {
144 return browse::BrowseNodeTypes::SCRIPT;
145 }
146
147
148 // OPropertySetHelper
149
150
152 {
153 return *getArrayHelper();
154 }
155
156
157 // OPropertyArrayUsageHelper
158
159
161 {
162 Sequence< Property > aProps;
163 describeProperties( aProps );
164 return new ::cppu::OPropertyArrayHelper( aProps );
165 }
166
167
168 // XPropertySet
169
170
171 Reference< XPropertySetInfo > BasicMethodNodeImpl::getPropertySetInfo( )
172 {
173 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
174 return xInfo;
175 }
176
177
178 // XInvocation
179
180
181 Reference< XIntrospectionAccess > BasicMethodNodeImpl::getIntrospection( )
182 {
183 return Reference< XIntrospectionAccess >();
184 }
185
186
187 Any BasicMethodNodeImpl::invoke( const OUString& aFunctionName, const Sequence< Any >&,
188 Sequence< sal_Int16 >&, Sequence< Any >& )
189 {
190 if ( aFunctionName != BASPROV_PROPERTY_EDITABLE )
191 {
192 throw IllegalArgumentException(
193 "BasicMethodNodeImpl::invoke: function name not supported!",
194 Reference< XInterface >(), 1 );
195 }
196
197 OUString sDocURL, sLibName, sModName;
198 sal_uInt16 nLine1 = 0;
199
200 if ( !m_bIsAppScript )
201 {
202 Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext );
203
204 if ( xModel.is() )
205 {
206 sDocURL = xModel->getURL();
207 if ( sDocURL.isEmpty() )
208 {
209 const Sequence < PropertyValue > aProps = xModel->getArgs();
210 // TODO: according to MBA the property 'Title' may change in future
211 const PropertyValue* pProp = std::find_if(aProps.begin(), aProps.end(),
212 [](const PropertyValue& rProp) { return rProp.Name == "Title"; });
213 if (pProp != aProps.end())
214 pProp->Value >>= sDocURL;
215 }
216 }
217 }
218
219 if ( m_pMethod )
220 {
221 sal_uInt16 nLine2;
222 m_pMethod->GetLineRange( nLine1, nLine2 );
223 SbModule* pModule = m_pMethod->GetModule();
224 if ( pModule )
225 {
226 sModName = pModule->GetName();
227 StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
228 if ( pBasic )
229 sLibName = pBasic->GetName();
230 }
231 }
232
233 if ( m_xContext.is() )
234 {
235 Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
236
237 Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY );
238
239 if ( xProv.is() )
240 {
241 Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create( m_xContext ) );
242
243 Sequence < PropertyValue > aArgs{
244 comphelper::makePropertyValue("Document", sDocURL),
245 comphelper::makePropertyValue("LibName", sLibName),
246 comphelper::makePropertyValue("Name", sModName),
247 comphelper::makePropertyValue("Type", OUString("Module")),
248 comphelper::makePropertyValue("Line", static_cast< sal_uInt32 >( nLine1 ))
249 };
250 xHelper->executeDispatch( xProv, ".uno:BasicIDEAppear", OUString(), 0, aArgs );
251 }
252 }
253
254
255 return Any();
256 }
257
258
259 void BasicMethodNodeImpl::setValue( const OUString&, const Any& )
260 {
261 throw UnknownPropertyException(
262 "BasicMethodNodeImpl::setValue: property name is unknown!" );
263 }
264
265
267 {
268 throw UnknownPropertyException(
269 "BasicMethodNodeImpl::getValue: property name is unknown!" );
270 }
271
272
274 {
275 bool bReturn = false;
277 bReturn = true;
278
279 return bReturn;
280 }
281
282
284 {
285 return false;
286 }
287
288
289} // namespace basprov
290
291
292/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
#define BASPROV_DEFAULT_ATTRIBS()
Definition: basmethnode.cxx:50
constexpr OUStringLiteral BASPROV_PROPERTY_URI
Definition: basmethnode.cxx:47
#define BASPROV_PROPERTY_ID_URI
Definition: basmethnode.cxx:44
#define BASPROV_PROPERTY_ID_EDITABLE
Definition: basmethnode.cxx:45
constexpr OUStringLiteral BASPROV_PROPERTY_EDITABLE
Definition: basmethnode.cxx:48
SbModule * GetModule()
void GetLineRange(sal_uInt16 &, sal_uInt16 &)
const SbxObject * GetParent() const
const OUString & GetName(SbxNameType=SbxNameType::NONE) const
virtual sal_Bool SAL_CALL hasProperty(const OUString &aName) override
virtual void SAL_CALL setValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes() override
virtual css::uno::Any SAL_CALL invoke(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
BasicMethodNodeImpl(const css::uno::Reference< css::uno::XComponentContext > &rxContext, OUString sScriptingContext, SbMethod *pMethod, bool isAppScript)
Definition: basmethnode.cxx:60
virtual sal_Bool SAL_CALL hasMethod(const OUString &aName) override
virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: basmethnode.hxx:54
virtual sal_Int16 SAL_CALL getType() override
virtual css::uno::Any SAL_CALL getValue(const OUString &aPropertyName) override
virtual sal_Bool SAL_CALL hasChildNodes() override
virtual ~BasicMethodNodeImpl() override
Definition: basmethnode.cxx:98
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
ContainerApprovalMethod m_pMethod
float u
std::mutex m_aMutex
OUString aName
::cppu::WeakImplHelper< css::script::browse::XBrowseNode, css::script::XInvocation > BasicMethodNodeImpl_BASE
Definition: basmethnode.hxx:45
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
Reference< XModel > xModel
unsigned char sal_Bool