xref: /aoo41x/main/forms/source/misc/services.cxx (revision cdf0e10c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 #include "services.hxx"
31 #include "frm_module.hxx"
32 #include <cppuhelper/factory.hxx>
33 #include <uno/lbnames.h>
34 #include <osl/diagnose.h>
35 #include <uno/mapping.hxx>
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::registry;
40 
41 //---------------------------------------------------------------------------------------
42 //.......................................................................................
43 #define DECLARE_SERVICE_INFO(classImplName) \
44 	namespace frm { \
45 		extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> SAL_CALL classImplName##_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory) throw (::com::sun::star::uno::RuntimeException); \
46 	}
47 
48 //---------------------------------------------------------------------------------------
49 DECLARE_SERVICE_INFO(OFixedTextModel)
50 DECLARE_SERVICE_INFO(ORadioButtonModel)
51 DECLARE_SERVICE_INFO(ORadioButtonControl)
52 DECLARE_SERVICE_INFO(OCheckBoxModel)
53 DECLARE_SERVICE_INFO(OCheckBoxControl)
54 DECLARE_SERVICE_INFO(OHiddenModel)
55 DECLARE_SERVICE_INFO(OGroupBoxModel)
56 DECLARE_SERVICE_INFO(OGroupBoxControl)
57 DECLARE_SERVICE_INFO(OListBoxControl)
58 DECLARE_SERVICE_INFO(OListBoxModel)
59 DECLARE_SERVICE_INFO(OComboBoxControl)
60 DECLARE_SERVICE_INFO(OComboBoxModel)
61 DECLARE_SERVICE_INFO(OEditControl)
62 DECLARE_SERVICE_INFO(OEditModel)
63 DECLARE_SERVICE_INFO(ONumericControl)
64 DECLARE_SERVICE_INFO(ONumericModel)
65 DECLARE_SERVICE_INFO(OPatternControl)
66 DECLARE_SERVICE_INFO(OPatternModel)
67 DECLARE_SERVICE_INFO(OCurrencyControl)
68 DECLARE_SERVICE_INFO(OCurrencyModel)
69 DECLARE_SERVICE_INFO(ODateControl)
70 DECLARE_SERVICE_INFO(ODateModel)
71 DECLARE_SERVICE_INFO(OTimeControl)
72 DECLARE_SERVICE_INFO(OTimeModel)
73 DECLARE_SERVICE_INFO(OFormattedControl)
74 DECLARE_SERVICE_INFO(OFormattedModel)
75 DECLARE_SERVICE_INFO(OFileControlModel)
76 DECLARE_SERVICE_INFO(OButtonControl)
77 DECLARE_SERVICE_INFO(OButtonModel)
78 DECLARE_SERVICE_INFO(OImageButtonControl)
79 DECLARE_SERVICE_INFO(OImageButtonModel)
80 
81 DECLARE_SERVICE_INFO(OImageControlControl)
82 DECLARE_SERVICE_INFO(OImageControlModel)
83 DECLARE_SERVICE_INFO(OGridControlModel)
84 
85 // XForms objects
86 DECLARE_SERVICE_INFO(Binding)
87 DECLARE_SERVICE_INFO(Model)
88 DECLARE_SERVICE_INFO(XForms)
89 
90 // some special handling for the FormattedFieldWrapper which can act as FormattedModel or as EditModel
91 DECLARE_SERVICE_INFO(OFormattedFieldWrapper)
92 	// this is for a service, which is instantiated through the EditModel service name
93 	// and which acts mostly as Edit (mostly means : if somebody uses XPersistObject::read immediately after
94 	// the object was instantiated and the stream contains a FormattedModel, it switches permanently to
95 	// formatted.)
96 namespace frm { \
97 	extern Reference< XInterface > SAL_CALL OFormattedFieldWrapper_CreateInstance_ForceFormatted(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException); \
98 }
99 
100 DECLARE_SERVICE_INFO(OFormsCollection)
101 DECLARE_SERVICE_INFO(ImageProducer)
102 
103 //---------------------------------------------------------------------------------------
104 
105 static Sequence< ::rtl::OUString >						s_aClassImplementationNames;
106 static Sequence<Sequence< ::rtl::OUString > >	s_aClassServiceNames;
107 static Sequence<sal_Int64>								s_aFactories;
108 	// need to use sal_Int64 instead of ComponentInstantiation, as ComponentInstantiation has no cppuType, so
109 	// it can't be used with sequences
110 
111 //---------------------------------------------------------------------------------------
112 void registerClassInfo(
113 		::rtl::OUString _rClassImplName,								// the ImplName of the class
114 		const Sequence< ::rtl::OUString >& _rServiceNames,		// the services supported by this class
115 		::cppu::ComponentInstantiation _pCreateFunction					// the method for instantiating such a class
116 		)
117 {
118 	sal_Int32 nCurrentLength = s_aClassImplementationNames.getLength();
119 	OSL_ENSURE((nCurrentLength == s_aClassServiceNames.getLength())
120 		&& (nCurrentLength == s_aFactories.getLength()),
121 		"forms::registerClassInfo : invalid class infos !");
122 
123 	s_aClassImplementationNames.realloc(nCurrentLength + 1);
124 	s_aClassServiceNames.realloc(nCurrentLength + 1);
125 	s_aFactories.realloc(nCurrentLength + 1);
126 
127 	s_aClassImplementationNames.getArray()[nCurrentLength] = _rClassImplName;
128 	s_aClassServiceNames.getArray()[nCurrentLength] = _rServiceNames;
129 	s_aFactories.getArray()[nCurrentLength] = reinterpret_cast<sal_Int64>(_pCreateFunction);
130 }
131 
132 //---------------------------------------------------------------------------------------
133 //.......................................................................................
134 #define REGISTER_CLASS_CORE(classImplName) \
135 	registerClassInfo( \
136 		::rtl::OUString::createFromAscii("com.sun.star.form.") + ::rtl::OUString::createFromAscii(#classImplName), \
137 		aServices, \
138 		frm::classImplName##_CreateInstance)
139 
140 //.......................................................................................
141 #define REGISTER_CLASS1(classImplName, service1) \
142 	aServices.realloc(1); \
143 	aServices.getArray()[0] = frm::service1; \
144 	REGISTER_CLASS_CORE(classImplName)
145 
146 //.......................................................................................
147 #define REGISTER_CLASS2(classImplName, service1, service2) \
148 	aServices.realloc(2); \
149 	aServices.getArray()[0] = frm::service1; \
150 	aServices.getArray()[1] = frm::service2; \
151 	REGISTER_CLASS_CORE(classImplName)
152 
153 //.......................................................................................
154 #define REGISTER_CLASS3(classImplName, service1, service2, service3) \
155 	aServices.realloc(3); \
156 	aServices.getArray()[0] = frm::service1; \
157 	aServices.getArray()[1] = frm::service2; \
158 	aServices.getArray()[2] = frm::service3; \
159 	REGISTER_CLASS_CORE(classImplName)
160 
161 //.......................................................................................
162 #define REGISTER_CLASS4(classImplName, service1, service2, service3, service4) \
163 	aServices.realloc(4); \
164 	aServices.getArray()[0] = frm::service1; \
165 	aServices.getArray()[1] = frm::service2; \
166 	aServices.getArray()[2] = frm::service3; \
167 	aServices.getArray()[3] = frm::service4; \
168 	REGISTER_CLASS_CORE(classImplName)
169 
170 //---------------------------------------------------------------------------------------
171 void ensureClassInfos()
172 {
173 	if (s_aClassImplementationNames.getLength())
174 		// nothing to do
175 		return;
176 	Sequence< ::rtl::OUString > aServices;
177 
178 	// ========================================================================
179 	// = ControlModels
180 	// ------------------------------------------------------------------------
181 	// - FixedText
182 	REGISTER_CLASS2(OFixedTextModel, FRM_COMPONENT_FIXEDTEXT, FRM_SUN_COMPONENT_FIXEDTEXT);
183 	// - Hidden
184 	REGISTER_CLASS3(OHiddenModel, FRM_COMPONENT_HIDDENCONTROL, FRM_SUN_COMPONENT_HIDDENCONTROL, FRM_COMPONENT_HIDDEN);
185 	// - FileControl
186 	REGISTER_CLASS2(OFileControlModel, FRM_COMPONENT_FILECONTROL, FRM_SUN_COMPONENT_FILECONTROL);
187 	// - ImageButton
188 	REGISTER_CLASS2(OImageButtonModel, FRM_COMPONENT_IMAGEBUTTON, FRM_SUN_COMPONENT_IMAGEBUTTON);
189 	// - GridControl
190 	REGISTER_CLASS3(OGridControlModel, FRM_COMPONENT_GRID /* compatibility */, FRM_COMPONENT_GRIDCONTROL, FRM_SUN_COMPONENT_GRIDCONTROL);
191 	// - GroupBox
192 	REGISTER_CLASS2(OGroupBoxModel, FRM_COMPONENT_GROUPBOX, FRM_SUN_COMPONENT_GROUPBOX);
193 
194 	// - RadioButton
195 	REGISTER_CLASS4( ORadioButtonModel, FRM_COMPONENT_RADIOBUTTON, FRM_SUN_COMPONENT_RADIOBUTTON, FRM_SUN_COMPONENT_DATABASE_RADIOBUTTON, BINDABLE_DATABASE_RADIO_BUTTON );
196 	// - CheckBox
197 	REGISTER_CLASS4( OCheckBoxModel, FRM_COMPONENT_CHECKBOX, FRM_SUN_COMPONENT_CHECKBOX, FRM_SUN_COMPONENT_DATABASE_CHECKBOX, BINDABLE_DATABASE_CHECK_BOX );
198 	// - ListBox
199 	REGISTER_CLASS4( OListBoxModel, FRM_COMPONENT_LISTBOX, FRM_SUN_COMPONENT_LISTBOX, FRM_SUN_COMPONENT_DATABASE_LISTBOX, BINDABLE_DATABASE_LIST_BOX );
200 	// - ComboBox
201 	REGISTER_CLASS4( OComboBoxModel, FRM_COMPONENT_COMBOBOX, FRM_SUN_COMPONENT_COMBOBOX, FRM_SUN_COMPONENT_DATABASE_COMBOBOX, BINDABLE_DATABASE_COMBO_BOX );
202 	// - EditControl
203 	REGISTER_CLASS4( OEditModel, FRM_COMPONENT_TEXTFIELD, FRM_SUN_COMPONENT_TEXTFIELD, FRM_SUN_COMPONENT_DATABASE_TEXTFIELD, BINDABLE_DATABASE_TEXT_FIELD );
204 	// - DateControl
205 	REGISTER_CLASS3( ODateModel, FRM_COMPONENT_DATEFIELD, FRM_SUN_COMPONENT_DATEFIELD, FRM_SUN_COMPONENT_DATABASE_DATEFIELD );
206 	// - TimeControl
207 	REGISTER_CLASS3( OTimeModel, FRM_COMPONENT_TIMEFIELD, FRM_SUN_COMPONENT_TIMEFIELD, FRM_SUN_COMPONENT_DATABASE_TIMEFIELD );
208 	// - NumericField
209 	REGISTER_CLASS4( ONumericModel, FRM_COMPONENT_NUMERICFIELD, FRM_SUN_COMPONENT_NUMERICFIELD, FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD, BINDABLE_DATABASE_NUMERIC_FIELD );
210 	// - CurrencyField
211 	REGISTER_CLASS3( OCurrencyModel, FRM_COMPONENT_CURRENCYFIELD, FRM_SUN_COMPONENT_CURRENCYFIELD, FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD );
212 	// - PatternField
213 	REGISTER_CLASS3( OPatternModel, FRM_COMPONENT_PATTERNFIELD, FRM_SUN_COMPONENT_PATTERNFIELD, FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD );
214 	// - Button
215 	REGISTER_CLASS2( OButtonModel, FRM_COMPONENT_COMMANDBUTTON, FRM_SUN_COMPONENT_COMMANDBUTTON );
216 	// - ImageControl
217 	REGISTER_CLASS2( OImageControlModel, FRM_COMPONENT_IMAGECONTROL, FRM_SUN_COMPONENT_IMAGECONTROL );
218 
219 	// - FormattedField
220 	REGISTER_CLASS1(OFormattedFieldWrapper, FRM_COMPONENT_EDIT);
221 		// since SRC568 both OFormattedModel and OEditModel use FRM_COMPONENT_EDIT for persistence,
222 		// and while reading a wrapper determines which kind of model it is
223 	// register the wrapper for the FormattedField, as it handles the XPersistObject::write
224 	// so that version <= 5.1 are able to read it
225 	aServices.realloc(4);
226 	aServices.getArray()[0] = frm::FRM_COMPONENT_FORMATTEDFIELD;
227 	aServices.getArray()[1] = frm::FRM_SUN_COMPONENT_FORMATTEDFIELD;
228     aServices.getArray()[2] = frm::FRM_SUN_COMPONENT_DATABASE_FORMATTEDFIELD;
229 	aServices.getArray()[3] = frm::BINDABLE_DATABASE_FORMATTED_FIELD;
230 
231 	registerClassInfo(::rtl::OUString::createFromAscii("com.sun.star.comp.forms.OFormattedFieldWrapper_ForcedFormatted"),
232 		aServices,
233 		frm::OFormattedFieldWrapper_CreateInstance_ForceFormatted);
234 
235 	// ========================================================================
236 	// = Controls
237 	// - RadioButton
238 	REGISTER_CLASS2(ORadioButtonControl, STARDIV_ONE_FORM_CONTROL_RADIOBUTTON, FRM_SUN_CONTROL_RADIOBUTTON);
239 	// - CheckBox
240 	REGISTER_CLASS2(OCheckBoxControl, STARDIV_ONE_FORM_CONTROL_CHECKBOX, FRM_SUN_CONTROL_CHECKBOX);
241 	// - GroupBox
242 	REGISTER_CLASS2(OGroupBoxControl, STARDIV_ONE_FORM_CONTROL_GROUPBOX, FRM_SUN_CONTROL_GROUPBOX);
243 	// - ListBox
244 	REGISTER_CLASS2(OListBoxControl, STARDIV_ONE_FORM_CONTROL_LISTBOX, FRM_SUN_CONTROL_LISTBOX);
245 	// - ComboBox
246 	REGISTER_CLASS2(OComboBoxControl, STARDIV_ONE_FORM_CONTROL_COMBOBOX, FRM_SUN_CONTROL_COMBOBOX);
247 	// - EditControl
248 	REGISTER_CLASS3(OEditControl, STARDIV_ONE_FORM_CONTROL_TEXTFIELD, FRM_SUN_CONTROL_TEXTFIELD, STARDIV_ONE_FORM_CONTROL_EDIT);
249 	// - DateControl
250 	REGISTER_CLASS2(ODateControl, STARDIV_ONE_FORM_CONTROL_DATEFIELD, FRM_SUN_CONTROL_DATEFIELD);
251 	// - TimeControl
252 	REGISTER_CLASS2(OTimeControl, STARDIV_ONE_FORM_CONTROL_TIMEFIELD, FRM_SUN_CONTROL_TIMEFIELD);
253 	// - NumericField
254 	REGISTER_CLASS2(ONumericControl, STARDIV_ONE_FORM_CONTROL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD);
255 	// - CurrencyField
256 	REGISTER_CLASS2(OCurrencyControl, STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD);
257 	// - PatternField
258 	REGISTER_CLASS2(OPatternControl, STARDIV_ONE_FORM_CONTROL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD);
259 	// - FormattedField
260 	REGISTER_CLASS2(OFormattedControl, STARDIV_ONE_FORM_CONTROL_FORMATTEDFIELD, FRM_SUN_CONTROL_FORMATTEDFIELD);
261 	// - Button
262 	REGISTER_CLASS2(OButtonControl, STARDIV_ONE_FORM_CONTROL_COMMANDBUTTON, FRM_SUN_CONTROL_COMMANDBUTTON);
263 	// - ImageButton
264 	REGISTER_CLASS2(OImageButtonControl, STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON);
265 	// - ImageControl
266 	REGISTER_CLASS2(OImageControlControl, STARDIV_ONE_FORM_CONTROL_IMAGECONTROL, FRM_SUN_CONTROL_IMAGECONTROL);
267 
268 
269 	// ========================================================================
270 	// = various
271 	REGISTER_CLASS1(OFormsCollection, FRM_SUN_FORMS_COLLECTION);
272 	REGISTER_CLASS1(ImageProducer, SRV_AWT_IMAGEPRODUCER);
273 
274 	// ========================================================================
275 	// = XForms core
276 #define REGISTER_XFORMS_CLASS(name) \
277 	aServices.realloc(1); \
278 	aServices.getArray()[0] = rtl::OUString::createFromAscii( "com.sun.star.xforms." #name ); \
279 	REGISTER_CLASS_CORE(name)
280 
281     REGISTER_XFORMS_CLASS(Model);
282     REGISTER_XFORMS_CLASS(XForms);
283 
284 }
285 
286 //=======================================================================================
287 extern "C"
288 {
289 
290 //---------------------------------------------------------------------------------------
291 void SAL_CALL createRegistryInfo_ODatabaseForm();
292 void SAL_CALL createRegistryInfo_OFilterControl();
293 void SAL_CALL createRegistryInfo_OScrollBarModel();
294 void SAL_CALL createRegistryInfo_OSpinButtonModel();
295 void SAL_CALL createRegistryInfo_ONavigationBarModel();
296 void SAL_CALL createRegistryInfo_ONavigationBarControl();
297 void SAL_CALL createRegistryInfo_ORichTextModel();
298 void SAL_CALL createRegistryInfo_ORichTextControl();
299 void SAL_CALL createRegistryInfo_CLibxml2XFormsExtension();
300 void SAL_CALL createRegistryInfo_FormOperations();
301 
302 //---------------------------------------------------------------------------------------
303 void SAL_CALL createRegistryInfo_FORMS()
304 {
305 	static sal_Bool bInit = sal_False;
306 	if (!bInit)
307 	{
308 		createRegistryInfo_ODatabaseForm();
309 		createRegistryInfo_OFilterControl();
310 		createRegistryInfo_OScrollBarModel();
311 		createRegistryInfo_OSpinButtonModel();
312         createRegistryInfo_ONavigationBarModel();
313         createRegistryInfo_ONavigationBarControl();
314         createRegistryInfo_ORichTextModel();
315         createRegistryInfo_ORichTextControl();
316         createRegistryInfo_CLibxml2XFormsExtension();
317         createRegistryInfo_FormOperations();
318 		bInit = sal_True;
319 	}
320 }
321 
322 //---------------------------------------------------------------------------------------
323 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** _ppEnvTypeName, uno_Environment** /*_ppEnv*/)
324 {
325 	*_ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
326 }
327 
328 //---------------------------------------------------------------------------------------
329 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* _pImplName, XMultiServiceFactory* _pServiceManager, void* /*_pRegistryKey*/)
330 {
331 	if (!_pServiceManager || !_pImplName)
332 		return NULL;
333 
334     // ========================================================================
335 	// a lot of stuff which is implemented "manually" here in this file
336 	void* pRet = NULL;
337 
338 	// collect the class infos
339 	ensureClassInfos();
340 
341 	// both our static sequences should have the same length ...
342 	sal_Int32 nClasses = s_aClassImplementationNames.getLength();
343 	OSL_ENSURE((s_aClassServiceNames.getLength() == nClasses) &&
344 		(s_aFactories.getLength() == nClasses),
345 		"forms::component_writeInfo : invalid class infos !");
346 
347 	// loop through the sequences and register the service providers
348 	const ::rtl::OUString* pClasses = s_aClassImplementationNames.getConstArray();
349 	const Sequence< ::rtl::OUString >* pServices = s_aClassServiceNames.getConstArray();
350 	const sal_Int64* pFunctionsAsInts = s_aFactories.getConstArray();
351 
352 	for (sal_Int32 i=0; i<nClasses; ++i, ++pClasses, ++pServices, ++pFunctionsAsInts)
353 	{
354 		if (rtl_ustr_ascii_compare(*pClasses, _pImplName) == 0)
355 		{
356 			::cppu::ComponentInstantiation aCurrentCreateFunction =
357 				reinterpret_cast< ::cppu::ComponentInstantiation>(*pFunctionsAsInts);
358 
359 			Reference<XSingleServiceFactory> xFactory(
360 				::cppu::createSingleFactory(
361 					_pServiceManager,
362 					*pClasses,
363 					aCurrentCreateFunction,
364 					*pServices
365 				)
366 			);
367 			if (xFactory.is())
368 			{
369 				xFactory->acquire();
370 				pRet = xFactory.get();
371 				break;
372 			}
373 		}
374 	}
375 
376     // ========================================================================
377 	// the real way - use the OModule
378 	if ( !pRet )
379 	{
380 		createRegistryInfo_FORMS();
381 		{
382 			// let the module look for the component
383 			Reference< XInterface > xRet;
384 			xRet = ::frm::OFormsModule::getComponentFactory(
385 				::rtl::OUString::createFromAscii( _pImplName ),
386 				static_cast< XMultiServiceFactory* >( _pServiceManager ) );
387 
388 			if ( xRet.is() )
389 				xRet->acquire();
390 			pRet = xRet.get();
391 		}
392 	}
393 
394 	return pRet;
395 }
396 
397 }
398