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 SVX_FORMDISPATCHINTERCEPTOR_HXX
25 #define SVX_FORMDISPATCHINTERCEPTOR_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
29 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
30 /** === end UNO includes === **/
31 
32 #include <cppuhelper/compbase2.hxx>
33 #include <comphelper/uno3.hxx>
34 
35 //........................................................................
36 namespace svxform
37 {
38 //........................................................................
39 
40 	//====================================================================
41 	//= DispatchInterceptor
42 	//====================================================================
43     class DispatchInterceptor
44     {
45     public:
DispatchInterceptor()46         DispatchInterceptor() { }
47 
48         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch> interceptedQueryDispatch(
49             const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( ::com::sun::star::uno::RuntimeException ) = 0;
50 
51         virtual ::osl::Mutex* getInterceptorMutex() = 0;
52     };
53 
54 	//====================================================================
55 	//=
56 	//====================================================================
57     typedef ::cppu::WeakComponentImplHelper2<	::com::sun::star::frame::XDispatchProviderInterceptor
58                                             ,	::com::sun::star::lang::XEventListener
59                                             >	DispatchInterceptionMultiplexer_BASE;
60 
61     class DispatchInterceptionMultiplexer : public DispatchInterceptionMultiplexer_BASE
62     {
63         ::osl::Mutex	m_aFallback;
64         ::osl::Mutex*   m_pMutex;
65 
66         // the component which's dispatches we're intercepting
67         ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XDispatchProviderInterception >
68                         m_xIntercepted;
69         sal_Bool		m_bListening;
70 
71         // the real interceptor
72         DispatchInterceptor*			m_pMaster;
73 
74         // chaining
75         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider>			m_xSlaveDispatcher;
76         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider>			m_xMasterDispatcher;
77 
78         virtual ~DispatchInterceptionMultiplexer();
79 
80     public:
getIntercepted() const81         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterception> getIntercepted() const { return m_xIntercepted; }
82 
83     public:
84         DispatchInterceptionMultiplexer(
85             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterception>& _rToIntercept,
86             DispatchInterceptor* _pMaster
87         );
88 
89         // UNO
90         DECLARE_UNO3_DEFAULTS(DispatchInterceptionMultiplexer, DispatchInterceptionMultiplexer_BASE);
91 
92         // ::com::sun::star::frame::XDispatchProvider
93         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch( const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw(::com::sun::star::uno::RuntimeException);
94         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw(::com::sun::star::uno::RuntimeException);
95 
96         // ::com::sun::star::frame::XDispatchProviderInterceptor
97         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider(  ) throw(::com::sun::star::uno::RuntimeException);
98         virtual void SAL_CALL setSlaveDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewDispatchProvider ) throw(::com::sun::star::uno::RuntimeException);
99         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider(	) throw(::com::sun::star::uno::RuntimeException);
100         virtual void SAL_CALL setMasterDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewSupplier ) throw(::com::sun::star::uno::RuntimeException);
101 
102         // ::com::sun::star::lang::XEventListener
103         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
104 
105         // OComponentHelper
106         virtual void SAL_CALL disposing();
107 
108     protected:
109         void ImplDetach();
110     };
111 
112 //........................................................................
113 } // namespace svxform
114 //........................................................................
115 
116 #endif // SVX_FORMDISPATCHINTERCEPTOR_HXX
117