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 COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
25cdf0e10cSrcweir #define COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
28cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
29cdf0e10cSrcweir #include <osl/thread.hxx>
30cdf0e10cSrcweir #include <osl/conditn.hxx>
31cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h>
32cdf0e10cSrcweir #include "comphelper/comphelperdllapi.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <map>
35cdf0e10cSrcweir #include <list>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //.........................................................................
38cdf0e10cSrcweir namespace comphelper
39cdf0e10cSrcweir {
40cdf0e10cSrcweir //.........................................................................
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	//=====================================================================
43cdf0e10cSrcweir 	//= AccessibleEventNotifier
44cdf0e10cSrcweir 	//=====================================================================
45cdf0e10cSrcweir 	class COMPHELPER_DLLPUBLIC AccessibleEventNotifier
46cdf0e10cSrcweir 	{
47cdf0e10cSrcweir 	// typedefs
48cdf0e10cSrcweir 	public:
49cdf0e10cSrcweir 		typedef sal_uInt32	TClientId;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 		typedef ::std::pair< TClientId, ::com::sun::star::accessibility::AccessibleEventObject >
52cdf0e10cSrcweir 																					ClientEvent;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 		typedef ::cppu::OInterfaceContainerHelper									EventListeners;
55cdf0e10cSrcweir 		typedef ::std::map< TClientId, EventListeners*, ::std::less< TClientId > >	ClientMap;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	protected:
58cdf0e10cSrcweir 		AccessibleEventNotifier( );		// never implemented
59cdf0e10cSrcweir 		~AccessibleEventNotifier( );	// never implemented
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	private:
62cdf0e10cSrcweir 		COMPHELPER_DLLPRIVATE AccessibleEventNotifier( const AccessibleEventNotifier& );				// never implemented!
63cdf0e10cSrcweir 		COMPHELPER_DLLPRIVATE AccessibleEventNotifier& operator=( const AccessibleEventNotifier& );	// never implemented!
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	public:
66cdf0e10cSrcweir 		/** registers a client of this class, means a broadcaster of AccessibleEvents
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			<p>No precaution is taken to care for disposal of this component. When the component
69cdf0e10cSrcweir 			dies, it <b>must</b> call <member>revokeClient</member> or <member>revokeClientNotifyDisposing</member>
70cdf0e10cSrcweir 			explicitly itself.</p>
71cdf0e10cSrcweir 		*/
72cdf0e10cSrcweir 		static	TClientId	registerClient( );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		/** revokes a broadcaster of AccessibleEvents
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			<p>Note that no disposing event is fired when you use this method, the client is simply revoked.
77cdf0e10cSrcweir 			You can for instance revoke a client if the last listener for it is revoked, but the client
78cdf0e10cSrcweir 			itself is not disposed.<br/>
79cdf0e10cSrcweir 			When the client is disposed, you should prefer <member>revokeClientNotifyDisposing</member></p>
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 			<p>Any possibly pending events for this client are removed from the queue.</p>
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 			@seealso revokeClientNotifyDisposing
84cdf0e10cSrcweir 		*/
85cdf0e10cSrcweir 		static	void		revokeClient( const TClientId _nClient );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		/** revokes a client, with additionally notifying a disposing event to all listeners registered for
88cdf0e10cSrcweir 			this client
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 			<p>Any other possibly pending events for this client are removed from the queue</p>
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 			@param _nClient
93cdf0e10cSrcweir 				the id of the client which should be revoked
94cdf0e10cSrcweir 			@param _rxEventSource
95cdf0e10cSrcweir 				the source to be notified together with the <member scope="com.sun.star.lang">XComponent::disposing</member>
96cdf0e10cSrcweir 				call.
97cdf0e10cSrcweir 		*/
98cdf0e10cSrcweir 		static	void		revokeClientNotifyDisposing(
99cdf0e10cSrcweir 						const TClientId _nClient,
100cdf0e10cSrcweir 						const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxEventSource
101cdf0e10cSrcweir 					) SAL_THROW( ( ) );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		/** registers a listener for the given client
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 			@param _nClient
106cdf0e10cSrcweir 				the id of the client for which a listener should be registered
107cdf0e10cSrcweir 			@return
108cdf0e10cSrcweir 				the number of event listeners currently registered for this client
109cdf0e10cSrcweir 		*/
110cdf0e10cSrcweir 		static sal_Int32 addEventListener(
111cdf0e10cSrcweir 						const TClientId _nClient,
112cdf0e10cSrcweir 						const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& _rxListener
113cdf0e10cSrcweir 					) SAL_THROW( ( ) );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		/** revokes a listener for the given client
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 			@param _nClient
118cdf0e10cSrcweir 				the id of the client for which a listener should be revoked
119cdf0e10cSrcweir 			@return
120cdf0e10cSrcweir 				the number of event listeners currently registered for this client
121cdf0e10cSrcweir 		*/
122cdf0e10cSrcweir 		static sal_Int32 removeEventListener(
123cdf0e10cSrcweir 						const TClientId _nClient,
124cdf0e10cSrcweir 						const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& _rxListener
125cdf0e10cSrcweir 					) SAL_THROW( ( ) );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 		/** retrieves the set of listeners registered for a given client
128cdf0e10cSrcweir 		*/
129cdf0e10cSrcweir 		static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
130cdf0e10cSrcweir 						getEventListeners( const TClientId _nClient ) SAL_THROW( ( ) );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 		/** adds an event, which is to be braodcasted, to the queue
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 			@param _nClient
135cdf0e10cSrcweir 				the id of the client which needs to broadcast the event
136cdf0e10cSrcweir 		*/
137cdf0e10cSrcweir 		static void	addEvent(
138cdf0e10cSrcweir 						const TClientId _nClient,
139cdf0e10cSrcweir 						const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent
140cdf0e10cSrcweir 					) SAL_THROW( ( ) );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	private:
143cdf0e10cSrcweir 		/// generates a new client id
144cdf0e10cSrcweir 		COMPHELPER_DLLPRIVATE static	TClientId	generateId();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		/** looks up a client in our client map, asserts if it cannot find it or no event thread is present
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 			@precond
149cdf0e10cSrcweir 				to be called with our mutex locked
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 			@param _nClient
152cdf0e10cSrcweir 				the id of the client to loopup
153cdf0e10cSrcweir 			@param _rPos
154cdf0e10cSrcweir 				out-parameter for the position of the client in the client map
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 			@return
157cdf0e10cSrcweir 				<TRUE/> if and only if the client could be found and <arg>_rPos</arg> has been filled with
158cdf0e10cSrcweir 				it's position
159cdf0e10cSrcweir 		*/
160cdf0e10cSrcweir 		COMPHELPER_DLLPRIVATE static	sal_Bool	implLookupClient( const TClientId _nClient, ClientMap::iterator& _rPos );
161cdf0e10cSrcweir 	};
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //.........................................................................
164cdf0e10cSrcweir }	// namespace comphelper
165cdf0e10cSrcweir //.........................................................................
166cdf0e10cSrcweir 
167cdf0e10cSrcweir #endif // COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170