xref: /AOO41X/main/basic/inc/basic/sbx.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SBXCLASS_HXX
29 #define _SBXCLASS_HXX
30 
31 #include "tools/ref.hxx"
32 #include "svl/svarray.hxx"
33 #include "svl/smplhint.hxx"
34 #include "svl/lstner.hxx"
35 #include <basic/sbxdef.hxx>
36 #include <basic/sbxform.hxx>
37 
38 #ifndef __SBX_SBXOBJECT_HXX
39 #include <basic/sbxobj.hxx>
40 #endif
41 #include <basic/sbxprop.hxx>
42 #include <basic/sbxmeth.hxx>
43 
44 class BigInt;
45 class String;
46 class UniString;
47 class SvStream;
48 class SbxBase;
49 class SbxVariable;
50 class SbxProperty;
51 class SbxMethod;
52 class SbxObject;
53 class SbxArray;
54 class SbxDimArray;
55 class SbxFactory;
56 struct SbxINT64;
57 struct SbxUINT64;
58 
59 class SfxBroadcaster;
60 class SvDispatch;
61 
62 ///////////////////////////////////////////////////////////////////////////
63 
64 ////////////////////////////////////////////////////////////////////////////
65 
66 #ifndef __SBX_SBXPARAMINFO
67 #define __SBX_SBXPARAMINFO
68 
69 // Parameter information
70 struct SbxParamInfo
71 {
72     const String aName;          // Name of the parameter
73     SbxBaseRef   aTypeRef;       // Object, if object type
74     SbxDataType  eType;          // Data type
75     sal_uInt16       nFlags;         // Flag-Bits
76     sal_uInt32       nUserData;      // IDs etc.
77     SbxParamInfo( const String& s, SbxDataType t, sal_uInt16 n, SbxBase* b = NULL )
78 	: aName( s ), aTypeRef( b ), eType( t ), nFlags( n ), nUserData( 0 ) {}
79 	~SbxParamInfo() {}
80 };
81 
82 //#if 0 // _SOLAR__PRIVATE
83 SV_DECL_PTRARR_DEL(SbxParams,SbxParamInfo*,4,4)
84 //#else
85 //typedef SvPtrarr SbxParams;
86 //#endif
87 
88 #endif
89 
90 #ifndef __SBX_SBXINFO
91 #define __SBX_SBXINFO
92 
93 class SbxInfo : public SvRefBase
94 {
95 	friend class SbxVariable;
96 	friend class SbMethod;
97 
98 	String			aComment;
99 	String			aHelpFile;
100 	sal_uInt32			nHelpId;
101 	SbxParams		aParams;
102 
103 protected:
104 	sal_Bool LoadData( SvStream&, sal_uInt16 );
105 	sal_Bool StoreData( SvStream& ) const;
106 	virtual ~SbxInfo();
107 public:
108 	SbxInfo();
109 	SbxInfo( const String&, sal_uInt32 );
110 
111 	void				AddParam( const String&, SbxDataType, sal_uInt16=SBX_READ );
112 	void				AddParam( const SbxParamInfo& );
113 	const SbxParamInfo*	GetParam( sal_uInt16 n ) const;	// index starts with 1!
114 	const String&		GetComment() const				{ return aComment; }
115 	const String&		GetHelpFile() const    			{ return aHelpFile; }
116 	sal_uInt32				GetHelpId() const				{ return nHelpId;   }
117 
118 	void				SetComment( const String& r )	{ aComment = r; }
119 	void				SetHelpFile( const String& r )	{ aHelpFile = r; }
120 	void				SetHelpId( sal_uInt32 nId )			{ nHelpId = nId; }
121 };
122 
123 #endif
124 
125 #ifndef __SBX_SBXHINT_HXX
126 #define __SBX_SBXHINT_HXX
127 
128 class SbxHint : public SfxSimpleHint
129 {
130 	SbxVariable* pVar;
131 public:
132 	TYPEINFO();
133 	SbxHint( sal_uIntPtr n, SbxVariable* v ) : SfxSimpleHint( n ), pVar( v ) {}
134 	SbxVariable* GetVar() const { return pVar; }
135 };
136 
137 #endif
138 
139 #ifndef __SBX_SBXALIAS_HXX
140 #define __SBX_SBXALIAS_HXX
141 
142 // SbxAlias is an alias for a var or object
143 class SbxAlias : public SbxVariable, public SfxListener
144 {
145 	SbxVariableRef xAlias;
146 	virtual ~SbxAlias();
147 	virtual void Broadcast( sal_uIntPtr );
148 	virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
149 							 const SfxHint& rHint, const TypeId& rHintType );
150 public:
151 	SbxAlias( const String& rName, SbxVariable* pOriginal );
152 	SbxAlias( const SbxAlias& );
153 	SbxAlias& operator=( const SbxAlias& );
154 };
155 
156 #endif
157 
158 #ifndef __SBX_SBXARRAY
159 #define __SBX_SBXARRAY
160 
161 // SbxArray ist ein eindimensionales, dynamisches Array
162 // von SbxVariablen. Put()/Insert() konvertieren die Variablen in den
163 // angegebenen Datentyp, falls er nicht SbxVARIANT ist.
164 
165 class SbxVarRefs;
166 class SbxVariableRef;
167 
168 class SbxArrayImpl;
169 
170 class SbxArray : public SbxBase
171 {
172 // #100883 Method to set method directly to parameter array
173     friend class SbMethod;
174     friend class SbClassModuleObject;
175 	friend SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj );
176     void PutDirect( SbxVariable* pVar, sal_uInt32 nIdx );
177 
178     SbxArrayImpl* mpSbxArrayImpl; // Impl data
179     SbxVarRefs*   pData;          // The variables
180 
181 protected:
182     SbxDataType eType;            // Data type of the array
183     virtual ~SbxArray();
184     virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
185     virtual sal_Bool StoreData( SvStream& ) const;
186 
187 public:
188     SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_ARRAY,1);
189     TYPEINFO();
190     SbxArray( SbxDataType=SbxVARIANT );
191     SbxArray( const SbxArray& );
192     SbxArray& operator=( const SbxArray& );
193     virtual void Clear();
194     sal_uInt16 Count() const;
195     virtual SbxDataType GetType() const;
196     virtual SbxClassType GetClass() const;
197     SbxVariableRef& GetRef( sal_uInt16 );
198     SbxVariable* Get( sal_uInt16 );
199     void Put( SbxVariable*, sal_uInt16 );
200     void Insert( SbxVariable*, sal_uInt16 );
201     void Remove( sal_uInt16 );
202     void Remove( SbxVariable* );
203     void Merge( SbxArray* );
204     const String& GetAlias( sal_uInt16 );
205     void PutAlias( const String&, sal_uInt16 );
206     SbxVariable* FindUserData( sal_uInt32 nUserData );
207     virtual SbxVariable* Find( const String&, SbxClassType );
208 
209     // Additional methods for 32-bit indices
210     sal_uInt32 Count32() const;
211     SbxVariableRef& GetRef32( sal_uInt32 );
212     SbxVariable* Get32( sal_uInt32 );
213     void Put32( SbxVariable*, sal_uInt32 );
214     void Insert32( SbxVariable*, sal_uInt32 );
215     void Remove32( sal_uInt32 );
216 };
217 
218 #endif
219 
220 #ifndef __SBX_SBXDIMARRAY_HXX
221 #define __SBX_SBXDIMARRAY_HXX
222 
223 // SbxDimArray is an array that can dimensioned using BASIC conventions.
224 struct SbxDim;
225 
226 class SbxDimArrayImpl;
227 
228 class SbxDimArray : public SbxArray
229 {
230 	SbxDimArrayImpl* mpSbxDimArrayImpl;   // Impl data
231 
232 	SbxDim* pFirst, *pLast;               // Links to Dimension table
233 	short   nDim;                         // Number of dimensions
234 	void   AddDimImpl32( sal_Int32, sal_Int32, sal_Bool bAllowSize0 );
235 	bool mbHasFixedSize;
236 protected:
237 	sal_uInt16  Offset( const short* );
238 	sal_uInt32  Offset32( const sal_Int32* );
239 	sal_uInt16  Offset( SbxArray* );
240 	sal_uInt32  Offset32( SbxArray* );
241 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
242 	virtual sal_Bool StoreData( SvStream& ) const;
243 	virtual ~SbxDimArray();
244 public:
245 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_DIMARRAY,1);
246 	TYPEINFO();
247 	SbxDimArray( SbxDataType=SbxVARIANT );
248 	SbxDimArray( const SbxDimArray& );
249 	SbxDimArray& operator=( const SbxDimArray& );
250 	virtual void Clear();
251 	using SbxArray::GetRef;
252 	SbxVariableRef& GetRef( const short* );
253 	using SbxArray::Get;
254 	SbxVariable* Get( const short* );
255 	using SbxArray::Put;
256 	void Put( SbxVariable*, const short* );
257 	SbxVariableRef& GetRef( SbxArray* );
258 	SbxVariable* Get( SbxArray* );
259 	void Put( SbxVariable*, SbxArray* );
260 
261 	short  GetDims() const { return nDim;  }
262 	void   AddDim( short, short );
263 	void   unoAddDim( short, short );
264 	sal_Bool   GetDim( short, short&, short& ) const;
265 
266 	using SbxArray::GetRef32;
267 	SbxVariableRef& GetRef32( const sal_Int32* );
268 	using SbxArray::Get32;
269 	SbxVariable* Get32( const sal_Int32* );
270 	using SbxArray::Put32;
271 	void Put32( SbxVariable*, const sal_Int32* );
272 	void   AddDim32( sal_Int32, sal_Int32 );
273 	void   unoAddDim32( sal_Int32, sal_Int32 );
274 	sal_Bool   GetDim32( sal_Int32, sal_Int32&, sal_Int32& ) const;
275         bool hasFixedSize() { return mbHasFixedSize; };
276         void setHasFixedSize( bool bHasFixedSize ) {mbHasFixedSize = bHasFixedSize; };
277 };
278 
279 #endif
280 
281 #ifndef __SBX_SBXCOLLECTION_HXX
282 #define __SBX_SBXCOLLECTION_HXX
283 
284 class SbxCollection : public SbxObject
285 {
286 	void Initialize();
287 protected:
288 	virtual ~SbxCollection();
289 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
290 	virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
291 							 const SfxHint& rHint, const TypeId& rHintType );
292 	// Overridable methods (why not pure virtual?):
293 	virtual void CollAdd( SbxArray* pPar );
294 	virtual void CollItem( SbxArray* pPar );
295 	virtual void CollRemove( SbxArray* pPar );
296 
297 public:
298 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_COLLECTION,1);
299 	TYPEINFO();
300 	SbxCollection( const String& rClassname );
301 	SbxCollection( const SbxCollection& );
302 	SbxCollection& operator=( const SbxCollection& );
303 	virtual SbxVariable* FindUserData( sal_uInt32 nUserData );
304 	virtual SbxVariable* Find( const String&, SbxClassType );
305 	virtual void Clear();
306 };
307 
308 #endif
309 
310 #ifndef __SBX_SBXSTDCOLLECTION_HXX
311 #define __SBX_SBXSTDCOLLECTION_HXX
312 
313 class SbxStdCollection : public SbxCollection
314 {
315 protected:
316 	String aElemClass;
317 	sal_Bool   bAddRemoveOk;
318 	virtual ~SbxStdCollection();
319 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
320 	virtual sal_Bool StoreData( SvStream& ) const;
321 	virtual void CollAdd( SbxArray* pPar );
322 	virtual void CollRemove( SbxArray* pPar );
323 public:
324 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_FIXCOLLECTION,1);
325 	TYPEINFO();
326 	SbxStdCollection
327 		( const String& rClassname, const String& rElemClass, sal_Bool=sal_True );
328 	SbxStdCollection( const SbxStdCollection& );
329 	SbxStdCollection& operator=( const SbxStdCollection& );
330 	virtual void Insert( SbxVariable* );
331 	const String& GetElementClass() const { return aElemClass; }
332 };
333 
334 #endif
335 
336 #ifndef __SBX_SBXREFS_HXX
337 #define __SBX_SBXREFS_HXX
338 
339 SV_IMPL_REF(SbxBase)
340 
341 SV_IMPL_REF(SbxVariable)
342 
343 #ifndef SBX_ARRAY_DECL_DEFINED
344 #define SBX_ARRAY_DECL_DEFINED
345 SV_DECL_REF(SbxArray)
346 #endif
347 #ifndef SBX_ARRAY_IMPL_DEFINED
348 #define SBX_ARRAY_IMPL_DEFINED
349 SV_IMPL_REF(SbxArray)
350 #endif
351 
352 #ifndef SBX_INFO_DECL_DEFINED
353 #define SBX_INFO_DECL_DEFINED
354 SV_DECL_REF(SbxInfo)
355 #endif
356 #ifndef SBX_INFO_IMPL_DEFINED
357 #define SBX_INFO_IMPL_DEFINED
358 SV_IMPL_REF(SbxInfo)
359 #endif
360 
361 #ifndef SBX_DIMARRAY_DECL_DEFINED
362 #define SBX_DIMARRAY_DECL_DEFINED
363 SV_DECL_REF(SbxDimArray)
364 #endif
365 SV_IMPL_REF(SbxDimArray)
366 
367 #endif
368 
369 #endif
370