bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svl / source / notify / listener.cxx
blob38856a835d4f10fa7f60b8df7552d2bd3589dd3a
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>
22 #include <cassert>
24 SvtListener::QueryBase::QueryBase( sal_uInt16 nId ) : mnId(nId) {}
25 SvtListener::QueryBase::~QueryBase() {}
27 sal_uInt16 SvtListener::QueryBase::getId() const
29 return mnId;
32 SvtListener::SvtListener() {}
34 SvtListener::SvtListener( const SvtListener & ) {}
36 SvtListener::~SvtListener() COVERITY_NOEXCEPT_FALSE
38 // Unregister itself from all broadcasters it's listening to.
39 EndListeningAll();
42 // registers at a specific SvtBroadcaster
44 bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
46 std::pair<BroadcastersType::const_iterator, bool> r =
47 maBroadcasters.insert(&rBroadcaster);
48 if (r.second)
50 // This is a new broadcaster.
51 rBroadcaster.Add(this);
53 return r.second;
56 bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
58 BroadcastersType::const_iterator it = maBroadcasters.find(&rBroadcaster);
59 if (it == maBroadcasters.end())
60 // Not listening to this broadcaster.
61 return false;
63 rBroadcaster.Remove(this);
64 maBroadcasters.erase(it);
65 return true;
68 // called from the SvtBroadcaster destructor, used to avoid calling
69 // back into the broadcaster again
70 void SvtListener::BroadcasterDying( SvtBroadcaster& rBroadcaster )
72 BroadcastersType::const_iterator it = maBroadcasters.find(&rBroadcaster);
73 if (it != maBroadcasters.end())
74 maBroadcasters.erase(it);
77 void SvtListener::EndListeningAll()
79 for (SvtBroadcaster* p : maBroadcasters)
81 SvtBroadcaster& rBC = *p;
82 rBC.Remove(this);
84 maBroadcasters.clear();
88 void SvtListener::CopyAllBroadcasters( const SvtListener& r )
90 EndListeningAll();
91 BroadcastersType aCopy(r.maBroadcasters);
92 maBroadcasters.swap(aCopy);
93 for (SvtBroadcaster* p : maBroadcasters)
95 p->Add(this);
99 bool SvtListener::HasBroadcaster() const
101 return !maBroadcasters.empty();
104 void SvtListener::Notify( const SfxHint& /*rHint*/ ) {}
106 void SvtListener::Query( QueryBase& /*rQuery*/ ) const {}
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */