1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include "vbaaddin.hxx"
24 #include <vbahelper/vbahelper.hxx>
25 #include <tools/diagnose_ex.h>
26 #include <tools/urlobj.hxx>
27 #include <osl/file.hxx>
28
29 using namespace ::ooo::vba;
30 using namespace ::com::sun::star;
31
SwVbaAddin(const uno::Reference<ooo::vba::XHelperInterface> & rParent,const uno::Reference<uno::XComponentContext> & rContext,const rtl::OUString & rFileURL,sal_Bool bAutoload)32 SwVbaAddin::SwVbaAddin( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const rtl::OUString& rFileURL, sal_Bool bAutoload ) throw ( uno::RuntimeException ) :
33 SwVbaAddin_BASE( rParent, rContext ), msFileURL( rFileURL ), mbAutoload( bAutoload ), mbInstalled( bAutoload )
34 {
35 }
36
~SwVbaAddin()37 SwVbaAddin::~SwVbaAddin()
38 {
39 }
40
getName()41 ::rtl::OUString SAL_CALL SwVbaAddin::getName() throw (uno::RuntimeException)
42 {
43 rtl::OUString sName;
44 INetURLObject aURL( msFileURL );
45 ::osl::File::getSystemPathFromFileURL( aURL.GetLastName(), sName );
46 return sName;
47 }
48
49 void SAL_CALL
setName(const rtl::OUString &)50 SwVbaAddin::setName( const rtl::OUString& ) throw ( css::uno::RuntimeException )
51 {
52 throw uno::RuntimeException( rtl::OUString(
53 RTL_CONSTASCII_USTRINGPARAM(" Fail to set name")), uno::Reference< uno::XInterface >() );
54 }
55
getPath()56 ::rtl::OUString SAL_CALL SwVbaAddin::getPath() throw (uno::RuntimeException)
57 {
58 INetURLObject aURL( msFileURL );
59 aURL.CutLastName();
60 return aURL.GetURLPath();
61 }
62
getAutoload()63 ::sal_Bool SAL_CALL SwVbaAddin::getAutoload() throw (uno::RuntimeException)
64 {
65 return mbAutoload;
66 }
67
getInstalled()68 ::sal_Bool SAL_CALL SwVbaAddin::getInstalled() throw (uno::RuntimeException)
69 {
70 return mbInstalled;
71 }
72
setInstalled(::sal_Bool _installed)73 void SAL_CALL SwVbaAddin::setInstalled( ::sal_Bool _installed ) throw (uno::RuntimeException)
74 {
75 if( _installed != mbInstalled )
76 {
77 mbInstalled = _installed;
78 // TODO: should call AutoExec and AutoExit etc.
79 }
80 }
81
82 rtl::OUString&
getServiceImplName()83 SwVbaAddin::getServiceImplName()
84 {
85 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAddin") );
86 return sImplName;
87 }
88
89 uno::Sequence< rtl::OUString >
getServiceNames()90 SwVbaAddin::getServiceNames()
91 {
92 static uno::Sequence< rtl::OUString > aServiceNames;
93 if ( aServiceNames.getLength() == 0 )
94 {
95 aServiceNames.realloc( 1 );
96 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Addin" ) );
97 }
98 return aServiceNames;
99 }
100
101