1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
29 #define INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
30 
31 #include <com/sun/star/view/XSelectionChangeListener.hpp>
32 #include <com/sun/star/view/XSelectionSupplier.hpp>
33 #include <cppuhelper/implbase1.hxx>
34 #include "comphelper/comphelperdllapi.h"
35 
36 //=========================================================================
37 //= selection helper classes
38 //=========================================================================
39 
40 //.........................................................................
41 namespace comphelper
42 {
43 //.........................................................................
44 
45 	class OSelectionChangeMultiplexer;
46 
47 	//==================================================================
48 	//= OSelectionChangeListener
49 	//==================================================================
50 	/// simple listener adapter for selections
51 	class COMPHELPER_DLLPUBLIC OSelectionChangeListener
52 	{
53 		friend class OSelectionChangeMultiplexer;
54 
55 		OSelectionChangeMultiplexer*    m_pAdapter;
56 		::osl::Mutex&				    m_rMutex;
57 
58 	public:
59 		OSelectionChangeListener(::osl::Mutex& _rMutex)
60 			: m_pAdapter(NULL), m_rMutex(_rMutex) { }
61 		virtual ~OSelectionChangeListener();
62 
63         virtual void _selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException) = 0;
64 		virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException);
65 
66 	protected:
67         /** If the derivee also owns the mutex which we know as reference, then call this within your
68             derivee's dtor.
69         */
70         void    disposeAdapter();
71 
72         // pseudo-private. Making it private now could break compatibility
73 		void    setAdapter( OSelectionChangeMultiplexer* _pAdapter );
74 	};
75 
76 	//==================================================================
77 	//= OSelectionChangeMultiplexer
78 	//==================================================================
79 	/// multiplexer for selection changes
80 	class COMPHELPER_DLLPUBLIC OSelectionChangeMultiplexer	:public cppu::WeakImplHelper1< ::com::sun::star::view::XSelectionChangeListener>
81 	{
82 		friend class OSelectionChangeListener;
83 		 ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier>	m_xSet;
84 		OSelectionChangeListener*					m_pListener;
85 		sal_Int32									m_nLockCount;
86 		sal_Bool									m_bListening		: 1;
87 		sal_Bool									m_bAutoSetRelease	: 1;
88 
89         OSelectionChangeMultiplexer(const OSelectionChangeMultiplexer&);
90 		OSelectionChangeMultiplexer& operator=(const OSelectionChangeMultiplexer&);
91     protected:
92 		virtual ~OSelectionChangeMultiplexer();
93 	public:
94 		OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True);
95 
96 	// XEventListener
97 		virtual void SAL_CALL disposing( const  ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
98 
99 	// XSelectionChangeListener
100         virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
101 
102 		/// incremental lock
103 		void		lock();
104 		/// incremental unlock
105 		void		unlock();
106 		/// get the lock count
107 		sal_Int32	locked() const { return m_nLockCount; }
108 
109 		void dispose();
110 	};
111 
112 //.........................................................................
113 }	// namespace comphelper
114 //.........................................................................
115 
116 #endif // INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX
117 
118