Files
libreoffice/basic/source/classes/eventatt.cxx

570 lines
20 KiB
C++
Raw Normal View History

/* -*- 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 <osl/mutex.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <com/sun/star/awt/XControlContainer.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XDialog.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/DialogProvider.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/resource/XStringResourceSupplier.hpp>
#include <com/sun/star/resource/XStringResourceManager.hpp>
#include <com/sun/star/script/XEventAttacher.hpp>
#include <com/sun/star/script/XAllListener.hpp>
#include <com/sun/star/script/XScriptEventsSupplier.hpp>
#include <com/sun/star/script/XScriptEventsAttacher.hpp>
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#include <com/sun/star/script/provider/XScriptProvider.hpp>
#include <basic/basicmanagerrepository.hxx>
#include <basic/basmgr.hxx>
2001-03-03 15:19:45 +00:00
//==================================================================================================
#include <xmlscript/xmldlg_imexp.hxx>
2001-03-03 15:19:45 +00:00
#include <sbunoobj.hxx>
#include <basic/sbstar.hxx>
#include <basic/sbmeth.hxx>
#include <basic/sbuno.hxx>
#include <runtime.hxx>
#include <sbintern.hxx>
#include <cppuhelper/implbase1.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::script;
using namespace ::com::sun::star::resource;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::reflection;
using namespace ::com::sun::star::awt;
2001-03-19 11:42:53 +00:00
using namespace ::com::sun::star::io;
using namespace ::cppu;
using namespace ::osl;
void SFURL_firing_impl( const ScriptEvent& aScriptEvent, Any* pRet, const Reference< frame::XModel >& xModel )
{
OSL_TRACE("SFURL_firing_impl() processing script url %s",
OUStringToOString( aScriptEvent.ScriptCode,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
try
{
Reference< provider::XScriptProvider > xScriptProvider;
if ( xModel.is() )
{
Reference< provider::XScriptProviderSupplier > xSupplier( xModel, UNO_QUERY );
OSL_ENSURE( xSupplier.is(), "SFURL_firing_impl: failed to get script provider supplier" );
if ( xSupplier.is() )
xScriptProvider.set( xSupplier->getScriptProvider() );
}
else
{
Reference< XComponentContext > xContext(
comphelper::getProcessComponentContext() );
Reference< provider::XScriptProviderFactory > xFactory =
provider::theMasterScriptProviderFactory::get( xContext );
Any aCtx;
aCtx <<= OUString("user");
xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
}
if ( !xScriptProvider.is() )
{
OSL_TRACE("SFURL_firing_impl() Failed to create msp");
return;
}
Sequence< Any > inArgs( 0 );
Sequence< Any > outArgs( 0 );
Sequence< sal_Int16 > outIndex;
// get Arguments for script
inArgs = aScriptEvent.Arguments;
Reference< provider::XScript > xScript = xScriptProvider->getScript( aScriptEvent.ScriptCode );
if ( !xScript.is() )
{
OSL_TRACE("SFURL_firing_impl() Failed to obtain XScript");
return;
}
Any result = xScript->invoke( inArgs, outIndex, outArgs );
if ( pRet )
{
*pRet = result;
}
}
2011-11-23 02:21:12 +09:00
catch ( const RuntimeException& re )
{
OSL_TRACE("SFURL_firing_impl() Caught RuntimeException reason %s.",
OUStringToOString( re.Message,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
}
2011-11-23 02:21:12 +09:00
catch ( const Exception& e )
{
OSL_TRACE("SFURL_firing_impl() Caught Exception reason %s.",
OUStringToOString( e.Message,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
}
}
class BasicScriptListener_Impl : public WeakImplHelper1< XScriptListener >
{
StarBASICRef maBasicRef;
Reference< frame::XModel > m_xModel;
virtual void firing_impl(const ScriptEvent& aScriptEvent, Any* pRet);
public:
BasicScriptListener_Impl( StarBASIC* pBasic, const Reference< frame::XModel >& xModel )
: maBasicRef( pBasic ), m_xModel( xModel ) {}
// Methods of XAllListener
virtual void SAL_CALL firing(const ScriptEvent& aScriptEvent)
throw( RuntimeException );
virtual Any SAL_CALL approveFiring(const ScriptEvent& aScriptEvent)
throw( InvocationTargetException, RuntimeException );
// Methods of XEventListener
virtual void SAL_CALL disposing(const EventObject& Source)
throw( RuntimeException );
};
// Methods XAllListener
void BasicScriptListener_Impl::firing( const ScriptEvent& aScriptEvent ) throw ( RuntimeException )
{
firing_impl( aScriptEvent, NULL );
}
2001-02-22 14:40:19 +00:00
Any BasicScriptListener_Impl::approveFiring( const ScriptEvent& aScriptEvent )
throw ( InvocationTargetException, RuntimeException )
{
Any aRetAny;
firing_impl( aScriptEvent, &aRetAny );
return aRetAny;
}
// Methods XEventListener
void BasicScriptListener_Impl::disposing(const EventObject& ) throw ( RuntimeException )
{
// TODO: ???
2010-10-14 16:43:16 -05:00
//SolarMutexGuard aGuard;
//xSbxObj.Clear();
}
void BasicScriptListener_Impl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet )
{
if( aScriptEvent.ScriptType.equalsAscii( "StarBasic" ) )
{
// Full qualified name?
OUString aMacro( aScriptEvent.ScriptCode );
OUString aLibName;
OUString aLocation;
if( comphelper::string::getTokenCount(aMacro, '.') == 3 )
{
sal_Int32 nLast = 0;
OUString aFullLibName = aMacro.getToken( (sal_Int32)0, (sal_Unicode)'.', nLast );
sal_Int32 nIndex = aFullLibName.indexOf( (sal_Unicode)':' );
if (nIndex >= 0)
{
aLocation = aFullLibName.copy( 0, nIndex );
aLibName = aFullLibName.copy( nIndex + 1 );
}
aMacro = aMacro.copy( nLast );
}
SbxObject* p = maBasicRef;
SbxObject* pParent = p->GetParent();
SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL;
StarBASICRef xAppStandardBasic;
StarBASICRef xDocStandardBasic;
if( pParentParent )
{
// Own basic must be document library
xAppStandardBasic = (StarBASIC*)pParentParent;
xDocStandardBasic = (StarBASIC*)pParent;
}
else if( pParent )
{
OUString aName = p->GetName();
if( aName.equalsAscii("Standard") )
{
// Own basic is doc standard lib
xDocStandardBasic = (StarBASIC*)p;
}
xAppStandardBasic = (StarBASIC*)pParent;
}
else
{
xAppStandardBasic = (StarBASIC*)p;
}
bool bSearchLib = true;
StarBASICRef xLibSearchBasic;
if( aLocation.equalsAscii("application") )
{
xLibSearchBasic = xAppStandardBasic;
}
else if( aLocation.equalsAscii("document") )
{
xLibSearchBasic = xDocStandardBasic;
}
else
{
bSearchLib = false;
}
SbxVariable* pMethVar = NULL;
// Be still tolerant and make default search if no search basic exists
if( bSearchLib && xLibSearchBasic.Is() )
{
StarBASICRef xLibBasic;
sal_Int16 nCount = xLibSearchBasic->GetObjects()->Count();
for( sal_Int16 nObj = -1; nObj < nCount ; nObj++ )
{
StarBASIC* pBasic;
if( nObj == -1 )
{
pBasic = (StarBASIC*)xLibSearchBasic;
}
else
{
SbxVariable* pVar = xLibSearchBasic->GetObjects()->Get( nObj );
pBasic = PTR_CAST(StarBASIC,pVar);
}
if( pBasic )
{
OUString aName = pBasic->GetName();
if( aName == aLibName )
{
// Search only in the lib, not automatically in application basic
sal_uInt16 nFlags = pBasic->GetFlags();
pBasic->ResetFlag( SBX_GBLSEARCH );
pMethVar = pBasic->Find( aMacro, SbxCLASS_DONTCARE );
pBasic->SetFlags( nFlags );
break;
}
}
}
}
// Default: Be tolerant and search everywhere
if( (!pMethVar || !pMethVar->ISA(SbMethod)) && maBasicRef.Is() )
{
pMethVar = maBasicRef->FindQualified( aMacro, SbxCLASS_DONTCARE );
}
SbMethod* pMeth = PTR_CAST(SbMethod,pMethVar);
if( !pMeth )
{
return;
}
// Setup parameters
SbxArrayRef xArray;
sal_Int32 nCnt = aScriptEvent.Arguments.getLength();
if( nCnt )
{
xArray = new SbxArray;
const Any *pArgs = aScriptEvent.Arguments.getConstArray();
for( sal_Int32 i = 0; i < nCnt; i++ )
{
SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
unoToSbxValue( (SbxVariable*)xVar, pArgs[i] );
xArray->Put( xVar, sal::static_int_cast< sal_uInt16 >(i+1) );
}
}
// Call method
SbxVariableRef xValue = pRet ? new SbxVariable : 0;
if( xArray.Is() )
{
pMeth->SetParameters( xArray );
}
pMeth->Call( xValue );
if( pRet )
{
*pRet = sbxToUnoValue( xValue );
}
pMeth->SetParameters( NULL );
}
else // scripting framework script
{
//callBasic via scripting framework
SFURL_firing_impl( aScriptEvent, pRet, m_xModel );
}
}
css::uno::Reference< css::container::XNameContainer > implFindDialogLibForDialog( const Any& rDlgAny, SbxObject* pBasic )
{
css::uno::Reference< css::container::XNameContainer > aRetDlgLib;
SbxVariable* pDlgLibContVar = pBasic->Find(OUString("DialogLibraries"), SbxCLASS_OBJECT);
if( pDlgLibContVar && pDlgLibContVar->ISA(SbUnoObject) )
{
SbUnoObject* pDlgLibContUnoObj = (SbUnoObject*)(SbxBase*)pDlgLibContVar;
Any aDlgLibContAny = pDlgLibContUnoObj->getUnoAny();
Reference< XLibraryContainer > xDlgLibContNameAccess( aDlgLibContAny, UNO_QUERY );
OSL_ENSURE( xDlgLibContNameAccess.is(), "implFindDialogLibForDialog: no lib container for the given dialog!" );
if( xDlgLibContNameAccess.is() )
{
Sequence< OUString > aLibNames = xDlgLibContNameAccess->getElementNames();
const OUString* pLibNames = aLibNames.getConstArray();
sal_Int32 nLibNameCount = aLibNames.getLength();
for( sal_Int32 iLib = 0 ; iLib < nLibNameCount ; iLib++ )
{
if ( !xDlgLibContNameAccess->isLibraryLoaded( pLibNames[ iLib ] ) )
// if the library isn't loaded, then the dialog cannot originate from this lib
continue;
Any aDlgLibAny = xDlgLibContNameAccess->getByName( pLibNames[ iLib ] );
Reference< XNameContainer > xDlgLibNameCont( aDlgLibAny, UNO_QUERY );
OSL_ENSURE( xDlgLibNameCont.is(), "implFindDialogLibForDialog: invalid dialog lib!" );
if( xDlgLibNameCont.is() )
{
Sequence< OUString > aDlgNames = xDlgLibNameCont->getElementNames();
const OUString* pDlgNames = aDlgNames.getConstArray();
sal_Int32 nDlgNameCount = aDlgNames.getLength();
for( sal_Int32 iDlg = 0 ; iDlg < nDlgNameCount ; iDlg++ )
{
Any aDlgAny = xDlgLibNameCont->getByName( pDlgNames[ iDlg ] );
if( aDlgAny == rDlgAny )
{
aRetDlgLib = xDlgLibNameCont;
break;
}
}
}
}
}
}
return aRetDlgLib;
}
css::uno::Reference< css::container::XNameContainer > implFindDialogLibForDialogBasic( const Any& aAnyISP, SbxObject* pBasic, StarBASIC*& pFoundBasic )
{
css::uno::Reference< css::container::XNameContainer > aDlgLib;
// Find dialog library for dialog, direct access is not possible here
StarBASIC* pStartedBasic = (StarBASIC*)pBasic;
SbxObject* pParentBasic = pStartedBasic ? pStartedBasic->GetParent() : NULL;
SbxObject* pParentParentBasic = pParentBasic ? pParentBasic->GetParent() : NULL;
SbxObject* pSearchBasic1 = NULL;
SbxObject* pSearchBasic2 = NULL;
if( pParentParentBasic )
{
pSearchBasic1 = pParentBasic;
pSearchBasic2 = pParentParentBasic;
}
else
{
pSearchBasic1 = pStartedBasic;
pSearchBasic2 = pParentBasic;
}
if( pSearchBasic1 )
{
aDlgLib = implFindDialogLibForDialog( aAnyISP, pSearchBasic1 );
if ( aDlgLib.is() )
pFoundBasic = (StarBASIC*)pSearchBasic1;
else if( pSearchBasic2 )
{
aDlgLib = implFindDialogLibForDialog( aAnyISP, pSearchBasic2 );
if ( aDlgLib.is() )
pFoundBasic = (StarBASIC*)pSearchBasic2;
}
}
return aDlgLib;
}
void RTL_Impl_CreateUnoDialog( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
{
(void)pBasic;
(void)bWrite;
Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
// We need at least 1 parameter
if ( rPar.Count() < 2 )
{
StarBASIC::Error( SbERR_BAD_ARGUMENT );
return;
}
// Get dialog
2001-03-03 15:19:45 +00:00
SbxBaseRef pObj = (SbxBase*)rPar.Get( 1 )->GetObject();
if( !(pObj && pObj->ISA(SbUnoObject)) )
{
StarBASIC::Error( SbERR_BAD_ARGUMENT );
return;
}
SbUnoObject* pUnoObj = (SbUnoObject*)(SbxBase*)pObj;
Any aAnyISP = pUnoObj->getUnoAny();
TypeClass eType = aAnyISP.getValueType().getTypeClass();
if( eType != TypeClass_INTERFACE )
{
2001-03-03 15:19:45 +00:00
StarBASIC::Error( SbERR_BAD_ARGUMENT );
return;
}
2001-03-19 11:42:53 +00:00
// Create new uno dialog
Reference< XNameContainer > xDialogModel( xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", xContext), UNO_QUERY );
Revert "fdo#46808, Convert awt::UnoControlDialogModel to new style" This reverts commit 6c61b20a8d4a6dcac28801cde82a211fb7e30654. As discussed at <http://lists.freedesktop.org/archives/libreoffice/2013-May/052449.html> "Re: fdo#46808, Convert awt::UnoControlDialogModel to new style problem" why the odd change in 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again" appears to fix things again: The problem is that the implementation of the css.awt.UnoControlDialogModel involves UNO aggregation (IMPL_CREATE_INSTANCE_WITH_GEOMETRY(UnoControlDialogModel) in toolkit/soruce/helper/registerservices.cxx creating a OGeometryControlModel<UnoControlDialogModel> instance that aggregates a UnoControlDialogModel instance). That means that queryInterface can return a reference to something that is technically a different object, and that's what's happening here, and explains why calling setPropertyValue in two different ways on what logically appears to be a single object can end up calling two different implementations (of two different physical objects). (UNO aggregation is known to be broken and should not be used. Nevertheless, there's still code that does---code that is a horrible mess and hard to clean up.) That all this worked as intended in the past is just sheer luck, but any way of substantially touching it is asking for trouble. I'm going to revert 6c61b20a8d4a6dcac28801cde82a211fb7e30654 again. I wasn't able to revert without also reverting be50ad28f5bbdaeff527f646481ce263843c2401 "fdo#46808, Convert awt::XUnoControlDialog to new style," as the two were tightly dependant. Also reverts all the follow-up fixes cb4b6dde8fda2a5848e11063028bf44d72f85431 "-Werror,-Wuninitialized" (sans the const-ness fix in UpdateHandler::insertControlModel), 697a007c61b9cabceb9767fad87cd5822b300452 "Fix exception specifications," 2ce6828bbbf6ba181bb2276adeec279e74151ef6 "fix awt::UnoControlModelDialog crash," and 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again." Conflicts: basctl/source/dlged/dlged.cxx filter/source/t602/t602filter.cxx xmlscript/test/imexp.cxx Change-Id: I5d133468062f3ca36300db52fbd699be1ac72998
2013-05-24 22:44:30 +02:00
if( !xDialogModel.is() )
{
return;
}
2001-03-19 11:42:53 +00:00
Reference< XInputStreamProvider > xISP;
aAnyISP >>= xISP;
if( !xISP.is() )
{
return;
}
// Import the DialogModel
2001-03-19 11:42:53 +00:00
Reference< XInputStream > xInput( xISP->createInputStream() );
// i83963 Force decoration
Revert "fdo#46808, Convert awt::UnoControlDialogModel to new style" This reverts commit 6c61b20a8d4a6dcac28801cde82a211fb7e30654. As discussed at <http://lists.freedesktop.org/archives/libreoffice/2013-May/052449.html> "Re: fdo#46808, Convert awt::UnoControlDialogModel to new style problem" why the odd change in 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again" appears to fix things again: The problem is that the implementation of the css.awt.UnoControlDialogModel involves UNO aggregation (IMPL_CREATE_INSTANCE_WITH_GEOMETRY(UnoControlDialogModel) in toolkit/soruce/helper/registerservices.cxx creating a OGeometryControlModel<UnoControlDialogModel> instance that aggregates a UnoControlDialogModel instance). That means that queryInterface can return a reference to something that is technically a different object, and that's what's happening here, and explains why calling setPropertyValue in two different ways on what logically appears to be a single object can end up calling two different implementations (of two different physical objects). (UNO aggregation is known to be broken and should not be used. Nevertheless, there's still code that does---code that is a horrible mess and hard to clean up.) That all this worked as intended in the past is just sheer luck, but any way of substantially touching it is asking for trouble. I'm going to revert 6c61b20a8d4a6dcac28801cde82a211fb7e30654 again. I wasn't able to revert without also reverting be50ad28f5bbdaeff527f646481ce263843c2401 "fdo#46808, Convert awt::XUnoControlDialog to new style," as the two were tightly dependant. Also reverts all the follow-up fixes cb4b6dde8fda2a5848e11063028bf44d72f85431 "-Werror,-Wuninitialized" (sans the const-ness fix in UpdateHandler::insertControlModel), 697a007c61b9cabceb9767fad87cd5822b300452 "Fix exception specifications," 2ce6828bbbf6ba181bb2276adeec279e74151ef6 "fix awt::UnoControlModelDialog crash," and 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again." Conflicts: basctl/source/dlged/dlged.cxx filter/source/t602/t602filter.cxx xmlscript/test/imexp.cxx Change-Id: I5d133468062f3ca36300db52fbd699be1ac72998
2013-05-24 22:44:30 +02:00
uno::Reference< beans::XPropertySet > xDlgModPropSet( xDialogModel, uno::UNO_QUERY );
if( xDlgModPropSet.is() )
{
Revert "fdo#46808, Convert awt::UnoControlDialogModel to new style" This reverts commit 6c61b20a8d4a6dcac28801cde82a211fb7e30654. As discussed at <http://lists.freedesktop.org/archives/libreoffice/2013-May/052449.html> "Re: fdo#46808, Convert awt::UnoControlDialogModel to new style problem" why the odd change in 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again" appears to fix things again: The problem is that the implementation of the css.awt.UnoControlDialogModel involves UNO aggregation (IMPL_CREATE_INSTANCE_WITH_GEOMETRY(UnoControlDialogModel) in toolkit/soruce/helper/registerservices.cxx creating a OGeometryControlModel<UnoControlDialogModel> instance that aggregates a UnoControlDialogModel instance). That means that queryInterface can return a reference to something that is technically a different object, and that's what's happening here, and explains why calling setPropertyValue in two different ways on what logically appears to be a single object can end up calling two different implementations (of two different physical objects). (UNO aggregation is known to be broken and should not be used. Nevertheless, there's still code that does---code that is a horrible mess and hard to clean up.) That all this worked as intended in the past is just sheer luck, but any way of substantially touching it is asking for trouble. I'm going to revert 6c61b20a8d4a6dcac28801cde82a211fb7e30654 again. I wasn't able to revert without also reverting be50ad28f5bbdaeff527f646481ce263843c2401 "fdo#46808, Convert awt::XUnoControlDialog to new style," as the two were tightly dependant. Also reverts all the follow-up fixes cb4b6dde8fda2a5848e11063028bf44d72f85431 "-Werror,-Wuninitialized" (sans the const-ness fix in UpdateHandler::insertControlModel), 697a007c61b9cabceb9767fad87cd5822b300452 "Fix exception specifications," 2ce6828bbbf6ba181bb2276adeec279e74151ef6 "fix awt::UnoControlModelDialog crash," and 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again." Conflicts: basctl/source/dlged/dlged.cxx filter/source/t602/t602filter.cxx xmlscript/test/imexp.cxx Change-Id: I5d133468062f3ca36300db52fbd699be1ac72998
2013-05-24 22:44:30 +02:00
bool bDecoration = true;
try
{
OUString aDecorationPropName("Decoration");
Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName );
aDecorationAny >>= bDecoration;
if( !bDecoration )
{
xDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) );
OUString aTitlePropName("Title");
xDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( OUString() ) );
}
}
catch(const UnknownPropertyException& )
{}
}
css::uno::Reference< css::container::XNameContainer > aDlgLib;
bool bDocDialog = false;
StarBASIC* pFoundBasic = NULL;
OSL_TRACE("About to try get a hold of ThisComponent");
2012-01-15 16:15:08 +01:00
Reference< frame::XModel > xModel = StarBASIC::GetModelFromBasic( GetSbData()->pInst->GetBasic() ) ;
aDlgLib = implFindDialogLibForDialogBasic( aAnyISP, GetSbData()->pInst->GetBasic(), pFoundBasic );
2010-10-24 20:28:48 +01:00
// If we found the dialog then it belongs to the Search basic
if ( !pFoundBasic )
{
Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
2010-10-24 20:28:48 +01:00
Reference< container::XEnumeration > xModels;
Reference< container::XEnumerationAccess > xComponents( xDesktop->getComponents(), UNO_QUERY );
if ( xComponents.is() )
2010-10-24 20:28:48 +01:00
{
xModels.set( xComponents->createEnumeration(), UNO_QUERY );
}
if ( xModels.is() )
{
while ( xModels->hasMoreElements() )
2010-10-24 20:28:48 +01:00
{
Reference< frame::XModel > xNextModel( xModels->nextElement(), UNO_QUERY );
if ( xNextModel.is() )
{
BasicManager* pMgr = basic::BasicManagerRepository::getDocumentBasicManager( xNextModel );
if ( pMgr )
{
aDlgLib = implFindDialogLibForDialogBasic( aAnyISP, pMgr->GetLib(0), pFoundBasic );
}
if ( aDlgLib.is() )
{
bDocDialog = true;
xModel = xNextModel;
break;
}
}
}
}
2010-10-24 20:28:48 +01:00
}
if ( pFoundBasic )
{
bDocDialog = pFoundBasic->IsDocBasic();
}
2012-01-15 16:15:08 +01:00
Reference< XScriptListener > xScriptListener = new BasicScriptListener_Impl( GetSbData()->pInst->GetBasic(), xModel );
// Create a "living" Dialog
2010-10-24 20:28:48 +01:00
Reference< XControl > xCntrl;
try
{
Reference< XDialogProvider > xDlgProv;;
if( bDocDialog )
xDlgProv = css::awt::DialogProvider::createWithModelAndScripting( xContext, xModel, xInput, aDlgLib, xScriptListener );
else
xDlgProv = css::awt::DialogProvider::createWithModelAndScripting( xContext, uno::Reference< frame::XModel >(), xInput, aDlgLib, xScriptListener );
xCntrl.set( xDlgProv->createDialog(OUString() ), UNO_QUERY_THROW );
2010-10-24 20:28:48 +01:00
// Add dialog model to dispose vector
Reference< XComponent > xDlgComponent( xCntrl->getModel(), UNO_QUERY );
2012-01-15 16:15:08 +01:00
GetSbData()->pInst->getComponentVector().push_back( xDlgComponent );
2010-10-24 20:28:48 +01:00
// need ThisCompoent from calling script
}
// preserve existing bad behaviour, it's possible... but probably
// illegal to open 2 dialogs ( they ARE modal ) when this happens, sometimes
// create dialog fails. So, in this case let's not throw, just leave basic
// detect the unset object.
catch(const uno::Exception& )
2010-10-24 20:28:48 +01:00
{
}
// Return dialog
2001-03-03 15:19:45 +00:00
Any aRetVal;
aRetVal <<= xCntrl;
SbxVariableRef refVar = rPar.Get(0);
2001-03-03 15:19:45 +00:00
unoToSbxValue( (SbxVariable*)refVar, aRetVal );
}
//===================================================================
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */