xref: /aoo41x/main/sot/source/base/object.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sot.hxx"
30 
31 #define _SOT_OBJECT_CXX
32 
33 #include <tools/debug.hxx>
34 #include <sot/object.hxx>
35 #include <sot/factory.hxx>
36 #include <sot/agg.hxx>
37 
38 /************** class SotObject ******************************************/
39 class SotObjectFactory : public SotFactory
40 {
41 public:
42  		TYPEINFO();
43 		SotObjectFactory( const SvGlobalName & rName,
44 					  		const String & rClassName,
45 					  		CreateInstanceType pCreateFuncP )
46 			: SotFactory( rName, rClassName, pCreateFuncP )
47 		{}
48 };
49 TYPEINIT1(SotObjectFactory,SotFactory);
50 
51 
52 SO2_IMPL_BASIC_CLASS_DLL(SotObject,SotObjectFactory,
53 					SvGlobalName( 0xf44b7830, 0xf83c, 0x11d0,
54 							0xaa, 0xa1, 0x0, 0xa0, 0x24, 0x9d, 0x55, 0x90 ) )
55 SO2_IMPL_INVARIANT(SotObject)
56 
57 /*************************************************************************
58 |*  SotObject::TestMemberObjRef()
59 |*
60 |*	Beschreibung:
61 *************************************************************************/
62 void SotObject::TestMemberObjRef( sal_Bool /*bFree*/ )
63 {
64 }
65 
66 /*************************************************************************
67 |*  SotObject::TestMemberObjRef()
68 |*
69 |*	Beschreibung:
70 *************************************************************************/
71 #ifdef TEST_INVARIANT
72 void SotObject::TestMemberInvariant( sal_Bool /*bPrint*/ )
73 {
74 }
75 #endif
76 
77 /*************************************************************************
78 |*    SotObject::SotObject()
79 |*
80 |*    Beschreibung
81 *************************************************************************/
82 SotObject::SotObject()
83     : nStrongLockCount( 0 )
84 	, nOwnerLockCount( 0 )
85     , bOwner      ( sal_True )
86     , bSVObject   ( sal_False )
87     , bInClose	  ( sal_False )
88 {
89 	SotFactory::IncSvObjectCount( this );
90 }
91 
92 /*************************************************************************
93 |*
94 |*    SotObject::~SotObject()
95 |*
96 |*    Beschreibung
97 |*    Ersterstellung    MM 05.06.94
98 |*    Letzte Aenderung  MM 05.06.94
99 |*
100 *************************************************************************/
101 SotObject::~SotObject()
102 {
103 	SotFactory::DecSvObjectCount( this );
104 }
105 
106 /*************************************************************************
107 |*    SotObject::GetInterface()
108 |*
109 |*    Beschreibung: Um so3 zu helfen
110 *************************************************************************/
111 IUnknown * SotObject::GetInterface( const SvGlobalName & )
112 {
113 	return NULL;
114 }
115 
116 /*************************************************************************
117 |*    SotObject::CastAndAddRef()
118 |*
119 |*    Beschreibung
120 *************************************************************************/
121 void* SotObject::CastAndAddRef( const SotFactory * pFact )
122 {
123 	void * pCast = Cast( pFact );
124 	if( pCast )
125 		AddRef();
126 	return pCast;
127 }
128 
129 //=========================================================================
130 sal_uInt16 SotObject::Lock( sal_Bool bLock )
131 {
132 	SotObjectRef xHoldAlive( this );
133 	sal_uInt16 nRet;
134 	if( bLock )
135 	{
136 		AddRef();
137 		nRet = ++nStrongLockCount;
138 	}
139 	else
140 	{
141 		nRet = --nStrongLockCount;
142 		ReleaseRef();
143 	}
144 
145 	if( !nRet && !nOwnerLockCount )
146 		DoClose();
147 
148 	return nRet;
149 }
150 
151 //=========================================================================
152 void SotObject::OwnerLock
153 (
154 	sal_Bool bLock		/* sal_True, lock. sal_False, unlock. */
155 )
156 /*	[Beschreibung]
157 
158 	Wenn der OwnerLock auf Null dekrementiert, dann wird die Methode
159 	DoClose gerufen. Dies geschieht unabh"angig vom Lock. bzw. RefCount.
160 	Ist der OwnerLock-Z"ahler != Null, dann wird kein DoClose durch
161 	<SotObject::FuzzyLock> gerufen.
162 */
163 {
164 	if( bLock )
165 	{
166 		nOwnerLockCount++;
167 		AddRef();
168 	}
169 	else if ( nOwnerLockCount )
170 	{
171 		if( 0 == --nOwnerLockCount )
172 			DoClose();
173 		ReleaseRef();
174 	}
175 }
176 
177 void SotObject::RemoveOwnerLock()
178 {
179 	if ( nOwnerLockCount )
180 	{
181 		--nOwnerLockCount;
182 		ReleaseRef();
183 	}
184 	else {
185 		DBG_ERROR("OwnerLockCount underflow!");
186     }
187 }
188 
189 //=========================================================================
190 sal_Bool SotObject::DoClose()
191 {
192 	sal_Bool bRet = sal_False;
193 	if( !bInClose )
194 	{
195 		SotObjectRef xHoldAlive( this );
196 		bInClose = sal_True;
197 		bRet = Close();
198 		bInClose = sal_False;
199 	}
200 	return bRet;
201 }
202 
203 //=========================================================================
204 sal_Bool SotObject::Close()
205 {
206 	return sal_True;
207 }
208 
209 
210