xref: /trunk/main/basic/inc/basic/sbxcore.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _SBXCORE_HXX
29*cdf0e10cSrcweir #define _SBXCORE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/rtti.hxx>
32*cdf0e10cSrcweir #include <tools/ref.hxx>
33*cdf0e10cSrcweir #include <tools/debug.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <basic/sbxdef.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir class SvStream;
38*cdf0e10cSrcweir class String;
39*cdf0e10cSrcweir class UniString;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir // The following Macro defines four (five) necessary methods within a
42*cdf0e10cSrcweir // SBX object. LoadPrivateData() and StorePrivateData() must be implemented.
43*cdf0e10cSrcweir // They are necessary for loading/storing the data of derived classes.
44*cdf0e10cSrcweir // Load() and Store() must not be overridden.
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir // This version of the Macros does not define Load/StorePrivateData()-methods
47*cdf0e10cSrcweir #define SBX_DECL_PERSIST_NODATA( nCre, nSbxId, nVer )		\
48*cdf0e10cSrcweir 	virtual sal_uInt32 GetCreator() const { return nCre;   }	\
49*cdf0e10cSrcweir 	virtual sal_uInt16 GetVersion() const { return nVer;   }	\
50*cdf0e10cSrcweir 	virtual sal_uInt16 GetSbxId() const	  { return nSbxId; }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #define SBX_DECL_PERSIST_NODATA_()							\
53*cdf0e10cSrcweir 	virtual sal_uInt32 GetCreator() const;						\
54*cdf0e10cSrcweir 	virtual sal_uInt16 GetVersion() const;						\
55*cdf0e10cSrcweir 	virtual sal_uInt16 GetSbxId() const;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // This version of the macro defines Load/StorePrivateData()-methods
58*cdf0e10cSrcweir #define SBX_DECL_PERSIST( nCre, nSbxId, nVer )				\
59*cdf0e10cSrcweir 	virtual sal_Bool LoadPrivateData( SvStream&, sal_uInt16 ); 		\
60*cdf0e10cSrcweir 	virtual sal_Bool StorePrivateData( SvStream& ) const;  		\
61*cdf0e10cSrcweir 	SBX_DECL_PERSIST_NODATA( nCre, nSbxId, nVer )
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #define SBX_DECL_PERSIST_()									\
64*cdf0e10cSrcweir 	virtual sal_Bool LoadPrivateData( SvStream&, sal_uInt16 ); 		\
65*cdf0e10cSrcweir 	virtual sal_Bool StorePrivateData( SvStream& ) const;  		\
66*cdf0e10cSrcweir 	SBX_DECL_PERSIST_NODATA_()
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #define SBX_IMPL_PERSIST( C, nCre, nSbxId, nVer )			\
69*cdf0e10cSrcweir 	sal_uInt32 C::GetCreator() const { return nCre;   }			\
70*cdf0e10cSrcweir 	sal_uInt16 C::GetVersion() const { return nVer;   }			\
71*cdf0e10cSrcweir 	sal_uInt16 C::GetSbxId() const	 { return nSbxId; }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir class SbxBase;
74*cdf0e10cSrcweir class SbxFactory;
75*cdf0e10cSrcweir class SbxObject;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir DBG_NAMEEX(SbxBase)
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir class SbxBaseImpl;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir class SbxBase : virtual public SvRefBase
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir 	SbxBaseImpl* mpSbxBaseImpl;	// Impl data
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
86*cdf0e10cSrcweir 	virtual sal_Bool StoreData( SvStream& ) const;
87*cdf0e10cSrcweir protected:
88*cdf0e10cSrcweir 	sal_uInt16 nFlags;			// Flag-Bits
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	SbxBase();
91*cdf0e10cSrcweir 	SbxBase( const SbxBase& );
92*cdf0e10cSrcweir 	SbxBase& operator=( const SbxBase& );
93*cdf0e10cSrcweir 	virtual ~SbxBase();
94*cdf0e10cSrcweir 	SBX_DECL_PERSIST(0,0,0);
95*cdf0e10cSrcweir public:
96*cdf0e10cSrcweir 	TYPEINFO();
97*cdf0e10cSrcweir 	inline void		SetFlags( sal_uInt16 n );
98*cdf0e10cSrcweir 	inline sal_uInt16	GetFlags() const;
99*cdf0e10cSrcweir 	inline void		SetFlag( sal_uInt16 n );
100*cdf0e10cSrcweir 	inline void		ResetFlag( sal_uInt16 n );
101*cdf0e10cSrcweir 	inline sal_Bool		IsSet( sal_uInt16 n ) const;
102*cdf0e10cSrcweir 	inline sal_Bool		IsReset( sal_uInt16 n ) const;
103*cdf0e10cSrcweir 	inline sal_Bool		CanRead() const;
104*cdf0e10cSrcweir 	inline sal_Bool		CanWrite() const;
105*cdf0e10cSrcweir 	inline sal_Bool		IsModified() const;
106*cdf0e10cSrcweir 	inline sal_Bool		IsConst() const;
107*cdf0e10cSrcweir 	inline sal_Bool		IsHidden() const;
108*cdf0e10cSrcweir 	inline sal_Bool		IsVisible() const;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	virtual sal_Bool IsFixed() const;
111*cdf0e10cSrcweir 	virtual void SetModified( sal_Bool );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	virtual SbxDataType  GetType()  const;
114*cdf0e10cSrcweir 	virtual SbxClassType GetClass() const;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	virtual void Clear();
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	static SbxBase* Load( SvStream& );
119*cdf0e10cSrcweir 	static void Skip( SvStream& );
120*cdf0e10cSrcweir 	sal_Bool Store( SvStream& );
121*cdf0e10cSrcweir 	virtual sal_Bool LoadCompleted();
122*cdf0e10cSrcweir 	virtual sal_Bool StoreCompleted();
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	static SbxError GetError();
125*cdf0e10cSrcweir 	static void SetError( SbxError );
126*cdf0e10cSrcweir 	static sal_Bool IsError();
127*cdf0e10cSrcweir 	static void ResetError();
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	// Set the factory for Load/Store/Create
130*cdf0e10cSrcweir 	static void AddFactory( SbxFactory* );
131*cdf0e10cSrcweir 	static void RemoveFactory( SbxFactory* );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	static SbxBase* Create( sal_uInt16, sal_uInt32=SBXCR_SBX );
134*cdf0e10cSrcweir 	static SbxObject* CreateObject( const String& );
135*cdf0e10cSrcweir 	// Sbx solution as replacement for SfxBroadcaster::Enable()
136*cdf0e10cSrcweir 	static void StaticEnableBroadcasting( sal_Bool bEnable );
137*cdf0e10cSrcweir 	static sal_Bool StaticIsEnabledBroadcasting( void );
138*cdf0e10cSrcweir };
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir #ifndef SBX_BASE_DECL_DEFINED
141*cdf0e10cSrcweir #define SBX_BASE_DECL_DEFINED
142*cdf0e10cSrcweir SV_DECL_REF(SbxBase)
143*cdf0e10cSrcweir #endif
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir inline void SbxBase::SetFlags( sal_uInt16 n )
146*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); nFlags = n; }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir inline sal_uInt16 SbxBase::GetFlags() const
149*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return nFlags; }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir inline void SbxBase::SetFlag( sal_uInt16 n )
152*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); nFlags |= n; }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir inline void SbxBase::ResetFlag( sal_uInt16 n )
155*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); nFlags &= ~n; }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir inline sal_Bool SbxBase::IsSet( sal_uInt16 n ) const
158*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return sal_Bool( ( nFlags & n ) != 0 ); }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir inline sal_Bool SbxBase::IsReset( sal_uInt16 n ) const
161*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return sal_Bool( ( nFlags & n ) == 0 ); }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir inline sal_Bool SbxBase::CanRead() const
164*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_READ ); }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir inline sal_Bool SbxBase::CanWrite() const
167*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_WRITE ); }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir inline sal_Bool SbxBase::IsModified() const
170*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_MODIFIED ); }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir inline sal_Bool SbxBase::IsConst() const
173*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_CONST ); }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir inline sal_Bool SbxBase::IsHidden() const
176*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_HIDDEN ); }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir inline sal_Bool SbxBase::IsVisible() const
179*cdf0e10cSrcweir { DBG_CHKTHIS( SbxBase, 0 ); return IsReset( SBX_INVISIBLE ); }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir #endif
182