Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / svl / source / notify / listener.cxx
blob6b1be0ca20b453fe3717924f9ecf4b6225febd83
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 <svl/listener.hxx>
21 #include <svl/broadcast.hxx>
23 SvtListener::~SvtListener() COVERITY_NOEXCEPT_FALSE
25 // Unregister itself from all broadcasters it's listening to.
26 EndListeningAll();
29 // registers at a specific SvtBroadcaster
31 bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
33 std::pair<BroadcastersType::const_iterator, bool> r =
34 maBroadcasters.insert(&rBroadcaster);
35 if (r.second)
37 // This is a new broadcaster.
38 rBroadcaster.Add(this);
40 return r.second;
43 void SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
45 BroadcastersType::const_iterator it = maBroadcasters.find(&rBroadcaster);
46 if (it == maBroadcasters.end())
47 // Not listening to this broadcaster.
48 return;
49 maBroadcasters.erase(it);
51 rBroadcaster.Remove(this);
54 // called from the SvtBroadcaster destructor, used to avoid calling
55 // back into the broadcaster again
56 void SvtListener::BroadcasterDying( SvtBroadcaster& rBroadcaster )
58 BroadcastersType::const_iterator it = maBroadcasters.find(&rBroadcaster);
59 if (it != maBroadcasters.end())
60 maBroadcasters.erase(it);
63 void SvtListener::EndListeningAll()
65 for (SvtBroadcaster* p : maBroadcasters)
67 SvtBroadcaster& rBC = *p;
68 rBC.Remove(this);
70 maBroadcasters.clear();
74 void SvtListener::CopyAllBroadcasters( const SvtListener& r )
76 EndListeningAll();
77 BroadcastersType aCopy(r.maBroadcasters);
78 maBroadcasters.swap(aCopy);
79 for (SvtBroadcaster* p : maBroadcasters)
81 p->Add(this);
85 void SvtListener::Notify( const SfxHint& /*rHint*/ ) {}
87 void SvtListener::Query( QueryBase& /*rQuery*/ ) const {}
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */