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.hxx,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 ************************************************************************/
34 #include <tools/solar.h>
35 #include "svx/svxdllapi.h"
37 #include <sot/storage.hxx>
43 /* Construct with the root storage of the MS document, with bImportCode
44 * set the visual basic code will be imported into the stardocument when Import
45 * is called, with bCopyStorage set, the visual basic storage tree will be
46 * copied completely into staroffice, so that any future export to a msoffice
47 * format will retain the vba code, allowing a lossless roundtrip from
48 * msoffice to staroffice and back.
50 * Setting bAsComment to true in Import will import the visual basic as a
51 * starbasic comment. Which is currently necessary, as vb is not valid sb.
53 * Setting bStripped will remove the "Attribute" lines from the vb, msoffice
54 * does this itself when it shows the vb code in the vbeditor, so this is
55 * probably what the user expects to see when viewing the code
58 typedef std::hash_map
< sal_Int32
, String
> ObjIdToName
;
60 typedef std::map
< String
, ObjIdToName
> ControlAttributeInfo
;
64 class SVX_DLLPUBLIC SvxImportMSVBasic
66 ControlAttributeInfo m_ModuleNameToObjIdHash
;
67 void extractAttribute( const String
& rAttribute
, const String
& rModName
);
70 SvxImportMSVBasic( SfxObjectShell
&rDocS
, SotStorage
&rRoot
,
71 BOOL bImportCode
= TRUE
, BOOL bCopyStorage
= TRUE
)
72 : xRoot(&rRoot
), rDocSh(rDocS
),
73 bImport(bImportCode
), bCopy(bCopyStorage
)
75 // returns the status of import:
76 // 0 - nothing has done
77 // bit 0 = 1 -> any code is imported to the SO-Basic
78 // bit 1 = 1 -> the VBA - storage is copy to the ObjectShell storage
79 int Import( const String
& rStorageName
, const String
&rSubStorageName
,
80 BOOL bAsComment
=TRUE
, BOOL bStripped
=TRUE
);
81 int Import( const String
& rStorageName
, const String
&rSubStorageName
,
82 const std::vector
< String
>& codeNames
, BOOL bAsComment
=TRUE
, BOOL bStripped
=TRUE
);
84 // only for the export - copy or delete the saved VBA-macro-storage
85 // form the ObjectShell
86 // - returns a warning code if a modified basic exist, in all other
87 // cases return ERRCODE_NONE.
88 ULONG
SaveOrDelMSVBAStorage( BOOL bSaveInto
, const String
& rStorageName
);
89 // check if the MS-VBA-Storage exist in the RootStorage of the DocShell.
90 // If it exist, then return the WarningId for loosing the information.
92 const ControlAttributeInfo
& ControlNameForObjectId(){ return m_ModuleNameToObjIdHash
; }
93 static ULONG
GetSaveWarningOfMSVBAStorage( SfxObjectShell
&rDocS
);
95 static String
GetMSBasicStorageName();
96 rtl::OUString
GetVBAProjectName() { return msProjectName
; }
99 SfxObjectShell
&rDocSh
;
103 SVX_DLLPRIVATE BOOL
ImportCode_Impl( const String
& rStorageName
,
104 const String
&rSubStorageName
,
105 const std::vector
< String
>&,
106 BOOL bAsComment
, BOOL bStripped
);
107 SVX_DLLPRIVATE
bool ImportForms_Impl(const String
& rStorageName
,
108 const String
&rSubStorageName
, BOOL bVBAMode
);
109 SVX_DLLPRIVATE BOOL
CopyStorage_Impl( const String
& rStorageName
,
110 const String
&rSubStorageName
);
111 rtl::OUString msProjectName
;
112 SVX_DLLPRIVATE BOOL
ImportCode_Impl( VBA_Impl
&, const std::vector
< String
>&, BOOL
, BOOL
);
113 SVX_DLLPRIVATE
bool ImportForms_Impl( VBA_Impl
&, const String
&, const String
&, BOOL
);