merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / layout / core / factory.cxx
blobe687ca833ff38630212bd98d43d84283c52ec7e5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile$
11 * $Revision$
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "factory.hxx"
34 #include <com/sun/star/registry/XRegistryKey.hpp>
35 #include <com/sun/star/registry/InvalidRegistryException.hpp>
36 #include <cppuhelper/factory.hxx>
38 #include "root.hxx"
40 using namespace ::com::sun::star;
41 using namespace layoutimpl;
43 void * SAL_CALL comp_Layout_component_getFactory( const char * pImplName, void * pServiceManager, void * /*registryKey*/ )
45 void * pRet = 0;
47 ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) );
48 uno::Reference< lang::XSingleServiceFactory > xFactory;
50 if ( pServiceManager && aImplName.equals( LayoutFactory::impl_staticGetImplementationName() ) )
51 xFactory = ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
52 LayoutFactory::impl_staticGetImplementationName(),
53 LayoutFactory::impl_staticCreateSelfInstance,
54 LayoutFactory::impl_staticGetSupportedServiceNames() );
55 if ( xFactory.is() )
57 xFactory->acquire();
58 pRet = xFactory.get();
61 return pRet;
64 sal_Bool SAL_CALL comp_Layout_component_writeInfo( void * /*serviceManager*/, void * pRegistryKey )
66 if ( pRegistryKey )
68 try
70 uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) );
71 uno::Reference< registry::XRegistryKey > xNewKey;
73 xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
74 LayoutFactory::impl_staticGetImplementationName() +
75 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) );
77 const uno::Sequence< ::rtl::OUString > aServices = LayoutFactory::impl_staticGetSupportedServiceNames();
78 for ( sal_Int32 i = 0; i < aServices.getLength(); i++ )
79 xNewKey->createKey( aServices.getConstArray()[i] );
81 return sal_True;
83 catch (registry::InvalidRegistryException &)
85 OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
88 return sal_False;
91 // Component registration
92 ::rtl::OUString SAL_CALL LayoutFactory::impl_staticGetImplementationName()
94 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.awt.Layout" );
97 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::impl_staticGetSupportedServiceNames()
99 uno::Sequence< ::rtl::OUString > aRet(2);
100 aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.awt.Layout");
101 aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.awt.Layout");
102 return aRet;
105 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::impl_staticCreateSelfInstance(
106 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
108 return uno::Reference< uno::XInterface >( *new LayoutFactory( xServiceManager ) );
111 // XServiceInfo
112 ::rtl::OUString SAL_CALL LayoutFactory::getImplementationName()
113 throw ( uno::RuntimeException )
115 return impl_staticGetImplementationName();
118 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::getSupportedServiceNames()
119 throw ( uno::RuntimeException )
121 return impl_staticGetSupportedServiceNames();
124 sal_Bool SAL_CALL LayoutFactory::supportsService( const ::rtl::OUString& ServiceName )
125 throw ( uno::RuntimeException )
127 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
128 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
129 if ( ServiceName.compareTo( aSeq[i] ) == 0 )
130 return sal_True;
132 return sal_False;
135 // XSingleServiceFactory
136 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstance()
137 throw ( uno::Exception,
138 uno::RuntimeException )
140 return uno::Reference< uno::XInterface >(
141 static_cast< OWeakObject* >( new LayoutRoot( m_xFactory ) ),
142 uno::UNO_QUERY );
145 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstanceWithArguments(
146 const uno::Sequence< uno::Any >& aArguments )
147 throw ( uno::Exception,
148 uno::RuntimeException )
150 uno::Reference< uno::XInterface > layout = createInstance();
151 uno::Reference< lang::XInitialization > xInit( layout, uno::UNO_QUERY );
152 xInit->initialize( aArguments );
153 return layout;