xref: /AOO41X/main/svtools/source/misc/itemdel.cxx (revision 5900e8ec128faec89519683efce668ccd8cc6084)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svtools/itemdel.hxx>
28cdf0e10cSrcweir #include <vcl/svapp.hxx>
29cdf0e10cSrcweir #include <tools/errcode.hxx>
30cdf0e10cSrcweir #include <limits.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <svtools/svtdata.hxx>
33cdf0e10cSrcweir #include <svl/svarray.hxx>
34cdf0e10cSrcweir #include <svl/itempool.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
37cdf0e10cSrcweir 
38cdf0e10cSrcweir DBG_NAME(SfxItemDesruptor_Impl);
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // -----------------------------------------------------------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class SfxItemDesruptor_Impl
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	SfxPoolItem *pItem;
45cdf0e10cSrcweir 	Link		 aLink;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir private:
48cdf0e10cSrcweir 				 DECL_LINK( Delete, void * );
49cdf0e10cSrcweir 				 SfxItemDesruptor_Impl( const SfxItemDesruptor_Impl& ); // n.i.
50cdf0e10cSrcweir 
51cdf0e10cSrcweir public:
52cdf0e10cSrcweir 				 SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt );
53cdf0e10cSrcweir 				 ~SfxItemDesruptor_Impl();
54cdf0e10cSrcweir };
55cdf0e10cSrcweir 
56cdf0e10cSrcweir SV_DECL_PTRARR( SfxItemDesruptorList_Impl, SfxItemDesruptor_Impl*, 4, 4 )
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // ------------------------------------------------------------------------
SfxItemDesruptor_Impl(SfxPoolItem * pItemToDesrupt)59cdf0e10cSrcweir SfxItemDesruptor_Impl::SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt ):
60cdf0e10cSrcweir 	pItem(pItemToDesrupt),
61cdf0e10cSrcweir 	aLink( LINK(this, SfxItemDesruptor_Impl, Delete) )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	DBG_CTOR(SfxItemDesruptor_Impl, 0);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	DBG_ASSERT( 0 == pItem->GetRefCount(), "desrupting pooled item" );
66cdf0e10cSrcweir 	pItem->SetKind( SFX_ITEMS_DELETEONIDLE );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	// im Idle abarbeiten
69cdf0e10cSrcweir 	GetpApp()->InsertIdleHdl( aLink, 1 );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	// und in Liste eintragen (damit geflusht werden kann)
72cdf0e10cSrcweir 	SfxItemDesruptorList_Impl* &rpList = ImpSvtData::GetSvtData().pItemDesruptList;
73cdf0e10cSrcweir 	if ( !rpList )
74cdf0e10cSrcweir 		rpList = new SfxItemDesruptorList_Impl;
75cdf0e10cSrcweir 	const SfxItemDesruptor_Impl *pThis = this;
76cdf0e10cSrcweir 	rpList->Insert( pThis, rpList->Count() );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // ------------------------------------------------------------------------
~SfxItemDesruptor_Impl()80cdf0e10cSrcweir SfxItemDesruptor_Impl::~SfxItemDesruptor_Impl()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	DBG_DTOR(SfxItemDesruptor_Impl, 0);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// aus Idle-Handler austragen
85cdf0e10cSrcweir 	GetpApp()->RemoveIdleHdl( aLink );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	// und aus Liste austragen
88cdf0e10cSrcweir 	SfxItemDesruptorList_Impl* &rpList = ImpSvtData::GetSvtData().pItemDesruptList;
89cdf0e10cSrcweir 	DBG_ASSERT( rpList, "no DesruptorList" );
90cdf0e10cSrcweir 	const SfxItemDesruptor_Impl *pThis = this;
91cdf0e10cSrcweir 	if ( rpList ) HACK(warum?)
92cdf0e10cSrcweir 		rpList->Remove( rpList->GetPos(pThis) );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	// reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
95cdf0e10cSrcweir 	pItem->SetRefCount( 0 );
96cdf0e10cSrcweir     //DBG_CHKOBJ( pItem, SfxPoolItem, 0 );
97cdf0e10cSrcweir 	delete pItem;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // ------------------------------------------------------------------------
IMPL_LINK(SfxItemDesruptor_Impl,Delete,void *,EMPTYARG)101cdf0e10cSrcweir IMPL_LINK( SfxItemDesruptor_Impl, Delete, void *, EMPTYARG )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	{DBG_CHKTHIS(SfxItemDesruptor_Impl, 0);}
104cdf0e10cSrcweir 	delete this;
105cdf0e10cSrcweir 	return 0;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // ------------------------------------------------------------------------
DeleteItemOnIdle(SfxPoolItem * pItem)109cdf0e10cSrcweir SfxPoolItem* DeleteItemOnIdle( SfxPoolItem* pItem )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" );
112cdf0e10cSrcweir 	new SfxItemDesruptor_Impl( pItem );
113cdf0e10cSrcweir 	return pItem;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir // ------------------------------------------------------------------------
DeleteOnIdleItems()117cdf0e10cSrcweir void DeleteOnIdleItems()
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	SfxItemDesruptorList_Impl* &rpList
120cdf0e10cSrcweir 	 = ImpSvtData::GetSvtData().pItemDesruptList;
121cdf0e10cSrcweir 	if ( rpList )
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		sal_uInt16 n;
124cdf0e10cSrcweir 		while ( 0 != ( n = rpList->Count() ) )
125cdf0e10cSrcweir 			// Remove ist implizit im Dtor
126cdf0e10cSrcweir 			delete rpList->GetObject( n-1 );
127cdf0e10cSrcweir 		DELETEZ(rpList);
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 
132