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