Kaydet (Commit) d16421f8 authored tarafından Vladimir Glazunov's avatar Vladimir Glazunov

CWS-TOOLING: integrate CWS ab76

......@@ -103,6 +103,7 @@ TYPEINIT1(SbUnoObject,SbxObject)
TYPEINIT1(SbUnoClass,SbxObject)
TYPEINIT1(SbUnoService,SbxObject)
TYPEINIT1(SbUnoServiceCtor,SbxMethod)
TYPEINIT1(SbUnoSingleton,SbxObject)
typedef WeakImplHelper1< XAllListener > BasicAllListenerHelper;
......@@ -3299,6 +3300,18 @@ SbxVariable* SbUnoClass::Find( const XubString& rName, SbxClassType t )
pRes->PutObject( xWrapper );
}
}
// An UNO singleton?
if( !pRes )
{
SbUnoSingleton* pUnoSingleton = findUnoSingleton( aNewName );
if( pUnoSingleton )
{
pRes = new SbxVariable( SbxVARIANT );
SbxObjectRef xWrapper = (SbxObject*)pUnoSingleton;
pRes->PutObject( xWrapper );
}
}
}
}
......@@ -3579,6 +3592,90 @@ SbxInfo* SbUnoServiceCtor::GetInfo()
}
SbUnoSingleton* findUnoSingleton( const String& rName )
{
SbUnoSingleton* pSbUnoSingleton = NULL;
Reference< XHierarchicalNameAccess > xTypeAccess = getTypeProvider_Impl();
if( xTypeAccess->hasByHierarchicalName( rName ) )
{
Any aRet = xTypeAccess->getByHierarchicalName( rName );
Reference< XTypeDescription > xTypeDesc;
aRet >>= xTypeDesc;
if( xTypeDesc.is() )
{
TypeClass eTypeClass = xTypeDesc->getTypeClass();
if( eTypeClass == TypeClass_SINGLETON )
{
Reference< XSingletonTypeDescription > xSingletonTypeDesc( xTypeDesc, UNO_QUERY );
if( xSingletonTypeDesc.is() )
pSbUnoSingleton = new SbUnoSingleton( rName, xSingletonTypeDesc );
}
}
}
return pSbUnoSingleton;
}
SbUnoSingleton::SbUnoSingleton( const String& aName_,
const Reference< XSingletonTypeDescription >& xSingletonTypeDesc )
: SbxObject( aName_ )
, m_xSingletonTypeDesc( xSingletonTypeDesc )
{
SbxVariableRef xGetMethodRef =
new SbxMethod( String( RTL_CONSTASCII_USTRINGPARAM( "get" ) ), SbxOBJECT );
QuickInsert( (SbxVariable*)xGetMethodRef );
}
void SbUnoSingleton::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
const SfxHint& rHint, const TypeId& rHintType )
{
const SbxHint* pHint = PTR_CAST(SbxHint,&rHint);
if( pHint )
{
SbxVariable* pVar = pHint->GetVar();
SbxArray* pParams = pVar->GetParameters();
UINT32 nParamCount = pParams ? ((UINT32)pParams->Count() - 1) : 0;
UINT32 nAllowedParamCount = 1;
Reference < XComponentContext > xContextToUse;
if( nParamCount > 0 )
{
// Check if first parameter is a context and use it then
Reference < XComponentContext > xFirstParamContext;
Any aArg1 = sbxToUnoValue( pParams->Get( 1 ) );
if( (aArg1 >>= xFirstParamContext) && xFirstParamContext.is() )
xContextToUse = xFirstParamContext;
}
if( !xContextToUse.is() )
{
Reference < XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
xContextToUse.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" )) ), UNO_QUERY_THROW );
--nAllowedParamCount;
}
if( nParamCount > nAllowedParamCount )
{
StarBASIC::Error( SbERR_BAD_ARGUMENT );
return;
}
Any aRetAny;
if( xContextToUse.is() )
{
String aSingletonName( RTL_CONSTASCII_USTRINGPARAM("/singletons/") );
aSingletonName += GetName();
Reference < XInterface > xRet;
xContextToUse->getValueByName( aSingletonName ) >>= xRet;
aRetAny <<= xRet;
}
unoToSbxValue( pVar, aRetAny );
}
else
SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
}
//========================================================================
//========================================================================
......
......@@ -41,6 +41,7 @@
#include <com/sun/star/script/XInvocation.hpp>
#include <com/sun/star/reflection/XIdlClass.hpp>
#include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
#include <com/sun/star/reflection/XSingletonTypeDescription.hpp>
#include <rtl/ustring.hxx>
class SbUnoObject: public SbxObject
......@@ -226,6 +227,23 @@ public:
};
// Wrapper for UNO Singleton
class SbUnoSingleton : public SbxObject
{
const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription > m_xSingletonTypeDesc;
public:
TYPEINFO();
SbUnoSingleton( const String& aName_,
const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >& xSingletonTypeDesc );
void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
};
SV_DECL_IMPL_REF(SbUnoSingleton);
SbUnoSingleton* findUnoSingleton( const String& rName );
// #105565 Special Object to wrap a strongly typed Uno Any
class SbUnoAnyObject: public SbxObject
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment