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