1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 SvtListener::QueryBase::QueryBase( sal_uInt16 nId
) : mnId(nId
) {}
25 SvtListener::QueryBase::~QueryBase() {}
27 sal_uInt16
SvtListener::QueryBase::getId() const
32 SvtListener::SvtListener() {}
34 SvtListener::SvtListener( const SvtListener
& ) {}
36 SvtListener::~SvtListener() COVERITY_NOEXCEPT_FALSE
38 // Unregister itself from all broadcasters it's listening to.
42 // registers at a specific SvtBroadcaster
44 bool SvtListener::StartListening( SvtBroadcaster
& rBroadcaster
)
46 std::pair
<BroadcastersType::const_iterator
, bool> r
=
47 maBroadcasters
.insert(&rBroadcaster
);
50 // This is a new broadcaster.
51 rBroadcaster
.Add(this);
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.
63 rBroadcaster
.Remove(this);
64 maBroadcasters
.erase(it
);
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
;
84 maBroadcasters
.clear();
88 void SvtListener::CopyAllBroadcasters( const SvtListener
& r
)
91 BroadcastersType
aCopy(r
.maBroadcasters
);
92 maBroadcasters
.swap(aCopy
);
93 for (SvtBroadcaster
* p
: maBroadcasters
)
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: */