LibreOffice Module vbahelper (master) 1
vbaaccesshelper.hxx
Go to the documentation of this file.
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
38namespace ooo::vba
39{
40
41 inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell const * pShell )
42 {
43 css::uno::Any aUnoVar;
44 if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) )
45 throw css::lang::IllegalArgumentException();
46 css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW );
47 return xVBAFactory;
48 }
49
51 inline css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell const * pShell, const char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs )
52 {
53 OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" );
54 OUString sVarName( OUString::createFromAscii( _pAsciiName ) );
55 css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs );
56 return xIf;
57 }
58
59
60 inline bool isAlienDoc( SfxObjectShell const & rDocShell, const char* pMimeType )
61 {
62 bool bRes( false );
63 const SfxMedium *pMedium = rDocShell.GetMedium();
64 std::shared_ptr<const SfxFilter> pFilt = pMedium ? pMedium->GetFilter() : nullptr;
65 if ( pFilt && pFilt->IsAlienFormat() )
66 bRes = pFilt->GetMimeType().equalsAscii( pMimeType );
67 return bRes;
68 }
69 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 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: */
bool GetGlobalUNOConstant(const OUString &rName, css::uno::Any &aOut)
const std::shared_ptr< const SfxFilter > & GetFilter() const
BasicManager * GetBasicManager() const
SfxMedium * GetMedium() const
bool isAlienWordDoc(SfxObjectShell const &rDocShell)
css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory(SfxObjectShell const *pShell)
bool isAlienExcelDoc(SfxObjectShell const &rDocShell)
css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs(SfxObjectShell const *pShell, const char *_pAsciiName, const css::uno::Sequence< css::uno::Any > &aArgs)
bool isAlienDoc(SfxObjectShell const &rDocShell, const char *pMimeType)