xref: /aoo4110/main/basic/inc/basic/sbmod.hxx (revision b1cdbd2c)
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 _SB_SBMOD_HXX
25 #define _SB_SBMOD_HXX
26 
27 #include <com/sun/star/script/XInvocation.hpp>
28 #include <basic/sbdef.hxx>
29 #include <basic/sbxobj.hxx>
30 #include <basic/sbxdef.hxx>
31 #include <rtl/ustring.hxx>
32 #include <vector>
33 
34 #include <deque>
35 
36 class SbMethod;
37 class SbProperty;
38 class SbiRuntime;
39 typedef std::deque< sal_uInt16 > SbiBreakpoints;
40 class SbiImage;
41 class SbProcedureProperty;
42 class SbIfaceMapperMethod;
43 class SbClassModuleObject;
44 
45 class ModuleInitDependencyMap;
46 struct ClassModuleRunInitItem;
47 struct SbClassData;
48 class SbModuleImpl;
49 
50 class SbModule : public SbxObject
51 {
52 	friend class	TestToolObj;	// allows module initialisation at runtime
53 	friend class	SbiCodeGen;
54 	friend class	SbMethod;
55 	friend class	SbiRuntime;
56 	friend class	StarBASIC;
57 	friend class	SbClassModuleObject;
58 
59 	SbModuleImpl*	mpSbModuleImpl;		// Impl data
60     std::vector< String > mModuleVariableNames;
61 
62 	void 			implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic );
63 
64 protected:
65     com::sun::star::uno::Reference< com::sun::star::script::XInvocation > mxWrapper;
66     ::rtl::OUString     aOUSource;
67     String              aComment;
68     SbiImage*           pImage;        // the Image
69     SbiBreakpoints*     pBreaks;       // Breakpoints
70     SbClassData*        pClassData;
71 	sal_Bool mbVBACompat;
72 	sal_Int32 mnType;
73 	SbxObjectRef pDocObject; // an impl object ( used by Document Modules )
74 	bool 	bIsProxyModule;
75 
76 	static void		implProcessModuleRunInit( ModuleInitDependencyMap& rMap, ClassModuleRunInitItem& rItem );
77 	void			StartDefinitions();
78 	SbMethod*		GetMethod( const String&, SbxDataType );
79 	SbProperty*		GetProperty( const String&, SbxDataType );
80 	SbProcedureProperty* GetProcedureProperty( const String&, SbxDataType );
81 	SbIfaceMapperMethod* GetIfaceMapperMethod( const String&, SbMethod* );
82 	void			EndDefinitions( sal_Bool=sal_False );
83 	sal_uInt16 			Run( SbMethod* );
84 	void			RunInit();
85 	void 			ClearPrivateVars();
86 	void 			ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic );
87 	void			GlobalRunInit( sal_Bool bBasicStart );	// for all modules
88 	void			GlobalRunDeInit( void );
89 	const sal_uInt8* 	FindNextStmnt( const sal_uInt8*, sal_uInt16&, sal_uInt16& ) const;
90 	const sal_uInt8* 	FindNextStmnt( const sal_uInt8*, sal_uInt16&, sal_uInt16&,
91 						sal_Bool bFollowJumps, const SbiImage* pImg=NULL ) const;
92 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
93 	virtual sal_Bool StoreData( SvStream& ) const;
94 	virtual sal_Bool LoadCompleted();
95 	virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
96 							 const SfxHint& rHint, const TypeId& rHintType );
97 	void handleProcedureProperties( SfxBroadcaster& rBC, const SfxHint& rHint );
98 	virtual ~SbModule();
99 public:
100 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_BASICMOD,2);
101 	TYPEINFO();
102 					SbModule( const String&, sal_Bool bCompat = sal_False );
103 	virtual void	SetParent( SbxObject* );
104 	virtual void 	Clear();
105 
106 	virtual SbxVariable* Find( const String&, SbxClassType );
107 
108 	virtual const String& 	GetSource() const;
109     const ::rtl::OUString& 	GetSource32() const;
GetComment() const110 	const String&	GetComment() const            { return aComment; }
111 	virtual void	SetSource( const String& r );
112 	void	        SetSource32( const ::rtl::OUString& r );
113 	void			SetComment( const String& r );
114 
115 	virtual sal_Bool	Compile();
116 	sal_Bool 			Disassemble( String& rText );
117 	virtual sal_Bool	IsCompiled() const;
118 	const SbxObject* FindType( String aTypeName ) const;
119 
120 	virtual sal_Bool	IsBreakable( sal_uInt16 nLine ) const;
121 	virtual size_t	GetBPCount() const;
122 	virtual sal_uInt16	GetBP( size_t n ) const;
123 	virtual sal_Bool	IsBP( sal_uInt16 nLine ) const;
124 	virtual sal_Bool	SetBP( sal_uInt16 nLine );
125 	virtual sal_Bool	ClearBP( sal_uInt16 nLine );
126 	virtual void	ClearAllBP();
127 
128 	// Lines of Subs
129 	virtual SbMethod*	GetFunctionForLine( sal_uInt16 );
130 
131     // Store only image, no source (needed for new password protection)
132    	sal_Bool StoreBinaryData( SvStream& );
133    	sal_Bool StoreBinaryData( SvStream&, sal_uInt16 nVer );
134 	sal_Bool LoadBinaryData( SvStream&, sal_uInt16 nVer );
135 	sal_Bool LoadBinaryData( SvStream& );
136 	sal_Bool ExceedsLegacyModuleSize();
137 	void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
138     sal_Bool IsVBACompat() const;
139     void SetVBACompat( sal_Bool bCompat );
GetModuleType()140     sal_Int32 GetModuleType() { return mnType; }
SetModuleType(sal_Int32 nType)141     void SetModuleType( sal_Int32 nType ) { mnType = nType; }
isProxyModule()142 	bool isProxyModule() { return bIsProxyModule; }
143 	void AddVarName( const String& aName );
144 	void RemoveVars();
145     ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule();
146 	bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
147 };
148 
149 #ifndef __SB_SBMODULEREF_HXX
150 #define __SB_SBMODULEREF_HXX
151 
152 SV_DECL_IMPL_REF(SbModule)
153 
154 #endif
155 
156 class SbClassModuleImpl;
157 
158 // Object class for instances of class modules
159 class SbClassModuleObject : public SbModule
160 {
161 	SbClassModuleImpl* mpSbClassModuleImpl;
162 
163 	SbModule*	mpClassModule;
164 	bool		mbInitializeEventDone;
165 
166 public:
167 	TYPEINFO();
168 	SbClassModuleObject( SbModule* pClassModule );
169 	~SbClassModuleObject();
170 
171 	// Overridden to support NameAccess etc.
172 	virtual SbxVariable* Find( const String&, SbxClassType );
173 
174 	virtual void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
175 
getClassModule(void)176 	SbModule* getClassModule( void )
177 		{ return mpClassModule; }
178 
179 	void triggerInitializeEvent( void );
180 	void triggerTerminateEvent( void );
181 };
182 
183 #ifndef __SB_SBCLASSMODULEREF_HXX
184 #define __SB_SBCLASSMODULEREF_HXX
185 
186 SV_DECL_IMPL_REF(SbClassModuleObject);
187 
188 #endif
189 
190 #endif
191