Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / comphelper / containermultiplexer.hxx
blob0a3729a5809b718f833d42f40644cc3a5e12961e
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 #ifndef INCLUDED_COMPHELPER_CONTAINERMULTIPLEXER_HXX
21 #define INCLUDED_COMPHELPER_CONTAINERMULTIPLEXER_HXX
23 #include <com/sun/star/container/XContainer.hpp>
24 #include <cppuhelper/implbase.hxx>
25 #include <osl/mutex.hxx>
26 #include <comphelper/comphelperdllapi.h>
27 #include <rtl/ref.hxx>
30 namespace comphelper
34 class OContainerListenerAdapter;
36 //= OContainerListener
38 /** a non-UNO container listener
39 <p>Useful if you have a non-refcountable class which should act as container listener.<br/>
40 In this case, derive this class from OContainerListener, and create an adapter
41 OContainerListenerAdapter which multiplexes the changes.</p>
43 class COMPHELPER_DLLPUBLIC OContainerListener
45 friend class OContainerListenerAdapter;
46 protected:
47 rtl::Reference<OContainerListenerAdapter> m_xAdapter;
48 ::osl::Mutex& m_rMutex;
50 public:
51 OContainerListener(::osl::Mutex& _rMutex);
52 virtual ~OContainerListener();
54 /// @throws css::uno::RuntimeException
55 virtual void _elementInserted( const css::container::ContainerEvent& _rEvent );
56 /// @throws css::uno::RuntimeException
57 virtual void _elementRemoved( const css::container::ContainerEvent& _rEvent );
58 /// @throws css::uno::RuntimeException
59 virtual void _elementReplaced( const css::container::ContainerEvent& _rEvent );
60 /// @throws css::uno::RuntimeException
61 virtual void _disposing(const css::lang::EventObject& _rSource);
63 protected:
64 void setAdapter(OContainerListenerAdapter* _pAdapter);
67 class COMPHELPER_DLLPUBLIC OContainerListenerAdapter
68 : public cppu::WeakImplHelper<css::container::XContainerListener>
70 friend class OContainerListener;
72 private:
73 css::uno::Reference< css::container::XContainer >
74 m_xContainer;
75 OContainerListener* m_pListener;
77 virtual ~OContainerListenerAdapter() override;
79 public:
80 OContainerListenerAdapter(OContainerListener* _pListener,
81 const css::uno::Reference< css::container::XContainer >& _rxContainer);
83 // XEventListener
84 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
86 // XContainerListener
87 virtual void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) override;
88 virtual void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override;
89 virtual void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) override;
91 /// dispose the object. No multiplexing anymore
92 void dispose();
97 } // namespace dbaui
100 #endif // INCLUDED_COMPHELPER_CONTAINERMULTIPLEXER_HXX
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */