1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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>
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
);
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
);
64 inline bool isAlienDoc( SfxObjectShell
& rDocShell
, const char* pMimeType
)
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
);
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" ); }
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */