xref: /trunk/main/basic/inc/basic/sbxcore.hxx (revision 7fef15a0)
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 _SBXCORE_HXX
25 #define _SBXCORE_HXX
26 
27 #include <tools/rtti.hxx>
28 #include <tools/ref.hxx>
29 #include <tools/debug.hxx>
30 
31 #include "basic/basicdllapi.h"
32 #include <basic/sbxdef.hxx>
33 
34 class SvStream;
35 class String;
36 class UniString;
37 
38 // The following Macro defines four (five) necessary methods within a
39 // SBX object. LoadPrivateData() and StorePrivateData() must be implemented.
40 // They are necessary for loading/storing the data of derived classes.
41 // Load() and Store() must not be overridden.
42 
43 // This version of the Macros does not define Load/StorePrivateData()-methods
44 #define SBX_DECL_PERSIST_NODATA( nCre, nSbxId, nVer )		\
45 	virtual sal_uInt32 GetCreator() const { return nCre;   }	\
46 	virtual sal_uInt16 GetVersion() const { return nVer;   }	\
47 	virtual sal_uInt16 GetSbxId() const	  { return nSbxId; }
48 
49 #define SBX_DECL_PERSIST_NODATA_()							\
50 	virtual sal_uInt32 GetCreator() const;						\
51 	virtual sal_uInt16 GetVersion() const;						\
52 	virtual sal_uInt16 GetSbxId() const;
53 
54 // This version of the macro defines Load/StorePrivateData()-methods
55 #define SBX_DECL_PERSIST( nCre, nSbxId, nVer )				\
56 	virtual sal_Bool LoadPrivateData( SvStream&, sal_uInt16 ); 		\
57 	virtual sal_Bool StorePrivateData( SvStream& ) const;  		\
58 	SBX_DECL_PERSIST_NODATA( nCre, nSbxId, nVer )
59 
60 #define SBX_DECL_PERSIST_()									\
61 	virtual sal_Bool LoadPrivateData( SvStream&, sal_uInt16 ); 		\
62 	virtual sal_Bool StorePrivateData( SvStream& ) const;  		\
63 	SBX_DECL_PERSIST_NODATA_()
64 
65 #define SBX_IMPL_PERSIST( C, nCre, nSbxId, nVer )			\
66 	sal_uInt32 C::GetCreator() const { return nCre;   }			\
67 	sal_uInt16 C::GetVersion() const { return nVer;   }			\
68 	sal_uInt16 C::GetSbxId() const	 { return nSbxId; }
69 
70 class SbxBase;
71 class SbxFactory;
72 class SbxObject;
73 
74 DBG_NAMEEX_VISIBILITY(SbxBase, BASIC_DLLPUBLIC)
75 
76 class SbxBaseImpl;
77 
78 class BASIC_DLLPUBLIC SbxBase : virtual public SvRefBase
79 {
80 	SbxBaseImpl* mpSbxBaseImpl;	// Impl data
81 
82 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
83 	virtual sal_Bool StoreData( SvStream& ) const;
84 protected:
85 	sal_uInt16 nFlags;			// Flag-Bits
86 
87 	SbxBase();
88 	SbxBase( const SbxBase& );
89 	SbxBase& operator=( const SbxBase& );
90 	virtual ~SbxBase();
91 	SBX_DECL_PERSIST(0,0,0);
92 public:
93 	TYPEINFO();
94 	inline void		SetFlags( sal_uInt16 n );
95 	inline sal_uInt16	GetFlags() const;
96 	inline void		SetFlag( sal_uInt16 n );
97 	inline void		ResetFlag( sal_uInt16 n );
98 	inline sal_Bool		IsSet( sal_uInt16 n ) const;
99 	inline sal_Bool		IsReset( sal_uInt16 n ) const;
100 	inline sal_Bool		CanRead() const;
101 	inline sal_Bool		CanWrite() const;
102 	inline sal_Bool		IsModified() const;
103 	inline sal_Bool		IsConst() const;
104 	inline sal_Bool		IsHidden() const;
105 	inline sal_Bool		IsVisible() const;
106 
107 	virtual sal_Bool IsFixed() const;
108 	virtual void SetModified( sal_Bool );
109 
110 	virtual SbxDataType  GetType()  const;
111 	virtual SbxClassType GetClass() const;
112 
113 	virtual void Clear();
114 
115 	static SbxBase* Load( SvStream& );
116 	static void Skip( SvStream& );
117 	sal_Bool Store( SvStream& );
118 	virtual sal_Bool LoadCompleted();
119 	virtual sal_Bool StoreCompleted();
120 
121 	static SbxError GetError();
122 	static void SetError( SbxError );
123 	static sal_Bool IsError();
124 	static void ResetError();
125 
126 	// Set the factory for Load/Store/Create
127 	static void AddFactory( SbxFactory* );
128 	static void RemoveFactory( SbxFactory* );
129 
130 	static SbxBase* Create( sal_uInt16, sal_uInt32=SBXCR_SBX );
131 	static SbxObject* CreateObject( const String& );
132 	// Sbx solution as replacement for SfxBroadcaster::Enable()
133 	static void StaticEnableBroadcasting( sal_Bool bEnable );
134 	static sal_Bool StaticIsEnabledBroadcasting( void );
135 };
136 
137 #ifndef SBX_BASE_DECL_DEFINED
138 #define SBX_BASE_DECL_DEFINED
SV_DECL_REF(SbxBase)139 SV_DECL_REF(SbxBase)
140 #endif
141 
142 inline void SbxBase::SetFlags( sal_uInt16 n )
143 { DBG_CHKTHIS( SbxBase, 0 ); nFlags = n; }
144 
GetFlags() const145 inline sal_uInt16 SbxBase::GetFlags() const
146 { DBG_CHKTHIS( SbxBase, 0 ); return nFlags; }
147 
SetFlag(sal_uInt16 n)148 inline void SbxBase::SetFlag( sal_uInt16 n )
149 { DBG_CHKTHIS( SbxBase, 0 ); nFlags |= n; }
150 
ResetFlag(sal_uInt16 n)151 inline void SbxBase::ResetFlag( sal_uInt16 n )
152 { DBG_CHKTHIS( SbxBase, 0 ); nFlags &= ~n; }
153 
IsSet(sal_uInt16 n) const154 inline sal_Bool SbxBase::IsSet( sal_uInt16 n ) const
155 { DBG_CHKTHIS( SbxBase, 0 ); return sal_Bool( ( nFlags & n ) != 0 ); }
156 
IsReset(sal_uInt16 n) const157 inline sal_Bool SbxBase::IsReset( sal_uInt16 n ) const
158 { DBG_CHKTHIS( SbxBase, 0 ); return sal_Bool( ( nFlags & n ) == 0 ); }
159 
CanRead() const160 inline sal_Bool SbxBase::CanRead() const
161 { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_READ ); }
162 
CanWrite() const163 inline sal_Bool SbxBase::CanWrite() const
164 { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_WRITE ); }
165 
IsModified() const166 inline sal_Bool SbxBase::IsModified() const
167 { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_MODIFIED ); }
168 
IsConst() const169 inline sal_Bool SbxBase::IsConst() const
170 { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_CONST ); }
171 
IsHidden() const172 inline sal_Bool SbxBase::IsHidden() const
173 { DBG_CHKTHIS( SbxBase, 0 ); return IsSet( SBX_HIDDEN ); }
174 
IsVisible() const175 inline sal_Bool SbxBase::IsVisible() const
176 { DBG_CHKTHIS( SbxBase, 0 ); return IsReset( SBX_INVISIBLE ); }
177 
178 #endif
179