android: Update app-specific/MIME type icons
[LibreOffice.git] / filter / source / msfilter / svxmsbas2.cxx
blob8a4ce43f19140cd207f0ce64fba4534f3d7741cb
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 .
20 #include <config_features.h>
22 #include <basic/basmgr.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sot/storage.hxx>
25 #include <svx/svxerr.hxx>
26 #include <filter/msfilter/svxmsbas.hxx>
28 using namespace com::sun::star;
30 ErrCode SvxImportMSVBasic::SaveOrDelMSVBAStorage( bool bSaveInto,
31 const OUString& rStorageName )
33 ErrCode nRet = ERRCODE_NONE;
34 uno::Reference < embed::XStorage > xSrcRoot( rDocSh.GetStorage() );
35 OUString aDstStgName( GetMSBasicStorageName() );
36 tools::SvRef<SotStorage> xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, aDstStgName,
37 StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYALL ) );
38 if( xVBAStg.is() && !xVBAStg->GetError() )
40 xVBAStg = nullptr;
41 if( bSaveInto )
43 #if HAVE_FEATURE_SCRIPTING
44 BasicManager *pBasicMan = rDocSh.GetBasicManager();
45 if( pBasicMan && pBasicMan->IsBasicModified() )
46 nRet = ERRCODE_SVX_MODIFIED_VBASIC_STORAGE;
47 #endif
48 tools::SvRef<SotStorage> xSrc = SotStorage::OpenOLEStorage( xSrcRoot, aDstStgName, StreamMode::STD_READ );
49 tools::SvRef<SotStorage> xDst = xRoot->OpenSotStorage( rStorageName, StreamMode::READWRITE | StreamMode::TRUNC );
50 xSrc->CopyTo( xDst.get() );
51 xDst->Commit();
52 ErrCode nError = xDst->GetError();
53 if ( nError == ERRCODE_NONE )
54 nError = xSrc->GetError();
55 if ( nError != ERRCODE_NONE )
56 xRoot->SetError( nError );
60 return nRet;
63 // check if the MS-VBA-Storage exists in the RootStorage of the DocShell.
64 // If it exists, then return the WarningId for losing the information.
65 ErrCode SvxImportMSVBasic::GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocSh)
67 uno::Reference < embed::XStorage > xSrcRoot( rDocSh.GetStorage() );
68 tools::SvRef<SotStorage> xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, GetMSBasicStorageName(),
69 StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYALL ));
70 return ( xVBAStg.is() && !xVBAStg->GetError() )
71 ? ERRCODE_SVX_VBASIC_STORAGE_EXIST
72 : ERRCODE_NONE;
75 OUString SvxImportMSVBasic::GetMSBasicStorageName()
77 return "_MS_VBA_Macros";
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */