1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
25 #define INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
26 
27 #include <com/sun/star/view/XSelectionChangeListener.hpp>
28 #include <com/sun/star/view/XSelectionSupplier.hpp>
29 #include <cppuhelper/implbase1.hxx>
30 #include "comphelper/comphelperdllapi.h"
31 
32 //=========================================================================
33 //= selection helper classes
34 //=========================================================================
35 
36 //.........................................................................
37 namespace comphelper
38 {
39 //.........................................................................
40 
41 	class OSelectionChangeMultiplexer;
42 
43 	//==================================================================
44 	//= OSelectionChangeListener
45 	//==================================================================
46 	/// simple listener adapter for selections
47 	class COMPHELPER_DLLPUBLIC OSelectionChangeListener
48 	{
49 		friend class OSelectionChangeMultiplexer;
50 
51 		OSelectionChangeMultiplexer*    m_pAdapter;
52 		::osl::Mutex&				    m_rMutex;
53 
54 	public:
OSelectionChangeListener(::osl::Mutex & _rMutex)55 		OSelectionChangeListener(::osl::Mutex& _rMutex)
56 			: m_pAdapter(NULL), m_rMutex(_rMutex) { }
57 		virtual ~OSelectionChangeListener();
58 
59         virtual void _selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException) = 0;
60 		virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException);
61 
62 	protected:
63         /** If the derivee also owns the mutex which we know as reference, then call this within your
64             derivee's dtor.
65         */
66         void    disposeAdapter();
67 
68         // pseudo-private. Making it private now could break compatibility
69 		void    setAdapter( OSelectionChangeMultiplexer* _pAdapter );
70 	};
71 
72 	//==================================================================
73 	//= OSelectionChangeMultiplexer
74 	//==================================================================
75 	/// multiplexer for selection changes
76 	class COMPHELPER_DLLPUBLIC OSelectionChangeMultiplexer	:public cppu::WeakImplHelper1< ::com::sun::star::view::XSelectionChangeListener>
77 	{
78 		friend class OSelectionChangeListener;
79 		 ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier>	m_xSet;
80 		OSelectionChangeListener*					m_pListener;
81 		sal_Int32									m_nLockCount;
82 		sal_Bool									m_bListening		: 1;
83 		sal_Bool									m_bAutoSetRelease	: 1;
84 
85         OSelectionChangeMultiplexer(const OSelectionChangeMultiplexer&);
86 		OSelectionChangeMultiplexer& operator=(const OSelectionChangeMultiplexer&);
87     protected:
88 		virtual ~OSelectionChangeMultiplexer();
89 	public:
90 		OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True);
91 
92 	// XEventListener
93 		virtual void SAL_CALL disposing( const  ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
94 
95 	// XSelectionChangeListener
96         virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
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 dispose();
106 	};
107 
108 //.........................................................................
109 }	// namespace comphelper
110 //.........................................................................
111 
112 #endif // INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
113 
114