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 #ifndef _MSVBAHELPER_HXX
24 #define _MSVBAHELPER_HXX
25 
26 #include <sfx2/objsh.hxx>
27 #include <cppuhelper/implbase3.hxx>
28 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/script/vba/XVBAMacroResolver.hpp>
31 #include "filter/msfilter/msfilterdllapi.h"
32 
33 namespace ooo {
34 namespace vba {
35 
36 // ============================================================================
37 
38 struct MSFILTER_DLLPUBLIC MacroResolvedInfo
39 {
40     SfxObjectShell*     mpDocContext;
41     String              msResolvedMacro;
42     bool                mbFound;
43 
MacroResolvedInfoooo::vba::MacroResolvedInfo44     inline explicit MacroResolvedInfo( SfxObjectShell* pDocContext = 0 ) : mpDocContext( pDocContext ), mbFound( false ) {}
45 };
46 
47 MSFILTER_DLLPUBLIC String makeMacroURL( const String& sMacroName );
48 MSFILTER_DLLPUBLIC ::rtl::OUString extractMacroName( const ::rtl::OUString& rMacroUrl );
49 MSFILTER_DLLPUBLIC ::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell );
50 MSFILTER_DLLPUBLIC ::rtl::OUString resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rLibName, const ::rtl::OUString& rModuleName, const ::rtl::OUString& rMacroName );
51 MSFILTER_DLLPUBLIC MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rMacroName, bool bSearchGlobalTemplates = false );
52 MSFILTER_DLLPUBLIC sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArgs, com::sun::star::uno::Any& aRet, const com::sun::star::uno::Any& aCaller );
53 
54 // ============================================================================
55 
56 typedef ::cppu::WeakImplHelper3<
57     ::com::sun::star::lang::XServiceInfo,
58     ::com::sun::star::lang::XInitialization,
59     ::com::sun::star::script::vba::XVBAMacroResolver > VBAMacroResolverBase;
60 
61 class VBAMacroResolver : public VBAMacroResolverBase
62 {
63 public:
64     explicit            VBAMacroResolver();
65     virtual             ~VBAMacroResolver();
66 
67     // com.sun.star.lang.XServiceInfo interface -------------------------------
68 
69     virtual ::rtl::OUString SAL_CALL
70                         getImplementationName() throw (::com::sun::star::uno::RuntimeException);
71 
72     virtual sal_Bool SAL_CALL
73                         supportsService( const ::rtl::OUString& rService )
74                             throw (::com::sun::star::uno::RuntimeException);
75 
76     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
77                         getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException);
78 
79     // com.sun.star.lang.XInitialization interface ----------------------------
80 
81     virtual void SAL_CALL initialize(
82                             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArgs )
83                             throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
84 
85     // com.sun.star.script.vba.XVBAMacroResolver interface --------------------
86 
87     virtual ::rtl::OUString SAL_CALL
88                         resolveVBAMacroToScriptURL( const ::rtl::OUString& rVBAMacroName )
89                             throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
90 
91     virtual ::rtl::OUString SAL_CALL
92                         resolveScriptURLtoVBAMacro( const ::rtl::OUString& rScriptURL )
93                             throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
94 
95 private:
96     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxModel;
97     SfxObjectShell*     mpObjShell;
98     ::rtl::OUString     maProjectName;
99 };
100 
101 // ============================================================================
102 
103 } // namespace vba
104 } // namespace ooo
105 
106 #endif
107