update dev300-m58
[ooovba.git] / sw / source / ui / vba / vbaaddins.cxx
blob17dbed8f95e2d2aefefe694d7278b8f88f0e73be
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile:
10 * $Revision:
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbaaddins.hxx"
31 #include "vbaaddin.hxx"
32 #include <cppuhelper/implbase3.hxx>
33 #include <svtools/pathoptions.hxx>
34 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
35 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
37 using namespace ::ooo::vba;
38 using namespace ::com::sun::star;
40 uno::Reference< container::XIndexAccess > lcl_getAddinCollection( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext )
42 XNamedObjectCollectionHelper< word::XAddin >::XNamedVec maAddins;
44 // first get the autoload addins in the directory STARTUP
45 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager(), uno::UNO_QUERY_THROW );
46 uno::Reference< ucb::XSimpleFileAccess > xSFA( xMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), xContext), uno::UNO_QUERY_THROW );
47 SvtPathOptions aPathOpt;
48 // FIXME: temporary the STARTUP path is located in $OO/basic3.1/program/addin
49 String aAddinPath = aPathOpt.GetAddinPath();
50 OSL_TRACE("lcl_getAddinCollection: %s", rtl::OUStringToOString( aAddinPath, RTL_TEXTENCODING_UTF8 ).getStr() );
51 if( xSFA->isFolder( aAddinPath ) )
53 uno::Sequence< rtl::OUString > sEntries = xSFA->getFolderContents( aAddinPath, sal_False );
54 sal_Int32 nEntry = sEntries.getLength();
55 for( sal_Int32 index = 0; index < nEntry; ++index )
57 rtl::OUString sUrl = sEntries[ index ];
58 if( !xSFA->isFolder( sUrl ) && sUrl.endsWithIgnoreAsciiCaseAsciiL( ".dot", 4 ) )
60 maAddins.push_back( uno::Reference< word::XAddin >( new SwVbaAddin( xParent, xContext, sUrl, sal_True ) ) );
65 // TODO: second get the customize addins in the org.openoffice.Office.Writer/GlobalTemplateList
67 uno::Reference< container::XIndexAccess > xAddinsAccess( new XNamedObjectCollectionHelper< word::XAddin >( maAddins ) );
68 return xAddinsAccess;
71 SwVbaAddins::SwVbaAddins( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext ) throw (uno::RuntimeException): SwVbaAddins_BASE( xParent, xContext, lcl_getAddinCollection( xParent,xContext ) )
74 // XEnumerationAccess
75 uno::Type
76 SwVbaAddins::getElementType() throw (uno::RuntimeException)
78 return word::XAddin::static_type(0);
80 uno::Reference< container::XEnumeration >
81 SwVbaAddins::createEnumeration() throw (uno::RuntimeException)
83 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
84 return xEnumerationAccess->createEnumeration();
87 uno::Any
88 SwVbaAddins::createCollectionObject( const css::uno::Any& aSource )
90 return aSource;
93 rtl::OUString&
94 SwVbaAddins::getServiceImplName()
96 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAddins") );
97 return sImplName;
100 css::uno::Sequence<rtl::OUString>
101 SwVbaAddins::getServiceNames()
103 static uno::Sequence< rtl::OUString > sNames;
104 if ( sNames.getLength() == 0 )
106 sNames.realloc( 1 );
107 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Addins") );
109 return sNames;