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 20 #ifndef INCLUDED_COMPHELPER_PROPMULTIPLEX_HXX 21 #define INCLUDED_COMPHELPER_PROPMULTIPLEX_HXX 22 23 #include <com/sun/star/beans/XPropertyChangeListener.hpp> 24 #include <cppuhelper/implbase.hxx> 25 #include <comphelper/comphelperdllapi.h> 26 #include <rtl/ref.hxx> 27 #include <vector> 28 29 namespace com { namespace sun { namespace star { namespace beans { 30 class XPropertySet; 31 } } } } 32 33 //= property helper classes 34 35 36 namespace comphelper 37 { 38 39 40 class OPropertyChangeMultiplexer; 41 42 43 //= OPropertyChangeListener 44 45 /// simple listener adapter for property sets 46 class COMPHELPER_DLLPUBLIC OPropertyChangeListener 47 { 48 friend class OPropertyChangeMultiplexer; 49 50 rtl::Reference<OPropertyChangeMultiplexer> m_xAdapter; 51 ::osl::Mutex& m_rMutex; 52 53 public: OPropertyChangeListener(::osl::Mutex & _rMutex)54 OPropertyChangeListener(::osl::Mutex& _rMutex) 55 : m_rMutex(_rMutex) { } 56 virtual ~OPropertyChangeListener(); 57 58 /// @throws css::uno::RuntimeException 59 virtual void _propertyChanged(const css::beans::PropertyChangeEvent& _rEvent) = 0; 60 /// @throws css::uno::RuntimeException 61 virtual void _disposing(const css::lang::EventObject& _rSource); 62 63 protected: 64 /** If the derivee also owns the mutex which we know as reference, then call this within your 65 derivee's dtor. 66 */ 67 void disposeAdapter(); 68 69 // pseudo-private. Making it private now could break compatibility 70 void setAdapter( OPropertyChangeMultiplexer* _pAdapter ); 71 }; 72 73 74 //= OPropertyChangeMultiplexer 75 76 /// multiplexer for property changes 77 class COMPHELPER_DLLPUBLIC OPropertyChangeMultiplexer :public cppu::WeakImplHelper< css::beans::XPropertyChangeListener> 78 { 79 friend class OPropertyChangeListener; 80 std::vector< OUString > m_aProperties; 81 css::uno::Reference< css::beans::XPropertySet> m_xSet; 82 OPropertyChangeListener* m_pListener; 83 sal_Int32 m_nLockCount; 84 bool m_bListening : 1; 85 bool const m_bAutoSetRelease : 1; 86 87 88 virtual ~OPropertyChangeMultiplexer() override; 89 public: 90 OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const css::uno::Reference< css::beans::XPropertySet>& _rxSet, bool _bAutoReleaseSet = true); 91 92 // XEventListener 93 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; 94 95 // XPropertyChangeListener 96 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override; 97 98 /// incremental lock 99 void lock(); 100 /// incremental unlock 101 void unlock(); 102 /// get the lock count locked() const103 sal_Int32 locked() const { return m_nLockCount; } 104 105 void addProperty(const OUString& aPropertyName); 106 void dispose(); 107 }; 108 109 110 } // namespace comphelper 111 112 113 #endif // INCLUDED_COMPHELPER_PROPMULTIPLEX_HXX 114 115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 116