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