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 : #ifndef INCLUDED_SVL_BROADCAST_HXX
20 : #define INCLUDED_SVL_BROADCAST_HXX
21 :
22 : #include <svl/svldllapi.h>
23 :
24 : #include <vector>
25 :
26 : class SvtListener;
27 : class SfxHint;
28 :
29 : class SVL_DLLPUBLIC SvtBroadcaster
30 : {
31 : public:
32 : friend class SvtListener;
33 :
34 : typedef std::vector<SvtListener*> ListenersType;
35 :
36 : private:
37 : const SvtBroadcaster& operator=(const SvtBroadcaster &); // verboten
38 :
39 : /**
40 : * Ensure that the container doesn't contain any duplicated listener
41 : * entries. As a side effect, the listeners get sorted by pointer values
42 : * after this call.
43 : */
44 : void Normalize();
45 :
46 : void Add( SvtListener* p );
47 : void Remove( SvtListener* p );
48 :
49 : protected:
50 : virtual void ListenersGone();
51 :
52 : public:
53 : SvtBroadcaster();
54 : SvtBroadcaster( const SvtBroadcaster &rBC );
55 : virtual ~SvtBroadcaster();
56 :
57 : void Broadcast( const SfxHint &rHint );
58 :
59 298 : ListenersType& GetAllListeners() { return maListeners;}
60 :
61 : bool HasListeners() const;
62 :
63 : /**
64 : * Listeners and broadcasters are M:N relationship. If you want to
65 : * destruct them, you easily end up in O(M*N) situation; where for every
66 : * listener, you iterate all broadcasters, to remove that one listener.
67 : *
68 : * To avoid that, use this call to announce to the broadcaster it is going
69 : * to die, and the listeners do not have to bother with removing
70 : * themselves from the broadcaster - the broadcaster will not broadcast
71 : * anything after the PrepareForDesctruction() call anyway.
72 : */
73 : void PrepareForDestruction();
74 :
75 : private:
76 : ListenersType maListeners;
77 :
78 : /// When the broadcaster is about to die, collect listeners that asked for removal.
79 : ListenersType maDestructedListeners;
80 :
81 : /// Indicate that this broadcaster will be destructed (we indicate this on all ScColumn's broadcasters during the ScTable destruction, eg.)
82 : bool mbAboutToDie:1;
83 : bool mbDisposing:1;
84 : bool mbNormalized:1;
85 : bool mbDestNormalized:1;
86 : };
87 :
88 :
89 : #endif
90 :
91 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|