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 SCRIPTING_DLGEVTATT_HXX
25 #define SCRIPTING_DLGEVTATT_HXX
26 
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/script/XAllListener.hpp>
29 #include <com/sun/star/script/XEventAttacher.hpp>
30 #include <com/sun/star/script/XScriptEventsAttacher.hpp>
31 #include <com/sun/star/script/XScriptListener.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/awt/XControl.hpp>
34 #ifndef _COM_SUN_STAR_BEANS_XINTROSPECTION_HPP_
35 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
36 #endif
37 #include <cppuhelper/implbase1.hxx>
38 
39 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
40 
41 #include <hash_map>
42 
43 //.........................................................................
44 namespace dlgprov
45 {
46 //.........................................................................
47 
48     // =============================================================================
49     // class DialogEventsAttacherImpl
50     // =============================================================================
51     typedef std::hash_map< rtl::OUString,
52         ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >,
53         ::rtl::OUStringHash,
54         ::std::equal_to< ::rtl::OUString > > ListenerHash;
55 
56     typedef ::cppu::WeakImplHelper1<
57         ::com::sun::star::script::XScriptEventsAttacher > DialogEventsAttacherImpl_BASE;
58 
59 
60     class DialogEventsAttacherImpl : public DialogEventsAttacherImpl_BASE
61     {
62     private:
63         bool mbUseFakeVBAEvents;
64         ListenerHash listernersForTypes;
65         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
66         ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacher > m_xEventAttacher;
67         ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > getScriptListenerForKey( const rtl::OUString& sScriptName ) throw ( ::com::sun::star::uno::RuntimeException );
68         ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier > getFakeVbaEventsSupplier( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, rtl::OUString& sCodeName );
69         void  SAL_CALL attachEventsToControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier >& events, const ::com::sun::star::uno::Any& Helper  );
70     public:
71         DialogEventsAttacherImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
72         	 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel,
73         	 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& xControl,
74         	 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xHandler,
75         	 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess >& xIntrospect,
76              bool bProviderMode,
77         	 const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& xRTLListener );
78         virtual ~DialogEventsAttacherImpl();
79 
80         // XScriptEventsAttacher
81         virtual void SAL_CALL attachEvents( const ::com::sun::star::uno::Sequence<
82             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& Objects,
83 			const com::sun::star::uno::Reference<com::sun::star::script::XScriptListener>&,
84             const ::com::sun::star::uno::Any& Helper )
85             throw (::com::sun::star::lang::IllegalArgumentException,
86                    ::com::sun::star::beans::IntrospectionException,
87                    ::com::sun::star::script::CannotCreateAdapterException,
88                    ::com::sun::star::lang::ServiceNotRegisteredException,
89                    ::com::sun::star::uno::RuntimeException);
90     };
91 
92 
93     // =============================================================================
94     // class DialogAllListenerImpl
95     // =============================================================================
96 
97     typedef ::cppu::WeakImplHelper1<
98         ::com::sun::star::script::XAllListener > DialogAllListenerImpl_BASE;
99 
100 
101     class DialogAllListenerImpl : public DialogAllListenerImpl_BASE
102     {
103     private:
104         ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > m_xScriptListener;
105         ::rtl::OUString m_sScriptType;
106         ::rtl::OUString m_sScriptCode;
107 
108         virtual void firing_impl( const ::com::sun::star::script::AllEventObject& Event, ::com::sun::star::uno::Any* pRet );
109 
110     public:
111         DialogAllListenerImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& rxListener,
112             const ::rtl::OUString& rScriptType, const ::rtl::OUString& rScriptCode );
113         virtual ~DialogAllListenerImpl();
114 
115         // XEventListener
116         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
117             throw (::com::sun::star::uno::RuntimeException);
118 
119         // XAllListener
120         virtual void SAL_CALL firing( const ::com::sun::star::script::AllEventObject& Event )
121             throw (::com::sun::star::uno::RuntimeException);
122         virtual ::com::sun::star::uno::Any SAL_CALL approveFiring( const ::com::sun::star::script::AllEventObject& Event )
123             throw (::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException);
124     };
125 
126 
127     // =============================================================================
128     // class DialogScriptListenerImpl
129     // =============================================================================
130 
131     typedef ::cppu::WeakImplHelper1<
132         ::com::sun::star::script::XScriptListener > DialogScriptListenerImpl_BASE;
133 
134 
135     class DialogScriptListenerImpl : public DialogScriptListenerImpl_BASE
136     {
137     protected:
138         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
139         virtual void firing_impl( const ::com::sun::star::script::ScriptEvent& aScriptEvent, ::com::sun::star::uno::Any* pRet ) = 0;
140     public:
DialogScriptListenerImpl(const::com::sun::star::uno::Reference<::com::sun::star::uno::XComponentContext> & rxContext)141         DialogScriptListenerImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) : m_xContext( rxContext ) {}
142         virtual ~DialogScriptListenerImpl();
143 
144         // XEventListener
145         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
146             throw (::com::sun::star::uno::RuntimeException);
147 
148         // XScriptListener
149         virtual void SAL_CALL firing( const ::com::sun::star::script::ScriptEvent& aScriptEvent )
150             throw (::com::sun::star::uno::RuntimeException);
151         virtual ::com::sun::star::uno::Any SAL_CALL approveFiring( const ::com::sun::star::script::ScriptEvent& aScriptEvent )
152             throw (::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException);
153     };
154 
155 
156 //.........................................................................
157 }	// namespace dlgprov
158 //.........................................................................
159 
160 #endif // SCRIPTING_DLGEVT_HXX
161