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