Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / UnoControls / source / base / registercontrols.cxx
blob969e246ea51aebaf6e5d621e5bf462c04997511c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 //______________________________________________________________________________________________________________
30 // includes of other projects
31 //______________________________________________________________________________________________________________
33 #include <cppuhelper/factory.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36 #include <com/sun/star/registry/XRegistryKey.hpp>
37 #include <com/sun/star/container/XSet.hpp>
39 #include <stdio.h>
41 //______________________________________________________________________________________________________________
42 // includes of my own project
43 //______________________________________________________________________________________________________________
45 //=============================================================================
46 // Add new include line to use new services.
47 //=============================================================================
48 #include "framecontrol.hxx"
49 #include "progressbar.hxx"
50 #include "progressmonitor.hxx"
51 #include "statusindicator.hxx"
52 //=============================================================================
54 //______________________________________________________________________________________________________________
55 // namespaces
56 //______________________________________________________________________________________________________________
58 using namespace ::rtl ;
59 using namespace ::cppu ;
60 using namespace ::unocontrols ;
61 using namespace ::com::sun::star::uno ;
62 using namespace ::com::sun::star::container ;
63 using namespace ::com::sun::star::lang ;
64 using namespace ::com::sun::star::registry ;
66 //______________________________________________________________________________________________________________
67 // macros
68 //______________________________________________________________________________________________________________
70 //******************************************************************************************************************************
71 #define CREATEINSTANCE(CLASS) \
73 static Reference< XInterface > SAL_CALL CLASS##_createInstance ( const Reference< XMultiServiceFactory >& rServiceManager ) throw ( Exception ) \
74 { \
75 return Reference< XInterface >( *(OWeakObject*)(new CLASS( rServiceManager )) ); \
78 //******************************************************************************************************************************
79 #define CREATEFACTORY_ONEINSTANCE(CLASS) \
81 /* Create right factory ... */ \
82 xFactory = Reference< XSingleServiceFactory > \
83 ( \
84 cppu::createOneInstanceFactory ( xServiceManager , \
85 CLASS::impl_getStaticImplementationName () , \
86 CLASS##_createInstance , \
87 CLASS::impl_getStaticSupportedServiceNames () ) \
88 ) ; \
90 //******************************************************************************************************************************
91 #define CREATEFACTORY_SINGLE(CLASS) \
93 /* Create right factory ... */ \
94 xFactory = Reference< XSingleServiceFactory > \
95 ( \
96 cppu::createSingleFactory ( xServiceManager , \
97 CLASS::impl_getStaticImplementationName () , \
98 CLASS##_createInstance , \
99 CLASS::impl_getStaticSupportedServiceNames () ) \
100 ) ; \
102 //******************************************************************************************************************************
103 #define IF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE(CLASS) \
105 if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \
107 CREATEFACTORY_ONEINSTANCE ( CLASS ) \
110 //******************************************************************************************************************************
111 #define IF_NAME_CREATECOMPONENTFACTORY_SINGLE(CLASS) \
113 if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \
115 CREATEFACTORY_SINGLE ( CLASS ) \
118 //______________________________________________________________________________________________________________
119 // declare functions to create a new instance of service
120 //______________________________________________________________________________________________________________
122 //=============================================================================
123 // Add new macro line to use new services.
125 // !!! ATTENTION !!!
126 // Write no ";" at end of line! (see macro)
127 //=============================================================================
128 CREATEINSTANCE ( FrameControl )
129 CREATEINSTANCE ( ProgressBar )
130 CREATEINSTANCE ( ProgressMonitor )
131 CREATEINSTANCE ( StatusIndicator )
132 //=============================================================================
134 //______________________________________________________________________________________________________________
135 // create right component factory
136 //______________________________________________________________________________________________________________
138 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char* pImplementationName ,
139 void* pServiceManager ,
140 void* /*pRegistryKey*/ )
142 // Set default return value for this operation - if it failed.
143 void* pReturn = NULL ;
145 if (
146 ( pImplementationName != NULL ) &&
147 ( pServiceManager != NULL )
150 // Define variables which are used in following macros.
151 Reference< XSingleServiceFactory > xFactory ;
152 Reference< XMultiServiceFactory > xServiceManager( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
154 //=============================================================================
155 // Add new macro line to handle new service.
157 // !!! ATTENTION !!!
158 // Write no ";" at end of line and dont forget "else" ! (see macro)
159 //=============================================================================
160 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( FrameControl )
161 else
162 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressBar )
163 else
164 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressMonitor )
165 else
166 IF_NAME_CREATECOMPONENTFACTORY_SINGLE( StatusIndicator )
167 //=============================================================================
169 // Factory is valid - service was found.
170 if ( xFactory.is() )
172 xFactory->acquire();
173 pReturn = xFactory.get();
177 // Return with result of this operation.
178 return pReturn ;
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */