1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svxmsbas.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <basic/basmgr.hxx>
35 #include <sfx2/objsh.hxx>
37 #include <svxmsbas.hxx>
39 using namespace com::sun::star
;
41 ULONG
SvxImportMSVBasic::SaveOrDelMSVBAStorage( BOOL bSaveInto
,
42 const String
& rStorageName
)
44 ULONG nRet
= ERRCODE_NONE
;
45 uno::Reference
< embed::XStorage
> xSrcRoot( rDocSh
.GetStorage() );
46 String
aDstStgName( GetMSBasicStorageName() );
47 SotStorageRef
xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot
, aDstStgName
,
48 STREAM_READWRITE
| STREAM_NOCREATE
| STREAM_SHARE_DENYALL
) );
49 if( xVBAStg
.Is() && !xVBAStg
->GetError() )
54 BasicManager
*pBasicMan
= rDocSh
.GetBasicManager();
55 if( pBasicMan
&& pBasicMan
->IsBasicModified() )
56 nRet
= ERRCODE_SVX_MODIFIED_VBASIC_STORAGE
;
58 SotStorageRef xSrc
= SotStorage::OpenOLEStorage( xSrcRoot
, aDstStgName
, STREAM_STD_READ
);
59 SotStorageRef xDst
= xRoot
->OpenSotStorage( rStorageName
, STREAM_READWRITE
| STREAM_TRUNC
);
62 ErrCode nError
= xDst
->GetError();
63 if ( nError
== ERRCODE_NONE
)
64 nError
= xSrc
->GetError();
65 if ( nError
!= ERRCODE_NONE
)
66 xRoot
->SetError( nError
);
73 // check if the MS-VBA-Storage exists in the RootStorage of the DocShell.
74 // If it exists, then return the WarningId for losing the information.
75 ULONG
SvxImportMSVBasic::GetSaveWarningOfMSVBAStorage( SfxObjectShell
&rDocSh
)
77 uno::Reference
< embed::XStorage
> xSrcRoot( rDocSh
.GetStorage() );
78 SvStorageRef
xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot
, GetMSBasicStorageName(),
79 STREAM_READ
| STREAM_NOCREATE
| STREAM_SHARE_DENYALL
));
80 return ( xVBAStg
.Is() && !xVBAStg
->GetError() )
81 ? ERRCODE_SVX_VBASIC_STORAGE_EXIST
85 String
SvxImportMSVBasic::GetMSBasicStorageName()
87 return String( RTL_CONSTASCII_USTRINGPARAM( "_MS_VBA_Macros" ) );