xref: /aoo41x/main/vcl/source/components/factory.cxx (revision 498ce991)
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_vcl.hxx"
26 #include <tools/debug.hxx>
27 #ifndef _OSL_MUTEX_HXX
28 #include <osl/mutex.hxx>
29 #endif
30 #ifndef _RTL_USTRBUF_HXX
31 #include <rtl/ustrbuf.hxx>
32 #endif
33 #include <uno/dispatcher.h> // declaration of generic uno interface
34 #include <uno/mapping.hxx> // mapping stuff
35 #include <cppuhelper/factory.hxx>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <vcl/dllapi.h>
38 
39 using ::rtl::OUString;
40 using ::rtl::OUStringBuffer;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
43 
44 // service implementation
45 extern Sequence< OUString > SAL_CALL vcl_session_getSupportedServiceNames();
46 extern OUString SAL_CALL vcl_session_getImplementationName();
47 extern Reference< XInterface > SAL_CALL vcl_session_createInstance( const Reference< XMultiServiceFactory > & );
48 
49 namespace vcl
50 {
51 extern Sequence< OUString > SAL_CALL DisplayAccess_getSupportedServiceNames();
52 extern OUString SAL_CALL DisplayAccess_getImplementationName();
53 extern Reference< XInterface > SAL_CALL DisplayAccess_createInstance( const Reference< XMultiServiceFactory > & );
54 
55 extern Sequence< OUString > SAL_CALL FontIdentificator_getSupportedServiceNames();
56 extern OUString SAL_CALL FontIdentificator_getImplementationName();
57 extern Reference< XInterface > SAL_CALL FontIdentificator_createInstance( const Reference< XMultiServiceFactory > & );
58 
59 extern Sequence< OUString > SAL_CALL StringMirror_getSupportedServiceNames();
60 extern OUString SAL_CALL StringMirror_getImplementationName();
61 extern Reference< XInterface > SAL_CALL StringMirror_createInstance( const Reference< XMultiServiceFactory > & );
62 
63 extern Sequence< OUString > SAL_CALL Clipboard_getSupportedServiceNames();
64 extern OUString SAL_CALL Clipboard_getImplementationName();
65 extern Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & );
66 
67 extern Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames();
68 extern OUString SAL_CALL DragSource_getImplementationName();
69 extern Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory > & );
70 
71 extern Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames();
72 extern OUString SAL_CALL DropTarget_getImplementationName();
73 extern Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory > & );
74 }
75 
76 extern "C" {
77 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)78 	VCL_DLLPUBLIC void SAL_CALL component_getImplementationEnvironment(
79 		const sal_Char** ppEnvTypeName,
80 		uno_Environment** /*ppEnv*/ )
81 	{
82 		*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
83 	}
84 
component_getFactory(const sal_Char * pImplementationName,void * pXUnoSMgr,void *)85 	VCL_DLLPUBLIC void* SAL_CALL component_getFactory(
86 		const sal_Char* pImplementationName,
87 		void* pXUnoSMgr,
88 		void* /*pXUnoKey*/
89 		)
90 	{
91 		void* pRet = 0;
92 
93 		if( pXUnoSMgr )
94 		{
95 			Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr(
96 				reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pXUnoSMgr )
97 				);
98 			Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory;
99 			if( vcl_session_getImplementationName().equalsAscii( pImplementationName ) )
100 			{
101 				xFactory = ::cppu::createSingleFactory(
102 					xMgr, vcl_session_getImplementationName(), vcl_session_createInstance,
103 					vcl_session_getSupportedServiceNames() );
104 			}
105 			else if( vcl::DisplayAccess_getImplementationName().equalsAscii( pImplementationName ) )
106 			{
107 				xFactory = ::cppu::createSingleFactory(
108 					xMgr, vcl::DisplayAccess_getImplementationName(), vcl::DisplayAccess_createInstance,
109 					vcl::DisplayAccess_getSupportedServiceNames() );
110 			}
111             else if( vcl::FontIdentificator_getImplementationName().equalsAscii( pImplementationName ) )
112             {
113 				xFactory = ::cppu::createSingleFactory(
114 					xMgr, vcl::FontIdentificator_getImplementationName(), vcl::FontIdentificator_createInstance,
115 					vcl::FontIdentificator_getSupportedServiceNames() );
116             }
117             else if( vcl::StringMirror_getImplementationName().equalsAscii( pImplementationName ) )
118             {
119 				xFactory = ::cppu::createSingleFactory(
120 					xMgr, vcl::StringMirror_getImplementationName(), vcl::StringMirror_createInstance,
121 					vcl::StringMirror_getSupportedServiceNames() );
122             }
123             else if( vcl::Clipboard_getImplementationName().equalsAscii( pImplementationName ) )
124             {
125 				xFactory = vcl::Clipboard_createFactory( xMgr );
126             }
127             else if( vcl::DragSource_getImplementationName().equalsAscii( pImplementationName ) )
128             {
129 				xFactory = ::cppu::createSingleFactory(
130 					xMgr, vcl::DragSource_getImplementationName(), vcl::DragSource_createInstance,
131 					vcl::DragSource_getSupportedServiceNames() );
132             }
133             else if( vcl::DropTarget_getImplementationName().equalsAscii( pImplementationName ) )
134             {
135 				xFactory = ::cppu::createSingleFactory(
136 					xMgr, vcl::DropTarget_getImplementationName(), vcl::DropTarget_createInstance,
137 					vcl::DropTarget_getSupportedServiceNames() );
138             }
139 			if( xFactory.is() )
140 			{
141 				xFactory->acquire();
142 				pRet = xFactory.get();
143 			}
144 		}
145 		return pRet;
146 	}
147 
148 } /* extern "C" */
149