1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "factory.hxx" 29 30 #include <com/sun/star/registry/XRegistryKey.hpp> 31 #include <com/sun/star/registry/InvalidRegistryException.hpp> 32 #include <cppuhelper/factory.hxx> 33 34 #include "root.hxx" 35 36 using namespace ::com::sun::star; 37 using namespace layoutimpl; 38 39 void * SAL_CALL comp_Layout_component_getFactory( const char * pImplName, void * pServiceManager, void * /*registryKey*/ ) 40 { 41 void * pRet = 0; 42 43 ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) ); 44 uno::Reference< lang::XSingleServiceFactory > xFactory; 45 46 if ( pServiceManager && aImplName.equals( LayoutFactory::impl_staticGetImplementationName() ) ) 47 xFactory = ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ), 48 LayoutFactory::impl_staticGetImplementationName(), 49 LayoutFactory::impl_staticCreateSelfInstance, 50 LayoutFactory::impl_staticGetSupportedServiceNames() ); 51 if ( xFactory.is() ) 52 { 53 xFactory->acquire(); 54 pRet = xFactory.get(); 55 } 56 57 return pRet; 58 } 59 60 // Component registration 61 ::rtl::OUString SAL_CALL LayoutFactory::impl_staticGetImplementationName() 62 { 63 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.awt.Layout" ); 64 } 65 66 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::impl_staticGetSupportedServiceNames() 67 { 68 uno::Sequence< ::rtl::OUString > aRet(2); 69 aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.awt.Layout"); 70 aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.awt.Layout"); 71 return aRet; 72 } 73 74 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::impl_staticCreateSelfInstance( 75 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) 76 { 77 return uno::Reference< uno::XInterface >( *new LayoutFactory( xServiceManager ) ); 78 } 79 80 // XServiceInfo 81 ::rtl::OUString SAL_CALL LayoutFactory::getImplementationName() 82 throw ( uno::RuntimeException ) 83 { 84 return impl_staticGetImplementationName(); 85 } 86 87 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::getSupportedServiceNames() 88 throw ( uno::RuntimeException ) 89 { 90 return impl_staticGetSupportedServiceNames(); 91 } 92 93 sal_Bool SAL_CALL LayoutFactory::supportsService( const ::rtl::OUString& ServiceName ) 94 throw ( uno::RuntimeException ) 95 { 96 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); 97 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ ) 98 if ( ServiceName.compareTo( aSeq[i] ) == 0 ) 99 return sal_True; 100 101 return sal_False; 102 } 103 104 // XSingleServiceFactory 105 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstance() 106 throw ( uno::Exception, 107 uno::RuntimeException ) 108 { 109 return uno::Reference< uno::XInterface >( 110 static_cast< OWeakObject* >( new LayoutRoot( m_xFactory ) ), 111 uno::UNO_QUERY ); 112 } 113 114 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstanceWithArguments( 115 const uno::Sequence< uno::Any >& aArguments ) 116 throw ( uno::Exception, 117 uno::RuntimeException ) 118 { 119 uno::Reference< uno::XInterface > layout = createInstance(); 120 uno::Reference< lang::XInitialization > xInit( layout, uno::UNO_QUERY ); 121 xInit->initialize( aArguments ); 122 return layout; 123 } 124