bump product version to 4.2.0.1
[LibreOffice.git] / include / sot / object.hxx
blob7360789ff6c3274a9093be6a136e7be5f5ef6921
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SOT_OBJECT_HXX
21 #define INCLUDED_SOT_OBJECT_HXX
23 #include <sot/sotdata.hxx>
24 #include <tools/globname.hxx>
25 #include <tools/ref.hxx>
26 #include <sot/sotdllapi.h>
28 /*************************************************************************
29 *************************************************************************/
31 #define SO2_DECL_BASIC_CLASS_DLL(ClassName,FacName) \
32 private: \
33 static SotFactory ** GetFactoryAdress() \
34 { return &(FacName->p##ClassName##Factory); } \
35 public: \
36 static void * CreateInstance( SotObject ** = NULL ); \
37 static SotFactory * ClassFactory(); \
38 virtual const SotFactory * GetSvFactory() const; \
39 virtual void * Cast( const SotFactory * );
41 #define SO2_DECL_BASIC_CLASS(ClassName) \
42 private: \
43 static SotFactory * pFactory; \
44 static SotFactory ** GetFactoryAdress() { return &pFactory; } \
45 public: \
46 static void * CreateInstance( SotObject ** = NULL ); \
47 static SotFactory * ClassFactory(); \
48 virtual const SotFactory * GetSvFactory() const; \
49 virtual void * Cast( const SotFactory * );
51 /**************************************************************************
52 **************************************************************************/
53 #define SO2_IMPL_BASIC_CLASS_DLL(ClassName,FactoryName,GlobalName) \
54 SotFactory * ClassName::ClassFactory() \
55 { \
56 SotFactory **ppFactory = GetFactoryAdress(); \
57 if( !*ppFactory ) \
58 { \
59 *ppFactory = new FactoryName( GlobalName, \
60 OUString( #ClassName ), ClassName::CreateInstance ); \
61 } \
62 return *ppFactory; \
63 } \
64 void * ClassName::CreateInstance( SotObject ** ppObj ) \
65 { \
66 ClassName * p = new ClassName(); \
67 if( ppObj ) \
68 *ppObj = p; \
69 return p; \
70 } \
71 const SotFactory * ClassName::GetSvFactory() const \
72 { \
73 return ClassFactory(); \
74 } \
75 void * ClassName::Cast( const SotFactory * pFact ) \
76 { \
77 void * pRet = NULL; \
78 if( !pFact || pFact == ClassFactory() ) \
79 pRet = this; \
80 return pRet; \
83 #define SO2_IMPL_BASIC_CLASS(ClassName,FactoryName,GlobalName) \
84 SotFactory * ClassName::pFactory = NULL; \
85 SO2_IMPL_BASIC_CLASS_DLL(ClassName,FactoryName,GlobalName)
87 /**************************************************************************
88 **************************************************************************/
89 #define SO2_IMPL_BASIC_CLASS1_DLL(ClassName,FactoryName,Super1,GlobalName)\
90 SotFactory * ClassName::ClassFactory() \
91 { \
92 SotFactory **ppFactory = GetFactoryAdress(); \
93 if( !*ppFactory ) \
94 { \
95 *ppFactory = new FactoryName( GlobalName, \
96 OUString( #ClassName ), ClassName::CreateInstance ); \
97 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \
98 } \
99 return *ppFactory; \
101 void * ClassName::CreateInstance( SotObject ** ppObj ) \
103 ClassName * p = new ClassName(); \
104 Super1* pSuper1 = p; \
105 SotObject* pBasicObj = pSuper1; \
106 if( ppObj ) \
107 *ppObj = pBasicObj; \
108 return p; \
110 const SotFactory * ClassName::GetSvFactory() const \
112 return ClassFactory(); \
114 void * ClassName::Cast( const SotFactory * pFact ) \
116 void * pRet = NULL; \
117 if( !pFact || pFact == ClassFactory() ) \
118 pRet = this; \
119 if( !pRet ) \
120 pRet = Super1::Cast( pFact ); \
121 return pRet; \
124 #define SO2_IMPL_BASIC_CLASS1(ClassName,FactoryName,Super1,GlobalName) \
125 SotFactory * ClassName::pFactory = NULL; \
126 SO2_IMPL_BASIC_CLASS1_DLL(ClassName,FactoryName,Super1,GlobalName)
128 /**************************************************************************
129 **************************************************************************/
130 #define SO2_IMPL_BASIC_CLASS2_DLL(ClassName,FactoryName,Super1,Super2,GlobalName) \
131 SotFactory * ClassName::ClassFactory() \
133 SotFactory **ppFactory = GetFactoryAdress(); \
134 if( !*ppFactory ) \
136 *ppFactory = new FactoryName( GlobalName, \
137 OUString( #ClassName ), ClassName::CreateInstance ); \
138 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \
139 (*ppFactory)->PutSuperClass( Super2::ClassFactory() ); \
141 return *ppFactory; \
143 void * ClassName::CreateInstance( SotObject ** ppObj ) \
145 ClassName * p = new ClassName(); \
146 if( ppObj ) \
147 *ppObj = p; \
148 return p; \
150 const SotFactory * ClassName::GetSvFactory() const \
152 return ClassFactory(); \
154 void * ClassName::Cast( const SotFactory * pFact ) \
156 void * pRet = NULL; \
157 if( !pFact || pFact == ClassFactory() ) \
158 pRet = this; \
159 if( !pRet ) \
160 pRet = Super1::Cast( pFact ); \
161 if( !pRet ) \
162 pRet = Super2::Cast( pFact ); \
163 return pRet; \
165 #define SO2_IMPL_BASIC_CLASS2(ClassName,FactoryName,Super1,Super2,GlobalName) \
166 SotFactory * ClassName::pFactory = NULL; \
167 SO2_IMPL_BASIC_CLASS2_DLL(ClassName,FactoryName,Super1,Super2,GlobalName)
169 /**************************************************************************
170 **************************************************************************/
171 #define SO2_IMPL_BASIC_CLASS3_DLL(ClassName,FactoryName,Super1,Super2,Super3,GlobalName) \
172 SotFactory * ClassName::ClassFactory() \
174 SotFactory **ppFactory = GetFactoryAdress(); \
175 if( !*ppFactory ) \
177 *ppFactory = new FactoryName( GlobalName, \
178 OUString( #ClassName ), ClassName::CreateInstance ); \
179 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \
180 (*ppFactory)->PutSuperClass( Super2::ClassFactory() ); \
181 (*ppFactory)->PutSuperClass( Super3::ClassFactory() ); \
183 return *pFactory; \
185 void * ClassName::CreateInstance( SotObject ** ppObj ) \
187 ClassName * p = new ClassName(); \
188 if( ppObj ) \
189 *ppObj = p; \
190 return p; \
192 const SotFactory * ClassName::GetSvFactory() const \
194 return ClassFactory(); \
196 void * ClassName::Cast( const SotFactory * pFact ) \
198 void * pRet = NULL; \
199 if( !pFact || pFact == ClassFactory() ) \
200 pRet = this; \
201 if( !pRet ) \
202 pRet = Super1::Cast( pFact ); \
203 if( !pRet ) \
204 pRet = Super2::Cast( pFact ); \
205 if( !pRet ) \
206 pRet = Super3::Cast( pFact ); \
207 return pRet; \
210 #define SO2_IMPL_BASIC_CLASS3(ClassName,FactoryName,Super1,Super2,Super3,GlobalName) \
211 SotFactory * ClassName::pFactory = NULL; \
212 SO2_IMPL_BASIC_CLASS3_DLL(ClassName,FactoryName,Super1,Super2,Super3,GlobalName)
214 /**************************************************************************
215 **************************************************************************/
216 #define SO2_IMPL_BASIC_CLASS4_DLL(ClassName,FactoryName,Super1,Super2,Super3,Super4,GlobalName) \
217 SotFactory * ClassName::ClassFactory() \
219 SotFactory **ppFactory = GetFactoryAdress(); \
220 if( !*ppFactory ) \
222 *ppFactory = new SotFactory( GlobalName, \
223 OUString( #ClassName ), ClassName::CreateInstance ); \
224 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \
225 (*ppFactory)->PutSuperClass( Super2::ClassFactory() ); \
226 (*ppFactory)->PutSuperClass( Super3::ClassFactory() ); \
227 (*ppFactory)->PutSuperClass( Super4::ClassFactory() ); \
229 return *ppFactory; \
231 void * ClassName::CreateInstance( SotObject ** ppObj ) \
233 ClassName * p = new ClassName(); \
234 if( ppObj ) \
235 *ppObj = p; \
236 return p; \
238 const SotFactory * ClassName::GetSvFactory() const \
240 return ClassFactory(); \
242 void * ClassName::Cast( const SotFactory * pFact ) \
244 void * pRet = NULL; \
245 if( !pFact || pFact == ClassFactory() ) \
246 pRet = this; \
247 if( !pRet ) \
248 pRet = Super1::Cast( pFact ); \
249 if( !pRet ) \
250 pRet = Super2::Cast( pFact ); \
251 if( !pRet ) \
252 pRet = Super3::Cast( pFact ); \
253 if( !pRet ) \
254 pRet = Super4::Cast( pFact ); \
255 return pRet; \
258 #define SO2_IMPL_BASIC_CLASS4(ClassName,FactoryName,Super1,Super2,Super3,Super4,GlobalName) \
259 SotFactory * ClassName::pFactory = NULL; \
260 SO2_IMPL_BASIC_CLASS4_DLL(ClassName,FactoryName,Super1,Super2,Super3,Super4,GlobalName)
262 //==================class SotObject========================================
263 #ifdef _MSC_VER
264 #pragma warning(disable: 4250)
265 #endif
267 struct IUnknown;
268 class SOT_DLLPUBLIC SotObject : virtual public SvRefBase
270 friend class SotFactory;
271 friend class SvObject;
272 sal_uInt16 nOwnerLockCount;
273 bool bOwner;
274 bool bSVObject; // Ist Proxy, dann TRUE wenn andere Seite SV ist
275 bool bInClose; // TRUE, im DoClose
277 protected:
278 virtual ~SotObject();
279 void SetExtern() { bOwner = false; }
280 virtual bool Close();
281 public:
282 SotObject();
283 SO2_DECL_BASIC_CLASS_DLL(SotObject,SOTDATA())
285 // Nur damit die Makros in So3 nicht ganz ausufern
286 virtual IUnknown * GetInterface( const SvGlobalName & );
288 bool Owner() const { return bOwner; }
290 sal_uInt16 GetOwnerLockCount() const { return nOwnerLockCount; }
292 void OwnerLock( bool bLock );
293 bool DoClose();
294 bool IsInClose() const { return bInClose; }
296 private:
297 // Kopieren und Zuweisen dieses Objekttyps ist nicht erlaubt
298 SOT_DLLPRIVATE SotObject & operator = ( const SotObject & );
299 SOT_DLLPRIVATE SotObject( const SotObject & );
302 //==================class SotObjectRef======================================
303 SV_DECL_IMPL_REF(SotObject)
305 #endif // _IFACE_HXX
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */