Branch data Line data Source code
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_SELECTION_MULTIPLEX_HXX
21 : : #define INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
22 : :
23 : : #include <com/sun/star/view/XSelectionChangeListener.hpp>
24 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
25 : : #include <cppuhelper/implbase1.hxx>
26 : : #include "comphelper/comphelperdllapi.h"
27 : :
28 : : //=========================================================================
29 : : //= selection helper classes
30 : : //=========================================================================
31 : :
32 : : //.........................................................................
33 : : namespace comphelper
34 : : {
35 : : //.........................................................................
36 : :
37 : : class OSelectionChangeMultiplexer;
38 : :
39 : : //==================================================================
40 : : //= OSelectionChangeListener
41 : : //==================================================================
42 : : /// simple listener adapter for selections
43 : : class COMPHELPER_DLLPUBLIC OSelectionChangeListener
44 : : {
45 : : friend class OSelectionChangeMultiplexer;
46 : :
47 : : OSelectionChangeMultiplexer* m_pAdapter;
48 : : ::osl::Mutex& m_rMutex;
49 : :
50 : : public:
51 : 0 : OSelectionChangeListener(::osl::Mutex& _rMutex)
52 : 0 : : m_pAdapter(NULL), m_rMutex(_rMutex) { }
53 : : virtual ~OSelectionChangeListener();
54 : :
55 : : virtual void _selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException) = 0;
56 : : virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException);
57 : :
58 : : protected:
59 : : // pseudo-private. Making it private now could break compatibility
60 : : void setAdapter( OSelectionChangeMultiplexer* _pAdapter );
61 : : };
62 : :
63 : : //==================================================================
64 : : //= OSelectionChangeMultiplexer
65 : : //==================================================================
66 : : /// multiplexer for selection changes
67 : : class COMPHELPER_DLLPUBLIC OSelectionChangeMultiplexer :public cppu::WeakImplHelper1< ::com::sun::star::view::XSelectionChangeListener>
68 : : {
69 : : friend class OSelectionChangeListener;
70 : : ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier> m_xSet;
71 : : OSelectionChangeListener* m_pListener;
72 : : sal_Int32 m_nLockCount;
73 : : sal_Bool m_bListening : 1;
74 : : sal_Bool m_bAutoSetRelease : 1;
75 : :
76 : : OSelectionChangeMultiplexer(const OSelectionChangeMultiplexer&);
77 : : OSelectionChangeMultiplexer& operator=(const OSelectionChangeMultiplexer&);
78 : : protected:
79 : : virtual ~OSelectionChangeMultiplexer();
80 : : public:
81 : : OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True);
82 : :
83 : : // XEventListener
84 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
85 : :
86 : : // XSelectionChangeListener
87 : : virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
88 : :
89 : : /// incremental lock
90 : : void lock();
91 : : /// incremental unlock
92 : : void unlock();
93 : : /// get the lock count
94 : 0 : sal_Int32 locked() const { return m_nLockCount; }
95 : :
96 : : void dispose();
97 : : };
98 : :
99 : : //.........................................................................
100 : : } // namespace comphelper
101 : : //.........................................................................
102 : :
103 : : #endif // INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
104 : :
105 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|