build fix
[LibreOffice.git] / include / vbahelper / vbaaccesshelper.hxx
blob6bf5d7a5eaad684cb01c5421dd46528b0e51817f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_VBAHELPER_VBAACCESSHELPER_HXX
20 #define INCLUDED_VBAHELPER_VBAACCESSHELPER_HXX
22 #include <memory>
24 #include <basic/basmgr.hxx>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Exception.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/uno/XInterface.hpp>
32 #include <osl/diagnose.h>
33 //#define VBAHELPER_DLLIMPLEMENTATION
34 #include <vbahelper/vbadllapi.h>
35 #include <rtl/ustring.hxx>
36 #include <sal/types.h>
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/docfilt.hxx>
39 #include <sfx2/docfile.hxx>
41 namespace ooo
43 namespace vba
46 inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell )
48 css::uno::Any aUnoVar;
49 if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) )
50 throw css::lang::IllegalArgumentException();
51 css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW );
52 return xVBAFactory;
55 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::Exception)
57 OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" );
58 OUString sVarName( OUString::createFromAscii( _pAsciiName ) );
59 css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs );
60 return xIf;
64 inline bool isAlienDoc( SfxObjectShell& rDocShell, const char* pMimeType )
66 bool bRes( false );
67 const SfxMedium *pMedium = rDocShell.GetMedium();
68 std::shared_ptr<const SfxFilter> pFilt = pMedium ? pMedium->GetFilter() : nullptr;
69 if ( pFilt && pFilt->IsAlienFormat() )
70 bRes = pFilt->GetMimeType().equalsAscii( pMimeType );
71 return bRes;
73 inline bool isAlienExcelDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); }
74 //VBAHELPER_DLLPRIVATE inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); }
75 // word seems to return an erroneous mime type :-/ "application/msword" not consistent with the excel one
76 inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/msword" ); }
78 } // openoffice
79 } // org
81 #endif
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */