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