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 //______________________________________________________________________________________________________________
25 //	includes of other projects
26 //______________________________________________________________________________________________________________
27 
28 #include <cppuhelper/factory.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/registry/XRegistryKey.hpp>
32 #include <com/sun/star/container/XSet.hpp>
33 
34 #include <stdio.h>
35 
36 //______________________________________________________________________________________________________________
37 //	includes of my own project
38 //______________________________________________________________________________________________________________
39 
40 //=============================================================================
41 //  Add new include line to use new services.
42 //=============================================================================
43 #include "framecontrol.hxx"
44 #include "progressbar.hxx"
45 #include "progressmonitor.hxx"
46 #include "statusindicator.hxx"
47 //=============================================================================
48 
49 //______________________________________________________________________________________________________________
50 //	defines
51 //______________________________________________________________________________________________________________
52 
53 // If you will debug macros of this file ... you must define follow constant!
54 // This switch on another macro AS_DBG_OUT(...), which will print text to "stdout".
55 
56 //#define AS_DBG_SWITCH
57 
58 //______________________________________________________________________________________________________________
59 //	namespaces
60 //______________________________________________________________________________________________________________
61 
62 using namespace ::rtl											;
63 using namespace ::cppu											;
64 using namespace ::unocontrols									;
65 using namespace ::com::sun::star::uno							;
66 using namespace ::com::sun::star::container						;
67 using namespace ::com::sun::star::lang							;
68 using namespace ::com::sun::star::registry						;
69 
70 //______________________________________________________________________________________________________________
71 //	macros
72 //______________________________________________________________________________________________________________
73 
74 //******************************************************************************************************************************
75 // See AS_DBG_SWITCH below !!!
76 #ifdef AS_DBG_SWITCH
77 	#define AS_DBG_OUT(OUTPUT)	printf( OUTPUT );
78 #else
79 	#define AS_DBG_OUT(OUTPUT)
80 #endif
81 
82 //******************************************************************************************************************************
83 #define	CREATEINSTANCE(CLASS)																												\
84 																																			\
85 	static Reference< XInterface > SAL_CALL CLASS##_createInstance ( const Reference< XMultiServiceFactory >& rServiceManager ) throw ( Exception )	\
86 	{																																		\
87 		AS_DBG_OUT ( "\tCREATEINSTANCE():\tOK\n" )																							\
88 		return Reference< XInterface >( *(OWeakObject*)(new CLASS( rServiceManager )) );													\
89 	}
90 
91 //******************************************************************************************************************************
92 #define	CREATEFACTORY_ONEINSTANCE(CLASS)																				\
93 																														\
94 	AS_DBG_OUT ( "\tCREATEFACTORY_ONEINSTANCE():\t[start]\n" )															\
95 	/* Create right factory ... */																						\
96 	xFactory = Reference< XSingleServiceFactory >																		\
97 					(																									\
98 						cppu::createOneInstanceFactory	(	xServiceManager										,		\
99 															CLASS::impl_getStaticImplementationName		()	,		\
100 															CLASS##_createInstance								,		\
101 															CLASS::impl_getStaticSupportedServiceNames	()	)		\
102 					) ;																									\
103 	AS_DBG_OUT ( "\tCREATEFACTORY_ONEINSTANCE():\t[end]\n" )
104 
105 //******************************************************************************************************************************
106 #define	CREATEFACTORY_SINGLE(CLASS)																						\
107 																														\
108 	AS_DBG_OUT ( "\tCREATEFACTORY_SINGLE():\t[start]\n" )																\
109 	/* Create right factory ... */																						\
110 	xFactory = Reference< XSingleServiceFactory >																		\
111 					(																									\
112 						cppu::createSingleFactory	(	xServiceManager										,			\
113 														CLASS::impl_getStaticImplementationName		()	,			\
114 														CLASS##_createInstance								,			\
115 														CLASS::impl_getStaticSupportedServiceNames	()	)			\
116 					) ;																									\
117 	AS_DBG_OUT ( "\tCREATEFACTORY_SINGLE():\t[end]\n" )
118 
119 //******************************************************************************************************************************
120 #define	IF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE(CLASS)																\
121 																														\
122 	if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) )		\
123 	{																													\
124 		AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE():\timplementationname found\n" )					\
125 		CREATEFACTORY_ONEINSTANCE ( CLASS )																			\
126 	}
127 
128 //******************************************************************************************************************************
129 #define	IF_NAME_CREATECOMPONENTFACTORY_SINGLE(CLASS)																	\
130 																														\
131 	if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) )		\
132 	{																													\
133 		AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_SINGLE():\timplementationname found\n" )							\
134 		CREATEFACTORY_SINGLE ( CLASS )																				\
135 	}
136 
137 //______________________________________________________________________________________________________________
138 //	declare functions to create a new instance of service
139 //______________________________________________________________________________________________________________
140 
141 //=============================================================================
142 //  Add new macro line to use new services.
143 //
144 //	!!! ATTENTION !!!
145 //		Write no ";" at end of line! (see macro)
146 //=============================================================================
147 CREATEINSTANCE	( FrameControl		)
CREATEINSTANCE(ProgressBar)148 CREATEINSTANCE	( ProgressBar		)
149 CREATEINSTANCE	( ProgressMonitor	)
150 CREATEINSTANCE	( StatusIndicator	)
151 //=============================================================================
152 
153 //______________________________________________________________________________________________________________
154 //	return environment
155 //______________________________________________________________________________________________________________
156 
157 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(	const	sal_Char**			ppEnvironmentTypeName	,
158 																			uno_Environment**	/*ppEnvironment*/			)
159 {
160 	*ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
161 }
162 
163 //______________________________________________________________________________________________________________
164 //	create right component factory
165 //______________________________________________________________________________________________________________
166 
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)167 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(	const	sal_Char*	pImplementationName	,
168 														void*		pServiceManager		,
169 														void*		/*pRegistryKey*/		)
170 {
171 	AS_DBG_OUT( "component_getFactory():\t[start]\n" )
172 
173 	// Set default return value for this operation - if it failed.
174 	void* pReturn = NULL ;
175 
176 	if	(
177 			( pImplementationName	!=	NULL ) &&
178 			( pServiceManager		!=	NULL )
179 		)
180 	{
181 		AS_DBG_OUT( "component_getFactory():\t\t... enter scope - pointer are valid\n" )
182 
183 		// Define variables which are used in following macros.
184 		Reference< XSingleServiceFactory >	xFactory																		;
185 		Reference< XMultiServiceFactory >	xServiceManager( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) )	;
186 
187 		//=============================================================================
188 		//  Add new macro line to handle new service.
189 		//
190 		//	!!! ATTENTION !!!
191 		//		Write no ";" at end of line and dont forget "else" ! (see macro)
192 		//=============================================================================
193 		IF_NAME_CREATECOMPONENTFACTORY_SINGLE( FrameControl		)
194 		else
195 		IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressBar		)
196 		else
197 		IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressMonitor	)
198 		else
199 		IF_NAME_CREATECOMPONENTFACTORY_SINGLE( StatusIndicator	)
200 		//=============================================================================
201 
202 		// Factory is valid - service was found.
203 		if ( xFactory.is() )
204 		{
205 			AS_DBG_OUT( "component_getFactory():\t\t\t... xFactory valid - service was found\n" )
206 
207 			xFactory->acquire();
208 			pReturn = xFactory.get();
209 		}
210 
211 		AS_DBG_OUT( "component_getFactory():\t\t... leave scope\n" )
212 	}
213 
214 	AS_DBG_OUT ( "component_getFactory():\t[end]\n" )
215 
216 	// Return with result of this operation.
217 	return pReturn ;
218 }
219