Fix rudimentary Emscripten Qt6 copy -> paste support
[LibreOffice.git] / include / vbahelper / vbaaccesshelper.hxx
blobcf163e90ac45a354609b1d30f2b50868f0629da6
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/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>
38 namespace ooo::vba
41 inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell const * pShell )
43 css::uno::Any aUnoVar;
44 if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( u"VBAGlobals"_ustr, aUnoVar ) )
45 throw css::lang::IllegalArgumentException();
46 css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW );
47 return xVBAFactory;
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 )
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;
60 inline bool isAlienDoc( SfxObjectShell const & rDocShell, const char* pMimeType )
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;
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" ); }
76 #endif
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */