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