Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svl/listener.hxx>
21 : #include <svl/broadcast.hxx>
22 :
23 56 : SvtListener::QueryBase::QueryBase( sal_uInt16 nId ) : mnId(nId) {}
24 56 : SvtListener::QueryBase::~QueryBase() {}
25 :
26 109 : sal_uInt16 SvtListener::QueryBase::getId() const
27 : {
28 109 : return mnId;
29 : }
30 :
31 15853 : SvtListener::SvtListener() {}
32 :
33 0 : SvtListener::SvtListener( const SvtListener &r ) :
34 0 : maBroadcasters(r.maBroadcasters) {}
35 :
36 30368 : SvtListener::~SvtListener()
37 : {
38 : // Unregister itself from all broadcasters it's listening to.
39 15184 : EndListeningAll();
40 15184 : }
41 :
42 : // registeres at a specific SvtBroadcaster
43 :
44 21609 : bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
45 : {
46 : std::pair<BroadcastersType::iterator, bool> r =
47 21609 : maBroadcasters.insert(&rBroadcaster);
48 21609 : if (r.second)
49 : {
50 : // This is a new broadcaster.
51 20445 : rBroadcaster.Add(this);
52 : }
53 21609 : return r.second;
54 : }
55 :
56 7342 : bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
57 : {
58 7342 : BroadcastersType::iterator it = maBroadcasters.find(&rBroadcaster);
59 7342 : if (it == maBroadcasters.end())
60 : // Not listening to this broadcaster.
61 1519 : return false;
62 :
63 5823 : rBroadcaster.Remove(this);
64 5823 : maBroadcasters.erase(it);
65 5823 : return true;
66 : }
67 :
68 19297 : void SvtListener::EndListeningAll()
69 : {
70 19297 : BroadcastersType::iterator it = maBroadcasters.begin(), itEnd = maBroadcasters.end();
71 33741 : for (; it != itEnd; ++it)
72 : {
73 14444 : SvtBroadcaster& rBC = **it;
74 14444 : rBC.Remove(this);
75 : }
76 19297 : maBroadcasters.clear();
77 19297 : }
78 :
79 :
80 0 : bool SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const
81 : {
82 0 : return maBroadcasters.count(&rBroadcaster) > 0;
83 : }
84 :
85 186 : void SvtListener::CopyAllBroadcasters( const SvtListener& r )
86 : {
87 186 : BroadcastersType aCopy(r.maBroadcasters);
88 186 : maBroadcasters.swap(aCopy);
89 186 : BroadcastersType::iterator it = maBroadcasters.begin(), itEnd = maBroadcasters.end();
90 334 : for (; it != itEnd; ++it)
91 : {
92 148 : SvtBroadcaster* p = *it;
93 148 : p->Add(this);
94 186 : }
95 186 : }
96 :
97 2379 : bool SvtListener::HasBroadcaster() const
98 : {
99 2379 : return !maBroadcasters.empty();
100 : }
101 :
102 0 : void SvtListener::Notify( const SfxHint& /*rHint*/ ) {}
103 :
104 0 : void SvtListener::Query( QueryBase& /*rQuery*/ ) const {}
105 :
106 :
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|