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 
25 #ifndef DBACCESS_DOCUMENTEVENTNOTIFIER_HXX
26 #define DBACCESS_DOCUMENTEVENTNOTIFIER_HXX
27 
28 /** === begin UNO includes === **/
29 #include <com/sun/star/document/XEventListener.hpp>
30 #include <com/sun/star/document/XDocumentEventListener.hpp>
31 /** === end UNO includes === **/
32 
33 #include <rtl/ref.hxx>
34 
35 namespace cppu
36 {
37     class OWeakObject;
38 }
39 
40 //........................................................................
41 namespace dbaccess
42 {
43 //........................................................................
44 
45     class DocumentEventNotifier_Impl;
46 	//====================================================================
47 	//= DocumentEventNotifier
48 	//====================================================================
49 	class DocumentEventNotifier
50 	{
51     public:
52         DocumentEventNotifier( ::cppu::OWeakObject& _rBroadcasterDocument, ::osl::Mutex& _rMutex );
53         ~DocumentEventNotifier();
54 
55         void addLegacyEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& _Listener );
56         void removeLegacyEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& _Listener );
57         void addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener );
58         void removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener );
59 
60         /** disposes the instance
61             @precond
62                 the mutex is not locked
63         */
64         void    disposing();
65 
66         /** tells the instance that its document is completely initialized now.
67 
68             Before you call this method, no notification will actually happen
69 
70             @precond
71                 the mutex is locked
72         */
73         void    onDocumentInitialized();
74 
75         /** notifies a document event described by the given parameters
76 
77             @precond
78                 the mutex is not locked
79             @precond
80                 ->onDocumentInitialized has been called
81         */
82         void    notifyDocumentEvent(
83                     const ::rtl::OUString& _EventName,
84                     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _rxViewController = NULL,
85                     const ::com::sun::star::uno::Any& _Supplement = ::com::sun::star::uno::Any()
86                 );
87 
88         /** notifies a document event, described by the given parameters, asynchronously
89 
90             Note that no event is actually notified before you called ->onDocumentInitialized.
91 
92             @precond
93                 the mutex is locked
94         */
95         void    notifyDocumentEventAsync(
96                     const ::rtl::OUString& _EventName,
97                     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _ViewController = NULL,
98                     const ::com::sun::star::uno::Any& _Supplement = ::com::sun::star::uno::Any()
99                 );
100 
101         /** notifies a document event to all registered listeners
102 
103             @precond
104                 the mutex is not locked
105             @precond
106                 ->onDocumentInitialized has been called
107         */
notifyDocumentEvent(const sal_Char * _pAsciiEventName,const::com::sun::star::uno::Reference<::com::sun::star::frame::XController2> & _rxViewController=NULL,const::com::sun::star::uno::Any & _rSupplement=::com::sun::star::uno::Any ())108         void    notifyDocumentEvent(
109                     const sal_Char* _pAsciiEventName,
110                     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _rxViewController = NULL,
111                     const ::com::sun::star::uno::Any& _rSupplement = ::com::sun::star::uno::Any()
112                 )
113         {
114             notifyDocumentEvent( ::rtl::OUString::createFromAscii( _pAsciiEventName ), _rxViewController, _rSupplement );
115         }
116 
117         /** notifies a document event to all registered listeners, asynchronously
118 
119             Note that no event is actually notified before you called ->onDocumentInitialized.
120 
121             @precond
122                 the mutex is locked
123         */
notifyDocumentEventAsync(const sal_Char * _pAsciiEventName,const::com::sun::star::uno::Reference<::com::sun::star::frame::XController2> & _rxViewController=NULL,const::com::sun::star::uno::Any & _rSupplement=::com::sun::star::uno::Any ())124         void    notifyDocumentEventAsync(
125                     const sal_Char* _pAsciiEventName,
126                     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _rxViewController = NULL,
127                     const ::com::sun::star::uno::Any& _rSupplement = ::com::sun::star::uno::Any()
128                 )
129         {
130             notifyDocumentEventAsync( ::rtl::OUString::createFromAscii( _pAsciiEventName ), _rxViewController, _rSupplement );
131         }
132 
133     private:
134         ::rtl::Reference< DocumentEventNotifier_Impl >   m_pImpl;
135 	};
136 
137 //........................................................................
138 } // namespace dbaccess
139 //........................................................................
140 
141 #endif // DBACCESS_DOCUMENTEVENTNOTIFIER_HXX
142