update credits
[LibreOffice.git] / include / comphelper / containermultiplexer.hxx
blob97fff52d653f3e115ca123ee30f5dd3a40a5f105
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/implbase1.hxx>
25 #include <osl/mutex.hxx>
26 #include <comphelper/comphelperdllapi.h>
29 namespace comphelper
33 class OContainerListenerAdapter;
35 //= OContainerListener
37 /** a non-UNO container listener
38 <p>Useful if you have a non-refcountable class which should act as container listener.<br/>
39 In this case, derive this class from OContainerListener, and create an adapter
40 OContainerListenerAdapter which multiplexes the changes.</p>
42 class COMPHELPER_DLLPUBLIC OContainerListener
44 friend class OContainerListenerAdapter;
45 protected:
46 OContainerListenerAdapter* m_pAdapter;
47 ::osl::Mutex& m_rMutex;
49 public:
50 OContainerListener(::osl::Mutex& _rMutex);
51 virtual ~OContainerListener();
53 virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent )
54 throw (::com::sun::star::uno::RuntimeException,
55 std::exception);
56 virtual void _elementRemoved( const ::com::sun::star::container::ContainerEvent& _Event )
57 throw (::com::sun::star::uno::RuntimeException,
58 std::exception);
59 virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent )
60 throw (::com::sun::star::uno::RuntimeException,
61 std::exception);
62 virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource)
63 throw (::com::sun::star::uno::RuntimeException,
64 std::exception);
66 protected:
67 void setAdapter(OContainerListenerAdapter* _pAdapter);
71 //= OContainerListenerAdapter
73 class COMPHELPER_DLLPUBLIC OContainerListenerAdapter
74 :public cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener >
76 friend class OContainerListener;
78 protected:
79 ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >
80 m_xContainer;
81 OContainerListener* m_pListener;
82 sal_Int32 m_nLockCount;
84 virtual ~OContainerListenerAdapter();
86 public:
87 OContainerListenerAdapter(OContainerListener* _pListener,
88 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _rxContainer);
90 // XEventListener
91 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 // XContainerListener
94 virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
95 virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
96 virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 // locking the multiplexer
99 sal_Int32 locked() const { return m_nLockCount; }
101 /// dispose the object. No multiplexing anymore
102 void dispose();
104 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >&
105 getContainer() const { return m_xContainer; }
109 } // namespace dbaui
112 #endif // INCLUDED_COMPHELPER_CONTAINERMULTIPLEXER_HXX
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */