Line data Source code
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 <com/sun/star/beans/XPropertySet.hpp>
23 : #include <basic/basmgr.hxx>
24 : #include <sfx2/objsh.hxx>
25 : #include <sfx2/docfilt.hxx>
26 : #include <sfx2/docfile.hxx>
27 : //#define VBAHELPER_DLLIMPLEMENTATION
28 : #include <vbahelper/vbadllapi.h>
29 : #include <memory>
30 :
31 : namespace ooo
32 : {
33 : namespace vba
34 : {
35 :
36 34272 : VBAHELPER_DLLPRIVATE inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell )
37 : {
38 34272 : css::uno::Any aUnoVar;
39 34272 : if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) )
40 32355 : throw css::lang::IllegalArgumentException();
41 1916 : css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW );
42 34272 : return xVBAFactory;
43 : }
44 :
45 34272 : VBAHELPER_DLLPRIVATE 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)
46 : {
47 : OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" );
48 34272 : OUString sVarName( OUString::createFromAscii( _pAsciiName ) );
49 34272 : css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs );
50 34272 : return xIf;
51 : }
52 :
53 :
54 179326 : VBAHELPER_DLLPRIVATE inline bool isAlienDoc( SfxObjectShell& rDocShell, const char* pMimeType )
55 : {
56 179326 : bool bRes( false );
57 179326 : const SfxMedium *pMedium = rDocShell.GetMedium();
58 179326 : const SfxFilter *pFilt = pMedium ? pMedium->GetFilter() : NULL;
59 179326 : if ( pFilt && pFilt->IsAlienFormat() )
60 43154 : bRes = pFilt->GetMimeType().equalsAscii( pMimeType );
61 179326 : return bRes;
62 : }
63 58 : VBAHELPER_DLLPRIVATE inline bool isAlienExcelDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); }
64 : //VBAHELPER_DLLPRIVATE inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); }
65 : // word seems to return an erroneous mime type :-/ "application/msword" not consistent with the excel one
66 179268 : VBAHELPER_DLLPRIVATE inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/msword" ); }
67 :
68 : } // openoffice
69 : } // org
70 :
71 : #endif
72 :
73 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|