1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <basic/basmgr.hxx>
22 #include <sfx2/objsh.hxx>
23 #include <svx/svxerr.hxx>
24 #include <filter/msfilter/svxmsbas.hxx>
26 using namespace com::sun::star
;
28 sal_uLong
SvxImportMSVBasic::SaveOrDelMSVBAStorage( sal_Bool bSaveInto
,
29 const OUString
& rStorageName
)
31 sal_uLong nRet
= ERRCODE_NONE
;
32 uno::Reference
< embed::XStorage
> xSrcRoot( rDocSh
.GetStorage() );
33 OUString
aDstStgName( GetMSBasicStorageName() );
34 SotStorageRef
xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot
, aDstStgName
,
35 STREAM_READWRITE
| STREAM_NOCREATE
| STREAM_SHARE_DENYALL
) );
36 if( xVBAStg
.Is() && !xVBAStg
->GetError() )
41 #ifndef DISABLE_SCRIPTING
42 BasicManager
*pBasicMan
= rDocSh
.GetBasicManager();
43 if( pBasicMan
&& pBasicMan
->IsBasicModified() )
44 nRet
= ERRCODE_SVX_MODIFIED_VBASIC_STORAGE
;
46 SotStorageRef xSrc
= SotStorage::OpenOLEStorage( xSrcRoot
, aDstStgName
, STREAM_STD_READ
);
47 SotStorageRef xDst
= xRoot
->OpenSotStorage( rStorageName
, STREAM_READWRITE
| STREAM_TRUNC
);
50 ErrCode nError
= xDst
->GetError();
51 if ( nError
== ERRCODE_NONE
)
52 nError
= xSrc
->GetError();
53 if ( nError
!= ERRCODE_NONE
)
54 xRoot
->SetError( nError
);
61 // check if the MS-VBA-Storage exists in the RootStorage of the DocShell.
62 // If it exists, then return the WarningId for losing the information.
63 sal_uLong
SvxImportMSVBasic::GetSaveWarningOfMSVBAStorage( SfxObjectShell
&rDocSh
)
65 uno::Reference
< embed::XStorage
> xSrcRoot( rDocSh
.GetStorage() );
66 SvStorageRef
xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot
, GetMSBasicStorageName(),
67 STREAM_READ
| STREAM_NOCREATE
| STREAM_SHARE_DENYALL
));
68 return ( xVBAStg
.Is() && !xVBAStg
->GetError() )
69 ? ERRCODE_SVX_VBASIC_STORAGE_EXIST
73 OUString
SvxImportMSVBasic::GetMSBasicStorageName()
75 return OUString( "_MS_VBA_Macros" );
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */