1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "services.hxx"
21 #include "frm_module.hxx"
22 #include <cppuhelper/factory.hxx>
23 #include <uno/lbnames.h>
24 #include <osl/diagnose.h>
25 #include <uno/mapping.hxx>
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::lang
;
29 using namespace ::com::sun::star::registry
;
31 //---------------------------------------------------------------------------------------
32 //.......................................................................................
33 #define DECLARE_SERVICE_INFO(classImplName) \
35 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); \
38 //---------------------------------------------------------------------------------------
39 DECLARE_SERVICE_INFO(OFixedTextModel
)
40 DECLARE_SERVICE_INFO(ORadioButtonModel
)
41 DECLARE_SERVICE_INFO(ORadioButtonControl
)
42 DECLARE_SERVICE_INFO(OCheckBoxModel
)
43 DECLARE_SERVICE_INFO(OCheckBoxControl
)
44 DECLARE_SERVICE_INFO(OHiddenModel
)
45 DECLARE_SERVICE_INFO(OGroupBoxModel
)
46 DECLARE_SERVICE_INFO(OGroupBoxControl
)
47 DECLARE_SERVICE_INFO(OListBoxControl
)
48 DECLARE_SERVICE_INFO(OListBoxModel
)
49 DECLARE_SERVICE_INFO(OComboBoxControl
)
50 DECLARE_SERVICE_INFO(OComboBoxModel
)
51 DECLARE_SERVICE_INFO(OEditControl
)
52 DECLARE_SERVICE_INFO(OEditModel
)
53 DECLARE_SERVICE_INFO(ONumericControl
)
54 DECLARE_SERVICE_INFO(ONumericModel
)
55 DECLARE_SERVICE_INFO(OPatternControl
)
56 DECLARE_SERVICE_INFO(OPatternModel
)
57 DECLARE_SERVICE_INFO(OCurrencyControl
)
58 DECLARE_SERVICE_INFO(OCurrencyModel
)
59 DECLARE_SERVICE_INFO(ODateControl
)
60 DECLARE_SERVICE_INFO(ODateModel
)
61 DECLARE_SERVICE_INFO(OTimeControl
)
62 DECLARE_SERVICE_INFO(OTimeModel
)
63 DECLARE_SERVICE_INFO(OFormattedControl
)
64 DECLARE_SERVICE_INFO(OFormattedModel
)
65 DECLARE_SERVICE_INFO(OFileControlModel
)
66 DECLARE_SERVICE_INFO(OButtonControl
)
67 DECLARE_SERVICE_INFO(OButtonModel
)
68 DECLARE_SERVICE_INFO(OImageButtonControl
)
69 DECLARE_SERVICE_INFO(OImageButtonModel
)
71 DECLARE_SERVICE_INFO(OImageControlControl
)
72 DECLARE_SERVICE_INFO(OImageControlModel
)
73 DECLARE_SERVICE_INFO(OGridControlModel
)
76 DECLARE_SERVICE_INFO(Binding
)
77 DECLARE_SERVICE_INFO(Model
)
78 DECLARE_SERVICE_INFO(XForms
)
80 // some special handling for the FormattedFieldWrapper which can act as FormattedModel or as EditModel
81 DECLARE_SERVICE_INFO(OFormattedFieldWrapper
)
82 // this is for a service, which is instantiated through the EditModel service name
83 // and which acts mostly as Edit (mostly means : if somebody uses XPersistObject::read immediately after
84 // the object was instantiated and the stream contains a FormattedModel, it switches permanently to
87 extern Reference
< XInterface
> SAL_CALL
OFormattedFieldWrapper_CreateInstance_ForceFormatted(const Reference
<XMultiServiceFactory
>& _rxFactory
) throw (RuntimeException
); \
90 DECLARE_SERVICE_INFO(OFormsCollection
)
91 DECLARE_SERVICE_INFO(ImageProducer
)
93 //---------------------------------------------------------------------------------------
95 static Sequence
< OUString
> s_aClassImplementationNames
;
96 static Sequence
<Sequence
< OUString
> > s_aClassServiceNames
;
97 static Sequence
<sal_Int64
> s_aFactories
;
98 // need to use sal_Int64 instead of ComponentInstantiation, as ComponentInstantiation has no cppuType, so
99 // it can't be used with sequences
101 //---------------------------------------------------------------------------------------
102 void registerClassInfo(
103 OUString _rClassImplName
, // the ImplName of the class
104 const Sequence
< OUString
>& _rServiceNames
, // the services supported by this class
105 ::cppu::ComponentInstantiation _pCreateFunction
// the method for instantiating such a class
108 sal_Int32 nCurrentLength
= s_aClassImplementationNames
.getLength();
109 OSL_ENSURE((nCurrentLength
== s_aClassServiceNames
.getLength())
110 && (nCurrentLength
== s_aFactories
.getLength()),
111 "forms::registerClassInfo : invalid class infos !");
113 s_aClassImplementationNames
.realloc(nCurrentLength
+ 1);
114 s_aClassServiceNames
.realloc(nCurrentLength
+ 1);
115 s_aFactories
.realloc(nCurrentLength
+ 1);
117 s_aClassImplementationNames
.getArray()[nCurrentLength
] = _rClassImplName
;
118 s_aClassServiceNames
.getArray()[nCurrentLength
] = _rServiceNames
;
119 s_aFactories
.getArray()[nCurrentLength
] = reinterpret_cast<sal_Int64
>(_pCreateFunction
);
122 //---------------------------------------------------------------------------------------
123 //.......................................................................................
124 #define REGISTER_CLASS_CORE(classImplName) \
126 OUString("com.sun.star.form.") + OUString(#classImplName), \
128 frm::classImplName##_CreateInstance)
130 //.......................................................................................
131 #define REGISTER_CLASS1(classImplName, service1) \
132 aServices.realloc(1); \
133 aServices.getArray()[0] = service1; \
134 REGISTER_CLASS_CORE(classImplName)
136 //.......................................................................................
137 #define REGISTER_CLASS2(classImplName, service1, service2) \
138 aServices.realloc(2); \
139 aServices.getArray()[0] = service1; \
140 aServices.getArray()[1] = service2; \
141 REGISTER_CLASS_CORE(classImplName)
143 //.......................................................................................
144 #define REGISTER_CLASS3(classImplName, service1, service2, service3) \
145 aServices.realloc(3); \
146 aServices.getArray()[0] = service1; \
147 aServices.getArray()[1] = service2; \
148 aServices.getArray()[2] = service3; \
149 REGISTER_CLASS_CORE(classImplName)
151 //.......................................................................................
152 #define REGISTER_CLASS4(classImplName, service1, service2, service3, service4) \
153 aServices.realloc(4); \
154 aServices.getArray()[0] = service1; \
155 aServices.getArray()[1] = service2; \
156 aServices.getArray()[2] = service3; \
157 aServices.getArray()[3] = service4; \
158 REGISTER_CLASS_CORE(classImplName)
160 //---------------------------------------------------------------------------------------
161 void ensureClassInfos()
163 if (s_aClassImplementationNames
.getLength())
166 Sequence
< OUString
> aServices
;
168 // ========================================================================
170 // ------------------------------------------------------------------------
172 REGISTER_CLASS2(OFixedTextModel
, FRM_COMPONENT_FIXEDTEXT
, FRM_SUN_COMPONENT_FIXEDTEXT
);
174 REGISTER_CLASS3(OHiddenModel
, FRM_COMPONENT_HIDDENCONTROL
, FRM_SUN_COMPONENT_HIDDENCONTROL
, FRM_COMPONENT_HIDDEN
);
176 REGISTER_CLASS2(OFileControlModel
, FRM_COMPONENT_FILECONTROL
, FRM_SUN_COMPONENT_FILECONTROL
);
178 REGISTER_CLASS2(OImageButtonModel
, FRM_COMPONENT_IMAGEBUTTON
, FRM_SUN_COMPONENT_IMAGEBUTTON
);
180 REGISTER_CLASS3(OGridControlModel
, FRM_COMPONENT_GRID
/* compatibility */, FRM_COMPONENT_GRIDCONTROL
, FRM_SUN_COMPONENT_GRIDCONTROL
);
182 REGISTER_CLASS2(OGroupBoxModel
, FRM_COMPONENT_GROUPBOX
, FRM_SUN_COMPONENT_GROUPBOX
);
185 REGISTER_CLASS4( ORadioButtonModel
, FRM_COMPONENT_RADIOBUTTON
, FRM_SUN_COMPONENT_RADIOBUTTON
, FRM_SUN_COMPONENT_DATABASE_RADIOBUTTON
, BINDABLE_DATABASE_RADIO_BUTTON
);
187 REGISTER_CLASS4( OCheckBoxModel
, FRM_COMPONENT_CHECKBOX
, FRM_SUN_COMPONENT_CHECKBOX
, FRM_SUN_COMPONENT_DATABASE_CHECKBOX
, BINDABLE_DATABASE_CHECK_BOX
);
189 REGISTER_CLASS4( OListBoxModel
, FRM_COMPONENT_LISTBOX
, FRM_SUN_COMPONENT_LISTBOX
, FRM_SUN_COMPONENT_DATABASE_LISTBOX
, BINDABLE_DATABASE_LIST_BOX
);
191 REGISTER_CLASS4( OComboBoxModel
, FRM_COMPONENT_COMBOBOX
, FRM_SUN_COMPONENT_COMBOBOX
, FRM_SUN_COMPONENT_DATABASE_COMBOBOX
, BINDABLE_DATABASE_COMBO_BOX
);
193 REGISTER_CLASS4( OEditModel
, FRM_COMPONENT_TEXTFIELD
, FRM_SUN_COMPONENT_TEXTFIELD
, FRM_SUN_COMPONENT_DATABASE_TEXTFIELD
, BINDABLE_DATABASE_TEXT_FIELD
);
195 REGISTER_CLASS3( ODateModel
, FRM_COMPONENT_DATEFIELD
, FRM_SUN_COMPONENT_DATEFIELD
, FRM_SUN_COMPONENT_DATABASE_DATEFIELD
);
197 REGISTER_CLASS3( OTimeModel
, FRM_COMPONENT_TIMEFIELD
, FRM_SUN_COMPONENT_TIMEFIELD
, FRM_SUN_COMPONENT_DATABASE_TIMEFIELD
);
199 REGISTER_CLASS4( ONumericModel
, FRM_COMPONENT_NUMERICFIELD
, FRM_SUN_COMPONENT_NUMERICFIELD
, FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD
, BINDABLE_DATABASE_NUMERIC_FIELD
);
201 REGISTER_CLASS3( OCurrencyModel
, FRM_COMPONENT_CURRENCYFIELD
, FRM_SUN_COMPONENT_CURRENCYFIELD
, FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD
);
203 REGISTER_CLASS3( OPatternModel
, FRM_COMPONENT_PATTERNFIELD
, FRM_SUN_COMPONENT_PATTERNFIELD
, FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD
);
205 REGISTER_CLASS2( OButtonModel
, FRM_COMPONENT_COMMANDBUTTON
, FRM_SUN_COMPONENT_COMMANDBUTTON
);
207 REGISTER_CLASS2( OImageControlModel
, FRM_COMPONENT_IMAGECONTROL
, FRM_SUN_COMPONENT_IMAGECONTROL
);
210 REGISTER_CLASS1(OFormattedFieldWrapper
, FRM_COMPONENT_EDIT
);
211 // since SRC568 both OFormattedModel and OEditModel use FRM_COMPONENT_EDIT for persistence,
212 // and while reading a wrapper determines which kind of model it is
213 // register the wrapper for the FormattedField, as it handles the XPersistObject::write
214 // so that version <= 5.1 are able to read it
215 aServices
.realloc(4);
216 aServices
.getArray()[0] = FRM_COMPONENT_FORMATTEDFIELD
;
217 aServices
.getArray()[1] = FRM_SUN_COMPONENT_FORMATTEDFIELD
;
218 aServices
.getArray()[2] = FRM_SUN_COMPONENT_DATABASE_FORMATTEDFIELD
;
219 aServices
.getArray()[3] = BINDABLE_DATABASE_FORMATTED_FIELD
;
221 registerClassInfo(OUString("com.sun.star.comp.forms.OFormattedFieldWrapper_ForcedFormatted"),
223 frm::OFormattedFieldWrapper_CreateInstance_ForceFormatted
);
225 // ========================================================================
228 REGISTER_CLASS2(ORadioButtonControl
, STARDIV_ONE_FORM_CONTROL_RADIOBUTTON
, FRM_SUN_CONTROL_RADIOBUTTON
);
230 REGISTER_CLASS2(OCheckBoxControl
, STARDIV_ONE_FORM_CONTROL_CHECKBOX
, FRM_SUN_CONTROL_CHECKBOX
);
232 REGISTER_CLASS2(OGroupBoxControl
, STARDIV_ONE_FORM_CONTROL_GROUPBOX
, FRM_SUN_CONTROL_GROUPBOX
);
234 REGISTER_CLASS2(OListBoxControl
, STARDIV_ONE_FORM_CONTROL_LISTBOX
, FRM_SUN_CONTROL_LISTBOX
);
236 REGISTER_CLASS2(OComboBoxControl
, STARDIV_ONE_FORM_CONTROL_COMBOBOX
, FRM_SUN_CONTROL_COMBOBOX
);
238 REGISTER_CLASS3(OEditControl
, STARDIV_ONE_FORM_CONTROL_TEXTFIELD
, FRM_SUN_CONTROL_TEXTFIELD
, STARDIV_ONE_FORM_CONTROL_EDIT
);
240 REGISTER_CLASS2(ODateControl
, STARDIV_ONE_FORM_CONTROL_DATEFIELD
, FRM_SUN_CONTROL_DATEFIELD
);
242 REGISTER_CLASS2(OTimeControl
, STARDIV_ONE_FORM_CONTROL_TIMEFIELD
, FRM_SUN_CONTROL_TIMEFIELD
);
244 REGISTER_CLASS2(ONumericControl
, STARDIV_ONE_FORM_CONTROL_NUMERICFIELD
, FRM_SUN_CONTROL_NUMERICFIELD
);
246 REGISTER_CLASS2(OCurrencyControl
, STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD
, FRM_SUN_CONTROL_CURRENCYFIELD
);
248 REGISTER_CLASS2(OPatternControl
, STARDIV_ONE_FORM_CONTROL_PATTERNFIELD
, FRM_SUN_CONTROL_PATTERNFIELD
);
250 REGISTER_CLASS2(OFormattedControl
, STARDIV_ONE_FORM_CONTROL_FORMATTEDFIELD
, FRM_SUN_CONTROL_FORMATTEDFIELD
);
252 REGISTER_CLASS2(OButtonControl
, STARDIV_ONE_FORM_CONTROL_COMMANDBUTTON
, FRM_SUN_CONTROL_COMMANDBUTTON
);
254 REGISTER_CLASS2(OImageButtonControl
, STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON
, FRM_SUN_CONTROL_IMAGEBUTTON
);
256 REGISTER_CLASS2(OImageControlControl
, STARDIV_ONE_FORM_CONTROL_IMAGECONTROL
, FRM_SUN_CONTROL_IMAGECONTROL
);
259 // ========================================================================
261 aServices
.realloc(1);
262 aServices
.getArray()[0] = OUString("com.sun.star.form.Forms");
263 REGISTER_CLASS_CORE(OFormsCollection
);
265 REGISTER_CLASS1(ImageProducer
, SRV_AWT_IMAGEPRODUCER
);
267 // ========================================================================
269 #define REGISTER_XFORMS_CLASS(name) \
270 aServices.realloc(1); \
271 aServices.getArray()[0] = OUString( "com.sun.star.xforms." #name ); \
272 REGISTER_CLASS_CORE(name)
274 REGISTER_XFORMS_CLASS(Model
);
275 REGISTER_XFORMS_CLASS(XForms
);
279 //=======================================================================================
283 //---------------------------------------------------------------------------------------
284 void SAL_CALL
createRegistryInfo_ODatabaseForm();
285 void SAL_CALL
createRegistryInfo_OFilterControl();
286 void SAL_CALL
createRegistryInfo_OScrollBarModel();
287 void SAL_CALL
createRegistryInfo_OSpinButtonModel();
288 void SAL_CALL
createRegistryInfo_ONavigationBarModel();
289 void SAL_CALL
createRegistryInfo_ONavigationBarControl();
290 void SAL_CALL
createRegistryInfo_ORichTextModel();
291 void SAL_CALL
createRegistryInfo_ORichTextControl();
292 void SAL_CALL
createRegistryInfo_CLibxml2XFormsExtension();
293 void SAL_CALL
createRegistryInfo_FormOperations();
295 //---------------------------------------------------------------------------------------
296 void SAL_CALL
createRegistryInfo_FORMS()
298 static sal_Bool bInit
= sal_False
;
301 createRegistryInfo_ODatabaseForm();
302 createRegistryInfo_OFilterControl();
303 createRegistryInfo_OScrollBarModel();
304 createRegistryInfo_OSpinButtonModel();
305 createRegistryInfo_ONavigationBarModel();
306 createRegistryInfo_ONavigationBarControl();
307 createRegistryInfo_ORichTextModel();
308 createRegistryInfo_ORichTextControl();
309 createRegistryInfo_CLibxml2XFormsExtension();
310 createRegistryInfo_FormOperations();
315 //---------------------------------------------------------------------------------------
316 SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
frm_component_getFactory(const sal_Char
* _pImplName
, XMultiServiceFactory
* _pServiceManager
, void* /*_pRegistryKey*/)
318 if (!_pServiceManager
|| !_pImplName
)
321 // ========================================================================
322 // a lot of stuff which is implemented "manually" here in this file
325 // collect the class infos
328 // both our static sequences should have the same length ...
329 sal_Int32 nClasses
= s_aClassImplementationNames
.getLength();
330 OSL_ENSURE((s_aClassServiceNames
.getLength() == nClasses
) &&
331 (s_aFactories
.getLength() == nClasses
),
332 "forms::component_getFactory : invalid class infos !");
334 // loop through the sequences and register the service providers
335 const OUString
* pClasses
= s_aClassImplementationNames
.getConstArray();
336 const Sequence
< OUString
>* pServices
= s_aClassServiceNames
.getConstArray();
337 const sal_Int64
* pFunctionsAsInts
= s_aFactories
.getConstArray();
339 for (sal_Int32 i
=0; i
<nClasses
; ++i
, ++pClasses
, ++pServices
, ++pFunctionsAsInts
)
341 if (rtl_ustr_ascii_compare(pClasses
->getStr(), _pImplName
) == 0)
343 ::cppu::ComponentInstantiation aCurrentCreateFunction
=
344 reinterpret_cast< ::cppu::ComponentInstantiation
>(*pFunctionsAsInts
);
346 Reference
<XSingleServiceFactory
> xFactory(
347 ::cppu::createSingleFactory(
350 aCurrentCreateFunction
,
357 pRet
= xFactory
.get();
363 // ========================================================================
364 // the real way - use the OModule
367 createRegistryInfo_FORMS();
369 // let the module look for the component
370 Reference
< XInterface
> xRet
;
371 xRet
= ::frm::OFormsModule::getComponentFactory(
372 OUString::createFromAscii( _pImplName
),
373 static_cast< XMultiServiceFactory
* >( _pServiceManager
) );
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */