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