diff options
Diffstat (limited to 'framework/source/uifactory')
-rw-r--r-- | framework/source/uifactory/addonstoolboxfactory.cxx | 221 | ||||
-rwxr-xr-x | framework/source/uifactory/factoryconfiguration.cxx | 341 | ||||
-rw-r--r-- | framework/source/uifactory/makefile.mk | 54 | ||||
-rw-r--r-- | framework/source/uifactory/menubarfactory.cxx | 212 | ||||
-rw-r--r-- | framework/source/uifactory/popupmenucontrollerfactory.cxx | 93 | ||||
-rw-r--r-- | framework/source/uifactory/statusbarcontrollerfactory.cxx | 91 | ||||
-rw-r--r-- | framework/source/uifactory/statusbarfactory.cxx | 109 | ||||
-rw-r--r-- | framework/source/uifactory/toolbarcontrollerfactory.cxx | 262 | ||||
-rw-r--r-- | framework/source/uifactory/toolboxfactory.cxx | 105 | ||||
-rw-r--r-- | framework/source/uifactory/uielementfactorymanager.cxx | 547 | ||||
-rw-r--r-- | framework/source/uifactory/windowcontentfactorymanager.cxx | 266 |
11 files changed, 2301 insertions, 0 deletions
diff --git a/framework/source/uifactory/addonstoolboxfactory.cxx b/framework/source/uifactory/addonstoolboxfactory.cxx new file mode 100644 index 000000000000..68331e1e0e97 --- /dev/null +++ b/framework/source/uifactory/addonstoolboxfactory.cxx @@ -0,0 +1,221 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" +#include <uifactory/addonstoolboxfactory.hxx> + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include <uielement/addonstoolbarwrapper.hxx> +#include <threadhelp/resetableguard.hxx> + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> + +#ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPLLIER_HPP_ +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#endif + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <vcl/svapp.hxx> +#include <tools/urlobj.hxx> +#include <rtl/ustrbuf.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::frame; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace ::com::sun::star::ui; + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( AddonsToolBoxFactory , + ::cppu::OWeakObject , + SERVICENAME_TOOLBARFACTORY , + IMPLEMENTATIONNAME_ADDONSTOOLBARFACTORY + ) + +DEFINE_INIT_SERVICE ( AddonsToolBoxFactory, {} ) + +AddonsToolBoxFactory::AddonsToolBoxFactory( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : + ThreadHelpBase( &Application::GetSolarMutex() ) + , m_xServiceManager( xServiceManager ) + , m_xModuleManager( xServiceManager->createInstance(SERVICENAME_MODULEMANAGER),UNO_QUERY ) +{ +} + +AddonsToolBoxFactory::~AddonsToolBoxFactory() +{ +} + +static sal_Bool IsCorrectContext( const ::rtl::OUString& rModuleIdentifier, const rtl::OUString& aContextList ) +{ + if ( aContextList.getLength() == 0 ) + return sal_True; + + if ( rModuleIdentifier.getLength() > 0 ) + { + sal_Int32 nIndex = aContextList.indexOf( rModuleIdentifier ); + return ( nIndex >= 0 ); + } + + return sal_False; +} + +sal_Bool AddonsToolBoxFactory::hasButtonsInContext( + const Sequence< Sequence< PropertyValue > >& rPropSeqSeq, + const Reference< XFrame >& rFrame ) +{ + ::rtl::OUString aModuleIdentifier; + try + { + aModuleIdentifier = m_xModuleManager->identify( rFrame ); + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + + // Check before we create a toolbar that we have at least one button in + // the current frame context. + for ( sal_uInt32 i = 0; i < (sal_uInt32)rPropSeqSeq.getLength(); i++ ) + { + sal_Bool bIsButton( sal_True ); + sal_Bool bIsCorrectContext( sal_False ); + sal_uInt32 nPropChecked( 0 ); + + const Sequence< PropertyValue >& rPropSeq = rPropSeqSeq[i]; + for ( sal_uInt32 j = 0; j < (sal_uInt32)rPropSeq.getLength(); j++ ) + { + if ( rPropSeq[j].Name.equalsAsciiL( "Context", 7 )) + { + ::rtl::OUString aContextList; + if ( rPropSeq[j].Value >>= aContextList ) + bIsCorrectContext = IsCorrectContext( aModuleIdentifier, aContextList ); + nPropChecked++; + } + else if ( rPropSeq[j].Name.equalsAsciiL( "URL", 3 )) + { + ::rtl::OUString aURL; + rPropSeq[j].Value >>= aURL; + bIsButton = !aURL.equalsAsciiL( "private:separator", 17 ); + nPropChecked++; + } + + if ( nPropChecked == 2 ) + break; + } + + if ( bIsButton && bIsCorrectContext ) + return sal_True; + } + + return sal_False; +} + +// XUIElementFactory +Reference< XUIElement > SAL_CALL AddonsToolBoxFactory::createUIElement( + const ::rtl::OUString& ResourceURL, + const Sequence< PropertyValue >& Args ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ) +{ + // SAFE + ResetableGuard aLock( m_aLock ); + + Sequence< Sequence< PropertyValue > > aConfigData; + Reference< XFrame > xFrame; + rtl::OUString aResourceURL( ResourceURL ); + + for ( sal_Int32 n = 0; n < Args.getLength(); n++ ) + { + if ( Args[n].Name.equalsAscii( "ConfigurationData" )) + Args[n].Value >>= aConfigData; + else if ( Args[n].Name.equalsAscii( "Frame" )) + Args[n].Value >>= xFrame; + else if ( Args[n].Name.equalsAscii( "ResourceURL" )) + Args[n].Value >>= aResourceURL; + } + + if ( aResourceURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/addon_" ))) != 0 ) + throw IllegalArgumentException(); + + // Identify frame and determine module identifier to look for context based buttons + Reference< ::com::sun::star::ui::XUIElement > xToolBar; + if ( xFrame.is() && + ( aConfigData.getLength()> 0 ) && + hasButtonsInContext( aConfigData, xFrame )) + { + PropertyValue aPropValue; + Sequence< Any > aPropSeq( 3 ); + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); + aPropValue.Value <<= xFrame; + aPropSeq[0] <<= aPropValue; + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationData" )); + aPropValue.Value <<= aConfigData; + aPropSeq[1] <<= aPropValue; + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )); + aPropValue.Value <<= aResourceURL; + aPropSeq[2] <<= aPropValue; + + vos::OGuard aGuard( Application::GetSolarMutex() ); + AddonsToolBarWrapper* pToolBarWrapper = new AddonsToolBarWrapper( m_xServiceManager ); + xToolBar = Reference< ::com::sun::star::ui::XUIElement >( (OWeakObject *)pToolBarWrapper, UNO_QUERY ); + Reference< XInitialization > xInit( xToolBar, UNO_QUERY ); + xInit->initialize( aPropSeq ); + } + + return xToolBar; +} + +} + diff --git a/framework/source/uifactory/factoryconfiguration.cxx b/framework/source/uifactory/factoryconfiguration.cxx new file mode 100755 index 000000000000..505f3418ed8c --- /dev/null +++ b/framework/source/uifactory/factoryconfiguration.cxx @@ -0,0 +1,341 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include "uifactory/factoryconfiguration.hxx" +#include <threadhelp/resetableguard.hxx> +#include "services.h" + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <rtl/ustrbuf.hxx> +#include <cppuhelper/weak.hxx> +#include <rtl/logfile.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// +using namespace com::sun::star; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace ::com::sun::star::frame; + +//_________________________________________________________________________________________________________________ +// Namespace +//_________________________________________________________________________________________________________________ +// + +namespace framework +{ +rtl::OUString getHashKeyFromStrings( const rtl::OUString& aCommandURL, const rtl::OUString& aModuleName ) +{ + rtl::OUStringBuffer aKey( aCommandURL ); + aKey.appendAscii( "-" ); + aKey.append( aModuleName ); + return aKey.makeStringAndClear(); +} + +//***************************************************************************************************************** +// XInterface, XTypeProvider +//***************************************************************************************************************** +ConfigurationAccess_ControllerFactory::ConfigurationAccess_ControllerFactory( Reference< XMultiServiceFactory >& rServiceManager,const ::rtl::OUString& _sRoot,bool _bAskValue ) : + ThreadHelpBase(), + m_aPropCommand( RTL_CONSTASCII_USTRINGPARAM( "Command" )), + m_aPropModule( RTL_CONSTASCII_USTRINGPARAM( "Module" )), + m_aPropController( RTL_CONSTASCII_USTRINGPARAM( "Controller" )), + m_aPropValue( RTL_CONSTASCII_USTRINGPARAM( "Value" )), + m_sRoot(_sRoot), + m_xServiceManager( rServiceManager ), + m_bConfigAccessInitialized( sal_False ), + m_bAskValue(_bAskValue) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::ConfigurationAccess_ControllerFactory" ); + m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance( SERVICENAME_CFGPROVIDER),UNO_QUERY ); +} + +ConfigurationAccess_ControllerFactory::~ConfigurationAccess_ControllerFactory() +{ + // SAFE + ResetableGuard aLock( m_aLock ); + + Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY ); + if ( xContainer.is() ) + xContainer->removeContainerListener( this ); +} + +rtl::OUString ConfigurationAccess_ControllerFactory::getServiceFromCommandModule( const rtl::OUString& rCommandURL, const rtl::OUString& rModule ) const +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::getServiceFromCommandModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + MenuControllerMap::const_iterator pIter = m_aMenuControllerMap.find( getHashKeyFromStrings( rCommandURL, rModule )); + + if ( pIter != m_aMenuControllerMap.end() ) + return pIter->second.m_aImplementationName; + else if ( rModule.getLength() ) + { + // Try to detect if we have a generic popup menu controller + pIter = m_aMenuControllerMap.find( getHashKeyFromStrings( rCommandURL, rtl::OUString() )); + + if ( pIter != m_aMenuControllerMap.end() ) + return pIter->second.m_aImplementationName; + } + + return rtl::OUString(); +} +rtl::OUString ConfigurationAccess_ControllerFactory::getValueFromCommandModule( const rtl::OUString& rCommandURL, const rtl::OUString& rModule ) const +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::getValueFromCommandModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + MenuControllerMap::const_iterator pIter = m_aMenuControllerMap.find( getHashKeyFromStrings( rCommandURL, rModule )); + + if ( pIter != m_aMenuControllerMap.end() ) + return pIter->second.m_aValue; + else if ( rModule.getLength() ) + { + // Try to detect if we have a generic popup menu controller + pIter = m_aMenuControllerMap.find( getHashKeyFromStrings( rCommandURL, rtl::OUString() )); + + if ( pIter != m_aMenuControllerMap.end() ) + return pIter->second.m_aValue; + } + + return rtl::OUString(); +} + + +void ConfigurationAccess_ControllerFactory::addServiceToCommandModule( + const rtl::OUString& rCommandURL, + const rtl::OUString& rModule, + const rtl::OUString& rServiceSpecifier ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::addServiceToCommandModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + rtl::OUString aHashKey = getHashKeyFromStrings( rCommandURL, rModule ); + m_aMenuControllerMap.insert( MenuControllerMap::value_type( aHashKey,ControllerInfo(rServiceSpecifier,::rtl::OUString()) )); +} + +void ConfigurationAccess_ControllerFactory::removeServiceFromCommandModule( + const rtl::OUString& rCommandURL, + const rtl::OUString& rModule ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::removeServiceFromCommandModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + rtl::OUString aHashKey = getHashKeyFromStrings( rCommandURL, rModule ); + m_aMenuControllerMap.erase( aHashKey ); +} + +// container.XContainerListener +void SAL_CALL ConfigurationAccess_ControllerFactory::elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::elementInserted" ); + rtl::OUString aCommand; + rtl::OUString aModule; + rtl::OUString aService; + rtl::OUString aValue; + + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( impl_getElementProps( aEvent.Element, aCommand, aModule, aService, aValue )) + { + // Create hash key from command and module as they are together a primary key to + // the UNO service that implements the popup menu controller. + rtl::OUString aHashKey( getHashKeyFromStrings( aCommand, aModule )); + ControllerInfo& rControllerInfo = m_aMenuControllerMap[ aHashKey ]; + rControllerInfo.m_aImplementationName = aService; + rControllerInfo.m_aValue = aValue; + } +} + +void SAL_CALL ConfigurationAccess_ControllerFactory::elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::elementRemoved" ); + rtl::OUString aCommand; + rtl::OUString aModule; + rtl::OUString aService; + rtl::OUString aValue; + + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( impl_getElementProps( aEvent.Element, aCommand, aModule, aService, aValue )) + { + // Create hash key from command and module as they are together a primary key to + // the UNO service that implements the popup menu controller. + rtl::OUString aHashKey( getHashKeyFromStrings( aCommand, aModule )); + m_aMenuControllerMap.erase( aHashKey ); + } +} + +void SAL_CALL ConfigurationAccess_ControllerFactory::elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::elementReplaced" ); + elementInserted(aEvent); +} + +// lang.XEventListener +void SAL_CALL ConfigurationAccess_ControllerFactory::disposing( const EventObject& ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::disposing" ); + // SAFE + // remove our reference to the config access + ResetableGuard aLock( m_aLock ); + m_xConfigAccess.clear(); +} + +void ConfigurationAccess_ControllerFactory::readConfigurationData() +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::readConfigurationData" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigAccessInitialized ) + { + Sequence< Any > aArgs( 1 ); + PropertyValue aPropValue; + + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" )); + aPropValue.Value <<= m_sRoot; + aArgs[0] <<= aPropValue; + + try + { + m_xConfigAccess = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ), UNO_QUERY ); + } + catch ( WrappedTargetException& ) + { + } + + m_bConfigAccessInitialized = sal_True; + } + + if ( m_xConfigAccess.is() ) + { + // Read and update configuration data + updateConfigurationData(); + + uno::Reference< container::XContainer > xContainer( m_xConfigAccess, uno::UNO_QUERY ); + // UNSAFE + aLock.unlock(); + + if ( xContainer.is() ) + xContainer->addContainerListener( this ); + } +} + +void ConfigurationAccess_ControllerFactory::updateConfigurationData() +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::updateConfigurationData" ); + // SAFE + ResetableGuard aLock( m_aLock ); + if ( m_xConfigAccess.is() ) + { + Sequence< rtl::OUString > aPopupMenuControllers = m_xConfigAccess->getElementNames(); + + rtl::OUString aCommand; + rtl::OUString aModule; + rtl::OUString aService; + rtl::OUString aHashKey; + rtl::OUString aValue; + + m_aMenuControllerMap.clear(); + for ( sal_Int32 i = 0; i < aPopupMenuControllers.getLength(); i++ ) + { + try + { + if ( impl_getElementProps( m_xConfigAccess->getByName( aPopupMenuControllers[i] ), aCommand, aModule, aService,aValue )) + { + // Create hash key from command and module as they are together a primary key to + // the UNO service that implements the popup menu controller. + aHashKey = getHashKeyFromStrings( aCommand, aModule ); + m_aMenuControllerMap.insert( MenuControllerMap::value_type( aHashKey, ControllerInfo(aService,aValue) )); + } + } + catch ( NoSuchElementException& ) + { + } + catch ( WrappedTargetException& ) + { + } + } + } +} + +sal_Bool ConfigurationAccess_ControllerFactory::impl_getElementProps( const Any& aElement, rtl::OUString& aCommand, rtl::OUString& aModule, rtl::OUString& aServiceSpecifier,rtl::OUString& aValue ) const +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ConfigurationAccess_ControllerFactory::impl_getElementProps" ); + Reference< XPropertySet > xPropertySet; + aElement >>= xPropertySet; + + if ( xPropertySet.is() ) + { + try + { + xPropertySet->getPropertyValue( m_aPropCommand ) >>= aCommand; + xPropertySet->getPropertyValue( m_aPropModule ) >>= aModule; + xPropertySet->getPropertyValue( m_aPropController ) >>= aServiceSpecifier; + if ( m_bAskValue ) + xPropertySet->getPropertyValue( m_aPropValue ) >>= aValue; + } + catch ( com::sun::star::beans::UnknownPropertyException& ) + { + return sal_False; + } + catch ( com::sun::star::lang::WrappedTargetException& ) + { + return sal_False; + } + } + + return sal_True; +} +} // namespace framework diff --git a/framework/source/uifactory/makefile.mk b/framework/source/uifactory/makefile.mk new file mode 100644 index 000000000000..cf820e98738f --- /dev/null +++ b/framework/source/uifactory/makefile.mk @@ -0,0 +1,54 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=framework +TARGET= fwk_uifactory +ENABLE_EXCEPTIONS= TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Generate ----------------------------------------------------- + +SLOFILES= \ + $(SLO)$/popupmenucontrollerfactory.obj \ + $(SLO)$/uielementfactorymanager.obj \ + $(SLO)$/menubarfactory.obj \ + $(SLO)$/toolboxfactory.obj \ + $(SLO)$/addonstoolboxfactory.obj \ + $(SLO)$/toolbarcontrollerfactory.obj \ + $(SLO)$/statusbarfactory.obj \ + $(SLO)$/statusbarcontrollerfactory.obj \ + $(SLO)$/factoryconfiguration.obj \ + $(SLO)$/windowcontentfactorymanager.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/framework/source/uifactory/menubarfactory.cxx b/framework/source/uifactory/menubarfactory.cxx new file mode 100644 index 000000000000..3cc132d9cb48 --- /dev/null +++ b/framework/source/uifactory/menubarfactory.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" +#include <uifactory/menubarfactory.hxx> + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include <threadhelp/resetableguard.hxx> +#include "services.h" +#include <uielement/menubarwrapper.hxx> + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> + +#ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPLLIER_HPP_ +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#endif + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ + +#ifndef _VCL_MENU_HXX_ +#include <vcl/menu.hxx> +#endif +#include <vcl/svapp.hxx> +#include <tools/urlobj.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/logfile.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::frame; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace ::com::sun::star::ui; + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( MenuBarFactory , + ::cppu::OWeakObject , + SERVICENAME_MENUBARFACTORY , + IMPLEMENTATIONNAME_MENUBARFACTORY + ) + +DEFINE_INIT_SERVICE ( MenuBarFactory, {} ) + +MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : + ThreadHelpBase() + , m_xServiceManager( xServiceManager ) + , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ) +{ +} +MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool ) : + ThreadHelpBase(&Application::GetSolarMutex()) + , m_xServiceManager( xServiceManager ) + , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ) +{ +} + +MenuBarFactory::~MenuBarFactory() +{ +} + +// XUIElementFactory +Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement( + const ::rtl::OUString& ResourceURL, + const Sequence< PropertyValue >& Args ) +throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ) +{ + // SAFE + ResetableGuard aLock( m_aLock ); + MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xServiceManager ); + Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY ); + Reference< ::com::sun::star::frame::XModuleManager > xModuleManager = m_xModuleManager; + aLock.unlock(); + CreateUIElement(ResourceURL,Args,"MenuOnly","private:resource/menubar/",xMenuBar,xModuleManager,m_xServiceManager); + return xMenuBar; +} +void MenuBarFactory::CreateUIElement(const ::rtl::OUString& ResourceURL + , const Sequence< PropertyValue >& Args + ,const char* _pExtraMode + ,const char* _pAsciiName + ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar + ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >& _xModuleManager + ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager) +{ + Reference< XUIConfigurationManager > xCfgMgr; + Reference< XUIConfigurationManager > xConfigSource; + Reference< XFrame > xFrame; + rtl::OUString aResourceURL( ResourceURL ); + sal_Bool bPersistent( sal_True ); + sal_Bool bExtraMode( sal_False ); + + for ( sal_Int32 n = 0; n < Args.getLength(); n++ ) + { + if ( Args[n].Name.equalsAscii( "ConfigurationSource" )) + Args[n].Value >>= xConfigSource; + else if ( Args[n].Name.equalsAscii( "Frame" )) + Args[n].Value >>= xFrame; + else if ( Args[n].Name.equalsAscii( "ResourceURL" )) + Args[n].Value >>= aResourceURL; + else if ( Args[n].Name.equalsAscii( "Persistent" )) + Args[n].Value >>= bPersistent; + else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode )) + Args[n].Value >>= bExtraMode; + } // for ( sal_Int32 n = 0; n < Args.getLength(); n++ ) + if ( aResourceURL.indexOf( rtl::OUString::createFromAscii(_pAsciiName)) != 0 ) + throw IllegalArgumentException(); + + // Identify frame and determine document based ui configuration manager/module ui configuration manager + if ( xFrame.is() && !xConfigSource.is() ) + { + bool bHasSettings( false ); + Reference< XModel > xModel; + + Reference< XController > xController = xFrame->getController(); + if ( xController.is() ) + xModel = xController->getModel(); + + if ( xModel.is() ) + { + Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY ); + if ( xUIConfigurationManagerSupplier.is() ) + { + xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager(); + bHasSettings = xCfgMgr->hasSettings( aResourceURL ); + } + } + + if ( !bHasSettings ) + { + rtl::OUString aModuleIdentifier = _xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY )); + if ( aModuleIdentifier.getLength() ) + { + Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier( + _xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY ); + xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier ); + bHasSettings = xCfgMgr->hasSettings( aResourceURL ); + } + } + } + + PropertyValue aPropValue; + Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4); + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); + aPropValue.Value <<= xFrame; + aPropSeq[0] <<= aPropValue; + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" )); + aPropValue.Value <<= xCfgMgr; + aPropSeq[1] <<= aPropValue; + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )); + aPropValue.Value <<= aResourceURL; + aPropSeq[2] <<= aPropValue; + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )); + aPropValue.Value <<= bPersistent; + aPropSeq[3] <<= aPropValue; + if ( _pExtraMode ) + { + aPropValue.Name = rtl::OUString::createFromAscii(_pExtraMode); + aPropValue.Value <<= bExtraMode; + aPropSeq[4] <<= aPropValue; + } + + vos::OGuard aGuard( Application::GetSolarMutex() ); + Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY ); + xInit->initialize( aPropSeq ); +} + +} // namespace framework diff --git a/framework/source/uifactory/popupmenucontrollerfactory.cxx b/framework/source/uifactory/popupmenucontrollerfactory.cxx new file mode 100644 index 000000000000..8736aa5dcf80 --- /dev/null +++ b/framework/source/uifactory/popupmenucontrollerfactory.cxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include "uifactory/popupmenucontrollerfactory.hxx" +#include <threadhelp/resetableguard.hxx> +#include "services.h" +#include "uifactory/factoryconfiguration.hxx" + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <rtl/ustrbuf.hxx> +#include <cppuhelper/weak.hxx> +#include <rtl/logfile.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace ::com::sun::star::frame; + +//_________________________________________________________________________________________________________________ +// Namespace +//_________________________________________________________________________________________________________________ +// + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( PopupMenuControllerFactory , + ::cppu::OWeakObject , + SERVICENAME_POPUPMENUCONTROLLERFACTORY , + IMPLEMENTATIONNAME_POPUPMENUCONTROLLERFACTORY + ) + +DEFINE_INIT_SERVICE ( PopupMenuControllerFactory, {} ) + +PopupMenuControllerFactory::PopupMenuControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) : + ToolbarControllerFactory(xServiceManager,true) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PopupMenuControllerFactory::PopupMenuControllerFactory" ); + m_pConfigAccess = new ConfigurationAccess_ControllerFactory( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/PopupMenu" )) ); + m_pConfigAccess->acquire(); +} + +} // namespace framework diff --git a/framework/source/uifactory/statusbarcontrollerfactory.cxx b/framework/source/uifactory/statusbarcontrollerfactory.cxx new file mode 100644 index 000000000000..cfbfcd49e23f --- /dev/null +++ b/framework/source/uifactory/statusbarcontrollerfactory.cxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include "uifactory/statusbarcontrollerfactory.hxx" +#include "uifactory/factoryconfiguration.hxx" +#include <threadhelp/resetableguard.hxx> +#include "services.h" + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <rtl/ustrbuf.hxx> +#include <cppuhelper/weak.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace ::com::sun::star::frame; + +//_________________________________________________________________________________________________________________ +// Namespace +//_________________________________________________________________________________________________________________ +// + +namespace framework +{ +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( StatusbarControllerFactory , + ::cppu::OWeakObject , + SERVICENAME_STATUSBARCONTROLLERFACTORY , + IMPLEMENTATIONNAME_STATUSBARCONTROLLERFACTORY + ) + +DEFINE_INIT_SERVICE ( StatusbarControllerFactory, {} ) + +StatusbarControllerFactory::StatusbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) : + ToolbarControllerFactory(xServiceManager,true) +{ + m_pConfigAccess = new ConfigurationAccess_ControllerFactory( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/StatusBar" )),true ); + m_pConfigAccess->acquire(); +} + + +} // namespace framework diff --git a/framework/source/uifactory/statusbarfactory.cxx b/framework/source/uifactory/statusbarfactory.cxx new file mode 100644 index 000000000000..ddbe47912a0e --- /dev/null +++ b/framework/source/uifactory/statusbarfactory.cxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" +#include <uifactory/statusbarfactory.hxx> +#include <uifactory/menubarfactory.hxx> + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include <uielement/statusbarwrapper.hxx> +#include <threadhelp/resetableguard.hxx> + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> + +#ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPLLIER_HPP_ +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#endif + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <vcl/svapp.hxx> +#include <tools/urlobj.hxx> +#include <rtl/ustrbuf.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::frame; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace ::com::sun::star::ui; + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( StatusBarFactory , + ::cppu::OWeakObject , + SERVICENAME_STATUSBARFACTORY , + IMPLEMENTATIONNAME_STATUSBARFACTORY + ) + +DEFINE_INIT_SERVICE ( StatusBarFactory, {} ) + +StatusBarFactory::StatusBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : + MenuBarFactory( xServiceManager,true ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarFactory::StatusBarFactory" ); +} + +// XUIElementFactory +Reference< XUIElement > SAL_CALL StatusBarFactory::createUIElement( + const ::rtl::OUString& ResourceURL, + const Sequence< PropertyValue >& Args ) +throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarFactory::createUIElement" ); + // SAFE + ResetableGuard aLock( m_aLock ); + StatusBarWrapper* pWrapper = new StatusBarWrapper( m_xServiceManager ); + Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pWrapper, UNO_QUERY ); + Reference< ::com::sun::star::frame::XModuleManager > xModuleManager = m_xModuleManager; + aLock.unlock(); + MenuBarFactory::CreateUIElement(ResourceURL,Args,NULL,"private:resource/statusbar/",xMenuBar,xModuleManager,m_xServiceManager); + return xMenuBar; +} + +} + diff --git a/framework/source/uifactory/toolbarcontrollerfactory.cxx b/framework/source/uifactory/toolbarcontrollerfactory.cxx new file mode 100644 index 000000000000..1905375f7022 --- /dev/null +++ b/framework/source/uifactory/toolbarcontrollerfactory.cxx @@ -0,0 +1,262 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include "uifactory/toolbarcontrollerfactory.hxx" +#include "uifactory/factoryconfiguration.hxx" +#include <threadhelp/resetableguard.hxx> +#include "services.h" + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <rtl/ustrbuf.hxx> +#include <cppuhelper/weak.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace ::com::sun::star::frame; + +//_________________________________________________________________________________________________________________ +// Namespace +//_________________________________________________________________________________________________________________ +// + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ToolbarControllerFactory , + ::cppu::OWeakObject , + SERVICENAME_TOOLBARCONTROLLERFACTORY , + IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY + ) + +DEFINE_INIT_SERVICE ( ToolbarControllerFactory, {} ) + +ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) : + ThreadHelpBase(), + m_bConfigRead( sal_False ), + m_xServiceManager( xServiceManager ) +{ + m_pConfigAccess = new ConfigurationAccess_ControllerFactory( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/ToolBar" )) ); + m_pConfigAccess->acquire(); +} + +ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager,bool ) : + ThreadHelpBase(), + m_bConfigRead( sal_False ), + m_xServiceManager( xServiceManager ) +{ + m_pConfigAccess = NULL; +} + +ToolbarControllerFactory::~ToolbarControllerFactory() +{ + ResetableGuard aLock( m_aLock ); + + // reduce reference count + m_pConfigAccess->release(); +} + +// XMultiComponentFactory +Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithContext( + const ::rtl::OUString& aServiceSpecifier, + const Reference< XComponentContext >& ) +throw (Exception, RuntimeException) +{ + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( aServiceSpecifier, rtl::OUString() ); + if ( aServiceName.getLength() > 0 ) + return m_xServiceManager->createInstance( aServiceName ); + else + return Reference< XInterface >(); + // SAFE +} + +Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithArgumentsAndContext( + const ::rtl::OUString& ServiceSpecifier, + const Sequence< Any >& Arguments, + const Reference< XComponentContext >& ) +throw (Exception, RuntimeException) +{ + const rtl::OUString aPropModuleName( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" )); + const rtl::OUString aPropValueName( RTL_CONSTASCII_USTRINGPARAM( "Value" )); + + rtl::OUString aPropName; + PropertyValue aPropValue; + + // Retrieve the optional module name form the Arguments sequence. It is used as a part of + // the hash map key to support different controller implementation for the same URL but different + // module!! + for ( int i = 0; i < Arguments.getLength(); i++ ) + { + if (( Arguments[i] >>= aPropValue ) && ( aPropValue.Name.equals( aPropModuleName ))) + { + aPropValue.Value >>= aPropName; + break; + } + } + + Sequence< Any > aNewArgs( Arguments ); + + sal_Int32 nAppendIndex = aNewArgs.getLength(); + bool bHasValue = m_pConfigAccess->hasValue(); + aNewArgs.realloc( aNewArgs.getLength() + (bHasValue ? 2 : 1) ); + + // Append the command URL to the Arguments sequence so that one controller can be + // used for more than one command URL. + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )); + aPropValue.Value <<= ServiceSpecifier; + aNewArgs[nAppendIndex] <<= aPropValue; + + if ( bHasValue ) + { + // Append the optional value argument. It's an empty string if no additional info + // is provided to the controller. + rtl::OUString aValue = m_pConfigAccess->getValueFromCommandModule( ServiceSpecifier, aPropName ); + aPropValue.Name = aPropValueName; + aPropValue.Value <<= aValue; + aNewArgs[nAppendIndex+1] <<= aPropValue; + } + + { + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( ServiceSpecifier, aPropName ); + Reference< XMultiServiceFactory > xServiceManager( m_xServiceManager ); + + aLock.unlock(); + // SAFE + + + if ( aServiceName.getLength() > 0 ) + return xServiceManager->createInstanceWithArguments( aServiceName, aNewArgs ); + else + return Reference< XInterface >(); + } +} + +Sequence< ::rtl::OUString > SAL_CALL ToolbarControllerFactory::getAvailableServiceNames() +throw (RuntimeException) +{ + return Sequence< ::rtl::OUString >(); +} + +// XUIControllerRegistration +sal_Bool SAL_CALL ToolbarControllerFactory::hasController( + const ::rtl::OUString& aCommandURL, + const rtl::OUString& aModuleName ) +throw (::com::sun::star::uno::RuntimeException) +{ + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + return ( m_pConfigAccess->getServiceFromCommandModule( aCommandURL, aModuleName ).getLength() > 0 ); +} + +void SAL_CALL ToolbarControllerFactory::registerController( + const ::rtl::OUString& aCommandURL, + const ::rtl::OUString& aModuleName, + const ::rtl::OUString& aControllerImplementationName ) +throw (RuntimeException) +{ + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + m_pConfigAccess->addServiceToCommandModule( aCommandURL, aModuleName, aControllerImplementationName ); + // SAFE +} + +void SAL_CALL ToolbarControllerFactory::deregisterController( + const ::rtl::OUString& aCommandURL, + const rtl::OUString& aModuleName ) +throw (RuntimeException) +{ + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + m_pConfigAccess->removeServiceFromCommandModule( aCommandURL, aModuleName ); + // SAFE +} + +} // namespace framework diff --git a/framework/source/uifactory/toolboxfactory.cxx b/framework/source/uifactory/toolboxfactory.cxx new file mode 100644 index 000000000000..f2e9aa9bc0d2 --- /dev/null +++ b/framework/source/uifactory/toolboxfactory.cxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" +#include <uifactory/toolboxfactory.hxx> + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include <uielement/toolbarwrapper.hxx> +#include <threadhelp/resetableguard.hxx> + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> + +#ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPLLIER_HPP_ +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#endif + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <vcl/svapp.hxx> +#include <tools/urlobj.hxx> +#include <rtl/ustrbuf.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::frame; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace ::com::sun::star::ui; + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ToolBoxFactory , + ::cppu::OWeakObject , + SERVICENAME_TOOLBARFACTORY , + IMPLEMENTATIONNAME_TOOLBARFACTORY + ) + +DEFINE_INIT_SERVICE ( ToolBoxFactory, {} ) + +ToolBoxFactory::ToolBoxFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : + MenuBarFactory( xServiceManager,true ) +{ +} + +// XUIElementFactory +Reference< XUIElement > SAL_CALL ToolBoxFactory::createUIElement( + const ::rtl::OUString& ResourceURL, + const Sequence< PropertyValue >& Args ) +throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ) +{ + ResetableGuard aLock( m_aLock ); + ToolBarWrapper* pWrapper = new ToolBarWrapper( m_xServiceManager ); + Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pWrapper, UNO_QUERY ); + Reference< ::com::sun::star::frame::XModuleManager > xModuleManager = m_xModuleManager; + aLock.unlock(); + CreateUIElement(ResourceURL,Args,"PopupMode","private:resource/toolbar/",xMenuBar,xModuleManager,m_xServiceManager); + return xMenuBar; +} + +} + diff --git a/framework/source/uifactory/uielementfactorymanager.cxx b/framework/source/uifactory/uielementfactorymanager.cxx new file mode 100644 index 000000000000..171acce9cb72 --- /dev/null +++ b/framework/source/uifactory/uielementfactorymanager.cxx @@ -0,0 +1,547 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include <uifactory/uielementfactorymanager.hxx> +#include <uifactory/windowcontentfactorymanager.hxx> +#include <threadhelp/resetableguard.hxx> +#include "services.h" + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> +#include <com/sun/star/frame/XFrame.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <rtl/ustrbuf.hxx> +#include <cppuhelper/weak.hxx> +#include <tools/urlobj.hxx> +#include <vcl/svapp.hxx> +#include <rtl/logfile.hxx> +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::frame; +using namespace com::sun::star::container; +using namespace ::com::sun::star::ui; +using namespace ::com::sun::star::frame; + +//_________________________________________________________________________________________________________________ +// Namespace +//_________________________________________________________________________________________________________________ +// + +namespace framework +{ + +// global function needed by both implementations +rtl::OUString getHashKeyFromStrings( const rtl::OUString& aType, const rtl::OUString& aName, const rtl::OUString& aModuleName ) +{ + rtl::OUStringBuffer aKey( aType ); + aKey.appendAscii( "^" ); + aKey.append( aName ); + aKey.appendAscii( "^" ); + aKey.append( aModuleName ); + return aKey.makeStringAndClear(); +} + + +//***************************************************************************************************************** +// Configuration access class for UIElementFactoryManager implementation +//***************************************************************************************************************** + + +ConfigurationAccess_FactoryManager::ConfigurationAccess_FactoryManager( Reference< XMultiServiceFactory >& rServiceManager,const ::rtl::OUString& _sRoot ) : + ThreadHelpBase(), + m_aPropType( RTL_CONSTASCII_USTRINGPARAM( "Type" )), + m_aPropName( RTL_CONSTASCII_USTRINGPARAM( "Name" )), + m_aPropModule( RTL_CONSTASCII_USTRINGPARAM( "Module" )), + m_aPropFactory( RTL_CONSTASCII_USTRINGPARAM( "FactoryImplementation" )), + m_sRoot(_sRoot), + m_xServiceManager( rServiceManager ), + m_bConfigAccessInitialized( sal_False ), + m_bConfigDirty(true) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::ConfigurationAccess_FactoryManager" ); + m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance( SERVICENAME_CFGPROVIDER),UNO_QUERY ); +} + +ConfigurationAccess_FactoryManager::~ConfigurationAccess_FactoryManager() +{ + // SAFE + ResetableGuard aLock( m_aLock ); + + Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY ); + if ( xContainer.is() ) + xContainer->removeContainerListener( this ); +} + +rtl::OUString ConfigurationAccess_FactoryManager::getFactorySpecifierFromTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule ) const +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getFactorySpecifierFromTypeNameModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + FactoryManagerMap::const_iterator pIter = + m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, rModule )); + if ( pIter != m_aFactoryManagerMap.end() ) + return pIter->second; + else + { + pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rName, rtl::OUString() )); + if ( pIter != m_aFactoryManagerMap.end() ) + return pIter->second; + else + { + // Support factories which uses a defined prefix before the ui name. + sal_Int32 nIndex = rName.indexOf( '_' ); + if ( nIndex > 0 ) + { + rtl::OUString aName = rName.copy( 0, nIndex+1 ); + pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, aName, rtl::OUString() )); + if ( pIter != m_aFactoryManagerMap.end() ) + return pIter->second; + } + + pIter = m_aFactoryManagerMap.find( getHashKeyFromStrings( rType, rtl::OUString(), rtl::OUString() )); + if ( pIter != m_aFactoryManagerMap.end() ) + return pIter->second; + } + } + + return rtl::OUString(); +} + +void ConfigurationAccess_FactoryManager::addFactorySpecifierToTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule, const rtl::OUString& rServiceSpecifier ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::addFactorySpecifierToTypeNameModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + rtl::OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule ); + + FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey ); + + if ( pIter != m_aFactoryManagerMap.end() ) + throw ElementExistException(); + else + m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, rServiceSpecifier )); +} + + +void ConfigurationAccess_FactoryManager::removeFactorySpecifierFromTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::removeFactorySpecifierFromTypeNameModule" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + rtl::OUString aHashKey = getHashKeyFromStrings( rType, rName, rModule ); + + FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.find( aHashKey ); + + if ( pIter == m_aFactoryManagerMap.end() ) + throw NoSuchElementException(); + else + m_aFactoryManagerMap.erase( aHashKey ); +} + +Sequence< Sequence< PropertyValue > > ConfigurationAccess_FactoryManager::getFactoriesDescription() const +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getFactoriesDescription" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + Sequence< Sequence< PropertyValue > > aSeqSeq; + + sal_Int32 nIndex( 0 ); + FactoryManagerMap::const_iterator pIter = m_aFactoryManagerMap.begin(); + while ( pIter != m_aFactoryManagerMap.end() ) + { + rtl::OUString aFactory = pIter->first; + if ( aFactory.getLength() > 0 ) + { + sal_Int32 nToken = 0; + Sequence< PropertyValue > aSeq( 1 ); + + aSeqSeq.realloc( aSeqSeq.getLength() + 1 ); + aSeq[0].Name = m_aPropType; + aSeq[0].Value = makeAny( aFactory.getToken( 0, '^', nToken )); + if ( nToken > 0 ) + { + aSeq.realloc( 2 ); + aSeq[1].Name = m_aPropName; + aSeq[1].Value = makeAny( aFactory.getToken( 0, '^', nToken )); + if ( nToken > 0 ) + { + aSeq.realloc( 3 ); + aSeq[2].Name = m_aPropModule; + aSeq[2].Value = makeAny( aFactory.getToken( 0, '^', nToken )); + } + } + + aSeqSeq[nIndex++] = aSeq; + } + + ++pIter; + } + + return aSeqSeq; +} + +// container.XContainerListener +void SAL_CALL ConfigurationAccess_FactoryManager::elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::elementInserted" ); + rtl::OUString aType; + rtl::OUString aName; + rtl::OUString aModule; + rtl::OUString aService; + + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService )) + { + // Create hash key from type, name and module as they are together a primary key to + // the UNO service that implements a user interface factory. + rtl::OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule )); + m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService )); + } +} + +void SAL_CALL ConfigurationAccess_FactoryManager::elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::elementRemoved " ); + rtl::OUString aType; + rtl::OUString aName; + rtl::OUString aModule; + rtl::OUString aService; + + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService )) + { + // Create hash key from command and model as they are together a primary key to + // the UNO service that implements the popup menu controller. + rtl::OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule )); + m_aFactoryManagerMap.erase( aHashKey ); + } +} + +void SAL_CALL ConfigurationAccess_FactoryManager::elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::elementReplaced" ); + rtl::OUString aType; + rtl::OUString aName; + rtl::OUString aModule; + rtl::OUString aService; + + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( impl_getElementProps( aEvent.Element, aType, aName, aModule, aService )) + { + // Create hash key from command and model as they are together a primary key to + // the UNO service that implements the popup menu controller. + rtl::OUString aHashKey( getHashKeyFromStrings( aType, aName, aModule )); + m_aFactoryManagerMap.erase( aHashKey ); + m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService )); + } +} + +// lang.XEventListener +void SAL_CALL ConfigurationAccess_FactoryManager::disposing( const EventObject& ) throw(RuntimeException) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::disposing" ); + // SAFE + // remove our reference to the config access + ResetableGuard aLock( m_aLock ); + m_xConfigAccess.clear(); +} + +void ConfigurationAccess_FactoryManager::readConfigurationData() +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::readConfigurationData" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigAccessInitialized ) + { + Sequence< Any > aArgs( 1 ); + PropertyValue aPropValue; + + aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" )); + aPropValue.Value <<= m_sRoot; + aArgs[0] <<= aPropValue; + + try + { + m_xConfigAccess.set( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ), UNO_QUERY ); + } + catch ( WrappedTargetException& ) + { + } + + m_bConfigAccessInitialized = sal_True; + } + + if ( m_xConfigAccess.is() ) + { + Sequence< rtl::OUString > aUIElementFactories = m_xConfigAccess->getElementNames(); + + rtl::OUString aType; + rtl::OUString aName; + rtl::OUString aModule; + rtl::OUString aService; + rtl::OUString aHashKey; + Reference< XPropertySet > xPropertySet; + for ( sal_Int32 i = 0; i < aUIElementFactories.getLength(); i++ ) + { + if ( impl_getElementProps( m_xConfigAccess->getByName( aUIElementFactories[i] ), aType, aName, aModule, aService )) + { + // Create hash key from type, name and module as they are together a primary key to + // the UNO service that implements the user interface element factory. + aHashKey = getHashKeyFromStrings( aType, aName, aModule ); + m_aFactoryManagerMap.insert( FactoryManagerMap::value_type( aHashKey, aService )); + } + } + + Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY ); + aLock.unlock(); + // UNSAFE + if ( xContainer.is() ) + xContainer->addContainerListener( this ); + } +} + +sal_Bool ConfigurationAccess_FactoryManager::impl_getElementProps( const Any& aElement, rtl::OUString& rType, rtl::OUString& rName, rtl::OUString& rModule, rtl::OUString& rServiceSpecifier ) const +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::impl_getElementProps" ); + Reference< XPropertySet > xPropertySet; + aElement >>= xPropertySet; + + if ( xPropertySet.is() ) + { + try + { + xPropertySet->getPropertyValue( m_aPropType ) >>= rType; + xPropertySet->getPropertyValue( m_aPropName ) >>= rName; + xPropertySet->getPropertyValue( m_aPropModule ) >>= rModule; + xPropertySet->getPropertyValue( m_aPropFactory ) >>= rServiceSpecifier; + } + catch ( com::sun::star::beans::UnknownPropertyException& ) + { + return sal_False; + } + catch ( com::sun::star::lang::WrappedTargetException& ) + { + return sal_False; + } + } + + return sal_True; +} + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( UIElementFactoryManager , + ::cppu::OWeakObject , + SERVICENAME_UIELEMENTFACTORYMANAGER , + IMPLEMENTATIONNAME_UIELEMENTFACTORYMANAGER + ) + +DEFINE_INIT_SERVICE ( UIElementFactoryManager, {} ) + +UIElementFactoryManager::UIElementFactoryManager( const Reference< XMultiServiceFactory >& xServiceManager ) : + ThreadHelpBase( &Application::GetSolarMutex() ), + m_bConfigRead( sal_False ), + m_xServiceManager( xServiceManager ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::UIElementFactoryManager" ); + m_pConfigAccess = new ConfigurationAccess_FactoryManager( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories" )) ); + m_pConfigAccess->acquire(); + m_xModuleManager = Reference< XModuleManager >( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ); +} + +UIElementFactoryManager::~UIElementFactoryManager() +{ + ResetableGuard aLock( m_aLock ); + + // reduce reference count + m_pConfigAccess->release(); +} + +// XUIElementFactory +Reference< XUIElement > SAL_CALL UIElementFactoryManager::createUIElement( + const ::rtl::OUString& ResourceURL, + const Sequence< PropertyValue >& Args ) +throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::createUIElement" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + const rtl::OUString aPropFrame( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); + + rtl::OUString aModuleId; + PropertyValue aPropValue; + Reference< XFrame > xFrame; + + // Retrieve the frame instance from the arguments to determine the module identifier. This must be provided + // to the search function. An empty module identifier is provided if the frame is missing or the module id cannot + // retrieve from it. + for ( int i = 0; i < Args.getLength(); i++ ) + { + if ( Args[i].Name.equals( aPropFrame )) + Args[i].Value >>= xFrame; + } + + Reference< XModuleManager > xManager( m_xModuleManager ); + aLock.unlock(); + + // Determine the module identifier + try + { + if ( xFrame.is() && xManager.is() ) + aModuleId = xManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ) ); + + Reference< XUIElementFactory > xUIElementFactory = getFactory( ResourceURL, aModuleId ); + if ( xUIElementFactory.is() ) + return xUIElementFactory->createUIElement( ResourceURL, Args ); + } + catch ( UnknownModuleException& ) + { + } + + throw NoSuchElementException(); +} + +// XUIElementFactoryRegistration +Sequence< Sequence< PropertyValue > > SAL_CALL UIElementFactoryManager::getRegisteredFactories() +throw ( RuntimeException ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getRegisteredFactories" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + return m_pConfigAccess->getFactoriesDescription(); +} + +Reference< XUIElementFactory > SAL_CALL UIElementFactoryManager::getFactory( const ::rtl::OUString& aResourceURL, const ::rtl::OUString& aModuleId ) +throw ( RuntimeException ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::getFactory" ); + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + rtl::OUString aType; + rtl::OUString aName; + + WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName ); + + Reference< XMultiServiceFactory > xSManager( m_xServiceManager ); + + rtl::OUString aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId ); + + aLock.unlock(); + if ( aServiceSpecifier.getLength() ) + return Reference< XUIElementFactory >( xSManager->createInstance( aServiceSpecifier ), UNO_QUERY ); + else + return Reference< XUIElementFactory >(); +} + +void SAL_CALL UIElementFactoryManager::registerFactory( const ::rtl::OUString& aType, const ::rtl::OUString& aName, const ::rtl::OUString& aModuleId, const ::rtl::OUString& aFactoryImplementationName ) +throw ( ElementExistException, RuntimeException ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::registerFactory" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + m_pConfigAccess->addFactorySpecifierToTypeNameModule( aType, aName, aModuleId, aFactoryImplementationName ); + // SAFE +} + +void SAL_CALL UIElementFactoryManager::deregisterFactory( const ::rtl::OUString& aType, const ::rtl::OUString& aName, const ::rtl::OUString& aModuleId ) +throw ( NoSuchElementException, RuntimeException ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UIElementFactoryManager::deregisterFactory" ); + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + m_pConfigAccess->removeFactorySpecifierFromTypeNameModule( aType, aName, aModuleId ); + // SAFE +} + +} // namespace framework diff --git a/framework/source/uifactory/windowcontentfactorymanager.cxx b/framework/source/uifactory/windowcontentfactorymanager.cxx new file mode 100644 index 000000000000..352fc1ad21f7 --- /dev/null +++ b/framework/source/uifactory/windowcontentfactorymanager.cxx @@ -0,0 +1,266 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_framework.hxx" + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ +#include <uifactory/windowcontentfactorymanager.hxx> +#include <uifactory/uielementfactorymanager.hxx> +#include <threadhelp/resetableguard.hxx> +#include "services.h" + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/awt/XToolkit.hpp> +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/awt/XControl.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <rtl/ustrbuf.hxx> +#include <cppuhelper/weak.hxx> +#include <tools/urlobj.hxx> +#include <vcl/svapp.hxx> + +//_________________________________________________________________________________________________________________ +// Defines +//_________________________________________________________________________________________________________________ +// + +using namespace ::com::sun::star; + +//_________________________________________________________________________________________________________________ +// Namespace +//_________________________________________________________________________________________________________________ +// + +namespace framework +{ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** +DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( WindowContentFactoryManager , + ::cppu::OWeakObject , + SERVICENAME_WINDOWCONTENTFACTORYMANAGER , + IMPLEMENTATIONNAME_WINDOWCONTENTFACTORYMANAGER + ) + +DEFINE_INIT_SERVICE ( WindowContentFactoryManager, {} ) + +WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) : + ThreadHelpBase( &Application::GetSolarMutex() ), + m_bConfigRead( sal_False ), + m_xServiceManager( xServiceManager ) +{ + m_pConfigAccess = new ConfigurationAccess_FactoryManager( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories" )) ); + m_pConfigAccess->acquire(); + m_xModuleManager = uno::Reference< frame::XModuleManager >( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), uno::UNO_QUERY ); +} + +WindowContentFactoryManager::~WindowContentFactoryManager() +{ + ResetableGuard aLock( m_aLock ); + + // reduce reference count + m_pConfigAccess->release(); +} + +void WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( const rtl::OUString& aResourceURL, rtl::OUString& aType, rtl::OUString& aName ) +{ + const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17; + const char RESOURCEURL_PREFIX[] = "private:resource/"; + + if (( aResourceURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) && + ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) + { + rtl::OUString aTmpStr( aResourceURL.copy( RESOURCEURL_PREFIX_SIZE )); + sal_Int32 nToken = 0; + sal_Int32 nPart = 0; + do + { + ::rtl::OUString sToken = aTmpStr.getToken( 0, '/', nToken); + if ( sToken.getLength() ) + { + if ( nPart == 0 ) + aType = sToken; + else if ( nPart == 1 ) + aName = sToken; + else + break; + nPart++; + } + } + while( nToken >=0 ); + } +} + +// XSingleComponentFactory +uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithContext( + const uno::Reference< uno::XComponentContext >& /*xContext*/ ) +throw (uno::Exception, uno::RuntimeException) +{ +/* + // Currently this method cannot be implemented for generic use. There is no way for external + code to get a handle to the dialog model. + + uno::Reference< lang::XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), uno::UNO_QUERY ); + + const ::rtl::OUString sToolkitService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Toolkit")); + uno::Reference< awt::XToolkit > xToolkit( xServiceManager->createInstance( sToolkitService ), uno::UNO_QUERY_THROW ); + + const ::rtl::OUString sDialogModelService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialogModel")); + uno::Reference< awt::XControlModel > xDialogModel( xServiceManager->createInstance( sDialogModelService ), uno::UNO_QUERY_THROW ); + + const ::rtl::OUString sDecoration(RTL_CONSTASCII_USTRINGPARAM("Decoration")); + uno::Reference< beans::XPropertySet > xPropSet( xDialogModel, uno::UNO_QUERY_THROW ); + xPropSet->setPropertyValue( sDecoration, uno::makeAny(false)); + + const ::rtl::OUString sDialogService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialog")); + uno::Reference< awt::XControl > xDialogControl( xServiceManager->createInstance( sDialogService ), uno::UNO_QUERY_THROW ); + + xDialogControl->setModel( xDialogModel ); + + uno::Reference< awt::XWindowPeer > xWindowParentPeer( xToolkit->getDesktopWindow(), uno::UNO_QUERY ); + xDialogControl->createPeer( xToolkit, xWindowParentPeer ); + uno::Reference< uno::XInterface > xWindow( xDialogControl->getPeer(), uno::UNO_QUERY ); +*/ + uno::Reference< uno::XInterface > xWindow; + return xWindow; +} + +uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithArgumentsAndContext( + const uno::Sequence< uno::Any >& Arguments, const uno::Reference< uno::XComponentContext >& Context ) +throw (uno::Exception, uno::RuntimeException) +{ + uno::Reference< uno::XInterface > xWindow; + uno::Reference< frame::XFrame > xFrame; + ::rtl::OUString aResourceURL; + + for (sal_Int32 i=0; i < Arguments.getLength(); i++ ) + { + beans::PropertyValue aPropValue; + if ( Arguments[i] >>= aPropValue ) + { + if ( aPropValue.Name.equalsAscii( "Frame" )) + aPropValue.Value >>= xFrame; + else if ( aPropValue.Name.equalsAscii( "ResourceURL" )) + aPropValue.Value >>= aResourceURL; + } + } + + uno::Reference< frame::XModuleManager > xModuleManager; + // SAFE + { + ResetableGuard aLock( m_aLock ); + xModuleManager = m_xModuleManager; + } + // UNSAFE + + // Determine the module identifier + ::rtl::OUString aType; + ::rtl::OUString aName; + ::rtl::OUString aModuleId; + try + { + if ( xFrame.is() && xModuleManager.is() ) + aModuleId = xModuleManager->identify( uno::Reference< uno::XInterface >( xFrame, uno::UNO_QUERY ) ); + } + catch ( frame::UnknownModuleException& ) + { + } + + RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName ); + if ( aType.getLength() > 0 && + aName.getLength() > 0 && + aModuleId.getLength() > 0 ) + { + ::rtl::OUString aImplementationName; + uno::Reference< uno::XInterface > xHolder( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY ); + + // Detetmine the implementation name of the window content factory dependent on the + // module identifier, user interface element type and name + // SAFE + ResetableGuard aLock( m_aLock ); + + if ( !m_bConfigRead ) + { + m_bConfigRead = sal_True; + m_pConfigAccess->readConfigurationData(); + } + + aImplementationName = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId ); + if ( aImplementationName.getLength() > 0 ) + { + aLock.unlock(); + // UNSAFE + + uno::Reference< lang::XMultiServiceFactory > xServiceManager( Context->getServiceManager(), uno::UNO_QUERY ); + if ( xServiceManager.is() ) + { + uno::Reference< lang::XSingleComponentFactory > xFactory( + xServiceManager->createInstance( aImplementationName ), uno::UNO_QUERY ); + if ( xFactory.is() ) + { + // Be careful: We call external code. Therefore here we have to catch all exceptions + try + { + xWindow = xFactory->createInstanceWithArgumentsAndContext( Arguments, Context ); + } + catch ( uno::RuntimeException& ) + { + } + catch ( uno::Exception& ) + { + } + } + } + } + } + + // UNSAFE + if ( !xWindow.is()) + { + // Fallback: Use internal factory code to create a toolkit dialog as a content window + xWindow = createInstanceWithContext(Context); + } + + return xWindow; +} + +} // namespace framework |