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_svtools.hxx" 30 31 #include <svtools/itemdel.hxx> 32 #include <vcl/svapp.hxx> 33 #include <tools/errcode.hxx> 34 #include <limits.h> 35 36 #include <svtools/svtdata.hxx> 37 #include <svl/svarray.hxx> 38 #include <svl/itempool.hxx> 39 40 // STATIC DATA ----------------------------------------------------------- 41 42 DBG_NAME(SfxItemDesruptor_Impl); 43 44 // ----------------------------------------------------------------------- 45 46 class SfxItemDesruptor_Impl 47 { 48 SfxPoolItem *pItem; 49 Link aLink; 50 51 private: 52 DECL_LINK( Delete, void * ); 53 SfxItemDesruptor_Impl( const SfxItemDesruptor_Impl& ); // n.i. 54 55 public: 56 SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt ); 57 ~SfxItemDesruptor_Impl(); 58 }; 59 60 SV_DECL_PTRARR( SfxItemDesruptorList_Impl, SfxItemDesruptor_Impl*, 4, 4 ) 61 62 // ------------------------------------------------------------------------ 63 SfxItemDesruptor_Impl::SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt ): 64 pItem(pItemToDesrupt), 65 aLink( LINK(this, SfxItemDesruptor_Impl, Delete) ) 66 { 67 DBG_CTOR(SfxItemDesruptor_Impl, 0); 68 69 DBG_ASSERT( 0 == pItem->GetRefCount(), "desrupting pooled item" ); 70 pItem->SetKind( SFX_ITEMS_DELETEONIDLE ); 71 72 // im Idle abarbeiten 73 GetpApp()->InsertIdleHdl( aLink, 1 ); 74 75 // und in Liste eintragen (damit geflusht werden kann) 76 SfxItemDesruptorList_Impl* &rpList = ImpSvtData::GetSvtData().pItemDesruptList; 77 if ( !rpList ) 78 rpList = new SfxItemDesruptorList_Impl; 79 const SfxItemDesruptor_Impl *pThis = this; 80 rpList->Insert( pThis, rpList->Count() ); 81 } 82 83 // ------------------------------------------------------------------------ 84 SfxItemDesruptor_Impl::~SfxItemDesruptor_Impl() 85 { 86 DBG_DTOR(SfxItemDesruptor_Impl, 0); 87 88 // aus Idle-Handler austragen 89 GetpApp()->RemoveIdleHdl( aLink ); 90 91 // und aus Liste austragen 92 SfxItemDesruptorList_Impl* &rpList = ImpSvtData::GetSvtData().pItemDesruptList; 93 DBG_ASSERT( rpList, "no DesruptorList" ); 94 const SfxItemDesruptor_Impl *pThis = this; 95 if ( rpList ) HACK(warum?) 96 rpList->Remove( rpList->GetPos(pThis) ); 97 98 // reset RefCount (was set to SFX_ITEMS_SPECIAL before!) 99 pItem->SetRefCount( 0 ); 100 //DBG_CHKOBJ( pItem, SfxPoolItem, 0 ); 101 delete pItem; 102 } 103 104 // ------------------------------------------------------------------------ 105 IMPL_LINK( SfxItemDesruptor_Impl, Delete, void *, EMPTYARG ) 106 { 107 {DBG_CHKTHIS(SfxItemDesruptor_Impl, 0);} 108 delete this; 109 return 0; 110 } 111 112 // ------------------------------------------------------------------------ 113 SfxPoolItem* DeleteItemOnIdle( SfxPoolItem* pItem ) 114 { 115 DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" ); 116 new SfxItemDesruptor_Impl( pItem ); 117 return pItem; 118 } 119 120 // ------------------------------------------------------------------------ 121 void DeleteOnIdleItems() 122 { 123 SfxItemDesruptorList_Impl* &rpList 124 = ImpSvtData::GetSvtData().pItemDesruptList; 125 if ( rpList ) 126 { 127 sal_uInt16 n; 128 while ( 0 != ( n = rpList->Count() ) ) 129 // Remove ist implizit im Dtor 130 delete rpList->GetObject( n-1 ); 131 DELETEZ(rpList); 132 } 133 } 134 135 136