bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / control / itemdel.cxx
blob9166d4b14ff50e83b95c7e1456d0a121b2b0bdaf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
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>
29 #include <svl/itempool.hxx>
31 class SfxItemDisruptor_Impl: private boost::noncopyable
33 SfxPoolItem *pItem;
34 Link<> aLink;
36 private:
37 DECL_LINK( Delete, void* );
39 public:
40 SfxItemDisruptor_Impl( SfxPoolItem *pItemToDesrupt );
41 void LaunchDeleteOnIdle();
42 ~SfxItemDisruptor_Impl();
45 SfxItemDisruptor_Impl::SfxItemDisruptor_Impl( SfxPoolItem *pItemToDesrupt ):
46 pItem(pItemToDesrupt),
47 aLink( LINK(this, SfxItemDisruptor_Impl, Delete) )
50 DBG_ASSERT( 0 == pItem->GetRefCount(), "disrupting pooled item" );
51 pItem->SetKind( SFX_ITEMS_DELETEONIDLE );
54 void SfxItemDisruptor_Impl::LaunchDeleteOnIdle()
56 // process in Idle
57 Application::InsertIdleHdl( aLink, 1 );
60 SfxItemDisruptor_Impl::~SfxItemDisruptor_Impl()
63 // remove from Idle-Handler
64 Application::RemoveIdleHdl( aLink );
66 // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
67 pItem->SetRefCount( 0 );
69 delete pItem;
72 IMPL_LINK_NOARG(SfxItemDisruptor_Impl, Delete)
74 delete this;
75 return 0;
78 void DeleteItemOnIdle(SfxPoolItem* pItem)
80 DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" );
81 SfxItemDisruptor_Impl *pDesruptor = new SfxItemDisruptor_Impl(pItem);
82 pDesruptor->LaunchDeleteOnIdle();
83 // coverity[leaked_storage] pDesruptor takes care of its own destruction at idle time
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */