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