1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 //.........................................................................
31 //.........................................................................
33 class OContainerListenerAdapter
;
34 //=====================================================================
35 //= OContainerListener
36 //=====================================================================
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
;
46 OContainerListenerAdapter
* m_pAdapter
;
47 ::osl::Mutex
& m_rMutex
;
50 OContainerListener(::osl::Mutex
& _rMutex
);
51 virtual ~OContainerListener();
53 virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw(::com::sun::star::uno::RuntimeException
);
54 virtual void _elementRemoved( const ::com::sun::star::container::ContainerEvent
& _Event
) throw(::com::sun::star::uno::RuntimeException
);
55 virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw(::com::sun::star::uno::RuntimeException
);
56 virtual void _disposing(const ::com::sun::star::lang::EventObject
& _rSource
) throw( ::com::sun::star::uno::RuntimeException
);
59 void setAdapter(OContainerListenerAdapter
* _pAdapter
);
62 //=====================================================================
63 //= OContainerListenerAdapter
64 //=====================================================================
65 class COMPHELPER_DLLPUBLIC OContainerListenerAdapter
66 :public cppu::WeakImplHelper1
< ::com::sun::star::container::XContainerListener
>
68 friend class OContainerListener
;
71 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainer
>
73 OContainerListener
* m_pListener
;
74 sal_Int32 m_nLockCount
;
76 virtual ~OContainerListenerAdapter();
79 OContainerListenerAdapter(OContainerListener
* _pListener
,
80 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainer
>& _rxContainer
);
83 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
);
86 virtual void SAL_CALL
elementInserted( const ::com::sun::star::container::ContainerEvent
& Event
) throw(::com::sun::star::uno::RuntimeException
);
87 virtual void SAL_CALL
elementRemoved( const ::com::sun::star::container::ContainerEvent
& Event
) throw(::com::sun::star::uno::RuntimeException
);
88 virtual void SAL_CALL
elementReplaced( const ::com::sun::star::container::ContainerEvent
& Event
) throw(::com::sun::star::uno::RuntimeException
);
90 // locking the multiplexer
91 sal_Int32
locked() const { return m_nLockCount
; }
93 /// dispose the object. No multiplexing anymore
96 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainer
>&
97 getContainer() const { return m_xContainer
; }
100 //.........................................................................
102 //.........................................................................
104 #endif // INCLUDED_COMPHELPER_CONTAINERMULTIPLEXER_HXX
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */