Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_FORMS_SOURCE_INC_LISTENERCONTAINERS_HXX
21 : #define INCLUDED_FORMS_SOURCE_INC_LISTENERCONTAINERS_HXX
22 :
23 : #include <com/sun/star/form/XResetListener.hpp>
24 : #include <comphelper/listenernotification.hxx>
25 : #include <cppuhelper/weak.hxx>
26 :
27 :
28 : namespace frm
29 : {
30 :
31 :
32 :
33 : //= EventListeners
34 :
35 : template < class LISTENER >
36 0 : class EventListeners : public ::comphelper::OListenerContainerBase< LISTENER, ::com::sun::star::lang::EventObject >
37 : {
38 : public:
39 : typedef LISTENER ListenerClass;
40 : typedef ::com::sun::star::lang::EventObject EventClass;
41 : typedef ::comphelper::OListenerContainerBase< ListenerClass, EventClass >
42 : EventListeners_Base;
43 :
44 : private:
45 : ::cppu::OWeakObject& m_rInstigator;
46 :
47 : protected:
48 : ::cppu::OWeakObject& getInstigator() { return m_rInstigator; }
49 :
50 : protected:
51 0 : inline EventListeners( ::cppu::OWeakObject& _rInstigator, ::osl::Mutex& _rMutex )
52 : :EventListeners_Base( _rMutex )
53 0 : ,m_rInstigator( _rInstigator )
54 : {
55 0 : }
56 :
57 : // still waiting to be overwritten
58 : virtual bool implTypedNotify(
59 : const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener,
60 : const EventClass& _rEvent
61 : ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ) = 0;
62 :
63 : public:
64 0 : inline bool notify()
65 : {
66 0 : ::com::sun::star::lang::EventObject aEvent( m_rInstigator );
67 0 : return EventListeners_Base::notify( aEvent );
68 : }
69 :
70 0 : inline void disposing()
71 : {
72 0 : ::com::sun::star::lang::EventObject aEvent( m_rInstigator );
73 0 : EventListeners_Base::disposing( aEvent );
74 0 : }
75 : protected:
76 : using EventListeners_Base::notify;
77 : using EventListeners_Base::disposing;
78 : };
79 :
80 :
81 : //= ResetListeners
82 :
83 : typedef EventListeners < ::com::sun::star::form::XResetListener
84 : > ResetListeners_Base;
85 0 : class ResetListeners : public ResetListeners_Base
86 : {
87 : private:
88 : enum NotificationType
89 : {
90 : eApproval,
91 : eFinal
92 : };
93 : NotificationType m_eCurrentNotificationType;
94 :
95 : public:
96 0 : inline ResetListeners( ::cppu::OWeakObject& _rInstigator, ::osl::Mutex& _rMutex )
97 : :ResetListeners_Base( _rInstigator, _rMutex )
98 0 : ,m_eCurrentNotificationType( eApproval )
99 : {
100 0 : }
101 :
102 : /** see whether all our listeners approve the reset
103 : */
104 0 : sal_Bool approveReset()
105 : {
106 0 : m_eCurrentNotificationType = eApproval;
107 0 : return notify();
108 : }
109 :
110 : /** tell all our listeners that the reset happened
111 : */
112 0 : void resetted()
113 : {
114 0 : m_eCurrentNotificationType = eFinal;
115 0 : notify();
116 0 : }
117 :
118 : protected:
119 : virtual bool implTypedNotify(
120 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& _rxListener,
121 : const ::com::sun::star::lang::EventObject& _rEvent
122 : ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ) SAL_OVERRIDE;
123 : };
124 :
125 :
126 : } // namespace frm
127 :
128 :
129 : #endif // INCLUDED_FORMS_SOURCE_INC_LISTENERCONTAINERS_HXX
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|