1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "factory.hxx"
25 
26 #include <com/sun/star/registry/XRegistryKey.hpp>
27 #include <com/sun/star/registry/InvalidRegistryException.hpp>
28 #include <cppuhelper/factory.hxx>
29 
30 #include "root.hxx"
31 
32 using namespace ::com::sun::star;
33 using namespace layoutimpl;
34 
comp_Layout_component_getFactory(const char * pImplName,void * pServiceManager,void *)35 void * SAL_CALL comp_Layout_component_getFactory( const char * pImplName, void * pServiceManager, void * /*registryKey*/ )
36     {
37         void * pRet = 0;
38 
39         ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) );
40         uno::Reference< lang::XSingleServiceFactory > xFactory;
41 
42         if ( pServiceManager && aImplName.equals( LayoutFactory::impl_staticGetImplementationName() ) )
43             xFactory = ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
44                                                          LayoutFactory::impl_staticGetImplementationName(),
45                                                          LayoutFactory::impl_staticCreateSelfInstance,
46                                                          LayoutFactory::impl_staticGetSupportedServiceNames() );
47         if ( xFactory.is() )
48         {
49             xFactory->acquire();
50             pRet = xFactory.get();
51         }
52 
53         return pRet;
54     }
55 
56 // Component registration
impl_staticGetImplementationName()57 ::rtl::OUString SAL_CALL LayoutFactory::impl_staticGetImplementationName()
58 {
59     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.awt.Layout" );
60 }
61 
impl_staticGetSupportedServiceNames()62 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::impl_staticGetSupportedServiceNames()
63 {
64     uno::Sequence< ::rtl::OUString > aRet(2);
65     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.awt.Layout");
66     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.awt.Layout");
67     return aRet;
68 }
69 
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)70 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::impl_staticCreateSelfInstance(
71     const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
72 {
73     return uno::Reference< uno::XInterface >( *new LayoutFactory( xServiceManager ) );
74 }
75 
76 // XServiceInfo
getImplementationName()77 ::rtl::OUString SAL_CALL LayoutFactory::getImplementationName()
78     throw ( uno::RuntimeException )
79 {
80     return impl_staticGetImplementationName();
81 }
82 
getSupportedServiceNames()83 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::getSupportedServiceNames()
84     throw ( uno::RuntimeException )
85 {
86     return impl_staticGetSupportedServiceNames();
87 }
88 
supportsService(const::rtl::OUString & ServiceName)89 sal_Bool SAL_CALL LayoutFactory::supportsService( const ::rtl::OUString& ServiceName )
90     throw ( uno::RuntimeException )
91 {
92     uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
93     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
94         if ( ServiceName.compareTo( aSeq[i] ) == 0 )
95             return sal_True;
96 
97     return sal_False;
98 }
99 
100 // XSingleServiceFactory
createInstance()101 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstance()
102     throw ( uno::Exception,
103             uno::RuntimeException )
104 {
105     return uno::Reference< uno::XInterface >(
106         static_cast< OWeakObject* >( new LayoutRoot( m_xFactory ) ),
107         uno::UNO_QUERY );
108 }
109 
createInstanceWithArguments(const uno::Sequence<uno::Any> & aArguments)110 uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstanceWithArguments(
111     const uno::Sequence< uno::Any >& aArguments )
112     throw ( uno::Exception,
113             uno::RuntimeException )
114 {
115     uno::Reference< uno::XInterface > layout = createInstance();
116     uno::Reference< lang::XInitialization > xInit( layout, uno::UNO_QUERY );
117     xInit->initialize( aArguments );
118     return layout;
119 }
120