1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxcore.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <tools/rtti.hxx>
35 #include <tools/ref.hxx>
36 #include <tools/debug.hxx>
38 #include <basic/sbxdef.hxx>
44 // The following Macro defines four (five) necessary methods within a
45 // SBX object. LoadPrivateData() and StorePrivateData() must be implemented.
46 // They are necessary for loading/storing the data of derived classes.
47 // Load() and Store() must not be overridden.
49 // This version of the Macros does not define Load/StorePrivateData()-methods
50 #define SBX_DECL_PERSIST_NODATA( nCre, nSbxId, nVer ) \
51 virtual UINT32 GetCreator() const { return nCre; } \
52 virtual UINT16 GetVersion() const { return nVer; } \
53 virtual UINT16 GetSbxId() const { return nSbxId; }
55 #define SBX_DECL_PERSIST_NODATA_() \
56 virtual UINT32 GetCreator() const; \
57 virtual UINT16 GetVersion() const; \
58 virtual UINT16 GetSbxId() const;
60 // This version of the macro defines Load/StorePrivateData()-methods
61 #define SBX_DECL_PERSIST( nCre, nSbxId, nVer ) \
62 virtual BOOL LoadPrivateData( SvStream&, USHORT ); \
63 virtual BOOL StorePrivateData( SvStream& ) const; \
64 SBX_DECL_PERSIST_NODATA( nCre, nSbxId, nVer )
66 #define SBX_DECL_PERSIST_() \
67 virtual BOOL LoadPrivateData( SvStream&, USHORT ); \
68 virtual BOOL StorePrivateData( SvStream& ) const; \
69 SBX_DECL_PERSIST_NODATA_()
71 #define SBX_IMPL_PERSIST( C, nCre, nSbxId, nVer ) \
72 UINT32 C::GetCreator() const { return nCre; } \
73 UINT16 C::GetVersion() const { return nVer; } \
74 UINT16 C::GetSbxId() const { return nSbxId; }
84 class SbxBase
: virtual public SvRefBase
86 SbxBaseImpl
* mpSbxBaseImpl
; // Impl data
88 virtual BOOL
LoadData( SvStream
&, USHORT
);
89 virtual BOOL
StoreData( SvStream
& ) const;
91 USHORT nFlags
; // Flag-Bits
94 SbxBase( const SbxBase
& );
95 SbxBase
& operator=( const SbxBase
& );
97 SBX_DECL_PERSIST(0,0,0);
100 inline void SetFlags( USHORT n
);
101 inline USHORT
GetFlags() const;
102 inline void SetFlag( USHORT n
);
103 inline void ResetFlag( USHORT n
);
104 inline BOOL
IsSet( USHORT n
) const;
105 inline BOOL
IsReset( USHORT n
) const;
106 inline BOOL
CanRead() const;
107 inline BOOL
CanWrite() const;
108 inline BOOL
IsModified() const;
109 inline BOOL
IsConst() const;
110 inline BOOL
IsHidden() const;
111 inline BOOL
IsVisible() const;
113 virtual BOOL
IsFixed() const;
114 virtual void SetModified( BOOL
);
116 virtual SbxDataType
GetType() const;
117 virtual SbxClassType
GetClass() const;
119 virtual void Clear();
121 static SbxBase
* Load( SvStream
& );
122 static void Skip( SvStream
& );
123 BOOL
Store( SvStream
& );
124 virtual BOOL
LoadCompleted();
125 virtual BOOL
StoreCompleted();
127 static SbxError
GetError();
128 static void SetError( SbxError
);
129 static BOOL
IsError();
130 static void ResetError();
132 // Set the factory for Load/Store/Create
133 static void AddFactory( SbxFactory
* );
134 static void RemoveFactory( SbxFactory
* );
136 static SbxBase
* Create( UINT16
, UINT32
=SBXCR_SBX
);
137 static SbxObject
* CreateObject( const String
& );
138 // Sbx solution as replacement for SfxBroadcaster::Enable()
139 static void StaticEnableBroadcasting( BOOL bEnable
);
140 static BOOL
StaticIsEnabledBroadcasting( void );
143 #ifndef SBX_BASE_DECL_DEFINED
144 #define SBX_BASE_DECL_DEFINED
148 inline void SbxBase::SetFlags( USHORT n
)
149 { DBG_CHKTHIS( SbxBase
, 0 ); nFlags
= n
; }
151 inline USHORT
SbxBase::GetFlags() const
152 { DBG_CHKTHIS( SbxBase
, 0 ); return nFlags
; }
154 inline void SbxBase::SetFlag( USHORT n
)
155 { DBG_CHKTHIS( SbxBase
, 0 ); nFlags
|= n
; }
157 inline void SbxBase::ResetFlag( USHORT n
)
158 { DBG_CHKTHIS( SbxBase
, 0 ); nFlags
&= ~n
; }
160 inline BOOL
SbxBase::IsSet( USHORT n
) const
161 { DBG_CHKTHIS( SbxBase
, 0 ); return BOOL( ( nFlags
& n
) != 0 ); }
163 inline BOOL
SbxBase::IsReset( USHORT n
) const
164 { DBG_CHKTHIS( SbxBase
, 0 ); return BOOL( ( nFlags
& n
) == 0 ); }
166 inline BOOL
SbxBase::CanRead() const
167 { DBG_CHKTHIS( SbxBase
, 0 ); return IsSet( SBX_READ
); }
169 inline BOOL
SbxBase::CanWrite() const
170 { DBG_CHKTHIS( SbxBase
, 0 ); return IsSet( SBX_WRITE
); }
172 inline BOOL
SbxBase::IsModified() const
173 { DBG_CHKTHIS( SbxBase
, 0 ); return IsSet( SBX_MODIFIED
); }
175 inline BOOL
SbxBase::IsConst() const
176 { DBG_CHKTHIS( SbxBase
, 0 ); return IsSet( SBX_CONST
); }
178 inline BOOL
SbxBase::IsHidden() const
179 { DBG_CHKTHIS( SbxBase
, 0 ); return IsSet( SBX_HIDDEN
); }
181 inline BOOL
SbxBase::IsVisible() const
182 { DBG_CHKTHIS( SbxBase
, 0 ); return IsReset( SBX_INVISIBLE
); }