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