1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVXMSBAS_HXX
25 #define _SVXMSBAS_HXX
26 
27 #include <tools/solar.h>
28 #include "filter/msfilter/msfilterdllapi.h"
29 
30 #include <sot/storage.hxx>
31 
32 class SfxObjectShell;
33 
34 /* Construct with the root storage of the MS document, with bImportCode
35  * set the visual basic code will be imported into the stardocument when Import
36  * is called, with bCopyStorage set, the visual basic storage tree will be
37  * copied completely into staroffice, so that any future export to a msoffice
38  * format will retain the vba code, allowing a lossless roundtrip from
39  * msoffice to staroffice and back.
40  *
41  * Setting bAsComment to true in Import will import the visual basic as a
42  * starbasic comment. Which is currently necessary, as vb is not valid sb.
43  *
44  * Setting bStripped will remove the "Attribute" lines from the vb, msoffice
45  * does this itself when it shows the vb code in the vbeditor, so this is
46  * probably what the user expects to see when viewing the code
47  */
48 
49 class MSFILTER_DLLPUBLIC SvxImportMSVBasic
50 {
51 public:
SvxImportMSVBasic(SfxObjectShell & rDocS,SotStorage & rRoot,sal_Bool bImportCode=sal_True,sal_Bool bCopyStorage=sal_True)52 	SvxImportMSVBasic( SfxObjectShell &rDocS, SotStorage &rRoot,
53 						sal_Bool bImportCode = sal_True, sal_Bool bCopyStorage = sal_True )
54 		:	xRoot(&rRoot), rDocSh(rDocS),
55 			bImport(bImportCode), bCopy(bCopyStorage)
56 		{}
57 	// returns the status of import:
58 	// 0 - nothing has done
59 	// bit 0 = 1 -> any code is imported to the SO-Basic
60 	// bit 1 = 1 -> the VBA - storage is copy to the ObjectShell storage
61 	int Import( const String& rStorageName, const String &rSubStorageName,
62 				sal_Bool bAsComment=sal_True, sal_Bool bStripped=sal_True );
63 	int Import( const String& rStorageName, const String &rSubStorageName,
64 				const std::vector< String >& codeNames,
65 				sal_Bool bAsComment=sal_True, sal_Bool bStripped=sal_True );
66 
67 	// only for the export - copy or delete the saved VBA-macro-storage
68 	// form the ObjectShell
69 	// - returns a warning code if a modified basic exist, in all other
70 	//   cases return ERRCODE_NONE.
71 	sal_uLong SaveOrDelMSVBAStorage( sal_Bool bSaveInto, const String& rStorageName );
72 
73 	// check if the MS-VBA-Storage exist in the RootStorage of the DocShell.
74 	// If it exist, then return the WarningId for loosing the information.
75 	static sal_uLong GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS );
76 
77 	static String GetMSBasicStorageName();
78 private:
79 	SotStorageRef xRoot;
80 	SfxObjectShell &rDocSh;
81 	sal_Bool bImport;
82 	sal_Bool bCopy;
83 
84 	MSFILTER_DLLPRIVATE sal_Bool ImportCode_Impl( const String& rStorageName,
85 						  const String &rSubStorageName,
86 						  const std::vector< String >& codeNames,
87 						  sal_Bool bAsComment, sal_Bool bStripped);
88 	MSFILTER_DLLPRIVATE bool ImportForms_Impl(const String& rStorageName,
89 		const String &rSubStorageName);
90 	MSFILTER_DLLPRIVATE sal_Bool CopyStorage_Impl( const String& rStorageName,
91 						   const String &rSubStorageName);
92 };
93 
94 #endif
95