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/XContainerListener.hpp>
24 #include <cppuhelper/implbase.hxx>
25 #include <comphelper/comphelperdllapi.h>
26 #include <rtl/ref.hxx>
28 namespace osl
{ class Mutex
; }
29 namespace com::sun::star::container
{ class XContainer
; }
36 class OContainerListenerAdapter
;
38 //= OContainerListener
40 /** a non-UNO container listener
41 <p>Useful if you have a non-refcountable class which should act as container listener.<br/>
42 In this case, derive this class from OContainerListener, and create an adapter
43 OContainerListenerAdapter which multiplexes the changes.</p>
45 class COMPHELPER_DLLPUBLIC OContainerListener
47 friend class OContainerListenerAdapter
;
48 rtl::Reference
<OContainerListenerAdapter
> m_xAdapter
;
49 ::osl::Mutex
& m_rMutex
;
52 OContainerListener(::osl::Mutex
& _rMutex
);
53 virtual ~OContainerListener();
55 /// @throws css::uno::RuntimeException
56 virtual void _elementInserted( const css::container::ContainerEvent
& _rEvent
);
57 /// @throws css::uno::RuntimeException
58 virtual void _elementRemoved( const css::container::ContainerEvent
& _rEvent
);
59 /// @throws css::uno::RuntimeException
60 virtual void _elementReplaced( const css::container::ContainerEvent
& _rEvent
);
61 /// @throws css::uno::RuntimeException
62 virtual void _disposing(const css::lang::EventObject
& _rSource
);
65 void setAdapter(OContainerListenerAdapter
* _pAdapter
);
68 // workaround for incremental linking bugs in MSVC2015
69 class SAL_DLLPUBLIC_TEMPLATE OContainerListenerAdapter_Base
: public cppu::WeakImplHelper
< css::container::XContainerListener
> {};
71 class COMPHELPER_DLLPUBLIC OContainerListenerAdapter final
: public OContainerListenerAdapter_Base
73 friend class OContainerListener
;
76 css::uno::Reference
< css::container::XContainer
>
78 OContainerListener
* m_pListener
;
80 virtual ~OContainerListenerAdapter() override
;
83 OContainerListenerAdapter(OContainerListener
* _pListener
,
84 const css::uno::Reference
< css::container::XContainer
>& _rxContainer
);
87 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
90 virtual void SAL_CALL
elementInserted( const css::container::ContainerEvent
& Event
) override
;
91 virtual void SAL_CALL
elementRemoved( const css::container::ContainerEvent
& Event
) override
;
92 virtual void SAL_CALL
elementReplaced( const css::container::ContainerEvent
& Event
) override
;
94 /// dispose the object. No multiplexing anymore
103 #endif // INCLUDED_COMPHELPER_CONTAINERMULTIPLEXER_HXX
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */