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