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