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