1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "basmethnode.hxx"
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
#include <vcl/svapp.hxx>
#include <basic/sbstar.hxx>
#include <basic/sbmeth.hxx>
#include <basic/sbmod.hxx>
#include <util/MiscUtils.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::comphelper;
using namespace ::com::sun::star::script;
using namespace ::sf_misc;
#define BASPROV_PROPERTY_ID_URI 1
#define BASPROV_PROPERTY_ID_EDITABLE 2
#define BASPROV_PROPERTY_URI "URI"
#define BASPROV_PROPERTY_EDITABLE "Editable"
#define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
namespace basprov
{
// BasicMethodNodeImpl
BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference< XComponentContext >& rxContext,
const OUString& sScriptingContext, SbMethod* pMethod, bool isAppScript )
: ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
,OPropertyContainer( GetBroadcastHelper() )
,m_xContext( rxContext )
,m_sScriptingContext( sScriptingContext )
,m_pMethod( pMethod )
,m_bIsAppScript( isAppScript )
,m_bEditable( true )
{
if ( m_pMethod )
{
SbModule* pModule = m_pMethod->GetModule();
if ( pModule )
{
StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
if ( pBasic )
{
m_sURI = "vnd.sun.star.script:";
m_sURI += pBasic->GetName();
m_sURI += ".";
m_sURI += pModule->GetName();
m_sURI += ".";
m_sURI += m_pMethod->GetName();
m_sURI += "?language=Basic&location=";
if ( m_bIsAppScript )
m_sURI += "application";
else
m_sURI += "document";
}
}
}
registerProperty( BASPROV_PROPERTY_URI, BASPROV_PROPERTY_ID_URI, BASPROV_DEFAULT_ATTRIBS(), &m_sURI, cppu::UnoType<decltype(m_sURI)>::get() );
registerProperty( BASPROV_PROPERTY_EDITABLE, BASPROV_PROPERTY_ID_EDITABLE, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable, cppu::UnoType<decltype(m_bEditable)>::get() );
}
BasicMethodNodeImpl::~BasicMethodNodeImpl()
{
}
// XInterface
IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
// XTypeProvider
IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
// XBrowseNode
OUString BasicMethodNodeImpl::getName( )
{
SolarMutexGuard aGuard;
OUString sMethodName;
if ( m_pMethod )
sMethodName = m_pMethod->GetName();
return sMethodName;
}
Sequence< Reference< browse::XBrowseNode > > BasicMethodNodeImpl::getChildNodes( )
{
return Sequence< Reference< browse::XBrowseNode > >();
}
sal_Bool BasicMethodNodeImpl::hasChildNodes( )
{
return false;
}
sal_Int16 BasicMethodNodeImpl::getType( )
{
return browse::BrowseNodeTypes::SCRIPT;
}
// OPropertySetHelper
::cppu::IPropertyArrayHelper& BasicMethodNodeImpl::getInfoHelper( )
{
return *getArrayHelper();
}
// OPropertyArrayUsageHelper
::cppu::IPropertyArrayHelper* BasicMethodNodeImpl::createArrayHelper( ) const
{
Sequence< Property > aProps;
describeProperties( aProps );
return new ::cppu::OPropertyArrayHelper( aProps );
}
// XPropertySet
Reference< XPropertySetInfo > BasicMethodNodeImpl::getPropertySetInfo( )
{
Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
return xInfo;
}
// XInvocation
Reference< XIntrospectionAccess > BasicMethodNodeImpl::getIntrospection( )
{
return Reference< XIntrospectionAccess >();
}
Any BasicMethodNodeImpl::invoke( const OUString& aFunctionName, const Sequence< Any >&,
Sequence< sal_Int16 >&, Sequence< Any >& )
{
if ( aFunctionName != BASPROV_PROPERTY_EDITABLE )
{
throw IllegalArgumentException(
"BasicMethodNodeImpl::invoke: function name not supported!",
Reference< XInterface >(), 1 );
}
OUString sDocURL, sLibName, sModName;
sal_uInt16 nLine1 = 0, nLine2;
if ( !m_bIsAppScript )
{
Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext );
if ( xModel.is() )
{
sDocURL = xModel->getURL();
if ( sDocURL.isEmpty() )
{
Sequence < PropertyValue > aProps = xModel->getArgs();
// TODO: according to MBA the property 'Title' may change in future
const PropertyValue* pProp = std::find_if(aProps.begin(), aProps.end(),
[](const PropertyValue& rProp) { return rProp.Name == "Title"; });
if (pProp != aProps.end())
pProp->Value >>= sDocURL;
}
}
}
if ( m_pMethod )
{
m_pMethod->GetLineRange( nLine1, nLine2 );
SbModule* pModule = m_pMethod->GetModule();
if ( pModule )
{
sModName = pModule->GetName();
StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
if ( pBasic )
sLibName = pBasic->GetName();
}
}
if ( m_xContext.is() )
{
Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY );
if ( xProv.is() )
{
Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create( m_xContext ) );
Sequence < PropertyValue > aArgs(7);
aArgs[0].Name = "Document";
aArgs[0].Value <<= sDocURL;
aArgs[1].Name = "LibName";
aArgs[1].Value <<= sLibName;
aArgs[2].Name = "Name";
aArgs[2].Value <<= sModName;
aArgs[3].Name = "Type";
aArgs[3].Value <<= OUString("Module");
aArgs[4].Name = "Line";
aArgs[4].Value <<= static_cast< sal_uInt32 >( nLine1 );
xHelper->executeDispatch( xProv, ".uno:BasicIDEAppear", OUString(), 0, aArgs );
}
}
return Any();
}
void BasicMethodNodeImpl::setValue( const OUString&, const Any& )
{
throw UnknownPropertyException(
"BasicMethodNodeImpl::setValue: property name is unknown!" );
}
Any BasicMethodNodeImpl::getValue( const OUString& )
{
throw UnknownPropertyException(
"BasicMethodNodeImpl::getValue: property name is unknown!" );
}
sal_Bool BasicMethodNodeImpl::hasMethod( const OUString& aName )
{
bool bReturn = false;
if ( aName == BASPROV_PROPERTY_EDITABLE )
bReturn = true;
return bReturn;
}
sal_Bool BasicMethodNodeImpl::hasProperty( const OUString& )
{
return false;
}
} // namespace basprov
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|