1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: services.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "services.hxx"
34 #include "frm_module.hxx"
35 #include <cppuhelper/factory.hxx>
36 #include <uno/lbnames.h>
37 #include <osl/diagnose.h>
38 #include <uno/mapping.hxx>
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::registry
;
44 //---------------------------------------------------------------------------------------
45 //.......................................................................................
46 #define DECLARE_SERVICE_INFO(classImplName) \
48 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); \
51 //---------------------------------------------------------------------------------------
52 DECLARE_SERVICE_INFO(OFixedTextModel
)
53 DECLARE_SERVICE_INFO(ORadioButtonModel
)
54 DECLARE_SERVICE_INFO(ORadioButtonControl
)
55 DECLARE_SERVICE_INFO(OCheckBoxModel
)
56 DECLARE_SERVICE_INFO(OCheckBoxControl
)
57 DECLARE_SERVICE_INFO(OHiddenModel
)
58 DECLARE_SERVICE_INFO(OGroupBoxModel
)
59 DECLARE_SERVICE_INFO(OGroupBoxControl
)
60 DECLARE_SERVICE_INFO(OListBoxControl
)
61 DECLARE_SERVICE_INFO(OListBoxModel
)
62 DECLARE_SERVICE_INFO(OComboBoxControl
)
63 DECLARE_SERVICE_INFO(OComboBoxModel
)
64 DECLARE_SERVICE_INFO(OEditControl
)
65 DECLARE_SERVICE_INFO(OEditModel
)
66 DECLARE_SERVICE_INFO(ONumericControl
)
67 DECLARE_SERVICE_INFO(ONumericModel
)
68 DECLARE_SERVICE_INFO(OPatternControl
)
69 DECLARE_SERVICE_INFO(OPatternModel
)
70 DECLARE_SERVICE_INFO(OCurrencyControl
)
71 DECLARE_SERVICE_INFO(OCurrencyModel
)
72 DECLARE_SERVICE_INFO(ODateControl
)
73 DECLARE_SERVICE_INFO(ODateModel
)
74 DECLARE_SERVICE_INFO(OTimeControl
)
75 DECLARE_SERVICE_INFO(OTimeModel
)
76 DECLARE_SERVICE_INFO(OFormattedControl
)
77 DECLARE_SERVICE_INFO(OFormattedModel
)
78 DECLARE_SERVICE_INFO(OFileControlModel
)
79 DECLARE_SERVICE_INFO(OButtonControl
)
80 DECLARE_SERVICE_INFO(OButtonModel
)
81 DECLARE_SERVICE_INFO(OImageButtonControl
)
82 DECLARE_SERVICE_INFO(OImageButtonModel
)
84 DECLARE_SERVICE_INFO(OImageControlControl
)
85 DECLARE_SERVICE_INFO(OImageControlModel
)
86 DECLARE_SERVICE_INFO(OGridControlModel
)
89 DECLARE_SERVICE_INFO(Binding
)
90 DECLARE_SERVICE_INFO(Model
)
91 DECLARE_SERVICE_INFO(XForms
)
93 // some special handling for the FormattedFieldWrapper which can act as FormattedModel or as EditModel
94 DECLARE_SERVICE_INFO(OFormattedFieldWrapper
)
95 // this is for a service, which is instantiated through the EditModel service name
96 // and which acts mostly as Edit (mostly means : if somebody uses XPersistObject::read immediately after
97 // the object was instantiated and the stream contains a FormattedModel, it switches permanently to
100 extern Reference
< XInterface
> SAL_CALL
OFormattedFieldWrapper_CreateInstance_ForceFormatted(const Reference
<XMultiServiceFactory
>& _rxFactory
) throw (RuntimeException
); \
103 DECLARE_SERVICE_INFO(OFormsCollection
)
104 DECLARE_SERVICE_INFO(ImageProducer
)
106 //---------------------------------------------------------------------------------------
108 static Sequence
< ::rtl::OUString
> s_aClassImplementationNames
;
109 static Sequence
<Sequence
< ::rtl::OUString
> > s_aClassServiceNames
;
110 static Sequence
<sal_Int64
> s_aFactories
;
111 // need to use sal_Int64 instead of ComponentInstantiation, as ComponentInstantiation has no cppuType, so
112 // it can't be used with sequences
114 //---------------------------------------------------------------------------------------
115 void registerClassInfo(
116 ::rtl::OUString _rClassImplName
, // the ImplName of the class
117 const Sequence
< ::rtl::OUString
>& _rServiceNames
, // the services supported by this class
118 ::cppu::ComponentInstantiation _pCreateFunction
// the method for instantiating such a class
121 sal_Int32 nCurrentLength
= s_aClassImplementationNames
.getLength();
122 OSL_ENSURE((nCurrentLength
== s_aClassServiceNames
.getLength())
123 && (nCurrentLength
== s_aFactories
.getLength()),
124 "forms::registerClassInfo : invalid class infos !");
126 s_aClassImplementationNames
.realloc(nCurrentLength
+ 1);
127 s_aClassServiceNames
.realloc(nCurrentLength
+ 1);
128 s_aFactories
.realloc(nCurrentLength
+ 1);
130 s_aClassImplementationNames
.getArray()[nCurrentLength
] = _rClassImplName
;
131 s_aClassServiceNames
.getArray()[nCurrentLength
] = _rServiceNames
;
132 s_aFactories
.getArray()[nCurrentLength
] = reinterpret_cast<sal_Int64
>(_pCreateFunction
);
135 //---------------------------------------------------------------------------------------
136 //.......................................................................................
137 #define REGISTER_CLASS_CORE(classImplName) \
139 ::rtl::OUString::createFromAscii("com.sun.star.form.") + ::rtl::OUString::createFromAscii(#classImplName), \
141 frm::classImplName##_CreateInstance)
143 //.......................................................................................
144 #define REGISTER_CLASS1(classImplName, service1) \
145 aServices.realloc(1); \
146 aServices.getArray()[0] = frm::service1; \
147 REGISTER_CLASS_CORE(classImplName)
149 //.......................................................................................
150 #define REGISTER_CLASS2(classImplName, service1, service2) \
151 aServices.realloc(2); \
152 aServices.getArray()[0] = frm::service1; \
153 aServices.getArray()[1] = frm::service2; \
154 REGISTER_CLASS_CORE(classImplName)
156 //.......................................................................................
157 #define REGISTER_CLASS3(classImplName, service1, service2, service3) \
158 aServices.realloc(3); \
159 aServices.getArray()[0] = frm::service1; \
160 aServices.getArray()[1] = frm::service2; \
161 aServices.getArray()[2] = frm::service3; \
162 REGISTER_CLASS_CORE(classImplName)
164 //.......................................................................................
165 #define REGISTER_CLASS4(classImplName, service1, service2, service3, service4) \
166 aServices.realloc(4); \
167 aServices.getArray()[0] = frm::service1; \
168 aServices.getArray()[1] = frm::service2; \
169 aServices.getArray()[2] = frm::service3; \
170 aServices.getArray()[3] = frm::service4; \
171 REGISTER_CLASS_CORE(classImplName)
173 //---------------------------------------------------------------------------------------
174 void ensureClassInfos()
176 if (s_aClassImplementationNames
.getLength())
179 Sequence
< ::rtl::OUString
> aServices
;
181 // ========================================================================
183 // ------------------------------------------------------------------------
185 REGISTER_CLASS2(OFixedTextModel
, FRM_COMPONENT_FIXEDTEXT
, FRM_SUN_COMPONENT_FIXEDTEXT
);
187 REGISTER_CLASS3(OHiddenModel
, FRM_COMPONENT_HIDDENCONTROL
, FRM_SUN_COMPONENT_HIDDENCONTROL
, FRM_COMPONENT_HIDDEN
);
189 REGISTER_CLASS2(OFileControlModel
, FRM_COMPONENT_FILECONTROL
, FRM_SUN_COMPONENT_FILECONTROL
);
191 REGISTER_CLASS2(OImageButtonModel
, FRM_COMPONENT_IMAGEBUTTON
, FRM_SUN_COMPONENT_IMAGEBUTTON
);
193 REGISTER_CLASS3(OGridControlModel
, FRM_COMPONENT_GRID
/* compatibility */, FRM_COMPONENT_GRIDCONTROL
, FRM_SUN_COMPONENT_GRIDCONTROL
);
195 REGISTER_CLASS2(OGroupBoxModel
, FRM_COMPONENT_GROUPBOX
, FRM_SUN_COMPONENT_GROUPBOX
);
198 REGISTER_CLASS4( ORadioButtonModel
, FRM_COMPONENT_RADIOBUTTON
, FRM_SUN_COMPONENT_RADIOBUTTON
, FRM_SUN_COMPONENT_DATABASE_RADIOBUTTON
, BINDABLE_DATABASE_RADIO_BUTTON
);
200 REGISTER_CLASS4( OCheckBoxModel
, FRM_COMPONENT_CHECKBOX
, FRM_SUN_COMPONENT_CHECKBOX
, FRM_SUN_COMPONENT_DATABASE_CHECKBOX
, BINDABLE_DATABASE_CHECK_BOX
);
202 REGISTER_CLASS4( OListBoxModel
, FRM_COMPONENT_LISTBOX
, FRM_SUN_COMPONENT_LISTBOX
, FRM_SUN_COMPONENT_DATABASE_LISTBOX
, BINDABLE_DATABASE_LIST_BOX
);
204 REGISTER_CLASS4( OComboBoxModel
, FRM_COMPONENT_COMBOBOX
, FRM_SUN_COMPONENT_COMBOBOX
, FRM_SUN_COMPONENT_DATABASE_COMBOBOX
, BINDABLE_DATABASE_COMBO_BOX
);
206 REGISTER_CLASS4( OEditModel
, FRM_COMPONENT_TEXTFIELD
, FRM_SUN_COMPONENT_TEXTFIELD
, FRM_SUN_COMPONENT_DATABASE_TEXTFIELD
, BINDABLE_DATABASE_TEXT_FIELD
);
208 REGISTER_CLASS3( ODateModel
, FRM_COMPONENT_DATEFIELD
, FRM_SUN_COMPONENT_DATEFIELD
, FRM_SUN_COMPONENT_DATABASE_DATEFIELD
);
210 REGISTER_CLASS3( OTimeModel
, FRM_COMPONENT_TIMEFIELD
, FRM_SUN_COMPONENT_TIMEFIELD
, FRM_SUN_COMPONENT_DATABASE_TIMEFIELD
);
212 REGISTER_CLASS4( ONumericModel
, FRM_COMPONENT_NUMERICFIELD
, FRM_SUN_COMPONENT_NUMERICFIELD
, FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD
, BINDABLE_DATABASE_NUMERIC_FIELD
);
214 REGISTER_CLASS3( OCurrencyModel
, FRM_COMPONENT_CURRENCYFIELD
, FRM_SUN_COMPONENT_CURRENCYFIELD
, FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD
);
216 REGISTER_CLASS3( OPatternModel
, FRM_COMPONENT_PATTERNFIELD
, FRM_SUN_COMPONENT_PATTERNFIELD
, FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD
);
218 REGISTER_CLASS2( OButtonModel
, FRM_COMPONENT_COMMANDBUTTON
, FRM_SUN_COMPONENT_COMMANDBUTTON
);
220 REGISTER_CLASS2( OImageControlModel
, FRM_COMPONENT_IMAGECONTROL
, FRM_SUN_COMPONENT_IMAGECONTROL
);
223 REGISTER_CLASS1(OFormattedFieldWrapper
, FRM_COMPONENT_EDIT
);
224 // since SRC568 both OFormattedModel and OEditModel use FRM_COMPONENT_EDIT for persistence,
225 // and while reading a wrapper determines which kind of model it is
226 // register the wrapper for the FormattedField, as it handles the XPersistObject::write
227 // so that version <= 5.1 are able to read it
228 aServices
.realloc(4);
229 aServices
.getArray()[0] = frm::FRM_COMPONENT_FORMATTEDFIELD
;
230 aServices
.getArray()[1] = frm::FRM_SUN_COMPONENT_FORMATTEDFIELD
;
231 aServices
.getArray()[2] = frm::FRM_SUN_COMPONENT_DATABASE_FORMATTEDFIELD
;
232 aServices
.getArray()[3] = frm::BINDABLE_DATABASE_FORMATTED_FIELD
;
234 registerClassInfo(::rtl::OUString::createFromAscii("com.sun.star.comp.forms.OFormattedFieldWrapper_ForcedFormatted"),
236 frm::OFormattedFieldWrapper_CreateInstance_ForceFormatted
);
238 // ========================================================================
241 REGISTER_CLASS2(ORadioButtonControl
, STARDIV_ONE_FORM_CONTROL_RADIOBUTTON
, FRM_SUN_CONTROL_RADIOBUTTON
);
243 REGISTER_CLASS2(OCheckBoxControl
, STARDIV_ONE_FORM_CONTROL_CHECKBOX
, FRM_SUN_CONTROL_CHECKBOX
);
245 REGISTER_CLASS2(OGroupBoxControl
, STARDIV_ONE_FORM_CONTROL_GROUPBOX
, FRM_SUN_CONTROL_GROUPBOX
);
247 REGISTER_CLASS2(OListBoxControl
, STARDIV_ONE_FORM_CONTROL_LISTBOX
, FRM_SUN_CONTROL_LISTBOX
);
249 REGISTER_CLASS2(OComboBoxControl
, STARDIV_ONE_FORM_CONTROL_COMBOBOX
, FRM_SUN_CONTROL_COMBOBOX
);
251 REGISTER_CLASS3(OEditControl
, STARDIV_ONE_FORM_CONTROL_TEXTFIELD
, FRM_SUN_CONTROL_TEXTFIELD
, STARDIV_ONE_FORM_CONTROL_EDIT
);
253 REGISTER_CLASS2(ODateControl
, STARDIV_ONE_FORM_CONTROL_DATEFIELD
, FRM_SUN_CONTROL_DATEFIELD
);
255 REGISTER_CLASS2(OTimeControl
, STARDIV_ONE_FORM_CONTROL_TIMEFIELD
, FRM_SUN_CONTROL_TIMEFIELD
);
257 REGISTER_CLASS2(ONumericControl
, STARDIV_ONE_FORM_CONTROL_NUMERICFIELD
, FRM_SUN_CONTROL_NUMERICFIELD
);
259 REGISTER_CLASS2(OCurrencyControl
, STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD
, FRM_SUN_CONTROL_CURRENCYFIELD
);
261 REGISTER_CLASS2(OPatternControl
, STARDIV_ONE_FORM_CONTROL_PATTERNFIELD
, FRM_SUN_CONTROL_PATTERNFIELD
);
263 REGISTER_CLASS2(OFormattedControl
, STARDIV_ONE_FORM_CONTROL_FORMATTEDFIELD
, FRM_SUN_CONTROL_FORMATTEDFIELD
);
265 REGISTER_CLASS2(OButtonControl
, STARDIV_ONE_FORM_CONTROL_COMMANDBUTTON
, FRM_SUN_CONTROL_COMMANDBUTTON
);
267 REGISTER_CLASS2(OImageButtonControl
, STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON
, FRM_SUN_CONTROL_IMAGEBUTTON
);
269 REGISTER_CLASS2(OImageControlControl
, STARDIV_ONE_FORM_CONTROL_IMAGECONTROL
, FRM_SUN_CONTROL_IMAGECONTROL
);
272 // ========================================================================
274 REGISTER_CLASS1(OFormsCollection
, FRM_SUN_FORMS_COLLECTION
);
275 REGISTER_CLASS1(ImageProducer
, SRV_AWT_IMAGEPRODUCER
);
277 // ========================================================================
279 #define REGISTER_XFORMS_CLASS(name) \
280 aServices.realloc(1); \
281 aServices.getArray()[0] = rtl::OUString::createFromAscii( "com.sun.star.xforms." #name ); \
282 REGISTER_CLASS_CORE(name)
284 REGISTER_XFORMS_CLASS(Model
);
285 REGISTER_XFORMS_CLASS(XForms
);
289 //---------------------------------------------------------------------------------------
290 void registerServiceProvider(const ::rtl::OUString
& _rServiceImplName
, const Sequence
< ::rtl::OUString
>& _rServices
, XRegistryKey
* _pKey
)
292 ::rtl::OUString sMainKeyName
= ::rtl::OUString::createFromAscii("/");
293 sMainKeyName
+= _rServiceImplName
;
294 sMainKeyName
+= ::rtl::OUString::createFromAscii("/UNO/SERVICES");
295 Reference
< XRegistryKey
> xNewKey
= _pKey
->createKey(sMainKeyName
);
296 OSL_ENSURE(xNewKey
.is(), "forms::registerProvider : could not create a registry key !");
300 const ::rtl::OUString
* pSupportedServices
= _rServices
.getConstArray();
301 for (sal_Int32 i
=0; i
<_rServices
.getLength(); ++i
, ++pSupportedServices
)
302 xNewKey
->createKey(*pSupportedServices
);
305 //=======================================================================================
309 //---------------------------------------------------------------------------------------
310 void SAL_CALL
createRegistryInfo_ODatabaseForm();
311 void SAL_CALL
createRegistryInfo_OFilterControl();
312 void SAL_CALL
createRegistryInfo_OScrollBarModel();
313 void SAL_CALL
createRegistryInfo_OSpinButtonModel();
314 void SAL_CALL
createRegistryInfo_ONavigationBarModel();
315 void SAL_CALL
createRegistryInfo_ONavigationBarControl();
316 void SAL_CALL
createRegistryInfo_ORichTextModel();
317 void SAL_CALL
createRegistryInfo_ORichTextControl();
318 void SAL_CALL
createRegistryInfo_CLibxml2XFormsExtension();
319 void SAL_CALL
createRegistryInfo_FormOperations();
321 //---------------------------------------------------------------------------------------
322 void SAL_CALL
createRegistryInfo_FORMS()
324 static sal_Bool bInit
= sal_False
;
327 createRegistryInfo_ODatabaseForm();
328 createRegistryInfo_OFilterControl();
329 createRegistryInfo_OScrollBarModel();
330 createRegistryInfo_OSpinButtonModel();
331 createRegistryInfo_ONavigationBarModel();
332 createRegistryInfo_ONavigationBarControl();
333 createRegistryInfo_ORichTextModel();
334 createRegistryInfo_ORichTextControl();
335 createRegistryInfo_CLibxml2XFormsExtension();
336 createRegistryInfo_FormOperations();
341 //---------------------------------------------------------------------------------------
342 SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironment(const sal_Char
** _ppEnvTypeName
, uno_Environment
** /*_ppEnv*/)
344 *_ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
347 //---------------------------------------------------------------------------------------
348 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(void* _pServiceManager
, XRegistryKey
* _pRegistryKey
)
354 // ========================================================================
355 // the real way - use the OModule
356 createRegistryInfo_FORMS();
357 if ( !::frm::OFormsModule::writeComponentInfos(
358 static_cast<XMultiServiceFactory
*>( _pServiceManager
),
359 static_cast<XRegistryKey
*>( _pRegistryKey
) )
363 // ========================================================================
364 // a lot of stuff which is implemented "manually" here in this file
366 // collect the class infos
369 // both our static sequences should have the same length ...
370 sal_Int32 nClasses
= s_aClassImplementationNames
.getLength();
371 OSL_ENSURE(s_aClassServiceNames
.getLength() == nClasses
,
372 "forms::component_writeInfo : invalid class infos !");
374 // loop through the sequences and register the service providers
375 const ::rtl::OUString
* pClasses
= s_aClassImplementationNames
.getConstArray();
376 const Sequence
< ::rtl::OUString
>* pServices
= s_aClassServiceNames
.getConstArray();
378 for (sal_Int32 i
=0; i
<nClasses
; ++i
, ++pClasses
, ++pServices
)
379 registerServiceProvider(*pClasses
, *pServices
, _pRegistryKey
);
381 s_aClassImplementationNames
.realloc(0);
382 s_aClassServiceNames
.realloc(0);
383 s_aFactories
.realloc(0);
387 catch ( InvalidRegistryException
& )
389 OSL_ENSURE(sal_False
, "forms::component_writeInfo : InvalidRegistryException !");
392 s_aClassImplementationNames
.realloc(0);
393 s_aClassServiceNames
.realloc(0);
394 s_aFactories
.realloc(0);
398 //---------------------------------------------------------------------------------------
399 SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(const sal_Char
* _pImplName
, XMultiServiceFactory
* _pServiceManager
, void* /*_pRegistryKey*/)
401 if (!_pServiceManager
|| !_pImplName
)
404 // ========================================================================
405 // a lot of stuff which is implemented "manually" here in this file
408 // collect the class infos
411 // both our static sequences should have the same length ...
412 sal_Int32 nClasses
= s_aClassImplementationNames
.getLength();
413 OSL_ENSURE((s_aClassServiceNames
.getLength() == nClasses
) &&
414 (s_aFactories
.getLength() == nClasses
),
415 "forms::component_writeInfo : invalid class infos !");
417 // loop through the sequences and register the service providers
418 const ::rtl::OUString
* pClasses
= s_aClassImplementationNames
.getConstArray();
419 const Sequence
< ::rtl::OUString
>* pServices
= s_aClassServiceNames
.getConstArray();
420 const sal_Int64
* pFunctionsAsInts
= s_aFactories
.getConstArray();
422 for (sal_Int32 i
=0; i
<nClasses
; ++i
, ++pClasses
, ++pServices
, ++pFunctionsAsInts
)
424 if (rtl_ustr_ascii_compare(*pClasses
, _pImplName
) == 0)
426 ::cppu::ComponentInstantiation aCurrentCreateFunction
=
427 reinterpret_cast< ::cppu::ComponentInstantiation
>(*pFunctionsAsInts
);
429 Reference
<XSingleServiceFactory
> xFactory(
430 ::cppu::createSingleFactory(
433 aCurrentCreateFunction
,
440 pRet
= xFactory
.get();
446 // ========================================================================
447 // the real way - use the OModule
450 createRegistryInfo_FORMS();
452 // let the module look for the component
453 Reference
< XInterface
> xRet
;
454 xRet
= ::frm::OFormsModule::getComponentFactory(
455 ::rtl::OUString::createFromAscii( _pImplName
),
456 static_cast< XMultiServiceFactory
* >( _pServiceManager
) );