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 FORMS_SOURCE_INC_LISTENERCONTAINERS_HXX
25 #define FORMS_SOURCE_INC_LISTENERCONTAINERS_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/form/XResetListener.hpp>
29 /** === end UNO includes === **/
30 #include <comphelper/listenernotification.hxx>
31 #include <cppuhelper/weak.hxx>
32 
33 //........................................................................
34 namespace frm
35 {
36 //........................................................................
37 
38     //=====================================================================
39     //= EventListeners
40     //=====================================================================
41     template < class LISTENER >
42     class EventListeners : public ::comphelper::OListenerContainerBase< LISTENER, ::com::sun::star::lang::EventObject >
43     {
44     public:
45         typedef LISTENER                            ListenerClass;
46         typedef ::com::sun::star::lang::EventObject EventClass;
47         typedef ::comphelper::OListenerContainerBase< ListenerClass, EventClass >
48                                                     EventListeners_Base;
49 
50     private:
51         ::cppu::OWeakObject&    m_rInstigator;
52 
53     protected:
getInstigator()54         ::cppu::OWeakObject&    getInstigator() { return m_rInstigator; }
55 
56     protected:
EventListeners(::cppu::OWeakObject & _rInstigator,::osl::Mutex & _rMutex)57         inline EventListeners( ::cppu::OWeakObject& _rInstigator, ::osl::Mutex& _rMutex )
58             :EventListeners_Base( _rMutex )
59             ,m_rInstigator( _rInstigator )
60         {
61         }
62 
63         // still waiting to be overwritten
64         virtual bool    implTypedNotify(
65                             const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener,
66                             const EventClass& _rEvent
67                         )   SAL_THROW( ( ::com::sun::star::uno::Exception ) ) = 0;
68 
69     public:
notify()70         inline bool notify()
71         {
72             ::com::sun::star::lang::EventObject aEvent( m_rInstigator );
73             return EventListeners_Base::notify( aEvent );
74         }
75 
disposing()76         inline void disposing()
77         {
78             ::com::sun::star::lang::EventObject aEvent( m_rInstigator );
79             EventListeners_Base::disposing( aEvent );
80         }
81     protected:
82         using EventListeners_Base::notify;
83         using EventListeners_Base::disposing;
84     };
85 
86     //=====================================================================
87     //= ResetListeners
88     //=====================================================================
89     typedef EventListeners  <   ::com::sun::star::form::XResetListener
90                             >   ResetListeners_Base;
91     class ResetListeners : public ResetListeners_Base
92     {
93     private:
94         enum NotificationType
95         {
96             eApproval,
97             eFinal
98         };
99         NotificationType        m_eCurrentNotificationType;
100 
101     public:
ResetListeners(::cppu::OWeakObject & _rInstigator,::osl::Mutex & _rMutex)102         inline ResetListeners( ::cppu::OWeakObject& _rInstigator, ::osl::Mutex& _rMutex )
103             :ResetListeners_Base( _rInstigator, _rMutex )
104             ,m_eCurrentNotificationType( eApproval )
105         {
106         }
107 
108         /** see whether all our listeners approve the reset
109         */
approveReset()110         sal_Bool approveReset()
111         {
112             m_eCurrentNotificationType = eApproval;
113             return notify();
114         }
115 
116         /** tell all our listeners that the reset happened
117         */
resetted()118         void resetted()
119         {
120             m_eCurrentNotificationType = eFinal;
121             notify();
122         }
123 
124     protected:
125         virtual bool    implTypedNotify(
126                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& _rxListener,
127                             const ::com::sun::star::lang::EventObject& _rEvent
128                         )   SAL_THROW( ( ::com::sun::star::uno::Exception ) );
129     };
130 
131 //........................................................................
132 } // namespace frm
133 //........................................................................
134 
135 #endif // FORMS_SOURCE_INC_LISTENERCONTAINERS_HXX
136 
137