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 // SODispatchInterceptor.h: Definition of the SODispatchInterceptor class
23 //
24 //////////////////////////////////////////////////////////////////////
25 
26 #if !defined __SODISPATCHINTERCEPTOR_H_
27 #define __SODISPATCHINTERCEPTOR_H_
28 
29 #if _MSC_VER > 1000
30 #pragma once
31 #endif // _MSC_VER > 1000
32 
33 #include "resource.h"       // main symbols
34 #include <ExDispID.h>
35 #include <ExDisp.h>
36 #include <shlguid.h>
37 
38 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
39 #undef _DEBUG
40 #endif
41 #include <atlctl.h>
42 
43 #include "so_activex.h"
44 
45 class CSOActiveX;
46 
47 /////////////////////////////////////////////////////////////////////////////
48 // SODispatchInterceptor
49 
50 class SODispatchInterceptor :
51 	public IDispatchImpl<ISODispatchInterceptor, &IID_ISODispatchInterceptor, &LIBID_SO_ACTIVEXLib>,
52 	public ISupportErrorInfo,
53 	public CComObjectRoot,
54 	public CComCoClass<SODispatchInterceptor,&CLSID_SODispatchInterceptor>
55 {
56 	CComPtr<IDispatch>	m_xMaster;
57 	CComPtr<IDispatch>	m_xSlave;
58 	CSOActiveX* 		m_xParentControl;
59 	CRITICAL_SECTION	mMutex;
60 public:
SODispatchInterceptor()61 	SODispatchInterceptor() : m_xParentControl( NULL ) { InitializeCriticalSection(&mMutex); }
~SODispatchInterceptor()62 	virtual ~SODispatchInterceptor() { ATLASSERT( !m_xParentControl ); DeleteCriticalSection(&mMutex); }
63 
64 BEGIN_COM_MAP(SODispatchInterceptor)
COM_INTERFACE_ENTRY(IDispatch)65 	COM_INTERFACE_ENTRY(IDispatch)
66 	COM_INTERFACE_ENTRY(ISODispatchInterceptor)
67 	COM_INTERFACE_ENTRY(ISupportErrorInfo)
68 END_COM_MAP()
69 DECLARE_NOT_AGGREGATABLE(SODispatchInterceptor)
70 // Remove the comment from the line above if you don't want your object to
71 // support aggregation.
72 
73 DECLARE_REGISTRY_RESOURCEID(IDR_SODISPATCHINTERCEPTOR)
74 
75 	void SetParent( CSOActiveX* pParent )
76 	{
77 		ATLASSERT( !m_xParentControl );
78 		EnterCriticalSection( &mMutex );
79 		m_xParentControl = pParent;
80 		LeaveCriticalSection( &mMutex );
81 	}
82 
ClearParent()83 	void ClearParent()
84 	{
85 		EnterCriticalSection( &mMutex );
86 		m_xParentControl = NULL;
87 		LeaveCriticalSection( &mMutex );
88 	}
89 
90 // ISupportsErrorInfo
91 	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
92 
93 // ISODispatchInterceptor
94 
getSlaveDispatchProvider(IDispatch __RPC_FAR * __RPC_FAR * retVal)95         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE getSlaveDispatchProvider(
96             /* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *retVal)
97 		{
98 			*retVal = m_xSlave;
99 			return S_OK;
100 		}
101 
setSlaveDispatchProvider(IDispatch __RPC_FAR * xNewDispatchProvider)102         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE setSlaveDispatchProvider(
103             /* [in] */ IDispatch __RPC_FAR *xNewDispatchProvider)
104 		{
105 			m_xSlave = xNewDispatchProvider;
106 			return S_OK;
107 		}
108 
getMasterDispatchProvider(IDispatch __RPC_FAR * __RPC_FAR * retVal)109         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE getMasterDispatchProvider(
110             /* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *retVal)
111 		{
112 			*retVal = m_xMaster;
113 			return S_OK;
114 		}
115 
setMasterDispatchProvider(IDispatch __RPC_FAR * xNewSupplier)116         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE setMasterDispatchProvider(
117             /* [in] */ IDispatch __RPC_FAR *xNewSupplier)
118 		{
119 			m_xMaster = xNewSupplier;
120 			return S_OK;
121 		}
122 
123         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE queryDispatch(
124             /* [in] */ IDispatch __RPC_FAR *aURL,
125             /* [in] */ BSTR aTargetFrameName,
126             /* [in] */ long nSearchFlags,
127             /* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *retVal);
128 
129         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE queryDispatches(
130             /* [in] */ SAFEARRAY __RPC_FAR * aDescripts,
131             /* [retval][out] */ SAFEARRAY __RPC_FAR * __RPC_FAR *retVal);
132 
133         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE dispatch(
134             /* [in] */ IDispatch __RPC_FAR *aURL,
135             /* [in] */ SAFEARRAY __RPC_FAR * aArgs);
136 
137         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE addStatusListener(
138             /* [in] */ IDispatch __RPC_FAR *xControl,
139             /* [in] */ IDispatch __RPC_FAR *aURL);
140 
141         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE removeStatusListener(
142             /* [in] */ IDispatch __RPC_FAR *xControl,
143             /* [in] */ IDispatch __RPC_FAR *aURL);
144 
145         virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE getInterceptedURLs(
146             /* [retval][out] */ SAFEARRAY __RPC_FAR * __RPC_FAR *pVal);
147 
get_Bridge_implementedInterfaces(SAFEARRAY __RPC_FAR * __RPC_FAR * pVal)148         virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_Bridge_implementedInterfaces(
149             /* [retval][out] */ SAFEARRAY __RPC_FAR * __RPC_FAR *pVal)
150 		{
151 			*pVal = SafeArrayCreateVector( VT_BSTR, 0, 4 );
152 
153 			if( !*pVal )
154 				return E_FAIL;
155 
156 			long ix = 0;
157             CComBSTR aInterface( OLESTR( "com.sun.star.frame.XDispatchProviderInterceptor" ) );
158 			SafeArrayPutElement( *pVal, &ix, aInterface );
159 
160 			ix = 1;
161             aInterface = CComBSTR( OLESTR( "com.sun.star.frame.XDispatchProvider" ) );
162 			SafeArrayPutElement( *pVal, &ix, aInterface );
163 
164 			ix = 2;
165             aInterface = CComBSTR( OLESTR( "com.sun.star.frame.XDispatch" ) );
166 			SafeArrayPutElement( *pVal, &ix, aInterface );
167 
168 			ix = 3;
169             aInterface = CComBSTR( OLESTR( "com.sun.star.frame.XInterceptorInfo" ) );
170 			SafeArrayPutElement( *pVal, &ix, aInterface );
171 
172 			return S_OK;
173 		}
174 };
175 
176 #endif // __SODISPATCHINTERCEPTOR_H_
177