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: itemdel.cxx,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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include "itemdel.hxx"
35 #include <vcl/svapp.hxx>
36 #include <tools/errcode.hxx>
39 #include <svtools/svtdata.hxx>
40 #include <svtools/svarray.hxx>
41 #include <svtools/itempool.hxx>
43 // STATIC DATA -----------------------------------------------------------
45 DBG_NAME(SfxItemDesruptor_Impl
);
47 // -----------------------------------------------------------------------
49 class SfxItemDesruptor_Impl
55 DECL_LINK( Delete
, void * );
56 SfxItemDesruptor_Impl( const SfxItemDesruptor_Impl
& ); // n.i.
59 SfxItemDesruptor_Impl( SfxPoolItem
*pItemToDesrupt
);
60 ~SfxItemDesruptor_Impl();
63 SV_DECL_PTRARR( SfxItemDesruptorList_Impl
, SfxItemDesruptor_Impl
*, 4, 4 )
65 // ------------------------------------------------------------------------
66 SfxItemDesruptor_Impl::SfxItemDesruptor_Impl( SfxPoolItem
*pItemToDesrupt
):
67 pItem(pItemToDesrupt
),
68 aLink( LINK(this, SfxItemDesruptor_Impl
, Delete
) )
70 DBG_CTOR(SfxItemDesruptor_Impl
, 0);
72 DBG_ASSERT( 0 == pItem
->GetRefCount(), "desrupting pooled item" );
73 pItem
->SetKind( SFX_ITEMS_DELETEONIDLE
);
76 GetpApp()->InsertIdleHdl( aLink
, 1 );
78 // und in Liste eintragen (damit geflusht werden kann)
79 SfxItemDesruptorList_Impl
* &rpList
= ImpSvtData::GetSvtData().pItemDesruptList
;
81 rpList
= new SfxItemDesruptorList_Impl
;
82 const SfxItemDesruptor_Impl
*pThis
= this;
83 rpList
->Insert( pThis
, rpList
->Count() );
86 // ------------------------------------------------------------------------
87 SfxItemDesruptor_Impl::~SfxItemDesruptor_Impl()
89 DBG_DTOR(SfxItemDesruptor_Impl
, 0);
91 // aus Idle-Handler austragen
92 GetpApp()->RemoveIdleHdl( aLink
);
94 // und aus Liste austragen
95 SfxItemDesruptorList_Impl
* &rpList
= ImpSvtData::GetSvtData().pItemDesruptList
;
96 DBG_ASSERT( rpList
, "no DesruptorList" );
97 const SfxItemDesruptor_Impl
*pThis
= this;
98 if ( rpList
) HACK(warum
?)
99 rpList
->Remove( rpList
->GetPos(pThis
) );
101 // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
102 pItem
->SetRefCount( 0 );
103 //DBG_CHKOBJ( pItem, SfxPoolItem, 0 );
107 // ------------------------------------------------------------------------
108 IMPL_LINK( SfxItemDesruptor_Impl
, Delete
, void *, EMPTYARG
)
110 {DBG_CHKTHIS(SfxItemDesruptor_Impl
, 0);}
115 // ------------------------------------------------------------------------
116 SfxPoolItem
* DeleteItemOnIdle( SfxPoolItem
* pItem
)
118 DBG_ASSERT( 0 == pItem
->GetRefCount(), "deleting item in use" );
119 new SfxItemDesruptor_Impl( pItem
);
123 // ------------------------------------------------------------------------
124 void DeleteOnIdleItems()
126 SfxItemDesruptorList_Impl
* &rpList
127 = ImpSvtData::GetSvtData().pItemDesruptList
;
131 while ( 0 != ( n
= rpList
->Count() ) )
132 // Remove ist implizit im Dtor
133 delete rpList
->GetObject( n
-1 );