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