LibreOffice Module sw (master) 1
deletelistener.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10#pragma once
11
12#include <svl/listener.hxx>
13#include <svl/lstner.hxx>
14#include "calbck.hxx"
15
16class SwDeleteListener final : public SwClient
17{
18private:
20
21 virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override
22 {
23 if (rHint.GetId() != SfxHintId::SwLegacyModify)
24 return;
25 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
26 if (pLegacy->GetWhich() == RES_OBJECTDYING)
27 {
28 m_pModify->Remove(this);
29 m_pModify = nullptr;
30 }
31 }
32
33public:
35 : m_pModify(&rModify)
36 {
37 m_pModify->Add(this);
38 }
39
40 bool WasDeleted() const { return !m_pModify; }
41
42 virtual ~SwDeleteListener() override
43 {
44 if (!m_pModify)
45 return;
46 m_pModify->Remove(this);
47 }
48};
49
50class SvtDeleteListener final : public SvtListener
51{
52private:
54
55public:
56 explicit SvtDeleteListener(SvtBroadcaster& rNotifier)
57 : m_bObjectDeleted(false)
58 {
59 StartListening(rNotifier);
60 }
61
62 virtual void Notify(const SfxHint& rHint) override
63 {
64 if (rHint.GetId() == SfxHintId::Dying)
65 m_bObjectDeleted = true;
66 }
67
68 bool WasDeleted() const { return m_bObjectDeleted; }
69};
70
71class SfxDeleteListener final : public SfxListener
72{
73private:
75
76public:
77 explicit SfxDeleteListener(SfxBroadcaster& rNotifier)
78 : m_bObjectDeleted(false)
79 {
80 StartListening(rNotifier);
81 }
82
83 virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override
84 {
85 if (rHint.GetId() == SfxHintId::Dying)
86 m_bObjectDeleted = true;
87 }
88
89 bool WasDeleted() const { return m_bObjectDeleted; }
90};
91
92/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
SfxDeleteListener(SfxBroadcaster &rNotifier)
virtual void Notify(SfxBroadcaster &, const SfxHint &rHint) override
bool WasDeleted() const
SfxHintId GetId() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
bool WasDeleted() const
SvtDeleteListener(SvtBroadcaster &rNotifier)
virtual void Notify(const SfxHint &rHint) override
bool StartListening(SvtBroadcaster &rBroadcaster)
SwModify * m_pModify
SwDeleteListener(SwModify &rModify)
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
bool WasDeleted() const
virtual ~SwDeleteListener() override
void Add(SwClient *pDepend)
Definition: calbck.cxx:172
SwClient * Remove(SwClient *pDepend)
Definition: calbck.cxx:225
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_MSG_BEGIN)