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 "sal/config.h"
21 :
22 : #include "codemaker/commoncpp.hxx"
23 : #include "codemaker/global.hxx"
24 :
25 : #include "skeletoncommon.hxx"
26 : #include "skeletoncpp.hxx"
27 :
28 : #include <iostream>
29 :
30 : using namespace ::rtl;
31 : using namespace ::codemaker::cpp;
32 :
33 : namespace skeletonmaker { namespace cpp {
34 :
35 0 : void generateIncludes(std::ostream & o,
36 : const std::set< OUString >& interfaces,
37 : OUString propertyhelper, bool serviceobject,
38 : bool supportxcomponent)
39 : {
40 0 : o << "#include \"sal/config.h\"\n";
41 0 : if (serviceobject) {
42 0 : o << "#include \"cppuhelper/factory.hxx\"\n"
43 0 : << "#include \"cppuhelper/implementationentry.hxx\"\n";
44 : } else {
45 0 : o << "#include \"com/sun/star/uno/XComponentContext.hpp\"\n";
46 : }
47 0 : if (supportxcomponent) {
48 0 : o << "#include \"cppuhelper/compbase" << interfaces.size() << ".hxx\"\n";
49 0 : o << "#include \"cppuhelper/basemutex.hxx\"\n";
50 : } else {
51 0 : o << "#include \"cppuhelper/implbase" << interfaces.size() << ".hxx\"\n";
52 : }
53 :
54 0 : if (propertyhelper.getLength() > 1) {
55 0 : if (propertyhelper.equals("_"))
56 0 : o << "#include \"cppuhelper/rpopshlp.hxx\"\n";
57 : else
58 0 : o << "#include \"cppuhelper/propertysetmixin.hxx\"\n";
59 : }
60 :
61 0 : std::set< OUString >::const_iterator iter = interfaces.begin();
62 0 : while (iter != interfaces.end())
63 : {
64 0 : o << "#include \""
65 0 : << ((*iter).replace('.', '/').getStr())
66 0 : << ".hpp\"\n";
67 0 : ++iter;
68 : }
69 0 : }
70 :
71 0 : short generateNamespace(std::ostream & o,
72 : const OString & implname,
73 : bool serviceobject,
74 : OString & nm)
75 : {
76 0 : short count=0;
77 0 : sal_Int32 index = implname.lastIndexOf('.');
78 0 : if (serviceobject) {
79 0 : o << "\n\n// component helper namespace\n";
80 : } else {
81 0 : o << "\n";
82 : }
83 0 : OStringBuffer buf;
84 0 : if (index == -1) {
85 0 : if (serviceobject) {
86 0 : buf.append("comp_");
87 0 : buf.append(implname);
88 0 : nm = buf.makeStringAndClear();
89 0 : o << "namespace comp_" << implname << " {\n\n";
90 0 : count=1;
91 : } else {
92 0 : nm = OString();
93 : }
94 : } else {
95 0 : sal_Int32 nPos=0;
96 0 : do {
97 0 : OString token(implname.getToken(0, '.', nPos));
98 0 : if (nPos < 0 && serviceobject) {
99 0 : buf.append("::comp_");
100 0 : buf.append(token);
101 0 : o << "namespace comp_" << token << " { ";
102 0 : count++;
103 : } else {
104 0 : buf.append("::");
105 0 : buf.append(token);
106 0 : o << "namespace " << token << " { ";
107 0 : count++;
108 0 : }
109 0 : } while( nPos <= index );
110 0 : nm = buf.makeStringAndClear();
111 0 : o << "\n\n";
112 : }
113 0 : return count;
114 : }
115 :
116 0 : OString generateCompHelperDeclaration(std::ostream & o,
117 : const OString & implname)
118 : {
119 0 : OString nm;
120 0 : short nbrackets = generateNamespace(o, implname, true, nm);
121 :
122 0 : o << "namespace css = ::com::sun::star;\n\n";
123 :
124 : // generate component/service helper functions
125 : o << "// component and service helper functions:\n"
126 : "::rtl::OUString SAL_CALL _getImplementationName();\n"
127 : "css::uno::Sequence< ::rtl::OUString > SAL_CALL "
128 : "_getSupportedServiceNames();\n"
129 : "css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
130 : " css::uno::Reference< css::uno::XComponentContext > const & "
131 0 : "context );\n\n";
132 :
133 : // close namepsace
134 0 : for (short i=0; i < nbrackets; i++)
135 0 : o << "} ";
136 0 : o << "// closing component helper namespace\n\n";
137 :
138 0 : return nm;
139 : }
140 :
141 0 : void generateCompHelperDefinition(std::ostream & o,
142 : const OString & implname,
143 : const OString & classname,
144 : const std::set< OUString >& services)
145 : {
146 0 : OString nm;
147 0 : short nbrackets = generateNamespace(o, implname, true, nm);
148 :
149 0 : o << "::rtl::OUString SAL_CALL _getImplementationName() {\n"
150 0 : << " return ::rtl::OUString(\n"
151 0 : << " \"" << implname << "\");\n}\n\n";
152 :
153 : o << "css::uno::Sequence< ::rtl::OUString > SAL_CALL "
154 0 : "_getSupportedServiceNames()\n{\n css::uno::Sequence< "
155 0 : << "::rtl::OUString >" << " s(" << services.size() << ");\n";
156 :
157 0 : std::set< OUString >::const_iterator iter = services.begin();
158 0 : short i=0;
159 0 : while (iter != services.end())
160 : {
161 0 : o << " s[" << i++ << "] = ::rtl::OUString(\""
162 0 : << *iter << "\");\n";
163 0 : ++iter;
164 : }
165 0 : o << " return s;\n}\n\n";
166 :
167 0 : o << "css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
168 0 : << "\n const css::uno::Reference< css::uno::XComponentContext > & "
169 0 : << "context)\n SAL_THROW((css::uno::Exception))\n{\n"
170 0 : << " return static_cast< ::cppu::OWeakObject * >(new "
171 0 : << classname << "(context));\n}\n\n";
172 :
173 : // close namepsace
174 0 : for (short j=0; j < nbrackets; j++)
175 0 : o << "} ";
176 0 : o << "// closing component helper namespace\n\n";
177 :
178 0 : }
179 :
180 0 : void generateCompFunctions(std::ostream & o, const OString & nmspace)
181 : {
182 0 : o << "static ::cppu::ImplementationEntry const entries[] = {\n"
183 0 : << " { &" << nmspace << "::_create,\n &"
184 0 : << nmspace << "::_getImplementationName,\n &"
185 0 : << nmspace << "::_getSupportedServiceNames,\n"
186 0 : << " &::cppu::createSingleComponentFactory, 0, 0 },\n"
187 0 : << " { 0, 0, 0, 0, 0, 0 }\n};\n\n";
188 :
189 0 : o << "extern \"C\" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(\n"
190 0 : << " const char * implName, void * serviceManager, void * registryKey)\n{\n"
191 0 : << " return ::cppu::component_getFactoryHelper(\n"
192 0 : << " implName, serviceManager, registryKey, entries);\n}\n\n";
193 :
194 0 : o << "extern \"C\" sal_Bool SAL_CALL component_writeInfo(\n"
195 0 : << " void * serviceManager, void * registryKey)\n{\n"
196 0 : << " return ::cppu::component_writeInfoHelper("
197 0 : << "serviceManager, registryKey, entries);\n}\n";
198 0 : }
199 :
200 0 : void generateXPropertySetBodies(std::ostream& o,
201 : const OString & classname,
202 : const OString & propertyhelper)
203 : {
204 0 : o << "// com.sun.star.beans.XPropertySet:\n";
205 :
206 0 : o << "css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL "
207 0 : << classname << "getPropertySetInfo() throw ("
208 0 : "css::uno::RuntimeException)\n{\n return ::cppu::PropertySetMixin< "
209 0 : << propertyhelper
210 0 : << " >::getPropertySetInfo();\n}\n\n";
211 :
212 0 : o << "void SAL_CALL " << classname << "setPropertyValue(const ::rtl::OUString"
213 : " & aPropertyName, const css::uno::Any & aValue) throw ("
214 : "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
215 : "css::beans::PropertyVetoException, css::lang::IllegalArgumentException, "
216 0 : "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
217 0 : << propertyhelper << " >::setPropertyValue(aPropertyName, aValue);\n}\n\n";
218 :
219 :
220 0 : o << "css::uno::Any SAL_CALL " << classname << "getPropertyValue(const "
221 : "::rtl::OUString & aPropertyName) throw (css::uno::RuntimeException, "
222 : "css::beans::UnknownPropertyException, css::lang::WrappedTargetException)"
223 0 : "\n{\n return ::cppu::PropertySetMixin< "
224 0 : << propertyhelper << " >::getPropertyValue(aPropertyName);\n}\n\n";
225 :
226 0 : o << "void SAL_CALL " << classname << "addPropertyChangeListener(const "
227 : "::rtl::OUString & aPropertyName, const css::uno::Reference< "
228 : "css::beans::XPropertyChangeListener > & xListener) throw ("
229 : "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
230 0 : "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
231 0 : << propertyhelper
232 0 : << " >::addPropertyChangeListener(aPropertyName, xListener);\n}\n\n";
233 :
234 0 : o << "void SAL_CALL " << classname << "removePropertyChangeListener(const "
235 : "::rtl::OUString & aPropertyName, const css::uno::Reference< "
236 : "css::beans::XPropertyChangeListener > & xListener) throw ("
237 : "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
238 0 : "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
239 0 : << propertyhelper
240 0 : << " >::removePropertyChangeListener(aPropertyName, xListener);\n}\n\n";
241 :
242 0 : o << "void SAL_CALL " << classname << "addVetoableChangeListener(const "
243 : "::rtl::OUString & aPropertyName, const css::uno::Reference< "
244 : "css::beans::XVetoableChangeListener > & xListener) throw ("
245 : "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
246 0 : "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
247 0 : << propertyhelper
248 0 : << " >::addVetoableChangeListener(aPropertyName, xListener);\n}\n\n";
249 :
250 0 : o << "void SAL_CALL " << classname << "removeVetoableChangeListener(const "
251 : "::rtl::OUString & aPropertyName, const css::uno::Reference< "
252 : "css::beans::XVetoableChangeListener > & xListener) throw ("
253 : "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
254 0 : "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
255 0 : << propertyhelper
256 0 : << " >::removeVetoableChangeListener(aPropertyName, xListener);\n}\n\n";
257 0 : }
258 :
259 0 : void generateXFastPropertySetBodies(std::ostream& o,
260 : const OString & classname,
261 : const OString & propertyhelper)
262 : {
263 0 : o << "// com.sun.star.beans.XFastPropertySet:\n";
264 :
265 0 : o << "void SAL_CALL " << classname << "setFastPropertyValue( ::sal_Int32 "
266 : "nHandle, const css::uno::Any& aValue ) throw ("
267 : "css::beans::UnknownPropertyException, css::beans::PropertyVetoException, "
268 : "css::lang::IllegalArgumentException, css::lang::WrappedTargetException, "
269 0 : "css::uno::RuntimeException)\n{\n ::cppu::PropertySetMixin< "
270 0 : << propertyhelper << " >::setFastPropertyValue(nHandle, aValue);\n}\n\n";
271 :
272 :
273 0 : o << "css::uno::Any SAL_CALL " << classname << "getFastPropertyValue( "
274 : "::sal_Int32 nHandle ) throw (css::beans::UnknownPropertyException, "
275 : "css::lang::WrappedTargetException, css::uno::RuntimeException)\n{\n"
276 0 : " return ::cppu::PropertySetMixin< "
277 0 : << propertyhelper << " >::getFastPropertyValue(nHandle);\n}\n\n";
278 0 : }
279 :
280 0 : void generateXPropertyAccessBodies(std::ostream& o,
281 : const OString & classname,
282 : const OString & propertyhelper)
283 : {
284 0 : o << " // com.sun.star.beans.XPropertyAccess:\n";
285 :
286 0 : o << "css::uno::Sequence< css::beans::PropertyValue > SAL_CALL "
287 0 : << classname << "getPropertyValues( ) throw ("
288 : "css::uno::RuntimeException)\n{\n"
289 0 : " return ::cppu::PropertySetMixin< "
290 0 : << propertyhelper << " >::getPropertyValues();\n}\n\n";
291 :
292 0 : o << "void SAL_CALL " << classname << "setPropertyValues( const "
293 : "css::uno::Sequence< css::beans::PropertyValue >& aProps ) throw ("
294 : "css::beans::UnknownPropertyException, css::beans::PropertyVetoException, "
295 : "css::lang::IllegalArgumentException, css::lang::WrappedTargetException, "
296 : "css::uno::RuntimeException)\n{\n"
297 0 : " ::cppu::PropertySetMixin< "
298 0 : << propertyhelper << " >::setPropertyValues(aProps);\n}\n\n";
299 0 : }
300 :
301 0 : void generateXLocalizable(std::ostream& o, const OString & classname)
302 : {
303 : o << "// css::lang::XLocalizable:\n"
304 0 : "void SAL_CALL " << classname << "setLocale(const css::lang::"
305 : "Locale & eLocale) throw (css::uno::RuntimeException)\n{\n"
306 : " m_locale = eLocale;\n}\n\n"
307 0 : "css::lang::Locale SAL_CALL " << classname << "getLocale() "
308 0 : "throw (css::uno::RuntimeException)\n{\n return m_locale;\n}\n\n";
309 0 : }
310 :
311 0 : void generateXAddInBodies(std::ostream& o, const OString & classname)
312 : {
313 0 : o << "// css::sheet::XAddIn:\n";
314 :
315 0 : o << "::rtl::OUString SAL_CALL " << classname << "getProgrammaticFuntionName("
316 : "const ::rtl::OUString & aDisplayName) throw (css::uno::RuntimeException)"
317 : "\n{\n ::rtl::OUString ret;\n try {\n css::uno::Reference< "
318 : "css::container::XNameAccess > xNAccess(m_xHAccess, css::uno::UNO_QUERY);\n"
319 : " css::uno::Sequence< ::rtl::OUString > functions = "
320 : "xNAccess->getElementNames();\n sal_Int32 len = functions."
321 : "getLength();\n ::rtl::OUString sDisplayName;\n"
322 : " for (sal_Int32 i=0; i < len; ++i) {\n"
323 : " sDisplayName = getAddinProperty(functions[i], "
324 : "::rtl::OUString(),\n "
325 : "sDISPLAYNAME);\n if (sDisplayName.equals(aDisplayName))\n"
326 : " return functions[i];\n }\n }\n"
327 : " catch ( const css::uno::RuntimeException & e ) {\n throw e;\n }\n"
328 0 : " catch ( css::uno::Exception & ) {\n }\n return ret;\n}\n\n";
329 :
330 0 : o << "::rtl::OUString SAL_CALL " << classname << "getDisplayFunctionName(const "
331 : "::rtl::OUString & aProgrammaticName) throw (css::uno::RuntimeException)\n"
332 : "{\n return getAddinProperty(aProgrammaticName, ::rtl::OUString(), "
333 0 : "sDISPLAYNAME);\n}\n\n";
334 :
335 0 : o << "::rtl::OUString SAL_CALL " << classname << "getFunctionDescription(const "
336 : "::rtl::OUString & aProgrammaticName) throw (css::uno::RuntimeException)\n"
337 : "{\n return getAddinProperty(aProgrammaticName, ::rtl::OUString(), "
338 0 : "sDESCRIPTION);\n}\n\n";
339 :
340 0 : o << "::rtl::OUString SAL_CALL " << classname << "getDisplayArgumentName(const "
341 : "::rtl::OUString & aProgrammaticFunctionName, ::sal_Int32 nArgument) throw "
342 : "(css::uno::RuntimeException)\n{\n return getAddinProperty("
343 : "aProgrammaticFunctionName,\n m_functionMap["
344 : "aProgrammaticFunctionName][nArgument],\n"
345 0 : " sDISPLAYNAME);\n}\n\n";
346 :
347 0 : o << "::rtl::OUString SAL_CALL " << classname << "getArgumentDescription(const "
348 : "::rtl::OUString & aProgrammaticFunctionName, ::sal_Int32 nArgument) throw "
349 : "(css::uno::RuntimeException)\n{\n return getAddinProperty("
350 : "aProgrammaticFunctionName,\n "
351 : "m_functionMap[aProgrammaticFunctionName][nArgument],\n"
352 0 : " sDESCRIPTION);\n}\n\n";
353 :
354 0 : o << "::rtl::OUString SAL_CALL " << classname << "getProgrammaticCategoryName("
355 : "const ::rtl::OUString & aProgrammaticFunctionName) throw ("
356 : "css::uno::RuntimeException)\n{\n return getAddinProperty("
357 0 : "aProgrammaticFunctionName, ::rtl::OUString(), sCATEGORY);\n}\n\n";
358 :
359 0 : o << "::rtl::OUString SAL_CALL " << classname << "getDisplayCategoryName(const "
360 : "::rtl::OUString & aProgrammaticFunctionName) throw ("
361 : "css::uno::RuntimeException)\n{\n return getAddinProperty("
362 : "aProgrammaticFunctionName, ::rtl::OUString(), "
363 0 : "sCATEGORYDISPLAYNAME);\n}\n\n";
364 0 : }
365 :
366 0 : void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname)
367 : {
368 : o << "// css::sheet::XCompatibilityNames:\n"
369 0 : "css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL " << classname
370 : << "getCompatibilityNames(const ::rtl::OUString & aProgrammaticName) throw "
371 : "(css::uno::RuntimeException)\n{\n css::uno::Sequence< "
372 : "css::sheet::LocalizedName > seqLocalizedNames;\n try {\n "
373 : "::rtl::OUStringBuffer buf("
374 : "aProgrammaticName);\n buf.appendAscii(\"/CompatibilityName\");\n"
375 : " ::rtl::OUString hname(buf.makeStringAndClear());\n\n "
376 : "if ( m_xCompAccess->hasByHierarchicalName(hname) ) {\n"
377 : " css::uno::Reference< css::container::XNameAccess > "
378 : "xNameAccess(\n"
379 : " m_xCompAccess->getByHierarchicalName(hname), "
380 : "css::uno::UNO_QUERY);\n\n css::uno::Sequence< ::rtl::OUString"
381 : " > elems = \n xNameAccess->getElementNames();"
382 : "\n ::sal_Int32 len = elems.getLength();\n\n "
383 : "seqLocalizedNames.realloc(len);\n\n ::rtl::OUString "
384 : "sCompatibilityName;\n for (::sal_Int32 i=0; i < len; ++i) {\n"
385 : " ::rtl::OUString sLocale(elems[i]);\n "
386 : "xNameAccess->getByName(sLocale) >>= sCompatibilityName;\n\n"
387 : " css::lang::Locale aLocale;\n "
388 : "::sal_Int32 nIndex = 0, nToken = 0;\n "
389 : "do {\n ::rtl::OUString aToken = sLocale.getToken(0, '-', "
390 : "nIndex);\n switch (nToken++) {\n "
391 : "case 0:\n aLocale.Language = aToken;\n"
392 : " break;\n case 1:\n"
393 : " aLocale.Country = aToken;\n "
394 : " break;\n default:\n "
395 : "aLocale.Variant = sLocale.copy(nIndex-aToken.getLength()-1);\n"
396 : " nIndex = -1;\n }\n"
397 : " } while ( nIndex >= 0 );\n\n "
398 : "seqLocalizedNames[i].Locale = aLocale;\n "
399 : "seqLocalizedNames[i].Name = sCompatibilityName;\n }"
400 : "\n }\n }\n catch ( const css::uno::RuntimeException & e ) {\n "
401 : "throw e;\n }\n catch ( css::uno::Exception & ) {\n }\n\n"
402 0 : " return seqLocalizedNames;\n}\n\n";
403 0 : }
404 :
405 0 : void generateXInitialization(std::ostream& o, const OString & classname)
406 : {
407 : o << "// css::lang::XInitialization:\n"
408 0 : "void SAL_CALL " << classname << "initialize( const css::uno::Sequence< "
409 : "css::uno::Any >& aArguments ) "
410 : "throw (css::uno::Exception, css::uno::RuntimeException)\n{\n"
411 : " css::uno::Reference < css::frame::XFrame > xFrame;\n"
412 : " if ( aArguments.getLength() ) {\n aArguments[0] >>= xFrame;\n"
413 0 : " m_xFrame = xFrame;\n }\n}\n\n";
414 0 : }
415 :
416 0 : void generateXDispatch(std::ostream& o,
417 : const OString & classname,
418 : const ProtocolCmdMap & protocolCmdMap)
419 : {
420 : // com.sun.star.frame.XDispatch
421 : // dispatch
422 : o << "// css::frame::XDispatch:\n"
423 0 : "void SAL_CALL " << classname << "dispatch( const css::util::URL& aURL, const "
424 : "css::uno::Sequence< css::beans::PropertyValue >& aArguments ) throw"
425 0 : "(css::uno::RuntimeException)\n{\n";
426 :
427 0 : ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
428 0 : while (iter != protocolCmdMap.end()) {
429 0 : o << " if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
430 0 : << "\") == 0 )\n {\n";
431 :
432 0 : for (std::vector< OString >::const_iterator i = (*iter).second.begin();
433 0 : i != (*iter).second.end(); ++i) {
434 0 : o << " if ( aURL.Path.equalsAscii(\"" << (*i) << "\") )\n"
435 : " {\n // add your own code here\n"
436 0 : " return;\n }\n";
437 : }
438 :
439 0 : o << " }\n";
440 0 : ++iter;
441 : }
442 0 : o << "}\n\n";
443 :
444 : // addStatusListener
445 0 : o << "void SAL_CALL " << classname << "addStatusListener( const css::uno::Reference< "
446 : "css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) "
447 : "throw (css::uno::RuntimeException)\n{\n"
448 0 : " // add your own code here\n}\n\n";
449 :
450 : // removeStatusListener
451 0 : o << "void SAL_CALL " << classname << "removeStatusListener( const css::uno::Reference"
452 : "< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) "
453 : "throw (css::uno::RuntimeException)\n{\n"
454 0 : " // add your own code here\n}\n\n";
455 0 : }
456 :
457 0 : void generateXDispatchProvider(std::ostream& o,
458 : const OString & classname,
459 : const ProtocolCmdMap & protocolCmdMap)
460 : {
461 :
462 : // com.sun.star.frame.XDispatchProvider
463 : // queryDispatch
464 : o << "// css::frame::XDispatchProvider:\n"
465 0 : "css::uno::Reference< css::frame::XDispatch > SAL_CALL " << classname
466 : << "queryDispatch( const css::util::URL& aURL,"
467 : " const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) "
468 : "throw(css::uno::RuntimeException)\n{\n css::uno::Reference< "
469 : "css::frame::XDispatch > xRet;\n"
470 0 : " if ( !m_xFrame.is() )\n return 0;\n\n";
471 :
472 0 : ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
473 0 : while (iter != protocolCmdMap.end()) {
474 0 : o << " if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
475 0 : << "\") == 0 )\n {\n";
476 :
477 0 : for (std::vector< OString >::const_iterator i = (*iter).second.begin();
478 0 : i != (*iter).second.end(); ++i) {
479 0 : o << " if ( aURL.Path.equalsAscii(\"" << (*i) << "\") == 0 )\n"
480 0 : " xRet = this;\n";
481 : }
482 :
483 0 : o << " }\n";
484 0 : ++iter;
485 : }
486 0 : o << " return xRet;\n}\n\n";
487 :
488 : // queryDispatches
489 0 : o << "css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL "
490 0 : << classname << "queryDispatches( const css::uno::Sequence< "
491 : "css::frame::DispatchDescriptor >& seqDescripts ) throw("
492 : "css::uno::RuntimeException)\n{\n"
493 : " sal_Int32 nCount = seqDescripts.getLength();\n"
494 : " css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > "
495 : "lDispatcher(nCount);\n\n"
496 : " for( sal_Int32 i=0; i<nCount; ++i ) {\n"
497 : " lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL,\n"
498 : " seqDescripts[i].FrameName,\n"
499 : " seqDescripts[i].SearchFlags );\n"
500 0 : " }\n\n return lDispatcher;\n}\n\n";
501 0 : }
502 :
503 0 : void generateAddinConstructorAndHelper(std::ostream& o,
504 : ProgramOptions const & options,
505 : rtl::Reference< TypeManager > const & manager, const OString & classname,
506 : const std::set< OUString >& interfaces)
507 : {
508 0 : o << classname << "::" << classname
509 0 : << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n"
510 0 : << " m_xContext(context), m_locale()\n{\n";
511 :
512 0 : if (options.backwardcompatible) {
513 0 : o << " try {\n";
514 :
515 0 : generateFunctionParameterMap(o, options, manager, interfaces);
516 :
517 : o << " css::uno::Reference< css::lang::XMultiServiceFactory > xProvider"
518 : "(\n m_xContext->getServiceManager()->createInstanceWithContext"
519 : "(\n ::rtl::OUString(\n "
520 : " \"com.sun.star.configuration.ConfigurationProvider\"),"
521 0 : "\n m_xContext ), css::uno::UNO_QUERY );\n\n";
522 :
523 : o << " ::rtl::OUString sReadOnlyView(\n"
524 0 : " \"com.sun.star.configuration.ConfigurationAccess\");\n\n";
525 :
526 : o << " ::rtl::OUStringBuffer sPath(::rtl::OUString(\n"
527 : " \"/org.openoffice.Office.CalcAddIns/AddInInfo/\"));\n"
528 : " sPath.appendAscii(sADDIN_SERVICENAME);\n"
529 : " sPath.appendAscii(\"/AddInFunctions\");\n\n"
530 : " // create arguments: nodepath\n"
531 : " css::beans::PropertyValue aArgument;\n"
532 : " aArgument.Name = ::rtl::OUString(\"nodepath\");\n"
533 : " aArgument.Value <<= sPath.makeStringAndClear();\n\n"
534 : " css::uno::Sequence< css::uno::Any > aArguments(1);\n"
535 0 : " aArguments[0] <<= aArgument;\n\n";
536 :
537 : o << " // create the default view using default UI locale\n"
538 : " css::uno::Reference< css::uno::XInterface > xIface =\n"
539 : " xProvider->createInstanceWithArguments(sReadOnlyView, "
540 : "aArguments);\n\n"
541 : " m_xHAccess = css::uno::Reference<\n "
542 : "css::container::XHierarchicalNameAccess >(xIface, css::uno::UNO_QUERY);"
543 0 : "\n\n";
544 :
545 : o << " // extend arguments to create a view for all locales to get "
546 : "simple\n // access to the compatibilityname property\n"
547 : " aArgument.Name = ::rtl::OUString(\"locale\");\n"
548 : " aArgument.Value <<= ::rtl::OUString(\"*\");\n"
549 : " aArguments.realloc(2);\n"
550 : " aArguments[1] <<= aArgument;\n\n"
551 : " // create view for all locales\n"
552 : " xIface = xProvider->createInstanceWithArguments(sReadOnlyView, "
553 : "aArguments);\n\n"
554 : " m_xCompAccess = css::uno::Reference<\n "
555 0 : "css::container::XHierarchicalNameAccess >(xIface, css::uno::UNO_QUERY);\n";
556 :
557 0 : o << " }\n catch ( css::uno::Exception & ) {\n }\n}\n\n";
558 :
559 : o << "// addin configuration property helper function:\n::rtl::OUString "
560 0 : "SAL_CALL " << classname << "::getAddinProperty(const ::rtl::OUString &"
561 : " funcName, const ::rtl::OUString & paramName, const char * propName) "
562 : "throw (css::uno::RuntimeException)\n{\n"
563 : " ::rtl::OUString ret;\n try {\n "
564 : "::rtl::OUStringBuffer buf(funcName);\n"
565 : " if (!paramName.isEmpty()) {\n"
566 : " buf.appendAscii(\"/Parameters/\");\n"
567 : " buf.append(paramName);\n }\n\n"
568 : " css::uno::Reference< css::beans::XPropertySet > xPropSet(\n"
569 : " m_xHAccess->getByHierarchicalName(\n"
570 : " buf.makeStringAndClear()), css::uno::UNO_QUERY);\n"
571 : " xPropSet->getPropertyValue(\n "
572 : "::rtl::OUString(propName)) >>= ret;\n }\n"
573 : " catch ( const css::uno::RuntimeException & e ) {\n throw e;\n }\n"
574 0 : " catch ( css::uno::Exception & ) {\n }\n return ret;\n";
575 : }
576 0 : o <<"}\n\n";
577 0 : }
578 :
579 0 : void generateMemberInitialization(std::ostream& o,
580 : ProgramOptions const & options,
581 : rtl::Reference< TypeManager > const & manager,
582 : AttributeInfo const & members)
583 : {
584 0 : if (!members.empty()) {
585 0 : for (AttributeInfo::const_iterator i(members.begin());
586 0 : i != members.end(); ++i)
587 : {
588 : sal_Int32 rank;
589 0 : if ((manager->decompose(i->type, true, 0, &rank, 0, 0)
590 0 : <= codemaker::UnoType::SORT_CHAR)
591 0 : && rank == 0)
592 : {
593 0 : o << ",\n m_" << i->name << "(";
594 0 : printType(o, options, manager, i->type, 16, true);
595 0 : o << ")";
596 : }
597 : }
598 : }
599 0 : }
600 :
601 0 : void generateMemberDeclaration(std::ostream& o,
602 : ProgramOptions const & options,
603 : rtl::Reference< TypeManager > const & manager,
604 : AttributeInfo const & members)
605 : {
606 0 : for (AttributeInfo::const_iterator i(members.begin());
607 0 : i != members.end(); ++i)
608 : {
609 0 : o << " ";
610 0 : printType(o, options, manager, i->type, 1, false);
611 0 : o << " m_" << i->name << ";\n";
612 : }
613 0 : }
614 :
615 0 : OString generateClassDefinition(std::ostream& o,
616 : ProgramOptions const & options,
617 : rtl::Reference< TypeManager > const & manager,
618 : OString const & classname,
619 : std::set< OUString > const & interfaces,
620 : AttributeInfo const & properties,
621 : AttributeInfo const & attributes,
622 : std::set< OUString > const & propinterfaces,
623 : OUString const & propertyhelper, bool supportxcomponent)
624 : {
625 0 : OStringBuffer parentname(64);
626 0 : o << "class " << classname << ":\n";
627 :
628 0 : if (!interfaces.empty()) {
629 0 : if (supportxcomponent) {
630 0 : parentname.append("::cppu::WeakComponentImplHelper");
631 0 : parentname.append(static_cast<sal_Int32>(interfaces.size()));
632 0 : o << " private ::cppu::BaseMutex,\n"
633 0 : << " public ::cppu::WeakComponentImplHelper"
634 0 : << interfaces.size() << "<";
635 : } else {
636 0 : parentname.append("::cppu::WeakImplHelper");
637 0 : parentname.append(static_cast<sal_Int32>(interfaces.size()));
638 0 : o << " public ::cppu::WeakImplHelper" << interfaces.size() << "<";
639 : }
640 :
641 0 : std::set< OUString >::const_iterator iter = interfaces.begin();
642 0 : while (iter != interfaces.end())
643 : {
644 0 : o << "\n " << scopedCppName(u2b(*iter));
645 0 : ++iter;
646 0 : if (iter != interfaces.end())
647 0 : o << ",";
648 : else
649 0 : o << ">";
650 : }
651 : }
652 :
653 0 : if (propertyhelper.getLength() > 1) {
654 0 : o << ",\n public ::cppu::PropertySetMixin< "
655 0 : << scopedCppName(u2b(propertyhelper)) << " >";
656 : }
657 :
658 0 : o << "\n{\npublic:\n"
659 0 : << " explicit " << classname << "("
660 0 : << "css::uno::Reference< css::uno::XComponentContext > const & context);\n\n";
661 :
662 : // generate component/service helper functions
663 : // o << " // component and service helper functions:\n"
664 : // << " static ::rtl::OUString SAL_CALL _getImplementationName();\n"
665 : // << " static css::uno::Sequence< ::rtl::OUString > SAL_CALL "
666 : // << "_getSupportedServiceNames();\n"
667 : // << " static css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
668 : // << "\n css::uno::Reference< css::uno::XComponentContext > const & "
669 : // << "context);\n\n";
670 :
671 : // overload queryInterface
672 0 : if (propertyhelper.getLength() > 1) {
673 : o << " // css::uno::XInterface:\n"
674 : " virtual css::uno::Any SAL_CALL queryInterface("
675 : "css::uno::Type const & type) throw ("
676 0 : "css::uno::RuntimeException);\n";
677 :
678 0 : OStringBuffer buffer(256);
679 0 : buffer.append(parentname.toString());
680 0 : buffer.append("< ");
681 0 : std::set< OUString >::const_iterator iter = interfaces.begin();
682 0 : while (iter != interfaces.end())
683 : {
684 0 : buffer.append(scopedCppName(u2b(*iter)));
685 0 : ++iter;
686 0 : if (iter != interfaces.end())
687 0 : buffer.append(", ");
688 : else
689 0 : buffer.append(" >");
690 : }
691 0 : OString parent(buffer.makeStringAndClear());
692 0 : o << " virtual void SAL_CALL acquire() throw ()\n { "
693 0 : << parent << "::acquire(); }\n";
694 0 : o << " virtual void SAL_CALL release() throw ()\n { "
695 0 : << parent << "::release(); }\n\n";
696 : }
697 :
698 0 : std::set< OUString >::const_iterator it = interfaces.begin();
699 0 : codemaker::GeneratedTypeSet generated;
700 0 : while (it != interfaces.end())
701 : {
702 0 : printMethods(o, options, manager, *it, generated, "", "", " ",
703 0 : true, propertyhelper);
704 0 : ++it;
705 : }
706 :
707 0 : o << "private:\n " << classname << "(const " << classname << " &); // not defined\n"
708 0 : << " " << classname << "& operator=(const " << classname << " &); // not defined\n\n"
709 0 : << " // destructor is private and will be called indirectly by the release call"
710 0 : << " virtual ~" << classname << "() {}\n\n";
711 :
712 0 : if (options.componenttype == 2) {
713 : o << " typedef boost::unordered_map< ::sal_Int32, rtl::OUString, "
714 : "boost::hash<::sal_Int32> > ParamMap;\n"
715 : " typedef boost::unordered_map< rtl::OUString, ParamMap, "
716 : "rtl::OUStringHash > FunctionMap;\n\n"
717 : " ::rtl::OUString SAL_CALL getAddinProperty(const ::rtl::OUString & "
718 : "funcName, const ::rtl::OUString & paramName, const char * propName) "
719 0 : "throw (css::uno::RuntimeException);\n\n";
720 : }
721 :
722 0 : if (supportxcomponent) {
723 : o << " // overload WeakComponentImplHelperBase::disposing()\n"
724 : " // This function is called upon disposing the component,\n"
725 : " // if your component needs special work when it becomes\n"
726 : " // disposed, do it here.\n"
727 0 : " virtual void SAL_CALL disposing();\n\n";
728 : }
729 :
730 : // members
731 0 : o << " css::uno::Reference< css::uno::XComponentContext > m_xContext;\n";
732 0 : if (!supportxcomponent && !attributes.empty())
733 0 : o << " mutable ::osl::Mutex m_aMutex;\n";
734 :
735 : // additional member for add-ons
736 0 : if (options.componenttype == 3) {
737 0 : o << " css::uno::Reference< css::frame::XFrame > m_xFrame;\n";
738 : }
739 :
740 0 : if (options.componenttype == 2) {
741 0 : if (options.backwardcompatible) {
742 : o <<" css::uno::Reference< css::container::XHierarchicalNameAccess > "
743 : "m_xHAccess;\n"
744 : " css::uno::Reference< css::container::XHierarchicalNameAccess > "
745 : "m_xCompAccess;\n"
746 0 : " FunctionMap m_functionMap;\n";
747 : }
748 0 : o << " css::lang::Locale m_locale;\n";
749 : }
750 :
751 0 : generateMemberDeclaration(o, options, manager, properties);
752 0 : generateMemberDeclaration(o, options, manager, attributes);
753 :
754 : // if (!properties.empty())
755 : // {
756 : // AttributeInfo::const_iterator iter = properties.begin();
757 : // while (iter != properties.end())
758 : // {
759 : // o << " ";
760 : // printType(o, options, manager, iter->second.first.replace('.','/'),
761 : // 1, false);
762 : // o << " m_" << iter->first << ";\n";
763 : // iter++;
764 : // }
765 : // }
766 : // if (!attributes.empty())
767 : // {
768 : // AttributeInfo::const_iterator iter = attributes.begin();
769 : // while (iter != attributes.end())
770 : // {
771 : // o << " ";
772 : // printType(o, options, manager, iter->second.first.replace('.','/'),
773 : // 1, false);
774 : // o << " m_" << iter->first << ";\n";
775 : // iter++;
776 : // }
777 : // }
778 :
779 0 : o << "};\n\n";
780 :
781 : // generate constructor
782 0 : if (options.componenttype == 2) {
783 : generateAddinConstructorAndHelper(o, options, manager,
784 0 : classname, interfaces);
785 : } else {
786 0 : o << classname << "::" << classname
787 0 : << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n";
788 0 : if (supportxcomponent) {
789 0 : o << " ::cppu::WeakComponentImplHelper" << interfaces.size() << "<";
790 0 : std::set< OUString >::const_iterator iter = interfaces.begin();
791 0 : while (iter != interfaces.end()) {
792 0 : o << "\n " << scopedCppName(u2b(*iter));
793 0 : ++iter;
794 0 : if (iter != interfaces.end())
795 0 : o << ",";
796 : else
797 0 : o << ">(m_aMutex),\n";
798 : }
799 : }
800 0 : if (propertyhelper.getLength() > 1) {
801 0 : o << " ::cppu::PropertySetMixin< "
802 0 : << scopedCppName(u2b(propertyhelper)) << " >(\n"
803 0 : << " context, static_cast< Implements >(\n ";
804 0 : OStringBuffer buffer(128);
805 0 : if (propinterfaces.find("com/sun/star/beans/XPropertySet")
806 0 : != propinterfaces.end()) {
807 0 : buffer.append("IMPLEMENTS_PROPERTY_SET");
808 : }
809 0 : if (propinterfaces.find("com/sun/star/beans/XFastPropertySet")
810 0 : != propinterfaces.end()) {
811 0 : if (!buffer.isEmpty())
812 0 : buffer.append(" | IMPLEMENTS_FAST_PROPERTY_SET");
813 : else
814 0 : buffer.append("IMPLEMENTS_FAST_PROPERTY_SET");
815 : }
816 0 : if (propinterfaces.find("com/sun/star/beans/XPropertyAccess")
817 0 : != propinterfaces.end()) {
818 0 : if (!buffer.isEmpty())
819 0 : buffer.append(" | IMPLEMENTS_PROPERTY_ACCESS");
820 : else
821 0 : buffer.append("IMPLEMENTS_PROPERTY_ACCESS");
822 : }
823 0 : o << buffer.makeStringAndClear()
824 0 : << "), css::uno::Sequence< ::rtl::OUString >()),\n";
825 : }
826 0 : o << " m_xContext(context)";
827 :
828 0 : generateMemberInitialization(o, options, manager, properties);
829 0 : generateMemberInitialization(o, options, manager, attributes);
830 :
831 0 : o << "\n{}\n\n";
832 : }
833 :
834 : // generate service/component helper function implementations
835 : // generateServiceHelper(o, options.implname, classname, services);
836 :
837 0 : if (supportxcomponent) {
838 : o << "// overload WeakComponentImplHelperBase::disposing()\n"
839 : "// This function is called upon disposing the component,\n"
840 : "// if your component needs special work when it becomes\n"
841 : "// disposed, do it here.\n"
842 0 : "void SAL_CALL " << classname << "::disposing()\n{\n\n}\n\n";
843 : }
844 :
845 0 : return parentname.makeStringAndClear();
846 : }
847 :
848 0 : void generateXServiceInfoBodies(std::ostream& o,
849 : OString const & classname,
850 : OString const & comphelpernamespace)
851 : {
852 0 : o << "// com.sun.star.uno.XServiceInfo:\n"
853 0 : << "::rtl::OUString SAL_CALL " << classname << "getImplementationName() "
854 0 : << "throw (css::uno::RuntimeException)\n{\n "
855 0 : << "return " << comphelpernamespace << "::_getImplementationName();\n}\n\n";
856 :
857 0 : o << "::sal_Bool SAL_CALL " << classname
858 0 : << "supportsService(::rtl::OUString const & "
859 0 : << "serviceName) throw (css::uno::RuntimeException)\n{\n "
860 0 : << "css::uno::Sequence< ::rtl::OUString > serviceNames = "
861 0 : << comphelpernamespace << "::_getSupportedServiceNames();\n "
862 0 : << "for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {\n "
863 0 : << " if (serviceNames[i] == serviceName)\n return sal_True;\n"
864 0 : << " }\n return sal_False;\n}\n\n";
865 :
866 0 : o << "css::uno::Sequence< ::rtl::OUString > SAL_CALL " << classname
867 0 : << "getSupportedServiceNames() throw (css::uno::RuntimeException)\n{\n "
868 0 : << "return " << comphelpernamespace
869 0 : << "::_getSupportedServiceNames();\n}\n\n";
870 0 : }
871 :
872 :
873 0 : void generateMethodBodies(std::ostream& o,
874 : ProgramOptions const & options,
875 : rtl::Reference< TypeManager > const & manager,
876 : std::set< OUString > const & interfaces,
877 : OString const & classname,
878 : OString const & comphelpernamespace,
879 : OUString const & propertyhelper)
880 : {
881 0 : OString name(classname.concat("::"));
882 0 : std::set< OUString >::const_iterator iter = interfaces.begin();
883 0 : codemaker::GeneratedTypeSet generated;
884 0 : while (iter != interfaces.end()) {
885 0 : if ( (*iter).equals("com.sun.star.lang.XServiceInfo") ) {
886 0 : generateXServiceInfoBodies(o, name, comphelpernamespace);
887 0 : generated.add(u2b(*iter));
888 : } else {
889 0 : printMethods(o, options, manager, *iter, generated, "_",
890 0 : name, "", true, propertyhelper);
891 : }
892 0 : ++iter;
893 0 : }
894 0 : }
895 :
896 0 : void generateQueryInterface(std::ostream& o,
897 : ProgramOptions const & options,
898 : rtl::Reference< TypeManager > const & manager,
899 : const std::set< OUString >& interfaces,
900 : OString const & parentname,
901 : OString const & classname,
902 : OUString const & propertyhelper)
903 : {
904 0 : if (propertyhelper.isEmpty())
905 0 : return;
906 :
907 0 : o << "css::uno::Any " << classname
908 : << "::queryInterface(css::uno::Type const & type) throw ("
909 0 : "css::uno::RuntimeException)\n{\n ";
910 :
911 0 : if (!propertyhelper.isEmpty())
912 0 : o << "return ";
913 : else
914 0 : o << "css::uno::Any a(";
915 :
916 0 : o << parentname << "<";
917 0 : std::set< OUString >::const_iterator iter = interfaces.begin();
918 0 : while (iter != interfaces.end())
919 : {
920 0 : o << "\n " << scopedCppName(u2b(*iter));
921 0 : ++iter;
922 0 : if (iter != interfaces.end())
923 0 : o << ",";
924 : else
925 0 : o << ">";
926 : }
927 :
928 0 : if (!propertyhelper.isEmpty()) {
929 0 : o << "::queryInterface(type);\n";
930 : } else {
931 0 : o << "::queryInterface(type));\n";
932 0 : o << " return a.hasValue() ? a\n : (";
933 0 : if (propertyhelper.equals("_")) {
934 0 : o << "::cppu::OPropertySetHelper::queryInterface(type));\n";
935 : } else {
936 0 : o << "::cppu::PropertySetMixin<\n ";
937 0 : printType(o, options, manager, propertyhelper, 0, false);
938 0 : o << " >::queryInterface(\n type));\n";
939 : }
940 : }
941 0 : o << "}\n\n";
942 : }
943 :
944 0 : void generateSkeleton(ProgramOptions const & options,
945 : rtl::Reference< TypeManager > const & manager,
946 : std::vector< OString > const & types)
947 : {
948 : // special handling of calc add-ins
949 0 : if (options.componenttype == 2) {
950 0 : generateCalcAddin(options, manager, types);
951 0 : return;
952 : }
953 :
954 0 : std::set< OUString > interfaces;
955 0 : std::set< OUString > services;
956 0 : AttributeInfo properties;
957 0 : AttributeInfo attributes;
958 0 : std::set< OUString > propinterfaces;
959 0 : bool serviceobject = false;
960 0 : bool supportxcomponent = false;
961 :
962 0 : std::vector< OString >::const_iterator iter = types.begin();
963 0 : while (iter != types.end()) {
964 0 : checkType(manager, b2u(*iter), interfaces, services, properties);
965 0 : ++iter;
966 : }
967 :
968 0 : if (options.componenttype == 3) {
969 : // the Protocolhandler service is mandatory for an protocol handler add-on,
970 : // so it is defaulted. The XDispatchProvider provides Dispatch objects for
971 : // certain functions and the generated impl object implements XDispatch
972 : // directly for simplicity reasons.
973 : checkType(manager, "com.sun.star.frame.ProtocolHandler",
974 0 : interfaces, services, properties);
975 : checkType(manager, "com.sun.star.frame.XDispatch",
976 0 : interfaces, services, properties);
977 : }
978 :
979 : // check if service object or simple UNO object
980 0 : if (!services.empty())
981 0 : serviceobject = true;
982 :
983 : OUString propertyhelper = checkPropertyHelper(
984 0 : options, manager, services, interfaces, attributes, propinterfaces);
985 :
986 0 : checkDefaultInterfaces(interfaces, services, propertyhelper);
987 :
988 0 : if (interfaces.size() > 12)
989 : throw CannotDumpException(
990 : "the skeletonmaker supports components with 12 interfaces "
991 0 : "only (limitation of the UNO implementation helpers)!");
992 :
993 :
994 0 : supportxcomponent = checkXComponentSupport(manager, interfaces);
995 :
996 0 : OString compFileName;
997 0 : OString tmpFileName;
998 0 : std::ostream* pofs = NULL;
999 : bool standardout = getOutputStream(options, ".cxx",
1000 0 : &pofs, compFileName, tmpFileName);
1001 :
1002 : try {
1003 0 : if (!standardout && options.license) {
1004 0 : printLicenseHeader(*pofs, compFileName);
1005 : }
1006 :
1007 : generateIncludes(*pofs, interfaces, propertyhelper, serviceobject,
1008 0 : supportxcomponent);
1009 :
1010 0 : if (options.componenttype == 3) {
1011 0 : *pofs << "#include \"com/sun/star/frame/XFrame.hpp\"\n";
1012 : }
1013 :
1014 : // namespace
1015 0 : OString nmspace;
1016 0 : short nm = 0;
1017 :
1018 0 : if (serviceobject) {
1019 0 : nmspace = generateCompHelperDeclaration(*pofs, options.implname);
1020 :
1021 : *pofs <<
1022 : "\n\n/// anonymous implementation namespace\nnamespace {\n\n"
1023 0 : "namespace css = ::com::sun::star;\n\n";
1024 : } else {
1025 0 : nm = generateNamespace(*pofs, options.implname, false, nmspace);
1026 0 : *pofs << "namespace css = ::com::sun::star;\n\n";
1027 : }
1028 :
1029 0 : sal_Int32 index = 0;
1030 0 : OString classname(options.implname);
1031 0 : if ((index = classname.lastIndexOf('.')) > 0)
1032 0 : classname = classname.copy(index+1);
1033 :
1034 : OString parentname(
1035 : generateClassDefinition(*pofs,
1036 : options, manager, classname, interfaces, properties,
1037 0 : attributes, propinterfaces, propertyhelper, supportxcomponent));
1038 :
1039 : generateQueryInterface(*pofs, options, manager, interfaces, parentname,
1040 0 : classname, propertyhelper);
1041 :
1042 : generateMethodBodies(*pofs, options, manager, interfaces, classname,
1043 0 : nmspace, propertyhelper);
1044 :
1045 0 : if (serviceobject) {
1046 : // close namepsace
1047 0 : *pofs << "} // closing anonymous implementation namespace\n\n";
1048 :
1049 : generateCompHelperDefinition(*pofs, options.implname,
1050 0 : classname, services);
1051 0 : generateCompFunctions(*pofs, nmspace);
1052 : } else {
1053 : // close namepsace
1054 0 : for (short i=0; i < nm; i++)
1055 0 : *pofs << "} ";
1056 0 : *pofs << (nm > 0 ? "// closing namespace\n\n" : "\n");
1057 : }
1058 :
1059 0 : if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
1060 0 : ((std::ofstream*)pofs)->close();
1061 0 : delete pofs;
1062 0 : OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False));
1063 0 : }
1064 0 : } catch (CannotDumpException & e) {
1065 0 : std::cerr << "ERROR: " << e.getMessage() << "\n";
1066 0 : if ( !standardout ) {
1067 0 : if (pofs && ((std::ofstream*)pofs)->is_open()) {
1068 0 : ((std::ofstream*)pofs)->close();
1069 0 : delete pofs;
1070 : }
1071 : // remove existing type file if something goes wrong to ensure
1072 : // consistency
1073 0 : if (fileExists(compFileName))
1074 0 : removeTypeFile(compFileName);
1075 :
1076 : // remove tmp file if something goes wrong
1077 0 : removeTypeFile(tmpFileName);
1078 : }
1079 0 : }
1080 : }
1081 :
1082 0 : void generateCalcAddin(ProgramOptions const & options,
1083 : rtl::Reference< TypeManager > const & manager,
1084 : std::vector< OString > const & types)
1085 : {
1086 0 : std::set< OUString > interfaces;
1087 0 : std::set< OUString > services;
1088 0 : AttributeInfo properties;
1089 0 : AttributeInfo attributes;
1090 0 : std::set< OUString > propinterfaces;
1091 0 : bool serviceobject = false;
1092 0 : bool supportxcomponent = false;
1093 :
1094 :
1095 0 : std::vector< OString >::const_iterator iter = types.begin();
1096 0 : while (iter != types.end()) {
1097 0 : checkType(manager, b2u(*iter), interfaces, services, properties);
1098 0 : ++iter;
1099 : }
1100 :
1101 0 : OUString sAddinService;
1102 0 : if (services.size() != 1) {
1103 : throw CannotDumpException(
1104 : "for calc add-in components one and only one service type is necessary!"
1105 0 : " Please reference a valid type with the '-t' option.");
1106 : }
1107 :
1108 :
1109 : // get the one and only add-in service for later use
1110 0 : std::set< OUString >::const_iterator iter2 = services.begin();
1111 0 : sAddinService = *iter2;
1112 0 : if (sAddinService.equals("com.sun.star.sheet.AddIn")) {
1113 0 : sAddinService = *(++iter2);
1114 : }
1115 :
1116 : // if backwardcompatible==true the AddIn service needs to be added to the
1117 : // suported service list, the necessary intefaces are mapped to the add-in
1118 : // configuration. Since OO.org 2.0.4 this is obsolete and the add-in is
1119 : // take form the configuration from Calc directly, this simplifies the
1120 : // add-in code
1121 0 : if (options.backwardcompatible) {
1122 : checkType(manager, "com.sun.star.sheet.AddIn",
1123 0 : interfaces, services, properties);
1124 : } else {
1125 : // special case for the optional XLocalization interface. It should be
1126 : // implemented always. But it is parent of the XAddIn and we need it only
1127 : // if backwardcompatible is false.
1128 0 : if (interfaces.find("com.sun.star.lang.XLocalizable") == interfaces.end()) {
1129 0 : interfaces.insert("com.sun.star.lang.XLocalizable");
1130 : }
1131 : }
1132 :
1133 : OUString propertyhelper = checkPropertyHelper(
1134 0 : options, manager, services, interfaces, attributes, propinterfaces);
1135 :
1136 0 : if (!propertyhelper.isEmpty())
1137 : std::cerr << "WARNING: interfaces specifying calc add-in functions "
1138 0 : "shouldn't support attributes!\n";
1139 :
1140 0 : checkDefaultInterfaces(interfaces, services, propertyhelper);
1141 :
1142 0 : if (interfaces.size() > 12) {
1143 : throw CannotDumpException(
1144 : "the skeletonmaker supports components with 12 interfaces "
1145 0 : "only (limitation of the UNO implementation helpers)!");
1146 : }
1147 :
1148 : // check if service object or simple UNO object
1149 0 : if (!services.empty())
1150 0 : serviceobject = true;
1151 :
1152 0 : supportxcomponent = checkXComponentSupport(manager, interfaces);
1153 0 : if (supportxcomponent)
1154 : std::cerr << "WARNING: add-ins shouldn't support "
1155 0 : "com.sun.star.uno.XComponent!\n";
1156 :
1157 0 : OString compFileName;
1158 0 : OString tmpFileName;
1159 0 : std::ostream* pofs = NULL;
1160 : bool standardout = getOutputStream(options, ".cxx",
1161 0 : &pofs, compFileName, tmpFileName);
1162 :
1163 : try {
1164 0 : if (!standardout && options.license) {
1165 0 : printLicenseHeader(*pofs, compFileName);
1166 : }
1167 :
1168 : generateIncludes(*pofs, interfaces, propertyhelper, serviceobject,
1169 0 : supportxcomponent);
1170 :
1171 : *pofs <<
1172 : "#include \"com/sun/star/beans/PropertyValue.hpp\"\n"
1173 : "#include \"com/sun/star/beans/XPropertySet.hpp\"\n"
1174 : "#include \"com/sun/star/container/XNameAccess.hpp\"\n"
1175 : "#include \"com/sun/star/container/XHierarchicalNameAccess.hpp\"\n\n"
1176 : "#include \"rtl/ustrbuf.hxx\"\n\n"
1177 : "#include <boost/unordered_map.hpp>\n"
1178 0 : "#include <set>\n";
1179 :
1180 : // namespace
1181 0 : OString nmspace(generateCompHelperDeclaration(*pofs, options.implname));
1182 :
1183 : *pofs <<
1184 : "\n\n// anonymous implementation namespace\nnamespace {\n\n"
1185 0 : "namespace css = ::com::sun::star;\n\n";
1186 :
1187 0 : sal_Int32 index = 0;
1188 0 : OString classname(options.implname);
1189 0 : if ((index = classname.lastIndexOf('.')) > 0) {
1190 0 : classname = classname.copy(index+1);
1191 : }
1192 :
1193 0 : if (options.backwardcompatible) {
1194 0 : *pofs << "static const char * sADDIN_SERVICENAME = \""
1195 0 : << sAddinService << "\";\n\n";
1196 : *pofs << "static const char * sDISPLAYNAME = \"DisplayName\";\n"
1197 : "static const char * sDESCRIPTION = \"Description\";\n"
1198 : "static const char * sCATEGORY = \"Category\";\n"
1199 : "static const char * sCATEGORYDISPLAYNAME = \"CategoryDisplayName\";"
1200 0 : "\n\n";
1201 : }
1202 :
1203 : OString parentname(
1204 : generateClassDefinition(*pofs,
1205 : options, manager, classname, interfaces, properties,
1206 0 : attributes, propinterfaces, propertyhelper, supportxcomponent));
1207 :
1208 : generateQueryInterface(*pofs, options, manager, interfaces, parentname,
1209 0 : classname, propertyhelper);
1210 :
1211 : generateMethodBodies(*pofs, options, manager, interfaces, classname,
1212 0 : nmspace, propertyhelper);
1213 :
1214 : // close namepsace
1215 0 : *pofs << "} // closing anonymous implementation namespace\n\n";
1216 :
1217 : generateCompHelperDefinition(*pofs, options.implname, classname,
1218 0 : services);
1219 :
1220 0 : generateCompFunctions(*pofs, nmspace);
1221 :
1222 0 : if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
1223 0 : ((std::ofstream*)pofs)->close();
1224 0 : delete pofs;
1225 0 : OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False));
1226 0 : }
1227 0 : } catch (CannotDumpException & e) {
1228 0 : std::cerr << "ERROR: " << e.getMessage() << "\n";
1229 0 : if ( !standardout ) {
1230 0 : if (pofs && ((std::ofstream*)pofs)->is_open()) {
1231 0 : ((std::ofstream*)pofs)->close();
1232 0 : delete pofs;
1233 : }
1234 : // remove existing type file if something goes wrong to ensure
1235 : // consistency
1236 0 : if (fileExists(compFileName))
1237 0 : removeTypeFile(compFileName);
1238 :
1239 : // remove tmp file if something goes wrong
1240 0 : removeTypeFile(tmpFileName);
1241 : }
1242 0 : }
1243 0 : }
1244 :
1245 0 : } }
1246 :
1247 :
1248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|