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 OOVBAAPI_VBA_ACCESS_HELPER_HXX
24 #define OOVBAAPI_VBA_ACCESS_HELPER_HXX
25 
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <basic/basmgr.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/docfile.hxx>
31 //#define VBAHELPER_DLLIMPLEMENTATION
32 #include <vbahelper/vbadllapi.h>
33 #include <memory>
34 namespace css = ::com::sun::star;
35 namespace ooo
36 {
37 	namespace vba
38 	{
39 
getVBAServiceFactory(SfxObjectShell * pShell)40         VBAHELPER_DLLPRIVATE inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell )
41         {
42             css::uno::Any aUnoVar;
43             if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) )
44                 throw css::lang::IllegalArgumentException();
45             css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW );
46             return xVBAFactory;
47         }
48 
createVBAUnoAPIServiceWithArgs(SfxObjectShell * pShell,const sal_Char * _pAsciiName,const css::uno::Sequence<css::uno::Any> & aArgs)49         VBAHELPER_DLLPUBLIC inline css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell,  const sal_Char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException)
50         {
51             OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" );
52             ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
53             css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs  );
54             return xIf;
55         }
56 
57 
isAlienDoc(SfxObjectShell & rDocShell,const char * pMimeType)58         VBAHELPER_DLLPRIVATE inline bool isAlienDoc( SfxObjectShell& rDocShell, const char* pMimeType )
59         {
60             bool bRes( false );
61             const SfxFilter *pFilt = rDocShell.GetMedium()->GetFilter();
62             if ( pFilt && pFilt->IsAlienFormat() )
63                 bRes = ( pFilt->GetMimeType().CompareToAscii( pMimeType ) == 0 );
64             return bRes;
65         }
isAlienExcelDoc(SfxObjectShell & rDocShell)66         VBAHELPER_DLLPUBLIC inline bool isAlienExcelDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); }
isAlienWordDoc(SfxObjectShell & rDocShell)67         VBAHELPER_DLLPUBLIC inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); }
68 
69 	} // openoffice
70 } // org
71 
72 #endif
73