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 "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 : class SfxItemDisruptor_Impl: private boost::noncopyable
32 : {
33 : SfxPoolItem *pItem;
34 : Link aLink;
35 :
36 : private:
37 : DECL_LINK( Delete, void* );
38 :
39 : public:
40 : SfxItemDisruptor_Impl( SfxPoolItem *pItemToDesrupt );
41 : void LaunchDeleteOnIdle();
42 : ~SfxItemDisruptor_Impl();
43 : };
44 :
45 137959 : SfxItemDisruptor_Impl::SfxItemDisruptor_Impl( SfxPoolItem *pItemToDesrupt ):
46 : pItem(pItemToDesrupt),
47 137959 : aLink( LINK(this, SfxItemDisruptor_Impl, Delete) )
48 : {
49 :
50 : DBG_ASSERT( 0 == pItem->GetRefCount(), "disrupting pooled item" );
51 137959 : pItem->SetKind( SFX_ITEMS_DELETEONIDLE );
52 137959 : }
53 :
54 137959 : void SfxItemDisruptor_Impl::LaunchDeleteOnIdle()
55 : {
56 : // process in Idle
57 137959 : Application::InsertIdleHdl( aLink, 1 );
58 137959 : }
59 :
60 137957 : SfxItemDisruptor_Impl::~SfxItemDisruptor_Impl()
61 : {
62 :
63 : // remove from Idle-Handler
64 137957 : Application::RemoveIdleHdl( aLink );
65 :
66 : // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
67 137957 : pItem->SetRefCount( 0 );
68 :
69 137957 : delete pItem;
70 137957 : }
71 :
72 275914 : IMPL_LINK_NOARG(SfxItemDisruptor_Impl, Delete)
73 : {
74 137957 : delete this;
75 137957 : return 0;
76 : }
77 :
78 137959 : void DeleteItemOnIdle(SfxPoolItem* pItem)
79 : {
80 : DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" );
81 137959 : SfxItemDisruptor_Impl *pDesruptor = new SfxItemDisruptor_Impl(pItem);
82 137959 : pDesruptor->LaunchDeleteOnIdle();
83 138910 : }
84 :
85 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|