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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include "hatchwindowfactory.hxx"
28 #include "hatchwindow.hxx"
29 #include "cppuhelper/factory.hxx"
30 #include <vcl/svapp.hxx>
31 
32 #include "documentcloser.hxx"
33 
34 using namespace ::com::sun::star;
35 
36 //-------------------------------------------------------------------------
impl_staticGetSupportedServiceNames()37 uno::Sequence< ::rtl::OUString > SAL_CALL OHatchWindowFactory::impl_staticGetSupportedServiceNames()
38 {
39     uno::Sequence< ::rtl::OUString > aRet(2);
40     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.HatchWindowFactory");
41     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.HatchWindowFactory");
42     return aRet;
43 }
44 
45 //-------------------------------------------------------------------------
impl_staticGetImplementationName()46 ::rtl::OUString SAL_CALL OHatchWindowFactory::impl_staticGetImplementationName()
47 {
48     return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.HatchWindowFactory");
49 }
50 
51 //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)52 uno::Reference< uno::XInterface > SAL_CALL OHatchWindowFactory::impl_staticCreateSelfInstance(
53             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
54 {
55     return uno::Reference< uno::XInterface >( *new OHatchWindowFactory( xServiceManager ) );
56 }
57 
58 
59 //-------------------------------------------------------------------------
createHatchWindowInstance(const uno::Reference<awt::XWindowPeer> & xParent,const awt::Rectangle & aBounds,const awt::Size & aHandlerSize)60 uno::Reference< embed::XHatchWindow > SAL_CALL OHatchWindowFactory::createHatchWindowInstance(
61                 const uno::Reference< awt::XWindowPeer >& xParent,
62                 const awt::Rectangle& aBounds,
63                 const awt::Size& aHandlerSize )
64     throw (uno::RuntimeException)
65 {
66     if ( !xParent.is() )
67         throw lang::IllegalArgumentException(); // TODO
68 
69     ::vos::OGuard aGuard( Application::GetSolarMutex() );
70     VCLXHatchWindow* pResult = new VCLXHatchWindow();
71     pResult->initializeWindow( xParent, aBounds, aHandlerSize );
72     return uno::Reference< embed::XHatchWindow >( static_cast< embed::XHatchWindow* >( pResult ) );
73 }
74 
75 //-------------------------------------------------------------------------
getImplementationName()76 ::rtl::OUString SAL_CALL OHatchWindowFactory::getImplementationName()
77     throw ( uno::RuntimeException )
78 {
79     return impl_staticGetImplementationName();
80 }
81 
82 //-------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)83 sal_Bool SAL_CALL OHatchWindowFactory::supportsService( const ::rtl::OUString& ServiceName )
84     throw ( uno::RuntimeException )
85 {
86     uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
87 
88     for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
89         if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
90             return sal_True;
91 
92     return sal_False;
93 }
94 
95 //-------------------------------------------------------------------------
getSupportedServiceNames()96 uno::Sequence< ::rtl::OUString > SAL_CALL OHatchWindowFactory::getSupportedServiceNames()
97     throw ( uno::RuntimeException )
98 {
99     return impl_staticGetSupportedServiceNames();
100 }
101 
102 //-------------------------------------------------------------------------
103 
104 extern "C"
105 {
106 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)107 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment (
108     const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */)
109 {
110     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
111 }
112 
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)113 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory (
114     const sal_Char * pImplementationName, void * pServiceManager, void * /* pRegistryKey */)
115 {
116     void * pResult = 0;
117     if (pServiceManager)
118     {
119         uno::Reference< lang::XSingleServiceFactory > xFactory;
120         if (OHatchWindowFactory::impl_staticGetImplementationName().compareToAscii (pImplementationName ) == 0)
121         {
122             xFactory = cppu::createOneInstanceFactory(
123                 reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager),
124                 OHatchWindowFactory::impl_staticGetImplementationName(),
125                 OHatchWindowFactory::impl_staticCreateSelfInstance,
126                 OHatchWindowFactory::impl_staticGetSupportedServiceNames());
127         }
128         else if (ODocumentCloser::impl_staticGetImplementationName().compareToAscii (pImplementationName ) == 0)
129         {
130             xFactory = cppu::createSingleFactory(
131                 reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ),
132                 ODocumentCloser::impl_staticGetImplementationName(),
133                 ODocumentCloser::impl_staticCreateSelfInstance,
134                 ODocumentCloser::impl_staticGetSupportedServiceNames() );
135         }
136 
137         if (xFactory.is())
138         {
139             xFactory->acquire();
140             pResult = xFactory.get();
141         }
142     }
143     return pResult;
144 }
145 
146 } // extern "C"
147