merge the formfield patch from ooo-build
[ooovba.git] / UnoControls / source / base / registercontrols.cxx
blob3073c43f9247262cd8f2cf134953f77295185187
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registercontrols.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //______________________________________________________________________________________________________________
32 // includes of other projects
33 //______________________________________________________________________________________________________________
35 #include <cppuhelper/factory.hxx>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #include <com/sun/star/container/XSet.hpp>
41 #include <stdio.h>
43 //______________________________________________________________________________________________________________
44 // includes of my own project
45 //______________________________________________________________________________________________________________
47 //=============================================================================
48 // Add new include line to use new services.
49 //=============================================================================
50 #include "framecontrol.hxx"
51 #include "progressbar.hxx"
52 #include "progressmonitor.hxx"
53 #include "statusindicator.hxx"
54 //=============================================================================
56 //______________________________________________________________________________________________________________
57 // defines
58 //______________________________________________________________________________________________________________
60 // If you will debug macros of this file ... you must define follow constant!
61 // Ths switch on another macro AS_DBG_OUT(...), which will print text to "stdout".
63 //#define AS_DBG_SWITCH
65 //______________________________________________________________________________________________________________
66 // namespaces
67 //______________________________________________________________________________________________________________
69 using namespace ::rtl ;
70 using namespace ::cppu ;
71 using namespace ::unocontrols ;
72 using namespace ::com::sun::star::uno ;
73 using namespace ::com::sun::star::container ;
74 using namespace ::com::sun::star::lang ;
75 using namespace ::com::sun::star::registry ;
77 //______________________________________________________________________________________________________________
78 // macros
79 //______________________________________________________________________________________________________________
81 //******************************************************************************************************************************
82 // See AS_DBG_SWITCH below !!!
83 #ifdef AS_DBG_SWITCH
84 #define AS_DBG_OUT(OUTPUT) printf( OUTPUT );
85 #else
86 #define AS_DBG_OUT(OUTPUT)
87 #endif
89 //******************************************************************************************************************************
90 #define CREATEINSTANCE(CLASS) \
92 static Reference< XInterface > SAL_CALL CLASS##_createInstance ( const Reference< XMultiServiceFactory >& rServiceManager ) throw ( Exception ) \
93 { \
94 AS_DBG_OUT ( "\tCREATEINSTANCE():\tOK\n" ) \
95 return Reference< XInterface >( *(OWeakObject*)(new CLASS( rServiceManager )) ); \
98 //******************************************************************************************************************************
99 #define COMPONENT_INFO(CLASS) \
101 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t[start]\n" ) \
102 try \
104 /* Set default result of follow operations !!! */ \
105 bReturn = sal_False ; \
107 /* Do the follow only, if given key is valid ! */ \
108 if ( xKey.is () ) \
110 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\txkey is valid ...\n" ) \
111 /* Build new keyname */ \
112 sKeyName = OUString::createFromAscii( "/" ) ; \
113 sKeyName += CLASS::impl_getStaticImplementationName() ; \
114 sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); \
116 /* Create new key with new name. */ \
117 xNewKey = xKey->createKey( sKeyName ); \
119 /* If this new key valid ... */ \
120 if ( xNewKey.is () ) \
122 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\txNewkey is valid ...\n" ) \
123 /* Get information about supported services. */ \
124 seqServiceNames = CLASS::impl_getStaticSupportedServiceNames() ; \
125 pArray = seqServiceNames.getArray() ; \
126 nLength = seqServiceNames.getLength() ; \
127 nCounter = 0 ; \
129 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\tloop ..." ) \
130 /* Then set this information on this key. */ \
131 for ( nCounter = 0; nCounter < nLength; ++nCounter ) \
133 xNewKey->createKey( pArray [nCounter] ); \
135 AS_DBG_OUT ( " OK\n" ) \
137 /* Result of this operations = OK. */ \
138 bReturn = sal_True ; \
140 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\t... leave xNewKey\n" ) \
142 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\t... leave xKey\n" ) \
144 catch( InvalidRegistryException& ) \
146 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\tInvalidRegistryException detected!!!\n" ) \
147 bReturn = sal_False ; \
149 AS_DBG_OUT ( "\tCOMPONENT_INFO():\t[end]\n" )
151 //******************************************************************************************************************************
152 #define CREATEFACTORY_ONEINSTANCE(CLASS) \
154 AS_DBG_OUT ( "\tCREATEFACTORY_ONEINSTANCE():\t[start]\n" ) \
155 /* Create right factory ... */ \
156 xFactory = Reference< XSingleServiceFactory > \
158 cppu::createOneInstanceFactory ( xServiceManager , \
159 CLASS::impl_getStaticImplementationName () , \
160 CLASS##_createInstance , \
161 CLASS::impl_getStaticSupportedServiceNames () ) \
162 ) ; \
163 AS_DBG_OUT ( "\tCREATEFACTORY_ONEINSTANCE():\t[end]\n" )
165 //******************************************************************************************************************************
166 #define CREATEFACTORY_SINGLE(CLASS) \
168 AS_DBG_OUT ( "\tCREATEFACTORY_SINGLE():\t[start]\n" ) \
169 /* Create right factory ... */ \
170 xFactory = Reference< XSingleServiceFactory > \
172 cppu::createSingleFactory ( xServiceManager , \
173 CLASS::impl_getStaticImplementationName () , \
174 CLASS##_createInstance , \
175 CLASS::impl_getStaticSupportedServiceNames () ) \
176 ) ; \
177 AS_DBG_OUT ( "\tCREATEFACTORY_SINGLE():\t[end]\n" )
179 //******************************************************************************************************************************
180 #define IF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE(CLASS) \
182 if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \
184 AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE():\timplementationname found\n" ) \
185 CREATEFACTORY_ONEINSTANCE ( CLASS ) \
188 //******************************************************************************************************************************
189 #define IF_NAME_CREATECOMPONENTFACTORY_SINGLE(CLASS) \
191 if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \
193 AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_SINGLE():\timplementationname found\n" ) \
194 CREATEFACTORY_SINGLE ( CLASS ) \
197 //______________________________________________________________________________________________________________
198 // declare functions to create a new instance of service
199 //______________________________________________________________________________________________________________
201 //=============================================================================
202 // Add new macro line to use new services.
204 // !!! ATTENTION !!!
205 // Write no ";" at end of line! (see macro)
206 //=============================================================================
207 CREATEINSTANCE ( FrameControl )
208 CREATEINSTANCE ( ProgressBar )
209 CREATEINSTANCE ( ProgressMonitor )
210 CREATEINSTANCE ( StatusIndicator )
211 //=============================================================================
213 //______________________________________________________________________________________________________________
214 // return environment
215 //______________________________________________________________________________________________________________
217 extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvironmentTypeName ,
218 uno_Environment** /*ppEnvironment*/ )
220 *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
223 //______________________________________________________________________________________________________________
224 // write component info to registry
225 //______________________________________________________________________________________________________________
227 extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/ ,
228 void* pRegistryKey )
230 AS_DBG_OUT ( "component_writeInfo():\t[start]\n" )
232 // Set default return value for this operation - if it failed.
233 sal_Bool bReturn = sal_False ;
235 if ( pRegistryKey != NULL )
237 AS_DBG_OUT ( "component_writeInfo():\t\tpRegistryKey is valid ... enter scope\n" )
239 // Define variables for following macros!
240 // bReturn is set automaticly.
241 Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ;
242 Reference< XRegistryKey > xNewKey ;
243 Sequence< OUString > seqServiceNames ;
244 const OUString* pArray ;
245 sal_Int32 nLength ;
246 sal_Int32 nCounter ;
247 OUString sKeyName ;
249 //=============================================================================
250 // Add new macro line to register new services.
252 // !!! ATTENTION !!!
253 // Write no ";" at end of line! (see macro)
254 //=============================================================================
255 COMPONENT_INFO ( FrameControl )
256 COMPONENT_INFO ( ProgressBar )
257 COMPONENT_INFO ( ProgressMonitor )
258 COMPONENT_INFO ( StatusIndicator )
259 //=============================================================================
261 AS_DBG_OUT ( "component_writeInfo():\t\t... leave pRegistryKey scope\n" )
264 AS_DBG_OUT ( "component_writeInfo():\t[end]\n" )
266 // Return with result of this operation.
267 return bReturn ;
270 //______________________________________________________________________________________________________________
271 // create right component factory
272 //______________________________________________________________________________________________________________
274 extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplementationName ,
275 void* pServiceManager ,
276 void* /*pRegistryKey*/ )
278 AS_DBG_OUT( "component_getFactory():\t[start]\n" )
280 // Set default return value for this operation - if it failed.
281 void* pReturn = NULL ;
283 if (
284 ( pImplementationName != NULL ) &&
285 ( pServiceManager != NULL )
288 AS_DBG_OUT( "component_getFactory():\t\t... enter scope - pointer are valid\n" )
290 // Define variables which are used in following macros.
291 Reference< XSingleServiceFactory > xFactory ;
292 Reference< XMultiServiceFactory > xServiceManager( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
294 //=============================================================================
295 // Add new macro line to handle new service.
297 // !!! ATTENTION !!!
298 // Write no ";" at end of line and dont forget "else" ! (see macro)
299 //=============================================================================
300 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( FrameControl )
301 else
302 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressBar )
303 else
304 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressMonitor )
305 else
306 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( StatusIndicator )
307 //=============================================================================
309 // Factory is valid - service was found.
310 if ( xFactory.is() )
312 AS_DBG_OUT( "component_getFactory():\t\t\t... xFactory valid - service was found\n" )
314 xFactory->acquire();
315 pReturn = xFactory.get();
318 AS_DBG_OUT( "component_getFactory():\t\t... leave scope\n" )
321 AS_DBG_OUT ( "component_getFactory():\t[end]\n" )
323 // Return with result of this operation.
324 return pReturn ;