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