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