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_BRDCST_HXX
20 : #define INCLUDED_SVL_BRDCST_HXX
21 :
22 : #include <svl/svldllapi.h>
23 : #include <tools/rtti.hxx>
24 : #include <vector>
25 :
26 : class SfxListener;
27 : class SfxHint;
28 : class SfxBroadcasterTest;
29 :
30 : class SVL_DLLPUBLIC SfxBroadcaster
31 : {
32 : typedef std::vector<SfxListener*> SfxListenerArr_Impl;
33 :
34 : /** Contains the positions of removed listeners. */
35 : std::vector<size_t> m_RemovedPositions;
36 : SfxListenerArr_Impl m_Listeners;
37 :
38 : private:
39 : void AddListener( SfxListener& rListener );
40 : void RemoveListener( SfxListener& rListener );
41 : const SfxBroadcaster& operator=(const SfxBroadcaster &); // verboten
42 :
43 : protected:
44 : void Forward(SfxBroadcaster& rBC, const SfxHint& rHint);
45 : virtual void ListenersGone();
46 :
47 : public:
48 : TYPEINFO();
49 :
50 : SfxBroadcaster();
51 : SfxBroadcaster( const SfxBroadcaster &rBC );
52 : virtual ~SfxBroadcaster();
53 :
54 : void Broadcast( const SfxHint &rHint );
55 : bool HasListeners() const;
56 :
57 : /** Get the number of listeners which are registered at this broadcaster */
58 : size_t GetListenerCount() const;
59 :
60 : /** Get the size of the internally stored vector.
61 : * Use it to iterate over all listeners.
62 : */
63 185406 : size_t GetSizeOfVector() const {
64 185406 : return m_Listeners.size();
65 : }
66 :
67 : /** Get a listener by its position in the internally stored vector.
68 : * Note that this method may return NULL
69 : */
70 2173368 : SfxListener* GetListener( size_t nNo ) const {
71 2173368 : return m_Listeners[nNo];
72 : }
73 :
74 : friend class SfxListener;
75 : friend class ::SfxBroadcasterTest;
76 : };
77 :
78 : #endif
79 :
80 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|