Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <svtools/itemdel.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <tools/errcode.hxx>
26 : #include <limits.h>
27 : #include <vector>
28 :
29 : #include <svl/itempool.hxx>
30 :
31 : // STATIC DATA -----------------------------------------------------------
32 :
33 :
34 :
35 :
36 : class SfxItemDesruptor_Impl: private boost::noncopyable
37 : {
38 : SfxPoolItem *pItem;
39 : Link aLink;
40 :
41 : private:
42 : DECL_LINK( Delete, void* );
43 :
44 : public:
45 : SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt );
46 : void LaunchDeleteOnIdle();
47 : ~SfxItemDesruptor_Impl();
48 : };
49 :
50 :
51 0 : SfxItemDesruptor_Impl::SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt ):
52 : pItem(pItemToDesrupt),
53 0 : aLink( LINK(this, SfxItemDesruptor_Impl, Delete) )
54 : {
55 :
56 : DBG_ASSERT( 0 == pItem->GetRefCount(), "disrupting pooled item" );
57 0 : pItem->SetKind( SFX_ITEMS_DELETEONIDLE );
58 0 : }
59 :
60 0 : void SfxItemDesruptor_Impl::LaunchDeleteOnIdle()
61 : {
62 : // process in Idle
63 0 : GetpApp()->InsertIdleHdl( aLink, 1 );
64 0 : }
65 :
66 :
67 0 : SfxItemDesruptor_Impl::~SfxItemDesruptor_Impl()
68 : {
69 :
70 : // remove from Idle-Handler
71 0 : GetpApp()->RemoveIdleHdl( aLink );
72 :
73 : // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
74 0 : pItem->SetRefCount( 0 );
75 :
76 0 : delete pItem;
77 0 : }
78 :
79 :
80 0 : IMPL_LINK_NOARG(SfxItemDesruptor_Impl, Delete)
81 : {
82 0 : delete this;
83 0 : return 0;
84 : }
85 :
86 0 : void DeleteItemOnIdle(SfxPoolItem* pItem)
87 : {
88 : DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" );
89 0 : SfxItemDesruptor_Impl *pDesruptor = new SfxItemDesruptor_Impl(pItem);
90 0 : pDesruptor->LaunchDeleteOnIdle();
91 0 : }
92 :
93 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|