Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SOT_OBJECT_HXX
21 : #define INCLUDED_SOT_OBJECT_HXX
22 :
23 : #include <sot/sotdata.hxx>
24 : #include <tools/globname.hxx>
25 : #include <tools/ref.hxx>
26 : #include <sot/sotdllapi.h>
27 :
28 : #define SO2_IMPL_BASIC_CLASS_DLL(ClassName,FactoryName,GlobalName) \
29 : SotFactory * ClassName::ClassFactory() \
30 : { \
31 : SotFactory **ppFactory = GetFactoryAdress(); \
32 : if( !*ppFactory ) \
33 : { \
34 : *ppFactory = new FactoryName( GlobalName, \
35 : OUString( #ClassName ), ClassName::CreateInstance ); \
36 : } \
37 : return *ppFactory; \
38 : } \
39 : void * ClassName::CreateInstance( SotObject ** ppObj ) \
40 : { \
41 : ClassName * p = new ClassName(); \
42 : if( ppObj ) \
43 : *ppObj = p; \
44 : return p; \
45 : } \
46 : const SotFactory * ClassName::GetSvFactory() const \
47 : { \
48 : return ClassFactory(); \
49 : } \
50 : void * ClassName::Cast( const SotFactory * pFact ) \
51 : { \
52 : void * pRet = NULL; \
53 : if( !pFact || pFact == ClassFactory() ) \
54 : pRet = this; \
55 : return pRet; \
56 : }
57 :
58 : #define SO2_IMPL_BASIC_CLASS1_DLL(ClassName,FactoryName,Super1,GlobalName)\
59 : SotFactory * ClassName::ClassFactory() \
60 : { \
61 : SotFactory **ppFactory = GetFactoryAdress(); \
62 : if( !*ppFactory ) \
63 : { \
64 : *ppFactory = new FactoryName( GlobalName, \
65 : OUString( #ClassName ), ClassName::CreateInstance ); \
66 : (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \
67 : } \
68 : return *ppFactory; \
69 : } \
70 : void * ClassName::CreateInstance( SotObject ** ppObj ) \
71 : { \
72 : ClassName * p = new ClassName(); \
73 : Super1* pSuper1 = p; \
74 : SotObject* pBasicObj = pSuper1; \
75 : if( ppObj ) \
76 : *ppObj = pBasicObj; \
77 : return p; \
78 : } \
79 : const SotFactory * ClassName::GetSvFactory() const \
80 : { \
81 : return ClassFactory(); \
82 : } \
83 : void * ClassName::Cast( const SotFactory * pFact ) \
84 : { \
85 : void * pRet = NULL; \
86 : if( !pFact || pFact == ClassFactory() ) \
87 : pRet = this; \
88 : if( !pRet ) \
89 : pRet = Super1::Cast( pFact ); \
90 : return pRet; \
91 : }
92 :
93 : struct IUnknown;
94 : class SOT_DLLPUBLIC SotObject : virtual public SvRefBase
95 : {
96 : friend class SotFactory;
97 : sal_uInt16 nOwnerLockCount;
98 : bool bOwner;
99 : bool bSVObject; // is proxy, then TRUE if other side is SV
100 : bool bInClose; // TRUE, in DoClose
101 :
102 : protected:
103 : virtual ~SotObject();
104 : void SetExtern() { bOwner = false; }
105 : virtual bool Close();
106 : public:
107 : SotObject();
108 :
109 : private:
110 0 : static SotFactory ** GetFactoryAdress()
111 0 : { return &(SOTDATA()->pSotObjectFactory); }
112 : public:
113 : static void * CreateInstance( SotObject ** = NULL );
114 : static SotFactory * ClassFactory();
115 : virtual const SotFactory * GetSvFactory() const;
116 : virtual void * Cast( const SotFactory * );
117 :
118 : bool Owner() const { return bOwner; }
119 :
120 3243 : sal_uInt16 GetOwnerLockCount() const { return nOwnerLockCount; }
121 :
122 : void OwnerLock( bool bLock );
123 : bool DoClose();
124 1 : bool IsInClose() const { return bInClose; }
125 :
126 : private:
127 : SotObject & operator = ( const SotObject & ) SAL_DELETED_FUNCTION;
128 : SotObject( const SotObject & ) SAL_DELETED_FUNCTION;
129 : };
130 :
131 : //==================class SotObjectRef======================================
132 : typedef tools::SvRef<SotObject> SotObjectRef;
133 :
134 : #endif // _IFACE_HXX
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|