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 0 : VBAHELPER_DLLPRIVATE inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell )
37 : {
38 0 : css::uno::Any aUnoVar;
39 0 : if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) )
40 0 : throw css::lang::IllegalArgumentException();
41 0 : css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW );
42 0 : return xVBAFactory;
43 : }
44 :
45 0 : 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 0 : OUString sVarName( OUString::createFromAscii( _pAsciiName ) );
49 0 : css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs );
50 0 : return xIf;
51 : }
52 :
53 :
54 0 : VBAHELPER_DLLPRIVATE inline bool isAlienDoc( SfxObjectShell& rDocShell, const char* pMimeType )
55 : {
56 0 : bool bRes( false );
57 0 : const SfxMedium *pMedium = rDocShell.GetMedium();
58 0 : const SfxFilter *pFilt = pMedium ? pMedium->GetFilter() : NULL;
59 0 : if ( pFilt && pFilt->IsAlienFormat() )
60 0 : bRes = ( pFilt->GetMimeType().compareToAscii( pMimeType ) == 0 );
61 0 : return bRes;
62 : }
63 0 : 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 0 : 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: */
|