2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-06 17:28:37 +01:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2003-09-23 09:09:14 +00:00
|
|
|
|
|
|
|
#include "basmethnode.hxx"
|
2003-11-07 12:51:16 +00:00
|
|
|
#include <com/sun/star/beans/PropertyAttribute.hpp>
|
2012-08-23 15:43:05 +02:00
|
|
|
#include <com/sun/star/frame/DispatchHelper.hpp>
|
2012-12-14 12:58:00 +02:00
|
|
|
#include <com/sun/star/frame/Desktop.hpp>
|
2003-11-07 12:51:16 +00:00
|
|
|
#include <com/sun/star/frame/XDispatchProvider.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
|
2004-10-22 13:01:20 +00:00
|
|
|
#include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
|
2010-10-16 03:18:35 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2005-01-13 16:42:30 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2003-09-23 09:09:14 +00:00
|
|
|
#include <basic/sbstar.hxx>
|
|
|
|
#include <basic/sbmeth.hxx>
|
2003-10-15 07:35:32 +00:00
|
|
|
#include <basic/sbmod.hxx>
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2004-07-23 13:06:10 +00:00
|
|
|
#include <util/MiscUtils.hxx>
|
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2003-11-07 12:51:16 +00:00
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::comphelper;
|
2004-10-22 13:01:20 +00:00
|
|
|
using namespace ::com::sun::star::script;
|
2004-07-23 13:06:10 +00:00
|
|
|
using namespace ::sf_misc;
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
#define BASPROV_PROPERTY_ID_URI 1
|
|
|
|
#define BASPROV_PROPERTY_ID_EDITABLE 2
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
#define BASPROV_PROPERTY_URI OUString( "URI" )
|
|
|
|
#define BASPROV_PROPERTY_EDITABLE OUString( "Editable" )
|
2003-11-07 12:51:16 +00:00
|
|
|
|
|
|
|
#define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
|
|
|
|
|
|
|
|
|
2014-02-25 20:05:49 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
namespace basprov
|
|
|
|
{
|
|
|
|
|
2014-02-25 20:05:49 +01:00
|
|
|
|
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
// BasicMethodNodeImpl
|
2014-02-25 20:05:49 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference< XComponentContext >& rxContext,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sScriptingContext, SbMethod* pMethod, bool isAppScript )
|
2005-01-13 16:42:30 +00:00
|
|
|
: ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
|
2003-11-07 12:51:16 +00:00
|
|
|
,OPropertyContainer( GetBroadcastHelper() )
|
|
|
|
,m_xContext( rxContext )
|
2004-07-23 13:06:10 +00:00
|
|
|
,m_sScriptingContext( sScriptingContext )
|
2003-11-07 12:51:16 +00:00
|
|
|
,m_pMethod( pMethod )
|
|
|
|
,m_bIsAppScript( isAppScript )
|
2012-09-25 16:57:23 +02:00
|
|
|
,m_bEditable( true )
|
2003-09-23 09:09:14 +00:00
|
|
|
{
|
2003-11-07 12:51:16 +00:00
|
|
|
if ( m_pMethod )
|
2003-10-15 07:35:32 +00:00
|
|
|
{
|
2003-11-07 12:51:16 +00:00
|
|
|
SbModule* pModule = m_pMethod->GetModule();
|
|
|
|
if ( pModule )
|
|
|
|
{
|
|
|
|
StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
|
|
|
|
if ( pBasic )
|
|
|
|
{
|
2013-11-04 10:31:49 +02:00
|
|
|
m_sURI = "vnd.sun.star.script:";
|
2003-11-07 12:51:16 +00:00
|
|
|
m_sURI += pBasic->GetName();
|
2013-10-25 17:17:50 +02:00
|
|
|
m_sURI += ".";
|
2003-11-07 12:51:16 +00:00
|
|
|
m_sURI += pModule->GetName();
|
2013-10-25 17:17:50 +02:00
|
|
|
m_sURI += ".";
|
2003-11-07 12:51:16 +00:00
|
|
|
m_sURI += m_pMethod->GetName();
|
2013-10-25 17:17:50 +02:00
|
|
|
m_sURI += "?language=Basic&location=";
|
2003-11-07 12:51:16 +00:00
|
|
|
if ( m_bIsAppScript )
|
2013-10-25 17:17:50 +02:00
|
|
|
m_sURI += "application";
|
2003-11-07 12:51:16 +00:00
|
|
|
else
|
2013-10-25 17:17:50 +02:00
|
|
|
m_sURI += "document";
|
2003-11-07 12:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-15 07:35:32 +00:00
|
|
|
}
|
2003-11-07 12:51:16 +00:00
|
|
|
|
|
|
|
registerProperty( BASPROV_PROPERTY_URI, BASPROV_PROPERTY_ID_URI, BASPROV_DEFAULT_ATTRIBS(), &m_sURI, ::getCppuType( &m_sURI ) );
|
|
|
|
registerProperty( BASPROV_PROPERTY_EDITABLE, BASPROV_PROPERTY_ID_EDITABLE, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable, ::getCppuType( &m_bEditable ) );
|
2003-09-23 09:09:14 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
|
|
|
BasicMethodNodeImpl::~BasicMethodNodeImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
// XInterface
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
|
|
|
IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
// XTypeProvider
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
|
|
|
IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
// XBrowseNode
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
OUString BasicMethodNodeImpl::getName( ) throw (RuntimeException, std::exception)
|
2003-09-23 09:09:14 +00:00
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sMethodName;
|
2003-09-23 09:09:14 +00:00
|
|
|
if ( m_pMethod )
|
|
|
|
sMethodName = m_pMethod->GetName();
|
|
|
|
|
|
|
|
return sMethodName;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Sequence< Reference< browse::XBrowseNode > > BasicMethodNodeImpl::getChildNodes( ) throw (RuntimeException, std::exception)
|
2003-09-23 09:09:14 +00:00
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2003-09-23 09:09:14 +00:00
|
|
|
|
|
|
|
return Sequence< Reference< browse::XBrowseNode > >();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Bool BasicMethodNodeImpl::hasChildNodes( ) throw (RuntimeException, std::exception)
|
2003-09-23 09:09:14 +00:00
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2003-09-23 09:09:14 +00:00
|
|
|
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Int16 BasicMethodNodeImpl::getType( ) throw (RuntimeException, std::exception)
|
2003-09-23 09:09:14 +00:00
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2003-09-23 09:09:14 +00:00
|
|
|
|
|
|
|
return browse::BrowseNodeTypes::SCRIPT;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
// OPropertySetHelper
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
::cppu::IPropertyArrayHelper& BasicMethodNodeImpl::getInfoHelper( )
|
|
|
|
{
|
|
|
|
return *getArrayHelper();
|
|
|
|
}
|
2003-10-15 07:35:32 +00:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
// OPropertyArrayUsageHelper
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-10-15 07:35:32 +00:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
::cppu::IPropertyArrayHelper* BasicMethodNodeImpl::createArrayHelper( ) const
|
|
|
|
{
|
|
|
|
Sequence< Property > aProps;
|
|
|
|
describeProperties( aProps );
|
|
|
|
return new ::cppu::OPropertyArrayHelper( aProps );
|
|
|
|
}
|
2003-10-15 07:35:32 +00:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
// XPropertySet
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-10-15 07:35:32 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Reference< XPropertySetInfo > BasicMethodNodeImpl::getPropertySetInfo( ) throw (RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
|
|
|
Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
|
|
|
|
return xInfo;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
// XInvocation
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Reference< XIntrospectionAccess > BasicMethodNodeImpl::getIntrospection( ) throw (RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
|
|
|
return Reference< XIntrospectionAccess >();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
Any BasicMethodNodeImpl::invoke( const OUString& aFunctionName, const Sequence< Any >& aParams,
|
2003-11-07 12:51:16 +00:00
|
|
|
Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
|
|
|
|
throw (IllegalArgumentException, script::CannotConvertException,
|
2014-02-25 21:31:58 +01:00
|
|
|
reflection::InvocationTargetException, RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
2006-06-19 09:18:11 +00:00
|
|
|
(void)aParams;
|
|
|
|
(void)aOutParamIndex;
|
|
|
|
(void)aOutParam;
|
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
if ( aFunctionName == BASPROV_PROPERTY_EDITABLE )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sDocURL, sLibName, sModName;
|
2011-01-14 16:07:01 +01:00
|
|
|
sal_uInt16 nLine1 = 0, nLine2;
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2004-07-23 13:06:10 +00:00
|
|
|
if ( !m_bIsAppScript )
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
2004-07-23 13:06:10 +00:00
|
|
|
Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext );
|
2003-11-07 12:51:16 +00:00
|
|
|
|
|
|
|
if ( xModel.is() )
|
|
|
|
{
|
|
|
|
sDocURL = xModel->getURL();
|
2012-01-05 14:15:36 -02:00
|
|
|
if ( sDocURL.isEmpty() )
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
|
|
|
Sequence < PropertyValue > aProps = xModel->getArgs();
|
|
|
|
sal_Int32 nProps = aProps.getLength();
|
|
|
|
const PropertyValue* pProps = aProps.getConstArray();
|
|
|
|
for ( sal_Int32 i = 0; i < nProps; ++i )
|
|
|
|
{
|
|
|
|
// TODO: according to MBA the property 'Title' may change in future
|
2012-04-06 15:05:52 +02:00
|
|
|
if ( pProps[i].Name == "Title" )
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
|
|
|
pProps[i].Value >>= sDocURL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2012-12-14 12:58:00 +02:00
|
|
|
Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2012-12-14 12:58:00 +02:00
|
|
|
Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY );
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2012-12-14 12:58:00 +02:00
|
|
|
if ( xProv.is() )
|
|
|
|
{
|
|
|
|
Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create( m_xContext ) );
|
|
|
|
|
|
|
|
Sequence < PropertyValue > aArgs(7);
|
2013-11-04 10:31:49 +02:00
|
|
|
aArgs[0].Name = "Document";
|
2012-12-14 12:58:00 +02:00
|
|
|
aArgs[0].Value <<= sDocURL;
|
2013-11-04 14:00:40 +02:00
|
|
|
aArgs[1].Name = "LibName";
|
2012-12-14 12:58:00 +02:00
|
|
|
aArgs[1].Value <<= sLibName;
|
2013-11-04 10:31:49 +02:00
|
|
|
aArgs[2].Name = "Name";
|
2012-12-14 12:58:00 +02:00
|
|
|
aArgs[2].Value <<= sModName;
|
2013-11-04 10:31:49 +02:00
|
|
|
aArgs[3].Name = "Type";
|
2013-04-07 12:06:47 +02:00
|
|
|
aArgs[3].Value <<= OUString("Module");
|
2013-11-04 10:31:49 +02:00
|
|
|
aArgs[4].Name = "Line";
|
2012-12-14 12:58:00 +02:00
|
|
|
aArgs[4].Value <<= static_cast< sal_uInt32 >( nLine1 );
|
2013-04-07 12:06:47 +02:00
|
|
|
xHelper->executeDispatch( xProv, OUString(".uno:BasicIDEAppear"), OUString(), 0, aArgs );
|
2003-11-07 12:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw IllegalArgumentException(
|
2014-05-28 12:50:02 +02:00
|
|
|
"BasicMethodNodeImpl::invoke: function name not supported!",
|
2003-11-07 12:51:16 +00:00
|
|
|
Reference< XInterface >(), 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return Any();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-10-15 07:35:32 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void BasicMethodNodeImpl::setValue( const OUString& aPropertyName, const Any& aValue )
|
2003-11-07 12:51:16 +00:00
|
|
|
throw (UnknownPropertyException, script::CannotConvertException,
|
2014-02-25 21:31:58 +01:00
|
|
|
reflection::InvocationTargetException, RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
2006-06-19 09:18:11 +00:00
|
|
|
(void)aPropertyName;
|
|
|
|
(void)aValue;
|
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
throw UnknownPropertyException(
|
2014-05-23 12:03:21 +02:00
|
|
|
"BasicMethodNodeImpl::setValue: property name is unknown!" );
|
2003-11-07 12:51:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Any BasicMethodNodeImpl::getValue( const OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
2006-06-19 09:18:11 +00:00
|
|
|
(void)aPropertyName;
|
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
throw UnknownPropertyException(
|
2014-05-23 12:03:21 +02:00
|
|
|
"BasicMethodNodeImpl::getValue: property name is unknown!" );
|
2003-11-07 12:51:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Bool BasicMethodNodeImpl::hasMethod( const OUString& aName ) throw (RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
2014-04-23 13:25:43 +02:00
|
|
|
bool bReturn = false;
|
2003-11-07 12:51:16 +00:00
|
|
|
if ( aName == BASPROV_PROPERTY_EDITABLE )
|
2014-04-23 13:25:43 +02:00
|
|
|
bReturn = true;
|
2003-11-07 12:51:16 +00:00
|
|
|
|
|
|
|
return bReturn;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Bool BasicMethodNodeImpl::hasProperty( const OUString& aName ) throw (RuntimeException, std::exception)
|
2003-11-07 12:51:16 +00:00
|
|
|
{
|
2006-06-19 09:18:11 +00:00
|
|
|
(void)aName;
|
|
|
|
|
2003-11-07 12:51:16 +00:00
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-10-15 07:35:32 +00:00
|
|
|
|
2014-02-25 20:05:49 +01:00
|
|
|
|
2003-09-23 09:09:14 +00:00
|
|
|
} // namespace basprov
|
2014-02-25 20:05:49 +01:00
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|