/src/libreoffice/include/vbahelper/vbaaccesshelper.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | #ifndef INCLUDED_VBAHELPER_VBAACCESSHELPER_HXX |
20 | | #define INCLUDED_VBAHELPER_VBAACCESSHELPER_HXX |
21 | | |
22 | | #include <memory> |
23 | | |
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/Reference.hxx> |
29 | | #include <com/sun/star/uno/Sequence.hxx> |
30 | | #include <com/sun/star/uno/XInterface.hpp> |
31 | | #include <osl/diagnose.h> |
32 | | //#define VBAHELPER_DLLIMPLEMENTATION |
33 | | #include <rtl/ustring.hxx> |
34 | | #include <sfx2/objsh.hxx> |
35 | | #include <sfx2/docfilt.hxx> |
36 | | #include <sfx2/docfile.hxx> |
37 | | |
38 | | namespace ooo::vba |
39 | | { |
40 | | |
41 | | inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell const * pShell ) |
42 | 0 | { |
43 | 0 | css::uno::Any aUnoVar; |
44 | 0 | if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( u"VBAGlobals"_ustr, aUnoVar ) ) |
45 | 0 | throw css::lang::IllegalArgumentException(); |
46 | 0 | css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW ); |
47 | 0 | return xVBAFactory; |
48 | 0 | } |
49 | | |
50 | | /// @throws css::uno::Exception |
51 | | inline css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell const * pShell, const char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) |
52 | 0 | { |
53 | 0 | OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); |
54 | 0 | OUString sVarName( OUString::createFromAscii( _pAsciiName ) ); |
55 | 0 | css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs ); |
56 | 0 | return xIf; |
57 | 0 | } |
58 | | |
59 | | |
60 | | inline bool isAlienDoc( SfxObjectShell const & rDocShell, const char* pMimeType ) |
61 | 0 | { |
62 | 0 | bool bRes( false ); |
63 | 0 | const SfxMedium *pMedium = rDocShell.GetMedium(); |
64 | 0 | std::shared_ptr<const SfxFilter> pFilt = pMedium ? pMedium->GetFilter() : nullptr; |
65 | 0 | if ( pFilt && pFilt->IsAlienFormat() ) |
66 | 0 | bRes = pFilt->GetMimeType().equalsAscii( pMimeType ); |
67 | 0 | return bRes; |
68 | 0 | } |
69 | 0 | inline bool isAlienExcelDoc( SfxObjectShell const & rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); } |
70 | | //VBAHELPER_DLLPRIVATE inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); } |
71 | | // word seems to return an erroneous mime type :-/ "application/msword" not consistent with the excel one |
72 | 0 | inline bool isAlienWordDoc( SfxObjectShell const & rDocShell ) { return isAlienDoc( rDocShell, "application/msword" ); } |
73 | | |
74 | | } |
75 | | |
76 | | #endif |
77 | | |
78 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |